#!perl use HTTP::Proxy; my $port=8080; # initialisation my $proxy = HTTP::Proxy->new( port => $port ); # this is a MainLoop-like method print "Running proxy on port $port\n"; $proxy->start; #### #!perl use strict; use HTTP::Proxy; use HTTP::Proxy::Engine; use HTTP::Proxy::Engine::NoFork; use HTTP::Proxy::HeaderFilter::simple; my $port=8080; my %Allowed=( 'pbskids.org' => 1, 'www.basgetti.com' => 1, 'disney.com' => 1, ); my $proxy = HTTP::Proxy->new( port => $port ); $proxy->push_filter ( request => HTTP::Proxy::HeaderFilter::simple->new( sub { my ($self, $headers, $message) = @_; my $host=$headers->{host}; $host=lc(strip($host)); my $uhost=getUniqueHost($host); $uhost=lc(strip($uhost)); my $allow=$Allowed{$host} || $Allowed{$uhost} || 0; if(!$allow && $host !~/localhost$/is){ print "$host not allowed\n"; $headers->{host} = "localhost"; $headers->{cookie} = ''; } }) ); print "Running proxy on port $port\n"; $proxy->start; ######################### sub getUniqueHost{ my $inhost=shift || return; my $uhost; if($inhost=~/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/){$uhost=$inhost;} elsif($inhost=~/([A-Z0-9\-]+)\.([A-Z0-9\-]+)\.([A-Z0-9\-]+)/is){$uhost=$2 . '.' . $3;} else{$uhost=$inhost;} $uhost=lc($uhost); return $uhost; } ############### sub strip{ my $str=shift; if(length($str)==0){return;} $str=~s/^[\r\n\s\t]+//s; $str=~s/[\r\n\s\t]+$//s; return $str; }