1 const char showargs_rcs[] = "$Id: showargs.c,v 1.12 2001/06/04 10:41:52 swa 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.12 2001/06/04 10:41:52 swa
37 * show version string of cgi.h and cgi.c
39 * Revision 1.11 2001/06/03 11:03:48 oes
46 * adapted to new enlist_unique arg format
50 * introduced confdir option
52 * filters.c filtrers.h
54 * extracted-CGI relevant stuff
62 * support for new cgi mechansim
66 * functions for new list type: "map"
67 * extended enlist_unique
74 * deleted const struct interceptors
82 * added struct http_response
83 * changes struct interceptors to struct cgi_dispatcher
84 * moved HTML stuff to cgi.h
93 * Revision 1.10 2001/05/31 21:36:07 jongfoster
94 * Added RCS for actions.[ch] and list.[ch]
96 * Revision 1.9 2001/05/29 23:11:38 oes
98 * - Moved strsav() from showargs to miscutil
100 * Revision 1.8 2001/05/29 09:50:24 jongfoster
101 * Unified blocklist/imagelist/permissionslist.
102 * File format is still under discussion, but the internal changes
105 * Also modified interceptor behaviour:
106 * - We now intercept all URLs beginning with one of the following
107 * prefixes (and *only* these prefixes):
109 * * http://ijbswa.sf.net/config/
110 * * http://ijbswa.sourceforge.net/config/
111 * - New interceptors "home page" - go to http://i.j.b/ to see it.
112 * - Internal changes so that intercepted and fast redirect pages
113 * are not replaced with an image.
114 * - Interceptors now have the option to send a binary page direct
115 * to the client. (i.e. ijb-send-banner uses this)
116 * - Implemented show-url-info interceptor. (Which is why I needed
117 * the above interceptors changes - a typical URL is
118 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
119 * The previous mechanism would not have intercepted that, and
120 * if it had been intercepted then it then it would have replaced
123 * Revision 1.7 2001/05/26 00:28:36 jongfoster
124 * Automatic reloading of config file.
125 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
126 * Most of the global variables have been moved to a new
127 * struct configuration_spec, accessed through csp->config->globalname
128 * Most of the globals remaining are used by the Win32 GUI.
130 * Revision 1.6 2001/05/25 22:32:56 jongfoster
133 * Revision 1.5 2001/05/22 18:54:49 oes
135 * - Enabled filtering banners by size rather than URL
136 * by adding patterns that replace all standard banner
137 * sizes with the "Junkbuster" gif to the re_filterfile
139 * - Enabled filtering WebBugs by providing a pattern
140 * which kills all 1x1 images
142 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
143 * which is selected by the (nonstandard and therefore
144 * capital) letter 'U' in the option string.
145 * It causes the quantifiers to be ungreedy by default.
146 * Appending a ? turns back to greedy (!).
148 * - Added a new interceptor ijb-send-banner, which
149 * sends back the "Junkbuster" gif. Without imagelist or
150 * MSIE detection support, or if tinygif = 1, or the
151 * URL isn't recognized as an imageurl, a lame HTML
152 * explanation is sent instead.
154 * - Added new feature, which permits blocking remote
155 * script redirects and firing back a local redirect
157 * The feature is conditionally compiled, i.e. it
158 * can be disabled with --disable-fast-redirects,
159 * plus it must be activated by a "fast-redirects"
160 * line in the config file, has its own log level
161 * and of course wants to be displayed by show-proxy-args
162 * Note: Boy, all the #ifdefs in 1001 locations and
163 * all the fumbling with configure.in and acconfig.h
164 * were *way* more work than the feature itself :-(
166 * - Because a generic redirect template was needed for
167 * this, tinygif = 3 now uses the same.
169 * - Moved GIFs, and other static HTTP response templates
174 * - Removed some >400 CRs again (Jon, you really worked
177 * Revision 1.4 2001/05/20 16:44:47 jongfoster
178 * Removing last hardcoded JunkBusters.com URLs.
180 * Revision 1.3 2001/05/20 01:21:20 jongfoster
181 * Version 2.9.4 checkin.
182 * - Merged popupfile and cookiefile, and added control over PCRS
183 * filtering, in new "permissionsfile".
184 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
185 * file error you now get a message box (in the Win32 GUI) rather
186 * than the program exiting with no explanation.
187 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
189 * - Removed tabs from "config"
190 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
191 * - Bumped up version number.
193 * Revision 1.2 2001/05/17 23:01:01 oes
194 * - Cleaned CRLF's from the sources and related files
196 * Revision 1.1.1.1 2001/05/15 13:59:03 oes
197 * Initial import of version 2.9.3 source tree
200 *********************************************************************/
206 #include <sys/types.h>
212 #include "showargs.h"
217 #include "miscutil.h"
220 const char showargs_h_rcs[] = SHOWARGS_H_VERSION;
223 /*********************************************************************
227 * Description : Called from `load_config'. It saves each non-empty
228 * and non-comment line from config into a list. This
229 * list is used to create the show-proxy-args page.
232 * 1 : c = config setting that was found
233 * 2 : o = the setting's argument (if any)
237 *********************************************************************/
238 void savearg(char *c, char *o, struct configuration_spec * config)
244 if ( ( NULL != c ) && ( '\0' != *c ) )
246 if ((c = html_encode(c)))
248 sprintf(buf, "<a href=\"" REDIRECT_URL "option#%s\">%s</a> ", c, c);
252 if ( ( NULL != o ) && ( '\0' != *o ) )
254 if ((o = html_encode(o)))
256 if (strncmpic(o, "http://", 7) == 0)
258 strcat(buf, "<a href=\"");
272 strcat(buf, "<br>\n");
274 config->proxy_args_invocation = strsav(config->proxy_args_invocation, buf);
279 /*********************************************************************
281 * Function : init_proxy_args
283 * Description : Create the "top" of the show-proxy-args page.
286 * 1 : argc = argument count (same as in main)
287 * 2 : argv[] = program arguments (same as in main)
291 *********************************************************************/
292 void init_proxy_args(int argc, const char *argv[], struct configuration_spec * config)
294 const struct gateway *g;
298 freez(config->proxy_args_header);
299 freez(config->proxy_args_gateways);
302 for (i=0; i < argc; i++)
304 b = strsav(b, argv[i]);
307 config->proxy_args_header = b;
310 for (g = gateways; g->name; g++)
312 b = strsav(b, g->name);
315 config->proxy_args_gateways = b;
319 /*********************************************************************
321 * Function : end_proxy_args
323 * Description : Create the "bottom" of the show-proxy-args page.
327 * Returns : string with that bottom
329 *********************************************************************/
330 char *end_proxy_args(struct configuration_spec * config)
335 /* Instead of including *all* dot h's in the project (thus creating a
336 * tremendous amount of dependencies), I will concede to declaring them
337 * as extern's. This forces the developer to add to this list, but oh well.
340 #ifndef SPLIT_PROXY_ARGS
341 if (suppress_blocklists && suppress_message!=NULL)
343 b = strsav(b, "<h2>File contents</h2>\n");
344 b = strsav(b, suppress_message);
347 #endif /* ndef SPLIT_PROXY_ARGS */
349 b = strsav(b, "<h2>Source versions:</h2>\n");
350 b = strsav(b, "<pre>");
352 #define SHOW_RCS(__x) \
354 extern const char __x[]; \
355 sprintf(buf, "%s\n", __x); \
356 b = strsav(b, buf); \
359 /* In alphabetical order */
360 SHOW_RCS(actions_h_rcs)
361 SHOW_RCS(actions_rcs)
365 SHOW_RCS(cygwin_h_rcs)
367 SHOW_RCS(encode_h_rcs)
369 SHOW_RCS(errlog_h_rcs)
371 SHOW_RCS(filters_h_rcs)
372 SHOW_RCS(filters_rcs)
373 SHOW_RCS(gateway_h_rcs)
374 SHOW_RCS(gateway_rcs)
376 SHOW_RCS(gnu_regex_h_rcs)
377 SHOW_RCS(gnu_regex_rcs)
378 #endif /* def GNU_REGEX */
379 SHOW_RCS(jbsockets_h_rcs)
380 SHOW_RCS(jbsockets_rcs)
384 SHOW_RCS(killpopup_h_rcs)
385 SHOW_RCS(killpopup_rcs)
386 #endif /* def KILLPOPUPS */
389 SHOW_RCS(loadcfg_h_rcs)
390 SHOW_RCS(loadcfg_rcs)
391 SHOW_RCS(loaders_h_rcs)
392 SHOW_RCS(loaders_rcs)
393 SHOW_RCS(miscutil_h_rcs)
394 SHOW_RCS(miscutil_rcs)
395 SHOW_RCS(parsers_h_rcs)
396 SHOW_RCS(parsers_rcs)
400 #endif /* def PCRS */
401 SHOW_RCS(project_h_rcs)
402 SHOW_RCS(showargs_h_rcs)
403 SHOW_RCS(showargs_rcs)
404 SHOW_RCS(ssplit_h_rcs)
408 SHOW_RCS(w32log_h_rcs)
410 SHOW_RCS(w32res_h_rcs)
411 SHOW_RCS(w32rulesdlg_h_rcs)
412 SHOW_RCS(w32rulesdlg_rcs)
413 SHOW_RCS(w32taskbar_h_rcs)
414 SHOW_RCS(w32taskbar_rcs)
415 #endif /* ndef _WIN_CONSOLE */
416 SHOW_RCS(win32_h_rcs)
418 #endif /* def _WIN32 */
422 b = strsav(b, "</pre>\n");
424 b = strsav(b, "<h2>Conditional defines:</h2>\n<ul>");
427 b = strsav(b, " <li><code>#define <b>REGEX</b></code> - Support for regular expressions in the path specs.</li>\n");
428 #else /* ifndef REGEX */
429 b = strsav(b, " <li><code>#undef <b>REGEX</b></code> - No support for regular expressions in the path specs.</li>\n");
430 #endif /* ndef REGEX */
433 b = strsav(b, " <li><code>#define <b>PCRE</b></code> - Use PCRE rather than old GNU regex library.</li>\n");
434 #else /* ifndef PCRE */
435 b = strsav(b, " <li><code>#undef <b>PCRE</b></code> - Use old GNU regex library rather than PCRE.</li>\n");
436 #endif /* ndef PCRE */
439 b = strsav(b, " <li><code>#define <b>PCRS</b></code> - Enables arbitrary content modification regexps.</li>\n");
440 #else /* ifndef PCRS */
441 b = strsav(b, " <li><code>#undef <b>PCRS</b></code> - Disables arbitrary content modification regexps.</li>\n");
442 #endif /* ndef PCRS */
445 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");
446 #else /* ifndef TOGGLE */
447 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");
448 #endif /* ndef TOGGLE */
451 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");
452 #else /* ifndef FORCE_LOAD */
453 b = strsav(b, " <li><code>#undef <b>FORCE_LOAD</b></code> - Disables bypassing filtering for a single page.</li>\n");
454 #endif /* ndef FORCE_LOAD */
457 b = strsav(b, " <li><code>#define <b>DENY_GZIP</b></code> - Prevents requests from being compressed - required for PCRS.</li>\n");
458 #else /* ifndef DENY_GZIP */
459 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");
460 #endif /* ndef DENY_GZIP */
463 b = strsav(b, " <li><code>#define <b>STATISTICS</b></code> - Enables statistics function.</li>\n");
464 #else /* ifndef STATISTICS */
465 b = strsav(b, " <li><code>#undef <b>STATISTICS</b></code> - Disables statistics function.</li>\n");
466 #endif /* ndef STATISTICS */
468 #ifdef SPLIT_PROXY_ARGS
469 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");
470 #else /* ifndef SPLIT_PROXY_ARGS */
471 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");
472 #endif /* ndef SPLIT_PROXY_ARGS */
475 b = strsav(b, " <li><code>#define <b>KILLPOPUPS</b></code> - Enables killing JavaScript popups.</li>\n");
476 #else /* ifndef KILLPOPUPS */
477 b = strsav(b, " <li><code>#undef <b>KILLPOPUPS</b></code> - Disables killing JavaScript popups.</li>\n");
478 #endif /* ndef KILLPOPUPS */
481 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");
482 #else /* ifndef WEBDAV */
483 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");
484 #endif /* ndef WEBDAV */
486 #ifdef DETECT_MSIE_IMAGES
487 b = strsav(b, " <li><code>#define <b>DETECT_MSIE_IMAGES</b></code> - Enables detecting image requests automatically for MSIE.</li>\n");
488 #else /* ifndef DETECT_MSIE_IMAGES */
489 b = strsav(b, " <li><code>#undef <b>DETECT_MSIE_IMAGES</b></code> - Disables detecting image requests automatically for MSIE.</li>\n");
490 #endif /* ndef DETECT_MSIE_IMAGES */
492 #ifdef IMAGE_BLOCKING
493 b = strsav(b, " <li><code>#define <b>IMAGE_BLOCKING</b></code> - Enables sending \"blocked\" images instead of HTML.</li>\n");
494 #else /* ifndef IMAGE_BLOCKING */
495 b = strsav(b, " <li><code>#undef <b>IMAGE_BLOCKING</b></code> - Disables sending \"blocked\" images instead of HTML.</li>\n");
496 #endif /* ndef IMAGE_BLOCKING */
499 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");
500 #else /* ifndef ACL_FILES */
501 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");
502 #endif /* ndef ACL_FILES */
505 b = strsav(b, " <li><code>#define <b>TRUST_FILES</b></code> - Enables the use of trust files.</li>\n");
506 #else /* ifndef TRUST_FILES */
507 b = strsav(b, " <li><code>#undef <b>TRUST_FILES</b></code> - Disables the use of trust files.</li>\n");
508 #endif /* ndef TRUST_FILES */
511 b = strsav(b, " <li><code>#define <b>JAR_FILES</b></code> - Enables the use of jar files to capture cookies.</li>\n");
512 #else /* ifndef JAR_FILES */
513 b = strsav(b, " <li><code>#undef <b>JAR_FILES</b></code> - Disables the use of jar files to capture cookies.</li>\n");
514 #endif /* ndef JAR_FILES */
516 #ifdef FAST_REDIRECTS
517 b = strsav(b, " <li><code>#define <b>FAST_REDIRECTS</b></code> - Enables intercepting remote script redirects.</li>\n");
518 #else /* ifndef FAST_REDIRECTS */
519 b = strsav(b, " <li><code>#undef <b>FAST_REDIRECTS</b></code> - Disables intercepting remote script redirects.</li>\n");
520 #endif /* ndef FAST_REDIRECTS */
522 b = strsav(b, "</ul>\n<br>\n");
524 config->proxy_args_trailer = b;