Introduced modular filters
authoroes <oes@users.sourceforge.net>
Tue, 12 Mar 2002 01:42:50 +0000 (01:42 +0000)
committeroes <oes@users.sourceforge.net>
Tue, 12 Mar 2002 01:42:50 +0000 (01:42 +0000)
actionlist.h
filters.c
ijb.action
jcc.c
loaders.c
project.h
re_filterfile
templates/edit-actions-for-url

index 056ccf9..577c982 100644 (file)
@@ -39,6 +39,9 @@
  *
  * Revisions   :
  *    $Log: actionlist.h,v $
  *
  * Revisions   :
  *    $Log: actionlist.h,v $
+ *    Revision 1.10  2002/03/08 18:19:14  jongfoster
+ *    Adding +image-blocker{pattern} option to edit interface
+ *
  *    Revision 1.9  2001/11/22 21:58:41  jongfoster
  *    Adding action +no-cookies-keep
  *
  *    Revision 1.9  2001/11/22 21:58:41  jongfoster
  *    Adding action +no-cookies-keep
  *
@@ -86,7 +89,7 @@ DEFINE_CGI_PARAM_RADIO   ("deanimate-gifs",  ACTION_DEANIMATE,       ACTION_STRI
 DEFINE_CGI_PARAM_RADIO   ("deanimate-gifs",  ACTION_DEANIMATE,       ACTION_STRING_DEANIMATE,     "last",  1)
 DEFINE_ACTION_BOOL       ("downgrade",       ACTION_DOWNGRADE)
 DEFINE_ACTION_BOOL       ("fast-redirects",  ACTION_FAST_REDIRECTS)
 DEFINE_CGI_PARAM_RADIO   ("deanimate-gifs",  ACTION_DEANIMATE,       ACTION_STRING_DEANIMATE,     "last",  1)
 DEFINE_ACTION_BOOL       ("downgrade",       ACTION_DOWNGRADE)
 DEFINE_ACTION_BOOL       ("fast-redirects",  ACTION_FAST_REDIRECTS)
-DEFINE_ACTION_BOOL       ("filter",          ACTION_FILTER)
+DEFINE_ACTION_MULTI      ("filter",          ACTION_MULTI_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_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)
index b703e1d..256b0c9 100644 (file)
--- a/filters.c
+++ b/filters.c
@@ -1,4 +1,4 @@
-const char filters_rcs[] = "$Id: filters.c,v 1.44 2002/03/07 03:49:31 oes Exp $";
+const char filters_rcs[] = "$Id: filters.c,v 1.45 2002/03/08 16:47:50 oes Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/filters.c,v $
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/filters.c,v $
@@ -38,6 +38,9 @@ const char filters_rcs[] = "$Id: filters.c,v 1.44 2002/03/07 03:49:31 oes Exp $"
  *
  * Revisions   :
  *    $Log: filters.c,v $
  *
  * Revisions   :
  *    $Log: filters.c,v $
+ *    Revision 1.45  2002/03/08 16:47:50  oes
+ *    Added choice beween GIF and PNG built-in images
+ *
  *    Revision 1.44  2002/03/07 03:49:31  oes
  *     - Fixed compiler warnings etc
  *     - Changed built-in images from GIF to PNG
  *    Revision 1.44  2002/03/07 03:49:31  oes
  *     - Fixed compiler warnings etc
  *     - Changed built-in images from GIF to PNG
@@ -1188,16 +1191,17 @@ int is_untrusted_url(struct client_state *csp)
  *
  * Function    :  pcrs_filter_response
  *
  *
  * Function    :  pcrs_filter_response
  *
- * Description :  Apply all the pcrs jobs from the joblist (re_filterfile)
- *                to the text buffer that's been accumulated in
- *                csp->iob->buf and set csp->content_length to the modified
- *                size and raise the CSP_FLAG_MODIFIED flag if appropriate.
+ * Description :  Ecexute all text substitutions from all applying
+ *                +filter actions on the text buffer that's been accumulated
+ *                in csp->iob->buf. If this changes the contents, set
+ *                csp->content_length to the modified size and raise the
+ *                CSP_FLAG_MODIFIED flag.
  *
  * Parameters  :
  *          1  :  csp = Current client state (buffers, headers, etc...)
  *
  * Returns     :  a pointer to the (newly allocated) modified buffer.
  *
  * Parameters  :
  *          1  :  csp = Current client state (buffers, headers, etc...)
  *
  * Returns     :  a pointer to the (newly allocated) modified buffer.
- *                or NULL in case something went wrong
+ *                or NULL if there were no hits or something went wrong
  *
  *********************************************************************/
 char *pcrs_filter_response(struct client_state *csp)
  *
  *********************************************************************/
 char *pcrs_filter_response(struct client_state *csp)
@@ -1210,14 +1214,23 @@ char *pcrs_filter_response(struct client_state *csp)
 
    struct file_list *fl;
    struct re_filterfile_spec *b;
 
    struct file_list *fl;
    struct re_filterfile_spec *b;
+   struct list_entry *filtername;
 
 
-   /* Sanity first */
+   /* 
+    * Sanity first
+    */
    if (csp->iob->cur >= csp->iob->eod)
    {
       return(NULL);
    }
    size = csp->iob->eod - csp->iob->cur;
 
    if (csp->iob->cur >= csp->iob->eod)
    {
       return(NULL);
    }
    size = csp->iob->eod - csp->iob->cur;
 
+   if ( ( NULL == (fl = csp->rlist) ) || ( NULL == fl->f) )
+   {
+      log_error(LOG_LEVEL_ERROR, "Unable to get current state of regexp filtering.");
+      return(NULL);
+   }
+
    /*
     * If the body has a "chunked" transfer-encoding,
     * get rid of it first, adjusting size and iob->eod
    /*
     * If the body has a "chunked" transfer-encoding,
     * get rid of it first, adjusting size and iob->eod
@@ -1233,31 +1246,40 @@ char *pcrs_filter_response(struct client_state *csp)
       csp->flags |= CSP_FLAG_MODIFIED;
    }
 
       csp->flags |= CSP_FLAG_MODIFIED;
    }
 
-   if ( ( NULL == (fl = csp->rlist) ) || ( NULL == (b = fl->f) ) )
+   /*
+    * For all applying +filter actions, look if a filter by that
+    * name exists and if yes, execute it's pcrs_joblist on the
+    * buffer.
+    */
+   for (b = fl->f; b; b = b->next)
    {
    {
-      log_error(LOG_LEVEL_ERROR, "Unable to get current state of regexp filtering.");
-      return(NULL);
-   }
+      for (filtername = csp->action->multi[ACTION_MULTI_FILTER]->first;
+           filtername ; filtername = filtername->next)
+      {
+         if (strcmp(b->filtername, filtername->str) == 0)
+         {
+            if ( NULL == b->joblist )
+            {
+               log_error(LOG_LEVEL_RE_FILTER, "Filter %s has empty joblist. Nothing to do.", b->filtername);
+               return(NULL);
+            }
 
 
-   if ( NULL == b->joblist )
-   {
-      log_error(LOG_LEVEL_RE_FILTER, "Empty joblist. Nothing to do.");
-      return(NULL);
-   }
+            log_error(LOG_LEVEL_RE_FILTER, "re_filtering %s%s (size %d) with filter %s...",
+                      csp->http->hostport, csp->http->path, size, b->filtername);
 
 
-   log_error(LOG_LEVEL_RE_FILTER, "re_filtering %s%s (size %d) ...",
-              csp->http->hostport, csp->http->path, size);
+            /* Apply all jobs from the joblist */
+            for (job = b->joblist; NULL != job; job = job->next)
+            {
+               hits += pcrs_execute(job, old, size, &new, &size);
+               if (old != csp->iob->cur) free(old);
+               old=new;
+            }
 
 
-   /* Apply all jobs from the joblist */
-   for (job = b->joblist; NULL != job; job = job->next)
-   {
-      hits += pcrs_execute(job, old, size, &new, &size);
-      if (old != csp->iob->cur) free(old);
-      old=new;
+            log_error(LOG_LEVEL_RE_FILTER, " ...produced %d hits (new size %d).", hits, size);
+         }
+      }
    }
 
    }
 
-   log_error(LOG_LEVEL_RE_FILTER, " produced %d hits (new size %d).", hits, size);
-
    /*
     * If there were no hits, destroy our copy and let
     * chat() use the original in csp->iob
    /*
     * If there were no hits, destroy our copy and let
     * chat() use the original in csp->iob
index 3adb659..77d2740 100644 (file)
@@ -3,7 +3,7 @@
 #
 # For information, see http://ijbswa.sourceforge.net/
 #
 #
 # For information, see http://ijbswa.sourceforge.net/
 #
-# $Id: ijb.action,v 1.6 2002/03/08 17:25:52 oes Exp $
+# $Id: ijb.action,v 1.7 2002/03/08 18:01:48 morcego Exp $
 #
 #############################################################################
 # Syntax
 #
 #############################################################################
 # Syntax
 #    request and send a local redirect back to your browser without
 #    contacting the remote site.
 #
 #    request and send a local redirect back to your browser without
 #    contacting the remote site.
 #
-# +filter
-#    Filter the website through the re_filterfile
-#    FIXME: The syntax should be +filter{filename}
+# +filter{name}
+#    Filter the website through one or more regular expression filters.
+#    Repeat for multiple filters.
+#   
+#    Filters predefined in the supplied re_filterfile include:
+#
+#     html-annoyances:  Get rid of particularly annoying HTML abuse
+#     js-annoyances:    Get rid of particularly annoying JavaScript abuse
+#     no-poups:         Kill all popups in JS and HTML
+#     frameset-borders: Give frames a border
+#     webbugs:          Squish WebBugs (1x1 invisible GIFs used for user tracking)
+#     no-refresh:       Automatic refresh sucks on auto-dialup lines
+#     fun:              Text replacements  for subversive browsing fun!
+#     nimda:            Remove (virus) Nimda code.
+#     banners-by-size:  Kill banners by size
+#     crude-parental:   Kill all web pages that contain the words "sex" or "warez"
+#
 #
 # +hide-forwarded
 #    Block any existing X-Forwarded-for header, and do not add a new one.
 #
 # +hide-forwarded
 #    Block any existing X-Forwarded-for header, and do not add a new one.
 +no-cookies = +no-cookies-set +no-cookies-read
 -no-cookies = -no-cookies-set -no-cookies-read
 +imageblock = +block +image
 +no-cookies = +no-cookies-set +no-cookies-read
 -no-cookies = -no-cookies-set -no-cookies-read
 +imageblock = +block +image
-+filter-all = +filter +no-compression
 
 # Fragile sites should have the minimum changes
 fragile     = -block -deanimate-gifs -fast-redirects -filter -hide-referer -no-cookies -no-popups
 
 # Fragile sites should have the minimum changes
 fragile     = -block -deanimate-gifs -fast-redirects -filter -hide-referer -no-cookies -no-popups
@@ -325,6 +338,11 @@ fragile     = -block -deanimate-gifs -fast-redirects -filter -hide-referer -no-c
 # Shops should be allowed to set persistent cookies
 shop        = -filter -no-cookies -no-cookies-keep
 
 # Shops should be allowed to set persistent cookies
 shop        = -filter -no-cookies -no-cookies-keep
 
+# Your favourite blend of filters:
+#
+myfilters   = +filter{html-annoyances} +filter{js-annoyances} +filter{no-popups}\
+              +filter{webbugs} +filter{nimda} +filter{banners-by-size}
+
 #... etc.  Customize to your heart's content.
 
 #############################################################################
 #... etc.  Customize to your heart's content.
 
 #############################################################################
@@ -336,7 +354,7 @@ shop        = -filter -no-cookies -no-cookies-keep
 -deanimate-gifs \
 -downgrade \
 +fast-redirects \
 -deanimate-gifs \
 -downgrade \
 +fast-redirects \
-+filter \
+myfilters \
 +no-compression \
 +no-cookies-keep \
 +hide-forwarded \
 +no-compression \
 +no-cookies-keep \
 +hide-forwarded \
diff --git a/jcc.c b/jcc.c
index 88db8b7..0997ef8 100644 (file)
--- a/jcc.c
+++ b/jcc.c
@@ -1,4 +1,4 @@
-const char jcc_rcs[] = "$Id: jcc.c,v 1.79 2002/03/09 20:03:52 jongfoster Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.80 2002/03/11 22:07:05 david__schmidt Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jcc.c,v $
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jcc.c,v $
@@ -33,6 +33,12 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.79 2002/03/09 20:03:52 jongfoster Exp $";
  *
  * Revisions   :
  *    $Log: jcc.c,v $
  *
  * Revisions   :
  *    $Log: jcc.c,v $
+ *    Revision 1.80  2002/03/11 22:07:05  david__schmidt
+ *    OS/2 port maintenance:
+ *    - Fixed EMX build - it had decayed a little
+ *    - Fixed inexplicable crash during FD_ZERO - must be due to a bad macro.
+ *      substituted a memset for now.
+ *
  *    Revision 1.79  2002/03/09 20:03:52  jongfoster
  *    - Making various functions return int rather than size_t.
  *      (Undoing a recent change).  Since size_t is unsigned on
  *    Revision 1.79  2002/03/09 20:03:52  jongfoster
  *    - Making various functions return int rather than size_t.
  *      (Undoing a recent change).  Since size_t is unsigned on
@@ -944,7 +950,7 @@ static void chat(struct client_state *csp)
 #endif /* def FEATURE_KILL_POPUPS */
 
    pcrs_filter                = (csp->rlist != NULL) &&  /* There are expressions to be used */
 #endif /* def FEATURE_KILL_POPUPS */
 
    pcrs_filter                = (csp->rlist != NULL) &&  /* There are expressions to be used */
-                                ((csp->action->flags & ACTION_FILTER) != 0);
+                                (!list_is_empty(csp->action->multi[ACTION_MULTI_FILTER]));
 
    gif_deanimate              = ((csp->action->flags & ACTION_DEANIMATE) != 0);
 
 
    gif_deanimate              = ((csp->action->flags & ACTION_DEANIMATE) != 0);
 
index 585ab75..7036158 100644 (file)
--- a/loaders.c
+++ b/loaders.c
@@ -1,4 +1,4 @@
-const char loaders_rcs[] = "$Id: loaders.c,v 1.39 2002/03/07 03:46:17 oes Exp $";
+const char loaders_rcs[] = "$Id: loaders.c,v 1.40 2002/03/08 17:46:04 jongfoster Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/loaders.c,v $
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/loaders.c,v $
@@ -35,6 +35,9 @@ const char loaders_rcs[] = "$Id: loaders.c,v 1.39 2002/03/07 03:46:17 oes Exp $"
  *
  * Revisions   :
  *    $Log: loaders.c,v $
  *
  * Revisions   :
  *    $Log: loaders.c,v $
+ *    Revision 1.40  2002/03/08 17:46:04  jongfoster
+ *    Fixing int/size_t warnings
+ *
  *    Revision 1.39  2002/03/07 03:46:17  oes
  *    Fixed compiler warnings
  *
  *    Revision 1.39  2002/03/07 03:46:17  oes
  *    Fixed compiler warnings
  *
@@ -1091,7 +1094,8 @@ load_trustfile_error:
  *
  * Function    :  unload_re_filterfile
  *
  *
  * Function    :  unload_re_filterfile
  *
- * Description :  Unload the re_filter list.
+ * Description :  Unload the re_filter list by freeing all chained
+ *                re_filterfile specs and their data.
  *
  * Parameters  :
  *          1  :  f = the data structure associated with the filterfile.
  *
  * Parameters  :
  *          1  :  f = the data structure associated with the filterfile.
@@ -1101,27 +1105,31 @@ load_trustfile_error:
  *********************************************************************/
 static void unload_re_filterfile(void *f)
 {
  *********************************************************************/
 static void unload_re_filterfile(void *f)
 {
-   struct re_filterfile_spec *b = (struct re_filterfile_spec *)f;
+   struct re_filterfile_spec *a, *b = (struct re_filterfile_spec *)f;
 
 
-   if (b == NULL)
+   while (b != NULL)
    {
    {
-      return;
-   }
+      a = b->next;
 
 
-   destroy_list(b->patterns);
-   pcrs_free_joblist(b->joblist);
-   freez(b);
+      destroy_list(b->patterns);
+      pcrs_free_joblist(b->joblist);
+      freez(b);
+
+      b = a;
+   }
 
    return;
 }
 
 
    return;
 }
 
+
 /*********************************************************************
  *
  * Function    :  load_re_filterfile
  *
 /*********************************************************************
  *
  * Function    :  load_re_filterfile
  *
- * Description :  Load the re_filterfile. Each non-comment, non-empty
- *                line is instantly added to the joblist, which is
- *                a chained list of pcrs_job structs.
+ * Description :  Load the re_filterfile. 
+ *                Generate a chained list of re_filterfile_spec's from
+ *                the "FILTER: " blocks, compiling all their substitutions
+ *                into chained lists of pcrs_job structs.
  *
  * Parameters  :
  *          1  :  csp = Current client state (buffers, headers, etc...)
  *
  * Parameters  :
  *          1  :  csp = Current client state (buffers, headers, etc...)
@@ -1133,7 +1141,7 @@ int load_re_filterfile(struct client_state *csp)
 {
    FILE *fp;
 
 {
    FILE *fp;
 
-   struct re_filterfile_spec *bl;
+   struct re_filterfile_spec *bl, *new_bl;
    struct file_list *fs;
 
    char  buf[BUFFER_SIZE];
    struct file_list *fs;
 
    char  buf[BUFFER_SIZE];
@@ -1141,9 +1149,11 @@ int load_re_filterfile(struct client_state *csp)
    unsigned long linenum = 0;
    pcrs_job *dummy;
 
    unsigned long linenum = 0;
    pcrs_job *dummy;
 
+   /*
+    * No need to reload if unchanged
+    */
    if (!check_file_changed(current_re_filterfile, csp->config->re_filterfile, &fs))
    {
    if (!check_file_changed(current_re_filterfile, csp->config->re_filterfile, &fs))
    {
-      /* No need to load */
       if (csp)
       {
          csp->rlist = current_re_filterfile;
       if (csp)
       {
          csp->rlist = current_re_filterfile;
@@ -1155,46 +1165,87 @@ int load_re_filterfile(struct client_state *csp)
       goto load_re_filterfile_error;
    }
 
       goto load_re_filterfile_error;
    }
 
+   /*
+    * Allocate the first re_filterfile_spec struct
+    */
    fs->f = bl = (struct re_filterfile_spec  *)zalloc(sizeof(*bl));
    if (bl == NULL)
    {
       goto load_re_filterfile_error;
    }
 
    fs->f = bl = (struct re_filterfile_spec  *)zalloc(sizeof(*bl));
    if (bl == NULL)
    {
       goto load_re_filterfile_error;
    }
 
-   /* Open the file or fail */
+   /*
+    * Initialize the name in case there are
+    * expressions before the first block header
+    */
+   bl->filtername = "default";
+
+   /* 
+    * Open the file or fail
+    */
    if ((fp = fopen(csp->config->re_filterfile, "r")) == NULL)
    {
       goto load_re_filterfile_error;
    }
 
    if ((fp = fopen(csp->config->re_filterfile, "r")) == NULL)
    {
       goto load_re_filterfile_error;
    }
 
-   /* Read line by line */
+   /* 
+    * Read line by line
+    */
    while (read_config_line(buf, sizeof(buf), fp, &linenum) != NULL)
    {
    while (read_config_line(buf, sizeof(buf), fp, &linenum) != NULL)
    {
-      enlist( bl->patterns, buf );
+      /*
+       * If this is the head of a new filter block, make it a
+       * re_filterfile spec of its own and chain it to the list:
+       */
+      if (strncmp(buf, "FILTER:", 7) == 0)
+      {
+         new_bl = (struct re_filterfile_spec  *)zalloc(sizeof(*bl));
+         if (new_bl == NULL)
+         {
+            goto load_re_filterfile_error;
+         }
+         else
+         {
+            new_bl->filtername = strdup(chomp(buf + 7));
+            bl->next = new_bl;
+            bl = new_bl;
+         }
+         continue;
+      }
+
+      /* 
+       * Else, save the expression, make it a pcrs_job
+       * and chain it into the current filter's joblist 
+       */
+      enlist(bl->patterns, buf);
 
 
-      /* We have a meaningful line -> make it a job */
       if ((dummy = pcrs_compile_command(buf, &error)) == NULL)
       {
          log_error(LOG_LEVEL_RE_FILTER,
       if ((dummy = pcrs_compile_command(buf, &error)) == NULL)
       {
          log_error(LOG_LEVEL_RE_FILTER,
-               "Adding re_filter job %s failed with error %d.", buf, error);
+               "Adding re_filter job %s to filter %s failed with error %d.", buf, bl->filtername, error);
          continue;
       }
       else
       {
          dummy->next = bl->joblist;
          bl->joblist = dummy;
          continue;
       }
       else
       {
          dummy->next = bl->joblist;
          bl->joblist = dummy;
-         log_error(LOG_LEVEL_RE_FILTER, "Adding re_filter job %s succeeded.", buf);
+         log_error(LOG_LEVEL_RE_FILTER, "Adding re_filter job %s to filter %s succeeded.", buf, bl->filtername);
       }
    }
 
    fclose(fp);
 
       }
    }
 
    fclose(fp);
 
-   /* the old one is now obsolete */
+   /* 
+    * Schedule the now-obsolete old data for unloading
+    */
    if ( NULL != current_re_filterfile )
    {
       current_re_filterfile->unloader = unload_re_filterfile;
    }
 
    if ( NULL != current_re_filterfile )
    {
       current_re_filterfile->unloader = unload_re_filterfile;
    }
 
+   /*
+    * Chain this file into the global list of loaded files
+    */
    fs->next    = files->next;
    files->next = fs;
    current_re_filterfile = fs;
    fs->next    = files->next;
    files->next = fs;
    current_re_filterfile = fs;
index aed21f0..8625265 100644 (file)
--- a/project.h
+++ b/project.h
@@ -1,6 +1,6 @@
 #ifndef PROJECT_H_INCLUDED
 #define PROJECT_H_INCLUDED
 #ifndef PROJECT_H_INCLUDED
 #define PROJECT_H_INCLUDED
-#define PROJECT_H_VERSION "$Id: project.h,v 1.53 2002/03/08 16:48:55 oes Exp $"
+#define PROJECT_H_VERSION "$Id: project.h,v 1.54 2002/03/09 20:03:52 jongfoster Exp $"
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/project.h,v $
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/project.h,v $
  *
  * Revisions   :
  *    $Log: project.h,v $
  *
  * Revisions   :
  *    $Log: project.h,v $
+ *    Revision 1.54  2002/03/09 20:03:52  jongfoster
+ *    - Making various functions return int rather than size_t.
+ *      (Undoing a recent change).  Since size_t is unsigned on
+ *      Windows, functions like read_socket that return -1 on
+ *      error cannot return a size_t.
+ *
+ *      THIS WAS A MAJOR BUG - it caused frequent, unpredictable
+ *      crashes, and also frequently caused JB to jump to 100%
+ *      CPU and stay there.  (Because it thought it had just
+ *      read ((unsigned)-1) == 4Gb of data...)
+ *
+ *    - The signature of write_socket has changed, it now simply
+ *      returns success=0/failure=nonzero.
+ *
+ *    - Trying to get rid of a few warnings --with-debug on
+ *      Windows, I've introduced a new type "jb_socket".  This is
+ *      used for the socket file descriptors.  On Windows, this
+ *      is SOCKET (a typedef for unsigned).  Everywhere else, it's
+ *      an int.  The error value can't be -1 any more, so it's
+ *      now JB_INVALID_SOCKET (which is -1 on UNIX, and in
+ *      Windows it maps to the #define INVALID_SOCKET.)
+ *
+ *    - The signature of bind_port has changed.
+ *
  *    Revision 1.53  2002/03/08 16:48:55  oes
  *    Added FEATURE_NO_GIFS and BUILTIN_IMAGE_MIMETYPE
  *
  *    Revision 1.53  2002/03/08 16:48:55  oes
  *    Added FEATURE_NO_GIFS and BUILTIN_IMAGE_MIMETYPE
  *
@@ -622,20 +646,19 @@ struct iob
 #define ACTION_DEANIMATE       0x00000002UL
 #define ACTION_DOWNGRADE       0x00000004UL
 #define ACTION_FAST_REDIRECTS  0x00000008UL
 #define ACTION_DEANIMATE       0x00000002UL
 #define ACTION_DOWNGRADE       0x00000004UL
 #define ACTION_FAST_REDIRECTS  0x00000008UL
-#define ACTION_FILTER          0x00000010UL
-#define ACTION_HIDE_FORWARDED  0x00000020UL
-#define ACTION_HIDE_FROM       0x00000040UL
-#define ACTION_HIDE_REFERER    0x00000080UL /* sic - follow HTTP, not English */
-#define ACTION_HIDE_USER_AGENT 0x00000100UL
-#define ACTION_IMAGE           0x00000200UL
-#define ACTION_IMAGE_BLOCKER   0x00000400UL
-#define ACTION_NO_COMPRESSION  0x00000800UL
-#define ACTION_NO_COOKIE_KEEP  0x00001000UL
-#define ACTION_NO_COOKIE_READ  0x00002000UL
-#define ACTION_NO_COOKIE_SET   0x00004000UL
-#define ACTION_NO_POPUPS       0x00008000UL
-#define ACTION_VANILLA_WAFER   0x00010000UL
-#define ACTION_LIMIT_CONNECT   0x00020000UL
+#define ACTION_HIDE_FORWARDED  0x00000010UL
+#define ACTION_HIDE_FROM       0x00000020UL
+#define ACTION_HIDE_REFERER    0x00000040UL /* sic - follow HTTP, not English */
+#define ACTION_HIDE_USER_AGENT 0x00000080UL
+#define ACTION_IMAGE           0x00000100UL
+#define ACTION_IMAGE_BLOCKER   0x00000200UL
+#define ACTION_NO_COMPRESSION  0x00000400UL
+#define ACTION_NO_COOKIE_KEEP  0x00000800UL
+#define ACTION_NO_COOKIE_READ  0x00001000UL
+#define ACTION_NO_COOKIE_SET   0x00002000UL
+#define ACTION_NO_POPUPS       0x00004000UL
+#define ACTION_VANILLA_WAFER   0x00008000UL
+#define ACTION_LIMIT_CONNECT   0x00010000UL
 
 #define ACTION_STRING_DEANIMATE     0
 #define ACTION_STRING_FROM          1
 
 #define ACTION_STRING_DEANIMATE     0
 #define ACTION_STRING_FROM          1
@@ -647,7 +670,9 @@ struct iob
 
 #define ACTION_MULTI_ADD_HEADER     0
 #define ACTION_MULTI_WAFER          1
 
 #define ACTION_MULTI_ADD_HEADER     0
 #define ACTION_MULTI_WAFER          1
-#define ACTION_MULTI_COUNT          2
+#define ACTION_MULTI_FILTER         2
+#define ACTION_MULTI_COUNT          3
+
 
 /*
  * This structure contains a list of actions to apply to a URL.
 
 /*
  * This structure contains a list of actions to apply to a URL.
@@ -896,12 +921,18 @@ struct forward_spec
 #define FORWARD_SPEC_INITIALIZER { { URL_SPEC_INITIALIZER }, 0, NULL, 0, NULL, 0, NULL }
 
 
 #define FORWARD_SPEC_INITIALIZER { { URL_SPEC_INITIALIZER }, 0, NULL, 0, NULL, 0, NULL }
 
 
+/*
+ * This struct represents one filter (one block) from
+ * the re_filterfile. If there is more than one filter
+ * in the file, the file will be represented by a
+ * chained list of re_filterfile specs.
+ */
 struct re_filterfile_spec
 {
 struct re_filterfile_spec
 {
-   char *username;
-   char *filtername;
-   struct list patterns[1];
-   pcrs_job *joblist;
+   char *filtername;                /* Name from FILTER: statement in re_filterfile (or "default") */
+   struct list patterns[1];         /* The patterns from the re_filterfile */
+   pcrs_job *joblist;               /* The resulting compiled pcrs_jobs */
+   struct re_filterfile_spec *next; /* The pointer for chaining */
 };
 
 #ifdef FEATURE_ACL
 };
 
 #ifdef FEATURE_ACL
index 9240220..29cb922 100644 (file)
@@ -27,6 +27,9 @@
 # 
 #  Revisions   :
 #     $Log: re_filterfile,v $
 # 
 #  Revisions   :
 #     $Log: re_filterfile,v $
+#     Revision 1.19  2002/03/10 19:49:24  oes
+#     Added expression to kill referer tracking in JavaScripts
+#
 #     Revision 1.18  2002/03/08 17:14:12  oes
 #     PNG -> image in comments
 #
 #     Revision 1.18  2002/03/08 17:14:12  oes
 #     PNG -> image in comments
 #
 #
 #
 # 
 #
 #
 # 
-# ********************************************************************/
+
+#################################################################################
+#
+# Syntax:
+#
+# Filters start with a line "FILTER: name". They are then referrable
+# from the actionsfile with +filter{name}
+#
+# Inside the filters, write one Perl-Style substitution per line.
+#
+# For Details see the pcrs manpage contained in this distribution.
+# (and the perlre, perlop and pcre manpages)
 #
 #
-# Syntax: One Perl-Style substitution per line.
-# For Details see the perlre, perlop and pcre manpages.
 # Note that you are free to choose the delimter as you see fit.
 #
 # Note that you are free to choose the delimter as you see fit.
 #
-# Note: In addidion to the Perl options egimosx, the following nonstandard
+# Note2: In addidion to the Perl options gimsx, the following nonstandard
 # options are supported:
 # 
 # 'U' turns the default to ungreedy matching.  Add ? to quantifiers to
 # options are supported:
 # 
 # 'U' turns the default to ungreedy matching.  Add ? to quantifiers to
 #     Use if you want to include text like '$&' in your substitute without
 #     quoting.
 # 
 #     Use if you want to include text like '$&' in your substitute without
 #     quoting.
 # 
+#################################################################################
+
 
 
-# ********************************************************************/
+#################################################################################
 #
 #
-# Kill OnUnload popups. Yummy.
-# check it out on http://www.zdnet.com/zdsubs/yahoo/tree/yfs.html
+# html-annoyances: Get rid of particularly annoying HTML abuse
 #
 #
-# ********************************************************************/
-s/(<body .*?)onunload(.*?>)/$1never$2/i
+#################################################################################
+FILTER: html-annoyances
 
 
-# ********************************************************************/
+# New browser windows should be resizeable and have a location and status bar
 #
 #
-# Kill refresh tags. I like to refresh myself. Manually.
-# check it out on http://www.airport-cgn.de/ and go to the arrivals page.
+s/resizable="?(no|0)"?/resizable=1/ig s/noresize/yesresize/ig
+s/location="?(no|0)"?/location=1/ig s/status="?(no|0)"?/status=1/ig
+s/scrolling="?(no|0|Auto)"?/scrolling=1/ig
+s/menubar="?(no|0)"?/menubar=1/ig 
+
+# The <BLINK> tag was a crime!
 #
 #
-# ********************************************************************/
-# only if content value isn't 0..1
-# FIXME: second line like first line for content value
-s/<meta[^>]*http-equiv[^>]*refresh.*([0-9]+[0-9]|"[2-9]);URL=([^>]*?)"?>/<link rev="x-refresh" href=$2>/i
-s/<meta[^>]*http-equiv="?page-enter"?[^>]*content=[^>]*>/<!--no page enter for me-->/i
+s*<blink>|</blink>**ig
+
+# Is this evil? 
+#
+#s/framespacing="?(no|0)"?//ig
+#s/margin(height|width)=[0-9]*//gi
 
 
-# ********************************************************************/
+
+#################################################################################
 #
 #
-# If I allow popups, I want them to be resizeable and have a location
-# and status bar: check it out on http://www.airport-cgn.de/ and go to
-# the arrivals page.
+# js-annoyances: Get rid of particularly annoying JavaScript abuse
 #
 #
-# ********************************************************************/
-# s/resizable="?(no|0)"?/resizable=1/ig s/noresize/yesresize/ig
-# s/location="?(no|0)"?/location=1/ig s/status="?(no|0)"?/status=1/ig
-# s/scrolling="?(no|0|Auto)"?/scrolling=1/ig
-# s/menubar="?(no|0)"?/menubar=1/ig #s/framespacing="?(no|0)"?//ig
-# #s/margin(height|width)=[0-9]*//gi
+#################################################################################
+FILTER: js-annoyances
 
 
-# ********************************************************************/
+# JS cookies, like found on privacy.net:
 #
 #
-# Remove frameborder=0 and border=0 from framesets
+s|(document\.cookie)([ \t\r\n]*=)|documenZapCooky$2|g
+
+# Get rid of Javascript referrer tracking. Test page: http://www.randomoddness.com/untitled.htm
 #
 #
-# ********************************************************************/
+s|(<script.*)document\.referrer(.*</script>)|$1"Not Your Business!"$2|Usg
+
+# The status bar is for displaying link targets, not pointless blahblah
+#
+s/status='.*?';*//ig
+
+# Kill OnUnload popups. Yummy. Test: http://www.zdnet.com/zdsubs/yahoo/tree/yfs.html
+#
+s/(<body .*)onunload(.*>)/$1never$2/iU
+
+
+##################################################################################
+#
+# no-poups: Kill all popups in JS and HTML
+#
+#################################################################################
+FILTER: no-poups
+
+s/window\.open\(/1;''\.concat\(/ig      # JavaScript
+s/target=['"]?_blank['"]?/target_who/g  # HTML
+
+
+#################################################################################
+#
+# frameset-borders: Give frames a border
+#
+#################################################################################
+FILTER: frameset-borders
+
 s/(<frameset[^>]+?)border=['"]?(no|0)['"]?/$1/ig
 s/(<frameset[^>]+?)frameborder=['"]?(no|0)['"]?/$1/ig
 
 s/(<frameset[^>]+?)border=['"]?(no|0)['"]?/$1/ig
 s/(<frameset[^>]+?)frameborder=['"]?(no|0)['"]?/$1/ig
 
-# ********************************************************************/
+
+#################################################################################
 #
 #
-# The status bar is for displaying link targets, not pointless descriptions.
-# Again, check it out on http://www.airport-cgn.de/
+# webbugs: Squish WebBugs (1x1 invisible GIFs used for user tracking)
 #
 #
-# ********************************************************************/
-s/status='.*?';*//ig
+#################################################################################
+FILTER: webbugs
 
 
-# ********************************************************************/
+s/<img\s+[^>]*?(width|height)\s*=\s*['"]?1\D[^>]*?(width|height)\s*=\s*['"]?1(\D[^>]*?)?>/<!-- Squished WebBug -->/sig
+
+
+#################################################################################
 #
 #
-# Get rid of Javascript cookies, like found on privacy.net:
+# no-refresh: Automatic refresh sucks on auto-dialup lines
 #
 #
-# ********************************************************************/
+#################################################################################
+FILTER: no-refresh
+
+# FIXME: second line like first line for content value
+#
+s/<meta[^>]*http-equiv[^>]*refresh.*([0-9]+[0-9]|"[2-9]);URL=([^>]*?)"?>/<link rev="x-refresh" href=$2>/i
+s/<meta[^>]*http-equiv="?page-enter"?[^>]*content=[^>]*>/<!--no page enter for me-->/i
+
+
+#################################################################################
+#
+# fun: Text replacements for subversive browsing fun!
+#
+#################################################################################
+FILTER: fun
+
+s/microsoft(?!.com)/MicroSuck/ig
+
+# Buzzword Bingo:
+#
+s/industry-leading|cutting-edge|award-winning/<font color=red><b>BINGO!</b></font>/ig
 
 
-s|(document\.cookie)([ \t\r\n]*=)|documenZapCooky$2|g
 
 
-# ********************************************************************/
+#################################################################################
 #
 #
-# Get rid of Javascript referrer tracking: (http://www.randomoddness.com/untitled.htm)
+# nimda: Remove Nimda (virus) code
 #
 #
-# ********************************************************************/
+#################################################################################
+FILTER: nimda
+
+s%<script language="JavaScript">(window\.open|1;''\.concat)\("readme\.eml", null, "resizable=no,top=6000,left=6000"\)</script>%<br><hr><font size=7><b>Internet J</b></font><b><font size=6>UNK</font><font size=5 color="red"><i>BUSTER</i></font></b><font size=7> WARNING: This Server is infected with <a href="http://www.cert.org/advisories/CA-2001-26.html">Nimda</a>!</font>%g
 
 
-s|(<script.*)document\.referrer(.*</script>)|$1"NotYourBusiness!"$2|Usg
 
 
-# ********************************************************************/
+#################################################################################
 #
 #
-# Kill *all* popups a la popup.c. (But for *all* sites, so I wouldn't do that.)
+# banners-by-size: Kill banners by size
 #
 #
-# JavaScript: s/window\.open\(/1;''\.concat\(/ig
-# HTML      : s/target=['"]?_blank['"]?/target_who/g
+#################################################################################
+#
+# Standard banner sizes taken from http://www.iab.net/iab_banner_standards/bannersizes.html
 #
 #
-# Kill banners by size:
-# (Sizes from http://www.iab.net/iab_banner_standards/bannersizes.html)
 # Note: Use http://ijbswa.sourceforge.net/config/send-banner?type=trans for a transparent 1x1 image
 #       Use http://ijbswa.sourceforge.net/config/send-banner?type=logo  for the logo image
 #       Use http://ijbswa.sourceforge.net/config/send-banner?type=logo  for a grey/white pattern image
 #       Use http://ijbswa.sourceforge.net/config/send-banner?type=auto  to auto-select.
 # Note: Use http://ijbswa.sourceforge.net/config/send-banner?type=trans for a transparent 1x1 image
 #       Use http://ijbswa.sourceforge.net/config/send-banner?type=logo  for the logo image
 #       Use http://ijbswa.sourceforge.net/config/send-banner?type=logo  for a grey/white pattern image
 #       Use http://ijbswa.sourceforge.net/config/send-banner?type=auto  to auto-select.
-# ********************************************************************/
+#
+#################################################################################
+FILTER: banners-by-size
+
 s|<img\s+[^>]*?(width=['"]?468\D)[^>]*(height=['"]?60[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
 s|<img\s+[^>]*?(width=['"]?234\D)[^>]*(height=['"]?60[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
 s|<img\s+[^>]*?(width=['"]?88\D)[^>]*(height=['"]?31[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
 s|<img\s+[^>]*?(width=['"]?468\D)[^>]*(height=['"]?60[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
 s|<img\s+[^>]*?(width=['"]?234\D)[^>]*(height=['"]?60[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
 s|<img\s+[^>]*?(width=['"]?88\D)[^>]*(height=['"]?31[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
@@ -182,39 +251,23 @@ s|<img\s+[^>]*?(width=['"]?250\D)[^>]*(height=['"]?250[^>]*?)>|<img src=http://i
 s|<img\s+[^>]*?(width=['"]?240\D)[^>]*(height=['"]?400[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
 s|<img\s+[^>]*?(width=['"]?336\D)[^>]*(height=['"]?280[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
 
 s|<img\s+[^>]*?(width=['"]?240\D)[^>]*(height=['"]?400[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
 s|<img\s+[^>]*?(width=['"]?336\D)[^>]*(height=['"]?280[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
 
-# Where is that from?
+# One more. (Where is 200x50 from?)
+#
 s|<img\s+[^>]*?(width=['"]?200\D)[^>]*(height=['"]?50[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
 
 s|<img\s+[^>]*?(width=['"]?200\D)[^>]*(height=['"]?50[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
 
-# ********************************************************************/
-#
-# Squish WebBugs:
-#
-# ********************************************************************/
-s/<img\s+[^>]*?(width|height)\s*=\s*['"]?1\D[^>]*?(width|height)\s*=\s*['"]?1(\D[^>]*?)?>/<!-- Squished WebBug -->/sig
 
 
-# ********************************************************************/
-#
-# Fun stuff
+#################################################################################
 #
 #
-# ********************************************************************/
-#s/microsoft(?!.com)/MicroSuck/ig
-
-# ********************************************************************/
+# crude-parental: Crude parental filtering?  (Use along with a suitable blocklist).
+#                 Shows how to deny access to whole page based on a keyword.
 #
 #
-# Crude parental filtering?  (Use along with a suitable blocklist).
-# Shows how to deny access to whole page based on a keyword.
+#################################################################################
 #
 # (Note: Middlesex, Sussex and Essex are counties in the UK, not rude words)
 # (Note #2: Is 'sex' a rude word?!)
 #
 #
 # (Note: Middlesex, Sussex and Essex are counties in the UK, not rude words)
 # (Note #2: Is 'sex' a rude word?!)
 #
-#s%^.*(?<!middle)(?<!sus)(?<!es)sex.*$%<html><head><title>Blocked</title></head><body><h3>Blocked due to possible adult content. Please see <a href="http://dmoz.org/Kids_and_Teens/">this site</a>.</h3></body></html>%is
-#s+^.*warez.*$+<html><head><title>No Warez</title></head><body><h3>You're not searching for illegal stuff, are you?</h3></body></html>+is
-
-# ********************************************************************/
-#
-# Remove Nimda code.
-#
-# ********************************************************************/
-s%<script language="JavaScript">(window\.open|1;''\.concat)\("readme\.eml", null, "resizable=no,top=6000,left=6000"\)</script>%<br><hr><font size=7><b>Internet J</b></font><b><font size=6>UNK</font><font size=5 color="red"><i>BUSTER</i></font></b><font size=7> WARNING: This Server is infected with <a href="http://www.cert.org/advisories/CA-2001-26.html">Nimda</a>!</font>%g
-
+#################################################################################
+FILTER: crude-parental
 
 
+s%^.*(?<!middle)(?<!sus)(?<!es)sex.*$%<html><head><title>Blocked</title></head><body><h3>Blocked due to possible adult content. Please see <a href="http://dmoz.org/Kids_and_Teens/">this site</a>.</h3></body></html>%is
+s+^.*warez.*$+<html><head><title>No Warez</title></head><body><h3>You're not searching for illegal stuff, are you?</h3></body></html>+is
index 222fb36..eb69443 100644 (file)
@@ -32,6 +32,9 @@
 #
 # Revisions   :
 #    $Log: edit-actions-for-url,v $
 #
 # Revisions   :
 #    $Log: edit-actions-for-url,v $
+#    Revision 1.11  2002/03/08 18:19:14  jongfoster
+#    Adding +image-blocker{pattern} option to edit interface
+#
 #    Revision 1.10  2002/03/03 10:29:12  swa
 #    point users to the right feedback forms,
 #    not necessarily the developer list.
 #    Revision 1.10  2002/03/03 10:29:12  swa
 #    point users to the right feedback forms,
 #    not necessarily the developer list.
@@ -221,6 +224,18 @@ function show_deanimate_opts(tf)
     target.style.display = (tf ? "" : "none");
 }
 
     target.style.display = (tf ? "" : "none");
 }
 
+function show_filter_opts(tf)
+{
+    if (document.getElementById) {
+        target = document.getElementById("filter_opts");
+    } else if (document.all) {
+        target = document.filter_opts;
+    } else {
+        return;
+    }
+    target.style.display = (tf ? "" : "none");
+}
+
 function show_hide_from_opts(tf)
 {
     if (document.getElementById) {
 function show_hide_from_opts(tf)
 {
     if (document.getElementById) {
@@ -443,16 +458,22 @@ href="http://sourceforge.net/mail/?group_id=11118">mailing lists</a>.
     </tr>
     <tr class="bg2" align="left" valign="top">
       <td class="action">+filter</td>
     </tr>
     <tr class="bg2" align="left" valign="top">
       <td class="action">+filter</td>
-      <td>Filter the website through the re_filterfile</td>
+      <td>Filter the website through one or more regular expression filters.</td>
       <td class="en2" align="center" valign="middle"><input type="radio"
       <td class="en2" align="center" valign="middle"><input type="radio"
-        name="filter" value="Y" @filter-y@
-        ></td>
+        name="filter" id="filter_y" value="Y" @filter-y@
+        onclick="show_filter_opts(true)"></td>
       <td class="dis2" align="center" valign="middle"><input type="radio"
       <td class="dis2" align="center" valign="middle"><input type="radio"
-        name="filter" value="N" @filter-n@ 
-        ></td>
+        name="filter" id="filter_n" value="N" @filter-n@
+        onclick="show_filter_opts(false)"></td>
       <td class="noc2" align="center" valign="middle"><input type="radio"
       <td class="noc2" align="center" valign="middle"><input type="radio"
-        name="filter" value="X" @filter-x@
-         ></td>
+        name="filter" id="filter_x" value="X" @filter-x@
+        onclick="show_filter_opts(false)"></td>
+    </tr>
+    <tr class="bg2" align="left" valign="top" id="filter_opts">
+      <td>&nbsp;</td>
+      <td colspan="4">Editing the settings for this option, or turning
+        it on if it was off, is not yet supported using this web-based
+        editor.</td>
     </tr>
     <tr class="bg1" align="left" valign="top">
       <td class="action">+hide-forwarded</td>
     </tr>
     <tr class="bg1" align="left" valign="top">
       <td class="action">+hide-forwarded</td>