1 const char killpopup_rcs[] = "$Id: killpopup.c,v 1.1 2001/05/13 21:57:06 administrator Exp $";
2 /*********************************************************************
4 * File : $Source: /home/administrator/cvs/ijb/killpopup.c,v $
6 * Purpose : Handles the filtering of popups.
8 * Copyright : Written by and Copyright (C) 2001 the SourceForge
9 * IJBSWA team. http://ijbswa.sourceforge.net
11 * Based on the Internet Junkbuster originally written
12 * by and Copyright (C) 1997 Anonymous Coders and
13 * Junkbusters Corporation. http://www.junkbusters.com
15 * This program is free software; you can redistribute it
16 * and/or modify it under the terms of the GNU General
17 * Public License as published by the Free Software
18 * Foundation; either version 2 of the License, or (at
19 * your option) any later version.
21 * This program is distributed in the hope that it will
22 * be useful, but WITHOUT ANY WARRANTY; without even the
23 * implied warranty of MERCHANTABILITY or FITNESS FOR A
24 * PARTICULAR PURPOSE. See the GNU General Public
25 * License for more details.
27 * The GNU General Public License should be included with
28 * this file. If not, you can view it at
29 * http://www.gnu.org/copyleft/gpl.html
30 * or write to the Free Software Foundation, Inc., 59
31 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 * $Log: killpopup.c,v $
36 *********************************************************************/
43 #include <sys/types.h>
55 #include "killpopup.h"
58 const char killpopup_h_rcs[] = KILLPOPUP_H_VERSION;
62 /* Change these for debug output. *lots*. */
63 /*#define POPUP_VERBOSE 1*/
64 /* CHANGED - added the below and shifted the more spammy stuff into it ;-) */
65 #undef POPUP_VERY_VERBOSE
69 /*********************************************************************
71 * Function : filter_popups
73 * Description : Filter the block of data that's been read from the server.
77 * 1 : csp = Client state
78 * 2 : host_name = hostname of originating web page to
79 * look up on blocklist
80 * 3 : buff = Buffer to scan and modify. Null terminated.
81 * 4 : size = Buffer size, excluding null terminator.
85 *********************************************************************/
86 void filter_popups(struct client_state *csp, char *host_name, char *buff, int size)
88 struct popup_settings * data;
89 struct popup_blocklist * cur;
95 char *q = NULL; /* by BREITENB NEW! */
97 if ( (!csp->plist) || ((data = csp->plist->f) == NULL) )
103 /* If the hostname is on our list for blocking then mark it
104 * as a host to block from. (This may be later changed if the
105 * host is also on the list-to-allow list).
108 for (i=0; (i < 50) && (i < size); i++) /* avoid scanning binary data! */
110 if ((unsigned int)(buff[i])>127)
113 fprintf(logfp, "I'm not scanning binary stuff! (%i)\n",buff[i]);
120 for (cur = data->blocked ; cur ; cur = cur->next)
122 if ( host_name != 0 )
124 if ( strcmp( cur->host_name, host_name ) == 0 )
127 fprintf(logfp, "Blocking %s\n", host_name );
134 /* Force match if we're supposed to nuke _all_ popups, globally. */
135 if ( kill_all_popups != 0 )
138 fprintf(logfp, "Indescriminatly nuking popups..\n" );
142 /* an exception-from blocking should still be an exception! by BREITENB NEW! */
145 /* Now, if its allowed adjust the filtering, so it _doesn't_ happen. */
146 for (cur = data->allowed ; cur ; cur = cur->next)
148 if ( host_name != 0 )
150 if ( strcmp( cur->host_name, host_name ) == 0 )
153 fprintf(logfp, "Reversing block decision for %s\n", host_name );
163 fprintf(logfp, "Allowing %s\n", host_name );
168 while ((popup = strstr( buff, "window.open(" )) != NULL)
169 /* if ( popup ) by BREITENB filter ALL popups! NEW! */
172 fprintf(logfp, "Found start of window open" );
174 close = strstr( popup+1, ");" );
178 fprintf(logfp, "Found end of window open" );
180 for ( p = popup; p != (close+1); p++ )
185 fprintf(logfp, "Blocked %s\n", host_name );
191 fprintf(logfp, "Couldn't find end, turned into comment. Read boundary?\n" );
199 q=popup; /* by BREITENB NEW! */
202 if (*q==' ' || *q=='\t')
208 if (*q=='=') *++q='1';
209 /* result of popup is assigned to a variable! ensure success. hehehe. */
213 /* Filter all other crap like onUnload onExit etc. (by BREITENB) NEW!*/
214 popup=strstr( buff, "<body");
215 if (!popup) popup=strstr( buff, "<BODY");
216 if (!popup) popup=strstr( buff, "<Body");
217 if (!popup) popup=strstr( buff, "<BOdy");
223 /* we are now between <body and the ending > */
224 p=strstr(popup, "onUnload");
229 p=strstr(popup, "onExit");
239 #endif /* def KILLPOPUPS */