- Added Convenience function enlist_unique_header(),
[privoxy.git] / showargs.c
1 const char showargs_rcs[] = "$Id: showargs.c,v 1.14 2001/06/07 23:15:40 jongfoster 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.14  2001/06/07 23:15:40  jongfoster
37  *    Removing config->proxy_args_gateways
38  *    Missing return statement added to end_proxy_args().
39  *
40  *    Revision 1.13  2001/06/06 09:37:59  sarantis
41  *    Fix misplaced comment start.
42  *
43  *    Revision 1.12  2001/06/04 10:41:52  swa
44  *    show version string of cgi.h and cgi.c
45  *
46  *    Revision 1.11  2001/06/03 11:03:48  oes
47  *    Makefile/in
48  *
49  *    introduced cgi.c
50  *
51  *    actions.c:
52  *
53  *    adapted to new enlist_unique arg format
54  *
55  *    conf loadcfg.c
56  *
57  *    introduced confdir option
58  *
59  *    filters.c filtrers.h
60  *
61  *     extracted-CGI relevant stuff
62  *
63  *    jbsockets.c
64  *
65  *     filled comment
66  *
67  *    jcc.c
68  *
69  *     support for new cgi mechansim
70  *
71  *    list.c list.h
72  *
73  *    functions for new list type: "map"
74  *    extended enlist_unique
75  *
76  *    miscutil.c .h
77  *    introduced bindup()
78  *
79  *    parsers.c parsers.h
80  *
81  *    deleted const struct interceptors
82  *
83  *    pcrs.c
84  *    added FIXME
85  *
86  *    project.h
87  *
88  *    added struct map
89  *    added struct http_response
90  *    changes struct interceptors to struct cgi_dispatcher
91  *    moved HTML stuff to cgi.h
92  *
93  *    re_filterfile:
94  *
95  *    changed
96  *
97  *    showargs.c
98  *    NO TIME LEFT
99  *
100  *    Revision 1.10  2001/05/31 21:36:07  jongfoster
101  *    Added RCS for actions.[ch] and list.[ch]
102  *
103  *    Revision 1.9  2001/05/29 23:11:38  oes
104  *
105  *     - Moved strsav() from showargs to miscutil
106  *
107  *    Revision 1.8  2001/05/29 09:50:24  jongfoster
108  *    Unified blocklist/imagelist/permissionslist.
109  *    File format is still under discussion, but the internal changes
110  *    are (mostly) done.
111  *
112  *    Also modified interceptor behaviour:
113  *    - We now intercept all URLs beginning with one of the following
114  *      prefixes (and *only* these prefixes):
115  *        * http://i.j.b/
116  *        * http://ijbswa.sf.net/config/
117  *        * http://ijbswa.sourceforge.net/config/
118  *    - New interceptors "home page" - go to http://i.j.b/ to see it.
119  *    - Internal changes so that intercepted and fast redirect pages
120  *      are not replaced with an image.
121  *    - Interceptors now have the option to send a binary page direct
122  *      to the client. (i.e. ijb-send-banner uses this)
123  *    - Implemented show-url-info interceptor.  (Which is why I needed
124  *      the above interceptors changes - a typical URL is
125  *      "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
126  *      The previous mechanism would not have intercepted that, and
127  *      if it had been intercepted then it then it would have replaced
128  *      it with an image.)
129  *
130  *    Revision 1.7  2001/05/26 00:28:36  jongfoster
131  *    Automatic reloading of config file.
132  *    Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
133  *    Most of the global variables have been moved to a new
134  *    struct configuration_spec, accessed through csp->config->globalname
135  *    Most of the globals remaining are used by the Win32 GUI.
136  *
137  *    Revision 1.6  2001/05/25 22:32:56  jongfoster
138  *    CRLF->LF
139  *
140  *    Revision 1.5  2001/05/22 18:54:49  oes
141  *
142  *    - Enabled filtering banners by size rather than URL
143  *      by adding patterns that replace all standard banner
144  *      sizes with the "Junkbuster" gif to the re_filterfile
145  *
146  *    - Enabled filtering WebBugs by providing a pattern
147  *      which kills all 1x1 images
148  *
149  *    - Added support for PCRE_UNGREEDY behaviour to pcrs,
150  *      which is selected by the (nonstandard and therefore
151  *      capital) letter 'U' in the option string.
152  *      It causes the quantifiers to be ungreedy by default.
153  *      Appending a ? turns back to greedy (!).
154  *
155  *    - Added a new interceptor ijb-send-banner, which
156  *      sends back the "Junkbuster" gif. Without imagelist or
157  *      MSIE detection support, or if tinygif = 1, or the
158  *      URL isn't recognized as an imageurl, a lame HTML
159  *      explanation is sent instead.
160  *
161  *    - Added new feature, which permits blocking remote
162  *      script redirects and firing back a local redirect
163  *      to the browser.
164  *      The feature is conditionally compiled, i.e. it
165  *      can be disabled with --disable-fast-redirects,
166  *      plus it must be activated by a "fast-redirects"
167  *      line in the config file, has its own log level
168  *      and of course wants to be displayed by show-proxy-args
169  *      Note: Boy, all the #ifdefs in 1001 locations and
170  *      all the fumbling with configure.in and acconfig.h
171  *      were *way* more work than the feature itself :-(
172  *
173  *    - Because a generic redirect template was needed for
174  *      this, tinygif = 3 now uses the same.
175  *
176  *    - Moved GIFs, and other static HTTP response templates
177  *      to project.h
178  *
179  *    - Some minor fixes
180  *
181  *    - Removed some >400 CRs again (Jon, you really worked
182  *      a lot! ;-)
183  *
184  *    Revision 1.4  2001/05/20 16:44:47  jongfoster
185  *    Removing last hardcoded JunkBusters.com URLs.
186  *
187  *    Revision 1.3  2001/05/20 01:21:20  jongfoster
188  *    Version 2.9.4 checkin.
189  *    - Merged popupfile and cookiefile, and added control over PCRS
190  *      filtering, in new "permissionsfile".
191  *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
192  *      file error you now get a message box (in the Win32 GUI) rather
193  *      than the program exiting with no explanation.
194  *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
195  *      skipping.
196  *    - Removed tabs from "config"
197  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
198  *    - Bumped up version number.
199  *
200  *    Revision 1.2  2001/05/17 23:01:01  oes
201  *     - Cleaned CRLF's from the sources and related files
202  *
203  *    Revision 1.1.1.1  2001/05/15 13:59:03  oes
204  *    Initial import of version 2.9.3 source tree
205  *
206  *
207  *********************************************************************/
208 \f
209 #include "config.h"
210
211 #include <stdio.h>
212 #include <stdlib.h>
213 #include <sys/types.h>
214 #include <string.h>
215 #include <malloc.h>
216 #include <errno.h>
217
218 #include "project.h"
219 #include "showargs.h"
220 #include "jcc.h"
221 #include "encode.h"
222 #include "parsers.h"
223 #include "errlog.h"
224 #include "miscutil.h"
225 #include "gateway.h"
226
227 const char showargs_h_rcs[] = SHOWARGS_H_VERSION;
228
229
230 /*********************************************************************
231  *
232  * Function    :  savearg
233  *
234  * Description :  Called from `load_config'.  It saves each non-empty
235  *                and non-comment line from config into a list.  This
236  *                list is used to create the show-proxy-args page.
237  *
238  * Parameters  :
239  *          1  :  c = config setting that was found
240  *          2  :  o = the setting's argument (if any)
241  *
242  * Returns     :  N/A
243  *
244  *********************************************************************/
245 void savearg(char *c, char *o, struct configuration_spec * config)
246 {
247    char buf[BUFFER_SIZE];
248
249    *buf = '\0';
250
251    if ( ( NULL != c ) && ( '\0' != *c ) )
252    {
253       if ((c = html_encode(c)))
254       {
255          sprintf(buf, "<a href=\"" REDIRECT_URL "option#%s\">%s</a> ", c, c);
256       }
257       freez(c);
258    }
259    if ( ( NULL != o ) && ( '\0' != *o ) )
260    {
261       if ((o = html_encode(o)))
262       {
263          if (strncmpic(o, "http://", 7) == 0)
264          {
265             strcat(buf, "<a href=\"");
266             strcat(buf, o);
267             strcat(buf, "\">");
268             strcat(buf, o);
269             strcat(buf, "</a>");
270          }
271          else
272          {
273             strcat(buf, o);
274          }
275       }
276       freez(o);
277    }
278
279    strcat(buf, "<br>\n");
280
281    config->proxy_args_invocation = strsav(config->proxy_args_invocation, buf);
282
283 }
284
285
286 /*********************************************************************
287  *
288  * Function    :  init_proxy_args
289  *
290  * Description :  Create the "top" of the show-proxy-args page.
291  *
292  * Parameters  :
293  *          1  :  argc = argument count (same as in main)
294  *          2  :  argv[] = program arguments (same as in main)
295  *
296  * Returns     :  N/A
297  *
298  *********************************************************************/
299 void init_proxy_args(int argc, const char *argv[], struct configuration_spec * config)
300 {
301    char * b = NULL;
302    int i;
303
304    freez(config->proxy_args_header);
305  
306    
307    for (i=0; i < argc; i++)
308    {
309       b = strsav(b, argv[i]);
310       b = strsav(b, " ");
311    }
312    config->proxy_args_header = b;
313 }
314
315
316 /*********************************************************************
317  *
318  * Function    :  end_proxy_args
319  *
320  * Description :  Create the "bottom" of the show-proxy-args page.
321  *
322  * Parameters  :  None
323  *
324  * Returns     :  string with that bottom
325  *
326  *********************************************************************/
327 char *end_proxy_args(struct configuration_spec * config)
328 {
329    char *b = NULL;
330    char buf[BUFFER_SIZE];
331
332    /* Instead of including *all* dot h's in the project (thus creating a
333     * tremendous amount of dependencies), I will concede to declaring them
334     * as extern's.  This forces the developer to add to this list, but oh well.
335     */
336
337 #ifndef SPLIT_PROXY_ARGS
338    if (suppress_blocklists && suppress_message!=NULL)
339    {
340       b = strsav(b, "<h2>File contents</h2>\n");
341       b = strsav(b, suppress_message);
342       b = strsav(b, "\n");
343    }
344 #endif /* ndef SPLIT_PROXY_ARGS */
345
346    b = strsav(b, "<h2>Source versions:</h2>\n");
347    b = strsav(b, "<pre>");
348
349 #define SHOW_RCS(__x)            \
350    {                             \
351       extern const char __x[];   \
352       sprintf(buf, "%s\n", __x); \
353       b = strsav(b, buf);        \
354    }
355
356    /* In alphabetical order */
357    SHOW_RCS(actions_h_rcs)
358    SHOW_RCS(actions_rcs)
359    SHOW_RCS(cgi_h_rcs)
360    SHOW_RCS(cgi_rcs)
361 #ifdef __MINGW32__
362    SHOW_RCS(cygwin_h_rcs)
363 #endif
364    SHOW_RCS(encode_h_rcs)
365    SHOW_RCS(encode_rcs)
366    SHOW_RCS(errlog_h_rcs)
367    SHOW_RCS(errlog_rcs)
368    SHOW_RCS(filters_h_rcs)
369    SHOW_RCS(filters_rcs)
370    SHOW_RCS(gateway_h_rcs)
371    SHOW_RCS(gateway_rcs)
372 #ifdef GNU_REGEX
373    SHOW_RCS(gnu_regex_h_rcs)
374    SHOW_RCS(gnu_regex_rcs)
375 #endif /* def GNU_REGEX */
376    SHOW_RCS(jbsockets_h_rcs)
377    SHOW_RCS(jbsockets_rcs)
378    SHOW_RCS(jcc_h_rcs)
379    SHOW_RCS(jcc_rcs)
380 #ifdef KILLPOPUPS
381    SHOW_RCS(killpopup_h_rcs)
382    SHOW_RCS(killpopup_rcs)
383 #endif /* def KILLPOPUPS */
384    SHOW_RCS(list_h_rcs)
385    SHOW_RCS(list_rcs)
386    SHOW_RCS(loadcfg_h_rcs)
387    SHOW_RCS(loadcfg_rcs)
388    SHOW_RCS(loaders_h_rcs)
389    SHOW_RCS(loaders_rcs)
390    SHOW_RCS(miscutil_h_rcs)
391    SHOW_RCS(miscutil_rcs)
392    SHOW_RCS(parsers_h_rcs)
393    SHOW_RCS(parsers_rcs)
394 #ifdef PCRS
395    SHOW_RCS(pcrs_rcs)
396    SHOW_RCS(pcrs_h_rcs)
397 #endif /* def PCRS */
398    SHOW_RCS(project_h_rcs)
399    SHOW_RCS(showargs_h_rcs)
400    SHOW_RCS(showargs_rcs)
401    SHOW_RCS(ssplit_h_rcs)
402    SHOW_RCS(ssplit_rcs)
403 #ifdef _WIN32
404 #ifndef _WIN_CONSOLE
405    SHOW_RCS(w32log_h_rcs)
406    SHOW_RCS(w32log_rcs)
407    SHOW_RCS(w32res_h_rcs)
408    SHOW_RCS(w32rulesdlg_h_rcs)
409    SHOW_RCS(w32rulesdlg_rcs)
410    SHOW_RCS(w32taskbar_h_rcs)
411    SHOW_RCS(w32taskbar_rcs)
412 #endif /* ndef _WIN_CONSOLE */
413    SHOW_RCS(win32_h_rcs)
414    SHOW_RCS(win32_rcs)
415 #endif /* def _WIN32 */
416
417 #undef SHOW_RCS
418
419    b = strsav(b, "</pre>\n");
420
421    b = strsav(b, "<h2>Conditional defines:</h2>\n<ul>");
422
423 #ifdef REGEX
424    b = strsav(b, "  <li><code>#define <b>REGEX</b></code> - Support for regular expressions in the path specs.</li>\n");
425 #else /* ifndef REGEX */
426    b = strsav(b, "  <li><code>#undef <b>REGEX</b></code> - No support for regular expressions in the path specs.</li>\n");
427 #endif /* ndef REGEX */
428
429 #ifdef PCRE
430    b = strsav(b, "  <li><code>#define <b>PCRE</b></code> - Use PCRE rather than old GNU regex library.</li>\n");
431 #else /* ifndef PCRE */
432    b = strsav(b, "  <li><code>#undef <b>PCRE</b></code> - Use old GNU regex library rather than PCRE.</li>\n");
433 #endif /* ndef PCRE */
434
435 #ifdef PCRS
436    b = strsav(b, "  <li><code>#define <b>PCRS</b></code> - Enables arbitrary content modification regexps.</li>\n");
437 #else /* ifndef PCRS */
438    b = strsav(b, "  <li><code>#undef <b>PCRS</b></code> - Disables arbitrary content modification regexps.</li>\n");
439 #endif /* ndef PCRS */
440
441 #ifdef TOGGLE
442    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");
443 #else /* ifndef TOGGLE */
444    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");
445 #endif /* ndef TOGGLE */
446
447 #ifdef FORCE_LOAD
448    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");
449 #else /* ifndef FORCE_LOAD */
450    b = strsav(b, "  <li><code>#undef <b>FORCE_LOAD</b></code> - Disables bypassing filtering for a single page.</li>\n");
451 #endif /* ndef FORCE_LOAD */
452
453 #ifdef DENY_GZIP
454    b = strsav(b, "  <li><code>#define <b>DENY_GZIP</b></code> - Prevents requests from being compressed - required for PCRS.</li>\n");
455 #else /* ifndef DENY_GZIP */
456    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");
457 #endif /* ndef DENY_GZIP */
458
459 #ifdef STATISTICS
460    b = strsav(b, "  <li><code>#define <b>STATISTICS</b></code> - Enables statistics function.</li>\n");
461 #else /* ifndef STATISTICS */
462    b = strsav(b, "  <li><code>#undef <b>STATISTICS</b></code> - Disables statistics function.</li>\n");
463 #endif /* ndef STATISTICS */
464
465 #ifdef SPLIT_PROXY_ARGS
466    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");
467 #else /* ifndef SPLIT_PROXY_ARGS */
468    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");
469 #endif /* ndef SPLIT_PROXY_ARGS */
470
471 #ifdef KILLPOPUPS
472    b = strsav(b, "  <li><code>#define <b>KILLPOPUPS</b></code> - Enables killing JavaScript popups.</li>\n");
473 #else /* ifndef KILLPOPUPS */
474    b = strsav(b, "  <li><code>#undef <b>KILLPOPUPS</b></code> - Disables killing JavaScript popups.</li>\n");
475 #endif /* ndef KILLPOPUPS */
476
477 #ifdef WEBDAV
478    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");
479 #else /* ifndef WEBDAV */
480    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");
481 #endif /* ndef WEBDAV */
482
483 #ifdef DETECT_MSIE_IMAGES
484    b = strsav(b, "  <li><code>#define <b>DETECT_MSIE_IMAGES</b></code> - Enables detecting image requests automatically for MSIE.</li>\n");
485 #else /* ifndef DETECT_MSIE_IMAGES */
486    b = strsav(b, "  <li><code>#undef <b>DETECT_MSIE_IMAGES</b></code> - Disables detecting image requests automatically for MSIE.</li>\n");
487 #endif /* ndef DETECT_MSIE_IMAGES */
488
489 #ifdef IMAGE_BLOCKING
490    b = strsav(b, "  <li><code>#define <b>IMAGE_BLOCKING</b></code> - Enables sending \"blocked\" images instead of HTML.</li>\n");
491 #else /* ifndef IMAGE_BLOCKING */
492    b = strsav(b, "  <li><code>#undef <b>IMAGE_BLOCKING</b></code> - Disables sending \"blocked\" images instead of HTML.</li>\n");
493 #endif /* ndef IMAGE_BLOCKING */
494
495 #ifdef ACL_FILES
496    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");
497 #else /* ifndef ACL_FILES */
498    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");
499 #endif /* ndef ACL_FILES */
500
501 #ifdef TRUST_FILES
502    b = strsav(b, "  <li><code>#define <b>TRUST_FILES</b></code> - Enables the use of trust files.</li>\n");
503 #else /* ifndef TRUST_FILES */
504    b = strsav(b, "  <li><code>#undef <b>TRUST_FILES</b></code> - Disables the use of trust files.</li>\n");
505 #endif /* ndef TRUST_FILES */
506
507 #ifdef JAR_FILES
508    b = strsav(b, "  <li><code>#define <b>JAR_FILES</b></code> - Enables the use of jar files to capture cookies.</li>\n");
509 #else /* ifndef JAR_FILES */
510    b = strsav(b, "  <li><code>#undef <b>JAR_FILES</b></code> - Disables the use of jar files to capture cookies.</li>\n");
511 #endif /* ndef JAR_FILES */
512
513 #ifdef FAST_REDIRECTS
514    b = strsav(b, "  <li><code>#define <b>FAST_REDIRECTS</b></code> - Enables intercepting remote script redirects.</li>\n");
515 #else /* ifndef FAST_REDIRECTS */
516    b = strsav(b, "  <li><code>#undef <b>FAST_REDIRECTS</b></code> - Disables intercepting remote script redirects.</li>\n");
517 #endif /* ndef FAST_REDIRECTS */
518
519    b = strsav(b, "</ul>\n<br>\n");
520
521    config->proxy_args_trailer = b;
522
523    return b;
524 }
525
526
527 /*
528   Local Variables:
529   tab-width: 3
530   end:
531 */