From 968c7021dfef00c459899520921faf7367e923d9 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 23 Mar 2015 00:24:56 +0100 Subject: web: add basic edit capability for first line --- libmproxy/web/app.py | 51 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 11 deletions(-) (limited to 'libmproxy/web/app.py') diff --git a/libmproxy/web/app.py b/libmproxy/web/app.py index 8598acf5..76160dc1 100644 --- a/libmproxy/web/app.py +++ b/libmproxy/web/app.py @@ -25,6 +25,12 @@ class RequestHandler(tornado.web.RequestHandler): "style-src 'self' 'unsafe-inline'" ) + @property + def json(self): + if not self.request.headers.get("Content-Type").startswith("application/json"): + return None + return json.loads(self.request.body) + @property def state(self): return self.application.master.state @@ -111,6 +117,35 @@ class FlowHandler(RequestHandler): self.flow.kill(self.master) self.state.delete_flow(self.flow) + def put(self, flow_id): + flow = self.flow + for a, b in self.json.iteritems(): + + if a == "request": + request = flow.request + for k, v in b.iteritems(): + if k in ["method", "scheme", "host", "path"]: + setattr(request, k, str(v)) + elif k == "port": + request.port = int(v) + elif k == "httpversion": + request.httpversion = tuple(int(x) for x in v) + else: + print "Warning: Unknown update {}.{}: {}".format(a, k, v) + + elif a == "response": + response = flow.response + for k, v in b.iteritems(): + if k == "msg": + response.msg = str(v) + elif k == "code": + response.code = int(v) + elif k == "httpversion": + response.httpversion = tuple(int(x) for x in v) + else: + print "Warning: Unknown update {}: {}".format(a, b) + self.state.update_flow(flow) + class DuplicateFlow(RequestHandler): def post(self, flow_id): @@ -176,18 +211,12 @@ class Settings(RequestHandler): ) )) - def put(self, *update, **kwargs): + def put(self): 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.state.set_intercept(v[0]) - update[k] = v[0] + for k, v in self.json.iteritems(): + if k == "intercept": + self.state.set_intercept(v) + update[k] = v else: print "Warning: Unknown setting {}: {}".format(k, v) -- cgit v1.2.3 From 9854379046a5464f4fd638785bafca87b91a495a Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 26 Mar 2015 18:17:30 +0100 Subject: web: backup flows on edit --- libmproxy/web/app.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'libmproxy/web/app.py') diff --git a/libmproxy/web/app.py b/libmproxy/web/app.py index 76160dc1..d95fb8ea 100644 --- a/libmproxy/web/app.py +++ b/libmproxy/web/app.py @@ -119,6 +119,7 @@ class FlowHandler(RequestHandler): def put(self, flow_id): flow = self.flow + self.state.backup(flow) for a, b in self.json.iteritems(): if a == "request": @@ -130,6 +131,8 @@ class FlowHandler(RequestHandler): request.port = int(v) elif k == "httpversion": request.httpversion = tuple(int(x) for x in v) + elif k == "headers": + request.headers.load_state(v) else: print "Warning: Unknown update {}.{}: {}".format(a, k, v) @@ -142,6 +145,10 @@ class FlowHandler(RequestHandler): response.code = int(v) elif k == "httpversion": response.httpversion = tuple(int(x) for x in v) + elif k == "headers": + response.headers.load_state(v) + else: + print "Warning: Unknown update {}.{}: {}".format(a, k, v) else: print "Warning: Unknown update {}: {}".format(a, b) self.state.update_flow(flow) -- cgit v1.2.3 From f39e6c5c18890de902d061226ba413254114c8ad Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 27 Mar 2015 18:51:25 +0100 Subject: web: minor ux improvements --- libmproxy/web/app.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libmproxy/web/app.py') diff --git a/libmproxy/web/app.py b/libmproxy/web/app.py index d95fb8ea..6bb522e1 100644 --- a/libmproxy/web/app.py +++ b/libmproxy/web/app.py @@ -166,6 +166,10 @@ class RevertFlow(RequestHandler): class ReplayFlow(RequestHandler): def post(self, flow_id): + self.flow.backup() + self.flow.response = None + self.state.update_flow(self.flow) + r = self.master.replay_request(self.flow) if r: raise APIError(400, r) -- cgit v1.2.3 From 3f5ca10c39a9f7d55e0f6943caf8f6ff762a0222 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 1 May 2015 17:24:44 +0200 Subject: mitmweb: add editor --- libmproxy/web/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libmproxy/web/app.py') diff --git a/libmproxy/web/app.py b/libmproxy/web/app.py index 6bb522e1..9582d97b 100644 --- a/libmproxy/web/app.py +++ b/libmproxy/web/app.py @@ -119,7 +119,7 @@ class FlowHandler(RequestHandler): def put(self, flow_id): flow = self.flow - self.state.backup(flow) + flow.backup() for a, b in self.json.iteritems(): if a == "request": -- cgit v1.2.3 From a05a70d8168a07c92b2a3ecbbb1958d85532efe3 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 30 May 2015 12:03:28 +1200 Subject: Add coding style check, reformat. --- libmproxy/web/app.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'libmproxy/web/app.py') diff --git a/libmproxy/web/app.py b/libmproxy/web/app.py index 9582d97b..69341e76 100644 --- a/libmproxy/web/app.py +++ b/libmproxy/web/app.py @@ -27,7 +27,8 @@ class RequestHandler(tornado.web.RequestHandler): @property def json(self): - if not self.request.headers.get("Content-Type").startswith("application/json"): + if not self.request.headers.get( + "Content-Type").startswith("application/json"): return None return json.loads(self.request.body) @@ -67,8 +68,10 @@ class FiltHelp(RequestHandler): commands=filt.help )) + class WebSocketEventBroadcaster(tornado.websocket.WebSocketHandler): - connections = None # raise an error if inherited class doesn't specify its own instance. + # raise an error if inherited class doesn't specify its own instance. + connections = None def open(self): self.connections.add(self) @@ -264,4 +267,4 @@ class Application(tornado.web.Application): cookie_secret=os.urandom(256), debug=debug, ) - super(Application, self).__init__(handlers, **settings) \ No newline at end of file + super(Application, self).__init__(handlers, **settings) -- cgit v1.2.3 From 4fe2c069cca07aadf983f54e18dac4de492d5d69 Mon Sep 17 00:00:00 2001 From: Jim Shaver Date: Fri, 29 May 2015 23:17:48 -0400 Subject: Fixed print function to be inline with python 3 --- libmproxy/web/app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libmproxy/web/app.py') diff --git a/libmproxy/web/app.py b/libmproxy/web/app.py index 8598acf5..2fc849f9 100644 --- a/libmproxy/web/app.py +++ b/libmproxy/web/app.py @@ -180,7 +180,7 @@ class Settings(RequestHandler): update = {} for k, v in self.request.arguments.iteritems(): if len(v) != 1: - print "Warning: Unknown length for setting {}: {}".format(k, v) + print("Warning: Unknown length for setting {}: {}".format(k, v)) continue if k == "_xsrf": @@ -189,7 +189,7 @@ class Settings(RequestHandler): self.state.set_intercept(v[0]) update[k] = v[0] else: - print "Warning: Unknown setting {}: {}".format(k, v) + print("Warning: Unknown setting {}: {}".format(k, v)) ClientConnection.broadcast( type="settings", @@ -224,4 +224,4 @@ class Application(tornado.web.Application): cookie_secret=os.urandom(256), debug=debug, ) - super(Application, self).__init__(handlers, **settings) \ No newline at end of file + super(Application, self).__init__(handlers, **settings) -- cgit v1.2.3