diff --git a/libmproxy/console.py b/libmproxy/console.py index 8507c1e30..7c12cc0ce 100644 --- a/libmproxy/console.py +++ b/libmproxy/console.py @@ -14,7 +14,7 @@ # along with this program. If not, see . import Queue, mailcap, mimetypes, tempfile, os, subprocess, threading -import os.path +import os.path, sys import cStringIO import urwid.curses_display import urwid @@ -609,6 +609,8 @@ class State: if not f: return False f.request = req + if self.focus is None: + self.set_focus(0) return f def add_response(self, resp): @@ -618,6 +620,8 @@ class State: f.response = resp f.waiting = False f.backup() + if self.focus is None: + self.set_focus(0) return f def add_error(self, err): @@ -661,7 +665,7 @@ class State: return self.flow_map.get(connection) def get_focus(self): - if not self.view: + if not self.view or self.focus is None: return None, None return self.view[self.focus], self.focus @@ -762,6 +766,26 @@ class ConsoleMaster(controller.Master): controller.Master.__init__(self, server) self.state = State() + r = self.set_limit(options.limit) + if r: + print >> sys.stderr, "Limit error:", r + sys.exit(1) + + r = self.set_intercept(options.intercept) + if r: + print >> sys.stderr, "Intercept error:", r + sys.exit(1) + + r = self.set_beep(options.beep) + if r: + print >> sys.stderr, "Beep error:", r + sys.exit(1) + + r = self.set_stickycookie(options.sticky) + if r: + print >> sys.stderr, "Sticky cookies error:", r + sys.exit(1) + self.stickycookie = None self.stickyhosts = {} @@ -974,7 +998,6 @@ class ConsoleMaster(controller.Master): self.state.set_limit(f) else: self.state.set_limit(None) - self.sync_list_view() def set_intercept(self, txt): if txt: @@ -983,7 +1006,6 @@ class ConsoleMaster(controller.Master): return "Invalid filter expression." else: self.state.intercept = None - self.sync_list_view() def set_beep(self, txt): if txt: @@ -1040,9 +1062,11 @@ class ConsoleMaster(controller.Master): self.view_help() elif k == "l": self.prompt("Limit: ", self.set_limit) + self.sync_list_view() k = None elif k == "i": self.prompt("Intercept: ", self.set_intercept) + self.sync_list_view() k = None elif k == "B": self.prompt("Beep: ", self.set_beep) diff --git a/mitmproxy b/mitmproxy index af841144d..fbe325fa6 100755 --- a/mitmproxy +++ b/mitmproxy @@ -25,16 +25,46 @@ if __name__ == '__main__': usage = "%prog [options] output", version="%prog 0.1", ) + parser.add_option( "-c", "--cert", action="store", type = "str", dest="cert", default="~/.mitmproxy/cert.pem", help = "SSL certificate file." ) + parser.add_option( "-p", "--port", action="store", type = "int", dest="port", default=8080, help = "Port." ) + + group = OptionGroup( + parser, + "Filters", + "See help in mitmproxy for filter expression syntax." + ) + group.add_option( + "-B", "--beep", action="store", + type = "str", dest="beep", default=None, + help = "Beep filter expression." + ) + group.add_option( + "-l", "--limit", action="store", + type = "str", dest="limit", default=None, + help = "Limit filter expression." + ) + group.add_option( + "-i", "--intercept", action="store", + type = "str", dest="intercept", default=None, + help = "Intercept filter expression." + ) + group.add_option( + "-s", "--sticky", action="store", + type = "str", dest="sticky", default=None, + help = "Sticky cookie filter expression." + ) + parser.add_option_group(group) + options, args = parser.parse_args() certpath = os.path.expanduser(options.cert)