<s> '''<STR_LIT>''' <EOL> '''<STR_LIT>''' <EOL> import sys , os , signal , base64 , Cookie , cgi , urlparse <EOL> from BaseHTTPServer import HTTPServer , BaseHTTPRequestHandler <EOL> Listen = ( '<STR_LIT:localhost>' , <NUM_LIT> ) <EOL> import threading <EOL> from SocketServer import ThreadingMixIn <EOL> class AuthHTTPServer ( ThreadingMixIn , HTTPServer ) : <EOL> pass <EOL> class AppHandler ( BaseHTTPRequestHandler ) : <EOL> def do_GET ( self ) : <EOL> url = urlparse . urlparse ( self . path ) <EOL> if url . path . startswith ( "<STR_LIT>" ) : <EOL> return self . auth_form ( ) <EOL> self . send_response ( <NUM_LIT:200> ) <EOL> self . end_headers ( ) <EOL> self . wfile . write ( '<STR_LIT>' + self . path + '<STR_LIT:\n>' ) <EOL> def auth_form ( self , target = None ) : <EOL> if target == None : <EOL> target = self . headers . get ( '<STR_LIT>' ) <EOL> if target == None : <EOL> self . log_error ( '<STR_LIT>' ) <EOL> self . send_response ( <NUM_LIT> ) <EOL> return <EOL> html = """<STR_LIT>""" <EOL> self . send_response ( <NUM_LIT:200> ) <EOL> self . end_headers ( ) <EOL> self . wfile . write ( html . replace ( '<STR_LIT>' , target ) ) <EOL> def do_POST ( self ) : <EOL> env = { '<STR_LIT>' : '<STR_LIT:POST>' , <EOL> '<STR_LIT>' : self . headers [ '<STR_LIT:Content-Type>' ] , } <EOL> form = cgi . FieldStorage ( fp = self . rfile , headers = self . headers , <EOL> environ = env ) <EOL> user = form . getvalue ( '<STR_LIT:username>' ) <EOL> passwd = form . getvalue ( '<STR_LIT:password>' ) <EOL> target = form . getvalue ( '<STR_LIT:target>' ) <EOL> if user != None and passwd != None and target != None : <EOL> self . send_response ( <NUM_LIT> ) <EOL> enc = base64 . b64encode ( user + '<STR_LIT::>' + passwd ) <EOL> self . send_header ( '<STR_LIT>' , '<STR_LIT>' + enc + '<STR_LIT>' ) <EOL> self . send_header ( '<STR_LIT>' , target ) <EOL> self . end_headers ( ) <EOL> return <EOL> self . log_error ( '<STR_LIT>' ) <EOL> self . auth_form ( target ) <EOL> def log_message ( self , format , * args ) : <EOL> if len ( self . client_address ) > <NUM_LIT:0> : <EOL> addr = BaseHTTPRequestHandler . address_string ( self ) <EOL> else : <EOL> addr = "<STR_LIT:->" <EOL> sys . stdout . write ( "<STR_LIT>" % ( addr , <EOL> self . log_date_time_string ( ) , format % args ) ) <EOL> def log_error ( self , format , * args ) : <EOL> self . log_message ( format , * args ) <EOL> def exit_handler ( signal , frame ) : <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> server = AuthHTTPServer ( Listen , AppHandler ) <EOL> signal . signal ( signal . SIGINT , exit_handler ) <EOL> server . serve_forever ( ) </s>
