From 2465a9102eb7d4f7a53bd454596e61edd16acb85 Mon Sep 17 00:00:00 2001 From: jongfoster Date: Sun, 16 Sep 2001 15:47:37 +0000 Subject: [PATCH] First version of CGI-based edit interface. This is very much a work-in-progress, and you can't actually use it to edit anything yet. You must #define FEATURE_CGI_EDIT_ACTIONS for these changes to have any effect. --- actionlist.h | 69 +++- actions.c | 108 +++++- actions.h | 8 +- cgi.c | 21 +- cgiedit.c | 503 ++++++++++++++++++++++++++++ cgiedit.h | 80 +++++ showargs.c | 13 +- templates/edit-actions | 397 ++++++++++++++++++++++ templates/edit-actions-list | 59 ++++ templates/edit-actions-list-section | 51 +++ templates/edit-actions-list-url | 8 + templates/edit-actions-submit | 23 ++ 12 files changed, 1318 insertions(+), 22 deletions(-) create mode 100644 cgiedit.c create mode 100644 cgiedit.h create mode 100644 templates/edit-actions create mode 100644 templates/edit-actions-list create mode 100644 templates/edit-actions-list-section create mode 100644 templates/edit-actions-list-url create mode 100644 templates/edit-actions-submit diff --git a/actionlist.h b/actionlist.h index cc65b2aa..626be452 100644 --- a/actionlist.h +++ b/actionlist.h @@ -39,6 +39,9 @@ * * Revisions : * $Log: actionlist.h,v $ + * Revision 1.5 2001/07/18 12:27:03 oes + * Changed deanimate-gifs to string action + * * Revision 1.4 2001/07/13 13:52:12 oes * - Formatting * - Introduced new action ACTION_DEANIMATE @@ -50,23 +53,53 @@ *********************************************************************/ -DEFINE_ACTION_MULTI ("add-header", ACTION_MULTI_ADD_HEADER) -DEFINE_ACTION_BOOL ("block", ACTION_BLOCK) -DEFINE_ACTION_STRING("deanimate-gifs", ACTION_DEANIMATE, ACTION_STRING_DEANIMATE) -DEFINE_ACTION_BOOL ("fast-redirects", ACTION_FAST_REDIRECTS) -DEFINE_ACTION_BOOL ("filter", ACTION_FILTER) -DEFINE_ACTION_BOOL ("hide-forwarded", ACTION_HIDE_FORWARDED) -DEFINE_ACTION_STRING("hide-from", ACTION_HIDE_FROM, ACTION_STRING_FROM) -DEFINE_ACTION_STRING("hide-referer", ACTION_HIDE_REFERER, ACTION_STRING_REFERER) -DEFINE_ACTION_STRING("hide-user-agent", ACTION_HIDE_USER_AGENT, ACTION_STRING_USER_AGENT) -DEFINE_ACTION_BOOL ("image", ACTION_IMAGE) -DEFINE_ACTION_STRING("image-blocker", ACTION_IMAGE_BLOCKER, ACTION_STRING_IMAGE_BLOCKER) -DEFINE_ACTION_BOOL ("no-cookies-read", ACTION_NO_COOKIE_READ) -DEFINE_ACTION_BOOL ("no-cookies-set", ACTION_NO_COOKIE_SET) -DEFINE_ACTION_BOOL ("no-popups", ACTION_NO_POPUPS) -DEFINE_ACTION_BOOL ("vanilla-wafer", ACTION_VANILLA_WAFER) -DEFINE_ACTION_MULTI ("wafer", ACTION_MULTI_WAFER) +#if !(defined(DEFINE_ACTION_BOOL) && defined(DEFINE_ACTION_MULTI) && defined(DEFINE_ACTION_STRING)) +#error Please define lots of macros before including "actionlist.h". +#endif /* !defined(all the DEFINE_ACTION_xxx macros) */ + +#ifndef DEFINE_CGI_PARAM_RADIO +#define DEFINE_CGI_PARAM_RADIO(name, bit, index, value, is_default) +#define DEFINE_CGI_PARAM_CUSTOM(name, bit, index, default_val) +#define DEFINE_CGI_PARAM_NO_RADIO(name, bit, index, default_val) +#endif /* ndef DEFINE_CGI_PARAM_RADIO */ + +DEFINE_ACTION_MULTI ("add-header", ACTION_MULTI_ADD_HEADER) +DEFINE_ACTION_BOOL ("block", ACTION_BLOCK) +DEFINE_ACTION_STRING ("deanimate-gifs", ACTION_DEANIMATE, ACTION_STRING_DEANIMATE) +DEFINE_CGI_PARAM_RADIO ("deanimate-gifs", ACTION_DEANIMATE, ACTION_STRING_DEANIMATE, "first", 0) +DEFINE_CGI_PARAM_RADIO ("deanimate-gifs", ACTION_DEANIMATE, ACTION_STRING_DEANIMATE, "last", 1) +DEFINE_ACTION_BOOL ("fast-redirects", ACTION_FAST_REDIRECTS) +DEFINE_ACTION_BOOL ("filter", ACTION_FILTER) +DEFINE_ACTION_BOOL ("hide-forwarded", ACTION_HIDE_FORWARDED) +DEFINE_ACTION_STRING ("hide-from", ACTION_HIDE_FROM, ACTION_STRING_FROM) +DEFINE_CGI_PARAM_RADIO ("hide-from", ACTION_HIDE_FROM, ACTION_STRING_FROM, "block", 1) +DEFINE_CGI_PARAM_CUSTOM ("hide-from", ACTION_HIDE_FROM, ACTION_STRING_FROM, "spam_me_senseless@sittingduck.xyz") +DEFINE_ACTION_STRING ("hide-referer", ACTION_HIDE_REFERER, ACTION_STRING_REFERER) +DEFINE_CGI_PARAM_RADIO ("hide-referer", ACTION_HIDE_REFERER, ACTION_STRING_REFERER, "forge", 1) +DEFINE_CGI_PARAM_RADIO ("hide-referer", ACTION_HIDE_REFERER, ACTION_STRING_REFERER, "block", 0) +DEFINE_CGI_PARAM_CUSTOM ("hide-referer", ACTION_HIDE_REFERER, ACTION_STRING_REFERER, "http://www.google.com/") +DEFINE_ACTION_STRING ("hide-user-agent", ACTION_HIDE_USER_AGENT, ACTION_STRING_USER_AGENT) +DEFINE_CGI_PARAM_NO_RADIO("hide-user-agent", ACTION_HIDE_USER_AGENT, ACTION_STRING_FROM, "JunkBuster/3.0 (Anonymized)") +DEFINE_ACTION_BOOL ("image", ACTION_IMAGE) +DEFINE_ACTION_STRING ("image-blocker", ACTION_IMAGE_BLOCKER, ACTION_STRING_IMAGE_BLOCKER) +DEFINE_CGI_PARAM_RADIO ("image-blocker", ACTION_IMAGE_BLOCKER, ACTION_STRING_IMAGE_BLOCKER, "logo", 1) +DEFINE_CGI_PARAM_RADIO ("image-blocker", ACTION_IMAGE_BLOCKER, ACTION_STRING_IMAGE_BLOCKER, "blank", 0) +DEFINE_CGI_PARAM_CUSTOM ("image-blocker", ACTION_IMAGE_BLOCKER, ACTION_STRING_IMAGE_BLOCKER, "http://") +DEFINE_ACTION_BOOL ("no-cookies-read", ACTION_NO_COOKIE_READ) +DEFINE_ACTION_BOOL ("no-cookies-set", ACTION_NO_COOKIE_SET) +DEFINE_ACTION_BOOL ("no-popups", ACTION_NO_POPUPS) +DEFINE_ACTION_BOOL ("vanilla-wafer", ACTION_VANILLA_WAFER) +DEFINE_ACTION_MULTI ("wafer", ACTION_MULTI_WAFER) #if DEFINE_ACTION_ALIAS -DEFINE_ACTION_BOOL ("no-popup", ACTION_NO_POPUPS) -DEFINE_ACTION_STRING("hide-referrer", ACTION_HIDE_REFERER, ACTION_STRING_REFERER) +DEFINE_ACTION_BOOL ("no-popup", ACTION_NO_POPUPS) +DEFINE_ACTION_STRING ("hide-referrer", ACTION_HIDE_REFERER, ACTION_STRING_REFERER) #endif /* if DEFINE_ACTION_ALIAS */ + +#undef DEFINE_ACTION_MULTI +#undef DEFINE_ACTION_STRING +#undef DEFINE_ACTION_BOOL +#undef DEFINE_ACTION_ALIAS +#undef DEFINE_CGI_PARAM_CUSTOM +#undef DEFINE_CGI_PARAM_RADIO +#undef DEFINE_CGI_PARAM_NO_RADIO + diff --git a/actions.c b/actions.c index 0bc413ad..a09f95a2 100644 --- a/actions.c +++ b/actions.c @@ -1,4 +1,4 @@ -const char actions_rcs[] = "$Id: actions.c,v 1.11 2001/09/14 00:17:32 jongfoster Exp $"; +const char actions_rcs[] = "$Id: actions.c,v 1.12 2001/09/16 13:21:27 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/actions.c,v $ @@ -33,6 +33,9 @@ const char actions_rcs[] = "$Id: actions.c,v 1.11 2001/09/14 00:17:32 jongfoster * * Revisions : * $Log: actions.c,v $ + * Revision 1.12 2001/09/16 13:21:27 jongfoster + * Changes to use new list functions. + * * Revision 1.11 2001/09/14 00:17:32 jongfoster * Tidying up memory allocation. New function init_action(). * @@ -87,6 +90,9 @@ const char actions_rcs[] = "$Id: actions.c,v 1.11 2001/09/14 00:17:32 jongfoster #include "miscutil.h" #include "errlog.h" #include "loaders.h" +#ifdef FEATURE_CGI_EDIT_ACTIONS +#include "encode.h" +#endif /* def FEATURE_CGI_EDIT_ACTIONS */ const char actions_h_rcs[] = ACTIONS_H_VERSION; @@ -655,6 +661,106 @@ char * actions_to_text(struct action_spec *action) } +#ifdef FEATURE_CGI_EDIT_ACTIONS +/********************************************************************* + * + * Function : actions_to_html + * + * Description : Converts a actionsfile entry from numeric form + * ("mask" and "add") to a
-seperated HTML string. + * + * Parameters : + * 1 : mask = As from struct url_actions + * 2 : add = As from struct url_actions + * + * Returns : A string. Caller must free it. + * + *********************************************************************/ +char * actions_to_html(struct action_spec *action) +{ + unsigned mask = action->mask; + unsigned add = action->add; + char * result = strdup(""); + char * enc_str; + struct list_entry * lst; + + /* sanity - prevents "-feature +feature" */ + mask |= add; + + +#define DEFINE_ACTION_BOOL(__name, __bit) \ + if (!(mask & __bit)) \ + { \ + result = strsav(result, "\n
-" __name); \ + } \ + else if (add & __bit) \ + { \ + result = strsav(result, "\n
+" __name); \ + } + +#define DEFINE_ACTION_STRING(__name, __bit, __index) \ + if (!(mask & __bit)) \ + { \ + result = strsav(result, "\n
-" __name); \ + } \ + else if (add & __bit) \ + { \ + result = strsav(result, "\n
+" __name "{"); \ + enc_str = html_encode(action->string[__index]);\ + result = strsav(result, enc_str); \ + freez(enc_str); \ + result = strsav(result, "}"); \ + } + +#define DEFINE_ACTION_MULTI(__name, __index) \ + if (action->multi_remove_all[__index]) \ + { \ + result = strsav(result, "\n
-" __name "{*}"); \ + } \ + else \ + { \ + lst = action->multi_remove[__index]->first; \ + while (lst) \ + { \ + result = strsav(result, "\n
-" __name "{");\ + enc_str = html_encode(lst->str); \ + result = strsav(result, enc_str); \ + freez(enc_str); \ + result = strsav(result, "}"); \ + lst = lst->next; \ + } \ + } \ + lst = action->multi_add[__index]->first; \ + while (lst) \ + { \ + result = strsav(result, "\n
+" __name "{"); \ + result = strsav(result, lst->str); \ + result = strsav(result, "}"); \ + lst = lst->next; \ + } + +#define DEFINE_ACTION_ALIAS 0 /* No aliases for output */ + +#include "actionlist.h" + +#undef DEFINE_ACTION_MULTI +#undef DEFINE_ACTION_STRING +#undef DEFINE_ACTION_BOOL +#undef DEFINE_ACTION_ALIAS + + /* trim leading
*/ + if (result && *result) + { + char * s = result; + result = strdup(result + 5); + free(s); + } + + return result; +} +#endif /* def FEATURE_CGI_EDIT_ACTIONS */ + + /********************************************************************* * * Function : current_actions_to_text diff --git a/actions.h b/actions.h index 63250b3b..c823a656 100644 --- a/actions.h +++ b/actions.h @@ -1,6 +1,6 @@ #ifndef ACTIONS_H_INCLUDED #define ACTIONS_H_INCLUDED -#define ACTIONS_H_VERSION "$Id: actions.h,v 1.2 2001/07/29 19:01:11 jongfoster Exp $" +#define ACTIONS_H_VERSION "$Id: actions.h,v 1.3 2001/09/14 00:17:32 jongfoster Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/actions.h,v $ @@ -35,6 +35,9 @@ * * Revisions : * $Log: actions.h,v $ + * Revision 1.3 2001/09/14 00:17:32 jongfoster + * Tidying up memory allocation. New function init_action(). + * * Revision 1.2 2001/07/29 19:01:11 jongfoster * Changed _FILENAME_H to FILENAME_H_INCLUDED. * Added forward declarations for needed structures. @@ -62,6 +65,9 @@ extern void merge_actions (struct action_spec *dest, extern void copy_action (struct action_spec *dest, const struct action_spec *src); extern char * actions_to_text (struct action_spec *action); +#ifdef FEATURE_CGI_EDIT_ACTIONS +extern char * actions_to_html (struct action_spec *action); +#endif /* def FEATURE_CGI_EDIT_ACTIONS */ extern void init_current_action (struct current_action_spec *dest); extern void free_current_action (struct current_action_spec *src); diff --git a/cgi.c b/cgi.c index ea63193e..de82743d 100644 --- a/cgi.c +++ b/cgi.c @@ -1,4 +1,4 @@ -const char cgi_rcs[] = "$Id: cgi.c,v 1.24 2001/09/16 11:38:01 jongfoster Exp $"; +const char cgi_rcs[] = "$Id: cgi.c,v 1.25 2001/09/16 15:02:35 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgi.c,v $ @@ -36,6 +36,10 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.24 2001/09/16 11:38:01 jongfoster Exp $"; * * Revisions : * $Log: cgi.c,v $ + * Revision 1.25 2001/09/16 15:02:35 jongfoster + * Adding i.j.b/robots.txt. + * Inlining add_stats() since it's only ever called from one place. + * * Revision 1.24 2001/09/16 11:38:01 jongfoster * Splitting fill_template() into 2 functions: * template_load() loads the file @@ -200,6 +204,9 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.24 2001/09/16 11:38:01 jongfoster Exp $"; #include "miscutil.h" #include "showargs.h" #include "loadcfg.h" +#ifdef FEATURE_CGI_EDIT_ACTIONS +#include "cgiedit.h" +#endif /* def FEATURE_CGI_EDIT_ACTIONS */ const char cgi_h_rcs[] = CGI_H_VERSION; @@ -219,6 +226,17 @@ const struct cgi_dispatcher cgi_dispatcher[] = { { "send-banner", 11, cgi_send_banner, "HIDE Send the transparent or \"Junkbuster\" gif" }, +#ifdef FEATURE_CGI_EDIT_ACTIONS + { "edit-actions-list", + 17, cgi_edit_actions_list, + "Edit the actions list" }, + { "edit-actions-submit", + 19, cgi_edit_actions_submit, + "HIDE Change the actions for (a) specified URL(s)" }, + { "edit-actions", + 12, cgi_edit_actions, + "HIDE Edit the actions for (a) specified URL(s)" }, +#endif /* def FEATURE_CGI_EDIT_ACTIONS */ { "", 0, cgi_default, "Junkbuster main page" }, @@ -311,6 +329,7 @@ struct http_response *dispatch_cgi(struct client_state *csp) return NULL; } + /* Remove leading slash */ if (*argstring == '/') { diff --git a/cgiedit.c b/cgiedit.c new file mode 100644 index 00000000..4b727c8f --- /dev/null +++ b/cgiedit.c @@ -0,0 +1,503 @@ +const char cgiedit_rcs[] = "$Id: cgi.c,v 1.25 2001/09/16 15:02:35 jongfoster Exp $"; +/********************************************************************* + * + * File : $Source: /cvsroot/ijbswa/current/cgiedit.c,v $ + * + * Purpose : CGI-based actionsfile editor. + * + * Functions declared include: + * + * + * Copyright : Written by and Copyright (C) 2001 the SourceForge + * IJBSWA team. http://ijbswa.sourceforge.net + * + * Based on the Internet Junkbuster originally written + * by and Copyright (C) 1997 Anonymous Coders and + * Junkbusters Corporation. http://www.junkbusters.com + * + * 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. + * + * The GNU General Public License should be included with + * this file. If not, you can view it at + * http://www.gnu.org/copyleft/gpl.html + * or write to the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Revisions : + * $Log: cgi.c,v $ + * + **********************************************************************/ + + +#include "config.h" + +/* + * FIXME: Following includes copied from cgi.c - which are actually needed? + */ + +#include +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#define snprintf _snprintf +#endif /* def _WIN32 */ + +#include "project.h" +#include "cgi.h" +#include "cgiedit.h" +#include "list.h" +#include "encode.h" +#include "ssplit.h" +#include "jcc.h" +#include "filters.h" +#include "actions.h" +#include "errlog.h" +#include "miscutil.h" +#include "showargs.h" +#include "loadcfg.h" + +const char cgiedit_h_rcs[] = CGIEDIT_H_VERSION; + + +#ifdef FEATURE_CGI_EDIT_ACTIONS + + +/********************************************************************* + * + * Function : cgi_edit_actions_list + * + * Description : CGI function that edits the actions list. + * + * Parameters : + * 1 : csp = Current client state (buffers, headers, etc...) + * 2 : rsp = http_response data structure for output + * 3 : parameters = map of cgi parameters + * + * CGI Parameters : None + * + * Returns : 0 + * + *********************************************************************/ +int cgi_edit_actions_list(struct client_state *csp, struct http_response *rsp, + struct map *parameters) +{ + struct file_list *fl; + struct url_actions *actions; + char * actions_html; + char * next_actions_html; + char * section_template; + char * url_template; + char * sections; + char * urls; + struct map * exports = default_exports(csp, NULL); + struct map * section_exports; + struct map * url_exports; + int urlid; + char buf[50]; + char * s; + int url_1_2; + + if (((fl = csp->actions_list) == NULL) || ((actions = fl->f) == NULL)) + { + /* FIXME: Oops, no file to edit */ + free_map(exports); + return cgi_default(csp, rsp, parameters); + } + + /* Should do all global exports above this point */ + + section_template = template_load(csp, "edit-actions-list-section"); + url_template = template_load(csp, "edit-actions-list-url"); + + template_fill(§ion_template, exports); + template_fill(&url_template, exports); + + urlid = 0; + sections = strdup(""); + + ++urlid; + actions = actions->next; + if (actions != NULL) + { + actions_html = actions_to_html(actions->action); + } + + while (actions != NULL) + { + section_exports = new_map(); + + snprintf(buf, 50, "%d", urlid); + map(section_exports, "sectionid", 1, buf, 1); + + map(section_exports, "actions", 1, actions_html, 1); + + /* Should do all section-specific exports above this point */ + + urls = strdup(""); + url_1_2 = 2; + + next_actions_html = NULL; + do + { + freez(next_actions_html); + + url_exports = new_map(); + + snprintf(buf, 50, "%d", urlid); + map(url_exports, "urlid", 1, buf, 1); + + snprintf(buf, 50, "%d", url_1_2); + map(url_exports, "url-1-2", 1, buf, 1); + + s = html_encode(actions->url->spec); + map(url_exports, "url", 1, s, 1); + + s = strdup(url_template); + template_fill(&s, section_exports); + template_fill(&s, url_exports); + urls = strsav(urls, s); + free_map(url_exports); + + ++urlid; + url_1_2 = 3 - url_1_2; + actions = actions->next; + if (actions) + { + next_actions_html = actions_to_html(actions->action); + } + } + while (actions && (0 == strcmp(actions_html, next_actions_html))); + + map(section_exports, "urls", 1, urls, 0); + + /* Could also do section-specific exports here, but it wouldn't be as fast */ + + s = strdup(section_template); + template_fill(&s, section_exports); + sections = strsav(sections, s); + free_map(section_exports); + + freez(actions_html); + actions_html = next_actions_html; + } + + map(exports, "sections", 1, sections, 0); + + /* Could also do global exports here, but it wouldn't be as fast */ + + rsp->body = template_load(csp, "edit-actions-list"); + template_fill(&rsp->body, exports); + free_map(exports); + + return(0); +} + + +/********************************************************************* + * + * Function : map_radio + * + * Description : Map a set of radio button values. E.g. if you have + * 3 radio buttons, declare them as: + *