From ed8249023fb7c0d429b9278c63b51ac071700987 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Wed, 26 Nov 2014 04:18:21 +0100 Subject: introduce revised views, port over changes from multiple_views branch --- libmproxy/web/__init__.py | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'libmproxy/web/__init__.py') diff --git a/libmproxy/web/__init__.py b/libmproxy/web/__init__.py index 69971436..f762466a 100644 --- a/libmproxy/web/__init__.py +++ b/libmproxy/web/__init__.py @@ -9,9 +9,32 @@ class Stop(Exception): pass +class WebFlowView(flow.FlowView): + def __init__(self, store): + super(WebFlowView, self).__init__(store, None) + + def _add(self, f): + super(WebFlowView, self)._add(f) + app.FlowUpdates.broadcast("add", f.get_state(short=True)) + + def _update(self, f): + super(WebFlowView, self)._update(f) + app.FlowUpdates.broadcast("update", f.get_state(short=True)) + + def _remove(self, f): + super(WebFlowView, self)._remove(f) + app.FlowUpdates.broadcast("remove", f.get_state(short=True)) + + def _recalculate(self, flows): + super(WebFlowView, self)._recalculate(flows) + app.FlowUpdates.broadcast("recalculate", None) + + class WebState(flow.State): def __init__(self): - flow.State.__init__(self) + super(WebState, self).__init__() + self.view._close() + self.view = WebFlowView(self.flows) class Options(object): @@ -58,8 +81,8 @@ class Options(object): class WebMaster(flow.FlowMaster): def __init__(self, server, options): self.options = options - self.app = app.Application(self.options.wdebug) super(WebMaster, self).__init__(server, WebState()) + self.app = app.Application(self.state, self.options.wdebug) self.last_log_id = 0 @@ -83,24 +106,17 @@ class WebMaster(flow.FlowMaster): self.shutdown() def handle_request(self, f): - app.ClientConnection.broadcast("add_flow", f.get_state(True)) - flow.FlowMaster.handle_request(self, f) + super(WebMaster, self).handle_request(f) if f: f.reply() return f def handle_response(self, f): - app.ClientConnection.broadcast("update_flow", f.get_state(True)) - flow.FlowMaster.handle_response(self, f) + super(WebMaster, self).handle_response(f) if f: f.reply() return f - def handle_error(self, f): - app.ClientConnection.broadcast("update_flow", f.get_state(True)) - flow.FlowMaster.handle_error(self, f) - return f - def handle_log(self, l): self.last_log_id += 1 app.ClientConnection.broadcast( -- cgit v1.2.3 From c39b6e4277357c9da1dfd5e3e8c41b5b3427e0ce Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 28 Nov 2014 19:16:47 +0100 Subject: web: various fixes, add clear button --- libmproxy/web/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libmproxy/web/__init__.py') diff --git a/libmproxy/web/__init__.py b/libmproxy/web/__init__.py index f762466a..a110aa4d 100644 --- a/libmproxy/web/__init__.py +++ b/libmproxy/web/__init__.py @@ -27,7 +27,7 @@ class WebFlowView(flow.FlowView): def _recalculate(self, flows): super(WebFlowView, self)._recalculate(flows) - app.FlowUpdates.broadcast("recalculate", None) + app.FlowUpdates.broadcast("reset", None) class WebState(flow.State): -- cgit v1.2.3 From 14a8d2f5b83a1ea28abbb490f6c94c43b4e1f960 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Tue, 9 Dec 2014 18:18:14 +0100 Subject: always use the app dispatcher --- libmproxy/web/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libmproxy/web/__init__.py') diff --git a/libmproxy/web/__init__.py b/libmproxy/web/__init__.py index a110aa4d..50c4b843 100644 --- a/libmproxy/web/__init__.py +++ b/libmproxy/web/__init__.py @@ -15,19 +15,19 @@ class WebFlowView(flow.FlowView): def _add(self, f): super(WebFlowView, self)._add(f) - app.FlowUpdates.broadcast("add", f.get_state(short=True)) + app.ClientConnection.broadcast("add_flow", f.get_state(short=True)) def _update(self, f): super(WebFlowView, self)._update(f) - app.FlowUpdates.broadcast("update", f.get_state(short=True)) + app.ClientConnection.broadcast("update_flow", f.get_state(short=True)) def _remove(self, f): super(WebFlowView, self)._remove(f) - app.FlowUpdates.broadcast("remove", f.get_state(short=True)) + app.ClientConnection.broadcast("remove_flow", f.get_state(short=True)) def _recalculate(self, flows): super(WebFlowView, self)._recalculate(flows) - app.FlowUpdates.broadcast("reset", None) + app.ClientConnection.broadcast("reset_flows", None) class WebState(flow.State): -- cgit v1.2.3 From 05bc7e8cd8382aabdd44f7bc569d2fd421c26f21 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Tue, 9 Dec 2014 18:55:16 +0100 Subject: generalize store --- libmproxy/web/__init__.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'libmproxy/web/__init__.py') diff --git a/libmproxy/web/__init__.py b/libmproxy/web/__init__.py index 50c4b843..8f9fffdd 100644 --- a/libmproxy/web/__init__.py +++ b/libmproxy/web/__init__.py @@ -15,19 +15,34 @@ class WebFlowView(flow.FlowView): def _add(self, f): super(WebFlowView, self)._add(f) - app.ClientConnection.broadcast("add_flow", f.get_state(short=True)) + app.ClientConnection.broadcast( + type="flows", + cmd="add", + data=f.get_state(short=True) + ) def _update(self, f): super(WebFlowView, self)._update(f) - app.ClientConnection.broadcast("update_flow", f.get_state(short=True)) + app.ClientConnection.broadcast( + type="flows", + cmd="update", + data=f.get_state(short=True) + ) def _remove(self, f): super(WebFlowView, self)._remove(f) - app.ClientConnection.broadcast("remove_flow", f.get_state(short=True)) + app.ClientConnection.broadcast( + type="flows", + cmd="remove", + data=f.get_state(short=True) + ) def _recalculate(self, flows): super(WebFlowView, self)._recalculate(flows) - app.ClientConnection.broadcast("reset_flows", None) + app.ClientConnection.broadcast( + type="flows", + cmd="reset" + ) class WebState(flow.State): @@ -120,7 +135,8 @@ class WebMaster(flow.FlowMaster): def handle_log(self, l): self.last_log_id += 1 app.ClientConnection.broadcast( - "add_event", { + type="add_event", + data={ "id": self.last_log_id, "message": l.msg, "level": l.level -- cgit v1.2.3 From e12bf19e35867f3ea69f45054decb024a75fc2b4 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Wed, 10 Dec 2014 00:47:05 +0100 Subject: web: add event store, fix all those bugs --- libmproxy/web/__init__.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'libmproxy/web/__init__.py') diff --git a/libmproxy/web/__init__.py b/libmproxy/web/__init__.py index 8f9fffdd..aa1531b3 100644 --- a/libmproxy/web/__init__.py +++ b/libmproxy/web/__init__.py @@ -1,4 +1,5 @@ from __future__ import absolute_import, print_function +import collections import tornado.ioloop import tornado.httpserver from .. import controller, flow @@ -51,6 +52,22 @@ class WebState(flow.State): self.view._close() self.view = WebFlowView(self.flows) + self._last_event_id = 0 + self.events = collections.deque(maxlen=1000) + + def add_event(self, e, level): + self._last_event_id += 1 + entry = { + "id": self._last_event_id, + "message": e, + "level": level + } + self.events.append(entry) + app.ClientConnection.broadcast( + type="events", + cmd="add", + data=entry + ) class Options(object): attributes = [ @@ -99,8 +116,6 @@ class WebMaster(flow.FlowMaster): super(WebMaster, self).__init__(server, WebState()) self.app = app.Application(self.state, self.options.wdebug) - self.last_log_id = 0 - def tick(self): flow.FlowMaster.tick(self, self.masterq, timeout=0) @@ -132,16 +147,6 @@ class WebMaster(flow.FlowMaster): f.reply() return f - def handle_log(self, l): - self.last_log_id += 1 - app.ClientConnection.broadcast( - type="add_event", - data={ - "id": self.last_log_id, - "message": l.msg, - "level": l.level - } - ) - self.add_event(l.msg, l.level) - l.reply() - + def add_event(self, e, level="info"): + super(WebMaster, self).add_event(e, level) + self.state.add_event(e, level) \ No newline at end of file -- cgit v1.2.3