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.
This commit is contained in:
Aldo Cortesi 2011-05-14 10:44:25 +12:00
parent c6075e1d93
commit f89581be1b
6 changed files with 49 additions and 25 deletions

View File

@ -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,

View File

@ -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.

View File

@ -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()

View File

@ -10,6 +10,7 @@ class Options(object):
"client_replay",
"keepserving",
"kill",
"no_server",
"refresh_server_playback",
"request_script",
"response_script",

View File

@ -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

View File

@ -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