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