From f0f1fb4b556b048c5a8f93541bea751981136aba Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Thu, 17 Feb 2011 10:18:38 +1300 Subject: Add file writing to mitmdump. --- libmproxy/console.py | 2 +- libmproxy/dump.py | 19 ++++++++++++++++++- libmproxy/utils.py | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) (limited to 'libmproxy') diff --git a/libmproxy/console.py b/libmproxy/console.py index ac1ef16c..c14f1aef 100644 --- a/libmproxy/console.py +++ b/libmproxy/console.py @@ -822,7 +822,7 @@ class ConsoleMaster(flow.FlowMaster): self.stickycookie = None self.stickyhosts = {} - if options.cache is not None: + if getattr(options, "cache", None) is not None: self.state.start_recording(recorder.Recorder(options)) def spawn_external_viewer(self, data, contenttype): diff --git a/libmproxy/dump.py b/libmproxy/dump.py index 76bf3ae2..e30c2422 100644 --- a/libmproxy/dump.py +++ b/libmproxy/dump.py @@ -1,6 +1,9 @@ -import sys +import sys, os import flow +class DumpError(Exception): pass + + class Options(object): __slots__ = [ "verbosity", @@ -9,6 +12,9 @@ class Options(object): def __init__(self, **kwargs): for k, v in kwargs.items(): setattr(self, k, v) + for i in self.__slots__: + if not hasattr(self, i): + setattr(self, i, None) class DumpMaster(flow.FlowMaster): @@ -17,6 +23,14 @@ class DumpMaster(flow.FlowMaster): self.outfile = outfile self.o = options + if options.wfile: + path = os.path.expanduser(options.wfile) + try: + f = file(path, "wb") + self.fwriter = flow.FlowWriter(f) + except IOError, v: + raise DumpError(v.strerror) + def handle_clientconnection(self, r): flow.FlowMaster.handle_clientconnection(self, r) r.ack() @@ -56,6 +70,9 @@ class DumpMaster(flow.FlowMaster): msg.ack() self.state.delete_flow(f) + if self.o.wfile: + self.fwriter.add(f) + # begin nocover def run(self): diff --git a/libmproxy/utils.py b/libmproxy/utils.py index 7172b4db..c9be7483 100644 --- a/libmproxy/utils.py +++ b/libmproxy/utils.py @@ -525,6 +525,6 @@ def process_certificate_option_group(options): options.certpath = os.path.expanduser(options.certpath) elif options.cacert is not None: options.certpath = os.path.dirname(options.cacert) - if options.cache is not None: + if getattr(options, "cache", None) is not None: options.cache = os.path.expanduser(options.cache) -- cgit v1.2.3