You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Rob Hartill <ro...@imdb.com> on 1996/07/03 19:20:43 UTC
Re: NO BUG --- Proxy-Enhancement
Hi,
thanks. I'll pass this on to our proxy guru for consideration in
Apache 1.2 (1.1 will be released very soon)
regards,
rob
>I'm configuring a "communication server" to be distributed to schools
>in Germany. We are urgently in need of a Proxy-Server which may be
>configured not to forward requests to certain sites.
>(*porn*, *sex*, ...). I was asked to use the apache proxy who
>apparently lacks this feature. (Maybe I overlooked somethin in the
>docu.)
>
>I therfore changed mod_proxy.c to add a `ProcyDeny'-Directive
>where you may enter regular expressions which are DECLINED.
>I don't know if the proposed change fits your coding style and quality
>standard and I have no idea of it's impact on performance but here it is:
>--
>Mit freundlichen Gruessen Klaus M. Fueller, Kassel
>http://www.osgo.ks.he.schule.de/~klausf
>
>*** mod_proxy.c.orig Wed Jul 3 11:06:01 1996
>--- mod_proxy.c Wed Jul 3 14:48:36 1996
>***************
>*** 92,97 ****
>--- 92,98 ----
> #include "http_log.h"
> #include "http_main.h"
> #include "http_protocol.h"
>+ #include "regex.h"
>
> #include "md5.h"
>
>***************
>*** 140,145 ****
>--- 141,154 ----
> int port; /* the port for this proxy */
> };
>
>+ struct proxy_deny {
>+ char *deny;
>+ };
>+
>+ static struct re_pattern_buffer * reg;
>+ static char translate[256];
>+ static reg_broken;
>+
> struct proxy_alias {
> char *real;
> char *fake;
>***************
>*** 174,179 ****
>--- 183,189 ----
> array_header *proxies;
> array_header *aliases;
> array_header *nocaches;
>+ array_header *denies;
> int req; /* true if proxy requests are enabled */
> } proxy_server_conf;
>
>***************
>*** 231,236 ****
>--- 241,250 ----
>
> static BUFF *cache_error(struct cache_req *r);
>
>+ static void
>+ log_uerror(const char *routine, const char *file, const char *err,
>+ server_rec *s);
>+
> /* -------------------------------------------------------------- */
> /* Translate the URL into a 'filename' */
>
>***************
>*** 280,286 ****
>--- 294,353 ----
>
> if (r->proxyreq)
> {
>+ int i, len;
>+ char *pat, *p;
> if (!conf->req) return DECLINED;
>+
>+ if (! conf->denies->nelts)
>+ reg_broken=1;
>+ /* Do the denies. */
>+ if (! reg && ! reg_broken) {
>+ /* The first time compile the Deny-Strings. */
>+
>+ struct proxy_deny *ent=(struct proxy_deny *)conf->denies->elts;
>+ char const *cp;
>+
>+ if (! (reg=malloc(sizeof(struct re_pattern_buffer))))
>+ return DECLINED;
>+ for (i=0; i<256; )
>+ translate[i++]=i;
>+ for (i='A'; i<='Z'; ++i)
>+ translate[i] = i - 'A' + 'a';
>+ reg->buffer=malloc(1000);
>+ reg->allocated = 1000;
>+ reg->fastmap=NULL;
>+ reg->translate=translate;
>+ for (i=0, len=0; i < conf->denies->nelts; i++) {
>+ len += (strlen(ent[i].deny)+3);
>+ }
>+ if (! (pat=malloc(len+10)))
>+ return DECLINED;
>+ p=pat;
>+ strcpy(p, ".*\\("); p+=strlen(p);
>+ for (i=0; i < conf->denies->nelts; i++) {
>+ strcpy(p, ent[i].deny);
>+ p += strlen(p);
>+ *p++='\\';
>+ *p++='|';
>+ }
>+ p-=2;
>+ strcpy(p, "\\)");
>+ if (cp=re_compile_pattern(pat, strlen(pat), reg)) {
>+ log_uerror("re_compile", NULL, cp, r->server);
>+ free(pat);
>+ free(reg);
>+ reg=NULL;
>+ reg_broken=1;
>+ return DECLINED;
>+ }
>+ free(pat);
>+ }
>+ if (reg && ! reg_broken) {
>+ if (re_match(reg, r->uri, strlen(r->uri), 0, 0) > 0) {
>+ /* log_uerror("Deny", NULL, r->uri, r->server); */
>+ return DECLINED;
>+ }
>+ }
>
> r->filename = pstrcat(r->pool, "proxy:", r->uri, NULL);
> r->handler = "proxy-server";
>***************
>*** 3006,3011 ****
>--- 3073,3079 ----
>
> ps->proxies = make_array(p, 10, sizeof(struct proxy_remote));
> ps->aliases = make_array(p, 10, sizeof(struct proxy_alias));
>+ ps->denies = make_array(p, 10, sizeof(struct proxy_deny));
> ps->nocaches = make_array(p, 10, sizeof(struct nocache_entry));
> ps->req = 0;
>
>***************
>*** 3076,3081 ****
>--- 3144,3166 ----
> return NULL;
> }
>
>+
>+ static char *
>+ add_deny(cmd_parms *cmd, void *dummy, char *f)
>+ {
>+ char *cp;
>+ server_rec *s = cmd->server;
>+ proxy_server_conf *conf =
>+ (proxy_server_conf *)get_module_config(s->module_config,&proxy_module);
>+ struct proxy_deny *new;
>+
>+ new = push_array (conf->denies);
>+ new->deny = f;
>+ for (cp=new->deny; *cp; ++cp)
>+ tolower(*cp);
>+ return NULL;
>+ }
>+
> static char *
> set_proxy_req(cmd_parms *parms, void *dummy, int flag)
> {
>***************
>*** 3216,3221 ****
>--- 3301,3308 ----
> "a scheme, partial URL or '*' and a proxy server"},
> { "ProxyPass", add_pass, NULL, RSRC_CONF, TAKE2,
> "a virtual path and a URL"},
>+ { "ProxyDeny", add_deny, NULL, RSRC_CONF, TAKE1,
>+ "an URL which is not served over the proxy"},
> { "CacheRoot", set_cache_root, NULL, RSRC_CONF, TAKE1,
> "The directory to store cache files"},
> { "CacheSize", set_cache_size, NULL, RSRC_CONF, TAKE1,
--
Rob Hartill (robh@imdb.com)
The Internet Movie Database (IMDb) http://www.imdb.com/
...more movie info than you can poke a stick at.