From a5f87657e1c55a73513a1ab73e31c0870c4aec0f Mon Sep 17 00:00:00 2001 From: Thomas Roth Date: Fri, 26 Feb 2010 14:01:38 +0100 Subject: [PATCH] Added beeping. --bireq and --bires enables beeping on intercepted requests/responses. --- libmproxy/console.py | 23 ++++++++++++++++++++--- mitmproxy | 10 +++++++++- todo | 2 ++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/libmproxy/console.py b/libmproxy/console.py index 3cbc61730..4740ee6b9 100644 --- a/libmproxy/console.py +++ b/libmproxy/console.py @@ -714,6 +714,12 @@ class State: #begin nocover class ConsoleMaster(controller.Master): + beep = { + 'intercepting_request':False, + 'request':False, + 'intercepting_response':False, + 'response':False + } palette = [] footer_text_default = [ ('key', "?"), ":help ", @@ -724,15 +730,22 @@ class ConsoleMaster(controller.Master): ('key', "?"), ":help ", ('key', "q"), ":back ", ] - def __init__(self, server, config, terminal_background): - self.set_palette(terminal_background) + def __init__(self, server, options): + self.set_palette(options.terminal_background) + self.beep = { + 'intercepting_request':options.beep_intercepted_request, + 'intercepting_response':options.beep_intercepted_response} controller.Master.__init__(self, server) - self.config = config + self.config = options.verbose self.state = State() self.stickycookie = None self.stickyhosts = {} + def check_beep(self, source): + if self.beep.get(source, False): + urwid.curses_display.curses.beep() + def set_palette(self, terminal_background): if terminal_background: background_color = 'default' @@ -1084,8 +1097,10 @@ class ConsoleMaster(controller.Master): f.request.headers["cookie"] = self.stickyhosts[hid] if f.match(self.state.intercept): + self.check_beep('intercepting_request') f.intercept() else: + self.check_beep('request') r.ack() self.sync_list_view() self.refresh_connection(f) @@ -1101,8 +1116,10 @@ class ConsoleMaster(controller.Master): self.stickyhosts[hid] = f.response.headers["set-cookie"] if f.match(self.state.intercept): + self.check_beep('intercepting_response') f.intercept() else: + self.check_beep('response') r.ack() self.sync_list_view() self.refresh_connection(f) diff --git a/mitmproxy b/mitmproxy index 6b1f0ae08..45f50d9ac 100755 --- a/mitmproxy +++ b/mitmproxy @@ -25,6 +25,14 @@ if __name__ == '__main__': usage = "%prog [options] output", version="%prog 0.1", ) + parser.add_option( + "", "--bireq", action="store_true", + dest="beep_intercepted_request", default=False, + help = "Beep on intercepted request") + parser.add_option( + "", "--bires", action="store_true", + dest="beep_intercepted_response", default=False, + help = "Beep on intercepted response") parser.add_option( "-d", "--dump", action="store_true", dest="dump", default=False, @@ -68,7 +76,7 @@ if __name__ == '__main__': if options.dump: m = controller.DumpMaster(server, options.verbose) else: - m = console.ConsoleMaster(server, options.verbose, options.terminal_background) + m = console.ConsoleMaster(server, options) if options.verbose > 0: print >> sys.stderr, "Running on port %s"%options.port m.run() diff --git a/todo b/todo index 363c07c5a..8e67c4d1b 100644 --- a/todo +++ b/todo @@ -10,6 +10,8 @@ Future: - Shortcut for viewing in pager - Serializing and de-serializing requests and responses. - Use real non-blocking input handling to minimize cpu load. + - Give the ability to beep on certain events. (On intercepted + request/response already working.) Bugs: