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:
Joel Martin 2012-05-31 09:17:51 -05:00
parent 233b622e47
commit cddc1613ff
2 changed files with 22 additions and 27 deletions

View File

@ -104,7 +104,7 @@ Sec-WebSocket-Accept: %s\r
def __init__(self, listen_host='', listen_port=None, source_is_ipv6=False,
verbose=False, cert='', key='', ssl_only=None,
daemon=False, record='', web='',
run_once=False, timeout=0, unix=None):
run_once=False, timeout=0):
# settings
self.verbose = verbose
@ -115,8 +115,6 @@ Sec-WebSocket-Accept: %s\r
self.run_once = run_once
self.timeout = timeout
self.unix_socket = unix
self.launch_time = time.time()
self.ws_connection = False
self.handler_id = 1

33
websockify Normal file → Executable file
View File

@ -43,6 +43,7 @@ Traffic Legend:
self.target_port = kwargs.pop('target_port')
self.wrap_cmd = kwargs.pop('wrap_cmd')
self.wrap_mode = kwargs.pop('wrap_mode')
self.unix_target = kwargs.pop('unix_target')
self.ssl_target = kwargs.pop('ssl_target')
# Last 3 timestamps command was run
self.wrap_times = [0, 0, 0]
@ -89,13 +90,13 @@ Traffic Legend:
# Need to call wrapped command after daemonization so we can
# know when the wrapped command exits
if self.wrap_cmd:
dst_string = self.unix_socket or "'%s' (port %s)" % (" ".join(self.wrap_cmd), self.target_port)
msg = " - proxying from %s:%s to %s\n" % (
self.listen_host, self.listen_port, dst_string)
self.run_wrap_cmd()
dst_string = "'%s' (port %s)" % (" ".join(self.wrap_cmd), self.target_port)
elif self.unix_target:
dst_string = self.unix_target
else:
dst_string = self.unix_socket or "%s:%s" % (self.target_host, self.target_port)
msg = " - proxying from %s:%s to %s\n" % (
dst_string = "%s:%s" % (self.target_host, self.target_port)
msg = " - proxying from %s:%s to %s" % (
self.listen_host, self.listen_port, dst_string)
if self.ssl_target:
@ -147,21 +148,20 @@ Traffic Legend:
Called after a new WebSocket connection has been established.
"""
# Connect to the target
if self.unix_socket:
msg = "connecting to unix socket : %s" % self.unix_socket
if self.wrap_cmd:
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:
msg = "connecting to: %s:%s" % (
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:
msg += " (using SSL)"
self.msg(msg)
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:
print(self.traffic_legend)
@ -242,8 +242,6 @@ def websockify_init():
help="verbose messages and per frame traffic")
parser.add_option("--record",
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",
dest="daemon", action="store_true",
help="become a daemon (background process)")
@ -259,6 +257,8 @@ def websockify_init():
help="disallow non-encrypted client connections")
parser.add_option("--ssl-target", action="store_true",
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",
help="run webserver on same port. Serve files from DIR.")
parser.add_option("--wrap-mode", default="exit", metavar="MODE",
@ -292,12 +292,9 @@ def websockify_init():
try: opts.listen_port = int(opts.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_port = None
else:
if hasattr(opts, 'unix'):
opts.target_host = opts.target_port = None
else:
if args[1].count(':') > 0:
opts.target_host, opts.target_port = args[1].rsplit(':', 1)