1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.29 2002/04/10 13:38:35 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.29 2002/04/10 13:38:35 oes
40 * load_template signature changed
42 * Revision 1.28 2002/04/07 15:42:12 jongfoster
43 * Fixing send-banner?type=auto when the image-blocker is
44 * a redirect to send-banner
46 * Revision 1.27 2002/04/05 15:50:48 oes
47 * added send-stylesheet CGI
49 * Revision 1.26 2002/04/04 00:36:36 gliptak
50 * always use pcre for matching
52 * Revision 1.25 2002/04/03 22:28:03 gliptak
53 * Removed references to gnu_regex
55 * Revision 1.24 2002/04/02 16:12:47 oes
56 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
58 * Revision 1.23 2002/03/26 22:29:54 swa
59 * we have a new homepage!
61 * Revision 1.22 2002/03/24 16:18:15 jongfoster
64 * Revision 1.21 2002/03/24 15:23:33 jongfoster
67 * Revision 1.20 2002/03/24 13:25:43 swa
68 * name change related issues
70 * Revision 1.19 2002/03/16 23:54:06 jongfoster
71 * Adding graceful termination feature, to help look for memory leaks.
72 * If you enable this (which, by design, has to be done by hand
73 * editing config.h) and then go to http://i.j.b/die, then the program
74 * will exit cleanly after the *next* request. It should free all the
75 * memory that was used.
77 * Revision 1.18 2002/03/12 01:44:49 oes
78 * Changed default for "blocked" image from jb logo to checkboard pattern
80 * Revision 1.17 2002/03/08 16:43:18 oes
81 * Added choice beween GIF and PNG built-in images
83 * Revision 1.16 2002/03/07 03:48:38 oes
84 * - Changed built-in images from GIF to PNG
85 * (with regard to Unisys patent issue)
86 * - Added a 4x4 pattern PNG which is less intrusive
87 * than the logo but also clearly marks the deleted banners
89 * Revision 1.15 2002/03/06 22:54:35 jongfoster
90 * Automated function-comment nitpicking.
92 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
93 * Clean up a little CRLF unpleasantness that suddenly appeared
95 * Revision 1.13 2002/02/21 00:10:37 jongfoster
96 * Adding send-banner?type=auto option
98 * Revision 1.12 2002/01/23 01:03:32 jongfoster
99 * Fixing gcc [CygWin] compiler warnings
101 * Revision 1.11 2002/01/23 00:01:04 jongfoster
102 * Adding cgi_transparent_gif() for http://i.j.b/t
103 * Adding missing html_encode() to many CGI functions.
104 * Adding urlmatch.[ch] to http://i.j.b/show-version
106 * Revision 1.10 2002/01/17 21:10:37 jongfoster
107 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
108 * Also fixing a problem in the same function with improperly quoted URLs
109 * in output HTML, and adding code to handle https:// URLs correctly.
111 * Revision 1.9 2001/11/30 23:09:15 jongfoster
112 * Now reports on FEATURE_CGI_EDIT_ACTIONS
113 * Removing FEATURE_DENY_GZIP from template
115 * Revision 1.8 2001/11/13 00:14:07 jongfoster
116 * Fixing stupid bug now I've figured out what || means.
117 * (It always returns 0 or 1, not one of it's paramaters.)
119 * Revision 1.7 2001/10/23 21:48:19 jongfoster
120 * Cleaning up error handling in CGI functions - they now send back
121 * a HTML error page and should never cause a FATAL error. (Fixes one
122 * potential source of "denial of service" attacks).
124 * CGI actions file editor that works and is actually useful.
126 * Ability to toggle JunkBuster remotely using a CGI call.
128 * You can turn off both the above features in the main configuration
129 * file, e.g. if you are running a multi-user proxy.
131 * Revision 1.6 2001/10/14 22:00:32 jongfoster
132 * Adding support for a 404 error when an invalid CGI page is requested.
134 * Revision 1.5 2001/10/07 15:30:41 oes
135 * Removed FEATURE_DENY_GZIP
137 * Revision 1.4 2001/10/02 15:31:12 oes
138 * Introduced show-request cgi
140 * Revision 1.3 2001/09/22 16:34:44 jongfoster
141 * Removing unneeded #includes
143 * Revision 1.2 2001/09/19 18:01:11 oes
144 * Fixed comments; cosmetics
146 * Revision 1.1 2001/09/16 17:08:54 jongfoster
147 * Moving simple CGI functions from cgi.c to new file cgisimple.c
150 **********************************************************************/
156 #include <sys/types.h>
163 #define snprintf _snprintf
164 #endif /* def _WIN32 */
168 #include "cgisimple.h"
174 #include "miscutil.h"
177 #include "urlmatch.h"
180 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
183 static char *show_rcs(void);
184 static jb_err show_defines(struct map *exports);
187 /*********************************************************************
189 * Function : cgi_default
191 * Description : CGI function that is called if no action was given.
192 * Lists menu of available unhidden CGIs.
195 * 1 : csp = Current client state (buffers, headers, etc...)
196 * 2 : rsp = http_response data structure for output
197 * 3 : parameters = map of cgi parameters
199 * CGI Parameters : none
201 * Returns : JB_ERR_OK on success
202 * JB_ERR_MEMORY on out-of-memory
203 * (Problems other than out-of-memory should be
204 * handled by this routine - it should set the
205 * rsp appropriately and return "success")
207 *********************************************************************/
208 jb_err cgi_default(struct client_state *csp,
209 struct http_response *rsp,
210 const struct map *parameters)
219 if (NULL == (exports = default_exports(csp, "")))
221 return JB_ERR_MEMORY;
224 /* If there were other parameters, export a dump as "cgi-parameters" */
225 if (parameters->first)
227 tmp = strdup("<p>What made you think this cgi takes parameters?\n"
228 "Anyway, here they are, in case you're interested:</p>\n");
229 string_join(&tmp, dump_map(parameters));
233 return JB_ERR_MEMORY;
235 if (map(exports, "cgi-parameters", 1, tmp, 0))
237 return JB_ERR_MEMORY;
242 if (map(exports, "cgi-parameters", 1, "", 1))
244 return JB_ERR_MEMORY;
248 return template_fill_for_cgi(csp, "default", exports, rsp);
254 /*********************************************************************
256 * Function : cgi_error_404
258 * Description : CGI function that is called if an unknown action was
262 * 1 : csp = Current client state (buffers, headers, etc...)
263 * 2 : rsp = http_response data structure for output
264 * 3 : parameters = map of cgi parameters
266 * CGI Parameters : none
268 * Returns : JB_ERR_OK on success
269 * JB_ERR_MEMORY on out-of-memory error.
271 *********************************************************************/
272 jb_err cgi_error_404(struct client_state *csp,
273 struct http_response *rsp,
274 const struct map *parameters)
282 if (NULL == (exports = default_exports(csp, NULL)))
284 return JB_ERR_MEMORY;
287 rsp->status = strdup("404 Privoxy configuration page not found");
288 if (rsp->status == NULL)
291 return JB_ERR_MEMORY;
294 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
298 #ifdef FEATURE_GRACEFUL_TERMINATION
299 /*********************************************************************
303 * Description : CGI function to shut down Privoxy.
304 * NOTE: Turning this on in a production build
305 * would be a BAD idea. An EXTREMELY BAD idea.
306 * In short, don't do it.
309 * 1 : csp = Current client state (buffers, headers, etc...)
310 * 2 : rsp = http_response data structure for output
311 * 3 : parameters = map of cgi parameters
313 * CGI Parameters : none
315 * Returns : JB_ERR_OK on success
316 * JB_ERR_MEMORY on out-of-memory error.
318 *********************************************************************/
319 jb_err cgi_die (struct client_state *csp,
320 struct http_response *rsp,
321 const struct map *parameters)
331 * I don't really care what gets sent back to the browser.
332 * Take the easy option - "out of memory" page.
335 return JB_ERR_MEMORY;
337 #endif /* def FEATURE_GRACEFUL_TERMINATION */
340 /*********************************************************************
342 * Function : cgi_show_request
344 * Description : Show the client's request and what sed() would have
348 * 1 : csp = Current client state (buffers, headers, etc...)
349 * 2 : rsp = http_response data structure for output
350 * 3 : parameters = map of cgi parameters
352 * CGI Parameters : none
354 * Returns : JB_ERR_OK on success
355 * JB_ERR_MEMORY on out-of-memory error.
357 *********************************************************************/
358 jb_err cgi_show_request(struct client_state *csp,
359 struct http_response *rsp,
360 const struct map *parameters)
369 if (NULL == (exports = default_exports(csp, "show-request")))
371 return JB_ERR_MEMORY;
375 * Repair the damage done to the IOB by get_header()
377 for (p = csp->iob->buf; p < csp->iob->eod; p++)
379 if (*p == '\0') *p = '\n';
383 * Export the original client's request and the one we would
384 * be sending to the server if this wasn't a CGI call
387 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
390 return JB_ERR_MEMORY;
393 if (map(exports, "processed-request", 1, html_encode_and_free_original(
394 sed(client_patterns, add_client_headers, csp)), 0))
397 return JB_ERR_MEMORY;
400 return template_fill_for_cgi(csp, "show-request", exports, rsp);
404 /*********************************************************************
406 * Function : cgi_send_banner
408 * Description : CGI function that returns a banner.
411 * 1 : csp = Current client state (buffers, headers, etc...)
412 * 2 : rsp = http_response data structure for output
413 * 3 : parameters = map of cgi parameters
416 * type : Selects the type of banner between "trans", "logo",
417 * and "auto". Defaults to "logo" if absent or invalid.
418 * "auto" means to select as if we were image-blocking.
419 * (Only the first character really counts).
421 * Returns : JB_ERR_OK on success
422 * JB_ERR_MEMORY on out-of-memory error.
424 *********************************************************************/
425 jb_err cgi_send_banner(struct client_state *csp,
426 struct http_response *rsp,
427 const struct map *parameters)
429 char imagetype = lookup(parameters, "type")[0];
431 if (imagetype == 'a') /* auto */
433 /* Default to pattern */
435 #ifdef FEATURE_IMAGE_BLOCKING
436 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
438 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
439 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
441 /* determine HOW images should be blocked */
442 const char * p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
444 /* and handle accordingly: */
447 /* Use default - nothing to do here. */
449 else if (0 == strcmpic(p, "blank"))
453 else if (0 == strcmpic(p, "pattern"))
457 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
459 imagetype = p[sizeof(prefix1) - 1];
461 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
463 imagetype = p[sizeof(prefix2) - 1];
466 #endif /* def FEATURE_IMAGE_BLOCKING */
469 if ((imagetype == 'b') || (imagetype == 't')) /* blank / transparent */
471 rsp->body = bindup(image_blank_data, image_blank_length);
472 rsp->content_length = image_blank_length;
477 rsp->body = bindup(image_pattern_data, image_pattern_length);
478 rsp->content_length = image_pattern_length;
481 if (rsp->body == NULL)
483 return JB_ERR_MEMORY;
486 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
488 return JB_ERR_MEMORY;
498 /*********************************************************************
500 * Function : cgi_transparent_image
502 * Description : CGI function that sends a 1x1 transparent image.
505 * 1 : csp = Current client state (buffers, headers, etc...)
506 * 2 : rsp = http_response data structure for output
507 * 3 : parameters = map of cgi parameters
509 * CGI Parameters : None
511 * Returns : JB_ERR_OK on success
512 * JB_ERR_MEMORY on out-of-memory error.
514 *********************************************************************/
515 jb_err cgi_transparent_image(struct client_state *csp,
516 struct http_response *rsp,
517 const struct map *parameters)
519 rsp->body = bindup(image_blank_data, image_blank_length);
520 rsp->content_length = image_blank_length;
522 if (rsp->body == NULL)
524 return JB_ERR_MEMORY;
527 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
529 return JB_ERR_MEMORY;
539 /*********************************************************************
541 * Function : cgi_send_stylesheet
543 * Description : CGI function that sends a css stylesheet found
544 * in the cgi-style.css template
547 * 1 : csp = Current client state (buffers, headers, etc...)
548 * 2 : rsp = http_response data structure for output
549 * 3 : parameters = map of cgi parameters
551 * CGI Parameters : None
553 * Returns : JB_ERR_OK on success
554 * JB_ERR_MEMORY on out-of-memory error.
556 *********************************************************************/
557 jb_err cgi_send_stylesheet(struct client_state *csp,
558 struct http_response *rsp,
559 const struct map *parameters)
566 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
568 if (err == JB_ERR_FILE)
571 * No way to tell user; send empty stylesheet
573 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
577 return err; /* JB_ERR_MEMORY */
580 if (enlist(rsp->headers, "Content-Type: text/css"))
582 return JB_ERR_MEMORY;
590 /*********************************************************************
592 * Function : cgi_show_version
594 * Description : CGI function that returns a a web page describing the
595 * file versions of Privoxy.
598 * 1 : csp = Current client state (buffers, headers, etc...)
599 * 2 : rsp = http_response data structure for output
600 * 3 : parameters = map of cgi parameters
602 * CGI Parameters : none
604 * Returns : JB_ERR_OK on success
605 * JB_ERR_MEMORY on out-of-memory error.
607 *********************************************************************/
608 jb_err cgi_show_version(struct client_state *csp,
609 struct http_response *rsp,
610 const struct map *parameters)
618 if (NULL == (exports = default_exports(csp, "show-version")))
620 return JB_ERR_MEMORY;
623 if (map(exports, "sourceversions", 1, show_rcs(), 0))
626 return JB_ERR_MEMORY;
629 return template_fill_for_cgi(csp, "show-version", exports, rsp);
633 /*********************************************************************
635 * Function : cgi_show_status
637 * Description : CGI function that returns a a web page describing the
638 * current status of Privoxy.
641 * 1 : csp = Current client state (buffers, headers, etc...)
642 * 2 : rsp = http_response data structure for output
643 * 3 : parameters = map of cgi parameters
646 * file : Which file to show. Only first letter is checked,
648 * - "p"ermissions (actions) file
651 * Default is to show menu and other information.
653 * Returns : JB_ERR_OK on success
654 * JB_ERR_MEMORY on out-of-memory error.
656 *********************************************************************/
657 jb_err cgi_show_status(struct client_state *csp,
658 struct http_response *rsp,
659 const struct map *parameters)
665 char buf[BUFFER_SIZE];
666 const char * filename = NULL;
667 char * file_description = NULL;
668 #ifdef FEATURE_STATISTICS
669 float perc_rej; /* Percentage of http requests rejected */
671 int local_urls_rejected;
672 #endif /* ndef FEATURE_STATISTICS */
673 struct file_list * fl;
674 struct url_actions * b;
683 if (NULL == (exports = default_exports(csp, "show-status")))
685 return JB_ERR_MEMORY;
688 switch (*(lookup(parameters, "file")))
691 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_ACTION_FILES && csp->actions_list[i])
693 filename = csp->actions_list[i]->filename;
694 file_description = "Actions File";
701 filename = csp->rlist->filename;
702 file_description = "Filter File";
710 filename = csp->tlist->filename;
711 file_description = "Trust File";
714 #endif /* def FEATURE_TRUST */
717 if (NULL != filename)
719 if ( map(exports, "file-description", 1, file_description, 1)
720 || map(exports, "filepath", 1, html_encode(filename), 0) )
723 return JB_ERR_MEMORY;
726 if ((fp = fopen(filename, "r")) == NULL)
728 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
731 return JB_ERR_MEMORY;
737 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
739 string_join (&s, html_encode(buf));
743 if (map(exports, "contents", 1, s, 0))
746 return JB_ERR_MEMORY;
750 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
753 if (map(exports, "redirect-url", 1, html_encode(REDIRECT_URL), 0))
756 return JB_ERR_MEMORY;
760 for (i = 0; (s != NULL) && (i < Argc); i++)
762 string_join (&s, html_encode(Argv[i]));
763 string_append(&s, " ");
765 if (map(exports, "invocation", 1, s, 0))
768 return JB_ERR_MEMORY;
771 err = map(exports, "options", 1, csp->config->proxy_args, 1);
772 if (!err) err = show_defines(exports);
774 #ifdef FEATURE_STATISTICS
775 local_urls_read = urls_read;
776 local_urls_rejected = urls_rejected;
779 * Need to alter the stats not to include the fetch of this
782 * Can't do following thread safely! doh!
785 * urls_rejected--; * This will be incremented subsequently *
788 if (local_urls_read == 0)
790 if (!err) err = map_block_killer(exports, "have-stats");
794 if (!err) err = map_block_killer(exports, "have-no-stats");
796 perc_rej = (float)local_urls_rejected * 100.0F /
797 (float)local_urls_read;
799 sprintf(buf, "%d", local_urls_read);
800 if (!err) err = map(exports, "requests-received", 1, buf, 1);
802 sprintf(buf, "%d", local_urls_rejected);
803 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
805 sprintf(buf, "%6.2f", perc_rej);
806 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
809 #else /* ndef FEATURE_STATISTICS */
810 err = err || map_block_killer(exports, "statistics");
811 #endif /* ndef FEATURE_STATISTICS */
814 * List all action files in use, together with view and edit links,
815 * except for standard.action, which should only be viewable. (Not
816 * enforced in the editor itself)
817 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
820 for (i = 0; i < MAX_ACTION_FILES; i++)
822 if (((fl = csp->actions_list[i]) != NULL) && ((b = fl->f) != NULL))
824 if (!err) err = string_append(&s, "<tr><td>");
825 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
826 snprintf(buf, 100, "</td><td class=\"cmd\"><a href=\"/show-status?file=actions&index=%d\">View</a> ", i);
827 if (!err) err = string_append(&s, buf);
829 if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
831 snprintf(buf, 100, "<a href=\"/edit-actions-list?f=%s\">Edit</a>", csp->config->actions_file_short[i]);
832 if (!err) err = string_append(&s, buf);
835 if (!err) err = string_append(&s, "</td></tr>\n");
840 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
844 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
849 if (!err) err = map(exports, "re-filter-filename", 1, html_encode(csp->rlist->filename), 0);
853 if (!err) err = map(exports, "re-filter-filename", 1, "None specified", 1);
854 if (!err) err = map_block_killer(exports, "have-filterfile");
860 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
864 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
865 if (!err) err = map_block_killer(exports, "have-trustfile");
868 if (!err) err = map_block_killer(exports, "trust-support");
869 #endif /* ndef FEATURE_TRUST */
874 return JB_ERR_MEMORY;
877 return template_fill_for_cgi(csp, "show-status", exports, rsp);
881 /*********************************************************************
883 * Function : cgi_show_url_info
885 * Description : CGI function that determines and shows which actions
886 * Privoxy will perform for a given url, and which
887 * matches starting from the defaults have lead to that.
890 * 1 : csp = Current client state (buffers, headers, etc...)
891 * 2 : rsp = http_response data structure for output
892 * 3 : parameters = map of cgi parameters
895 * url : The url whose actions are to be determined.
896 * If url is unset, the url-given conditional will be
897 * set, so that all but the form can be suppressed in
900 * Returns : JB_ERR_OK on success
901 * JB_ERR_MEMORY on out-of-memory error.
903 *********************************************************************/
904 jb_err cgi_show_url_info(struct client_state *csp,
905 struct http_response *rsp,
906 const struct map *parameters)
915 if (NULL == (exports = default_exports(csp, "show-url-info")))
917 return JB_ERR_MEMORY;
921 * Get the url= parameter (if present) and remove any leading/trailing spaces.
923 url_param = strdup(lookup(parameters, "url"));
924 if (url_param == NULL)
927 return JB_ERR_MEMORY;
932 * Handle prefixes. 4 possibilities:
933 * 1) "http://" or "https://" prefix present and followed by URL - OK
934 * 2) Only the "http://" or "https://" part is present, no URL - change
935 * to empty string so it will be detected later as "no URL".
936 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
938 * 4) Parameter not specified or is empty string - let this fall through
939 * for now, next block of code will handle it.
941 if (0 == strncmp(url_param, "http://", 7))
943 if (url_param[7] == '\0')
946 * Empty URL (just prefix).
947 * Make it totally empty so it's caught by the next if()
952 else if (0 == strncmp(url_param, "https://", 8))
954 if (url_param[8] == '\0')
957 * Empty URL (just prefix).
958 * Make it totally empty so it's caught by the next if()
963 else if (url_param[0] != '\0')
966 * Unknown prefix - assume http://
968 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
969 if (NULL == url_param_prefixed)
973 return JB_ERR_MEMORY;
975 strcpy(url_param_prefixed, "http://");
976 strcpy(url_param_prefixed + 7, url_param);
978 url_param = url_param_prefixed;
982 if (url_param[0] == '\0')
984 /* URL paramater not specified, display query form only. */
986 if (map_block_killer(exports, "url-given")
987 || map(exports, "url", 1, "", 1))
990 return JB_ERR_MEMORY;
995 /* Given a URL, so query it. */
1000 struct file_list *fl;
1001 struct url_actions *b;
1002 struct http_request url_to_query[1];
1003 struct current_action_spec action[1];
1006 if (map(exports, "url", 1, html_encode(url_param), 0))
1010 return JB_ERR_MEMORY;
1013 init_current_action(action);
1015 if (map(exports, "default", 1, html_encode_and_free_original(
1016 current_action_to_text(action)), 0))
1018 free_current_action(action);
1021 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("");
1068 for (i = 0; i < MAX_ACTION_FILES; i++)
1072 if ((fl = csp->actions_list[i]) != NULL)
1074 if ((b = fl->f) != NULL)
1076 string_append(&matches, "<b>--- <a href=\"edit-actions-list?f=");
1077 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1078 string_append(&matches, "\">File ");
1079 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1080 string_append(&matches, "</a> ---</b><br>\n<br>\n");
1087 for (; (b != NULL) && (matches != NULL); b = b->next)
1089 if (url_match(b->url, url_to_query))
1091 string_append(&matches, "<b>{");
1092 string_join (&matches, html_encode_and_free_original(
1093 actions_to_text(b->action)));
1094 string_append(&matches, " }</b><br>\n<code>");
1095 string_join (&matches, html_encode(b->url->spec));
1096 string_append(&matches, "</code><br>\n<br>\n");
1098 if (merge_current_action(action, b->action))
1101 free_http_request(url_to_query);
1102 free_current_action(action);
1104 return JB_ERR_MEMORY;
1112 string_append(&matches, "(no matches in this file)\n<br>\n");
1116 free_http_request(url_to_query);
1118 if (matches == NULL)
1120 free_current_action(action);
1122 return JB_ERR_MEMORY;
1125 if (map(exports, "matches", 1, matches , 0))
1127 free_current_action(action);
1129 return JB_ERR_MEMORY;
1132 s = html_encode_and_free_original(current_action_to_text(action));
1134 free_current_action(action);
1136 if (map(exports, "final", 1, s, 0))
1139 return JB_ERR_MEMORY;
1143 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1147 /*********************************************************************
1149 * Function : cgi_robots_txt
1151 * Description : CGI function to return "/robots.txt".
1154 * 1 : csp = Current client state (buffers, headers, etc...)
1155 * 2 : rsp = http_response data structure for output
1156 * 3 : parameters = map of cgi parameters
1158 * CGI Parameters : None
1160 * Returns : JB_ERR_OK on success
1161 * JB_ERR_MEMORY on out-of-memory error.
1163 *********************************************************************/
1164 jb_err cgi_robots_txt(struct client_state *csp,
1165 struct http_response *rsp,
1166 const struct map *parameters)
1172 "# This is the Privoxy control interface.\n"
1173 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1179 if (rsp->body == NULL)
1181 return JB_ERR_MEMORY;
1184 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1188 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1189 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1191 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1195 /*********************************************************************
1197 * Function : show_defines
1199 * Description : Add to a map the state od all conditional #defines
1200 * used when building
1203 * 1 : exports = map to extend
1205 * Returns : JB_ERR_OK on success
1206 * JB_ERR_MEMORY on out-of-memory error.
1208 *********************************************************************/
1209 static jb_err show_defines(struct map *exports)
1211 jb_err err = JB_ERR_OK;
1214 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1215 #else /* ifndef FEATURE_ACL */
1216 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1217 #endif /* ndef FEATURE_ACL */
1219 #ifdef FEATURE_CGI_EDIT_ACTIONS
1220 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1221 #else /* ifndef FEATURE_COOKIE_JAR */
1222 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1223 #endif /* ndef FEATURE_COOKIE_JAR */
1225 #ifdef FEATURE_COOKIE_JAR
1226 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1227 #else /* ifndef FEATURE_COOKIE_JAR */
1228 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1229 #endif /* ndef FEATURE_COOKIE_JAR */
1231 #ifdef FEATURE_FAST_REDIRECTS
1232 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1233 #else /* ifndef FEATURE_FAST_REDIRECTS */
1234 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1235 #endif /* ndef FEATURE_FAST_REDIRECTS */
1237 #ifdef FEATURE_FORCE_LOAD
1238 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1239 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1240 #else /* ifndef FEATURE_FORCE_LOAD */
1241 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1242 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1243 #endif /* ndef FEATURE_FORCE_LOAD */
1245 #ifdef FEATURE_IMAGE_BLOCKING
1246 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1247 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1248 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1249 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1251 #ifdef FEATURE_IMAGE_DETECT_MSIE
1252 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1253 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1254 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1255 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1257 #ifdef FEATURE_KILL_POPUPS
1258 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1259 #else /* ifndef FEATURE_KILL_POPUPS */
1260 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1261 #endif /* ndef FEATURE_KILL_POPUPS */
1263 #ifdef FEATURE_NO_GIFS
1264 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1265 #else /* ifndef FEATURE_NO_GIFS */
1266 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1267 #endif /* ndef FEATURE_NO_GIFS */
1269 #ifdef FEATURE_PTHREAD
1270 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1271 #else /* ifndef FEATURE_PTHREAD */
1272 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1273 #endif /* ndef FEATURE_PTHREAD */
1275 #ifdef FEATURE_STATISTICS
1276 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1277 #else /* ifndef FEATURE_STATISTICS */
1278 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1279 #endif /* ndef FEATURE_STATISTICS */
1281 #ifdef FEATURE_TOGGLE
1282 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1283 #else /* ifndef FEATURE_TOGGLE */
1284 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1285 #endif /* ndef FEATURE_TOGGLE */
1287 #ifdef FEATURE_TRUST
1288 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1289 #else /* ifndef FEATURE_TRUST */
1290 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1291 #endif /* ndef FEATURE_TRUST */
1294 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1295 #else /* ifndef STATIC_PCRE */
1296 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1297 #endif /* ndef STATIC_PCRE */
1300 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1301 #else /* ifndef STATIC_PCRS */
1302 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1303 #endif /* ndef STATIC_PCRS */
1309 /*********************************************************************
1311 * Function : show_rcs
1313 * Description : Create a string with the rcs info for all sourcefiles
1317 * Returns : A string, or NULL on out-of-memory.
1319 *********************************************************************/
1320 static char *show_rcs(void)
1322 char *result = strdup("");
1323 char buf[BUFFER_SIZE];
1325 /* Instead of including *all* dot h's in the project (thus creating a
1326 * tremendous amount of dependencies), I will concede to declaring them
1327 * as extern's. This forces the developer to add to this list, but oh well.
1330 #define SHOW_RCS(__x) \
1332 extern const char __x[]; \
1333 sprintf(buf, "%s\n", __x); \
1334 string_append(&result, buf); \
1337 /* In alphabetical order */
1338 SHOW_RCS(actions_h_rcs)
1339 SHOW_RCS(actions_rcs)
1342 #ifdef FEATURE_CGI_EDIT_ACTIONS
1343 SHOW_RCS(cgiedit_h_rcs)
1344 SHOW_RCS(cgiedit_rcs)
1345 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1346 SHOW_RCS(cgisimple_h_rcs)
1347 SHOW_RCS(cgisimple_rcs)
1349 SHOW_RCS(cygwin_h_rcs)
1351 SHOW_RCS(deanimate_h_rcs)
1352 SHOW_RCS(deanimate_rcs)
1353 SHOW_RCS(encode_h_rcs)
1354 SHOW_RCS(encode_rcs)
1355 SHOW_RCS(errlog_h_rcs)
1356 SHOW_RCS(errlog_rcs)
1357 SHOW_RCS(filters_h_rcs)
1358 SHOW_RCS(filters_rcs)
1359 SHOW_RCS(gateway_h_rcs)
1360 SHOW_RCS(gateway_rcs)
1361 SHOW_RCS(jbsockets_h_rcs)
1362 SHOW_RCS(jbsockets_rcs)
1365 #ifdef FEATURE_KILL_POPUPS
1366 SHOW_RCS(killpopup_h_rcs)
1367 SHOW_RCS(killpopup_rcs)
1368 #endif /* def FEATURE_KILL_POPUPS */
1369 SHOW_RCS(list_h_rcs)
1371 SHOW_RCS(loadcfg_h_rcs)
1372 SHOW_RCS(loadcfg_rcs)
1373 SHOW_RCS(loaders_h_rcs)
1374 SHOW_RCS(loaders_rcs)
1375 SHOW_RCS(miscutil_h_rcs)
1376 SHOW_RCS(miscutil_rcs)
1377 SHOW_RCS(parsers_h_rcs)
1378 SHOW_RCS(parsers_rcs)
1380 SHOW_RCS(pcrs_h_rcs)
1381 SHOW_RCS(project_h_rcs)
1382 SHOW_RCS(ssplit_h_rcs)
1383 SHOW_RCS(ssplit_rcs)
1384 SHOW_RCS(urlmatch_h_rcs)
1385 SHOW_RCS(urlmatch_rcs)
1387 #ifndef _WIN_CONSOLE
1388 SHOW_RCS(w32log_h_rcs)
1389 SHOW_RCS(w32log_rcs)
1390 SHOW_RCS(w32res_h_rcs)
1391 SHOW_RCS(w32taskbar_h_rcs)
1392 SHOW_RCS(w32taskbar_rcs)
1393 #endif /* ndef _WIN_CONSOLE */
1394 SHOW_RCS(win32_h_rcs)
1396 #endif /* def _WIN32 */