#
# Makefile for the Squid Object Cache server
#
-# $Id: Makefile.am,v 1.107 2005/04/06 19:07:03 serassio Exp $
+# $Id: Makefile.am,v 1.108 2005/04/23 20:40:50 serassio Exp $
#
# Uncomment and customize the following to suit your needs:
#
cf_gen.$(OBJEXT): cf_gen_defines.h
squidclient_SOURCES = client.cc
cachemgr__CGIEXT__SOURCES = cachemgr.cc
+cachemgr__CGIEXT__CFLAGS = -DDEFAULT_CACHEMGR_CONFIG=\"$(DEFAULT_CACHEMGR_CONFIG)\" $(AM_CFLAGS)
all_FSMODULES = \
fs/aufs/StoreFSaufs.cc \
mk-string-arrays.pl \
repl_modules.sh \
mib.txt \
+ cachemgr.conf \
mime.conf.default
libAIO_a_SOURCES = \
DEFAULT_PREFIX = $(prefix)
DEFAULT_CONFIG_FILE = $(sysconfdir)/squid.conf
+DEFAULT_CACHEMGR_CONFIG = $(sysconfdir)/cachemgr.conf
DEFAULT_MIME_TABLE = $(sysconfdir)/mime.conf
DEFAULT_DNSSERVER = $(libexecdir)/`echo dnsserver | sed '$(transform);s/$$/$(EXEEXT)/'`
DEFAULT_LOG_PREFIX = $(localstatedir)/logs
echo "$(INSTALL_DATA) squid.conf.default $(DESTDIR)$(DEFAULT_CONFIG_FILE)"; \
$(INSTALL_DATA) squid.conf.default $(DESTDIR)$(DEFAULT_CONFIG_FILE); \
fi
+ @if test -f $(DESTDIR)$(DEFAULT_CACHEMGR_CONFIG) ; then \
+ echo "$@ will not overwrite existing $(DESTDIR)$(DEFAULT_CACHEMGR_CONFIG)" ; \
+ else \
+ echo "$(INSTALL_DATA) $(srcdir)/cachemgr.conf $(DESTDIR)$(DEFAULT_CACHEMGR_CONFIG)"; \
+ $(INSTALL_DATA) $(srcdir)/cachemgr.conf $(DESTDIR)$(DEFAULT_CACHEMGR_CONFIG); \
+ fi
$(mkinstalldirs) $(DESTDIR)$(DEFAULT_LOG_PREFIX)
uninstall-local:
/*
- * $Id: cachemgr.cc,v 1.108 2005/04/18 21:52:42 hno Exp $
+ * $Id: cachemgr.cc,v 1.109 2005/04/23 20:40:51 serassio Exp $
*
* DEBUG: section 0 CGI Cache Manager
* AUTHOR: Duane Wessels
#if HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
+#if HAVE_FNMATCH_H
+#include <fnmatch.h>
+#endif
#include <assert.h>
#include "util.h"
#include "snprintf.h"
+#ifndef DEFAULT_CACHEMGR_CONFIG
+#define DEFAULT_CACHEMGR_CONFIG "/etc/squid/cahemgr.conf"
+#endif
+
typedef struct
{
+ char *server;
char *hostname;
int port;
char *action;
static void reset_auth(cachemgr_request * req);
static const char *make_auth_header(const cachemgr_request * req);
+static int check_target_acl(const char *hostname, int port);
+
#ifdef _SQUID_MSWIN_
static int s_iInitCount = 0;
int Win32SockInit(void)
static void
auth_html(const char *host, int port, const char *user_name)
{
+ FILE *fp;
+ int need_host = 1;
+
if (!user_name)
user_name = "";
if (!host || !strlen(host))
- host = "localhost";
+ host = "";
printf("Content-Type: text/html\r\n\r\n");
printf("<TABLE BORDER=\"0\" CELLPADDING=\"10\" CELLSPACING=\"1\">\n");
- printf("<TR><TH ALIGN=\"left\">Cache Host:</TH><TD><INPUT NAME=\"host\" ");
- printf("size=\"30\" VALUE=\"%s\"></TD></TR>\n", host);
+ fp = fopen("cachemgr.conf", "r");
+
+ if (fp == NULL)
+ fp = fopen(DEFAULT_CACHEMGR_CONFIG, "r");
+
+ if (fp != NULL) {
+ int servers = 0;
+ char config_line[BUFSIZ];
+
+ while (fgets(config_line, BUFSIZ, fp)) {
+ char *server, *comment;
+ strtok(config_line, "\r\n");
+
+ if (config_line[0] == '#')
+ continue;
+
+ if (config_line[0] == '\0')
+ continue;
+
+ if ((server = strtok(config_line, " \t")) == NULL)
+ continue;
+
+ if (strchr(server, '*') || strchr(server, '[') || strchr(server, '?')) {
+ need_host = -1;
+ continue;
+ }
+
+ comment = strtok(NULL, "");
+
+ if (comment)
+ while (*comment == ' ' || *comment == '\t')
+ comment++;
+
+ if (!comment || !*comment)
+ comment = server;
+
+ if (!servers) {
+ printf("<TR><TH ALIGN=\"left\">Cache Server:</TH><TD><SELECT NAME=\"server\">\n");
+ }
+
+ printf("<OPTION VALUE=\"%s\"%s>%s</OPTION>\n", server, (servers || *host) ? "" : " SELECTED", comment);
+ servers++;
+ }
+
+ if (servers) {
+ if (need_host == 1 && !*host)
+ need_host = 0;
+
+ if (need_host)
+ printf("<OPTION VALUE=\"\"%s>Other</OPTION>\n", (*host) ? " SELECTED" : "");
+
+ printf("</SELECT></TR>\n");
+ }
+
+ fclose(fp);
+ }
+
+ if (need_host) {
+ if (need_host == 1 && !*host)
+ host = "localhost";
+
+ printf("<TR><TH ALIGN=\"left\">Cache Host:</TH><TD><INPUT NAME=\"host\" ");
- printf("<TR><TH ALIGN=\"left\">Cache Port:</TH><TD><INPUT NAME=\"port\" ");
+ printf("size=\"30\" VALUE=\"%s\"></TD></TR>\n", host);
- printf("size=\"30\" VALUE=\"%d\"></TD></TR>\n", port);
+ printf("<TR><TH ALIGN=\"left\">Cache Port:</TH><TD><INPUT NAME=\"port\" ");
+
+ printf("size=\"30\" VALUE=\"%d\"></TD></TR>\n", port);
+ }
printf("<TR><TH ALIGN=\"left\">Manager name:</TH><TD><INPUT NAME=\"user_name\" ");
req->action = xstrdup("");
}
- if (!strcmp(req->action, "authenticate")) {
+ if (strcmp(req->action, "authenticate") == 0) {
auth_html(req->hostname, req->port, req->user_name);
return 0;
}
+ if (!check_target_acl(req->hostname, req->port)) {
+ snprintf(buf, 1024, "target %s:%d not allowed in cachemgr.conf\n", req->hostname, req->port);
+ error_html(buf);
+ return 1;
+ }
+
if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
snprintf(buf, 1024, "socket: %s\n", xstrerror());
error_html(buf);
*q++ = '\0';
- if (0 == strcasecmp(t, "host") && strlen(q))
+ rfc1738_unescape(t);
+
+ rfc1738_unescape(q);
+
+ if (0 == strcasecmp(t, "server") && strlen(q))
+ req->server = xstrdup(q);
+ else if (0 == strcasecmp(t, "host") && strlen(q))
req->hostname = xstrdup(q);
else if (0 == strcasecmp(t, "port") && strlen(q))
req->port = atoi(q);
req->action = xstrdup(q);
}
+ if (req->server && !req->hostname) {
+ char *p;
+ req->hostname = strtok(req->server, ":");
+
+ if ((p = strtok(NULL, ":")))
+ req->port = atoi(p);
+ }
+
make_pub_auth(req);
debug(1) fprintf(stderr, "cmgr: got req: host: '%s' port: %d uname: '%s' passwd: '%s' auth: '%s' oper: '%s'\n",
safe_str(req->hostname), req->port, safe_str(req->user_name), safe_str(req->passwd), safe_str(req->pub_auth), safe_str(req->action));
return buf;
}
+
+static int
+check_target_acl(const char *hostname, int port) {
+ char config_line[BUFSIZ];
+ FILE *fp = NULL;
+ int ret = 0;
+ fp = fopen("cachemgr.conf", "r");
+
+ if (fp == NULL)
+ fp = fopen(DEFAULT_CACHEMGR_CONFIG, "r");
+
+ if (fp == NULL) {
+#ifdef CACHEMGR_HOSTNAME_DEFINED
+
+ if (strcmp(hostname, CACHEMGR_HOSTNAME) == 0 && port == CACHE_HTTP_PORT)
+ return 1;
+
+#else
+
+ if (strcmp(hostname, "localhost") == 0)
+ return 1;
+
+ if (strcmp(hostname, getfullhostname()) == 0)
+ return 1;
+
+#endif
+
+ return 0;
+ }
+
+ while (fgets(config_line, BUFSIZ, fp)) {
+ char *token = NULL;
+ strtok(config_line, " \r\n\t");
+
+ if (config_line[0] == '#')
+ continue;
+
+ if (config_line[0] == '\0')
+ continue;
+
+ if ((token = strtok(config_line, ":")) == NULL)
+ continue;
+
+#if HAVE_FNMATCH_H
+
+ if (fnmatch(token, hostname, 0) != 0)
+ continue;
+
+#else
+
+ if (strcmp(token, hostname) != 0)
+ continue;
+
+#endif
+
+ if ((token = strtok(NULL, ":")) != NULL) {
+ int i;
+
+ if (sscanf(token, "%d", &i) != 1)
+ continue;
+
+ if (i != port)
+ continue;
+ } else if (port != CACHE_HTTP_PORT)
+ continue;
+
+ ret = 1;
+
+ break;
+ }
+
+ fclose(fp);
+ return ret;
+}