1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.32 2002/04/26 18:29:13 jongfoster 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.32 2002/04/26 18:29:13 jongfoster
40 * Fixing this Visual C++ warning:
41 * cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
43 * Revision 1.31 2002/04/26 12:54:36 oes
44 * - Kill obsolete REDIRECT_URL code
45 * - Error handling fixes
46 * - Style sheet related HTML snipplet changes
47 * - cgi_show_url_info:
48 * - Matches now in table, actions on single lines,
50 * - standard.action suppressed
51 * - Buttons to View and Edit AFs
53 * Revision 1.30 2002/04/24 02:18:08 oes
54 * - show-status is now the starting point for editing
55 * the actions files, generate list of all AFs with buttons
56 * for viewing and editing, new look for file list (Jon:
57 * buttons now aligned ;-P ), view mode now supports multiple
58 * AFs, name changes, no view links for unspecified files,
59 * no edit link for standard.action.
61 * - Jon's multiple AF patch: cgi_show_url_info now uses all
62 * AFs and marks the output accordingly
64 * Revision 1.29 2002/04/10 13:38:35 oes
65 * load_template signature changed
67 * Revision 1.28 2002/04/07 15:42:12 jongfoster
68 * Fixing send-banner?type=auto when the image-blocker is
69 * a redirect to send-banner
71 * Revision 1.27 2002/04/05 15:50:48 oes
72 * added send-stylesheet CGI
74 * Revision 1.26 2002/04/04 00:36:36 gliptak
75 * always use pcre for matching
77 * Revision 1.25 2002/04/03 22:28:03 gliptak
78 * Removed references to gnu_regex
80 * Revision 1.24 2002/04/02 16:12:47 oes
81 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
83 * Revision 1.23 2002/03/26 22:29:54 swa
84 * we have a new homepage!
86 * Revision 1.22 2002/03/24 16:18:15 jongfoster
89 * Revision 1.21 2002/03/24 15:23:33 jongfoster
92 * Revision 1.20 2002/03/24 13:25:43 swa
93 * name change related issues
95 * Revision 1.19 2002/03/16 23:54:06 jongfoster
96 * Adding graceful termination feature, to help look for memory leaks.
97 * If you enable this (which, by design, has to be done by hand
98 * editing config.h) and then go to http://i.j.b/die, then the program
99 * will exit cleanly after the *next* request. It should free all the
100 * memory that was used.
102 * Revision 1.18 2002/03/12 01:44:49 oes
103 * Changed default for "blocked" image from jb logo to checkboard pattern
105 * Revision 1.17 2002/03/08 16:43:18 oes
106 * Added choice beween GIF and PNG built-in images
108 * Revision 1.16 2002/03/07 03:48:38 oes
109 * - Changed built-in images from GIF to PNG
110 * (with regard to Unisys patent issue)
111 * - Added a 4x4 pattern PNG which is less intrusive
112 * than the logo but also clearly marks the deleted banners
114 * Revision 1.15 2002/03/06 22:54:35 jongfoster
115 * Automated function-comment nitpicking.
117 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
118 * Clean up a little CRLF unpleasantness that suddenly appeared
120 * Revision 1.13 2002/02/21 00:10:37 jongfoster
121 * Adding send-banner?type=auto option
123 * Revision 1.12 2002/01/23 01:03:32 jongfoster
124 * Fixing gcc [CygWin] compiler warnings
126 * Revision 1.11 2002/01/23 00:01:04 jongfoster
127 * Adding cgi_transparent_gif() for http://i.j.b/t
128 * Adding missing html_encode() to many CGI functions.
129 * Adding urlmatch.[ch] to http://i.j.b/show-version
131 * Revision 1.10 2002/01/17 21:10:37 jongfoster
132 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
133 * Also fixing a problem in the same function with improperly quoted URLs
134 * in output HTML, and adding code to handle https:// URLs correctly.
136 * Revision 1.9 2001/11/30 23:09:15 jongfoster
137 * Now reports on FEATURE_CGI_EDIT_ACTIONS
138 * Removing FEATURE_DENY_GZIP from template
140 * Revision 1.8 2001/11/13 00:14:07 jongfoster
141 * Fixing stupid bug now I've figured out what || means.
142 * (It always returns 0 or 1, not one of it's paramaters.)
144 * Revision 1.7 2001/10/23 21:48:19 jongfoster
145 * Cleaning up error handling in CGI functions - they now send back
146 * a HTML error page and should never cause a FATAL error. (Fixes one
147 * potential source of "denial of service" attacks).
149 * CGI actions file editor that works and is actually useful.
151 * Ability to toggle JunkBuster remotely using a CGI call.
153 * You can turn off both the above features in the main configuration
154 * file, e.g. if you are running a multi-user proxy.
156 * Revision 1.6 2001/10/14 22:00:32 jongfoster
157 * Adding support for a 404 error when an invalid CGI page is requested.
159 * Revision 1.5 2001/10/07 15:30:41 oes
160 * Removed FEATURE_DENY_GZIP
162 * Revision 1.4 2001/10/02 15:31:12 oes
163 * Introduced show-request cgi
165 * Revision 1.3 2001/09/22 16:34:44 jongfoster
166 * Removing unneeded #includes
168 * Revision 1.2 2001/09/19 18:01:11 oes
169 * Fixed comments; cosmetics
171 * Revision 1.1 2001/09/16 17:08:54 jongfoster
172 * Moving simple CGI functions from cgi.c to new file cgisimple.c
175 **********************************************************************/
181 #include <sys/types.h>
188 #define snprintf _snprintf
189 #endif /* def _WIN32 */
193 #include "cgisimple.h"
199 #include "miscutil.h"
202 #include "urlmatch.h"
205 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
208 static char *show_rcs(void);
209 static jb_err show_defines(struct map *exports);
212 /*********************************************************************
214 * Function : cgi_default
216 * Description : CGI function that is called if no action was given.
217 * Lists menu of available unhidden CGIs.
220 * 1 : csp = Current client state (buffers, headers, etc...)
221 * 2 : rsp = http_response data structure for output
222 * 3 : parameters = map of cgi parameters
224 * CGI Parameters : none
226 * Returns : JB_ERR_OK on success
227 * JB_ERR_MEMORY on out-of-memory
228 * (Problems other than out-of-memory should be
229 * handled by this routine - it should set the
230 * rsp appropriately and return "success")
232 *********************************************************************/
233 jb_err cgi_default(struct client_state *csp,
234 struct http_response *rsp,
235 const struct map *parameters)
244 if (NULL == (exports = default_exports(csp, "")))
246 return JB_ERR_MEMORY;
249 /* If there were other parameters, export a dump as "cgi-parameters" */
250 if (parameters->first)
252 tmp = strdup("<p>What made you think this cgi takes parameters?\n"
253 "Anyway, here they are, in case you're interested:</p>\n");
254 string_join(&tmp, dump_map(parameters));
258 return JB_ERR_MEMORY;
260 if (map(exports, "cgi-parameters", 1, tmp, 0))
262 return JB_ERR_MEMORY;
267 if (map(exports, "cgi-parameters", 1, "", 1))
269 return JB_ERR_MEMORY;
273 return template_fill_for_cgi(csp, "default", exports, rsp);
279 /*********************************************************************
281 * Function : cgi_error_404
283 * Description : CGI function that is called if an unknown action was
287 * 1 : csp = Current client state (buffers, headers, etc...)
288 * 2 : rsp = http_response data structure for output
289 * 3 : parameters = map of cgi parameters
291 * CGI Parameters : none
293 * Returns : JB_ERR_OK on success
294 * JB_ERR_MEMORY on out-of-memory error.
296 *********************************************************************/
297 jb_err cgi_error_404(struct client_state *csp,
298 struct http_response *rsp,
299 const struct map *parameters)
307 if (NULL == (exports = default_exports(csp, NULL)))
309 return JB_ERR_MEMORY;
312 rsp->status = strdup("404 Privoxy configuration page not found");
313 if (rsp->status == NULL)
316 return JB_ERR_MEMORY;
319 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
323 #ifdef FEATURE_GRACEFUL_TERMINATION
324 /*********************************************************************
328 * Description : CGI function to shut down Privoxy.
329 * NOTE: Turning this on in a production build
330 * would be a BAD idea. An EXTREMELY BAD idea.
331 * In short, don't do it.
334 * 1 : csp = Current client state (buffers, headers, etc...)
335 * 2 : rsp = http_response data structure for output
336 * 3 : parameters = map of cgi parameters
338 * CGI Parameters : none
340 * Returns : JB_ERR_OK on success
341 * JB_ERR_MEMORY on out-of-memory error.
343 *********************************************************************/
344 jb_err cgi_die (struct client_state *csp,
345 struct http_response *rsp,
346 const struct map *parameters)
356 * I don't really care what gets sent back to the browser.
357 * Take the easy option - "out of memory" page.
360 return JB_ERR_MEMORY;
362 #endif /* def FEATURE_GRACEFUL_TERMINATION */
365 /*********************************************************************
367 * Function : cgi_show_request
369 * Description : Show the client's request and what sed() would have
373 * 1 : csp = Current client state (buffers, headers, etc...)
374 * 2 : rsp = http_response data structure for output
375 * 3 : parameters = map of cgi parameters
377 * CGI Parameters : none
379 * Returns : JB_ERR_OK on success
380 * JB_ERR_MEMORY on out-of-memory error.
382 *********************************************************************/
383 jb_err cgi_show_request(struct client_state *csp,
384 struct http_response *rsp,
385 const struct map *parameters)
394 if (NULL == (exports = default_exports(csp, "show-request")))
396 return JB_ERR_MEMORY;
400 * Repair the damage done to the IOB by get_header()
402 for (p = csp->iob->buf; p < csp->iob->eod; p++)
404 if (*p == '\0') *p = '\n';
408 * Export the original client's request and the one we would
409 * be sending to the server if this wasn't a CGI call
412 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
415 return JB_ERR_MEMORY;
418 if (map(exports, "processed-request", 1, html_encode_and_free_original(
419 sed(client_patterns, add_client_headers, csp)), 0))
422 return JB_ERR_MEMORY;
425 return template_fill_for_cgi(csp, "show-request", exports, rsp);
429 /*********************************************************************
431 * Function : cgi_send_banner
433 * Description : CGI function that returns a banner.
436 * 1 : csp = Current client state (buffers, headers, etc...)
437 * 2 : rsp = http_response data structure for output
438 * 3 : parameters = map of cgi parameters
441 * type : Selects the type of banner between "trans", "logo",
442 * and "auto". Defaults to "logo" if absent or invalid.
443 * "auto" means to select as if we were image-blocking.
444 * (Only the first character really counts).
446 * Returns : JB_ERR_OK on success
447 * JB_ERR_MEMORY on out-of-memory error.
449 *********************************************************************/
450 jb_err cgi_send_banner(struct client_state *csp,
451 struct http_response *rsp,
452 const struct map *parameters)
454 char imagetype = lookup(parameters, "type")[0];
456 if (imagetype == 'a') /* auto */
458 /* Default to pattern */
460 #ifdef FEATURE_IMAGE_BLOCKING
461 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
463 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
464 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
466 /* determine HOW images should be blocked */
467 const char * p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
469 /* and handle accordingly: */
472 /* Use default - nothing to do here. */
474 else if (0 == strcmpic(p, "blank"))
478 else if (0 == strcmpic(p, "pattern"))
482 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
484 imagetype = p[sizeof(prefix1) - 1];
486 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
488 imagetype = p[sizeof(prefix2) - 1];
491 #endif /* def FEATURE_IMAGE_BLOCKING */
494 if ((imagetype == 'b') || (imagetype == 't')) /* blank / transparent */
496 rsp->body = bindup(image_blank_data, image_blank_length);
497 rsp->content_length = image_blank_length;
502 rsp->body = bindup(image_pattern_data, image_pattern_length);
503 rsp->content_length = image_pattern_length;
506 if (rsp->body == NULL)
508 return JB_ERR_MEMORY;
511 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
513 return JB_ERR_MEMORY;
523 /*********************************************************************
525 * Function : cgi_transparent_image
527 * Description : CGI function that sends a 1x1 transparent image.
530 * 1 : csp = Current client state (buffers, headers, etc...)
531 * 2 : rsp = http_response data structure for output
532 * 3 : parameters = map of cgi parameters
534 * CGI Parameters : None
536 * Returns : JB_ERR_OK on success
537 * JB_ERR_MEMORY on out-of-memory error.
539 *********************************************************************/
540 jb_err cgi_transparent_image(struct client_state *csp,
541 struct http_response *rsp,
542 const struct map *parameters)
544 rsp->body = bindup(image_blank_data, image_blank_length);
545 rsp->content_length = image_blank_length;
547 if (rsp->body == NULL)
549 return JB_ERR_MEMORY;
552 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
554 return JB_ERR_MEMORY;
564 /*********************************************************************
566 * Function : cgi_send_stylesheet
568 * Description : CGI function that sends a css stylesheet found
569 * in the cgi-style.css template
572 * 1 : csp = Current client state (buffers, headers, etc...)
573 * 2 : rsp = http_response data structure for output
574 * 3 : parameters = map of cgi parameters
576 * CGI Parameters : None
578 * Returns : JB_ERR_OK on success
579 * JB_ERR_MEMORY on out-of-memory error.
581 *********************************************************************/
582 jb_err cgi_send_stylesheet(struct client_state *csp,
583 struct http_response *rsp,
584 const struct map *parameters)
591 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
593 if (err == JB_ERR_FILE)
596 * No way to tell user; send empty stylesheet
598 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
602 return err; /* JB_ERR_MEMORY */
605 if (enlist(rsp->headers, "Content-Type: text/css"))
607 return JB_ERR_MEMORY;
615 /*********************************************************************
617 * Function : cgi_show_version
619 * Description : CGI function that returns a a web page describing the
620 * file versions of Privoxy.
623 * 1 : csp = Current client state (buffers, headers, etc...)
624 * 2 : rsp = http_response data structure for output
625 * 3 : parameters = map of cgi parameters
627 * CGI Parameters : none
629 * Returns : JB_ERR_OK on success
630 * JB_ERR_MEMORY on out-of-memory error.
632 *********************************************************************/
633 jb_err cgi_show_version(struct client_state *csp,
634 struct http_response *rsp,
635 const struct map *parameters)
643 if (NULL == (exports = default_exports(csp, "show-version")))
645 return JB_ERR_MEMORY;
648 if (map(exports, "sourceversions", 1, show_rcs(), 0))
651 return JB_ERR_MEMORY;
654 return template_fill_for_cgi(csp, "show-version", exports, rsp);
658 /*********************************************************************
660 * Function : cgi_show_status
662 * Description : CGI function that returns a a web page describing the
663 * current status of Privoxy.
666 * 1 : csp = Current client state (buffers, headers, etc...)
667 * 2 : rsp = http_response data structure for output
668 * 3 : parameters = map of cgi parameters
671 * file : Which file to show. Only first letter is checked,
673 * - "p"ermissions (actions) file
676 * Default is to show menu and other information.
678 * Returns : JB_ERR_OK on success
679 * JB_ERR_MEMORY on out-of-memory error.
681 *********************************************************************/
682 jb_err cgi_show_status(struct client_state *csp,
683 struct http_response *rsp,
684 const struct map *parameters)
691 char buf[BUFFER_SIZE];
692 const char * filename = NULL;
693 char * file_description = NULL;
694 #ifdef FEATURE_STATISTICS
695 float perc_rej; /* Percentage of http requests rejected */
697 int local_urls_rejected;
698 #endif /* ndef FEATURE_STATISTICS */
699 struct file_list * fl;
700 struct url_actions * b;
701 jb_err err = JB_ERR_OK;
709 if (NULL == (exports = default_exports(csp, "show-status")))
711 return JB_ERR_MEMORY;
714 switch (*(lookup(parameters, "file")))
717 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_ACTION_FILES && csp->actions_list[i])
719 filename = csp->actions_list[i]->filename;
720 file_description = "Actions File";
727 filename = csp->rlist->filename;
728 file_description = "Filter File";
736 filename = csp->tlist->filename;
737 file_description = "Trust File";
740 #endif /* def FEATURE_TRUST */
743 if (NULL != filename)
745 if ( map(exports, "file-description", 1, file_description, 1)
746 || map(exports, "filepath", 1, html_encode(filename), 0) )
749 return JB_ERR_MEMORY;
752 if ((fp = fopen(filename, "r")) == NULL)
754 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
757 return JB_ERR_MEMORY;
763 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
765 string_join (&s, html_encode(buf));
769 if (map(exports, "contents", 1, s, 0))
772 return JB_ERR_MEMORY;
776 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
780 for (j = 0; (s != NULL) && (j < Argc); j++)
782 if (!err) err = string_join (&s, html_encode(Argv[j]));
783 if (!err) err = string_append(&s, " ");
785 if (!err) err = map(exports, "invocation", 1, s, 0);
787 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
788 if (!err) err = show_defines(exports);
793 return JB_ERR_MEMORY;
796 #ifdef FEATURE_STATISTICS
797 local_urls_read = urls_read;
798 local_urls_rejected = urls_rejected;
801 * Need to alter the stats not to include the fetch of this
804 * Can't do following thread safely! doh!
807 * urls_rejected--; * This will be incremented subsequently *
810 if (local_urls_read == 0)
812 if (!err) err = map_block_killer(exports, "have-stats");
816 if (!err) err = map_block_killer(exports, "have-no-stats");
818 perc_rej = (float)local_urls_rejected * 100.0F /
819 (float)local_urls_read;
821 sprintf(buf, "%d", local_urls_read);
822 if (!err) err = map(exports, "requests-received", 1, buf, 1);
824 sprintf(buf, "%d", local_urls_rejected);
825 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
827 sprintf(buf, "%6.2f", perc_rej);
828 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
831 #else /* ndef FEATURE_STATISTICS */
832 err = err || map_block_killer(exports, "statistics");
833 #endif /* ndef FEATURE_STATISTICS */
836 * List all action files in use, together with view and edit links,
837 * except for standard.action, which should only be viewable. (Not
838 * enforced in the editor itself)
839 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
842 for (i = 0; i < MAX_ACTION_FILES; i++)
844 if (((fl = csp->actions_list[i]) != NULL) && ((b = fl->f) != NULL))
846 if (!err) err = string_append(&s, "<tr><td>");
847 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
848 snprintf(buf, 100, "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a> ", i);
849 if (!err) err = string_append(&s, buf);
851 if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
853 snprintf(buf, 100, "<a href=\"/edit-actions-list?f=%s\">Edit</a>", csp->config->actions_file_short[i]);
854 if (!err) err = string_append(&s, buf);
857 if (!err) err = string_append(&s, "</td></tr>\n");
862 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
866 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
871 if (!err) err = map(exports, "re-filter-filename", 1, html_encode(csp->rlist->filename), 0);
875 if (!err) err = map(exports, "re-filter-filename", 1, "None specified", 1);
876 if (!err) err = map_block_killer(exports, "have-filterfile");
882 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
886 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
887 if (!err) err = map_block_killer(exports, "have-trustfile");
890 if (!err) err = map_block_killer(exports, "trust-support");
891 #endif /* ndef FEATURE_TRUST */
896 return JB_ERR_MEMORY;
899 return template_fill_for_cgi(csp, "show-status", exports, rsp);
903 /*********************************************************************
905 * Function : cgi_show_url_info
907 * Description : CGI function that determines and shows which actions
908 * Privoxy will perform for a given url, and which
909 * matches starting from the defaults have lead to that.
912 * 1 : csp = Current client state (buffers, headers, etc...)
913 * 2 : rsp = http_response data structure for output
914 * 3 : parameters = map of cgi parameters
917 * url : The url whose actions are to be determined.
918 * If url is unset, the url-given conditional will be
919 * set, so that all but the form can be suppressed in
922 * Returns : JB_ERR_OK on success
923 * JB_ERR_MEMORY on out-of-memory error.
925 *********************************************************************/
926 jb_err cgi_show_url_info(struct client_state *csp,
927 struct http_response *rsp,
928 const struct map *parameters)
938 if (NULL == (exports = default_exports(csp, "show-url-info")))
940 return JB_ERR_MEMORY;
944 * Get the url= parameter (if present) and remove any leading/trailing spaces.
946 url_param = strdup(lookup(parameters, "url"));
947 if (url_param == NULL)
950 return JB_ERR_MEMORY;
955 * Handle prefixes. 4 possibilities:
956 * 1) "http://" or "https://" prefix present and followed by URL - OK
957 * 2) Only the "http://" or "https://" part is present, no URL - change
958 * to empty string so it will be detected later as "no URL".
959 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
961 * 4) Parameter not specified or is empty string - let this fall through
962 * for now, next block of code will handle it.
964 if (0 == strncmp(url_param, "http://", 7))
966 if (url_param[7] == '\0')
969 * Empty URL (just prefix).
970 * Make it totally empty so it's caught by the next if()
975 else if (0 == strncmp(url_param, "https://", 8))
977 if (url_param[8] == '\0')
980 * Empty URL (just prefix).
981 * Make it totally empty so it's caught by the next if()
986 else if (url_param[0] != '\0')
989 * Unknown prefix - assume http://
991 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
992 if (NULL == url_param_prefixed)
996 return JB_ERR_MEMORY;
998 strcpy(url_param_prefixed, "http://");
999 strcpy(url_param_prefixed + 7, url_param);
1001 url_param = url_param_prefixed;
1005 if (url_param[0] == '\0')
1007 /* URL paramater not specified, display query form only. */
1009 if (map_block_killer(exports, "url-given")
1010 || map(exports, "url", 1, "", 1))
1013 return JB_ERR_MEMORY;
1018 /* Given a URL, so query it. */
1023 struct file_list *fl;
1024 struct url_actions *b;
1025 struct http_request url_to_query[1];
1026 struct current_action_spec action[1];
1029 if (map(exports, "url", 1, html_encode(url_param), 0))
1033 return JB_ERR_MEMORY;
1036 init_current_action(action);
1038 if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1040 free_current_action(action);
1043 return JB_ERR_MEMORY;
1046 err = parse_http_url(url_param, url_to_query, csp);
1050 if (err == JB_ERR_MEMORY)
1052 free_current_action(action);
1054 return JB_ERR_MEMORY;
1060 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1061 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1063 free_current_action(action);
1068 return JB_ERR_MEMORY;
1071 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1075 * We have a warning about SSL paths. Hide it for insecure sites.
1077 if (!url_to_query->ssl)
1079 if (map_block_killer(exports, "https"))
1081 free_current_action(action);
1083 return JB_ERR_MEMORY;
1087 matches = strdup("<table class=\"transparent\">");
1089 for (i = 0; i < MAX_ACTION_FILES; i++)
1091 if (NULL == csp->config->actions_file_short[i]
1092 || !strcmp(csp->config->actions_file_short[i], "standard")) continue;
1096 if ((fl = csp->actions_list[i]) != NULL)
1098 if ((b = fl->f) != NULL)
1100 /* FIXME: Hardcoded HTML! */
1101 string_append(&matches, "<tr><th>In file: ");
1102 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1103 snprintf(buf, 150, ".action <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1104 string_append(&matches, buf);
1105 string_append(&matches, "View</a> <a class=\"cmd\" href=\"/edit-actions-list?f=");
1106 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1107 string_append(&matches, "\">Edit</a></th></tr>\n");
1114 for (; (b != NULL) && (matches != NULL); b = b->next)
1116 if (url_match(b->url, url_to_query))
1118 string_append(&matches, "<tr><td>{");
1119 string_join (&matches, actions_to_html(csp, b->action));
1120 string_append(&matches, " }</b><br>\n<code>");
1121 string_join (&matches, html_encode(b->url->spec));
1122 string_append(&matches, "</code></td></tr>\n");
1124 if (merge_current_action(action, b->action))
1127 free_http_request(url_to_query);
1128 free_current_action(action);
1130 return JB_ERR_MEMORY;
1138 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1141 string_append(&matches, "</table>\n");
1143 free_http_request(url_to_query);
1145 if (matches == NULL)
1147 free_current_action(action);
1149 return JB_ERR_MEMORY;
1152 if (map(exports, "matches", 1, matches , 0))
1154 free_current_action(action);
1156 return JB_ERR_MEMORY;
1159 s = current_action_to_html(csp, action);
1161 free_current_action(action);
1163 if (map(exports, "final", 1, s, 0))
1166 return JB_ERR_MEMORY;
1170 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1174 /*********************************************************************
1176 * Function : cgi_robots_txt
1178 * Description : CGI function to return "/robots.txt".
1181 * 1 : csp = Current client state (buffers, headers, etc...)
1182 * 2 : rsp = http_response data structure for output
1183 * 3 : parameters = map of cgi parameters
1185 * CGI Parameters : None
1187 * Returns : JB_ERR_OK on success
1188 * JB_ERR_MEMORY on out-of-memory error.
1190 *********************************************************************/
1191 jb_err cgi_robots_txt(struct client_state *csp,
1192 struct http_response *rsp,
1193 const struct map *parameters)
1199 "# This is the Privoxy control interface.\n"
1200 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1206 if (rsp->body == NULL)
1208 return JB_ERR_MEMORY;
1211 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1215 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1216 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1218 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1222 /*********************************************************************
1224 * Function : show_defines
1226 * Description : Add to a map the state od all conditional #defines
1227 * used when building
1230 * 1 : exports = map to extend
1232 * Returns : JB_ERR_OK on success
1233 * JB_ERR_MEMORY on out-of-memory error.
1235 *********************************************************************/
1236 static jb_err show_defines(struct map *exports)
1238 jb_err err = JB_ERR_OK;
1241 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1242 #else /* ifndef FEATURE_ACL */
1243 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1244 #endif /* ndef FEATURE_ACL */
1246 #ifdef FEATURE_CGI_EDIT_ACTIONS
1247 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1248 #else /* ifndef FEATURE_COOKIE_JAR */
1249 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1250 #endif /* ndef FEATURE_COOKIE_JAR */
1252 #ifdef FEATURE_COOKIE_JAR
1253 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1254 #else /* ifndef FEATURE_COOKIE_JAR */
1255 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1256 #endif /* ndef FEATURE_COOKIE_JAR */
1258 #ifdef FEATURE_FAST_REDIRECTS
1259 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1260 #else /* ifndef FEATURE_FAST_REDIRECTS */
1261 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1262 #endif /* ndef FEATURE_FAST_REDIRECTS */
1264 #ifdef FEATURE_FORCE_LOAD
1265 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1266 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1267 #else /* ifndef FEATURE_FORCE_LOAD */
1268 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1269 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1270 #endif /* ndef FEATURE_FORCE_LOAD */
1272 #ifdef FEATURE_IMAGE_BLOCKING
1273 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1274 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1275 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1276 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1278 #ifdef FEATURE_IMAGE_DETECT_MSIE
1279 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1280 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1281 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1282 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1284 #ifdef FEATURE_KILL_POPUPS
1285 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1286 #else /* ifndef FEATURE_KILL_POPUPS */
1287 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1288 #endif /* ndef FEATURE_KILL_POPUPS */
1290 #ifdef FEATURE_NO_GIFS
1291 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1292 #else /* ifndef FEATURE_NO_GIFS */
1293 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1294 #endif /* ndef FEATURE_NO_GIFS */
1296 #ifdef FEATURE_PTHREAD
1297 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1298 #else /* ifndef FEATURE_PTHREAD */
1299 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1300 #endif /* ndef FEATURE_PTHREAD */
1302 #ifdef FEATURE_STATISTICS
1303 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1304 #else /* ifndef FEATURE_STATISTICS */
1305 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1306 #endif /* ndef FEATURE_STATISTICS */
1308 #ifdef FEATURE_TOGGLE
1309 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1310 #else /* ifndef FEATURE_TOGGLE */
1311 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1312 #endif /* ndef FEATURE_TOGGLE */
1314 #ifdef FEATURE_TRUST
1315 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1316 #else /* ifndef FEATURE_TRUST */
1317 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1318 #endif /* ndef FEATURE_TRUST */
1321 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1322 #else /* ifndef STATIC_PCRE */
1323 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1324 #endif /* ndef STATIC_PCRE */
1327 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1328 #else /* ifndef STATIC_PCRS */
1329 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1330 #endif /* ndef STATIC_PCRS */
1336 /*********************************************************************
1338 * Function : show_rcs
1340 * Description : Create a string with the rcs info for all sourcefiles
1344 * Returns : A string, or NULL on out-of-memory.
1346 *********************************************************************/
1347 static char *show_rcs(void)
1349 char *result = strdup("");
1350 char buf[BUFFER_SIZE];
1352 /* Instead of including *all* dot h's in the project (thus creating a
1353 * tremendous amount of dependencies), I will concede to declaring them
1354 * as extern's. This forces the developer to add to this list, but oh well.
1357 #define SHOW_RCS(__x) \
1359 extern const char __x[]; \
1360 sprintf(buf, "%s\n", __x); \
1361 string_append(&result, buf); \
1364 /* In alphabetical order */
1365 SHOW_RCS(actions_h_rcs)
1366 SHOW_RCS(actions_rcs)
1369 #ifdef FEATURE_CGI_EDIT_ACTIONS
1370 SHOW_RCS(cgiedit_h_rcs)
1371 SHOW_RCS(cgiedit_rcs)
1372 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1373 SHOW_RCS(cgisimple_h_rcs)
1374 SHOW_RCS(cgisimple_rcs)
1376 SHOW_RCS(cygwin_h_rcs)
1378 SHOW_RCS(deanimate_h_rcs)
1379 SHOW_RCS(deanimate_rcs)
1380 SHOW_RCS(encode_h_rcs)
1381 SHOW_RCS(encode_rcs)
1382 SHOW_RCS(errlog_h_rcs)
1383 SHOW_RCS(errlog_rcs)
1384 SHOW_RCS(filters_h_rcs)
1385 SHOW_RCS(filters_rcs)
1386 SHOW_RCS(gateway_h_rcs)
1387 SHOW_RCS(gateway_rcs)
1388 SHOW_RCS(jbsockets_h_rcs)
1389 SHOW_RCS(jbsockets_rcs)
1392 #ifdef FEATURE_KILL_POPUPS
1393 SHOW_RCS(killpopup_h_rcs)
1394 SHOW_RCS(killpopup_rcs)
1395 #endif /* def FEATURE_KILL_POPUPS */
1396 SHOW_RCS(list_h_rcs)
1398 SHOW_RCS(loadcfg_h_rcs)
1399 SHOW_RCS(loadcfg_rcs)
1400 SHOW_RCS(loaders_h_rcs)
1401 SHOW_RCS(loaders_rcs)
1402 SHOW_RCS(miscutil_h_rcs)
1403 SHOW_RCS(miscutil_rcs)
1404 SHOW_RCS(parsers_h_rcs)
1405 SHOW_RCS(parsers_rcs)
1407 SHOW_RCS(pcrs_h_rcs)
1408 SHOW_RCS(project_h_rcs)
1409 SHOW_RCS(ssplit_h_rcs)
1410 SHOW_RCS(ssplit_rcs)
1411 SHOW_RCS(urlmatch_h_rcs)
1412 SHOW_RCS(urlmatch_rcs)
1414 #ifndef _WIN_CONSOLE
1415 SHOW_RCS(w32log_h_rcs)
1416 SHOW_RCS(w32log_rcs)
1417 SHOW_RCS(w32res_h_rcs)
1418 SHOW_RCS(w32taskbar_h_rcs)
1419 SHOW_RCS(w32taskbar_rcs)
1420 #endif /* ndef _WIN_CONSOLE */
1421 SHOW_RCS(win32_h_rcs)
1423 #endif /* def _WIN32 */