/* MiddleMan filtering proxy server Copyright (C) 2002 Jason McLaughlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include "proto.h" extern char configfile[]; extern THREADLIST threads[]; extern pthread_mutex_t dns_cache_lock; extern HASH_TABLE *dns_cache; extern FILTER_LIST *filter_list; extern HEADER_LIST *header_list; extern MIME_LIST *mime_list; extern REDIRECT_LIST *redirect_list; extern KEYWORD_LIST *keyword_list; extern ACCESS_LIST *access_list; extern COOKIE_LIST *cookie_list; extern REWRITE_LIST *rewrite_list; extern FORWARD_LIST *forward_list; extern TEMPLATES *templates; extern EXTERNAL *external; extern NETWORK *network; extern LOGBUFFER *logbuffer; struct pages_t { char *file; void (*handler) (FILEBUF *, struct cgi_args_t *, CONNECTION *); }; struct pages_t pages[] = { {"/connections", interface_page_connections}, {"/dnscache", interface_page_dnscache}, {"/headers", interface_page_headers}, {"/config", interface_page_config}, {"/save", interface_page_save}, {"/load", interface_page_load}, {"/log", interface_page_log}, {NULL, NULL} }; struct pages_t config_pages[] = { {"filter", interface_page_config_filter}, {"access", interface_page_config_access}, {"rewrite", interface_page_config_rewrite}, {"mime", interface_page_config_mime}, {"cookies", interface_page_config_cookies}, {"external", interface_page_config_external}, {"templates", interface_page_config_templates}, {"network", interface_page_config_network}, {"header", interface_page_config_header}, {"redirect", interface_page_config_redirect}, {"forward", interface_page_config_forward}, {"keywords", interface_page_config_keywords}, {NULL, NULL} }; struct pages_t action_pages[] = { {"filter", interface_page_config_filter_action}, {"external", interface_page_config_external_action}, {"rewrite", interface_page_config_rewrite_action}, {"access", interface_page_config_access_action}, {"mime", interface_page_config_mime_action}, {"templates", interface_page_config_templates_action}, {"header", interface_page_config_header_action}, {"cookies", interface_page_config_cookies_action}, {"redirect", interface_page_config_redirect_action}, {"forward", interface_page_config_forward_action}, {"keywords", interface_page_config_keywords_action}, {NULL, NULL} }; struct pages_t dialog_pages[] = { {"filter", interface_page_config_filter_dialog}, {"external", interface_page_config_external_dialog}, {"rewrite", interface_page_config_rewrite_dialog}, {"access", interface_page_config_access_dialog}, {"mime", interface_page_config_mime_dialog}, {"templates", interface_page_config_templates_dialog}, {"header", interface_page_config_header_dialog}, {"cookies", interface_page_config_cookies_dialog}, {"redirect", interface_page_config_redirect_dialog}, {"forward", interface_page_config_forward_dialog}, {"keywords", interface_page_config_keywords_dialog}, {NULL, NULL} }; struct cgi_args_t *cgi_parse_request(char *file) { int pos = 0, astart = 0, aequal = -1; struct cgi_args_t *args = NULL, *start = NULL; for (; file[pos]; pos++) { if (file[pos] == '=') aequal = pos; else if (file[pos] == '&' && aequal != -1) { if (args == NULL) { args = xmalloc(sizeof(struct cgi_args_t)); start = args; } else { args->next = xmalloc(sizeof(struct cgi_args_t)); args = args->next; } args->name = url_decode(&file[astart], aequal - astart); args->value = url_decode(&file[aequal + 1], pos - aequal - 1); args->next = NULL; aequal = -1; astart = pos + 1; } } if (aequal != -1) { if (args == NULL) { args = xmalloc(sizeof(struct cgi_args_t)); start = args; } else { args->next = xmalloc(sizeof(struct cgi_args_t)); args = args->next; } args->next = NULL; args->name = url_decode(&file[astart], aequal - astart); args->value = url_decode(&file[aequal + 1], pos - aequal - 1); } return start; } void cgi_args_free(struct cgi_args_t *args) { struct cgi_args_t *tmp; while (args != NULL) { tmp = args->next; xfree(args->name); xfree(args->value); xfree(args); args = tmp; } } void interface_handle_request(CONNECTION * connection) { int i; char *ptr = NULL, *file; HEADER *header; FILEBUF *filebuf; struct cgi_args_t *args = NULL; if (!strncasecmp(&connection->header->file[(connection->header->type == HTTP_REQUEST) ? strlen(INTERFACEURL) + 1 : 0], "/template/", 9)) { template_send(templates, &connection->header->file[(connection->header->type == HTTP_REQUEST) ? strlen(INTERFACEURL) + 11 : 10], connection, 200); return; } if (!(connection->access & ACCESS_CONFIG)) { template_send(templates, "noaccess", connection, 403); return; } header = header_new(); header->type = HTTP_RESP; header->code = 200; header->version = HTTP_HTTP11; header->content_type = xstrdup("text/html"); if (connection->header->type == HTTP_REQUEST) { /* we wouldn't be here if connection->header->file wasn't this big */ file = connection->header->file + strlen(INTERFACEURL) + 1; if (*file != '/') { /* send redirect to correct relative links */ header->code = 302; header->content_length = 0; header->location = xmalloc(strlen(INTERFACEURL) + 2); sprintf(header->location, "%s/", INTERFACEURL); header_send(header, connection, CLIENT, HEADER_RESP); http_header_free(header); return; } } else file = connection->header->file; if (strcasecmp(connection->header->method, "POST")) { /* retrieve cgi arguments from GET request */ ptr = strchr(file, '?'); if (ptr != NULL) args = cgi_parse_request(&ptr[1]); } else if (connection->header->content_length != -1) { /* retrieve form data from POST request */ filebuf = http_transfer_filebuf(connection, CLIENT); filebuf_add(filebuf, "", 1); args = cgi_parse_request(filebuf->data); filebuf_free(filebuf); } filebuf = filebuf_new(); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "Middleman %s web interface\n", MMAN_VERSION); filebuf_addf(filebuf, "\n", INTERFACE_BG, INTERFACE_TEXT, INTERFACE_LINK, INTERFACE_VLINK); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n
\n"); filebuf_addf(filebuf, "
Middleman Web interface
\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "

\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Active connectionsConfigDNS cacheShow headers
Save settingsLoad settings
View log entries

\n"); for (i = 0; pages[i].file != NULL; i++) { if (!strncasecmp(file, pages[i].file, (ptr != NULL) ? ptr - file : ~0)) pages[i].handler(filebuf, args, connection); } filebuf_addf(filebuf, "
\n"); header->content_length = filebuf->size; header_send(header, connection, CLIENT, HEADER_RESP); if (strcasecmp(connection->header->method, "HEAD")) net_filebuf_send(filebuf, connection, CLIENT); if (args != NULL) cgi_args_free(args); http_header_free(header); filebuf_free(filebuf); } void interface_page_connections(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int i; filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); for (i = 0; i < MAXTHREADS; i++) { pthread_mutex_lock(&threads[i].lock); if (threads[i].flags != THREAD_UNUSED && threads[i].flags != THREAD_IDLE) filebuf_addf(filebuf, "\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"); pthread_mutex_unlock(&threads[i].lock); } filebuf_addf(filebuf, "
PIDIPRequestsMethodHostPortFile
%d%s%d%s%s%d%s
\n"); } void interface_page_dnscache(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int i; struct HASH_LIST *hash_list; filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); pthread_mutex_lock(&dns_cache_lock); for (i = 0; i < dns_cache->size; i++) { hash_list = dns_cache->hash_list[i]; for (; hash_list; hash_list = hash_list->next) filebuf_addf(filebuf, "\n", hash_list->ref, (char *) hash_list->data); } filebuf_addf(filebuf, "
HostnameIP address
%s%s
\n"); pthread_mutex_unlock(&dns_cache_lock); } void interface_page_headers(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { struct HTTP_HEADER_LIST *header_list; filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); for (header_list = connection->header->header; header_list; header_list = header_list->next) if (!bad_header(header_list->type, HEADER_DIRECT)) filebuf_addf(filebuf, "\n", header_list->type, header_list->value); filebuf_addf(filebuf, "
Unfiltered
TypeValue
%s%s
\n"); filebuf_addf(filebuf, "
\n"); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); for (header_list = connection->header->header_filtered; header_list; header_list = header_list->next) if (!bad_header(header_list->type, HEADER_DIRECT)) filebuf_addf(filebuf, "\n", header_list->type, header_list->value); filebuf_addf(filebuf, "
Filtered
TypeValue
%s%s
\n"); } void interface_page_save(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int ret; char *filename = NULL; for (; args; args = args->next) if (!strcasecmp(args->name, "filename")) filename = args->value; filebuf_addf(filebuf, "
\n"); if (filename == NULL) { filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n", (*configfile) ? configfile : ""); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Filename
\n"); filebuf_addf(filebuf, "
\n"); return; } ret = config_save(filename); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "
\n"); if (ret == TRUE) filebuf_addf(filebuf, "File saved\n"); else filebuf_addf(filebuf, "Saved failed\n"); filebuf_addf(filebuf, "
\n"); } void interface_page_load(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int ret, overwrite = FALSE; char *filename = NULL; for (; args; args = args->next) { if (!strcasecmp(args->name, "filename")) filename = args->value; else if (!strcasecmp(args->name, "overwrite")) { if (!strcasecmp(args->value, "yes")) overwrite = TRUE; else overwrite = FALSE; } } filebuf_addf(filebuf, "
\n"); if (filename == NULL) { filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n", (*configfile) ? configfile : ""); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Filename
OverwriteYes: No:
\n"); filebuf_addf(filebuf, "
\n"); return; } ret = config_load(overwrite, filename); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "
\n"); if (ret == TRUE) filebuf_addf(filebuf, "File loaded\n"); else filebuf_addf(filebuf, "Load failed\n"); filebuf_addf(filebuf, "
\n"); } void interface_page_log(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int size = -1, clear = FALSE; char *ptr, *pattern = NULL; struct LOGBUFFER_LIST *ll; struct cgi_args_t *a; regex_t *pe = NULL; for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "pattern")) pattern = a->value; if (!strcasecmp(a->name, "clear")) clear = TRUE; if (!strcasecmp(a->name, "size")) size = atoi(a->value); } if (clear == TRUE) logbuffer_clear(logbuffer); if (size != -1) logbuffer_resize(logbuffer, size); pthread_rwlock_rdlock(&logbuffer->lock); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
\n"); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n", (pattern != NULL) ? pattern : ""); filebuf_addf(filebuf, "\n", logbuffer->size); filebuf_addf(filebuf, ""); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Regular expression match
Log buffer size: Clear:

\n", INTERFACE_TABLEBG); pthread_rwlock_unlock(&logbuffer->lock); if (pattern != NULL && strcmp(pattern, "")) pe = reg_compile(pattern, REGFLAGS); pthread_rwlock_rdlock(&logbuffer->lock); for (ll = logbuffer->head; ll; ll = ll->next) { if (pe != NULL) if (reg_exec(pe, ll->msg)) continue; ptr = string_to_html(ll->msg, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (pe != NULL) reg_free(pe); filebuf_addf(filebuf, "
%s
\n"); pthread_rwlock_unlock(&logbuffer->lock); } void interface_page_config(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int i; char *section = NULL, *action = NULL, *dialog = NULL; struct cgi_args_t *a; for (a = args; a != NULL; a = a->next) { if (!strcasecmp(a->name, "section")) section = a->value; else if (!strcasecmp(a->name, "action")) action = a->value; else if (!strcasecmp(a->name, "dialog")) dialog = a->value; else if (!strcasecmp(a->name, "filter")) { pthread_rwlock_wrlock(&filter_list->lock); if (!strcasecmp(a->value, "off")) filter_list->enabled = FALSE; else filter_list->enabled = TRUE; pthread_rwlock_unlock(&filter_list->lock); } else if (!strcasecmp(a->name, "header")) { pthread_rwlock_wrlock(&header_list->lock); if (!strcasecmp(a->value, "off")) header_list->enabled = FALSE; else header_list->enabled = TRUE; pthread_rwlock_unlock(&header_list->lock); } else if (!strcasecmp(a->name, "mime")) { pthread_rwlock_wrlock(&mime_list->lock); if (!strcasecmp(a->value, "off")) mime_list->enabled = FALSE; else mime_list->enabled = TRUE; pthread_rwlock_unlock(&mime_list->lock); } else if (!strcasecmp(a->name, "cookie")) { pthread_rwlock_wrlock(&cookie_list->lock); if (!strcasecmp(a->value, "off")) cookie_list->enabled = FALSE; else cookie_list->enabled = TRUE; pthread_rwlock_unlock(&cookie_list->lock); } else if (!strcasecmp(a->name, "redirect")) { pthread_rwlock_wrlock(&redirect_list->lock); if (!strcasecmp(a->value, "off")) redirect_list->enabled = FALSE; else redirect_list->enabled = TRUE; pthread_rwlock_unlock(&redirect_list->lock); } else if (!strcasecmp(a->name, "rewrite")) { pthread_rwlock_wrlock(&rewrite_list->lock); if (!strcasecmp(a->value, "off")) rewrite_list->enabled = FALSE; else rewrite_list->enabled = TRUE; pthread_rwlock_unlock(&rewrite_list->lock); } else if (!strcasecmp(a->name, "keywords")) { pthread_rwlock_wrlock(&keyword_list->lock); if (!strcasecmp(a->value, "off")) keyword_list->enabled = FALSE; else keyword_list->enabled = TRUE; pthread_rwlock_unlock(&keyword_list->lock); } else if (!strcasecmp(a->name, "external")) { pthread_rwlock_wrlock(&external->lock); if (!strcasecmp(a->value, "off")) external->enabled = FALSE; else external->enabled = TRUE; pthread_rwlock_unlock(&external->lock); } else if (!strcasecmp(a->name, "forward")) { pthread_rwlock_wrlock(&forward_list->lock); if (!strcasecmp(a->value, "off")) forward_list->enabled = FALSE; else forward_list->enabled = TRUE; pthread_rwlock_unlock(&forward_list->lock); } } filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "
\n"); filebuf_addf(filebuf, "

