45#define MGR_PASSWD_SZ 128
50 Must(profile !=
nullptr);
52 menu_.push_back(profile);
53 debugs(16, 3,
"registered profile: " << *profile);
55 debugs(16, 2,
"skipped duplicate profile: " << *profile);
68 Must(action !=
nullptr);
69 Menu::const_iterator a;
71 debugs(16, 5,
"CacheManager::findAction: looking for action " << action);
72 for (a =
menu_.begin(); a !=
menu_.end(); ++a) {
73 if (0 == strcmp((*a)->name, action)) {
79 debugs(16, 6,
"Action not found.");
90 cmd->params.actionName = actionName;
92 Must(cmd->profile !=
nullptr);
93 return cmd->profile->creator->create(cmd);
100 cmd->params = params;
102 Must(cmd->profile !=
nullptr);
103 return cmd->profile->creator->create(cmd);
109 static const SBuf prefix(
"/squid-internal-mgr/");
138 if (!
tok.prefix(action, fieldChars)) {
139 static const SBuf indexReport(
"index");
140 action = indexReport;
149 if (!strcmp(prot,
"disabled") || !strcmp(prot,
"hidden"))
151 cmd->profile = profile;
156 params =
tok.remaining();
160 if (!
tok.skip(
'#') && !
tok.atEnd())
164 debugs(16, 3,
"MGR request: host=" << uri.
host() <<
", action=" << action <<
", params=" << params);
183#if HAVE_AUTH_MODULE_BASIC
189 if (basic_cookie.isEmpty())
192 const auto colonPos = basic_cookie.find(
':');
194 debugs(16,
DBG_IMPORTANT,
"ERROR: CacheManager::ParseHeaders: unknown basic_cookie format '" << basic_cookie <<
"'");
203 debugs(16, 9,
"CacheManager::ParseHeaders: got user: '" <<
219 const char *action = cmd.
profile->name;
222 debugs(16, 4,
"CacheManager::CheckPassword for action " << action);
227 if (strcmp(pwd,
"disable") == 0)
230 if (strcmp(pwd,
"none") == 0)
248 debugs(16, 3,
"request-url= '" << request->
url <<
"', entry-url='" << entry->
url() <<
"'");
263 const char *actionName = cmd->profile->name;
267 debugs(16, 5,
"CacheManager: " << client <<
" requesting '" << actionName <<
"'");
272 const char *userName = cmd->params.userName.size() ?
273 cmd->params.userName.termedBuf() :
"unknown";
282 if (cmd->params.password.size()) {
285 client <<
": incorrect password for '" <<
290 client <<
": password needed for '" <<
296#if HAVE_AUTH_MODULE_BASIC
321 debugs(16, 2,
"CacheManager: " <<
323 client <<
" requesting '" <<
327 if (!strcmp(cmd->profile->name,
"index")) {
331 if (strncmp(rep->
body.
content(),
"Internal Error:", 15) == 0)
349 Must(action !=
nullptr);
350 action->run(entry,
true);
361 assert(profile !=
nullptr);
365 return profile->isPwReq ?
"hidden" :
"public";
367 if (!strcmp(pwd,
"disable"))
370 if (strcmp(pwd,
"none") == 0)
386 if (w.cmp(action) == 0)
389 static const SBuf allAction(
"all");
405 response.
header.
putExt(
"Access-Control-Allow-Origin", httpOrigin);
406#if HAVE_AUTH_MODULE_BASIC
407 response.
header.
putExt(
"Access-Control-Allow-Credentials",
"true");
409 response.
header.
putExt(
"Access-Control-Expose-Headers",
"Server");
426 debugs(16, 6,
"starting cachemanager up");
#define Assure(condition)
#define Here()
source code location of the caller
String SBufToString(const SBuf &s)
std::ostream & CurrentException(std::ostream &os)
prints active (i.e., thrown but not yet handled) exception
void host(const char *src)
static void Start(const Pointer &job)
char * PasswdGet(Mgr::ActionPasswordList *, const char *)
const char * ActionProtection(const Mgr::ActionProfilePointer &profile)
static void PutCommonResponseHeaders(HttpReply &, const char *httpOrigin)
Mgr::ActionProfilePointer findAction(char const *action) const
void ParseHeaders(const HttpRequest *request, Mgr::ActionParams ¶ms)
Mgr::Action::Pointer createRequestedAction(const Mgr::ActionParams &)
static CacheManager * GetInstance()
int CheckPassword(const Mgr::Command &cmd)
void registerProfile(const Mgr::ActionProfilePointer &)
remembers the given profile while ignoring attempts to register a same-name duplicate
static const SBuf & WellKnownUrlPathPrefix()
initial URL path characters that identify cache manager requests
Mgr::Action::Pointer createNamedAction(const char *actionName)
CacheManager()
use Instance() instead
Mgr::CommandPointer ParseUrl(const AnyP::Uri &)
void start(const Comm::ConnectionPointer &client, HttpRequest *request, StoreEntry *entry, const AccessLogEntryPointer &ale)
optimized set of C chars, with quick membership test and merge support
CharacterSet complement(const char *complementLabel=nullptr) const
HttpReply * BuildHttpReply(void)
const char * content() const
void noCache(const String &v)
Http::MethodType id() const
AnyP::Uri url
the request URI
void putCc(const HttpHdrCc &)
void set(const AnyP::ProtocolVersion &newVersion, Http::StatusCode newStatus, const char *newReason=nullptr)
Cache Manager Action parameters extracted from the user request.
String userName
user login name; currently only used for logging
String password
user password; used for acceptance check and cleared
String actionName
action name (and credentials realm)
RequestFlags httpFlags
HTTP request flags.
HttpRequestMethod httpMethod
HTTP request method.
list of cachemgr password authorization definitions. Currently a POD.
ActionPasswordList * next
combined hard-coded action profile with user-supplied action parameters
ActionParams params
user-supplied action arguments
ActionProfilePointer profile
hard-coded action specification
static void Parse(Parser::Tokenizer &, QueryParams &)
parses the query string parameters
static const size_type npos
Mgr::ActionPasswordList * passwd_list
void replaceHttpReply(const HttpReplyPointer &, const bool andStartWriting=true)
char const * termedBuf() const
an std::runtime_error with thrower location info
#define debugs(SECTION, LEVEL, CONTENT)
@ ERR_CACHE_MGR_ACCESS_DENIED
void errorAppendEntry(StoreEntry *entry, ErrorState *err)
AnyP::ProtocolVersion ProtocolVersion()
RefCount< ActionProfile > ActionProfilePointer
void RegisterBasics()
Registers profiles for the actions above; TODO: move elsewhere?
SBuf ToSBuf(Args &&... args)
slowly stream-prints all arguments into a freshly allocated SBuf