1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.30 2002/04/24 02:18:08 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.30 2002/04/24 02:18:08 oes
40 * - show-status is now the starting point for editing
41 * the actions files, generate list of all AFs with buttons
42 * for viewing and editing, new look for file list (Jon:
43 * buttons now aligned ;-P ), view mode now supports multiple
44 * AFs, name changes, no view links for unspecified files,
45 * no edit link for standard.action.
47 * - Jon's multiple AF patch: cgi_show_url_info now uses all
48 * AFs and marks the output accordingly
50 * Revision 1.29 2002/04/10 13:38:35 oes
51 * load_template signature changed
53 * Revision 1.28 2002/04/07 15:42:12 jongfoster
54 * Fixing send-banner?type=auto when the image-blocker is
55 * a redirect to send-banner
57 * Revision 1.27 2002/04/05 15:50:48 oes
58 * added send-stylesheet CGI
60 * Revision 1.26 2002/04/04 00:36:36 gliptak
61 * always use pcre for matching
63 * Revision 1.25 2002/04/03 22:28:03 gliptak
64 * Removed references to gnu_regex
66 * Revision 1.24 2002/04/02 16:12:47 oes
67 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
69 * Revision 1.23 2002/03/26 22:29:54 swa
70 * we have a new homepage!
72 * Revision 1.22 2002/03/24 16:18:15 jongfoster
75 * Revision 1.21 2002/03/24 15:23:33 jongfoster
78 * Revision 1.20 2002/03/24 13:25:43 swa
79 * name change related issues
81 * Revision 1.19 2002/03/16 23:54:06 jongfoster
82 * Adding graceful termination feature, to help look for memory leaks.
83 * If you enable this (which, by design, has to be done by hand
84 * editing config.h) and then go to http://i.j.b/die, then the program
85 * will exit cleanly after the *next* request. It should free all the
86 * memory that was used.
88 * Revision 1.18 2002/03/12 01:44:49 oes
89 * Changed default for "blocked" image from jb logo to checkboard pattern
91 * Revision 1.17 2002/03/08 16:43:18 oes
92 * Added choice beween GIF and PNG built-in images
94 * Revision 1.16 2002/03/07 03:48:38 oes
95 * - Changed built-in images from GIF to PNG
96 * (with regard to Unisys patent issue)
97 * - Added a 4x4 pattern PNG which is less intrusive
98 * than the logo but also clearly marks the deleted banners
100 * Revision 1.15 2002/03/06 22:54:35 jongfoster
101 * Automated function-comment nitpicking.
103 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
104 * Clean up a little CRLF unpleasantness that suddenly appeared
106 * Revision 1.13 2002/02/21 00:10:37 jongfoster
107 * Adding send-banner?type=auto option
109 * Revision 1.12 2002/01/23 01:03:32 jongfoster
110 * Fixing gcc [CygWin] compiler warnings
112 * Revision 1.11 2002/01/23 00:01:04 jongfoster
113 * Adding cgi_transparent_gif() for http://i.j.b/t
114 * Adding missing html_encode() to many CGI functions.
115 * Adding urlmatch.[ch] to http://i.j.b/show-version
117 * Revision 1.10 2002/01/17 21:10:37 jongfoster
118 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
119 * Also fixing a problem in the same function with improperly quoted URLs
120 * in output HTML, and adding code to handle https:// URLs correctly.
122 * Revision 1.9 2001/11/30 23:09:15 jongfoster
123 * Now reports on FEATURE_CGI_EDIT_ACTIONS
124 * Removing FEATURE_DENY_GZIP from template
126 * Revision 1.8 2001/11/13 00:14:07 jongfoster
127 * Fixing stupid bug now I've figured out what || means.
128 * (It always returns 0 or 1, not one of it's paramaters.)
130 * Revision 1.7 2001/10/23 21:48:19 jongfoster
131 * Cleaning up error handling in CGI functions - they now send back
132 * a HTML error page and should never cause a FATAL error. (Fixes one
133 * potential source of "denial of service" attacks).
135 * CGI actions file editor that works and is actually useful.
137 * Ability to toggle JunkBuster remotely using a CGI call.
139 * You can turn off both the above features in the main configuration
140 * file, e.g. if you are running a multi-user proxy.
142 * Revision 1.6 2001/10/14 22:00:32 jongfoster
143 * Adding support for a 404 error when an invalid CGI page is requested.
145 * Revision 1.5 2001/10/07 15:30:41 oes
146 * Removed FEATURE_DENY_GZIP
148 * Revision 1.4 2001/10/02 15:31:12 oes
149 * Introduced show-request cgi
151 * Revision 1.3 2001/09/22 16:34:44 jongfoster
152 * Removing unneeded #includes
154 * Revision 1.2 2001/09/19 18:01:11 oes
155 * Fixed comments; cosmetics
157 * Revision 1.1 2001/09/16 17:08:54 jongfoster
158 * Moving simple CGI functions from cgi.c to new file cgisimple.c
161 **********************************************************************/
167 #include <sys/types.h>
174 #define snprintf _snprintf
175 #endif /* def _WIN32 */
179 #include "cgisimple.h"
185 #include "miscutil.h"
188 #include "urlmatch.h"
191 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
194 static char *show_rcs(void);
195 static jb_err show_defines(struct map *exports);
198 /*********************************************************************
200 * Function : cgi_default
202 * Description : CGI function that is called if no action was given.
203 * Lists menu of available unhidden CGIs.
206 * 1 : csp = Current client state (buffers, headers, etc...)
207 * 2 : rsp = http_response data structure for output
208 * 3 : parameters = map of cgi parameters
210 * CGI Parameters : none
212 * Returns : JB_ERR_OK on success
213 * JB_ERR_MEMORY on out-of-memory
214 * (Problems other than out-of-memory should be
215 * handled by this routine - it should set the
216 * rsp appropriately and return "success")
218 *********************************************************************/
219 jb_err cgi_default(struct client_state *csp,
220 struct http_response *rsp,
221 const struct map *parameters)
230 if (NULL == (exports = default_exports(csp, "")))
232 return JB_ERR_MEMORY;
235 /* If there were other parameters, export a dump as "cgi-parameters" */
236 if (parameters->first)
238 tmp = strdup("<p>What made you think this cgi takes parameters?\n"
239 "Anyway, here they are, in case you're interested:</p>\n");
240 string_join(&tmp, dump_map(parameters));
244 return JB_ERR_MEMORY;
246 if (map(exports, "cgi-parameters", 1, tmp, 0))
248 return JB_ERR_MEMORY;
253 if (map(exports, "cgi-parameters", 1, "", 1))
255 return JB_ERR_MEMORY;
259 return template_fill_for_cgi(csp, "default", exports, rsp);
265 /*********************************************************************
267 * Function : cgi_error_404
269 * Description : CGI function that is called if an unknown action was
273 * 1 : csp = Current client state (buffers, headers, etc...)
274 * 2 : rsp = http_response data structure for output
275 * 3 : parameters = map of cgi parameters
277 * CGI Parameters : none
279 * Returns : JB_ERR_OK on success
280 * JB_ERR_MEMORY on out-of-memory error.
282 *********************************************************************/
283 jb_err cgi_error_404(struct client_state *csp,
284 struct http_response *rsp,
285 const struct map *parameters)
293 if (NULL == (exports = default_exports(csp, NULL)))
295 return JB_ERR_MEMORY;
298 rsp->status = strdup("404 Privoxy configuration page not found");
299 if (rsp->status == NULL)
302 return JB_ERR_MEMORY;
305 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
309 #ifdef FEATURE_GRACEFUL_TERMINATION
310 /*********************************************************************
314 * Description : CGI function to shut down Privoxy.
315 * NOTE: Turning this on in a production build
316 * would be a BAD idea. An EXTREMELY BAD idea.
317 * In short, don't do it.
320 * 1 : csp = Current client state (buffers, headers, etc...)
321 * 2 : rsp = http_response data structure for output
322 * 3 : parameters = map of cgi parameters
324 * CGI Parameters : none
326 * Returns : JB_ERR_OK on success
327 * JB_ERR_MEMORY on out-of-memory error.
329 *********************************************************************/
330 jb_err cgi_die (struct client_state *csp,
331 struct http_response *rsp,
332 const struct map *parameters)
342 * I don't really care what gets sent back to the browser.
343 * Take the easy option - "out of memory" page.
346 return JB_ERR_MEMORY;
348 #endif /* def FEATURE_GRACEFUL_TERMINATION */
351 /*********************************************************************
353 * Function : cgi_show_request
355 * Description : Show the client's request and what sed() would have
359 * 1 : csp = Current client state (buffers, headers, etc...)
360 * 2 : rsp = http_response data structure for output
361 * 3 : parameters = map of cgi parameters
363 * CGI Parameters : none
365 * Returns : JB_ERR_OK on success
366 * JB_ERR_MEMORY on out-of-memory error.
368 *********************************************************************/
369 jb_err cgi_show_request(struct client_state *csp,
370 struct http_response *rsp,
371 const struct map *parameters)
380 if (NULL == (exports = default_exports(csp, "show-request")))
382 return JB_ERR_MEMORY;
386 * Repair the damage done to the IOB by get_header()
388 for (p = csp->iob->buf; p < csp->iob->eod; p++)
390 if (*p == '\0') *p = '\n';
394 * Export the original client's request and the one we would
395 * be sending to the server if this wasn't a CGI call
398 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
401 return JB_ERR_MEMORY;
404 if (map(exports, "processed-request", 1, html_encode_and_free_original(
405 sed(client_patterns, add_client_headers, csp)), 0))
408 return JB_ERR_MEMORY;
411 return template_fill_for_cgi(csp, "show-request", exports, rsp);
415 /*********************************************************************
417 * Function : cgi_send_banner
419 * Description : CGI function that returns a banner.
422 * 1 : csp = Current client state (buffers, headers, etc...)
423 * 2 : rsp = http_response data structure for output
424 * 3 : parameters = map of cgi parameters
427 * type : Selects the type of banner between "trans", "logo",
428 * and "auto". Defaults to "logo" if absent or invalid.
429 * "auto" means to select as if we were image-blocking.
430 * (Only the first character really counts).
432 * Returns : JB_ERR_OK on success
433 * JB_ERR_MEMORY on out-of-memory error.
435 *********************************************************************/
436 jb_err cgi_send_banner(struct client_state *csp,
437 struct http_response *rsp,
438 const struct map *parameters)
440 char imagetype = lookup(parameters, "type")[0];
442 if (imagetype == 'a') /* auto */
444 /* Default to pattern */
446 #ifdef FEATURE_IMAGE_BLOCKING
447 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
449 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
450 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
452 /* determine HOW images should be blocked */
453 const char * p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
455 /* and handle accordingly: */
458 /* Use default - nothing to do here. */
460 else if (0 == strcmpic(p, "blank"))
464 else if (0 == strcmpic(p, "pattern"))
468 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
470 imagetype = p[sizeof(prefix1) - 1];
472 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
474 imagetype = p[sizeof(prefix2) - 1];
477 #endif /* def FEATURE_IMAGE_BLOCKING */
480 if ((imagetype == 'b') || (imagetype == 't')) /* blank / transparent */
482 rsp->body = bindup(image_blank_data, image_blank_length);
483 rsp->content_length = image_blank_length;
488 rsp->body = bindup(image_pattern_data, image_pattern_length);
489 rsp->content_length = image_pattern_length;
492 if (rsp->body == NULL)
494 return JB_ERR_MEMORY;
497 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
499 return JB_ERR_MEMORY;
509 /*********************************************************************
511 * Function : cgi_transparent_image
513 * Description : CGI function that sends a 1x1 transparent image.
516 * 1 : csp = Current client state (buffers, headers, etc...)
517 * 2 : rsp = http_response data structure for output
518 * 3 : parameters = map of cgi parameters
520 * CGI Parameters : None
522 * Returns : JB_ERR_OK on success
523 * JB_ERR_MEMORY on out-of-memory error.
525 *********************************************************************/
526 jb_err cgi_transparent_image(struct client_state *csp,
527 struct http_response *rsp,
528 const struct map *parameters)
530 rsp->body = bindup(image_blank_data, image_blank_length);
531 rsp->content_length = image_blank_length;
533 if (rsp->body == NULL)
535 return JB_ERR_MEMORY;
538 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
540 return JB_ERR_MEMORY;
550 /*********************************************************************
552 * Function : cgi_send_stylesheet
554 * Description : CGI function that sends a css stylesheet found
555 * in the cgi-style.css template
558 * 1 : csp = Current client state (buffers, headers, etc...)
559 * 2 : rsp = http_response data structure for output
560 * 3 : parameters = map of cgi parameters
562 * CGI Parameters : None
564 * Returns : JB_ERR_OK on success
565 * JB_ERR_MEMORY on out-of-memory error.
567 *********************************************************************/
568 jb_err cgi_send_stylesheet(struct client_state *csp,
569 struct http_response *rsp,
570 const struct map *parameters)
577 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
579 if (err == JB_ERR_FILE)
582 * No way to tell user; send empty stylesheet
584 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
588 return err; /* JB_ERR_MEMORY */
591 if (enlist(rsp->headers, "Content-Type: text/css"))
593 return JB_ERR_MEMORY;
601 /*********************************************************************
603 * Function : cgi_show_version
605 * Description : CGI function that returns a a web page describing the
606 * file versions of Privoxy.
609 * 1 : csp = Current client state (buffers, headers, etc...)
610 * 2 : rsp = http_response data structure for output
611 * 3 : parameters = map of cgi parameters
613 * CGI Parameters : none
615 * Returns : JB_ERR_OK on success
616 * JB_ERR_MEMORY on out-of-memory error.
618 *********************************************************************/
619 jb_err cgi_show_version(struct client_state *csp,
620 struct http_response *rsp,
621 const struct map *parameters)
629 if (NULL == (exports = default_exports(csp, "show-version")))
631 return JB_ERR_MEMORY;
634 if (map(exports, "sourceversions", 1, show_rcs(), 0))
637 return JB_ERR_MEMORY;
640 return template_fill_for_cgi(csp, "show-version", exports, rsp);
644 /*********************************************************************
646 * Function : cgi_show_status
648 * Description : CGI function that returns a a web page describing the
649 * current status of Privoxy.
652 * 1 : csp = Current client state (buffers, headers, etc...)
653 * 2 : rsp = http_response data structure for output
654 * 3 : parameters = map of cgi parameters
657 * file : Which file to show. Only first letter is checked,
659 * - "p"ermissions (actions) file
662 * Default is to show menu and other information.
664 * Returns : JB_ERR_OK on success
665 * JB_ERR_MEMORY on out-of-memory error.
667 *********************************************************************/
668 jb_err cgi_show_status(struct client_state *csp,
669 struct http_response *rsp,
670 const struct map *parameters)
676 char buf[BUFFER_SIZE];
677 const char * filename = NULL;
678 char * file_description = NULL;
679 #ifdef FEATURE_STATISTICS
680 float perc_rej; /* Percentage of http requests rejected */
682 int local_urls_rejected;
683 #endif /* ndef FEATURE_STATISTICS */
684 struct file_list * fl;
685 struct url_actions * b;
686 jb_err err = JB_ERR_OK;
694 if (NULL == (exports = default_exports(csp, "show-status")))
696 return JB_ERR_MEMORY;
699 switch (*(lookup(parameters, "file")))
702 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_ACTION_FILES && csp->actions_list[i])
704 filename = csp->actions_list[i]->filename;
705 file_description = "Actions File";
712 filename = csp->rlist->filename;
713 file_description = "Filter File";
721 filename = csp->tlist->filename;
722 file_description = "Trust File";
725 #endif /* def FEATURE_TRUST */
728 if (NULL != filename)
730 if ( map(exports, "file-description", 1, file_description, 1)
731 || map(exports, "filepath", 1, html_encode(filename), 0) )
734 return JB_ERR_MEMORY;
737 if ((fp = fopen(filename, "r")) == NULL)
739 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
742 return JB_ERR_MEMORY;
748 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
750 string_join (&s, html_encode(buf));
754 if (map(exports, "contents", 1, s, 0))
757 return JB_ERR_MEMORY;
761 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
765 for (i = 0; (s != NULL) && (i < Argc); i++)
767 if (!err) err = string_join (&s, html_encode(Argv[i]));
768 if (!err) err = string_append(&s, " ");
770 if (!err) err = map(exports, "invocation", 1, s, 0);
772 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
773 if (!err) err = show_defines(exports);
778 return JB_ERR_MEMORY;
781 #ifdef FEATURE_STATISTICS
782 local_urls_read = urls_read;
783 local_urls_rejected = urls_rejected;
786 * Need to alter the stats not to include the fetch of this
789 * Can't do following thread safely! doh!
792 * urls_rejected--; * This will be incremented subsequently *
795 if (local_urls_read == 0)
797 if (!err) err = map_block_killer(exports, "have-stats");
801 if (!err) err = map_block_killer(exports, "have-no-stats");
803 perc_rej = (float)local_urls_rejected * 100.0F /
804 (float)local_urls_read;
806 sprintf(buf, "%d", local_urls_read);
807 if (!err) err = map(exports, "requests-received", 1, buf, 1);
809 sprintf(buf, "%d", local_urls_rejected);
810 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
812 sprintf(buf, "%6.2f", perc_rej);
813 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
816 #else /* ndef FEATURE_STATISTICS */
817 err = err || map_block_killer(exports, "statistics");
818 #endif /* ndef FEATURE_STATISTICS */
821 * List all action files in use, together with view and edit links,
822 * except for standard.action, which should only be viewable. (Not
823 * enforced in the editor itself)
824 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
827 for (i = 0; i < MAX_ACTION_FILES; i++)
829 if (((fl = csp->actions_list[i]) != NULL) && ((b = fl->f) != NULL))
831 if (!err) err = string_append(&s, "<tr><td>");
832 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
833 snprintf(buf, 100, "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a> ", i);
834 if (!err) err = string_append(&s, buf);
836 if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
838 snprintf(buf, 100, "<a href=\"/edit-actions-list?f=%s\">Edit</a>", csp->config->actions_file_short[i]);
839 if (!err) err = string_append(&s, buf);
842 if (!err) err = string_append(&s, "</td></tr>\n");
847 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
851 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
856 if (!err) err = map(exports, "re-filter-filename", 1, html_encode(csp->rlist->filename), 0);
860 if (!err) err = map(exports, "re-filter-filename", 1, "None specified", 1);
861 if (!err) err = map_block_killer(exports, "have-filterfile");
867 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
871 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
872 if (!err) err = map_block_killer(exports, "have-trustfile");
875 if (!err) err = map_block_killer(exports, "trust-support");
876 #endif /* ndef FEATURE_TRUST */
881 return JB_ERR_MEMORY;
884 return template_fill_for_cgi(csp, "show-status", exports, rsp);
888 /*********************************************************************
890 * Function : cgi_show_url_info
892 * Description : CGI function that determines and shows which actions
893 * Privoxy will perform for a given url, and which
894 * matches starting from the defaults have lead to that.
897 * 1 : csp = Current client state (buffers, headers, etc...)
898 * 2 : rsp = http_response data structure for output
899 * 3 : parameters = map of cgi parameters
902 * url : The url whose actions are to be determined.
903 * If url is unset, the url-given conditional will be
904 * set, so that all but the form can be suppressed in
907 * Returns : JB_ERR_OK on success
908 * JB_ERR_MEMORY on out-of-memory error.
910 *********************************************************************/
911 jb_err cgi_show_url_info(struct client_state *csp,
912 struct http_response *rsp,
913 const struct map *parameters)
923 if (NULL == (exports = default_exports(csp, "show-url-info")))
925 return JB_ERR_MEMORY;
929 * Get the url= parameter (if present) and remove any leading/trailing spaces.
931 url_param = strdup(lookup(parameters, "url"));
932 if (url_param == NULL)
935 return JB_ERR_MEMORY;
940 * Handle prefixes. 4 possibilities:
941 * 1) "http://" or "https://" prefix present and followed by URL - OK
942 * 2) Only the "http://" or "https://" part is present, no URL - change
943 * to empty string so it will be detected later as "no URL".
944 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
946 * 4) Parameter not specified or is empty string - let this fall through
947 * for now, next block of code will handle it.
949 if (0 == strncmp(url_param, "http://", 7))
951 if (url_param[7] == '\0')
954 * Empty URL (just prefix).
955 * Make it totally empty so it's caught by the next if()
960 else if (0 == strncmp(url_param, "https://", 8))
962 if (url_param[8] == '\0')
965 * Empty URL (just prefix).
966 * Make it totally empty so it's caught by the next if()
971 else if (url_param[0] != '\0')
974 * Unknown prefix - assume http://
976 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
977 if (NULL == url_param_prefixed)
981 return JB_ERR_MEMORY;
983 strcpy(url_param_prefixed, "http://");
984 strcpy(url_param_prefixed + 7, url_param);
986 url_param = url_param_prefixed;
990 if (url_param[0] == '\0')
992 /* URL paramater not specified, display query form only. */
994 if (map_block_killer(exports, "url-given")
995 || map(exports, "url", 1, "", 1))
998 return JB_ERR_MEMORY;
1003 /* Given a URL, so query it. */
1008 struct file_list *fl;
1009 struct url_actions *b;
1010 struct http_request url_to_query[1];
1011 struct current_action_spec action[1];
1014 if (map(exports, "url", 1, html_encode(url_param), 0))
1018 return JB_ERR_MEMORY;
1021 init_current_action(action);
1023 if (map(exports, "default", 1, current_action_to_html(action, csp), 0))
1025 free_current_action(action);
1028 return JB_ERR_MEMORY;
1031 err = parse_http_url(url_param, url_to_query, csp);
1035 if (err == JB_ERR_MEMORY)
1037 free_current_action(action);
1039 return JB_ERR_MEMORY;
1045 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1046 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1048 free_current_action(action);
1053 return JB_ERR_MEMORY;
1056 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1060 * We have a warning about SSL paths. Hide it for insecure sites.
1062 if (!url_to_query->ssl)
1064 if (map_block_killer(exports, "https"))
1066 free_current_action(action);
1068 return JB_ERR_MEMORY;
1072 matches = strdup("<table class=\"transparent\">");
1074 for (i = 0; i < MAX_ACTION_FILES; i++)
1076 if (NULL == csp->config->actions_file_short[i]
1077 || !strcmp(csp->config->actions_file_short[i], "standard")) continue;
1081 if ((fl = csp->actions_list[i]) != NULL)
1083 if ((b = fl->f) != NULL)
1085 /* FIXME: Hardcoded HTML! */
1086 string_append(&matches, "<tr><th>In file: ");
1087 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1088 snprintf(buf, 150, ".action <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1089 string_append(&matches, buf);
1090 string_append(&matches, "View</a> <a class=\"cmd\" href=\"/edit-actions-list?f=");
1091 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1092 string_append(&matches, "\">Edit</a></th></tr>\n");
1099 for (; (b != NULL) && (matches != NULL); b = b->next)
1101 if (url_match(b->url, url_to_query))
1103 string_append(&matches, "<tr><td>{");
1104 string_join (&matches, actions_to_html(b->action, csp));
1105 string_append(&matches, " }</b><br>\n<code>");
1106 string_join (&matches, html_encode(b->url->spec));
1107 string_append(&matches, "</code></td></tr>\n");
1109 if (merge_current_action(action, b->action))
1112 free_http_request(url_to_query);
1113 free_current_action(action);
1115 return JB_ERR_MEMORY;
1123 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1126 string_append(&matches, "</table>\n");
1128 free_http_request(url_to_query);
1130 if (matches == NULL)
1132 free_current_action(action);
1134 return JB_ERR_MEMORY;
1137 if (map(exports, "matches", 1, matches , 0))
1139 free_current_action(action);
1141 return JB_ERR_MEMORY;
1144 s = current_action_to_html(action, csp);
1146 free_current_action(action);
1148 if (map(exports, "final", 1, s, 0))
1151 return JB_ERR_MEMORY;
1155 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1159 /*********************************************************************
1161 * Function : cgi_robots_txt
1163 * Description : CGI function to return "/robots.txt".
1166 * 1 : csp = Current client state (buffers, headers, etc...)
1167 * 2 : rsp = http_response data structure for output
1168 * 3 : parameters = map of cgi parameters
1170 * CGI Parameters : None
1172 * Returns : JB_ERR_OK on success
1173 * JB_ERR_MEMORY on out-of-memory error.
1175 *********************************************************************/
1176 jb_err cgi_robots_txt(struct client_state *csp,
1177 struct http_response *rsp,
1178 const struct map *parameters)
1184 "# This is the Privoxy control interface.\n"
1185 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1191 if (rsp->body == NULL)
1193 return JB_ERR_MEMORY;
1196 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1200 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1201 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1203 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1207 /*********************************************************************
1209 * Function : show_defines
1211 * Description : Add to a map the state od all conditional #defines
1212 * used when building
1215 * 1 : exports = map to extend
1217 * Returns : JB_ERR_OK on success
1218 * JB_ERR_MEMORY on out-of-memory error.
1220 *********************************************************************/
1221 static jb_err show_defines(struct map *exports)
1223 jb_err err = JB_ERR_OK;
1226 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1227 #else /* ifndef FEATURE_ACL */
1228 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1229 #endif /* ndef FEATURE_ACL */
1231 #ifdef FEATURE_CGI_EDIT_ACTIONS
1232 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1233 #else /* ifndef FEATURE_COOKIE_JAR */
1234 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1235 #endif /* ndef FEATURE_COOKIE_JAR */
1237 #ifdef FEATURE_COOKIE_JAR
1238 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1239 #else /* ifndef FEATURE_COOKIE_JAR */
1240 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1241 #endif /* ndef FEATURE_COOKIE_JAR */
1243 #ifdef FEATURE_FAST_REDIRECTS
1244 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1245 #else /* ifndef FEATURE_FAST_REDIRECTS */
1246 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1247 #endif /* ndef FEATURE_FAST_REDIRECTS */
1249 #ifdef FEATURE_FORCE_LOAD
1250 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1251 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1252 #else /* ifndef FEATURE_FORCE_LOAD */
1253 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1254 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1255 #endif /* ndef FEATURE_FORCE_LOAD */
1257 #ifdef FEATURE_IMAGE_BLOCKING
1258 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1259 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1260 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1261 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1263 #ifdef FEATURE_IMAGE_DETECT_MSIE
1264 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1265 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1266 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1267 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1269 #ifdef FEATURE_KILL_POPUPS
1270 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1271 #else /* ifndef FEATURE_KILL_POPUPS */
1272 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1273 #endif /* ndef FEATURE_KILL_POPUPS */
1275 #ifdef FEATURE_NO_GIFS
1276 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1277 #else /* ifndef FEATURE_NO_GIFS */
1278 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1279 #endif /* ndef FEATURE_NO_GIFS */
1281 #ifdef FEATURE_PTHREAD
1282 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1283 #else /* ifndef FEATURE_PTHREAD */
1284 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1285 #endif /* ndef FEATURE_PTHREAD */
1287 #ifdef FEATURE_STATISTICS
1288 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1289 #else /* ifndef FEATURE_STATISTICS */
1290 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1291 #endif /* ndef FEATURE_STATISTICS */
1293 #ifdef FEATURE_TOGGLE
1294 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1295 #else /* ifndef FEATURE_TOGGLE */
1296 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1297 #endif /* ndef FEATURE_TOGGLE */
1299 #ifdef FEATURE_TRUST
1300 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1301 #else /* ifndef FEATURE_TRUST */
1302 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1303 #endif /* ndef FEATURE_TRUST */
1306 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1307 #else /* ifndef STATIC_PCRE */
1308 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1309 #endif /* ndef STATIC_PCRE */
1312 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1313 #else /* ifndef STATIC_PCRS */
1314 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1315 #endif /* ndef STATIC_PCRS */
1321 /*********************************************************************
1323 * Function : show_rcs
1325 * Description : Create a string with the rcs info for all sourcefiles
1329 * Returns : A string, or NULL on out-of-memory.
1331 *********************************************************************/
1332 static char *show_rcs(void)
1334 char *result = strdup("");
1335 char buf[BUFFER_SIZE];
1337 /* Instead of including *all* dot h's in the project (thus creating a
1338 * tremendous amount of dependencies), I will concede to declaring them
1339 * as extern's. This forces the developer to add to this list, but oh well.
1342 #define SHOW_RCS(__x) \
1344 extern const char __x[]; \
1345 sprintf(buf, "%s\n", __x); \
1346 string_append(&result, buf); \
1349 /* In alphabetical order */
1350 SHOW_RCS(actions_h_rcs)
1351 SHOW_RCS(actions_rcs)
1354 #ifdef FEATURE_CGI_EDIT_ACTIONS
1355 SHOW_RCS(cgiedit_h_rcs)
1356 SHOW_RCS(cgiedit_rcs)
1357 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1358 SHOW_RCS(cgisimple_h_rcs)
1359 SHOW_RCS(cgisimple_rcs)
1361 SHOW_RCS(cygwin_h_rcs)
1363 SHOW_RCS(deanimate_h_rcs)
1364 SHOW_RCS(deanimate_rcs)
1365 SHOW_RCS(encode_h_rcs)
1366 SHOW_RCS(encode_rcs)
1367 SHOW_RCS(errlog_h_rcs)
1368 SHOW_RCS(errlog_rcs)
1369 SHOW_RCS(filters_h_rcs)
1370 SHOW_RCS(filters_rcs)
1371 SHOW_RCS(gateway_h_rcs)
1372 SHOW_RCS(gateway_rcs)
1373 SHOW_RCS(jbsockets_h_rcs)
1374 SHOW_RCS(jbsockets_rcs)
1377 #ifdef FEATURE_KILL_POPUPS
1378 SHOW_RCS(killpopup_h_rcs)
1379 SHOW_RCS(killpopup_rcs)
1380 #endif /* def FEATURE_KILL_POPUPS */
1381 SHOW_RCS(list_h_rcs)
1383 SHOW_RCS(loadcfg_h_rcs)
1384 SHOW_RCS(loadcfg_rcs)
1385 SHOW_RCS(loaders_h_rcs)
1386 SHOW_RCS(loaders_rcs)
1387 SHOW_RCS(miscutil_h_rcs)
1388 SHOW_RCS(miscutil_rcs)
1389 SHOW_RCS(parsers_h_rcs)
1390 SHOW_RCS(parsers_rcs)
1392 SHOW_RCS(pcrs_h_rcs)
1393 SHOW_RCS(project_h_rcs)
1394 SHOW_RCS(ssplit_h_rcs)
1395 SHOW_RCS(ssplit_rcs)
1396 SHOW_RCS(urlmatch_h_rcs)
1397 SHOW_RCS(urlmatch_rcs)
1399 #ifndef _WIN_CONSOLE
1400 SHOW_RCS(w32log_h_rcs)
1401 SHOW_RCS(w32log_rcs)
1402 SHOW_RCS(w32res_h_rcs)
1403 SHOW_RCS(w32taskbar_h_rcs)
1404 SHOW_RCS(w32taskbar_rcs)
1405 #endif /* ndef _WIN_CONSOLE */
1406 SHOW_RCS(win32_h_rcs)
1408 #endif /* def _WIN32 */