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