From: Amos Jeffries Date: Fri, 30 Dec 2011 16:01:37 +0000 (+1300) Subject: Cache Manager migration support X-Git-Tag: BumpSslServerFirst.take05~12^2~100 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b073fc4bde37d3b0dd2f820f90c801d7dada1338;p=thirdparty%2Fsquid.git Cache Manager migration support * Add a little bit of XHR script to the CGI cachemgr front page which probes each of the managed proxies for http:// and https:// capabilities and produces web links to their internal managers. * Reserve the template name MGR_INDEX for use by cachemgr scripts. But do not distribute any preset template. This allows manager apps to provide their own static template with linked scripts and objects. * The error page system is updated to create a blanket message indicating missing template instead of aborting Squid if a template is not even installed. --- diff --git a/src/cache_manager.cc b/src/cache_manager.cc index 49535b29d7..88f195786c 100644 --- a/src/cache_manager.cc +++ b/src/cache_manager.cc @@ -203,7 +203,7 @@ CacheManager::ParseUrl(const char *url) 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); #if _SQUID_OS2_ if (t == 2 && request[0] == '\0') { @@ -211,7 +211,7 @@ CacheManager::ParseUrl(const char *url) * emx's sscanf insists of returning 2 because it sets request * to null */ - xstrncpy(request, "menu", MAX_URL); + xstrncpy(request, "index", MAX_URL); } #endif @@ -399,6 +399,26 @@ CacheManager::Start(const Comm::ConnectionPointer &client, HttpRequest * request 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)); diff --git a/src/err_type.h b/src/err_type.h index e919310c10..a8c28ae7ea 100644 --- a/src/err_type.h +++ b/src/err_type.h @@ -52,6 +52,9 @@ typedef enum { /* ICAP Errors */ ERR_ICAP_FAILURE, + /* Cache Manager */ + MGR_INDEX, + /* Squid problem */ ERR_GATEWAY_FAILURE, diff --git a/src/errorpage.cc b/src/errorpage.cc index 1197445c52..39e10c6c02 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -298,8 +298,11 @@ TemplateFile::loadDefault() } /* giving up if failed */ - if (!loaded()) - fatal("failed to find or read error text file."); + if (!loaded()) { + debugs(1, DBG_CRITICAL, "WARNING: failed to find or read error text file " << templateName); + parse("Internal Error: Missing Template ", 33, '\0'); + parse(templateName.termedBuf(), templateName.size(), '\0'); + } return true; } diff --git a/src/mgr/BasicActions.cc b/src/mgr/BasicActions.cc index f98a9c7251..1d0a8909a8 100644 --- a/src/mgr/BasicActions.cc +++ b/src/mgr/BasicActions.cc @@ -15,6 +15,23 @@ #include "Store.h" +Mgr::IndexAction::Pointer +Mgr::IndexAction::Create(const Command::Pointer &cmd) +{ + return new IndexAction(cmd); +} + +Mgr::IndexAction::IndexAction(const Command::Pointer &cmd): Action(cmd) +{ + debugs(16, 5, HERE); +} + +void +Mgr::IndexAction::dump(StoreEntry* entry) +{ + debugs(16, 5, HERE); +} + Mgr::MenuAction::Pointer Mgr::MenuAction::Create(const Command::Pointer &cmd) { @@ -128,9 +145,10 @@ Mgr::OfflineToggleAction::dump(StoreEntry* entry) void Mgr::RegisterBasics() { + RegisterAction("index", "Cache Manager Interface", &Mgr::IndexAction::Create, 0, 1); + RegisterAction("menu", "Cache Manager Menu", &Mgr::MenuAction::Create, 0, 1); RegisterAction("offline_toggle", "Toggle offline_mode setting", &Mgr::OfflineToggleAction::Create, 1, 1); RegisterAction("shutdown", "Shut Down the Squid Process", &Mgr::ShutdownAction::Create, 1, 1); RegisterAction("reconfigure", "Reconfigure Squid", &Mgr::ReconfigureAction::Create, 1, 1); RegisterAction("rotate", "Rotate Squid Logs", &Mgr::RotateAction::Create, 1, 1); - RegisterAction("menu", "Cache Manager Menu", &Mgr::MenuAction::Create, 0, 1); } diff --git a/src/mgr/BasicActions.h b/src/mgr/BasicActions.h index ffe8008579..495e5bff2b 100644 --- a/src/mgr/BasicActions.h +++ b/src/mgr/BasicActions.h @@ -16,6 +16,22 @@ namespace Mgr { +/// A dummy action placeholder for the no-action requests +/// a templated Cache Manager index ('home') page. +/// Display output is produced directly by the receiving worker +/// without invoking the co-ordinator or action Job. +class IndexAction: public Action +{ +public: + static Pointer Create(const CommandPointer &cmd); + /* Action API */ + virtual void dump(StoreEntry *entry); + +protected: + IndexAction(const CommandPointer &cmd); +}; + + /// returns available Cache Manager actions and their access requirements class MenuAction: public Action { diff --git a/tools/cachemgr.cc b/tools/cachemgr.cc index e8c7060b2a..a8c3930ee6 100644 --- a/tools/cachemgr.cc +++ b/tools/cachemgr.cc @@ -274,13 +274,40 @@ auth_html(const char *host, int port, const char *user_name) if (!host || !strlen(host)) host = ""; + fp = fopen("cachemgr.conf", "r"); + + if (fp == NULL) + fp = fopen(DEFAULT_CACHEMGR_CONFIG, "r"); + + if (fp == NULL) + printf("X-Error: message=\"Unable to open config %s\"", DEFAULT_CACHEMGR_CONFIG); + printf("Content-Type: text/html\r\n\r\n"); printf("\n"); printf("Cache Manager Interface\n"); - printf("\n"); + printf("\n"); + + printf("\n"); + + printf("\n"); printf("

Cache Manager Interface

\n"); @@ -290,16 +317,15 @@ auth_html(const char *host, int port, const char *user_name) printf("
\n"); + printf("
\n"); + printf("
\n"); + printf("
\n"); + printf("

CGI Managed Proxies

\n"); printf("
\n", script_name); printf("\n"); - fp = fopen("cachemgr.conf", "r"); - - if (fp == NULL) - fp = fopen(DEFAULT_CACHEMGR_CONFIG, "r"); - if (fp != NULL) { int servers = 0; char config_line[BUFSIZ]; @@ -331,9 +357,8 @@ auth_html(const char *host, int port, const char *user_name) if (!comment || !*comment) comment = server; - if (!servers) { - printf("
Cache Server:
Cache Server:\n"); - printf("\n"); + printf("\n"); + + printf("\n"); print_trailer(); }