diff options
author | Maximilian Hils <git@maximilianhils.com> | 2013-08-17 13:30:36 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2013-08-17 13:30:36 +0200 |
commit | 729677cd85cffedec8f481f1b6025f00fb637e13 (patch) | |
tree | 39c245643c5a3a48bd14c6e13757148bda54e2f3 /libmproxy/console | |
parent | 6fe175913e611097fdfdf0a6b20b1c05909374e1 (diff) | |
parent | a558c016d4430b67d221a369abe0cde1f4a40fce (diff) | |
download | mitmproxy-729677cd85cffedec8f481f1b6025f00fb637e13.tar.gz mitmproxy-729677cd85cffedec8f481f1b6025f00fb637e13.tar.bz2 mitmproxy-729677cd85cffedec8f481f1b6025f00fb637e13.zip |
Merge branch 'master' into 0.10
Diffstat (limited to 'libmproxy/console')
-rw-r--r-- | libmproxy/console/__init__.py | 75 | ||||
-rw-r--r-- | libmproxy/console/common.py | 18 | ||||
-rw-r--r-- | libmproxy/console/flowdetailview.py | 15 | ||||
-rw-r--r-- | libmproxy/console/flowlist.py | 18 | ||||
-rw-r--r-- | libmproxy/console/flowview.py | 23 | ||||
-rw-r--r-- | libmproxy/console/grideditor.py | 15 | ||||
-rw-r--r-- | libmproxy/console/help.py | 15 | ||||
-rw-r--r-- | libmproxy/console/palettes.py | 15 |
8 files changed, 41 insertions, 153 deletions
diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index 2c673531..04e240d3 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 <http://www.gnu.org/licenses/>. - import mailcap, mimetypes, tempfile, os, subprocess, glob, time, shlex, stat import os.path, sys, weakref import urwid @@ -204,15 +189,13 @@ 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)) - ] + if self.master.state.focus is None: + offset = 0 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 +246,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 +294,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 +309,10 @@ 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 + if self.focus < 0: + self.focus = None ret = flow.State.delete_flow(self, f) self.set_focus(self.focus) return ret @@ -328,6 +321,9 @@ class ConsoleState(flow.State): class Options(object): attributes = [ + "app", + "app_domain", + "app_ip", "anticache", "anticomp", "client_replay", @@ -426,6 +422,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: @@ -564,8 +563,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) @@ -599,13 +596,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, @@ -640,8 +630,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) @@ -649,7 +637,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 @@ -658,7 +646,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 @@ -705,7 +694,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): @@ -771,8 +759,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: @@ -790,8 +777,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() @@ -966,7 +953,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": @@ -997,6 +984,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..187a755f 100644 --- a/libmproxy/console/common.py +++ b/libmproxy/console/common.py @@ -1,23 +1,11 @@ -# 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 <http://www.gnu.org/licenses/>. - import urwid 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/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 <http://www.gnu.org/licenses/>. - import urwid import common diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index 8fd4efce..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 <http://www.gnu.org/licenses/>. - import urwid import common @@ -160,8 +145,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..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 <http://www.gnu.org/licenses/>. - import os, sys import urwid import common, grideditor, contentview @@ -342,7 +327,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 +378,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 +463,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: @@ -577,7 +561,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: ", 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 <http://www.gnu.org/licenses/>. - 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 <http://www.gnu.org/licenses/>. - 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 <http://www.gnu.org/licenses/>. - palettes = { # Default palette for dark background |