forked from shaba/openuds
fixing up tunnel stuff
This commit is contained in:
parent
ae5fafae76
commit
ee59f45838
@ -10,6 +10,7 @@ import SocketServer
|
|||||||
import paramiko
|
import paramiko
|
||||||
import threading
|
import threading
|
||||||
import random
|
import random
|
||||||
|
import time
|
||||||
|
|
||||||
g_verbose = True
|
g_verbose = True
|
||||||
|
|
||||||
@ -70,10 +71,14 @@ class Handler (SocketServer.BaseRequestHandler):
|
|||||||
|
|
||||||
def verbose(s):
|
def verbose(s):
|
||||||
if g_verbose:
|
if g_verbose:
|
||||||
print(s)
|
with open('/Users/admin/log.txt', 'a') as f:
|
||||||
|
f.write(s)
|
||||||
|
f.write('\n')
|
||||||
|
|
||||||
|
|
||||||
class ForwardThread(threading.Thread):
|
class ForwardThread(threading.Thread):
|
||||||
|
status = 0 # Connecting
|
||||||
|
|
||||||
def __init__(self, server, port, username, password, localPort, redirectHost, redirectPort, waitTime):
|
def __init__(self, server, port, username, password, localPort, redirectHost, redirectPort, waitTime):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.client = None
|
self.client = None
|
||||||
@ -108,7 +113,12 @@ class ForwardThread(threading.Thread):
|
|||||||
|
|
||||||
verbose('Connecting to ssh host %s:%d ...' % (self.server, self.port))
|
verbose('Connecting to ssh host %s:%d ...' % (self.server, self.port))
|
||||||
|
|
||||||
|
try:
|
||||||
self.client.connect(self.server, self.port, username=self.username, password=self.password)
|
self.client.connect(self.server, self.port, username=self.username, password=self.password)
|
||||||
|
except Exception as e:
|
||||||
|
verbose('Exception: {}'.format(e))
|
||||||
|
self.status = 2 # Error
|
||||||
|
return
|
||||||
|
|
||||||
class SubHandler (Handler):
|
class SubHandler (Handler):
|
||||||
chain_host = self.redirectHost
|
chain_host = self.redirectHost
|
||||||
@ -121,6 +131,8 @@ class ForwardThread(threading.Thread):
|
|||||||
self.timer = threading.Timer(self.waitTime, self._timerFnc)
|
self.timer = threading.Timer(self.waitTime, self._timerFnc)
|
||||||
self.timer.start()
|
self.timer.start()
|
||||||
|
|
||||||
|
self.status = 1 # Ok, listening
|
||||||
|
|
||||||
self.fs = ForwardServer(('', self.localPort), SubHandler)
|
self.fs = ForwardServer(('', self.localPort), SubHandler)
|
||||||
self.fs.serve_forever()
|
self.fs.serve_forever()
|
||||||
|
|
||||||
@ -155,4 +167,7 @@ def forward(server, port, username, password, redirectHost, redirectPort, localP
|
|||||||
|
|
||||||
ft.start()
|
ft.start()
|
||||||
|
|
||||||
|
while ft.status == 0:
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
return (ft, localPort)
|
return (ft, localPort)
|
||||||
|
Loading…
Reference in New Issue
Block a user