asqredir - another squid redirect program
descriptionasqredir is a small, basic and fast redirect program for the almighty squid webcache. It can be used for filtering out advertisements from web sites or preventing proxy users to get certain files and redirect them to another url.
the url patterns and corresponding redirect urls are read into memory from a easy-to-maintain plaintext file on startup, when asqredir is invoked as redirect program by squid. asqredir is easy to configure and run, optional logging is available.
asqredir's redirect logic is based on urls only, it does not recognize ad banners by their image properties or similar. basically it is useful for you if you want redirects to happen based on matched url patterns.
asqredir is written in c and consists of one small source file offering the tiny functionality needed. it has been tested to run and perform well on openbsd and gnu/linux and should basically compile and run on any posix compliant system. see history for a list of changes since previous versions.
downloadyou can download the package asqredir-0.3.tar.gz containing the necessary files, or get asqredir.c and the files below individually.
installing asqredirchange to the directory where you downloaded the package and unpack it:
gzip -dc asqredir-0.3.tar.gz | tar xvf -
adapt the makefile if necessary and type:
to install the binary and a default url file to /usr/local/asqredir type:
of course you can compile the source on your own or select your own locations for the binary and the url file. just invoke asqredir accordingly.
editing the url filea sample url file is delivered with the distribution and copied to /usr/local/asqredir/urls.txt by default. in order to filter requests through asqredir you need to specify the rules in this file.
some sample rules are included but all of them are commented out by default. the url file consists of lines which either
url_pattern describes the pattern which should be matched in the request line in order to cause the desired action (pass or deny). url_pattern can be a substring or the whole url and you can use regular expressions to describe it, but you don't need to if you don't want. In other words, even if you do use regexp for your urls you don't have to care about consuming the whole string. By the way, using regexp (such as putting a "^" in front of "http" certainly helps to optimize the matches but is not necessary for correct operations.
# all requests for urls containing the string "/adclick/" are redirected:
# same for string "/admanager/":
# always allow requests with the following pattern:
# always redirect "event.ng" requests, but this time to a html file:
# this is another comment
testing asqredircall asqredir interactively by typing
where the optional argument is the path to the url file in case it's not installed in the default location.
now type a http request like squid would pass it for a non-blocked site:
http://www.slashdot.org 192.168.25.132 - GET
the output should be an empty new line. next, enter a url matching a pattern from your url file:
http://www.adsite.com/admanager/ad.gif 192.168.25.132 - GET
this should give you back the redirect url configured for the pattern wrapped up in the old request, such as:
http://my.local.web/empty.gif 192.168.25.132 - GET
test the non-blocked url again, see the blank new line again and continue installing :)
configuring squidyou have to specify asqredir as redirect_program in the squid config file (usually squid.conf):
redirect_program /usr/local/asqredir/asqredir /path/to/asqredir/urls.txt
maybe you'd like to change the amount of redirect processes squid forks, depending on your site's traffic:
if you make changes to the url file and want them to take effect, you can restart asqredir by reconfiguring squid:
squid -k reconfigure
all asqredir processes terminate on squid's shutdown or reconfiguration, so you don't have to worry (anymore) about killing them manually.
how it worksif asqredir is configured as redirect_program in squid.conf, squid will pipe all requests it gets through it.
every request coming from squid to asqredir has got the following format:
url src_address ident method
http://www.someurl.com/index.html 192.168.45.122 - GET
asqredir compares the url part against a set of regular expressions previously read into memory from a file. if there's a match for a pass rule, an empty string is given back to squid to indicate that no redirect should happen. if there's a match for a deny rule, the url is rewritten to the value specified in the url file. the client_address, ident and method values are passed out as they came in and the whole string is returned to squid. if there's no match, asqredir just returns an empty string to squid.
creditsspecial thanks go out to jb, ls and eduardo perez for their valuable feedback on previous versions of asqredir, to the squid people for their great product and to my project team mate arno for his great support.
why I wrote another redirect plugin... instead of using one of the many already available packages serving the same purpose:
related sitessquid web proxy cache
squid related software page
licenseasqredir 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.
Thomas Zippo <
thomas at zippo dot ch