Commits

Ivan Vučica committed 7490f31

Prepared repository.

  • Participants

Comments (0)

Files changed (3)

+Websockets TUN/TAP
+==================
+
+This pywebsocket request handler allows Javascript software to establish
+ethernet connectivity to the server through a service exposing the TAP
+device via Websockets.
+
+Useful for 'certain emulators'.
+
+Note: this is not of production quality, and is almost certainly a
+security risk. Think hard before running this without authentication or
+thinking multiple times whether you want the server you run this on to be
+VPNed to. While intended for Javascript, remember that anyone could connect
+to this service even without Javascript.
+
+(c) 2013 Ivan Vucica
+#!/bin/bash
+
+# Obtain and install mod_pywebsocket from:
+#  https://code.google.com/p/pywebsocket/
+
+python -m mod_pywebsocket.standalone -d . --log-level=info -p 3000
+
+def web_socket_do_extra_handshake(request):
+    """Received Sec-WebSocket-Extensions header value is parsed into
+    request.ws_requested_extensions. pywebsocket creates extension
+    processors using it before do_extra_handshake call and never looks at it
+    after the call.
+
+    To reject requested extensions, clear the processor list.
+    """
+
+    # for easier debugging:
+    request.ws_extension_processors = []
+
+def web_socket_transfer_data(request):
+    """Echo. Same as echo_wsh.py."""
+
+    while True:
+        line = request.ws_stream.receive_message()
+        if line is None:
+            return
+    
+        if isinstance(line, unicode):
+            request.ws_stream.send_message(line, binary=False)
+            if line == _GOODBYE_MESSAGE:
+                return
+        else:
+            request.ws_stream.send_message(line, binary=True)
+# vi:sts=4 sw=4 et