\n"); if (dialog != NULL) { for (i = 0; dialog_pages[i].file; i++) { if (!strcasecmp(section, dialog_pages[i].file)) dialog_pages[i].handler(filebuf, args, connection); } } else if (section != NULL && strcmp(section, "")) { if (action != NULL) { for (i = 0; action_pages[i].file; i++) { if (!strcasecmp(section, action_pages[i].file)) action_pages[i].handler(filebuf, args, connection); } } for (i = 0; config_pages[i].file; i++) { if (!strcasecmp(section, config_pages[i].file)) config_pages[i].handler(filebuf, args, connection); } } else { filebuf_addf(filebuf, "
\n"); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); pthread_rwlock_rdlock(&filter_list->lock); filebuf_addf(filebuf, "\n", (filter_list->enabled == TRUE) ? "checked" : "", (filter_list->enabled == FALSE) ? "checked" : ""); pthread_rwlock_unlock(&filter_list->lock); pthread_rwlock_rdlock(&header_list->lock); filebuf_addf(filebuf, "\n", (header_list->enabled == TRUE) ? "checked" : "", (header_list->enabled == FALSE) ? "checked" : ""); pthread_rwlock_unlock(&header_list->lock); pthread_rwlock_rdlock(&mime_list->lock); filebuf_addf(filebuf, "\n", (mime_list->enabled == TRUE) ? "checked" : "", (mime_list->enabled == FALSE) ? "checked" : ""); pthread_rwlock_unlock(&mime_list->lock); pthread_rwlock_rdlock(&cookie_list->lock); filebuf_addf(filebuf, "\n", (cookie_list->enabled == TRUE) ? "checked" : "", (cookie_list->enabled == FALSE) ? "checked" : ""); pthread_rwlock_unlock(&cookie_list->lock); pthread_rwlock_rdlock(&redirect_list->lock); filebuf_addf(filebuf, "\n", (redirect_list->enabled == TRUE) ? "checked" : "", (redirect_list->enabled == FALSE) ? "checked" : ""); pthread_rwlock_unlock(&redirect_list->lock); pthread_rwlock_rdlock(&forward_list->lock); filebuf_addf(filebuf, "\n", (forward_list->enabled == TRUE) ? "checked" : "", (forward_list->enabled == FALSE) ? "checked" : ""); pthread_rwlock_unlock(&forward_list->lock); pthread_rwlock_rdlock(&rewrite_list->lock); filebuf_addf(filebuf, "\n", (rewrite_list->enabled == TRUE) ? "checked" : "", (rewrite_list->enabled == FALSE) ? "checked" : ""); pthread_rwlock_unlock(&rewrite_list->lock); pthread_rwlock_rdlock(&keyword_list->lock); filebuf_addf(filebuf, "\n", (keyword_list->enabled == TRUE) ? "checked" : "", (keyword_list->enabled == FALSE) ? "checked" : ""); pthread_rwlock_unlock(&keyword_list->lock); pthread_rwlock_rdlock(&external->lock); filebuf_addf(filebuf, "\n", (external->enabled == TRUE) ? "checked" : "", (external->enabled == FALSE) ? "checked" : ""); pthread_rwlock_unlock(&external->lock); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
FeatureEnabledDisabled
URL filtering
Header filtering
MIME filtering
Cookie filtering
URL redirecting
Forwarding
Document rewriting
Keyword filtering
External parsers
\n"); } filebuf_addf(filebuf, "
\n"); } void interface_page_config_filter(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int i; char *ptr; struct FILTER_LIST_LIST *fl = NULL; if (filter_list == NULL) return; pthread_rwlock_rdlock(&filter_list->lock); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); for (i = 0; i < 2; i++) { filebuf_addf(filebuf, "\n"); if (fl != NULL) filebuf_addf(filebuf, "\n"); for (; fl; fl = fl->next) { filebuf_addf(filebuf, "\n"); } } filebuf_addf(filebuf, "
\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "", (filter_list->policy == POLICY_ALLOW) ? "selected" : "", (filter_list->policy == POLICY_DENY) ? "selected" : ""); filebuf_addf(filebuf, "\n", (filter_list->dtemplate != NULL) ? filter_list->dtemplate : ""); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Policy
Default template
Add

\n", INTERFACE_TABLEBG); switch (i) { case 0: fl = filter_list->allow; if (fl != NULL) filebuf_addf(filebuf, "\n"); break; case 1: fl = filter_list->deny; if (fl != NULL) filebuf_addf(filebuf, "\n"); break; } filebuf_addf(filebuf, "
ALLOW
DENY

