This 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.
For the produced links to be usable when viewed from a browser the
http[s]://*/squid-internal-mgr/ URLs should also be updated to produce
an HTML snippet bootstraping a manager viewer such as the javascript one
Kinkie was working on a few months ago. The current situation in 3.2
just links to the plain-text manager menu, which is a bit unfriendly. I
am expecting that we will be able to complete that small update and get
the internal manager a bit more polished before squid-3.3 is released.
So am optimistically targeting the detection in this patch to produce
links for 3.3 and later releases (including 3.HEAD).
This depends loosely on the CORS patch I submitted earlier. Squid which
do not emit the CORS headers are unlikely to pass the XHR scan (a good
thing).
Amos
=== modified file 'tools/cachemgr.cc'
--- tools/cachemgr.cc 2011-07-23 08:37:52 +0000
+++ tools/cachemgr.cc 2011-12-23 13:55:14 +0000
@@ -280,7 +280,26 @@
printf("<HTML><HEAD><TITLE>Cache Manager Interface</TITLE>\n");
- printf("<STYLE
type=\"text/css\"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}--></STYLE></HEAD>\n");
+ printf("<STYLE
type=\"text/css\"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}--></STYLE>\n");
+
+ printf("<script type=\"text/javascript\">\n");
+ printf("function TS(t, s) {\n");
+ printf(" var x = new XMLHttpRequest();\n");
+ printf(" x.open('GET', 'http' + s + '://' + t + '/squid-internal-mgr/',
true);\n");
+ printf(" x.onreadystatechange=function() {\n");
+ printf(" if (x.readyState==4) {\n");
+ printf(" if ((x.status>=200 && x.status <= 299) || x.status==401) {\n");
+ printf(" var v = x.getResponseHeader('Server');\n");
+ printf(" if (v.substring(0,8) == 'squid/3.' && (v[8]=='H' ||
parseInt(v.substring(8)) >= 3)) {\n");
+ printf(" var d = document.getElementById('H' + s + 'mgr');\n");
+ printf(" if (d.innerHTML == '') d.innerHTML = '<h2>HTTP' +
(s=='s'?'S':'') + ' Managed Proxies</h2>';\n");
+ printf(" d.innerHTML = d.innerHTML + '<p>Host: <a href=\"http' + s +
'://' + t + '/squid-internal-mgr/\">' + t + '</a></p>';\n");
+ printf(" }}}}\n");
+ printf(" x.send(null);\n");
+ printf("}\n");
+ printf("</script>\n");
+
+ printf("</HEAD>\n");
printf("<BODY><H1>Cache Manager Interface</H1>\n");
@@ -290,6 +309,10 @@
printf("<HR noshade size=\"1px\">\n");
+ printf("<div id=\"Hsmgr\"></div>\n");
+ printf("<div id=\"Hmgr\"></div>\n");
+ printf("<div id=\"Cmgr\">\n");
+ printf("<h2>CGI Managed Proxies</h2>\n");
printf("<FORM METHOD=\"POST\" ACTION=\"%s\">\n", script_name);
printf("<TABLE BORDER=\"0\" CELLPADDING=\"10\" CELLSPACING=\"1\">\n");
@@ -331,9 +354,8 @@
if (!comment || !*comment)
comment = server;
- if (!servers) {
- printf("<TR><TH ALIGN=\"left\">Cache Server:</TH><TD><SELECT
NAME=\"server\">\n");
- }
+ if (!servers)
+ printf("<TR><TH ALIGN=\"left\">Cache Server:</TH><TD><SELECT
id=\"server\" NAME=\"server\">\n");
printf("<OPTION VALUE=\"%s\"%s>%s</OPTION>\n", server, (servers ||
*host) ? "" : " SELECTED", comment);
servers++;
@@ -377,7 +399,14 @@
printf("<INPUT TYPE=\"submit\" VALUE=\"Continue...\">\n");
- printf("</FORM>\n");
+ printf("</FORM></div>\n");
+
+ printf("<script type=\"text/javascript\">\n");
+ printf("var s = document.getElementById(\"server\");\n");
+ printf("for (var i = 0; i < s.childElementCount; i++) {\n");
+ printf(" TS(s.children[i].value, '');\n");
+ printf(" TS(s.children[i].value, 's');\n");
+ printf("}</script>\n");
print_trailer();
}