1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 2.0 2002/06/04 14:34:21 jongfoster Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/src/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 2.0 2002/06/04 14:34:21 jongfoster
40 * Moving source files to src/
42 * Revision 1.35 2002/05/12 21:44:44 jongfoster
43 * Adding amiga.[ch] revision information, if on an amiga.
45 * Revision 1.34 2002/04/30 12:06:12 oes
46 * Deleted unused code from default_cgi
48 * Revision 1.33 2002/04/30 11:14:52 oes
49 * Made csp the first parameter in *action_to_html
51 * Revision 1.32 2002/04/26 18:29:13 jongfoster
52 * Fixing this Visual C++ warning:
53 * cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
55 * Revision 1.31 2002/04/26 12:54:36 oes
56 * - Kill obsolete REDIRECT_URL code
57 * - Error handling fixes
58 * - Style sheet related HTML snipplet changes
59 * - cgi_show_url_info:
60 * - Matches now in table, actions on single lines,
62 * - standard.action suppressed
63 * - Buttons to View and Edit AFs
65 * Revision 1.30 2002/04/24 02:18:08 oes
66 * - show-status is now the starting point for editing
67 * the actions files, generate list of all AFs with buttons
68 * for viewing and editing, new look for file list (Jon:
69 * buttons now aligned ;-P ), view mode now supports multiple
70 * AFs, name changes, no view links for unspecified files,
71 * no edit link for standard.action.
73 * - Jon's multiple AF patch: cgi_show_url_info now uses all
74 * AFs and marks the output accordingly
76 * Revision 1.29 2002/04/10 13:38:35 oes
77 * load_template signature changed
79 * Revision 1.28 2002/04/07 15:42:12 jongfoster
80 * Fixing send-banner?type=auto when the image-blocker is
81 * a redirect to send-banner
83 * Revision 1.27 2002/04/05 15:50:48 oes
84 * added send-stylesheet CGI
86 * Revision 1.26 2002/04/04 00:36:36 gliptak
87 * always use pcre for matching
89 * Revision 1.25 2002/04/03 22:28:03 gliptak
90 * Removed references to gnu_regex
92 * Revision 1.24 2002/04/02 16:12:47 oes
93 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
95 * Revision 1.23 2002/03/26 22:29:54 swa
96 * we have a new homepage!
98 * Revision 1.22 2002/03/24 16:18:15 jongfoster
101 * Revision 1.21 2002/03/24 15:23:33 jongfoster
104 * Revision 1.20 2002/03/24 13:25:43 swa
105 * name change related issues
107 * Revision 1.19 2002/03/16 23:54:06 jongfoster
108 * Adding graceful termination feature, to help look for memory leaks.
109 * If you enable this (which, by design, has to be done by hand
110 * editing config.h) and then go to http://i.j.b/die, then the program
111 * will exit cleanly after the *next* request. It should free all the
112 * memory that was used.
114 * Revision 1.18 2002/03/12 01:44:49 oes
115 * Changed default for "blocked" image from jb logo to checkboard pattern
117 * Revision 1.17 2002/03/08 16:43:18 oes
118 * Added choice beween GIF and PNG built-in images
120 * Revision 1.16 2002/03/07 03:48:38 oes
121 * - Changed built-in images from GIF to PNG
122 * (with regard to Unisys patent issue)
123 * - Added a 4x4 pattern PNG which is less intrusive
124 * than the logo but also clearly marks the deleted banners
126 * Revision 1.15 2002/03/06 22:54:35 jongfoster
127 * Automated function-comment nitpicking.
129 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
130 * Clean up a little CRLF unpleasantness that suddenly appeared
132 * Revision 1.13 2002/02/21 00:10:37 jongfoster
133 * Adding send-banner?type=auto option
135 * Revision 1.12 2002/01/23 01:03:32 jongfoster
136 * Fixing gcc [CygWin] compiler warnings
138 * Revision 1.11 2002/01/23 00:01:04 jongfoster
139 * Adding cgi_transparent_gif() for http://i.j.b/t
140 * Adding missing html_encode() to many CGI functions.
141 * Adding urlmatch.[ch] to http://i.j.b/show-version
143 * Revision 1.10 2002/01/17 21:10:37 jongfoster
144 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
145 * Also fixing a problem in the same function with improperly quoted URLs
146 * in output HTML, and adding code to handle https:// URLs correctly.
148 * Revision 1.9 2001/11/30 23:09:15 jongfoster
149 * Now reports on FEATURE_CGI_EDIT_ACTIONS
150 * Removing FEATURE_DENY_GZIP from template
152 * Revision 1.8 2001/11/13 00:14:07 jongfoster
153 * Fixing stupid bug now I've figured out what || means.
154 * (It always returns 0 or 1, not one of it's paramaters.)
156 * Revision 1.7 2001/10/23 21:48:19 jongfoster
157 * Cleaning up error handling in CGI functions - they now send back
158 * a HTML error page and should never cause a FATAL error. (Fixes one
159 * potential source of "denial of service" attacks).
161 * CGI actions file editor that works and is actually useful.
163 * Ability to toggle JunkBuster remotely using a CGI call.
165 * You can turn off both the above features in the main configuration
166 * file, e.g. if you are running a multi-user proxy.
168 * Revision 1.6 2001/10/14 22:00:32 jongfoster
169 * Adding support for a 404 error when an invalid CGI page is requested.
171 * Revision 1.5 2001/10/07 15:30:41 oes
172 * Removed FEATURE_DENY_GZIP
174 * Revision 1.4 2001/10/02 15:31:12 oes
175 * Introduced show-request cgi
177 * Revision 1.3 2001/09/22 16:34:44 jongfoster
178 * Removing unneeded #includes
180 * Revision 1.2 2001/09/19 18:01:11 oes
181 * Fixed comments; cosmetics
183 * Revision 1.1 2001/09/16 17:08:54 jongfoster
184 * Moving simple CGI functions from cgi.c to new file cgisimple.c
187 **********************************************************************/
193 #include <sys/types.h>
200 #define snprintf _snprintf
201 #endif /* def _WIN32 */
205 #include "cgisimple.h"
211 #include "miscutil.h"
214 #include "urlmatch.h"
217 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
220 static char *show_rcs(void);
221 static jb_err show_defines(struct map *exports);
224 /*********************************************************************
226 * Function : cgi_default
228 * Description : CGI function that is called for the CGI_SITE_1_HOST
229 * and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
230 * Boring - only exports the default exports.
233 * 1 : csp = Current client state (buffers, headers, etc...)
234 * 2 : rsp = http_response data structure for output
235 * 3 : parameters = map of cgi parameters
237 * CGI Parameters : none
239 * Returns : JB_ERR_OK on success
240 * JB_ERR_MEMORY on out-of-memory
242 *********************************************************************/
243 jb_err cgi_default(struct client_state *csp,
244 struct http_response *rsp,
245 const struct map *parameters)
252 if (NULL == (exports = default_exports(csp, "")))
254 return JB_ERR_MEMORY;
257 return template_fill_for_cgi(csp, "default", exports, rsp);
261 /*********************************************************************
263 * Function : cgi_error_404
265 * Description : CGI function that is called if an unknown action was
269 * 1 : csp = Current client state (buffers, headers, etc...)
270 * 2 : rsp = http_response data structure for output
271 * 3 : parameters = map of cgi parameters
273 * CGI Parameters : none
275 * Returns : JB_ERR_OK on success
276 * JB_ERR_MEMORY on out-of-memory error.
278 *********************************************************************/
279 jb_err cgi_error_404(struct client_state *csp,
280 struct http_response *rsp,
281 const struct map *parameters)
289 if (NULL == (exports = default_exports(csp, NULL)))
291 return JB_ERR_MEMORY;
294 rsp->status = strdup("404 Privoxy configuration page not found");
295 if (rsp->status == NULL)
298 return JB_ERR_MEMORY;
301 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
305 #ifdef FEATURE_GRACEFUL_TERMINATION
306 /*********************************************************************
310 * Description : CGI function to shut down Privoxy.
311 * NOTE: Turning this on in a production build
312 * would be a BAD idea. An EXTREMELY BAD idea.
313 * In short, don't do it.
316 * 1 : csp = Current client state (buffers, headers, etc...)
317 * 2 : rsp = http_response data structure for output
318 * 3 : parameters = map of cgi parameters
320 * CGI Parameters : none
322 * Returns : JB_ERR_OK on success
323 * JB_ERR_MEMORY on out-of-memory error.
325 *********************************************************************/
326 jb_err cgi_die (struct client_state *csp,
327 struct http_response *rsp,
328 const struct map *parameters)
338 * I don't really care what gets sent back to the browser.
339 * Take the easy option - "out of memory" page.
342 return JB_ERR_MEMORY;
344 #endif /* def FEATURE_GRACEFUL_TERMINATION */
347 /*********************************************************************
349 * Function : cgi_show_request
351 * Description : Show the client's request and what sed() would have
355 * 1 : csp = Current client state (buffers, headers, etc...)
356 * 2 : rsp = http_response data structure for output
357 * 3 : parameters = map of cgi parameters
359 * CGI Parameters : none
361 * Returns : JB_ERR_OK on success
362 * JB_ERR_MEMORY on out-of-memory error.
364 *********************************************************************/
365 jb_err cgi_show_request(struct client_state *csp,
366 struct http_response *rsp,
367 const struct map *parameters)
376 if (NULL == (exports = default_exports(csp, "show-request")))
378 return JB_ERR_MEMORY;
382 * Repair the damage done to the IOB by get_header()
384 for (p = csp->iob->buf; p < csp->iob->eod; p++)
386 if (*p == '\0') *p = '\n';
390 * Export the original client's request and the one we would
391 * be sending to the server if this wasn't a CGI call
394 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
397 return JB_ERR_MEMORY;
400 if (map(exports, "processed-request", 1, html_encode_and_free_original(
401 sed(client_patterns, add_client_headers, csp)), 0))
404 return JB_ERR_MEMORY;
407 return template_fill_for_cgi(csp, "show-request", exports, rsp);
411 /*********************************************************************
413 * Function : cgi_send_banner
415 * Description : CGI function that returns a banner.
418 * 1 : csp = Current client state (buffers, headers, etc...)
419 * 2 : rsp = http_response data structure for output
420 * 3 : parameters = map of cgi parameters
423 * type : Selects the type of banner between "trans", "logo",
424 * and "auto". Defaults to "logo" if absent or invalid.
425 * "auto" means to select as if we were image-blocking.
426 * (Only the first character really counts; b and t are
429 * Returns : JB_ERR_OK on success
430 * JB_ERR_MEMORY on out-of-memory error.
432 *********************************************************************/
433 jb_err cgi_send_banner(struct client_state *csp,
434 struct http_response *rsp,
435 const struct map *parameters)
437 char imagetype = lookup(parameters, "type")[0];
440 * If type is auto, then determine the right thing
441 * to do from the set-image-blocker action
443 if (imagetype == 'a')
450 #ifdef FEATURE_IMAGE_BLOCKING
451 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
453 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
454 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
455 const char *p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
459 /* Use default - nothing to do here. */
461 else if (0 == strcmpic(p, "blank"))
465 else if (0 == strcmpic(p, "pattern"))
471 * If the action is to call this CGI, determine
474 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
476 imagetype = p[sizeof(prefix1) - 1];
478 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
480 imagetype = p[sizeof(prefix2) - 1];
484 * Everything else must (should) be a URL to
492 #endif /* def FEATURE_IMAGE_BLOCKING */
496 * Now imagetype is either the non-auto type we were called with,
497 * or it was auto and has since been determined. In any case, we
498 * can proceed to actually answering the request by sending a redirect
499 * or an image as appropriate:
501 if (imagetype == 'r')
503 rsp->status = strdup("302 Local Redirect from Privoxy");
504 if (rsp->status == NULL)
506 return JB_ERR_MEMORY;
508 if (enlist_unique_header(rsp->headers, "Location",
509 csp->action->string[ACTION_STRING_IMAGE_BLOCKER]))
511 return JB_ERR_MEMORY;
516 if ((imagetype == 'b') || (imagetype == 't'))
518 rsp->body = bindup(image_blank_data, image_blank_length);
519 rsp->content_length = image_blank_length;
523 rsp->body = bindup(image_pattern_data, image_pattern_length);
524 rsp->content_length = image_pattern_length;
527 if (rsp->body == NULL)
529 return JB_ERR_MEMORY;
531 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
533 return JB_ERR_MEMORY;
544 /*********************************************************************
546 * Function : cgi_transparent_image
548 * Description : CGI function that sends a 1x1 transparent image.
551 * 1 : csp = Current client state (buffers, headers, etc...)
552 * 2 : rsp = http_response data structure for output
553 * 3 : parameters = map of cgi parameters
555 * CGI Parameters : None
557 * Returns : JB_ERR_OK on success
558 * JB_ERR_MEMORY on out-of-memory error.
560 *********************************************************************/
561 jb_err cgi_transparent_image(struct client_state *csp,
562 struct http_response *rsp,
563 const struct map *parameters)
565 rsp->body = bindup(image_blank_data, image_blank_length);
566 rsp->content_length = image_blank_length;
568 if (rsp->body == NULL)
570 return JB_ERR_MEMORY;
573 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
575 return JB_ERR_MEMORY;
585 /*********************************************************************
587 * Function : cgi_send_stylesheet
589 * Description : CGI function that sends a css stylesheet found
590 * in the cgi-style.css template
593 * 1 : csp = Current client state (buffers, headers, etc...)
594 * 2 : rsp = http_response data structure for output
595 * 3 : parameters = map of cgi parameters
597 * CGI Parameters : None
599 * Returns : JB_ERR_OK on success
600 * JB_ERR_MEMORY on out-of-memory error.
602 *********************************************************************/
603 jb_err cgi_send_stylesheet(struct client_state *csp,
604 struct http_response *rsp,
605 const struct map *parameters)
612 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
614 if (err == JB_ERR_FILE)
617 * No way to tell user; send empty stylesheet
619 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
623 return err; /* JB_ERR_MEMORY */
626 if (enlist(rsp->headers, "Content-Type: text/css"))
628 return JB_ERR_MEMORY;
636 /*********************************************************************
638 * Function : cgi_show_version
640 * Description : CGI function that returns a a web page describing the
641 * file versions of Privoxy.
644 * 1 : csp = Current client state (buffers, headers, etc...)
645 * 2 : rsp = http_response data structure for output
646 * 3 : parameters = map of cgi parameters
648 * CGI Parameters : none
650 * Returns : JB_ERR_OK on success
651 * JB_ERR_MEMORY on out-of-memory error.
653 *********************************************************************/
654 jb_err cgi_show_version(struct client_state *csp,
655 struct http_response *rsp,
656 const struct map *parameters)
664 if (NULL == (exports = default_exports(csp, "show-version")))
666 return JB_ERR_MEMORY;
669 if (map(exports, "sourceversions", 1, show_rcs(), 0))
672 return JB_ERR_MEMORY;
675 return template_fill_for_cgi(csp, "show-version", exports, rsp);
679 /*********************************************************************
681 * Function : cgi_show_status
683 * Description : CGI function that returns a a web page describing the
684 * current status of Privoxy.
687 * 1 : csp = Current client state (buffers, headers, etc...)
688 * 2 : rsp = http_response data structure for output
689 * 3 : parameters = map of cgi parameters
692 * file : Which file to show. Only first letter is checked,
694 * - "p"ermissions (actions) file
697 * Default is to show menu and other information.
699 * Returns : JB_ERR_OK on success
700 * JB_ERR_MEMORY on out-of-memory error.
702 *********************************************************************/
703 jb_err cgi_show_status(struct client_state *csp,
704 struct http_response *rsp,
705 const struct map *parameters)
712 char buf[BUFFER_SIZE];
713 const char * filename = NULL;
714 char * file_description = NULL;
715 #ifdef FEATURE_STATISTICS
716 float perc_rej; /* Percentage of http requests rejected */
718 int local_urls_rejected;
719 #endif /* ndef FEATURE_STATISTICS */
720 struct file_list * fl;
721 struct url_actions * b;
722 jb_err err = JB_ERR_OK;
730 if (NULL == (exports = default_exports(csp, "show-status")))
732 return JB_ERR_MEMORY;
735 switch (*(lookup(parameters, "file")))
738 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_ACTION_FILES && csp->actions_list[i])
740 filename = csp->actions_list[i]->filename;
741 file_description = "Actions File";
748 filename = csp->rlist->filename;
749 file_description = "Filter File";
757 filename = csp->tlist->filename;
758 file_description = "Trust File";
761 #endif /* def FEATURE_TRUST */
764 if (NULL != filename)
766 if ( map(exports, "file-description", 1, file_description, 1)
767 || map(exports, "filepath", 1, html_encode(filename), 0) )
770 return JB_ERR_MEMORY;
773 if ((fp = fopen(filename, "r")) == NULL)
775 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
778 return JB_ERR_MEMORY;
784 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
786 string_join (&s, html_encode(buf));
790 if (map(exports, "contents", 1, s, 0))
793 return JB_ERR_MEMORY;
797 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
801 for (j = 0; (s != NULL) && (j < Argc); j++)
803 if (!err) err = string_join (&s, html_encode(Argv[j]));
804 if (!err) err = string_append(&s, " ");
806 if (!err) err = map(exports, "invocation", 1, s, 0);
808 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
809 if (!err) err = show_defines(exports);
814 return JB_ERR_MEMORY;
817 #ifdef FEATURE_STATISTICS
818 local_urls_read = urls_read;
819 local_urls_rejected = urls_rejected;
822 * Need to alter the stats not to include the fetch of this
825 * Can't do following thread safely! doh!
828 * urls_rejected--; * This will be incremented subsequently *
831 if (local_urls_read == 0)
833 if (!err) err = map_block_killer(exports, "have-stats");
837 if (!err) err = map_block_killer(exports, "have-no-stats");
839 perc_rej = (float)local_urls_rejected * 100.0F /
840 (float)local_urls_read;
842 sprintf(buf, "%d", local_urls_read);
843 if (!err) err = map(exports, "requests-received", 1, buf, 1);
845 sprintf(buf, "%d", local_urls_rejected);
846 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
848 sprintf(buf, "%6.2f", perc_rej);
849 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
852 #else /* ndef FEATURE_STATISTICS */
853 err = err || map_block_killer(exports, "statistics");
854 #endif /* ndef FEATURE_STATISTICS */
857 * List all action files in use, together with view and edit links,
858 * except for standard.action, which should only be viewable. (Not
859 * enforced in the editor itself)
860 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
863 for (i = 0; i < MAX_ACTION_FILES; i++)
865 if (((fl = csp->actions_list[i]) != NULL) && ((b = fl->f) != NULL))
867 if (!err) err = string_append(&s, "<tr><td>");
868 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
869 snprintf(buf, 100, "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a> ", i);
870 if (!err) err = string_append(&s, buf);
872 if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
874 snprintf(buf, 100, "<a href=\"/edit-actions-list?f=%s\">Edit</a>", csp->config->actions_file_short[i]);
875 if (!err) err = string_append(&s, buf);
878 if (!err) err = string_append(&s, "</td></tr>\n");
883 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
887 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
892 if (!err) err = map(exports, "re-filter-filename", 1, html_encode(csp->rlist->filename), 0);
896 if (!err) err = map(exports, "re-filter-filename", 1, "None specified", 1);
897 if (!err) err = map_block_killer(exports, "have-filterfile");
903 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
907 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
908 if (!err) err = map_block_killer(exports, "have-trustfile");
911 if (!err) err = map_block_killer(exports, "trust-support");
912 #endif /* ndef FEATURE_TRUST */
917 return JB_ERR_MEMORY;
920 return template_fill_for_cgi(csp, "show-status", exports, rsp);
924 /*********************************************************************
926 * Function : cgi_show_url_info
928 * Description : CGI function that determines and shows which actions
929 * Privoxy will perform for a given url, and which
930 * matches starting from the defaults have lead to that.
933 * 1 : csp = Current client state (buffers, headers, etc...)
934 * 2 : rsp = http_response data structure for output
935 * 3 : parameters = map of cgi parameters
938 * url : The url whose actions are to be determined.
939 * If url is unset, the url-given conditional will be
940 * set, so that all but the form can be suppressed in
943 * Returns : JB_ERR_OK on success
944 * JB_ERR_MEMORY on out-of-memory error.
946 *********************************************************************/
947 jb_err cgi_show_url_info(struct client_state *csp,
948 struct http_response *rsp,
949 const struct map *parameters)
959 if (NULL == (exports = default_exports(csp, "show-url-info")))
961 return JB_ERR_MEMORY;
965 * Get the url= parameter (if present) and remove any leading/trailing spaces.
967 url_param = strdup(lookup(parameters, "url"));
968 if (url_param == NULL)
971 return JB_ERR_MEMORY;
976 * Handle prefixes. 4 possibilities:
977 * 1) "http://" or "https://" prefix present and followed by URL - OK
978 * 2) Only the "http://" or "https://" part is present, no URL - change
979 * to empty string so it will be detected later as "no URL".
980 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
982 * 4) Parameter not specified or is empty string - let this fall through
983 * for now, next block of code will handle it.
985 if (0 == strncmp(url_param, "http://", 7))
987 if (url_param[7] == '\0')
990 * Empty URL (just prefix).
991 * Make it totally empty so it's caught by the next if()
996 else if (0 == strncmp(url_param, "https://", 8))
998 if (url_param[8] == '\0')
1001 * Empty URL (just prefix).
1002 * Make it totally empty so it's caught by the next if()
1004 url_param[0] = '\0';
1007 else if (url_param[0] != '\0')
1010 * Unknown prefix - assume http://
1012 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
1013 if (NULL == url_param_prefixed)
1017 return JB_ERR_MEMORY;
1019 strcpy(url_param_prefixed, "http://");
1020 strcpy(url_param_prefixed + 7, url_param);
1022 url_param = url_param_prefixed;
1026 if (url_param[0] == '\0')
1028 /* URL paramater not specified, display query form only. */
1030 if (map_block_killer(exports, "url-given")
1031 || map(exports, "url", 1, "", 1))
1034 return JB_ERR_MEMORY;
1039 /* Given a URL, so query it. */
1044 struct file_list *fl;
1045 struct url_actions *b;
1046 struct http_request url_to_query[1];
1047 struct current_action_spec action[1];
1050 if (map(exports, "url", 1, html_encode(url_param), 0))
1054 return JB_ERR_MEMORY;
1057 init_current_action(action);
1059 if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1061 free_current_action(action);
1064 return JB_ERR_MEMORY;
1067 err = parse_http_url(url_param, url_to_query, csp);
1071 if (err == JB_ERR_MEMORY)
1073 free_current_action(action);
1075 return JB_ERR_MEMORY;
1081 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1082 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1084 free_current_action(action);
1089 return JB_ERR_MEMORY;
1092 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1096 * We have a warning about SSL paths. Hide it for insecure sites.
1098 if (!url_to_query->ssl)
1100 if (map_block_killer(exports, "https"))
1102 free_current_action(action);
1104 return JB_ERR_MEMORY;
1108 matches = strdup("<table class=\"transparent\">");
1110 for (i = 0; i < MAX_ACTION_FILES; i++)
1112 if (NULL == csp->config->actions_file_short[i]
1113 || !strcmp(csp->config->actions_file_short[i], "standard")) continue;
1117 if ((fl = csp->actions_list[i]) != NULL)
1119 if ((b = fl->f) != NULL)
1121 /* FIXME: Hardcoded HTML! */
1122 string_append(&matches, "<tr><th>In file: ");
1123 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1124 snprintf(buf, 150, ".action <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1125 string_append(&matches, buf);
1126 string_append(&matches, "View</a> <a class=\"cmd\" href=\"/edit-actions-list?f=");
1127 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1128 string_append(&matches, "\">Edit</a></th></tr>\n");
1135 for (; (b != NULL) && (matches != NULL); b = b->next)
1137 if (url_match(b->url, url_to_query))
1139 string_append(&matches, "<tr><td>{");
1140 string_join (&matches, actions_to_html(csp, b->action));
1141 string_append(&matches, " }</b><br>\n<code>");
1142 string_join (&matches, html_encode(b->url->spec));
1143 string_append(&matches, "</code></td></tr>\n");
1145 if (merge_current_action(action, b->action))
1148 free_http_request(url_to_query);
1149 free_current_action(action);
1151 return JB_ERR_MEMORY;
1159 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1162 string_append(&matches, "</table>\n");
1164 free_http_request(url_to_query);
1166 if (matches == NULL)
1168 free_current_action(action);
1170 return JB_ERR_MEMORY;
1173 if (map(exports, "matches", 1, matches , 0))
1175 free_current_action(action);
1177 return JB_ERR_MEMORY;
1180 s = current_action_to_html(csp, action);
1182 free_current_action(action);
1184 if (map(exports, "final", 1, s, 0))
1187 return JB_ERR_MEMORY;
1191 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1195 /*********************************************************************
1197 * Function : cgi_robots_txt
1199 * Description : CGI function to return "/robots.txt".
1202 * 1 : csp = Current client state (buffers, headers, etc...)
1203 * 2 : rsp = http_response data structure for output
1204 * 3 : parameters = map of cgi parameters
1206 * CGI Parameters : None
1208 * Returns : JB_ERR_OK on success
1209 * JB_ERR_MEMORY on out-of-memory error.
1211 *********************************************************************/
1212 jb_err cgi_robots_txt(struct client_state *csp,
1213 struct http_response *rsp,
1214 const struct map *parameters)
1220 "# This is the Privoxy control interface.\n"
1221 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1227 if (rsp->body == NULL)
1229 return JB_ERR_MEMORY;
1232 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1236 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1237 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1239 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1243 /*********************************************************************
1245 * Function : show_defines
1247 * Description : Add to a map the state od all conditional #defines
1248 * used when building
1251 * 1 : exports = map to extend
1253 * Returns : JB_ERR_OK on success
1254 * JB_ERR_MEMORY on out-of-memory error.
1256 *********************************************************************/
1257 static jb_err show_defines(struct map *exports)
1259 jb_err err = JB_ERR_OK;
1262 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1263 #else /* ifndef FEATURE_ACL */
1264 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1265 #endif /* ndef FEATURE_ACL */
1267 #ifdef FEATURE_CGI_EDIT_ACTIONS
1268 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1269 #else /* ifndef FEATURE_COOKIE_JAR */
1270 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1271 #endif /* ndef FEATURE_COOKIE_JAR */
1273 #ifdef FEATURE_COOKIE_JAR
1274 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1275 #else /* ifndef FEATURE_COOKIE_JAR */
1276 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1277 #endif /* ndef FEATURE_COOKIE_JAR */
1279 #ifdef FEATURE_FAST_REDIRECTS
1280 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1281 #else /* ifndef FEATURE_FAST_REDIRECTS */
1282 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1283 #endif /* ndef FEATURE_FAST_REDIRECTS */
1285 #ifdef FEATURE_FORCE_LOAD
1286 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1287 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1288 #else /* ifndef FEATURE_FORCE_LOAD */
1289 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1290 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1291 #endif /* ndef FEATURE_FORCE_LOAD */
1293 #ifdef FEATURE_IMAGE_BLOCKING
1294 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1295 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1296 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1297 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1299 #ifdef FEATURE_IMAGE_DETECT_MSIE
1300 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1301 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1302 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1303 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1305 #ifdef FEATURE_KILL_POPUPS
1306 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1307 #else /* ifndef FEATURE_KILL_POPUPS */
1308 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1309 #endif /* ndef FEATURE_KILL_POPUPS */
1311 #ifdef FEATURE_NO_GIFS
1312 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1313 #else /* ifndef FEATURE_NO_GIFS */
1314 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1315 #endif /* ndef FEATURE_NO_GIFS */
1317 #ifdef FEATURE_PTHREAD
1318 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1319 #else /* ifndef FEATURE_PTHREAD */
1320 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1321 #endif /* ndef FEATURE_PTHREAD */
1323 #ifdef FEATURE_STATISTICS
1324 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1325 #else /* ifndef FEATURE_STATISTICS */
1326 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1327 #endif /* ndef FEATURE_STATISTICS */
1329 #ifdef FEATURE_TOGGLE
1330 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1331 #else /* ifndef FEATURE_TOGGLE */
1332 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1333 #endif /* ndef FEATURE_TOGGLE */
1335 #ifdef FEATURE_TRUST
1336 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1337 #else /* ifndef FEATURE_TRUST */
1338 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1339 #endif /* ndef FEATURE_TRUST */
1342 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1343 #else /* ifndef STATIC_PCRE */
1344 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1345 #endif /* ndef STATIC_PCRE */
1348 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1349 #else /* ifndef STATIC_PCRS */
1350 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1351 #endif /* ndef STATIC_PCRS */
1357 /*********************************************************************
1359 * Function : show_rcs
1361 * Description : Create a string with the rcs info for all sourcefiles
1365 * Returns : A string, or NULL on out-of-memory.
1367 *********************************************************************/
1368 static char *show_rcs(void)
1370 char *result = strdup("");
1371 char buf[BUFFER_SIZE];
1373 /* Instead of including *all* dot h's in the project (thus creating a
1374 * tremendous amount of dependencies), I will concede to declaring them
1375 * as extern's. This forces the developer to add to this list, but oh well.
1378 #define SHOW_RCS(__x) \
1380 extern const char __x[]; \
1381 sprintf(buf, "%s\n", __x); \
1382 string_append(&result, buf); \
1385 /* In alphabetical order */
1386 SHOW_RCS(actions_h_rcs)
1387 SHOW_RCS(actions_rcs)
1389 SHOW_RCS(amiga_h_rcs)
1391 #endif /* def AMIGA */
1394 #ifdef FEATURE_CGI_EDIT_ACTIONS
1395 SHOW_RCS(cgiedit_h_rcs)
1396 SHOW_RCS(cgiedit_rcs)
1397 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1398 SHOW_RCS(cgisimple_h_rcs)
1399 SHOW_RCS(cgisimple_rcs)
1401 SHOW_RCS(cygwin_h_rcs)
1403 SHOW_RCS(deanimate_h_rcs)
1404 SHOW_RCS(deanimate_rcs)
1405 SHOW_RCS(encode_h_rcs)
1406 SHOW_RCS(encode_rcs)
1407 SHOW_RCS(errlog_h_rcs)
1408 SHOW_RCS(errlog_rcs)
1409 SHOW_RCS(filters_h_rcs)
1410 SHOW_RCS(filters_rcs)
1411 SHOW_RCS(gateway_h_rcs)
1412 SHOW_RCS(gateway_rcs)
1413 SHOW_RCS(jbsockets_h_rcs)
1414 SHOW_RCS(jbsockets_rcs)
1417 #ifdef FEATURE_KILL_POPUPS
1418 SHOW_RCS(killpopup_h_rcs)
1419 SHOW_RCS(killpopup_rcs)
1420 #endif /* def FEATURE_KILL_POPUPS */
1421 SHOW_RCS(list_h_rcs)
1423 SHOW_RCS(loadcfg_h_rcs)
1424 SHOW_RCS(loadcfg_rcs)
1425 SHOW_RCS(loaders_h_rcs)
1426 SHOW_RCS(loaders_rcs)
1427 SHOW_RCS(miscutil_h_rcs)
1428 SHOW_RCS(miscutil_rcs)
1429 SHOW_RCS(parsers_h_rcs)
1430 SHOW_RCS(parsers_rcs)
1432 SHOW_RCS(pcrs_h_rcs)
1433 SHOW_RCS(project_h_rcs)
1434 SHOW_RCS(ssplit_h_rcs)
1435 SHOW_RCS(ssplit_rcs)
1436 SHOW_RCS(urlmatch_h_rcs)
1437 SHOW_RCS(urlmatch_rcs)
1439 #ifndef _WIN_CONSOLE
1440 SHOW_RCS(w32log_h_rcs)
1441 SHOW_RCS(w32log_rcs)
1442 SHOW_RCS(w32res_h_rcs)
1443 SHOW_RCS(w32taskbar_h_rcs)
1444 SHOW_RCS(w32taskbar_rcs)
1445 #endif /* ndef _WIN_CONSOLE */
1446 SHOW_RCS(win32_h_rcs)
1448 #endif /* def _WIN32 */