\n"); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n", (fl->enabled == TRUE) ? "yes" : "no"); if (fl->comment != NULL) { ptr = string_to_html(fl->comment, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (fl->host != NULL) { ptr = string_to_html(fl->host, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (fl->file != NULL) { ptr = string_to_html(fl->file, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (fl->template != NULL) filebuf_addf(filebuf, "\n", fl->template); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled%s
Comment%s
Host%s
File%s
Template%s
\n"); filebuf_addf(filebuf, "\n", (i == 0) ? "allow" : "deny", fl->id, (i == 0) ? "allow" : "deny", fl->id); filebuf_addf(filebuf, "\n", (i == 0) ? "allow" : "deny", fl->id, (i == 0) ? "allow" : "deny", fl->id); filebuf_addf(filebuf, "\n", (i == 0) ? "allow" : "deny", fl->id, (i == 0) ? "allow" : "deny", fl->id); filebuf_addf(filebuf, "
Edit DeleteUp DownTop Bottom

\n"); pthread_rwlock_unlock(&filter_list->lock); } void interface_page_config_filter_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *list = NULL, *ptr = NULL; struct FILTER_LIST_LIST *fl = NULL; struct cgi_args_t *a = args; if (filter_list == NULL) return; pthread_rwlock_rdlock(&filter_list->lock); for (; a; a = a->next) { if (!strcasecmp(a->name, "id")) id = atoi(a->value); if (!strcasecmp(a->name, "list")) list = a->value; } if (id != -1 && list != NULL) { if (!strcasecmp(list, "allow")) for (fl = filter_list->allow; fl && fl->id != id; fl = fl->next); else if (!strcasecmp(list, "deny")) for (fl = filter_list->deny; fl && fl->id != id; fl = fl->next); } filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (list != NULL) filebuf_addf(filebuf, "\n", list); if (id != -1) { filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n", id); } else filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (fl != NULL && fl->comment != NULL) ptr = string_to_html(fl->comment, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (fl != NULL && fl->host != NULL) ptr = string_to_html(fl->host, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (fl != NULL && fl->file != NULL) ptr = string_to_html(fl->file, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (fl != NULL && fl->template != NULL) ptr = string_to_html(fl->template, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled"); filebuf_addf(filebuf, "Yes: ", (fl == NULL || fl->enabled == TRUE) ? "checked" : ""); filebuf_addf(filebuf, "No: ", (fl != NULL && fl->enabled == FALSE) ? "checked" : ""); filebuf_addf(filebuf, "
Action
Comment
Host
File
Template

\n"); pthread_rwlock_unlock(&filter_list->lock); } void interface_page_config_filter_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *list = NULL, *action = NULL; struct FILTER_LIST_LIST *fl = NULL; struct cgi_args_t *a; if (filter_list == NULL) return; pthread_rwlock_wrlock(&filter_list->lock); for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "action")) action = a->value; if (!strcasecmp(a->name, "id")) id = atoi(a->value); if (!strcasecmp(a->name, "list")) list = a->value; } if (action != NULL && !strcasecmp(action, "global")) { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "policy")) { if (!strcasecmp(a->value, "allow")) filter_list->policy = POLICY_ALLOW; else if (!strcasecmp(a->value, "deny")) filter_list->policy = POLICY_DENY; } else if (!strcasecmp(a->name, "dtemplate")) { FREE_AND_NULL(filter_list->dtemplate); if (strcmp(a->name, "")) filter_list->dtemplate = xstrdup(a->value); } } } if (action == NULL || list == NULL) goto finish; if (!strcasecmp(action, "delete")) { if (!strcasecmp(list, "allow")) fl = filter_list->allow; else if (!strcasecmp(list, "deny")) fl = filter_list->deny; for (; fl; fl = fl->next) { if (fl->id == id) { if (!strcasecmp(list, "allow")) filter_list->allow = filter_ll_delete(fl); else if (!strcasecmp(list, "deny")) filter_list->deny = filter_ll_delete(fl); break; } } } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) { if (!strcasecmp(action, "add")) { if (!strcasecmp(list, "allow")) { fl = filter_ll_new(filter_list->allow); if (filter_list->allow == NULL) filter_list->allow = fl; } else if (!strcasecmp(list, "deny")) { fl = filter_ll_new(filter_list->deny); if (filter_list->deny == NULL) filter_list->deny = fl; } else goto finish; fl->id = filter_list->id++; } else { if (!strcasecmp(list, "allow")) { for (fl = filter_list->allow; fl; fl = fl->next) if (fl->id == id) break; } else if (!strcasecmp(list, "deny")) { for (fl = filter_list->deny; fl; fl = fl->next) if (fl->id == id) break; } if (fl == NULL) goto finish; } if (strcasecmp(action, "shift")) { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "enabled")) { if (!strcasecmp(a->value, "no")) fl->enabled = FALSE; else fl->enabled = TRUE; } else if (!strcasecmp(a->name, "comment")) filter_ll_insert(fl, a->value, NULL, NULL, NULL); else if (!strcasecmp(a->name, "host")) filter_ll_insert(fl, NULL, a->value, NULL, NULL); else if (!strcasecmp(a->name, "file")) filter_ll_insert(fl, NULL, NULL, a->value, NULL); else if (!strcasecmp(a->name, "template")) filter_ll_insert(fl, NULL, NULL, NULL, a->value); else if (!strcasecmp(a->name, "move")) { if (!strcasecmp(a->value, "allow") && strcasecmp(list, a->value)) { MOVENODE(struct FILTER_LIST_LIST *, fl, filter_list->deny, filter_list->allow); } else if (!strcasecmp(a->value, "deny") && strcasecmp(list, a->value)) { MOVENODE(struct FILTER_LIST_LIST *, fl, filter_list->allow, filter_list->deny); } } } } else { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "direction")) { if (!strcasecmp(a->value, "up")) { SHIFTNODE(struct FILTER_LIST_LIST *, (!strcasecmp(list, "allow")) ? filter_list->allow : filter_list->deny, fl, UP); } else if (!strcasecmp(a->value, "down")) { SHIFTNODE(struct FILTER_LIST_LIST *, (!strcasecmp(list, "allow")) ? filter_list->allow : filter_list->deny, fl, DOWN); } else if (!strcasecmp(a->value, "top")) { SETNODE(struct FILTER_LIST_LIST *, (!strcasecmp(list, "allow")) ? filter_list->allow : filter_list->deny, fl, TOP); } else if (!strcasecmp(a->value, "bottom")) { SETNODE(struct FILTER_LIST_LIST *, (!strcasecmp(list, "allow")) ? filter_list->allow : filter_list->deny, fl, BOTTOM); } } } } } finish: pthread_rwlock_unlock(&filter_list->lock); } void interface_page_config_header(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connectin) { int i; char *ptr; struct HEADER_LIST_LIST *hl = NULL; if (header_list == NULL) return; pthread_rwlock_rdlock(&header_list->lock); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); for (i = 0; i < 3; i++) { filebuf_addf(filebuf, "\n"); if (hl != NULL) filebuf_addf(filebuf, "\n"); for (; hl; hl = hl->next) { filebuf_addf(filebuf, "\n"); } } filebuf_addf(filebuf, "
\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "", (header_list->policy == POLICY_ALLOW) ? "selected" : "", (header_list->policy == POLICY_DENY) ? "selected" : ""); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Policy
Add

\n", INTERFACE_TABLEBG); switch (i) { case 0: hl = header_list->allow; if (hl != NULL) filebuf_addf(filebuf, "\n"); break; case 1: hl = header_list->deny; if (hl != NULL) filebuf_addf(filebuf, "\n"); break; case 2: hl = header_list->insert; if (hl != NULL) filebuf_addf(filebuf, "\n"); } filebuf_addf(filebuf, "
ALLOW
DENY
INSERT

\n"); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n", (hl->enabled == TRUE) ? "yes" : "no"); if (hl->comment != NULL) { ptr = string_to_html(hl->comment, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (hl->host != NULL) { ptr = string_to_html(hl->host, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (hl->type != NULL) { ptr = string_to_html(hl->type, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (hl->value != NULL) { ptr = string_to_html(hl->value, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled%s
Comment%s
Host%s
Type%s
Value%s
\n"); filebuf_addf(filebuf, "\n", (i == 0) ? "allow" : (i == 1) ? "deny" : "insert", hl->id, (i == 0) ? "allow" : (i == 1) ? "deny" : "insert", hl->id); filebuf_addf(filebuf, "\n", (i == 0) ? "allow" : (i == 1) ? "deny" : "insert", hl->id, (i == 0) ? "allow" : (i == 1) ? "deny" : "insert", hl->id); filebuf_addf(filebuf, "\n", (i == 0) ? "allow" : (i == 1) ? "deny" : "insert", hl->id, (i == 0) ? "allow" : (i == 1) ? "deny" : "insert", hl->id); filebuf_addf(filebuf, "
Edit DeleteUp DownTop Bottom

\n"); pthread_rwlock_unlock(&header_list->lock); } void interface_page_config_header_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *list = NULL, *ptr = NULL; struct HEADER_LIST_LIST *hl = NULL; struct cgi_args_t *a = args; if (header_list == NULL) return; pthread_rwlock_rdlock(&header_list->lock); for (; a; a = a->next) { if (!strcasecmp(a->name, "id")) id = atoi(a->value); if (!strcasecmp(a->name, "list")) list = a->value; } if (id != -1 && list != NULL) { if (!strcasecmp(list, "allow")) for (hl = header_list->allow; hl && hl->id != id; hl = hl->next); else if (!strcasecmp(list, "deny")) for (hl = header_list->deny; hl && hl->id != id; hl = hl->next); else if (!strcasecmp(list, "insert")) for (hl = header_list->insert; hl && hl->id != id; hl = hl->next); } filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (list != NULL) filebuf_addf(filebuf, "\n", list); if (id != -1) { filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n", id); } else filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (hl != NULL && hl->comment != NULL) ptr = string_to_html(hl->comment, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (hl != NULL && hl->host != NULL) ptr = string_to_html(hl->host, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (hl != NULL && hl->type != NULL) ptr = string_to_html(hl->type, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (hl != NULL && hl->value != NULL) ptr = string_to_html(hl->value, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled"); filebuf_addf(filebuf, "Yes: ", (hl == NULL || hl->enabled == TRUE) ? "checked" : ""); filebuf_addf(filebuf, "No: ", (hl != NULL && hl->enabled == FALSE) ? "checked" : ""); filebuf_addf(filebuf, "
Action
Comment
Host
Type
Value

\n"); pthread_rwlock_unlock(&header_list->lock); } void interface_page_config_header_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *list = NULL, *action = NULL; struct HEADER_LIST_LIST *hl = NULL; struct cgi_args_t *a; if (header_list == NULL) return; pthread_rwlock_wrlock(&header_list->lock); for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "action")) action = a->value; if (!strcasecmp(a->name, "id")) id = atoi(a->value); if (!strcasecmp(a->name, "list")) list = a->value; } if (action != NULL && !strcasecmp(action, "global")) { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "policy")) { if (!strcasecmp(a->value, "allow")) header_list->policy = POLICY_ALLOW; else if (!strcasecmp(a->value, "deny")) header_list->policy = POLICY_DENY; } } } if (action == NULL || list == NULL) goto finish; if (!strcasecmp(action, "delete")) { if (!strcasecmp(list, "allow")) hl = header_list->allow; else if (!strcasecmp(list, "deny")) hl = header_list->deny; else if (!strcasecmp(list, "insert")) hl = header_list->insert; for (; hl; hl = hl->next) { if (hl->id == id) { if (!strcasecmp(list, "allow")) header_list->allow = header_ll_delete(hl); else if (!strcasecmp(list, "deny")) header_list->deny = header_ll_delete(hl); else if (!strcasecmp(list, "insert")) header_list->insert = header_ll_delete(hl); break; } } } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) { if (!strcasecmp(action, "add")) { if (!strcasecmp(list, "allow")) { hl = header_ll_new(header_list->allow); if (header_list->allow == NULL) header_list->allow = hl; } else if (!strcasecmp(list, "deny")) { hl = header_ll_new(header_list->deny); if (header_list->deny == NULL) header_list->deny = hl; } else if (!strcasecmp(list, "insert")) { hl = header_ll_new(header_list->insert); if (header_list->insert == NULL) header_list->insert = hl; } else goto finish; hl->id = header_list->id++; } else { if (!strcasecmp(list, "allow")) { for (hl = header_list->allow; hl; hl = hl->next) if (hl->id == id) break; } else if (!strcasecmp(list, "deny")) { for (hl = header_list->deny; hl; hl = hl->next) if (hl->id == id) break; } else if (!strcasecmp(list, "insert")) { for (hl = header_list->insert; hl; hl = hl->next) if (hl->id == id) break; } if (hl == NULL) goto finish; } if (strcasecmp(action, "shift")) { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "enabled")) { if (!strcasecmp(a->value, "no")) hl->enabled = FALSE; else hl->enabled = TRUE; } else if (!strcasecmp(a->name, "comment")) header_ll_insert(hl, a->value, NULL, NULL, NULL); else if (!strcasecmp(a->name, "type")) header_ll_insert(hl, NULL, a->value, NULL, NULL); else if (!strcasecmp(a->name, "value")) header_ll_insert(hl, NULL, NULL, a->value, NULL); else if (!strcasecmp(a->name, "host")) header_ll_insert(hl, NULL, NULL, NULL, a->value); else if (!strcasecmp(a->name, "move")) { if (!strcasecmp(a->value, "allow") && strcasecmp(list, a->value)) { if (!strcasecmp(list, "deny")) { MOVENODE(struct HEADER_LIST_LIST *, hl, header_list->deny, header_list->allow); } else if (!strcasecmp(list, "insert")) { MOVENODE(struct HEADER_LIST_LIST *, hl, header_list->insert, header_list->allow); } } else if (!strcasecmp(a->value, "deny") && strcasecmp(list, a->value)) { if (!strcasecmp(list, "allow")) { MOVENODE(struct HEADER_LIST_LIST *, hl, header_list->allow, header_list->deny); } else if (!strcasecmp(list, "insert")) { MOVENODE(struct HEADER_LIST_LIST *, hl, header_list->insert, header_list->deny); } } else if (!strcasecmp(a->value, "insert") && strcasecmp(list, a->value)) { if (!strcasecmp(list, "allow")) { MOVENODE(struct HEADER_LIST_LIST *, hl, header_list->allow, header_list->insert); } else if (!strcasecmp(list, "deny")) { MOVENODE(struct HEADER_LIST_LIST *, hl, header_list->deny, header_list->insert); } } } } } else { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "direction")) { if (!strcasecmp(a->value, "up")) { SHIFTNODE(struct HEADER_LIST_LIST *, (!strcasecmp(list, "allow")) ? header_list->allow : (!strcasecmp(list, "deny")) ? header_list->deny : header_list->insert, hl, UP); } else if (!strcasecmp(a->value, "down")) { SHIFTNODE(struct HEADER_LIST_LIST *, (!strcasecmp(list, "allow")) ? header_list->allow : (!strcasecmp(list, "deny")) ? header_list->deny : header_list->insert, hl, DOWN); } else if (!strcasecmp(a->value, "top")) { SETNODE(struct HEADER_LIST_LIST *, (!strcasecmp(list, "allow")) ? header_list->allow : (!strcasecmp(list, "deny")) ? header_list->deny : header_list->insert, hl, TOP); } else if (!strcasecmp(a->value, "bottom")) { SETNODE(struct HEADER_LIST_LIST *, (!strcasecmp(list, "allow")) ? header_list->allow : (!strcasecmp(list, "deny")) ? header_list->deny : header_list->insert, hl, BOTTOM); } } } } } finish: pthread_rwlock_unlock(&header_list->lock); } void interface_page_config_access(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int i; char *ptr; struct ACCESS_LIST_LIST *al = NULL; if (access_list == NULL) return; pthread_rwlock_rdlock(&access_list->lock); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); for (i = 0; i < 2; i++) { filebuf_addf(filebuf, "\n"); if (al != NULL) filebuf_addf(filebuf, "\n"); for (; al; al = al->next) { filebuf_addf(filebuf, "\n"); } } filebuf_addf(filebuf, "
\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "", (access_list->policy == POLICY_ALLOW) ? "selected" : "", (access_list->policy == POLICY_DENY) ? "selected" : ""); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Policy
Add

\n", INTERFACE_TABLEBG); switch (i) { case 0: al = access_list->allow; if (al != NULL) filebuf_addf(filebuf, "\n"); break; case 1: al = access_list->deny; if (al != NULL) filebuf_addf(filebuf, "\n"); break; } filebuf_addf(filebuf, "
ALLOW
DENY

\n"); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n", (al->enabled == TRUE) ? "yes" : "no"); if (al->comment != NULL) { ptr = string_to_html(al->comment, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (al->ip != NULL) { ptr = string_to_html(al->ip, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (al->username != NULL) { ptr = string_to_html(al->username, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (al->password != NULL) { ptr = string_to_html(al->password, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (al->bypass != 0) filebuf_addf(filebuf, "\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" : ""); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled%s
Comment%s
IP address%s
Username%s
Password%s
Bypass%s,%s,%s,%s,%s,%s,%s,%s,%s
Access%s,%s,%s,%s,%s,%s\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" : ""); filebuf_addf(filebuf, "
\n"); filebuf_addf(filebuf, "\n", (i == 0) ? "allow" : "deny", al->id, (i == 0) ? "allow" : "deny", al->id); filebuf_addf(filebuf, "\n", (i == 0) ? "allow" : "deny", al->id, (i == 0) ? "allow" : "deny", al->id); filebuf_addf(filebuf, "\n", (i == 0) ? "allow" : "deny", al->id, (i == 0) ? "allow" : "deny", al->id); filebuf_addf(filebuf, "
Edit DeleteUp DownTop Bottom

\n"); pthread_rwlock_unlock(&access_list->lock); } void interface_page_config_access_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *list = NULL, *ptr = NULL; struct ACCESS_LIST_LIST *al = NULL; struct cgi_args_t *a = args; if (access_list == NULL) return; pthread_rwlock_rdlock(&access_list->lock); for (; a; a = a->next) { if (!strcasecmp(a->name, "id")) id = atoi(a->value); if (!strcasecmp(a->name, "list")) list = a->value; } if (id != -1 && list != NULL) { if (!strcasecmp(list, "allow")) for (al = access_list->allow; al && al->id != id; al = al->next); else if (!strcasecmp(list, "deny")) for (al = access_list->deny; al && al->id != id; al = al->next); } filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (list != NULL) filebuf_addf(filebuf, "\n", list); if (id != -1) { filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n", id); } else filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (al != NULL && al->comment != NULL) ptr = string_to_html(al->comment, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (al != NULL && al->ip != NULL) ptr = string_to_html(al->ip, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (al != NULL && al->username != NULL) ptr = string_to_html(al->username, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (al != NULL && al->password!= NULL) ptr = string_to_html(al->password, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled"); filebuf_addf(filebuf, "Yes: ", (al == NULL || al->enabled == TRUE) ? "checked" : ""); filebuf_addf(filebuf, "No: ", (al != NULL && al->enabled == FALSE) ? "checked" : ""); filebuf_addf(filebuf, "
Action
Comment
IP Address
Username
Password
Access"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "", (al != NULL && (al->access & ACCESS_CONFIG)) ? "checked" : ""); filebuf_addf(filebuf, "", (al != NULL && (al->access & ACCESS_PROXY)) ? "checked" : ""); filebuf_addf(filebuf, "", (al != NULL && (al->access & ACCESS_CONNECT)) ? "checked" : ""); filebuf_addf(filebuf, "", (al != NULL && (al->access & ACCESS_HTTP)) ? "checked" : ""); filebuf_addf(filebuf, "", (al != NULL && (al->access & ACCESS_TRANSPARENT)) ? "checked" : ""); filebuf_addf(filebuf, "", (al != NULL && (al->access & ACCESS_BYPASS)) ? "checked" : ""); filebuf_addf(filebuf, "
Web interface:
Proxy requests:
CONNECT requests:
HTTP requests:
Transparent proxying:
Allow bypassing:
Bypass"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "", (al != NULL && (al->bypass & FEATURE_FILTER)) ? "checked" : ""); filebuf_addf(filebuf, "", (al != NULL && (al->bypass & FEATURE_HEADER)) ? "checked" : ""); filebuf_addf(filebuf, "", (al != NULL && (al->bypass & FEATURE_MIME)) ? "checked" : ""); filebuf_addf(filebuf, "", (al != NULL && (al->bypass & FEATURE_REDIRECT)) ? "checked" : ""); filebuf_addf(filebuf, "", (al != NULL && (al->bypass & FEATURE_COOKIES)) ? "checked" : ""); filebuf_addf(filebuf, "", (al != NULL && (al->bypass & FEATURE_REWRITE)) ? "checked" : ""); filebuf_addf(filebuf, "", (al != NULL && (al->bypass & FEATURE_EXTERNAL)) ? "checked" : ""); filebuf_addf(filebuf, "", (al != NULL && (al->bypass & FEATURE_FORWARD)) ? "checked" : ""); filebuf_addf(filebuf, "", (al != NULL && (al->bypass & FEATURE_KEYWORDS)) ? "checked" : ""); filebuf_addf(filebuf, "
URL filtering:
Header filtering:
MIME filtering:
URL redirecting:
Cookie filtering:
Document rewriting:
External parsers:
Forwarding:
Keyword filtering:

\n"); pthread_rwlock_unlock(&access_list->lock); } void interface_page_config_access_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *list = NULL, *action = NULL; struct ACCESS_LIST_LIST *al = NULL; struct cgi_args_t *a; if (access_list == NULL) return; pthread_rwlock_wrlock(&access_list->lock); for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "action")) action = a->value; if (!strcasecmp(a->name, "id")) id = atoi(a->value); if (!strcasecmp(a->name, "list")) list = a->value; } if (action != NULL && !strcasecmp(action, "global")) { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "policy")) { if (!strcasecmp(a->value, "allow")) access_list->policy = POLICY_ALLOW; else if (!strcasecmp(a->value, "deny")) access_list->policy = POLICY_DENY; } } } if (action == NULL || list == NULL) goto finish; if (!strcasecmp(action, "delete")) { if (!strcasecmp(list, "allow")) al = access_list->allow; else if (!strcasecmp(list, "deny")) al = access_list->deny; for (; al; al = al->next) { if (al->id == id) { if (!strcasecmp(list, "allow")) access_list->allow = access_ll_delete(al); else if (!strcasecmp(list, "deny")) access_list->deny = access_ll_delete(al); break; } } } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) { if (!strcasecmp(action, "add")) { if (!strcasecmp(list, "allow")) { al = access_ll_new(access_list->allow); if (access_list->allow == NULL) access_list->allow = al; } else if (!strcasecmp(list, "deny")) { al = access_ll_new(access_list->deny); if (access_list->deny == NULL) access_list->deny = al; } else goto finish; al->id = access_list->id++; } else { if (!strcasecmp(list, "allow")) { for (al = access_list->allow; al; al = al->next) if (al->id == id) break; } else if (!strcasecmp(list, "deny")) { for (al = access_list->deny; al; al = al->next) if (al->id == id) break; } if (al == NULL) goto finish; } if (strcasecmp(action, "shift")) { al->access = al->bypass = 0; for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "enabled")) { if (!strcasecmp(a->value, "no")) al->enabled = FALSE; else al->enabled = TRUE; } else if (!strcasecmp(a->name, "comment")) access_ll_insert(al, a->value, NULL, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "ip")) access_ll_insert(al, NULL, a->value, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "username")) access_ll_insert(al, NULL, NULL, NULL, NULL, a->value, NULL); else if (!strcasecmp(a->name, "password")) access_ll_insert(al, NULL, NULL, NULL, NULL, NULL, a->value); else if (!strcasecmp(a->name, "access_config")) al->access |= ACCESS_CONFIG; else if (!strcasecmp(a->name, "access_proxy")) al->access |= ACCESS_PROXY; else if (!strcasecmp(a->name, "access_connect")) al->access |= ACCESS_CONNECT; else if (!strcasecmp(a->name, "access_http")) al->access |= ACCESS_HTTP; else if (!strcasecmp(a->name, "access_transparent")) al->access |= ACCESS_TRANSPARENT; else if (!strcasecmp(a->name, "access_bypass")) al->access |= ACCESS_BYPASS; else if (!strcasecmp(a->name, "bfilter")) al->bypass |= FEATURE_FILTER; else if (!strcasecmp(a->name, "bheader")) al->bypass |= FEATURE_HEADER; else if (!strcasecmp(a->name, "bmime")) al->bypass |= FEATURE_MIME; else if (!strcasecmp(a->name, "bredirect")) al->bypass |= FEATURE_REDIRECT; else if (!strcasecmp(a->name, "bcookies")) al->bypass |= FEATURE_COOKIES; else if (!strcasecmp(a->name, "brewrite")) al->bypass |= FEATURE_REWRITE; else if (!strcasecmp(a->name, "bexternal")) al->bypass |= FEATURE_EXTERNAL; else if (!strcasecmp(a->name, "bforward")) al->bypass |= FEATURE_FORWARD; else if (!strcasecmp(a->name, "bkeywords")) al->bypass |= FEATURE_KEYWORDS; else if (!strcasecmp(a->name, "move")) { if (!strcasecmp(a->value, "allow") && strcasecmp(list, a->value)) { MOVENODE(struct ACCESS_LIST_LIST *, al, access_list->deny, access_list->allow); } else if (!strcasecmp(a->value, "deny") && strcasecmp(list, a->value)) { MOVENODE(struct ACCESS_LIST_LIST *, al, access_list->allow, access_list->deny); } } } } else { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "direction")) { if (!strcasecmp(a->value, "up")) { SHIFTNODE(struct ACCESS_LIST_LIST *, (!strcasecmp(list, "allow")) ? access_list->allow : access_list->deny, al, UP); } else if (!strcasecmp(a->value, "down")) { SHIFTNODE(struct ACCESS_LIST_LIST *, (!strcasecmp(list, "allow")) ? access_list->allow : access_list->deny, al, DOWN); } else if (!strcasecmp(a->value, "top")) { SETNODE(struct ACCESS_LIST_LIST *, (!strcasecmp(list, "allow")) ? access_list->allow : access_list->deny, al, TOP); } else if (!strcasecmp(a->value, "bottom")) { SETNODE(struct ACCESS_LIST_LIST *, (!strcasecmp(list, "allow")) ? access_list->allow : access_list->deny, al, BOTTOM); } } } } } finish: pthread_rwlock_unlock(&access_list->lock); } void interface_page_config_rewrite(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { char *ptr; struct REWRITE_LIST_LIST *rl = NULL; if (rewrite_list == NULL) return; pthread_rwlock_rdlock(&rewrite_list->lock); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); for (rl = rewrite_list->rewrite; rl; rl = rl->next) { filebuf_addf(filebuf, "\n"); } filebuf_addf(filebuf, "
\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Add

\n"); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n", (rl->enabled == TRUE) ? "yes" : "no"); if (rl->comment != NULL) { ptr = string_to_html(rl->comment, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (rl->host != NULL) { ptr = string_to_html(rl->host, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (rl->file != NULL) { ptr = string_to_html(rl->file, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (rl->mime != NULL) { ptr = string_to_html(rl->mime, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (rl->pattern != NULL) { ptr = string_to_html(rl->pattern, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (rl->replace != NULL) { ptr = string_to_html(rl->replace, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (rl->which != 0) filebuf_addf(filebuf, "\n", (rl->which & REWRITE_SERVER) ? "server header" : "", (rl->which & REWRITE_CLIENT) ? "client header" : "", (rl->which & REWRITE_BODY) ? "body" : "", (rl->which & REWRITE_POST) ? "post" : ""); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled%s
Comment%s
Host%s
File%s
Mimetype%s
Pattern%s
Replacement%s
Applies to%s,%s,%s,%s
\n"); filebuf_addf(filebuf, "\n", rl->id, rl->id); filebuf_addf(filebuf, "\n", rl->id, rl->id); filebuf_addf(filebuf, "\n", rl->id, rl->id); filebuf_addf(filebuf, "
Edit DeleteUp DownTop Bottom

\n"); pthread_rwlock_unlock(&rewrite_list->lock); } void interface_page_config_rewrite_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *ptr = NULL; struct REWRITE_LIST_LIST *rl = NULL; struct cgi_args_t *a = args; if (rewrite_list == NULL) return; pthread_rwlock_rdlock(&rewrite_list->lock); for (; a; a = a->next) { if (!strcasecmp(a->name, "id")) id = atoi(a->value); } if (id != -1) for (rl = rewrite_list->rewrite; rl && rl->id != id; rl = rl->next); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (id != -1) { filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n", id); } else filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (rl != NULL && rl->comment != NULL) ptr = string_to_html(rl->comment, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (rl != NULL && rl->host != NULL) ptr = string_to_html(rl->host, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (rl != NULL && rl->file != NULL) ptr = string_to_html(rl->file, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (rl != NULL && rl->mime != NULL) ptr = string_to_html(rl->mime, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (rl != NULL && rl->pattern != NULL) ptr = string_to_html(rl->pattern, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (rl != NULL && rl->replace != NULL) ptr = string_to_html(rl->replace, FALSE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled"); filebuf_addf(filebuf, "Yes: ", (rl == NULL || rl->enabled == TRUE) ? "checked" : ""); filebuf_addf(filebuf, "No: ", (rl != NULL && rl->enabled == FALSE) ? "checked" : ""); filebuf_addf(filebuf, "
Comment
Host
File
Mimetype
Pattern
Replace
Applies to"); filebuf_addf(filebuf, "Server header: ", (rl != NULL && rl->which & REWRITE_SERVER) ? "checked" : ""); filebuf_addf(filebuf, "Client header: ", (rl != NULL && rl->which & REWRITE_CLIENT) ? "checked" : ""); filebuf_addf(filebuf, "Body : ", (rl == NULL || rl->which & REWRITE_BODY) ? "checked" : ""); filebuf_addf(filebuf, "POST data : ", (rl != NULL && rl->which & REWRITE_POST) ? "checked" : ""); filebuf_addf(filebuf, "

\n"); pthread_rwlock_unlock(&rewrite_list->lock); } void interface_page_config_rewrite_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *action = NULL; struct REWRITE_LIST_LIST *rl = NULL; struct cgi_args_t *a; if (rewrite_list == NULL) return; pthread_rwlock_wrlock(&rewrite_list->lock); for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "action")) action = a->value; if (!strcasecmp(a->name, "id")) id = atoi(a->value); } if (action == NULL) goto finish; if (!strcasecmp(action, "delete")) { for (rl = rewrite_list->rewrite; rl; rl = rl->next) { if (rl->id == id) { rewrite_list->rewrite = rewrite_list_delete(rl); break; } } } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) { if (!strcasecmp(action, "add")) { rl = rewrite_list_new(rewrite_list->rewrite); if (rewrite_list->rewrite == NULL) rewrite_list->rewrite = rl; rl->id = rewrite_list->id++; } else { for (rl = rewrite_list->rewrite; rl; rl = rl->next) if (rl->id == id) break; if (rl == NULL) goto finish; } if (strcasecmp(action, "shift")) { rl->which = 0; for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "enabled")) { if (!strcasecmp(a->value, "no")) rl->enabled = FALSE; else rl->enabled = TRUE; } else if (!strcasecmp(a->name, "comment")) rewrite_list_insert(rl, a->value, NULL, NULL, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "pattern")) rewrite_list_insert(rl, NULL, a->value, NULL, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "replace")) rewrite_list_insert(rl, NULL, NULL, a->value, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "host")) rewrite_list_insert(rl, NULL, NULL, NULL, NULL, a->value, NULL, NULL); else if (!strcasecmp(a->name, "file")) rewrite_list_insert(rl, NULL, NULL, NULL, NULL, NULL, a->value, NULL); else if (!strcasecmp(a->name, "mime")) rewrite_list_insert(rl, NULL, NULL, NULL, NULL, NULL, NULL, a->value); else if (!strcasecmp(a->name, "server")) rl->which |= REWRITE_SERVER; else if (!strcasecmp(a->name, "client")) rl->which |= REWRITE_CLIENT; else if (!strcasecmp(a->name, "body")) rl->which |= REWRITE_BODY; else if (!strcasecmp(a->name, "post")) rl->which |= REWRITE_POST; } } else { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "direction")) { if (!strcasecmp(a->value, "up")) { SHIFTNODE(struct REWRITE_LIST_LIST *, rewrite_list->rewrite, rl, UP); } else if (!strcasecmp(a->value, "down")) { SHIFTNODE(struct REWRITE_LIST_LIST *, rewrite_list->rewrite, rl, DOWN); } else if (!strcasecmp(a->value, "top")) { SETNODE(struct REWRITE_LIST_LIST *, rewrite_list->rewrite, rl, TOP); } else if (!strcasecmp(a->value, "bottom")) { SETNODE(struct REWRITE_LIST_LIST *, rewrite_list->rewrite, rl, BOTTOM); } } } } } finish: pthread_rwlock_unlock(&rewrite_list->lock); } void interface_page_config_mime(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int i; char *ptr; struct MIME_LIST_LIST *ml = NULL; if (mime_list == NULL) return; pthread_rwlock_rdlock(&mime_list->lock); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); for (i = 0; i < 2; i++) { filebuf_addf(filebuf, "\n"); if (ml != NULL) filebuf_addf(filebuf, "\n"); for (; ml; ml = ml->next) { filebuf_addf(filebuf, "\n"); } } filebuf_addf(filebuf, "
\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "", (mime_list->policy == POLICY_ALLOW) ? "selected" : "", (mime_list->policy == POLICY_DENY) ? "selected" : ""); filebuf_addf(filebuf, "\n", (mime_list->dtemplate != NULL) ? mime_list->dtemplate : ""); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Policy
Default template
Add

\n", INTERFACE_TABLEBG); switch (i) { case 0: ml = mime_list->allow; if (ml != NULL) filebuf_addf(filebuf, "\n"); break; case 1: ml = mime_list->deny; if (ml != NULL) filebuf_addf(filebuf, "\n"); break; } filebuf_addf(filebuf, "
ALLOW
DENY

\n"); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n", (ml->enabled == TRUE) ? "yes" : "no"); if (ml->comment != NULL) { ptr = string_to_html(ml->comment, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (ml->host != NULL) { ptr = string_to_html(ml->host, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (ml->file != NULL) { ptr = string_to_html(ml->file, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (ml->mime != NULL) { ptr = string_to_html(ml->mime, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (ml->template != NULL) filebuf_addf(filebuf, "\n", ml->template); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled%s
Comment%s
Host%s
File%s
Mimetype%s
Template%s
\n"); filebuf_addf(filebuf, "\n", (i == 0) ? "allow" : "deny", ml->id, (i == 0) ? "allow" : "deny", ml->id); filebuf_addf(filebuf, "\n", (i == 0) ? "allow" : "deny", ml->id, (i == 0) ? "allow" : "deny", ml->id); filebuf_addf(filebuf, "\n", (i == 0) ? "allow" : "deny", ml->id, (i == 0) ? "allow" : "deny", ml->id); filebuf_addf(filebuf, "
Edit DeleteUp DownTop Bottom

\n"); pthread_rwlock_unlock(&mime_list->lock); } void interface_page_config_mime_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *list = NULL, *ptr = NULL; struct MIME_LIST_LIST *ml = NULL; struct cgi_args_t *a = args; if (mime_list == NULL) return; pthread_rwlock_rdlock(&mime_list->lock); for (; a; a = a->next) { if (!strcasecmp(a->name, "id")) id = atoi(a->value); if (!strcasecmp(a->name, "list")) list = a->value; } if (id != -1 && list != NULL) { if (!strcasecmp(list, "allow")) for (ml = mime_list->allow; ml && ml->id != id; ml = ml->next); else if (!strcasecmp(list, "deny")) for (ml = mime_list->deny; ml && ml->id != id; ml = ml->next); } filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (list != NULL) filebuf_addf(filebuf, "\n", list); if (id != -1) { filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n", id); } else filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (ml != NULL && ml->comment != NULL) ptr = string_to_html(ml->comment, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (ml != NULL && ml->host != NULL) ptr = string_to_html(ml->host, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (ml != NULL && ml->file != NULL) ptr = string_to_html(ml->file, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (ml != NULL && ml->mime != NULL) ptr = string_to_html(ml->mime, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (ml != NULL && ml->template != NULL) ptr = string_to_html(ml->template, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled"); filebuf_addf(filebuf, "Yes: ", (ml == NULL || ml->enabled == TRUE) ? "checked" : ""); filebuf_addf(filebuf, "No: ", (ml != NULL && ml->enabled == FALSE) ? "checked" : ""); filebuf_addf(filebuf, "
Action
Comment
Host
File
Mimetype
Template

\n"); pthread_rwlock_unlock(&mime_list->lock); } void interface_page_config_mime_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *list = NULL, *action = NULL; struct MIME_LIST_LIST *ml = NULL; struct cgi_args_t *a; if (mime_list == NULL) return; pthread_rwlock_wrlock(&mime_list->lock); for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "action")) action = a->value; if (!strcasecmp(a->name, "id")) id = atoi(a->value); if (!strcasecmp(a->name, "list")) list = a->value; } if (action != NULL && !strcasecmp(action, "global")) { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "policy")) { if (!strcasecmp(a->value, "allow")) mime_list->policy = POLICY_ALLOW; else if (!strcasecmp(a->value, "deny")) mime_list->policy = POLICY_DENY; } else if (!strcasecmp(a->name, "dtemplate")) { FREE_AND_NULL(mime_list->dtemplate); if (strcmp(a->name, "")) mime_list->dtemplate = xstrdup(a->value); } } } if (action == NULL || list == NULL) goto finish; if (!strcasecmp(action, "delete")) { if (!strcasecmp(list, "allow")) ml = mime_list->allow; else if (!strcasecmp(list, "deny")) ml = mime_list->deny; for (; ml; ml = ml->next) { if (ml->id == id) { if (!strcasecmp(list, "allow")) mime_list->allow = mime_ll_delete(ml); else if (!strcasecmp(list, "deny")) mime_list->deny = mime_ll_delete(ml); break; } } } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) { if (!strcasecmp(action, "add")) { if (!strcasecmp(list, "allow")) { ml = mime_ll_new(mime_list->allow); if (mime_list->allow == NULL) mime_list->allow = ml; } else if (!strcasecmp(list, "deny")) { ml = mime_ll_new(mime_list->deny); if (mime_list->deny == NULL) mime_list->deny = ml; } else goto finish; ml->id = mime_list->id++; } else { if (!strcasecmp(list, "allow")) { for (ml = mime_list->allow; ml; ml = ml->next) if (ml->id == id) break; } else if (!strcasecmp(list, "deny")) { for (ml = mime_list->deny; ml; ml = ml->next) if (ml->id == id) break; } if (ml == NULL) goto finish; } if (strcasecmp(action, "shift")) { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "enabled")) { if (!strcasecmp(a->value, "no")) ml->enabled = FALSE; else ml->enabled = TRUE; } else if (!strcasecmp(a->name, "comment")) mime_ll_insert(ml, a->value, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "template")) mime_ll_insert(ml, NULL, a->value, NULL, NULL, NULL); else if (!strcasecmp(a->name, "host")) mime_ll_insert(ml, NULL, NULL, a->value, NULL, NULL); else if (!strcasecmp(a->name, "mime")) mime_ll_insert(ml, NULL, NULL, NULL, a->value, NULL); else if (!strcasecmp(a->name, "file")) mime_ll_insert(ml, NULL, NULL, NULL, NULL, a->value); else if (!strcasecmp(a->name, "move")) { if (!strcasecmp(a->value, "allow") && strcasecmp(list, a->value)) { MOVENODE(struct MIME_LIST_LIST *, ml, mime_list->deny, mime_list->allow); } else if (!strcasecmp(a->value, "deny") && strcasecmp(list, a->value)) { MOVENODE(struct MIME_LIST_LIST *, ml, mime_list->allow, mime_list->deny); } } } } else { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "direction")) { if (!strcasecmp(a->value, "up")) { SHIFTNODE(struct MIME_LIST_LIST *, (!strcasecmp(list, "allow")) ? mime_list->allow : mime_list->deny, ml, UP); } else if (!strcasecmp(a->value, "down")) { SHIFTNODE(struct MIME_LIST_LIST *, (!strcasecmp(list, "allow")) ? mime_list->allow : mime_list->deny, ml, DOWN); } else if (!strcasecmp(a->value, "top")) { SETNODE(struct MIME_LIST_LIST *, (!strcasecmp(list, "allow")) ? mime_list->allow : mime_list->deny, ml, TOP); } else if (!strcasecmp(a->value, "bottom")) { SETNODE(struct MIME_LIST_LIST *, (!strcasecmp(list, "allow")) ? mime_list->allow : mime_list->deny, ml, BOTTOM); } } } } } finish: pthread_rwlock_unlock(&mime_list->lock); } void interface_page_config_cookies(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int i; char *ptr; struct COOKIE_LIST_LIST *cl = NULL; if (cookie_list == NULL) return; pthread_rwlock_rdlock(&cookie_list->lock); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); for (i = 0; i < 2; i++) { filebuf_addf(filebuf, "\n"); if (cl != NULL) filebuf_addf(filebuf, "\n"); for (; cl; cl = cl->next) { filebuf_addf(filebuf, "\n"); } } pthread_rwlock_unlock(&cookie_list->lock); filebuf_addf(filebuf, "
\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "", (cookie_list->policy == POLICY_ALLOW) ? "selected" : "", (cookie_list->policy == POLICY_DENY) ? "selected" : ""); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Policy
Add

\n", INTERFACE_TABLEBG); switch (i) { case 0: cl = cookie_list->allow; if (cl != NULL) filebuf_addf(filebuf, "\n"); break; case 1: cl = cookie_list->deny; if (cl != NULL) filebuf_addf(filebuf, "\n"); break; } filebuf_addf(filebuf, "
ALLOW
DENY

\n"); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n", (cl->enabled == TRUE) ? "yes" : "no"); if (cl->comment != NULL) { ptr = string_to_html(cl->comment, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (cl->host != NULL) { ptr = string_to_html(cl->host, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } filebuf_addf(filebuf, "\n", (cl->direction == COOKIE_BOTH) ? "ANY" : (cl->direction == COOKIE_IN) ? "IN" : "OUT"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled%s
Comment%s
Host%s
Direction%s
\n"); filebuf_addf(filebuf, "\n", (i == 0) ? "allow" : "deny", cl->id, (i == 0) ? "allow" : "deny", cl->id); filebuf_addf(filebuf, "\n", (i == 0) ? "allow" : "deny", cl->id, (i == 0) ? "allow" : "deny", cl->id); filebuf_addf(filebuf, "\n", (i == 0) ? "allow" : "deny", cl->id, (i == 0) ? "allow" : "deny", cl->id); filebuf_addf(filebuf, "
Edit DeleteUp DownTop Bottom

\n"); } void interface_page_config_cookies_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *list = NULL, *ptr = NULL; struct COOKIE_LIST_LIST *cl = NULL; struct cgi_args_t *a = args; if (cookie_list == NULL) return; pthread_rwlock_rdlock(&cookie_list->lock); for (; a; a = a->next) { if (!strcasecmp(a->name, "id")) id = atoi(a->value); if (!strcasecmp(a->name, "list")) list = a->value; } if (id != -1 && list != NULL) { if (!strcasecmp(list, "allow")) for (cl = cookie_list->allow; cl && cl->id != id; cl = cl->next); else if (!strcasecmp(list, "deny")) for (cl = cookie_list->deny; cl && cl->id != id; cl = cl->next); } filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (list != NULL) filebuf_addf(filebuf, "\n", list); if (id != -1) { filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n", id); } else filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (cl != NULL && cl->comment != NULL) ptr = string_to_html(cl->comment, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (cl != NULL && cl->host != NULL) ptr = string_to_html(cl->host, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled"); filebuf_addf(filebuf, "Yes: ", (cl == NULL || cl->enabled == TRUE) ? "checked" : ""); filebuf_addf(filebuf, "No: ", (cl != NULL && cl->enabled == FALSE) ? "checked" : ""); filebuf_addf(filebuf, "
Action
Comment
Host
Direction"); filebuf_addf(filebuf, "Both: ", (cl == NULL || cl->direction == COOKIE_BOTH) ? "checked" : ""); filebuf_addf(filebuf, "In: ", (cl != NULL && cl->direction == COOKIE_IN) ? "checked" : ""); filebuf_addf(filebuf, "Out: ", (cl != NULL && cl->direction == COOKIE_OUT) ? "checked" : ""); filebuf_addf(filebuf, "

\n"); pthread_rwlock_unlock(&cookie_list->lock); } void interface_page_config_cookies_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *list = NULL, *action = NULL; struct COOKIE_LIST_LIST *cl = NULL; struct cgi_args_t *a; if (cookie_list == NULL) return; pthread_rwlock_wrlock(&cookie_list->lock); for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "action")) action = a->value; if (!strcasecmp(a->name, "id")) id = atoi(a->value); if (!strcasecmp(a->name, "list")) list = a->value; } if (action != NULL && !strcasecmp(action, "global")) { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "policy")) { if (!strcasecmp(a->value, "allow")) cookie_list->policy = POLICY_ALLOW; else if (!strcasecmp(a->value, "deny")) cookie_list->policy = POLICY_DENY; } } } if (action == NULL || list == NULL) goto finish; if (!strcasecmp(action, "delete")) { if (!strcasecmp(list, "allow")) cl = cookie_list->allow; else if (!strcasecmp(list, "deny")) cl = cookie_list->deny; for (; cl; cl = cl->next) { if (cl->id == id) { if (!strcasecmp(list, "allow")) cookie_list->allow = cookie_ll_delete(cl); else if (!strcasecmp(list, "deny")) cookie_list->deny = cookie_ll_delete(cl); break; } } } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) { if (!strcasecmp(action, "add")) { if (!strcasecmp(list, "allow")) { cl = cookie_ll_new(cookie_list->allow); if (cookie_list->allow == NULL) cookie_list->allow = cl; } else if (!strcasecmp(list, "deny")) { cl = cookie_ll_new(cookie_list->deny); if (cookie_list->deny == NULL) cookie_list->deny = cl; } else goto finish; cl->id = cookie_list->id++; } else { if (!strcasecmp(list, "allow")) { for (cl = cookie_list->allow; cl; cl = cl->next) if (cl->id == id) break; } else if (!strcasecmp(list, "deny")) { for (cl = cookie_list->deny; cl; cl = cl->next) if (cl->id == id) break; } if (cl == NULL) goto finish; } if (strcasecmp(action, "shift")) { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "enabled")) { if (!strcasecmp(a->value, "no")) cl->enabled = FALSE; else cl->enabled = TRUE; } else if (!strcasecmp(a->name, "comment")) cookie_ll_insert(cl, a->value, NULL, NULL); else if (!strcasecmp(a->name, "direction")) cookie_ll_insert(cl, NULL, a->value, NULL); else if (!strcasecmp(a->name, "host")) cookie_ll_insert(cl, NULL, NULL, a->value); else if (!strcasecmp(a->name, "move")) { if (!strcasecmp(a->value, "allow") && strcasecmp(list, a->value)) { MOVENODE(struct COOKIE_LIST_LIST *, cl, cookie_list->deny, cookie_list->allow); } else if (!strcasecmp(a->value, "deny") && strcasecmp(list, a->value)) { MOVENODE(struct COOKIE_LIST_LIST *, cl, cookie_list->allow, cookie_list->deny); } } } } else { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "direction")) { if (!strcasecmp(a->value, "up")) { SHIFTNODE(struct COOKIE_LIST_LIST *, (!strcasecmp(list, "allow")) ? cookie_list->allow : cookie_list->deny, cl, UP); } else if (!strcasecmp(a->value, "down")) { SHIFTNODE(struct COOKIE_LIST_LIST *, (!strcasecmp(list, "allow")) ? cookie_list->allow : cookie_list->deny, cl, DOWN); } else if (!strcasecmp(a->value, "top")) { SETNODE(struct COOKIE_LIST_LIST *, (!strcasecmp(list, "allow")) ? cookie_list->allow : cookie_list->deny, cl, TOP); } else if (!strcasecmp(a->value, "bottom")) { SETNODE(struct COOKIE_LIST_LIST *, (!strcasecmp(list, "allow")) ? cookie_list->allow : cookie_list->deny, cl, BOTTOM); } } } } } finish: pthread_rwlock_unlock(&cookie_list->lock); } void interface_page_config_external(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { char *ptr; struct EXTERNAL_LIST_LIST *el = NULL; if (external == NULL) return; pthread_rwlock_rdlock(&external->lock); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); for (el = external->external_list; el; el = el->next) { filebuf_addf(filebuf, "\n"); } filebuf_addf(filebuf, "
\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Add

\n"); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n", (el->enabled == TRUE) ? "yes" : "no"); if (el->comment != NULL) { ptr = string_to_html(el->comment, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (el->host != NULL) { ptr = string_to_html(el->host, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (el->file != NULL) { ptr = string_to_html(el->file, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (el->mime != NULL) { ptr = string_to_html(el->mime, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (el->newmime != NULL) { ptr = string_to_html(el->newmime, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (el->exec != NULL) { ptr = string_to_html(el->exec, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } filebuf_addf(filebuf, "\n", (el->type == EXTERNAL_PIPE) ? "pipe" : "file"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled%s
Comment%s
Host%s
File%s
Mimetype%s
New mime%s
Executable%s
Type%s
\n"); filebuf_addf(filebuf, "\n", el->id, el->id); filebuf_addf(filebuf, "\n", el->id, el->id); filebuf_addf(filebuf, "\n", el->id, el->id); filebuf_addf(filebuf, "
Edit DeleteUp DownTop Bottom

\n"); pthread_rwlock_unlock(&external->lock); } void interface_page_config_external_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *ptr = NULL; struct EXTERNAL_LIST_LIST *el = NULL; struct cgi_args_t *a = args; if (external == NULL) return; pthread_rwlock_rdlock(&external->lock); for (; a; a = a->next) { if (!strcasecmp(a->name, "id")) id = atoi(a->value); } if (id != -1) for (el = external->external_list; el && el->id != id; el = el->next); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (id != -1) { filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n", id); } else filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (el != NULL && el->comment != NULL) ptr = string_to_html(el->comment, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (el != NULL && el->exec != NULL) ptr = string_to_html(el->exec, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (el != NULL && el->host != NULL) ptr = string_to_html(el->host, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (el != NULL && el->file != NULL) ptr = string_to_html(el->file, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (el != NULL && el->mime != NULL) ptr = string_to_html(el->mime, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (el != NULL && el->newmime != NULL) ptr = string_to_html(el->newmime, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled"); filebuf_addf(filebuf, "Yes: ", (el == NULL || el->enabled == TRUE) ? "checked" : ""); filebuf_addf(filebuf, "No: ", (el != NULL && el->enabled == FALSE) ? "checked" : ""); filebuf_addf(filebuf, "
Comment
Executable
Host
File
Mimetype
Newmime
Type"); filebuf_addf(filebuf, "Pipe: ", (el == NULL || el->type == EXTERNAL_PIPE) ? "checked" : ""); filebuf_addf(filebuf, "File: ", (el != NULL && el->type == EXTERNAL_FILE) ? "checked" : ""); filebuf_addf(filebuf, "

\n"); pthread_rwlock_unlock(&external->lock); } void interface_page_config_external_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *action = NULL; struct EXTERNAL_LIST_LIST *el = NULL; struct cgi_args_t *a; if (external == NULL) return; pthread_rwlock_wrlock(&external->lock); for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "action")) action = a->value; if (!strcasecmp(a->name, "id")) id = atoi(a->value); } if (action == NULL) goto finish; if (!strcasecmp(action, "delete")) { for (el = external->external_list; el; el = el->next) { if (el->id == id) { external->external_list = external_list_delete(el); break; } } } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) { if (!strcasecmp(action, "add")) { el = external_list_new(external->external_list); if (external->external_list == NULL) external->external_list = el; el->id = external->id++; } else { for (el = external->external_list; el; el = el->next) if (el->id == id) break; if (el == NULL) goto finish; } if (strcasecmp(action, "shift")) { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "enabled")) { if (!strcasecmp(a->value, "no")) el->enabled = FALSE; else el->enabled = TRUE; } else if (!strcasecmp(a->name, "comment")) external_list_insert(el, a->value, NULL, NULL, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "mime")) external_list_insert(el, NULL, a->value, NULL, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "host")) external_list_insert(el, NULL, NULL, a->value, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "file")) external_list_insert(el, NULL, NULL, NULL, a->value, NULL, NULL, NULL); else if (!strcasecmp(a->name, "exec")) external_list_insert(el, NULL, NULL, NULL, NULL, a->value, NULL, NULL); else if (!strcasecmp(a->name, "newmime")) external_list_insert(el, NULL, NULL, NULL, NULL, NULL, a->value, NULL); else if (!strcasecmp(a->name, "type")) external_list_insert(el, NULL, NULL, NULL, NULL, NULL, NULL, a->value); } } else { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "direction")) { if (!strcasecmp(a->value, "up")) { SHIFTNODE(struct EXTERNAL_LIST_LIST *, external->external_list, el, UP); } else if (!strcasecmp(a->value, "down")) { SHIFTNODE(struct EXTERNAL_LIST_LIST *, external->external_list, el, DOWN); } else if (!strcasecmp(a->value, "top")) { SETNODE(struct EXTERNAL_LIST_LIST *, external->external_list, el, TOP); } else if (!strcasecmp(a->value, "bottom")) { SETNODE(struct EXTERNAL_LIST_LIST *, external->external_list, el, BOTTOM); } } } } } finish: pthread_rwlock_unlock(&external->lock); } void interface_page_config_templates(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { char *ptr; struct TEMPLATE_LIST *tl = NULL; if (templates == NULL) return; pthread_rwlock_rdlock(&templates->lock); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); for (tl = templates->template_list; tl; tl = tl->next) { filebuf_addf(filebuf, "\n"); } filebuf_addf(filebuf, "
\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n", (templates->path != NULL) ? templates->path : ""); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Path
Add

\n"); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n", (tl->enabled == TRUE) ? "yes" : "no"); if (tl->comment != NULL) { ptr = string_to_html(tl->comment, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (tl->name != NULL) { ptr = string_to_html(tl->name, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (tl->file != NULL) { ptr = string_to_html(tl->file, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (tl->mime != NULL) { ptr = string_to_html(tl->mime, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (tl->code != -1) filebuf_addf(filebuf, "\n", tl->code); filebuf_addf(filebuf, "\n", (tl->type == TEMPLATE_FILE) ? "file" : "executable"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled%s
Comment%s
Name%s
File%s
Mimetype%s
Response code%d
Type%s
\n"); filebuf_addf(filebuf, "\n", tl->id, tl->id); filebuf_addf(filebuf, "\n", tl->id, tl->id); filebuf_addf(filebuf, "\n", tl->id, tl->id); filebuf_addf(filebuf, "
Edit DeleteUp DownTop Bottom

\n"); pthread_rwlock_unlock(&templates->lock); } void interface_page_config_templates_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *ptr = NULL, buf[16]; struct TEMPLATE_LIST *tl = NULL; struct cgi_args_t *a = args; if (rewrite_list == NULL) return; pthread_rwlock_rdlock(&templates->lock); for (; a; a = a->next) { if (!strcasecmp(a->name, "id")) id = atoi(a->value); } if (id != -1) for (tl = templates->template_list; tl && tl->id != id; tl = tl->next); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (id != -1) { filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n", id); } else filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (tl != NULL && tl->comment != NULL) ptr = string_to_html(tl->comment, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (tl != NULL && tl->name != NULL) ptr = string_to_html(tl->name, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (tl != NULL && tl->file != NULL) ptr = string_to_html(tl->file, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (tl != NULL && tl->mime != NULL) ptr = string_to_html(tl->mime, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (tl != NULL) snprintf(buf, sizeof(buf), "%d", tl->code); filebuf_addf(filebuf, "\n", (tl != NULL && tl->code != -1) ? buf : ""); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled"); filebuf_addf(filebuf, "Yes: ", (tl == NULL || tl->enabled == TRUE) ? "checked" : ""); filebuf_addf(filebuf, "No: ", (tl != NULL && tl->enabled == FALSE) ? "checked" : ""); filebuf_addf(filebuf, "
Comment
Name
File
Mimetype
Response code
Type"); filebuf_addf(filebuf, "File: ", (tl == NULL || tl->type == TEMPLATE_FILE) ? "checked" : ""); filebuf_addf(filebuf, "Executable: ", (tl != NULL && tl->type == TEMPLATE_EXECUTABLE) ? "checked" : ""); filebuf_addf(filebuf, "

\n"); pthread_rwlock_unlock(&templates->lock); } void interface_page_config_templates_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *action = NULL; struct TEMPLATE_LIST *tl = NULL; struct cgi_args_t *a; if (templates == NULL) return; pthread_rwlock_wrlock(&templates->lock); for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "action")) action = a->value; if (!strcasecmp(a->name, "id")) id = atoi(a->value); } if (action == NULL) goto finish; if (!strcasecmp(action, "delete")) { for (tl = templates->template_list; tl; tl = tl->next) { if (tl->id == id) { templates->template_list = template_list_delete(tl); break; } } } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) { if (!strcasecmp(action, "add")) { tl = template_list_new(templates->template_list); if (templates->template_list == NULL) templates->template_list = tl; tl->id = templates->id++; } else { for (tl = templates->template_list; tl; tl = tl->next) if (tl->id == id) break; if (tl == NULL) goto finish; } if (strcasecmp(action, "shift")) { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "enabled")) { if (!strcasecmp(a->value, "no")) tl->enabled = FALSE; else tl->enabled = TRUE; } else if (!strcasecmp(a->name, "comment")) template_list_insert(tl, a->value, NULL, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "name")) template_list_insert(tl, NULL, a->value, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "file")) template_list_insert(tl, NULL, NULL, a->value, NULL, NULL, NULL); else if (!strcasecmp(a->name, "type")) template_list_insert(tl, NULL, NULL, NULL, a->value, NULL, NULL); else if (!strcasecmp(a->name, "mime")) template_list_insert(tl, NULL, NULL, NULL, NULL, a->value, NULL); else if (!strcasecmp(a->name, "code")) template_list_insert(tl, NULL, NULL, NULL, NULL, NULL, a->value); } } else { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "direction")) { if (!strcasecmp(a->value, "up")) { SHIFTNODE(struct TEMPLATE_LIST *, templates->template_list, tl, UP); } else if (!strcasecmp(a->value, "down")) { SHIFTNODE(struct TEMPLATE_LIST *, templates->template_list, tl, DOWN); } else if (!strcasecmp(a->value, "top")) { SETNODE(struct TEMPLATE_LIST *, templates->template_list, tl, TOP); } else if (!strcasecmp(a->value, "down")) { SETNODE(struct TEMPLATE_LIST *, templates->template_list, tl, BOTTOM); } } } } } finish: pthread_rwlock_unlock(&templates->lock); } void interface_page_config_network(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { char *ptr; struct LISTEN_LIST *ll = NULL; if (network == NULL) return; filebuf_addf(filebuf, "\n"); ll = network->listen_list; for (; ll; ll = ll->next) { filebuf_addf(filebuf, "\n"); } filebuf_addf(filebuf, "
\n"); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); if (ll->ip != NULL) { ptr = string_to_html(ll->ip, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (ll->port != -1) { filebuf_addf(filebuf, "\n", ll->port); } if (ll->proxytype != PROXY_DIRECT) { filebuf_addf(filebuf, "\n", (ll->proxytype == PROXY_NORMAL) ? "HTTP" : "SOCKS4"); } if (ll->proxy != NULL) { ptr = string_to_html(ll->proxy, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } filebuf_addf(filebuf, "
IP Address%s
Port%d
Proxy type%s
Proxy%s

\n"); } void interface_page_config_redirect(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { char *ptr; struct REDIRECT_LIST_LIST *rl = NULL; if (redirect_list == NULL) return; pthread_rwlock_rdlock(&redirect_list->lock); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); for (rl = redirect_list->redirect_list; rl; rl = rl->next) { filebuf_addf(filebuf, "\n"); } filebuf_addf(filebuf, "
\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Add

\n"); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n", (rl->enabled == TRUE) ? "yes" : "no"); if (rl->comment != NULL) { ptr = string_to_html(rl->comment, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (rl->url != NULL) { ptr = string_to_html(rl->url, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (rl->redirect != NULL) { ptr = string_to_html(rl->redirect, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (rl->port != -1) filebuf_addf(filebuf, "\n", rl->port); filebuf_addf(filebuf, "\n", (rl->send302 == TRUE) ? "yes" : "no"); if (rl->options != 0) filebuf_addf(filebuf, "\n", (rl->options & URL_ENCODE) ? "encode URL" : "", (rl->options & URL_DECODEBEFORE) ? "decode URL before" : "", (rl->options & URL_DECODEAFTER) ? "decode URL after" : ""); filebuf_addf(filebuf, "\n", (rl->which == REDIRECT_BOTH) ? "both" : (rl->which == REDIRECT_URL) ? "URL" : "location"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled%s
Comment%s
URL%s
Redirect%s
Port%d
302 redirect%s
Options%s,%s,%s
Applies to%s
\n"); filebuf_addf(filebuf, "\n", rl->id, rl->id); filebuf_addf(filebuf, "\n", rl->id, rl->id); filebuf_addf(filebuf, "\n", rl->id, rl->id); filebuf_addf(filebuf, "
Edit DeleteUp DownTop Bottom

\n"); pthread_rwlock_unlock(&redirect_list->lock); } void interface_page_config_redirect_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *ptr = NULL; struct REDIRECT_LIST_LIST *rl = NULL; struct cgi_args_t *a = args; if (redirect_list == NULL) return; pthread_rwlock_rdlock(&redirect_list->lock); for (; a; a = a->next) { if (!strcasecmp(a->name, "id")) id = atoi(a->value); } if (id != -1) for (rl = redirect_list->redirect_list; rl && rl->id != id; rl = rl->next); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (id != -1) { filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n", id); } else filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (rl != NULL && rl->comment != NULL) ptr = string_to_html(rl->comment, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (rl != NULL && rl->url != NULL) ptr = string_to_html(rl->url, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (rl != NULL && rl->redirect != NULL) ptr = string_to_html(rl->redirect, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (rl != NULL && rl->port != -1) filebuf_addf(filebuf, "\n", rl->port); else filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled"); filebuf_addf(filebuf, "Yes: ", (rl == NULL || rl->enabled == TRUE) ? "checked" : ""); filebuf_addf(filebuf, "No: ", (rl != NULL && rl->enabled == FALSE) ? "checked" : ""); filebuf_addf(filebuf, "
Comment
URL
Redirect
Port
Port
302 redirect"); filebuf_addf(filebuf, "Yes: ", (rl == NULL || rl->send302 == TRUE) ? "checked" : ""); filebuf_addf(filebuf, "No: ", (rl != NULL && rl->send302 == FALSE) ? "checked" : ""); filebuf_addf(filebuf, "
Options"); filebuf_addf(filebuf, "Encode URL: ", (rl != NULL && (rl->options & URL_ENCODE)) ? "checked" : ""); filebuf_addf(filebuf, "Decode URL before: ", (rl != NULL && (rl->options & URL_DECODEBEFORE)) ? "checked" : ""); filebuf_addf(filebuf, "Decode URL after: ", (rl != NULL && (rl->options & URL_DECODEAFTER)) ? "checked" : ""); filebuf_addf(filebuf, "
Applies to"); filebuf_addf(filebuf, "Both: ", (rl != NULL && rl->which == REDIRECT_BOTH) ? "checked" : ""); filebuf_addf(filebuf, "URL: ", (rl == NULL || rl->which == REDIRECT_URL) ? "checked" : ""); filebuf_addf(filebuf, "Location header: ", (rl != NULL && rl->which == REDIRECT_LOCATION) ? "checked" : ""); filebuf_addf(filebuf, "

\n"); pthread_rwlock_unlock(&redirect_list->lock); } void interface_page_config_redirect_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *action = NULL; struct REDIRECT_LIST_LIST *rl = NULL; struct cgi_args_t *a; if (redirect_list == NULL) return; pthread_rwlock_wrlock(&redirect_list->lock); for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "action")) action = a->value; if (!strcasecmp(a->name, "id")) id = atoi(a->value); } if (action == NULL) goto finish; if (!strcasecmp(action, "delete")) { for (rl = redirect_list->redirect_list; rl; rl = rl->next) { if (rl->id == id) { redirect_list->redirect_list = redirect_list_delete(rl); break; } } } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) { if (!strcasecmp(action, "add")) { rl = redirect_list_new(redirect_list->redirect_list); if (redirect_list->redirect_list == NULL) redirect_list->redirect_list = rl; rl->id = redirect_list->id++; } else { for (rl = redirect_list->redirect_list; rl; rl = rl->next) if (rl->id == id) break; if (rl == NULL) goto finish; } if (strcasecmp(action, "shift")) { rl->options = 0; for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "enabled")) { if (!strcasecmp(a->value, "no")) rl->enabled = FALSE; else rl->enabled = TRUE; } else if (!strcasecmp(a->name, "comment")) redirect_list_insert(rl, a->value, NULL, NULL, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "url")) redirect_list_insert(rl, NULL, a->value, NULL, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "redirect")) redirect_list_insert(rl, NULL, NULL, a->value, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "port")) redirect_list_insert(rl, NULL, NULL, NULL, a->value, NULL, NULL, NULL); else if (!strcasecmp(a->name, "which")) redirect_list_insert(rl, NULL, NULL, NULL, NULL, a->value, NULL, NULL); else if (!strcasecmp(a->name, "send302")) redirect_list_insert(rl, NULL, NULL, NULL, NULL, NULL, a->value, NULL); else if (!strcasecmp(a->name, "encode")) rl->options |= URL_ENCODE; else if (!strcasecmp(a->name, "decodebefore")) rl->options |= URL_DECODEBEFORE; else if (!strcasecmp(a->name, "decodeafter")) rl->options |= URL_DECODEAFTER; } } else { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "direction")) { if (!strcasecmp(a->value, "up")) { SHIFTNODE(struct REDIRECT_LIST_LIST *, redirect_list->redirect_list, rl, UP); } else if (!strcasecmp(a->value, "down")) { SHIFTNODE(struct REDIRECT_LIST_LIST *, redirect_list->redirect_list, rl, DOWN); } else if (!strcasecmp(a->value, "top")) { SETNODE(struct REDIRECT_LIST_LIST *, redirect_list->redirect_list, rl, TOP); } else if (!strcasecmp(a->value, "bottom")) { SETNODE(struct REDIRECT_LIST_LIST *, redirect_list->redirect_list, rl, BOTTOM); } } } } } finish: pthread_rwlock_unlock(&redirect_list->lock); } void interface_page_config_forward(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { char *ptr; struct FORWARD_LIST_LIST *fl = NULL; if (forward_list == NULL) return; pthread_rwlock_rdlock(&forward_list->lock); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); for (fl = forward_list->forward_list; fl; fl = fl->next) { filebuf_addf(filebuf, "\n"); } filebuf_addf(filebuf, "
\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Add

\n"); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n", (fl->enabled == TRUE) ? "yes" : "no"); if (fl->comment != NULL) { ptr = string_to_html(fl->comment, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (fl->host != NULL) { ptr = string_to_html(fl->host, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (fl->file != NULL) { ptr = string_to_html(fl->file, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (fl->proxy != NULL) { ptr = string_to_html(fl->proxy, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (fl->username != NULL) { ptr = string_to_html(fl->username, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (fl->password != NULL) { ptr = string_to_html(fl->password, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (fl->domain != NULL) { ptr = string_to_html(fl->domain, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (fl->port != -1) filebuf_addf(filebuf, "\n", fl->port); filebuf_addf(filebuf, "\n", (fl->type == PROXY_NORMAL) ? "HTTP" : "SOCKS4"); if (fl->which != 0) filebuf_addf(filebuf, "\n", (fl->which & FORWARD_HTTP) ? "HTTP requests" : "", (fl->which & FORWARD_CONNECT) ? "CONNECT requests" : ""); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled%s
Comment%s
Host%s
File%s
Proxy%s
Username%s
Password%s
Domain%s
Port%d
Type%s
Applies to%s,%s
\n"); filebuf_addf(filebuf, "\n", fl->id, fl->id); filebuf_addf(filebuf, "\n", fl->id, fl->id); filebuf_addf(filebuf, "\n", fl->id, fl->id); filebuf_addf(filebuf, "
Edit DeleteUp DownTop Bottom

\n"); pthread_rwlock_unlock(&forward_list->lock); } void interface_page_config_forward_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *ptr = NULL; struct FORWARD_LIST_LIST *fl = NULL; struct cgi_args_t *a = args; if (forward_list == NULL) return; pthread_rwlock_rdlock(&forward_list->lock); for (; a; a = a->next) { if (!strcasecmp(a->name, "id")) id = atoi(a->value); } if (id != -1) for (fl = forward_list->forward_list; fl && fl->id != id; fl = fl->next); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (id != -1) { filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n", id); } else filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (fl != NULL && fl->comment != NULL) ptr = string_to_html(fl->comment, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (fl != NULL && fl->host != NULL) ptr = string_to_html(fl->host, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (fl != NULL && fl->file != NULL) ptr = string_to_html(fl->file, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (fl != NULL && fl->proxy != NULL) ptr = string_to_html(fl->proxy, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (fl != NULL && fl->username != NULL) ptr = string_to_html(fl->username, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (fl != NULL && fl->password != NULL) ptr = string_to_html(fl->password, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (fl != NULL && fl->domain != NULL) ptr = string_to_html(fl->domain, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (fl != NULL && fl->port != -1) filebuf_addf(filebuf, "\n", fl->port); else filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled"); filebuf_addf(filebuf, "Yes: ", (fl == NULL || fl->enabled == TRUE) ? "checked" : ""); filebuf_addf(filebuf, "No: ", (fl != NULL && fl->enabled == FALSE) ? "checked" : ""); filebuf_addf(filebuf, "
Comment
Host
File
Proxy
Username
Password
Domain
Port
Port
Type"); filebuf_addf(filebuf, "HTTP: ", (fl == NULL || fl->type == PROXY_NORMAL) ? "checked" : ""); filebuf_addf(filebuf, "SOCKS4: ", (fl != NULL && fl->type == PROXY_SOCKS4) ? "checked" : ""); filebuf_addf(filebuf, "
Applies to"); filebuf_addf(filebuf, "HTTP requests: ", (fl == NULL || (fl->which & FORWARD_HTTP)) ? "checked" : ""); filebuf_addf(filebuf, "CONNECT requests: ", (fl != NULL && (fl->which & FORWARD_CONNECT)) ? "checked" : ""); filebuf_addf(filebuf, "

\n"); pthread_rwlock_unlock(&forward_list->lock); } void interface_page_config_forward_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *action = NULL; struct FORWARD_LIST_LIST *fl = NULL; struct cgi_args_t *a; if (forward_list == NULL) return; pthread_rwlock_wrlock(&forward_list->lock); for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "action")) action = a->value; if (!strcasecmp(a->name, "id")) id = atoi(a->value); } if (action == NULL) goto finish; if (!strcasecmp(action, "delete")) { for (fl = forward_list->forward_list; fl; fl = fl->next) { if (fl->id == id) { forward_list->forward_list = forward_list_delete(fl); break; } } } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) { if (!strcasecmp(action, "add")) { fl = forward_list_new(forward_list->forward_list); if (forward_list->forward_list == NULL) forward_list->forward_list = fl; fl->id = forward_list->id++; } else { for (fl = forward_list->forward_list; fl; fl = fl->next) if (fl->id == id) break; if (fl == NULL) goto finish; } if (strcasecmp(action, "shift")) { fl->which = 0; for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "enabled")) { if (!strcasecmp(a->value, "no")) fl->enabled = FALSE; else fl->enabled = TRUE; } else if (!strcasecmp(a->name, "comment")) forward_list_insert(fl, a->value, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "host")) forward_list_insert(fl, NULL, a->value, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "file")) forward_list_insert(fl, NULL, NULL, a->value, NULL, NULL, NULL, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "proxy")) forward_list_insert(fl, NULL, NULL, NULL, a->value, NULL, NULL, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "port")) forward_list_insert(fl, NULL, NULL, NULL, NULL, a->value, NULL, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "type")) forward_list_insert(fl, NULL, NULL, NULL, NULL, NULL, a->value, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "username")) forward_list_insert(fl, NULL, NULL, NULL, NULL, NULL, NULL, NULL, a->value, NULL, NULL); else if (!strcasecmp(a->name, "password")) forward_list_insert(fl, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, a->value, NULL); else if (!strcasecmp(a->name, "domain")) forward_list_insert(fl, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, a->value); else if (!strcasecmp(a->name, "HTTP")) fl->which |= FORWARD_HTTP; else if (!strcasecmp(a->name, "CONNECT")) fl->which |= FORWARD_CONNECT; } } else { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "direction")) { if (!strcasecmp(a->value, "up")) { SHIFTNODE(struct FORWARD_LIST_LIST *, forward_list->forward_list, fl, UP); } else if (!strcasecmp(a->value, "down")) { SHIFTNODE(struct FORWARD_LIST_LIST *, forward_list->forward_list, fl, DOWN); } else if (!strcasecmp(a->value, "top")) { SETNODE(struct FORWARD_LIST_LIST *, forward_list->forward_list, fl, TOP); } else if (!strcasecmp(a->value, "bottom")) { SETNODE(struct FORWARD_LIST_LIST *, forward_list->forward_list, fl, BOTTOM); } } } } } finish: pthread_rwlock_unlock(&forward_list->lock); } void interface_page_config_keywords(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { char *ptr; struct KEYWORD_LIST_LIST *kl = NULL; if (keyword_list == NULL) return; pthread_rwlock_rdlock(&keyword_list->lock); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); for (kl = keyword_list->keyword_list; kl; kl = kl->next) { filebuf_addf(filebuf, "\n"); } filebuf_addf(filebuf, "
\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n", (keyword_list->template != NULL) ? keyword_list->template : ""); filebuf_addf(filebuf, "\n", keyword_list->threshold); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Template
Threshold
Add

\n"); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n", (kl->enabled == TRUE) ? "yes" : "no"); if (kl->comment != NULL) { ptr = string_to_html(kl->comment, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (kl->host != NULL) { ptr = string_to_html(kl->host, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (kl->file != NULL) { ptr = string_to_html(kl->file, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (kl->mime != NULL) { ptr = string_to_html(kl->mime, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (kl->keyword != NULL) { ptr = string_to_html(kl->keyword, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } filebuf_addf(filebuf, "\n", kl->score); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled%s
Comment%s
Host%s
File%s
Mimetype%s
Keyword%s
Score%d
\n"); filebuf_addf(filebuf, "\n", kl->id, kl->id); filebuf_addf(filebuf, "\n", kl->id, kl->id); filebuf_addf(filebuf, "\n", kl->id, kl->id); filebuf_addf(filebuf, "
Edit DeleteUp DownTop Bottom

\n"); pthread_rwlock_unlock(&keyword_list->lock); } void interface_page_config_keywords_dialog(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *ptr = NULL; struct KEYWORD_LIST_LIST *kl = NULL; struct cgi_args_t *a = args; if (keyword_list == NULL) return; pthread_rwlock_rdlock(&keyword_list->lock); for (; a; a = a->next) { if (!strcasecmp(a->name, "id")) id = atoi(a->value); } if (id != -1) for (kl = keyword_list->keyword_list; kl && kl->id != id; kl = kl->next); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (id != -1) { filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n", id); } else filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); if (kl != NULL && kl->comment != NULL) ptr = string_to_html(kl->comment, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (kl != NULL && kl->host != NULL) ptr = string_to_html(kl->host, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (kl != NULL && kl->file != NULL) ptr = string_to_html(kl->file, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (kl != NULL && kl->mime != NULL) ptr = string_to_html(kl->mime, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); if (kl != NULL && kl->keyword != NULL) ptr = string_to_html(kl->keyword, TRUE); filebuf_addf(filebuf, "\n", (ptr != NULL) ? ptr : ""); FREE_AND_NULL(ptr); filebuf_addf(filebuf, "\n", (kl != NULL) ? kl->score : 0); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "
Enabled"); filebuf_addf(filebuf, "Yes: ", (kl == NULL || kl->enabled == TRUE) ? "checked" : ""); filebuf_addf(filebuf, "No: ", (kl != NULL && kl->enabled == FALSE) ? "checked" : ""); filebuf_addf(filebuf, "
Comment
Host
File
Mimetype
Keyword
Score

\n"); pthread_rwlock_unlock(&keyword_list->lock); } void interface_page_config_keywords_action(FILEBUF * filebuf, struct cgi_args_t *args, CONNECTION * connection) { int id = -1; char *action = NULL; struct KEYWORD_LIST_LIST *kl = NULL; struct cgi_args_t *a; if (keyword_list == NULL) return; pthread_rwlock_wrlock(&keyword_list->lock); for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "action")) action = a->value; if (!strcasecmp(a->name, "id")) id = atoi(a->value); } if (action == NULL) goto finish; if (!strcasecmp(action, "global")) { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "template")) { FREE_AND_NULL(keyword_list->template); if (strcmp(a->value, "")) keyword_list->template = xstrdup(a->value); } else if (!strcasecmp(a->name, "threshold")) keyword_list->threshold = atoi(a->value); } } if (!strcasecmp(action, "delete")) { for (kl = keyword_list->keyword_list; kl; kl = kl->next) { if (kl->id == id) { keyword_list->keyword_list = keyword_list_delete(kl); break; } } } else if (!strcasecmp(action, "add") || !strcasecmp(action, "edit") || !strcasecmp(action, "shift")) { if (!strcasecmp(action, "add")) { kl = keyword_list_new(keyword_list->keyword_list); if (keyword_list->keyword_list == NULL) keyword_list->keyword_list = kl; kl->id = keyword_list->id++; } else { for (kl = keyword_list->keyword_list; kl; kl = kl->next) if (kl->id == id) break; if (kl == NULL) goto finish; } if (strcasecmp(action, "shift")) { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "enabled")) { if (!strcasecmp(a->value, "no")) kl->enabled = FALSE; else kl->enabled = TRUE; } else if (!strcasecmp(a->name, "comment")) keyword_list_insert(kl, a->value, NULL, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "host")) keyword_list_insert(kl, NULL, a->value, NULL, NULL, NULL, NULL); else if (!strcasecmp(a->name, "file")) keyword_list_insert(kl, NULL, NULL, a->value, NULL, NULL, NULL); else if (!strcasecmp(a->name, "mime")) keyword_list_insert(kl, NULL, NULL, NULL, a->value, NULL, NULL); else if (!strcasecmp(a->name, "keyword")) keyword_list_insert(kl, NULL, NULL, NULL, NULL, a->value, NULL); else if (!strcasecmp(a->name, "score")) keyword_list_insert(kl, NULL, NULL, NULL, NULL, NULL, a->value); } } else { for (a = args; a; a = a->next) { if (!strcasecmp(a->name, "direction")) { if (!strcasecmp(a->value, "up")) { SHIFTNODE(struct KEYWORD_LIST_LIST *, keyword_list->keyword_list, kl, UP); } else if (!strcasecmp(a->value, "down")) { SHIFTNODE(struct KEYWORD_LIST_LIST *, keyword_list->keyword_list, kl, DOWN); } else if (!strcasecmp(a->value, "top")) { SETNODE(struct KEYWORD_LIST_LIST *, keyword_list->keyword_list, kl, TOP); } else if (!strcasecmp(a->value, "bottom")) { SETNODE(struct KEYWORD_LIST_LIST *, keyword_list->keyword_list, kl, BOTTOM); } } } } } finish: pthread_rwlock_unlock(&keyword_list->lock); } void filter_check_show(CONNECTION * connection) { char *ptr; struct FILTER_LIST_LIST *fl; FILEBUF *filebuf; HEADER *header; filebuf = filebuf_new(); fl = filter_check(filter_list, connection); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "URL filter matche for %s%s", connection->header->host, connection->header->file); filebuf_addf(filebuf, "\n", INTERFACE_TEXT, INTERFACE_BG, INTERFACE_LINK, INTERFACE_VLINK); filebuf_addf(filebuf, "
\n"); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n", connection->header->host, connection->header->file); if (fl == NULL) filebuf_addf(filebuf, "\n"); else { if (fl->comment != NULL) { ptr = string_to_html(fl->comment, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (fl->host != NULL) { ptr = string_to_html(fl->host, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (fl->file != NULL) { ptr = string_to_html(fl->file, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (fl->template != NULL) filebuf_addf(filebuf, "\n", fl->template); filebuf_addf(filebuf, "
URL filter match for %s%s
None
Comment%s
Host%s
File%s
Template%s
\n"); filebuf_addf(filebuf, "\n", INTERFACEURL, fl->id, INTERFACEURL, fl->id); } filebuf_addf(filebuf, "
Edit Delete
\n"); header = header_new();; header->type = HTTP_RESP; header->code = 200; header->content_type = xstrdup("text/html"); header->content_length = filebuf->size; header_send(header, connection, CLIENT, HEADER_RESP); net_filebuf_send(filebuf, connection, CLIENT); http_header_free(header); filebuf_free(filebuf); pthread_rwlock_unlock(&filter_list->lock); return; } void mime_check_show(CONNECTION * connection) { char *ptr; struct MIME_LIST_LIST *ml; FILEBUF *filebuf; HEADER *header; filebuf = filebuf_new(); ml = mime_check(mime_list, connection); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "MIME filter match for %s%s", connection->header->host, connection->header->file); filebuf_addf(filebuf, "\n", INTERFACE_TEXT, INTERFACE_BG, INTERFACE_LINK, INTERFACE_VLINK); filebuf_addf(filebuf, "
\n"); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n", connection->header->host, connection->header->file); if (ml == NULL) filebuf_addf(filebuf, "\n"); else { if (ml->comment != NULL) { ptr = string_to_html(ml->comment, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (ml->host != NULL) { ptr = string_to_html(ml->host, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (ml->file != NULL) { ptr = string_to_html(ml->file, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (ml->mime != NULL) { ptr = string_to_html(ml->mime, TRUE); filebuf_addf(filebuf, "\n", ptr); xfree(ptr); } if (ml->template != NULL) filebuf_addf(filebuf, "\n", ml->template); filebuf_addf(filebuf, "
MIME filter match for %s%s
None
Comment%s
Host%s
File%s
Mimetype%s
Template%s
\n"); filebuf_addf(filebuf, "\n", INTERFACEURL, ml->id, INTERFACEURL, ml->id); } filebuf_addf(filebuf, "
Edit Delete
\n"); header = header_new();; header->type = HTTP_RESP; header->code = 200; header->content_type = xstrdup("text/html"); header->content_length = filebuf->size; header_send(header, connection, CLIENT, HEADER_RESP); net_filebuf_send(filebuf, connection, CLIENT); http_header_free(header); filebuf_free(filebuf); pthread_rwlock_unlock(&mime_list->lock); return; } void score_show(CONNECTION *connection, int score) { FILEBUF *filebuf; HEADER *header; filebuf = filebuf_new(); filebuf_addf(filebuf, "\n"); filebuf_addf(filebuf, "Keyword score for %s%s", connection->header->host, connection->header->file); filebuf_addf(filebuf, "\n", INTERFACE_TEXT, INTERFACE_BG, INTERFACE_LINK, INTERFACE_VLINK); filebuf_addf(filebuf, "
\n"); filebuf_addf(filebuf, "\n", INTERFACE_TABLEBG); filebuf_addf(filebuf, "\n", connection->header->host, connection->header->file); filebuf_addf(filebuf, "\n", score); filebuf_addf(filebuf, "
Keyword score for %s%s
%d
\n"); header = header_new();; header->type = HTTP_RESP; header->code = 200; header->content_type = xstrdup("text/html"); header->content_length = filebuf->size; header_send(header, connection, CLIENT, HEADER_RESP); net_filebuf_send(filebuf, connection, CLIENT); http_header_free(header); filebuf_free(filebuf); }