diff options
author | Maximilian Hils <git@maximilianhils.com> | 2014-12-23 20:33:42 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2014-12-23 20:33:42 +0100 |
commit | 2861d99de4d329bcba0a3c2193523398a22673c0 (patch) | |
tree | 0aa1a2aae666c2909285a6fd5049f2ef7d6d8ebc /libmproxy/web/app.py | |
parent | 459772a8ef79ac0adeaeba56577972e86074265e (diff) | |
download | mitmproxy-2861d99de4d329bcba0a3c2193523398a22673c0.tar.gz mitmproxy-2861d99de4d329bcba0a3c2193523398a22673c0.tar.bz2 mitmproxy-2861d99de4d329bcba0a3c2193523398a22673c0.zip |
web: intercept feature
Diffstat (limited to 'libmproxy/web/app.py')
-rw-r--r-- | libmproxy/web/app.py | 55 |
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), ] |