Commit 9ec97d86 authored by Joel Martin's avatar Joel Martin

Base64 encode/decode for client Javascript.

parent 65e27ddd
#!/usr/bin/python #!/usr/bin/python
import sys, os, socket, time, traceback import sys, os, socket, time, traceback
from base64 import b64encode, b64decode
from select import select from select import select
server_handshake = """HTTP/1.1 101 Web Socket Protocol Handshake\r server_handshake = """HTTP/1.1 101 Web Socket Protocol Handshake\r
...@@ -36,29 +37,28 @@ def proxy(client, target): ...@@ -36,29 +37,28 @@ def proxy(client, target):
if client in ins: if client in ins:
buf = client.recv(1024) buf = client.recv(1024)
if len(buf) == 0: raise Exception("Client closed") if len(buf) == 0: raise Exception("Client closed")
tqueue.append(buf[1:-1]) tqueue.append(b64decode(buf[1:-1]))
#print "Client recv: %s (%d)" % (buf[1:-1], len(buf)) print "Client recv: %s (%d)" % (repr(buf[1:-1]), len(buf))
traffic("}") #traffic("}")
if target in ins: if target in ins:
buf = target.recv(1024) buf = target.recv(1024)
if len(buf) == 0: raise Exception("Target closed") if len(buf) == 0: raise Exception("Target closed")
cqueue.append("\x00" + buf + "\xff") cqueue.append("\x00" + b64encode(buf) + "\xff")
#print "Target recv: %s (%d)" % (buf, len(buf)) print "Target recv: %s (%d)" % (repr(buf), len(buf))
traffic("{") #traffic("{")
if cqueue and client in outs: if cqueue and client in outs:
while cqueue: while cqueue:
#print "Client send: %s" % cqueue[0] print "Client send: %s" % repr(cqueue[0])
client.send(cqueue.pop(0)) client.send(cqueue.pop(0))
traffic("<") #traffic("<")
if tqueue and target in outs: if tqueue and target in outs:
while tqueue: while tqueue:
#print "Target send: %s" % tqueue[0] print "Target send: %s" % repr(tqueue[0])
sys.stdout.flush()
target.send(tqueue.pop(0)) target.send(tqueue.pop(0))
traffic(">") #traffic(">")
def start_server(listen_port, target_host, target_port): def start_server(listen_port, target_host, target_port):
lsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) lsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment