Fixup bugs from merge (pull #46).
- Rename unix socket option to '--unix-target' to be consistent with '--ssl-target' which is an analogous switch. - Fix normal socket target mode which was broken after merge. - Normalize/fix output for SSL, unix socket and wrap command modes.
This commit is contained in:
parent
233b622e47
commit
cddc1613ff
|
|
@ -104,7 +104,7 @@ Sec-WebSocket-Accept: %s\r
|
||||||
def __init__(self, listen_host='', listen_port=None, source_is_ipv6=False,
|
def __init__(self, listen_host='', listen_port=None, source_is_ipv6=False,
|
||||||
verbose=False, cert='', key='', ssl_only=None,
|
verbose=False, cert='', key='', ssl_only=None,
|
||||||
daemon=False, record='', web='',
|
daemon=False, record='', web='',
|
||||||
run_once=False, timeout=0, unix=None):
|
run_once=False, timeout=0):
|
||||||
|
|
||||||
# settings
|
# settings
|
||||||
self.verbose = verbose
|
self.verbose = verbose
|
||||||
|
|
@ -115,8 +115,6 @@ Sec-WebSocket-Accept: %s\r
|
||||||
self.run_once = run_once
|
self.run_once = run_once
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
|
||||||
self.unix_socket = unix
|
|
||||||
|
|
||||||
self.launch_time = time.time()
|
self.launch_time = time.time()
|
||||||
self.ws_connection = False
|
self.ws_connection = False
|
||||||
self.handler_id = 1
|
self.handler_id = 1
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ Traffic Legend:
|
||||||
self.target_port = kwargs.pop('target_port')
|
self.target_port = kwargs.pop('target_port')
|
||||||
self.wrap_cmd = kwargs.pop('wrap_cmd')
|
self.wrap_cmd = kwargs.pop('wrap_cmd')
|
||||||
self.wrap_mode = kwargs.pop('wrap_mode')
|
self.wrap_mode = kwargs.pop('wrap_mode')
|
||||||
|
self.unix_target = kwargs.pop('unix_target')
|
||||||
self.ssl_target = kwargs.pop('ssl_target')
|
self.ssl_target = kwargs.pop('ssl_target')
|
||||||
# Last 3 timestamps command was run
|
# Last 3 timestamps command was run
|
||||||
self.wrap_times = [0, 0, 0]
|
self.wrap_times = [0, 0, 0]
|
||||||
|
|
@ -89,13 +90,13 @@ Traffic Legend:
|
||||||
# Need to call wrapped command after daemonization so we can
|
# Need to call wrapped command after daemonization so we can
|
||||||
# know when the wrapped command exits
|
# know when the wrapped command exits
|
||||||
if self.wrap_cmd:
|
if self.wrap_cmd:
|
||||||
dst_string = self.unix_socket or "'%s' (port %s)" % (" ".join(self.wrap_cmd), self.target_port)
|
dst_string = "'%s' (port %s)" % (" ".join(self.wrap_cmd), self.target_port)
|
||||||
msg = " - proxying from %s:%s to %s\n" % (
|
elif self.unix_target:
|
||||||
self.listen_host, self.listen_port, dst_string)
|
dst_string = self.unix_target
|
||||||
self.run_wrap_cmd()
|
|
||||||
else:
|
else:
|
||||||
dst_string = self.unix_socket or "%s:%s" % (self.target_host, self.target_port)
|
dst_string = "%s:%s" % (self.target_host, self.target_port)
|
||||||
msg = " - proxying from %s:%s to %s\n" % (
|
|
||||||
|
msg = " - proxying from %s:%s to %s" % (
|
||||||
self.listen_host, self.listen_port, dst_string)
|
self.listen_host, self.listen_port, dst_string)
|
||||||
|
|
||||||
if self.ssl_target:
|
if self.ssl_target:
|
||||||
|
|
@ -147,21 +148,20 @@ Traffic Legend:
|
||||||
Called after a new WebSocket connection has been established.
|
Called after a new WebSocket connection has been established.
|
||||||
"""
|
"""
|
||||||
# Connect to the target
|
# Connect to the target
|
||||||
if self.unix_socket:
|
if self.wrap_cmd:
|
||||||
msg = "connecting to unix socket : %s" % self.unix_socket
|
msg = "connecting to command: %s" % (" ".join(self.wrap_cmd), self.target_port)
|
||||||
|
elif self.unix_target:
|
||||||
|
msg = "connecting to unix socket: %s" % self.unix_target
|
||||||
else:
|
else:
|
||||||
msg = "connecting to: %s:%s" % (
|
msg = "connecting to: %s:%s" % (
|
||||||
self.target_host, self.target_port)
|
self.target_host, self.target_port)
|
||||||
|
|
||||||
tsock = self.socket(self.target_host, self.target_port,
|
|
||||||
connect=True, use_ssl=self.ssl_target, unix_socket=self.unix_socket)
|
|
||||||
|
|
||||||
if self.ssl_target:
|
if self.ssl_target:
|
||||||
msg += " (using SSL)"
|
msg += " (using SSL)"
|
||||||
self.msg(msg)
|
self.msg(msg)
|
||||||
|
|
||||||
tsock = self.socket(self.target_host, self.target_port,
|
tsock = self.socket(self.target_host, self.target_port,
|
||||||
connect=True, use_ssl=self.ssl_target)
|
connect=True, use_ssl=self.ssl_target, unix_socket=self.unix_target)
|
||||||
|
|
||||||
if self.verbose and not self.daemon:
|
if self.verbose and not self.daemon:
|
||||||
print(self.traffic_legend)
|
print(self.traffic_legend)
|
||||||
|
|
@ -242,8 +242,6 @@ def websockify_init():
|
||||||
help="verbose messages and per frame traffic")
|
help="verbose messages and per frame traffic")
|
||||||
parser.add_option("--record",
|
parser.add_option("--record",
|
||||||
help="record sessions to FILE.[session_number]", metavar="FILE")
|
help="record sessions to FILE.[session_number]", metavar="FILE")
|
||||||
parser.add_option("--unix",
|
|
||||||
help="unix socket to proxy network from", metavar="FILE")
|
|
||||||
parser.add_option("--daemon", "-D",
|
parser.add_option("--daemon", "-D",
|
||||||
dest="daemon", action="store_true",
|
dest="daemon", action="store_true",
|
||||||
help="become a daemon (background process)")
|
help="become a daemon (background process)")
|
||||||
|
|
@ -259,6 +257,8 @@ def websockify_init():
|
||||||
help="disallow non-encrypted client connections")
|
help="disallow non-encrypted client connections")
|
||||||
parser.add_option("--ssl-target", action="store_true",
|
parser.add_option("--ssl-target", action="store_true",
|
||||||
help="connect to SSL target as SSL client")
|
help="connect to SSL target as SSL client")
|
||||||
|
parser.add_option("--unix-target",
|
||||||
|
help="connect to unix socket target", metavar="FILE")
|
||||||
parser.add_option("--web", default=None, metavar="DIR",
|
parser.add_option("--web", default=None, metavar="DIR",
|
||||||
help="run webserver on same port. Serve files from DIR.")
|
help="run webserver on same port. Serve files from DIR.")
|
||||||
parser.add_option("--wrap-mode", default="exit", metavar="MODE",
|
parser.add_option("--wrap-mode", default="exit", metavar="MODE",
|
||||||
|
|
@ -292,12 +292,9 @@ def websockify_init():
|
||||||
try: opts.listen_port = int(opts.listen_port)
|
try: opts.listen_port = int(opts.listen_port)
|
||||||
except: parser.error("Error parsing listen port")
|
except: parser.error("Error parsing listen port")
|
||||||
|
|
||||||
if opts.wrap_cmd:
|
if opts.wrap_cmd or opts.unix_target:
|
||||||
opts.target_host = None
|
opts.target_host = None
|
||||||
opts.target_port = None
|
opts.target_port = None
|
||||||
else:
|
|
||||||
if hasattr(opts, 'unix'):
|
|
||||||
opts.target_host = opts.target_port = None
|
|
||||||
else:
|
else:
|
||||||
if args[1].count(':') > 0:
|
if args[1].count(':') > 0:
|
||||||
opts.target_host, opts.target_port = args[1].rsplit(':', 1)
|
opts.target_host, opts.target_port = args[1].rsplit(':', 1)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue