1 const char filters_rcs[] = "$Id: filters.c,v 1.3 2001/05/20 16:44:47 jongfoster Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/filters.c,v $
6 * Purpose : Declares functions to parse/crunch headers and pages.
7 * Functions declared include:
8 * `acl_addr', `add_stats', `block_acl', `block_imageurl',
9 * `block_url', `url_permissions', `domaincmp', `dsplit',
10 * `filter_popups', `forward_url', 'redirect_url',
11 * `ij_untrusted_url', `intercept_url', `re_process_buffer',
12 * `show_proxy_args', 'ijb_send_banner', and `trust_url'
14 * Copyright : Written by and Copyright (C) 2001 the SourceForge
15 * IJBSWA team. http://ijbswa.sourceforge.net
17 * Based on the Internet Junkbuster originally written
18 * by and Copyright (C) 1997 Anonymous Coders and
19 * Junkbusters Corporation. http://www.junkbusters.com
21 * This program is free software; you can redistribute it
22 * and/or modify it under the terms of the GNU General
23 * Public License as published by the Free Software
24 * Foundation; either version 2 of the License, or (at
25 * your option) any later version.
27 * This program is distributed in the hope that it will
28 * be useful, but WITHOUT ANY WARRANTY; without even the
29 * implied warranty of MERCHANTABILITY or FITNESS FOR A
30 * PARTICULAR PURPOSE. See the GNU General Public
31 * License for more details.
33 * The GNU General Public License should be included with
34 * this file. If not, you can view it at
35 * http://www.gnu.org/copyleft/gpl.html
36 * or write to the Free Software Foundation, Inc., 59
37 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
41 * Revision 1.3 2001/05/20 16:44:47 jongfoster
42 * Removing last hardcoded JunkBusters.com URLs.
44 * Revision 1.2 2001/05/20 01:21:20 jongfoster
45 * Version 2.9.4 checkin.
46 * - Merged popupfile and cookiefile, and added control over PCRS
47 * filtering, in new "permissionsfile".
48 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
49 * file error you now get a message box (in the Win32 GUI) rather
50 * than the program exiting with no explanation.
51 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
53 * - Removed tabs from "config"
54 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
55 * - Bumped up version number.
57 * Revision 1.1.1.1 2001/05/15 13:58:52 oes
58 * Initial import of version 2.9.3 source tree
61 *********************************************************************/
67 #include <sys/types.h>
74 #include <netinet/in.h>
87 #include "jbsockets.h"
89 #include "jbsockets.h"
95 const char filters_h_rcs[] = FILTERS_H_VERSION;
97 /* Fix a problem with Solaris. There should be no effect on other
99 * Solaris's isspace() is a macro which uses it's argument directly
100 * as an array index. Therefore we need to make sure that high-bit
101 * characters generate +ve values, and ideally we also want to make
102 * the argument match the declared parameter type of "int".
104 #define ijb_isdigit(__X) isdigit((int)(unsigned char)(__X))
107 static const char CBLOCK[] =
109 "HTTP/1.0 403 Request for blocked URL\n"
110 #else /* ifndef AMIGA */
111 "HTTP/1.0 202 Request for blocked URL\n"
112 #endif /* ndef AMIGA */
114 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\n"
115 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\n"
116 "Content-Type: text/html\n\n"
119 "<title>Internet Junkbuster: Request for blocked URL</title>\n"
125 "<p align=center>Your request for <b>%s%s</b><br>\n"
126 "was blocked because it matches the following pattern "
127 "in the blockfile: <b>%s</b>\n</p>"
129 "<p align=center><a href=\"http://%s" FORCE_PREFIX
130 "%s\">Go there anyway.</a></p>"
131 #endif /* def FORCE_LOAD */
136 static const char CTRUST[] =
138 "HTTP/1.0 403 Request for untrusted URL\n"
139 #else /* ifndef AMIGA */
140 "HTTP/1.0 202 Request for untrusted URL\n"
141 #endif /* ndef AMIGA */
143 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\n"
144 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\n"
145 "Content-Type: text/html\n\n"
148 "<title>Internet Junkbuster: Request for untrusted URL</title>\n"
152 "<a href=http://internet.junkbuster.com/ij-untrusted-url?%s+%s+%s>"
158 #endif /* def TRUST_FILES */
162 /*********************************************************************
164 * Function : block_acl
166 * Description : Block this request?
167 * Decide yes or no based on ACL file.
170 * 1 : src = Address the browser/user agent is requesting.
171 * 2 : dst = The proxy or gateway address this is going to.
172 * 3 : csp = Current client state (buffers, headers, etc...)
174 * Returns : 0 = FALSE (don't block) and 1 = TRUE (do block)
176 *********************************************************************/
177 int block_acl(struct access_control_addr *src, struct access_control_addr *dst, struct client_state *csp)
179 struct file_list *fl;
180 struct access_control_list *a, *acl;
181 struct access_control_addr s[1], d[1];
183 /* if not using an access control list, then permit the connection */
184 if (((fl = csp->alist) == NULL) || ((acl = fl->f) == NULL))
189 /* search the list */
190 for (a = acl->next ; a ; a = a->next)
195 s->addr &= a->src->mask;
196 d->addr &= a->dst->mask;
198 if ((s->addr == a->src->addr)
199 && (d->addr == a->dst->addr)
200 && ((s->port == a->src->port)
202 || (a->src->port == 0))
203 && ((d->port == a->dst->port)
205 || (a->dst->port == 0)))
207 if (a->action == ACL_PERMIT)
223 /*********************************************************************
225 * Function : acl_addr
227 * Description : Called from `load_aclfile'. FIXME: I can't say more.
230 * 1 : aspec = (what?)
233 * Returns : 0 => Ok, everything else is an error.
235 *********************************************************************/
236 int acl_addr(char *aspec, struct access_control_addr *aca)
238 int i, masklength, port;
244 if ((p = strchr(aspec, '/')))
248 if (ijb_isdigit(*p) == 0)
252 masklength = atoi(p);
255 if ((masklength < 0) || (masklength > 32))
260 if ((p = strchr(aspec, ':')))
264 if (ijb_isdigit(*p) == 0)
273 aca->addr = ntohl(resolve_hostname_to_ip(aspec));
277 log_error(LOG_LEVEL_ERROR, "can't resolve address for %s", aspec);
281 /* build the netmask */
283 for (i=1; i <= masklength ; i++)
285 aca->mask |= (1 << (32 - i));
288 /* now mask off the host portion of the ip address
289 * (i.e. save on the network portion of the address).
291 aca->addr = aca->addr & aca->mask;
296 #endif /* def ACL_FILES */
299 /*********************************************************************
301 * Function : block_url
303 * Description : Called from `chat'. Check to see if we need to block this.
306 * 1 : http = http_request request to "check" for blocked
307 * 2 : csp = Current client state (buffers, headers, etc...)
309 * Returns : NULL => unblocked, else string to HTML block description.
311 *********************************************************************/
312 char *block_url(struct http_request *http, struct client_state *csp)
314 struct file_list *fl;
315 struct block_spec *b;
316 struct url_spec url[1];
320 if (((fl = csp->blist) == NULL) || ((b = fl->f) == NULL))
325 *url = dsplit(http->host);
327 /* if splitting the domain fails, punt */
328 if (url->dbuf == NULL) return(NULL);
330 for (b = b->next; b ; b = b->next)
332 if ((b->url->port == 0) || (b->url->port == http->port))
334 if ((b->url->domain[0] == '\0') || (domaincmp(b->url, url) == 0))
336 if ((b->url->path == NULL) ||
338 (regexec(b->url->preg, http->path, 0, NULL, 0) == 0)
340 (strncmp(b->url->path, http->path, b->url->pathlen) == 0)
347 if (b->reject == 0) return(NULL);
350 n += strlen(http->hostport);
351 n += strlen(http->path);
352 n += strlen(b->url->spec);
354 n += strlen(http->hostport);
355 n += strlen(http->path);
356 #endif /* def FORCE_LOAD */
358 p = (char *)malloc(n);
361 sprintf(p, CBLOCK, http->hostport, http->path, b->url->spec, http->hostport, http->path);
363 sprintf(p, CBLOCK, http->hostport, http->path, b->url->spec);
364 #endif /* def FORCE_LOAD */
378 #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST)
379 /*********************************************************************
381 * Function : block_imageurl
383 * Description : Given a URL which is blocked, decide whether to
384 * send the "blocked" image or HTML.
387 * 1 : http = URL to check.
388 * 2 : csp = Current client state (buffers, headers, etc...)
390 * Returns : True (nonzero) if URL is in image list, false (0)
393 *********************************************************************/
394 int block_imageurl(struct http_request *http, struct client_state *csp)
396 #ifdef DETECT_MSIE_IMAGES
397 if ((csp->accept_types
398 & (ACCEPT_TYPE_IS_MSIE|ACCEPT_TYPE_MSIE_IMAGE|ACCEPT_TYPE_MSIE_HTML))
399 == (ACCEPT_TYPE_IS_MSIE|ACCEPT_TYPE_MSIE_IMAGE))
403 else if ((csp->accept_types
404 & (ACCEPT_TYPE_IS_MSIE|ACCEPT_TYPE_MSIE_IMAGE|ACCEPT_TYPE_MSIE_HTML))
405 == (ACCEPT_TYPE_IS_MSIE|ACCEPT_TYPE_MSIE_HTML))
411 #if defined(USE_IMAGE_LIST)
412 return block_imageurl_using_imagelist(http, csp);
414 /* Don't know - assume HTML */
418 #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */
421 #ifdef USE_IMAGE_LIST
422 /*********************************************************************
424 * Function : block_imageurl
426 * Description : Test if a URL is in the imagelist.
429 * 1 : http = URL to check.
430 * 2 : csp = Current client state (buffers, headers, etc...)
432 * Returns : True (nonzero) if URL is in image list, false (0)
435 *********************************************************************/
436 int block_imageurl_using_imagelist(struct http_request *http, struct client_state *csp)
438 struct file_list *fl;
439 struct block_spec *b;
440 struct url_spec url[1];
442 if (((fl = csp->ilist) == NULL) || ((b = fl->f) == NULL))
447 *url = dsplit(http->host);
449 /* if splitting the domain fails, punt */
450 if (url->dbuf == NULL) return(0);
452 for (b = b->next; b ; b = b->next)
455 if ((b->url->port == 0) || (b->url->port == http->port))
457 /* port matches, check domain */
458 if ((b->url->domain[0] == '\0') || (domaincmp(b->url, url) == 0))
460 /* domain matches, check path */
461 if ((b->url->path == NULL) ||
463 (regexec(b->url->preg, http->path, 0, NULL, 0) == 0)
465 (strncmp(b->url->path, http->path, b->url->pathlen) == 0)
473 if (b->reject == 0) return(0);
485 #endif /* def USE_IMAGE_LIST */
489 /*********************************************************************
491 * Function : re_process_buffer
493 * Description : Apply all jobs from the joblist (aka. Perl regexp's) to
494 * the text buffer that's been accumulated in csp->iob->buf.
495 * Then, write the modified buffer out to the client
496 * (Maybe this should happen from jcc.c via flush_socket
497 * for better readability).
500 * 1 : csp = Current client state (buffers, headers, etc...)
504 *********************************************************************/
505 void re_process_buffer(struct client_state *csp)
508 int size = csp->iob->eod - csp->iob->cur;
509 char *old=csp->iob->cur, *new = NULL;
510 pcrs_job *job, *joblist;
512 struct file_list *fl;
513 struct re_filterfile_spec *b;
515 /* Sanity first ;-) */
521 if ( ( NULL == (fl = csp->rlist) ) || ( NULL == (b = fl->f) ) )
523 log_error(LOG_LEVEL_ERROR, "Unable to get current state of regexp filtering.");
527 joblist = b->joblist;
530 log_error(LOG_LEVEL_RE_FILTER, "re_filtering %s%s (size %d) ...",
531 csp->http->hostport, csp->http->path, size);
533 /* Apply all jobs from the joblist */
534 for (job = joblist; NULL != job; job = job->next)
536 hits += pcrs_exec_substitution(job, old, size, &new, &size);
537 if (old != csp->iob->cur) free(old);
541 log_error(LOG_LEVEL_RE_FILTER, " produced %d hits (new size %d).", hits, size);
543 if (write_socket(csp->cfd, old, size) != size)
545 log_error(LOG_LEVEL_ERROR, "write to client failed.");
548 /* fwiw, reset the iob */
554 #endif /* def PCRS */
558 /*********************************************************************
560 * Function : trust_url
562 * Description : Should we "trust" this URL? See "trustfile" line in config.
565 * 1 : http = http_request request for requested URL
566 * 2 : csp = Current client state (buffers, headers, etc...)
568 * Returns : NULL => trusted, else string to HTML "untrusted" description.
570 *********************************************************************/
571 char *trust_url(struct http_request *http, struct client_state *csp)
573 struct file_list *fl;
574 struct block_spec *b;
575 struct url_spec url[1], **tl, *t;
577 char *hostport, *path, *refer;
578 struct http_request rhttp[1];
581 if (((fl = csp->tlist) == NULL) || ((b = fl->f) == NULL))
586 *url = dsplit(http->host);
588 /* if splitting the domain fails, punt */
589 if (url->dbuf == NULL) return(NULL);
591 memset(rhttp, '\0', sizeof(*rhttp));
593 for (b = b->next; b ; b = b->next)
595 if ((b->url->port == 0) || (b->url->port == http->port))
597 if ((b->url->domain[0] == '\0') || (domaincmp(b->url, url) == 0))
599 if ((b->url->path == NULL) ||
601 (regexec(b->url->preg, http->path, 0, NULL, 0) == 0)
603 (strncmp(b->url->path, http->path, b->url->pathlen) == 0)
610 if (b->reject == 0) return(NULL);
612 hostport = url_encode(http->hostport);
613 path = url_encode(http->path);
617 refer = url_encode(csp->referrer);
621 refer = url_encode("undefined");
625 n += strlen(hostport);
629 p = (char *)malloc(n);
631 sprintf(p, CTRUST, hostport, path, refer);
646 if ((csp->referrer == NULL)|| (strlen(csp->referrer) <= 9))
648 /* no referrer was supplied */
649 goto trust_url_not_trusted;
652 /* forge a URL from the referrer so we can use
653 * convert_url() to parse it into its components.
657 p = strsav(p, "GET ");
658 p = strsav(p, csp->referrer + 9); /* skip over "Referer: " */
659 p = strsav(p, " HTTP/1.0");
661 parse_http_request(p, rhttp, csp);
663 if (rhttp->cmd == NULL)
666 goto trust_url_not_trusted;
671 *url = dsplit(rhttp->host);
673 /* if splitting the domain fails, punt */
674 if (url->dbuf == NULL) goto trust_url_not_trusted;
676 for (tl = trust_list; (t = *tl) ; tl++)
678 if ((t->port == 0) || (t->port == rhttp->port))
680 if ((t->domain[0] == '\0') || domaincmp(t, url) == 0)
682 if ((t->path == NULL) ||
684 (regexec(t->preg, rhttp->path, 0, NULL, 0) == 0)
686 (strncmp(t->path, rhttp->path, t->pathlen) == 0)
690 /* if the URL's referrer is from a trusted referrer, then
691 * add the target spec to the trustfile as an unblocked
692 * domain and return NULL (which means it's OK).
700 if ((fp = fopen(trustfile, "a")))
705 h = strsav(h, http->hostport);
711 /* since this path points into a user's home space
712 * be sure to include this spec in the trustfile.
714 if ((p = strchr(p, '/')))
717 h = strsav(h, http->path);
722 free_http_request(rhttp);
724 fprintf(fp, "%s\n", h);
734 trust_url_not_trusted:
735 free_http_request(rhttp);
737 hostport = url_encode(http->hostport);
738 path = url_encode(http->path);
742 refer = url_encode(csp->referrer);
746 refer = url_encode("undefined");
750 n += strlen(hostport);
754 p = (char *)malloc(n);
755 sprintf(p, CTRUST, hostport, path, refer);
764 #endif /* def TRUST_FILES */
767 /*********************************************************************
769 * Function : intercept_url
771 * Description : checks the URL `basename' against a list of URLs to
772 * snarf. If it matches, it calls the associated function
773 * which returns an HTML page to send back to the client.
774 * Right now, we snarf:
775 * "show-proxy-args", and
776 * "ij-untrusted-url" (optional w/TRUST_FILES)
779 * 1 : http = http_request request, check `basename's of blocklist
780 * 2 : csp = Current client state (buffers, headers, etc...)
782 * Returns : NULL for no recognized URLs, or an HTML description page.
784 *********************************************************************/
785 char *intercept_url(struct http_request *http, struct client_state *csp)
788 const struct interceptors *v;
790 basename = strrchr(http->path, '/');
792 if (basename == NULL) return(NULL);
794 basename ++; /* first char past the last slash */
798 for (v = intercept_patterns; v->str; v++)
800 if (strncmp(basename, v->str, v->len) == 0)
802 return((v->interceptor)(http, csp));
811 #ifdef FAST_REDIRECTS
812 /*********************************************************************
814 * Function : redirect_url
816 * Description : Checks for redirection URLs and returns a HTTP redirect
817 * to the destination URL.
820 * 1 : http = http_request request, check `basename's of blocklist
821 * 2 : csp = Current client state (buffers, headers, etc...)
823 * Returns : NULL if URL was clean, HTTP redirect otherwise.
825 *********************************************************************/
826 char *redirect_url(struct http_request *http, struct client_state *csp)
830 p = q = csp->http->path;
831 log_error(LOG_LEVEL_REDIRECTS, "checking path: %s", p);
833 /* find the last URL encoded in the request */
834 while (p = strstr(p, "http://"))
839 /* if there was any, generate and return a HTTP redirect */
840 if (q != csp->http->path)
842 log_error(LOG_LEVEL_REDIRECTS, "redirecting to: %s", q);
844 p = (char *)malloc(strlen(HTTP_REDIRECT_TEMPLATE) + strlen(q));
845 sprintf(p, HTTP_REDIRECT_TEMPLATE, q);
854 #endif /* def FAST_REDIRECTS */
856 /*********************************************************************
858 * Function : url_permissions
860 * Description : Gets the permissions for this URL.
863 * 1 : http = http_request request for blocked URLs
864 * 2 : csp = Current client state (buffers, headers, etc...)
866 * Returns : permissions bitmask specifiying what this URL can do.
867 * If not on list, will be default_permissions.
869 *********************************************************************/
870 int url_permissions(struct http_request *http, struct client_state *csp)
872 struct file_list *fl;
873 struct permissions_spec *b;
874 struct url_spec url[1];
876 if (((fl = csp->permissions_list) == NULL) || ((b = fl->f) == NULL))
878 return(default_permissions);
881 *url = dsplit(http->host);
883 /* if splitting the domain fails, punt */
884 if (url->dbuf == NULL)
886 return(default_permissions);
889 for (b = b->next; NULL != b; b = b->next)
891 if ((b->url->port == 0) || (b->url->port == http->port))
893 if ((b->url->domain[0] == '\0') || (domaincmp(b->url, url) == 0))
895 if ((b->url->path == NULL) ||
897 (regexec(b->url->preg, http->path, 0, NULL, 0) == 0)
899 (strncmp(b->url->path, http->path, b->url->pathlen) == 0)
905 return(b->permissions);
913 return(default_permissions);
918 /*********************************************************************
920 * Function : forward_url
922 * Description : Should we forward this to another proxy?
925 * 1 : http = http_request request for current URL
926 * 2 : csp = Current client state (buffers, headers, etc...)
928 * Returns : Return gw_default for no forward match,
929 * else a gateway pointer to a specific forwarding proxy.
931 *********************************************************************/
932 const struct gateway *forward_url(struct http_request *http, struct client_state *csp)
934 struct file_list *fl;
935 struct forward_spec *b;
936 struct url_spec url[1];
938 if (((fl = csp->flist) == NULL) || ((b = fl->f) == NULL))
943 *url = dsplit(http->host);
945 /* if splitting the domain fails, punt */
946 if (url->dbuf == NULL) return(gw_default);
948 for (b = b->next; b ; b = b->next)
950 if ((b->url->port == 0) || (b->url->port == http->port))
952 if ((b->url->domain[0] == '\0') || (domaincmp(b->url, url) == 0))
954 if ((b->url->path == NULL) ||
956 (regexec(b->url->preg, http->path, 0, NULL, 0) == 0)
958 (strncmp(b->url->path, http->path, b->url->pathlen) == 0)
977 /*********************************************************************
981 * Description : Takes a domain and returns a pointer to a url_spec
982 * structure populated with dbuf, dcnt and dvec. The
983 * other fields in the structure that is returned are zero.
986 * 1 : domain = a URL address
988 * Returns : url_spec structure populated with dbuf, dcnt and dvec.
990 *********************************************************************/
991 struct url_spec dsplit(char *domain)
993 struct url_spec ret[1];
998 memset(ret, '\0', sizeof(*ret));
1000 if ((p = strrchr(domain, '.')))
1008 ret->dbuf = strdup(domain);
1010 /* map to lower case */
1011 for (p = ret->dbuf; *p ; p++) *p = tolower(*p);
1013 /* split the domain name into components */
1014 ret->dcnt = ssplit(ret->dbuf, ".", v, SZ(v), 1, 1);
1018 memset(ret, '\0', sizeof(ret));
1022 /* save a copy of the pointers in dvec */
1023 size = ret->dcnt * sizeof(*ret->dvec);
1025 if ((ret->dvec = (char **)malloc(size)))
1027 memcpy(ret->dvec, v, size);
1035 /*********************************************************************
1037 * Function : domaincmp
1039 * Description : Compare domain names.
1040 * domaincmp("a.b.c" , "a.b.c") => 0 (MATCH)
1041 * domaincmp("a*.b.c", "a.b.c") => 0 (MATCH)
1042 * domaincmp("b.c" , "a.b.c") => 0 (MATCH)
1043 * domaincmp("" , "a.b.c") => 0 (MATCH)
1046 * 1 : pattern = a domain that may contain a '*' as a wildcard.
1047 * 2 : fqdn = domain name against which the patterns are compared.
1049 * Returns : 0 => domains are equivalent, else no match.
1051 *********************************************************************/
1052 int domaincmp(struct url_spec *pattern, struct url_spec *fqdn)
1054 char **pv, **fv; /* vectors */
1055 int pn, fn; /* counters */
1056 char *p, *f; /* chars */
1064 while ((pn > 0) && (fn > 0))
1069 while (*p && *f && (*p == tolower(*f)))
1074 if ((*p != tolower(*f)) && (*p != '*')) return(1);
1077 if (pn > 0) return(1);
1084 /* intercept functions */
1086 /*********************************************************************
1088 * Function : show_proxy_args
1090 * Description : This "crunch"es "http:/any.thing/show-proxy-args" and
1091 * returns a web page describing the current status of IJB.
1094 * 1 : http = ignored
1095 * 2 : csp = Current client state (buffers, headers, etc...)
1097 * Returns : A string that contains the current status of IJB.
1099 *********************************************************************/
1100 char *show_proxy_args(struct http_request *http, struct client_state *csp)
1104 #ifdef SPLIT_PROXY_ARGS
1108 const char * filename = NULL;
1109 const char * file_description = NULL;
1110 char * query_string = strrchr(http->path, '?');
1111 char which_file = '\0';
1114 if (query_string != NULL)
1116 /* first char past the last '?' (maybe '\0')*/
1117 which_file = query_string[1];
1124 filename = csp->blist->filename;
1125 file_description = "Block List";
1129 if (csp->permissions_list)
1131 filename = csp->permissions_list->filename;
1132 file_description = "Permissions List";
1138 filename = csp->flist->filename;
1139 file_description = "Forward List";
1147 filename = csp->alist->filename;
1148 file_description = "Access Control List";
1151 #endif /* def ACL_FILES */
1153 #ifdef USE_IMAGE_LIST
1157 filename = csp->ilist->filename;
1158 file_description = "Image List";
1161 #endif /* def USE_IMAGE_LIST */
1167 filename = csp->rlist->filename;
1168 file_description = "RE Filter List";
1171 #endif /* def PCRS */
1177 filename = csp->tlist->filename;
1178 file_description = "Trust List";
1181 #endif /* def TRUST_FILES */
1186 /* Display specified file */
1187 /* FIXME: Add HTTP headers so this isn't cached */
1190 "Server: IJ/" VERSION "\n"
1191 "Content-type: text/html\n"
1192 "Pragma: no-cache\n"
1193 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\n"
1194 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\n"
1199 "<title>Internet Junkbuster Proxy Status - ");
1200 s = strsav(s, file_description);
1204 "<body bgcolor=\"#f8f8f0\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
1206 "<h1>" BANNER "\n");
1207 s = strsav(s, file_description);
1210 "<p><a href=\"show-proxy-args\">Back to proxy status</a></p>\n"
1212 s = strsav(s, file_description);
1215 "Contents of file "<code>");
1216 p = html_encode(filename);
1220 "</code>":<br>\n"
1224 if ((fp = fopen(filename, "r")) == NULL)
1226 s = strsav(s, "</pre><h1>ERROR OPENING FILE!</h1><pre>");
1230 while (fgets(buf, sizeof(buf), fp))
1232 p = html_encode(buf);
1237 s = strsav(s, "<br>");
1246 "<p><a href=\"show-proxy-args\">Back to proxy status</a></p>\n"
1248 "<small><small><p>\n"
1249 "The " BANNER " Proxy - \n"
1250 "<a href=\"" HOME_PAGE_URL "\">" HOME_PAGE_URL "</a>\n"
1252 "</body></html>\n");
1255 #endif /* def SPLIT_PROXY_ARGS */
1257 s = strsav(s, proxy_args->header);
1258 s = strsav(s, proxy_args->invocation);
1261 #endif /* def STATISTICS */
1262 s = strsav(s, proxy_args->gateways);
1264 #ifdef SPLIT_PROXY_ARGS
1266 "<h2>The following files are in use:</h2>\n"
1267 "<p>(Click a filename to view it)</p>\n"
1272 s = strsav(s, "<li>Block List: <a href=\"show-proxy-args?block\"><code>");
1273 s = strsav(s, csp->blist->filename);
1274 s = strsav(s, "</code></a></li>\n");
1277 if (csp->permissions_list)
1279 s = strsav(s, "<li>Permissions List: <a href=\"show-proxy-args?permit\"><code>");
1280 s = strsav(s, csp->permissions_list->filename);
1281 s = strsav(s, "</code></a></li>\n");
1286 s = strsav(s, "<li>Forward List: <a href=\"show-proxy-args?forward\"><code>");
1287 s = strsav(s, csp->flist->filename);
1288 s = strsav(s, "</code></a></li>\n");
1294 s = strsav(s, "<li>Access Control List: <a href=\"show-proxy-args?acl\"><code>");
1295 s = strsav(s, csp->alist->filename);
1296 s = strsav(s, "</code></a></li>\n");
1298 #endif /* def ACL_FILES */
1300 #ifdef USE_IMAGE_LIST
1303 s = strsav(s, "<li>Image List: <a href=\"show-proxy-args?image\"><code>");
1304 s = strsav(s, csp->ilist->filename);
1305 s = strsav(s, "</code></a></li>\n");
1307 #endif /* def USE_IMAGE_LIST */
1312 s = strsav(s, "<li>RE Filter List: <a href=\"show-proxy-args?re\"><code>");
1313 s = strsav(s, csp->rlist->filename);
1314 s = strsav(s, "</code></a></li>\n");
1316 #endif /* def PCRS */
1321 s = strsav(s, "<li>Trust List: <a href=\"show-proxy-args?trust\"><code>");
1322 s = strsav(s, csp->tlist->filename);
1323 s = strsav(s, "</code></a></li>\n");
1325 #endif /* def TRUST_FILES */
1327 s = strsav(s, "</ul>");
1329 #else /* ifndef SPLIT_PROXY_ARGS */
1332 s = strsav(s, csp->blist->proxy_args);
1337 s = strsav(s, csp->clist->proxy_args);
1342 s = strsav(s, csp->flist->proxy_args);
1348 s = strsav(s, csp->alist->proxy_args);
1350 #endif /* def ACL_FILES */
1352 #ifdef USE_IMAGE_LIST
1355 s = strsav(s, csp->ilist->proxy_args);
1357 #endif /* def USE_IMAGE_LIST */
1362 s = strsav(s, csp->rlist->proxy_args);
1364 #endif /* def PCRS */
1369 s = strsav(s, csp->tlist->proxy_args);
1371 #endif /* def TRUST_FILES */
1373 #endif /* ndef SPLIT_PROXY_ARGS */
1375 s = strsav(s, proxy_args->trailer);
1382 /*********************************************************************
1384 * Function : ijb_send_banner
1386 * Description : This "crunch"es "http:/any.thing/ijb-send-banner and
1387 * thus triggers sending the image in jcc.c:chat.
1388 * For the unlikely case, that the imagefile/MSIE
1389 * mechanism is not used, or tinygif = 0, a page
1390 * describing the reson of the interception is generated.
1393 * 1 : http = http_request request for crunched URL
1394 * 2 : csp = Current client state (buffers, headers, etc...)
1396 * Returns : A string that contains why this was intercepted.
1398 *********************************************************************/
1399 char *ijb_send_banner(struct http_request *http, struct client_state *csp)
1401 return(strdup(CNOBANNER));
1405 /*********************************************************************
1407 * Function : ij_untrusted_url
1409 * Description : This "crunch"es "http:/any.thing/ij-untrusted-url" and
1410 * returns a web page describing why it was untrusted.
1413 * 1 : http = http_request request for crunched URL
1414 * 2 : csp = Current client state (buffers, headers, etc...)
1416 * Returns : A string that contains why this was untrusted.
1418 *********************************************************************/
1419 char *ij_untrusted_url(struct http_request *http, struct client_state *csp)
1422 char *hostport, *path, *refer, *p, *v[9];
1424 struct url_spec **tl, *t;
1427 static const char format[] =
1428 "HTTP/1.0 200 OK\r\n"
1429 "Pragma: no-cache\n"
1430 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\n"
1431 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\n"
1432 "Content-Type: text/html\n\n"
1435 "<title>Internet Junkbuster: Request for untrusted URL</title>\n"
1441 "The " BANNER " Proxy "
1442 "<A href=\"" HOME_PAGE_URL "\">"
1443 "(" HOME_PAGE_URL ") </A>"
1444 "intercepted the request for %s%s\n"
1445 "because the URL is not trusted.\n"
1448 if ((n = ssplit(http->path, "?+", v, SZ(v), 0, 0)) == 4)
1450 hostport = url_decode(v[1]);
1451 path = url_decode(v[2]);
1452 refer = url_decode(v[3]);
1456 hostport = strdup("undefined_host");
1457 path = strdup("/undefined_path");
1458 refer = strdup("undefined");
1462 n += strlen(hostport);
1465 if ((p = (char *)malloc(n)))
1467 sprintf(p, format, hostport, path);
1470 strsav(p, "The referrer in this request was <strong>");
1472 strsav(p, "</strong><br>\n");
1478 p = strsav(p, "<h3>The following referrers are trusted</h3>\n");
1480 for (tl = trust_list; (t = *tl) ; tl++)
1482 sprintf(buf, "%s<br>\n", t->spec);
1486 if (trust_info->next)
1492 "You can learn more about what this means "
1493 "and what you may be able to do about it by "
1494 "reading the following documents:<br>\n"
1500 for (l = trust_info->next; l ; l = l->next)
1503 "<li> <a href=%s>%s</a><br>\n",
1508 p = strsav(p, "</ol>\n");
1511 p = strsav(p, "</body>\n" "</html>\n");
1516 #endif /* def TRUST_FILES */
1520 /*********************************************************************
1522 * Function : add_stats
1524 * Description : Statistics function of JB. Called by `show_proxy_args'.
1527 * 1 : s = string that holds the proxy args description page
1529 * Returns : A pointer to the descriptive status web page.
1531 *********************************************************************/
1532 char *add_stats(char *s)
1535 * Output details of the number of requests rejected and
1536 * accepted. This is switchable in the junkbuster config.
1537 * Does nothing if this option is not enabled.
1540 float perc_rej; /* Percentage of http requests rejected */
1542 int local_urls_read = urls_read;
1543 int local_urls_rejected = urls_rejected;
1546 * Need to alter the stats not to include the fetch of this
1549 * Can't do following thread safely! doh!
1552 * urls_rejected--; * This will be incremented subsequently *
1555 s = strsav(s,"<h2>Statistics for this " BANNER ":</h2>\n");
1557 if (local_urls_read == 0)
1560 s = strsav(s,"No activity so far!\n");
1566 perc_rej = (float)local_urls_rejected * 100.0F /
1567 (float)local_urls_read;
1570 "%d requests received, %d filtered "
1573 local_urls_rejected, perc_rej);
1575 s = strsav(s,out_str);
1580 #endif /* def STATISTICS */