aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/web/app.py
diff options
context:
space:
mode:
Diffstat (limited to 'libmproxy/web/app.py')
-rw-r--r--libmproxy/web/app.py55
1 files changed, 49 insertions, 6 deletions
diff --git a/libmproxy/web/app.py b/libmproxy/web/app.py
index 37da4a42..7f1964ae 100644
--- a/libmproxy/web/app.py
+++ b/libmproxy/web/app.py
@@ -32,12 +32,30 @@ class WebSocketEventBroadcaster(tornado.websocket.WebSocketHandler):
logging.error("Error sending message", exc_info=True)
+class ClientConnection(WebSocketEventBroadcaster):
+ connections = set()
+
+
class Flows(tornado.web.RequestHandler):
def get(self):
self.write(dict(
data=[f.get_state(short=True) for f in self.application.state.flows]
))
+
+class AcceptFlows(tornado.web.RequestHandler):
+ def post(self):
+ self.application.state.flows.accept_all(self.application.master)
+
+
+class AcceptFlow(tornado.web.RequestHandler):
+ def post(self, flow_id):
+ flow_id = str(flow_id)
+ for flow in self.application.state.flows:
+ if flow.id == flow_id:
+ flow.accept_intercept(self.application.master)
+ break
+
class Events(tornado.web.RequestHandler):
def get(self):
self.write(dict(
@@ -49,28 +67,53 @@ class Settings(tornado.web.RequestHandler):
def get(self):
self.write(dict(
data=dict(
- showEventLog=True
+ showEventLog=True,
+ intercept=self.application.state.intercept_txt
)
))
+ def put(self, *update, **kwargs):
+ update = {}
+ for k, v in self.request.arguments.iteritems():
+ if len(v) != 1:
+ print "Warning: Unknown length for setting {}: {}".format(k, v)
+ continue
+
+ if k == "_xsrf":
+ continue
+ elif k == "intercept":
+ self.application.state.set_intercept(v[0])
+ update[k] = v[0]
+ else:
+ print "Warning: Unknown setting {}: {}".format(k, v)
+
+ ClientConnection.broadcast(
+ type="settings",
+ cmd="update",
+ data=update
+ )
+
class Clear(tornado.web.RequestHandler):
def post(self):
self.application.state.clear()
-class ClientConnection(WebSocketEventBroadcaster):
- connections = set()
+class Application(tornado.web.Application):
+ @property
+ def state(self):
+ return self.master.state
-class Application(tornado.web.Application):
- def __init__(self, state, debug):
- self.state = state
+ def __init__(self, master, debug):
+ self.master = master
handlers = [
(r"/", IndexHandler),
(r"/updates", ClientConnection),
(r"/events", Events),
(r"/flows", Flows),
+ (r"/flows/accept", AcceptFlows),
+ (r"/flows/([0-9a-f\-]+)/accept", AcceptFlow),
(r"/settings", Settings),
(r"/clear", Clear),
]