Added another #ifdef _WIN_CONSOLE
[privoxy.git] / showargs.c
1 const char showargs_rcs[] = "$Id: showargs.c,v 1.3 2001/05/20 01:21: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  *
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.3  2001/05/20 01:21:20  jongfoster
37  *    Version 2.9.4 checkin.
38  *    - Merged popupfile and cookiefile, and added control over PCRS
39  *      filtering, in new "permissionsfile".
40  *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
41  *      file error you now get a message box (in the Win32 GUI) rather
42  *      than the program exiting with no explanation.
43  *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
44  *      skipping.
45  *    - Removed tabs from "config"
46  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
47  *    - Bumped up version number.
48  *
49  *    Revision 1.2  2001/05/17 23:01:01  oes
50  *     - Cleaned CRLF's from the sources and related files
51  *
52  *    Revision 1.1.1.1  2001/05/15 13:59:03  oes
53  *    Initial import of version 2.9.3 source tree
54  *
55  *
56  *********************************************************************/
57 \f
58 #include "config.h"
59
60 #include <stdio.h>
61 #include <stdlib.h>
62 #include <sys/types.h>
63 #include <string.h>
64 #include <malloc.h>
65 #include <errno.h>
66
67 #include "showargs.h"
68 #include "jcc.h"
69 #include "encode.h"
70 #include "parsers.h"
71 #include "errlog.h"
72 #include "miscutil.h"
73 #include "gateway.h"
74
75 const char showargs_h_rcs[] = SHOWARGS_H_VERSION;
76
77 /*********************************************************************
78  *
79  * Function    :  strsav
80  *
81  * Description :  Reallocate "old" and append text to it.  This makes
82  *                it easier to append to malloc'd strings.
83  *
84  * Parameters  :
85  *          1  :  old = Old text that is to be extended.  Will be
86  *                free()d by this routine.
87  *          2  :  text_to_append = Text to be appended to old.
88  *
89  * Returns     :  Pointer to newly malloc'ed appended string.
90  *                If there is no text to append, return old.  Caller
91  *                must free().
92  *
93  *********************************************************************/
94 char *strsav(char *old, const char *text_to_append)
95 {
96    int old_len, new_len;
97    char *p;
98
99    if (( text_to_append == NULL) || (*text_to_append == '\0'))
100    {
101       return(old);
102    }
103
104    if (NULL != old)
105    {
106       old_len = strlen(old);
107    }
108    else
109    {
110       old_len = 0;
111    }
112
113    new_len = old_len + strlen(text_to_append) + 1;
114
115    if (old)
116    {
117       if ((p = realloc(old, new_len)) == NULL)
118       {
119          log_error(LOG_LEVEL_FATAL, "realloc(%d) bytes for proxy_args failed!", new_len);
120          /* Never get here - LOG_LEVEL_FATAL causes program exit */\r
121       }
122    }
123    else
124    {
125       if ((p = (char *)malloc(new_len)) == NULL)
126       {
127          log_error(LOG_LEVEL_FATAL, "malloc(%d) bytes for proxy_args failed!", new_len);
128          /* Never get here - LOG_LEVEL_FATAL causes program exit */\r
129       }
130    }
131
132    strcpy(p + old_len, text_to_append);
133    return(p);
134
135 }
136
137
138 /*********************************************************************
139  *
140  * Function    :  savearg
141  *
142  * Description :  Called from `load_config'.  It saves each non-empty
143  *                and non-comment line from config into a list.  This
144  *                list is used to create the show-proxy-args page.
145  *
146  * Parameters  :
147  *          1  :  c = config setting that was found
148  *          2  :  o = the setting's argument (if any)
149  *
150  * Returns     :  N/A
151  *
152  *********************************************************************/
153 void savearg(char *c, char *o)
154 {
155    char buf[BUFSIZ];
156
157    *buf = '\0';
158
159    if ( ( NULL != c ) && ( '\0' != *c ) )
160    {
161       if ((c = html_encode(c)))
162       {
163          sprintf(buf, "<a href=\"" REDIRECT_URL "option#%s\">%s</a> ", c, c);
164       }
165       freez(c);
166    }
167    if ( ( NULL != o ) && ( '\0' != *o ) )
168    {
169       if ((o = html_encode(o)))
170       {
171          if (strncmpic(o, "http://", 7) == 0)
172          {
173             strcat(buf, "<a href=\"");
174             strcat(buf, o);
175             strcat(buf, "\">");
176             strcat(buf, o);
177             strcat(buf, "</a>");
178          }
179          else
180          {
181             strcat(buf, o);
182          }
183       }
184       freez(o);
185    }
186
187    strcat(buf, "<br>\n");
188
189    proxy_args->invocation = strsav(proxy_args->invocation, buf);
190
191 }
192
193
194 /*********************************************************************
195  *
196  * Function    :  init_proxy_args
197  *
198  * Description :  Create the "top" of the show-proxy-args page.
199  *
200  * Parameters  :
201  *          1  :  argc = argument count (same as in main)
202  *          2  :  argv[] = program arguments (same as in main)
203  *
204  * Returns     :  N/A
205  *
206  *********************************************************************/
207 void init_proxy_args(int argc, const char *argv[])
208 {
209    const struct gateway *g;
210    int i;
211
212    freez(proxy_args->header);
213    freez(proxy_args->invocation);
214    freez(proxy_args->gateways);
215    freez(proxy_args->trailer);
216    
217
218    proxy_args->header = strsav(proxy_args->header,
219       "HTTP/1.0 200 OK\n"
220       "Server: IJ/" VERSION "\n"
221       "Content-type: text/html\n\n"
222
223       "<html>"
224       "<head>"
225       "<title>Internet Junkbuster Proxy Status</title>"
226       "</head>\n"
227       "<body bgcolor=\"#f8f8f0\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
228       "<center>\n"
229       "<h1>" BANNER "\n"
230       "<a href=\"" REDIRECT_URL "faq#show\">Proxy Status</a>\n"
231       "</h1></center>\n"
232       "<h2>You are using the " BANNER " <sup><small><small>TM</small></small></sup></h2>\n"
233       "Version: " VERSION "\n"
234       "<br>Home page: <a href=\"" HOME_PAGE_URL "\">" HOME_PAGE_URL "</a>\n"
235       "<p>\n"
236    );
237
238    proxy_args->header = strsav(proxy_args->header,
239       "<h2>The program was invoked as follows</h2>\n");
240
241    for (i=0; i < argc; i++)
242    {
243       proxy_args->header = strsav(proxy_args->header, argv[i]);
244       proxy_args->header = strsav(proxy_args->header, " ");
245    }
246    proxy_args->header = strsav(proxy_args->header, "<br>\n");
247
248
249    proxy_args->invocation = strsav(
250       proxy_args->invocation,
251       "<br>\n"
252       "and the following options were set in the configuration file"
253       "<br><br>\n"
254    );
255
256
257    proxy_args->gateways = strsav(proxy_args->gateways,
258       "<h2>It supports the following gateway protocols:</h2>\n");
259
260    for (g = gateways; g->name; g++)
261    {
262       proxy_args->gateways = strsav(proxy_args->gateways, g->name);
263       proxy_args->gateways = strsav(proxy_args->gateways, " ");
264    }
265    proxy_args->gateways = strsav(proxy_args->gateways, "<br>\n");
266
267 }
268
269
270 /*********************************************************************
271  *
272  * Function    :  end_proxy_args
273  *
274  * Description :  Create the "bottom" of the show-proxy-args page.
275  *
276  * Parameters  :  None
277  *
278  * Returns     :  N/A
279  *
280  *********************************************************************/
281 void end_proxy_args(void)
282 {
283    char *b = NULL;
284    char buf[BUFSIZ];
285
286    /* Instead of including *all* dot h's in the project (thus creating a
287     * tremendous amount of dependencies), I will concede to declaring them
288     * as extern's.  This forces the developer to add to this list, but oh well.
289     */
290
291 #ifndef SPLIT_PROXY_ARGS
292    if (suppress_blocklists && suppress_message!=NULL)
293    {
294       b = strsav(b, "<h2>File contents</h2>\n");
295       b = strsav(b, suppress_message);
296       b = strsav(b, "\n");
297    }
298 #endif /* ndef SPLIT_PROXY_ARGS */
299
300    b = strsav(b, "<h2>Source versions:</h2>\n");
301    b = strsav(b, "<pre>");
302
303 #define SHOW_RCS(__x)            \
304    {                             \
305       extern const char __x[];   \
306       sprintf(buf, "%s\n", __x); \
307       b = strsav(b, buf);        \
308    }
309
310    /* In alphabetical order */
311 #ifdef __MINGW32__
312    SHOW_RCS(cygwin_h_rcs)
313 #endif
314    SHOW_RCS(encode_h_rcs)
315    SHOW_RCS(encode_rcs)
316    SHOW_RCS(errlog_h_rcs)
317    SHOW_RCS(errlog_rcs)
318    SHOW_RCS(filters_h_rcs)
319    SHOW_RCS(filters_rcs)
320    SHOW_RCS(gateway_h_rcs)
321    SHOW_RCS(gateway_rcs)
322 #ifdef GNU_REGEX
323    SHOW_RCS(gnu_regex_h_rcs)
324    SHOW_RCS(gnu_regex_rcs)
325 #endif /* def GNU_REGEX */
326    SHOW_RCS(jbsockets_h_rcs)
327    SHOW_RCS(jbsockets_rcs)
328    SHOW_RCS(jcc_h_rcs)
329    SHOW_RCS(jcc_rcs)
330 #ifdef KILLPOPUPS
331    SHOW_RCS(killpopup_h_rcs)
332    SHOW_RCS(killpopup_rcs)
333 #endif /* def KILLPOPUPS */
334    SHOW_RCS(loadcfg_h_rcs)
335    SHOW_RCS(loadcfg_rcs)
336    SHOW_RCS(loaders_h_rcs)
337    SHOW_RCS(loaders_rcs)
338    SHOW_RCS(miscutil_h_rcs)
339    SHOW_RCS(miscutil_rcs)
340    SHOW_RCS(parsers_h_rcs)
341    SHOW_RCS(parsers_rcs)
342 #ifdef PCRS
343    SHOW_RCS(pcrs_rcs)
344    SHOW_RCS(pcrs_h_rcs)
345 #endif /* def PCRS */
346    SHOW_RCS(project_h_rcs)
347    SHOW_RCS(showargs_h_rcs)
348    SHOW_RCS(showargs_rcs)
349    SHOW_RCS(ssplit_h_rcs)
350    SHOW_RCS(ssplit_rcs)
351 #ifdef _WIN32\r
352 #ifndef _WIN_CONSOLE\r
353    SHOW_RCS(w32log_h_rcs)
354    SHOW_RCS(w32log_rcs)
355    SHOW_RCS(w32res_h_rcs)
356    SHOW_RCS(w32rulesdlg_h_rcs)
357    SHOW_RCS(w32rulesdlg_rcs)
358    SHOW_RCS(w32taskbar_h_rcs)
359    SHOW_RCS(w32taskbar_rcs)
360 #endif /* ndef _WIN_CONSOLE */\r
361    SHOW_RCS(win32_h_rcs)
362    SHOW_RCS(win32_rcs)
363 #endif /* def _WIN32 */
364
365 #undef SHOW_RCS
366
367    b = strsav(b, "</pre>\n");
368
369    b = strsav(b, "<h2>Conditional defines:</h2>\n<ul>");
370
371 #ifdef REGEX
372    b = strsav(b, "  <li><code>#define <b>REGEX</b></code> - Support for regular expressions in the path specs.</li>\n");
373 #else /* ifndef REGEX */
374    b = strsav(b, "  <li><code>#undef <b>REGEX</b></code> - No support for regular expressions in the path specs.</li>\n");
375 #endif /* ndef REGEX */
376
377 #ifdef PCRE
378    b = strsav(b, "  <li><code>#define <b>PCRE</b></code> - Use PCRE rather than old GNU regex library.</li>\n");
379 #else /* ifndef PCRE */
380    b = strsav(b, "  <li><code>#undef <b>PCRE</b></code> - Use old GNU regex library rather than PCRE.</li>\n");
381 #endif /* ndef PCRE */
382
383 #ifdef PCRS
384    b = strsav(b, "  <li><code>#define <b>PCRS</b></code> - Enables arbitrary content modification regexps.</li>\n");
385 #else /* ifndef PCRS */
386    b = strsav(b, "  <li><code>#undef <b>PCRS</b></code> - Disables arbitrary content modification regexps.</li>\n");
387 #endif /* ndef PCRS */
388
389 #ifdef TOGGLE
390    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");
391 #else /* ifndef TOGGLE */
392    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");
393 #endif /* ndef TOGGLE */
394
395 #ifdef FORCE_LOAD
396    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");
397 #else /* ifndef FORCE_LOAD */
398    b = strsav(b, "  <li><code>#undef <b>FORCE_LOAD</b></code> - Disables bypassing filtering for a single page.</li>\n");
399 #endif /* ndef FORCE_LOAD */
400
401 #ifdef DENY_GZIP
402    b = strsav(b, "  <li><code>#define <b>DENY_GZIP</b></code> - Prevents requests from being compressed - required for PCRS.</li>\n");
403 #else /* ifndef DENY_GZIP */
404    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");
405 #endif /* ndef DENY_GZIP */
406
407 #ifdef STATISTICS
408    b = strsav(b, "  <li><code>#define <b>STATISTICS</b></code> - Enables statistics function.</li>\n");
409 #else /* ifndef STATISTICS */
410    b = strsav(b, "  <li><code>#undef <b>STATISTICS</b></code> - Disables statistics function.</li>\n");
411 #endif /* ndef STATISTICS */
412
413 #ifdef SPLIT_PROXY_ARGS
414    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");
415 #else /* ifndef SPLIT_PROXY_ARGS */
416    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");
417 #endif /* ndef SPLIT_PROXY_ARGS */
418
419 #ifdef KILLPOPUPS
420    b = strsav(b, "  <li><code>#define <b>KILLPOPUPS</b></code> - Enables killing JavaScript popups.</li>\n");
421 #else /* ifndef KILLPOPUPS */
422    b = strsav(b, "  <li><code>#undef <b>KILLPOPUPS</b></code> - Disables killing JavaScript popups.</li>\n");
423 #endif /* ndef KILLPOPUPS */
424
425 #ifdef WEBDAV
426    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");
427 #else /* ifndef WEBDAV */
428    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");
429 #endif /* ndef WEBDAV */
430
431 #ifdef DETECT_MSIE_IMAGES
432    b = strsav(b, "  <li><code>#define <b>DETECT_MSIE_IMAGES</b></code> - Enables detecting image requests automatically for MSIE.</li>\n");
433 #else /* ifndef DETECT_MSIE_IMAGES */
434    b = strsav(b, "  <li><code>#undef <b>DETECT_MSIE_IMAGES</b></code> - Disables detecting image requests automatically for MSIE.</li>\n");
435 #endif /* ndef DETECT_MSIE_IMAGES */
436
437 #ifdef USE_IMAGE_LIST
438    b = strsav(b, "  <li><code>#define <b>USE_IMAGE_LIST</b></code> - Enables using image list to detect images.</li>\n");
439 #else /* ifndef USE_IMAGE_LIST */
440    b = strsav(b, "  <li><code>#undef <b>USE_IMAGE_LIST</b></code> - Disables using image list to detect images.</li>\n");
441 #endif /* ndef USE_IMAGE_LIST */
442
443 #ifdef ACL_FILES
444    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");
445 #else /* ifndef ACL_FILES */
446    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");
447 #endif /* ndef ACL_FILES */
448
449 #ifdef TRUST_FILES
450    b = strsav(b, "  <li><code>#define <b>TRUST_FILES</b></code> - Enables the use of trust files.</li>\n");
451 #else /* ifndef TRUST_FILES */
452    b = strsav(b, "  <li><code>#undef <b>TRUST_FILES</b></code> - Disables the use of trust files.</li>\n");
453 #endif /* ndef TRUST_FILES */
454
455 #ifdef JAR_FILES
456    b = strsav(b, "  <li><code>#define <b>JAR_FILES</b></code> - Enables the use of jar files to capture cookies.</li>\n");
457 #else /* ifndef JAR_FILES */
458    b = strsav(b, "  <li><code>#undef <b>JAR_FILES</b></code> - Disables the use of jar files to capture cookies.</li>\n");
459 #endif /* ndef JAR_FILES */
460
461    b = strsav(b, "</ul>\n<br>\n");
462
463    b = strsav(b,
464       "<small><small><p>\n"
465       "The " BANNER " Proxy - \n"\r
466       "<a href=\"" HOME_PAGE_URL "\">" HOME_PAGE_URL "</a><p>\n"\r
467       "Copyright &#169; 2001 <a href=\"" HOME_PAGE_URL "\">the SourceForge IJBSWA team</a><br>\n"\r
468       "Copyright &#169; 1997 <a href=\"http://www.junkbusters.com/\">\n" "Junkbusters Corporation</a><br>\n"
469       "Copying and distribution permitted under the "
470       "<a href=\"http://www.gnu.org/copyleft/gpl.html\">GNU General Public License.</a>\n"
471       "</small></small>"
472       "</body></html>\n"
473    );
474
475    proxy_args->trailer = b;
476
477 }
478
479
480 /*
481   Local Variables:
482   tab-width: 3
483   end:
484 */