*
*/
-#include "config.h"
+#include "squid.h"
#include "base/TextException.h"
#include "CacheManager.h"
#include "comm/Connection.h"
int len = strlen(url);
Must(len > 0);
t = sscanf(url, "cache_object://%[^/]/%[^@?]%n@%[^?]?%s", host, request, &pos, password, params);
-
- if (pos >0 && url[pos] == '?') {
- ++pos;
- if (pos < len)
- xstrncpy(params, url + pos, sizeof(params));
+ if (t < 3) {
+ t = sscanf(url, "cache_object://%[^/]/%[^?]%n?%s", host, request, &pos, params);
+ }
+ if (t < 1) {
+ t = sscanf(url, "http://%[^/]/squid-internal-mgr/%[^?]%n?%s", host, request, &pos, params);
+ }
+ if (t < 1) {
+ t = sscanf(url, "https://%[^/]/squid-internal-mgr/%[^?]%n?%s", host, request, &pos, params);
}
-
if (t < 2)
- xstrncpy(request, "menu", MAX_URL);
+ xstrncpy(request, "index", MAX_URL);
-#ifdef _SQUID_OS2_
+#if _SQUID_OS2_
if (t == 2 && request[0] == '\0') {
/*
* emx's sscanf insists of returning 2 because it sets request
* to null
*/
- xstrncpy(request, "menu", MAX_URL);
+ xstrncpy(request, "index", MAX_URL);
}
#endif
+ debugs(16, 3, HERE << "MGR request: t=" << t << ", host='" << host << "', request='" << request << "', pos=" << pos <<
+ ", password='" << password << "', params='" << params << "'");
+
Mgr::ActionProfile::Pointer profile = findAction(request);
if (!profile) {
debugs(16, DBG_IMPORTANT, "CacheManager::ParseUrl: action '" << request << "' not found");
void
CacheManager::Start(const Comm::ConnectionPointer &client, HttpRequest * request, StoreEntry * entry)
{
- ErrorState *err = NULL;
debugs(16, 3, "CacheManager::Start: '" << entry->url() << "'" );
Mgr::Command::Pointer cmd = ParseUrl(entry->url());
if (!cmd) {
- err = errorCon(ERR_INVALID_URL, HTTP_NOT_FOUND, request);
+ ErrorState *err = new ErrorState(ERR_INVALID_URL, HTTP_NOT_FOUND, request);
err->url = xstrdup(entry->url());
errorAppendEntry(entry, err);
entry->expires = squid_curtime;
if (CheckPassword(*cmd) != 0) {
/* build error message */
- ErrorState *errState;
- HttpReply *rep;
- errState = errorCon(ERR_CACHE_MGR_ACCESS_DENIED, HTTP_UNAUTHORIZED, request);
+ ErrorState errState(ERR_CACHE_MGR_ACCESS_DENIED, HTTP_UNAUTHORIZED, request);
/* warn if user specified incorrect password */
if (cmd->params.password.size()) {
actionName << "'" );
}
- rep = errState->BuildHttpReply();
-
- errorStateFree(errState);
+ HttpReply *rep = errState.BuildHttpReply();
#if HAVE_AUTH_MODULE_BASIC
/*
*/
rep->header.putAuth("Basic", actionName);
#endif
+ // Allow cachemgr and other XHR scripts access to our version string
+ if (request->header.has(HDR_ORIGIN)) {
+ rep->header.putExt("Access-Control-Allow-Origin",request->header.getStr(HDR_ORIGIN));
+#if HAVE_AUTH_MODULE_BASIC
+ rep->header.putExt("Access-Control-Allow-Credentials","true");
+#endif
+ rep->header.putExt("Access-Control-Expose-Headers","Server");
+ }
/* store the reply */
entry->replaceHttpReply(rep);
return;
}
+ if (request->header.has(HDR_ORIGIN)) {
+ cmd->params.httpOrigin = request->header.getStr(HDR_ORIGIN);
+ }
+
debugs(16, 2, "CacheManager: " <<
userName << "@" <<
client << " requesting '" <<
actionName << "'" );
+ // special case: /squid-internal-mgr/ index page
+ if (!strcmp(cmd->profile->name, "index")) {
+ ErrorState err(MGR_INDEX, HTTP_OK, request);
+ err.url = xstrdup(entry->url());
+ HttpReply *rep = err.BuildHttpReply();
+ if (strncmp(rep->body.content(),"Internal Error:", 15) == 0)
+ rep->sline.status = HTTP_NOT_FOUND;
+ // Allow cachemgr and other XHR scripts access to our version string
+ if (request->header.has(HDR_ORIGIN)) {
+ rep->header.putExt("Access-Control-Allow-Origin",request->header.getStr(HDR_ORIGIN));
+#if HAVE_AUTH_MODULE_BASIC
+ rep->header.putExt("Access-Control-Allow-Credentials","true");
+#endif
+ rep->header.putExt("Access-Control-Expose-Headers","Server");
+ }
+ entry->replaceHttpReply(rep);
+ entry->complete();
+ return;
+ }
+
if (UsingSmp() && IamWorkerProcess()) {
// is client the right connection to pass here?
AsyncJob::Start(new Mgr::Forwarder(client, cmd->params, request, entry));