1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## 01_local_usermanual.dpatch by Roland Rosenfeld <roland@debian.org>
4 ## All lines beginning with `## DP:' are a description of the patch.
5 ## DP: Add new "cgi" user-manual, which sends the user manual to the client
6 ## DP: and activate it in config file (Closes: #148128).
9 diff -urNad privoxy~/cgi.c privoxy/cgi.c
14 cgi_transparent_image,
15 NULL, TRUE /* Send a transparent image (short name) */ },
17 + cgi_send_user_manual,
18 + NULL, TRUE /* Send user-manual */ },
19 { NULL, /* NULL Indicates end of list and default page */
21 NULL, TRUE /* Unknown CGI page */ }
24 return cgi_error_memory();
27 query_args_start = path_copy;
28 - while (*query_args_start && *query_args_start != '?')
29 + while (*query_args_start && *query_args_start != '?' && *query_args_start != '/')
33 - if (*query_args_start == '?')
34 + if (*query_args_start == '/')
36 *query_args_start++ = '\0';
39 - if (NULL == (param_list = parse_cgi_parameters(query_args_start)))
42 - return cgi_error_memory();
43 + if ((param_list = new_map()))
45 + map(param_list, "file", 1, url_decode(query_args_start), 0);
48 + if (*query_args_start == '?')
50 + *query_args_start++ = '\0';
52 + if (NULL == (param_list = parse_cgi_parameters(query_args_start)))
55 + return cgi_error_memory();
60 @@ -1604,7 +1614,13 @@
61 if (!item) return NULL;
63 result = strdup("<a href=\"");
64 - string_append(&result, config->usermanual);
65 + if (config->usermanual[0] == '/') {
66 + string_append(&result, "http://");
67 + string_append(&result, CGI_SITE_2_HOST);
68 + string_append(&result, "/user-manual/");
70 + string_append(&result, config->usermanual);
72 string_append(&result, ACTIONS_HELP_PREFIX);
73 string_join (&result, string_toupper(item));
74 string_append(&result, "\">");
75 @@ -2193,7 +2209,11 @@
76 if (!err) err = map(exports, "default-cgi", 1, html_encode(CGI_PREFIX), 0);
77 if (!err) err = map(exports, "menu", 1, make_menu(caller), 0);
78 if (!err) err = map(exports, "code-status", 1, CODE_STATUS, 1);
79 - if (!err) err = map(exports, "user-manual", 1, csp->config->usermanual ,1);
80 + if (csp->config->usermanual[0] == '/') {
81 + if (!err) err = map(exports, "user-manual", 1, "http://"CGI_SITE_2_HOST"/user-manual/" ,1);
83 + if (!err) err = map(exports, "user-manual", 1, csp->config->usermanual ,1);
85 if (!err) err = map(exports, "actions-help-prefix", 1, ACTIONS_HELP_PREFIX ,1);
87 if (!err) err = map_conditional(exports, "enabled-display", global_toggle_state);
88 diff -urNad privoxy~/cgisimple.c privoxy/cgisimple.c
89 --- privoxy~/cgisimple.c
90 +++ privoxy/cgisimple.c
95 +/*********************************************************************
97 + * Function : cgi_send_user_manual
99 + * Description : CGI function that sends a user manual HTML file
102 + * 1 : csp = Current client state (buffers, headers, etc...)
103 + * 2 : rsp = http_response data structure for output
104 + * 3 : parameters = map of cgi parameters
106 + * CGI Parameters : file=name.html, the mane of the HTML file
107 + * (relative to user-manual from config)
109 + * Returns : JB_ERR_OK on success
110 + * JB_ERR_MEMORY on out-of-memory error.
112 + *********************************************************************/
113 +jb_err cgi_send_user_manual(struct client_state *csp,
114 + struct http_response *rsp,
115 + const struct map *parameters)
117 + const char * filename;
120 + char buf[BUFFER_SIZE];
124 + assert(parameters);
126 + get_string_param(parameters, "file", &filename);
127 + /* Check paramter for hack attempts */
128 + if (filename && strchr(filename, '/')) {
129 + return JB_ERR_CGI_PARAMS;
131 + if (filename && strstr(filename, "..")) {
132 + return JB_ERR_CGI_PARAMS;
135 + full_path = make_path(csp->config->usermanual,
136 + filename?filename:"index.html");
137 + if (full_path == NULL)
139 + return JB_ERR_MEMORY;
142 + /* Allocate buffer */
143 + rsp->body = strdup("");
144 + if (rsp->body == NULL)
147 + return JB_ERR_MEMORY;
150 + /* Open user-manual file */
151 + if (NULL == (fp = fopen(full_path, "r")))
153 + log_error(LOG_LEVEL_ERROR, "Cannot open user-manual file %s: %E", full_path);
156 + return JB_ERR_FILE;
160 + /* Read file and write it out */
161 + while (fgets(buf, BUFFER_SIZE, fp))
163 + if (string_append(&rsp->body, buf))
166 + return JB_ERR_MEMORY;
171 + if (enlist(rsp->headers, "Content-Type: text/html"))
173 + return JB_ERR_MEMORY;
180 /*********************************************************************
181 diff -urNad privoxy~/cgisimple.h privoxy/cgisimple.h
182 --- privoxy~/cgisimple.h
183 +++ privoxy/cgisimple.h
185 extern jb_err cgi_send_stylesheet(struct client_state *csp,
186 struct http_response *rsp,
187 const struct map *parameters);
188 +extern jb_err cgi_send_user_manual(struct client_state *csp,
189 + struct http_response *rsp,
190 + const struct map *parameters);
192 #ifdef FEATURE_GRACEFUL_TERMINATION
193 extern jb_err cgi_die (struct client_state *csp,
194 diff -urNad privoxy~/loadcfg.c privoxy/loadcfg.c
195 --- privoxy~/loadcfg.c
196 +++ privoxy/loadcfg.c
197 @@ -1605,7 +1605,13 @@
198 * link to it's section in the user-manual
200 buf = strdup("\n<br><a href=\"");
201 - string_append(&buf, config->usermanual);
202 + if (config->usermanual[0] == '/') {
203 + string_append(&buf, "http://");
204 + string_append(&buf, CGI_SITE_2_HOST);
205 + string_append(&buf, "/user-manual/");
207 + string_append(&buf, config->usermanual);
209 string_append(&buf, CONFIG_HELP_PREFIX);
210 string_join (&buf, string_toupper(command));
211 string_append(&buf, "\">");