2 MiddleMan filtering proxy server
3 Copyright (C) 2002 Jason McLaughlin
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 extern char configfile[];
28 extern THREADLIST threads[];
29 extern pthread_mutex_t dns_cache_lock;
30 extern HASH_TABLE *dns_cache;
31 extern FILTER_LIST *filter_list;
32 extern HEADER_LIST *header_list;
33 extern MIME_LIST *mime_list;
34 extern REDIRECT_LIST *redirect_list;
35 extern KEYWORD_LIST *keyword_list;
36 extern ACCESS_LIST *access_list;
37 extern COOKIE_LIST *cookie_list;
38 extern REWRITE_LIST *rewrite_list;
39 extern FORWARD_LIST *forward_list;
40 extern TEMPLATES *templates;
41 extern EXTERNAL *external;
42 extern NETWORK *network;
43 extern LOGBUFFER *logbuffer;
47 void (*handler) (FILEBUF *, struct cgi_args_t *, CONNECTION *);
50 struct pages_t pages[] = {
51 {"/connections", interface_page_connections},
52 {"/dnscache", interface_page_dnscache},
53 {"/headers", interface_page_headers},
54 {"/config", interface_page_config},
55 {"/save", interface_page_save},
56 {"/load", interface_page_load},
57 {"/log", interface_page_log},
61 struct pages_t config_pages[] = {
62 {"filter", interface_page_config_filter},
63 {"access", interface_page_config_access},
64 {"rewrite", interface_page_config_rewrite},
65 {"mime", interface_page_config_mime},
66 {"cookies", interface_page_config_cookies},
67 {"external", interface_page_config_external},
68 {"templates", interface_page_config_templates},
69 {"network", interface_page_config_network},
70 {"header", interface_page_config_header},
71 {"redirect", interface_page_config_redirect},
72 {"forward", interface_page_config_forward},
73 {"keywords", interface_page_config_keywords},
77 struct pages_t action_pages[] = {
78 {"filter", interface_page_config_filter_action},
79 {"external", interface_page_config_external_action},
80 {"rewrite", interface_page_config_rewrite_action},
81 {"access", interface_page_config_access_action},
82 {"mime", interface_page_config_mime_action},
83 {"templates", interface_page_config_templates_action},
84 {"header", interface_page_config_header_action},
85 {"cookies", interface_page_config_cookies_action},
86 {"redirect", interface_page_config_redirect_action},
87 {"forward", interface_page_config_forward_action},
88 {"keywords", interface_page_config_keywords_action},
92 struct pages_t dialog_pages[] = {
93 {"filter", interface_page_config_filter_dialog},
94 {"external", interface_page_config_external_dialog},
95 {"rewrite", interface_page_config_rewrite_dialog},
96 {"access", interface_page_config_access_dialog},
97 {"mime", interface_page_config_mime_dialog},
98 {"templates", interface_page_config_templates_dialog},
99 {"header", interface_page_config_header_dialog},
100 {"cookies", interface_page_config_cookies_dialog},
101 {"redirect", interface_page_config_redirect_dialog},
102 {"forward", interface_page_config_forward_dialog},
103 {"keywords", interface_page_config_keywords_dialog},
107 struct cgi_args_t *cgi_parse_request(char *file)
109 int pos = 0, astart = 0, aequal = -1;
110 struct cgi_args_t *args = NULL, *start = NULL;
112 for (; file[pos]; pos++) {
113 if (file[pos] == '=')
115 else if (file[pos] == '&' && aequal != -1) {
117 args = xmalloc(sizeof(struct cgi_args_t));
120 args->next = xmalloc(sizeof(struct cgi_args_t));
124 args->name = url_decode(&file[astart], aequal - astart);
125 args->value = url_decode(&file[aequal + 1], pos - aequal - 1);
136 args = xmalloc(sizeof(struct cgi_args_t));
139 args->next = xmalloc(sizeof(struct cgi_args_t));
145 args->name = url_decode(&file[astart], aequal - astart);
146 args->value = url_decode(&file[aequal + 1], pos - aequal - 1);
152 void cgi_args_free(struct cgi_args_t *args)
154 struct cgi_args_t *tmp;
156 while (args != NULL) {
167 void interface_handle_request(CONNECTION * connection)
170 char *ptr = NULL, *file;
173 struct cgi_args_t *args = NULL;
175 if (!strncasecmp(&connection->header->file[(connection->header->type == HTTP_REQUEST) ? strlen(INTERFACEURL) + 1 : 0], "/template/", 9)) {
176 template_send(templates, &connection->header->file[(connection->header->type == HTTP_REQUEST) ? strlen(INTERFACEURL) + 11 : 10], connection, 200);
181 if (!(connection->access & ACCESS_CONFIG)) {
182 template_send(templates, "noaccess", connection, 403);
187 header = header_new();
189 header->type = HTTP_RESP;
191 header->version = HTTP_HTTP11;
192 header->content_type = xstrdup("text/html");
194 if (connection->header->type == HTTP_REQUEST) {
195 /* we wouldn't be here if connection->header->file wasn't this big */
196 file = connection->header->file + strlen(INTERFACEURL) + 1;
199 /* send redirect to correct relative links */
202 header->content_length = 0;
203 header->location = xmalloc(strlen(INTERFACEURL) + 2);
204 sprintf(header->location, "%s/", INTERFACEURL);
206 header_send(header, connection, CLIENT, HEADER_RESP);
208 http_header_free(header);
213 file = connection->header->file;
216 if (strcasecmp(connection->header->method, "POST")) {
217 /* retrieve cgi arguments from GET request */
218 ptr = strchr(file, '?');
220 args = cgi_parse_request(&ptr[1]);
221 } else if (connection->header->content_length != -1) {
222 /* retrieve form data from POST request */
223 filebuf = http_transfer_filebuf(connection, CLIENT);
224 filebuf_add(filebuf, "", 1);
226 args = cgi_parse_request(filebuf->data);
228 filebuf_free(filebuf);
231 filebuf = filebuf_new();
233 filebuf_addf(filebuf, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
234 filebuf_addf(filebuf, "<html><head><title>Middleman %s web interface</title></head>\n", MMAN_VERSION);
235 filebuf_addf(filebuf, "<body bgcolor=\"%s\" text=\"%s\" link=\"%s\" vlink=\"%s\">\n", INTERFACE_BG, INTERFACE_TEXT, INTERFACE_LINK, INTERFACE_VLINK);
236 filebuf_addf(filebuf, "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n");
237 filebuf_addf(filebuf, "<tr><td align=\"center\">\n");
238 filebuf_addf(filebuf, "<table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" width=\"60%%\" bgcolor=\"%s\"><tr><td align=\"center\"><font size=\"6\">Middleman Web interface</font></td></tr></table>\n", INTERFACE_TABLEBG);
239 filebuf_addf(filebuf, "</td></tr><tr><td><br></td></tr>\n");
240 filebuf_addf(filebuf, "<tr><td><table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" width=\"100%\" bgcolor=\"%s\"><tr align=\"center\">\n", INTERFACE_TABLEBG);
241 filebuf_addf(filebuf, "<td><a href=\"connections\">Active connections</a></td>\n");
242 filebuf_addf(filebuf, "<td><a href=\"config\">Config</a></td>\n");
243 filebuf_addf(filebuf, "<td><a href=\"dnscache\">DNS cache</a></td>\n");
244 filebuf_addf(filebuf, "<td><a href=\"headers\">Show headers</a></td></tr>\n");
245 filebuf_addf(filebuf, "<tr align=\"center\">\n");
246 filebuf_addf(filebuf, "<td colspan=\"2\"><a href=\"save\">Save settings</a></td>\n");
247 filebuf_addf(filebuf, "<td colspan=\"2\"><a href=\"load\">Load settings</a></td>\n");
248 filebuf_addf(filebuf, "</tr>\n");
249 filebuf_addf(filebuf, "<tr align=\"center\"><td colspan=\"4\"><a href=\"log\">View log entries</a></td></tr>\n");
250 filebuf_addf(filebuf, "</table></td></tr>\n<tr><td><br></td></tr><tr><td>\n");
252 for (i = 0; pages[i].file != NULL; i++) {
253 if (!strncasecmp(file, pages[i].file, (ptr != NULL) ? ptr - file : ~0))
254 pages[i].handler(filebuf, args, connection);
257 filebuf_addf(filebuf, "</td></tr></table></body></html>\n");
259 header->content_length = filebuf->size;
261 header_send(header, connection, CLIENT, HEADER_RESP);
263 if (strcasecmp(connection->header->method, "HEAD"))
264 net_filebuf_send(filebuf, connection, CLIENT);
268 http_header_free(header);
269 filebuf_free(filebuf);
272 void interface_page_connections(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
276 filebuf_addf(filebuf, "<table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" width=\"100%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
278 filebuf_addf(filebuf, "<tr><td>PID</td><td>IP</td><td>Requests</td><td>Method</td><td>Host</td><td>Port</td><td>File</td></tr>\n");
280 for (i = 0; i < MAXTHREADS; i++) {
281 pthread_mutex_lock(&threads[i].lock);
282 if (threads[i].flags != THREAD_UNUSED && threads[i].flags != THREAD_IDLE)
283 filebuf_addf(filebuf, "<tr><td>%d</td><td>%s</td><td>%d</td><td>%s</td><td>%s</td><td>%d</td><td>%s</td></tr>\n", threads[i].pid, threads[i].ip, threads[i].requests, (threads[i].method != NULL) ? threads[i].method : "NONE", (threads[i].host != NULL) ? threads[i].host : "NONE", threads[i].port, (threads[i].file != NULL) ? threads[i].file : "NONE");
285 pthread_mutex_unlock(&threads[i].lock);
288 filebuf_addf(filebuf, "</table>\n");
291 void interface_page_dnscache(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
294 struct HASH_LIST *hash_list;
296 filebuf_addf(filebuf, "<table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" width=\"100%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
298 filebuf_addf(filebuf, "<tr><td>Hostname</td><td>IP address</td></tr>\n");
300 pthread_mutex_lock(&dns_cache_lock);
301 for (i = 0; i < dns_cache->size; i++) {
302 hash_list = dns_cache->hash_list[i];
304 for (; hash_list; hash_list = hash_list->next)
305 filebuf_addf(filebuf, "<tr><td>%s</td><td>%s</td></tr>\n", hash_list->ref, (char *) hash_list->data);
308 filebuf_addf(filebuf, "</table>\n");
310 pthread_mutex_unlock(&dns_cache_lock);
313 void interface_page_headers(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
315 struct HTTP_HEADER_LIST *header_list;
318 filebuf_addf(filebuf, "<tr><td><table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" width=\"100%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
319 filebuf_addf(filebuf, "<tr><th colspan=\"2\">Unfiltered</th></tr>\n");
320 filebuf_addf(filebuf, "<tr><td>Type</td><td>Value</td></tr>\n");
322 for (header_list = connection->header->header; header_list; header_list = header_list->next)
323 if (!bad_header(header_list->type, HEADER_DIRECT)) filebuf_addf(filebuf, "<tr><td>%s</td><td>%s</td></tr>\n", header_list->type, header_list->value);
325 filebuf_addf(filebuf, "</table></td></tr>\n");
327 filebuf_addf(filebuf, "<tr><td><br></td></tr>\n");
329 filebuf_addf(filebuf, "<tr><td><table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" width=\"100%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
330 filebuf_addf(filebuf, "<tr><th colspan=\"2\">Filtered</th></tr>\n");
331 filebuf_addf(filebuf, "<tr><td>Type</td><td>Value</td></tr>\n");
333 for (header_list = connection->header->header_filtered; header_list; header_list = header_list->next)
334 if (!bad_header(header_list->type, HEADER_DIRECT)) filebuf_addf(filebuf, "<tr><td>%s</td><td>%s</td></tr>\n", header_list->type, header_list->value);
336 filebuf_addf(filebuf, "</table></td></tr>\n");
339 void interface_page_save(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
342 char *filename = NULL;
344 for (; args; args = args->next)
345 if (!strcasecmp(args->name, "filename"))
346 filename = args->value;
348 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\"><tr><td align=\"center\">\n");
350 if (filename == NULL) {
351 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
352 filebuf_addf(filebuf, "<form action=\"save\" method=\"POST\">\n");
353 filebuf_addf(filebuf, "<tr><td>Filename</td><td><input type=\"text\" name=\"filename\" value=\"%s\" size=\"80\"></td></tr>\n", (*configfile) ? configfile : "");
354 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
355 filebuf_addf(filebuf, "</form></table>\n");
357 filebuf_addf(filebuf, "</td></tr></table>\n");
362 ret = config_save(filename);
364 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
365 filebuf_addf(filebuf, "<tr><td align=\"center\">\n");
367 filebuf_addf(filebuf, "File saved\n");
369 filebuf_addf(filebuf, "Saved failed\n");
371 filebuf_addf(filebuf, "</td></tr></table></td></tr></table>\n");
374 void interface_page_load(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
376 int ret, overwrite = FALSE;
377 char *filename = NULL;
379 for (; args; args = args->next) {
380 if (!strcasecmp(args->name, "filename"))
381 filename = args->value;
382 else if (!strcasecmp(args->name, "overwrite")) {
383 if (!strcasecmp(args->value, "yes"))
390 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\"><tr><td align=\"center\">\n");
392 if (filename == NULL) {
393 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
394 filebuf_addf(filebuf, "<form action=\"load\" method=\"POST\">\n");
395 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Filename</td><td><input type=\"text\" name=\"filename\" value=\"%s\" size=\"80\"></td></tr>\n", (*configfile) ? configfile : "");
396 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Overwrite</td><td align=\"center\">Yes: <input type=\"radio\" name=\"overwrite\" value=\"yes\" checked> No: <input type=\"radio\" name=\"overwrite\" value=\"no\"></td></tr>\n");
397 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
398 filebuf_addf(filebuf, "</form></table>\n");
400 filebuf_addf(filebuf, "</td></tr></table>\n");
405 ret = config_load(overwrite, filename);
407 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
408 filebuf_addf(filebuf, "<tr><td align=\"center\">\n");
411 filebuf_addf(filebuf, "File loaded\n");
413 filebuf_addf(filebuf, "Load failed\n");
415 filebuf_addf(filebuf, "</td></tr></table></td></tr></table>\n");
418 void interface_page_log(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
420 int size = -1, clear = FALSE;
421 char *ptr, *pattern = NULL;
422 struct LOGBUFFER_LIST *ll;
423 struct cgi_args_t *a;
426 for (a = args; a; a = a->next) {
427 if (!strcasecmp(a->name, "pattern"))
429 if (!strcasecmp(a->name, "clear"))
431 if (!strcasecmp(a->name, "size"))
432 size = atoi(a->value);
436 logbuffer_clear(logbuffer);
438 logbuffer_resize(logbuffer, size);
440 pthread_rwlock_rdlock(&logbuffer->lock);
442 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\"><tr><td align=\"center\">\n");
443 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
444 filebuf_addf(filebuf, "<form action=\"log\" method=\"POST\">\n");
445 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\">Regular expression match</td></tr>\n");
446 filebuf_addf(filebuf, "<tr><td align=\"center\" colspan=\"2\"><input type=\"text\" name=\"pattern\" value=\"%s\" size=\"80\"></td></tr>\n", (pattern != NULL) ? pattern : "");
447 filebuf_addf(filebuf, "<tr><td align=\"center\">Log buffer size: <input type=\"text\" name=\"size\" value=\"%d\" size=\"10\"></td>\n", logbuffer->size);
448 filebuf_addf(filebuf, "<td align=\"center\">Clear: <input type=\"checkbox\" name=\"clear\" value=\"yes\"></td></tr>");
449 filebuf_addf(filebuf, "<tr><td align=\"center\" colspan=\"2\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
450 filebuf_addf(filebuf, "</form></table></td></tr><tr><td><br></td></tr>\n");
452 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"100%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
454 pthread_rwlock_unlock(&logbuffer->lock);
456 if (pattern != NULL && strcmp(pattern, ""))
457 pe = reg_compile(pattern, REGFLAGS);
459 pthread_rwlock_rdlock(&logbuffer->lock);
461 for (ll = logbuffer->head; ll; ll = ll->next) {
463 if (reg_exec(pe, ll->msg))
466 ptr = string_to_html(ll->msg, TRUE);
467 filebuf_addf(filebuf, "<tr><td>%s</td></tr>\n", ptr);
474 filebuf_addf(filebuf, "</table></td></tr></table>\n");
476 pthread_rwlock_unlock(&logbuffer->lock);
478 void interface_page_config(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
481 char *section = NULL, *action = NULL, *dialog = NULL;
482 struct cgi_args_t *a;
484 for (a = args; a != NULL; a = a->next) {
485 if (!strcasecmp(a->name, "section"))
487 else if (!strcasecmp(a->name, "action"))
489 else if (!strcasecmp(a->name, "dialog"))
491 else if (!strcasecmp(a->name, "filter")) {
492 pthread_rwlock_wrlock(&filter_list->lock);
493 if (!strcasecmp(a->value, "off"))
494 filter_list->enabled = FALSE;
496 filter_list->enabled = TRUE;
497 pthread_rwlock_unlock(&filter_list->lock);
498 } else if (!strcasecmp(a->name, "header")) {
499 pthread_rwlock_wrlock(&header_list->lock);
500 if (!strcasecmp(a->value, "off"))
501 header_list->enabled = FALSE;
503 header_list->enabled = TRUE;
504 pthread_rwlock_unlock(&header_list->lock);
505 } else if (!strcasecmp(a->name, "mime")) {
506 pthread_rwlock_wrlock(&mime_list->lock);
507 if (!strcasecmp(a->value, "off"))
508 mime_list->enabled = FALSE;
510 mime_list->enabled = TRUE;
511 pthread_rwlock_unlock(&mime_list->lock);
512 } else if (!strcasecmp(a->name, "cookie")) {
513 pthread_rwlock_wrlock(&cookie_list->lock);
514 if (!strcasecmp(a->value, "off"))
515 cookie_list->enabled = FALSE;
517 cookie_list->enabled = TRUE;
518 pthread_rwlock_unlock(&cookie_list->lock);
519 } else if (!strcasecmp(a->name, "redirect")) {
520 pthread_rwlock_wrlock(&redirect_list->lock);
521 if (!strcasecmp(a->value, "off"))
522 redirect_list->enabled = FALSE;
524 redirect_list->enabled = TRUE;
525 pthread_rwlock_unlock(&redirect_list->lock);
526 } else if (!strcasecmp(a->name, "rewrite")) {
527 pthread_rwlock_wrlock(&rewrite_list->lock);
528 if (!strcasecmp(a->value, "off"))
529 rewrite_list->enabled = FALSE;
531 rewrite_list->enabled = TRUE;
532 pthread_rwlock_unlock(&rewrite_list->lock);
533 } else if (!strcasecmp(a->name, "keywords")) {
534 pthread_rwlock_wrlock(&keyword_list->lock);
535 if (!strcasecmp(a->value, "off"))
536 keyword_list->enabled = FALSE;
538 keyword_list->enabled = TRUE;
539 pthread_rwlock_unlock(&keyword_list->lock);
540 } else if (!strcasecmp(a->name, "external")) {
541 pthread_rwlock_wrlock(&external->lock);
542 if (!strcasecmp(a->value, "off"))
543 external->enabled = FALSE;
545 external->enabled = TRUE;
546 pthread_rwlock_unlock(&external->lock);
547 } else if (!strcasecmp(a->name, "forward")) {
548 pthread_rwlock_wrlock(&forward_list->lock);
549 if (!strcasecmp(a->value, "off"))
550 forward_list->enabled = FALSE;
552 forward_list->enabled = TRUE;
553 pthread_rwlock_unlock(&forward_list->lock);
558 filebuf_addf(filebuf, "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tr><td align=\"center\">\n");
559 filebuf_addf(filebuf, "<table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" width=\"60%\" bgcolor=\"%s\"><tr><td align=\"center\">\n", INTERFACE_TABLEBG);
560 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
561 filebuf_addf(filebuf, "<select name=\"section\">\n");
562 filebuf_addf(filebuf, "<option value=\"\">Select a section\n");
563 filebuf_addf(filebuf, "<option value=\"access\" %s>access\n", (section != NULL && !strcasecmp(section, "access")) ? "selected" : "");
564 filebuf_addf(filebuf, "<option value=\"filter\" %s>filter\n", (section != NULL && !strcasecmp(section, "filter")) ? "selected" : "");
565 filebuf_addf(filebuf, "<option value=\"network\" %s>network\n", (section != NULL && !strcasecmp(section, "network")) ? "selected" : "");
566 filebuf_addf(filebuf, "<option value=\"mime\" %s>mime\n", (section != NULL && !strcasecmp(section, "mime")) ? "selected" : "");
567 filebuf_addf(filebuf, "<option value=\"redirect\" %s>redirect\n", (section != NULL && !strcasecmp(section, "redirect")) ? "selected" : "");
568 filebuf_addf(filebuf, "<option value=\"forward\" %s>forward\n", (section != NULL && !strcasecmp(section, "forward")) ? "selected" : "");
569 filebuf_addf(filebuf, "<option value=\"header\" %s>header\n", (section != NULL && !strcasecmp(section, "header")) ? "selected" : "");
570 filebuf_addf(filebuf, "<option value=\"rewrite\" %s>rewrite\n", (section != NULL && !strcasecmp(section, "rewrite")) ? "selected" : "");
571 filebuf_addf(filebuf, "<option value=\"keywords\" %s>keywords\n", (section != NULL && !strcasecmp(section, "keywords")) ? "selected" : "");
572 filebuf_addf(filebuf, "<option value=\"templates\" %s>templates\n", (section != NULL && !strcasecmp(section, "templates")) ? "selected" : "");
573 filebuf_addf(filebuf, "<option value=\"cookies\" %s>cookies\n", (section != NULL && !strcasecmp(section, "cookies")) ? "selected" : "");
574 filebuf_addf(filebuf, "<option value=\"external\" %s>external\n", (section != NULL && !strcasecmp(section, "external")) ? "selected" : "");
575 filebuf_addf(filebuf, "</select></td>\n");
576 filebuf_addf(filebuf, "<td align=\"center\"><input type=\"submit\" value=\"Submit\"></form></td></tr>\n");
577 filebuf_addf(filebuf, "</table></td></tr>\n");
578 filebuf_addf(filebuf, "<tr><td><br></td></tr><tr><td align=\"center\">\n");
581 if (dialog != NULL) {
582 for (i = 0; dialog_pages[i].file; i++) {
583 if (!strcasecmp(section, dialog_pages[i].file))
584 dialog_pages[i].handler(filebuf, args, connection);
586 } else if (section != NULL && strcmp(section, "")) {
587 if (action != NULL) {
588 for (i = 0; action_pages[i].file; i++) {
589 if (!strcasecmp(section, action_pages[i].file))
590 action_pages[i].handler(filebuf, args, connection);
593 for (i = 0; config_pages[i].file; i++) {
594 if (!strcasecmp(section, config_pages[i].file))
595 config_pages[i].handler(filebuf, args, connection);
598 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\"><tr><td align=\"center\">\n");
599 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
600 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
601 filebuf_addf(filebuf, "<tr><td align=\"center\">Feature</td><td align=\"center\">Enabled</td><td align=\"center\">Disabled</td></tr>\n");
603 pthread_rwlock_rdlock(&filter_list->lock);
604 filebuf_addf(filebuf, "<tr><td>URL filtering</td><td><input type=\"radio\" name=\"filter\" value=\"on\" %s></td><td><input type=\"radio\" name=\"filter\" value=\"off\" %s></td></tr>\n", (filter_list->enabled == TRUE) ? "checked" : "", (filter_list->enabled == FALSE) ? "checked" : "");
605 pthread_rwlock_unlock(&filter_list->lock);
607 pthread_rwlock_rdlock(&header_list->lock);
608 filebuf_addf(filebuf, "<tr><td>Header filtering</td><td><input type=\"radio\" name=\"header\" value=\"on\" %s></td><td><input type=\"radio\" name=\"header\" value=\"off\" %s></td></tr>\n", (header_list->enabled == TRUE) ? "checked" : "", (header_list->enabled == FALSE) ? "checked" : "");
609 pthread_rwlock_unlock(&header_list->lock);
611 pthread_rwlock_rdlock(&mime_list->lock);
612 filebuf_addf(filebuf, "<tr><td>MIME filtering</td><td><input type=\"radio\" name=\"mime\" value=\"on\" %s></td><td><input type=\"radio\" name=\"mime\" value=\"off\" %s></td></tr>\n", (mime_list->enabled == TRUE) ? "checked" : "", (mime_list->enabled == FALSE) ? "checked" : "");
613 pthread_rwlock_unlock(&mime_list->lock);
615 pthread_rwlock_rdlock(&cookie_list->lock);
616 filebuf_addf(filebuf, "<tr><td>Cookie filtering</td><td><input type=\"radio\" name=\"cookie\" value=\"on\" %s></td><td><input type=\"radio\" name=\"cookie\" value=\"off\" %s></td></tr>\n", (cookie_list->enabled == TRUE) ? "checked" : "", (cookie_list->enabled == FALSE) ? "checked" : "");
617 pthread_rwlock_unlock(&cookie_list->lock);
619 pthread_rwlock_rdlock(&redirect_list->lock);
620 filebuf_addf(filebuf, "<tr><td>URL redirecting</td><td><input type=\"radio\" name=\"redirect\" value=\"on\" %s></td><td><input type=\"radio\" name=\"redirect\" value=\"off\" %s></td></tr>\n", (redirect_list->enabled == TRUE) ? "checked" : "", (redirect_list->enabled == FALSE) ? "checked" : "");
621 pthread_rwlock_unlock(&redirect_list->lock);
623 pthread_rwlock_rdlock(&forward_list->lock);
624 filebuf_addf(filebuf, "<tr><td>Forwarding</td><td><input type=\"radio\" name=\"forward\" value=\"on\" %s></td><td><input type=\"radio\" name=\"forward\" value=\"off\" %s></td></tr>\n", (forward_list->enabled == TRUE) ? "checked" : "", (forward_list->enabled == FALSE) ? "checked" : "");
625 pthread_rwlock_unlock(&forward_list->lock);
627 pthread_rwlock_rdlock(&rewrite_list->lock);
628 filebuf_addf(filebuf, "<tr><td>Document rewriting</td><td><input type=\"radio\" name=\"rewrite\" value=\"on\" %s></td><td><input type=\"radio\" name=\"rewrite\" value=\"off\" %s></td></tr>\n", (rewrite_list->enabled == TRUE) ? "checked" : "", (rewrite_list->enabled == FALSE) ? "checked" : "");
629 pthread_rwlock_unlock(&rewrite_list->lock);
631 pthread_rwlock_rdlock(&keyword_list->lock);
632 filebuf_addf(filebuf, "<tr><td>Keyword filtering</td><td><input type=\"radio\" name=\"keywords\" value=\"on\" %s></td><td><input type=\"radio\" name=\"keywords\" value=\"off\" %s></td></tr>\n", (keyword_list->enabled == TRUE) ? "checked" : "", (keyword_list->enabled == FALSE) ? "checked" : "");
633 pthread_rwlock_unlock(&keyword_list->lock);
635 pthread_rwlock_rdlock(&external->lock);
636 filebuf_addf(filebuf, "<tr><td>External parsers</td><td><input type=\"radio\" name=\"external\" value=\"on\" %s></td><td><input type=\"radio\" name=\"external\" value=\"off\" %s></td></tr>\n", (external->enabled == TRUE) ? "checked" : "", (external->enabled == FALSE) ? "checked" : "");
637 pthread_rwlock_unlock(&external->lock);
639 filebuf_addf(filebuf, "<tr><td colspan=\"3\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
640 filebuf_addf(filebuf, "</form></table></td></tr></table>\n");
644 filebuf_addf(filebuf, "</td></tr></table>\n");
647 void interface_page_config_filter(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
651 struct FILTER_LIST_LIST *fl = NULL;
653 if (filter_list == NULL)
656 pthread_rwlock_rdlock(&filter_list->lock);
658 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
659 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"60%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
660 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
661 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"section\" value=\"filter\">\n");
662 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"global\">\n");
663 filebuf_addf(filebuf, "<tr><td>Policy</td><td><select name=\"policy\"><option value=\"allow\" %s>allow<option value=\"deny\" %s>deny</select></td></tr>", (filter_list->policy == POLICY_ALLOW) ? "selected" : "", (filter_list->policy == POLICY_DENY) ? "selected" : "");
664 filebuf_addf(filebuf, "<tr><td>Default template</td><td><input type=\"text\" name=\"dtemplate\" value=\"%s\" size=\"20\"></td></tr>\n", (filter_list->dtemplate != NULL) ? filter_list->dtemplate : "");
665 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
666 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><a href=\"config?section=filter&dialog=show\">Add</a></td></tr>\n");
667 filebuf_addf(filebuf, "</form></table></td></tr> <tr><td><br></td></tr>\n");
669 for (i = 0; i < 2; i++) {
670 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" width=\"30%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
674 fl = filter_list->allow;
676 filebuf_addf(filebuf, "<tr><th>ALLOW</th></tr>\n");
679 fl = filter_list->deny;
681 filebuf_addf(filebuf, "<tr><th>DENY</th></tr>\n");
685 filebuf_addf(filebuf, "</table></td></tr>\n");
687 filebuf_addf(filebuf, "<tr><td><br></td></tr>\n");
689 for (; fl; fl = fl->next) {
690 filebuf_addf(filebuf, "<tr><td align=\"center\">\n");
691 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
693 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Enabled</td><td>%s</td></tr>\n", (fl->enabled == TRUE) ? "yes" : "no");
694 if (fl->comment != NULL) {
695 ptr = string_to_html(fl->comment, TRUE);
696 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Comment</td><td>%s</td></tr>\n", ptr);
699 if (fl->host != NULL) {
700 ptr = string_to_html(fl->host, TRUE);
701 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Host</td><td>%s</td></tr>\n", ptr);
704 if (fl->file != NULL) {
705 ptr = string_to_html(fl->file, TRUE);
706 filebuf_addf(filebuf, "<tr><td width=\"10%%\">File</td><td>%s</td></tr>\n", ptr);
709 if (fl->template != NULL)
710 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Template</td><td>%s</td></tr>\n", fl->template);
712 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
713 filebuf_addf(filebuf, "<tr><td align=\"center\"><a href=\"config?section=filter&dialog=show&list=%s&id=%d\">Edit</a> <a href=\"config?section=filter&action=delete&list=%s&id=%d\">Delete</a></td>\n", (i == 0) ? "allow" : "deny", fl->id, (i == 0) ? "allow" : "deny", fl->id);
714 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=filter&action=shift&list=%s&id=%d&direction=up\">Up</a> <a href=\"config?section=filter&action=shift&list=%s&id=%d&direction=down\">Down</a></td>\n", (i == 0) ? "allow" : "deny", fl->id, (i == 0) ? "allow" : "deny", fl->id);
715 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=filter&action=shift&list=%s&id=%d&direction=top\">Top</a> <a href=\"config?section=filter&action=shift&list=%s&id=%d&direction=bottom\">Bottom</a></td></tr>\n", (i == 0) ? "allow" : "deny", fl->id, (i == 0) ? "allow" : "deny", fl->id);
716 filebuf_addf(filebuf, "</table></td></tr>\n");
718 filebuf_addf(filebuf, "</table></td></tr> <tr><td><br></td></tr>\n");
722 filebuf_addf(filebuf, "</table>\n");
724 pthread_rwlock_unlock(&filter_list->lock);
727 void interface_page_config_filter_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
730 char *list = NULL, *ptr = NULL;
731 struct FILTER_LIST_LIST *fl = NULL;
732 struct cgi_args_t *a = args;
734 if (filter_list == NULL)
737 pthread_rwlock_rdlock(&filter_list->lock);
739 for (; a; a = a->next) {
740 if (!strcasecmp(a->name, "id"))
742 if (!strcasecmp(a->name, "list"))
746 if (id != -1 && list != NULL) {
747 if (!strcasecmp(list, "allow"))
748 for (fl = filter_list->allow; fl && fl->id != id; fl = fl->next);
749 else if (!strcasecmp(list, "deny"))
750 for (fl = filter_list->deny; fl && fl->id != id; fl = fl->next);
753 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
754 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
756 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"section\" value=\"filter\">\n");
758 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"list\" value=\"%s\">\n", list);
761 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"edit\">\n");
762 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"id\" value=\"%d\">\n", id);
764 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"add\">\n");
766 filebuf_addf(filebuf, "<tr><td>Enabled</td><td align=\"center\">");
767 filebuf_addf(filebuf, "Yes: <input type=\"radio\" name=\"enabled\" value=\"yes\" %s> ", (fl == NULL || fl->enabled == TRUE) ? "checked" : "");
768 filebuf_addf(filebuf, "No: <input type=\"radio\" name=\"enabled\" value=\"no\" %s> ", (fl != NULL && fl->enabled == FALSE) ? "checked" : "");
769 filebuf_addf(filebuf, "</td></tr>\n");
771 filebuf_addf(filebuf, "<tr><td>Action</td><td><select name=\"%s\">\n", (list != NULL) ? "move" : "list");
772 filebuf_addf(filebuf, "<option value=\"allow\" %s>allow\n", (list != NULL && !strcasecmp(list, "allow")) ? "selected" : "");
773 filebuf_addf(filebuf, "<option value=\"deny\" %s>deny\n", (list != NULL && !strcasecmp(list, "deny")) ? "selected" : "");
774 filebuf_addf(filebuf, "</select></tr>\n");
776 if (fl != NULL && fl->comment != NULL)
777 ptr = string_to_html(fl->comment, TRUE);
778 filebuf_addf(filebuf, "<tr><td>Comment</td><td><input type=\"text\" name=\"comment\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
781 if (fl != NULL && fl->host != NULL)
782 ptr = string_to_html(fl->host, TRUE);
783 filebuf_addf(filebuf, "<tr><td>Host</td><td><input type=\"text\" name=\"host\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
786 if (fl != NULL && fl->file != NULL)
787 ptr = string_to_html(fl->file, TRUE);
788 filebuf_addf(filebuf, "<tr><td>File</td><td><input type=\"text\" name=\"file\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
791 if (fl != NULL && fl->template != NULL)
792 ptr = string_to_html(fl->template, TRUE);
793 filebuf_addf(filebuf, "<tr><td>Template</td><td><input type=\"text\" name=\"template\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
796 filebuf_addf(filebuf, "<tr><td colspan=\"2\"><br></td></tr>\n");
797 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
799 filebuf_addf(filebuf, "</table></td></tr>\n");
801 pthread_rwlock_unlock(&filter_list->lock);
805 void interface_page_config_filter_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
808 char *list = NULL, *action = NULL;
809 struct FILTER_LIST_LIST *fl = NULL;
810 struct cgi_args_t *a;
812 if (filter_list == NULL)
815 pthread_rwlock_wrlock(&filter_list->lock);
817 for (a = args; a; a = a->next) {
818 if (!strcasecmp(a->name, "action"))
820 if (!strcasecmp(a->name, "id"))
822 if (!strcasecmp(a->name, "list"))
826 if (action != NULL && !strcasecmp(action, "global")) {
827 for (a = args; a; a = a->next) {
828 if (!strcasecmp(a->name, "policy")) {
829 if (!strcasecmp(a->value, "allow"))
830 filter_list->policy = POLICY_ALLOW;
831 else if (!strcasecmp(a->value, "deny"))
832 filter_list->policy = POLICY_DENY;
833 } else if (!strcasecmp(a->name, "dtemplate")) {
834 FREE_AND_NULL(filter_list->dtemplate);
835 if (strcmp(a->name, ""))
836 filter_list->dtemplate = xstrdup(a->value);
841 if (action == NULL || list == NULL)
844 if (!strcasecmp(action, "delete")) {
845 if (!strcasecmp(list, "allow"))
846 fl = filter_list->allow;
847 else if (!strcasecmp(list, "deny"))
848 fl = filter_list->deny;
850 for (; fl; fl = fl->next) {
852 if (!strcasecmp(list, "allow"))
853 filter_list->allow = filter_ll_delete(fl);
854 else if (!strcasecmp(list, "deny"))
855 filter_list->deny = filter_ll_delete(fl);
860 } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) {
861 if (!strcasecmp(action, "add")) {
862 if (!strcasecmp(list, "allow")) {
863 fl = filter_ll_new(filter_list->allow);
864 if (filter_list->allow == NULL)
865 filter_list->allow = fl;
866 } else if (!strcasecmp(list, "deny")) {
867 fl = filter_ll_new(filter_list->deny);
868 if (filter_list->deny == NULL)
869 filter_list->deny = fl;
873 fl->id = filter_list->id++;
875 if (!strcasecmp(list, "allow")) {
876 for (fl = filter_list->allow; fl; fl = fl->next)
879 } else if (!strcasecmp(list, "deny")) {
880 for (fl = filter_list->deny; fl; fl = fl->next)
889 if (strcasecmp(action, "shift")) {
890 for (a = args; a; a = a->next) {
891 if (!strcasecmp(a->name, "enabled")) {
892 if (!strcasecmp(a->value, "no"))
896 } else if (!strcasecmp(a->name, "comment"))
897 filter_ll_insert(fl, a->value, NULL, NULL, NULL);
898 else if (!strcasecmp(a->name, "host"))
899 filter_ll_insert(fl, NULL, a->value, NULL, NULL);
900 else if (!strcasecmp(a->name, "file"))
901 filter_ll_insert(fl, NULL, NULL, a->value, NULL);
902 else if (!strcasecmp(a->name, "template"))
903 filter_ll_insert(fl, NULL, NULL, NULL, a->value);
904 else if (!strcasecmp(a->name, "move")) {
905 if (!strcasecmp(a->value, "allow") && strcasecmp(list, a->value)) {
906 MOVENODE(struct FILTER_LIST_LIST *, fl, filter_list->deny, filter_list->allow);
907 } else if (!strcasecmp(a->value, "deny") && strcasecmp(list, a->value)) {
908 MOVENODE(struct FILTER_LIST_LIST *, fl, filter_list->allow, filter_list->deny);
913 for (a = args; a; a = a->next) {
914 if (!strcasecmp(a->name, "direction")) {
915 if (!strcasecmp(a->value, "up")) {
916 SHIFTNODE(struct FILTER_LIST_LIST *, (!strcasecmp(list, "allow")) ? filter_list->allow : filter_list->deny, fl, UP);
917 } else if (!strcasecmp(a->value, "down")) {
918 SHIFTNODE(struct FILTER_LIST_LIST *, (!strcasecmp(list, "allow")) ? filter_list->allow : filter_list->deny, fl, DOWN);
919 } else if (!strcasecmp(a->value, "top")) {
920 SETNODE(struct FILTER_LIST_LIST *, (!strcasecmp(list, "allow")) ? filter_list->allow : filter_list->deny, fl, TOP);
921 } else if (!strcasecmp(a->value, "bottom")) {
922 SETNODE(struct FILTER_LIST_LIST *, (!strcasecmp(list, "allow")) ? filter_list->allow : filter_list->deny, fl, BOTTOM);
930 pthread_rwlock_unlock(&filter_list->lock);
933 void interface_page_config_header(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connectin)
937 struct HEADER_LIST_LIST *hl = NULL;
939 if (header_list == NULL)
942 pthread_rwlock_rdlock(&header_list->lock);
944 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
945 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"60%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
946 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
947 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"section\" value=\"header\">\n");
948 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"global\">\n");
949 filebuf_addf(filebuf, "<tr><td>Policy</td><td><select name=\"policy\"><option value=\"allow\" %s>allow<option value=\"deny\" %s>deny</select></td></tr>", (header_list->policy == POLICY_ALLOW) ? "selected" : "", (header_list->policy == POLICY_DENY) ? "selected" : "");
950 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
951 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><a href=\"config?section=header&dialog=show\">Add</a></td></tr>\n");
952 filebuf_addf(filebuf, "</form></table></td></tr> <tr><td><br></td></tr>\n");
954 for (i = 0; i < 3; i++) {
955 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" width=\"30%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
959 hl = header_list->allow;
961 filebuf_addf(filebuf, "<tr><th>ALLOW</th></tr>\n");
964 hl = header_list->deny;
966 filebuf_addf(filebuf, "<tr><th>DENY</th></tr>\n");
969 hl = header_list->insert;
971 filebuf_addf(filebuf, "<tr><th>INSERT</th></tr>\n");
974 filebuf_addf(filebuf, "</table></td></tr><tr>\n");
976 filebuf_addf(filebuf, "<tr><td><br></td></tr>\n");
978 for (; hl; hl = hl->next) {
979 filebuf_addf(filebuf, "<tr><td align=\"center\">\n");
980 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
982 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Enabled</td><td>%s</td></tr>\n", (hl->enabled == TRUE) ? "yes" : "no");
983 if (hl->comment != NULL) {
984 ptr = string_to_html(hl->comment, TRUE);
985 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Comment</td><td>%s</td></tr>\n", ptr);
988 if (hl->host != NULL) {
989 ptr = string_to_html(hl->host, TRUE);
990 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Host</td><td>%s</td></tr>\n", ptr);
993 if (hl->type != NULL) {
994 ptr = string_to_html(hl->type, TRUE);
995 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Type</td><td>%s</td></tr>\n", ptr);
998 if (hl->value != NULL) {
999 ptr = string_to_html(hl->value, TRUE);
1000 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Value</td><td>%s</td></tr>\n", ptr);
1004 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
1005 filebuf_addf(filebuf, "<tr><td align=\"center\"><a href=\"config?section=header&dialog=show&list=%s&id=%d\">Edit</a> <a href=\"config?section=header&action=delete&list=%s&id=%d\">Delete</a></td>\n", (i == 0) ? "allow" : (i == 1) ? "deny" : "insert", hl->id, (i == 0) ? "allow" : (i == 1) ? "deny" : "insert", hl->id);
1006 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=header&action=shift&list=%s&id=%d&direction=up\">Up</a> <a href=\"config?section=header&action=shift&list=%s&id=%d&direction=down\">Down</a></td>\n", (i == 0) ? "allow" : (i == 1) ? "deny" : "insert", hl->id, (i == 0) ? "allow" : (i == 1) ? "deny" : "insert", hl->id);
1007 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=header&action=shift&list=%s&id=%d&direction=top\">Top</a> <a href=\"config?section=header&action=shift&list=%s&id=%d&direction=bottom\">Bottom</a></td></tr>\n", (i == 0) ? "allow" : (i == 1) ? "deny" : "insert", hl->id, (i == 0) ? "allow" : (i == 1) ? "deny" : "insert", hl->id);
1008 filebuf_addf(filebuf, "</table></td></tr>\n");
1010 filebuf_addf(filebuf, "</table></td></tr> <tr><td><br></td></tr>\n");
1014 filebuf_addf(filebuf, "</table>\n");
1016 pthread_rwlock_unlock(&header_list->lock);
1019 void interface_page_config_header_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
1022 char *list = NULL, *ptr = NULL;
1023 struct HEADER_LIST_LIST *hl = NULL;
1024 struct cgi_args_t *a = args;
1026 if (header_list == NULL)
1029 pthread_rwlock_rdlock(&header_list->lock);
1031 for (; a; a = a->next) {
1032 if (!strcasecmp(a->name, "id"))
1033 id = atoi(a->value);
1034 if (!strcasecmp(a->name, "list"))
1038 if (id != -1 && list != NULL) {
1039 if (!strcasecmp(list, "allow"))
1040 for (hl = header_list->allow; hl && hl->id != id; hl = hl->next);
1041 else if (!strcasecmp(list, "deny"))
1042 for (hl = header_list->deny; hl && hl->id != id; hl = hl->next);
1043 else if (!strcasecmp(list, "insert"))
1044 for (hl = header_list->insert; hl && hl->id != id; hl = hl->next);
1047 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
1048 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
1050 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"section\" value=\"header\">\n");
1052 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"list\" value=\"%s\">\n", list);
1055 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"edit\">\n");
1056 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"id\" value=\"%d\">\n", id);
1058 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"add\">\n");
1060 filebuf_addf(filebuf, "<tr><td>Enabled</td><td align=\"center\">");
1061 filebuf_addf(filebuf, "Yes: <input type=\"radio\" name=\"enabled\" value=\"yes\" %s> ", (hl == NULL || hl->enabled == TRUE) ? "checked" : "");
1062 filebuf_addf(filebuf, "No: <input type=\"radio\" name=\"enabled\" value=\"no\" %s> ", (hl != NULL && hl->enabled == FALSE) ? "checked" : "");
1063 filebuf_addf(filebuf, "</td></tr>\n");
1065 filebuf_addf(filebuf, "<tr><td>Action</td><td><select name=\"%s\">\n", (list != NULL) ? "move" : "list");
1066 filebuf_addf(filebuf, "<option value=\"allow\" %s>allow\n", (list != NULL && !strcasecmp(list, "allow")) ? "selected" : "");
1067 filebuf_addf(filebuf, "<option value=\"deny\" %s>deny\n", (list != NULL && !strcasecmp(list, "deny")) ? "selected" : "");
1068 filebuf_addf(filebuf, "<option value=\"insert\" %s>insert\n", (list != NULL && !strcasecmp(list, "insert")) ? "selected" : "");
1069 filebuf_addf(filebuf, "</select></tr>\n");
1071 if (hl != NULL && hl->comment != NULL)
1072 ptr = string_to_html(hl->comment, TRUE);
1073 filebuf_addf(filebuf, "<tr><td>Comment</td><td><input type=\"text\" name=\"comment\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
1076 if (hl != NULL && hl->host != NULL)
1077 ptr = string_to_html(hl->host, TRUE);
1078 filebuf_addf(filebuf, "<tr><td>Host</td><td><input type=\"text\" name=\"host\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
1081 if (hl != NULL && hl->type != NULL)
1082 ptr = string_to_html(hl->type, TRUE);
1083 filebuf_addf(filebuf, "<tr><td>Type</td><td><input type=\"text\" name=\"type\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
1086 if (hl != NULL && hl->value != NULL)
1087 ptr = string_to_html(hl->value, TRUE);
1088 filebuf_addf(filebuf, "<tr><td>Value</td><td><input type=\"text\" name=\"value\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
1091 filebuf_addf(filebuf, "<tr><td colspan=\"2\"><br></td></tr>\n");
1092 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
1094 filebuf_addf(filebuf, "</table></td></tr>\n");
1096 pthread_rwlock_unlock(&header_list->lock);
1100 void interface_page_config_header_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
1103 char *list = NULL, *action = NULL;
1104 struct HEADER_LIST_LIST *hl = NULL;
1105 struct cgi_args_t *a;
1107 if (header_list == NULL)
1110 pthread_rwlock_wrlock(&header_list->lock);
1112 for (a = args; a; a = a->next) {
1113 if (!strcasecmp(a->name, "action"))
1115 if (!strcasecmp(a->name, "id"))
1116 id = atoi(a->value);
1117 if (!strcasecmp(a->name, "list"))
1121 if (action != NULL && !strcasecmp(action, "global")) {
1122 for (a = args; a; a = a->next) {
1123 if (!strcasecmp(a->name, "policy")) {
1124 if (!strcasecmp(a->value, "allow"))
1125 header_list->policy = POLICY_ALLOW;
1126 else if (!strcasecmp(a->value, "deny"))
1127 header_list->policy = POLICY_DENY;
1132 if (action == NULL || list == NULL)
1135 if (!strcasecmp(action, "delete")) {
1136 if (!strcasecmp(list, "allow"))
1137 hl = header_list->allow;
1138 else if (!strcasecmp(list, "deny"))
1139 hl = header_list->deny;
1140 else if (!strcasecmp(list, "insert"))
1141 hl = header_list->insert;
1143 for (; hl; hl = hl->next) {
1145 if (!strcasecmp(list, "allow"))
1146 header_list->allow = header_ll_delete(hl);
1147 else if (!strcasecmp(list, "deny"))
1148 header_list->deny = header_ll_delete(hl);
1149 else if (!strcasecmp(list, "insert"))
1150 header_list->insert = header_ll_delete(hl);
1155 } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) {
1156 if (!strcasecmp(action, "add")) {
1157 if (!strcasecmp(list, "allow")) {
1158 hl = header_ll_new(header_list->allow);
1159 if (header_list->allow == NULL)
1160 header_list->allow = hl;
1161 } else if (!strcasecmp(list, "deny")) {
1162 hl = header_ll_new(header_list->deny);
1163 if (header_list->deny == NULL)
1164 header_list->deny = hl;
1165 } else if (!strcasecmp(list, "insert")) {
1166 hl = header_ll_new(header_list->insert);
1167 if (header_list->insert == NULL)
1168 header_list->insert = hl;
1172 hl->id = header_list->id++;
1174 if (!strcasecmp(list, "allow")) {
1175 for (hl = header_list->allow; hl; hl = hl->next)
1178 } else if (!strcasecmp(list, "deny")) {
1179 for (hl = header_list->deny; hl; hl = hl->next)
1182 } else if (!strcasecmp(list, "insert")) {
1183 for (hl = header_list->insert; hl; hl = hl->next)
1192 if (strcasecmp(action, "shift")) {
1193 for (a = args; a; a = a->next) {
1194 if (!strcasecmp(a->name, "enabled")) {
1195 if (!strcasecmp(a->value, "no"))
1196 hl->enabled = FALSE;
1199 } else if (!strcasecmp(a->name, "comment"))
1200 header_ll_insert(hl, a->value, NULL, NULL, NULL);
1201 else if (!strcasecmp(a->name, "type"))
1202 header_ll_insert(hl, NULL, a->value, NULL, NULL);
1203 else if (!strcasecmp(a->name, "value"))
1204 header_ll_insert(hl, NULL, NULL, a->value, NULL);
1205 else if (!strcasecmp(a->name, "host"))
1206 header_ll_insert(hl, NULL, NULL, NULL, a->value);
1207 else if (!strcasecmp(a->name, "move")) {
1208 if (!strcasecmp(a->value, "allow") && strcasecmp(list, a->value)) {
1209 if (!strcasecmp(list, "deny")) {
1210 MOVENODE(struct HEADER_LIST_LIST *, hl, header_list->deny, header_list->allow);
1211 } else if (!strcasecmp(list, "insert")) {
1212 MOVENODE(struct HEADER_LIST_LIST *, hl, header_list->insert, header_list->allow);
1214 } else if (!strcasecmp(a->value, "deny") && strcasecmp(list, a->value)) {
1215 if (!strcasecmp(list, "allow")) {
1216 MOVENODE(struct HEADER_LIST_LIST *, hl, header_list->allow, header_list->deny);
1217 } else if (!strcasecmp(list, "insert")) {
1218 MOVENODE(struct HEADER_LIST_LIST *, hl, header_list->insert, header_list->deny);
1220 } else if (!strcasecmp(a->value, "insert") && strcasecmp(list, a->value)) {
1221 if (!strcasecmp(list, "allow")) {
1222 MOVENODE(struct HEADER_LIST_LIST *, hl, header_list->allow, header_list->insert);
1223 } else if (!strcasecmp(list, "deny")) {
1224 MOVENODE(struct HEADER_LIST_LIST *, hl, header_list->deny, header_list->insert);
1230 for (a = args; a; a = a->next) {
1231 if (!strcasecmp(a->name, "direction")) {
1232 if (!strcasecmp(a->value, "up")) {
1233 SHIFTNODE(struct HEADER_LIST_LIST *, (!strcasecmp(list, "allow")) ? header_list->allow : (!strcasecmp(list, "deny")) ? header_list->deny : header_list->insert, hl, UP);
1234 } else if (!strcasecmp(a->value, "down")) {
1235 SHIFTNODE(struct HEADER_LIST_LIST *, (!strcasecmp(list, "allow")) ? header_list->allow : (!strcasecmp(list, "deny")) ? header_list->deny : header_list->insert, hl, DOWN);
1236 } else if (!strcasecmp(a->value, "top")) {
1237 SETNODE(struct HEADER_LIST_LIST *, (!strcasecmp(list, "allow")) ? header_list->allow : (!strcasecmp(list, "deny")) ? header_list->deny : header_list->insert, hl, TOP);
1238 } else if (!strcasecmp(a->value, "bottom")) {
1239 SETNODE(struct HEADER_LIST_LIST *, (!strcasecmp(list, "allow")) ? header_list->allow : (!strcasecmp(list, "deny")) ? header_list->deny : header_list->insert, hl, BOTTOM);
1247 pthread_rwlock_unlock(&header_list->lock);
1250 void interface_page_config_access(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
1254 struct ACCESS_LIST_LIST *al = NULL;
1256 if (access_list == NULL)
1259 pthread_rwlock_rdlock(&access_list->lock);
1261 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
1262 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"60%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
1263 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
1264 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"section\" value=\"access\">\n");
1265 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"global\">\n");
1266 filebuf_addf(filebuf, "<tr><td>Policy</td><td><select name=\"policy\"><option value=\"allow\" %s>allow<option value=\"deny\" %s>deny</select></td></tr>", (access_list->policy == POLICY_ALLOW) ? "selected" : "", (access_list->policy == POLICY_DENY) ? "selected" : "");
1267 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
1268 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><a href=\"config?section=access&dialog=show\">Add</a></td></tr>\n");
1269 filebuf_addf(filebuf, "</form></table></td></tr> <tr><td><br></td></tr>\n");
1271 for (i = 0; i < 2; i++) {
1272 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" width=\"30%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
1276 al = access_list->allow;
1278 filebuf_addf(filebuf, "<tr><th>ALLOW</th></tr>\n");
1281 al = access_list->deny;
1283 filebuf_addf(filebuf, "<tr><th>DENY</th></tr>\n");
1287 filebuf_addf(filebuf, "</table></td></tr>\n");
1289 filebuf_addf(filebuf, "<tr><td><br></td></tr>\n");
1291 for (; al; al = al->next) {
1292 filebuf_addf(filebuf, "<tr><td align=\"center\">\n");
1293 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
1295 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Enabled</td><td>%s</td></tr>\n", (al->enabled == TRUE) ? "yes" : "no");
1296 if (al->comment != NULL) {
1297 ptr = string_to_html(al->comment, TRUE);
1298 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Comment</td><td>%s</td></tr>\n", ptr);
1301 if (al->ip != NULL) {
1302 ptr = string_to_html(al->ip, TRUE);
1303 filebuf_addf(filebuf, "<tr><td width=\"10%%\">IP address</td><td>%s</td></tr>\n", ptr);
1306 if (al->username != NULL) {
1307 ptr = string_to_html(al->username, TRUE);
1308 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Username</td><td>%s</td></tr>\n", ptr);
1311 if (al->password != NULL) {
1312 ptr = string_to_html(al->password, TRUE);
1313 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Password</td><td>%s</td></tr>\n", ptr);
1317 if (al->bypass != 0)
1318 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Bypass</td><td>%s,%s,%s,%s,%s,%s,%s,%s,%s</td></tr>\n", (al->bypass & FEATURE_FILTER) ? "filter" : "", (al->bypass & FEATURE_HEADER) ? "header" : "", (al->bypass & FEATURE_MIME) ? "mime" : "", (al->bypass & FEATURE_REDIRECT) ? "redirect" : "", (al->bypass & FEATURE_COOKIES) ? "cookies" : "", (al->bypass & FEATURE_REWRITE) ? "rewrite" : "", (al->bypass & FEATURE_EXTERNAL) ? "external" : "", (al->bypass & FEATURE_FORWARD) ? "forward" : "", (al->bypass & FEATURE_KEYWORDS) ? "keywords" : "");
1320 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Access</td><td>%s,%s,%s,%s,%s,%s</td.</tr>\n", (al->access & ACCESS_CONFIG) ? "Web interface" : "", (al->access & ACCESS_PROXY) ? "Proxy requests" : "", (al->access & ACCESS_CONNECT) ? "CONNECT requests" : "", (al->access & ACCESS_HTTP) ? "HTTP requests" : "", (al->access & ACCESS_TRANSPARENT) ? "Transparent proxying" : "", (al->access & ACCESS_BYPASS) ? "Allow bypassing" : "");
1323 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
1324 filebuf_addf(filebuf, "<tr><td align=\"center\"><a href=\"config?section=access&dialog=show&list=%s&id=%d\">Edit</a> <a href=\"config?section=access&action=delete&list=%s&id=%d\">Delete</a></td>\n", (i == 0) ? "allow" : "deny", al->id, (i == 0) ? "allow" : "deny", al->id);
1325 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=access&action=shift&list=%s&id=%d&direction=up\">Up</a> <a href=\"config?section=access&action=shift&list=%s&id=%d&direction=down\">Down</a></td>\n", (i == 0) ? "allow" : "deny", al->id, (i == 0) ? "allow" : "deny", al->id);
1326 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=access&action=shift&list=%s&id=%d&direction=top\">Top</a> <a href=\"config?section=access&action=shift&list=%s&id=%d&direction=bottom\">Bottom</a></td></tr>\n", (i == 0) ? "allow" : "deny", al->id, (i == 0) ? "allow" : "deny", al->id);
1327 filebuf_addf(filebuf, "</table></td></tr>\n");
1329 filebuf_addf(filebuf, "</table></td></tr> <tr><td><br></td></tr>\n");
1333 filebuf_addf(filebuf, "</table>\n");
1335 pthread_rwlock_unlock(&access_list->lock);
1338 void interface_page_config_access_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
1341 char *list = NULL, *ptr = NULL;
1342 struct ACCESS_LIST_LIST *al = NULL;
1343 struct cgi_args_t *a = args;
1345 if (access_list == NULL)
1348 pthread_rwlock_rdlock(&access_list->lock);
1350 for (; a; a = a->next) {
1351 if (!strcasecmp(a->name, "id"))
1352 id = atoi(a->value);
1353 if (!strcasecmp(a->name, "list"))
1357 if (id != -1 && list != NULL) {
1358 if (!strcasecmp(list, "allow"))
1359 for (al = access_list->allow; al && al->id != id; al = al->next);
1360 else if (!strcasecmp(list, "deny"))
1361 for (al = access_list->deny; al && al->id != id; al = al->next);
1364 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
1365 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
1367 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"section\" value=\"access\">\n");
1369 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"list\" value=\"%s\">\n", list);
1372 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"edit\">\n");
1373 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"id\" value=\"%d\">\n", id);
1375 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"add\">\n");
1377 filebuf_addf(filebuf, "<tr><td>Enabled</td><td align=\"center\">");
1378 filebuf_addf(filebuf, "Yes: <input type=\"radio\" name=\"enabled\" value=\"yes\" %s> ", (al == NULL || al->enabled == TRUE) ? "checked" : "");
1379 filebuf_addf(filebuf, "No: <input type=\"radio\" name=\"enabled\" value=\"no\" %s> ", (al != NULL && al->enabled == FALSE) ? "checked" : "");
1380 filebuf_addf(filebuf, "</td></tr>\n");
1382 filebuf_addf(filebuf, "<tr><td>Action</td><td><select name=\"%s\">\n", (list != NULL) ? "move" : "list");
1383 filebuf_addf(filebuf, "<option value=\"allow\" %s>allow\n", (list != NULL && !strcasecmp(list, "allow")) ? "selected" : "");
1384 filebuf_addf(filebuf, "<option value=\"deny\" %s>deny\n", (list != NULL && !strcasecmp(list, "deny")) ? "selected" : "");
1385 filebuf_addf(filebuf, "</select></tr>\n");
1387 if (al != NULL && al->comment != NULL)
1388 ptr = string_to_html(al->comment, TRUE);
1389 filebuf_addf(filebuf, "<tr><td>Comment</td><td><input type=\"text\" name=\"comment\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
1392 if (al != NULL && al->ip != NULL)
1393 ptr = string_to_html(al->ip, TRUE);
1394 filebuf_addf(filebuf, "<tr><td>IP Address</td><td><input type=\"text\" name=\"ip\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
1397 if (al != NULL && al->username != NULL)
1398 ptr = string_to_html(al->username, TRUE);
1399 filebuf_addf(filebuf, "<tr><td>Username</td><td><input type=\"text\" name=\"username\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
1402 if (al != NULL && al->password!= NULL)
1403 ptr = string_to_html(al->password, TRUE);
1404 filebuf_addf(filebuf, "<tr><td>Password</td><td><input type=\"text\" name=\"password\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
1407 filebuf_addf(filebuf, "<tr><td>Access</td><td align=\"center\">");
1408 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n");
1409 filebuf_addf(filebuf, "<tr><td>Web interface: </td><td><input type=\"checkbox\" name=\"access_config\" %s></td></tr>", (al != NULL && (al->access & ACCESS_CONFIG)) ? "checked" : "");
1410 filebuf_addf(filebuf, "<tr><td>Proxy requests: </td><td><input type=\"checkbox\" name=\"access_proxy\" %s></td></tr>", (al != NULL && (al->access & ACCESS_PROXY)) ? "checked" : "");
1411 filebuf_addf(filebuf, "<tr><td>CONNECT requests: </td><td><input type=\"checkbox\" name=\"access_connect\" %s></td></tr>", (al != NULL && (al->access & ACCESS_CONNECT)) ? "checked" : "");
1412 filebuf_addf(filebuf, "<tr><td>HTTP requests: </td><td><input type=\"checkbox\" name=\"access_http\" %s></td></tr>", (al != NULL && (al->access & ACCESS_HTTP)) ? "checked" : "");
1413 filebuf_addf(filebuf, "<tr><td>Transparent proxying: </td><td><input type=\"checkbox\" name=\"access_transparent\" %s></td></tr>", (al != NULL && (al->access & ACCESS_TRANSPARENT)) ? "checked" : "");
1414 filebuf_addf(filebuf, "<tr><td>Allow bypassing: </td><td><input type=\"checkbox\" name=\"access_bypass\" %s></td></tr>", (al != NULL && (al->access & ACCESS_BYPASS)) ? "checked" : "");
1415 filebuf_addf(filebuf, "</table></td></tr>\n");
1417 filebuf_addf(filebuf, "<tr><td>Bypass</td><td align=\"center\">");
1418 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n");
1419 filebuf_addf(filebuf, "<tr><td>URL filtering: </td><td><input type=\"checkbox\" name=\"bfilter\" %s></td></tr>", (al != NULL && (al->bypass & FEATURE_FILTER)) ? "checked" : "");
1420 filebuf_addf(filebuf, "<tr><td>Header filtering: </td><td><input type=\"checkbox\" name=\"bheader\" %s></td></tr>", (al != NULL && (al->bypass & FEATURE_HEADER)) ? "checked" : "");
1421 filebuf_addf(filebuf, "<tr><td>MIME filtering: </td><td><input type=\"checkbox\" name=\"bmime\" %s></td></tr>", (al != NULL && (al->bypass & FEATURE_MIME)) ? "checked" : "");
1422 filebuf_addf(filebuf, "<tr><td>URL redirecting: </td><td><input type=\"checkbox\" name=\"bredirect\" %s></td></tr>", (al != NULL && (al->bypass & FEATURE_REDIRECT)) ? "checked" : "");
1423 filebuf_addf(filebuf, "<tr><td>Cookie filtering: </td><td><input type=\"checkbox\" name=\"bcookies\" %s></td></tr>", (al != NULL && (al->bypass & FEATURE_COOKIES)) ? "checked" : "");
1424 filebuf_addf(filebuf, "<tr><td>Document rewriting: </td><td><input type=\"checkbox\" name=\"brewrite\" %s></td></tr>", (al != NULL && (al->bypass & FEATURE_REWRITE)) ? "checked" : "");
1425 filebuf_addf(filebuf, "<tr><td>External parsers: </td><td><input type=\"checkbox\" name=\"bexternal\" %s></td></tr>", (al != NULL && (al->bypass & FEATURE_EXTERNAL)) ? "checked" : "");
1426 filebuf_addf(filebuf, "<tr><td>Forwarding: </td><td><input type=\"checkbox\" name=\"bforward\" %s></td></tr>", (al != NULL && (al->bypass & FEATURE_FORWARD)) ? "checked" : "");
1427 filebuf_addf(filebuf, "<tr><td>Keyword filtering: </td><td><input type=\"checkbox\" name=\"bkeywords\" %s></td></tr>", (al != NULL && (al->bypass & FEATURE_KEYWORDS)) ? "checked" : "");
1428 filebuf_addf(filebuf, "</table></td></tr>\n");
1430 filebuf_addf(filebuf, "<tr><td colspan=\"2\"><br></td></tr>\n");
1431 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
1433 filebuf_addf(filebuf, "</table></td></tr>\n");
1435 pthread_rwlock_unlock(&access_list->lock);
1439 void interface_page_config_access_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
1442 char *list = NULL, *action = NULL;
1443 struct ACCESS_LIST_LIST *al = NULL;
1444 struct cgi_args_t *a;
1446 if (access_list == NULL)
1449 pthread_rwlock_wrlock(&access_list->lock);
1451 for (a = args; a; a = a->next) {
1452 if (!strcasecmp(a->name, "action"))
1454 if (!strcasecmp(a->name, "id"))
1455 id = atoi(a->value);
1456 if (!strcasecmp(a->name, "list"))
1460 if (action != NULL && !strcasecmp(action, "global")) {
1461 for (a = args; a; a = a->next) {
1462 if (!strcasecmp(a->name, "policy")) {
1463 if (!strcasecmp(a->value, "allow"))
1464 access_list->policy = POLICY_ALLOW;
1465 else if (!strcasecmp(a->value, "deny"))
1466 access_list->policy = POLICY_DENY;
1471 if (action == NULL || list == NULL)
1474 if (!strcasecmp(action, "delete")) {
1475 if (!strcasecmp(list, "allow"))
1476 al = access_list->allow;
1477 else if (!strcasecmp(list, "deny"))
1478 al = access_list->deny;
1480 for (; al; al = al->next) {
1482 if (!strcasecmp(list, "allow"))
1483 access_list->allow = access_ll_delete(al);
1484 else if (!strcasecmp(list, "deny"))
1485 access_list->deny = access_ll_delete(al);
1490 } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) {
1491 if (!strcasecmp(action, "add")) {
1492 if (!strcasecmp(list, "allow")) {
1493 al = access_ll_new(access_list->allow);
1494 if (access_list->allow == NULL)
1495 access_list->allow = al;
1496 } else if (!strcasecmp(list, "deny")) {
1497 al = access_ll_new(access_list->deny);
1498 if (access_list->deny == NULL)
1499 access_list->deny = al;
1503 al->id = access_list->id++;
1505 if (!strcasecmp(list, "allow")) {
1506 for (al = access_list->allow; al; al = al->next)
1509 } else if (!strcasecmp(list, "deny")) {
1510 for (al = access_list->deny; al; al = al->next)
1519 if (strcasecmp(action, "shift")) {
1520 al->access = al->bypass = 0;
1522 for (a = args; a; a = a->next) {
1523 if (!strcasecmp(a->name, "enabled")) {
1524 if (!strcasecmp(a->value, "no"))
1525 al->enabled = FALSE;
1528 } else if (!strcasecmp(a->name, "comment"))
1529 access_ll_insert(al, a->value, NULL, NULL, NULL, NULL, NULL);
1530 else if (!strcasecmp(a->name, "ip"))
1531 access_ll_insert(al, NULL, a->value, NULL, NULL, NULL, NULL);
1532 else if (!strcasecmp(a->name, "username"))
1533 access_ll_insert(al, NULL, NULL, NULL, NULL, a->value, NULL);
1534 else if (!strcasecmp(a->name, "password"))
1535 access_ll_insert(al, NULL, NULL, NULL, NULL, NULL, a->value);
1536 else if (!strcasecmp(a->name, "access_config"))
1537 al->access |= ACCESS_CONFIG;
1538 else if (!strcasecmp(a->name, "access_proxy"))
1539 al->access |= ACCESS_PROXY;
1540 else if (!strcasecmp(a->name, "access_connect"))
1541 al->access |= ACCESS_CONNECT;
1542 else if (!strcasecmp(a->name, "access_http"))
1543 al->access |= ACCESS_HTTP;
1544 else if (!strcasecmp(a->name, "access_transparent"))
1545 al->access |= ACCESS_TRANSPARENT;
1546 else if (!strcasecmp(a->name, "access_bypass"))
1547 al->access |= ACCESS_BYPASS;
1548 else if (!strcasecmp(a->name, "bfilter"))
1549 al->bypass |= FEATURE_FILTER;
1550 else if (!strcasecmp(a->name, "bheader"))
1551 al->bypass |= FEATURE_HEADER;
1552 else if (!strcasecmp(a->name, "bmime"))
1553 al->bypass |= FEATURE_MIME;
1554 else if (!strcasecmp(a->name, "bredirect"))
1555 al->bypass |= FEATURE_REDIRECT;
1556 else if (!strcasecmp(a->name, "bcookies"))
1557 al->bypass |= FEATURE_COOKIES;
1558 else if (!strcasecmp(a->name, "brewrite"))
1559 al->bypass |= FEATURE_REWRITE;
1560 else if (!strcasecmp(a->name, "bexternal"))
1561 al->bypass |= FEATURE_EXTERNAL;
1562 else if (!strcasecmp(a->name, "bforward"))
1563 al->bypass |= FEATURE_FORWARD;
1564 else if (!strcasecmp(a->name, "bkeywords"))
1565 al->bypass |= FEATURE_KEYWORDS;
1566 else if (!strcasecmp(a->name, "move")) {
1567 if (!strcasecmp(a->value, "allow") && strcasecmp(list, a->value)) {
1568 MOVENODE(struct ACCESS_LIST_LIST *, al, access_list->deny, access_list->allow);
1569 } else if (!strcasecmp(a->value, "deny") && strcasecmp(list, a->value)) {
1570 MOVENODE(struct ACCESS_LIST_LIST *, al, access_list->allow, access_list->deny);
1575 for (a = args; a; a = a->next) {
1576 if (!strcasecmp(a->name, "direction")) {
1577 if (!strcasecmp(a->value, "up")) {
1578 SHIFTNODE(struct ACCESS_LIST_LIST *, (!strcasecmp(list, "allow")) ? access_list->allow : access_list->deny, al, UP);
1579 } else if (!strcasecmp(a->value, "down")) {
1580 SHIFTNODE(struct ACCESS_LIST_LIST *, (!strcasecmp(list, "allow")) ? access_list->allow : access_list->deny, al, DOWN);
1581 } else if (!strcasecmp(a->value, "top")) {
1582 SETNODE(struct ACCESS_LIST_LIST *, (!strcasecmp(list, "allow")) ? access_list->allow : access_list->deny, al, TOP);
1583 } else if (!strcasecmp(a->value, "bottom")) {
1584 SETNODE(struct ACCESS_LIST_LIST *, (!strcasecmp(list, "allow")) ? access_list->allow : access_list->deny, al, BOTTOM);
1592 pthread_rwlock_unlock(&access_list->lock);
1595 void interface_page_config_rewrite(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
1598 struct REWRITE_LIST_LIST *rl = NULL;
1600 if (rewrite_list == NULL)
1603 pthread_rwlock_rdlock(&rewrite_list->lock);
1605 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
1606 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"60%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
1607 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><a href=\"config?section=rewrite&dialog=show\">Add</a></td></tr>\n");
1608 filebuf_addf(filebuf, "</table></td></tr> <tr><td><br></td></tr>\n");
1610 for (rl = rewrite_list->rewrite; rl; rl = rl->next) {
1611 filebuf_addf(filebuf, "<tr><td align=\"center\">\n");
1612 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
1614 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Enabled</td><td>%s</td></tr>\n", (rl->enabled == TRUE) ? "yes" : "no");
1615 if (rl->comment != NULL) {
1616 ptr = string_to_html(rl->comment, TRUE);
1617 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Comment</td><td>%s</td></tr>\n", ptr);
1620 if (rl->host != NULL) {
1621 ptr = string_to_html(rl->host, TRUE);
1622 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Host</td><td>%s</td></tr>\n", ptr);
1625 if (rl->file != NULL) {
1626 ptr = string_to_html(rl->file, TRUE);
1627 filebuf_addf(filebuf, "<tr><td width=\"10%%\">File</td><td>%s</td></tr>\n", ptr);
1630 if (rl->mime != NULL) {
1631 ptr = string_to_html(rl->mime, TRUE);
1632 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Mimetype</td><td>%s</td></tr>\n", ptr);
1635 if (rl->pattern != NULL) {
1636 ptr = string_to_html(rl->pattern, TRUE);
1637 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Pattern</td><td>%s</td></tr>\n", ptr);
1640 if (rl->replace != NULL) {
1641 ptr = string_to_html(rl->replace, TRUE);
1642 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Replacement</td><td>%s</td></tr>\n", ptr);
1647 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Applies to</td><td>%s,%s,%s,%s</td></tr>\n", (rl->which & REWRITE_SERVER) ? "server header" : "", (rl->which & REWRITE_CLIENT) ? "client header" : "", (rl->which & REWRITE_BODY) ? "body" : "", (rl->which & REWRITE_POST) ? "post" : "");
1649 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
1650 filebuf_addf(filebuf, "<tr><td align=\"center\"><a href=\"config?section=rewrite&dialog=show&id=%d\">Edit</a> <a href=\"config?section=rewrite&action=delete&id=%d\">Delete</a></td>\n", rl->id, rl->id);
1651 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=rewrite&action=shift&id=%d&direction=up\">Up</a> <a href=\"config?section=rewrite&action=shift&id=%d&direction=down\">Down</a></td>\n", rl->id, rl->id);
1652 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=rewrite&action=shift&id=%d&direction=top\">Top</a> <a href=\"config?section=rewrite&action=shift&id=%d&direction=bottom\">Bottom</a></td></tr>\n", rl->id, rl->id);
1653 filebuf_addf(filebuf, "</table></td></tr>\n");
1655 filebuf_addf(filebuf, "</table></td></tr> <tr><td><br></td></tr>\n");
1658 filebuf_addf(filebuf, "</table>\n");
1660 pthread_rwlock_unlock(&rewrite_list->lock);
1663 void interface_page_config_rewrite_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
1667 struct REWRITE_LIST_LIST *rl = NULL;
1668 struct cgi_args_t *a = args;
1670 if (rewrite_list == NULL)
1673 pthread_rwlock_rdlock(&rewrite_list->lock);
1675 for (; a; a = a->next) {
1676 if (!strcasecmp(a->name, "id"))
1677 id = atoi(a->value);
1681 for (rl = rewrite_list->rewrite; rl && rl->id != id; rl = rl->next);
1683 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
1684 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
1686 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"section\" value=\"rewrite\">\n");
1689 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"edit\">\n");
1690 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"id\" value=\"%d\">\n", id);
1692 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"add\">\n");
1694 filebuf_addf(filebuf, "<tr><td>Enabled</td><td align=\"center\">");
1695 filebuf_addf(filebuf, "Yes: <input type=\"radio\" name=\"enabled\" value=\"yes\" %s> ", (rl == NULL || rl->enabled == TRUE) ? "checked" : "");
1696 filebuf_addf(filebuf, "No: <input type=\"radio\" name=\"enabled\" value=\"no\" %s> ", (rl != NULL && rl->enabled == FALSE) ? "checked" : "");
1697 filebuf_addf(filebuf, "</td></tr>\n");
1699 if (rl != NULL && rl->comment != NULL)
1700 ptr = string_to_html(rl->comment, TRUE);
1701 filebuf_addf(filebuf, "<tr><td>Comment</td><td><input type=\"text\" name=\"comment\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
1704 if (rl != NULL && rl->host != NULL)
1705 ptr = string_to_html(rl->host, TRUE);
1706 filebuf_addf(filebuf, "<tr><td>Host</td><td><input type=\"text\" name=\"host\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
1709 if (rl != NULL && rl->file != NULL)
1710 ptr = string_to_html(rl->file, TRUE);
1711 filebuf_addf(filebuf, "<tr><td>File</td><td><input type=\"text\" name=\"file\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
1714 if (rl != NULL && rl->mime != NULL)
1715 ptr = string_to_html(rl->mime, TRUE);
1716 filebuf_addf(filebuf, "<tr><td>Mimetype</td><td><input type=\"text\" name=\"mime\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
1719 if (rl != NULL && rl->pattern != NULL)
1720 ptr = string_to_html(rl->pattern, TRUE);
1721 filebuf_addf(filebuf, "<tr><td>Pattern</td><td><input type=\"text\" name=\"pattern\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
1724 if (rl != NULL && rl->replace != NULL)
1725 ptr = string_to_html(rl->replace, FALSE);
1726 filebuf_addf(filebuf, "<tr><td>Replace</td><td><textarea name=\"replace\" cols=\"80\" rows=\"8\" wrap=\"virtual\">%s</textarea></td></tr>\n", (ptr != NULL) ? ptr : "");
1729 filebuf_addf(filebuf, "<tr><td>Applies to</td><td align=\"center\">");
1730 filebuf_addf(filebuf, "Server header: <input type=\"checkbox\" name=\"server\" %s> ", (rl != NULL && rl->which & REWRITE_SERVER) ? "checked" : "");
1731 filebuf_addf(filebuf, "Client header: <input type=\"checkbox\" name=\"client\" %s> ", (rl != NULL && rl->which & REWRITE_CLIENT) ? "checked" : "");
1732 filebuf_addf(filebuf, "Body : <input type=\"checkbox\" name=\"body\" %s> ", (rl == NULL || rl->which & REWRITE_BODY) ? "checked" : "");
1733 filebuf_addf(filebuf, "POST data : <input type=\"checkbox\" name=\"post\" %s> ", (rl != NULL && rl->which & REWRITE_POST) ? "checked" : "");
1734 filebuf_addf(filebuf, "</td></tr>\n");
1736 filebuf_addf(filebuf, "<tr><td colspan=\"2\"><br></td></tr>\n");
1737 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
1739 filebuf_addf(filebuf, "</table></td></tr>\n");
1741 pthread_rwlock_unlock(&rewrite_list->lock);
1745 void interface_page_config_rewrite_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
1748 char *action = NULL;
1749 struct REWRITE_LIST_LIST *rl = NULL;
1750 struct cgi_args_t *a;
1752 if (rewrite_list == NULL)
1755 pthread_rwlock_wrlock(&rewrite_list->lock);
1757 for (a = args; a; a = a->next) {
1758 if (!strcasecmp(a->name, "action"))
1760 if (!strcasecmp(a->name, "id"))
1761 id = atoi(a->value);
1767 if (!strcasecmp(action, "delete")) {
1768 for (rl = rewrite_list->rewrite; rl; rl = rl->next) {
1770 rewrite_list->rewrite = rewrite_list_delete(rl);
1775 } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) {
1776 if (!strcasecmp(action, "add")) {
1777 rl = rewrite_list_new(rewrite_list->rewrite);
1778 if (rewrite_list->rewrite == NULL)
1779 rewrite_list->rewrite = rl;
1780 rl->id = rewrite_list->id++;
1782 for (rl = rewrite_list->rewrite; rl; rl = rl->next)
1790 if (strcasecmp(action, "shift")) {
1793 for (a = args; a; a = a->next) {
1794 if (!strcasecmp(a->name, "enabled")) {
1795 if (!strcasecmp(a->value, "no"))
1796 rl->enabled = FALSE;
1799 } else if (!strcasecmp(a->name, "comment"))
1800 rewrite_list_insert(rl, a->value, NULL, NULL, NULL, NULL, NULL, NULL);
1801 else if (!strcasecmp(a->name, "pattern"))
1802 rewrite_list_insert(rl, NULL, a->value, NULL, NULL, NULL, NULL, NULL);
1803 else if (!strcasecmp(a->name, "replace"))
1804 rewrite_list_insert(rl, NULL, NULL, a->value, NULL, NULL, NULL, NULL);
1805 else if (!strcasecmp(a->name, "host"))
1806 rewrite_list_insert(rl, NULL, NULL, NULL, NULL, a->value, NULL, NULL);
1807 else if (!strcasecmp(a->name, "file"))
1808 rewrite_list_insert(rl, NULL, NULL, NULL, NULL, NULL, a->value, NULL);
1809 else if (!strcasecmp(a->name, "mime"))
1810 rewrite_list_insert(rl, NULL, NULL, NULL, NULL, NULL, NULL, a->value);
1811 else if (!strcasecmp(a->name, "server"))
1812 rl->which |= REWRITE_SERVER;
1813 else if (!strcasecmp(a->name, "client"))
1814 rl->which |= REWRITE_CLIENT;
1815 else if (!strcasecmp(a->name, "body"))
1816 rl->which |= REWRITE_BODY;
1817 else if (!strcasecmp(a->name, "post"))
1818 rl->which |= REWRITE_POST;
1821 for (a = args; a; a = a->next) {
1822 if (!strcasecmp(a->name, "direction")) {
1823 if (!strcasecmp(a->value, "up")) {
1824 SHIFTNODE(struct REWRITE_LIST_LIST *, rewrite_list->rewrite, rl, UP);
1825 } else if (!strcasecmp(a->value, "down")) {
1826 SHIFTNODE(struct REWRITE_LIST_LIST *, rewrite_list->rewrite, rl, DOWN);
1827 } else if (!strcasecmp(a->value, "top")) {
1828 SETNODE(struct REWRITE_LIST_LIST *, rewrite_list->rewrite, rl, TOP);
1829 } else if (!strcasecmp(a->value, "bottom")) {
1830 SETNODE(struct REWRITE_LIST_LIST *, rewrite_list->rewrite, rl, BOTTOM);
1838 pthread_rwlock_unlock(&rewrite_list->lock);
1841 void interface_page_config_mime(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
1845 struct MIME_LIST_LIST *ml = NULL;
1847 if (mime_list == NULL)
1850 pthread_rwlock_rdlock(&mime_list->lock);
1852 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
1853 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"60%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
1854 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
1855 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"section\" value=\"mime\">\n");
1856 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"global\">\n");
1857 filebuf_addf(filebuf, "<tr><td>Policy</td><td><select name=\"policy\"><option value=\"allow\" %s>allow<option value=\"deny\" %s>deny</select></td></tr>", (mime_list->policy == POLICY_ALLOW) ? "selected" : "", (mime_list->policy == POLICY_DENY) ? "selected" : "");
1858 filebuf_addf(filebuf, "<tr><td>Default template</td><td><input type=\"text\" name=\"dtemplate\" value=\"%s\" size=\"20\"></td></tr>\n", (mime_list->dtemplate != NULL) ? mime_list->dtemplate : "");
1859 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
1860 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><a href=\"config?section=mime&dialog=show\">Add</a></td></tr>\n");
1861 filebuf_addf(filebuf, "</form></table></td></tr> <tr><td><br></td></tr>\n");
1863 for (i = 0; i < 2; i++) {
1864 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" width=\"30%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
1868 ml = mime_list->allow;
1870 filebuf_addf(filebuf, "<tr><th>ALLOW</th></tr>\n");
1873 ml = mime_list->deny;
1875 filebuf_addf(filebuf, "<tr><th>DENY</th></tr>\n");
1879 filebuf_addf(filebuf, "</table></td></tr>\n");
1881 filebuf_addf(filebuf, "<tr><td><br></td></tr>\n");
1883 for (; ml; ml = ml->next) {
1884 filebuf_addf(filebuf, "<tr><td align=\"center\">\n");
1885 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
1887 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Enabled</td><td>%s</td></tr>\n", (ml->enabled == TRUE) ? "yes" : "no");
1888 if (ml->comment != NULL) {
1889 ptr = string_to_html(ml->comment, TRUE);
1890 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Comment</td><td>%s</td></tr>\n", ptr);
1893 if (ml->host != NULL) {
1894 ptr = string_to_html(ml->host, TRUE);
1895 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Host</td><td>%s</td></tr>\n", ptr);
1898 if (ml->file != NULL) {
1899 ptr = string_to_html(ml->file, TRUE);
1900 filebuf_addf(filebuf, "<tr><td width=\"10%%\">File</td><td>%s</td></tr>\n", ptr);
1903 if (ml->mime != NULL) {
1904 ptr = string_to_html(ml->mime, TRUE);
1905 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Mimetype</td><td>%s</td></tr>\n", ptr);
1908 if (ml->template != NULL)
1909 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Template</td><td>%s</td></tr>\n", ml->template);
1912 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
1913 filebuf_addf(filebuf, "<tr><td align=\"center\"><a href=\"config?section=mime&dialog=show&list=%s&id=%d\">Edit</a> <a href=\"config?section=mime&action=delete&list=%s&id=%d\">Delete</a></td>\n", (i == 0) ? "allow" : "deny", ml->id, (i == 0) ? "allow" : "deny", ml->id);
1914 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=mime&action=shift&list=%s&id=%d&direction=up\">Up</a> <a href=\"config?section=mime&action=shift&list=%s&id=%d&direction=down\">Down</a></td>\n", (i == 0) ? "allow" : "deny", ml->id, (i == 0) ? "allow" : "deny", ml->id);
1915 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=mime&action=shift&list=%s&id=%d&direction=top\">Top</a> <a href=\"config?section=mime&action=shift&list=%s&id=%d&direction=bottom\">Bottom</a></td></tr>\n", (i == 0) ? "allow" : "deny", ml->id, (i == 0) ? "allow" : "deny", ml->id);
1916 filebuf_addf(filebuf, "</table></td></tr>\n");
1918 filebuf_addf(filebuf, "</table></td></tr> <tr><td><br></td></tr>\n");
1922 filebuf_addf(filebuf, "</table>\n");
1924 pthread_rwlock_unlock(&mime_list->lock);
1927 void interface_page_config_mime_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
1930 char *list = NULL, *ptr = NULL;
1931 struct MIME_LIST_LIST *ml = NULL;
1932 struct cgi_args_t *a = args;
1934 if (mime_list == NULL)
1937 pthread_rwlock_rdlock(&mime_list->lock);
1939 for (; a; a = a->next) {
1940 if (!strcasecmp(a->name, "id"))
1941 id = atoi(a->value);
1942 if (!strcasecmp(a->name, "list"))
1946 if (id != -1 && list != NULL) {
1947 if (!strcasecmp(list, "allow"))
1948 for (ml = mime_list->allow; ml && ml->id != id; ml = ml->next);
1949 else if (!strcasecmp(list, "deny"))
1950 for (ml = mime_list->deny; ml && ml->id != id; ml = ml->next);
1953 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
1954 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
1956 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"section\" value=\"mime\">\n");
1958 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"list\" value=\"%s\">\n", list);
1961 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"edit\">\n");
1962 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"id\" value=\"%d\">\n", id);
1964 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"add\">\n");
1966 filebuf_addf(filebuf, "<tr><td>Enabled</td><td align=\"center\">");
1967 filebuf_addf(filebuf, "Yes: <input type=\"radio\" name=\"enabled\" value=\"yes\" %s> ", (ml == NULL || ml->enabled == TRUE) ? "checked" : "");
1968 filebuf_addf(filebuf, "No: <input type=\"radio\" name=\"enabled\" value=\"no\" %s> ", (ml != NULL && ml->enabled == FALSE) ? "checked" : "");
1969 filebuf_addf(filebuf, "</td></tr>\n");
1971 filebuf_addf(filebuf, "<tr><td>Action</td><td><select name=\"%s\">\n", (list != NULL) ? "move" : "list");
1972 filebuf_addf(filebuf, "<option value=\"allow\" %s>allow\n", (list != NULL && !strcasecmp(list, "allow")) ? "selected" : "");
1973 filebuf_addf(filebuf, "<option value=\"deny\" %s>deny\n", (list != NULL && !strcasecmp(list, "deny")) ? "selected" : "");
1974 filebuf_addf(filebuf, "</select></tr>\n");
1976 if (ml != NULL && ml->comment != NULL)
1977 ptr = string_to_html(ml->comment, TRUE);
1978 filebuf_addf(filebuf, "<tr><td>Comment</td><td><input type=\"text\" name=\"comment\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
1981 if (ml != NULL && ml->host != NULL)
1982 ptr = string_to_html(ml->host, TRUE);
1983 filebuf_addf(filebuf, "<tr><td>Host</td><td><input type=\"text\" name=\"host\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
1986 if (ml != NULL && ml->file != NULL)
1987 ptr = string_to_html(ml->file, TRUE);
1988 filebuf_addf(filebuf, "<tr><td>File</td><td><input type=\"text\" name=\"file\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
1991 if (ml != NULL && ml->mime != NULL)
1992 ptr = string_to_html(ml->mime, TRUE);
1993 filebuf_addf(filebuf, "<tr><td>Mimetype</td><td><input type=\"text\" name=\"mime\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
1996 if (ml != NULL && ml->template != NULL)
1997 ptr = string_to_html(ml->template, TRUE);
1998 filebuf_addf(filebuf, "<tr><td>Template</td><td><input type=\"text\" name=\"template\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
2001 filebuf_addf(filebuf, "<tr><td colspan=\"2\"><br></td></tr>\n");
2002 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
2004 filebuf_addf(filebuf, "</table></td></tr>\n");
2006 pthread_rwlock_unlock(&mime_list->lock);
2009 void interface_page_config_mime_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
2012 char *list = NULL, *action = NULL;
2013 struct MIME_LIST_LIST *ml = NULL;
2014 struct cgi_args_t *a;
2016 if (mime_list == NULL)
2019 pthread_rwlock_wrlock(&mime_list->lock);
2021 for (a = args; a; a = a->next) {
2022 if (!strcasecmp(a->name, "action"))
2024 if (!strcasecmp(a->name, "id"))
2025 id = atoi(a->value);
2026 if (!strcasecmp(a->name, "list"))
2030 if (action != NULL && !strcasecmp(action, "global")) {
2031 for (a = args; a; a = a->next) {
2032 if (!strcasecmp(a->name, "policy")) {
2033 if (!strcasecmp(a->value, "allow"))
2034 mime_list->policy = POLICY_ALLOW;
2035 else if (!strcasecmp(a->value, "deny"))
2036 mime_list->policy = POLICY_DENY;
2037 } else if (!strcasecmp(a->name, "dtemplate")) {
2038 FREE_AND_NULL(mime_list->dtemplate);
2039 if (strcmp(a->name, ""))
2040 mime_list->dtemplate = xstrdup(a->value);
2045 if (action == NULL || list == NULL)
2048 if (!strcasecmp(action, "delete")) {
2049 if (!strcasecmp(list, "allow"))
2050 ml = mime_list->allow;
2051 else if (!strcasecmp(list, "deny"))
2052 ml = mime_list->deny;
2054 for (; ml; ml = ml->next) {
2056 if (!strcasecmp(list, "allow"))
2057 mime_list->allow = mime_ll_delete(ml);
2058 else if (!strcasecmp(list, "deny"))
2059 mime_list->deny = mime_ll_delete(ml);
2064 } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) {
2065 if (!strcasecmp(action, "add")) {
2066 if (!strcasecmp(list, "allow")) {
2067 ml = mime_ll_new(mime_list->allow);
2068 if (mime_list->allow == NULL)
2069 mime_list->allow = ml;
2070 } else if (!strcasecmp(list, "deny")) {
2071 ml = mime_ll_new(mime_list->deny);
2072 if (mime_list->deny == NULL)
2073 mime_list->deny = ml;
2077 ml->id = mime_list->id++;
2079 if (!strcasecmp(list, "allow")) {
2080 for (ml = mime_list->allow; ml; ml = ml->next)
2083 } else if (!strcasecmp(list, "deny")) {
2084 for (ml = mime_list->deny; ml; ml = ml->next)
2093 if (strcasecmp(action, "shift")) {
2094 for (a = args; a; a = a->next) {
2095 if (!strcasecmp(a->name, "enabled")) {
2096 if (!strcasecmp(a->value, "no"))
2097 ml->enabled = FALSE;
2100 } else if (!strcasecmp(a->name, "comment"))
2101 mime_ll_insert(ml, a->value, NULL, NULL, NULL, NULL);
2102 else if (!strcasecmp(a->name, "template"))
2103 mime_ll_insert(ml, NULL, a->value, NULL, NULL, NULL);
2104 else if (!strcasecmp(a->name, "host"))
2105 mime_ll_insert(ml, NULL, NULL, a->value, NULL, NULL);
2106 else if (!strcasecmp(a->name, "mime"))
2107 mime_ll_insert(ml, NULL, NULL, NULL, a->value, NULL);
2108 else if (!strcasecmp(a->name, "file"))
2109 mime_ll_insert(ml, NULL, NULL, NULL, NULL, a->value);
2110 else if (!strcasecmp(a->name, "move")) {
2111 if (!strcasecmp(a->value, "allow") && strcasecmp(list, a->value)) {
2112 MOVENODE(struct MIME_LIST_LIST *, ml, mime_list->deny, mime_list->allow);
2113 } else if (!strcasecmp(a->value, "deny") && strcasecmp(list, a->value)) {
2114 MOVENODE(struct MIME_LIST_LIST *, ml, mime_list->allow, mime_list->deny);
2119 for (a = args; a; a = a->next) {
2120 if (!strcasecmp(a->name, "direction")) {
2121 if (!strcasecmp(a->value, "up")) {
2122 SHIFTNODE(struct MIME_LIST_LIST *, (!strcasecmp(list, "allow")) ? mime_list->allow : mime_list->deny, ml, UP);
2123 } else if (!strcasecmp(a->value, "down")) {
2124 SHIFTNODE(struct MIME_LIST_LIST *, (!strcasecmp(list, "allow")) ? mime_list->allow : mime_list->deny, ml, DOWN);
2125 } else if (!strcasecmp(a->value, "top")) {
2126 SETNODE(struct MIME_LIST_LIST *, (!strcasecmp(list, "allow")) ? mime_list->allow : mime_list->deny, ml, TOP);
2127 } else if (!strcasecmp(a->value, "bottom")) {
2128 SETNODE(struct MIME_LIST_LIST *, (!strcasecmp(list, "allow")) ? mime_list->allow : mime_list->deny, ml, BOTTOM);
2136 pthread_rwlock_unlock(&mime_list->lock);
2139 void interface_page_config_cookies(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
2143 struct COOKIE_LIST_LIST *cl = NULL;
2145 if (cookie_list == NULL)
2148 pthread_rwlock_rdlock(&cookie_list->lock);
2150 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
2151 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"60%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
2152 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
2153 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"section\" value=\"cookies\">\n");
2154 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"global\">\n");
2155 filebuf_addf(filebuf, "<tr><td>Policy</td><td><select name=\"policy\"><option value=\"allow\" %s>allow<option value=\"deny\" %s>deny</select></td></tr>", (cookie_list->policy == POLICY_ALLOW) ? "selected" : "", (cookie_list->policy == POLICY_DENY) ? "selected" : "");
2156 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
2157 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><a href=\"config?section=cookies&dialog=show\">Add</a></td></tr>\n");
2158 filebuf_addf(filebuf, "</form></table></td></tr> <tr><td><br></td></tr>\n");
2160 for (i = 0; i < 2; i++) {
2161 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" width=\"30%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
2165 cl = cookie_list->allow;
2167 filebuf_addf(filebuf, "<tr><th>ALLOW</th></tr>\n");
2170 cl = cookie_list->deny;
2172 filebuf_addf(filebuf, "<tr><th>DENY</th></tr>\n");
2176 filebuf_addf(filebuf, "</table></td></tr>\n");
2178 filebuf_addf(filebuf, "<tr><td><br></td></tr>\n");
2180 for (; cl; cl = cl->next) {
2181 filebuf_addf(filebuf, "<tr><td align=\"center\">\n");
2182 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
2184 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Enabled</td><td>%s</td></tr>\n", (cl->enabled == TRUE) ? "yes" : "no");
2185 if (cl->comment != NULL) {
2186 ptr = string_to_html(cl->comment, TRUE);
2187 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Comment</td><td>%s</td></tr>\n", ptr);
2190 if (cl->host != NULL) {
2191 ptr = string_to_html(cl->host, TRUE);
2192 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Host</td><td>%s</td></tr>\n", ptr);
2195 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Direction</td><td>%s</td></tr>\n", (cl->direction == COOKIE_BOTH) ? "ANY" : (cl->direction == COOKIE_IN) ? "IN" : "OUT");
2198 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
2199 filebuf_addf(filebuf, "<tr><td align=\"center\"><a href=\"config?section=cookies&dialog=show&list=%s&id=%d\">Edit</a> <a href=\"config?section=cookies&action=delete&list=%s&id=%d\">Delete</a></td>\n", (i == 0) ? "allow" : "deny", cl->id, (i == 0) ? "allow" : "deny", cl->id);
2200 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=cookies&action=shift&list=%s&id=%d&direction=up\">Up</a> <a href=\"config?section=cookies&action=shift&list=%s&id=%d&direction=down\">Down</a></td>\n", (i == 0) ? "allow" : "deny", cl->id, (i == 0) ? "allow" : "deny", cl->id);
2201 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=cookies&action=shift&list=%s&id=%d&direction=top\">Top</a> <a href=\"config?section=cookies&action=shift&list=%s&id=%d&direction=bottom\">Bottom</a></td></tr>\n", (i == 0) ? "allow" : "deny", cl->id, (i == 0) ? "allow" : "deny", cl->id);
2202 filebuf_addf(filebuf, "</table></td></tr>\n");
2204 filebuf_addf(filebuf, "</table></td></tr> <tr><td><br></td></tr>\n");
2208 pthread_rwlock_unlock(&cookie_list->lock);
2210 filebuf_addf(filebuf, "</table>\n");
2213 void interface_page_config_cookies_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
2216 char *list = NULL, *ptr = NULL;
2217 struct COOKIE_LIST_LIST *cl = NULL;
2218 struct cgi_args_t *a = args;
2220 if (cookie_list == NULL)
2223 pthread_rwlock_rdlock(&cookie_list->lock);
2225 for (; a; a = a->next) {
2226 if (!strcasecmp(a->name, "id"))
2227 id = atoi(a->value);
2228 if (!strcasecmp(a->name, "list"))
2232 if (id != -1 && list != NULL) {
2233 if (!strcasecmp(list, "allow"))
2234 for (cl = cookie_list->allow; cl && cl->id != id; cl = cl->next);
2235 else if (!strcasecmp(list, "deny"))
2236 for (cl = cookie_list->deny; cl && cl->id != id; cl = cl->next);
2239 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
2240 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
2242 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"section\" value=\"cookies\">\n");
2244 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"list\" value=\"%s\">\n", list);
2247 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"edit\">\n");
2248 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"id\" value=\"%d\">\n", id);
2250 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"add\">\n");
2252 filebuf_addf(filebuf, "<tr><td>Enabled</td><td align=\"center\">");
2253 filebuf_addf(filebuf, "Yes: <input type=\"radio\" name=\"enabled\" value=\"yes\" %s> ", (cl == NULL || cl->enabled == TRUE) ? "checked" : "");
2254 filebuf_addf(filebuf, "No: <input type=\"radio\" name=\"enabled\" value=\"no\" %s> ", (cl != NULL && cl->enabled == FALSE) ? "checked" : "");
2255 filebuf_addf(filebuf, "</td></tr>\n");
2257 filebuf_addf(filebuf, "<tr><td>Action</td><td><select name=\"%s\">\n", (list != NULL) ? "move" : "list");
2258 filebuf_addf(filebuf, "<option value=\"allow\" %s>allow\n", (list != NULL && !strcasecmp(list, "allow")) ? "selected" : "");
2259 filebuf_addf(filebuf, "<option value=\"deny\" %s>deny\n", (list != NULL && !strcasecmp(list, "deny")) ? "selected" : "");
2260 filebuf_addf(filebuf, "</select></tr>\n");
2262 if (cl != NULL && cl->comment != NULL)
2263 ptr = string_to_html(cl->comment, TRUE);
2264 filebuf_addf(filebuf, "<tr><td>Comment</td><td><input type=\"text\" name=\"comment\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
2267 if (cl != NULL && cl->host != NULL)
2268 ptr = string_to_html(cl->host, TRUE);
2269 filebuf_addf(filebuf, "<tr><td>Host</td><td><input type=\"text\" name=\"host\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
2272 filebuf_addf(filebuf, "<tr><td>Direction</td><td align=\"center\">");
2273 filebuf_addf(filebuf, "Both: <input type=\"radio\" name=\"direction\" value=\"both\" %s> ", (cl == NULL || cl->direction == COOKIE_BOTH) ? "checked" : "");
2274 filebuf_addf(filebuf, "In: <input type=\"radio\" name=\"direction\" value=\"in\" %s> ", (cl != NULL && cl->direction == COOKIE_IN) ? "checked" : "");
2275 filebuf_addf(filebuf, "Out: <input type=\"radio\" name=\"direction\" value=\"out\" %s> ", (cl != NULL && cl->direction == COOKIE_OUT) ? "checked" : "");
2276 filebuf_addf(filebuf, "</td></tr>\n");
2278 filebuf_addf(filebuf, "<tr><td colspan=\"2\"><br></td></tr>\n");
2279 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
2281 filebuf_addf(filebuf, "</table></td></tr>\n");
2283 pthread_rwlock_unlock(&cookie_list->lock);
2287 void interface_page_config_cookies_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
2290 char *list = NULL, *action = NULL;
2291 struct COOKIE_LIST_LIST *cl = NULL;
2292 struct cgi_args_t *a;
2294 if (cookie_list == NULL)
2297 pthread_rwlock_wrlock(&cookie_list->lock);
2299 for (a = args; a; a = a->next) {
2300 if (!strcasecmp(a->name, "action"))
2302 if (!strcasecmp(a->name, "id"))
2303 id = atoi(a->value);
2304 if (!strcasecmp(a->name, "list"))
2308 if (action != NULL && !strcasecmp(action, "global")) {
2309 for (a = args; a; a = a->next) {
2310 if (!strcasecmp(a->name, "policy")) {
2311 if (!strcasecmp(a->value, "allow"))
2312 cookie_list->policy = POLICY_ALLOW;
2313 else if (!strcasecmp(a->value, "deny"))
2314 cookie_list->policy = POLICY_DENY;
2319 if (action == NULL || list == NULL)
2322 if (!strcasecmp(action, "delete")) {
2323 if (!strcasecmp(list, "allow"))
2324 cl = cookie_list->allow;
2325 else if (!strcasecmp(list, "deny"))
2326 cl = cookie_list->deny;
2328 for (; cl; cl = cl->next) {
2330 if (!strcasecmp(list, "allow"))
2331 cookie_list->allow = cookie_ll_delete(cl);
2332 else if (!strcasecmp(list, "deny"))
2333 cookie_list->deny = cookie_ll_delete(cl);
2338 } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) {
2339 if (!strcasecmp(action, "add")) {
2340 if (!strcasecmp(list, "allow")) {
2341 cl = cookie_ll_new(cookie_list->allow);
2342 if (cookie_list->allow == NULL)
2343 cookie_list->allow = cl;
2344 } else if (!strcasecmp(list, "deny")) {
2345 cl = cookie_ll_new(cookie_list->deny);
2346 if (cookie_list->deny == NULL)
2347 cookie_list->deny = cl;
2351 cl->id = cookie_list->id++;
2353 if (!strcasecmp(list, "allow")) {
2354 for (cl = cookie_list->allow; cl; cl = cl->next)
2357 } else if (!strcasecmp(list, "deny")) {
2358 for (cl = cookie_list->deny; cl; cl = cl->next)
2367 if (strcasecmp(action, "shift")) {
2368 for (a = args; a; a = a->next) {
2369 if (!strcasecmp(a->name, "enabled")) {
2370 if (!strcasecmp(a->value, "no"))
2371 cl->enabled = FALSE;
2374 } else if (!strcasecmp(a->name, "comment"))
2375 cookie_ll_insert(cl, a->value, NULL, NULL);
2376 else if (!strcasecmp(a->name, "direction"))
2377 cookie_ll_insert(cl, NULL, a->value, NULL);
2378 else if (!strcasecmp(a->name, "host"))
2379 cookie_ll_insert(cl, NULL, NULL, a->value);
2380 else if (!strcasecmp(a->name, "move")) {
2381 if (!strcasecmp(a->value, "allow") && strcasecmp(list, a->value)) {
2382 MOVENODE(struct COOKIE_LIST_LIST *, cl, cookie_list->deny, cookie_list->allow);
2383 } else if (!strcasecmp(a->value, "deny") && strcasecmp(list, a->value)) {
2384 MOVENODE(struct COOKIE_LIST_LIST *, cl, cookie_list->allow, cookie_list->deny);
2389 for (a = args; a; a = a->next) {
2390 if (!strcasecmp(a->name, "direction")) {
2391 if (!strcasecmp(a->value, "up")) {
2392 SHIFTNODE(struct COOKIE_LIST_LIST *, (!strcasecmp(list, "allow")) ? cookie_list->allow : cookie_list->deny, cl, UP);
2393 } else if (!strcasecmp(a->value, "down")) {
2394 SHIFTNODE(struct COOKIE_LIST_LIST *, (!strcasecmp(list, "allow")) ? cookie_list->allow : cookie_list->deny, cl, DOWN);
2395 } else if (!strcasecmp(a->value, "top")) {
2396 SETNODE(struct COOKIE_LIST_LIST *, (!strcasecmp(list, "allow")) ? cookie_list->allow : cookie_list->deny, cl, TOP);
2397 } else if (!strcasecmp(a->value, "bottom")) {
2398 SETNODE(struct COOKIE_LIST_LIST *, (!strcasecmp(list, "allow")) ? cookie_list->allow : cookie_list->deny, cl, BOTTOM);
2406 pthread_rwlock_unlock(&cookie_list->lock);
2409 void interface_page_config_external(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
2412 struct EXTERNAL_LIST_LIST *el = NULL;
2414 if (external == NULL)
2417 pthread_rwlock_rdlock(&external->lock);
2419 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
2420 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"60%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
2421 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><a href=\"config?section=external&dialog=show\">Add</a></td></tr>\n");
2422 filebuf_addf(filebuf, "</table></td></tr> <tr><td><br></td></tr>\n");
2424 for (el = external->external_list; el; el = el->next) {
2425 filebuf_addf(filebuf, "<tr><td align=\"center\">\n");
2426 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
2428 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Enabled</td><td>%s</td></tr>\n", (el->enabled == TRUE) ? "yes" : "no");
2429 if (el->comment != NULL) {
2430 ptr = string_to_html(el->comment, TRUE);
2431 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Comment</td><td>%s</td></tr>\n", ptr);
2434 if (el->host != NULL) {
2435 ptr = string_to_html(el->host, TRUE);
2436 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Host</td><td>%s</td></tr>\n", ptr);
2439 if (el->file != NULL) {
2440 ptr = string_to_html(el->file, TRUE);
2441 filebuf_addf(filebuf, "<tr><td width=\"10%%\">File</td><td>%s</td></tr>\n", ptr);
2444 if (el->mime != NULL) {
2445 ptr = string_to_html(el->mime, TRUE);
2446 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Mimetype</td><td>%s</td></tr>\n", ptr);
2449 if (el->newmime != NULL) {
2450 ptr = string_to_html(el->newmime, TRUE);
2451 filebuf_addf(filebuf, "<tr><td width=\"10%%\">New mime</td><td>%s</td></tr>\n", ptr);
2454 if (el->exec != NULL) {
2455 ptr = string_to_html(el->exec, TRUE);
2456 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Executable</td><td>%s</td></tr>\n", ptr);
2460 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Type</td><td>%s</td></tr>\n", (el->type == EXTERNAL_PIPE) ? "pipe" : "file");
2463 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
2464 filebuf_addf(filebuf, "<tr><td align=\"center\"><a href=\"config?section=external&dialog=show&id=%d\">Edit</a> <a href=\"config?section=external&action=delete&id=%d\">Delete</a></td>\n", el->id, el->id);
2465 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=external&action=shift&id=%d&direction=up\">Up</a> <a href=\"config?section=external&action=shift&id=%d&direction=down\">Down</a></td>\n", el->id, el->id);
2466 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=external&action=shift&id=%d&direction=top\">Top</a> <a href=\"config?section=external&action=shift&id=%d&direction=bottom\">Bottom</a></td></tr>\n", el->id, el->id);
2467 filebuf_addf(filebuf, "</table></td></tr>\n");
2469 filebuf_addf(filebuf, "</table></td></tr> <tr><td><br></td></tr>\n");
2472 filebuf_addf(filebuf, "</table>\n");
2474 pthread_rwlock_unlock(&external->lock);
2477 void interface_page_config_external_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
2481 struct EXTERNAL_LIST_LIST *el = NULL;
2482 struct cgi_args_t *a = args;
2484 if (external == NULL)
2487 pthread_rwlock_rdlock(&external->lock);
2489 for (; a; a = a->next) {
2490 if (!strcasecmp(a->name, "id"))
2491 id = atoi(a->value);
2495 for (el = external->external_list; el && el->id != id; el = el->next);
2497 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
2498 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
2500 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"section\" value=\"external\">\n");
2503 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"edit\">\n");
2504 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"id\" value=\"%d\">\n", id);
2506 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"add\">\n");
2508 filebuf_addf(filebuf, "<tr><td>Enabled</td><td align=\"center\">");
2509 filebuf_addf(filebuf, "Yes: <input type=\"radio\" name=\"enabled\" value=\"yes\" %s> ", (el == NULL || el->enabled == TRUE) ? "checked" : "");
2510 filebuf_addf(filebuf, "No: <input type=\"radio\" name=\"enabled\" value=\"no\" %s> ", (el != NULL && el->enabled == FALSE) ? "checked" : "");
2511 filebuf_addf(filebuf, "</td></tr>\n");
2513 if (el != NULL && el->comment != NULL)
2514 ptr = string_to_html(el->comment, TRUE);
2515 filebuf_addf(filebuf, "<tr><td>Comment</td><td><input type=\"text\" name=\"comment\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
2518 if (el != NULL && el->exec != NULL)
2519 ptr = string_to_html(el->exec, TRUE);
2520 filebuf_addf(filebuf, "<tr><td>Executable</td><td><input type=\"text\" name=\"exec\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
2523 if (el != NULL && el->host != NULL)
2524 ptr = string_to_html(el->host, TRUE);
2525 filebuf_addf(filebuf, "<tr><td>Host</td><td><input type=\"text\" name=\"host\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
2528 if (el != NULL && el->file != NULL)
2529 ptr = string_to_html(el->file, TRUE);
2530 filebuf_addf(filebuf, "<tr><td>File</td><td><input type=\"text\" name=\"file\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
2533 if (el != NULL && el->mime != NULL)
2534 ptr = string_to_html(el->mime, TRUE);
2535 filebuf_addf(filebuf, "<tr><td>Mimetype</td><td><input type=\"text\" name=\"mime\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
2538 if (el != NULL && el->newmime != NULL)
2539 ptr = string_to_html(el->newmime, TRUE);
2540 filebuf_addf(filebuf, "<tr><td>Newmime</td><td><input type=\"text\" name=\"newmime\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
2543 filebuf_addf(filebuf, "<tr><td>Type</td><td align=\"center\">");
2544 filebuf_addf(filebuf, "Pipe: <input type=\"radio\" name=\"type\" value=\"pipe\" %s> ", (el == NULL || el->type == EXTERNAL_PIPE) ? "checked" : "");
2545 filebuf_addf(filebuf, "File: <input type=\"radio\" name=\"type\" value=\"file\" %s> ", (el != NULL && el->type == EXTERNAL_FILE) ? "checked" : "");
2546 filebuf_addf(filebuf, "</td></tr>\n");
2548 filebuf_addf(filebuf, "<tr><td colspan=\"2\"><br></td></tr>\n");
2549 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
2551 filebuf_addf(filebuf, "</table></td></tr>\n");
2553 pthread_rwlock_unlock(&external->lock);
2557 void interface_page_config_external_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
2560 char *action = NULL;
2561 struct EXTERNAL_LIST_LIST *el = NULL;
2562 struct cgi_args_t *a;
2564 if (external == NULL)
2567 pthread_rwlock_wrlock(&external->lock);
2569 for (a = args; a; a = a->next) {
2570 if (!strcasecmp(a->name, "action"))
2572 if (!strcasecmp(a->name, "id"))
2573 id = atoi(a->value);
2579 if (!strcasecmp(action, "delete")) {
2580 for (el = external->external_list; el; el = el->next) {
2582 external->external_list = external_list_delete(el);
2587 } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) {
2588 if (!strcasecmp(action, "add")) {
2589 el = external_list_new(external->external_list);
2590 if (external->external_list == NULL)
2591 external->external_list = el;
2592 el->id = external->id++;
2594 for (el = external->external_list; el; el = el->next)
2602 if (strcasecmp(action, "shift")) {
2603 for (a = args; a; a = a->next) {
2604 if (!strcasecmp(a->name, "enabled")) {
2605 if (!strcasecmp(a->value, "no"))
2606 el->enabled = FALSE;
2609 } else if (!strcasecmp(a->name, "comment"))
2610 external_list_insert(el, a->value, NULL, NULL, NULL, NULL, NULL, NULL);
2611 else if (!strcasecmp(a->name, "mime"))
2612 external_list_insert(el, NULL, a->value, NULL, NULL, NULL, NULL, NULL);
2613 else if (!strcasecmp(a->name, "host"))
2614 external_list_insert(el, NULL, NULL, a->value, NULL, NULL, NULL, NULL);
2615 else if (!strcasecmp(a->name, "file"))
2616 external_list_insert(el, NULL, NULL, NULL, a->value, NULL, NULL, NULL);
2617 else if (!strcasecmp(a->name, "exec"))
2618 external_list_insert(el, NULL, NULL, NULL, NULL, a->value, NULL, NULL);
2619 else if (!strcasecmp(a->name, "newmime"))
2620 external_list_insert(el, NULL, NULL, NULL, NULL, NULL, a->value, NULL);
2621 else if (!strcasecmp(a->name, "type"))
2622 external_list_insert(el, NULL, NULL, NULL, NULL, NULL, NULL, a->value);
2626 for (a = args; a; a = a->next) {
2627 if (!strcasecmp(a->name, "direction")) {
2628 if (!strcasecmp(a->value, "up")) {
2629 SHIFTNODE(struct EXTERNAL_LIST_LIST *, external->external_list, el, UP);
2630 } else if (!strcasecmp(a->value, "down")) {
2631 SHIFTNODE(struct EXTERNAL_LIST_LIST *, external->external_list, el, DOWN);
2632 } else if (!strcasecmp(a->value, "top")) {
2633 SETNODE(struct EXTERNAL_LIST_LIST *, external->external_list, el, TOP);
2634 } else if (!strcasecmp(a->value, "bottom")) {
2635 SETNODE(struct EXTERNAL_LIST_LIST *, external->external_list, el, BOTTOM);
2643 pthread_rwlock_unlock(&external->lock);
2646 void interface_page_config_templates(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
2649 struct TEMPLATE_LIST *tl = NULL;
2651 if (templates == NULL)
2654 pthread_rwlock_rdlock(&templates->lock);
2656 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
2657 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"60%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
2658 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
2659 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"section\" value=\"templates\">\n");
2660 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"global\">\n");
2661 filebuf_addf(filebuf, "<tr><td>Path</td><td><input type=\"text\" name=\"path\" value=\"%s\" size=\"20\"></td></tr>\n", (templates->path != NULL) ? templates->path : "");
2662 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
2663 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><a href=\"config?section=templates&dialog=show\">Add</a></td></tr>\n");
2664 filebuf_addf(filebuf, "</form></table></td></tr> <tr><td><br></td></tr>\n");
2666 for (tl = templates->template_list; tl; tl = tl->next) {
2667 filebuf_addf(filebuf, "<tr><td align=\"center\">\n");
2668 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
2670 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Enabled</td><td>%s</td></tr>\n", (tl->enabled == TRUE) ? "yes" : "no");
2671 if (tl->comment != NULL) {
2672 ptr = string_to_html(tl->comment, TRUE);
2673 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Comment</td><td>%s</td></tr>\n", ptr);
2676 if (tl->name != NULL) {
2677 ptr = string_to_html(tl->name, TRUE);
2678 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Name</td><td>%s</td></tr>\n", ptr);
2681 if (tl->file != NULL) {
2682 ptr = string_to_html(tl->file, TRUE);
2683 filebuf_addf(filebuf, "<tr><td width=\"10%%\">File</td><td>%s</td></tr>\n", ptr);
2686 if (tl->mime != NULL) {
2687 ptr = string_to_html(tl->mime, TRUE);
2688 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Mimetype</td><td>%s</td></tr>\n", ptr);
2693 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Response code</td><td>%d</td></tr>\n", tl->code);
2696 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Type</td><td>%s</td></tr>\n", (tl->type == TEMPLATE_FILE) ? "file" : "executable");
2698 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
2699 filebuf_addf(filebuf, "<tr><td align=\"center\"><a href=\"config?section=templates&dialog=show&id=%d\">Edit</a> <a href=\"config?section=templates&action=delete&id=%d\">Delete</a></td>\n", tl->id, tl->id);
2700 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=templates&action=shift&id=%d&direction=up\">Up</a> <a href=\"config?section=templates&action=shift&id=%d&direction=down\">Down</a></td>\n", tl->id, tl->id);
2701 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=templates&action=shift&id=%d&direction=top\">Top</a> <a href=\"config?section=templates&action=shift&id=%d&direction=bottom\">Bottom</a></td></tr>\n", tl->id, tl->id);
2702 filebuf_addf(filebuf, "</table></td></tr>\n");
2704 filebuf_addf(filebuf, "</table></td></tr> <tr><td><br></td></tr>\n");
2707 filebuf_addf(filebuf, "</table>\n");
2709 pthread_rwlock_unlock(&templates->lock);
2712 void interface_page_config_templates_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
2715 char *ptr = NULL, buf[16];
2716 struct TEMPLATE_LIST *tl = NULL;
2717 struct cgi_args_t *a = args;
2719 if (rewrite_list == NULL)
2722 pthread_rwlock_rdlock(&templates->lock);
2724 for (; a; a = a->next) {
2725 if (!strcasecmp(a->name, "id"))
2726 id = atoi(a->value);
2730 for (tl = templates->template_list; tl && tl->id != id; tl = tl->next);
2732 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
2733 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
2735 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"section\" value=\"templates\">\n");
2738 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"edit\">\n");
2739 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"id\" value=\"%d\">\n", id);
2741 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"add\">\n");
2743 filebuf_addf(filebuf, "<tr><td>Enabled</td><td align=\"center\">");
2744 filebuf_addf(filebuf, "Yes: <input type=\"radio\" name=\"enabled\" value=\"yes\" %s> ", (tl == NULL || tl->enabled == TRUE) ? "checked" : "");
2745 filebuf_addf(filebuf, "No: <input type=\"radio\" name=\"enabled\" value=\"no\" %s> ", (tl != NULL && tl->enabled == FALSE) ? "checked" : "");
2746 filebuf_addf(filebuf, "</td></tr>\n");
2748 if (tl != NULL && tl->comment != NULL)
2749 ptr = string_to_html(tl->comment, TRUE);
2750 filebuf_addf(filebuf, "<tr><td>Comment</td><td><input type=\"text\" name=\"comment\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
2753 if (tl != NULL && tl->name != NULL)
2754 ptr = string_to_html(tl->name, TRUE);
2755 filebuf_addf(filebuf, "<tr><td>Name</td><td><input type=\"text\" name=\"name\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
2758 if (tl != NULL && tl->file != NULL)
2759 ptr = string_to_html(tl->file, TRUE);
2760 filebuf_addf(filebuf, "<tr><td>File</td><td><input type=\"text\" name=\"file\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
2763 if (tl != NULL && tl->mime != NULL)
2764 ptr = string_to_html(tl->mime, TRUE);
2765 filebuf_addf(filebuf, "<tr><td>Mimetype</td><td><input type=\"text\" name=\"mime\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
2769 snprintf(buf, sizeof(buf), "%d", tl->code);
2770 filebuf_addf(filebuf, "<tr><Td>Response code</td><td><input type=\"text\" name=\"code\" value=\"%s\"></td></tr>\n", (tl != NULL && tl->code != -1) ? buf : "");
2772 filebuf_addf(filebuf, "<tr><td>Type</td><td align=\"center\">");
2773 filebuf_addf(filebuf, "File: <input type=\"radio\" name=\"type\" value=\"file\" %s> ", (tl == NULL || tl->type == TEMPLATE_FILE) ? "checked" : "");
2774 filebuf_addf(filebuf, "Executable: <input type=\"radio\" name=\"type\" value=\"executable\" %s> ", (tl != NULL && tl->type == TEMPLATE_EXECUTABLE) ? "checked" : "");
2775 filebuf_addf(filebuf, "</td></tr>\n");
2777 filebuf_addf(filebuf, "<tr><td colspan=\"2\"><br></td></tr>\n");
2778 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
2780 filebuf_addf(filebuf, "</table></td></tr>\n");
2782 pthread_rwlock_unlock(&templates->lock);
2785 void interface_page_config_templates_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
2788 char *action = NULL;
2789 struct TEMPLATE_LIST *tl = NULL;
2790 struct cgi_args_t *a;
2792 if (templates == NULL)
2795 pthread_rwlock_wrlock(&templates->lock);
2797 for (a = args; a; a = a->next) {
2798 if (!strcasecmp(a->name, "action"))
2800 if (!strcasecmp(a->name, "id"))
2801 id = atoi(a->value);
2807 if (!strcasecmp(action, "delete")) {
2808 for (tl = templates->template_list; tl; tl = tl->next) {
2810 templates->template_list = template_list_delete(tl);
2815 } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) {
2816 if (!strcasecmp(action, "add")) {
2817 tl = template_list_new(templates->template_list);
2818 if (templates->template_list == NULL)
2819 templates->template_list = tl;
2820 tl->id = templates->id++;
2822 for (tl = templates->template_list; tl; tl = tl->next)
2830 if (strcasecmp(action, "shift")) {
2831 for (a = args; a; a = a->next) {
2832 if (!strcasecmp(a->name, "enabled")) {
2833 if (!strcasecmp(a->value, "no"))
2834 tl->enabled = FALSE;
2837 } else if (!strcasecmp(a->name, "comment"))
2838 template_list_insert(tl, a->value, NULL, NULL, NULL, NULL, NULL);
2839 else if (!strcasecmp(a->name, "name"))
2840 template_list_insert(tl, NULL, a->value, NULL, NULL, NULL, NULL);
2841 else if (!strcasecmp(a->name, "file"))
2842 template_list_insert(tl, NULL, NULL, a->value, NULL, NULL, NULL);
2843 else if (!strcasecmp(a->name, "type"))
2844 template_list_insert(tl, NULL, NULL, NULL, a->value, NULL, NULL);
2845 else if (!strcasecmp(a->name, "mime"))
2846 template_list_insert(tl, NULL, NULL, NULL, NULL, a->value, NULL);
2847 else if (!strcasecmp(a->name, "code"))
2848 template_list_insert(tl, NULL, NULL, NULL, NULL, NULL, a->value);
2852 for (a = args; a; a = a->next) {
2853 if (!strcasecmp(a->name, "direction")) {
2854 if (!strcasecmp(a->value, "up")) {
2855 SHIFTNODE(struct TEMPLATE_LIST *, templates->template_list, tl, UP);
2856 } else if (!strcasecmp(a->value, "down")) {
2857 SHIFTNODE(struct TEMPLATE_LIST *, templates->template_list, tl, DOWN);
2858 } else if (!strcasecmp(a->value, "top")) {
2859 SETNODE(struct TEMPLATE_LIST *, templates->template_list, tl, TOP);
2860 } else if (!strcasecmp(a->value, "down")) {
2861 SETNODE(struct TEMPLATE_LIST *, templates->template_list, tl, BOTTOM);
2869 pthread_rwlock_unlock(&templates->lock);
2872 void interface_page_config_network(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
2875 struct LISTEN_LIST *ll = NULL;
2877 if (network == NULL)
2880 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
2882 ll = network->listen_list;
2884 for (; ll; ll = ll->next) {
2885 filebuf_addf(filebuf, "<tr><td align=\"center\">\n");
2886 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
2887 if (ll->ip != NULL) {
2888 ptr = string_to_html(ll->ip, TRUE);
2889 filebuf_addf(filebuf, "<tr><td width=\"10%%\">IP Address</td><td>%s</td></tr>\n", ptr);
2892 if (ll->port != -1) {
2893 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Port</td><td>%d</td></tr>\n", ll->port);
2896 if (ll->proxytype != PROXY_DIRECT) {
2897 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Proxy type</td><td>%s</td></tr>\n", (ll->proxytype == PROXY_NORMAL) ? "HTTP" : "SOCKS4");
2900 if (ll->proxy != NULL) {
2901 ptr = string_to_html(ll->proxy, TRUE);
2902 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Proxy</td><td>%s</td></tr>\n", ptr);
2906 filebuf_addf(filebuf, "</table></td></tr> <tr><td><br></td></tr>\n");
2909 filebuf_addf(filebuf, "</table>\n");
2912 void interface_page_config_redirect(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
2915 struct REDIRECT_LIST_LIST *rl = NULL;
2917 if (redirect_list == NULL)
2920 pthread_rwlock_rdlock(&redirect_list->lock);
2922 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
2923 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"60%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
2924 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><a href=\"config?section=redirect&dialog=show\">Add</a></td></tr>\n");
2925 filebuf_addf(filebuf, "</table></td></tr> <tr><td><br></td></tr>\n");
2927 for (rl = redirect_list->redirect_list; rl; rl = rl->next) {
2928 filebuf_addf(filebuf, "<tr><td align=\"center\">\n");
2929 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
2931 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Enabled</td><td>%s</td></tr>\n", (rl->enabled == TRUE) ? "yes" : "no");
2932 if (rl->comment != NULL) {
2933 ptr = string_to_html(rl->comment, TRUE);
2934 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Comment</td><td>%s</td></tr>\n", ptr);
2937 if (rl->url != NULL) {
2938 ptr = string_to_html(rl->url, TRUE);
2939 filebuf_addf(filebuf, "<tr><td width=\"10%%\">URL</td><td>%s</td></tr>\n", ptr);
2942 if (rl->redirect != NULL) {
2943 ptr = string_to_html(rl->redirect, TRUE);
2944 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Redirect</td><td>%s</td></tr>\n", ptr);
2948 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Port</td><td>%d</td></tr>\n", rl->port);
2950 filebuf_addf(filebuf, "<tr><td width=\"10%%\">302 redirect</td><td>%s</td></tr>\n", (rl->send302 == TRUE) ? "yes" : "no");
2952 if (rl->options != 0)
2953 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Options</td><td>%s,%s,%s</td></tr>\n", (rl->options & URL_ENCODE) ? "encode URL" : "", (rl->options & URL_DECODEBEFORE) ? "decode URL before" : "", (rl->options & URL_DECODEAFTER) ? "decode URL after" : "");
2955 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Applies to</td><td>%s</td></tr>\n", (rl->which == REDIRECT_BOTH) ? "both" : (rl->which == REDIRECT_URL) ? "URL" : "location");
2957 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
2958 filebuf_addf(filebuf, "<tr><td align=\"center\"><a href=\"config?section=redirect&dialog=show&id=%d\">Edit</a> <a href=\"config?section=redirect&action=delete&id=%d\">Delete</a></td>\n", rl->id, rl->id);
2959 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=redirect&action=shift&id=%d&direction=up\">Up</a> <a href=\"config?section=redirect&action=shift&id=%d&direction=down\">Down</a></td>\n", rl->id, rl->id);
2960 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=redirect&action=shift&id=%d&direction=top\">Top</a> <a href=\"config?section=redirect&action=shift&id=%d&direction=bottom\">Bottom</a></td></tr>\n", rl->id, rl->id);
2961 filebuf_addf(filebuf, "</table></td></tr>\n");
2963 filebuf_addf(filebuf, "</table></td></tr> <tr><td><br></td></tr>\n");
2966 filebuf_addf(filebuf, "</table>\n");
2968 pthread_rwlock_unlock(&redirect_list->lock);
2971 void interface_page_config_redirect_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
2975 struct REDIRECT_LIST_LIST *rl = NULL;
2976 struct cgi_args_t *a = args;
2978 if (redirect_list == NULL)
2981 pthread_rwlock_rdlock(&redirect_list->lock);
2983 for (; a; a = a->next) {
2984 if (!strcasecmp(a->name, "id"))
2985 id = atoi(a->value);
2989 for (rl = redirect_list->redirect_list; rl && rl->id != id; rl = rl->next);
2991 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
2992 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
2994 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"section\" value=\"redirect\">\n");
2997 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"edit\">\n");
2998 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"id\" value=\"%d\">\n", id);
3000 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"add\">\n");
3002 filebuf_addf(filebuf, "<tr><td>Enabled</td><td align=\"center\">");
3003 filebuf_addf(filebuf, "Yes: <input type=\"radio\" name=\"enabled\" value=\"yes\" %s> ", (rl == NULL || rl->enabled == TRUE) ? "checked" : "");
3004 filebuf_addf(filebuf, "No: <input type=\"radio\" name=\"enabled\" value=\"no\" %s> ", (rl != NULL && rl->enabled == FALSE) ? "checked" : "");
3005 filebuf_addf(filebuf, "</td></tr>\n");
3007 if (rl != NULL && rl->comment != NULL)
3008 ptr = string_to_html(rl->comment, TRUE);
3009 filebuf_addf(filebuf, "<tr><td>Comment</td><td><input type=\"text\" name=\"comment\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
3012 if (rl != NULL && rl->url != NULL)
3013 ptr = string_to_html(rl->url, TRUE);
3014 filebuf_addf(filebuf, "<tr><td>URL</td><td><input type=\"text\" name=\"url\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
3017 if (rl != NULL && rl->redirect != NULL)
3018 ptr = string_to_html(rl->redirect, TRUE);
3019 filebuf_addf(filebuf, "<tr><td>Redirect</td><td><input type=\"text\" name=\"redirect\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
3022 if (rl != NULL && rl->port != -1)
3023 filebuf_addf(filebuf, "<tr><td>Port</td><td><input type=\"text\" name=\"port\" value=\"%d\" size=\"20\"></td></tr>\n", rl->port);
3025 filebuf_addf(filebuf, "<tr><td>Port</td><td><input type=\"text\" name=\"port\" value=\"\" size\"20\"></td></tr>\n");
3027 filebuf_addf(filebuf, "<tr><td>302 redirect</td><td align=\"center\">");
3028 filebuf_addf(filebuf, "Yes: <input type=\"radio\" name=\"send302\" value=\"yes\" %s> ", (rl == NULL || rl->send302 == TRUE) ? "checked" : "");
3029 filebuf_addf(filebuf, "No: <input type=\"radio\" name=\"send302\" value=\"no\" %s> ", (rl != NULL && rl->send302 == FALSE) ? "checked" : "");
3030 filebuf_addf(filebuf, "</td></tr>\n");
3032 filebuf_addf(filebuf, "<tr><td>Options</td><td align=\"center\">");
3033 filebuf_addf(filebuf, "Encode URL: <input type=\"checkbox\" name=\"encode\" %s> ", (rl != NULL && (rl->options & URL_ENCODE)) ? "checked" : "");
3034 filebuf_addf(filebuf, "Decode URL before: <input type=\"checkbox\" name=\"decodebefore\" %s> ", (rl != NULL && (rl->options & URL_DECODEBEFORE)) ? "checked" : "");
3035 filebuf_addf(filebuf, "Decode URL after: <input type=\"checkbox\" name=\"decodeafter\" %s>", (rl != NULL && (rl->options & URL_DECODEAFTER)) ? "checked" : "");
3036 filebuf_addf(filebuf, "</td></tr>\n");
3038 filebuf_addf(filebuf, "<tr><td>Applies to</td><td align=\"center\">");
3039 filebuf_addf(filebuf, "Both: <input type=\"radio\" name=\"which\" value=\"both\" %s> ", (rl != NULL && rl->which == REDIRECT_BOTH) ? "checked" : "");
3040 filebuf_addf(filebuf, "URL: <input type=\"radio\" name=\"which\" value=\"url\" %s> ", (rl == NULL || rl->which == REDIRECT_URL) ? "checked" : "");
3041 filebuf_addf(filebuf, "Location header: <input type=\"radio\" name=\"which\" value=\"location\" %s> ", (rl != NULL && rl->which == REDIRECT_LOCATION) ? "checked" : "");
3042 filebuf_addf(filebuf, "</td></tr>\n");
3044 filebuf_addf(filebuf, "<tr><td colspan=\"2\"><br></td></tr>\n");
3045 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
3047 filebuf_addf(filebuf, "</table></td></tr>\n");
3049 pthread_rwlock_unlock(&redirect_list->lock);
3053 void interface_page_config_redirect_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
3056 char *action = NULL;
3057 struct REDIRECT_LIST_LIST *rl = NULL;
3058 struct cgi_args_t *a;
3060 if (redirect_list == NULL)
3063 pthread_rwlock_wrlock(&redirect_list->lock);
3065 for (a = args; a; a = a->next) {
3066 if (!strcasecmp(a->name, "action"))
3068 if (!strcasecmp(a->name, "id"))
3069 id = atoi(a->value);
3075 if (!strcasecmp(action, "delete")) {
3076 for (rl = redirect_list->redirect_list; rl; rl = rl->next) {
3078 redirect_list->redirect_list = redirect_list_delete(rl);
3083 } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) {
3084 if (!strcasecmp(action, "add")) {
3085 rl = redirect_list_new(redirect_list->redirect_list);
3086 if (redirect_list->redirect_list == NULL)
3087 redirect_list->redirect_list = rl;
3088 rl->id = redirect_list->id++;
3090 for (rl = redirect_list->redirect_list; rl; rl = rl->next)
3098 if (strcasecmp(action, "shift")) {
3101 for (a = args; a; a = a->next) {
3102 if (!strcasecmp(a->name, "enabled")) {
3103 if (!strcasecmp(a->value, "no"))
3104 rl->enabled = FALSE;
3107 } else if (!strcasecmp(a->name, "comment"))
3108 redirect_list_insert(rl, a->value, NULL, NULL, NULL, NULL, NULL, NULL);
3109 else if (!strcasecmp(a->name, "url"))
3110 redirect_list_insert(rl, NULL, a->value, NULL, NULL, NULL, NULL, NULL);
3111 else if (!strcasecmp(a->name, "redirect"))
3112 redirect_list_insert(rl, NULL, NULL, a->value, NULL, NULL, NULL, NULL);
3113 else if (!strcasecmp(a->name, "port"))
3114 redirect_list_insert(rl, NULL, NULL, NULL, a->value, NULL, NULL, NULL);
3115 else if (!strcasecmp(a->name, "which"))
3116 redirect_list_insert(rl, NULL, NULL, NULL, NULL, a->value, NULL, NULL);
3117 else if (!strcasecmp(a->name, "send302"))
3118 redirect_list_insert(rl, NULL, NULL, NULL, NULL, NULL, a->value, NULL);
3119 else if (!strcasecmp(a->name, "encode"))
3120 rl->options |= URL_ENCODE;
3121 else if (!strcasecmp(a->name, "decodebefore"))
3122 rl->options |= URL_DECODEBEFORE;
3123 else if (!strcasecmp(a->name, "decodeafter"))
3124 rl->options |= URL_DECODEAFTER;
3127 for (a = args; a; a = a->next) {
3128 if (!strcasecmp(a->name, "direction")) {
3129 if (!strcasecmp(a->value, "up")) {
3130 SHIFTNODE(struct REDIRECT_LIST_LIST *, redirect_list->redirect_list, rl, UP);
3131 } else if (!strcasecmp(a->value, "down")) {
3132 SHIFTNODE(struct REDIRECT_LIST_LIST *, redirect_list->redirect_list, rl, DOWN);
3133 } else if (!strcasecmp(a->value, "top")) {
3134 SETNODE(struct REDIRECT_LIST_LIST *, redirect_list->redirect_list, rl, TOP);
3135 } else if (!strcasecmp(a->value, "bottom")) {
3136 SETNODE(struct REDIRECT_LIST_LIST *, redirect_list->redirect_list, rl, BOTTOM);
3144 pthread_rwlock_unlock(&redirect_list->lock);
3146 void interface_page_config_forward(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
3149 struct FORWARD_LIST_LIST *fl = NULL;
3151 if (forward_list == NULL)
3154 pthread_rwlock_rdlock(&forward_list->lock);
3156 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
3157 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"60%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
3158 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><a href=\"config?section=forward&dialog=show\">Add</a></td></tr>\n");
3159 filebuf_addf(filebuf, "</table></td></tr> <tr><td><br></td></tr>\n");
3161 for (fl = forward_list->forward_list; fl; fl = fl->next) {
3162 filebuf_addf(filebuf, "<tr><td align=\"center\">\n");
3163 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
3165 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Enabled</td><td>%s</td></tr>\n", (fl->enabled == TRUE) ? "yes" : "no");
3166 if (fl->comment != NULL) {
3167 ptr = string_to_html(fl->comment, TRUE);
3168 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Comment</td><td>%s</td></tr>\n", ptr);
3171 if (fl->host != NULL) {
3172 ptr = string_to_html(fl->host, TRUE);
3173 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Host</td><td>%s</td></tr>\n", ptr);
3176 if (fl->file != NULL) {
3177 ptr = string_to_html(fl->file, TRUE);
3178 filebuf_addf(filebuf, "<tr><td width=\"10%%\">File</td><td>%s</td></tr>\n", ptr);
3181 if (fl->proxy != NULL) {
3182 ptr = string_to_html(fl->proxy, TRUE);
3183 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Proxy</td><td>%s</td></tr>\n", ptr);
3186 if (fl->username != NULL) {
3187 ptr = string_to_html(fl->username, TRUE);
3188 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Username</td><td>%s</td></tr>\n", ptr);
3191 if (fl->password != NULL) {
3192 ptr = string_to_html(fl->password, TRUE);
3193 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Password</td><td>%s</td></tr>\n", ptr);
3196 if (fl->domain != NULL) {
3197 ptr = string_to_html(fl->domain, TRUE);
3198 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Domain</td><td>%s</td></tr>\n", ptr);
3202 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Port</td><td>%d</td></tr>\n", fl->port);
3204 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Type</td><td>%s</td></tr>\n", (fl->type == PROXY_NORMAL) ? "HTTP" : "SOCKS4");
3207 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Applies to</td><td>%s,%s</td></tr>\n", (fl->which & FORWARD_HTTP) ? "HTTP requests" : "", (fl->which & FORWARD_CONNECT) ? "CONNECT requests" : "");
3209 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
3210 filebuf_addf(filebuf, "<tr><td align=\"center\"><a href=\"config?section=forward&dialog=show&id=%d\">Edit</a> <a href=\"config?section=forward&action=delete&id=%d\">Delete</a></td>\n", fl->id, fl->id);
3211 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=forward&action=shift&id=%d&direction=up\">Up</a> <a href=\"config?section=forward&action=shift&id=%d&direction=down\">Down</a></td>\n", fl->id, fl->id);
3212 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=forward&action=shift&id=%d&direction=top\">Top</a> <a href=\"config?section=forward&action=shift&id=%d&direction=bottom\">Bottom</a></td></tr>\n", fl->id, fl->id);
3213 filebuf_addf(filebuf, "</table></td></tr>\n");
3215 filebuf_addf(filebuf, "</table></td></tr> <tr><td><br></td></tr>\n");
3218 filebuf_addf(filebuf, "</table>\n");
3220 pthread_rwlock_unlock(&forward_list->lock);
3223 void interface_page_config_forward_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
3227 struct FORWARD_LIST_LIST *fl = NULL;
3228 struct cgi_args_t *a = args;
3230 if (forward_list == NULL)
3233 pthread_rwlock_rdlock(&forward_list->lock);
3235 for (; a; a = a->next) {
3236 if (!strcasecmp(a->name, "id"))
3237 id = atoi(a->value);
3241 for (fl = forward_list->forward_list; fl && fl->id != id; fl = fl->next);
3243 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
3244 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
3246 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"section\" value=\"forward\">\n");
3249 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"edit\">\n");
3250 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"id\" value=\"%d\">\n", id);
3252 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"add\">\n");
3254 filebuf_addf(filebuf, "<tr><td>Enabled</td><td align=\"center\">");
3255 filebuf_addf(filebuf, "Yes: <input type=\"radio\" name=\"enabled\" value=\"yes\" %s> ", (fl == NULL || fl->enabled == TRUE) ? "checked" : "");
3256 filebuf_addf(filebuf, "No: <input type=\"radio\" name=\"enabled\" value=\"no\" %s> ", (fl != NULL && fl->enabled == FALSE) ? "checked" : "");
3257 filebuf_addf(filebuf, "</td></tr>\n");
3259 if (fl != NULL && fl->comment != NULL)
3260 ptr = string_to_html(fl->comment, TRUE);
3261 filebuf_addf(filebuf, "<tr><td>Comment</td><td><input type=\"text\" name=\"comment\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
3264 if (fl != NULL && fl->host != NULL)
3265 ptr = string_to_html(fl->host, TRUE);
3266 filebuf_addf(filebuf, "<tr><td>Host</td><td><input type=\"text\" name=\"host\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
3269 if (fl != NULL && fl->file != NULL)
3270 ptr = string_to_html(fl->file, TRUE);
3271 filebuf_addf(filebuf, "<tr><td>File</td><td><input type=\"text\" name=\"file\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
3274 if (fl != NULL && fl->proxy != NULL)
3275 ptr = string_to_html(fl->proxy, TRUE);
3276 filebuf_addf(filebuf, "<tr><td>Proxy</td><td><input type=\"text\" name=\"proxy\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
3279 if (fl != NULL && fl->username != NULL)
3280 ptr = string_to_html(fl->username, TRUE);
3281 filebuf_addf(filebuf, "<tr><td>Username</td><td><input type=\"text\" name=\"username\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
3284 if (fl != NULL && fl->password != NULL)
3285 ptr = string_to_html(fl->password, TRUE);
3286 filebuf_addf(filebuf, "<tr><td>Password</td><td><input type=\"text\" name=\"password\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
3289 if (fl != NULL && fl->domain != NULL)
3290 ptr = string_to_html(fl->domain, TRUE);
3291 filebuf_addf(filebuf, "<tr><td>Domain</td><td><input type=\"text\" name=\"domain\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
3294 if (fl != NULL && fl->port != -1)
3295 filebuf_addf(filebuf, "<tr><td>Port</td><td><input type=\"text\" name=\"port\" value=\"%d\" size=\"20\"></td></tr>\n", fl->port);
3297 filebuf_addf(filebuf, "<tr><td>Port</td><td><input type=\"text\" name=\"port\" value=\"\" size\"20\"></td></tr>\n");
3299 filebuf_addf(filebuf, "<tr><td>Type</td><td align=\"center\">");
3300 filebuf_addf(filebuf, "HTTP: <input type=\"radio\" name=\"type\" value=\"HTTP\" %s> ", (fl == NULL || fl->type == PROXY_NORMAL) ? "checked" : "");
3301 filebuf_addf(filebuf, "SOCKS4: <input type=\"radio\" name=\"type\" value=\"SOCKS4\" %s> ", (fl != NULL && fl->type == PROXY_SOCKS4) ? "checked" : "");
3302 filebuf_addf(filebuf, "</td></tr>\n");
3304 filebuf_addf(filebuf, "<tr><td>Applies to</td><td align=\"center\">");
3305 filebuf_addf(filebuf, "HTTP requests: <input type=\"checkbox\" name=\"HTTP\" %s> ", (fl == NULL || (fl->which & FORWARD_HTTP)) ? "checked" : "");
3306 filebuf_addf(filebuf, "CONNECT requests: <input type=\"checkbox\" name=\"CONNECT\" %s> ", (fl != NULL && (fl->which & FORWARD_CONNECT)) ? "checked" : "");
3307 filebuf_addf(filebuf, "</td></tr>\n");
3309 filebuf_addf(filebuf, "<tr><td colspan=\"2\"><br></td></tr>\n");
3310 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
3312 filebuf_addf(filebuf, "</table></td></tr>\n");
3314 pthread_rwlock_unlock(&forward_list->lock);
3318 void interface_page_config_forward_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
3321 char *action = NULL;
3322 struct FORWARD_LIST_LIST *fl = NULL;
3323 struct cgi_args_t *a;
3325 if (forward_list == NULL)
3328 pthread_rwlock_wrlock(&forward_list->lock);
3330 for (a = args; a; a = a->next) {
3331 if (!strcasecmp(a->name, "action"))
3333 if (!strcasecmp(a->name, "id"))
3334 id = atoi(a->value);
3340 if (!strcasecmp(action, "delete")) {
3341 for (fl = forward_list->forward_list; fl; fl = fl->next) {
3343 forward_list->forward_list = forward_list_delete(fl);
3348 } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) {
3349 if (!strcasecmp(action, "add")) {
3350 fl = forward_list_new(forward_list->forward_list);
3351 if (forward_list->forward_list == NULL)
3352 forward_list->forward_list = fl;
3353 fl->id = forward_list->id++;
3355 for (fl = forward_list->forward_list; fl; fl = fl->next)
3363 if (strcasecmp(action, "shift")) {
3366 for (a = args; a; a = a->next) {
3367 if (!strcasecmp(a->name, "enabled")) {
3368 if (!strcasecmp(a->value, "no"))
3369 fl->enabled = FALSE;
3372 } else if (!strcasecmp(a->name, "comment"))
3373 forward_list_insert(fl, a->value, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
3374 else if (!strcasecmp(a->name, "host"))
3375 forward_list_insert(fl, NULL, a->value, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
3376 else if (!strcasecmp(a->name, "file"))
3377 forward_list_insert(fl, NULL, NULL, a->value, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
3378 else if (!strcasecmp(a->name, "proxy"))
3379 forward_list_insert(fl, NULL, NULL, NULL, a->value, NULL, NULL, NULL, NULL, NULL, NULL);
3380 else if (!strcasecmp(a->name, "port"))
3381 forward_list_insert(fl, NULL, NULL, NULL, NULL, a->value, NULL, NULL, NULL, NULL, NULL);
3382 else if (!strcasecmp(a->name, "type"))
3383 forward_list_insert(fl, NULL, NULL, NULL, NULL, NULL, a->value, NULL, NULL, NULL, NULL);
3384 else if (!strcasecmp(a->name, "username"))
3385 forward_list_insert(fl, NULL, NULL, NULL, NULL, NULL, NULL, NULL, a->value, NULL, NULL);
3386 else if (!strcasecmp(a->name, "password"))
3387 forward_list_insert(fl, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, a->value, NULL);
3388 else if (!strcasecmp(a->name, "domain"))
3389 forward_list_insert(fl, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, a->value);
3390 else if (!strcasecmp(a->name, "HTTP"))
3391 fl->which |= FORWARD_HTTP;
3392 else if (!strcasecmp(a->name, "CONNECT"))
3393 fl->which |= FORWARD_CONNECT;
3396 for (a = args; a; a = a->next) {
3397 if (!strcasecmp(a->name, "direction")) {
3398 if (!strcasecmp(a->value, "up")) {
3399 SHIFTNODE(struct FORWARD_LIST_LIST *, forward_list->forward_list, fl, UP);
3400 } else if (!strcasecmp(a->value, "down")) {
3401 SHIFTNODE(struct FORWARD_LIST_LIST *, forward_list->forward_list, fl, DOWN);
3402 } else if (!strcasecmp(a->value, "top")) {
3403 SETNODE(struct FORWARD_LIST_LIST *, forward_list->forward_list, fl, TOP);
3404 } else if (!strcasecmp(a->value, "bottom")) {
3405 SETNODE(struct FORWARD_LIST_LIST *, forward_list->forward_list, fl, BOTTOM);
3413 pthread_rwlock_unlock(&forward_list->lock);
3416 void interface_page_config_keywords(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
3419 struct KEYWORD_LIST_LIST *kl = NULL;
3421 if (keyword_list == NULL)
3424 pthread_rwlock_rdlock(&keyword_list->lock);
3426 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
3427 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"60%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
3428 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
3429 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"section\" value=\"keywords\">\n");
3430 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"global\">\n");
3431 filebuf_addf(filebuf, "<tr><td>Template</td><td><input type=\"text\" name=\"template\" value=\"%s\" size=\"20\"></td></tr>\n", (keyword_list->template != NULL) ? keyword_list->template : "");
3432 filebuf_addf(filebuf, "<tr><td>Threshold</td><td><input type=\"text\" name=\"threshold\" value=\"%d\" size=\"20\"></td></tr>\n", keyword_list->threshold);
3433 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
3434 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><a href=\"config?section=keywords&dialog=show\">Add</a></td></tr>\n");
3435 filebuf_addf(filebuf, "</form></table></td></tr> <tr><td><br></td></tr>\n");
3437 for (kl = keyword_list->keyword_list; kl; kl = kl->next) {
3438 filebuf_addf(filebuf, "<tr><td align=\"center\">\n");
3439 filebuf_addf(filebuf, "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
3441 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Enabled</td><td>%s</td></tr>\n", (kl->enabled == TRUE) ? "yes" : "no");
3442 if (kl->comment != NULL) {
3443 ptr = string_to_html(kl->comment, TRUE);
3444 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Comment</td><td>%s</td></tr>\n", ptr);
3447 if (kl->host != NULL) {
3448 ptr = string_to_html(kl->host, TRUE);
3449 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Host</td><td>%s</td></tr>\n", ptr);
3452 if (kl->file != NULL) {
3453 ptr = string_to_html(kl->file, TRUE);
3454 filebuf_addf(filebuf, "<tr><td width=\"10%%\">File</td><td>%s</td></tr>\n", ptr);
3457 if (kl->mime != NULL) {
3458 ptr = string_to_html(kl->mime, TRUE);
3459 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Mimetype</td><td>%s</td></tr>\n", ptr);
3462 if (kl->keyword != NULL) {
3463 ptr = string_to_html(kl->keyword, TRUE);
3464 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Keyword</td><td>%s</td></tr>\n", ptr);
3467 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Score</td><td>%d</td></tr>\n", kl->score);
3469 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
3470 filebuf_addf(filebuf, "<tr><td align=\"center\"><a href=\"config?section=keywords&dialog=show&id=%d\">Edit</a> <a href=\"config?section=keywords&action=delete&id=%d\">Delete</a></td>\n", kl->id, kl->id);
3471 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=keywords&action=shift&id=%d&direction=up\">Up</a> <a href=\"config?section=keywords&action=shift&id=%d&direction=down\">Down</a></td>\n", kl->id, kl->id);
3472 filebuf_addf(filebuf, "<td align=\"center\"><a href=\"config?section=keywords&action=shift&id=%d&direction=top\">Top</a> <a href=\"config?section=keywords&action=shift&id=%d&direction=bottom\">Bottom</a></td></tr>\n", kl->id, kl->id);
3473 filebuf_addf(filebuf, "</table></td></tr>\n");
3475 filebuf_addf(filebuf, "</table></td></tr> <tr><td><br></td></tr>\n");
3478 filebuf_addf(filebuf, "</table>\n");
3480 pthread_rwlock_unlock(&keyword_list->lock);
3483 void interface_page_config_keywords_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
3487 struct KEYWORD_LIST_LIST *kl = NULL;
3488 struct cgi_args_t *a = args;
3490 if (keyword_list == NULL)
3493 pthread_rwlock_rdlock(&keyword_list->lock);
3495 for (; a; a = a->next) {
3496 if (!strcasecmp(a->name, "id"))
3497 id = atoi(a->value);
3501 for (kl = keyword_list->keyword_list; kl && kl->id != id; kl = kl->next);
3503 filebuf_addf(filebuf, "<tr><td align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
3504 filebuf_addf(filebuf, "<form action=\"config\" method=\"POST\">\n");
3506 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"section\" value=\"keywords\">\n");
3509 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"edit\">\n");
3510 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"id\" value=\"%d\">\n", id);
3512 filebuf_addf(filebuf, "<input type=\"hidden\" name=\"action\" value=\"add\">\n");
3514 filebuf_addf(filebuf, "<tr><td>Enabled</td><td align=\"center\">");
3515 filebuf_addf(filebuf, "Yes: <input type=\"radio\" name=\"enabled\" value=\"yes\" %s> ", (kl == NULL || kl->enabled == TRUE) ? "checked" : "");
3516 filebuf_addf(filebuf, "No: <input type=\"radio\" name=\"enabled\" value=\"no\" %s> ", (kl != NULL && kl->enabled == FALSE) ? "checked" : "");
3517 filebuf_addf(filebuf, "</td></tr>\n");
3519 if (kl != NULL && kl->comment != NULL)
3520 ptr = string_to_html(kl->comment, TRUE);
3521 filebuf_addf(filebuf, "<tr><td>Comment</td><td><input type=\"text\" name=\"comment\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
3524 if (kl != NULL && kl->host != NULL)
3525 ptr = string_to_html(kl->host, TRUE);
3526 filebuf_addf(filebuf, "<tr><td>Host</td><td><input type=\"text\" name=\"host\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
3529 if (kl != NULL && kl->file != NULL)
3530 ptr = string_to_html(kl->file, TRUE);
3531 filebuf_addf(filebuf, "<tr><td>File</td><td><input type=\"text\" name=\"file\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
3534 if (kl != NULL && kl->mime != NULL)
3535 ptr = string_to_html(kl->mime, TRUE);
3536 filebuf_addf(filebuf, "<tr><td>Mimetype</td><td><input type=\"text\" name=\"mime\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
3539 if (kl != NULL && kl->keyword != NULL)
3540 ptr = string_to_html(kl->keyword, TRUE);
3541 filebuf_addf(filebuf, "<tr><td>Keyword</td><td><input type=\"text\" name=\"keyword\" value=\"%s\" size=\"80\"></td></tr>\n", (ptr != NULL) ? ptr : "");
3544 filebuf_addf(filebuf, "<tr><td>Score</td><td><input type=\"text\" name=\"score\" value=\"%d\" size=\"20\"></td></tr>\n", (kl != NULL) ? kl->score : 0);
3546 filebuf_addf(filebuf, "<tr><td colspan=\"2\"><br></td></tr>\n");
3547 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Submit\"></td></tr>\n");
3549 filebuf_addf(filebuf, "</table></td></tr>\n");
3551 pthread_rwlock_unlock(&keyword_list->lock);
3555 void interface_page_config_keywords_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection)
3558 char *action = NULL;
3559 struct KEYWORD_LIST_LIST *kl = NULL;
3560 struct cgi_args_t *a;
3562 if (keyword_list == NULL)
3565 pthread_rwlock_wrlock(&keyword_list->lock);
3567 for (a = args; a; a = a->next) {
3568 if (!strcasecmp(a->name, "action"))
3570 if (!strcasecmp(a->name, "id"))
3571 id = atoi(a->value);
3574 if (action == NULL) goto finish;
3576 if (!strcasecmp(action, "global")) {
3577 for (a = args; a; a = a->next) {
3578 if (!strcasecmp(a->name, "template")) {
3579 FREE_AND_NULL(keyword_list->template);
3580 if (strcmp(a->value, ""))
3581 keyword_list->template = xstrdup(a->value);
3582 } else if (!strcasecmp(a->name, "threshold"))
3583 keyword_list->threshold = atoi(a->value);
3587 if (!strcasecmp(action, "delete")) {
3588 for (kl = keyword_list->keyword_list; kl; kl = kl->next) {
3590 keyword_list->keyword_list = keyword_list_delete(kl);
3595 } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) {
3596 if (!strcasecmp(action, "add")) {
3597 kl = keyword_list_new(keyword_list->keyword_list);
3598 if (keyword_list->keyword_list == NULL)
3599 keyword_list->keyword_list = kl;
3600 kl->id = keyword_list->id++;
3602 for (kl = keyword_list->keyword_list; kl; kl = kl->next)
3610 if (strcasecmp(action, "shift")) {
3611 for (a = args; a; a = a->next) {
3612 if (!strcasecmp(a->name, "enabled")) {
3613 if (!strcasecmp(a->value, "no"))
3614 kl->enabled = FALSE;
3617 } else if (!strcasecmp(a->name, "comment"))
3618 keyword_list_insert(kl, a->value, NULL, NULL, NULL, NULL, NULL);
3619 else if (!strcasecmp(a->name, "host"))
3620 keyword_list_insert(kl, NULL, a->value, NULL, NULL, NULL, NULL);
3621 else if (!strcasecmp(a->name, "file"))
3622 keyword_list_insert(kl, NULL, NULL, a->value, NULL, NULL, NULL);
3623 else if (!strcasecmp(a->name, "mime"))
3624 keyword_list_insert(kl, NULL, NULL, NULL, a->value, NULL, NULL);
3625 else if (!strcasecmp(a->name, "keyword"))
3626 keyword_list_insert(kl, NULL, NULL, NULL, NULL, a->value, NULL);
3627 else if (!strcasecmp(a->name, "score"))
3628 keyword_list_insert(kl, NULL, NULL, NULL, NULL, NULL, a->value);
3631 for (a = args; a; a = a->next) {
3632 if (!strcasecmp(a->name, "direction")) {
3633 if (!strcasecmp(a->value, "up")) {
3634 SHIFTNODE(struct KEYWORD_LIST_LIST *, keyword_list->keyword_list, kl, UP);
3635 } else if (!strcasecmp(a->value, "down")) {
3636 SHIFTNODE(struct KEYWORD_LIST_LIST *, keyword_list->keyword_list, kl, DOWN);
3637 } else if (!strcasecmp(a->value, "top")) {
3638 SETNODE(struct KEYWORD_LIST_LIST *, keyword_list->keyword_list, kl, TOP);
3639 } else if (!strcasecmp(a->value, "bottom")) {
3640 SETNODE(struct KEYWORD_LIST_LIST *, keyword_list->keyword_list, kl, BOTTOM);
3648 pthread_rwlock_unlock(&keyword_list->lock);
3651 void filter_check_show(CONNECTION * connection)
3654 struct FILTER_LIST_LIST *fl;
3658 filebuf = filebuf_new();
3660 fl = filter_check(filter_list, connection);
3662 filebuf_addf(filebuf, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
3663 filebuf_addf(filebuf, "<html><head><title>URL filter matche for %s%s</title></head>", connection->header->host, connection->header->file);
3664 filebuf_addf(filebuf, "<body text=\"%s\" bgcolor=\"%s\" link=\"%s\" vlink=\"%s\">\n", INTERFACE_TEXT, INTERFACE_BG, INTERFACE_LINK, INTERFACE_VLINK);
3665 filebuf_addf(filebuf, "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%%\"><tr><td align=\"center\">\n");
3666 filebuf_addf(filebuf, "<table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
3667 filebuf_addf(filebuf, "<tr><th align=\"center\" colspan=\"2\">URL filter match for %s%s</th></tr>\n", connection->header->host, connection->header->file);
3669 filebuf_addf(filebuf, "<tr><td align=\"center\" colspan=\"2\">None</td></tr>\n");
3671 if (fl->comment != NULL) {
3672 ptr = string_to_html(fl->comment, TRUE);
3673 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Comment</td><td>%s</td></tr>\n", ptr);
3676 if (fl->host != NULL) {
3677 ptr = string_to_html(fl->host, TRUE);
3678 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Host</td><td>%s</td></tr>\n", ptr);
3681 if (fl->file != NULL) {
3682 ptr = string_to_html(fl->file, TRUE);
3683 filebuf_addf(filebuf, "<tr><td width=\"10%%\">File</td><td>%s</td></tr>\n", ptr);
3687 if (fl->template != NULL)
3688 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Template</td><td>%s</td></tr>\n", fl->template);
3690 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
3691 filebuf_addf(filebuf, "<tr><td align=\"center\"><a href=\"http://%s/config?section=filter&dialog=show&list=deny&id=%d\">Edit</a> <a href=\"http://%s/config?section=filter&action=delete&list=deny&id=%d\">Delete</a></td>\n", INTERFACEURL, fl->id, INTERFACEURL, fl->id);
3694 filebuf_addf(filebuf, "</table></td></tr></table></body></html>\n");
3696 header = header_new();;
3697 header->type = HTTP_RESP;
3699 header->content_type = xstrdup("text/html");
3700 header->content_length = filebuf->size;
3702 header_send(header, connection, CLIENT, HEADER_RESP);
3703 net_filebuf_send(filebuf, connection, CLIENT);
3705 http_header_free(header);
3706 filebuf_free(filebuf);
3708 pthread_rwlock_unlock(&filter_list->lock);
3713 void mime_check_show(CONNECTION * connection)
3716 struct MIME_LIST_LIST *ml;
3720 filebuf = filebuf_new();
3722 ml = mime_check(mime_list, connection);
3724 filebuf_addf(filebuf, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
3725 filebuf_addf(filebuf, "<html><head><title>MIME filter match for %s%s</title></head>", connection->header->host, connection->header->file);
3726 filebuf_addf(filebuf, "<body text=\"%s\" bgcolor=\"%s\" link=\"%s\" vlink=\"%s\">\n", INTERFACE_TEXT, INTERFACE_BG, INTERFACE_LINK, INTERFACE_VLINK);
3727 filebuf_addf(filebuf, "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%%\"><tr><td align=\"center\">\n");
3728 filebuf_addf(filebuf, "<table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
3729 filebuf_addf(filebuf, "<tr><th align=\"center\" colspan=\"2\">MIME filter match for %s%s</th></tr>\n", connection->header->host, connection->header->file);
3731 filebuf_addf(filebuf, "<tr><td align=\"center\" colspan=\"2\">None</td></tr>\n");
3733 if (ml->comment != NULL) {
3734 ptr = string_to_html(ml->comment, TRUE);
3735 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Comment</td><td>%s</td></tr>\n", ptr);
3738 if (ml->host != NULL) {
3739 ptr = string_to_html(ml->host, TRUE);
3740 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Host</td><td>%s</td></tr>\n", ptr);
3743 if (ml->file != NULL) {
3744 ptr = string_to_html(ml->file, TRUE);
3745 filebuf_addf(filebuf, "<tr><td width=\"10%%\">File</td><td>%s</td></tr>\n", ptr);
3748 if (ml->mime != NULL) {
3749 ptr = string_to_html(ml->mime, TRUE);
3750 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Mimetype</td><td>%s</td></tr>\n", ptr);
3753 if (ml->template != NULL)
3754 filebuf_addf(filebuf, "<tr><td width=\"10%%\">Template</td><td>%s</td></tr>\n", ml->template);
3757 filebuf_addf(filebuf, "<tr><td colspan=\"2\" align=\"center\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%%\">\n");
3758 filebuf_addf(filebuf, "<tr><td align=\"center\"><a href=\"http://%s/config?section=mime&dialog=show&list=deny&id=%d\">Edit</a> <a href=\"http://%s/config?section=mime&action=delete&list=deny&id=%d\">Delete</a></td>\n", INTERFACEURL, ml->id, INTERFACEURL, ml->id);
3761 filebuf_addf(filebuf, "</table></td></tr></table></body></html>\n");
3763 header = header_new();;
3764 header->type = HTTP_RESP;
3766 header->content_type = xstrdup("text/html");
3767 header->content_length = filebuf->size;
3769 header_send(header, connection, CLIENT, HEADER_RESP);
3770 net_filebuf_send(filebuf, connection, CLIENT);
3772 http_header_free(header);
3773 filebuf_free(filebuf);
3775 pthread_rwlock_unlock(&mime_list->lock);
3780 void score_show(CONNECTION *connection, int score) {
3784 filebuf = filebuf_new();
3786 filebuf_addf(filebuf, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
3787 filebuf_addf(filebuf, "<html><head><title>Keyword score for %s%s</title></head>", connection->header->host, connection->header->file);
3788 filebuf_addf(filebuf, "<body text=\"%s\" bgcolor=\"%s\" link=\"%s\" vlink=\"%s\">\n", INTERFACE_TEXT, INTERFACE_BG, INTERFACE_LINK, INTERFACE_VLINK);
3789 filebuf_addf(filebuf, "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%%\"><tr><td align=\"center\">\n");
3790 filebuf_addf(filebuf, "<table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" width=\"80%%\" bgcolor=\"%s\">\n", INTERFACE_TABLEBG);
3791 filebuf_addf(filebuf, "<tr><th align=\"center\">Keyword score for %s%s</th></tr>\n", connection->header->host, connection->header->file);
3792 filebuf_addf(filebuf, "<tr><td align=\"center\">%d</td></tr>\n", score);
3793 filebuf_addf(filebuf, "</table></td></tr></table></body></html>\n");
3795 header = header_new();;
3796 header->type = HTTP_RESP;
3798 header->content_type = xstrdup("text/html");
3799 header->content_length = filebuf->size;
3801 header_send(header, connection, CLIENT, HEADER_RESP);
3802 net_filebuf_send(filebuf, connection, CLIENT);
3804 http_header_free(header);
3805 filebuf_free(filebuf);