First version of CGI-based edit interface. This is very much a
[privoxy.git] / showargs.c
1 const char showargs_rcs[] = "$Id: showargs.c,v 1.24 2001/08/05 16:06:20 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.24  2001/08/05 16:06:20  jongfoster
38  *    Modifiying "struct map" so that there are now separate header and
39  *    "map_entry" structures.  This means that functions which modify a
40  *    map no longer need to return a pointer to the modified map.
41  *    Also, it no longer reverses the order of the entries (which may be
42  *    important with some advanced template substitutions).
43  *
44  *    Revision 1.23  2001/08/02 22:03:23  jongfoster
45  *    Fixing an unterminated character constant.
46  *
47  *    Revision 1.22  2001/08/01 00:20:57  jongfoster
48  *    Changing show_defines so that it doesn't contain any HTML.
49  *
50  *    Revision 1.21  2001/07/30 22:08:36  jongfoster
51  *    Tidying up #defines:
52  *    - All feature #defines are now of the form FEATURE_xxx
53  *    - Permanently turned off WIN_GUI_EDIT
54  *    - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
55  *
56  *    Revision 1.20  2001/07/18 17:27:22  oes
57  *    Adapted to new #defines
58  *
59  *    Revision 1.19  2001/07/13 14:11:36  oes
60  *     - Included SHOW_RCS for deanimate.*
61  *     - Removed all #ifdef PCRS
62  *
63  *
64  *    Revision 1.18  2001/07/02 02:55:16  iwanttokeepanon
65  *    Apended " on some sites" to the HTML generating function `show_defines' (@ line
66  *    392); since "DENY_GZIP" is not *really* necessary for all PCRS functionallity.
67  *
68  *    Revision 1.17  2001/06/29 21:45:41  oes
69  *    Indentation, CRLF->LF, Tab-> Space
70  *
71  *    Revision 1.16  2001/06/29 13:35:07  oes
72  *    - Adapted
73  *    - Improved comments
74  *    - Removed init_proxy_args
75  *    - Renamed end_proxy_args(csp) to show_rcs(void)
76  *    - Removed logentry from cancelled commit
77  *    - Destroyed support for ndef SPLIT_PROXY_ARGS (Ooops)
78  *    - Separated the #define list into show_defines()
79  *
80  *    Revision 1.15  2001/06/09 10:55:28  jongfoster
81  *    Changing BUFSIZ ==> BUFFER_SIZE
82  *
83  *    Revision 1.14  2001/06/07 23:15:40  jongfoster
84  *    Removing config->proxy_args_gateways
85  *    Missing return statement added to end_proxy_args().
86  *
87  *    Revision 1.13  2001/06/06 09:37:59  sarantis
88  *    Fix misplaced comment start.
89  *
90  *    Revision 1.12  2001/06/04 10:41:52  swa
91  *    show version string of cgi.h and cgi.c
92  *
93  *    Revision 1.11  2001/06/03 11:03:48  oes
94  *    moved stuff to cgi.c
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 #include "cgi.h"
223 #include "list.h"
224
225 const char showargs_h_rcs[] = SHOWARGS_H_VERSION;
226
227
228 /*********************************************************************
229  *
230  * Function    :  savearg
231  *
232  * Description :  Called from `load_config'.  It saves each non-empty
233  *                and non-comment line from config into a list.  This
234  *                list is used to create the show-proxy-args page.
235  *
236  * Parameters  :
237  *          1  :  c = config setting that was found
238  *          2  :  o = the setting's argument (if any)
239  *
240  * Returns     :  N/A
241  *
242  *********************************************************************/
243 void savearg(char *c, char *o, struct configuration_spec * config)
244 {
245    char buf[BUFFER_SIZE];
246
247    *buf = '\0';
248
249    if ( ( NULL != c ) && ( '\0' != *c ) )
250    {
251       if ((c = html_encode(c)))
252       {
253          sprintf(buf, "<a href=\"" REDIRECT_URL "option#%s\">%s</a> ", c, c);
254       }
255       freez(c);
256    }
257    if ( ( NULL != o ) && ( '\0' != *o ) )
258    {
259       if ((o = html_encode(o)))
260       {
261          if (strncmpic(o, "http://", 7) == 0)
262          {
263             strcat(buf, "<a href=\"");
264             strcat(buf, o);
265             strcat(buf, "\">");
266             strcat(buf, o);
267             strcat(buf, "</a>");
268          }
269          else
270          {
271             strcat(buf, o);
272          }
273       }
274       freez(o);
275    }
276
277    strcat(buf, "<br>\n");
278
279    config->proxy_args = strsav(config->proxy_args, buf);
280
281 }
282
283
284 /*********************************************************************
285  *
286  * Function    :  show_rcs
287  *
288  * Description :  Create a string with the rcs info for all sourcefiles
289  *
290  * Parameters  :  None
291  *
292  * Returns     :  string 
293  *
294  *********************************************************************/
295 char *show_rcs(void)
296 {
297    char *b = NULL;
298    char buf[BUFFER_SIZE];
299
300    /* Instead of including *all* dot h's in the project (thus creating a
301     * tremendous amount of dependencies), I will concede to declaring them
302     * as extern's.  This forces the developer to add to this list, but oh well.
303     */
304
305 #define SHOW_RCS(__x)            \
306    {                             \
307       extern const char __x[];   \
308       sprintf(buf, "%s\n", __x); \
309       b = strsav(b, buf);        \
310    }
311
312    /* In alphabetical order */
313    SHOW_RCS(actions_h_rcs)
314    SHOW_RCS(actions_rcs)
315    SHOW_RCS(cgi_h_rcs)
316    SHOW_RCS(cgi_rcs)
317 #ifdef FEATURE_CGI_EDIT_ACTIONS
318    SHOW_RCS(cgiedit_rcs)
319    SHOW_RCS(cgiedit_h_rcs)
320 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
321 #ifdef __MINGW32__
322    SHOW_RCS(cygwin_h_rcs)
323 #endif
324    SHOW_RCS(deanimate_h_rcs)
325    SHOW_RCS(deanimate_rcs)
326    SHOW_RCS(encode_h_rcs)
327    SHOW_RCS(encode_rcs)
328    SHOW_RCS(errlog_h_rcs)
329    SHOW_RCS(errlog_rcs)
330    SHOW_RCS(filters_h_rcs)
331    SHOW_RCS(filters_rcs)
332    SHOW_RCS(gateway_h_rcs)
333    SHOW_RCS(gateway_rcs)
334 #ifdef GNU_REGEX
335    SHOW_RCS(gnu_regex_h_rcs)
336    SHOW_RCS(gnu_regex_rcs)
337 #endif /* def GNU_REGEX */
338    SHOW_RCS(jbsockets_h_rcs)
339    SHOW_RCS(jbsockets_rcs)
340    SHOW_RCS(jcc_h_rcs)
341    SHOW_RCS(jcc_rcs)
342 #ifdef FEATURE_KILL_POPUPS
343    SHOW_RCS(killpopup_h_rcs)
344    SHOW_RCS(killpopup_rcs)
345 #endif /* def FEATURE_KILL_POPUPS */
346    SHOW_RCS(list_h_rcs)
347    SHOW_RCS(list_rcs)
348    SHOW_RCS(loadcfg_h_rcs)
349    SHOW_RCS(loadcfg_rcs)
350    SHOW_RCS(loaders_h_rcs)
351    SHOW_RCS(loaders_rcs)
352    SHOW_RCS(miscutil_h_rcs)
353    SHOW_RCS(miscutil_rcs)
354    SHOW_RCS(parsers_h_rcs)
355    SHOW_RCS(parsers_rcs)
356    SHOW_RCS(pcrs_rcs)
357    SHOW_RCS(pcrs_h_rcs)
358    SHOW_RCS(project_h_rcs)
359    SHOW_RCS(showargs_h_rcs)
360    SHOW_RCS(showargs_rcs)
361    SHOW_RCS(ssplit_h_rcs)
362    SHOW_RCS(ssplit_rcs)
363 #ifdef _WIN32
364 #ifndef _WIN_CONSOLE
365    SHOW_RCS(w32log_h_rcs)
366    SHOW_RCS(w32log_rcs)
367    SHOW_RCS(w32res_h_rcs)
368    SHOW_RCS(w32taskbar_h_rcs)
369    SHOW_RCS(w32taskbar_rcs)
370 #endif /* ndef _WIN_CONSOLE */
371    SHOW_RCS(win32_h_rcs)
372    SHOW_RCS(win32_rcs)
373 #endif /* def _WIN32 */
374
375 #undef SHOW_RCS
376
377    return(b);
378 }
379
380 /*********************************************************************
381  *
382  * Function    :  show_defines
383  *
384  * Description :  Create a string with all conditional #defines used
385  *                when building
386  *
387  * Parameters  :  None
388  *
389  * Returns     :  string 
390  *
391  *********************************************************************/
392 void show_defines(struct map *exports)
393 {
394
395 #ifdef FEATURE_ACL
396    map_conditional(exports, "FEATURE_ACL", 1);
397 #else /* ifndef FEATURE_ACL */
398    map_conditional(exports, "FEATURE_ACL", 0);
399 #endif /* ndef FEATURE_ACL */
400
401 #ifdef FEATURE_COOKIE_JAR
402    map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
403 #else /* ifndef FEATURE_COOKIE_JAR */
404    map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
405 #endif /* ndef FEATURE_COOKIE_JAR */
406
407 #ifdef FEATURE_DENY_GZIP
408    map_conditional(exports, "FEATURE_DENY_GZIP", 1);
409 #else /* ifndef FEATURE_DENY_GZIP */
410    map_conditional(exports, "FEATURE_DENY_GZIP", 0);
411 #endif /* ndef FEATURE_DENY_GZIP */
412
413 #ifdef FEATURE_FAST_REDIRECTS
414    map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
415 #else /* ifndef FEATURE_FAST_REDIRECTS */
416    map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
417 #endif /* ndef FEATURE_FAST_REDIRECTS */
418
419 #ifdef FEATURE_FORCE_LOAD
420    map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
421 #else /* ifndef FEATURE_FORCE_LOAD */
422    map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
423 #endif /* ndef FEATURE_FORCE_LOAD */
424
425 #ifdef FEATURE_IMAGE_BLOCKING
426    map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
427 #else /* ifndef FEATURE_IMAGE_BLOCKING */
428    map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
429 #endif /* ndef FEATURE_IMAGE_BLOCKING */
430
431 #ifdef FEATURE_IMAGE_DETECT_MSIE
432    map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
433 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
434    map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
435 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
436
437 #ifdef FEATURE_KILL_POPUPS
438    map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
439 #else /* ifndef FEATURE_KILL_POPUPS */
440    map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
441 #endif /* ndef FEATURE_KILL_POPUPS */
442
443 #ifdef FEATURE_PTHREAD
444    map_conditional(exports, "FEATURE_PTHREAD", 1);
445 #else /* ifndef FEATURE_PTHREAD */
446    map_conditional(exports, "FEATURE_PTHREAD", 0);
447 #endif /* ndef FEATURE_PTHREAD */
448
449 #ifdef FEATURE_STATISTICS
450    map_conditional(exports, "FEATURE_STATISTICS", 1);
451 #else /* ifndef FEATURE_STATISTICS */
452    map_conditional(exports, "FEATURE_STATISTICS", 0);
453 #endif /* ndef FEATURE_STATISTICS */
454
455 #ifdef FEATURE_TOGGLE
456    map_conditional(exports, "FEATURE_TOGGLE", 1);
457 #else /* ifndef FEATURE_TOGGLE */
458    map_conditional(exports, "FEATURE_TOGGLE", 0);
459 #endif /* ndef FEATURE_TOGGLE */
460
461 #ifdef FEATURE_TRUST
462    map_conditional(exports, "FEATURE_TRUST", 1);
463 #else /* ifndef FEATURE_TRUST */
464    map_conditional(exports, "FEATURE_TRUST", 0);
465 #endif /* ndef FEATURE_TRUST */
466
467 #ifdef REGEX_GNU
468    map_conditional(exports, "REGEX_GNU", 1);
469 #else /* ifndef REGEX_GNU */
470    map_conditional(exports, "REGEX_GNU", 0);
471 #endif /* def REGEX_GNU */
472
473 #ifdef REGEX_PCRE
474    map_conditional(exports, "REGEX_PCRE", 1);
475 #else /* ifndef REGEX_PCRE */
476    map_conditional(exports, "REGEX_PCRE", 0);
477 #endif /* def REGEX_PCRE */
478
479 #ifdef STATIC_PCRE
480    map_conditional(exports, "STATIC_PCRE", 1);
481 #else /* ifndef STATIC_PCRE */
482    map_conditional(exports, "STATIC_PCRE", 0);
483 #endif /* ndef STATIC_PCRE */
484
485 #ifdef STATIC_PCRS
486    map_conditional(exports, "STATIC_PCRS", 1);
487 #else /* ifndef STATIC_PCRS */
488    map_conditional(exports, "STATIC_PCRS", 0);
489 #endif /* ndef STATIC_PCRS */
490
491    map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
492 }
493
494
495 /*
496   Local Variables:
497   tab-width: 3
498   end:
499 */