1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.35 2002/05/12 21:44:44 jongfoster Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/cgisimple.c,v $
6 * Purpose : Simple CGIs to get information about Privoxy's
9 * Functions declared include:
12 * Copyright : Written by and Copyright (C) 2001 the SourceForge
13 * Privoxy team. http://www.privoxy.org/
15 * Based on the Internet Junkbuster originally written
16 * by and Copyright (C) 1997 Anonymous Coders and
17 * Junkbusters Corporation. http://www.junkbusters.com
19 * This program is free software; you can redistribute it
20 * and/or modify it under the terms of the GNU General
21 * Public License as published by the Free Software
22 * Foundation; either version 2 of the License, or (at
23 * your option) any later version.
25 * This program is distributed in the hope that it will
26 * be useful, but WITHOUT ANY WARRANTY; without even the
27 * implied warranty of MERCHANTABILITY or FITNESS FOR A
28 * PARTICULAR PURPOSE. See the GNU General Public
29 * License for more details.
31 * The GNU General Public License should be included with
32 * this file. If not, you can view it at
33 * http://www.gnu.org/copyleft/gpl.html
34 * or write to the Free Software Foundation, Inc., 59
35 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38 * $Log: cgisimple.c,v $
39 * Revision 1.35 2002/05/12 21:44:44 jongfoster
40 * Adding amiga.[ch] revision information, if on an amiga.
42 * Revision 1.34 2002/04/30 12:06:12 oes
43 * Deleted unused code from default_cgi
45 * Revision 1.33 2002/04/30 11:14:52 oes
46 * Made csp the first parameter in *action_to_html
48 * Revision 1.32 2002/04/26 18:29:13 jongfoster
49 * Fixing this Visual C++ warning:
50 * cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
52 * Revision 1.31 2002/04/26 12:54:36 oes
53 * - Kill obsolete REDIRECT_URL code
54 * - Error handling fixes
55 * - Style sheet related HTML snipplet changes
56 * - cgi_show_url_info:
57 * - Matches now in table, actions on single lines,
59 * - standard.action suppressed
60 * - Buttons to View and Edit AFs
62 * Revision 1.30 2002/04/24 02:18:08 oes
63 * - show-status is now the starting point for editing
64 * the actions files, generate list of all AFs with buttons
65 * for viewing and editing, new look for file list (Jon:
66 * buttons now aligned ;-P ), view mode now supports multiple
67 * AFs, name changes, no view links for unspecified files,
68 * no edit link for standard.action.
70 * - Jon's multiple AF patch: cgi_show_url_info now uses all
71 * AFs and marks the output accordingly
73 * Revision 1.29 2002/04/10 13:38:35 oes
74 * load_template signature changed
76 * Revision 1.28 2002/04/07 15:42:12 jongfoster
77 * Fixing send-banner?type=auto when the image-blocker is
78 * a redirect to send-banner
80 * Revision 1.27 2002/04/05 15:50:48 oes
81 * added send-stylesheet CGI
83 * Revision 1.26 2002/04/04 00:36:36 gliptak
84 * always use pcre for matching
86 * Revision 1.25 2002/04/03 22:28:03 gliptak
87 * Removed references to gnu_regex
89 * Revision 1.24 2002/04/02 16:12:47 oes
90 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
92 * Revision 1.23 2002/03/26 22:29:54 swa
93 * we have a new homepage!
95 * Revision 1.22 2002/03/24 16:18:15 jongfoster
98 * Revision 1.21 2002/03/24 15:23:33 jongfoster
101 * Revision 1.20 2002/03/24 13:25:43 swa
102 * name change related issues
104 * Revision 1.19 2002/03/16 23:54:06 jongfoster
105 * Adding graceful termination feature, to help look for memory leaks.
106 * If you enable this (which, by design, has to be done by hand
107 * editing config.h) and then go to http://i.j.b/die, then the program
108 * will exit cleanly after the *next* request. It should free all the
109 * memory that was used.
111 * Revision 1.18 2002/03/12 01:44:49 oes
112 * Changed default for "blocked" image from jb logo to checkboard pattern
114 * Revision 1.17 2002/03/08 16:43:18 oes
115 * Added choice beween GIF and PNG built-in images
117 * Revision 1.16 2002/03/07 03:48:38 oes
118 * - Changed built-in images from GIF to PNG
119 * (with regard to Unisys patent issue)
120 * - Added a 4x4 pattern PNG which is less intrusive
121 * than the logo but also clearly marks the deleted banners
123 * Revision 1.15 2002/03/06 22:54:35 jongfoster
124 * Automated function-comment nitpicking.
126 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
127 * Clean up a little CRLF unpleasantness that suddenly appeared
129 * Revision 1.13 2002/02/21 00:10:37 jongfoster
130 * Adding send-banner?type=auto option
132 * Revision 1.12 2002/01/23 01:03:32 jongfoster
133 * Fixing gcc [CygWin] compiler warnings
135 * Revision 1.11 2002/01/23 00:01:04 jongfoster
136 * Adding cgi_transparent_gif() for http://i.j.b/t
137 * Adding missing html_encode() to many CGI functions.
138 * Adding urlmatch.[ch] to http://i.j.b/show-version
140 * Revision 1.10 2002/01/17 21:10:37 jongfoster
141 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
142 * Also fixing a problem in the same function with improperly quoted URLs
143 * in output HTML, and adding code to handle https:// URLs correctly.
145 * Revision 1.9 2001/11/30 23:09:15 jongfoster
146 * Now reports on FEATURE_CGI_EDIT_ACTIONS
147 * Removing FEATURE_DENY_GZIP from template
149 * Revision 1.8 2001/11/13 00:14:07 jongfoster
150 * Fixing stupid bug now I've figured out what || means.
151 * (It always returns 0 or 1, not one of it's paramaters.)
153 * Revision 1.7 2001/10/23 21:48:19 jongfoster
154 * Cleaning up error handling in CGI functions - they now send back
155 * a HTML error page and should never cause a FATAL error. (Fixes one
156 * potential source of "denial of service" attacks).
158 * CGI actions file editor that works and is actually useful.
160 * Ability to toggle JunkBuster remotely using a CGI call.
162 * You can turn off both the above features in the main configuration
163 * file, e.g. if you are running a multi-user proxy.
165 * Revision 1.6 2001/10/14 22:00:32 jongfoster
166 * Adding support for a 404 error when an invalid CGI page is requested.
168 * Revision 1.5 2001/10/07 15:30:41 oes
169 * Removed FEATURE_DENY_GZIP
171 * Revision 1.4 2001/10/02 15:31:12 oes
172 * Introduced show-request cgi
174 * Revision 1.3 2001/09/22 16:34:44 jongfoster
175 * Removing unneeded #includes
177 * Revision 1.2 2001/09/19 18:01:11 oes
178 * Fixed comments; cosmetics
180 * Revision 1.1 2001/09/16 17:08:54 jongfoster
181 * Moving simple CGI functions from cgi.c to new file cgisimple.c
184 **********************************************************************/
190 #include <sys/types.h>
197 #define snprintf _snprintf
198 #endif /* def _WIN32 */
202 #include "cgisimple.h"
208 #include "miscutil.h"
211 #include "urlmatch.h"
214 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
217 static char *show_rcs(void);
218 static jb_err show_defines(struct map *exports);
221 /*********************************************************************
223 * Function : cgi_default
225 * Description : CGI function that is called for the CGI_SITE_1_HOST
226 * and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
227 * Boring - only exports the default exports.
230 * 1 : csp = Current client state (buffers, headers, etc...)
231 * 2 : rsp = http_response data structure for output
232 * 3 : parameters = map of cgi parameters
234 * CGI Parameters : none
236 * Returns : JB_ERR_OK on success
237 * JB_ERR_MEMORY on out-of-memory
239 *********************************************************************/
240 jb_err cgi_default(struct client_state *csp,
241 struct http_response *rsp,
242 const struct map *parameters)
249 if (NULL == (exports = default_exports(csp, "")))
251 return JB_ERR_MEMORY;
254 return template_fill_for_cgi(csp, "default", exports, rsp);
258 /*********************************************************************
260 * Function : cgi_error_404
262 * Description : CGI function that is called if an unknown action was
266 * 1 : csp = Current client state (buffers, headers, etc...)
267 * 2 : rsp = http_response data structure for output
268 * 3 : parameters = map of cgi parameters
270 * CGI Parameters : none
272 * Returns : JB_ERR_OK on success
273 * JB_ERR_MEMORY on out-of-memory error.
275 *********************************************************************/
276 jb_err cgi_error_404(struct client_state *csp,
277 struct http_response *rsp,
278 const struct map *parameters)
286 if (NULL == (exports = default_exports(csp, NULL)))
288 return JB_ERR_MEMORY;
291 rsp->status = strdup("404 Privoxy configuration page not found");
292 if (rsp->status == NULL)
295 return JB_ERR_MEMORY;
298 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
302 #ifdef FEATURE_GRACEFUL_TERMINATION
303 /*********************************************************************
307 * Description : CGI function to shut down Privoxy.
308 * NOTE: Turning this on in a production build
309 * would be a BAD idea. An EXTREMELY BAD idea.
310 * In short, don't do it.
313 * 1 : csp = Current client state (buffers, headers, etc...)
314 * 2 : rsp = http_response data structure for output
315 * 3 : parameters = map of cgi parameters
317 * CGI Parameters : none
319 * Returns : JB_ERR_OK on success
320 * JB_ERR_MEMORY on out-of-memory error.
322 *********************************************************************/
323 jb_err cgi_die (struct client_state *csp,
324 struct http_response *rsp,
325 const struct map *parameters)
335 * I don't really care what gets sent back to the browser.
336 * Take the easy option - "out of memory" page.
339 return JB_ERR_MEMORY;
341 #endif /* def FEATURE_GRACEFUL_TERMINATION */
344 /*********************************************************************
346 * Function : cgi_show_request
348 * Description : Show the client's request and what sed() would have
352 * 1 : csp = Current client state (buffers, headers, etc...)
353 * 2 : rsp = http_response data structure for output
354 * 3 : parameters = map of cgi parameters
356 * CGI Parameters : none
358 * Returns : JB_ERR_OK on success
359 * JB_ERR_MEMORY on out-of-memory error.
361 *********************************************************************/
362 jb_err cgi_show_request(struct client_state *csp,
363 struct http_response *rsp,
364 const struct map *parameters)
373 if (NULL == (exports = default_exports(csp, "show-request")))
375 return JB_ERR_MEMORY;
379 * Repair the damage done to the IOB by get_header()
381 for (p = csp->iob->buf; p < csp->iob->eod; p++)
383 if (*p == '\0') *p = '\n';
387 * Export the original client's request and the one we would
388 * be sending to the server if this wasn't a CGI call
391 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
394 return JB_ERR_MEMORY;
397 if (map(exports, "processed-request", 1, html_encode_and_free_original(
398 sed(client_patterns, add_client_headers, csp)), 0))
401 return JB_ERR_MEMORY;
404 return template_fill_for_cgi(csp, "show-request", exports, rsp);
408 /*********************************************************************
410 * Function : cgi_send_banner
412 * Description : CGI function that returns a banner.
415 * 1 : csp = Current client state (buffers, headers, etc...)
416 * 2 : rsp = http_response data structure for output
417 * 3 : parameters = map of cgi parameters
420 * type : Selects the type of banner between "trans", "logo",
421 * and "auto". Defaults to "logo" if absent or invalid.
422 * "auto" means to select as if we were image-blocking.
423 * (Only the first character really counts).
425 * Returns : JB_ERR_OK on success
426 * JB_ERR_MEMORY on out-of-memory error.
428 *********************************************************************/
429 jb_err cgi_send_banner(struct client_state *csp,
430 struct http_response *rsp,
431 const struct map *parameters)
433 char imagetype = lookup(parameters, "type")[0];
435 if (imagetype == 'a') /* auto */
437 /* Default to pattern */
439 #ifdef FEATURE_IMAGE_BLOCKING
440 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
442 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
443 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
445 /* determine HOW images should be blocked */
446 const char * p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
448 /* and handle accordingly: */
451 /* Use default - nothing to do here. */
453 else if (0 == strcmpic(p, "blank"))
457 else if (0 == strcmpic(p, "pattern"))
461 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
463 imagetype = p[sizeof(prefix1) - 1];
465 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
467 imagetype = p[sizeof(prefix2) - 1];
470 #endif /* def FEATURE_IMAGE_BLOCKING */
473 if ((imagetype == 'b') || (imagetype == 't')) /* blank / transparent */
475 rsp->body = bindup(image_blank_data, image_blank_length);
476 rsp->content_length = image_blank_length;
481 rsp->body = bindup(image_pattern_data, image_pattern_length);
482 rsp->content_length = image_pattern_length;
485 if (rsp->body == NULL)
487 return JB_ERR_MEMORY;
490 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
492 return JB_ERR_MEMORY;
502 /*********************************************************************
504 * Function : cgi_transparent_image
506 * Description : CGI function that sends a 1x1 transparent image.
509 * 1 : csp = Current client state (buffers, headers, etc...)
510 * 2 : rsp = http_response data structure for output
511 * 3 : parameters = map of cgi parameters
513 * CGI Parameters : None
515 * Returns : JB_ERR_OK on success
516 * JB_ERR_MEMORY on out-of-memory error.
518 *********************************************************************/
519 jb_err cgi_transparent_image(struct client_state *csp,
520 struct http_response *rsp,
521 const struct map *parameters)
523 rsp->body = bindup(image_blank_data, image_blank_length);
524 rsp->content_length = image_blank_length;
526 if (rsp->body == NULL)
528 return JB_ERR_MEMORY;
531 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
533 return JB_ERR_MEMORY;
543 /*********************************************************************
545 * Function : cgi_send_stylesheet
547 * Description : CGI function that sends a css stylesheet found
548 * in the cgi-style.css template
551 * 1 : csp = Current client state (buffers, headers, etc...)
552 * 2 : rsp = http_response data structure for output
553 * 3 : parameters = map of cgi parameters
555 * CGI Parameters : None
557 * Returns : JB_ERR_OK on success
558 * JB_ERR_MEMORY on out-of-memory error.
560 *********************************************************************/
561 jb_err cgi_send_stylesheet(struct client_state *csp,
562 struct http_response *rsp,
563 const struct map *parameters)
570 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
572 if (err == JB_ERR_FILE)
575 * No way to tell user; send empty stylesheet
577 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
581 return err; /* JB_ERR_MEMORY */
584 if (enlist(rsp->headers, "Content-Type: text/css"))
586 return JB_ERR_MEMORY;
594 /*********************************************************************
596 * Function : cgi_show_version
598 * Description : CGI function that returns a a web page describing the
599 * file versions of Privoxy.
602 * 1 : csp = Current client state (buffers, headers, etc...)
603 * 2 : rsp = http_response data structure for output
604 * 3 : parameters = map of cgi parameters
606 * CGI Parameters : none
608 * Returns : JB_ERR_OK on success
609 * JB_ERR_MEMORY on out-of-memory error.
611 *********************************************************************/
612 jb_err cgi_show_version(struct client_state *csp,
613 struct http_response *rsp,
614 const struct map *parameters)
622 if (NULL == (exports = default_exports(csp, "show-version")))
624 return JB_ERR_MEMORY;
627 if (map(exports, "sourceversions", 1, show_rcs(), 0))
630 return JB_ERR_MEMORY;
633 return template_fill_for_cgi(csp, "show-version", exports, rsp);
637 /*********************************************************************
639 * Function : cgi_show_status
641 * Description : CGI function that returns a a web page describing the
642 * current status of Privoxy.
645 * 1 : csp = Current client state (buffers, headers, etc...)
646 * 2 : rsp = http_response data structure for output
647 * 3 : parameters = map of cgi parameters
650 * file : Which file to show. Only first letter is checked,
652 * - "p"ermissions (actions) file
655 * Default is to show menu and other information.
657 * Returns : JB_ERR_OK on success
658 * JB_ERR_MEMORY on out-of-memory error.
660 *********************************************************************/
661 jb_err cgi_show_status(struct client_state *csp,
662 struct http_response *rsp,
663 const struct map *parameters)
670 char buf[BUFFER_SIZE];
671 const char * filename = NULL;
672 char * file_description = NULL;
673 #ifdef FEATURE_STATISTICS
674 float perc_rej; /* Percentage of http requests rejected */
676 int local_urls_rejected;
677 #endif /* ndef FEATURE_STATISTICS */
678 struct file_list * fl;
679 struct url_actions * b;
680 jb_err err = JB_ERR_OK;
688 if (NULL == (exports = default_exports(csp, "show-status")))
690 return JB_ERR_MEMORY;
693 switch (*(lookup(parameters, "file")))
696 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_ACTION_FILES && csp->actions_list[i])
698 filename = csp->actions_list[i]->filename;
699 file_description = "Actions File";
706 filename = csp->rlist->filename;
707 file_description = "Filter File";
715 filename = csp->tlist->filename;
716 file_description = "Trust File";
719 #endif /* def FEATURE_TRUST */
722 if (NULL != filename)
724 if ( map(exports, "file-description", 1, file_description, 1)
725 || map(exports, "filepath", 1, html_encode(filename), 0) )
728 return JB_ERR_MEMORY;
731 if ((fp = fopen(filename, "r")) == NULL)
733 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
736 return JB_ERR_MEMORY;
742 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
744 string_join (&s, html_encode(buf));
748 if (map(exports, "contents", 1, s, 0))
751 return JB_ERR_MEMORY;
755 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
759 for (j = 0; (s != NULL) && (j < Argc); j++)
761 if (!err) err = string_join (&s, html_encode(Argv[j]));
762 if (!err) err = string_append(&s, " ");
764 if (!err) err = map(exports, "invocation", 1, s, 0);
766 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
767 if (!err) err = show_defines(exports);
772 return JB_ERR_MEMORY;
775 #ifdef FEATURE_STATISTICS
776 local_urls_read = urls_read;
777 local_urls_rejected = urls_rejected;
780 * Need to alter the stats not to include the fetch of this
783 * Can't do following thread safely! doh!
786 * urls_rejected--; * This will be incremented subsequently *
789 if (local_urls_read == 0)
791 if (!err) err = map_block_killer(exports, "have-stats");
795 if (!err) err = map_block_killer(exports, "have-no-stats");
797 perc_rej = (float)local_urls_rejected * 100.0F /
798 (float)local_urls_read;
800 sprintf(buf, "%d", local_urls_read);
801 if (!err) err = map(exports, "requests-received", 1, buf, 1);
803 sprintf(buf, "%d", local_urls_rejected);
804 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
806 sprintf(buf, "%6.2f", perc_rej);
807 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
810 #else /* ndef FEATURE_STATISTICS */
811 err = err || map_block_killer(exports, "statistics");
812 #endif /* ndef FEATURE_STATISTICS */
815 * List all action files in use, together with view and edit links,
816 * except for standard.action, which should only be viewable. (Not
817 * enforced in the editor itself)
818 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
821 for (i = 0; i < MAX_ACTION_FILES; i++)
823 if (((fl = csp->actions_list[i]) != NULL) && ((b = fl->f) != NULL))
825 if (!err) err = string_append(&s, "<tr><td>");
826 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
827 snprintf(buf, 100, "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a> ", i);
828 if (!err) err = string_append(&s, buf);
830 if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
832 snprintf(buf, 100, "<a href=\"/edit-actions-list?f=%s\">Edit</a>", csp->config->actions_file_short[i]);
833 if (!err) err = string_append(&s, buf);
836 if (!err) err = string_append(&s, "</td></tr>\n");
841 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
845 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
850 if (!err) err = map(exports, "re-filter-filename", 1, html_encode(csp->rlist->filename), 0);
854 if (!err) err = map(exports, "re-filter-filename", 1, "None specified", 1);
855 if (!err) err = map_block_killer(exports, "have-filterfile");
861 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
865 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
866 if (!err) err = map_block_killer(exports, "have-trustfile");
869 if (!err) err = map_block_killer(exports, "trust-support");
870 #endif /* ndef FEATURE_TRUST */
875 return JB_ERR_MEMORY;
878 return template_fill_for_cgi(csp, "show-status", exports, rsp);
882 /*********************************************************************
884 * Function : cgi_show_url_info
886 * Description : CGI function that determines and shows which actions
887 * Privoxy will perform for a given url, and which
888 * matches starting from the defaults have lead to that.
891 * 1 : csp = Current client state (buffers, headers, etc...)
892 * 2 : rsp = http_response data structure for output
893 * 3 : parameters = map of cgi parameters
896 * url : The url whose actions are to be determined.
897 * If url is unset, the url-given conditional will be
898 * set, so that all but the form can be suppressed in
901 * Returns : JB_ERR_OK on success
902 * JB_ERR_MEMORY on out-of-memory error.
904 *********************************************************************/
905 jb_err cgi_show_url_info(struct client_state *csp,
906 struct http_response *rsp,
907 const struct map *parameters)
917 if (NULL == (exports = default_exports(csp, "show-url-info")))
919 return JB_ERR_MEMORY;
923 * Get the url= parameter (if present) and remove any leading/trailing spaces.
925 url_param = strdup(lookup(parameters, "url"));
926 if (url_param == NULL)
929 return JB_ERR_MEMORY;
934 * Handle prefixes. 4 possibilities:
935 * 1) "http://" or "https://" prefix present and followed by URL - OK
936 * 2) Only the "http://" or "https://" part is present, no URL - change
937 * to empty string so it will be detected later as "no URL".
938 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
940 * 4) Parameter not specified or is empty string - let this fall through
941 * for now, next block of code will handle it.
943 if (0 == strncmp(url_param, "http://", 7))
945 if (url_param[7] == '\0')
948 * Empty URL (just prefix).
949 * Make it totally empty so it's caught by the next if()
954 else if (0 == strncmp(url_param, "https://", 8))
956 if (url_param[8] == '\0')
959 * Empty URL (just prefix).
960 * Make it totally empty so it's caught by the next if()
965 else if (url_param[0] != '\0')
968 * Unknown prefix - assume http://
970 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
971 if (NULL == url_param_prefixed)
975 return JB_ERR_MEMORY;
977 strcpy(url_param_prefixed, "http://");
978 strcpy(url_param_prefixed + 7, url_param);
980 url_param = url_param_prefixed;
984 if (url_param[0] == '\0')
986 /* URL paramater not specified, display query form only. */
988 if (map_block_killer(exports, "url-given")
989 || map(exports, "url", 1, "", 1))
992 return JB_ERR_MEMORY;
997 /* Given a URL, so query it. */
1002 struct file_list *fl;
1003 struct url_actions *b;
1004 struct http_request url_to_query[1];
1005 struct current_action_spec action[1];
1008 if (map(exports, "url", 1, html_encode(url_param), 0))
1012 return JB_ERR_MEMORY;
1015 init_current_action(action);
1017 if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1019 free_current_action(action);
1022 return JB_ERR_MEMORY;
1025 err = parse_http_url(url_param, url_to_query, csp);
1029 if (err == JB_ERR_MEMORY)
1031 free_current_action(action);
1033 return JB_ERR_MEMORY;
1039 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1040 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1042 free_current_action(action);
1047 return JB_ERR_MEMORY;
1050 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1054 * We have a warning about SSL paths. Hide it for insecure sites.
1056 if (!url_to_query->ssl)
1058 if (map_block_killer(exports, "https"))
1060 free_current_action(action);
1062 return JB_ERR_MEMORY;
1066 matches = strdup("<table class=\"transparent\">");
1068 for (i = 0; i < MAX_ACTION_FILES; i++)
1070 if (NULL == csp->config->actions_file_short[i]
1071 || !strcmp(csp->config->actions_file_short[i], "standard")) continue;
1075 if ((fl = csp->actions_list[i]) != NULL)
1077 if ((b = fl->f) != NULL)
1079 /* FIXME: Hardcoded HTML! */
1080 string_append(&matches, "<tr><th>In file: ");
1081 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1082 snprintf(buf, 150, ".action <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1083 string_append(&matches, buf);
1084 string_append(&matches, "View</a> <a class=\"cmd\" href=\"/edit-actions-list?f=");
1085 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1086 string_append(&matches, "\">Edit</a></th></tr>\n");
1093 for (; (b != NULL) && (matches != NULL); b = b->next)
1095 if (url_match(b->url, url_to_query))
1097 string_append(&matches, "<tr><td>{");
1098 string_join (&matches, actions_to_html(csp, b->action));
1099 string_append(&matches, " }</b><br>\n<code>");
1100 string_join (&matches, html_encode(b->url->spec));
1101 string_append(&matches, "</code></td></tr>\n");
1103 if (merge_current_action(action, b->action))
1106 free_http_request(url_to_query);
1107 free_current_action(action);
1109 return JB_ERR_MEMORY;
1117 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1120 string_append(&matches, "</table>\n");
1122 free_http_request(url_to_query);
1124 if (matches == NULL)
1126 free_current_action(action);
1128 return JB_ERR_MEMORY;
1131 if (map(exports, "matches", 1, matches , 0))
1133 free_current_action(action);
1135 return JB_ERR_MEMORY;
1138 s = current_action_to_html(csp, action);
1140 free_current_action(action);
1142 if (map(exports, "final", 1, s, 0))
1145 return JB_ERR_MEMORY;
1149 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1153 /*********************************************************************
1155 * Function : cgi_robots_txt
1157 * Description : CGI function to return "/robots.txt".
1160 * 1 : csp = Current client state (buffers, headers, etc...)
1161 * 2 : rsp = http_response data structure for output
1162 * 3 : parameters = map of cgi parameters
1164 * CGI Parameters : None
1166 * Returns : JB_ERR_OK on success
1167 * JB_ERR_MEMORY on out-of-memory error.
1169 *********************************************************************/
1170 jb_err cgi_robots_txt(struct client_state *csp,
1171 struct http_response *rsp,
1172 const struct map *parameters)
1178 "# This is the Privoxy control interface.\n"
1179 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1185 if (rsp->body == NULL)
1187 return JB_ERR_MEMORY;
1190 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1194 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1195 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1197 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1201 /*********************************************************************
1203 * Function : show_defines
1205 * Description : Add to a map the state od all conditional #defines
1206 * used when building
1209 * 1 : exports = map to extend
1211 * Returns : JB_ERR_OK on success
1212 * JB_ERR_MEMORY on out-of-memory error.
1214 *********************************************************************/
1215 static jb_err show_defines(struct map *exports)
1217 jb_err err = JB_ERR_OK;
1220 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1221 #else /* ifndef FEATURE_ACL */
1222 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1223 #endif /* ndef FEATURE_ACL */
1225 #ifdef FEATURE_CGI_EDIT_ACTIONS
1226 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1227 #else /* ifndef FEATURE_COOKIE_JAR */
1228 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1229 #endif /* ndef FEATURE_COOKIE_JAR */
1231 #ifdef FEATURE_COOKIE_JAR
1232 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1233 #else /* ifndef FEATURE_COOKIE_JAR */
1234 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1235 #endif /* ndef FEATURE_COOKIE_JAR */
1237 #ifdef FEATURE_FAST_REDIRECTS
1238 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1239 #else /* ifndef FEATURE_FAST_REDIRECTS */
1240 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1241 #endif /* ndef FEATURE_FAST_REDIRECTS */
1243 #ifdef FEATURE_FORCE_LOAD
1244 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1245 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1246 #else /* ifndef FEATURE_FORCE_LOAD */
1247 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1248 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1249 #endif /* ndef FEATURE_FORCE_LOAD */
1251 #ifdef FEATURE_IMAGE_BLOCKING
1252 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1253 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1254 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1255 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1257 #ifdef FEATURE_IMAGE_DETECT_MSIE
1258 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1259 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1260 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1261 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1263 #ifdef FEATURE_KILL_POPUPS
1264 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1265 #else /* ifndef FEATURE_KILL_POPUPS */
1266 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1267 #endif /* ndef FEATURE_KILL_POPUPS */
1269 #ifdef FEATURE_NO_GIFS
1270 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1271 #else /* ifndef FEATURE_NO_GIFS */
1272 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1273 #endif /* ndef FEATURE_NO_GIFS */
1275 #ifdef FEATURE_PTHREAD
1276 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1277 #else /* ifndef FEATURE_PTHREAD */
1278 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1279 #endif /* ndef FEATURE_PTHREAD */
1281 #ifdef FEATURE_STATISTICS
1282 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1283 #else /* ifndef FEATURE_STATISTICS */
1284 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1285 #endif /* ndef FEATURE_STATISTICS */
1287 #ifdef FEATURE_TOGGLE
1288 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1289 #else /* ifndef FEATURE_TOGGLE */
1290 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1291 #endif /* ndef FEATURE_TOGGLE */
1293 #ifdef FEATURE_TRUST
1294 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1295 #else /* ifndef FEATURE_TRUST */
1296 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1297 #endif /* ndef FEATURE_TRUST */
1300 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1301 #else /* ifndef STATIC_PCRE */
1302 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1303 #endif /* ndef STATIC_PCRE */
1306 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1307 #else /* ifndef STATIC_PCRS */
1308 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1309 #endif /* ndef STATIC_PCRS */
1315 /*********************************************************************
1317 * Function : show_rcs
1319 * Description : Create a string with the rcs info for all sourcefiles
1323 * Returns : A string, or NULL on out-of-memory.
1325 *********************************************************************/
1326 static char *show_rcs(void)
1328 char *result = strdup("");
1329 char buf[BUFFER_SIZE];
1331 /* Instead of including *all* dot h's in the project (thus creating a
1332 * tremendous amount of dependencies), I will concede to declaring them
1333 * as extern's. This forces the developer to add to this list, but oh well.
1336 #define SHOW_RCS(__x) \
1338 extern const char __x[]; \
1339 sprintf(buf, "%s\n", __x); \
1340 string_append(&result, buf); \
1343 /* In alphabetical order */
1344 SHOW_RCS(actions_h_rcs)
1345 SHOW_RCS(actions_rcs)
1347 SHOW_RCS(amiga_h_rcs)
1349 #endif /* def AMIGA */
1352 #ifdef FEATURE_CGI_EDIT_ACTIONS
1353 SHOW_RCS(cgiedit_h_rcs)
1354 SHOW_RCS(cgiedit_rcs)
1355 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1356 SHOW_RCS(cgisimple_h_rcs)
1357 SHOW_RCS(cgisimple_rcs)
1359 SHOW_RCS(cygwin_h_rcs)
1361 SHOW_RCS(deanimate_h_rcs)
1362 SHOW_RCS(deanimate_rcs)
1363 SHOW_RCS(encode_h_rcs)
1364 SHOW_RCS(encode_rcs)
1365 SHOW_RCS(errlog_h_rcs)
1366 SHOW_RCS(errlog_rcs)
1367 SHOW_RCS(filters_h_rcs)
1368 SHOW_RCS(filters_rcs)
1369 SHOW_RCS(gateway_h_rcs)
1370 SHOW_RCS(gateway_rcs)
1371 SHOW_RCS(jbsockets_h_rcs)
1372 SHOW_RCS(jbsockets_rcs)
1375 #ifdef FEATURE_KILL_POPUPS
1376 SHOW_RCS(killpopup_h_rcs)
1377 SHOW_RCS(killpopup_rcs)
1378 #endif /* def FEATURE_KILL_POPUPS */
1379 SHOW_RCS(list_h_rcs)
1381 SHOW_RCS(loadcfg_h_rcs)
1382 SHOW_RCS(loadcfg_rcs)
1383 SHOW_RCS(loaders_h_rcs)
1384 SHOW_RCS(loaders_rcs)
1385 SHOW_RCS(miscutil_h_rcs)
1386 SHOW_RCS(miscutil_rcs)
1387 SHOW_RCS(parsers_h_rcs)
1388 SHOW_RCS(parsers_rcs)
1390 SHOW_RCS(pcrs_h_rcs)
1391 SHOW_RCS(project_h_rcs)
1392 SHOW_RCS(ssplit_h_rcs)
1393 SHOW_RCS(ssplit_rcs)
1394 SHOW_RCS(urlmatch_h_rcs)
1395 SHOW_RCS(urlmatch_rcs)
1397 #ifndef _WIN_CONSOLE
1398 SHOW_RCS(w32log_h_rcs)
1399 SHOW_RCS(w32log_rcs)
1400 SHOW_RCS(w32res_h_rcs)
1401 SHOW_RCS(w32taskbar_h_rcs)
1402 SHOW_RCS(w32taskbar_rcs)
1403 #endif /* ndef _WIN_CONSOLE */
1404 SHOW_RCS(win32_h_rcs)
1406 #endif /* def _WIN32 */