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