added bash http auth from proxy-auth.pl
authordpavlin <dpavlin@zemlja.ffzg.hr>
Tue, 24 Nov 2009 22:58:22 +0000 (23:58 +0100)
committerdpavlin <dpavlin@zemlja.ffzg.hr>
Tue, 24 Nov 2009 22:58:22 +0000 (23:58 +0100)
proxy.pl

index a2b5546..590da2d 100755 (executable)
--- a/proxy.pl
+++ b/proxy.pl
@@ -175,6 +175,42 @@ $proxy->push_filter(
     ),
 );
 
+#
+# 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
 #