1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.35.2.1 2002/07/01 17:32:04 morcego Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/Attic/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.35.2.1 2002/07/01 17:32:04 morcego
40 * Applying patch from Andreas as provided by Hal on the list.
41 * Message-ID: <20020701121218.V1606@feenix.burgiss.net>
43 * Revision 1.35 2002/05/12 21:44:44 jongfoster
44 * Adding amiga.[ch] revision information, if on an amiga.
46 * Revision 1.34 2002/04/30 12:06:12 oes
47 * Deleted unused code from default_cgi
49 * Revision 1.33 2002/04/30 11:14:52 oes
50 * Made csp the first parameter in *action_to_html
52 * Revision 1.32 2002/04/26 18:29:13 jongfoster
53 * Fixing this Visual C++ warning:
54 * cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
56 * Revision 1.31 2002/04/26 12:54:36 oes
57 * - Kill obsolete REDIRECT_URL code
58 * - Error handling fixes
59 * - Style sheet related HTML snipplet changes
60 * - cgi_show_url_info:
61 * - Matches now in table, actions on single lines,
63 * - standard.action suppressed
64 * - Buttons to View and Edit AFs
66 * Revision 1.30 2002/04/24 02:18:08 oes
67 * - show-status is now the starting point for editing
68 * the actions files, generate list of all AFs with buttons
69 * for viewing and editing, new look for file list (Jon:
70 * buttons now aligned ;-P ), view mode now supports multiple
71 * AFs, name changes, no view links for unspecified files,
72 * no edit link for standard.action.
74 * - Jon's multiple AF patch: cgi_show_url_info now uses all
75 * AFs and marks the output accordingly
77 * Revision 1.29 2002/04/10 13:38:35 oes
78 * load_template signature changed
80 * Revision 1.28 2002/04/07 15:42:12 jongfoster
81 * Fixing send-banner?type=auto when the image-blocker is
82 * a redirect to send-banner
84 * Revision 1.27 2002/04/05 15:50:48 oes
85 * added send-stylesheet CGI
87 * Revision 1.26 2002/04/04 00:36:36 gliptak
88 * always use pcre for matching
90 * Revision 1.25 2002/04/03 22:28:03 gliptak
91 * Removed references to gnu_regex
93 * Revision 1.24 2002/04/02 16:12:47 oes
94 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
96 * Revision 1.23 2002/03/26 22:29:54 swa
97 * we have a new homepage!
99 * Revision 1.22 2002/03/24 16:18:15 jongfoster
102 * Revision 1.21 2002/03/24 15:23:33 jongfoster
105 * Revision 1.20 2002/03/24 13:25:43 swa
106 * name change related issues
108 * Revision 1.19 2002/03/16 23:54:06 jongfoster
109 * Adding graceful termination feature, to help look for memory leaks.
110 * If you enable this (which, by design, has to be done by hand
111 * editing config.h) and then go to http://i.j.b/die, then the program
112 * will exit cleanly after the *next* request. It should free all the
113 * memory that was used.
115 * Revision 1.18 2002/03/12 01:44:49 oes
116 * Changed default for "blocked" image from jb logo to checkboard pattern
118 * Revision 1.17 2002/03/08 16:43:18 oes
119 * Added choice beween GIF and PNG built-in images
121 * Revision 1.16 2002/03/07 03:48:38 oes
122 * - Changed built-in images from GIF to PNG
123 * (with regard to Unisys patent issue)
124 * - Added a 4x4 pattern PNG which is less intrusive
125 * than the logo but also clearly marks the deleted banners
127 * Revision 1.15 2002/03/06 22:54:35 jongfoster
128 * Automated function-comment nitpicking.
130 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
131 * Clean up a little CRLF unpleasantness that suddenly appeared
133 * Revision 1.13 2002/02/21 00:10:37 jongfoster
134 * Adding send-banner?type=auto option
136 * Revision 1.12 2002/01/23 01:03:32 jongfoster
137 * Fixing gcc [CygWin] compiler warnings
139 * Revision 1.11 2002/01/23 00:01:04 jongfoster
140 * Adding cgi_transparent_gif() for http://i.j.b/t
141 * Adding missing html_encode() to many CGI functions.
142 * Adding urlmatch.[ch] to http://i.j.b/show-version
144 * Revision 1.10 2002/01/17 21:10:37 jongfoster
145 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
146 * Also fixing a problem in the same function with improperly quoted URLs
147 * in output HTML, and adding code to handle https:// URLs correctly.
149 * Revision 1.9 2001/11/30 23:09:15 jongfoster
150 * Now reports on FEATURE_CGI_EDIT_ACTIONS
151 * Removing FEATURE_DENY_GZIP from template
153 * Revision 1.8 2001/11/13 00:14:07 jongfoster
154 * Fixing stupid bug now I've figured out what || means.
155 * (It always returns 0 or 1, not one of it's paramaters.)
157 * Revision 1.7 2001/10/23 21:48:19 jongfoster
158 * Cleaning up error handling in CGI functions - they now send back
159 * a HTML error page and should never cause a FATAL error. (Fixes one
160 * potential source of "denial of service" attacks).
162 * CGI actions file editor that works and is actually useful.
164 * Ability to toggle JunkBuster remotely using a CGI call.
166 * You can turn off both the above features in the main configuration
167 * file, e.g. if you are running a multi-user proxy.
169 * Revision 1.6 2001/10/14 22:00:32 jongfoster
170 * Adding support for a 404 error when an invalid CGI page is requested.
172 * Revision 1.5 2001/10/07 15:30:41 oes
173 * Removed FEATURE_DENY_GZIP
175 * Revision 1.4 2001/10/02 15:31:12 oes
176 * Introduced show-request cgi
178 * Revision 1.3 2001/09/22 16:34:44 jongfoster
179 * Removing unneeded #includes
181 * Revision 1.2 2001/09/19 18:01:11 oes
182 * Fixed comments; cosmetics
184 * Revision 1.1 2001/09/16 17:08:54 jongfoster
185 * Moving simple CGI functions from cgi.c to new file cgisimple.c
188 **********************************************************************/
194 #include <sys/types.h>
201 #define snprintf _snprintf
202 #endif /* def _WIN32 */
206 #include "cgisimple.h"
212 #include "miscutil.h"
215 #include "urlmatch.h"
218 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
221 static char *show_rcs(void);
222 static jb_err show_defines(struct map *exports);
225 /*********************************************************************
227 * Function : cgi_default
229 * Description : CGI function that is called for the CGI_SITE_1_HOST
230 * and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
231 * Boring - only exports the default exports.
234 * 1 : csp = Current client state (buffers, headers, etc...)
235 * 2 : rsp = http_response data structure for output
236 * 3 : parameters = map of cgi parameters
238 * CGI Parameters : none
240 * Returns : JB_ERR_OK on success
241 * JB_ERR_MEMORY on out-of-memory
243 *********************************************************************/
244 jb_err cgi_default(struct client_state *csp,
245 struct http_response *rsp,
246 const struct map *parameters)
253 if (NULL == (exports = default_exports(csp, "")))
255 return JB_ERR_MEMORY;
258 return template_fill_for_cgi(csp, "default", exports, rsp);
262 /*********************************************************************
264 * Function : cgi_error_404
266 * Description : CGI function that is called if an unknown action was
270 * 1 : csp = Current client state (buffers, headers, etc...)
271 * 2 : rsp = http_response data structure for output
272 * 3 : parameters = map of cgi parameters
274 * CGI Parameters : none
276 * Returns : JB_ERR_OK on success
277 * JB_ERR_MEMORY on out-of-memory error.
279 *********************************************************************/
280 jb_err cgi_error_404(struct client_state *csp,
281 struct http_response *rsp,
282 const struct map *parameters)
290 if (NULL == (exports = default_exports(csp, NULL)))
292 return JB_ERR_MEMORY;
295 rsp->status = strdup("404 Privoxy configuration page not found");
296 if (rsp->status == NULL)
299 return JB_ERR_MEMORY;
302 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
306 #ifdef FEATURE_GRACEFUL_TERMINATION
307 /*********************************************************************
311 * Description : CGI function to shut down Privoxy.
312 * NOTE: Turning this on in a production build
313 * would be a BAD idea. An EXTREMELY BAD idea.
314 * In short, don't do it.
317 * 1 : csp = Current client state (buffers, headers, etc...)
318 * 2 : rsp = http_response data structure for output
319 * 3 : parameters = map of cgi parameters
321 * CGI Parameters : none
323 * Returns : JB_ERR_OK on success
324 * JB_ERR_MEMORY on out-of-memory error.
326 *********************************************************************/
327 jb_err cgi_die (struct client_state *csp,
328 struct http_response *rsp,
329 const struct map *parameters)
339 * I don't really care what gets sent back to the browser.
340 * Take the easy option - "out of memory" page.
343 return JB_ERR_MEMORY;
345 #endif /* def FEATURE_GRACEFUL_TERMINATION */
348 /*********************************************************************
350 * Function : cgi_show_request
352 * Description : Show the client's request and what sed() would have
356 * 1 : csp = Current client state (buffers, headers, etc...)
357 * 2 : rsp = http_response data structure for output
358 * 3 : parameters = map of cgi parameters
360 * CGI Parameters : none
362 * Returns : JB_ERR_OK on success
363 * JB_ERR_MEMORY on out-of-memory error.
365 *********************************************************************/
366 jb_err cgi_show_request(struct client_state *csp,
367 struct http_response *rsp,
368 const struct map *parameters)
377 if (NULL == (exports = default_exports(csp, "show-request")))
379 return JB_ERR_MEMORY;
383 * Repair the damage done to the IOB by get_header()
385 for (p = csp->iob->buf; p < csp->iob->eod; p++)
387 if (*p == '\0') *p = '\n';
391 * Export the original client's request and the one we would
392 * be sending to the server if this wasn't a CGI call
395 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
398 return JB_ERR_MEMORY;
401 if (map(exports, "processed-request", 1, html_encode_and_free_original(
402 sed(client_patterns, add_client_headers, csp)), 0))
405 return JB_ERR_MEMORY;
408 return template_fill_for_cgi(csp, "show-request", exports, rsp);
412 /*********************************************************************
414 * Function : cgi_send_banner
416 * Description : CGI function that returns a banner.
419 * 1 : csp = Current client state (buffers, headers, etc...)
420 * 2 : rsp = http_response data structure for output
421 * 3 : parameters = map of cgi parameters
424 * type : Selects the type of banner between "trans", "logo",
425 * and "auto". Defaults to "logo" if absent or invalid.
426 * "auto" means to select as if we were image-blocking.
427 * (Only the first character really counts; b and t are
430 * Returns : JB_ERR_OK on success
431 * JB_ERR_MEMORY on out-of-memory error.
433 *********************************************************************/
434 jb_err cgi_send_banner(struct client_state *csp,
435 struct http_response *rsp,
436 const struct map *parameters)
438 char imagetype = lookup(parameters, "type")[0];
441 * If type is auto, then determine the right thing
442 * to do from the set-image-blocker action
444 if (imagetype == 'a')
451 #ifdef FEATURE_IMAGE_BLOCKING
452 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
454 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
455 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
456 const char *p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
460 /* Use default - nothing to do here. */
462 else if (0 == strcmpic(p, "blank"))
466 else if (0 == strcmpic(p, "pattern"))
472 * If the action is to call this CGI, determine
475 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
477 imagetype = p[sizeof(prefix1) - 1];
479 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
481 imagetype = p[sizeof(prefix2) - 1];
485 * Everything else must (should) be a URL to
493 #endif /* def FEATURE_IMAGE_BLOCKING */
497 * Now imagetype is either the non-auto type we were called with,
498 * or it was auto and has since been determined. In any case, we
499 * can proceed to actually answering the request by sending a redirect
500 * or an image as appropriate:
502 if (imagetype == 'r')
504 rsp->status = strdup("302 Local Redirect from Privoxy");
505 if (rsp->status == NULL)
507 return JB_ERR_MEMORY;
509 if (enlist_unique_header(rsp->headers, "Location",
510 csp->action->string[ACTION_STRING_IMAGE_BLOCKER]))
512 return JB_ERR_MEMORY;
517 if ((imagetype == 'b') || (imagetype == 't'))
519 rsp->body = bindup(image_blank_data, image_blank_length);
520 rsp->content_length = image_blank_length;
524 rsp->body = bindup(image_pattern_data, image_pattern_length);
525 rsp->content_length = image_pattern_length;
528 if (rsp->body == NULL)
530 return JB_ERR_MEMORY;
532 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
534 return JB_ERR_MEMORY;
545 /*********************************************************************
547 * Function : cgi_transparent_image
549 * Description : CGI function that sends a 1x1 transparent image.
552 * 1 : csp = Current client state (buffers, headers, etc...)
553 * 2 : rsp = http_response data structure for output
554 * 3 : parameters = map of cgi parameters
556 * CGI Parameters : None
558 * Returns : JB_ERR_OK on success
559 * JB_ERR_MEMORY on out-of-memory error.
561 *********************************************************************/
562 jb_err cgi_transparent_image(struct client_state *csp,
563 struct http_response *rsp,
564 const struct map *parameters)
566 rsp->body = bindup(image_blank_data, image_blank_length);
567 rsp->content_length = image_blank_length;
569 if (rsp->body == NULL)
571 return JB_ERR_MEMORY;
574 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
576 return JB_ERR_MEMORY;
586 /*********************************************************************
588 * Function : cgi_send_stylesheet
590 * Description : CGI function that sends a css stylesheet found
591 * in the cgi-style.css template
594 * 1 : csp = Current client state (buffers, headers, etc...)
595 * 2 : rsp = http_response data structure for output
596 * 3 : parameters = map of cgi parameters
598 * CGI Parameters : None
600 * Returns : JB_ERR_OK on success
601 * JB_ERR_MEMORY on out-of-memory error.
603 *********************************************************************/
604 jb_err cgi_send_stylesheet(struct client_state *csp,
605 struct http_response *rsp,
606 const struct map *parameters)
613 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
615 if (err == JB_ERR_FILE)
618 * No way to tell user; send empty stylesheet
620 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
624 return err; /* JB_ERR_MEMORY */
627 if (enlist(rsp->headers, "Content-Type: text/css"))
629 return JB_ERR_MEMORY;
637 /*********************************************************************
639 * Function : cgi_show_version
641 * Description : CGI function that returns a a web page describing the
642 * file versions of Privoxy.
645 * 1 : csp = Current client state (buffers, headers, etc...)
646 * 2 : rsp = http_response data structure for output
647 * 3 : parameters = map of cgi parameters
649 * CGI Parameters : none
651 * Returns : JB_ERR_OK on success
652 * JB_ERR_MEMORY on out-of-memory error.
654 *********************************************************************/
655 jb_err cgi_show_version(struct client_state *csp,
656 struct http_response *rsp,
657 const struct map *parameters)
665 if (NULL == (exports = default_exports(csp, "show-version")))
667 return JB_ERR_MEMORY;
670 if (map(exports, "sourceversions", 1, show_rcs(), 0))
673 return JB_ERR_MEMORY;
676 return template_fill_for_cgi(csp, "show-version", exports, rsp);
680 /*********************************************************************
682 * Function : cgi_show_status
684 * Description : CGI function that returns a a web page describing the
685 * current status of Privoxy.
688 * 1 : csp = Current client state (buffers, headers, etc...)
689 * 2 : rsp = http_response data structure for output
690 * 3 : parameters = map of cgi parameters
693 * file : Which file to show. Only first letter is checked,
695 * - "p"ermissions (actions) file
698 * Default is to show menu and other information.
700 * Returns : JB_ERR_OK on success
701 * JB_ERR_MEMORY on out-of-memory error.
703 *********************************************************************/
704 jb_err cgi_show_status(struct client_state *csp,
705 struct http_response *rsp,
706 const struct map *parameters)
713 char buf[BUFFER_SIZE];
714 const char * filename = NULL;
715 char * file_description = NULL;
716 #ifdef FEATURE_STATISTICS
717 float perc_rej; /* Percentage of http requests rejected */
719 int local_urls_rejected;
720 #endif /* ndef FEATURE_STATISTICS */
721 struct file_list * fl;
722 struct url_actions * b;
723 jb_err err = JB_ERR_OK;
731 if (NULL == (exports = default_exports(csp, "show-status")))
733 return JB_ERR_MEMORY;
736 switch (*(lookup(parameters, "file")))
739 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_ACTION_FILES && csp->actions_list[i])
741 filename = csp->actions_list[i]->filename;
742 file_description = "Actions File";
749 filename = csp->rlist->filename;
750 file_description = "Filter File";
758 filename = csp->tlist->filename;
759 file_description = "Trust File";
762 #endif /* def FEATURE_TRUST */
765 if (NULL != filename)
767 if ( map(exports, "file-description", 1, file_description, 1)
768 || map(exports, "filepath", 1, html_encode(filename), 0) )
771 return JB_ERR_MEMORY;
774 if ((fp = fopen(filename, "r")) == NULL)
776 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
779 return JB_ERR_MEMORY;
785 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
787 string_join (&s, html_encode(buf));
791 if (map(exports, "contents", 1, s, 0))
794 return JB_ERR_MEMORY;
798 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
802 for (j = 0; (s != NULL) && (j < Argc); j++)
804 if (!err) err = string_join (&s, html_encode(Argv[j]));
805 if (!err) err = string_append(&s, " ");
807 if (!err) err = map(exports, "invocation", 1, s, 0);
809 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
810 if (!err) err = show_defines(exports);
815 return JB_ERR_MEMORY;
818 #ifdef FEATURE_STATISTICS
819 local_urls_read = urls_read;
820 local_urls_rejected = urls_rejected;
823 * Need to alter the stats not to include the fetch of this
826 * Can't do following thread safely! doh!
829 * urls_rejected--; * This will be incremented subsequently *
832 if (local_urls_read == 0)
834 if (!err) err = map_block_killer(exports, "have-stats");
838 if (!err) err = map_block_killer(exports, "have-no-stats");
840 perc_rej = (float)local_urls_rejected * 100.0F /
841 (float)local_urls_read;
843 sprintf(buf, "%d", local_urls_read);
844 if (!err) err = map(exports, "requests-received", 1, buf, 1);
846 sprintf(buf, "%d", local_urls_rejected);
847 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
849 sprintf(buf, "%6.2f", perc_rej);
850 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
853 #else /* ndef FEATURE_STATISTICS */
854 err = err || map_block_killer(exports, "statistics");
855 #endif /* ndef FEATURE_STATISTICS */
858 * List all action files in use, together with view and edit links,
859 * except for standard.action, which should only be viewable. (Not
860 * enforced in the editor itself)
861 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
864 for (i = 0; i < MAX_ACTION_FILES; i++)
866 if (((fl = csp->actions_list[i]) != NULL) && ((b = fl->f) != NULL))
868 if (!err) err = string_append(&s, "<tr><td>");
869 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
870 snprintf(buf, 100, "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a> ", i);
871 if (!err) err = string_append(&s, buf);
873 if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
875 snprintf(buf, 100, "<a href=\"/edit-actions-list?f=%s\">Edit</a>", csp->config->actions_file_short[i]);
876 if (!err) err = string_append(&s, buf);
879 if (!err) err = string_append(&s, "</td></tr>\n");
884 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
888 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
893 if (!err) err = map(exports, "re-filter-filename", 1, html_encode(csp->rlist->filename), 0);
897 if (!err) err = map(exports, "re-filter-filename", 1, "None specified", 1);
898 if (!err) err = map_block_killer(exports, "have-filterfile");
904 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
908 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
909 if (!err) err = map_block_killer(exports, "have-trustfile");
912 if (!err) err = map_block_killer(exports, "trust-support");
913 #endif /* ndef FEATURE_TRUST */
918 return JB_ERR_MEMORY;
921 return template_fill_for_cgi(csp, "show-status", exports, rsp);
925 /*********************************************************************
927 * Function : cgi_show_url_info
929 * Description : CGI function that determines and shows which actions
930 * Privoxy will perform for a given url, and which
931 * matches starting from the defaults have lead to that.
934 * 1 : csp = Current client state (buffers, headers, etc...)
935 * 2 : rsp = http_response data structure for output
936 * 3 : parameters = map of cgi parameters
939 * url : The url whose actions are to be determined.
940 * If url is unset, the url-given conditional will be
941 * set, so that all but the form can be suppressed in
944 * Returns : JB_ERR_OK on success
945 * JB_ERR_MEMORY on out-of-memory error.
947 *********************************************************************/
948 jb_err cgi_show_url_info(struct client_state *csp,
949 struct http_response *rsp,
950 const struct map *parameters)
960 if (NULL == (exports = default_exports(csp, "show-url-info")))
962 return JB_ERR_MEMORY;
966 * Get the url= parameter (if present) and remove any leading/trailing spaces.
968 url_param = strdup(lookup(parameters, "url"));
969 if (url_param == NULL)
972 return JB_ERR_MEMORY;
977 * Handle prefixes. 4 possibilities:
978 * 1) "http://" or "https://" prefix present and followed by URL - OK
979 * 2) Only the "http://" or "https://" part is present, no URL - change
980 * to empty string so it will be detected later as "no URL".
981 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
983 * 4) Parameter not specified or is empty string - let this fall through
984 * for now, next block of code will handle it.
986 if (0 == strncmp(url_param, "http://", 7))
988 if (url_param[7] == '\0')
991 * Empty URL (just prefix).
992 * Make it totally empty so it's caught by the next if()
997 else if (0 == strncmp(url_param, "https://", 8))
999 if (url_param[8] == '\0')
1002 * Empty URL (just prefix).
1003 * Make it totally empty so it's caught by the next if()
1005 url_param[0] = '\0';
1008 else if (url_param[0] != '\0')
1011 * Unknown prefix - assume http://
1013 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
1014 if (NULL == url_param_prefixed)
1018 return JB_ERR_MEMORY;
1020 strcpy(url_param_prefixed, "http://");
1021 strcpy(url_param_prefixed + 7, url_param);
1023 url_param = url_param_prefixed;
1027 if (url_param[0] == '\0')
1029 /* URL paramater not specified, display query form only. */
1031 if (map_block_killer(exports, "url-given")
1032 || map(exports, "url", 1, "", 1))
1035 return JB_ERR_MEMORY;
1040 /* Given a URL, so query it. */
1045 struct file_list *fl;
1046 struct url_actions *b;
1047 struct http_request url_to_query[1];
1048 struct current_action_spec action[1];
1051 if (map(exports, "url", 1, html_encode(url_param), 0))
1055 return JB_ERR_MEMORY;
1058 init_current_action(action);
1060 if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1062 free_current_action(action);
1065 return JB_ERR_MEMORY;
1068 err = parse_http_url(url_param, url_to_query, csp);
1072 if (err == JB_ERR_MEMORY)
1074 free_current_action(action);
1076 return JB_ERR_MEMORY;
1082 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1083 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1085 free_current_action(action);
1090 return JB_ERR_MEMORY;
1093 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1097 * We have a warning about SSL paths. Hide it for insecure sites.
1099 if (!url_to_query->ssl)
1101 if (map_block_killer(exports, "https"))
1103 free_current_action(action);
1105 return JB_ERR_MEMORY;
1109 matches = strdup("<table class=\"transparent\">");
1111 for (i = 0; i < MAX_ACTION_FILES; i++)
1113 if (NULL == csp->config->actions_file_short[i]
1114 || !strcmp(csp->config->actions_file_short[i], "standard")) continue;
1118 if ((fl = csp->actions_list[i]) != NULL)
1120 if ((b = fl->f) != NULL)
1122 /* FIXME: Hardcoded HTML! */
1123 string_append(&matches, "<tr><th>In file: ");
1124 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1125 snprintf(buf, 150, ".action <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1126 string_append(&matches, buf);
1127 string_append(&matches, "View</a> <a class=\"cmd\" href=\"/edit-actions-list?f=");
1128 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1129 string_append(&matches, "\">Edit</a></th></tr>\n");
1136 for (; (b != NULL) && (matches != NULL); b = b->next)
1138 if (url_match(b->url, url_to_query))
1140 string_append(&matches, "<tr><td>{");
1141 string_join (&matches, actions_to_html(csp, b->action));
1142 string_append(&matches, " }</b><br>\n<code>");
1143 string_join (&matches, html_encode(b->url->spec));
1144 string_append(&matches, "</code></td></tr>\n");
1146 if (merge_current_action(action, b->action))
1149 free_http_request(url_to_query);
1150 free_current_action(action);
1152 return JB_ERR_MEMORY;
1160 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1163 string_append(&matches, "</table>\n");
1165 free_http_request(url_to_query);
1167 if (matches == NULL)
1169 free_current_action(action);
1171 return JB_ERR_MEMORY;
1174 if (map(exports, "matches", 1, matches , 0))
1176 free_current_action(action);
1178 return JB_ERR_MEMORY;
1181 s = current_action_to_html(csp, action);
1183 free_current_action(action);
1185 if (map(exports, "final", 1, s, 0))
1188 return JB_ERR_MEMORY;
1192 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1196 /*********************************************************************
1198 * Function : cgi_robots_txt
1200 * Description : CGI function to return "/robots.txt".
1203 * 1 : csp = Current client state (buffers, headers, etc...)
1204 * 2 : rsp = http_response data structure for output
1205 * 3 : parameters = map of cgi parameters
1207 * CGI Parameters : None
1209 * Returns : JB_ERR_OK on success
1210 * JB_ERR_MEMORY on out-of-memory error.
1212 *********************************************************************/
1213 jb_err cgi_robots_txt(struct client_state *csp,
1214 struct http_response *rsp,
1215 const struct map *parameters)
1221 "# This is the Privoxy control interface.\n"
1222 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1228 if (rsp->body == NULL)
1230 return JB_ERR_MEMORY;
1233 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1237 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1238 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1240 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1244 /*********************************************************************
1246 * Function : show_defines
1248 * Description : Add to a map the state od all conditional #defines
1249 * used when building
1252 * 1 : exports = map to extend
1254 * Returns : JB_ERR_OK on success
1255 * JB_ERR_MEMORY on out-of-memory error.
1257 *********************************************************************/
1258 static jb_err show_defines(struct map *exports)
1260 jb_err err = JB_ERR_OK;
1263 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1264 #else /* ifndef FEATURE_ACL */
1265 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1266 #endif /* ndef FEATURE_ACL */
1268 #ifdef FEATURE_CGI_EDIT_ACTIONS
1269 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1270 #else /* ifndef FEATURE_COOKIE_JAR */
1271 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1272 #endif /* ndef FEATURE_COOKIE_JAR */
1274 #ifdef FEATURE_COOKIE_JAR
1275 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1276 #else /* ifndef FEATURE_COOKIE_JAR */
1277 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1278 #endif /* ndef FEATURE_COOKIE_JAR */
1280 #ifdef FEATURE_FAST_REDIRECTS
1281 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1282 #else /* ifndef FEATURE_FAST_REDIRECTS */
1283 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1284 #endif /* ndef FEATURE_FAST_REDIRECTS */
1286 #ifdef FEATURE_FORCE_LOAD
1287 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1288 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1289 #else /* ifndef FEATURE_FORCE_LOAD */
1290 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1291 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1292 #endif /* ndef FEATURE_FORCE_LOAD */
1294 #ifdef FEATURE_IMAGE_BLOCKING
1295 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1296 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1297 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1298 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1300 #ifdef FEATURE_IMAGE_DETECT_MSIE
1301 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1302 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1303 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1304 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1306 #ifdef FEATURE_KILL_POPUPS
1307 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1308 #else /* ifndef FEATURE_KILL_POPUPS */
1309 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1310 #endif /* ndef FEATURE_KILL_POPUPS */
1312 #ifdef FEATURE_NO_GIFS
1313 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1314 #else /* ifndef FEATURE_NO_GIFS */
1315 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1316 #endif /* ndef FEATURE_NO_GIFS */
1318 #ifdef FEATURE_PTHREAD
1319 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1320 #else /* ifndef FEATURE_PTHREAD */
1321 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1322 #endif /* ndef FEATURE_PTHREAD */
1324 #ifdef FEATURE_STATISTICS
1325 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1326 #else /* ifndef FEATURE_STATISTICS */
1327 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1328 #endif /* ndef FEATURE_STATISTICS */
1330 #ifdef FEATURE_TOGGLE
1331 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1332 #else /* ifndef FEATURE_TOGGLE */
1333 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1334 #endif /* ndef FEATURE_TOGGLE */
1336 #ifdef FEATURE_TRUST
1337 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1338 #else /* ifndef FEATURE_TRUST */
1339 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1340 #endif /* ndef FEATURE_TRUST */
1343 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1344 #else /* ifndef STATIC_PCRE */
1345 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1346 #endif /* ndef STATIC_PCRE */
1349 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1350 #else /* ifndef STATIC_PCRS */
1351 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1352 #endif /* ndef STATIC_PCRS */
1358 /*********************************************************************
1360 * Function : show_rcs
1362 * Description : Create a string with the rcs info for all sourcefiles
1366 * Returns : A string, or NULL on out-of-memory.
1368 *********************************************************************/
1369 static char *show_rcs(void)
1371 char *result = strdup("");
1372 char buf[BUFFER_SIZE];
1374 /* Instead of including *all* dot h's in the project (thus creating a
1375 * tremendous amount of dependencies), I will concede to declaring them
1376 * as extern's. This forces the developer to add to this list, but oh well.
1379 #define SHOW_RCS(__x) \
1381 extern const char __x[]; \
1382 sprintf(buf, "%s\n", __x); \
1383 string_append(&result, buf); \
1386 /* In alphabetical order */
1387 SHOW_RCS(actions_h_rcs)
1388 SHOW_RCS(actions_rcs)
1390 SHOW_RCS(amiga_h_rcs)
1392 #endif /* def AMIGA */
1395 #ifdef FEATURE_CGI_EDIT_ACTIONS
1396 SHOW_RCS(cgiedit_h_rcs)
1397 SHOW_RCS(cgiedit_rcs)
1398 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1399 SHOW_RCS(cgisimple_h_rcs)
1400 SHOW_RCS(cgisimple_rcs)
1402 SHOW_RCS(cygwin_h_rcs)
1404 SHOW_RCS(deanimate_h_rcs)
1405 SHOW_RCS(deanimate_rcs)
1406 SHOW_RCS(encode_h_rcs)
1407 SHOW_RCS(encode_rcs)
1408 SHOW_RCS(errlog_h_rcs)
1409 SHOW_RCS(errlog_rcs)
1410 SHOW_RCS(filters_h_rcs)
1411 SHOW_RCS(filters_rcs)
1412 SHOW_RCS(gateway_h_rcs)
1413 SHOW_RCS(gateway_rcs)
1414 SHOW_RCS(jbsockets_h_rcs)
1415 SHOW_RCS(jbsockets_rcs)
1418 #ifdef FEATURE_KILL_POPUPS
1419 SHOW_RCS(killpopup_h_rcs)
1420 SHOW_RCS(killpopup_rcs)
1421 #endif /* def FEATURE_KILL_POPUPS */
1422 SHOW_RCS(list_h_rcs)
1424 SHOW_RCS(loadcfg_h_rcs)
1425 SHOW_RCS(loadcfg_rcs)
1426 SHOW_RCS(loaders_h_rcs)
1427 SHOW_RCS(loaders_rcs)
1428 SHOW_RCS(miscutil_h_rcs)
1429 SHOW_RCS(miscutil_rcs)
1430 SHOW_RCS(parsers_h_rcs)
1431 SHOW_RCS(parsers_rcs)
1433 SHOW_RCS(pcrs_h_rcs)
1434 SHOW_RCS(project_h_rcs)
1435 SHOW_RCS(ssplit_h_rcs)
1436 SHOW_RCS(ssplit_rcs)
1437 SHOW_RCS(urlmatch_h_rcs)
1438 SHOW_RCS(urlmatch_rcs)
1440 #ifndef _WIN_CONSOLE
1441 SHOW_RCS(w32log_h_rcs)
1442 SHOW_RCS(w32log_rcs)
1443 SHOW_RCS(w32res_h_rcs)
1444 SHOW_RCS(w32taskbar_h_rcs)
1445 SHOW_RCS(w32taskbar_rcs)
1446 #endif /* ndef _WIN_CONSOLE */
1447 SHOW_RCS(win32_h_rcs)
1449 #endif /* def _WIN32 */