Author: sparky
Date: Sun Oct 11 16:43:12 2009
New Revision: 10754

Modified:
   toys/rsget.pl/README
   toys/rsget.pl/RSGet/HTTPServer.pm
   toys/rsget.pl/RSGet/Main.pm
Log:
- basic http authentification


Modified: toys/rsget.pl/README
==============================================================================
--- toys/rsget.pl/README        (original)
+++ toys/rsget.pl/README        Sun Oct 11 16:43:12 2009
@@ -1,7 +1,8 @@
 
 TODO:
 - Write more documentation
-
+- When continuing partially downloaded data start few kb before the end and
+  compare old with new.
 
 Features:
 - Perfect for screen session

Modified: toys/rsget.pl/RSGet/HTTPServer.pm
==============================================================================
--- toys/rsget.pl/RSGet/HTTPServer.pm   (original)
+++ toys/rsget.pl/RSGet/HTTPServer.pm   Sun Oct 11 16:43:12 2009
@@ -5,6 +5,7 @@
 use IO::Socket;
 use RSGet::Tools;
 use RSGet::HTTPRequest;
+use MIME::Base64 ();
 use URI::Escape;
 set_rev qq$Id$;
 
@@ -53,6 +54,7 @@
                                $OK = 1;
                                last;
                        }
+                       s/\r\n$//;
                        push @headers, $_;
                        $len = $1 if /^Content-Length:\s*(\d+)/i;
                }
@@ -71,7 +73,7 @@
                close $client;
                return undef;
        }
-       
+
        my( $method, $file, $ignore ) = split /\s+/, $request;
        $file =~ s#^/+##;
 
@@ -88,8 +90,28 @@
                my $get = $1;
                %post = map { /^(.*?)=(.*)/; (uri_unescape( $1 ), uri_unescape( 
$2 )) } split /;+/, $get;
        }
+
+       my $authorized = 1;
+       if ( my $pass = setting( "http_pass" ) ) {
+               $authorized = 0;
+               my %headers = map /^(.*?):\s*(.*)$/, @headers;
+               if ( $headers{Authorization} and $headers{Authorization} =~ 
/^Basic\s+(.*)/ ) {
+                       my $auth = MIME::Base64::decode( $1 );
+                       $auth =~ s/^(.*?)://;
+                       my $user = $1;
+                       if ( $user eq "root" ) {
+                               $authorized = 1 if $pass eq $auth;
+                       }
+               }
+       }
+
        my $print;
-       if ( my $func = $RSGet::HTTPRequest::handlers{$file} ) {
+       if ( not $authorized ) {
+               $print .= "HTTP/1.1 401 Authorization Required\r\n";
+               $print .= "WWW-Authenticate: Basic\r\n";
+               $print .= "Content-Type: text/plain\r\n";
+               $print .= "\r\nAuthorization Required\n";
+       } elsif ( my $func = $RSGet::HTTPRequest::handlers{$file} ) {
                $print = "HTTP/1.1 200 OK\r\n";
                my $headers = { Content_Type => "text/xml; charset=utf-8" };
                my $data = &$func( $file, \%post, $headers );

Modified: toys/rsget.pl/RSGet/Main.pm
==============================================================================
--- toys/rsget.pl/RSGet/Main.pm (original)
+++ toys/rsget.pl/RSGet/Main.pm Sun Oct 11 16:43:12 2009
@@ -23,6 +23,7 @@
 def_settings(
        interfaces => [ "Specify output interfaces or IP addresses.", undef, 
qr/.+/ ],
        http_port => [ "Start HTTP server on specified port.", undef, qr/\d+/ ],
+       http_pass => [ "HTTP password, as plain text, user is 'root'.", undef, 
qr/\S+/ ],
        verbose => [ "Verbosity level.", 0, qr/\d+/ ],
 );
 
_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to