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