1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.31 2002/04/26 12:54:36 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.31 2002/04/26 12:54:36 oes
40 * - Kill obsolete REDIRECT_URL code
41 * - Error handling fixes
42 * - Style sheet related HTML snipplet changes
43 * - cgi_show_url_info:
44 * - Matches now in table, actions on single lines,
46 * - standard.action suppressed
47 * - Buttons to View and Edit AFs
49 * Revision 1.30 2002/04/24 02:18:08 oes
50 * - show-status is now the starting point for editing
51 * the actions files, generate list of all AFs with buttons
52 * for viewing and editing, new look for file list (Jon:
53 * buttons now aligned ;-P ), view mode now supports multiple
54 * AFs, name changes, no view links for unspecified files,
55 * no edit link for standard.action.
57 * - Jon's multiple AF patch: cgi_show_url_info now uses all
58 * AFs and marks the output accordingly
60 * Revision 1.29 2002/04/10 13:38:35 oes
61 * load_template signature changed
63 * Revision 1.28 2002/04/07 15:42:12 jongfoster
64 * Fixing send-banner?type=auto when the image-blocker is
65 * a redirect to send-banner
67 * Revision 1.27 2002/04/05 15:50:48 oes
68 * added send-stylesheet CGI
70 * Revision 1.26 2002/04/04 00:36:36 gliptak
71 * always use pcre for matching
73 * Revision 1.25 2002/04/03 22:28:03 gliptak
74 * Removed references to gnu_regex
76 * Revision 1.24 2002/04/02 16:12:47 oes
77 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
79 * Revision 1.23 2002/03/26 22:29:54 swa
80 * we have a new homepage!
82 * Revision 1.22 2002/03/24 16:18:15 jongfoster
85 * Revision 1.21 2002/03/24 15:23:33 jongfoster
88 * Revision 1.20 2002/03/24 13:25:43 swa
89 * name change related issues
91 * Revision 1.19 2002/03/16 23:54:06 jongfoster
92 * Adding graceful termination feature, to help look for memory leaks.
93 * If you enable this (which, by design, has to be done by hand
94 * editing config.h) and then go to http://i.j.b/die, then the program
95 * will exit cleanly after the *next* request. It should free all the
96 * memory that was used.
98 * Revision 1.18 2002/03/12 01:44:49 oes
99 * Changed default for "blocked" image from jb logo to checkboard pattern
101 * Revision 1.17 2002/03/08 16:43:18 oes
102 * Added choice beween GIF and PNG built-in images
104 * Revision 1.16 2002/03/07 03:48:38 oes
105 * - Changed built-in images from GIF to PNG
106 * (with regard to Unisys patent issue)
107 * - Added a 4x4 pattern PNG which is less intrusive
108 * than the logo but also clearly marks the deleted banners
110 * Revision 1.15 2002/03/06 22:54:35 jongfoster
111 * Automated function-comment nitpicking.
113 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
114 * Clean up a little CRLF unpleasantness that suddenly appeared
116 * Revision 1.13 2002/02/21 00:10:37 jongfoster
117 * Adding send-banner?type=auto option
119 * Revision 1.12 2002/01/23 01:03:32 jongfoster
120 * Fixing gcc [CygWin] compiler warnings
122 * Revision 1.11 2002/01/23 00:01:04 jongfoster
123 * Adding cgi_transparent_gif() for http://i.j.b/t
124 * Adding missing html_encode() to many CGI functions.
125 * Adding urlmatch.[ch] to http://i.j.b/show-version
127 * Revision 1.10 2002/01/17 21:10:37 jongfoster
128 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
129 * Also fixing a problem in the same function with improperly quoted URLs
130 * in output HTML, and adding code to handle https:// URLs correctly.
132 * Revision 1.9 2001/11/30 23:09:15 jongfoster
133 * Now reports on FEATURE_CGI_EDIT_ACTIONS
134 * Removing FEATURE_DENY_GZIP from template
136 * Revision 1.8 2001/11/13 00:14:07 jongfoster
137 * Fixing stupid bug now I've figured out what || means.
138 * (It always returns 0 or 1, not one of it's paramaters.)
140 * Revision 1.7 2001/10/23 21:48:19 jongfoster
141 * Cleaning up error handling in CGI functions - they now send back
142 * a HTML error page and should never cause a FATAL error. (Fixes one
143 * potential source of "denial of service" attacks).
145 * CGI actions file editor that works and is actually useful.
147 * Ability to toggle JunkBuster remotely using a CGI call.
149 * You can turn off both the above features in the main configuration
150 * file, e.g. if you are running a multi-user proxy.
152 * Revision 1.6 2001/10/14 22:00:32 jongfoster
153 * Adding support for a 404 error when an invalid CGI page is requested.
155 * Revision 1.5 2001/10/07 15:30:41 oes
156 * Removed FEATURE_DENY_GZIP
158 * Revision 1.4 2001/10/02 15:31:12 oes
159 * Introduced show-request cgi
161 * Revision 1.3 2001/09/22 16:34:44 jongfoster
162 * Removing unneeded #includes
164 * Revision 1.2 2001/09/19 18:01:11 oes
165 * Fixed comments; cosmetics
167 * Revision 1.1 2001/09/16 17:08:54 jongfoster
168 * Moving simple CGI functions from cgi.c to new file cgisimple.c
171 **********************************************************************/
177 #include <sys/types.h>
184 #define snprintf _snprintf
185 #endif /* def _WIN32 */
189 #include "cgisimple.h"
195 #include "miscutil.h"
198 #include "urlmatch.h"
201 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
204 static char *show_rcs(void);
205 static jb_err show_defines(struct map *exports);
208 /*********************************************************************
210 * Function : cgi_default
212 * Description : CGI function that is called if no action was given.
213 * Lists menu of available unhidden CGIs.
216 * 1 : csp = Current client state (buffers, headers, etc...)
217 * 2 : rsp = http_response data structure for output
218 * 3 : parameters = map of cgi parameters
220 * CGI Parameters : none
222 * Returns : JB_ERR_OK on success
223 * JB_ERR_MEMORY on out-of-memory
224 * (Problems other than out-of-memory should be
225 * handled by this routine - it should set the
226 * rsp appropriately and return "success")
228 *********************************************************************/
229 jb_err cgi_default(struct client_state *csp,
230 struct http_response *rsp,
231 const struct map *parameters)
240 if (NULL == (exports = default_exports(csp, "")))
242 return JB_ERR_MEMORY;
245 /* If there were other parameters, export a dump as "cgi-parameters" */
246 if (parameters->first)
248 tmp = strdup("<p>What made you think this cgi takes parameters?\n"
249 "Anyway, here they are, in case you're interested:</p>\n");
250 string_join(&tmp, dump_map(parameters));
254 return JB_ERR_MEMORY;
256 if (map(exports, "cgi-parameters", 1, tmp, 0))
258 return JB_ERR_MEMORY;
263 if (map(exports, "cgi-parameters", 1, "", 1))
265 return JB_ERR_MEMORY;
269 return template_fill_for_cgi(csp, "default", exports, rsp);
275 /*********************************************************************
277 * Function : cgi_error_404
279 * Description : CGI function that is called if an unknown action was
283 * 1 : csp = Current client state (buffers, headers, etc...)
284 * 2 : rsp = http_response data structure for output
285 * 3 : parameters = map of cgi parameters
287 * CGI Parameters : none
289 * Returns : JB_ERR_OK on success
290 * JB_ERR_MEMORY on out-of-memory error.
292 *********************************************************************/
293 jb_err cgi_error_404(struct client_state *csp,
294 struct http_response *rsp,
295 const struct map *parameters)
303 if (NULL == (exports = default_exports(csp, NULL)))
305 return JB_ERR_MEMORY;
308 rsp->status = strdup("404 Privoxy configuration page not found");
309 if (rsp->status == NULL)
312 return JB_ERR_MEMORY;
315 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
319 #ifdef FEATURE_GRACEFUL_TERMINATION
320 /*********************************************************************
324 * Description : CGI function to shut down Privoxy.
325 * NOTE: Turning this on in a production build
326 * would be a BAD idea. An EXTREMELY BAD idea.
327 * In short, don't do it.
330 * 1 : csp = Current client state (buffers, headers, etc...)
331 * 2 : rsp = http_response data structure for output
332 * 3 : parameters = map of cgi parameters
334 * CGI Parameters : none
336 * Returns : JB_ERR_OK on success
337 * JB_ERR_MEMORY on out-of-memory error.
339 *********************************************************************/
340 jb_err cgi_die (struct client_state *csp,
341 struct http_response *rsp,
342 const struct map *parameters)
352 * I don't really care what gets sent back to the browser.
353 * Take the easy option - "out of memory" page.
356 return JB_ERR_MEMORY;
358 #endif /* def FEATURE_GRACEFUL_TERMINATION */
361 /*********************************************************************
363 * Function : cgi_show_request
365 * Description : Show the client's request and what sed() would have
369 * 1 : csp = Current client state (buffers, headers, etc...)
370 * 2 : rsp = http_response data structure for output
371 * 3 : parameters = map of cgi parameters
373 * CGI Parameters : none
375 * Returns : JB_ERR_OK on success
376 * JB_ERR_MEMORY on out-of-memory error.
378 *********************************************************************/
379 jb_err cgi_show_request(struct client_state *csp,
380 struct http_response *rsp,
381 const struct map *parameters)
390 if (NULL == (exports = default_exports(csp, "show-request")))
392 return JB_ERR_MEMORY;
396 * Repair the damage done to the IOB by get_header()
398 for (p = csp->iob->buf; p < csp->iob->eod; p++)
400 if (*p == '\0') *p = '\n';
404 * Export the original client's request and the one we would
405 * be sending to the server if this wasn't a CGI call
408 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
411 return JB_ERR_MEMORY;
414 if (map(exports, "processed-request", 1, html_encode_and_free_original(
415 sed(client_patterns, add_client_headers, csp)), 0))
418 return JB_ERR_MEMORY;
421 return template_fill_for_cgi(csp, "show-request", exports, rsp);
425 /*********************************************************************
427 * Function : cgi_send_banner
429 * Description : CGI function that returns a banner.
432 * 1 : csp = Current client state (buffers, headers, etc...)
433 * 2 : rsp = http_response data structure for output
434 * 3 : parameters = map of cgi parameters
437 * type : Selects the type of banner between "trans", "logo",
438 * and "auto". Defaults to "logo" if absent or invalid.
439 * "auto" means to select as if we were image-blocking.
440 * (Only the first character really counts).
442 * Returns : JB_ERR_OK on success
443 * JB_ERR_MEMORY on out-of-memory error.
445 *********************************************************************/
446 jb_err cgi_send_banner(struct client_state *csp,
447 struct http_response *rsp,
448 const struct map *parameters)
450 char imagetype = lookup(parameters, "type")[0];
452 if (imagetype == 'a') /* auto */
454 /* Default to pattern */
456 #ifdef FEATURE_IMAGE_BLOCKING
457 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
459 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
460 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
462 /* determine HOW images should be blocked */
463 const char * p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
465 /* and handle accordingly: */
468 /* Use default - nothing to do here. */
470 else if (0 == strcmpic(p, "blank"))
474 else if (0 == strcmpic(p, "pattern"))
478 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
480 imagetype = p[sizeof(prefix1) - 1];
482 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
484 imagetype = p[sizeof(prefix2) - 1];
487 #endif /* def FEATURE_IMAGE_BLOCKING */
490 if ((imagetype == 'b') || (imagetype == 't')) /* blank / transparent */
492 rsp->body = bindup(image_blank_data, image_blank_length);
493 rsp->content_length = image_blank_length;
498 rsp->body = bindup(image_pattern_data, image_pattern_length);
499 rsp->content_length = image_pattern_length;
502 if (rsp->body == NULL)
504 return JB_ERR_MEMORY;
507 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
509 return JB_ERR_MEMORY;
519 /*********************************************************************
521 * Function : cgi_transparent_image
523 * Description : CGI function that sends a 1x1 transparent image.
526 * 1 : csp = Current client state (buffers, headers, etc...)
527 * 2 : rsp = http_response data structure for output
528 * 3 : parameters = map of cgi parameters
530 * CGI Parameters : None
532 * Returns : JB_ERR_OK on success
533 * JB_ERR_MEMORY on out-of-memory error.
535 *********************************************************************/
536 jb_err cgi_transparent_image(struct client_state *csp,
537 struct http_response *rsp,
538 const struct map *parameters)
540 rsp->body = bindup(image_blank_data, image_blank_length);
541 rsp->content_length = image_blank_length;
543 if (rsp->body == NULL)
545 return JB_ERR_MEMORY;
548 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
550 return JB_ERR_MEMORY;
560 /*********************************************************************
562 * Function : cgi_send_stylesheet
564 * Description : CGI function that sends a css stylesheet found
565 * in the cgi-style.css template
568 * 1 : csp = Current client state (buffers, headers, etc...)
569 * 2 : rsp = http_response data structure for output
570 * 3 : parameters = map of cgi parameters
572 * CGI Parameters : None
574 * Returns : JB_ERR_OK on success
575 * JB_ERR_MEMORY on out-of-memory error.
577 *********************************************************************/
578 jb_err cgi_send_stylesheet(struct client_state *csp,
579 struct http_response *rsp,
580 const struct map *parameters)
587 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
589 if (err == JB_ERR_FILE)
592 * No way to tell user; send empty stylesheet
594 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
598 return err; /* JB_ERR_MEMORY */
601 if (enlist(rsp->headers, "Content-Type: text/css"))
603 return JB_ERR_MEMORY;
611 /*********************************************************************
613 * Function : cgi_show_version
615 * Description : CGI function that returns a a web page describing the
616 * file versions of Privoxy.
619 * 1 : csp = Current client state (buffers, headers, etc...)
620 * 2 : rsp = http_response data structure for output
621 * 3 : parameters = map of cgi parameters
623 * CGI Parameters : none
625 * Returns : JB_ERR_OK on success
626 * JB_ERR_MEMORY on out-of-memory error.
628 *********************************************************************/
629 jb_err cgi_show_version(struct client_state *csp,
630 struct http_response *rsp,
631 const struct map *parameters)
639 if (NULL == (exports = default_exports(csp, "show-version")))
641 return JB_ERR_MEMORY;
644 if (map(exports, "sourceversions", 1, show_rcs(), 0))
647 return JB_ERR_MEMORY;
650 return template_fill_for_cgi(csp, "show-version", exports, rsp);
654 /*********************************************************************
656 * Function : cgi_show_status
658 * Description : CGI function that returns a a web page describing the
659 * current status of Privoxy.
662 * 1 : csp = Current client state (buffers, headers, etc...)
663 * 2 : rsp = http_response data structure for output
664 * 3 : parameters = map of cgi parameters
667 * file : Which file to show. Only first letter is checked,
669 * - "p"ermissions (actions) file
672 * Default is to show menu and other information.
674 * Returns : JB_ERR_OK on success
675 * JB_ERR_MEMORY on out-of-memory error.
677 *********************************************************************/
678 jb_err cgi_show_status(struct client_state *csp,
679 struct http_response *rsp,
680 const struct map *parameters)
687 char buf[BUFFER_SIZE];
688 const char * filename = NULL;
689 char * file_description = NULL;
690 #ifdef FEATURE_STATISTICS
691 float perc_rej; /* Percentage of http requests rejected */
693 int local_urls_rejected;
694 #endif /* ndef FEATURE_STATISTICS */
695 struct file_list * fl;
696 struct url_actions * b;
697 jb_err err = JB_ERR_OK;
705 if (NULL == (exports = default_exports(csp, "show-status")))
707 return JB_ERR_MEMORY;
710 switch (*(lookup(parameters, "file")))
713 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_ACTION_FILES && csp->actions_list[i])
715 filename = csp->actions_list[i]->filename;
716 file_description = "Actions File";
723 filename = csp->rlist->filename;
724 file_description = "Filter File";
732 filename = csp->tlist->filename;
733 file_description = "Trust File";
736 #endif /* def FEATURE_TRUST */
739 if (NULL != filename)
741 if ( map(exports, "file-description", 1, file_description, 1)
742 || map(exports, "filepath", 1, html_encode(filename), 0) )
745 return JB_ERR_MEMORY;
748 if ((fp = fopen(filename, "r")) == NULL)
750 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
753 return JB_ERR_MEMORY;
759 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
761 string_join (&s, html_encode(buf));
765 if (map(exports, "contents", 1, s, 0))
768 return JB_ERR_MEMORY;
772 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
776 for (j = 0; (s != NULL) && (j < Argc); j++)
778 if (!err) err = string_join (&s, html_encode(Argv[j]));
779 if (!err) err = string_append(&s, " ");
781 if (!err) err = map(exports, "invocation", 1, s, 0);
783 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
784 if (!err) err = show_defines(exports);
789 return JB_ERR_MEMORY;
792 #ifdef FEATURE_STATISTICS
793 local_urls_read = urls_read;
794 local_urls_rejected = urls_rejected;
797 * Need to alter the stats not to include the fetch of this
800 * Can't do following thread safely! doh!
803 * urls_rejected--; * This will be incremented subsequently *
806 if (local_urls_read == 0)
808 if (!err) err = map_block_killer(exports, "have-stats");
812 if (!err) err = map_block_killer(exports, "have-no-stats");
814 perc_rej = (float)local_urls_rejected * 100.0F /
815 (float)local_urls_read;
817 sprintf(buf, "%d", local_urls_read);
818 if (!err) err = map(exports, "requests-received", 1, buf, 1);
820 sprintf(buf, "%d", local_urls_rejected);
821 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
823 sprintf(buf, "%6.2f", perc_rej);
824 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
827 #else /* ndef FEATURE_STATISTICS */
828 err = err || map_block_killer(exports, "statistics");
829 #endif /* ndef FEATURE_STATISTICS */
832 * List all action files in use, together with view and edit links,
833 * except for standard.action, which should only be viewable. (Not
834 * enforced in the editor itself)
835 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
838 for (i = 0; i < MAX_ACTION_FILES; i++)
840 if (((fl = csp->actions_list[i]) != NULL) && ((b = fl->f) != NULL))
842 if (!err) err = string_append(&s, "<tr><td>");
843 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
844 snprintf(buf, 100, "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a> ", i);
845 if (!err) err = string_append(&s, buf);
847 if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
849 snprintf(buf, 100, "<a href=\"/edit-actions-list?f=%s\">Edit</a>", csp->config->actions_file_short[i]);
850 if (!err) err = string_append(&s, buf);
853 if (!err) err = string_append(&s, "</td></tr>\n");
858 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
862 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
867 if (!err) err = map(exports, "re-filter-filename", 1, html_encode(csp->rlist->filename), 0);
871 if (!err) err = map(exports, "re-filter-filename", 1, "None specified", 1);
872 if (!err) err = map_block_killer(exports, "have-filterfile");
878 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
882 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
883 if (!err) err = map_block_killer(exports, "have-trustfile");
886 if (!err) err = map_block_killer(exports, "trust-support");
887 #endif /* ndef FEATURE_TRUST */
892 return JB_ERR_MEMORY;
895 return template_fill_for_cgi(csp, "show-status", exports, rsp);
899 /*********************************************************************
901 * Function : cgi_show_url_info
903 * Description : CGI function that determines and shows which actions
904 * Privoxy will perform for a given url, and which
905 * matches starting from the defaults have lead to that.
908 * 1 : csp = Current client state (buffers, headers, etc...)
909 * 2 : rsp = http_response data structure for output
910 * 3 : parameters = map of cgi parameters
913 * url : The url whose actions are to be determined.
914 * If url is unset, the url-given conditional will be
915 * set, so that all but the form can be suppressed in
918 * Returns : JB_ERR_OK on success
919 * JB_ERR_MEMORY on out-of-memory error.
921 *********************************************************************/
922 jb_err cgi_show_url_info(struct client_state *csp,
923 struct http_response *rsp,
924 const struct map *parameters)
934 if (NULL == (exports = default_exports(csp, "show-url-info")))
936 return JB_ERR_MEMORY;
940 * Get the url= parameter (if present) and remove any leading/trailing spaces.
942 url_param = strdup(lookup(parameters, "url"));
943 if (url_param == NULL)
946 return JB_ERR_MEMORY;
951 * Handle prefixes. 4 possibilities:
952 * 1) "http://" or "https://" prefix present and followed by URL - OK
953 * 2) Only the "http://" or "https://" part is present, no URL - change
954 * to empty string so it will be detected later as "no URL".
955 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
957 * 4) Parameter not specified or is empty string - let this fall through
958 * for now, next block of code will handle it.
960 if (0 == strncmp(url_param, "http://", 7))
962 if (url_param[7] == '\0')
965 * Empty URL (just prefix).
966 * Make it totally empty so it's caught by the next if()
971 else if (0 == strncmp(url_param, "https://", 8))
973 if (url_param[8] == '\0')
976 * Empty URL (just prefix).
977 * Make it totally empty so it's caught by the next if()
982 else if (url_param[0] != '\0')
985 * Unknown prefix - assume http://
987 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
988 if (NULL == url_param_prefixed)
992 return JB_ERR_MEMORY;
994 strcpy(url_param_prefixed, "http://");
995 strcpy(url_param_prefixed + 7, url_param);
997 url_param = url_param_prefixed;
1001 if (url_param[0] == '\0')
1003 /* URL paramater not specified, display query form only. */
1005 if (map_block_killer(exports, "url-given")
1006 || map(exports, "url", 1, "", 1))
1009 return JB_ERR_MEMORY;
1014 /* Given a URL, so query it. */
1019 struct file_list *fl;
1020 struct url_actions *b;
1021 struct http_request url_to_query[1];
1022 struct current_action_spec action[1];
1025 if (map(exports, "url", 1, html_encode(url_param), 0))
1029 return JB_ERR_MEMORY;
1032 init_current_action(action);
1034 if (map(exports, "default", 1, current_action_to_html(action, csp), 0))
1036 free_current_action(action);
1039 return JB_ERR_MEMORY;
1042 err = parse_http_url(url_param, url_to_query, csp);
1046 if (err == JB_ERR_MEMORY)
1048 free_current_action(action);
1050 return JB_ERR_MEMORY;
1056 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1057 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1059 free_current_action(action);
1064 return JB_ERR_MEMORY;
1067 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1071 * We have a warning about SSL paths. Hide it for insecure sites.
1073 if (!url_to_query->ssl)
1075 if (map_block_killer(exports, "https"))
1077 free_current_action(action);
1079 return JB_ERR_MEMORY;
1083 matches = strdup("<table class=\"transparent\">");
1085 for (i = 0; i < MAX_ACTION_FILES; i++)
1087 if (NULL == csp->config->actions_file_short[i]
1088 || !strcmp(csp->config->actions_file_short[i], "standard")) continue;
1092 if ((fl = csp->actions_list[i]) != NULL)
1094 if ((b = fl->f) != NULL)
1096 /* FIXME: Hardcoded HTML! */
1097 string_append(&matches, "<tr><th>In file: ");
1098 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1099 snprintf(buf, 150, ".action <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1100 string_append(&matches, buf);
1101 string_append(&matches, "View</a> <a class=\"cmd\" href=\"/edit-actions-list?f=");
1102 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1103 string_append(&matches, "\">Edit</a></th></tr>\n");
1110 for (; (b != NULL) && (matches != NULL); b = b->next)
1112 if (url_match(b->url, url_to_query))
1114 string_append(&matches, "<tr><td>{");
1115 string_join (&matches, actions_to_html(b->action, csp));
1116 string_append(&matches, " }</b><br>\n<code>");
1117 string_join (&matches, html_encode(b->url->spec));
1118 string_append(&matches, "</code></td></tr>\n");
1120 if (merge_current_action(action, b->action))
1123 free_http_request(url_to_query);
1124 free_current_action(action);
1126 return JB_ERR_MEMORY;
1134 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1137 string_append(&matches, "</table>\n");
1139 free_http_request(url_to_query);
1141 if (matches == NULL)
1143 free_current_action(action);
1145 return JB_ERR_MEMORY;
1148 if (map(exports, "matches", 1, matches , 0))
1150 free_current_action(action);
1152 return JB_ERR_MEMORY;
1155 s = current_action_to_html(action, csp);
1157 free_current_action(action);
1159 if (map(exports, "final", 1, s, 0))
1162 return JB_ERR_MEMORY;
1166 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1170 /*********************************************************************
1172 * Function : cgi_robots_txt
1174 * Description : CGI function to return "/robots.txt".
1177 * 1 : csp = Current client state (buffers, headers, etc...)
1178 * 2 : rsp = http_response data structure for output
1179 * 3 : parameters = map of cgi parameters
1181 * CGI Parameters : None
1183 * Returns : JB_ERR_OK on success
1184 * JB_ERR_MEMORY on out-of-memory error.
1186 *********************************************************************/
1187 jb_err cgi_robots_txt(struct client_state *csp,
1188 struct http_response *rsp,
1189 const struct map *parameters)
1195 "# This is the Privoxy control interface.\n"
1196 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1202 if (rsp->body == NULL)
1204 return JB_ERR_MEMORY;
1207 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1211 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1212 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1214 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1218 /*********************************************************************
1220 * Function : show_defines
1222 * Description : Add to a map the state od all conditional #defines
1223 * used when building
1226 * 1 : exports = map to extend
1228 * Returns : JB_ERR_OK on success
1229 * JB_ERR_MEMORY on out-of-memory error.
1231 *********************************************************************/
1232 static jb_err show_defines(struct map *exports)
1234 jb_err err = JB_ERR_OK;
1237 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1238 #else /* ifndef FEATURE_ACL */
1239 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1240 #endif /* ndef FEATURE_ACL */
1242 #ifdef FEATURE_CGI_EDIT_ACTIONS
1243 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1244 #else /* ifndef FEATURE_COOKIE_JAR */
1245 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1246 #endif /* ndef FEATURE_COOKIE_JAR */
1248 #ifdef FEATURE_COOKIE_JAR
1249 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1250 #else /* ifndef FEATURE_COOKIE_JAR */
1251 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1252 #endif /* ndef FEATURE_COOKIE_JAR */
1254 #ifdef FEATURE_FAST_REDIRECTS
1255 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1256 #else /* ifndef FEATURE_FAST_REDIRECTS */
1257 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1258 #endif /* ndef FEATURE_FAST_REDIRECTS */
1260 #ifdef FEATURE_FORCE_LOAD
1261 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1262 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1263 #else /* ifndef FEATURE_FORCE_LOAD */
1264 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1265 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1266 #endif /* ndef FEATURE_FORCE_LOAD */
1268 #ifdef FEATURE_IMAGE_BLOCKING
1269 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1270 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1271 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1272 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1274 #ifdef FEATURE_IMAGE_DETECT_MSIE
1275 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1276 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1277 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1278 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1280 #ifdef FEATURE_KILL_POPUPS
1281 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1282 #else /* ifndef FEATURE_KILL_POPUPS */
1283 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1284 #endif /* ndef FEATURE_KILL_POPUPS */
1286 #ifdef FEATURE_NO_GIFS
1287 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1288 #else /* ifndef FEATURE_NO_GIFS */
1289 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1290 #endif /* ndef FEATURE_NO_GIFS */
1292 #ifdef FEATURE_PTHREAD
1293 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1294 #else /* ifndef FEATURE_PTHREAD */
1295 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1296 #endif /* ndef FEATURE_PTHREAD */
1298 #ifdef FEATURE_STATISTICS
1299 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1300 #else /* ifndef FEATURE_STATISTICS */
1301 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1302 #endif /* ndef FEATURE_STATISTICS */
1304 #ifdef FEATURE_TOGGLE
1305 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1306 #else /* ifndef FEATURE_TOGGLE */
1307 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1308 #endif /* ndef FEATURE_TOGGLE */
1310 #ifdef FEATURE_TRUST
1311 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1312 #else /* ifndef FEATURE_TRUST */
1313 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1314 #endif /* ndef FEATURE_TRUST */
1317 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1318 #else /* ifndef STATIC_PCRE */
1319 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1320 #endif /* ndef STATIC_PCRE */
1323 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1324 #else /* ifndef STATIC_PCRS */
1325 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1326 #endif /* ndef STATIC_PCRS */
1332 /*********************************************************************
1334 * Function : show_rcs
1336 * Description : Create a string with the rcs info for all sourcefiles
1340 * Returns : A string, or NULL on out-of-memory.
1342 *********************************************************************/
1343 static char *show_rcs(void)
1345 char *result = strdup("");
1346 char buf[BUFFER_SIZE];
1348 /* Instead of including *all* dot h's in the project (thus creating a
1349 * tremendous amount of dependencies), I will concede to declaring them
1350 * as extern's. This forces the developer to add to this list, but oh well.
1353 #define SHOW_RCS(__x) \
1355 extern const char __x[]; \
1356 sprintf(buf, "%s\n", __x); \
1357 string_append(&result, buf); \
1360 /* In alphabetical order */
1361 SHOW_RCS(actions_h_rcs)
1362 SHOW_RCS(actions_rcs)
1365 #ifdef FEATURE_CGI_EDIT_ACTIONS
1366 SHOW_RCS(cgiedit_h_rcs)
1367 SHOW_RCS(cgiedit_rcs)
1368 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1369 SHOW_RCS(cgisimple_h_rcs)
1370 SHOW_RCS(cgisimple_rcs)
1372 SHOW_RCS(cygwin_h_rcs)
1374 SHOW_RCS(deanimate_h_rcs)
1375 SHOW_RCS(deanimate_rcs)
1376 SHOW_RCS(encode_h_rcs)
1377 SHOW_RCS(encode_rcs)
1378 SHOW_RCS(errlog_h_rcs)
1379 SHOW_RCS(errlog_rcs)
1380 SHOW_RCS(filters_h_rcs)
1381 SHOW_RCS(filters_rcs)
1382 SHOW_RCS(gateway_h_rcs)
1383 SHOW_RCS(gateway_rcs)
1384 SHOW_RCS(jbsockets_h_rcs)
1385 SHOW_RCS(jbsockets_rcs)
1388 #ifdef FEATURE_KILL_POPUPS
1389 SHOW_RCS(killpopup_h_rcs)
1390 SHOW_RCS(killpopup_rcs)
1391 #endif /* def FEATURE_KILL_POPUPS */
1392 SHOW_RCS(list_h_rcs)
1394 SHOW_RCS(loadcfg_h_rcs)
1395 SHOW_RCS(loadcfg_rcs)
1396 SHOW_RCS(loaders_h_rcs)
1397 SHOW_RCS(loaders_rcs)
1398 SHOW_RCS(miscutil_h_rcs)
1399 SHOW_RCS(miscutil_rcs)
1400 SHOW_RCS(parsers_h_rcs)
1401 SHOW_RCS(parsers_rcs)
1403 SHOW_RCS(pcrs_h_rcs)
1404 SHOW_RCS(project_h_rcs)
1405 SHOW_RCS(ssplit_h_rcs)
1406 SHOW_RCS(ssplit_rcs)
1407 SHOW_RCS(urlmatch_h_rcs)
1408 SHOW_RCS(urlmatch_rcs)
1410 #ifndef _WIN_CONSOLE
1411 SHOW_RCS(w32log_h_rcs)
1412 SHOW_RCS(w32log_rcs)
1413 SHOW_RCS(w32res_h_rcs)
1414 SHOW_RCS(w32taskbar_h_rcs)
1415 SHOW_RCS(w32taskbar_rcs)
1416 #endif /* ndef _WIN_CONSOLE */
1417 SHOW_RCS(win32_h_rcs)
1419 #endif /* def _WIN32 */