1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.69 2008/04/17 14:40:48 fabiankeil Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/cgisimple.c,v $
6 * Purpose : Simple CGIs to get information about Privoxy's
9 * Functions declared include:
12 * Copyright : Written by and Copyright (C) 2001-2008 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.69 2008/04/17 14:40:48 fabiankeil
40 * Provide get_http_time() with the buffer size so it doesn't
41 * have to blindly assume that the buffer is big enough.
43 * Revision 1.68 2008/03/27 18:27:21 fabiankeil
44 * Remove kill-popups action.
46 * Revision 1.67 2008/03/27 17:00:05 fabiankeil
47 * Turn the favicon blobs into locals.
49 * Revision 1.66 2008/02/23 16:57:12 fabiankeil
50 * Rename url_actions() to get_url_actions() and let it
51 * use the standard parameter ordering.
53 * Revision 1.65 2008/02/23 16:33:43 fabiankeil
54 * Let forward_url() use the standard parameter ordering
55 * and mark its second parameter immutable.
57 * Revision 1.64 2008/02/03 13:56:07 fabiankeil
58 * Add SOCKS5 support for show-url-info CGI page.
60 * Revision 1.63 2008/02/01 06:04:31 fabiankeil
61 * If edit buttons on the show-url-info CGI page are hidden, explain why.
63 * Revision 1.62 2008/02/01 05:52:40 fabiankeil
64 * Hide edit buttons on the show-url-info CGI page if enable-edit-action
65 * is disabled. Patch by Lee with additional white space adjustments.
67 * Revision 1.61 2008/01/26 11:13:25 fabiankeil
68 * If enable-edit-actions is disabled, hide the edit buttons and explain why.
70 * Revision 1.60 2007/10/27 13:12:13 fabiankeil
71 * Finish 1.49 and check write access before
72 * showing edit buttons on show-url-info page.
74 * Revision 1.59 2007/10/19 16:42:36 fabiankeil
75 * Plug memory leak I introduced five months ago.
76 * Yay Valgrind and Privoxy-Regression-Test.
78 * Revision 1.58 2007/07/21 12:19:50 fabiankeil
79 * If show-url-info is called with an URL that Privoxy
80 * would reject as invalid, don't show unresolved forwarding
81 * variables, "final matches" or claim the site's secure.
83 * Revision 1.57 2007/06/01 16:53:05 fabiankeil
84 * Adjust cgi_show_url_info() to show what forward-override{}
85 * would do with the requested URL (instead of showing how the
86 * request for the CGI page would be forwarded if it wasn't a
89 * Revision 1.56 2007/05/21 10:50:35 fabiankeil
90 * - Use strlcpy() instead of strcpy().
91 * - Stop treating actions files special. Expect a complete file name
92 * (with or without path) like it's done for the rest of the files.
94 * - Don't rerun sed() in cgi_show_request().
96 * Revision 1.55 2007/04/13 13:36:46 fabiankeil
97 * Reference action files in CGI URLs by id instead
98 * of using the first part of the file name.
99 * Fixes BR 1694250 and BR 1590556.
101 * Revision 1.54 2007/04/09 18:11:35 fabiankeil
102 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
104 * Revision 1.53 2007/04/08 13:21:04 fabiankeil
105 * Reference action files in CGI URLs by id instead
106 * of using the first part of the file name.
107 * Fixes BR 1694250 and BR 1590556.
109 * Revision 1.52 2007/02/13 15:10:26 fabiankeil
110 * Apparently fopen()ing in "binary" mode doesn't require
111 * #ifdefs, it's already done without them in cgiedit.c.
113 * Revision 1.51 2007/02/10 16:55:22 fabiankeil
114 * - Show forwarding settings on the show-url-info page
115 * - Fix some HTML syntax errors.
117 * Revision 1.50 2007/01/23 15:51:17 fabiankeil
118 * Add favicon delivery functions.
120 * Revision 1.49 2007/01/20 16:29:38 fabiankeil
121 * Suppress edit buttons for action files if Privoxy has
122 * no write access. Suggested by Roland in PR 1564026.
124 * Revision 1.48 2007/01/20 15:31:31 fabiankeil
125 * Display warning if show-url-info CGI page
126 * is used while Privoxy is toggled off.
128 * Revision 1.47 2007/01/12 15:07:10 fabiankeil
129 * Use zalloc in cgi_send_user_manual.
131 * Revision 1.46 2007/01/02 12:49:46 fabiankeil
132 * Add FEATURE_ZLIB to the list of conditional
133 * defines at the show-status page.
135 * Revision 1.45 2006/12/28 18:16:41 fabiankeil
136 * Fixed gcc43 compiler warnings, zero out cgi_send_user_manual's
137 * body memory before using it, replaced sprintf calls with snprintf.
139 * Revision 1.44 2006/12/22 14:19:27 fabiankeil
140 * Removed checks whether or not AF_FILES have
141 * data structures associated with them in cgi_show_status.
142 * It doesn't matter as we're only interested in the file names.
144 * For the action files the checks were always true,
145 * but they prevented empty filter files from being
146 * listed. Fixes parts of BR 1619208.
148 * Revision 1.43 2006/12/17 17:57:56 fabiankeil
149 * - Added FEATURE_GRACEFUL_TERMINATION to the
150 * "conditional #defines" section
151 * - Escaped ampersands in generated HTML.
152 * - Renamed re-filter-filename to re-filter-filenames
154 * Revision 1.42 2006/11/21 15:43:12 fabiankeil
155 * Add special treatment for WIN32 to make sure
156 * cgi_send_user_manual opens the files in binary mode.
157 * Fixes BR 1600411 and unbreaks image delivery.
159 * Remove outdated comment.
161 * Revision 1.41 2006/10/09 19:18:28 roro
162 * Redirect http://p.p/user-manual (without trailing slash) to
163 * http://p.p/user-manual/ (with trailing slash), otherwise links will be broken.
165 * Revision 1.40 2006/09/09 13:05:33 fabiankeil
166 * Modified cgi_send_user_manual to serve binary
167 * content without destroying it first. Should also be
168 * faster now. Added ".jpg" check for Content-Type guessing.
170 * Revision 1.39 2006/09/08 09:49:23 fabiankeil
171 * Deliver documents in the user-manual directory
172 * with "Content-Type text/css" if their filename
175 * Revision 1.38 2006/09/06 18:45:03 fabiankeil
176 * Incorporate modified version of Roland Rosenfeld's patch to
177 * optionally access the user-manual via Privoxy. Closes patch 679075.
179 * Formatting changed to Privoxy style, added call to
180 * cgi_error_no_template if the requested file doesn't
181 * exist and modified check whether or not Privoxy itself
182 * should serve the manual. Should work cross-platform now.
184 * Revision 1.37 2006/07/18 14:48:45 david__schmidt
185 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
186 * with what was really the latest development (the v_3_0_branch branch)
188 * Revision 1.35.2.7 2006/01/29 23:10:56 david__schmidt
189 * Multiple filter file support
191 * Revision 1.35.2.6 2005/07/04 03:13:43 david__schmidt
192 * Undo some damaging memory leak patches
194 * Revision 1.35.2.5 2005/05/07 21:50:55 david__schmidt
195 * A few memory leaks plugged (mostly on error paths)
197 * Revision 1.35.2.4 2005/04/04 02:21:24 david__schmidt
198 * Another instance of:
199 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
200 * Thanks to Magnus Holmgren for the patch
202 * Revision 1.35.2.3 2003/12/17 16:34:15 oes
203 * - Prevent line wrap beween "View/Edit" link buttons on status page
204 * - Some (mostly irrelevant) fixes for Out-of-mem-case handling
206 * Revision 1.35.2.2 2003/04/03 13:48:28 oes
207 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
209 * Revision 1.35.2.1 2002/07/04 15:02:38 oes
210 * Added ability to send redirects to send-banner CGI, so that it can completely mimic the image blocking action if called with type=auto
212 * Revision 1.35.2.1 2002/07/01 17:32:04 morcego
213 * Applying patch from Andreas as provided by Hal on the list.
214 * Message-ID: <20020701121218.V1606@feenix.burgiss.net>
216 * Revision 1.35 2002/05/12 21:44:44 jongfoster
217 * Adding amiga.[ch] revision information, if on an amiga.
219 * Revision 1.34 2002/04/30 12:06:12 oes
220 * Deleted unused code from default_cgi
222 * Revision 1.33 2002/04/30 11:14:52 oes
223 * Made csp the first parameter in *action_to_html
225 * Revision 1.32 2002/04/26 18:29:13 jongfoster
226 * Fixing this Visual C++ warning:
227 * cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
229 * Revision 1.31 2002/04/26 12:54:36 oes
230 * - Kill obsolete REDIRECT_URL code
231 * - Error handling fixes
232 * - Style sheet related HTML snipplet changes
233 * - cgi_show_url_info:
234 * - Matches now in table, actions on single lines,
236 * - standard.action suppressed
237 * - Buttons to View and Edit AFs
239 * Revision 1.30 2002/04/24 02:18:08 oes
240 * - show-status is now the starting point for editing
241 * the actions files, generate list of all AFs with buttons
242 * for viewing and editing, new look for file list (Jon:
243 * buttons now aligned ;-P ), view mode now supports multiple
244 * AFs, name changes, no view links for unspecified files,
245 * no edit link for standard.action.
247 * - Jon's multiple AF patch: cgi_show_url_info now uses all
248 * AFs and marks the output accordingly
250 * Revision 1.29 2002/04/10 13:38:35 oes
251 * load_template signature changed
253 * Revision 1.28 2002/04/07 15:42:12 jongfoster
254 * Fixing send-banner?type=auto when the image-blocker is
255 * a redirect to send-banner
257 * Revision 1.27 2002/04/05 15:50:48 oes
258 * added send-stylesheet CGI
260 * Revision 1.26 2002/04/04 00:36:36 gliptak
261 * always use pcre for matching
263 * Revision 1.25 2002/04/03 22:28:03 gliptak
264 * Removed references to gnu_regex
266 * Revision 1.24 2002/04/02 16:12:47 oes
267 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
269 * Revision 1.23 2002/03/26 22:29:54 swa
270 * we have a new homepage!
272 * Revision 1.22 2002/03/24 16:18:15 jongfoster
275 * Revision 1.21 2002/03/24 15:23:33 jongfoster
278 * Revision 1.20 2002/03/24 13:25:43 swa
279 * name change related issues
281 * Revision 1.19 2002/03/16 23:54:06 jongfoster
282 * Adding graceful termination feature, to help look for memory leaks.
283 * If you enable this (which, by design, has to be done by hand
284 * editing config.h) and then go to http://i.j.b/die, then the program
285 * will exit cleanly after the *next* request. It should free all the
286 * memory that was used.
288 * Revision 1.18 2002/03/12 01:44:49 oes
289 * Changed default for "blocked" image from jb logo to checkboard pattern
291 * Revision 1.17 2002/03/08 16:43:18 oes
292 * Added choice beween GIF and PNG built-in images
294 * Revision 1.16 2002/03/07 03:48:38 oes
295 * - Changed built-in images from GIF to PNG
296 * (with regard to Unisys patent issue)
297 * - Added a 4x4 pattern PNG which is less intrusive
298 * than the logo but also clearly marks the deleted banners
300 * Revision 1.15 2002/03/06 22:54:35 jongfoster
301 * Automated function-comment nitpicking.
303 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
304 * Clean up a little CRLF unpleasantness that suddenly appeared
306 * Revision 1.13 2002/02/21 00:10:37 jongfoster
307 * Adding send-banner?type=auto option
309 * Revision 1.12 2002/01/23 01:03:32 jongfoster
310 * Fixing gcc [CygWin] compiler warnings
312 * Revision 1.11 2002/01/23 00:01:04 jongfoster
313 * Adding cgi_transparent_gif() for http://i.j.b/t
314 * Adding missing html_encode() to many CGI functions.
315 * Adding urlmatch.[ch] to http://i.j.b/show-version
317 * Revision 1.10 2002/01/17 21:10:37 jongfoster
318 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
319 * Also fixing a problem in the same function with improperly quoted URLs
320 * in output HTML, and adding code to handle https:// URLs correctly.
322 * Revision 1.9 2001/11/30 23:09:15 jongfoster
323 * Now reports on FEATURE_CGI_EDIT_ACTIONS
324 * Removing FEATURE_DENY_GZIP from template
326 * Revision 1.8 2001/11/13 00:14:07 jongfoster
327 * Fixing stupid bug now I've figured out what || means.
328 * (It always returns 0 or 1, not one of it's paramaters.)
330 * Revision 1.7 2001/10/23 21:48:19 jongfoster
331 * Cleaning up error handling in CGI functions - they now send back
332 * a HTML error page and should never cause a FATAL error. (Fixes one
333 * potential source of "denial of service" attacks).
335 * CGI actions file editor that works and is actually useful.
337 * Ability to toggle JunkBuster remotely using a CGI call.
339 * You can turn off both the above features in the main configuration
340 * file, e.g. if you are running a multi-user proxy.
342 * Revision 1.6 2001/10/14 22:00:32 jongfoster
343 * Adding support for a 404 error when an invalid CGI page is requested.
345 * Revision 1.5 2001/10/07 15:30:41 oes
346 * Removed FEATURE_DENY_GZIP
348 * Revision 1.4 2001/10/02 15:31:12 oes
349 * Introduced show-request cgi
351 * Revision 1.3 2001/09/22 16:34:44 jongfoster
352 * Removing unneeded #includes
354 * Revision 1.2 2001/09/19 18:01:11 oes
355 * Fixed comments; cosmetics
357 * Revision 1.1 2001/09/16 17:08:54 jongfoster
358 * Moving simple CGI functions from cgi.c to new file cgisimple.c
361 **********************************************************************/
367 #include <sys/types.h>
375 #endif /* def HAVE_ACCESS */
379 #include "cgisimple.h"
385 #include "miscutil.h"
388 #include "urlmatch.h"
391 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
394 static char *show_rcs(void);
395 static jb_err show_defines(struct map *exports);
397 /*********************************************************************
399 * Function : cgi_default
401 * Description : CGI function that is called for the CGI_SITE_1_HOST
402 * and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
403 * Boring - only exports the default exports.
406 * 1 : csp = Current client state (buffers, headers, etc...)
407 * 2 : rsp = http_response data structure for output
408 * 3 : parameters = map of cgi parameters
410 * CGI Parameters : none
412 * Returns : JB_ERR_OK on success
413 * JB_ERR_MEMORY on out-of-memory
415 *********************************************************************/
416 jb_err cgi_default(struct client_state *csp,
417 struct http_response *rsp,
418 const struct map *parameters)
425 if (NULL == (exports = default_exports(csp, "")))
427 return JB_ERR_MEMORY;
430 return template_fill_for_cgi(csp, "default", exports, rsp);
434 /*********************************************************************
436 * Function : cgi_error_404
438 * Description : CGI function that is called if an unknown action was
442 * 1 : csp = Current client state (buffers, headers, etc...)
443 * 2 : rsp = http_response data structure for output
444 * 3 : parameters = map of cgi parameters
446 * CGI Parameters : none
448 * Returns : JB_ERR_OK on success
449 * JB_ERR_MEMORY on out-of-memory error.
451 *********************************************************************/
452 jb_err cgi_error_404(struct client_state *csp,
453 struct http_response *rsp,
454 const struct map *parameters)
462 if (NULL == (exports = default_exports(csp, NULL)))
464 return JB_ERR_MEMORY;
467 rsp->status = strdup("404 Privoxy configuration page not found");
468 if (rsp->status == NULL)
471 return JB_ERR_MEMORY;
474 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
478 #ifdef FEATURE_GRACEFUL_TERMINATION
479 /*********************************************************************
483 * Description : CGI function to shut down Privoxy.
484 * NOTE: Turning this on in a production build
485 * would be a BAD idea. An EXTREMELY BAD idea.
486 * In short, don't do it.
489 * 1 : csp = Current client state (buffers, headers, etc...)
490 * 2 : rsp = http_response data structure for output
491 * 3 : parameters = map of cgi parameters
493 * CGI Parameters : none
495 * Returns : JB_ERR_OK on success
496 * JB_ERR_MEMORY on out-of-memory error.
498 *********************************************************************/
499 jb_err cgi_die (struct client_state *csp,
500 struct http_response *rsp,
501 const struct map *parameters)
511 * I don't really care what gets sent back to the browser.
512 * Take the easy option - "out of memory" page.
515 return JB_ERR_MEMORY;
517 #endif /* def FEATURE_GRACEFUL_TERMINATION */
520 /*********************************************************************
522 * Function : cgi_show_request
524 * Description : Show the client's request and what sed() would have
528 * 1 : csp = Current client state (buffers, headers, etc...)
529 * 2 : rsp = http_response data structure for output
530 * 3 : parameters = map of cgi parameters
532 * CGI Parameters : none
534 * Returns : JB_ERR_OK on success
535 * JB_ERR_MEMORY on out-of-memory error.
537 *********************************************************************/
538 jb_err cgi_show_request(struct client_state *csp,
539 struct http_response *rsp,
540 const struct map *parameters)
549 if (NULL == (exports = default_exports(csp, "show-request")))
551 return JB_ERR_MEMORY;
555 * Repair the damage done to the IOB by get_header()
557 for (p = csp->iob->buf; p < csp->iob->eod; p++)
559 if (*p == '\0') *p = '\n';
563 * Export the original client's request and the one we would
564 * be sending to the server if this wasn't a CGI call
567 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
570 return JB_ERR_MEMORY;
573 if (map(exports, "processed-request", 1,
574 html_encode_and_free_original(list_to_text(csp->headers)), 0))
577 return JB_ERR_MEMORY;
580 return template_fill_for_cgi(csp, "show-request", exports, rsp);
584 /*********************************************************************
586 * Function : cgi_send_banner
588 * Description : CGI function that returns a banner.
591 * 1 : csp = Current client state (buffers, headers, etc...)
592 * 2 : rsp = http_response data structure for output
593 * 3 : parameters = map of cgi parameters
596 * type : Selects the type of banner between "trans", "logo",
597 * and "auto". Defaults to "logo" if absent or invalid.
598 * "auto" means to select as if we were image-blocking.
599 * (Only the first character really counts; b and t are
602 * Returns : JB_ERR_OK on success
603 * JB_ERR_MEMORY on out-of-memory error.
605 *********************************************************************/
606 jb_err cgi_send_banner(struct client_state *csp,
607 struct http_response *rsp,
608 const struct map *parameters)
610 char imagetype = lookup(parameters, "type")[0];
613 * If type is auto, then determine the right thing
614 * to do from the set-image-blocker action
616 if (imagetype == 'a')
623 #ifdef FEATURE_IMAGE_BLOCKING
624 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
626 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
627 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
628 const char *p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
632 /* Use default - nothing to do here. */
634 else if (0 == strcmpic(p, "blank"))
638 else if (0 == strcmpic(p, "pattern"))
644 * If the action is to call this CGI, determine
647 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
649 imagetype = p[sizeof(prefix1) - 1];
651 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
653 imagetype = p[sizeof(prefix2) - 1];
657 * Everything else must (should) be a URL to
665 #endif /* def FEATURE_IMAGE_BLOCKING */
669 * Now imagetype is either the non-auto type we were called with,
670 * or it was auto and has since been determined. In any case, we
671 * can proceed to actually answering the request by sending a redirect
672 * or an image as appropriate:
674 if (imagetype == 'r')
676 rsp->status = strdup("302 Local Redirect from Privoxy");
677 if (rsp->status == NULL)
679 return JB_ERR_MEMORY;
681 if (enlist_unique_header(rsp->headers, "Location",
682 csp->action->string[ACTION_STRING_IMAGE_BLOCKER]))
684 return JB_ERR_MEMORY;
689 if ((imagetype == 'b') || (imagetype == 't'))
691 rsp->body = bindup(image_blank_data, image_blank_length);
692 rsp->content_length = image_blank_length;
696 rsp->body = bindup(image_pattern_data, image_pattern_length);
697 rsp->content_length = image_pattern_length;
700 if (rsp->body == NULL)
702 return JB_ERR_MEMORY;
704 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
706 return JB_ERR_MEMORY;
717 /*********************************************************************
719 * Function : cgi_transparent_image
721 * Description : CGI function that sends a 1x1 transparent image.
724 * 1 : csp = Current client state (buffers, headers, etc...)
725 * 2 : rsp = http_response data structure for output
726 * 3 : parameters = map of cgi parameters
728 * CGI Parameters : None
730 * Returns : JB_ERR_OK on success
731 * JB_ERR_MEMORY on out-of-memory error.
733 *********************************************************************/
734 jb_err cgi_transparent_image(struct client_state *csp,
735 struct http_response *rsp,
736 const struct map *parameters)
738 rsp->body = bindup(image_blank_data, image_blank_length);
739 rsp->content_length = image_blank_length;
741 if (rsp->body == NULL)
743 return JB_ERR_MEMORY;
746 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
748 return JB_ERR_MEMORY;
758 /*********************************************************************
760 * Function : cgi_send_default_favicon
762 * Description : CGI function that sends the standard favicon.
765 * 1 : csp = Current client state (buffers, headers, etc...)
766 * 2 : rsp = http_response data structure for output
767 * 3 : parameters = map of cgi parameters
769 * CGI Parameters : None
771 * Returns : JB_ERR_OK on success
772 * JB_ERR_MEMORY on out-of-memory error.
774 *********************************************************************/
775 jb_err cgi_send_default_favicon(struct client_state *csp,
776 struct http_response *rsp,
777 const struct map *parameters)
779 static const char default_favicon_data[] =
780 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
781 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
782 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
783 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
784 "\000\000\377\377\377\000\377\000\052\000\017\360\000\000\077"
785 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
786 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
787 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
788 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
789 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
790 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
791 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
792 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
794 static const size_t favicon_length = sizeof(default_favicon_data) - 1;
796 rsp->body = bindup(default_favicon_data, favicon_length);
797 rsp->content_length = favicon_length;
799 if (rsp->body == NULL)
801 return JB_ERR_MEMORY;
804 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
806 return JB_ERR_MEMORY;
816 /*********************************************************************
818 * Function : cgi_send_error_favicon
820 * Description : CGI function that sends the favicon for error pages.
823 * 1 : csp = Current client state (buffers, headers, etc...)
824 * 2 : rsp = http_response data structure for output
825 * 3 : parameters = map of cgi parameters
827 * CGI Parameters : None
829 * Returns : JB_ERR_OK on success
830 * JB_ERR_MEMORY on out-of-memory error.
832 *********************************************************************/
833 jb_err cgi_send_error_favicon(struct client_state *csp,
834 struct http_response *rsp,
835 const struct map *parameters)
837 static const char error_favicon_data[] =
838 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
839 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
840 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
841 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
842 "\000\000\377\377\377\000\000\000\377\000\017\360\000\000\077"
843 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
844 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
845 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
846 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
847 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
848 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
849 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
850 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
852 static const size_t favicon_length = sizeof(error_favicon_data) - 1;
854 rsp->body = bindup(error_favicon_data, favicon_length);
855 rsp->content_length = favicon_length;
857 if (rsp->body == NULL)
859 return JB_ERR_MEMORY;
862 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
864 return JB_ERR_MEMORY;
874 /*********************************************************************
876 * Function : cgi_send_stylesheet
878 * Description : CGI function that sends a css stylesheet found
879 * in the cgi-style.css template
882 * 1 : csp = Current client state (buffers, headers, etc...)
883 * 2 : rsp = http_response data structure for output
884 * 3 : parameters = map of cgi parameters
886 * CGI Parameters : None
888 * Returns : JB_ERR_OK on success
889 * JB_ERR_MEMORY on out-of-memory error.
891 *********************************************************************/
892 jb_err cgi_send_stylesheet(struct client_state *csp,
893 struct http_response *rsp,
894 const struct map *parameters)
901 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
903 if (err == JB_ERR_FILE)
906 * No way to tell user; send empty stylesheet
908 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
912 return err; /* JB_ERR_MEMORY */
915 if (enlist(rsp->headers, "Content-Type: text/css"))
917 return JB_ERR_MEMORY;
923 /*********************************************************************
925 * Function : cgi_send_user_manual
927 * Description : CGI function that sends a file in the user
931 * 1 : csp = Current client state (buffers, headers, etc...)
932 * 2 : rsp = http_response data structure for output
933 * 3 : parameters = map of cgi parameters
935 * CGI Parameters : file=name.html, the name of the HTML file
936 * (relative to user-manual from config)
938 * Returns : JB_ERR_OK on success
939 * JB_ERR_MEMORY on out-of-memory error.
941 *********************************************************************/
942 jb_err cgi_send_user_manual(struct client_state *csp,
943 struct http_response *rsp,
944 const struct map *parameters)
946 const char * filename;
949 jb_err err = JB_ERR_OK;
956 if (!parameters->first)
958 /* requested http://p.p/user-manual (without trailing slash) */
959 return cgi_redirect(rsp, CGI_PREFIX "user-manual/");
962 get_string_param(parameters, "file", &filename);
963 /* Check paramter for hack attempts */
964 if (filename && strchr(filename, '/'))
966 return JB_ERR_CGI_PARAMS;
968 if (filename && strstr(filename, ".."))
970 return JB_ERR_CGI_PARAMS;
973 full_path = make_path(csp->config->usermanual, filename ? filename : "index.html");
974 if (full_path == NULL)
976 return JB_ERR_MEMORY;
979 /* Open user-manual file */
980 if (NULL == (fp = fopen(full_path, "rb")))
982 log_error(LOG_LEVEL_ERROR, "Cannot open user-manual file %s: %E", full_path);
983 err = cgi_error_no_template(csp, rsp, full_path);
988 /* Get file length */
989 fseek(fp, 0, SEEK_END);
990 length = (size_t)ftell(fp);
991 fseek(fp, 0, SEEK_SET);
993 /* Allocate memory and load the file directly into the body */
994 rsp->body = (char *)zalloc(length+1);
999 return JB_ERR_MEMORY;
1001 if (!fread(rsp->body, length, 1, fp))
1004 * May happen if the file size changes between fseek() and fread().
1005 * If it does, we just log it and serve what we got.
1007 log_error(LOG_LEVEL_ERROR, "Couldn't completely read user-manual file %s.", full_path);
1012 rsp->content_length = length;
1014 /* Guess correct Content-Type based on the filename's ending */
1017 length = strlen(filename);
1023 if((length>=4) && !strcmp(&filename[length-4], ".css"))
1025 err = enlist(rsp->headers, "Content-Type: text/css");
1027 else if((length>=4) && !strcmp(&filename[length-4], ".jpg"))
1029 err = enlist(rsp->headers, "Content-Type: image/jpeg");
1033 err = enlist(rsp->headers, "Content-Type: text/html");
1040 /*********************************************************************
1042 * Function : cgi_show_version
1044 * Description : CGI function that returns a a web page describing the
1045 * file versions of Privoxy.
1048 * 1 : csp = Current client state (buffers, headers, etc...)
1049 * 2 : rsp = http_response data structure for output
1050 * 3 : parameters = map of cgi parameters
1052 * CGI Parameters : none
1054 * Returns : JB_ERR_OK on success
1055 * JB_ERR_MEMORY on out-of-memory error.
1057 *********************************************************************/
1058 jb_err cgi_show_version(struct client_state *csp,
1059 struct http_response *rsp,
1060 const struct map *parameters)
1062 struct map *exports;
1068 if (NULL == (exports = default_exports(csp, "show-version")))
1070 return JB_ERR_MEMORY;
1073 if (map(exports, "sourceversions", 1, show_rcs(), 0))
1076 return JB_ERR_MEMORY;
1079 return template_fill_for_cgi(csp, "show-version", exports, rsp);
1083 /*********************************************************************
1085 * Function : cgi_show_status
1087 * Description : CGI function that returns a web page describing the
1088 * current status of Privoxy.
1091 * 1 : csp = Current client state (buffers, headers, etc...)
1092 * 2 : rsp = http_response data structure for output
1093 * 3 : parameters = map of cgi parameters
1096 * file : Which file to show. Only first letter is checked,
1098 * - "p"ermissions (actions) file
1101 * Default is to show menu and other information.
1103 * Returns : JB_ERR_OK on success
1104 * JB_ERR_MEMORY on out-of-memory error.
1106 *********************************************************************/
1107 jb_err cgi_show_status(struct client_state *csp,
1108 struct http_response *rsp,
1109 const struct map *parameters)
1116 char buf[BUFFER_SIZE];
1117 const char * filename = NULL;
1118 char * file_description = NULL;
1119 #ifdef FEATURE_STATISTICS
1120 float perc_rej; /* Percentage of http requests rejected */
1121 int local_urls_read;
1122 int local_urls_rejected;
1123 #endif /* ndef FEATURE_STATISTICS */
1124 jb_err err = JB_ERR_OK;
1126 struct map *exports;
1132 if (NULL == (exports = default_exports(csp, "show-status")))
1134 return JB_ERR_MEMORY;
1137 switch (*(lookup(parameters, "file")))
1140 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->actions_list[i])
1142 filename = csp->actions_list[i]->filename;
1143 file_description = "Actions File";
1148 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->rlist[i])
1150 filename = csp->rlist[i]->filename;
1151 file_description = "Filter File";
1155 #ifdef FEATURE_TRUST
1159 filename = csp->tlist->filename;
1160 file_description = "Trust File";
1163 #endif /* def FEATURE_TRUST */
1166 if (NULL != filename)
1168 if ( map(exports, "file-description", 1, file_description, 1)
1169 || map(exports, "filepath", 1, html_encode(filename), 0) )
1172 return JB_ERR_MEMORY;
1175 if ((fp = fopen(filename, "rb")) == NULL)
1177 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
1180 return JB_ERR_MEMORY;
1186 * XXX: this code is "quite similar" to the one
1187 * in cgi_send_user_manual() and should be refactored.
1188 * While at it, the return codes for ftell() and fseek
1189 * should be verified.
1192 /* Get file length */
1193 fseek(fp, 0, SEEK_END);
1194 length = (size_t)ftell(fp);
1195 fseek(fp, 0, SEEK_SET);
1197 s = (char *)zalloc(length+1);
1201 return JB_ERR_MEMORY;
1203 if (!fread(s, length, 1, fp))
1206 * May happen if the file size changes between fseek() and fread().
1207 * If it does, we just log it and serve what we got.
1209 log_error(LOG_LEVEL_ERROR, "Couldn't completely read file %s.", filename);
1213 s = html_encode_and_free_original(s);
1216 return JB_ERR_MEMORY;
1219 if (map(exports, "contents", 1, s, 0))
1222 return JB_ERR_MEMORY;
1226 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
1230 for (j = 0; (s != NULL) && (j < Argc); j++)
1232 if (!err) err = string_join (&s, html_encode(Argv[j]));
1233 if (!err) err = string_append(&s, " ");
1235 if (!err) err = map(exports, "invocation", 1, s, 0);
1237 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
1238 if (!err) err = show_defines(exports);
1243 return JB_ERR_MEMORY;
1246 #ifdef FEATURE_STATISTICS
1247 local_urls_read = urls_read;
1248 local_urls_rejected = urls_rejected;
1251 * Need to alter the stats not to include the fetch of this
1254 * Can't do following thread safely! doh!
1257 * urls_rejected--; * This will be incremented subsequently *
1260 if (local_urls_read == 0)
1262 if (!err) err = map_block_killer(exports, "have-stats");
1266 if (!err) err = map_block_killer(exports, "have-no-stats");
1268 perc_rej = (float)local_urls_rejected * 100.0F /
1269 (float)local_urls_read;
1271 snprintf(buf, sizeof(buf), "%d", local_urls_read);
1272 if (!err) err = map(exports, "requests-received", 1, buf, 1);
1274 snprintf(buf, sizeof(buf), "%d", local_urls_rejected);
1275 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
1277 snprintf(buf, sizeof(buf), "%6.2f", perc_rej);
1278 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
1281 #else /* ndef FEATURE_STATISTICS */
1282 err = err || map_block_killer(exports, "statistics");
1283 #endif /* ndef FEATURE_STATISTICS */
1286 * List all action files in use, together with view and edit links,
1287 * except for standard.action, which should only be viewable. (Not
1288 * enforced in the editor itself)
1289 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1292 for (i = 0; i < MAX_AF_FILES; i++)
1294 if (csp->actions_list[i] != NULL)
1296 if (!err) err = string_append(&s, "<tr><td>");
1297 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
1298 snprintf(buf, sizeof(buf),
1299 "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a>", i);
1300 if (!err) err = string_append(&s, buf);
1302 #ifdef FEATURE_CGI_EDIT_ACTIONS
1303 if ((csp->config->feature_flags & RUNTIME_FEATURE_CGI_EDIT_ACTIONS)
1304 && (NULL == strstr(csp->actions_list[i]->filename, "standard.action"))
1305 && (NULL != csp->config->actions_file_short[i]))
1308 if (access(csp->config->actions_file[i], W_OK) == 0)
1310 #endif /* def HAVE_ACCESS */
1311 snprintf(buf, sizeof(buf), " <a href=\"/edit-actions-list?f=%d\">Edit</a>", i);
1312 if (!err) err = string_append(&s, buf);
1317 if (!err) err = string_append(&s, " <strong>No write access.</strong>");
1319 #endif /* def HAVE_ACCESS */
1323 if (!err) err = string_append(&s, "</td></tr>\n");
1328 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
1332 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1336 * List all re_filterfiles in use, together with view options.
1337 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1340 for (i = 0; i < MAX_AF_FILES; i++)
1342 if (csp->rlist[i] != NULL)
1344 if (!err) err = string_append(&s, "<tr><td>");
1345 if (!err) err = string_join(&s, html_encode(csp->rlist[i]->filename));
1347 "</td><td class=\"buttons\"><a href=\"/show-status?file=filter&index=%d\">View</a>", i);
1348 if (!err) err = string_append(&s, buf);
1349 if (!err) err = string_append(&s, "</td></tr>\n");
1354 if (!err) err = map(exports, "re-filter-filenames", 1, s, 0);
1358 if (!err) err = map(exports, "re-filter-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1359 if (!err) err = map_block_killer(exports, "have-filterfile");
1362 #ifdef FEATURE_TRUST
1365 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
1369 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
1370 if (!err) err = map_block_killer(exports, "have-trustfile");
1373 if (!err) err = map_block_killer(exports, "trust-support");
1374 #endif /* ndef FEATURE_TRUST */
1376 #ifdef FEATURE_CGI_EDIT_ACTIONS
1377 if (!err && (csp->config->feature_flags & RUNTIME_FEATURE_CGI_EDIT_ACTIONS))
1379 err = map_block_killer(exports, "cgi-editor-is-disabled");
1381 #endif /* ndef CGI_EDIT_ACTIONS */
1386 return JB_ERR_MEMORY;
1389 return template_fill_for_cgi(csp, "show-status", exports, rsp);
1393 /*********************************************************************
1395 * Function : cgi_show_url_info
1397 * Description : CGI function that determines and shows which actions
1398 * Privoxy will perform for a given url, and which
1399 * matches starting from the defaults have lead to that.
1402 * 1 : csp = Current client state (buffers, headers, etc...)
1403 * 2 : rsp = http_response data structure for output
1404 * 3 : parameters = map of cgi parameters
1407 * url : The url whose actions are to be determined.
1408 * If url is unset, the url-given conditional will be
1409 * set, so that all but the form can be suppressed in
1412 * Returns : JB_ERR_OK on success
1413 * JB_ERR_MEMORY on out-of-memory error.
1415 *********************************************************************/
1416 jb_err cgi_show_url_info(struct client_state *csp,
1417 struct http_response *rsp,
1418 const struct map *parameters)
1421 struct map *exports;
1428 if (NULL == (exports = default_exports(csp, "show-url-info")))
1430 return JB_ERR_MEMORY;
1434 * Get the url= parameter (if present) and remove any leading/trailing spaces.
1436 url_param = strdup(lookup(parameters, "url"));
1437 if (url_param == NULL)
1440 return JB_ERR_MEMORY;
1445 * Handle prefixes. 4 possibilities:
1446 * 1) "http://" or "https://" prefix present and followed by URL - OK
1447 * 2) Only the "http://" or "https://" part is present, no URL - change
1448 * to empty string so it will be detected later as "no URL".
1449 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
1451 * 4) Parameter not specified or is empty string - let this fall through
1452 * for now, next block of code will handle it.
1454 if (0 == strncmp(url_param, "http://", 7))
1456 if (url_param[7] == '\0')
1459 * Empty URL (just prefix).
1460 * Make it totally empty so it's caught by the next if()
1462 url_param[0] = '\0';
1465 else if (0 == strncmp(url_param, "https://", 8))
1467 if (url_param[8] == '\0')
1470 * Empty URL (just prefix).
1471 * Make it totally empty so it's caught by the next if()
1473 url_param[0] = '\0';
1476 else if (url_param[0] != '\0')
1479 * Unknown prefix - assume http://
1481 const size_t url_param_prefixed_size = 7 + 1 + strlen(url_param);
1482 char * url_param_prefixed = malloc(url_param_prefixed_size);
1483 if (NULL == url_param_prefixed)
1487 return JB_ERR_MEMORY;
1489 strlcpy(url_param_prefixed, "http://", url_param_prefixed_size);
1490 strlcat(url_param_prefixed, url_param, url_param_prefixed_size);
1492 url_param = url_param_prefixed;
1496 * Hide "toggle off" warning if Privoxy is toggled on.
1499 #ifdef FEATURE_TOGGLE
1500 (global_toggle_state == 1) &&
1501 #endif /* def FEATURE_TOGGLE */
1502 map_block_killer(exports, "privoxy-is-toggled-off")
1506 return JB_ERR_MEMORY;
1509 if (url_param[0] == '\0')
1511 /* URL paramater not specified, display query form only. */
1513 if (map_block_killer(exports, "url-given")
1514 || map(exports, "url", 1, "", 1))
1517 return JB_ERR_MEMORY;
1522 /* Given a URL, so query it. */
1527 struct file_list *fl;
1528 struct url_actions *b;
1529 struct http_request url_to_query[1];
1530 struct current_action_spec action[1];
1533 if (map(exports, "url", 1, html_encode(url_param), 0))
1537 return JB_ERR_MEMORY;
1540 init_current_action(action);
1542 if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1544 free_current_action(action);
1547 return JB_ERR_MEMORY;
1550 err = parse_http_url(url_param, url_to_query, csp);
1554 if (err == JB_ERR_MEMORY)
1556 free_http_request(url_to_query);
1557 free_current_action(action);
1559 return JB_ERR_MEMORY;
1565 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1566 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1567 if (!err) err = map_block_killer(exports, "valid-url");
1569 free_current_action(action);
1570 free_http_request(url_to_query);
1575 return JB_ERR_MEMORY;
1578 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1582 * We have a warning about SSL paths. Hide it for unencrypted sites.
1584 if (!url_to_query->ssl)
1586 if (map_block_killer(exports, "https"))
1588 free_current_action(action);
1590 free_http_request(url_to_query);
1591 return JB_ERR_MEMORY;
1595 matches = strdup("<table summary=\"\" class=\"transparent\">");
1597 for (i = 0; i < MAX_AF_FILES; i++)
1599 if (NULL == csp->config->actions_file_short[i]
1600 || !strcmp(csp->config->actions_file_short[i], "standard.action")) continue;
1604 if ((fl = csp->actions_list[i]) != NULL)
1606 if ((b = fl->f) != NULL)
1608 /* FIXME: Hardcoded HTML! */
1609 string_append(&matches, "<tr><th>In file: ");
1610 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1611 snprintf(buf, sizeof(buf), " <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1612 string_append(&matches, buf);
1613 string_append(&matches, "View</a>");
1614 #ifdef FEATURE_CGI_EDIT_ACTIONS
1615 if (csp->config->feature_flags & RUNTIME_FEATURE_CGI_EDIT_ACTIONS)
1618 if (access(csp->config->actions_file[i], W_OK) == 0)
1620 #endif /* def HAVE_ACCESS */
1621 snprintf(buf, sizeof(buf),
1622 " <a class=\"cmd\" href=\"/edit-actions-list?f=%d\">", i);
1623 string_append(&matches, buf);
1624 string_append(&matches, "Edit</a>");
1629 string_append(&matches, " <strong>No write access.</strong>");
1631 #endif /* def HAVE_ACCESS */
1633 #endif /* FEATURE_CGI_EDIT_ACTIONS */
1635 string_append(&matches, "</th></tr>\n");
1642 for (; (b != NULL) && (matches != NULL); b = b->next)
1644 if (url_match(b->url, url_to_query))
1646 string_append(&matches, "<tr><td>{");
1647 string_join (&matches, actions_to_html(csp, b->action));
1648 string_append(&matches, " }<br>\n<code>");
1649 string_join (&matches, html_encode(b->url->spec));
1650 string_append(&matches, "</code></td></tr>\n");
1652 if (merge_current_action(action, b->action))
1655 free_http_request(url_to_query);
1656 free_current_action(action);
1658 return JB_ERR_MEMORY;
1666 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1669 string_append(&matches, "</table>\n");
1672 * XXX: Kludge to make sure the "Forward settings" section
1673 * shows what forward-override{} would do with the requested URL.
1674 * No one really cares how the CGI request would be forwarded
1675 * if it wasn't intercepted as CGI request in the first place.
1677 * From here on the action bitmask will no longer reflect
1678 * the real url (http://config.privoxy.org/show-url-info?url=.*),
1679 * but luckily it's no longer required later on anyway.
1681 free_current_action(csp->action);
1682 get_url_actions(csp, url_to_query);
1685 * Fill in forwarding settings.
1687 * The possibilities are:
1689 * - http forwarding only
1690 * - socks4(a) forwarding only
1691 * - socks4(a) and http forwarding.
1693 * XXX: Parts of this code could be reused for the
1694 * "forwarding-failed" template which currently doesn't
1695 * display the proxy port and an eventual second forwarder.
1698 const struct forward_spec *fwd = forward_url(csp, url_to_query);
1700 if ((fwd->gateway_host == NULL) && (fwd->forward_host == NULL))
1702 if (!err) err = map_block_killer(exports, "socks-forwarder");
1703 if (!err) err = map_block_killer(exports, "http-forwarder");
1707 char port[10]; /* We save proxy ports as int but need a string here */
1709 if (!err) err = map_block_killer(exports, "no-forwarder");
1711 if (fwd->gateway_host != NULL)
1713 char *socks_type = NULL;
1718 socks_type = "socks4";
1721 socks_type = "socks4a";
1724 socks_type = "socks5";
1727 log_error(LOG_LEVEL_FATAL, "Unknown socks type: %d.", fwd->type);
1730 if (!err) err = map(exports, "socks-type", 1, socks_type, 1);
1731 if (!err) err = map(exports, "gateway-host", 1, fwd->gateway_host, 1);
1732 snprintf(port, sizeof(port), "%d", fwd->gateway_port);
1733 if (!err) err = map(exports, "gateway-port", 1, port, 1);
1737 if (!err) err = map_block_killer(exports, "socks-forwarder");
1740 if (fwd->forward_host != NULL)
1742 if (!err) err = map(exports, "forward-host", 1, fwd->forward_host, 1);
1743 snprintf(port, sizeof(port), "%d", fwd->forward_port);
1744 if (!err) err = map(exports, "forward-port", 1, port, 1);
1748 if (!err) err = map_block_killer(exports, "http-forwarder");
1753 free_http_request(url_to_query);
1755 if (err || matches == NULL)
1757 free_current_action(action);
1759 return JB_ERR_MEMORY;
1762 #ifdef FEATURE_CGI_EDIT_ACTIONS
1763 if ((csp->config->feature_flags & RUNTIME_FEATURE_CGI_EDIT_ACTIONS))
1765 err = map_block_killer(exports, "cgi-editor-is-disabled");
1767 #endif /* FEATURE_CGI_EDIT_ACTIONS */
1769 if (err || map(exports, "matches", 1, matches , 0))
1771 free_current_action(action);
1773 return JB_ERR_MEMORY;
1776 s = current_action_to_html(csp, action);
1778 free_current_action(action);
1780 if (map(exports, "final", 1, s, 0))
1783 return JB_ERR_MEMORY;
1787 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1791 /*********************************************************************
1793 * Function : cgi_robots_txt
1795 * Description : CGI function to return "/robots.txt".
1798 * 1 : csp = Current client state (buffers, headers, etc...)
1799 * 2 : rsp = http_response data structure for output
1800 * 3 : parameters = map of cgi parameters
1802 * CGI Parameters : None
1804 * Returns : JB_ERR_OK on success
1805 * JB_ERR_MEMORY on out-of-memory error.
1807 *********************************************************************/
1808 jb_err cgi_robots_txt(struct client_state *csp,
1809 struct http_response *rsp,
1810 const struct map *parameters)
1816 "# This is the Privoxy control interface.\n"
1817 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1823 if (rsp->body == NULL)
1825 return JB_ERR_MEMORY;
1828 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1832 get_http_time(7 * 24 * 60 * 60, buf, sizeof(buf)); /* 7 days into future */
1833 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1835 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1839 /*********************************************************************
1841 * Function : show_defines
1843 * Description : Add to a map the state od all conditional #defines
1844 * used when building
1847 * 1 : exports = map to extend
1849 * Returns : JB_ERR_OK on success
1850 * JB_ERR_MEMORY on out-of-memory error.
1852 *********************************************************************/
1853 static jb_err show_defines(struct map *exports)
1855 jb_err err = JB_ERR_OK;
1858 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1859 #else /* ifndef FEATURE_ACL */
1860 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1861 #endif /* ndef FEATURE_ACL */
1863 #ifdef FEATURE_CGI_EDIT_ACTIONS
1864 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1865 #else /* ifndef FEATURE_COOKIE_JAR */
1866 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1867 #endif /* ndef FEATURE_COOKIE_JAR */
1869 #ifdef FEATURE_COOKIE_JAR
1870 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1871 #else /* ifndef FEATURE_COOKIE_JAR */
1872 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1873 #endif /* ndef FEATURE_COOKIE_JAR */
1875 #ifdef FEATURE_FAST_REDIRECTS
1876 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1877 #else /* ifndef FEATURE_FAST_REDIRECTS */
1878 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1879 #endif /* ndef FEATURE_FAST_REDIRECTS */
1881 #ifdef FEATURE_FORCE_LOAD
1882 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1883 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1884 #else /* ifndef FEATURE_FORCE_LOAD */
1885 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1886 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1887 #endif /* ndef FEATURE_FORCE_LOAD */
1889 #ifdef FEATURE_GRACEFUL_TERMINATION
1890 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 1);
1891 #else /* ifndef FEATURE_GRACEFUL_TERMINATION */
1892 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 0);
1893 #endif /* ndef FEATURE_GRACEFUL_TERMINATION */
1895 #ifdef FEATURE_IMAGE_BLOCKING
1896 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1897 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1898 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1899 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1901 #ifdef FEATURE_IMAGE_DETECT_MSIE
1902 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1903 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1904 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1905 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1907 #ifdef FEATURE_NO_GIFS
1908 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1909 #else /* ifndef FEATURE_NO_GIFS */
1910 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1911 #endif /* ndef FEATURE_NO_GIFS */
1913 #ifdef FEATURE_PTHREAD
1914 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1915 #else /* ifndef FEATURE_PTHREAD */
1916 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1917 #endif /* ndef FEATURE_PTHREAD */
1919 #ifdef FEATURE_STATISTICS
1920 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1921 #else /* ifndef FEATURE_STATISTICS */
1922 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1923 #endif /* ndef FEATURE_STATISTICS */
1925 #ifdef FEATURE_TOGGLE
1926 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1927 #else /* ifndef FEATURE_TOGGLE */
1928 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1929 #endif /* ndef FEATURE_TOGGLE */
1931 #ifdef FEATURE_TRUST
1932 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1933 #else /* ifndef FEATURE_TRUST */
1934 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1935 #endif /* ndef FEATURE_TRUST */
1938 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 1);
1939 #else /* ifndef FEATURE_ZLIB */
1940 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 0);
1941 #endif /* ndef FEATURE_ZLIB */
1944 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1945 #else /* ifndef STATIC_PCRE */
1946 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1947 #endif /* ndef STATIC_PCRE */
1950 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1951 #else /* ifndef STATIC_PCRS */
1952 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1953 #endif /* ndef STATIC_PCRS */
1959 /*********************************************************************
1961 * Function : show_rcs
1963 * Description : Create a string with the rcs info for all sourcefiles
1967 * Returns : A string, or NULL on out-of-memory.
1969 *********************************************************************/
1970 static char *show_rcs(void)
1972 char *result = strdup("");
1973 char buf[BUFFER_SIZE];
1975 /* Instead of including *all* dot h's in the project (thus creating a
1976 * tremendous amount of dependencies), I will concede to declaring them
1977 * as extern's. This forces the developer to add to this list, but oh well.
1980 #define SHOW_RCS(__x) \
1982 extern const char __x[]; \
1983 snprintf(buf, sizeof(buf), " %s\n", __x); \
1984 string_append(&result, buf); \
1987 /* In alphabetical order */
1988 SHOW_RCS(actions_h_rcs)
1989 SHOW_RCS(actions_rcs)
1991 SHOW_RCS(amiga_h_rcs)
1993 #endif /* def AMIGA */
1996 #ifdef FEATURE_CGI_EDIT_ACTIONS
1997 SHOW_RCS(cgiedit_h_rcs)
1998 SHOW_RCS(cgiedit_rcs)
1999 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
2000 SHOW_RCS(cgisimple_h_rcs)
2001 SHOW_RCS(cgisimple_rcs)
2003 SHOW_RCS(cygwin_h_rcs)
2005 SHOW_RCS(deanimate_h_rcs)
2006 SHOW_RCS(deanimate_rcs)
2007 SHOW_RCS(encode_h_rcs)
2008 SHOW_RCS(encode_rcs)
2009 SHOW_RCS(errlog_h_rcs)
2010 SHOW_RCS(errlog_rcs)
2011 SHOW_RCS(filters_h_rcs)
2012 SHOW_RCS(filters_rcs)
2013 SHOW_RCS(gateway_h_rcs)
2014 SHOW_RCS(gateway_rcs)
2015 SHOW_RCS(jbsockets_h_rcs)
2016 SHOW_RCS(jbsockets_rcs)
2019 SHOW_RCS(list_h_rcs)
2021 SHOW_RCS(loadcfg_h_rcs)
2022 SHOW_RCS(loadcfg_rcs)
2023 SHOW_RCS(loaders_h_rcs)
2024 SHOW_RCS(loaders_rcs)
2025 SHOW_RCS(miscutil_h_rcs)
2026 SHOW_RCS(miscutil_rcs)
2027 SHOW_RCS(parsers_h_rcs)
2028 SHOW_RCS(parsers_rcs)
2030 SHOW_RCS(pcrs_h_rcs)
2031 SHOW_RCS(project_h_rcs)
2032 SHOW_RCS(ssplit_h_rcs)
2033 SHOW_RCS(ssplit_rcs)
2034 SHOW_RCS(urlmatch_h_rcs)
2035 SHOW_RCS(urlmatch_rcs)
2037 #ifndef _WIN_CONSOLE
2038 SHOW_RCS(w32log_h_rcs)
2039 SHOW_RCS(w32log_rcs)
2040 SHOW_RCS(w32res_h_rcs)
2041 SHOW_RCS(w32taskbar_h_rcs)
2042 SHOW_RCS(w32taskbar_rcs)
2043 #endif /* ndef _WIN_CONSOLE */
2044 SHOW_RCS(win32_h_rcs)
2046 #endif /* def _WIN32 */