1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.33 2002/04/30 11:14:52 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.33 2002/04/30 11:14:52 oes
40 * Made csp the first parameter in *action_to_html
42 * Revision 1.32 2002/04/26 18:29:13 jongfoster
43 * Fixing this Visual C++ warning:
44 * cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
46 * Revision 1.31 2002/04/26 12:54:36 oes
47 * - Kill obsolete REDIRECT_URL code
48 * - Error handling fixes
49 * - Style sheet related HTML snipplet changes
50 * - cgi_show_url_info:
51 * - Matches now in table, actions on single lines,
53 * - standard.action suppressed
54 * - Buttons to View and Edit AFs
56 * Revision 1.30 2002/04/24 02:18:08 oes
57 * - show-status is now the starting point for editing
58 * the actions files, generate list of all AFs with buttons
59 * for viewing and editing, new look for file list (Jon:
60 * buttons now aligned ;-P ), view mode now supports multiple
61 * AFs, name changes, no view links for unspecified files,
62 * no edit link for standard.action.
64 * - Jon's multiple AF patch: cgi_show_url_info now uses all
65 * AFs and marks the output accordingly
67 * Revision 1.29 2002/04/10 13:38:35 oes
68 * load_template signature changed
70 * Revision 1.28 2002/04/07 15:42:12 jongfoster
71 * Fixing send-banner?type=auto when the image-blocker is
72 * a redirect to send-banner
74 * Revision 1.27 2002/04/05 15:50:48 oes
75 * added send-stylesheet CGI
77 * Revision 1.26 2002/04/04 00:36:36 gliptak
78 * always use pcre for matching
80 * Revision 1.25 2002/04/03 22:28:03 gliptak
81 * Removed references to gnu_regex
83 * Revision 1.24 2002/04/02 16:12:47 oes
84 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
86 * Revision 1.23 2002/03/26 22:29:54 swa
87 * we have a new homepage!
89 * Revision 1.22 2002/03/24 16:18:15 jongfoster
92 * Revision 1.21 2002/03/24 15:23:33 jongfoster
95 * Revision 1.20 2002/03/24 13:25:43 swa
96 * name change related issues
98 * Revision 1.19 2002/03/16 23:54:06 jongfoster
99 * Adding graceful termination feature, to help look for memory leaks.
100 * If you enable this (which, by design, has to be done by hand
101 * editing config.h) and then go to http://i.j.b/die, then the program
102 * will exit cleanly after the *next* request. It should free all the
103 * memory that was used.
105 * Revision 1.18 2002/03/12 01:44:49 oes
106 * Changed default for "blocked" image from jb logo to checkboard pattern
108 * Revision 1.17 2002/03/08 16:43:18 oes
109 * Added choice beween GIF and PNG built-in images
111 * Revision 1.16 2002/03/07 03:48:38 oes
112 * - Changed built-in images from GIF to PNG
113 * (with regard to Unisys patent issue)
114 * - Added a 4x4 pattern PNG which is less intrusive
115 * than the logo but also clearly marks the deleted banners
117 * Revision 1.15 2002/03/06 22:54:35 jongfoster
118 * Automated function-comment nitpicking.
120 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
121 * Clean up a little CRLF unpleasantness that suddenly appeared
123 * Revision 1.13 2002/02/21 00:10:37 jongfoster
124 * Adding send-banner?type=auto option
126 * Revision 1.12 2002/01/23 01:03:32 jongfoster
127 * Fixing gcc [CygWin] compiler warnings
129 * Revision 1.11 2002/01/23 00:01:04 jongfoster
130 * Adding cgi_transparent_gif() for http://i.j.b/t
131 * Adding missing html_encode() to many CGI functions.
132 * Adding urlmatch.[ch] to http://i.j.b/show-version
134 * Revision 1.10 2002/01/17 21:10:37 jongfoster
135 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
136 * Also fixing a problem in the same function with improperly quoted URLs
137 * in output HTML, and adding code to handle https:// URLs correctly.
139 * Revision 1.9 2001/11/30 23:09:15 jongfoster
140 * Now reports on FEATURE_CGI_EDIT_ACTIONS
141 * Removing FEATURE_DENY_GZIP from template
143 * Revision 1.8 2001/11/13 00:14:07 jongfoster
144 * Fixing stupid bug now I've figured out what || means.
145 * (It always returns 0 or 1, not one of it's paramaters.)
147 * Revision 1.7 2001/10/23 21:48:19 jongfoster
148 * Cleaning up error handling in CGI functions - they now send back
149 * a HTML error page and should never cause a FATAL error. (Fixes one
150 * potential source of "denial of service" attacks).
152 * CGI actions file editor that works and is actually useful.
154 * Ability to toggle JunkBuster remotely using a CGI call.
156 * You can turn off both the above features in the main configuration
157 * file, e.g. if you are running a multi-user proxy.
159 * Revision 1.6 2001/10/14 22:00:32 jongfoster
160 * Adding support for a 404 error when an invalid CGI page is requested.
162 * Revision 1.5 2001/10/07 15:30:41 oes
163 * Removed FEATURE_DENY_GZIP
165 * Revision 1.4 2001/10/02 15:31:12 oes
166 * Introduced show-request cgi
168 * Revision 1.3 2001/09/22 16:34:44 jongfoster
169 * Removing unneeded #includes
171 * Revision 1.2 2001/09/19 18:01:11 oes
172 * Fixed comments; cosmetics
174 * Revision 1.1 2001/09/16 17:08:54 jongfoster
175 * Moving simple CGI functions from cgi.c to new file cgisimple.c
178 **********************************************************************/
184 #include <sys/types.h>
191 #define snprintf _snprintf
192 #endif /* def _WIN32 */
196 #include "cgisimple.h"
202 #include "miscutil.h"
205 #include "urlmatch.h"
208 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
211 static char *show_rcs(void);
212 static jb_err show_defines(struct map *exports);
215 /*********************************************************************
217 * Function : cgi_default
219 * Description : CGI function that is called for the CGI_SITE_1_HOST
220 * and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
221 * Boring - only exports the default exports.
224 * 1 : csp = Current client state (buffers, headers, etc...)
225 * 2 : rsp = http_response data structure for output
226 * 3 : parameters = map of cgi parameters
228 * CGI Parameters : none
230 * Returns : JB_ERR_OK on success
231 * JB_ERR_MEMORY on out-of-memory
233 *********************************************************************/
234 jb_err cgi_default(struct client_state *csp,
235 struct http_response *rsp,
236 const struct map *parameters)
243 if (NULL == (exports = default_exports(csp, "")))
245 return JB_ERR_MEMORY;
248 return template_fill_for_cgi(csp, "default", exports, rsp);
252 /*********************************************************************
254 * Function : cgi_error_404
256 * Description : CGI function that is called if an unknown action was
260 * 1 : csp = Current client state (buffers, headers, etc...)
261 * 2 : rsp = http_response data structure for output
262 * 3 : parameters = map of cgi parameters
264 * CGI Parameters : none
266 * Returns : JB_ERR_OK on success
267 * JB_ERR_MEMORY on out-of-memory error.
269 *********************************************************************/
270 jb_err cgi_error_404(struct client_state *csp,
271 struct http_response *rsp,
272 const struct map *parameters)
280 if (NULL == (exports = default_exports(csp, NULL)))
282 return JB_ERR_MEMORY;
285 rsp->status = strdup("404 Privoxy configuration page not found");
286 if (rsp->status == NULL)
289 return JB_ERR_MEMORY;
292 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
296 #ifdef FEATURE_GRACEFUL_TERMINATION
297 /*********************************************************************
301 * Description : CGI function to shut down Privoxy.
302 * NOTE: Turning this on in a production build
303 * would be a BAD idea. An EXTREMELY BAD idea.
304 * In short, don't do it.
307 * 1 : csp = Current client state (buffers, headers, etc...)
308 * 2 : rsp = http_response data structure for output
309 * 3 : parameters = map of cgi parameters
311 * CGI Parameters : none
313 * Returns : JB_ERR_OK on success
314 * JB_ERR_MEMORY on out-of-memory error.
316 *********************************************************************/
317 jb_err cgi_die (struct client_state *csp,
318 struct http_response *rsp,
319 const struct map *parameters)
329 * I don't really care what gets sent back to the browser.
330 * Take the easy option - "out of memory" page.
333 return JB_ERR_MEMORY;
335 #endif /* def FEATURE_GRACEFUL_TERMINATION */
338 /*********************************************************************
340 * Function : cgi_show_request
342 * Description : Show the client's request and what sed() would have
346 * 1 : csp = Current client state (buffers, headers, etc...)
347 * 2 : rsp = http_response data structure for output
348 * 3 : parameters = map of cgi parameters
350 * CGI Parameters : none
352 * Returns : JB_ERR_OK on success
353 * JB_ERR_MEMORY on out-of-memory error.
355 *********************************************************************/
356 jb_err cgi_show_request(struct client_state *csp,
357 struct http_response *rsp,
358 const struct map *parameters)
367 if (NULL == (exports = default_exports(csp, "show-request")))
369 return JB_ERR_MEMORY;
373 * Repair the damage done to the IOB by get_header()
375 for (p = csp->iob->buf; p < csp->iob->eod; p++)
377 if (*p == '\0') *p = '\n';
381 * Export the original client's request and the one we would
382 * be sending to the server if this wasn't a CGI call
385 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
388 return JB_ERR_MEMORY;
391 if (map(exports, "processed-request", 1, html_encode_and_free_original(
392 sed(client_patterns, add_client_headers, csp)), 0))
395 return JB_ERR_MEMORY;
398 return template_fill_for_cgi(csp, "show-request", exports, rsp);
402 /*********************************************************************
404 * Function : cgi_send_banner
406 * Description : CGI function that returns a banner.
409 * 1 : csp = Current client state (buffers, headers, etc...)
410 * 2 : rsp = http_response data structure for output
411 * 3 : parameters = map of cgi parameters
414 * type : Selects the type of banner between "trans", "logo",
415 * and "auto". Defaults to "logo" if absent or invalid.
416 * "auto" means to select as if we were image-blocking.
417 * (Only the first character really counts).
419 * Returns : JB_ERR_OK on success
420 * JB_ERR_MEMORY on out-of-memory error.
422 *********************************************************************/
423 jb_err cgi_send_banner(struct client_state *csp,
424 struct http_response *rsp,
425 const struct map *parameters)
427 char imagetype = lookup(parameters, "type")[0];
429 if (imagetype == 'a') /* auto */
431 /* Default to pattern */
433 #ifdef FEATURE_IMAGE_BLOCKING
434 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
436 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
437 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
439 /* determine HOW images should be blocked */
440 const char * p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
442 /* and handle accordingly: */
445 /* Use default - nothing to do here. */
447 else if (0 == strcmpic(p, "blank"))
451 else if (0 == strcmpic(p, "pattern"))
455 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
457 imagetype = p[sizeof(prefix1) - 1];
459 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
461 imagetype = p[sizeof(prefix2) - 1];
464 #endif /* def FEATURE_IMAGE_BLOCKING */
467 if ((imagetype == 'b') || (imagetype == 't')) /* blank / transparent */
469 rsp->body = bindup(image_blank_data, image_blank_length);
470 rsp->content_length = image_blank_length;
475 rsp->body = bindup(image_pattern_data, image_pattern_length);
476 rsp->content_length = image_pattern_length;
479 if (rsp->body == NULL)
481 return JB_ERR_MEMORY;
484 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
486 return JB_ERR_MEMORY;
496 /*********************************************************************
498 * Function : cgi_transparent_image
500 * Description : CGI function that sends a 1x1 transparent image.
503 * 1 : csp = Current client state (buffers, headers, etc...)
504 * 2 : rsp = http_response data structure for output
505 * 3 : parameters = map of cgi parameters
507 * CGI Parameters : None
509 * Returns : JB_ERR_OK on success
510 * JB_ERR_MEMORY on out-of-memory error.
512 *********************************************************************/
513 jb_err cgi_transparent_image(struct client_state *csp,
514 struct http_response *rsp,
515 const struct map *parameters)
517 rsp->body = bindup(image_blank_data, image_blank_length);
518 rsp->content_length = image_blank_length;
520 if (rsp->body == NULL)
522 return JB_ERR_MEMORY;
525 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
527 return JB_ERR_MEMORY;
537 /*********************************************************************
539 * Function : cgi_send_stylesheet
541 * Description : CGI function that sends a css stylesheet found
542 * in the cgi-style.css template
545 * 1 : csp = Current client state (buffers, headers, etc...)
546 * 2 : rsp = http_response data structure for output
547 * 3 : parameters = map of cgi parameters
549 * CGI Parameters : None
551 * Returns : JB_ERR_OK on success
552 * JB_ERR_MEMORY on out-of-memory error.
554 *********************************************************************/
555 jb_err cgi_send_stylesheet(struct client_state *csp,
556 struct http_response *rsp,
557 const struct map *parameters)
564 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
566 if (err == JB_ERR_FILE)
569 * No way to tell user; send empty stylesheet
571 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
575 return err; /* JB_ERR_MEMORY */
578 if (enlist(rsp->headers, "Content-Type: text/css"))
580 return JB_ERR_MEMORY;
588 /*********************************************************************
590 * Function : cgi_show_version
592 * Description : CGI function that returns a a web page describing the
593 * file versions of Privoxy.
596 * 1 : csp = Current client state (buffers, headers, etc...)
597 * 2 : rsp = http_response data structure for output
598 * 3 : parameters = map of cgi parameters
600 * CGI Parameters : none
602 * Returns : JB_ERR_OK on success
603 * JB_ERR_MEMORY on out-of-memory error.
605 *********************************************************************/
606 jb_err cgi_show_version(struct client_state *csp,
607 struct http_response *rsp,
608 const struct map *parameters)
616 if (NULL == (exports = default_exports(csp, "show-version")))
618 return JB_ERR_MEMORY;
621 if (map(exports, "sourceversions", 1, show_rcs(), 0))
624 return JB_ERR_MEMORY;
627 return template_fill_for_cgi(csp, "show-version", exports, rsp);
631 /*********************************************************************
633 * Function : cgi_show_status
635 * Description : CGI function that returns a a web page describing the
636 * current status of Privoxy.
639 * 1 : csp = Current client state (buffers, headers, etc...)
640 * 2 : rsp = http_response data structure for output
641 * 3 : parameters = map of cgi parameters
644 * file : Which file to show. Only first letter is checked,
646 * - "p"ermissions (actions) file
649 * Default is to show menu and other information.
651 * Returns : JB_ERR_OK on success
652 * JB_ERR_MEMORY on out-of-memory error.
654 *********************************************************************/
655 jb_err cgi_show_status(struct client_state *csp,
656 struct http_response *rsp,
657 const struct map *parameters)
664 char buf[BUFFER_SIZE];
665 const char * filename = NULL;
666 char * file_description = NULL;
667 #ifdef FEATURE_STATISTICS
668 float perc_rej; /* Percentage of http requests rejected */
670 int local_urls_rejected;
671 #endif /* ndef FEATURE_STATISTICS */
672 struct file_list * fl;
673 struct url_actions * b;
674 jb_err err = JB_ERR_OK;
682 if (NULL == (exports = default_exports(csp, "show-status")))
684 return JB_ERR_MEMORY;
687 switch (*(lookup(parameters, "file")))
690 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_ACTION_FILES && csp->actions_list[i])
692 filename = csp->actions_list[i]->filename;
693 file_description = "Actions File";
700 filename = csp->rlist->filename;
701 file_description = "Filter File";
709 filename = csp->tlist->filename;
710 file_description = "Trust File";
713 #endif /* def FEATURE_TRUST */
716 if (NULL != filename)
718 if ( map(exports, "file-description", 1, file_description, 1)
719 || map(exports, "filepath", 1, html_encode(filename), 0) )
722 return JB_ERR_MEMORY;
725 if ((fp = fopen(filename, "r")) == NULL)
727 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
730 return JB_ERR_MEMORY;
736 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
738 string_join (&s, html_encode(buf));
742 if (map(exports, "contents", 1, s, 0))
745 return JB_ERR_MEMORY;
749 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
753 for (j = 0; (s != NULL) && (j < Argc); j++)
755 if (!err) err = string_join (&s, html_encode(Argv[j]));
756 if (!err) err = string_append(&s, " ");
758 if (!err) err = map(exports, "invocation", 1, s, 0);
760 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
761 if (!err) err = show_defines(exports);
766 return JB_ERR_MEMORY;
769 #ifdef FEATURE_STATISTICS
770 local_urls_read = urls_read;
771 local_urls_rejected = urls_rejected;
774 * Need to alter the stats not to include the fetch of this
777 * Can't do following thread safely! doh!
780 * urls_rejected--; * This will be incremented subsequently *
783 if (local_urls_read == 0)
785 if (!err) err = map_block_killer(exports, "have-stats");
789 if (!err) err = map_block_killer(exports, "have-no-stats");
791 perc_rej = (float)local_urls_rejected * 100.0F /
792 (float)local_urls_read;
794 sprintf(buf, "%d", local_urls_read);
795 if (!err) err = map(exports, "requests-received", 1, buf, 1);
797 sprintf(buf, "%d", local_urls_rejected);
798 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
800 sprintf(buf, "%6.2f", perc_rej);
801 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
804 #else /* ndef FEATURE_STATISTICS */
805 err = err || map_block_killer(exports, "statistics");
806 #endif /* ndef FEATURE_STATISTICS */
809 * List all action files in use, together with view and edit links,
810 * except for standard.action, which should only be viewable. (Not
811 * enforced in the editor itself)
812 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
815 for (i = 0; i < MAX_ACTION_FILES; i++)
817 if (((fl = csp->actions_list[i]) != NULL) && ((b = fl->f) != NULL))
819 if (!err) err = string_append(&s, "<tr><td>");
820 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
821 snprintf(buf, 100, "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a> ", i);
822 if (!err) err = string_append(&s, buf);
824 if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
826 snprintf(buf, 100, "<a href=\"/edit-actions-list?f=%s\">Edit</a>", csp->config->actions_file_short[i]);
827 if (!err) err = string_append(&s, buf);
830 if (!err) err = string_append(&s, "</td></tr>\n");
835 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
839 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
844 if (!err) err = map(exports, "re-filter-filename", 1, html_encode(csp->rlist->filename), 0);
848 if (!err) err = map(exports, "re-filter-filename", 1, "None specified", 1);
849 if (!err) err = map_block_killer(exports, "have-filterfile");
855 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
859 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
860 if (!err) err = map_block_killer(exports, "have-trustfile");
863 if (!err) err = map_block_killer(exports, "trust-support");
864 #endif /* ndef FEATURE_TRUST */
869 return JB_ERR_MEMORY;
872 return template_fill_for_cgi(csp, "show-status", exports, rsp);
876 /*********************************************************************
878 * Function : cgi_show_url_info
880 * Description : CGI function that determines and shows which actions
881 * Privoxy will perform for a given url, and which
882 * matches starting from the defaults have lead to that.
885 * 1 : csp = Current client state (buffers, headers, etc...)
886 * 2 : rsp = http_response data structure for output
887 * 3 : parameters = map of cgi parameters
890 * url : The url whose actions are to be determined.
891 * If url is unset, the url-given conditional will be
892 * set, so that all but the form can be suppressed in
895 * Returns : JB_ERR_OK on success
896 * JB_ERR_MEMORY on out-of-memory error.
898 *********************************************************************/
899 jb_err cgi_show_url_info(struct client_state *csp,
900 struct http_response *rsp,
901 const struct map *parameters)
911 if (NULL == (exports = default_exports(csp, "show-url-info")))
913 return JB_ERR_MEMORY;
917 * Get the url= parameter (if present) and remove any leading/trailing spaces.
919 url_param = strdup(lookup(parameters, "url"));
920 if (url_param == NULL)
923 return JB_ERR_MEMORY;
928 * Handle prefixes. 4 possibilities:
929 * 1) "http://" or "https://" prefix present and followed by URL - OK
930 * 2) Only the "http://" or "https://" part is present, no URL - change
931 * to empty string so it will be detected later as "no URL".
932 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
934 * 4) Parameter not specified or is empty string - let this fall through
935 * for now, next block of code will handle it.
937 if (0 == strncmp(url_param, "http://", 7))
939 if (url_param[7] == '\0')
942 * Empty URL (just prefix).
943 * Make it totally empty so it's caught by the next if()
948 else if (0 == strncmp(url_param, "https://", 8))
950 if (url_param[8] == '\0')
953 * Empty URL (just prefix).
954 * Make it totally empty so it's caught by the next if()
959 else if (url_param[0] != '\0')
962 * Unknown prefix - assume http://
964 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
965 if (NULL == url_param_prefixed)
969 return JB_ERR_MEMORY;
971 strcpy(url_param_prefixed, "http://");
972 strcpy(url_param_prefixed + 7, url_param);
974 url_param = url_param_prefixed;
978 if (url_param[0] == '\0')
980 /* URL paramater not specified, display query form only. */
982 if (map_block_killer(exports, "url-given")
983 || map(exports, "url", 1, "", 1))
986 return JB_ERR_MEMORY;
991 /* Given a URL, so query it. */
996 struct file_list *fl;
997 struct url_actions *b;
998 struct http_request url_to_query[1];
999 struct current_action_spec action[1];
1002 if (map(exports, "url", 1, html_encode(url_param), 0))
1006 return JB_ERR_MEMORY;
1009 init_current_action(action);
1011 if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1013 free_current_action(action);
1016 return JB_ERR_MEMORY;
1019 err = parse_http_url(url_param, url_to_query, csp);
1023 if (err == JB_ERR_MEMORY)
1025 free_current_action(action);
1027 return JB_ERR_MEMORY;
1033 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1034 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1036 free_current_action(action);
1041 return JB_ERR_MEMORY;
1044 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1048 * We have a warning about SSL paths. Hide it for insecure sites.
1050 if (!url_to_query->ssl)
1052 if (map_block_killer(exports, "https"))
1054 free_current_action(action);
1056 return JB_ERR_MEMORY;
1060 matches = strdup("<table class=\"transparent\">");
1062 for (i = 0; i < MAX_ACTION_FILES; i++)
1064 if (NULL == csp->config->actions_file_short[i]
1065 || !strcmp(csp->config->actions_file_short[i], "standard")) continue;
1069 if ((fl = csp->actions_list[i]) != NULL)
1071 if ((b = fl->f) != NULL)
1073 /* FIXME: Hardcoded HTML! */
1074 string_append(&matches, "<tr><th>In file: ");
1075 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1076 snprintf(buf, 150, ".action <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1077 string_append(&matches, buf);
1078 string_append(&matches, "View</a> <a class=\"cmd\" href=\"/edit-actions-list?f=");
1079 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1080 string_append(&matches, "\">Edit</a></th></tr>\n");
1087 for (; (b != NULL) && (matches != NULL); b = b->next)
1089 if (url_match(b->url, url_to_query))
1091 string_append(&matches, "<tr><td>{");
1092 string_join (&matches, actions_to_html(csp, b->action));
1093 string_append(&matches, " }</b><br>\n<code>");
1094 string_join (&matches, html_encode(b->url->spec));
1095 string_append(&matches, "</code></td></tr>\n");
1097 if (merge_current_action(action, b->action))
1100 free_http_request(url_to_query);
1101 free_current_action(action);
1103 return JB_ERR_MEMORY;
1111 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1114 string_append(&matches, "</table>\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 = current_action_to_html(csp, 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 */