Rewritten to Perl to cure the slowness
[redirector-ad.git] / redirector
1 #! /usr/bin/perl
2 #
3 # $Id$
4
5 use strict;
6 use warnings;
7
8 use constant DIR_AD => "/usr/local/squid/etc/ad";
9
10
11 chdir DIR_AD or die "chdir ".DIR_AD.": $!";
12
13 my($patt)="";
14 open(M4,"-|","m4 -P main") or die "m4 run: $!";
15 while (<M4>) {
16         chomp;
17         next if !$_;
18         $patt.="|" if $patt;
19         $patt.=$_;
20         }
21 close M4;
22
23 select STDOUT;
24 $|=1;
25
26 while (<>) {
27         s@^http://($patt).*\n$@http://localhost/cgi-bin/redirector-ad.cgi?$1\n@os;
28         print;
29         }