1 const char showargs_rcs[] = "$Id: showargs.c,v 1.8 2001/05/29 09:50:24 jongfoster Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/showargs.c,v $
6 * Purpose : Contains various utility routines needed to
7 * generate the show-proxy-args page.
9 * Copyright : Written by and Copyright (C) 2001 the SourceForge
10 * IJBSWA team. http://ijbswa.sourceforge.net
12 * Based on the Internet Junkbuster originally written
13 * by and Copyright (C) 1997 Anonymous Coders and
14 * Junkbusters Corporation. http://www.junkbusters.com
16 * This program is free software; you can redistribute it
17 * and/or modify it under the terms of the GNU General
18 * Public License as published by the Free Software
19 * Foundation; either version 2 of the License, or (at
20 * your option) any later version.
22 * This program is distributed in the hope that it will
23 * be useful, but WITHOUT ANY WARRANTY; without even the
24 * implied warranty of MERCHANTABILITY or FITNESS FOR A
25 * PARTICULAR PURPOSE. See the GNU General Public
26 * License for more details.
28 * The GNU General Public License should be included with
29 * this file. If not, you can view it at
30 * http://www.gnu.org/copyleft/gpl.html
31 * or write to the Free Software Foundation, Inc., 59
32 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 * $Log: showargs.c,v $
36 * Revision 1.8 2001/05/29 09:50:24 jongfoster
37 * Unified blocklist/imagelist/permissionslist.
38 * File format is still under discussion, but the internal changes
41 * Also modified interceptor behaviour:
42 * - We now intercept all URLs beginning with one of the following
43 * prefixes (and *only* these prefixes):
45 * * http://ijbswa.sf.net/config/
46 * * http://ijbswa.sourceforge.net/config/
47 * - New interceptors "home page" - go to http://i.j.b/ to see it.
48 * - Internal changes so that intercepted and fast redirect pages
49 * are not replaced with an image.
50 * - Interceptors now have the option to send a binary page direct
51 * to the client. (i.e. ijb-send-banner uses this)
52 * - Implemented show-url-info interceptor. (Which is why I needed
53 * the above interceptors changes - a typical URL is
54 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
55 * The previous mechanism would not have intercepted that, and
56 * if it had been intercepted then it then it would have replaced
59 * Revision 1.7 2001/05/26 00:28:36 jongfoster
60 * Automatic reloading of config file.
61 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
62 * Most of the global variables have been moved to a new
63 * struct configuration_spec, accessed through csp->config->globalname
64 * Most of the globals remaining are used by the Win32 GUI.
66 * Revision 1.6 2001/05/25 22:32:56 jongfoster
69 * Revision 1.5 2001/05/22 18:54:49 oes
71 * - Enabled filtering banners by size rather than URL
72 * by adding patterns that replace all standard banner
73 * sizes with the "Junkbuster" gif to the re_filterfile
75 * - Enabled filtering WebBugs by providing a pattern
76 * which kills all 1x1 images
78 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
79 * which is selected by the (nonstandard and therefore
80 * capital) letter 'U' in the option string.
81 * It causes the quantifiers to be ungreedy by default.
82 * Appending a ? turns back to greedy (!).
84 * - Added a new interceptor ijb-send-banner, which
85 * sends back the "Junkbuster" gif. Without imagelist or
86 * MSIE detection support, or if tinygif = 1, or the
87 * URL isn't recognized as an imageurl, a lame HTML
88 * explanation is sent instead.
90 * - Added new feature, which permits blocking remote
91 * script redirects and firing back a local redirect
93 * The feature is conditionally compiled, i.e. it
94 * can be disabled with --disable-fast-redirects,
95 * plus it must be activated by a "fast-redirects"
96 * line in the config file, has its own log level
97 * and of course wants to be displayed by show-proxy-args
98 * Note: Boy, all the #ifdefs in 1001 locations and
99 * all the fumbling with configure.in and acconfig.h
100 * were *way* more work than the feature itself :-(
102 * - Because a generic redirect template was needed for
103 * this, tinygif = 3 now uses the same.
105 * - Moved GIFs, and other static HTTP response templates
110 * - Removed some >400 CRs again (Jon, you really worked
113 * Revision 1.4 2001/05/20 16:44:47 jongfoster
114 * Removing last hardcoded JunkBusters.com URLs.
116 * Revision 1.3 2001/05/20 01:21:20 jongfoster
117 * Version 2.9.4 checkin.
118 * - Merged popupfile and cookiefile, and added control over PCRS
119 * filtering, in new "permissionsfile".
120 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
121 * file error you now get a message box (in the Win32 GUI) rather
122 * than the program exiting with no explanation.
123 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
125 * - Removed tabs from "config"
126 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
127 * - Bumped up version number.
129 * Revision 1.2 2001/05/17 23:01:01 oes
130 * - Cleaned CRLF's from the sources and related files
132 * Revision 1.1.1.1 2001/05/15 13:59:03 oes
133 * Initial import of version 2.9.3 source tree
136 *********************************************************************/
142 #include <sys/types.h>
148 #include "showargs.h"
153 #include "miscutil.h"
156 const char showargs_h_rcs[] = SHOWARGS_H_VERSION;
159 /*********************************************************************
163 * Description : Called from `load_config'. It saves each non-empty
164 * and non-comment line from config into a list. This
165 * list is used to create the show-proxy-args page.
168 * 1 : c = config setting that was found
169 * 2 : o = the setting's argument (if any)
173 *********************************************************************/
174 void savearg(char *c, char *o, struct configuration_spec * config)
180 if ( ( NULL != c ) && ( '\0' != *c ) )
182 if ((c = html_encode(c)))
184 sprintf(buf, "<a href=\"" REDIRECT_URL "option#%s\">%s</a> ", c, c);
188 if ( ( NULL != o ) && ( '\0' != *o ) )
190 if ((o = html_encode(o)))
192 if (strncmpic(o, "http://", 7) == 0)
194 strcat(buf, "<a href=\"");
208 strcat(buf, "<br>\n");
210 config->proxy_args_invocation = strsav(config->proxy_args_invocation, buf);
215 /*********************************************************************
217 * Function : init_proxy_args
219 * Description : Create the "top" of the show-proxy-args page.
222 * 1 : argc = argument count (same as in main)
223 * 2 : argv[] = program arguments (same as in main)
227 *********************************************************************/
228 void init_proxy_args(int argc, const char *argv[], struct configuration_spec * config)
230 const struct gateway *g;
234 freez(config->proxy_args_header);
235 freez(config->proxy_args_invocation);
236 freez(config->proxy_args_gateways);
237 freez(config->proxy_args_trailer);
243 "Server: IJ/" VERSION "\n"
244 "Content-type: text/html\n\n"
248 "<title>Internet Junkbuster Proxy Status</title>"
250 "<body bgcolor=\"#f8f8f0\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
253 "<a href=\"" REDIRECT_URL "faq#show\">Proxy Status</a>\n"
255 "<h2>You are using the " BANNER " <sup><small><small>TM</small></small></sup></h2>\n"
256 "Version: " VERSION "\n"
257 "<br>Home page: <a href=\"" HOME_PAGE_URL "\">" HOME_PAGE_URL "</a>\n"
262 "<h2>The program was invoked as follows</h2>\n");
264 for (i=0; i < argc; i++)
266 b = strsav(b, argv[i]);
269 b = strsav(b, "<br>\n");
271 config->proxy_args_header = b;
273 config->proxy_args_invocation = strsav(
274 config->proxy_args_invocation,
276 "and the following options were set in the configuration file"
283 "<h2>It supports the following gateway protocols:</h2>\n");
285 for (g = gateways; g->name; g++)
287 b = strsav(b, g->name);
290 b = strsav(b, "<br>\n");
292 config->proxy_args_gateways = b;
296 /*********************************************************************
298 * Function : end_proxy_args
300 * Description : Create the "bottom" of the show-proxy-args page.
306 *********************************************************************/
307 void end_proxy_args(struct configuration_spec * config)
312 /* Instead of including *all* dot h's in the project (thus creating a
313 * tremendous amount of dependencies), I will concede to declaring them
314 * as extern's. This forces the developer to add to this list, but oh well.
317 #ifndef SPLIT_PROXY_ARGS
318 if (suppress_blocklists && suppress_message!=NULL)
320 b = strsav(b, "<h2>File contents</h2>\n");
321 b = strsav(b, suppress_message);
324 #endif /* ndef SPLIT_PROXY_ARGS */
326 b = strsav(b, "<h2>Source versions:</h2>\n");
327 b = strsav(b, "<pre>");
329 #define SHOW_RCS(__x) \
331 extern const char __x[]; \
332 sprintf(buf, "%s\n", __x); \
333 b = strsav(b, buf); \
336 /* In alphabetical order */
338 SHOW_RCS(cygwin_h_rcs)
340 SHOW_RCS(encode_h_rcs)
342 SHOW_RCS(errlog_h_rcs)
344 SHOW_RCS(filters_h_rcs)
345 SHOW_RCS(filters_rcs)
346 SHOW_RCS(gateway_h_rcs)
347 SHOW_RCS(gateway_rcs)
349 SHOW_RCS(gnu_regex_h_rcs)
350 SHOW_RCS(gnu_regex_rcs)
351 #endif /* def GNU_REGEX */
352 SHOW_RCS(jbsockets_h_rcs)
353 SHOW_RCS(jbsockets_rcs)
357 SHOW_RCS(killpopup_h_rcs)
358 SHOW_RCS(killpopup_rcs)
359 #endif /* def KILLPOPUPS */
360 SHOW_RCS(loadcfg_h_rcs)
361 SHOW_RCS(loadcfg_rcs)
362 SHOW_RCS(loaders_h_rcs)
363 SHOW_RCS(loaders_rcs)
364 SHOW_RCS(miscutil_h_rcs)
365 SHOW_RCS(miscutil_rcs)
366 SHOW_RCS(parsers_h_rcs)
367 SHOW_RCS(parsers_rcs)
371 #endif /* def PCRS */
372 SHOW_RCS(project_h_rcs)
373 SHOW_RCS(showargs_h_rcs)
374 SHOW_RCS(showargs_rcs)
375 SHOW_RCS(ssplit_h_rcs)
379 SHOW_RCS(w32log_h_rcs)
381 SHOW_RCS(w32res_h_rcs)
382 SHOW_RCS(w32rulesdlg_h_rcs)
383 SHOW_RCS(w32rulesdlg_rcs)
384 SHOW_RCS(w32taskbar_h_rcs)
385 SHOW_RCS(w32taskbar_rcs)
386 #endif /* ndef _WIN_CONSOLE */
387 SHOW_RCS(win32_h_rcs)
389 #endif /* def _WIN32 */
393 b = strsav(b, "</pre>\n");
395 b = strsav(b, "<h2>Conditional defines:</h2>\n<ul>");
398 b = strsav(b, " <li><code>#define <b>REGEX</b></code> - Support for regular expressions in the path specs.</li>\n");
399 #else /* ifndef REGEX */
400 b = strsav(b, " <li><code>#undef <b>REGEX</b></code> - No support for regular expressions in the path specs.</li>\n");
401 #endif /* ndef REGEX */
404 b = strsav(b, " <li><code>#define <b>PCRE</b></code> - Use PCRE rather than old GNU regex library.</li>\n");
405 #else /* ifndef PCRE */
406 b = strsav(b, " <li><code>#undef <b>PCRE</b></code> - Use old GNU regex library rather than PCRE.</li>\n");
407 #endif /* ndef PCRE */
410 b = strsav(b, " <li><code>#define <b>PCRS</b></code> - Enables arbitrary content modification regexps.</li>\n");
411 #else /* ifndef PCRS */
412 b = strsav(b, " <li><code>#undef <b>PCRS</b></code> - Disables arbitrary content modification regexps.</li>\n");
413 #endif /* ndef PCRS */
416 b = strsav(b, " <li><code>#define <b>TOGGLE</b></code> - Allow JunkBuster to be \"disabled\" so it is just a normal non-blocking non-anonymizing proxy.</li>\n");
417 #else /* ifndef TOGGLE */
418 b = strsav(b, " <li><code>#undef <b>TOGGLE</b></code> - Do not allow JunkBuster to be \"disabled\" so it is just a normal non-blocking non-anonymizing proxy.</li>\n");
419 #endif /* ndef TOGGLE */
422 b = strsav(b, " <li><code>#define <b>FORCE_LOAD</b></code> - Enables bypassing filtering for a single page using the prefix \"" FORCE_PREFIX "\".</li>\n");
423 #else /* ifndef FORCE_LOAD */
424 b = strsav(b, " <li><code>#undef <b>FORCE_LOAD</b></code> - Disables bypassing filtering for a single page.</li>\n");
425 #endif /* ndef FORCE_LOAD */
428 b = strsav(b, " <li><code>#define <b>DENY_GZIP</b></code> - Prevents requests from being compressed - required for PCRS.</li>\n");
429 #else /* ifndef DENY_GZIP */
430 b = strsav(b, " <li><code>#undef <b>DENY_GZIP</b></code> - Allows requests to be compressed if the browser and server support it.</li>\n");
431 #endif /* ndef DENY_GZIP */
434 b = strsav(b, " <li><code>#define <b>STATISTICS</b></code> - Enables statistics function.</li>\n");
435 #else /* ifndef STATISTICS */
436 b = strsav(b, " <li><code>#undef <b>STATISTICS</b></code> - Disables statistics function.</li>\n");
437 #endif /* ndef STATISTICS */
439 #ifdef SPLIT_PROXY_ARGS
440 b = strsav(b, " <li><code>#define <b>SPLIT_PROXY_ARGS</b></code> - Split this page up by placing the configuration files on separate pages.</li>\n");
441 #else /* ifndef SPLIT_PROXY_ARGS */
442 b = strsav(b, " <li><code>#undef <b>SPLIT_PROXY_ARGS</b></code> - This page contains the text of the configuration files, they are not split onto separate pages.</li>\n");
443 #endif /* ndef SPLIT_PROXY_ARGS */
446 b = strsav(b, " <li><code>#define <b>KILLPOPUPS</b></code> - Enables killing JavaScript popups.</li>\n");
447 #else /* ifndef KILLPOPUPS */
448 b = strsav(b, " <li><code>#undef <b>KILLPOPUPS</b></code> - Disables killing JavaScript popups.</li>\n");
449 #endif /* ndef KILLPOPUPS */
452 b = strsav(b, " <li><code>#define <b>WEBDAV</b></code> - Enables support for webDAV - e.g. stops Microsoft Outlook from accessing HotMail e-mail.</li>\n");
453 #else /* ifndef WEBDAV */
454 b = strsav(b, " <li><code>#undef <b>WEBDAV</b></code> - Disables support for webDAV - e.g. so Microsoft Outlook can access HotMail e-mail.</li>\n");
455 #endif /* ndef WEBDAV */
457 #ifdef DETECT_MSIE_IMAGES
458 b = strsav(b, " <li><code>#define <b>DETECT_MSIE_IMAGES</b></code> - Enables detecting image requests automatically for MSIE.</li>\n");
459 #else /* ifndef DETECT_MSIE_IMAGES */
460 b = strsav(b, " <li><code>#undef <b>DETECT_MSIE_IMAGES</b></code> - Disables detecting image requests automatically for MSIE.</li>\n");
461 #endif /* ndef DETECT_MSIE_IMAGES */
463 #ifdef IMAGE_BLOCKING
464 b = strsav(b, " <li><code>#define <b>IMAGE_BLOCKING</b></code> - Enables sending \"blocked\" images instead of HTML.</li>\n");
465 #else /* ifndef IMAGE_BLOCKING */
466 b = strsav(b, " <li><code>#undef <b>IMAGE_BLOCKING</b></code> - Disables sending \"blocked\" images instead of HTML.</li>\n");
467 #endif /* ndef IMAGE_BLOCKING */
470 b = strsav(b, " <li><code>#define <b>ACL_FILES</b></code> - Enables the use of ACL files to control access to the proxy by IP address.</li>\n");
471 #else /* ifndef ACL_FILES */
472 b = strsav(b, " <li><code>#undef <b>ACL_FILES</b></code> - Disables the use of ACL files to control access to the proxy by IP address.</li>\n");
473 #endif /* ndef ACL_FILES */
476 b = strsav(b, " <li><code>#define <b>TRUST_FILES</b></code> - Enables the use of trust files.</li>\n");
477 #else /* ifndef TRUST_FILES */
478 b = strsav(b, " <li><code>#undef <b>TRUST_FILES</b></code> - Disables the use of trust files.</li>\n");
479 #endif /* ndef TRUST_FILES */
482 b = strsav(b, " <li><code>#define <b>JAR_FILES</b></code> - Enables the use of jar files to capture cookies.</li>\n");
483 #else /* ifndef JAR_FILES */
484 b = strsav(b, " <li><code>#undef <b>JAR_FILES</b></code> - Disables the use of jar files to capture cookies.</li>\n");
485 #endif /* ndef JAR_FILES */
487 #ifdef FAST_REDIRECTS
488 b = strsav(b, " <li><code>#define <b>FAST_REDIRECTS</b></code> - Enables intercepting remote script redirects.</li>\n");
489 #else /* ifndef FAST_REDIRECTS */
490 b = strsav(b, " <li><code>#undef <b>FAST_REDIRECTS</b></code> - Disables intercepting remote script redirects.</li>\n");
491 #endif ndef /* FAST_REDIRECTS */
493 b = strsav(b, "</ul>\n<br>\n");
496 "<small><small><p>\n"
497 "The " BANNER " Proxy - \n"
498 "<a href=\"" HOME_PAGE_URL "\">" HOME_PAGE_URL "</a><p>\n"
499 "Copyright © 2001 <a href=\"" HOME_PAGE_URL "\">the SourceForge IJBSWA team</a><br>\n"
500 "Copyright © 1997 <a href=\"http://www.junkbusters.com/\">\n" "Junkbusters Corporation</a><br>\n"
501 "Copying and distribution permitted under the "
502 "<a href=\"http://www.gnu.org/copyleft/gpl.html\">GNU General Public License.</a>\n"
507 config->proxy_args_trailer = b;