1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.34 2002/04/30 12:06:12 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.34 2002/04/30 12:06:12 oes
40 * Deleted unused code from default_cgi
42 * Revision 1.33 2002/04/30 11:14:52 oes
43 * Made csp the first parameter in *action_to_html
45 * Revision 1.32 2002/04/26 18:29:13 jongfoster
46 * Fixing this Visual C++ warning:
47 * cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
49 * Revision 1.31 2002/04/26 12:54:36 oes
50 * - Kill obsolete REDIRECT_URL code
51 * - Error handling fixes
52 * - Style sheet related HTML snipplet changes
53 * - cgi_show_url_info:
54 * - Matches now in table, actions on single lines,
56 * - standard.action suppressed
57 * - Buttons to View and Edit AFs
59 * Revision 1.30 2002/04/24 02:18:08 oes
60 * - show-status is now the starting point for editing
61 * the actions files, generate list of all AFs with buttons
62 * for viewing and editing, new look for file list (Jon:
63 * buttons now aligned ;-P ), view mode now supports multiple
64 * AFs, name changes, no view links for unspecified files,
65 * no edit link for standard.action.
67 * - Jon's multiple AF patch: cgi_show_url_info now uses all
68 * AFs and marks the output accordingly
70 * Revision 1.29 2002/04/10 13:38:35 oes
71 * load_template signature changed
73 * Revision 1.28 2002/04/07 15:42:12 jongfoster
74 * Fixing send-banner?type=auto when the image-blocker is
75 * a redirect to send-banner
77 * Revision 1.27 2002/04/05 15:50:48 oes
78 * added send-stylesheet CGI
80 * Revision 1.26 2002/04/04 00:36:36 gliptak
81 * always use pcre for matching
83 * Revision 1.25 2002/04/03 22:28:03 gliptak
84 * Removed references to gnu_regex
86 * Revision 1.24 2002/04/02 16:12:47 oes
87 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
89 * Revision 1.23 2002/03/26 22:29:54 swa
90 * we have a new homepage!
92 * Revision 1.22 2002/03/24 16:18:15 jongfoster
95 * Revision 1.21 2002/03/24 15:23:33 jongfoster
98 * Revision 1.20 2002/03/24 13:25:43 swa
99 * name change related issues
101 * Revision 1.19 2002/03/16 23:54:06 jongfoster
102 * Adding graceful termination feature, to help look for memory leaks.
103 * If you enable this (which, by design, has to be done by hand
104 * editing config.h) and then go to http://i.j.b/die, then the program
105 * will exit cleanly after the *next* request. It should free all the
106 * memory that was used.
108 * Revision 1.18 2002/03/12 01:44:49 oes
109 * Changed default for "blocked" image from jb logo to checkboard pattern
111 * Revision 1.17 2002/03/08 16:43:18 oes
112 * Added choice beween GIF and PNG built-in images
114 * Revision 1.16 2002/03/07 03:48:38 oes
115 * - Changed built-in images from GIF to PNG
116 * (with regard to Unisys patent issue)
117 * - Added a 4x4 pattern PNG which is less intrusive
118 * than the logo but also clearly marks the deleted banners
120 * Revision 1.15 2002/03/06 22:54:35 jongfoster
121 * Automated function-comment nitpicking.
123 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
124 * Clean up a little CRLF unpleasantness that suddenly appeared
126 * Revision 1.13 2002/02/21 00:10:37 jongfoster
127 * Adding send-banner?type=auto option
129 * Revision 1.12 2002/01/23 01:03:32 jongfoster
130 * Fixing gcc [CygWin] compiler warnings
132 * Revision 1.11 2002/01/23 00:01:04 jongfoster
133 * Adding cgi_transparent_gif() for http://i.j.b/t
134 * Adding missing html_encode() to many CGI functions.
135 * Adding urlmatch.[ch] to http://i.j.b/show-version
137 * Revision 1.10 2002/01/17 21:10:37 jongfoster
138 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
139 * Also fixing a problem in the same function with improperly quoted URLs
140 * in output HTML, and adding code to handle https:// URLs correctly.
142 * Revision 1.9 2001/11/30 23:09:15 jongfoster
143 * Now reports on FEATURE_CGI_EDIT_ACTIONS
144 * Removing FEATURE_DENY_GZIP from template
146 * Revision 1.8 2001/11/13 00:14:07 jongfoster
147 * Fixing stupid bug now I've figured out what || means.
148 * (It always returns 0 or 1, not one of it's paramaters.)
150 * Revision 1.7 2001/10/23 21:48:19 jongfoster
151 * Cleaning up error handling in CGI functions - they now send back
152 * a HTML error page and should never cause a FATAL error. (Fixes one
153 * potential source of "denial of service" attacks).
155 * CGI actions file editor that works and is actually useful.
157 * Ability to toggle JunkBuster remotely using a CGI call.
159 * You can turn off both the above features in the main configuration
160 * file, e.g. if you are running a multi-user proxy.
162 * Revision 1.6 2001/10/14 22:00:32 jongfoster
163 * Adding support for a 404 error when an invalid CGI page is requested.
165 * Revision 1.5 2001/10/07 15:30:41 oes
166 * Removed FEATURE_DENY_GZIP
168 * Revision 1.4 2001/10/02 15:31:12 oes
169 * Introduced show-request cgi
171 * Revision 1.3 2001/09/22 16:34:44 jongfoster
172 * Removing unneeded #includes
174 * Revision 1.2 2001/09/19 18:01:11 oes
175 * Fixed comments; cosmetics
177 * Revision 1.1 2001/09/16 17:08:54 jongfoster
178 * Moving simple CGI functions from cgi.c to new file cgisimple.c
181 **********************************************************************/
187 #include <sys/types.h>
194 #define snprintf _snprintf
195 #endif /* def _WIN32 */
199 #include "cgisimple.h"
205 #include "miscutil.h"
208 #include "urlmatch.h"
211 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
214 static char *show_rcs(void);
215 static jb_err show_defines(struct map *exports);
218 /*********************************************************************
220 * Function : cgi_default
222 * Description : CGI function that is called for the CGI_SITE_1_HOST
223 * and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
224 * Boring - only exports the default exports.
227 * 1 : csp = Current client state (buffers, headers, etc...)
228 * 2 : rsp = http_response data structure for output
229 * 3 : parameters = map of cgi parameters
231 * CGI Parameters : none
233 * Returns : JB_ERR_OK on success
234 * JB_ERR_MEMORY on out-of-memory
236 *********************************************************************/
237 jb_err cgi_default(struct client_state *csp,
238 struct http_response *rsp,
239 const struct map *parameters)
246 if (NULL == (exports = default_exports(csp, "")))
248 return JB_ERR_MEMORY;
251 return template_fill_for_cgi(csp, "default", exports, rsp);
255 /*********************************************************************
257 * Function : cgi_error_404
259 * Description : CGI function that is called if an unknown action was
263 * 1 : csp = Current client state (buffers, headers, etc...)
264 * 2 : rsp = http_response data structure for output
265 * 3 : parameters = map of cgi parameters
267 * CGI Parameters : none
269 * Returns : JB_ERR_OK on success
270 * JB_ERR_MEMORY on out-of-memory error.
272 *********************************************************************/
273 jb_err cgi_error_404(struct client_state *csp,
274 struct http_response *rsp,
275 const struct map *parameters)
283 if (NULL == (exports = default_exports(csp, NULL)))
285 return JB_ERR_MEMORY;
288 rsp->status = strdup("404 Privoxy configuration page not found");
289 if (rsp->status == NULL)
292 return JB_ERR_MEMORY;
295 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
299 #ifdef FEATURE_GRACEFUL_TERMINATION
300 /*********************************************************************
304 * Description : CGI function to shut down Privoxy.
305 * NOTE: Turning this on in a production build
306 * would be a BAD idea. An EXTREMELY BAD idea.
307 * In short, don't do it.
310 * 1 : csp = Current client state (buffers, headers, etc...)
311 * 2 : rsp = http_response data structure for output
312 * 3 : parameters = map of cgi parameters
314 * CGI Parameters : none
316 * Returns : JB_ERR_OK on success
317 * JB_ERR_MEMORY on out-of-memory error.
319 *********************************************************************/
320 jb_err cgi_die (struct client_state *csp,
321 struct http_response *rsp,
322 const struct map *parameters)
332 * I don't really care what gets sent back to the browser.
333 * Take the easy option - "out of memory" page.
336 return JB_ERR_MEMORY;
338 #endif /* def FEATURE_GRACEFUL_TERMINATION */
341 /*********************************************************************
343 * Function : cgi_show_request
345 * Description : Show the client's request and what sed() would have
349 * 1 : csp = Current client state (buffers, headers, etc...)
350 * 2 : rsp = http_response data structure for output
351 * 3 : parameters = map of cgi parameters
353 * CGI Parameters : none
355 * Returns : JB_ERR_OK on success
356 * JB_ERR_MEMORY on out-of-memory error.
358 *********************************************************************/
359 jb_err cgi_show_request(struct client_state *csp,
360 struct http_response *rsp,
361 const struct map *parameters)
370 if (NULL == (exports = default_exports(csp, "show-request")))
372 return JB_ERR_MEMORY;
376 * Repair the damage done to the IOB by get_header()
378 for (p = csp->iob->buf; p < csp->iob->eod; p++)
380 if (*p == '\0') *p = '\n';
384 * Export the original client's request and the one we would
385 * be sending to the server if this wasn't a CGI call
388 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
391 return JB_ERR_MEMORY;
394 if (map(exports, "processed-request", 1, html_encode_and_free_original(
395 sed(client_patterns, add_client_headers, csp)), 0))
398 return JB_ERR_MEMORY;
401 return template_fill_for_cgi(csp, "show-request", exports, rsp);
405 /*********************************************************************
407 * Function : cgi_send_banner
409 * Description : CGI function that returns a banner.
412 * 1 : csp = Current client state (buffers, headers, etc...)
413 * 2 : rsp = http_response data structure for output
414 * 3 : parameters = map of cgi parameters
417 * type : Selects the type of banner between "trans", "logo",
418 * and "auto". Defaults to "logo" if absent or invalid.
419 * "auto" means to select as if we were image-blocking.
420 * (Only the first character really counts).
422 * Returns : JB_ERR_OK on success
423 * JB_ERR_MEMORY on out-of-memory error.
425 *********************************************************************/
426 jb_err cgi_send_banner(struct client_state *csp,
427 struct http_response *rsp,
428 const struct map *parameters)
430 char imagetype = lookup(parameters, "type")[0];
432 if (imagetype == 'a') /* auto */
434 /* Default to pattern */
436 #ifdef FEATURE_IMAGE_BLOCKING
437 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
439 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
440 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
442 /* determine HOW images should be blocked */
443 const char * p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
445 /* and handle accordingly: */
448 /* Use default - nothing to do here. */
450 else if (0 == strcmpic(p, "blank"))
454 else if (0 == strcmpic(p, "pattern"))
458 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
460 imagetype = p[sizeof(prefix1) - 1];
462 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
464 imagetype = p[sizeof(prefix2) - 1];
467 #endif /* def FEATURE_IMAGE_BLOCKING */
470 if ((imagetype == 'b') || (imagetype == 't')) /* blank / transparent */
472 rsp->body = bindup(image_blank_data, image_blank_length);
473 rsp->content_length = image_blank_length;
478 rsp->body = bindup(image_pattern_data, image_pattern_length);
479 rsp->content_length = image_pattern_length;
482 if (rsp->body == NULL)
484 return JB_ERR_MEMORY;
487 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
489 return JB_ERR_MEMORY;
499 /*********************************************************************
501 * Function : cgi_transparent_image
503 * Description : CGI function that sends a 1x1 transparent image.
506 * 1 : csp = Current client state (buffers, headers, etc...)
507 * 2 : rsp = http_response data structure for output
508 * 3 : parameters = map of cgi parameters
510 * CGI Parameters : None
512 * Returns : JB_ERR_OK on success
513 * JB_ERR_MEMORY on out-of-memory error.
515 *********************************************************************/
516 jb_err cgi_transparent_image(struct client_state *csp,
517 struct http_response *rsp,
518 const struct map *parameters)
520 rsp->body = bindup(image_blank_data, image_blank_length);
521 rsp->content_length = image_blank_length;
523 if (rsp->body == NULL)
525 return JB_ERR_MEMORY;
528 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
530 return JB_ERR_MEMORY;
540 /*********************************************************************
542 * Function : cgi_send_stylesheet
544 * Description : CGI function that sends a css stylesheet found
545 * in the cgi-style.css template
548 * 1 : csp = Current client state (buffers, headers, etc...)
549 * 2 : rsp = http_response data structure for output
550 * 3 : parameters = map of cgi parameters
552 * CGI Parameters : None
554 * Returns : JB_ERR_OK on success
555 * JB_ERR_MEMORY on out-of-memory error.
557 *********************************************************************/
558 jb_err cgi_send_stylesheet(struct client_state *csp,
559 struct http_response *rsp,
560 const struct map *parameters)
567 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
569 if (err == JB_ERR_FILE)
572 * No way to tell user; send empty stylesheet
574 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
578 return err; /* JB_ERR_MEMORY */
581 if (enlist(rsp->headers, "Content-Type: text/css"))
583 return JB_ERR_MEMORY;
591 /*********************************************************************
593 * Function : cgi_show_version
595 * Description : CGI function that returns a a web page describing the
596 * file versions of Privoxy.
599 * 1 : csp = Current client state (buffers, headers, etc...)
600 * 2 : rsp = http_response data structure for output
601 * 3 : parameters = map of cgi parameters
603 * CGI Parameters : none
605 * Returns : JB_ERR_OK on success
606 * JB_ERR_MEMORY on out-of-memory error.
608 *********************************************************************/
609 jb_err cgi_show_version(struct client_state *csp,
610 struct http_response *rsp,
611 const struct map *parameters)
619 if (NULL == (exports = default_exports(csp, "show-version")))
621 return JB_ERR_MEMORY;
624 if (map(exports, "sourceversions", 1, show_rcs(), 0))
627 return JB_ERR_MEMORY;
630 return template_fill_for_cgi(csp, "show-version", exports, rsp);
634 /*********************************************************************
636 * Function : cgi_show_status
638 * Description : CGI function that returns a a web page describing the
639 * current status of Privoxy.
642 * 1 : csp = Current client state (buffers, headers, etc...)
643 * 2 : rsp = http_response data structure for output
644 * 3 : parameters = map of cgi parameters
647 * file : Which file to show. Only first letter is checked,
649 * - "p"ermissions (actions) file
652 * Default is to show menu and other information.
654 * Returns : JB_ERR_OK on success
655 * JB_ERR_MEMORY on out-of-memory error.
657 *********************************************************************/
658 jb_err cgi_show_status(struct client_state *csp,
659 struct http_response *rsp,
660 const struct map *parameters)
667 char buf[BUFFER_SIZE];
668 const char * filename = NULL;
669 char * file_description = NULL;
670 #ifdef FEATURE_STATISTICS
671 float perc_rej; /* Percentage of http requests rejected */
673 int local_urls_rejected;
674 #endif /* ndef FEATURE_STATISTICS */
675 struct file_list * fl;
676 struct url_actions * b;
677 jb_err err = JB_ERR_OK;
685 if (NULL == (exports = default_exports(csp, "show-status")))
687 return JB_ERR_MEMORY;
690 switch (*(lookup(parameters, "file")))
693 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_ACTION_FILES && csp->actions_list[i])
695 filename = csp->actions_list[i]->filename;
696 file_description = "Actions File";
703 filename = csp->rlist->filename;
704 file_description = "Filter File";
712 filename = csp->tlist->filename;
713 file_description = "Trust File";
716 #endif /* def FEATURE_TRUST */
719 if (NULL != filename)
721 if ( map(exports, "file-description", 1, file_description, 1)
722 || map(exports, "filepath", 1, html_encode(filename), 0) )
725 return JB_ERR_MEMORY;
728 if ((fp = fopen(filename, "r")) == NULL)
730 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
733 return JB_ERR_MEMORY;
739 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
741 string_join (&s, html_encode(buf));
745 if (map(exports, "contents", 1, s, 0))
748 return JB_ERR_MEMORY;
752 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
756 for (j = 0; (s != NULL) && (j < Argc); j++)
758 if (!err) err = string_join (&s, html_encode(Argv[j]));
759 if (!err) err = string_append(&s, " ");
761 if (!err) err = map(exports, "invocation", 1, s, 0);
763 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
764 if (!err) err = show_defines(exports);
769 return JB_ERR_MEMORY;
772 #ifdef FEATURE_STATISTICS
773 local_urls_read = urls_read;
774 local_urls_rejected = urls_rejected;
777 * Need to alter the stats not to include the fetch of this
780 * Can't do following thread safely! doh!
783 * urls_rejected--; * This will be incremented subsequently *
786 if (local_urls_read == 0)
788 if (!err) err = map_block_killer(exports, "have-stats");
792 if (!err) err = map_block_killer(exports, "have-no-stats");
794 perc_rej = (float)local_urls_rejected * 100.0F /
795 (float)local_urls_read;
797 sprintf(buf, "%d", local_urls_read);
798 if (!err) err = map(exports, "requests-received", 1, buf, 1);
800 sprintf(buf, "%d", local_urls_rejected);
801 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
803 sprintf(buf, "%6.2f", perc_rej);
804 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
807 #else /* ndef FEATURE_STATISTICS */
808 err = err || map_block_killer(exports, "statistics");
809 #endif /* ndef FEATURE_STATISTICS */
812 * List all action files in use, together with view and edit links,
813 * except for standard.action, which should only be viewable. (Not
814 * enforced in the editor itself)
815 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
818 for (i = 0; i < MAX_ACTION_FILES; i++)
820 if (((fl = csp->actions_list[i]) != NULL) && ((b = fl->f) != NULL))
822 if (!err) err = string_append(&s, "<tr><td>");
823 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
824 snprintf(buf, 100, "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a> ", i);
825 if (!err) err = string_append(&s, buf);
827 if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
829 snprintf(buf, 100, "<a href=\"/edit-actions-list?f=%s\">Edit</a>", csp->config->actions_file_short[i]);
830 if (!err) err = string_append(&s, buf);
833 if (!err) err = string_append(&s, "</td></tr>\n");
838 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
842 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
847 if (!err) err = map(exports, "re-filter-filename", 1, html_encode(csp->rlist->filename), 0);
851 if (!err) err = map(exports, "re-filter-filename", 1, "None specified", 1);
852 if (!err) err = map_block_killer(exports, "have-filterfile");
858 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
862 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
863 if (!err) err = map_block_killer(exports, "have-trustfile");
866 if (!err) err = map_block_killer(exports, "trust-support");
867 #endif /* ndef FEATURE_TRUST */
872 return JB_ERR_MEMORY;
875 return template_fill_for_cgi(csp, "show-status", exports, rsp);
879 /*********************************************************************
881 * Function : cgi_show_url_info
883 * Description : CGI function that determines and shows which actions
884 * Privoxy will perform for a given url, and which
885 * matches starting from the defaults have lead to that.
888 * 1 : csp = Current client state (buffers, headers, etc...)
889 * 2 : rsp = http_response data structure for output
890 * 3 : parameters = map of cgi parameters
893 * url : The url whose actions are to be determined.
894 * If url is unset, the url-given conditional will be
895 * set, so that all but the form can be suppressed in
898 * Returns : JB_ERR_OK on success
899 * JB_ERR_MEMORY on out-of-memory error.
901 *********************************************************************/
902 jb_err cgi_show_url_info(struct client_state *csp,
903 struct http_response *rsp,
904 const struct map *parameters)
914 if (NULL == (exports = default_exports(csp, "show-url-info")))
916 return JB_ERR_MEMORY;
920 * Get the url= parameter (if present) and remove any leading/trailing spaces.
922 url_param = strdup(lookup(parameters, "url"));
923 if (url_param == NULL)
926 return JB_ERR_MEMORY;
931 * Handle prefixes. 4 possibilities:
932 * 1) "http://" or "https://" prefix present and followed by URL - OK
933 * 2) Only the "http://" or "https://" part is present, no URL - change
934 * to empty string so it will be detected later as "no URL".
935 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
937 * 4) Parameter not specified or is empty string - let this fall through
938 * for now, next block of code will handle it.
940 if (0 == strncmp(url_param, "http://", 7))
942 if (url_param[7] == '\0')
945 * Empty URL (just prefix).
946 * Make it totally empty so it's caught by the next if()
951 else if (0 == strncmp(url_param, "https://", 8))
953 if (url_param[8] == '\0')
956 * Empty URL (just prefix).
957 * Make it totally empty so it's caught by the next if()
962 else if (url_param[0] != '\0')
965 * Unknown prefix - assume http://
967 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
968 if (NULL == url_param_prefixed)
972 return JB_ERR_MEMORY;
974 strcpy(url_param_prefixed, "http://");
975 strcpy(url_param_prefixed + 7, url_param);
977 url_param = url_param_prefixed;
981 if (url_param[0] == '\0')
983 /* URL paramater not specified, display query form only. */
985 if (map_block_killer(exports, "url-given")
986 || map(exports, "url", 1, "", 1))
989 return JB_ERR_MEMORY;
994 /* Given a URL, so query it. */
999 struct file_list *fl;
1000 struct url_actions *b;
1001 struct http_request url_to_query[1];
1002 struct current_action_spec action[1];
1005 if (map(exports, "url", 1, html_encode(url_param), 0))
1009 return JB_ERR_MEMORY;
1012 init_current_action(action);
1014 if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1016 free_current_action(action);
1019 return JB_ERR_MEMORY;
1022 err = parse_http_url(url_param, url_to_query, csp);
1026 if (err == JB_ERR_MEMORY)
1028 free_current_action(action);
1030 return JB_ERR_MEMORY;
1036 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1037 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1039 free_current_action(action);
1044 return JB_ERR_MEMORY;
1047 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1051 * We have a warning about SSL paths. Hide it for insecure sites.
1053 if (!url_to_query->ssl)
1055 if (map_block_killer(exports, "https"))
1057 free_current_action(action);
1059 return JB_ERR_MEMORY;
1063 matches = strdup("<table class=\"transparent\">");
1065 for (i = 0; i < MAX_ACTION_FILES; i++)
1067 if (NULL == csp->config->actions_file_short[i]
1068 || !strcmp(csp->config->actions_file_short[i], "standard")) continue;
1072 if ((fl = csp->actions_list[i]) != NULL)
1074 if ((b = fl->f) != NULL)
1076 /* FIXME: Hardcoded HTML! */
1077 string_append(&matches, "<tr><th>In file: ");
1078 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1079 snprintf(buf, 150, ".action <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1080 string_append(&matches, buf);
1081 string_append(&matches, "View</a> <a class=\"cmd\" href=\"/edit-actions-list?f=");
1082 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1083 string_append(&matches, "\">Edit</a></th></tr>\n");
1090 for (; (b != NULL) && (matches != NULL); b = b->next)
1092 if (url_match(b->url, url_to_query))
1094 string_append(&matches, "<tr><td>{");
1095 string_join (&matches, actions_to_html(csp, b->action));
1096 string_append(&matches, " }</b><br>\n<code>");
1097 string_join (&matches, html_encode(b->url->spec));
1098 string_append(&matches, "</code></td></tr>\n");
1100 if (merge_current_action(action, b->action))
1103 free_http_request(url_to_query);
1104 free_current_action(action);
1106 return JB_ERR_MEMORY;
1114 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1117 string_append(&matches, "</table>\n");
1119 free_http_request(url_to_query);
1121 if (matches == NULL)
1123 free_current_action(action);
1125 return JB_ERR_MEMORY;
1128 if (map(exports, "matches", 1, matches , 0))
1130 free_current_action(action);
1132 return JB_ERR_MEMORY;
1135 s = current_action_to_html(csp, action);
1137 free_current_action(action);
1139 if (map(exports, "final", 1, s, 0))
1142 return JB_ERR_MEMORY;
1146 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1150 /*********************************************************************
1152 * Function : cgi_robots_txt
1154 * Description : CGI function to return "/robots.txt".
1157 * 1 : csp = Current client state (buffers, headers, etc...)
1158 * 2 : rsp = http_response data structure for output
1159 * 3 : parameters = map of cgi parameters
1161 * CGI Parameters : None
1163 * Returns : JB_ERR_OK on success
1164 * JB_ERR_MEMORY on out-of-memory error.
1166 *********************************************************************/
1167 jb_err cgi_robots_txt(struct client_state *csp,
1168 struct http_response *rsp,
1169 const struct map *parameters)
1175 "# This is the Privoxy control interface.\n"
1176 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1182 if (rsp->body == NULL)
1184 return JB_ERR_MEMORY;
1187 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1191 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1192 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1194 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1198 /*********************************************************************
1200 * Function : show_defines
1202 * Description : Add to a map the state od all conditional #defines
1203 * used when building
1206 * 1 : exports = map to extend
1208 * Returns : JB_ERR_OK on success
1209 * JB_ERR_MEMORY on out-of-memory error.
1211 *********************************************************************/
1212 static jb_err show_defines(struct map *exports)
1214 jb_err err = JB_ERR_OK;
1217 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1218 #else /* ifndef FEATURE_ACL */
1219 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1220 #endif /* ndef FEATURE_ACL */
1222 #ifdef FEATURE_CGI_EDIT_ACTIONS
1223 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1224 #else /* ifndef FEATURE_COOKIE_JAR */
1225 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1226 #endif /* ndef FEATURE_COOKIE_JAR */
1228 #ifdef FEATURE_COOKIE_JAR
1229 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1230 #else /* ifndef FEATURE_COOKIE_JAR */
1231 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1232 #endif /* ndef FEATURE_COOKIE_JAR */
1234 #ifdef FEATURE_FAST_REDIRECTS
1235 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1236 #else /* ifndef FEATURE_FAST_REDIRECTS */
1237 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1238 #endif /* ndef FEATURE_FAST_REDIRECTS */
1240 #ifdef FEATURE_FORCE_LOAD
1241 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1242 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1243 #else /* ifndef FEATURE_FORCE_LOAD */
1244 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1245 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1246 #endif /* ndef FEATURE_FORCE_LOAD */
1248 #ifdef FEATURE_IMAGE_BLOCKING
1249 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1250 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1251 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1252 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1254 #ifdef FEATURE_IMAGE_DETECT_MSIE
1255 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1256 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1257 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1258 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1260 #ifdef FEATURE_KILL_POPUPS
1261 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1262 #else /* ifndef FEATURE_KILL_POPUPS */
1263 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1264 #endif /* ndef FEATURE_KILL_POPUPS */
1266 #ifdef FEATURE_NO_GIFS
1267 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1268 #else /* ifndef FEATURE_NO_GIFS */
1269 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1270 #endif /* ndef FEATURE_NO_GIFS */
1272 #ifdef FEATURE_PTHREAD
1273 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1274 #else /* ifndef FEATURE_PTHREAD */
1275 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1276 #endif /* ndef FEATURE_PTHREAD */
1278 #ifdef FEATURE_STATISTICS
1279 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1280 #else /* ifndef FEATURE_STATISTICS */
1281 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1282 #endif /* ndef FEATURE_STATISTICS */
1284 #ifdef FEATURE_TOGGLE
1285 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1286 #else /* ifndef FEATURE_TOGGLE */
1287 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1288 #endif /* ndef FEATURE_TOGGLE */
1290 #ifdef FEATURE_TRUST
1291 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1292 #else /* ifndef FEATURE_TRUST */
1293 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1294 #endif /* ndef FEATURE_TRUST */
1297 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1298 #else /* ifndef STATIC_PCRE */
1299 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1300 #endif /* ndef STATIC_PCRE */
1303 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1304 #else /* ifndef STATIC_PCRS */
1305 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1306 #endif /* ndef STATIC_PCRS */
1312 /*********************************************************************
1314 * Function : show_rcs
1316 * Description : Create a string with the rcs info for all sourcefiles
1320 * Returns : A string, or NULL on out-of-memory.
1322 *********************************************************************/
1323 static char *show_rcs(void)
1325 char *result = strdup("");
1326 char buf[BUFFER_SIZE];
1328 /* Instead of including *all* dot h's in the project (thus creating a
1329 * tremendous amount of dependencies), I will concede to declaring them
1330 * as extern's. This forces the developer to add to this list, but oh well.
1333 #define SHOW_RCS(__x) \
1335 extern const char __x[]; \
1336 sprintf(buf, "%s\n", __x); \
1337 string_append(&result, buf); \
1340 /* In alphabetical order */
1341 SHOW_RCS(actions_h_rcs)
1342 SHOW_RCS(actions_rcs)
1344 SHOW_RCS(amiga_h_rcs)
1346 #endif /* def AMIGA */
1349 #ifdef FEATURE_CGI_EDIT_ACTIONS
1350 SHOW_RCS(cgiedit_h_rcs)
1351 SHOW_RCS(cgiedit_rcs)
1352 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1353 SHOW_RCS(cgisimple_h_rcs)
1354 SHOW_RCS(cgisimple_rcs)
1356 SHOW_RCS(cygwin_h_rcs)
1358 SHOW_RCS(deanimate_h_rcs)
1359 SHOW_RCS(deanimate_rcs)
1360 SHOW_RCS(encode_h_rcs)
1361 SHOW_RCS(encode_rcs)
1362 SHOW_RCS(errlog_h_rcs)
1363 SHOW_RCS(errlog_rcs)
1364 SHOW_RCS(filters_h_rcs)
1365 SHOW_RCS(filters_rcs)
1366 SHOW_RCS(gateway_h_rcs)
1367 SHOW_RCS(gateway_rcs)
1368 SHOW_RCS(jbsockets_h_rcs)
1369 SHOW_RCS(jbsockets_rcs)
1372 #ifdef FEATURE_KILL_POPUPS
1373 SHOW_RCS(killpopup_h_rcs)
1374 SHOW_RCS(killpopup_rcs)
1375 #endif /* def FEATURE_KILL_POPUPS */
1376 SHOW_RCS(list_h_rcs)
1378 SHOW_RCS(loadcfg_h_rcs)
1379 SHOW_RCS(loadcfg_rcs)
1380 SHOW_RCS(loaders_h_rcs)
1381 SHOW_RCS(loaders_rcs)
1382 SHOW_RCS(miscutil_h_rcs)
1383 SHOW_RCS(miscutil_rcs)
1384 SHOW_RCS(parsers_h_rcs)
1385 SHOW_RCS(parsers_rcs)
1387 SHOW_RCS(pcrs_h_rcs)
1388 SHOW_RCS(project_h_rcs)
1389 SHOW_RCS(ssplit_h_rcs)
1390 SHOW_RCS(ssplit_rcs)
1391 SHOW_RCS(urlmatch_h_rcs)
1392 SHOW_RCS(urlmatch_rcs)
1394 #ifndef _WIN_CONSOLE
1395 SHOW_RCS(w32log_h_rcs)
1396 SHOW_RCS(w32log_rcs)
1397 SHOW_RCS(w32res_h_rcs)
1398 SHOW_RCS(w32taskbar_h_rcs)
1399 SHOW_RCS(w32taskbar_rcs)
1400 #endif /* ndef _WIN_CONSOLE */
1401 SHOW_RCS(win32_h_rcs)
1403 #endif /* def _WIN32 */