Add mitmproxy command line flags for a number of filter expressions.

For now, these are supported: intercept, limit, sticky cookies, beep
This commit is contained in:
Aldo Cortesi 2010-03-01 15:42:38 +13:00
parent fbe6e0a820
commit f457342aab
2 changed files with 58 additions and 4 deletions

View File

@ -14,7 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import Queue, mailcap, mimetypes, tempfile, os, subprocess, threading import Queue, mailcap, mimetypes, tempfile, os, subprocess, threading
import os.path import os.path, sys
import cStringIO import cStringIO
import urwid.curses_display import urwid.curses_display
import urwid import urwid
@ -609,6 +609,8 @@ class State:
if not f: if not f:
return False return False
f.request = req f.request = req
if self.focus is None:
self.set_focus(0)
return f return f
def add_response(self, resp): def add_response(self, resp):
@ -618,6 +620,8 @@ class State:
f.response = resp f.response = resp
f.waiting = False f.waiting = False
f.backup() f.backup()
if self.focus is None:
self.set_focus(0)
return f return f
def add_error(self, err): def add_error(self, err):
@ -661,7 +665,7 @@ class State:
return self.flow_map.get(connection) return self.flow_map.get(connection)
def get_focus(self): def get_focus(self):
if not self.view: if not self.view or self.focus is None:
return None, None return None, None
return self.view[self.focus], self.focus return self.view[self.focus], self.focus
@ -762,6 +766,26 @@ class ConsoleMaster(controller.Master):
controller.Master.__init__(self, server) controller.Master.__init__(self, server)
self.state = State() self.state = State()
r = self.set_limit(options.limit)
if r:
print >> sys.stderr, "Limit error:", r
sys.exit(1)
r = self.set_intercept(options.intercept)
if r:
print >> sys.stderr, "Intercept error:", r
sys.exit(1)
r = self.set_beep(options.beep)
if r:
print >> sys.stderr, "Beep error:", r
sys.exit(1)
r = self.set_stickycookie(options.sticky)
if r:
print >> sys.stderr, "Sticky cookies error:", r
sys.exit(1)
self.stickycookie = None self.stickycookie = None
self.stickyhosts = {} self.stickyhosts = {}
@ -974,7 +998,6 @@ class ConsoleMaster(controller.Master):
self.state.set_limit(f) self.state.set_limit(f)
else: else:
self.state.set_limit(None) self.state.set_limit(None)
self.sync_list_view()
def set_intercept(self, txt): def set_intercept(self, txt):
if txt: if txt:
@ -983,7 +1006,6 @@ class ConsoleMaster(controller.Master):
return "Invalid filter expression." return "Invalid filter expression."
else: else:
self.state.intercept = None self.state.intercept = None
self.sync_list_view()
def set_beep(self, txt): def set_beep(self, txt):
if txt: if txt:
@ -1040,9 +1062,11 @@ class ConsoleMaster(controller.Master):
self.view_help() self.view_help()
elif k == "l": elif k == "l":
self.prompt("Limit: ", self.set_limit) self.prompt("Limit: ", self.set_limit)
self.sync_list_view()
k = None k = None
elif k == "i": elif k == "i":
self.prompt("Intercept: ", self.set_intercept) self.prompt("Intercept: ", self.set_intercept)
self.sync_list_view()
k = None k = None
elif k == "B": elif k == "B":
self.prompt("Beep: ", self.set_beep) self.prompt("Beep: ", self.set_beep)

View File

@ -25,16 +25,46 @@ if __name__ == '__main__':
usage = "%prog [options] output", usage = "%prog [options] output",
version="%prog 0.1", version="%prog 0.1",
) )
parser.add_option( parser.add_option(
"-c", "--cert", action="store", "-c", "--cert", action="store",
type = "str", dest="cert", default="~/.mitmproxy/cert.pem", type = "str", dest="cert", default="~/.mitmproxy/cert.pem",
help = "SSL certificate file." help = "SSL certificate file."
) )
parser.add_option( parser.add_option(
"-p", "--port", action="store", "-p", "--port", action="store",
type = "int", dest="port", default=8080, type = "int", dest="port", default=8080,
help = "Port." help = "Port."
) )
group = OptionGroup(
parser,
"Filters",
"See help in mitmproxy for filter expression syntax."
)
group.add_option(
"-B", "--beep", action="store",
type = "str", dest="beep", default=None,
help = "Beep filter expression."
)
group.add_option(
"-l", "--limit", action="store",
type = "str", dest="limit", default=None,
help = "Limit filter expression."
)
group.add_option(
"-i", "--intercept", action="store",
type = "str", dest="intercept", default=None,
help = "Intercept filter expression."
)
group.add_option(
"-s", "--sticky", action="store",
type = "str", dest="sticky", default=None,
help = "Sticky cookie filter expression."
)
parser.add_option_group(group)
options, args = parser.parse_args() options, args = parser.parse_args()
certpath = os.path.expanduser(options.cert) certpath = os.path.expanduser(options.cert)