optionally access the user-manual via Privoxy. Closes patch 679075.
Formatting changed to Privoxy style, added call to
cgi_error_no_template if the requested file doesn't
exist and modified check whether or not Privoxy itself
should serve the manual. Should work cross-platform now.
-const char cgi_rcs[] = "$Id: cgi.c,v 1.72 2006/07/18 14:48:45 david__schmidt Exp $";
+const char cgi_rcs[] = "$Id: cgi.c,v 1.73 2006/08/03 02:46:41 david__schmidt Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/cgi.c,v $
*
* Revisions :
* $Log: cgi.c,v $
+ * Revision 1.73 2006/08/03 02:46:41 david__schmidt
+ * Incorporate Fabian Keil's patch work:\rhttp://www.fabiankeil.de/sourcecode/privoxy/
+ *
* Revision 1.72 2006/07/18 14:48:45 david__schmidt
* Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
* with what was really the latest development (the v_3_0_branch branch)
{ "t",
cgi_transparent_image,
NULL, TRUE /* Send a transparent image (short name) */ },
+ { "user-manual",
+ cgi_send_user_manual,
+ NULL /* Send user-manual */ },
{ NULL, /* NULL Indicates end of list and default page */
cgi_error_404,
NULL, TRUE /* Unknown CGI page */ }
{
return cgi_error_memory();
}
-
query_args_start = path_copy;
- while (*query_args_start && *query_args_start != '?')
+ while (*query_args_start && *query_args_start != '?' && *query_args_start != '/')
{
query_args_start++;
}
- if (*query_args_start == '?')
+ if (*query_args_start == '/')
{
*query_args_start++ = '\0';
+ if ((param_list = new_map()))
+ {
+ map(param_list, "file", 1, url_decode(query_args_start), 0);
+ }
}
-
- if (NULL == (param_list = parse_cgi_parameters(query_args_start)))
+ else
{
- free(path_copy);
- return cgi_error_memory();
+ if (*query_args_start == '?')
+ {
+ *query_args_start++ = '\0';
+ }
+ if (NULL == (param_list = parse_cgi_parameters(query_args_start)))
+ {
+ free(path_copy);
+ return cgi_error_memory();
+ }
}
/*
if (!item) return NULL;
result = strdup("<a href=\"");
- string_append(&result, config->usermanual);
+ if (!strncmpic(config->usermanual, "file://", 7) ||
+ !strncmpic(config->usermanual, "http", 4))
+ {
+ string_append(&result, config->usermanual);
+ }
+ else
+ {
+ string_append(&result, "http://");
+ string_append(&result, CGI_SITE_2_HOST);
+ string_append(&result, "/user-manual/");
+ }
string_append(&result, ACTIONS_HELP_PREFIX);
string_join (&result, string_toupper(item));
string_append(&result, "\">");
if (!err) err = map(exports, "default-cgi", 1, html_encode(CGI_PREFIX), 0);
if (!err) err = map(exports, "menu", 1, make_menu(caller), 0);
if (!err) err = map(exports, "code-status", 1, CODE_STATUS, 1);
- if (!err) err = map(exports, "user-manual", 1, csp->config->usermanual ,1);
+ if (!strncmpic(csp->config->usermanual, "file://", 7) ||
+ !strncmpic(csp->config->usermanual, "http", 4))
+ {
+ if (!err) err = map(exports, "user-manual", 1, csp->config->usermanual ,1);
+ }
+ else
+ {
+ if (!err) err = map(exports, "user-manual", 1, "http://"CGI_SITE_2_HOST"/user-manual/" ,1);
+ }
if (!err) err = map(exports, "actions-help-prefix", 1, ACTIONS_HELP_PREFIX ,1);
#ifdef FEATURE_TOGGLE
if (!err) err = map_conditional(exports, "enabled-display", global_toggle_state);
-const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.35.2.7 2006/01/29 23:10:56 david__schmidt Exp $";
+const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.37 2006/07/18 14:48:45 david__schmidt Exp $";
/*********************************************************************
*
- * File : $Source: /cvsroot/ijbswa/current/Attic/cgisimple.c,v $
+ * File : $Source: /cvsroot/ijbswa/current/cgisimple.c,v $
*
* Purpose : Simple CGIs to get information about Privoxy's
* status.
*
* Revisions :
* $Log: cgisimple.c,v $
+ * Revision 1.37 2006/07/18 14:48:45 david__schmidt
+ * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
+ * with what was really the latest development (the v_3_0_branch branch)
+ *
* Revision 1.35.2.7 2006/01/29 23:10:56 david__schmidt
* Multiple filter file support
*
return JB_ERR_OK;
}
+/*********************************************************************
+ *
+ * Function : cgi_send_user_manual
+ *
+ * Description : CGI function that sends a user manual HTML file
+ *
+ * Parameters :
+ * 1 : csp = Current client state (buffers, headers, etc...)
+ * 2 : rsp = http_response data structure for output
+ * 3 : parameters = map of cgi parameters
+ *
+ * CGI Parameters : file=name.html, the name of the HTML file
+ * (relative to user-manual from config)
+ *
+ * Returns : JB_ERR_OK on success
+ * JB_ERR_MEMORY on out-of-memory error.
+ *
+ *********************************************************************/
+jb_err cgi_send_user_manual(struct client_state *csp,
+ struct http_response *rsp,
+ const struct map *parameters)
+{
+ const char * filename;
+ char *full_path;
+ FILE *fp;
+ char buf[BUFFER_SIZE];
+ jb_err err = JB_ERR_OK;
+
+ assert(csp);
+ assert(rsp);
+ assert(parameters);
+
+ get_string_param(parameters, "file", &filename);
+ /* Check paramter for hack attempts */
+ if (filename && strchr(filename, '/'))
+ {
+ return JB_ERR_CGI_PARAMS;
+ }
+ if (filename && strstr(filename, ".."))
+ {
+ return JB_ERR_CGI_PARAMS;
+ }
+
+ full_path = make_path(csp->config->usermanual, filename ? filename : "index.html");
+ if (full_path == NULL)
+ {
+ return JB_ERR_MEMORY;
+ }
+
+ /* Allocate buffer */
+ rsp->body = strdup("");
+ if (rsp->body == NULL)
+ {
+ free(full_path);
+ return JB_ERR_MEMORY;
+ }
+
+ /* Open user-manual file */
+ if (NULL == (fp = fopen(full_path, "r")))
+ {
+ log_error(LOG_LEVEL_ERROR, "Cannot open user-manual file %s: %E", full_path);
+ err = cgi_error_no_template(csp, rsp, full_path);
+ free(full_path);
+ return err;
+ }
+ free(full_path);
+
+ /* Read file and write it out */
+ while (fgets(buf, BUFFER_SIZE, fp))
+ {
+ if (string_append(&rsp->body, buf))
+ {
+ fclose(fp);
+ return JB_ERR_MEMORY;
+ }
+ }
+ fclose(fp);
+
+ if (enlist(rsp->headers, "Content-Type: text/html"))
+ {
+ return JB_ERR_MEMORY;
+ }
+
+ return JB_ERR_OK;
+}
/*********************************************************************
#ifndef CGISIMPLE_H_INCLUDED
#define CGISIMPLE_H_INCLUDED
-#define CGISIMPLE_H_VERSION "$Id: cgisimple.h,v 1.11 2002/04/05 15:50:53 oes Exp $"
+#define CGISIMPLE_H_VERSION "$Id: cgisimple.h,v 1.13 2006/07/18 14:48:45 david__schmidt Exp $"
/*********************************************************************
*
- * File : $Source: /cvsroot/ijbswa/current/Attic/cgisimple.h,v $
+ * File : $Source: /cvsroot/ijbswa/current/cgisimple.h,v $
*
* Purpose : Declares functions to intercept request, generate
* html or gif answers, and to compose HTTP resonses.
*
* Revisions :
* $Log: cgisimple.h,v $
+ * Revision 1.13 2006/07/18 14:48:45 david__schmidt
+ * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
+ * with what was really the latest development (the v_3_0_branch branch)
+ *
* Revision 1.11 2002/04/05 15:50:53 oes
* added send-stylesheet CGI
*
extern jb_err cgi_send_stylesheet(struct client_state *csp,
struct http_response *rsp,
const struct map *parameters);
+extern jb_err cgi_send_user_manual(struct client_state *csp,
+ struct http_response *rsp,
+ const struct map *parameters);
+
#ifdef FEATURE_GRACEFUL_TERMINATION
extern jb_err cgi_die (struct client_state *csp,
-const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.51 2006/09/06 09:23:37 fabiankeil Exp $";
+const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.52 2006/09/06 10:43:32 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
*
* Revisions :
* $Log: loadcfg.c,v $
+ * Revision 1.52 2006/09/06 10:43:32 fabiankeil
+ * Added config option enable-remote-http-toggle
+ * to specify if Privoxy should recognize special
+ * headers (currently only X-Filter) to change its
+ * behaviour. Disabled by default.
+ *
* Revision 1.51 2006/09/06 09:23:37 fabiankeil
* Make number of retries in case of forwarded-connect problems
* a config file option (forwarded-connect-retries) and use 0 as
* link to it's section in the user-manual
*/
buf = strdup("\n<br><a href=\"");
- string_append(&buf, config->usermanual);
+ if (!strncmpic(config->usermanual, "file://", 7) ||
+ !strncmpic(config->usermanual, "http", 4))
+ {
+ string_append(&buf, config->usermanual);
+ }
+ else
+ {
+ string_append(&buf, "http://");
+ string_append(&buf, CGI_SITE_2_HOST);
+ string_append(&buf, "/user-manual/");
+ }
string_append(&buf, CONFIG_HELP_PREFIX);
string_join (&buf, string_toupper(command));
string_append(&buf, "\">");