From f89581be1b2a884fe95b764a25eead280303f595 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 14 May 2011 10:44:25 +1200 Subject: [PATCH] Add a -n option which tells the tools not to bind a proxy. This is useful when you just want to inspect or process dumps. --- libmproxy/cmdline.py | 20 +++++++++++++------- libmproxy/console.py | 17 +++++++++++------ libmproxy/controller.py | 8 ++++++-- libmproxy/dump.py | 1 + mitmdump | 14 +++++++++----- mitmproxy | 14 +++++++++----- 6 files changed, 49 insertions(+), 25 deletions(-) diff --git a/libmproxy/cmdline.py b/libmproxy/cmdline.py index 4ff7cbe08..222defebf 100644 --- a/libmproxy/cmdline.py +++ b/libmproxy/cmdline.py @@ -15,18 +15,19 @@ def get_common_options(options): stickyauth = options.stickyauth_filt return dict( - verbosity = options.verbose, - wfile = options.wfile, + anticache = options.anticache, + client_replay = options.client_replay, + kill = options.kill, + no_server = options.no_server, + refresh_server_playback = not options.norefresh, + rheaders = options.rheaders, request_script = options.request_script, response_script = options.response_script, server_replay = options.server_replay, - kill = options.kill, - rheaders = options.rheaders, - client_replay = options.client_replay, stickycookie = stickycookie, stickyauth = stickyauth, - anticache = options.anticache, - refresh_server_playback = not options.norefresh, + wfile = options.wfile, + verbosity = options.verbose, ) @@ -41,6 +42,11 @@ def common_options(parser): action="store", type = "str", dest="confdir", default='~/.mitmproxy', help = "Configuration directory. (~/.mitmproxy)" ) + parser.add_option( + "-n", + action="store_true", dest="no_server", + help="Don't start a proxy server." + ) parser.add_option( "-p", action="store", type = "int", dest="port", default=8080, diff --git a/libmproxy/console.py b/libmproxy/console.py index 399640c22..f0fb74e2e 100644 --- a/libmproxy/console.py +++ b/libmproxy/console.py @@ -664,16 +664,19 @@ class StatusBar(WWrap): ('statusbar_text', ("[%s]"%len(self.master.state.flow_list)).ljust(7)), ] t.extend(self.get_status()) + + if self.master.server: + boundaddr = "[%s:%s]"%(self.master.server.address or "*", self.master.server.port) + else: + boundaddr = "[no proxy]" + status = urwid.AttrWrap(urwid.Columns([ urwid.Text(t), urwid.Text( [ self.helptext, " ", - ( - 'statusbar_text', - "[%s:%s]"%(self.master.server.address or "*", self.master.server.port) - ), + ('statusbar_text', boundaddr), ], align="right" ), @@ -775,6 +778,7 @@ class Options(object): "kill", "intercept", "limit", + "no_server", "refresh_server_playback", "request_script", "response_script", @@ -1024,8 +1028,9 @@ class ConsoleMaster(flow.FlowMaster): self.view_connlist() self.masterq = Queue.Queue() - slave = controller.Slave(self.masterq, self.server) - slave.start() + if self.server: + slave = controller.Slave(self.masterq, self.server) + slave.start() self.ui.run_wrapper(self.loop) # If True, quit just pops out to connection list view. diff --git a/libmproxy/controller.py b/libmproxy/controller.py index f0e65e7f1..337f379dc 100644 --- a/libmproxy/controller.py +++ b/libmproxy/controller.py @@ -58,6 +58,9 @@ class Slave(threading.Thread): class Master: def __init__(self, server): + """ + server may be None if no server is needed. + """ self.server = server self.masterq = Queue.Queue() @@ -75,8 +78,9 @@ class Master: pass def run(self): - slave = Slave(self.masterq, self.server) - slave.start() + if self.server: + slave = Slave(self.masterq, self.server) + slave.start() while not exit: self.tick(self.masterq) self.shutdown() diff --git a/libmproxy/dump.py b/libmproxy/dump.py index 6f18c8fec..3e645167f 100644 --- a/libmproxy/dump.py +++ b/libmproxy/dump.py @@ -10,6 +10,7 @@ class Options(object): "client_replay", "keepserving", "kill", + "no_server", "refresh_server_playback", "request_script", "response_script", diff --git a/mitmdump b/mitmdump index 461abf4b6..b54d051f6 100755 --- a/mitmdump +++ b/mitmdump @@ -39,11 +39,15 @@ if __name__ == '__main__': options.verbose = 0 config = proxy.process_certificate_option_group(parser, options) - try: - server = proxy.ProxyServer(config, options.port, options.addr) - except proxy.ProxyServerError, v: - print >> sys.stderr, "mitmdump:", v.args[0] - sys.exit(1) + if options.no_server: + server = None + else: + try: + server = proxy.ProxyServer(config, options.port, options.addr) + except proxy.ProxyServerError, v: + print >> sys.stderr, "mitmdump:", v.args[0] + sys.exit(1) + dumpopts = dump.Options(**cmdline.get_common_options(options)) dumpopts.keepserving = options.keepserving diff --git a/mitmproxy b/mitmproxy index a1828b846..bcb079a30 100755 --- a/mitmproxy +++ b/mitmproxy @@ -49,11 +49,15 @@ if __name__ == '__main__': options, args = parser.parse_args() config = proxy.process_certificate_option_group(parser, options) - try: - server = proxy.ProxyServer(config, options.port, options.addr) - except proxy.ProxyServerError, v: - print >> sys.stderr, "mitmproxy:", v.args[0] - sys.exit(1) + + if options.no_server: + server = None + else: + try: + server = proxy.ProxyServer(config, options.port, options.addr) + except proxy.ProxyServerError, v: + print >> sys.stderr, "mitmproxy:", v.args[0] + sys.exit(1) opts = console.Options(**cmdline.get_common_options(options)) opts.intercept = options.intercept