From 493302d1805d49935d4ab9d2fad3311b4f3d3541 Mon Sep 17 00:00:00 2001 From: Chris Czub Date: Mon, 16 Nov 2015 11:53:08 -0500 Subject: Support writing to outfile from mitmweb --- libmproxy/console/__init__.py | 9 --------- libmproxy/flow.py | 12 +++++++++++- libmproxy/web/__init__.py | 10 ++++++++++ 3 files changed, 21 insertions(+), 10 deletions(-) (limited to 'libmproxy') diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index cef2013e..31edca81 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -290,15 +290,6 @@ class ConsoleMaster(flow.FlowMaster): self.loop.widget = window self.loop.draw_screen() - def start_stream_to_path(self, path, mode="wb"): - path = os.path.expanduser(path) - try: - f = file(path, mode) - self.start_stream(f, None) - except IOError as v: - return str(v) - self.stream_path = path - def _run_script_method(self, method, s, f): status, val = s.run(method, f) if val: diff --git a/libmproxy/flow.py b/libmproxy/flow.py index a2b069ed..f02b5767 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -665,7 +665,7 @@ class FlowMaster(controller.Master): self.add_event("Script error:\n" + str(e), "error") script.reloader.unwatch(script_obj) self.scripts.remove(script_obj) - + def load_script(self, command, use_reloader=False): """ Loads a script. Returns an error description if something went @@ -1066,6 +1066,16 @@ class FlowMaster(controller.Master): self.stream.fo.close() self.stream = None + def start_stream_to_path(self, path, mode="wb"): + path = os.path.expanduser(path) + try: + f = file(path, mode) + self.start_stream(f, None) + except IOError as v: + return str(v) + self.stream_path = path + + def read_flows_from_paths(paths): """ Given a list of filepaths, read all flows and return a list of them. diff --git a/libmproxy/web/__init__.py b/libmproxy/web/__init__.py index a0af7315..90da6ffe 100644 --- a/libmproxy/web/__init__.py +++ b/libmproxy/web/__init__.py @@ -134,6 +134,16 @@ class WebMaster(flow.FlowMaster): "Could not read flow file: %s" % v, "error" ) + + if options.outfile: + err = self.start_stream_to_path( + options.outfile[0], + options.outfile[1] + ) + if err: + print >> sys.stderr, "Stream file error:", err + sys.exit(1) + if self.options.app: self.start_app(self.options.app_host, self.options.app_port) -- cgit v1.2.3 From aea3837d4ae637af42f716acb27d7ea8394ece35 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Sun, 10 Jan 2016 11:45:26 +0100 Subject: remove code duplication --- libmproxy/dump.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'libmproxy') diff --git a/libmproxy/dump.py b/libmproxy/dump.py index 22a2b75c..c2a3268a 100644 --- a/libmproxy/dump.py +++ b/libmproxy/dump.py @@ -85,12 +85,12 @@ class DumpMaster(flow.FlowMaster): self.set_stickyauth(options.stickyauth) if options.outfile: - path = os.path.expanduser(options.outfile[0]) - try: - f = open(path, options.outfile[1]) - self.start_stream(f, self.filt) - except IOError as v: - raise DumpError(v.strerror) + err = self.start_stream_to_path( + options.outfile[0], + options.outfile[1] + ) + if err: + raise DumpError(err) if options.replacements: for i in options.replacements: -- cgit v1.2.3