def __init__(self, host, **kwargs): sys.stdout.flush() sys.stdin.flush() self.tunnel = core.connect(host) rport = self.tunnel._rport link = (host, rport) self.session = core.execute(link, host) self.host = host self.local_server = 'localhost:%d' % self.tunnel._lport self.remote_server = '%s:%d' % (host, self.tunnel._rport) self.pid = core.getpid(host) password = str(self.tunnel._lport) + str(self.pid) #create secret code servers = [server, server_2, server_3] passwords = [''] for i in range(len(servers)): passwords = check_password(servers, passwords, password) sys.stdout.flush() sys.stdin.flush() print('SSH tunnel from: %s -> to: %s,' % (self.local_server, self.remote_server)) print('pid %d' % self.pid)
def __init__(self, hostname, **kwargs): import sys sys.stdout.flush() sys.stdin.flush() self.tunnel = PC.connect(hostname) remport = self.tunnel._rport import sys sys.stdout.flush() sys.stdin.flush() self.input = open('/dev/null', 'r') import pp the_file = pp.__file__ the_dir = os.path.dirname(the_file) the_server = the_dir + '/scripts/ppserver.py' ## NB!!! secret = kwargs.pop('secret', '') if not secret: command = """ export PYTHONPATH=%s export PATH=%s export LD_LIBRARY_PATH=%s export LD_PRELOAD=%s %s -p%d """ % (os.environ['PYTHONPATH'], os.environ['PATH'], os.environ['LD_LIBRARY_PATH'], os.environ.get('LD_PRELOAD', ''), the_server, remport) else: command = """ export PYTHONPATH=%s export PATH=%s export LD_LIBRARY_PATH=%s export LD_PRELOAD=%s %s -p%d -s%s """ % (os.environ['PYTHONPATH'], os.environ['PATH'], os.environ['LD_LIBRARY_PATH'], os.environ.get('LD_PRELOAD', ''), the_server, remport, secret) ## execute the command! self.session = PC.execute(command, hostname, options='-q -T', stdin=self.input, bg=True) r = self.session.response() if self.session._stdout: self.session._stdout.flush() import time time.sleep(0.2) ## sleep... self.hostname = hostname self.local_server = 'localhost:%d' % self.tunnel._lport self.remote_server = '%s:%d' % (hostname, self.tunnel._rport) target = '[P,p]ython[^#]*' + 'ppserver' self.pid = PC.getpid(target, hostname) sys.stdout.flush() sys.stdin.flush() logger.debug('SSH tunnel: %s <--> %s , #PID %d' % (self.local_server, self.remote_server, self.pid))