BannerAds Blocker is a rule based HTTP blocking application which can be utilised to avoid downloading banner adverts found on many web pages. The core components of BannerAds blocker are a series of PHP scripts to allow management of a database of banner ad urls to block and a perl script which interfaces the squid proxy with this banner database and blocks advert images as squid tries to fetch them.
The application was developed on FreeBSD 2.2.7-RELEASE, Apache 1.3.3 with PHP 3.0.6, mySQL 3.21.33b, perl 5.004_04. What version of the DBI and mySQL drivers I don't know.
It is currently running on FreeBSD 3.3-RELEASE, Apache 1.3.9 - PHP 3.0.12, MySQL 3.22.27, Perl 5.005_03, p5-DBI-1.06 and p5-Mysql 1.2016 perl modules.
Some parts of BannerAds blocker are based on the squid banner ads blocker at http://www.taz.net.au/block/index.html
- Create a directory on the web server and put the *.php and *.html files there.
- Create a MySQL database called bannerads and populate using the supplied bannerads.sql script and mysqldump
- Create a database user banner with password banner and make sure this user has permission to access the database from localhost.
- Place the db.redir script in a directory somewhere near squid. (like /usr/local/squid/)
- Modify squid.conf file to include the path to the db.redir program in the redirector section and the number of child processes to include.
excerpt from squid.conf...
# TAG: redirect_program
# Specify the location of the executable for the URL redirector.
# Since they can perform almost any function there isn't one included.
# See the Release-Notes for information on how to write one.
# By default, a redirector is not used.
# TAG: redirect_children
# The number of redirector processes to spawn. If you start
# too few Squid will have to wait for them to process a backlog of
# URLs, slowing it down. If you start too many they will use RAM
# and other system resources.
- Restart squid and watch everything break as you realise the permissions on the DB are screwwy.
DISCLAIMER OF WARRANTY
THIS SOFTWARE AND THE ACCOMPANYING FILES ARE PROVIDED "AS IS" AND
WITHOUT WARRANTIES OF ANY KIND WHETHER EXPRESSED OR IMPLIED.
In no event shall the author be held liable for any damages whatsoever,
including without limitation, damages for loss of business profits,
business interruption, loss of business information, or any other loss
arising from the use or inability to use the software.
Contact firstname.lastname@example.org with suggestions.
The latest version of the BannerAds Blocker will be available from
This solution was in place on my FreeBSD 2.2.7 machine for over 9 months and has now been on FreeBSD 3.3 for two months without (m)any problems. Documentation is sparce, I may sometime in the future do more but probably not...
- Redirectors will exit on certain URLs containing whitespaces (www.microsoft.com does this alot!). Squid has the flag uri_whitespace in the conf file to deal with this kind of thing. I've set this to encode, and also upped the number of redirectors from 3 to 9. It still occasionally happens. Perhaps error handling and logging needs to be enhanced in the perl script. When squid runs out of redirectors is has a bit of a panic and restarts another 9 of them, which is nice..
- Web front end has some quirks when editing existing records. The wild cards .* are re-appended. I'm sure its a quick fix but I've get to find the time to do it. A workaround is on editing an existing entry, remove the leading and trailing wildcard and save.
- Oh, the web front end is ugly as sin... I've been meaning to tidy it up for over a year now, but its not gonna happen soon. Sorry...
- A set of GRANT statements so DB config is automatic would be nice. However, its so long since I did it, even I'm not sure what the right permissions are.
- I have received a report of pages which have had a banner ad blocked causing a segfault in NS. I haven't managed to replicate it myself in NS for windows or X. However these are the steps that have been reported to cause it.
- - Go to webpage with banners
- - Copy img location.
- - New window > goto banneradmin
- - go to db edit, add new rec, paste in offending url, replacing file with wildcard.
- - refresh webpage.
- - nutscrape segfaults!