1 const char showargs_rcs[] = "$Id: showargs.c,v 1.5 2001/05/22 18:54:49 oes 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.5 2001/05/22 18:54:49 oes
38 * - Enabled filtering banners by size rather than URL
39 * by adding patterns that replace all standard banner
40 * sizes with the "Junkbuster" gif to the re_filterfile
42 * - Enabled filtering WebBugs by providing a pattern
43 * which kills all 1x1 images
45 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
46 * which is selected by the (nonstandard and therefore
47 * capital) letter 'U' in the option string.
48 * It causes the quantifiers to be ungreedy by default.
49 * Appending a ? turns back to greedy (!).
51 * - Added a new interceptor ijb-send-banner, which
52 * sends back the "Junkbuster" gif. Without imagelist or
53 * MSIE detection support, or if tinygif = 1, or the
54 * URL isn't recognized as an imageurl, a lame HTML
55 * explanation is sent instead.
57 * - Added new feature, which permits blocking remote
58 * script redirects and firing back a local redirect
60 * The feature is conditionally compiled, i.e. it
61 * can be disabled with --disable-fast-redirects,
62 * plus it must be activated by a "fast-redirects"
63 * line in the config file, has its own log level
64 * and of course wants to be displayed by show-proxy-args
65 * Note: Boy, all the #ifdefs in 1001 locations and
66 * all the fumbling with configure.in and acconfig.h
67 * were *way* more work than the feature itself :-(
69 * - Because a generic redirect template was needed for
70 * this, tinygif = 3 now uses the same.
72 * - Moved GIFs, and other static HTTP response templates
77 * - Removed some >400 CRs again (Jon, you really worked
80 * Revision 1.4 2001/05/20 16:44:47 jongfoster
81 * Removing last hardcoded JunkBusters.com URLs.
83 * Revision 1.3 2001/05/20 01:21:20 jongfoster
84 * Version 2.9.4 checkin.
85 * - Merged popupfile and cookiefile, and added control over PCRS
86 * filtering, in new "permissionsfile".
87 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
88 * file error you now get a message box (in the Win32 GUI) rather
89 * than the program exiting with no explanation.
90 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
92 * - Removed tabs from "config"
93 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
94 * - Bumped up version number.
96 * Revision 1.2 2001/05/17 23:01:01 oes
97 * - Cleaned CRLF's from the sources and related files
99 * Revision 1.1.1.1 2001/05/15 13:59:03 oes
100 * Initial import of version 2.9.3 source tree
103 *********************************************************************/
109 #include <sys/types.h>
114 #include "showargs.h"
119 #include "miscutil.h"
122 const char showargs_h_rcs[] = SHOWARGS_H_VERSION;
124 /*********************************************************************
128 * Description : Reallocate "old" and append text to it. This makes
129 * it easier to append to malloc'd strings.
132 * 1 : old = Old text that is to be extended. Will be
133 * free()d by this routine.
134 * 2 : text_to_append = Text to be appended to old.
136 * Returns : Pointer to newly malloc'ed appended string.
137 * If there is no text to append, return old. Caller
140 *********************************************************************/
141 char *strsav(char *old, const char *text_to_append)
143 int old_len, new_len;
146 if (( text_to_append == NULL) || (*text_to_append == '\0'))
153 old_len = strlen(old);
160 new_len = old_len + strlen(text_to_append) + 1;
164 if ((p = realloc(old, new_len)) == NULL)
166 log_error(LOG_LEVEL_FATAL, "realloc(%d) bytes for proxy_args failed!", new_len);
167 /* Never get here - LOG_LEVEL_FATAL causes program exit */
172 if ((p = (char *)malloc(new_len)) == NULL)
174 log_error(LOG_LEVEL_FATAL, "malloc(%d) bytes for proxy_args failed!", new_len);
175 /* Never get here - LOG_LEVEL_FATAL causes program exit */
179 strcpy(p + old_len, text_to_append);
185 /*********************************************************************
189 * Description : Called from `load_config'. It saves each non-empty
190 * and non-comment line from config into a list. This
191 * list is used to create the show-proxy-args page.
194 * 1 : c = config setting that was found
195 * 2 : o = the setting's argument (if any)
199 *********************************************************************/
200 void savearg(char *c, char *o)
206 if ( ( NULL != c ) && ( '\0' != *c ) )
208 if ((c = html_encode(c)))
210 sprintf(buf, "<a href=\"" REDIRECT_URL "option#%s\">%s</a> ", c, c);
214 if ( ( NULL != o ) && ( '\0' != *o ) )
216 if ((o = html_encode(o)))
218 if (strncmpic(o, "http://", 7) == 0)
220 strcat(buf, "<a href=\"");
234 strcat(buf, "<br>\n");
236 proxy_args->invocation = strsav(proxy_args->invocation, buf);
241 /*********************************************************************
243 * Function : init_proxy_args
245 * Description : Create the "top" of the show-proxy-args page.
248 * 1 : argc = argument count (same as in main)
249 * 2 : argv[] = program arguments (same as in main)
253 *********************************************************************/
254 void init_proxy_args(int argc, const char *argv[])
256 const struct gateway *g;
259 freez(proxy_args->header);
260 freez(proxy_args->invocation);
261 freez(proxy_args->gateways);
262 freez(proxy_args->trailer);
265 proxy_args->header = strsav(proxy_args->header,
267 "Server: IJ/" VERSION "\n"
268 "Content-type: text/html\n\n"
272 "<title>Internet Junkbuster Proxy Status</title>"
274 "<body bgcolor=\"#f8f8f0\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
277 "<a href=\"" REDIRECT_URL "faq#show\">Proxy Status</a>\n"
279 "<h2>You are using the " BANNER " <sup><small><small>TM</small></small></sup></h2>\n"
280 "Version: " VERSION "\n"
281 "<br>Home page: <a href=\"" HOME_PAGE_URL "\">" HOME_PAGE_URL "</a>\n"
285 proxy_args->header = strsav(proxy_args->header,
286 "<h2>The program was invoked as follows</h2>\n");
288 for (i=0; i < argc; i++)
290 proxy_args->header = strsav(proxy_args->header, argv[i]);
291 proxy_args->header = strsav(proxy_args->header, " ");
293 proxy_args->header = strsav(proxy_args->header, "<br>\n");
296 proxy_args->invocation = strsav(
297 proxy_args->invocation,
299 "and the following options were set in the configuration file"
304 proxy_args->gateways = strsav(proxy_args->gateways,
305 "<h2>It supports the following gateway protocols:</h2>\n");
307 for (g = gateways; g->name; g++)
309 proxy_args->gateways = strsav(proxy_args->gateways, g->name);
310 proxy_args->gateways = strsav(proxy_args->gateways, " ");
312 proxy_args->gateways = strsav(proxy_args->gateways, "<br>\n");
317 /*********************************************************************
319 * Function : end_proxy_args
321 * Description : Create the "bottom" of the show-proxy-args page.
327 *********************************************************************/
328 void end_proxy_args(void)
333 /* Instead of including *all* dot h's in the project (thus creating a
334 * tremendous amount of dependencies), I will concede to declaring them
335 * as extern's. This forces the developer to add to this list, but oh well.
338 #ifndef SPLIT_PROXY_ARGS
339 if (suppress_blocklists && suppress_message!=NULL)
341 b = strsav(b, "<h2>File contents</h2>\n");
342 b = strsav(b, suppress_message);
345 #endif /* ndef SPLIT_PROXY_ARGS */
347 b = strsav(b, "<h2>Source versions:</h2>\n");
348 b = strsav(b, "<pre>");
350 #define SHOW_RCS(__x) \
352 extern const char __x[]; \
353 sprintf(buf, "%s\n", __x); \
354 b = strsav(b, buf); \
357 /* In alphabetical order */
359 SHOW_RCS(cygwin_h_rcs)
361 SHOW_RCS(encode_h_rcs)
363 SHOW_RCS(errlog_h_rcs)
365 SHOW_RCS(filters_h_rcs)
366 SHOW_RCS(filters_rcs)
367 SHOW_RCS(gateway_h_rcs)
368 SHOW_RCS(gateway_rcs)
370 SHOW_RCS(gnu_regex_h_rcs)
371 SHOW_RCS(gnu_regex_rcs)
372 #endif /* def GNU_REGEX */
373 SHOW_RCS(jbsockets_h_rcs)
374 SHOW_RCS(jbsockets_rcs)
378 SHOW_RCS(killpopup_h_rcs)
379 SHOW_RCS(killpopup_rcs)
380 #endif /* def KILLPOPUPS */
381 SHOW_RCS(loadcfg_h_rcs)
382 SHOW_RCS(loadcfg_rcs)
383 SHOW_RCS(loaders_h_rcs)
384 SHOW_RCS(loaders_rcs)
385 SHOW_RCS(miscutil_h_rcs)
386 SHOW_RCS(miscutil_rcs)
387 SHOW_RCS(parsers_h_rcs)
388 SHOW_RCS(parsers_rcs)
392 #endif /* def PCRS */
393 SHOW_RCS(project_h_rcs)
394 SHOW_RCS(showargs_h_rcs)
395 SHOW_RCS(showargs_rcs)
396 SHOW_RCS(ssplit_h_rcs)
400 SHOW_RCS(w32log_h_rcs)
402 SHOW_RCS(w32res_h_rcs)
403 SHOW_RCS(w32rulesdlg_h_rcs)
404 SHOW_RCS(w32rulesdlg_rcs)
405 SHOW_RCS(w32taskbar_h_rcs)
406 SHOW_RCS(w32taskbar_rcs)
407 #endif /* ndef _WIN_CONSOLE */
408 SHOW_RCS(win32_h_rcs)
410 #endif /* def _WIN32 */
414 b = strsav(b, "</pre>\n");
416 b = strsav(b, "<h2>Conditional defines:</h2>\n<ul>");
419 b = strsav(b, " <li><code>#define <b>REGEX</b></code> - Support for regular expressions in the path specs.</li>\n");
420 #else /* ifndef REGEX */
421 b = strsav(b, " <li><code>#undef <b>REGEX</b></code> - No support for regular expressions in the path specs.</li>\n");
422 #endif /* ndef REGEX */
425 b = strsav(b, " <li><code>#define <b>PCRE</b></code> - Use PCRE rather than old GNU regex library.</li>\n");
426 #else /* ifndef PCRE */
427 b = strsav(b, " <li><code>#undef <b>PCRE</b></code> - Use old GNU regex library rather than PCRE.</li>\n");
428 #endif /* ndef PCRE */
431 b = strsav(b, " <li><code>#define <b>PCRS</b></code> - Enables arbitrary content modification regexps.</li>\n");
432 #else /* ifndef PCRS */
433 b = strsav(b, " <li><code>#undef <b>PCRS</b></code> - Disables arbitrary content modification regexps.</li>\n");
434 #endif /* ndef PCRS */
437 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");
438 #else /* ifndef TOGGLE */
439 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");
440 #endif /* ndef TOGGLE */
443 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");
444 #else /* ifndef FORCE_LOAD */
445 b = strsav(b, " <li><code>#undef <b>FORCE_LOAD</b></code> - Disables bypassing filtering for a single page.</li>\n");
446 #endif /* ndef FORCE_LOAD */
449 b = strsav(b, " <li><code>#define <b>DENY_GZIP</b></code> - Prevents requests from being compressed - required for PCRS.</li>\n");
450 #else /* ifndef DENY_GZIP */
451 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");
452 #endif /* ndef DENY_GZIP */
455 b = strsav(b, " <li><code>#define <b>STATISTICS</b></code> - Enables statistics function.</li>\n");
456 #else /* ifndef STATISTICS */
457 b = strsav(b, " <li><code>#undef <b>STATISTICS</b></code> - Disables statistics function.</li>\n");
458 #endif /* ndef STATISTICS */
460 #ifdef SPLIT_PROXY_ARGS
461 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");
462 #else /* ifndef SPLIT_PROXY_ARGS */
463 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");
464 #endif /* ndef SPLIT_PROXY_ARGS */
467 b = strsav(b, " <li><code>#define <b>KILLPOPUPS</b></code> - Enables killing JavaScript popups.</li>\n");
468 #else /* ifndef KILLPOPUPS */
469 b = strsav(b, " <li><code>#undef <b>KILLPOPUPS</b></code> - Disables killing JavaScript popups.</li>\n");
470 #endif /* ndef KILLPOPUPS */
473 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");
474 #else /* ifndef WEBDAV */
475 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");
476 #endif /* ndef WEBDAV */
478 #ifdef DETECT_MSIE_IMAGES
479 b = strsav(b, " <li><code>#define <b>DETECT_MSIE_IMAGES</b></code> - Enables detecting image requests automatically for MSIE.</li>\n");
480 #else /* ifndef DETECT_MSIE_IMAGES */
481 b = strsav(b, " <li><code>#undef <b>DETECT_MSIE_IMAGES</b></code> - Disables detecting image requests automatically for MSIE.</li>\n");
482 #endif /* ndef DETECT_MSIE_IMAGES */
484 #ifdef USE_IMAGE_LIST
485 b = strsav(b, " <li><code>#define <b>USE_IMAGE_LIST</b></code> - Enables using image list to detect images.</li>\n");
486 #else /* ifndef USE_IMAGE_LIST */
487 b = strsav(b, " <li><code>#undef <b>USE_IMAGE_LIST</b></code> - Disables using image list to detect images.</li>\n");
488 #endif /* ndef USE_IMAGE_LIST */
491 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");
492 #else /* ifndef ACL_FILES */
493 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");
494 #endif /* ndef ACL_FILES */
497 b = strsav(b, " <li><code>#define <b>TRUST_FILES</b></code> - Enables the use of trust files.</li>\n");
498 #else /* ifndef TRUST_FILES */
499 b = strsav(b, " <li><code>#undef <b>TRUST_FILES</b></code> - Disables the use of trust files.</li>\n");
500 #endif /* ndef TRUST_FILES */
503 b = strsav(b, " <li><code>#define <b>JAR_FILES</b></code> - Enables the use of jar files to capture cookies.</li>\n");
504 #else /* ifndef JAR_FILES */
505 b = strsav(b, " <li><code>#undef <b>JAR_FILES</b></code> - Disables the use of jar files to capture cookies.</li>\n");
506 #endif /* ndef JAR_FILES */
508 #ifdef FAST_REDIRECTS
509 b = strsav(b, " <li><code>#define <b>FAST_REDIRECTS</b></code> - Enables intercepting remote script redirects.</li>\n");
510 #else /* ifndef FAST_REDIRECTS */
511 b = strsav(b, " <li><code>#undef <b>FAST_REDIRECTS</b></code> - Disables intercepting remote script redirects.</li>\n");
512 #endif ndef /* FAST_REDIRECTS */
514 b = strsav(b, "</ul>\n<br>\n");
517 "<small><small><p>\n"
518 "The " BANNER " Proxy - \n"
519 "<a href=\"" HOME_PAGE_URL "\">" HOME_PAGE_URL "</a><p>\n"
520 "Copyright © 2001 <a href=\"" HOME_PAGE_URL "\">the SourceForge IJBSWA team</a><br>\n"
521 "Copyright © 1997 <a href=\"http://www.junkbusters.com/\">\n" "Junkbusters Corporation</a><br>\n"
522 "Copying and distribution permitted under the "
523 "<a href=\"http://www.gnu.org/copyleft/gpl.html\">GNU General Public License.</a>\n"
528 proxy_args->trailer = b;