Merge branch 'master' of https://github.com/michalsrb/websockify
This commit is contained in:
commit
5e19bc3f96
|
@ -297,12 +297,17 @@ class WebSocketProxy(websockifyserver.WebSockifyServer):
|
||||||
else:
|
else:
|
||||||
dst_string = "%s:%s" % (self.target_host, self.target_port)
|
dst_string = "%s:%s" % (self.target_host, self.target_port)
|
||||||
|
|
||||||
if self.token_plugin:
|
if self.listen_fd != None:
|
||||||
msg = " - proxying from %s:%s to targets generated by %s" % (
|
src_string = "inetd"
|
||||||
self.listen_host, self.listen_port, type(self.token_plugin).__name__)
|
|
||||||
else:
|
else:
|
||||||
msg = " - proxying from %s:%s to %s" % (
|
src_string = "%s:%s" % (self.listen_host, self.listen_port)
|
||||||
self.listen_host, self.listen_port, dst_string)
|
|
||||||
|
if self.token_plugin:
|
||||||
|
msg = " - proxying from %s to targets generated by %s" % (
|
||||||
|
src_string, type(self.token_plugin).__name__)
|
||||||
|
else:
|
||||||
|
msg = " - proxying from %s to %s" % (
|
||||||
|
src_string, dst_string)
|
||||||
|
|
||||||
if self.ssl_target:
|
if self.ssl_target:
|
||||||
msg += " (using SSL)"
|
msg += " (using SSL)"
|
||||||
|
@ -389,6 +394,8 @@ def websockify_init():
|
||||||
help="connect to SSL target as SSL client")
|
help="connect to SSL target as SSL client")
|
||||||
parser.add_option("--unix-target",
|
parser.add_option("--unix-target",
|
||||||
help="connect to unix socket target", metavar="FILE")
|
help="connect to unix socket target", metavar="FILE")
|
||||||
|
parser.add_option("--inetd",
|
||||||
|
help="inetd mode, receive listening socket from stdin", action="store_true")
|
||||||
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",
|
||||||
|
@ -457,15 +464,10 @@ def websockify_init():
|
||||||
|
|
||||||
del opts.target_cfg
|
del opts.target_cfg
|
||||||
|
|
||||||
# Sanity checks
|
|
||||||
if len(args) < 2 and not (opts.token_plugin or opts.unix_target):
|
|
||||||
parser.error("Too few arguments")
|
|
||||||
if sys.argv.count('--'):
|
if sys.argv.count('--'):
|
||||||
opts.wrap_cmd = args[1:]
|
opts.wrap_cmd = args[1:]
|
||||||
else:
|
else:
|
||||||
opts.wrap_cmd = None
|
opts.wrap_cmd = None
|
||||||
if len(args) > 2:
|
|
||||||
parser.error("Too many arguments")
|
|
||||||
|
|
||||||
if not websockifyserver.ssl and opts.ssl_target:
|
if not websockifyserver.ssl and opts.ssl_target:
|
||||||
parser.error("SSL target requested and Python SSL module not loaded.");
|
parser.error("SSL target requested and Python SSL module not loaded.");
|
||||||
|
@ -473,28 +475,42 @@ def websockify_init():
|
||||||
if opts.ssl_only and not os.path.exists(opts.cert):
|
if opts.ssl_only and not os.path.exists(opts.cert):
|
||||||
parser.error("SSL only and %s not found" % opts.cert)
|
parser.error("SSL only and %s not found" % opts.cert)
|
||||||
|
|
||||||
|
if opts.inetd:
|
||||||
|
opts.listen_fd = sys.stdin.fileno()
|
||||||
|
else:
|
||||||
|
if len(args) < 1:
|
||||||
|
parser.error("Too few arguments")
|
||||||
|
arg = args.pop(0)
|
||||||
# Parse host:port and convert ports to numbers
|
# Parse host:port and convert ports to numbers
|
||||||
if args[0].count(':') > 0:
|
if arg.count(':') > 0:
|
||||||
opts.listen_host, opts.listen_port = args[0].rsplit(':', 1)
|
opts.listen_host, opts.listen_port = arg.rsplit(':', 1)
|
||||||
opts.listen_host = opts.listen_host.strip('[]')
|
opts.listen_host = opts.listen_host.strip('[]')
|
||||||
else:
|
else:
|
||||||
opts.listen_host, opts.listen_port = '', args[0]
|
opts.listen_host, opts.listen_port = '', arg
|
||||||
|
|
||||||
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")
|
||||||
|
|
||||||
|
del opts.inetd
|
||||||
|
|
||||||
if opts.wrap_cmd or opts.unix_target or opts.token_plugin:
|
if opts.wrap_cmd or opts.unix_target or opts.token_plugin:
|
||||||
opts.target_host = None
|
opts.target_host = None
|
||||||
opts.target_port = None
|
opts.target_port = None
|
||||||
else:
|
else:
|
||||||
if args[1].count(':') > 0:
|
if len(args) < 1:
|
||||||
opts.target_host, opts.target_port = args[1].rsplit(':', 1)
|
parser.error("Too few arguments")
|
||||||
|
arg = args.pop(0)
|
||||||
|
if arg.count(':') > 0:
|
||||||
|
opts.target_host, opts.target_port = arg.rsplit(':', 1)
|
||||||
opts.target_host = opts.target_host.strip('[]')
|
opts.target_host = opts.target_host.strip('[]')
|
||||||
else:
|
else:
|
||||||
parser.error("Error parsing target")
|
parser.error("Error parsing target")
|
||||||
try: opts.target_port = int(opts.target_port)
|
try: opts.target_port = int(opts.target_port)
|
||||||
except: parser.error("Error parsing target port")
|
except: parser.error("Error parsing target port")
|
||||||
|
|
||||||
|
if len(args) > 0 and opts.wrap_cmd == None:
|
||||||
|
parser.error("Too many arguments")
|
||||||
|
|
||||||
if opts.token_plugin is not None:
|
if opts.token_plugin is not None:
|
||||||
if '.' not in opts.token_plugin:
|
if '.' not in opts.token_plugin:
|
||||||
opts.token_plugin = (
|
opts.token_plugin = (
|
||||||
|
|
|
@ -316,8 +316,8 @@ class WebSockifyServer(object):
|
||||||
class Terminate(Exception):
|
class Terminate(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __init__(self, RequestHandlerClass, listen_host='',
|
def __init__(self, RequestHandlerClass, listen_fd=None,
|
||||||
listen_port=None, source_is_ipv6=False,
|
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='',
|
||||||
file_only=False,
|
file_only=False,
|
||||||
|
@ -328,6 +328,7 @@ class WebSockifyServer(object):
|
||||||
# settings
|
# settings
|
||||||
self.RequestHandlerClass = RequestHandlerClass
|
self.RequestHandlerClass = RequestHandlerClass
|
||||||
self.verbose = verbose
|
self.verbose = verbose
|
||||||
|
self.listen_fd = listen_fd
|
||||||
self.listen_host = listen_host
|
self.listen_host = listen_host
|
||||||
self.listen_port = listen_port
|
self.listen_port = listen_port
|
||||||
self.prefer_ipv6 = source_is_ipv6
|
self.prefer_ipv6 = source_is_ipv6
|
||||||
|
@ -371,6 +372,9 @@ class WebSockifyServer(object):
|
||||||
|
|
||||||
# Show configuration
|
# Show configuration
|
||||||
self.msg("WebSocket server settings:")
|
self.msg("WebSocket server settings:")
|
||||||
|
if self.listen_fd != None:
|
||||||
|
self.msg(" - Listen for inetd connections")
|
||||||
|
else:
|
||||||
self.msg(" - Listen on %s:%s",
|
self.msg(" - Listen on %s:%s",
|
||||||
self.listen_host, self.listen_port)
|
self.listen_host, self.listen_port)
|
||||||
if self.web:
|
if self.web:
|
||||||
|
@ -669,6 +673,14 @@ class WebSockifyServer(object):
|
||||||
is a WebSockets client then call new_websocket_client() method (which must
|
is a WebSockets client then call new_websocket_client() method (which must
|
||||||
be overridden) for each new client connection.
|
be overridden) for each new client connection.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if self.listen_fd != None:
|
||||||
|
lsock = socket.fromfd(self.listen_fd, socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
if sys.hexversion < 0x3000000:
|
||||||
|
# For python 2 we have to wrap the "raw" socket into a socket object,
|
||||||
|
# otherwise ssl wrap_socket doesn't work.
|
||||||
|
lsock = socket.socket(_sock=lsock)
|
||||||
|
else:
|
||||||
lsock = self.socket(self.listen_host, self.listen_port, False,
|
lsock = self.socket(self.listen_host, self.listen_port, False,
|
||||||
self.prefer_ipv6,
|
self.prefer_ipv6,
|
||||||
tcp_keepalive=self.tcp_keepalive,
|
tcp_keepalive=self.tcp_keepalive,
|
||||||
|
|
Loading…
Reference in New Issue