<s> r'''<STR_LIT>''' <EOL> import logging <EOL> import textwrap <EOL> from nogotofail . mitm . connection . handlers import base <EOL> from nogotofail . mitm . event import connection <EOL> class LoggingHandler ( base . BaseConnectionHandler ) : <EOL> name = "<STR_LIT>" <EOL> description = "<STR_LIT>" <EOL> FORMAT = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> logger = logging . getLogger ( "<STR_LIT>" ) <EOL> event_logger = logging . getLogger ( "<STR_LIT>" ) <EOL> ssl = False <EOL> def log ( self , level , message ) : <EOL> d = { "<STR_LIT>" : self . connection . client_addr , <EOL> "<STR_LIT>" : self . connection . client_port , <EOL> "<STR_LIT>" : self . connection . server_addr , <EOL> "<STR_LIT>" : self . connection . server_port , <EOL> "<STR_LIT:message>" : message , <EOL> "<STR_LIT>" : self . applications_str , <EOL> "<STR_LIT:class>" : self . name , <EOL> "<STR_LIT>" : self . connection . id } <EOL> self . logger . log ( level , self . FORMAT % d ) <EOL> def log_event ( self , level , event ) : <EOL> self . event_logger . log ( level , event . dumps ( ) ) <EOL> def log_attack_event ( self , data = None , success = True ) : <EOL> self . log_event ( <EOL> logging . ERROR , <EOL> connection . AttackEvent ( <EOL> self . connection , self . name , success , <EOL> data ) ) <EOL> @ property <EOL> def applications_str ( self ) : <EOL> apps = self . connection . applications ( ) <EOL> if apps is None : <EOL> return "<STR_LIT>" <EOL> info , apps = apps <EOL> return "<STR_LIT>" % info + "<STR_LIT:U+002CU+0020>" . join ( [ <EOL> "<STR_LIT>" % <EOL> ( app . package , app . version ) <EOL> for app in apps ] ) <EOL> def on_select ( self ) : <EOL> self . log ( logging . INFO , "<STR_LIT>" ) <EOL> def on_establish ( self ) : <EOL> self . log ( logging . INFO , "<STR_LIT>" ) <EOL> def on_ssl_error ( self , error ) : <EOL> self . log ( logging . DEBUG , "<STR_LIT>" % error ) <EOL> def on_close ( self , handler_initiated ) : <EOL> if handler_initiated : <EOL> self . log ( logging . INFO , "<STR_LIT>" ) <EOL> else : <EOL> self . log ( logging . INFO , "<STR_LIT>" ) <EOL> def on_remove ( self ) : <EOL> self . log ( logging . INFO , "<STR_LIT>" ) <EOL> def on_ssl ( self , client_hello ) : <EOL> self . log ( logging . DEBUG , "<STR_LIT>" ) <EOL> def on_ssl_establish ( self ) : <EOL> self . log ( logging . INFO , "<STR_LIT>" ) <EOL> self . ssl = True </s>
