1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.35.2.2 2003/04/03 13:48:28 oes 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.2 2003/04/03 13:48:28 oes
40 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
42 * Revision 1.35.2.1 2002/07/04 15:02:38 oes
43 * Added ability to send redirects to send-banner CGI, so that it can completely mimic the image blocking action if called with type=auto
45 * Revision 1.35.2.1 2002/07/01 17:32:04 morcego
46 * Applying patch from Andreas as provided by Hal on the list.
47 * Message-ID: <20020701121218.V1606@feenix.burgiss.net>
49 * Revision 1.35 2002/05/12 21:44:44 jongfoster
50 * Adding amiga.[ch] revision information, if on an amiga.
52 * Revision 1.34 2002/04/30 12:06:12 oes
53 * Deleted unused code from default_cgi
55 * Revision 1.33 2002/04/30 11:14:52 oes
56 * Made csp the first parameter in *action_to_html
58 * Revision 1.32 2002/04/26 18:29:13 jongfoster
59 * Fixing this Visual C++ warning:
60 * cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
62 * Revision 1.31 2002/04/26 12:54:36 oes
63 * - Kill obsolete REDIRECT_URL code
64 * - Error handling fixes
65 * - Style sheet related HTML snipplet changes
66 * - cgi_show_url_info:
67 * - Matches now in table, actions on single lines,
69 * - standard.action suppressed
70 * - Buttons to View and Edit AFs
72 * Revision 1.30 2002/04/24 02:18:08 oes
73 * - show-status is now the starting point for editing
74 * the actions files, generate list of all AFs with buttons
75 * for viewing and editing, new look for file list (Jon:
76 * buttons now aligned ;-P ), view mode now supports multiple
77 * AFs, name changes, no view links for unspecified files,
78 * no edit link for standard.action.
80 * - Jon's multiple AF patch: cgi_show_url_info now uses all
81 * AFs and marks the output accordingly
83 * Revision 1.29 2002/04/10 13:38:35 oes
84 * load_template signature changed
86 * Revision 1.28 2002/04/07 15:42:12 jongfoster
87 * Fixing send-banner?type=auto when the image-blocker is
88 * a redirect to send-banner
90 * Revision 1.27 2002/04/05 15:50:48 oes
91 * added send-stylesheet CGI
93 * Revision 1.26 2002/04/04 00:36:36 gliptak
94 * always use pcre for matching
96 * Revision 1.25 2002/04/03 22:28:03 gliptak
97 * Removed references to gnu_regex
99 * Revision 1.24 2002/04/02 16:12:47 oes
100 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
102 * Revision 1.23 2002/03/26 22:29:54 swa
103 * we have a new homepage!
105 * Revision 1.22 2002/03/24 16:18:15 jongfoster
108 * Revision 1.21 2002/03/24 15:23:33 jongfoster
111 * Revision 1.20 2002/03/24 13:25:43 swa
112 * name change related issues
114 * Revision 1.19 2002/03/16 23:54:06 jongfoster
115 * Adding graceful termination feature, to help look for memory leaks.
116 * If you enable this (which, by design, has to be done by hand
117 * editing config.h) and then go to http://i.j.b/die, then the program
118 * will exit cleanly after the *next* request. It should free all the
119 * memory that was used.
121 * Revision 1.18 2002/03/12 01:44:49 oes
122 * Changed default for "blocked" image from jb logo to checkboard pattern
124 * Revision 1.17 2002/03/08 16:43:18 oes
125 * Added choice beween GIF and PNG built-in images
127 * Revision 1.16 2002/03/07 03:48:38 oes
128 * - Changed built-in images from GIF to PNG
129 * (with regard to Unisys patent issue)
130 * - Added a 4x4 pattern PNG which is less intrusive
131 * than the logo but also clearly marks the deleted banners
133 * Revision 1.15 2002/03/06 22:54:35 jongfoster
134 * Automated function-comment nitpicking.
136 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
137 * Clean up a little CRLF unpleasantness that suddenly appeared
139 * Revision 1.13 2002/02/21 00:10:37 jongfoster
140 * Adding send-banner?type=auto option
142 * Revision 1.12 2002/01/23 01:03:32 jongfoster
143 * Fixing gcc [CygWin] compiler warnings
145 * Revision 1.11 2002/01/23 00:01:04 jongfoster
146 * Adding cgi_transparent_gif() for http://i.j.b/t
147 * Adding missing html_encode() to many CGI functions.
148 * Adding urlmatch.[ch] to http://i.j.b/show-version
150 * Revision 1.10 2002/01/17 21:10:37 jongfoster
151 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
152 * Also fixing a problem in the same function with improperly quoted URLs
153 * in output HTML, and adding code to handle https:// URLs correctly.
155 * Revision 1.9 2001/11/30 23:09:15 jongfoster
156 * Now reports on FEATURE_CGI_EDIT_ACTIONS
157 * Removing FEATURE_DENY_GZIP from template
159 * Revision 1.8 2001/11/13 00:14:07 jongfoster
160 * Fixing stupid bug now I've figured out what || means.
161 * (It always returns 0 or 1, not one of it's paramaters.)
163 * Revision 1.7 2001/10/23 21:48:19 jongfoster
164 * Cleaning up error handling in CGI functions - they now send back
165 * a HTML error page and should never cause a FATAL error. (Fixes one
166 * potential source of "denial of service" attacks).
168 * CGI actions file editor that works and is actually useful.
170 * Ability to toggle JunkBuster remotely using a CGI call.
172 * You can turn off both the above features in the main configuration
173 * file, e.g. if you are running a multi-user proxy.
175 * Revision 1.6 2001/10/14 22:00:32 jongfoster
176 * Adding support for a 404 error when an invalid CGI page is requested.
178 * Revision 1.5 2001/10/07 15:30:41 oes
179 * Removed FEATURE_DENY_GZIP
181 * Revision 1.4 2001/10/02 15:31:12 oes
182 * Introduced show-request cgi
184 * Revision 1.3 2001/09/22 16:34:44 jongfoster
185 * Removing unneeded #includes
187 * Revision 1.2 2001/09/19 18:01:11 oes
188 * Fixed comments; cosmetics
190 * Revision 1.1 2001/09/16 17:08:54 jongfoster
191 * Moving simple CGI functions from cgi.c to new file cgisimple.c
194 **********************************************************************/
200 #include <sys/types.h>
207 #define snprintf _snprintf
208 #endif /* def _WIN32 */
212 #include "cgisimple.h"
218 #include "miscutil.h"
221 #include "urlmatch.h"
224 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
227 static char *show_rcs(void);
228 static jb_err show_defines(struct map *exports);
231 /*********************************************************************
233 * Function : cgi_default
235 * Description : CGI function that is called for the CGI_SITE_1_HOST
236 * and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
237 * Boring - only exports the default exports.
240 * 1 : csp = Current client state (buffers, headers, etc...)
241 * 2 : rsp = http_response data structure for output
242 * 3 : parameters = map of cgi parameters
244 * CGI Parameters : none
246 * Returns : JB_ERR_OK on success
247 * JB_ERR_MEMORY on out-of-memory
249 *********************************************************************/
250 jb_err cgi_default(struct client_state *csp,
251 struct http_response *rsp,
252 const struct map *parameters)
259 if (NULL == (exports = default_exports(csp, "")))
261 return JB_ERR_MEMORY;
264 return template_fill_for_cgi(csp, "default", exports, rsp);
268 /*********************************************************************
270 * Function : cgi_error_404
272 * Description : CGI function that is called if an unknown action was
276 * 1 : csp = Current client state (buffers, headers, etc...)
277 * 2 : rsp = http_response data structure for output
278 * 3 : parameters = map of cgi parameters
280 * CGI Parameters : none
282 * Returns : JB_ERR_OK on success
283 * JB_ERR_MEMORY on out-of-memory error.
285 *********************************************************************/
286 jb_err cgi_error_404(struct client_state *csp,
287 struct http_response *rsp,
288 const struct map *parameters)
296 if (NULL == (exports = default_exports(csp, NULL)))
298 return JB_ERR_MEMORY;
301 rsp->status = strdup("404 Privoxy configuration page not found");
302 if (rsp->status == NULL)
305 return JB_ERR_MEMORY;
308 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
312 #ifdef FEATURE_GRACEFUL_TERMINATION
313 /*********************************************************************
317 * Description : CGI function to shut down Privoxy.
318 * NOTE: Turning this on in a production build
319 * would be a BAD idea. An EXTREMELY BAD idea.
320 * In short, don't do it.
323 * 1 : csp = Current client state (buffers, headers, etc...)
324 * 2 : rsp = http_response data structure for output
325 * 3 : parameters = map of cgi parameters
327 * CGI Parameters : none
329 * Returns : JB_ERR_OK on success
330 * JB_ERR_MEMORY on out-of-memory error.
332 *********************************************************************/
333 jb_err cgi_die (struct client_state *csp,
334 struct http_response *rsp,
335 const struct map *parameters)
345 * I don't really care what gets sent back to the browser.
346 * Take the easy option - "out of memory" page.
349 return JB_ERR_MEMORY;
351 #endif /* def FEATURE_GRACEFUL_TERMINATION */
354 /*********************************************************************
356 * Function : cgi_show_request
358 * Description : Show the client's request and what sed() would have
362 * 1 : csp = Current client state (buffers, headers, etc...)
363 * 2 : rsp = http_response data structure for output
364 * 3 : parameters = map of cgi parameters
366 * CGI Parameters : none
368 * Returns : JB_ERR_OK on success
369 * JB_ERR_MEMORY on out-of-memory error.
371 *********************************************************************/
372 jb_err cgi_show_request(struct client_state *csp,
373 struct http_response *rsp,
374 const struct map *parameters)
383 if (NULL == (exports = default_exports(csp, "show-request")))
385 return JB_ERR_MEMORY;
389 * Repair the damage done to the IOB by get_header()
391 for (p = csp->iob->buf; p < csp->iob->eod; p++)
393 if (*p == '\0') *p = '\n';
397 * Export the original client's request and the one we would
398 * be sending to the server if this wasn't a CGI call
401 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
404 return JB_ERR_MEMORY;
407 if (map(exports, "processed-request", 1, html_encode_and_free_original(
408 sed(client_patterns, add_client_headers, csp)), 0))
411 return JB_ERR_MEMORY;
414 return template_fill_for_cgi(csp, "show-request", exports, rsp);
418 /*********************************************************************
420 * Function : cgi_send_banner
422 * Description : CGI function that returns a banner.
425 * 1 : csp = Current client state (buffers, headers, etc...)
426 * 2 : rsp = http_response data structure for output
427 * 3 : parameters = map of cgi parameters
430 * type : Selects the type of banner between "trans", "logo",
431 * and "auto". Defaults to "logo" if absent or invalid.
432 * "auto" means to select as if we were image-blocking.
433 * (Only the first character really counts; b and t are
436 * Returns : JB_ERR_OK on success
437 * JB_ERR_MEMORY on out-of-memory error.
439 *********************************************************************/
440 jb_err cgi_send_banner(struct client_state *csp,
441 struct http_response *rsp,
442 const struct map *parameters)
444 char imagetype = lookup(parameters, "type")[0];
447 * If type is auto, then determine the right thing
448 * to do from the set-image-blocker action
450 if (imagetype == 'a')
457 #ifdef FEATURE_IMAGE_BLOCKING
458 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
460 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
461 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
462 const char *p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
466 /* Use default - nothing to do here. */
468 else if (0 == strcmpic(p, "blank"))
472 else if (0 == strcmpic(p, "pattern"))
478 * If the action is to call this CGI, determine
481 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
483 imagetype = p[sizeof(prefix1) - 1];
485 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
487 imagetype = p[sizeof(prefix2) - 1];
491 * Everything else must (should) be a URL to
499 #endif /* def FEATURE_IMAGE_BLOCKING */
503 * Now imagetype is either the non-auto type we were called with,
504 * or it was auto and has since been determined. In any case, we
505 * can proceed to actually answering the request by sending a redirect
506 * or an image as appropriate:
508 if (imagetype == 'r')
510 rsp->status = strdup("302 Local Redirect from Privoxy");
511 if (rsp->status == NULL)
513 return JB_ERR_MEMORY;
515 if (enlist_unique_header(rsp->headers, "Location",
516 csp->action->string[ACTION_STRING_IMAGE_BLOCKER]))
518 return JB_ERR_MEMORY;
523 if ((imagetype == 'b') || (imagetype == 't'))
525 rsp->body = bindup(image_blank_data, image_blank_length);
526 rsp->content_length = image_blank_length;
530 rsp->body = bindup(image_pattern_data, image_pattern_length);
531 rsp->content_length = image_pattern_length;
534 if (rsp->body == NULL)
536 return JB_ERR_MEMORY;
538 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
540 return JB_ERR_MEMORY;
551 /*********************************************************************
553 * Function : cgi_transparent_image
555 * Description : CGI function that sends a 1x1 transparent image.
558 * 1 : csp = Current client state (buffers, headers, etc...)
559 * 2 : rsp = http_response data structure for output
560 * 3 : parameters = map of cgi parameters
562 * CGI Parameters : None
564 * Returns : JB_ERR_OK on success
565 * JB_ERR_MEMORY on out-of-memory error.
567 *********************************************************************/
568 jb_err cgi_transparent_image(struct client_state *csp,
569 struct http_response *rsp,
570 const struct map *parameters)
572 rsp->body = bindup(image_blank_data, image_blank_length);
573 rsp->content_length = image_blank_length;
575 if (rsp->body == NULL)
577 return JB_ERR_MEMORY;
580 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
582 return JB_ERR_MEMORY;
592 /*********************************************************************
594 * Function : cgi_send_stylesheet
596 * Description : CGI function that sends a css stylesheet found
597 * in the cgi-style.css template
600 * 1 : csp = Current client state (buffers, headers, etc...)
601 * 2 : rsp = http_response data structure for output
602 * 3 : parameters = map of cgi parameters
604 * CGI Parameters : None
606 * Returns : JB_ERR_OK on success
607 * JB_ERR_MEMORY on out-of-memory error.
609 *********************************************************************/
610 jb_err cgi_send_stylesheet(struct client_state *csp,
611 struct http_response *rsp,
612 const struct map *parameters)
619 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
621 if (err == JB_ERR_FILE)
624 * No way to tell user; send empty stylesheet
626 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
630 return err; /* JB_ERR_MEMORY */
633 if (enlist(rsp->headers, "Content-Type: text/css"))
635 return JB_ERR_MEMORY;
643 /*********************************************************************
645 * Function : cgi_show_version
647 * Description : CGI function that returns a a web page describing the
648 * file versions of Privoxy.
651 * 1 : csp = Current client state (buffers, headers, etc...)
652 * 2 : rsp = http_response data structure for output
653 * 3 : parameters = map of cgi parameters
655 * CGI Parameters : none
657 * Returns : JB_ERR_OK on success
658 * JB_ERR_MEMORY on out-of-memory error.
660 *********************************************************************/
661 jb_err cgi_show_version(struct client_state *csp,
662 struct http_response *rsp,
663 const struct map *parameters)
671 if (NULL == (exports = default_exports(csp, "show-version")))
673 return JB_ERR_MEMORY;
676 if (map(exports, "sourceversions", 1, show_rcs(), 0))
679 return JB_ERR_MEMORY;
682 return template_fill_for_cgi(csp, "show-version", exports, rsp);
686 /*********************************************************************
688 * Function : cgi_show_status
690 * Description : CGI function that returns a a web page describing the
691 * current status of Privoxy.
694 * 1 : csp = Current client state (buffers, headers, etc...)
695 * 2 : rsp = http_response data structure for output
696 * 3 : parameters = map of cgi parameters
699 * file : Which file to show. Only first letter is checked,
701 * - "p"ermissions (actions) file
704 * Default is to show menu and other information.
706 * Returns : JB_ERR_OK on success
707 * JB_ERR_MEMORY on out-of-memory error.
709 *********************************************************************/
710 jb_err cgi_show_status(struct client_state *csp,
711 struct http_response *rsp,
712 const struct map *parameters)
719 char buf[BUFFER_SIZE];
720 const char * filename = NULL;
721 char * file_description = NULL;
722 #ifdef FEATURE_STATISTICS
723 float perc_rej; /* Percentage of http requests rejected */
725 int local_urls_rejected;
726 #endif /* ndef FEATURE_STATISTICS */
727 struct file_list * fl;
728 struct url_actions * b;
729 jb_err err = JB_ERR_OK;
737 if (NULL == (exports = default_exports(csp, "show-status")))
739 return JB_ERR_MEMORY;
742 switch (*(lookup(parameters, "file")))
745 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_ACTION_FILES && csp->actions_list[i])
747 filename = csp->actions_list[i]->filename;
748 file_description = "Actions File";
755 filename = csp->rlist->filename;
756 file_description = "Filter File";
764 filename = csp->tlist->filename;
765 file_description = "Trust File";
768 #endif /* def FEATURE_TRUST */
771 if (NULL != filename)
773 if ( map(exports, "file-description", 1, file_description, 1)
774 || map(exports, "filepath", 1, html_encode(filename), 0) )
777 return JB_ERR_MEMORY;
780 if ((fp = fopen(filename, "r")) == NULL)
782 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
785 return JB_ERR_MEMORY;
791 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
793 string_join (&s, html_encode(buf));
797 if (map(exports, "contents", 1, s, 0))
800 return JB_ERR_MEMORY;
804 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
808 for (j = 0; (s != NULL) && (j < Argc); j++)
810 if (!err) err = string_join (&s, html_encode(Argv[j]));
811 if (!err) err = string_append(&s, " ");
813 if (!err) err = map(exports, "invocation", 1, s, 0);
815 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
816 if (!err) err = show_defines(exports);
821 return JB_ERR_MEMORY;
824 #ifdef FEATURE_STATISTICS
825 local_urls_read = urls_read;
826 local_urls_rejected = urls_rejected;
829 * Need to alter the stats not to include the fetch of this
832 * Can't do following thread safely! doh!
835 * urls_rejected--; * This will be incremented subsequently *
838 if (local_urls_read == 0)
840 if (!err) err = map_block_killer(exports, "have-stats");
844 if (!err) err = map_block_killer(exports, "have-no-stats");
846 perc_rej = (float)local_urls_rejected * 100.0F /
847 (float)local_urls_read;
849 sprintf(buf, "%d", local_urls_read);
850 if (!err) err = map(exports, "requests-received", 1, buf, 1);
852 sprintf(buf, "%d", local_urls_rejected);
853 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
855 sprintf(buf, "%6.2f", perc_rej);
856 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
859 #else /* ndef FEATURE_STATISTICS */
860 err = err || map_block_killer(exports, "statistics");
861 #endif /* ndef FEATURE_STATISTICS */
864 * List all action files in use, together with view and edit links,
865 * except for standard.action, which should only be viewable. (Not
866 * enforced in the editor itself)
867 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
870 for (i = 0; i < MAX_ACTION_FILES; i++)
872 if (((fl = csp->actions_list[i]) != NULL) && ((b = fl->f) != NULL))
874 if (!err) err = string_append(&s, "<tr><td>");
875 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
876 snprintf(buf, 100, "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a>", i);
877 if (!err) err = string_append(&s, buf);
879 #ifdef FEATURE_CGI_EDIT_ACTIONS
880 if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
882 snprintf(buf, 100, " <a href=\"/edit-actions-list?f=%s\">Edit</a>", csp->config->actions_file_short[i]);
883 if (!err) err = string_append(&s, buf);
887 if (!err) err = string_append(&s, "</td></tr>\n");
892 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
896 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
901 if (!err) err = map(exports, "re-filter-filename", 1, html_encode(csp->rlist->filename), 0);
905 if (!err) err = map(exports, "re-filter-filename", 1, "None specified", 1);
906 if (!err) err = map_block_killer(exports, "have-filterfile");
912 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
916 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
917 if (!err) err = map_block_killer(exports, "have-trustfile");
920 if (!err) err = map_block_killer(exports, "trust-support");
921 #endif /* ndef FEATURE_TRUST */
926 return JB_ERR_MEMORY;
929 return template_fill_for_cgi(csp, "show-status", exports, rsp);
933 /*********************************************************************
935 * Function : cgi_show_url_info
937 * Description : CGI function that determines and shows which actions
938 * Privoxy will perform for a given url, and which
939 * matches starting from the defaults have lead to that.
942 * 1 : csp = Current client state (buffers, headers, etc...)
943 * 2 : rsp = http_response data structure for output
944 * 3 : parameters = map of cgi parameters
947 * url : The url whose actions are to be determined.
948 * If url is unset, the url-given conditional will be
949 * set, so that all but the form can be suppressed in
952 * Returns : JB_ERR_OK on success
953 * JB_ERR_MEMORY on out-of-memory error.
955 *********************************************************************/
956 jb_err cgi_show_url_info(struct client_state *csp,
957 struct http_response *rsp,
958 const struct map *parameters)
968 if (NULL == (exports = default_exports(csp, "show-url-info")))
970 return JB_ERR_MEMORY;
974 * Get the url= parameter (if present) and remove any leading/trailing spaces.
976 url_param = strdup(lookup(parameters, "url"));
977 if (url_param == NULL)
980 return JB_ERR_MEMORY;
985 * Handle prefixes. 4 possibilities:
986 * 1) "http://" or "https://" prefix present and followed by URL - OK
987 * 2) Only the "http://" or "https://" part is present, no URL - change
988 * to empty string so it will be detected later as "no URL".
989 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
991 * 4) Parameter not specified or is empty string - let this fall through
992 * for now, next block of code will handle it.
994 if (0 == strncmp(url_param, "http://", 7))
996 if (url_param[7] == '\0')
999 * Empty URL (just prefix).
1000 * Make it totally empty so it's caught by the next if()
1002 url_param[0] = '\0';
1005 else if (0 == strncmp(url_param, "https://", 8))
1007 if (url_param[8] == '\0')
1010 * Empty URL (just prefix).
1011 * Make it totally empty so it's caught by the next if()
1013 url_param[0] = '\0';
1016 else if (url_param[0] != '\0')
1019 * Unknown prefix - assume http://
1021 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
1022 if (NULL == url_param_prefixed)
1026 return JB_ERR_MEMORY;
1028 strcpy(url_param_prefixed, "http://");
1029 strcpy(url_param_prefixed + 7, url_param);
1031 url_param = url_param_prefixed;
1035 if (url_param[0] == '\0')
1037 /* URL paramater not specified, display query form only. */
1039 if (map_block_killer(exports, "url-given")
1040 || map(exports, "url", 1, "", 1))
1043 return JB_ERR_MEMORY;
1048 /* Given a URL, so query it. */
1053 struct file_list *fl;
1054 struct url_actions *b;
1055 struct http_request url_to_query[1];
1056 struct current_action_spec action[1];
1059 if (map(exports, "url", 1, html_encode(url_param), 0))
1063 return JB_ERR_MEMORY;
1066 init_current_action(action);
1068 if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1070 free_current_action(action);
1073 return JB_ERR_MEMORY;
1076 err = parse_http_url(url_param, url_to_query, csp);
1080 if (err == JB_ERR_MEMORY)
1082 free_http_request(url_to_query);
1083 free_current_action(action);
1085 return JB_ERR_MEMORY;
1091 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1092 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1094 free_current_action(action);
1095 free_http_request(url_to_query);
1100 return JB_ERR_MEMORY;
1103 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1107 * We have a warning about SSL paths. Hide it for insecure sites.
1109 if (!url_to_query->ssl)
1111 if (map_block_killer(exports, "https"))
1113 free_current_action(action);
1115 free_http_request(url_to_query);
1116 return JB_ERR_MEMORY;
1120 matches = strdup("<table class=\"transparent\">");
1122 for (i = 0; i < MAX_ACTION_FILES; i++)
1124 if (NULL == csp->config->actions_file_short[i]
1125 || !strcmp(csp->config->actions_file_short[i], "standard")) continue;
1129 if ((fl = csp->actions_list[i]) != NULL)
1131 if ((b = fl->f) != NULL)
1133 /* FIXME: Hardcoded HTML! */
1134 string_append(&matches, "<tr><th>In file: ");
1135 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1136 snprintf(buf, 150, ".action <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1137 string_append(&matches, buf);
1138 string_append(&matches, "View</a> <a class=\"cmd\" href=\"/edit-actions-list?f=");
1139 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1140 string_append(&matches, "\">Edit</a></th></tr>\n");
1147 for (; (b != NULL) && (matches != NULL); b = b->next)
1149 if (url_match(b->url, url_to_query))
1151 string_append(&matches, "<tr><td>{");
1152 string_join (&matches, actions_to_html(csp, b->action));
1153 string_append(&matches, " }</b><br>\n<code>");
1154 string_join (&matches, html_encode(b->url->spec));
1155 string_append(&matches, "</code></td></tr>\n");
1157 if (merge_current_action(action, b->action))
1160 free_http_request(url_to_query);
1161 free_current_action(action);
1163 return JB_ERR_MEMORY;
1171 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1174 string_append(&matches, "</table>\n");
1176 free_http_request(url_to_query);
1178 if (matches == NULL)
1180 free_current_action(action);
1182 return JB_ERR_MEMORY;
1185 if (map(exports, "matches", 1, matches , 0))
1187 free_current_action(action);
1189 return JB_ERR_MEMORY;
1192 s = current_action_to_html(csp, action);
1194 free_current_action(action);
1196 if (map(exports, "final", 1, s, 0))
1199 return JB_ERR_MEMORY;
1203 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1207 /*********************************************************************
1209 * Function : cgi_robots_txt
1211 * Description : CGI function to return "/robots.txt".
1214 * 1 : csp = Current client state (buffers, headers, etc...)
1215 * 2 : rsp = http_response data structure for output
1216 * 3 : parameters = map of cgi parameters
1218 * CGI Parameters : None
1220 * Returns : JB_ERR_OK on success
1221 * JB_ERR_MEMORY on out-of-memory error.
1223 *********************************************************************/
1224 jb_err cgi_robots_txt(struct client_state *csp,
1225 struct http_response *rsp,
1226 const struct map *parameters)
1232 "# This is the Privoxy control interface.\n"
1233 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1239 if (rsp->body == NULL)
1241 return JB_ERR_MEMORY;
1244 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1248 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1249 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1251 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1255 /*********************************************************************
1257 * Function : show_defines
1259 * Description : Add to a map the state od all conditional #defines
1260 * used when building
1263 * 1 : exports = map to extend
1265 * Returns : JB_ERR_OK on success
1266 * JB_ERR_MEMORY on out-of-memory error.
1268 *********************************************************************/
1269 static jb_err show_defines(struct map *exports)
1271 jb_err err = JB_ERR_OK;
1274 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1275 #else /* ifndef FEATURE_ACL */
1276 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1277 #endif /* ndef FEATURE_ACL */
1279 #ifdef FEATURE_CGI_EDIT_ACTIONS
1280 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1281 #else /* ifndef FEATURE_COOKIE_JAR */
1282 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1283 #endif /* ndef FEATURE_COOKIE_JAR */
1285 #ifdef FEATURE_COOKIE_JAR
1286 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1287 #else /* ifndef FEATURE_COOKIE_JAR */
1288 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1289 #endif /* ndef FEATURE_COOKIE_JAR */
1291 #ifdef FEATURE_FAST_REDIRECTS
1292 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1293 #else /* ifndef FEATURE_FAST_REDIRECTS */
1294 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1295 #endif /* ndef FEATURE_FAST_REDIRECTS */
1297 #ifdef FEATURE_FORCE_LOAD
1298 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1299 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1300 #else /* ifndef FEATURE_FORCE_LOAD */
1301 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1302 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1303 #endif /* ndef FEATURE_FORCE_LOAD */
1305 #ifdef FEATURE_IMAGE_BLOCKING
1306 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1307 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1308 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1309 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1311 #ifdef FEATURE_IMAGE_DETECT_MSIE
1312 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1313 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1314 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1315 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1317 #ifdef FEATURE_KILL_POPUPS
1318 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1319 #else /* ifndef FEATURE_KILL_POPUPS */
1320 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1321 #endif /* ndef FEATURE_KILL_POPUPS */
1323 #ifdef FEATURE_NO_GIFS
1324 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1325 #else /* ifndef FEATURE_NO_GIFS */
1326 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1327 #endif /* ndef FEATURE_NO_GIFS */
1329 #ifdef FEATURE_PTHREAD
1330 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1331 #else /* ifndef FEATURE_PTHREAD */
1332 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1333 #endif /* ndef FEATURE_PTHREAD */
1335 #ifdef FEATURE_STATISTICS
1336 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1337 #else /* ifndef FEATURE_STATISTICS */
1338 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1339 #endif /* ndef FEATURE_STATISTICS */
1341 #ifdef FEATURE_TOGGLE
1342 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1343 #else /* ifndef FEATURE_TOGGLE */
1344 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1345 #endif /* ndef FEATURE_TOGGLE */
1347 #ifdef FEATURE_TRUST
1348 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1349 #else /* ifndef FEATURE_TRUST */
1350 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1351 #endif /* ndef FEATURE_TRUST */
1354 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1355 #else /* ifndef STATIC_PCRE */
1356 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1357 #endif /* ndef STATIC_PCRE */
1360 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1361 #else /* ifndef STATIC_PCRS */
1362 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1363 #endif /* ndef STATIC_PCRS */
1369 /*********************************************************************
1371 * Function : show_rcs
1373 * Description : Create a string with the rcs info for all sourcefiles
1377 * Returns : A string, or NULL on out-of-memory.
1379 *********************************************************************/
1380 static char *show_rcs(void)
1382 char *result = strdup("");
1383 char buf[BUFFER_SIZE];
1385 /* Instead of including *all* dot h's in the project (thus creating a
1386 * tremendous amount of dependencies), I will concede to declaring them
1387 * as extern's. This forces the developer to add to this list, but oh well.
1390 #define SHOW_RCS(__x) \
1392 extern const char __x[]; \
1393 sprintf(buf, "%s\n", __x); \
1394 string_append(&result, buf); \
1397 /* In alphabetical order */
1398 SHOW_RCS(actions_h_rcs)
1399 SHOW_RCS(actions_rcs)
1401 SHOW_RCS(amiga_h_rcs)
1403 #endif /* def AMIGA */
1406 #ifdef FEATURE_CGI_EDIT_ACTIONS
1407 SHOW_RCS(cgiedit_h_rcs)
1408 SHOW_RCS(cgiedit_rcs)
1409 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1410 SHOW_RCS(cgisimple_h_rcs)
1411 SHOW_RCS(cgisimple_rcs)
1413 SHOW_RCS(cygwin_h_rcs)
1415 SHOW_RCS(deanimate_h_rcs)
1416 SHOW_RCS(deanimate_rcs)
1417 SHOW_RCS(encode_h_rcs)
1418 SHOW_RCS(encode_rcs)
1419 SHOW_RCS(errlog_h_rcs)
1420 SHOW_RCS(errlog_rcs)
1421 SHOW_RCS(filters_h_rcs)
1422 SHOW_RCS(filters_rcs)
1423 SHOW_RCS(gateway_h_rcs)
1424 SHOW_RCS(gateway_rcs)
1425 SHOW_RCS(jbsockets_h_rcs)
1426 SHOW_RCS(jbsockets_rcs)
1429 #ifdef FEATURE_KILL_POPUPS
1430 SHOW_RCS(killpopup_h_rcs)
1431 SHOW_RCS(killpopup_rcs)
1432 #endif /* def FEATURE_KILL_POPUPS */
1433 SHOW_RCS(list_h_rcs)
1435 SHOW_RCS(loadcfg_h_rcs)
1436 SHOW_RCS(loadcfg_rcs)
1437 SHOW_RCS(loaders_h_rcs)
1438 SHOW_RCS(loaders_rcs)
1439 SHOW_RCS(miscutil_h_rcs)
1440 SHOW_RCS(miscutil_rcs)
1441 SHOW_RCS(parsers_h_rcs)
1442 SHOW_RCS(parsers_rcs)
1444 SHOW_RCS(pcrs_h_rcs)
1445 SHOW_RCS(project_h_rcs)
1446 SHOW_RCS(ssplit_h_rcs)
1447 SHOW_RCS(ssplit_rcs)
1448 SHOW_RCS(urlmatch_h_rcs)
1449 SHOW_RCS(urlmatch_rcs)
1451 #ifndef _WIN_CONSOLE
1452 SHOW_RCS(w32log_h_rcs)
1453 SHOW_RCS(w32log_rcs)
1454 SHOW_RCS(w32res_h_rcs)
1455 SHOW_RCS(w32taskbar_h_rcs)
1456 SHOW_RCS(w32taskbar_rcs)
1457 #endif /* ndef _WIN_CONSOLE */
1458 SHOW_RCS(win32_h_rcs)
1460 #endif /* def _WIN32 */