[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Banner exchange



On Wed, 18 Feb 1998, Behan Webster wrote:

> > steve, if you don't like banner ads and if you run the squid proxy
> > server, take a look at my banner blocker.
> >
> > http://www.taz.net.au/block/
> >
> > the web site hasn't been updated in ages, so the version of the
> > redirector script on there is old (my new one doesn't tie a hash db
> > file, it generates a perl script to do the redirection whenever the
> > redir db is updated....*MUCH* faster, and more flexible). oh yeah,
> > i'm also using a transparent 1 pixel gif as the substitute graphic
> > now.
>
> When you first posted about this, I setup our squid server in a
> similar fashion.  I too have modified your script extensively, but we
> use a 32x32 grey gif.  That is just so there is something to fill the
> spot that would normally be an ad, and sinde it's all one color it can
> be forced to whatever size without looking strange.

the one pixel gif works nicely.  all banner ads (that i've seen) have width
and height tags so the 1 pixel gif gets stretched appropriately.  

> Our script also allows people to opt out from having ads blocked.  One
> of the guys here really wanted to see the ads (I know, I don't quite
> understand this either, but there you are).

I'd implement this by running a second squid. either on a separate
machine, or on the same machine with a different config file on a
different port. in both cases, the banner blocking squid would have only
a tiny (under 100mb) cache and use the main cache as the parent,

I've done exactly this for a site that needs extensive filtering of
pornography and games and chat sites etc (for schools).  The main
squid has no filtering, it's job is to cache stuff...it needs lots of
memory and lots of disk.  The filtering proxy doesn't cache, it just
filters...it needs fast cpu but not much disk or ram.


> I would love to see your current incarnation of your script, and would
> be happy to post ours if you'd like to see it.

I'd be very interested in seeing your version.  There may be some
improvements/ideas I can add into mine.

Here's my latest version.  This one reads in the redir file and
generates a perl script on stdout.  The big advantage is that it is
MUCH faster - I can use the /o option on the regexps so they are
compiled only once at load time, not every time they are used.  Not that
important on a small squid proxy but very important on a heavily hit
one.  It is also implemented as a switch type statement, which speeds it
up a little.

A minor improvement is that I don't have to type the full URL for the
substitute graphic on each line of the redir file - the generator
recognises "BLANK" as shorthand for it.


---cut here---
#!/usr/bin/perl

# generate a perl script from a redir textfile database. redir is fed in
# on stdin, perl script is printed on stdout.
#
# run like so:
#	./gen.squid.redir redir >squid.redir
#	chmod +x squid.redir
#	/etc/init.d/squid reload
#
# put that in a Makefile.

#$BLANK="//taz.net.au/blank_ad.gif" ;
$BLANK="//taz.net.au/dot.gif" ;
$BLANK =~ s:/:\\\/:g ;

print '#! /usr/bin/perl

$|=1 ;

while (<>) {
  chop ;
  # URL ip-address/fqdn ident method
  ($url, $address, $ident, $method) = split ;
  SWITCH: {
';

while (<>) {
	chomp ;
	s/#.*// ;
	next if (/^$/) ;
	s:/:\\\/:og ;
	($s,$r) = split /\s+/;
	$r = $BLANK if ($r eq "BLANK" ) ;
	print '    if ($url =~ ' . "s/$s/$r/io" . ') { ' ;
	print 'print $url ; last SWITCH ' ;
	print "}\n" ;
} ;
print "\n  # end switch\n  }\n" ;
print '  print "\n" ;' ;
print "\n# end while\n}\n" ;
---cut here---


here's a small example of it in action.  a tiny sample of my redir file...

---input file --- cut here ---
# comment and blank lines are ignored

# url regexp                                    redirection
# --------------------------------------------- ------------
//.*excite.com/img/ads/.*                       BLANK
//.*four11.com/g/ads/.*                         BLANK
//.*apcmag.com/ads/.*                           BLANK
//www.geocities.com/cgi-bin-local/GeoAD?.*      //www.geocities.com/cgi-bin-local/GeoAD?kill.your.damned.javascript!!!
---input file --- cut here ---

note that the input file is still generic. you can redirect anything to
anything else, it just recognises the "BLANK" keyword as a convenience.

The geocities redirection doesn't actually prevent that annoying popup
window from appearing. i'd have to use muffin or disable javascript
entirely to do that. what it does do is prevent an ad from appearing in
the window and puts a message in their log file.

they'll notice it when they do their stats/billing run :-). But they'll
probably ignore it :-(.

if more people do the same redirection, they might even do something
about it.


--- output squid.redir ---
#! /usr/bin/perl

$|=1 ;

while (<>) {
  chop ;
  # URL ip-address/fqdn ident method
  ($url, $address, $ident, $method) = split ;
  SWITCH: {
    if ($url =~ s/\/\/.*excite.com\/img\/ads\/.*/\/\/taz.net.au\/dot.gif/io) { print $url ; last SWITCH }
    if ($url =~ s/\/\/.*four11.com\/g\/ads\/.*/\/\/taz.net.au\/dot.gif/io) { print $url ; last SWITCH }
    if ($url =~ s/\/\/.*apcmag.com\/ads\/.*/\/\/taz.net.au\/dot.gif/io) { print $url ; last SWITCH }
    if ($url =~ s/\/\/www.geocities.com\/cgi-bin-local\/GeoAD?.*/\/\/www.geocities.com\/cgi-bin-local\/GeoAD?kill.your.damned.javascript!!!/io) { print $url ; last SWITCH }
  # end switch
  }
  print "\n" ;
# end while
}
--- output squid.redir ---




I run this using a Makefile

---cut here --- Makefile ---
#! /usr/bin/make -f

all: stamp-restart

squid.redir:    redir gen.squid.redir
        ./gen.squid.redir redir > squid.redir
        chmod +x squid.redir

stamp-restart: squid.redir
        /etc/init.d/squid reload
        touch stamp-restart
---cut here --- Makefile ---

so all i have to do is 'vi redir' and then type 'make'.


> Thanks for the great idea!  It makes certain heavily ad laden pages load
> considerably faster over our 28.8 Internet link.
> 
> > one of these days i'll redo the web site. i suppose i should make a
> > debian package of this too.
> 
> That would be great!

I've decided I'm going to clean up the script and package it.  But
it brings up a few questions. the redir db should be renamed to
/etc/squid/redir or something like that, but where do i put the
generated perl script? /usr/lib/squid/squid.redir is what i am doing
now....but a package shouldn't assume that /usr is rw, it might be
mounted ro. would /var/lib/squid be appropriate?

I should also make the BLANK keyword shortcut more generic.  use a config
file called /etc/squid/redir.shortcuts or something.  then users won't
have to edit the script to customise the blank ad location.


> > animated gifs are an abomination.
> 
> I like animated gifs, but not as ads.  Then they are extremely annoying!

i could ignore the banner ads until they started animating them. that
was too much. distracts from the content (an unforgiveable crime). so i
did something about it :-)


craig

--
craig sanders


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-devel-request@lists.debian.org . 
Trouble?  e-mail to templin@bucknell.edu .


Reply to: