aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2017-02-01 08:39:35 +1300
committerGitHub <noreply@github.com>2017-02-01 08:39:35 +1300
commit02f51d043d9213e192c2ca7840da10745dc48b4b (patch)
tree6d87b9cb5f9417d55d58b3345a47e518b719820c /mitmproxy
parentff379b7665d6e28c30ac48ccdae9d611e38dddef (diff)
parent35aff3b7838f8df718cc574d2643f1355849fa8e (diff)
downloadmitmproxy-02f51d043d9213e192c2ca7840da10745dc48b4b.tar.gz
mitmproxy-02f51d043d9213e192c2ca7840da10745dc48b4b.tar.bz2
mitmproxy-02f51d043d9213e192c2ca7840da10745dc48b4b.zip
Merge pull request #1965 from cortesi/optname
Consolidate option names
Diffstat (limited to 'mitmproxy')
-rw-r--r--mitmproxy/addons/onboarding.py6
-rw-r--r--mitmproxy/addons/view.py18
-rw-r--r--mitmproxy/options.py195
-rw-r--r--mitmproxy/optmanager.py12
-rw-r--r--mitmproxy/tools/cmdline.py44
-rw-r--r--mitmproxy/tools/console/flowlist.py6
-rw-r--r--mitmproxy/tools/console/master.py12
-rw-r--r--mitmproxy/tools/console/options.py2
-rw-r--r--mitmproxy/tools/console/palettepicker.py4
-rw-r--r--mitmproxy/tools/console/statusbar.py8
-rw-r--r--mitmproxy/tools/main.py23
-rw-r--r--mitmproxy/tools/web/master.py8
12 files changed, 174 insertions, 164 deletions
diff --git a/mitmproxy/addons/onboarding.py b/mitmproxy/addons/onboarding.py
index 4b952438..cb57990f 100644
--- a/mitmproxy/addons/onboarding.py
+++ b/mitmproxy/addons/onboarding.py
@@ -8,9 +8,9 @@ class Onboarding(wsgiapp.WSGIApp):
self.enabled = False
def configure(self, options, updated):
- self.host = options.app_host
- self.port = options.app_port
- self.enabled = options.app
+ self.host = options.onboarding_host
+ self.port = options.onboarding_port
+ self.enabled = options.onboarding
def request(self, f):
if self.enabled:
diff --git a/mitmproxy/addons/view.py b/mitmproxy/addons/view.py
index 25696e43..8358a045 100644
--- a/mitmproxy/addons/view.py
+++ b/mitmproxy/addons/view.py
@@ -298,19 +298,19 @@ class View(collections.Sequence):
"Invalid interception filter: %s" % opts.filter
)
self.set_filter(filt)
- if "order" in updated:
- if opts.order is None:
+ if "console_order" in updated:
+ if opts.console_order is None:
self.set_order(self.default_order)
else:
- if opts.order not in self.orders:
+ if opts.console_order not in self.orders:
raise exceptions.OptionsError(
- "Unknown flow order: %s" % opts.order
+ "Unknown flow order: %s" % opts.console_order
)
- self.set_order(self.orders[opts.order])
- if "order_reversed" in updated:
- self.set_reversed(opts.order_reversed)
- if "focus_follow" in updated:
- self.focus_follow = opts.focus_follow
+ self.set_order(self.orders[opts.console_order])
+ if "console_order_reversed" in updated:
+ self.set_reversed(opts.console_order_reversed)
+ if "console_focus_follow" in updated:
+ self.focus_follow = opts.console_focus_follow
def request(self, f):
self.add(f)
diff --git a/mitmproxy/options.py b/mitmproxy/options.py
index 157b0168..db7bd437 100644
--- a/mitmproxy/options.py
+++ b/mitmproxy/options.py
@@ -22,96 +22,96 @@ DEFAULT_CLIENT_CIPHERS = "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA
class Options(optmanager.OptManager):
def __init__(
- self,
- *, # all args are keyword-only.
- # TODO: rename to onboarding_app_*
- app: bool = True,
- app_host: str = APP_HOST,
- app_port: int = APP_PORT,
- anticache: bool = False,
- anticomp: bool = False,
- client_replay: Sequence[str] = [],
- replay_kill_extra: bool = False,
- keepserving: bool = True,
- no_server: bool = False,
- server_replay_nopop: bool = False,
- refresh_server_playback: bool = True,
- rfile: Optional[str] = None,
- scripts: Sequence[str] = [],
- showhost: bool = False,
- replacements: Sequence[Tuple[str, str, str]] = [],
- server_replay_use_headers: Sequence[str] = [],
- setheaders: Sequence[Tuple[str, str, str]] = [],
- server_replay: Sequence[str] = [],
- stickycookie: Optional[str] = None,
- stickyauth: Optional[str] = None,
- stream_large_bodies: Optional[int] = None,
- verbosity: int = 2,
- default_contentview: str = "auto",
- streamfile: Optional[str] = None,
- streamfile_append: bool = False,
- server_replay_ignore_content: bool = False,
- server_replay_ignore_params: Sequence[str] = [],
- server_replay_ignore_payload_params: Sequence[str] = [],
- server_replay_ignore_host: bool = False,
- # Proxy options
- auth_nonanonymous: bool = False,
- auth_singleuser: Optional[str] = None,
- auth_htpasswd: Optional[str] = None,
- add_upstream_certs_to_client_chain: bool = False,
- body_size_limit: Optional[int] = None,
- cadir: str = CA_DIR,
- certs: Sequence[Tuple[str, str]] = [],
- ciphers_client: str=DEFAULT_CLIENT_CIPHERS,
- ciphers_server: Optional[str]=None,
- clientcerts: Optional[str] = None,
- http2: bool = True,
- ignore_hosts: Sequence[str] = [],
- listen_host: str = "",
- listen_port: int = LISTEN_PORT,
- upstream_bind_address: str = "",
- mode: str = "regular",
- no_upstream_cert: bool = False,
- rawtcp: bool = False,
- websocket: bool = True,
- spoof_source_address: bool = False,
- upstream_server: Optional[str] = None,
- upstream_auth: Optional[str] = None,
- ssl_version_client: str = "secure",
- ssl_version_server: str = "secure",
- ssl_insecure: bool = False,
- ssl_verify_upstream_trusted_cadir: Optional[str] = None,
- ssl_verify_upstream_trusted_ca: Optional[str] = None,
- tcp_hosts: Sequence[str] = [],
-
- intercept: Optional[str] = None,
-
- # Console options
- eventlog: bool = False,
- focus_follow: bool = False,
- filter: Optional[str] = None,
- palette: Optional[str] = "dark",
- palette_transparent: bool = False,
- no_mouse: bool = False,
- order: Optional[str] = None,
- order_reversed: bool = False,
-
- # Web options
- open_browser: bool = True,
- wdebug: bool = False,
- wport: int = 8081,
- wiface: str = "127.0.0.1",
-
- # Dump options
- filtstr: Optional[str] = None,
- flow_detail: int = 1
+ self,
+ *, # all args are keyword-only.
+ onboarding: bool = True,
+ onboarding_host: str = APP_HOST,
+ onboarding_port: int = APP_PORT,
+ anticache: bool = False,
+ anticomp: bool = False,
+ client_replay: Sequence[str] = [],
+ replay_kill_extra: bool = False,
+ keepserving: bool = True,
+ no_server: bool = False,
+ server_replay_nopop: bool = False,
+ refresh_server_playback: bool = True,
+ rfile: Optional[str] = None,
+ scripts: Sequence[str] = [],
+ showhost: bool = False,
+ replacements: Sequence[Tuple[str, str, str]] = [],
+ server_replay_use_headers: Sequence[str] = [],
+ setheaders: Sequence[Tuple[str, str, str]] = [],
+ server_replay: Sequence[str] = [],
+ stickycookie: Optional[str] = None,
+ stickyauth: Optional[str] = None,
+ stream_large_bodies: Optional[int] = None,
+ verbosity: int = 2,
+ default_contentview: str = "auto",
+ streamfile: Optional[str] = None,
+ streamfile_append: bool = False,
+ server_replay_ignore_content: bool = False,
+ server_replay_ignore_params: Sequence[str] = [],
+ server_replay_ignore_payload_params: Sequence[str] = [],
+ server_replay_ignore_host: bool = False,
+ # Proxy options
+ auth_nonanonymous: bool = False,
+ auth_singleuser: Optional[str] = None,
+ auth_htpasswd: Optional[str] = None,
+ add_upstream_certs_to_client_chain: bool = False,
+ body_size_limit: Optional[int] = None,
+ cadir: str = CA_DIR,
+ certs: Sequence[Tuple[str, str]] = [],
+ ciphers_client: str=DEFAULT_CLIENT_CIPHERS,
+ ciphers_server: Optional[str]=None,
+ clientcerts: Optional[str] = None,
+ http2: bool = True,
+ ignore_hosts: Sequence[str] = [],
+ listen_host: str = "",
+ listen_port: int = LISTEN_PORT,
+ upstream_bind_address: str = "",
+ mode: str = "regular",
+ no_upstream_cert: bool = False,
+ rawtcp: bool = False,
+ websocket: bool = True,
+ spoof_source_address: bool = False,
+ upstream_server: Optional[str] = None,
+ upstream_auth: Optional[str] = None,
+ ssl_version_client: str = "secure",
+ ssl_version_server: str = "secure",
+ ssl_insecure: bool = False,
+ ssl_verify_upstream_trusted_cadir: Optional[str] = None,
+ ssl_verify_upstream_trusted_ca: Optional[str] = None,
+ tcp_hosts: Sequence[str] = [],
+
+ intercept: Optional[str] = None,
+
+ # Console options
+ console_eventlog: bool = False,
+ console_focus_follow: bool = False,
+ console_palette: Optional[str] = "dark",
+ console_palette_transparent: bool = False,
+ console_no_mouse: bool = False,
+ console_order: Optional[str] = None,
+ console_order_reversed: bool = False,
+
+ filter: Optional[str] = None,
+
+ # Web options
+ web_open_browser: bool = True,
+ web_debug: bool = False,
+ web_port: int = 8081,
+ web_iface: str = "127.0.0.1",
+
+ # Dump options
+ filtstr: Optional[str] = None,
+ flow_detail: int = 1
) -> None:
# We could replace all assignments with clever metaprogramming,
# but type hints are a much more valueable asset.
- self.app = app
- self.app_host = app_host
- self.app_port = app_port
+ self.onboarding = onboarding
+ self.onboarding_host = onboarding_host
+ self.onboarding_port = onboarding_port
self.anticache = anticache
self.anticomp = anticomp
self.client_replay = client_replay
@@ -172,20 +172,21 @@ class Options(optmanager.OptManager):
self.intercept = intercept
# Console options
- self.eventlog = eventlog
- self.focus_follow = focus_follow
+ self.console_eventlog = console_eventlog
+ self.console_focus_follow = console_focus_follow
+ self.console_palette = console_palette
+ self.console_palette_transparent = console_palette_transparent
+ self.console_no_mouse = console_no_mouse
+ self.console_order = console_order
+ self.console_order_reversed = console_order_reversed
+
self.filter = filter
- self.palette = palette
- self.palette_transparent = palette_transparent
- self.no_mouse = no_mouse
- self.order = order
- self.order_reversed = order_reversed
# Web options
- self.open_browser = open_browser
- self.wdebug = wdebug
- self.wport = wport
- self.wiface = wiface
+ self.web_open_browser = web_open_browser
+ self.web_debug = web_debug
+ self.web_port = web_port
+ self.web_iface = web_iface
# Dump options
self.filtstr = filtstr
diff --git a/mitmproxy/optmanager.py b/mitmproxy/optmanager.py
index da1a3f17..f95ce836 100644
--- a/mitmproxy/optmanager.py
+++ b/mitmproxy/optmanager.py
@@ -229,7 +229,10 @@ class OptManager(metaclass=_DefaultsMeta):
this object. May raise OptionsError if the config file is invalid.
"""
data = self._load(text)
- self.update(**data)
+ try:
+ self.update(**data)
+ except KeyError as v:
+ raise exceptions.OptionsError(v)
def load_paths(self, *paths):
"""
@@ -242,7 +245,12 @@ class OptManager(metaclass=_DefaultsMeta):
if os.path.exists(p) and os.path.isfile(p):
with open(p, "r") as f:
txt = f.read()
- self.load(txt)
+ try:
+ self.load(txt)
+ except exceptions.OptionsError as e:
+ raise exceptions.OptionsError(
+ "Error reading %s: %s" % (p, e)
+ )
def merge(self, opts):
"""
diff --git a/mitmproxy/tools/cmdline.py b/mitmproxy/tools/cmdline.py
index f607ad71..1d5bd017 100644
--- a/mitmproxy/tools/cmdline.py
+++ b/mitmproxy/tools/cmdline.py
@@ -212,9 +212,9 @@ def get_common_options(args):
args.verbose = 0
return dict(
- app=args.app,
- app_host=args.app_host,
- app_port=args.app_port,
+ onboarding=args.onboarding,
+ onboarding_host=args.onboarding_host,
+ onboarding_port=args.onboarding_port,
anticache=args.anticache,
anticomp=args.anticomp,
@@ -568,13 +568,13 @@ def proxy_ssl_options(parser):
def onboarding_app(parser):
group = parser.add_argument_group("Onboarding App")
group.add_argument(
- "--noapp",
- action="store_false", dest="app",
+ "--no-onboarding",
+ action="store_false", dest="onboarding",
help="Disable the mitmproxy onboarding app."
)
group.add_argument(
- "--app-host",
- action="store", dest="app_host",
+ "--onboarding-host",
+ action="store", dest="onboarding_host",
help="""
Domain to serve the onboarding app from. For transparent mode, use
an IP when a DNS entry for the app domain is not present. Default:
@@ -582,9 +582,9 @@ def onboarding_app(parser):
""" % options.APP_HOST
)
group.add_argument(
- "--app-port",
+ "--onboarding-port",
action="store",
- dest="app_port",
+ dest="onboarding_port",
type=int,
metavar="80",
help="Port to serve the onboarding app from."
@@ -770,34 +770,34 @@ def mitmproxy():
common_options(parser)
parser.add_argument(
"--palette", type=str,
- action="store", dest="palette",
+ action="store", dest="console_palette",
choices=sorted(palettes.palettes.keys()),
help="Select color palette: " + ", ".join(palettes.palettes.keys())
)
parser.add_argument(
"--palette-transparent",
- action="store_true", dest="palette_transparent",
+ action="store_true", dest="console_palette_transparent",
help="Set transparent background for palette."
)
parser.add_argument(
"-e", "--eventlog",
- action="store_true", dest="eventlog",
+ action="store_true", dest="console_eventlog",
help="Show event log."
)
parser.add_argument(
"--follow",
- action="store_true", dest="focus_follow",
+ action="store_true", dest="console_focus_follow",
help="Focus follows new flows."
)
parser.add_argument(
"--order",
- type=str, dest="order",
+ type=str, dest="console_order",
choices=[o[1] for o in view.orders],
help="Flow sort order."
)
parser.add_argument(
"--no-mouse",
- action="store_true", dest="no_mouse",
+ action="store_true", dest="console_no_mouse",
help="Disable mouse interaction."
)
group = parser.add_argument_group(
@@ -851,24 +851,24 @@ def mitmweb():
group = parser.add_argument_group("Mitmweb")
group.add_argument(
"--no-browser",
- action="store_false", dest="open_browser",
+ action="store_false", dest="web_open_browser",
help="Don't start a browser"
)
group.add_argument(
- "--wport",
- action="store", type=int, dest="wport",
+ "--web-port",
+ action="store", type=int, dest="web_port",
metavar="PORT",
help="Mitmweb port."
)
group.add_argument(
- "--wiface",
- action="store", dest="wiface",
+ "--web-iface",
+ action="store", dest="web_iface",
metavar="IFACE",
help="Mitmweb interface."
)
group.add_argument(
- "--wdebug",
- action="store_true", dest="wdebug",
+ "--web-debug",
+ action="store_true", dest="web_debug",
help="Turn on mitmweb debugging"
)
diff --git a/mitmproxy/tools/console/flowlist.py b/mitmproxy/tools/console/flowlist.py
index 1fe0be73..8ee2d55d 100644
--- a/mitmproxy/tools/console/flowlist.py
+++ b/mitmproxy/tools/console/flowlist.py
@@ -387,7 +387,7 @@ class FlowListBox(urwid.ListBox):
lookup = dict([(i[0], i[1]) for i in view.orders])
def change_order(k):
- self.master.options.order = lookup[k]
+ self.master.options.console_order = lookup[k]
signals.status_prompt_onekey.send(
prompt = "Order",
@@ -398,8 +398,8 @@ class FlowListBox(urwid.ListBox):
o = self.master.options
o.focus_follow = not o.focus_follow
elif key == "v":
- val = not self.master.options.order_reversed
- self.master.options.order_reversed = val
+ val = not self.master.options.console_order_reversed
+ self.master.options.console_order_reversed = val
elif key == "W":
if self.master.options.streamfile:
self.master.options.streamfile = None
diff --git a/mitmproxy/tools/console/master.py b/mitmproxy/tools/console/master.py
index f6626c55..77b48e8d 100644
--- a/mitmproxy/tools/console/master.py
+++ b/mitmproxy/tools/console/master.py
@@ -106,7 +106,7 @@ class ConsoleMaster(master.Master):
self.logbuffer.append(e)
if len(self.logbuffer) > EVENTLOG_SIZE:
self.logbuffer.pop(0)
- if self.options.focus_follow:
+ if self.options.console_focus_follow:
self.logbuffer.set_focus(len(self.logbuffer) - 1)
def sig_call_in(self, sender, seconds, callback, args=()):
@@ -150,7 +150,7 @@ class ConsoleMaster(master.Master):
signals.add_log("Script error: %s" % e, "warn")
def toggle_eventlog(self):
- self.options.eventlog = not self.options.eventlog
+ self.options.console_eventlog = not self.options.console_eventlog
self.view_flowlist()
signals.replace_view_state.send(self)
@@ -230,8 +230,8 @@ class ConsoleMaster(master.Master):
def set_palette(self, options, updated):
self.ui.register_palette(
- palettes.palettes[options.palette].palette(
- options.palette_transparent
+ palettes.palettes[options.console_palette].palette(
+ options.console_palette_transparent
)
)
self.ui.clear()
@@ -253,7 +253,7 @@ class ConsoleMaster(master.Master):
self.loop = urwid.MainLoop(
urwid.SolidFill("x"),
screen = self.ui,
- handle_mouse = not self.options.no_mouse,
+ handle_mouse = not self.options.console_no_mouse,
)
self.ab = statusbar.ActionBar()
@@ -347,7 +347,7 @@ class ConsoleMaster(master.Master):
if self.ui.started:
self.ui.clear()
- if self.options.eventlog:
+ if self.options.console_eventlog:
body = flowlist.BodyPile(self)
else:
body = flowlist.FlowListBox(self)
diff --git a/mitmproxy/tools/console/options.py b/mitmproxy/tools/console/options.py
index 54876f87..8c953e8e 100644
--- a/mitmproxy/tools/console/options.py
+++ b/mitmproxy/tools/console/options.py
@@ -75,7 +75,7 @@ class Options(urwid.WidgetWrap):
select.Option(
"Palette",
"P",
- checker("palette", master.options),
+ checker("console_palette", master.options),
self.palette
),
select.Option(
diff --git a/mitmproxy/tools/console/palettepicker.py b/mitmproxy/tools/console/palettepicker.py
index 0d943baf..4c5c62a0 100644
--- a/mitmproxy/tools/console/palettepicker.py
+++ b/mitmproxy/tools/console/palettepicker.py
@@ -42,7 +42,7 @@ class PalettePicker(urwid.WidgetWrap):
return select.Option(
i,
None,
- lambda: self.master.options.palette == name,
+ lambda: self.master.options.console_palette == name,
lambda: setattr(self.master.options, "palette", name)
)
@@ -58,7 +58,7 @@ class PalettePicker(urwid.WidgetWrap):
select.Option(
"Transparent",
"T",
- lambda: master.options.palette_transparent,
+ lambda: master.options.console_palette_transparent,
master.options.toggler("palette_transparent")
)
]
diff --git a/mitmproxy/tools/console/statusbar.py b/mitmproxy/tools/console/statusbar.py
index 785dc766..2c7f9efb 100644
--- a/mitmproxy/tools/console/statusbar.py
+++ b/mitmproxy/tools/console/statusbar.py
@@ -204,10 +204,10 @@ class StatusBar(urwid.WidgetWrap):
r.append("[")
r.append(("heading_key", "M"))
r.append(":%s]" % self.master.options.default_contentview)
- if self.master.options.order:
+ if self.master.options.console_order:
r.append("[")
r.append(("heading_key", "o"))
- r.append(":%s]" % self.master.options.order)
+ r.append(":%s]" % self.master.options.console_order)
opts = []
if self.master.options.anticache:
@@ -222,7 +222,7 @@ class StatusBar(urwid.WidgetWrap):
opts.append("killextra")
if self.master.options.no_upstream_cert:
opts.append("no-upstream-cert")
- if self.master.options.focus_follow:
+ if self.master.options.console_focus_follow:
opts.append("following")
if self.master.options.stream_large_bodies:
opts.append(
@@ -258,7 +258,7 @@ class StatusBar(urwid.WidgetWrap):
else:
offset = self.master.view.focus.index + 1
- if self.master.options.order_reversed:
+ if self.master.options.console_order_reversed:
arrow = common.SYMBOL_UP
else:
arrow = common.SYMBOL_DOWN
diff --git a/mitmproxy/tools/main.py b/mitmproxy/tools/main.py
index 727e993f..ce78cd13 100644
--- a/mitmproxy/tools/main.py
+++ b/mitmproxy/tools/main.py
@@ -70,14 +70,15 @@ def mitmproxy(args=None): # pragma: no cover
console_options.merge(cmdline.get_common_options(args))
console_options.merge(
dict(
- palette = args.palette,
- palette_transparent = args.palette_transparent,
- eventlog = args.eventlog,
- focus_follow = args.focus_follow,
- intercept = args.intercept,
+ console_palette = args.console_palette,
+ console_palette_transparent = args.console_palette_transparent,
+ console_eventlog = args.console_eventlog,
+ console_focus_follow = args.console_focus_follow,
+ console_no_mouse = args.console_no_mouse,
+ console_order = args.console_order,
+
filter = args.filter,
- no_mouse = args.no_mouse,
- order = args.order,
+ intercept = args.intercept,
)
)
@@ -149,10 +150,10 @@ def mitmweb(args=None): # pragma: no cover
web_options.merge(
dict(
intercept = args.intercept,
- open_browser = args.open_browser,
- wdebug = args.wdebug,
- wiface = args.wiface,
- wport = args.wport,
+ web_open_browser = args.web_open_browser,
+ web_debug = args.web_debug,
+ web_iface = args.web_iface,
+ web_port = args.web_port,
)
)
server = process_options(parser, web_options, args)
diff --git a/mitmproxy/tools/web/master.py b/mitmproxy/tools/web/master.py
index e6c15a0a..6ebcfe47 100644
--- a/mitmproxy/tools/web/master.py
+++ b/mitmproxy/tools/web/master.py
@@ -38,7 +38,7 @@ class WebMaster(master.Master):
if with_termlog:
self.addons.add(termlog.TermLog())
self.app = app.Application(
- self, self.options.wdebug
+ self, self.options.web_debug
)
# This line is just for type hinting
self.options = self.options # type: Options
@@ -103,7 +103,7 @@ class WebMaster(master.Master):
iol = tornado.ioloop.IOLoop.instance()
http_server = tornado.httpserver.HTTPServer(self.app)
- http_server.listen(self.options.wport, self.options.wiface)
+ http_server.listen(self.options.web_port, self.options.web_iface)
iol.add_callback(self.start)
tornado.ioloop.PeriodicCallback(lambda: self.tick(timeout=0), 5).start()
@@ -113,13 +113,13 @@ class WebMaster(master.Master):
"info"
)
- web_url = "http://{}:{}/".format(self.options.wiface, self.options.wport)
+ web_url = "http://{}:{}/".format(self.options.web_iface, self.options.web_port)
self.add_log(
"Web server listening at {}".format(web_url),
"info"
)
- if self.options.open_browser:
+ if self.options.web_open_browser:
success = open_browser(web_url)
if not success:
self.add_log(