aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/web
diff options
context:
space:
mode:
Diffstat (limited to 'libmproxy/web')
-rw-r--r--libmproxy/web/__init__.py6
-rw-r--r--libmproxy/web/app.py22
-rw-r--r--libmproxy/web/static/js/app.js25
3 files changed, 35 insertions, 18 deletions
diff --git a/libmproxy/web/__init__.py b/libmproxy/web/__init__.py
index 8f98060c..044cb0cd 100644
--- a/libmproxy/web/__init__.py
+++ b/libmproxy/web/__init__.py
@@ -58,6 +58,7 @@ class Options(object):
class WebMaster(flow.FlowMaster):
def __init__(self, server, options):
self.options = options
+ self.app = app.Application(self.options.wdebug)
flow.FlowMaster.__init__(self, server, WebState())
def tick(self):
@@ -70,9 +71,7 @@ class WebMaster(flow.FlowMaster):
)
iol = tornado.ioloop.IOLoop.instance()
- http_server = tornado.httpserver.HTTPServer(
- app.Application(self.options.wdebug)
- )
+ http_server = tornado.httpserver.HTTPServer(self.app)
http_server.listen(self.options.wport)
tornado.ioloop.PeriodicCallback(self.tick, 5).start()
@@ -82,6 +81,7 @@ class WebMaster(flow.FlowMaster):
self.shutdown()
def handle_request(self, f):
+ print f
flow.FlowMaster.handle_request(self, f)
if f:
f.reply()
diff --git a/libmproxy/web/app.py b/libmproxy/web/app.py
index 31b299a3..e9bcc526 100644
--- a/libmproxy/web/app.py
+++ b/libmproxy/web/app.py
@@ -1,6 +1,7 @@
-
import os.path
import tornado.web
+import tornado.websocket
+import logging
class IndexHandler(tornado.web.RequestHandler):
@@ -8,10 +9,29 @@ class IndexHandler(tornado.web.RequestHandler):
self.render("index.html")
+class ClientConnection(tornado.websocket.WebSocketHandler):
+ connections = set()
+
+ def open(self):
+ ClientConnection.connections.add(self)
+
+ def on_close(self):
+ ClientConnection.connections.remove(self)
+
+ @classmethod
+ def broadcast(cls, type, data):
+ for conn in cls.connections:
+ try:
+ conn.write_message(type, data)
+ except:
+ logging.error("Error sending message", exc_info=True)
+
+
class Application(tornado.web.Application):
def __init__(self, debug):
handlers = [
(r"/", IndexHandler),
+ (r"/updates", ClientConnection),
]
settings = dict(
template_path=os.path.join(os.path.dirname(__file__), "templates"),
diff --git a/libmproxy/web/static/js/app.js b/libmproxy/web/static/js/app.js
index c095fd44..6a157b24 100644
--- a/libmproxy/web/static/js/app.js
+++ b/libmproxy/web/static/js/app.js
@@ -198,17 +198,14 @@ _.extend(_EventLogStore.prototype, EventEmitter.prototype, {
var EventLogStore = new _EventLogStore();
AppDispatcher.register(EventLogStore.handle.bind(EventLogStore));
-function _Connection(root) {"use strict";
- if (!root) {
- root = location.origin + "/api/v1";
- }
- this.root = root;
- }
-_Connection.prototype.init=function() {"use strict";
+function _Connection(url) {
+ this.url = url;
+}
+_Connection.prototype.init=function() {
this.openWebSocketConnection();
};
-_Connection.prototype.openWebSocketConnection=function() {"use strict";
- this.ws = new WebSocket(this.root.replace("http", "ws") + "/ws");
+_Connection.prototype.openWebSocketConnection=function() {
+ this.ws = new WebSocket(this.url.replace("http", "ws"));
var ws = this.ws;
ws.onopen = this.onopen.bind(this);
@@ -216,21 +213,21 @@ _Connection.prototype.openWebSocketConnection=function() {"use strict";
ws.onerror = this.onerror.bind(this);
ws.onclose = this.onclose.bind(this);
};
-_Connection.prototype.onopen=function(open) {"use strict";
+_Connection.prototype.onopen=function(open) {
console.log("onopen", this, arguments);
};
-_Connection.prototype.onmessage=function(message) {"use strict";
+_Connection.prototype.onmessage=function(message) {
//AppDispatcher.dispatchServerAction(...);
console.log("onmessage", this, arguments);
};
-_Connection.prototype.onerror=function(error) {"use strict";
+_Connection.prototype.onerror=function(error) {
console.log("onerror", this, arguments);
};
-_Connection.prototype.onclose=function(close) {"use strict";
+_Connection.prototype.onclose=function(close) {
console.log("onclose", this, arguments);
};
-var Connection = new _Connection();
+var Connection = new _Connection(location.origin + "/updates");
/** @jsx React.DOM */