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