#!/usr/bin/perl # $Id: gen.squid.redir,v 1.16 2000/12/19 23:05:01 root Exp root $ # generate a perl script from a redir 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. # *** Do *NOT* use my server taz.net.au as the base url. # *** # *** Copy the dot.gif, closeme.html, and do_nothing.js # *** files to the DocRoot of your own web server. # *** # *** THIS MEANS YOU. $BASE_URL="//YOUR SERVER HERE" ; $BLANK="$BASE_URL/dot.gif" ; $CLOSEME="$BASE_URL/closeme.html" ; $NULLJS="$BASE_URL/do_nothing.js" ; $BLANK =~ s:/:\\\/:g ; $CLOSEME =~ s:/:\\\/:g ; $NULLJS =~ s:/:\\\/:g ; print '#! /usr/bin/perl $|=1 ; while (<>) { chop ; # URL ip-address/fqdn ident method ($url, $address, $ident, $method) = split ; $orig=$url ; SWITCH: { '; $B="" ; $C="" ; $N="" ; while (<>) { chomp ; s/#.*// ; next if (/^$/) ; s:/:\\\/:og ; ($s,$r) = split ; if ($r eq "BLANK" ) { $B .= "$s|" ; next } ; if ($r eq "CLOSEME" ) { $C .= "$s|" ; next } ; if ($r eq "NULLJS" ) { $N .= "$s|" ; next } ; print ' last SWITCH if ($url =~ ' . "s/$s/$r/io" . ') ;' . "\n" ; } ; # trim off trailing | characters chop $B ; chop $C ; chop $N ; if ( $B ) { print ' last SWITCH if ($url =~ ' . "s/($B)/$BLANK/io" . ') ;' . "\n" ; } ; if ( $C ) { print ' last SWITCH if ($url =~ ' . "s/($C)/$CLOSEME/io" . ') ;' . "\n" ; } ; if ( $N ) { print ' last SWITCH if ($url =~ ' . "s/($N)/$NULLJS/io" . ') ;' . "\n" ; } ; print "\n # end switch\n };\n" ; print ' print $url if ( $url ne $orig ) ;' . "\n"; print ' print "\n" ;' ; print "\n# end while\n}\n" ;