1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 2.1 2002/07/04 14:35:05 oes 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.1 2002/07/04 14:35:05 oes
40 * Added ability to send redirects to send-banner CGI, so that it can completely mimic the image blocking action if called with type=auto
42 * Revision 2.0 2002/06/04 14:34:21 jongfoster
43 * Moving source files to src/
45 * Revision 1.35 2002/05/12 21:44:44 jongfoster
46 * Adding amiga.[ch] revision information, if on an amiga.
48 * Revision 1.34 2002/04/30 12:06:12 oes
49 * Deleted unused code from default_cgi
51 * Revision 1.33 2002/04/30 11:14:52 oes
52 * Made csp the first parameter in *action_to_html
54 * Revision 1.32 2002/04/26 18:29:13 jongfoster
55 * Fixing this Visual C++ warning:
56 * cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
58 * Revision 1.31 2002/04/26 12:54:36 oes
59 * - Kill obsolete REDIRECT_URL code
60 * - Error handling fixes
61 * - Style sheet related HTML snipplet changes
62 * - cgi_show_url_info:
63 * - Matches now in table, actions on single lines,
65 * - standard.action suppressed
66 * - Buttons to View and Edit AFs
68 * Revision 1.30 2002/04/24 02:18:08 oes
69 * - show-status is now the starting point for editing
70 * the actions files, generate list of all AFs with buttons
71 * for viewing and editing, new look for file list (Jon:
72 * buttons now aligned ;-P ), view mode now supports multiple
73 * AFs, name changes, no view links for unspecified files,
74 * no edit link for standard.action.
76 * - Jon's multiple AF patch: cgi_show_url_info now uses all
77 * AFs and marks the output accordingly
79 * Revision 1.29 2002/04/10 13:38:35 oes
80 * load_template signature changed
82 * Revision 1.28 2002/04/07 15:42:12 jongfoster
83 * Fixing send-banner?type=auto when the image-blocker is
84 * a redirect to send-banner
86 * Revision 1.27 2002/04/05 15:50:48 oes
87 * added send-stylesheet CGI
89 * Revision 1.26 2002/04/04 00:36:36 gliptak
90 * always use pcre for matching
92 * Revision 1.25 2002/04/03 22:28:03 gliptak
93 * Removed references to gnu_regex
95 * Revision 1.24 2002/04/02 16:12:47 oes
96 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
98 * Revision 1.23 2002/03/26 22:29:54 swa
99 * we have a new homepage!
101 * Revision 1.22 2002/03/24 16:18:15 jongfoster
104 * Revision 1.21 2002/03/24 15:23:33 jongfoster
107 * Revision 1.20 2002/03/24 13:25:43 swa
108 * name change related issues
110 * Revision 1.19 2002/03/16 23:54:06 jongfoster
111 * Adding graceful termination feature, to help look for memory leaks.
112 * If you enable this (which, by design, has to be done by hand
113 * editing config.h) and then go to http://i.j.b/die, then the program
114 * will exit cleanly after the *next* request. It should free all the
115 * memory that was used.
117 * Revision 1.18 2002/03/12 01:44:49 oes
118 * Changed default for "blocked" image from jb logo to checkboard pattern
120 * Revision 1.17 2002/03/08 16:43:18 oes
121 * Added choice beween GIF and PNG built-in images
123 * Revision 1.16 2002/03/07 03:48:38 oes
124 * - Changed built-in images from GIF to PNG
125 * (with regard to Unisys patent issue)
126 * - Added a 4x4 pattern PNG which is less intrusive
127 * than the logo but also clearly marks the deleted banners
129 * Revision 1.15 2002/03/06 22:54:35 jongfoster
130 * Automated function-comment nitpicking.
132 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
133 * Clean up a little CRLF unpleasantness that suddenly appeared
135 * Revision 1.13 2002/02/21 00:10:37 jongfoster
136 * Adding send-banner?type=auto option
138 * Revision 1.12 2002/01/23 01:03:32 jongfoster
139 * Fixing gcc [CygWin] compiler warnings
141 * Revision 1.11 2002/01/23 00:01:04 jongfoster
142 * Adding cgi_transparent_gif() for http://i.j.b/t
143 * Adding missing html_encode() to many CGI functions.
144 * Adding urlmatch.[ch] to http://i.j.b/show-version
146 * Revision 1.10 2002/01/17 21:10:37 jongfoster
147 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
148 * Also fixing a problem in the same function with improperly quoted URLs
149 * in output HTML, and adding code to handle https:// URLs correctly.
151 * Revision 1.9 2001/11/30 23:09:15 jongfoster
152 * Now reports on FEATURE_CGI_EDIT_ACTIONS
153 * Removing FEATURE_DENY_GZIP from template
155 * Revision 1.8 2001/11/13 00:14:07 jongfoster
156 * Fixing stupid bug now I've figured out what || means.
157 * (It always returns 0 or 1, not one of it's paramaters.)
159 * Revision 1.7 2001/10/23 21:48:19 jongfoster
160 * Cleaning up error handling in CGI functions - they now send back
161 * a HTML error page and should never cause a FATAL error. (Fixes one
162 * potential source of "denial of service" attacks).
164 * CGI actions file editor that works and is actually useful.
166 * Ability to toggle JunkBuster remotely using a CGI call.
168 * You can turn off both the above features in the main configuration
169 * file, e.g. if you are running a multi-user proxy.
171 * Revision 1.6 2001/10/14 22:00:32 jongfoster
172 * Adding support for a 404 error when an invalid CGI page is requested.
174 * Revision 1.5 2001/10/07 15:30:41 oes
175 * Removed FEATURE_DENY_GZIP
177 * Revision 1.4 2001/10/02 15:31:12 oes
178 * Introduced show-request cgi
180 * Revision 1.3 2001/09/22 16:34:44 jongfoster
181 * Removing unneeded #includes
183 * Revision 1.2 2001/09/19 18:01:11 oes
184 * Fixed comments; cosmetics
186 * Revision 1.1 2001/09/16 17:08:54 jongfoster
187 * Moving simple CGI functions from cgi.c to new file cgisimple.c
190 **********************************************************************/
196 #include <sys/types.h>
203 #define snprintf _snprintf
204 #endif /* def _WIN32 */
208 #include "cgisimple.h"
214 #include "miscutil.h"
217 #include "urlmatch.h"
220 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
223 static char *show_rcs(void);
224 static jb_err show_defines(struct map *exports);
227 /*********************************************************************
229 * Function : cgi_default
231 * Description : CGI function that is called for the CGI_SITE_1_HOST
232 * and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
233 * Boring - only exports the default exports.
236 * 1 : csp = Current client state (buffers, headers, etc...)
237 * 2 : rsp = http_response data structure for output
238 * 3 : parameters = map of cgi parameters
240 * CGI Parameters : none
242 * Returns : JB_ERR_OK on success
243 * JB_ERR_MEMORY on out-of-memory
245 *********************************************************************/
246 jb_err cgi_default(struct client_state *csp,
247 struct http_response *rsp,
248 const struct map *parameters)
255 if (NULL == (exports = default_exports(csp, "")))
257 return JB_ERR_MEMORY;
260 return template_fill_for_cgi(csp, "default", exports, rsp);
264 /*********************************************************************
266 * Function : cgi_error_404
268 * Description : CGI function that is called if an unknown action was
272 * 1 : csp = Current client state (buffers, headers, etc...)
273 * 2 : rsp = http_response data structure for output
274 * 3 : parameters = map of cgi parameters
276 * CGI Parameters : none
278 * Returns : JB_ERR_OK on success
279 * JB_ERR_MEMORY on out-of-memory error.
281 *********************************************************************/
282 jb_err cgi_error_404(struct client_state *csp,
283 struct http_response *rsp,
284 const struct map *parameters)
292 if (NULL == (exports = default_exports(csp, NULL)))
294 return JB_ERR_MEMORY;
297 rsp->status = strdup("404 Privoxy configuration page not found");
298 if (rsp->status == NULL)
301 return JB_ERR_MEMORY;
304 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
308 #ifdef FEATURE_GRACEFUL_TERMINATION
309 /*********************************************************************
313 * Description : CGI function to shut down Privoxy.
314 * NOTE: Turning this on in a production build
315 * would be a BAD idea. An EXTREMELY BAD idea.
316 * In short, don't do it.
319 * 1 : csp = Current client state (buffers, headers, etc...)
320 * 2 : rsp = http_response data structure for output
321 * 3 : parameters = map of cgi parameters
323 * CGI Parameters : none
325 * Returns : JB_ERR_OK on success
326 * JB_ERR_MEMORY on out-of-memory error.
328 *********************************************************************/
329 jb_err cgi_die (struct client_state *csp,
330 struct http_response *rsp,
331 const struct map *parameters)
341 * I don't really care what gets sent back to the browser.
342 * Take the easy option - "out of memory" page.
345 return JB_ERR_MEMORY;
347 #endif /* def FEATURE_GRACEFUL_TERMINATION */
350 /*********************************************************************
352 * Function : cgi_show_request
354 * Description : Show the client's request and what sed() would have
358 * 1 : csp = Current client state (buffers, headers, etc...)
359 * 2 : rsp = http_response data structure for output
360 * 3 : parameters = map of cgi parameters
362 * CGI Parameters : none
364 * Returns : JB_ERR_OK on success
365 * JB_ERR_MEMORY on out-of-memory error.
367 *********************************************************************/
368 jb_err cgi_show_request(struct client_state *csp,
369 struct http_response *rsp,
370 const struct map *parameters)
379 if (NULL == (exports = default_exports(csp, "show-request")))
381 return JB_ERR_MEMORY;
385 * Repair the damage done to the IOB by get_header()
387 for (p = csp->iob->buf; p < csp->iob->eod; p++)
389 if (*p == '\0') *p = '\n';
393 * Export the original client's request and the one we would
394 * be sending to the server if this wasn't a CGI call
397 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
400 return JB_ERR_MEMORY;
403 if (map(exports, "processed-request", 1, html_encode_and_free_original(
404 sed(client_patterns, add_client_headers, csp)), 0))
407 return JB_ERR_MEMORY;
410 return template_fill_for_cgi(csp, "show-request", exports, rsp);
414 /*********************************************************************
416 * Function : cgi_send_banner
418 * Description : CGI function that returns a banner.
421 * 1 : csp = Current client state (buffers, headers, etc...)
422 * 2 : rsp = http_response data structure for output
423 * 3 : parameters = map of cgi parameters
426 * type : Selects the type of banner between "trans", "logo",
427 * and "auto". Defaults to "logo" if absent or invalid.
428 * "auto" means to select as if we were image-blocking.
429 * (Only the first character really counts; b and t are
432 * Returns : JB_ERR_OK on success
433 * JB_ERR_MEMORY on out-of-memory error.
435 *********************************************************************/
436 jb_err cgi_send_banner(struct client_state *csp,
437 struct http_response *rsp,
438 const struct map *parameters)
440 char imagetype = lookup(parameters, "type")[0];
443 * If type is auto, then determine the right thing
444 * to do from the set-image-blocker action
446 if (imagetype == 'a')
453 #ifdef FEATURE_IMAGE_BLOCKING
454 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
456 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
457 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
458 const char *p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
462 /* Use default - nothing to do here. */
464 else if (0 == strcmpic(p, "blank"))
468 else if (0 == strcmpic(p, "pattern"))
474 * If the action is to call this CGI, determine
477 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
479 imagetype = p[sizeof(prefix1) - 1];
481 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
483 imagetype = p[sizeof(prefix2) - 1];
487 * Everything else must (should) be a URL to
495 #endif /* def FEATURE_IMAGE_BLOCKING */
499 * Now imagetype is either the non-auto type we were called with,
500 * or it was auto and has since been determined. In any case, we
501 * can proceed to actually answering the request by sending a redirect
502 * or an image as appropriate:
504 if (imagetype == 'r')
506 rsp->status = strdup("302 Local Redirect from Privoxy");
507 if (rsp->status == NULL)
509 return JB_ERR_MEMORY;
511 if (enlist_unique_header(rsp->headers, "Location",
512 csp->action->string[ACTION_STRING_IMAGE_BLOCKER]))
514 return JB_ERR_MEMORY;
519 if ((imagetype == 'b') || (imagetype == 't'))
521 rsp->body = bindup(image_blank_data, image_blank_length);
522 rsp->content_length = image_blank_length;
526 rsp->body = bindup(image_pattern_data, image_pattern_length);
527 rsp->content_length = image_pattern_length;
530 if (rsp->body == NULL)
532 return JB_ERR_MEMORY;
534 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
536 return JB_ERR_MEMORY;
547 /*********************************************************************
549 * Function : cgi_transparent_image
551 * Description : CGI function that sends a 1x1 transparent image.
554 * 1 : csp = Current client state (buffers, headers, etc...)
555 * 2 : rsp = http_response data structure for output
556 * 3 : parameters = map of cgi parameters
558 * CGI Parameters : None
560 * Returns : JB_ERR_OK on success
561 * JB_ERR_MEMORY on out-of-memory error.
563 *********************************************************************/
564 jb_err cgi_transparent_image(struct client_state *csp,
565 struct http_response *rsp,
566 const struct map *parameters)
568 rsp->body = bindup(image_blank_data, image_blank_length);
569 rsp->content_length = image_blank_length;
571 if (rsp->body == NULL)
573 return JB_ERR_MEMORY;
576 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
578 return JB_ERR_MEMORY;
588 /*********************************************************************
590 * Function : cgi_send_stylesheet
592 * Description : CGI function that sends a css stylesheet found
593 * in the cgi-style.css template
596 * 1 : csp = Current client state (buffers, headers, etc...)
597 * 2 : rsp = http_response data structure for output
598 * 3 : parameters = map of cgi parameters
600 * CGI Parameters : None
602 * Returns : JB_ERR_OK on success
603 * JB_ERR_MEMORY on out-of-memory error.
605 *********************************************************************/
606 jb_err cgi_send_stylesheet(struct client_state *csp,
607 struct http_response *rsp,
608 const struct map *parameters)
615 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
617 if (err == JB_ERR_FILE)
620 * No way to tell user; send empty stylesheet
622 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
626 return err; /* JB_ERR_MEMORY */
629 if (enlist(rsp->headers, "Content-Type: text/css"))
631 return JB_ERR_MEMORY;
639 /*********************************************************************
641 * Function : cgi_show_version
643 * Description : CGI function that returns a a web page describing the
644 * file versions of Privoxy.
647 * 1 : csp = Current client state (buffers, headers, etc...)
648 * 2 : rsp = http_response data structure for output
649 * 3 : parameters = map of cgi parameters
651 * CGI Parameters : none
653 * Returns : JB_ERR_OK on success
654 * JB_ERR_MEMORY on out-of-memory error.
656 *********************************************************************/
657 jb_err cgi_show_version(struct client_state *csp,
658 struct http_response *rsp,
659 const struct map *parameters)
667 if (NULL == (exports = default_exports(csp, "show-version")))
669 return JB_ERR_MEMORY;
672 if (map(exports, "sourceversions", 1, show_rcs(), 0))
675 return JB_ERR_MEMORY;
678 return template_fill_for_cgi(csp, "show-version", exports, rsp);
682 /*********************************************************************
684 * Function : cgi_show_status
686 * Description : CGI function that returns a a web page describing the
687 * current status of Privoxy.
690 * 1 : csp = Current client state (buffers, headers, etc...)
691 * 2 : rsp = http_response data structure for output
692 * 3 : parameters = map of cgi parameters
695 * file : Which file to show. Only first letter is checked,
697 * - "p"ermissions (actions) file
700 * Default is to show menu and other information.
702 * Returns : JB_ERR_OK on success
703 * JB_ERR_MEMORY on out-of-memory error.
705 *********************************************************************/
706 jb_err cgi_show_status(struct client_state *csp,
707 struct http_response *rsp,
708 const struct map *parameters)
715 char buf[BUFFER_SIZE];
716 const char * filename = NULL;
717 char * file_description = NULL;
718 #ifdef FEATURE_STATISTICS
719 float perc_rej; /* Percentage of http requests rejected */
721 int local_urls_rejected;
722 #endif /* ndef FEATURE_STATISTICS */
723 struct file_list * fl;
724 struct url_actions * b;
725 jb_err err = JB_ERR_OK;
733 if (NULL == (exports = default_exports(csp, "show-status")))
735 return JB_ERR_MEMORY;
738 switch (*(lookup(parameters, "file")))
741 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_ACTION_FILES && csp->actions_list[i])
743 filename = csp->actions_list[i]->filename;
744 file_description = "Actions File";
751 filename = csp->rlist->filename;
752 file_description = "Filter File";
760 filename = csp->tlist->filename;
761 file_description = "Trust File";
764 #endif /* def FEATURE_TRUST */
767 if (NULL != filename)
769 if ( map(exports, "file-description", 1, file_description, 1)
770 || map(exports, "filepath", 1, html_encode(filename), 0) )
773 return JB_ERR_MEMORY;
776 if ((fp = fopen(filename, "r")) == NULL)
778 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
781 return JB_ERR_MEMORY;
787 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
789 string_join (&s, html_encode(buf));
793 if (map(exports, "contents", 1, s, 0))
796 return JB_ERR_MEMORY;
800 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
804 for (j = 0; (s != NULL) && (j < Argc); j++)
806 if (!err) err = string_join (&s, html_encode(Argv[j]));
807 if (!err) err = string_append(&s, " ");
809 if (!err) err = map(exports, "invocation", 1, s, 0);
811 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
812 if (!err) err = show_defines(exports);
817 return JB_ERR_MEMORY;
820 #ifdef FEATURE_STATISTICS
821 local_urls_read = urls_read;
822 local_urls_rejected = urls_rejected;
825 * Need to alter the stats not to include the fetch of this
828 * Can't do following thread safely! doh!
831 * urls_rejected--; * This will be incremented subsequently *
834 if (local_urls_read == 0)
836 if (!err) err = map_block_killer(exports, "have-stats");
840 if (!err) err = map_block_killer(exports, "have-no-stats");
842 perc_rej = (float)local_urls_rejected * 100.0F /
843 (float)local_urls_read;
845 sprintf(buf, "%d", local_urls_read);
846 if (!err) err = map(exports, "requests-received", 1, buf, 1);
848 sprintf(buf, "%d", local_urls_rejected);
849 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
851 sprintf(buf, "%6.2f", perc_rej);
852 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
855 #else /* ndef FEATURE_STATISTICS */
856 err = err || map_block_killer(exports, "statistics");
857 #endif /* ndef FEATURE_STATISTICS */
860 * List all action files in use, together with view and edit links,
861 * except for standard.action, which should only be viewable. (Not
862 * enforced in the editor itself)
863 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
866 for (i = 0; i < MAX_ACTION_FILES; i++)
868 if (((fl = csp->actions_list[i]) != NULL) && ((b = fl->f) != NULL))
870 if (!err) err = string_append(&s, "<tr><td>");
871 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
872 snprintf(buf, 100, "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a> ", i);
873 if (!err) err = string_append(&s, buf);
875 if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
877 snprintf(buf, 100, "<a href=\"/edit-actions-list?f=%s\">Edit</a>", csp->config->actions_file_short[i]);
878 if (!err) err = string_append(&s, buf);
881 if (!err) err = string_append(&s, "</td></tr>\n");
886 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
890 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
895 if (!err) err = map(exports, "re-filter-filename", 1, html_encode(csp->rlist->filename), 0);
899 if (!err) err = map(exports, "re-filter-filename", 1, "None specified", 1);
900 if (!err) err = map_block_killer(exports, "have-filterfile");
906 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
910 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
911 if (!err) err = map_block_killer(exports, "have-trustfile");
914 if (!err) err = map_block_killer(exports, "trust-support");
915 #endif /* ndef FEATURE_TRUST */
920 return JB_ERR_MEMORY;
923 return template_fill_for_cgi(csp, "show-status", exports, rsp);
927 /*********************************************************************
929 * Function : cgi_show_url_info
931 * Description : CGI function that determines and shows which actions
932 * Privoxy will perform for a given url, and which
933 * matches starting from the defaults have lead to that.
936 * 1 : csp = Current client state (buffers, headers, etc...)
937 * 2 : rsp = http_response data structure for output
938 * 3 : parameters = map of cgi parameters
941 * url : The url whose actions are to be determined.
942 * If url is unset, the url-given conditional will be
943 * set, so that all but the form can be suppressed in
946 * Returns : JB_ERR_OK on success
947 * JB_ERR_MEMORY on out-of-memory error.
949 *********************************************************************/
950 jb_err cgi_show_url_info(struct client_state *csp,
951 struct http_response *rsp,
952 const struct map *parameters)
962 if (NULL == (exports = default_exports(csp, "show-url-info")))
964 return JB_ERR_MEMORY;
968 * Get the url= parameter (if present) and remove any leading/trailing spaces.
970 url_param = strdup(lookup(parameters, "url"));
971 if (url_param == NULL)
974 return JB_ERR_MEMORY;
979 * Handle prefixes. 4 possibilities:
980 * 1) "http://" or "https://" prefix present and followed by URL - OK
981 * 2) Only the "http://" or "https://" part is present, no URL - change
982 * to empty string so it will be detected later as "no URL".
983 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
985 * 4) Parameter not specified or is empty string - let this fall through
986 * for now, next block of code will handle it.
988 if (0 == strncmp(url_param, "http://", 7))
990 if (url_param[7] == '\0')
993 * Empty URL (just prefix).
994 * Make it totally empty so it's caught by the next if()
999 else if (0 == strncmp(url_param, "https://", 8))
1001 if (url_param[8] == '\0')
1004 * Empty URL (just prefix).
1005 * Make it totally empty so it's caught by the next if()
1007 url_param[0] = '\0';
1010 else if (url_param[0] != '\0')
1013 * Unknown prefix - assume http://
1015 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
1016 if (NULL == url_param_prefixed)
1020 return JB_ERR_MEMORY;
1022 strcpy(url_param_prefixed, "http://");
1023 strcpy(url_param_prefixed + 7, url_param);
1025 url_param = url_param_prefixed;
1029 if (url_param[0] == '\0')
1031 /* URL paramater not specified, display query form only. */
1033 if (map_block_killer(exports, "url-given")
1034 || map(exports, "url", 1, "", 1))
1037 return JB_ERR_MEMORY;
1042 /* Given a URL, so query it. */
1047 struct file_list *fl;
1048 struct url_actions *b;
1049 struct http_request url_to_query[1];
1050 struct current_action_spec action[1];
1053 if (map(exports, "url", 1, html_encode(url_param), 0))
1057 return JB_ERR_MEMORY;
1060 init_current_action(action);
1062 if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1064 free_current_action(action);
1067 return JB_ERR_MEMORY;
1070 err = parse_http_url(url_param, url_to_query, csp);
1074 if (err == JB_ERR_MEMORY)
1076 free_current_action(action);
1078 return JB_ERR_MEMORY;
1084 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1085 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1087 free_current_action(action);
1092 return JB_ERR_MEMORY;
1095 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1099 * We have a warning about SSL paths. Hide it for insecure sites.
1101 if (!url_to_query->ssl)
1103 if (map_block_killer(exports, "https"))
1105 free_current_action(action);
1107 return JB_ERR_MEMORY;
1111 matches = strdup("<table class=\"transparent\">");
1113 for (i = 0; i < MAX_ACTION_FILES; i++)
1115 if (NULL == csp->config->actions_file_short[i]
1116 || !strcmp(csp->config->actions_file_short[i], "standard")) continue;
1120 if ((fl = csp->actions_list[i]) != NULL)
1122 if ((b = fl->f) != NULL)
1124 /* FIXME: Hardcoded HTML! */
1125 string_append(&matches, "<tr><th>In file: ");
1126 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1127 snprintf(buf, 150, ".action <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1128 string_append(&matches, buf);
1129 string_append(&matches, "View</a> <a class=\"cmd\" href=\"/edit-actions-list?f=");
1130 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1131 string_append(&matches, "\">Edit</a></th></tr>\n");
1138 for (; (b != NULL) && (matches != NULL); b = b->next)
1140 if (url_match(b->url, url_to_query))
1142 string_append(&matches, "<tr><td>{");
1143 string_join (&matches, actions_to_html(csp, b->action));
1144 string_append(&matches, " }</b><br>\n<code>");
1145 string_join (&matches, html_encode(b->url->spec));
1146 string_append(&matches, "</code></td></tr>\n");
1148 if (merge_current_action(action, b->action))
1151 free_http_request(url_to_query);
1152 free_current_action(action);
1154 return JB_ERR_MEMORY;
1162 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1165 string_append(&matches, "</table>\n");
1167 free_http_request(url_to_query);
1169 if (matches == NULL)
1171 free_current_action(action);
1173 return JB_ERR_MEMORY;
1176 if (map(exports, "matches", 1, matches , 0))
1178 free_current_action(action);
1180 return JB_ERR_MEMORY;
1183 s = current_action_to_html(csp, action);
1185 free_current_action(action);
1187 if (map(exports, "final", 1, s, 0))
1190 return JB_ERR_MEMORY;
1194 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1198 /*********************************************************************
1200 * Function : cgi_robots_txt
1202 * Description : CGI function to return "/robots.txt".
1205 * 1 : csp = Current client state (buffers, headers, etc...)
1206 * 2 : rsp = http_response data structure for output
1207 * 3 : parameters = map of cgi parameters
1209 * CGI Parameters : None
1211 * Returns : JB_ERR_OK on success
1212 * JB_ERR_MEMORY on out-of-memory error.
1214 *********************************************************************/
1215 jb_err cgi_robots_txt(struct client_state *csp,
1216 struct http_response *rsp,
1217 const struct map *parameters)
1223 "# This is the Privoxy control interface.\n"
1224 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1230 if (rsp->body == NULL)
1232 return JB_ERR_MEMORY;
1235 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1239 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1240 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1242 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1246 /*********************************************************************
1248 * Function : show_defines
1250 * Description : Add to a map the state od all conditional #defines
1251 * used when building
1254 * 1 : exports = map to extend
1256 * Returns : JB_ERR_OK on success
1257 * JB_ERR_MEMORY on out-of-memory error.
1259 *********************************************************************/
1260 static jb_err show_defines(struct map *exports)
1262 jb_err err = JB_ERR_OK;
1265 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1266 #else /* ifndef FEATURE_ACL */
1267 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1268 #endif /* ndef FEATURE_ACL */
1270 #ifdef FEATURE_CGI_EDIT_ACTIONS
1271 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1272 #else /* ifndef FEATURE_COOKIE_JAR */
1273 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1274 #endif /* ndef FEATURE_COOKIE_JAR */
1276 #ifdef FEATURE_COOKIE_JAR
1277 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1278 #else /* ifndef FEATURE_COOKIE_JAR */
1279 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1280 #endif /* ndef FEATURE_COOKIE_JAR */
1282 #ifdef FEATURE_FAST_REDIRECTS
1283 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1284 #else /* ifndef FEATURE_FAST_REDIRECTS */
1285 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1286 #endif /* ndef FEATURE_FAST_REDIRECTS */
1288 #ifdef FEATURE_FORCE_LOAD
1289 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1290 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1291 #else /* ifndef FEATURE_FORCE_LOAD */
1292 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1293 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1294 #endif /* ndef FEATURE_FORCE_LOAD */
1296 #ifdef FEATURE_IMAGE_BLOCKING
1297 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1298 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1299 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1300 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1302 #ifdef FEATURE_IMAGE_DETECT_MSIE
1303 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1304 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1305 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1306 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1308 #ifdef FEATURE_KILL_POPUPS
1309 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1310 #else /* ifndef FEATURE_KILL_POPUPS */
1311 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1312 #endif /* ndef FEATURE_KILL_POPUPS */
1314 #ifdef FEATURE_NO_GIFS
1315 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1316 #else /* ifndef FEATURE_NO_GIFS */
1317 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1318 #endif /* ndef FEATURE_NO_GIFS */
1320 #ifdef FEATURE_PTHREAD
1321 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1322 #else /* ifndef FEATURE_PTHREAD */
1323 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1324 #endif /* ndef FEATURE_PTHREAD */
1326 #ifdef FEATURE_STATISTICS
1327 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1328 #else /* ifndef FEATURE_STATISTICS */
1329 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1330 #endif /* ndef FEATURE_STATISTICS */
1332 #ifdef FEATURE_TOGGLE
1333 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1334 #else /* ifndef FEATURE_TOGGLE */
1335 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1336 #endif /* ndef FEATURE_TOGGLE */
1338 #ifdef FEATURE_TRUST
1339 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1340 #else /* ifndef FEATURE_TRUST */
1341 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1342 #endif /* ndef FEATURE_TRUST */
1345 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1346 #else /* ifndef STATIC_PCRE */
1347 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1348 #endif /* ndef STATIC_PCRE */
1351 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1352 #else /* ifndef STATIC_PCRS */
1353 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1354 #endif /* ndef STATIC_PCRS */
1360 /*********************************************************************
1362 * Function : show_rcs
1364 * Description : Create a string with the rcs info for all sourcefiles
1368 * Returns : A string, or NULL on out-of-memory.
1370 *********************************************************************/
1371 static char *show_rcs(void)
1373 char *result = strdup("");
1374 char buf[BUFFER_SIZE];
1376 /* Instead of including *all* dot h's in the project (thus creating a
1377 * tremendous amount of dependencies), I will concede to declaring them
1378 * as extern's. This forces the developer to add to this list, but oh well.
1381 #define SHOW_RCS(__x) \
1383 extern const char __x[]; \
1384 sprintf(buf, "%s\n", __x); \
1385 string_append(&result, buf); \
1388 /* In alphabetical order */
1389 SHOW_RCS(actions_h_rcs)
1390 SHOW_RCS(actions_rcs)
1392 SHOW_RCS(amiga_h_rcs)
1394 #endif /* def AMIGA */
1397 #ifdef FEATURE_CGI_EDIT_ACTIONS
1398 SHOW_RCS(cgiedit_h_rcs)
1399 SHOW_RCS(cgiedit_rcs)
1400 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1401 SHOW_RCS(cgisimple_h_rcs)
1402 SHOW_RCS(cgisimple_rcs)
1404 SHOW_RCS(cygwin_h_rcs)
1406 SHOW_RCS(deanimate_h_rcs)
1407 SHOW_RCS(deanimate_rcs)
1408 SHOW_RCS(encode_h_rcs)
1409 SHOW_RCS(encode_rcs)
1410 SHOW_RCS(errlog_h_rcs)
1411 SHOW_RCS(errlog_rcs)
1412 SHOW_RCS(filters_h_rcs)
1413 SHOW_RCS(filters_rcs)
1414 SHOW_RCS(gateway_h_rcs)
1415 SHOW_RCS(gateway_rcs)
1416 #ifdef FEATURE_ACTIVITY_CONSOLE
1418 #endif /* def FEATURE_ACTIVITY_CONSOLE */
1419 SHOW_RCS(jbsockets_h_rcs)
1420 SHOW_RCS(jbsockets_rcs)
1423 #ifdef FEATURE_KILL_POPUPS
1424 SHOW_RCS(killpopup_h_rcs)
1425 SHOW_RCS(killpopup_rcs)
1426 #endif /* def FEATURE_KILL_POPUPS */
1427 SHOW_RCS(list_h_rcs)
1429 SHOW_RCS(loadcfg_h_rcs)
1430 SHOW_RCS(loadcfg_rcs)
1431 SHOW_RCS(loaders_h_rcs)
1432 SHOW_RCS(loaders_rcs)
1433 SHOW_RCS(miscutil_h_rcs)
1434 SHOW_RCS(miscutil_rcs)
1435 SHOW_RCS(parsers_h_rcs)
1436 SHOW_RCS(parsers_rcs)
1438 SHOW_RCS(pcrs_h_rcs)
1439 SHOW_RCS(project_h_rcs)
1440 SHOW_RCS(ssplit_h_rcs)
1441 SHOW_RCS(ssplit_rcs)
1442 #ifdef FEATURE_ACTIVITY_CONSOLE
1443 SHOW_RCS(stats_h_rcs)
1445 #endif /* def FEATURE_ACTIVITY_CONSOLE */
1446 SHOW_RCS(urlmatch_h_rcs)
1447 SHOW_RCS(urlmatch_rcs)
1449 #ifndef _WIN_CONSOLE
1450 SHOW_RCS(w32log_h_rcs)
1451 SHOW_RCS(w32log_rcs)
1452 SHOW_RCS(w32res_h_rcs)
1453 SHOW_RCS(w32taskbar_h_rcs)
1454 SHOW_RCS(w32taskbar_rcs)
1455 #endif /* ndef _WIN_CONSOLE */
1456 SHOW_RCS(win32_h_rcs)
1458 #endif /* def _WIN32 */