sub var_save {
my ( $dir, $name, $value ) = @_;
$value ||= "\n";
+ mkdir 'var' unless -e 'var';
mkdir "var/$dir" unless -e "var/$dir";
open(my $fh, '>>', "var/$dir/$name") || die $!;
print $fh $value;
my $saved;
$proxy->push_filter(
# you should probably restrict this to certain hosts as well
- path => qr/\.pdf$/,
+ path => qr/\.pdf\b/,
mime => 'application/pdf',
# save the PDF
response => HTTP::Proxy::BodyFilter::save->new(
+ timestamp => 1,
template => "%f",
prefix => 'pdf'
),
),
);
+#
+# proxy-auth.pl
+#
+
+
+use HTTP::Proxy qw( :log );
+use MIME::Base64 qw( encode_base64 );
+
+# the encoded user:password pair
+# login: http
+# passwd: proxy
+my $token = "Basic " . encode_base64( "http:proxy", '' );
+
+# the authentication filter
+$proxy->push_filter(
+ request => HTTP::Proxy::HeaderFilter::simple->new(
+ sub {
+ my ( $self, $headers, $request ) = @_;
+
+ # check the token against all credentials
+ my $ok = 0;
+ $_ eq $token && $ok++
+ for $self->proxy->hop_headers->header('Proxy-Authorization');
+
+ # no valid credential
+ if ( !$ok ) {
+ my $response = HTTP::Response->new(407);
+ $response->header(
+ Proxy_Authenticate => 'Basic realm="HTTP::Proxy"' );
+ $self->proxy->response($response);
+ }
+ }
+ )
+);
+
+
#
# 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";
+warn "\nXXX [", $headers->header('x-forwarded-for'), '] ', $message->uri, "\n";
print $message->headers_as_string if debug_on;
if (shExpMatch(url, "*.ico")) return "DIRECT";
if (shExpMatch(url, "*.jpg")) return "DIRECT";
+ if (isInNet(host, "127.0.0.0", "255.0.0.0"))
+ return "DIRECT";
+
// if (isInNet(host, "10.0.0.0", "255.255.248.0")) {
// return "PROXY fastproxy.example.com:8080";
// }