Merge 852de01768 into e295098330
This commit is contained in:
commit
97b2805933
20
websocket.py
20
websocket.py
|
|
@ -16,11 +16,11 @@ as taken from http://docs.python.org/dev/library/ssl.html#certificates
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os, sys, time, errno, signal, socket, traceback, select
|
import os, sys, time, errno, signal, socket, traceback, select, pdb, re
|
||||||
import array, struct
|
import array, struct
|
||||||
from cgi import parse_qsl
|
from cgi import parse_qsl
|
||||||
from base64 import b64encode, b64decode
|
from base64 import b64encode, b64decode
|
||||||
|
from subprocess import call
|
||||||
# Imports that vary by python version
|
# Imports that vary by python version
|
||||||
|
|
||||||
# python 3.0 differences
|
# python 3.0 differences
|
||||||
|
|
@ -104,10 +104,11 @@ 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):
|
run_once=False, timeout=0, auth_hook=''):
|
||||||
|
|
||||||
# settings
|
# settings
|
||||||
self.verbose = verbose
|
self.verbose = verbose
|
||||||
|
self.auth_hook = auth_hook
|
||||||
self.listen_host = listen_host
|
self.listen_host = listen_host
|
||||||
self.listen_port = listen_port
|
self.listen_port = listen_port
|
||||||
self.ssl_only = ssl_only
|
self.ssl_only = ssl_only
|
||||||
|
|
@ -590,11 +591,20 @@ Sec-WebSocket-Accept: %s\r
|
||||||
raise self.EClose("ignoring socket not ready")
|
raise self.EClose("ignoring socket not ready")
|
||||||
# Peek, but do not read the data so that we have a opportunity
|
# Peek, but do not read the data so that we have a opportunity
|
||||||
# to SSL wrap the socket first
|
# to SSL wrap the socket first
|
||||||
|
|
||||||
handshake = sock.recv(1024, socket.MSG_PEEK)
|
handshake = sock.recv(1024, socket.MSG_PEEK)
|
||||||
#self.msg("Handshake [%s]" % handshake)
|
|
||||||
|
tmp = handshake.split("Sec-WebSocket-Protocol:")[1].split(',')[1].split("\r")[0].split('-----')
|
||||||
|
if self.auth_hook != '':
|
||||||
|
ret = call([self.auth_hook, tmp[0], tmp[1]])
|
||||||
|
if ret != 0:
|
||||||
|
raise self.EClose("auth denied")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if handshake == "":
|
if handshake == "":
|
||||||
raise self.EClose("ignoring empty handshake")
|
raise self.EClose("ignoring empty handshake")
|
||||||
|
|
||||||
|
|
||||||
elif handshake.startswith(s2b("<policy-file-request/>")):
|
elif handshake.startswith(s2b("<policy-file-request/>")):
|
||||||
# Answer Flash policy request
|
# Answer Flash policy request
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ as taken from http://docs.python.org/dev/library/ssl.html#certificates
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import socket, optparse, time, os, sys, subprocess
|
import socket, optparse, time, os, sys, subprocess
|
||||||
|
import pdb#;pdb.set_trace();
|
||||||
from select import select
|
from select import select
|
||||||
import websocket
|
import websocket
|
||||||
|
|
||||||
|
|
@ -169,7 +170,7 @@ Traffic Legend:
|
||||||
|
|
||||||
# Start proxying
|
# Start proxying
|
||||||
try:
|
try:
|
||||||
self.do_proxy(tsock)
|
self.do_proxy(tsock)
|
||||||
except:
|
except:
|
||||||
if tsock:
|
if tsock:
|
||||||
tsock.shutdown(socket.SHUT_RDWR)
|
tsock.shutdown(socket.SHUT_RDWR)
|
||||||
|
|
@ -266,6 +267,7 @@ def websockify_init():
|
||||||
choices=["exit", "ignore", "respawn"],
|
choices=["exit", "ignore", "respawn"],
|
||||||
help="action to take when the wrapped program exits "
|
help="action to take when the wrapped program exits "
|
||||||
"or daemonizes: exit (default), ignore, respawn")
|
"or daemonizes: exit (default), ignore, respawn")
|
||||||
|
parser.add_option("--auth_hook", default="")
|
||||||
(opts, args) = parser.parse_args()
|
(opts, args) = parser.parse_args()
|
||||||
|
|
||||||
# Sanity checks
|
# Sanity checks
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue