<s> import os <EOL> import paramiko <EOL> import socket <EOL> import sys <EOL> sys . path . append ( '<STR_LIT>' ) <EOL> sys . path . append ( '<STR_LIT>' ) <EOL> os . environ . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> from django . db . models . loading import cache <EOL> cache . get_apps ( ) <EOL> from freenasUI . storage . models import Replication <EOL> def fixkey ( ip ) : <EOL> """<STR_LIT>""" <EOL> print "<STR_LIT>" <EOL> while True : <EOL> ret = raw_input ( "<STR_LIT>" ) <EOL> if ret . lower ( ) == "<STR_LIT:y>" : <EOL> rep = os . popen ( "<STR_LIT>" % ip ) . read ( ) <EOL> return rep or False <EOL> elif ret . lower ( ) == "<STR_LIT:n>" : <EOL> return False <EOL> else : <EOL> print "<STR_LIT>" <EOL> continue <EOL> def check_ssh ( ip , port , user , key_file , retries = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> ssh = paramiko . SSHClient ( ) <EOL> if os . path . isfile ( "<STR_LIT>" ) : <EOL> try : <EOL> ssh . load_system_host_keys ( "<STR_LIT>" ) <EOL> except paramiko . hostkeys . InvalidHostKey : <EOL> os . unlink ( "<STR_LIT>" ) <EOL> for x in range ( retries ) : <EOL> try : <EOL> ssh . connect ( ip , port , username = user , key_filename = key_file ) <EOL> return True <EOL> except ( paramiko . BadHostKeyException , paramiko . SSHException ) as e : <EOL> if hasattr ( e , "<STR_LIT:message>" ) and ( "<STR_LIT>" <EOL> in e . message or "<STR_LIT>" <EOL> in e . message ) : <EOL> return fixkey ( ip ) <EOL> except ( paramiko . AuthenticationException , <EOL> paramiko . SSHException , socket . error ) as e : <EOL> print e <EOL> return False <EOL> replication_tasks = Replication . objects . all ( ) <EOL> for replication in replication_tasks : <EOL> print "<STR_LIT>" % replication <EOL> if not replication . repl_enabled : <EOL> print ( "<STR_LIT>" % replication ) <EOL> remote = replication . repl_remote . ssh_remote_hostname . __str__ ( ) <EOL> remote_port = replication . repl_remote . ssh_remote_port <EOL> if replication . repl_remote . ssh_remote_dedicateduser_enabled : <EOL> user = replication . repl_remote . ssh_remote_dedicateduser <EOL> else : <EOL> user = "<STR_LIT:root>" <EOL> ret = check_ssh ( remote , remote_port , user , "<STR_LIT>" ) <EOL> if ret is True : <EOL> print "<STR_LIT>" <EOL> print <EOL> elif ret is False : <EOL> print "<STR_LIT>" <EOL> print <EOL> else : <EOL> replication . repl_remote . ssh_remote_hostkey = ret <EOL> replication . repl_remote . save ( ) <EOL> os . system ( "<STR_LIT>" ) <EOL> print "<STR_LIT>" <EOL> print </s>
