1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.27 2002/04/05 15:50:48 oes 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.27 2002/04/05 15:50:48 oes
40 * added send-stylesheet CGI
42 * Revision 1.26 2002/04/04 00:36:36 gliptak
43 * always use pcre for matching
45 * Revision 1.25 2002/04/03 22:28:03 gliptak
46 * Removed references to gnu_regex
48 * Revision 1.24 2002/04/02 16:12:47 oes
49 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
51 * Revision 1.23 2002/03/26 22:29:54 swa
52 * we have a new homepage!
54 * Revision 1.22 2002/03/24 16:18:15 jongfoster
57 * Revision 1.21 2002/03/24 15:23:33 jongfoster
60 * Revision 1.20 2002/03/24 13:25:43 swa
61 * name change related issues
63 * Revision 1.19 2002/03/16 23:54:06 jongfoster
64 * Adding graceful termination feature, to help look for memory leaks.
65 * If you enable this (which, by design, has to be done by hand
66 * editing config.h) and then go to http://i.j.b/die, then the program
67 * will exit cleanly after the *next* request. It should free all the
68 * memory that was used.
70 * Revision 1.18 2002/03/12 01:44:49 oes
71 * Changed default for "blocked" image from jb logo to checkboard pattern
73 * Revision 1.17 2002/03/08 16:43:18 oes
74 * Added choice beween GIF and PNG built-in images
76 * Revision 1.16 2002/03/07 03:48:38 oes
77 * - Changed built-in images from GIF to PNG
78 * (with regard to Unisys patent issue)
79 * - Added a 4x4 pattern PNG which is less intrusive
80 * than the logo but also clearly marks the deleted banners
82 * Revision 1.15 2002/03/06 22:54:35 jongfoster
83 * Automated function-comment nitpicking.
85 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
86 * Clean up a little CRLF unpleasantness that suddenly appeared
88 * Revision 1.13 2002/02/21 00:10:37 jongfoster
89 * Adding send-banner?type=auto option
91 * Revision 1.12 2002/01/23 01:03:32 jongfoster
92 * Fixing gcc [CygWin] compiler warnings
94 * Revision 1.11 2002/01/23 00:01:04 jongfoster
95 * Adding cgi_transparent_gif() for http://i.j.b/t
96 * Adding missing html_encode() to many CGI functions.
97 * Adding urlmatch.[ch] to http://i.j.b/show-version
99 * Revision 1.10 2002/01/17 21:10:37 jongfoster
100 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
101 * Also fixing a problem in the same function with improperly quoted URLs
102 * in output HTML, and adding code to handle https:// URLs correctly.
104 * Revision 1.9 2001/11/30 23:09:15 jongfoster
105 * Now reports on FEATURE_CGI_EDIT_ACTIONS
106 * Removing FEATURE_DENY_GZIP from template
108 * Revision 1.8 2001/11/13 00:14:07 jongfoster
109 * Fixing stupid bug now I've figured out what || means.
110 * (It always returns 0 or 1, not one of it's paramaters.)
112 * Revision 1.7 2001/10/23 21:48:19 jongfoster
113 * Cleaning up error handling in CGI functions - they now send back
114 * a HTML error page and should never cause a FATAL error. (Fixes one
115 * potential source of "denial of service" attacks).
117 * CGI actions file editor that works and is actually useful.
119 * Ability to toggle JunkBuster remotely using a CGI call.
121 * You can turn off both the above features in the main configuration
122 * file, e.g. if you are running a multi-user proxy.
124 * Revision 1.6 2001/10/14 22:00:32 jongfoster
125 * Adding support for a 404 error when an invalid CGI page is requested.
127 * Revision 1.5 2001/10/07 15:30:41 oes
128 * Removed FEATURE_DENY_GZIP
130 * Revision 1.4 2001/10/02 15:31:12 oes
131 * Introduced show-request cgi
133 * Revision 1.3 2001/09/22 16:34:44 jongfoster
134 * Removing unneeded #includes
136 * Revision 1.2 2001/09/19 18:01:11 oes
137 * Fixed comments; cosmetics
139 * Revision 1.1 2001/09/16 17:08:54 jongfoster
140 * Moving simple CGI functions from cgi.c to new file cgisimple.c
143 **********************************************************************/
149 #include <sys/types.h>
156 #define snprintf _snprintf
157 #endif /* def _WIN32 */
161 #include "cgisimple.h"
167 #include "miscutil.h"
170 #include "urlmatch.h"
173 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
176 static char *show_rcs(void);
177 static jb_err show_defines(struct map *exports);
180 /*********************************************************************
182 * Function : cgi_default
184 * Description : CGI function that is called if no action was given.
185 * Lists menu of available unhidden CGIs.
188 * 1 : csp = Current client state (buffers, headers, etc...)
189 * 2 : rsp = http_response data structure for output
190 * 3 : parameters = map of cgi parameters
192 * CGI Parameters : none
194 * Returns : JB_ERR_OK on success
195 * JB_ERR_MEMORY on out-of-memory
196 * (Problems other than out-of-memory should be
197 * handled by this routine - it should set the
198 * rsp appropriately and return "success")
200 *********************************************************************/
201 jb_err cgi_default(struct client_state *csp,
202 struct http_response *rsp,
203 const struct map *parameters)
212 if (NULL == (exports = default_exports(csp, "")))
214 return JB_ERR_MEMORY;
217 /* If there were other parameters, export a dump as "cgi-parameters" */
218 if (parameters->first)
220 tmp = strdup("<p>What made you think this cgi takes parameters?\n"
221 "Anyway, here they are, in case you're interested:</p>\n");
222 string_join(&tmp, dump_map(parameters));
226 return JB_ERR_MEMORY;
228 if (map(exports, "cgi-parameters", 1, tmp, 0))
230 return JB_ERR_MEMORY;
235 if (map(exports, "cgi-parameters", 1, "", 1))
237 return JB_ERR_MEMORY;
241 return template_fill_for_cgi(csp, "default", exports, rsp);
247 /*********************************************************************
249 * Function : cgi_error_404
251 * Description : CGI function that is called if an unknown action was
255 * 1 : csp = Current client state (buffers, headers, etc...)
256 * 2 : rsp = http_response data structure for output
257 * 3 : parameters = map of cgi parameters
259 * CGI Parameters : none
261 * Returns : JB_ERR_OK on success
262 * JB_ERR_MEMORY on out-of-memory error.
264 *********************************************************************/
265 jb_err cgi_error_404(struct client_state *csp,
266 struct http_response *rsp,
267 const struct map *parameters)
275 if (NULL == (exports = default_exports(csp, NULL)))
277 return JB_ERR_MEMORY;
280 rsp->status = strdup("404 Privoxy configuration page not found");
281 if (rsp->status == NULL)
284 return JB_ERR_MEMORY;
287 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
291 #ifdef FEATURE_GRACEFUL_TERMINATION
292 /*********************************************************************
296 * Description : CGI function to shut down Privoxy.
297 * NOTE: Turning this on in a production build
298 * would be a BAD idea. An EXTREMELY BAD idea.
299 * In short, don't do it.
302 * 1 : csp = Current client state (buffers, headers, etc...)
303 * 2 : rsp = http_response data structure for output
304 * 3 : parameters = map of cgi parameters
306 * CGI Parameters : none
308 * Returns : JB_ERR_OK on success
309 * JB_ERR_MEMORY on out-of-memory error.
311 *********************************************************************/
312 jb_err cgi_die (struct client_state *csp,
313 struct http_response *rsp,
314 const struct map *parameters)
324 * I don't really care what gets sent back to the browser.
325 * Take the easy option - "out of memory" page.
328 return JB_ERR_MEMORY;
330 #endif /* def FEATURE_GRACEFUL_TERMINATION */
333 /*********************************************************************
335 * Function : cgi_show_request
337 * Description : Show the client's request and what sed() would have
341 * 1 : csp = Current client state (buffers, headers, etc...)
342 * 2 : rsp = http_response data structure for output
343 * 3 : parameters = map of cgi parameters
345 * CGI Parameters : none
347 * Returns : JB_ERR_OK on success
348 * JB_ERR_MEMORY on out-of-memory error.
350 *********************************************************************/
351 jb_err cgi_show_request(struct client_state *csp,
352 struct http_response *rsp,
353 const struct map *parameters)
362 if (NULL == (exports = default_exports(csp, "show-request")))
364 return JB_ERR_MEMORY;
368 * Repair the damage done to the IOB by get_header()
370 for (p = csp->iob->buf; p < csp->iob->eod; p++)
372 if (*p == '\0') *p = '\n';
376 * Export the original client's request and the one we would
377 * be sending to the server if this wasn't a CGI call
380 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
383 return JB_ERR_MEMORY;
386 if (map(exports, "processed-request", 1, html_encode_and_free_original(
387 sed(client_patterns, add_client_headers, csp)), 0))
390 return JB_ERR_MEMORY;
393 return template_fill_for_cgi(csp, "show-request", exports, rsp);
397 /*********************************************************************
399 * Function : cgi_send_banner
401 * Description : CGI function that returns a banner.
404 * 1 : csp = Current client state (buffers, headers, etc...)
405 * 2 : rsp = http_response data structure for output
406 * 3 : parameters = map of cgi parameters
409 * type : Selects the type of banner between "trans", "logo",
410 * and "auto". Defaults to "logo" if absent or invalid.
411 * "auto" means to select as if we were image-blocking.
412 * (Only the first character really counts).
414 * Returns : JB_ERR_OK on success
415 * JB_ERR_MEMORY on out-of-memory error.
417 *********************************************************************/
418 jb_err cgi_send_banner(struct client_state *csp,
419 struct http_response *rsp,
420 const struct map *parameters)
422 char imagetype = lookup(parameters, "type")[0];
424 if (imagetype == 'a') /* auto */
426 /* Default to pattern */
428 #ifdef FEATURE_IMAGE_BLOCKING
429 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
431 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
432 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
434 /* determine HOW images should be blocked */
435 const char * p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
437 /* and handle accordingly: */
440 /* Use default - nothing to do here. */
442 else if (0 == strcmpic(p, "blank"))
446 else if (0 == strcmpic(p, "pattern"))
450 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
452 imagetype = p[sizeof(prefix1) - 1];
454 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
456 imagetype = p[sizeof(prefix2) - 1];
459 #endif /* def FEATURE_IMAGE_BLOCKING */
462 if ((imagetype == 'b') || (imagetype == 't')) /* blank / transparent */
464 rsp->body = bindup(image_blank_data, image_blank_length);
465 rsp->content_length = image_blank_length;
470 rsp->body = bindup(image_pattern_data, image_pattern_length);
471 rsp->content_length = image_pattern_length;
474 if (rsp->body == NULL)
476 return JB_ERR_MEMORY;
479 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
481 return JB_ERR_MEMORY;
491 /*********************************************************************
493 * Function : cgi_transparent_image
495 * Description : CGI function that sends a 1x1 transparent image.
498 * 1 : csp = Current client state (buffers, headers, etc...)
499 * 2 : rsp = http_response data structure for output
500 * 3 : parameters = map of cgi parameters
502 * CGI Parameters : None
504 * Returns : JB_ERR_OK on success
505 * JB_ERR_MEMORY on out-of-memory error.
507 *********************************************************************/
508 jb_err cgi_transparent_image(struct client_state *csp,
509 struct http_response *rsp,
510 const struct map *parameters)
512 rsp->body = bindup(image_blank_data, image_blank_length);
513 rsp->content_length = image_blank_length;
515 if (rsp->body == NULL)
517 return JB_ERR_MEMORY;
520 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
522 return JB_ERR_MEMORY;
532 /*********************************************************************
534 * Function : cgi_send_stylesheet
536 * Description : CGI function that sends a css stylesheet found
537 * in the cgi-style.css template
540 * 1 : csp = Current client state (buffers, headers, etc...)
541 * 2 : rsp = http_response data structure for output
542 * 3 : parameters = map of cgi parameters
544 * CGI Parameters : None
546 * Returns : JB_ERR_OK on success
547 * JB_ERR_MEMORY on out-of-memory error.
549 *********************************************************************/
550 jb_err cgi_send_stylesheet(struct client_state *csp,
551 struct http_response *rsp,
552 const struct map *parameters)
559 err = template_load(csp, &rsp->body, "cgi-style.css");
561 if (err == JB_ERR_FILE)
564 * No way to tell user; send empty stylesheet
566 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
570 return err; /* JB_ERR_MEMORY */
573 if (enlist(rsp->headers, "Content-Type: text/css"))
575 return JB_ERR_MEMORY;
583 /*********************************************************************
585 * Function : cgi_show_version
587 * Description : CGI function that returns a a web page describing the
588 * file versions of Privoxy.
591 * 1 : csp = Current client state (buffers, headers, etc...)
592 * 2 : rsp = http_response data structure for output
593 * 3 : parameters = map of cgi parameters
595 * CGI Parameters : none
597 * Returns : JB_ERR_OK on success
598 * JB_ERR_MEMORY on out-of-memory error.
600 *********************************************************************/
601 jb_err cgi_show_version(struct client_state *csp,
602 struct http_response *rsp,
603 const struct map *parameters)
611 if (NULL == (exports = default_exports(csp, "show-version")))
613 return JB_ERR_MEMORY;
616 if (map(exports, "sourceversions", 1, show_rcs(), 0))
619 return JB_ERR_MEMORY;
622 return template_fill_for_cgi(csp, "show-version", exports, rsp);
626 /*********************************************************************
628 * Function : cgi_show_status
630 * Description : CGI function that returns a a web page describing the
631 * current status of Privoxy.
634 * 1 : csp = Current client state (buffers, headers, etc...)
635 * 2 : rsp = http_response data structure for output
636 * 3 : parameters = map of cgi parameters
639 * file : Which file to show. Only first letter is checked,
641 * - "p"ermissions (actions) file
644 * Default is to show menu and other information.
646 * Returns : JB_ERR_OK on success
647 * JB_ERR_MEMORY on out-of-memory error.
649 *********************************************************************/
650 jb_err cgi_show_status(struct client_state *csp,
651 struct http_response *rsp,
652 const struct map *parameters)
658 char buf[BUFFER_SIZE];
659 const char * filename = NULL;
660 char * file_description = NULL;
661 #ifdef FEATURE_STATISTICS
662 float perc_rej; /* Percentage of http requests rejected */
664 int local_urls_rejected;
665 #endif /* ndef FEATURE_STATISTICS */
674 if (NULL == (exports = default_exports(csp, "show-status")))
676 return JB_ERR_MEMORY;
679 switch (*(lookup(parameters, "file")))
682 if (csp->actions_list)
684 filename = csp->actions_list->filename;
685 file_description = "Actions List";
692 filename = csp->rlist->filename;
693 file_description = "Regex Filter List";
701 filename = csp->tlist->filename;
702 file_description = "Trust List";
705 #endif /* def FEATURE_TRUST */
708 if (NULL != filename)
710 if ( map(exports, "file-description", 1, file_description, 1)
711 || map(exports, "filepath", 1, html_encode(filename), 0) )
714 return JB_ERR_MEMORY;
717 if ((fp = fopen(filename, "r")) == NULL)
719 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
722 return JB_ERR_MEMORY;
728 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
730 string_join (&s, html_encode(buf));
734 if (map(exports, "contents", 1, s, 0))
737 return JB_ERR_MEMORY;
741 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
744 if (map(exports, "redirect-url", 1, html_encode(REDIRECT_URL), 0))
747 return JB_ERR_MEMORY;
751 for (i = 0; (s != NULL) && (i < Argc); i++)
753 string_join (&s, html_encode(Argv[i]));
754 string_append(&s, " ");
756 if (map(exports, "invocation", 1, s, 0))
759 return JB_ERR_MEMORY;
762 err = map(exports, "options", 1, csp->config->proxy_args, 1);
763 if (!err) err = show_defines(exports);
765 #ifdef FEATURE_STATISTICS
766 local_urls_read = urls_read;
767 local_urls_rejected = urls_rejected;
770 * Need to alter the stats not to include the fetch of this
773 * Can't do following thread safely! doh!
776 * urls_rejected--; * This will be incremented subsequently *
779 if (local_urls_read == 0)
781 if (!err) err = map_block_killer(exports, "have-stats");
785 if (!err) err = map_block_killer(exports, "have-no-stats");
787 perc_rej = (float)local_urls_rejected * 100.0F /
788 (float)local_urls_read;
790 sprintf(buf, "%d", local_urls_read);
791 if (!err) err = map(exports, "requests-received", 1, buf, 1);
793 sprintf(buf, "%d", local_urls_rejected);
794 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
796 sprintf(buf, "%6.2f", perc_rej);
797 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
800 #else /* ndef FEATURE_STATISTICS */
801 err = err || map_block_killer(exports, "statistics");
802 #endif /* ndef FEATURE_STATISTICS */
804 if (csp->actions_list)
806 if (!err) err = map(exports, "actions-filename", 1, html_encode(csp->actions_list->filename), 0);
810 if (!err) err = map(exports, "actions-filename", 1, "None specified", 1);
815 if (!err) err = map(exports, "re-filter-filename", 1, html_encode(csp->rlist->filename), 0);
819 if (!err) err = map(exports, "re-filter-filename", 1, "None specified", 1);
825 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
829 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
832 if (!err) err = map_block_killer(exports, "trust-support");
833 #endif /* ndef FEATURE_TRUST */
838 return JB_ERR_MEMORY;
841 return template_fill_for_cgi(csp, "show-status", exports, rsp);
845 /*********************************************************************
847 * Function : cgi_show_url_info
849 * Description : CGI function that determines and shows which actions
850 * Privoxy will perform for a given url, and which
851 * matches starting from the defaults have lead to that.
854 * 1 : csp = Current client state (buffers, headers, etc...)
855 * 2 : rsp = http_response data structure for output
856 * 3 : parameters = map of cgi parameters
859 * url : The url whose actions are to be determined.
860 * If url is unset, the url-given conditional will be
861 * set, so that all but the form can be suppressed in
864 * Returns : JB_ERR_OK on success
865 * JB_ERR_MEMORY on out-of-memory error.
867 *********************************************************************/
868 jb_err cgi_show_url_info(struct client_state *csp,
869 struct http_response *rsp,
870 const struct map *parameters)
879 if (NULL == (exports = default_exports(csp, "show-url-info")))
881 return JB_ERR_MEMORY;
885 * Get the url= parameter (if present) and remove any leading/trailing spaces.
887 url_param = strdup(lookup(parameters, "url"));
888 if (url_param == NULL)
891 return JB_ERR_MEMORY;
896 * Handle prefixes. 4 possibilities:
897 * 1) "http://" or "https://" prefix present and followed by URL - OK
898 * 2) Only the "http://" or "https://" part is present, no URL - change
899 * to empty string so it will be detected later as "no URL".
900 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
902 * 4) Parameter not specified or is empty string - let this fall through
903 * for now, next block of code will handle it.
905 if (0 == strncmp(url_param, "http://", 7))
907 if (url_param[7] == '\0')
910 * Empty URL (just prefix).
911 * Make it totally empty so it's caught by the next if()
916 else if (0 == strncmp(url_param, "https://", 8))
918 if (url_param[8] == '\0')
921 * Empty URL (just prefix).
922 * Make it totally empty so it's caught by the next if()
927 else if (url_param[0] != '\0')
930 * Unknown prefix - assume http://
932 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
933 if (NULL == url_param_prefixed)
937 return JB_ERR_MEMORY;
939 strcpy(url_param_prefixed, "http://");
940 strcpy(url_param_prefixed + 7, url_param);
942 url_param = url_param_prefixed;
946 if (url_param[0] == '\0')
948 /* URL paramater not specified, display query form only. */
950 if (map_block_killer(exports, "url-given")
951 || map(exports, "url", 1, "", 1))
954 return JB_ERR_MEMORY;
959 /* Given a URL, so query it. */
964 struct file_list *fl;
965 struct url_actions *b;
966 struct http_request url_to_query[1];
967 struct current_action_spec action[1];
969 if (map(exports, "url", 1, html_encode(url_param), 0))
973 return JB_ERR_MEMORY;
976 init_current_action(action);
978 if (map(exports, "default", 1, html_encode_and_free_original(
979 current_action_to_text(action)), 0))
981 free_current_action(action);
984 return JB_ERR_MEMORY;
987 if (((fl = csp->actions_list) == NULL) || ((b = fl->f) == NULL))
989 err = map(exports, "matches", 1, "none" , 1);
990 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
992 free_current_action(action);
998 return JB_ERR_MEMORY;
1001 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1004 err = parse_http_url(url_param, url_to_query, csp);
1008 if (err == JB_ERR_MEMORY)
1010 free_current_action(action);
1012 return JB_ERR_MEMORY;
1018 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1019 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1021 free_current_action(action);
1026 return JB_ERR_MEMORY;
1029 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1033 * We have a warning about SSL paths. Hide it for insecure sites.
1035 if (!url_to_query->ssl)
1037 if (map_block_killer(exports, "https"))
1039 free_current_action(action);
1041 return JB_ERR_MEMORY;
1045 matches = strdup("");
1047 for (b = b->next; (b != NULL) && (matches != NULL); b = b->next)
1049 if (url_match(b->url, url_to_query))
1051 string_append(&matches, "<b>{");
1052 string_join (&matches, html_encode_and_free_original(
1053 actions_to_text(b->action)));
1054 string_append(&matches, " }</b><br>\n<code>");
1055 string_join (&matches, html_encode(b->url->spec));
1056 string_append(&matches, "</code><br>\n<br>\n");
1058 if (merge_current_action(action, b->action))
1061 free_http_request(url_to_query);
1062 free_current_action(action);
1064 return JB_ERR_MEMORY;
1070 free_http_request(url_to_query);
1072 if (matches == NULL)
1074 free_current_action(action);
1076 return JB_ERR_MEMORY;
1082 matches = strdup("none");
1084 if (map(exports, "matches", 1, matches , 0))
1086 free_current_action(action);
1088 return JB_ERR_MEMORY;
1091 s = html_encode_and_free_original(current_action_to_text(action));
1093 free_current_action(action);
1095 if (map(exports, "final", 1, s, 0))
1098 return JB_ERR_MEMORY;
1102 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1106 /*********************************************************************
1108 * Function : cgi_robots_txt
1110 * Description : CGI function to return "/robots.txt".
1113 * 1 : csp = Current client state (buffers, headers, etc...)
1114 * 2 : rsp = http_response data structure for output
1115 * 3 : parameters = map of cgi parameters
1117 * CGI Parameters : None
1119 * Returns : JB_ERR_OK on success
1120 * JB_ERR_MEMORY on out-of-memory error.
1122 *********************************************************************/
1123 jb_err cgi_robots_txt(struct client_state *csp,
1124 struct http_response *rsp,
1125 const struct map *parameters)
1131 "# This is the Privoxy control interface.\n"
1132 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1138 if (rsp->body == NULL)
1140 return JB_ERR_MEMORY;
1143 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1147 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1148 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1150 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1154 /*********************************************************************
1156 * Function : show_defines
1158 * Description : Add to a map the state od all conditional #defines
1159 * used when building
1162 * 1 : exports = map to extend
1164 * Returns : JB_ERR_OK on success
1165 * JB_ERR_MEMORY on out-of-memory error.
1167 *********************************************************************/
1168 static jb_err show_defines(struct map *exports)
1170 jb_err err = JB_ERR_OK;
1173 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1174 #else /* ifndef FEATURE_ACL */
1175 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1176 #endif /* ndef FEATURE_ACL */
1178 #ifdef FEATURE_CGI_EDIT_ACTIONS
1179 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1180 #else /* ifndef FEATURE_COOKIE_JAR */
1181 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1182 #endif /* ndef FEATURE_COOKIE_JAR */
1184 #ifdef FEATURE_COOKIE_JAR
1185 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1186 #else /* ifndef FEATURE_COOKIE_JAR */
1187 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1188 #endif /* ndef FEATURE_COOKIE_JAR */
1190 #ifdef FEATURE_FAST_REDIRECTS
1191 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1192 #else /* ifndef FEATURE_FAST_REDIRECTS */
1193 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1194 #endif /* ndef FEATURE_FAST_REDIRECTS */
1196 #ifdef FEATURE_FORCE_LOAD
1197 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1198 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1199 #else /* ifndef FEATURE_FORCE_LOAD */
1200 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1201 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1202 #endif /* ndef FEATURE_FORCE_LOAD */
1204 #ifdef FEATURE_IMAGE_BLOCKING
1205 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1206 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1207 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1208 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1210 #ifdef FEATURE_IMAGE_DETECT_MSIE
1211 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1212 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1213 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1214 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1216 #ifdef FEATURE_KILL_POPUPS
1217 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1218 #else /* ifndef FEATURE_KILL_POPUPS */
1219 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1220 #endif /* ndef FEATURE_KILL_POPUPS */
1222 #ifdef FEATURE_NO_GIFS
1223 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1224 #else /* ifndef FEATURE_NO_GIFS */
1225 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1226 #endif /* ndef FEATURE_NO_GIFS */
1228 #ifdef FEATURE_PTHREAD
1229 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1230 #else /* ifndef FEATURE_PTHREAD */
1231 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1232 #endif /* ndef FEATURE_PTHREAD */
1234 #ifdef FEATURE_STATISTICS
1235 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1236 #else /* ifndef FEATURE_STATISTICS */
1237 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1238 #endif /* ndef FEATURE_STATISTICS */
1240 #ifdef FEATURE_TOGGLE
1241 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1242 #else /* ifndef FEATURE_TOGGLE */
1243 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1244 #endif /* ndef FEATURE_TOGGLE */
1246 #ifdef FEATURE_TRUST
1247 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1248 #else /* ifndef FEATURE_TRUST */
1249 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1250 #endif /* ndef FEATURE_TRUST */
1253 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1254 #else /* ifndef STATIC_PCRE */
1255 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1256 #endif /* ndef STATIC_PCRE */
1259 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1260 #else /* ifndef STATIC_PCRS */
1261 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1262 #endif /* ndef STATIC_PCRS */
1268 /*********************************************************************
1270 * Function : show_rcs
1272 * Description : Create a string with the rcs info for all sourcefiles
1276 * Returns : A string, or NULL on out-of-memory.
1278 *********************************************************************/
1279 static char *show_rcs(void)
1281 char *result = strdup("");
1282 char buf[BUFFER_SIZE];
1284 /* Instead of including *all* dot h's in the project (thus creating a
1285 * tremendous amount of dependencies), I will concede to declaring them
1286 * as extern's. This forces the developer to add to this list, but oh well.
1289 #define SHOW_RCS(__x) \
1291 extern const char __x[]; \
1292 sprintf(buf, "%s\n", __x); \
1293 string_append(&result, buf); \
1296 /* In alphabetical order */
1297 SHOW_RCS(actions_h_rcs)
1298 SHOW_RCS(actions_rcs)
1301 #ifdef FEATURE_CGI_EDIT_ACTIONS
1302 SHOW_RCS(cgiedit_h_rcs)
1303 SHOW_RCS(cgiedit_rcs)
1304 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1305 SHOW_RCS(cgisimple_h_rcs)
1306 SHOW_RCS(cgisimple_rcs)
1308 SHOW_RCS(cygwin_h_rcs)
1310 SHOW_RCS(deanimate_h_rcs)
1311 SHOW_RCS(deanimate_rcs)
1312 SHOW_RCS(encode_h_rcs)
1313 SHOW_RCS(encode_rcs)
1314 SHOW_RCS(errlog_h_rcs)
1315 SHOW_RCS(errlog_rcs)
1316 SHOW_RCS(filters_h_rcs)
1317 SHOW_RCS(filters_rcs)
1318 SHOW_RCS(gateway_h_rcs)
1319 SHOW_RCS(gateway_rcs)
1320 SHOW_RCS(jbsockets_h_rcs)
1321 SHOW_RCS(jbsockets_rcs)
1324 #ifdef FEATURE_KILL_POPUPS
1325 SHOW_RCS(killpopup_h_rcs)
1326 SHOW_RCS(killpopup_rcs)
1327 #endif /* def FEATURE_KILL_POPUPS */
1328 SHOW_RCS(list_h_rcs)
1330 SHOW_RCS(loadcfg_h_rcs)
1331 SHOW_RCS(loadcfg_rcs)
1332 SHOW_RCS(loaders_h_rcs)
1333 SHOW_RCS(loaders_rcs)
1334 SHOW_RCS(miscutil_h_rcs)
1335 SHOW_RCS(miscutil_rcs)
1336 SHOW_RCS(parsers_h_rcs)
1337 SHOW_RCS(parsers_rcs)
1339 SHOW_RCS(pcrs_h_rcs)
1340 SHOW_RCS(project_h_rcs)
1341 SHOW_RCS(ssplit_h_rcs)
1342 SHOW_RCS(ssplit_rcs)
1343 SHOW_RCS(urlmatch_h_rcs)
1344 SHOW_RCS(urlmatch_rcs)
1346 #ifndef _WIN_CONSOLE
1347 SHOW_RCS(w32log_h_rcs)
1348 SHOW_RCS(w32log_rcs)
1349 SHOW_RCS(w32res_h_rcs)
1350 SHOW_RCS(w32taskbar_h_rcs)
1351 SHOW_RCS(w32taskbar_rcs)
1352 #endif /* ndef _WIN_CONSOLE */
1353 SHOW_RCS(win32_h_rcs)
1355 #endif /* def _WIN32 */