Cosmetic indentation changes.
[privoxy.git] / showargs.c
1 const char showargs_rcs[] = "$Id: showargs.c,v 1.12 2001/06/04 10:41:52 swa Exp $";
2 /*********************************************************************
3  *
4  * File        :  $Source: /cvsroot/ijbswa/current/showargs.c,v $
5  *
6  * Purpose     :  Contains various utility routines needed to 
7  *                generate the show-proxy-args page.
8  *
9  * Copyright   :  Written by and Copyright (C) 2001 the SourceForge
10  *                IJBSWA team.  http://ijbswa.sourceforge.net
11  *
12  *                Based on the Internet Junkbuster originally written
13  *                by and Copyright (C) 1997 Anonymous Coders and 
14  *                Junkbusters Corporation.  http://www.junkbusters.com
15  *
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.
21  *
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.
27  *
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.
33  *
34  * Revisions   :
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
38  *
39  *    Revision 1.11  2001/06/03 11:03:48  oes
40  *    Makefile/in
41  *
42  *    introduced cgi.c
43  *
44  *    actions.c:
45  *
46  *    adapted to new enlist_unique arg format
47  *
48  *    conf loadcfg.c
49  *
50  *    introduced confdir option
51  *
52  *    filters.c filtrers.h
53  *
54  *     extracted-CGI relevant stuff
55  *
56  *    jbsockets.c
57  *
58  *     filled comment
59  *
60  *    jcc.c
61  *
62  *     support for new cgi mechansim
63  *
64  *    list.c list.h
65  *
66  *    functions for new list type: "map"
67  *    extended enlist_unique
68  *
69  *    miscutil.c .h
70  *    introduced bindup()
71  *
72  *    parsers.c parsers.h
73  *
74  *    deleted const struct interceptors
75  *
76  *    pcrs.c
77  *    added FIXME
78  *
79  *    project.h
80  *
81  *    added struct map
82  *    added struct http_response
83  *    changes struct interceptors to struct cgi_dispatcher
84  *    moved HTML stuff to cgi.h
85  *
86  *    re_filterfile:
87  *
88  *    changed
89  *
90  *    showargs.c
91  *    NO TIME LEFT
92  *
93  *    Revision 1.10  2001/05/31 21:36:07  jongfoster
94  *    Added RCS for actions.[ch] and list.[ch]
95  *
96  *    Revision 1.9  2001/05/29 23:11:38  oes
97  *
98  *     - Moved strsav() from showargs to miscutil
99  *
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
103  *    are (mostly) done.
104  *
105  *    Also modified interceptor behaviour:
106  *    - We now intercept all URLs beginning with one of the following
107  *      prefixes (and *only* these prefixes):
108  *        * http://i.j.b/
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
121  *      it with an image.)
122  *
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.
129  *
130  *    Revision 1.6  2001/05/25 22:32:56  jongfoster
131  *    CRLF->LF
132  *
133  *    Revision 1.5  2001/05/22 18:54:49  oes
134  *
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
138  *
139  *    - Enabled filtering WebBugs by providing a pattern
140  *      which kills all 1x1 images
141  *
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 (!).
147  *
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.
153  *
154  *    - Added new feature, which permits blocking remote
155  *      script redirects and firing back a local redirect
156  *      to the browser.
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 :-(
165  *
166  *    - Because a generic redirect template was needed for
167  *      this, tinygif = 3 now uses the same.
168  *
169  *    - Moved GIFs, and other static HTTP response templates
170  *      to project.h
171  *
172  *    - Some minor fixes
173  *
174  *    - Removed some >400 CRs again (Jon, you really worked
175  *      a lot! ;-)
176  *
177  *    Revision 1.4  2001/05/20 16:44:47  jongfoster
178  *    Removing last hardcoded JunkBusters.com URLs.
179  *
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
188  *      skipping.
189  *    - Removed tabs from "config"
190  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
191  *    - Bumped up version number.
192  *
193  *    Revision 1.2  2001/05/17 23:01:01  oes
194  *     - Cleaned CRLF's from the sources and related files
195  *
196  *    Revision 1.1.1.1  2001/05/15 13:59:03  oes
197  *    Initial import of version 2.9.3 source tree
198  *
199  *
200  *********************************************************************/
201 \f
202 #include "config.h"
203
204 #include <stdio.h>
205 #include <stdlib.h>
206 #include <sys/types.h>
207 #include <string.h>
208 #include <malloc.h>
209 #include <errno.h>
210
211 #include "project.h"
212 #include "showargs.h"
213 #include "jcc.h"
214 #include "encode.h"
215 #include "parsers.h"
216 #include "errlog.h"
217 #include "miscutil.h"
218 #include "gateway.h"
219
220 const char showargs_h_rcs[] = SHOWARGS_H_VERSION;
221
222
223 /*********************************************************************
224  *
225  * Function    :  savearg
226  *
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.
230  *
231  * Parameters  :
232  *          1  :  c = config setting that was found
233  *          2  :  o = the setting's argument (if any)
234  *
235  * Returns     :  N/A
236  *
237  *********************************************************************/
238 void savearg(char *c, char *o, struct configuration_spec * config)
239 {
240    char buf[BUFSIZ];
241
242    *buf = '\0';
243
244    if ( ( NULL != c ) && ( '\0' != *c ) )
245    {
246       if ((c = html_encode(c)))
247       {
248          sprintf(buf, "<a href=\"" REDIRECT_URL "option#%s\">%s</a> ", c, c);
249       }
250       freez(c);
251    }
252    if ( ( NULL != o ) && ( '\0' != *o ) )
253    {
254       if ((o = html_encode(o)))
255       {
256          if (strncmpic(o, "http://", 7) == 0)
257          {
258             strcat(buf, "<a href=\"");
259             strcat(buf, o);
260             strcat(buf, "\">");
261             strcat(buf, o);
262             strcat(buf, "</a>");
263          }
264          else
265          {
266             strcat(buf, o);
267          }
268       }
269       freez(o);
270    }
271
272    strcat(buf, "<br>\n");
273
274    config->proxy_args_invocation = strsav(config->proxy_args_invocation, buf);
275
276 }
277
278
279 /*********************************************************************
280  *
281  * Function    :  init_proxy_args
282  *
283  * Description :  Create the "top" of the show-proxy-args page.
284  *
285  * Parameters  :
286  *          1  :  argc = argument count (same as in main)
287  *          2  :  argv[] = program arguments (same as in main)
288  *
289  * Returns     :  N/A
290  *
291  *********************************************************************/
292 void init_proxy_args(int argc, const char *argv[], struct configuration_spec * config)
293 {
294    const struct gateway *g;
295    char * b = NULL;
296    int i;
297
298    freez(config->proxy_args_header);
299    freez(config->proxy_args_gateways);
300  
301    
302    for (i=0; i < argc; i++)
303    {
304       b = strsav(b, argv[i]);
305       b = strsav(b, " ");
306    }
307    config->proxy_args_header = b;
308  
309    b = NULL;
310    for (g = gateways; g->name; g++)
311    {
312       b = strsav(b, g->name);
313       b = strsav(b, " ");
314    }
315    config->proxy_args_gateways = b;
316 }
317
318
319 /*********************************************************************
320  *
321  * Function    :  end_proxy_args
322  *
323  * Description :  Create the "bottom" of the show-proxy-args page.
324  *
325  * Parameters  :  None
326  *
327  * Returns     :  string with that bottom
328  *
329  *********************************************************************/
330 char *end_proxy_args(struct configuration_spec * config)
331 {
332    char *b = NULL;
333    char buf[BUFSIZ];
334
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.
338     */
339
340 #ifndef SPLIT_PROXY_ARGS
341    if (suppress_blocklists && suppress_message!=NULL)
342    {
343       b = strsav(b, "<h2>File contents</h2>\n");
344       b = strsav(b, suppress_message);
345       b = strsav(b, "\n");
346    }
347 #endif /* ndef SPLIT_PROXY_ARGS */
348
349    b = strsav(b, "<h2>Source versions:</h2>\n");
350    b = strsav(b, "<pre>");
351
352 #define SHOW_RCS(__x)            \
353    {                             \
354       extern const char __x[];   \
355       sprintf(buf, "%s\n", __x); \
356       b = strsav(b, buf);        \
357    }
358
359    /* In alphabetical order */
360    SHOW_RCS(actions_h_rcs)
361    SHOW_RCS(actions_rcs)
362    SHOW_RCS(cgi_h_rcs)
363    SHOW_RCS(cgi_rcs)
364 #ifdef __MINGW32__
365    SHOW_RCS(cygwin_h_rcs)
366 #endif
367    SHOW_RCS(encode_h_rcs)
368    SHOW_RCS(encode_rcs)
369    SHOW_RCS(errlog_h_rcs)
370    SHOW_RCS(errlog_rcs)
371    SHOW_RCS(filters_h_rcs)
372    SHOW_RCS(filters_rcs)
373    SHOW_RCS(gateway_h_rcs)
374    SHOW_RCS(gateway_rcs)
375 #ifdef GNU_REGEX
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)
381    SHOW_RCS(jcc_h_rcs)
382    SHOW_RCS(jcc_rcs)
383 #ifdef KILLPOPUPS
384    SHOW_RCS(killpopup_h_rcs)
385    SHOW_RCS(killpopup_rcs)
386 #endif /* def KILLPOPUPS */
387    SHOW_RCS(list_h_rcs)
388    SHOW_RCS(list_rcs)
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)
397 #ifdef PCRS
398    SHOW_RCS(pcrs_rcs)
399    SHOW_RCS(pcrs_h_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)
405    SHOW_RCS(ssplit_rcs)
406 #ifdef _WIN32
407 #ifndef _WIN_CONSOLE
408    SHOW_RCS(w32log_h_rcs)
409    SHOW_RCS(w32log_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)
417    SHOW_RCS(win32_rcs)
418 #endif /* def _WIN32 */
419
420 #undef SHOW_RCS
421
422    b = strsav(b, "</pre>\n");
423
424    b = strsav(b, "<h2>Conditional defines:</h2>\n<ul>");
425
426 #ifdef REGEX
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 */
431
432 #ifdef PCRE
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 */
437
438 #ifdef PCRS
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 */
443
444 #ifdef TOGGLE
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 */
449
450 #ifdef FORCE_LOAD
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 */
455
456 #ifdef DENY_GZIP
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 */
461
462 #ifdef STATISTICS
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 */
467
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 */
473
474 #ifdef KILLPOPUPS
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 */
479
480 #ifdef WEBDAV
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 */
485
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 */
491
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 */
497
498 #ifdef ACL_FILES
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 */
503
504 #ifdef TRUST_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 */
509
510 #ifdef JAR_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 */
515
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 */
521
522    b = strsav(b, "</ul>\n<br>\n");
523
524    config->proxy_args_trailer = b;
525
526 }
527
528
529 /*
530   Local Variables:
531   tab-width: 3
532   end:
533 */