From 5c1157ddaf01b9245519d176469587aa6539ac5d Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 24 Jul 2013 10:32:56 +1200 Subject: Move app instantiation out of proxy.py. --- libmproxy/console/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libmproxy/console') diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index ef799167..dd3adaa9 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -328,6 +328,9 @@ class ConsoleState(flow.State): class Options(object): attributes = [ + "app", + "app_domain", + "app_ip", "anticache", "anticomp", "client_replay", @@ -426,6 +429,9 @@ class ConsoleMaster(flow.FlowMaster): print >> sys.stderr, "Script load error:", err sys.exit(1) + if options.app: + self.start_app(options.app_domain, options.app_ip) + def start_stream(self, path): path = os.path.expanduser(path) try: -- cgit v1.2.3 From 10a9e3365fbfc0b0b789385a3a212ca01d332ab1 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 28 Jul 2013 18:00:49 +1200 Subject: Some refactoring of the console inteface. Reduce some state duplication, by removing currentflow variable. Fixes #141 --- libmproxy/console/__init__.py | 51 +++++++++++++++++++------------------------ libmproxy/console/common.py | 3 +++ libmproxy/console/flowlist.py | 3 +-- libmproxy/console/flowview.py | 5 ++--- 4 files changed, 29 insertions(+), 33 deletions(-) (limited to 'libmproxy/console') diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index dd3adaa9..cf4fc988 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -204,15 +204,10 @@ class StatusBar(common.WWrap): self.message("") fc = self.master.state.flow_count() - if self.master.currentflow: - idx = self.master.state.view.index(self.master.currentflow) + 1 - t = [ - ('heading', ("[%s/%s]"%(idx, fc)).ljust(9)) - ] - else: - t = [ - ('heading', ("[%s]"%fc).ljust(9)) - ] + offset = min(self.master.state.focus + 1, fc) + t = [ + ('heading', ("[%s/%s]"%(offset, fc)).ljust(9)) + ] if self.master.server.bound: boundaddr = "[%s:%s]"%(self.master.server.address or "*", self.master.server.port) @@ -263,7 +258,10 @@ class ConsoleState(flow.State): self.focus = None self.follow_focus = None self.default_body_view = contentview.get("Auto") + + self.view_mode = common.VIEW_LIST self.view_flow_mode = common.VIEW_FLOW_REQUEST + self.last_script = "" self.last_saveload = "" self.flowsettings = weakref.WeakKeyDictionary() @@ -308,6 +306,9 @@ class ConsoleState(flow.State): idx = 0 self.focus = idx + def set_focus_flow(self, f): + self.set_focus(self.view.index(f)) + def get_from_pos(self, pos): if len(self.view) <= pos or pos < 0: return None, None @@ -320,6 +321,8 @@ class ConsoleState(flow.State): return self.get_from_pos(pos-1) def delete_flow(self, f): + if f in self.view and self.view.index(f) <= self.focus: + self.focus -= 1 ret = flow.State.delete_flow(self, f) self.set_focus(self.focus) return ret @@ -570,8 +573,6 @@ class ConsoleMaster(flow.FlowMaster): self.palette = palettes.palettes[name] def run(self): - self.currentflow = None - self.ui = urwid.raw_display.Screen() self.ui.set_terminal_properties(256) self.ui.register_palette(self.palette) @@ -605,13 +606,6 @@ class ConsoleMaster(flow.FlowMaster): sys.stderr.flush() self.shutdown() - def focus_current(self): - if self.currentflow: - try: - self.flow_list_walker.set_focus(self.state.view.index(self.currentflow)) - except (IndexError, ValueError): - pass - def make_view(self): self.view = urwid.Frame( self.body, @@ -646,8 +640,6 @@ class ConsoleMaster(flow.FlowMaster): self.ui.clear() if self.state.follow_focus: self.state.set_focus(self.state.flow_count()) - else: - self.focus_current() if self.eventlog: self.body = flowlist.BodyPile(self) @@ -655,7 +647,7 @@ class ConsoleMaster(flow.FlowMaster): self.body = flowlist.FlowListBox(self) self.statusbar = StatusBar(self, flowlist.footer) self.header = None - self.currentflow = None + self.state.view_mode = common.VIEW_LIST self.make_view() self.help_context = flowlist.help_context @@ -664,7 +656,8 @@ class ConsoleMaster(flow.FlowMaster): self.body = flowview.FlowView(self, self.state, flow) self.header = flowview.FlowViewHeader(self, flow) self.statusbar = StatusBar(self, flowview.footer) - self.currentflow = flow + self.state.set_focus_flow(flow) + self.state.view_mode = common.VIEW_FLOW self.make_view() self.help_context = flowview.help_context @@ -711,7 +704,6 @@ class ConsoleMaster(flow.FlowMaster): f.close() if self.flow_list_walker: self.sync_list_view() - self.focus_current() return reterr def path_prompt(self, prompt, text, callback, *args): @@ -777,8 +769,7 @@ class ConsoleMaster(flow.FlowMaster): def change_default_display_mode(self, t): v = contentview.get_by_shortcut(t) self.state.default_body_view = v - if self.currentflow: - self.refresh_flow(self.currentflow) + self.refresh_focus() def set_reverse_proxy(self, txt): if not txt: @@ -796,8 +787,8 @@ class ConsoleMaster(flow.FlowMaster): return size def pop_view(self): - if self.currentflow: - self.view_flow(self.currentflow) + if self.state.view_mode == common.VIEW_FLOW: + self.view_flow(self.state.view[self.state.focus]) else: self.view_flowlist() @@ -972,7 +963,7 @@ class ConsoleMaster(flow.FlowMaster): if a == "h": self.showhost = not self.showhost self.sync_list_view() - self.refresh_flow(self.currentflow) + self.refresh_focus() elif a == "k": self.killextra = not self.killextra elif a == "n": @@ -1003,6 +994,10 @@ class ConsoleMaster(flow.FlowMaster): self.state.delete_flow(f) self.sync_list_view() + def refresh_focus(self): + if self.state.view: + self.refresh_flow(self.state.view[self.state.focus]) + def refresh_flow(self, c): if hasattr(self.header, "refresh_flow"): self.header.refresh_flow(c) diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py index d68aba3d..4f3ab090 100644 --- a/libmproxy/console/common.py +++ b/libmproxy/console/common.py @@ -18,6 +18,9 @@ import urwid.util from .. import utils, flow +VIEW_LIST = 0 +VIEW_FLOW = 1 + VIEW_FLOW_REQUEST = 0 VIEW_FLOW_RESPONSE = 1 diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index 8fd4efce..124e252e 100644 --- a/libmproxy/console/flowlist.py +++ b/libmproxy/console/flowlist.py @@ -160,8 +160,7 @@ class ConnectionItem(common.WWrap): self.master.sync_list_view() elif key == "D": f = self.master.duplicate_flow(self.flow) - self.master.currentflow = f - self.master.focus_current() + self.master.view_flow(f) elif key == "r": self.flow.backup() r = self.master.replay_request(self.flow) diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index da5a6c65..419bfbcd 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -342,7 +342,7 @@ class FlowView(common.WWrap): else: if not self.flow.response: self.flow.response = flow.Response( - self.flow.request, + self.flow.request, self.flow.request.httpversion, 200, "OK", flow.ODictCaseless(), "", None ) @@ -393,7 +393,7 @@ class FlowView(common.WWrap): new_flow, new_idx = self.state.get_next(idx) else: new_flow, new_idx = self.state.get_prev(idx) - if new_idx is None: + if new_flow is None: self.master.statusbar.message("No more flows!") return self.master.view_flow(new_flow) @@ -478,7 +478,6 @@ class FlowView(common.WWrap): elif key == "D": f = self.master.duplicate_flow(self.flow) self.master.view_flow(f) - self.master.currentflow = f self.master.statusbar.message("Duplicated.") elif key == "e": if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST: -- cgit v1.2.3 From a21c989ccdcb8f96a1b98fd216d9cb3ee1173681 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 28 Jul 2013 22:40:51 +1200 Subject: Fix startup with no state. Bug introduced in previous patch. --- libmproxy/console/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'libmproxy/console') diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index cf4fc988..69fa6fa8 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -204,7 +204,10 @@ class StatusBar(common.WWrap): self.message("") fc = self.master.state.flow_count() - offset = min(self.master.state.focus + 1, fc) + if self.master.state.focus is None: + offset = 0 + else: + offset = min(self.master.state.focus + 1, fc) t = [ ('heading', ("[%s/%s]"%(offset, fc)).ljust(9)) ] -- cgit v1.2.3 From d54398cc7909584d34990eaaa492f47bff156d93 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Mon, 29 Jul 2013 12:38:41 +1200 Subject: Repair minor user interface issue that caused brief flashes of duplicate flows in the flow list. --- libmproxy/console/__init__.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libmproxy/console') diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index 69fa6fa8..16c257bb 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -326,6 +326,8 @@ class ConsoleState(flow.State): def delete_flow(self, f): if f in self.view and self.view.index(f) <= self.focus: self.focus -= 1 + if self.focus < 0: + self.focus = None ret = flow.State.delete_flow(self, f) self.set_focus(self.focus) return ret -- cgit v1.2.3 From 5f0b5532bc9681c0fac8cfe821f49bff904d47be Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Mon, 29 Jul 2013 18:14:11 +1200 Subject: Show an error when attempting to decode invalid data. --- libmproxy/console/flowview.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libmproxy/console') diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index 419bfbcd..61e8715b 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -576,7 +576,8 @@ class FlowView(common.WWrap): self.flow.backup() e = conn.headers.get_first("content-encoding", "identity") if e != "identity": - conn.decode() + if not conn.decode(): + self.master.statusbar.message("Could not decode - invalid data?") else: self.master.prompt_onekey( "Select encoding: ", -- cgit v1.2.3 From edb10e33aa84c45410bfbd1088b7714245c9f154 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Thu, 1 Aug 2013 11:08:00 +1200 Subject: Remove GPL notices left in source files after our change to the MIT license. Thanks to Roy Shamir for reporting this. --- libmproxy/console/__init__.py | 15 --------------- libmproxy/console/common.py | 15 --------------- libmproxy/console/flowdetailview.py | 15 --------------- libmproxy/console/flowlist.py | 15 --------------- libmproxy/console/flowview.py | 15 --------------- libmproxy/console/grideditor.py | 15 --------------- libmproxy/console/help.py | 15 --------------- libmproxy/console/palettes.py | 15 --------------- 8 files changed, 120 deletions(-) (limited to 'libmproxy/console') diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index 16c257bb..37f5d646 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -1,18 +1,3 @@ -# Copyright (C) 2010 Aldo Cortesi -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - import mailcap, mimetypes, tempfile, os, subprocess, glob, time, shlex, stat import os.path, sys, weakref import urwid diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py index 4f3ab090..187a755f 100644 --- a/libmproxy/console/common.py +++ b/libmproxy/console/common.py @@ -1,18 +1,3 @@ -# Copyright (C) 2012 Aldo Cortesi -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - import urwid import urwid.util from .. import utils, flow diff --git a/libmproxy/console/flowdetailview.py b/libmproxy/console/flowdetailview.py index c4090c85..a26e5308 100644 --- a/libmproxy/console/flowdetailview.py +++ b/libmproxy/console/flowdetailview.py @@ -1,18 +1,3 @@ -# Copyright (C) 2012 Aldo Cortesi -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - import urwid import common diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index 124e252e..6ba97733 100644 --- a/libmproxy/console/flowlist.py +++ b/libmproxy/console/flowlist.py @@ -1,18 +1,3 @@ -# Copyright (C) 2012 Aldo Cortesi -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - import urwid import common diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index 61e8715b..c19ba5e6 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -1,18 +1,3 @@ -# Copyright (C) 2012 Aldo Cortesi -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - import os, sys import urwid import common, grideditor, contentview diff --git a/libmproxy/console/grideditor.py b/libmproxy/console/grideditor.py index 55f3ba0f..4986840d 100644 --- a/libmproxy/console/grideditor.py +++ b/libmproxy/console/grideditor.py @@ -1,18 +1,3 @@ -# Copyright (C) 2012 Aldo Cortesi -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - import copy, re, os import urwid import common diff --git a/libmproxy/console/help.py b/libmproxy/console/help.py index de373083..f8be6605 100644 --- a/libmproxy/console/help.py +++ b/libmproxy/console/help.py @@ -1,18 +1,3 @@ -# Copyright (C) 2012 Aldo Cortesi -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - import urwid import common from .. import filt, version diff --git a/libmproxy/console/palettes.py b/libmproxy/console/palettes.py index c4e92d99..650cf261 100644 --- a/libmproxy/console/palettes.py +++ b/libmproxy/console/palettes.py @@ -1,18 +1,3 @@ -# Copyright (C) 2012 Aldo Cortesi -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - palettes = { # Default palette for dark background -- cgit v1.2.3