From f8f9ed9346b75496e177854f5480e9ba62ee38b0 Mon Sep 17 00:00:00 2001 From: dpavlin Date: Tue, 24 Nov 2009 20:39:31 +0100 Subject: [PATCH] add proxy.pac on admin interface --- proxy.pl | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/proxy.pl b/proxy.pl index 80a546a..5c076b1 100755 --- a/proxy.pl +++ b/proxy.pl @@ -9,7 +9,17 @@ use HTTP::Proxy::BodyFilter::save; use HTTP::Proxy::BodyFilter::simple; use HTTP::Proxy::HeaderFilter::simple; +our $info = { + debug => 1, + direct => [ qw/ +imageserver.ebscohost.com + / ], +}; +use Data::Dump qw(dump); + +# # logger.pl +# use CGI::Util qw( unescape ); @@ -119,7 +129,9 @@ else { $proxy->push_filter( response => $get_filter, mime => $args{mime} ); } +# # pdf.pl +# my $saved; $proxy->push_filter( @@ -153,6 +165,66 @@ $proxy->push_filter( ), ); +# +# admin interface +# + +my $admin_filter = HTTP::Proxy::HeaderFilter::simple->new( sub { + my ( $self, $headers, $message ) = @_; +warn "XXX ", $headers->header('x-forwarded-for'), ' ', $message->uri, "\n"; + + return unless $message->uri->host eq $proxy->host; + + $info->{debug} = not $info->{debug} if $message->uri->query =~ m{debug}; + warn "## ", dump( $headers, $message ) if $info->{debug}; + + my $host_port = $proxy->host . ':' . $proxy->port; + + my $res = HTTP::Response->new( 200 ); + + if ( $message->uri->path =~ m/(proxy.pac|wpad.dat)/ ) { + $res->content_type('application/x-ns-proxy-autoconfig'); + $res->content(qq| + +function FindProxyForURL(url, host) { +// if (shExpMatch(url, "*.example.com:*/*")) {return "DIRECT";} + + if (shExpMatch(url, "*.js")) return "DIRECT"; + if (shExpMatch(url, "*.css")) return "DIRECT"; + if (shExpMatch(url, "*.gif")) return "DIRECT"; + if (shExpMatch(url, "*.png")) return "DIRECT"; + if (shExpMatch(url, "*.ico")) return "DIRECT"; + +// if (isInNet(host, "10.0.0.0", "255.255.248.0")) { +// return "PROXY fastproxy.example.com:8080"; +// } + + return "PROXY $host_port; DIRECT"; +} + + |); + $self->proxy->response( $res ); + return; + } + + $res->content_type('text/html'); + $res->content(qq| + +

HTTP Proxy Archive

+ +proxy.pac + + | . '
' . dump($info) . '
' ); + + $self->proxy->response( $res ); +} ); +$proxy->push_filter( request => $admin_filter ); + + +# +# start +# + warn "listen on host ", $proxy->host, " port ", $proxy->port, "\n"; $proxy->start; -- 2.20.1