mitmproxy/libmproxy/console/options.py

271 lines
8.5 KiB
Python
Raw Normal View History

2015-04-03 01:10:57 +00:00
import urwid
from . import common, signals, grideditor, contentview
from . import select, palettes
2015-04-03 01:10:57 +00:00
footer = [
('heading_key', "enter/space"), ":toggle ",
('heading_key', "C"), ":clear all ",
]
2015-04-03 01:10:57 +00:00
2015-04-03 07:04:19 +00:00
def _mkhelp():
text = []
keys = [
("enter/space", "activate option"),
("C", "clear all options"),
]
text.extend(common.format_keyvals(keys, key="key", val="text", indent=4))
return text
help_context = _mkhelp()
2015-04-03 01:10:57 +00:00
class Options(urwid.WidgetWrap):
def __init__(self, master):
self.master = master
2015-04-06 05:45:36 +00:00
self.lb = select.Select(
2015-04-03 01:10:57 +00:00
[
2015-04-06 05:45:36 +00:00
select.Heading("Traffic Manipulation"),
select.Option(
"Header Set Patterns",
"H",
lambda: master.setheaders.count(),
self.setheaders
),
2015-04-06 05:45:36 +00:00
select.Option(
"Ignore Patterns",
"I",
lambda: master.server.config.check_ignore,
self.ignorepatterns
),
2015-04-06 05:45:36 +00:00
select.Option(
"Replacement Patterns",
"R",
lambda: master.replacehooks.count(),
self.replacepatterns
),
2015-04-06 05:45:36 +00:00
select.Option(
"Scripts",
2015-04-06 05:11:02 +00:00
"S",
lambda: master.scripts,
self.scripts
),
2015-04-06 05:45:36 +00:00
select.Heading("Interface"),
select.Option(
"Default Display Mode",
"M",
self.has_default_displaymode,
self.default_displaymode
),
select.Option(
"Palette",
"P",
lambda: self.master.palette != palettes.DEFAULT,
self.palette
),
2015-04-06 05:45:36 +00:00
select.Option(
"Show Host",
"w",
lambda: master.showhost,
self.toggle_showhost
),
2015-04-06 05:45:36 +00:00
select.Heading("Network"),
select.Option(
"No Upstream Certs",
"U",
lambda: master.server.config.no_upstream_cert,
self.toggle_upstream_cert
),
2015-04-06 05:45:36 +00:00
select.Option(
"TCP Proxying",
"T",
lambda: master.server.config.check_tcp,
self.tcp_proxy
),
2015-04-06 05:45:36 +00:00
select.Heading("Utility"),
select.Option(
2015-04-03 01:10:57 +00:00
"Anti-Cache",
"a",
2015-04-03 01:10:57 +00:00
lambda: master.anticache,
self.toggle_anticache
),
2015-04-06 05:45:36 +00:00
select.Option(
2015-04-03 01:10:57 +00:00
"Anti-Compression",
"o",
2015-04-03 01:10:57 +00:00
lambda: master.anticomp,
self.toggle_anticomp
),
2015-04-06 05:45:36 +00:00
select.Option(
2015-04-03 01:10:57 +00:00
"Kill Extra",
"x",
2015-04-03 01:10:57 +00:00
lambda: master.killextra,
self.toggle_killextra
),
2015-04-06 05:45:36 +00:00
select.Option(
2015-04-03 01:10:57 +00:00
"No Refresh",
"f",
2015-04-03 01:10:57 +00:00
lambda: not master.refresh_server_playback,
self.toggle_refresh_server_playback
),
2015-04-06 05:45:36 +00:00
select.Option(
"Sticky Auth",
"A",
lambda: master.stickyauth_txt,
self.sticky_auth
),
2015-04-06 05:45:36 +00:00
select.Option(
"Sticky Cookies",
"t",
lambda: master.stickycookie_txt,
self.sticky_cookie
2015-04-03 01:10:57 +00:00
),
]
)
title = urwid.Text("Options")
2015-04-03 01:10:57 +00:00
title = urwid.Padding(title, align="left", width=("relative", 100))
title = urwid.AttrWrap(title, "heading")
2015-04-03 01:10:57 +00:00
self._w = urwid.Frame(
self.lb,
header = title
)
self.master.loop.widget.footer.update("")
2015-04-06 05:45:36 +00:00
signals.update_settings.connect(self.sig_update_settings)
def sig_update_settings(self, sender):
self.lb.walker._modified()
2015-04-03 01:10:57 +00:00
def keypress(self, size, key):
if key == "C":
self.clearall()
return None
return super(self.__class__, self).keypress(size, key)
def clearall(self):
self.master.anticache = False
self.master.anticomp = False
self.master.killextra = False
self.master.showhost = False
self.master.refresh_server_playback = True
self.master.server.config.no_upstream_cert = False
self.master.setheaders.clear()
self.master.replacehooks.clear()
self.master.set_ignore_filter([])
self.master.set_tcp_filter([])
2015-04-06 05:11:02 +00:00
self.master.scripts = []
self.master.set_stickyauth(None)
self.master.set_stickycookie(None)
self.master.state.default_body_view = contentview.get("Auto")
signals.update_settings.send(self)
signals.status_message.send(
2015-04-06 05:45:36 +00:00
message = "All select.Options cleared",
expire = 1
)
2015-04-03 01:10:57 +00:00
def toggle_anticache(self):
self.master.anticache = not self.master.anticache
def toggle_anticomp(self):
self.master.anticomp = not self.master.anticomp
def toggle_killextra(self):
self.master.killextra = not self.master.killextra
def toggle_showhost(self):
self.master.showhost = not self.master.showhost
def toggle_refresh_server_playback(self):
self.master.refresh_server_playback = not self.master.refresh_server_playback
def toggle_upstream_cert(self):
self.master.server.config.no_upstream_cert = not self.master.server.config.no_upstream_cert
signals.update_settings.send(self)
def setheaders(self):
def _set(*args, **kwargs):
self.master.setheaders.set(*args, **kwargs)
signals.update_settings.send(self)
self.master.view_grideditor(
grideditor.SetHeadersEditor(
self.master,
self.master.setheaders.get_specs(),
_set
)
)
def ignorepatterns(self):
def _set(ignore):
patterns = (x[0] for x in ignore)
self.master.set_ignore_filter(patterns)
signals.update_settings.send(self)
self.master.view_grideditor(
grideditor.HostPatternEditor(
self.master,
[[x] for x in self.master.get_ignore_filter()],
_set
)
)
def replacepatterns(self):
def _set(*args, **kwargs):
self.master.replacehooks.set(*args, **kwargs)
signals.update_settings.send(self)
self.master.view_grideditor(
grideditor.ReplaceEditor(
self.master,
self.master.replacehooks.get_specs(),
_set
)
)
2015-04-06 05:11:02 +00:00
def scripts(self):
self.master.view_grideditor(
grideditor.ScriptEditor(
self.master,
[[i.command] for i in self.master.scripts],
self.master.edit_scripts
)
)
def default_displaymode(self):
signals.status_prompt_onekey.send(
prompt = "Global default display mode",
keys = contentview.view_prompts,
callback = self.master.change_default_display_mode
)
def has_default_displaymode(self):
return self.master.state.default_body_view.name != "Auto"
def tcp_proxy(self):
def _set(tcp):
patterns = (x[0] for x in tcp)
self.master.set_tcp_filter(patterns)
signals.update_settings.send(self)
self.master.view_grideditor(
grideditor.HostPatternEditor(
self.master,
[[x] for x in self.master.get_tcp_filter()],
_set
)
)
def sticky_auth(self):
signals.status_prompt.send(
prompt = "Sticky auth filter",
text = self.master.stickyauth_txt,
callback = self.master.set_stickyauth
)
def sticky_cookie(self):
signals.status_prompt.send(
prompt = "Sticky cookie filter",
text = self.master.stickycookie_txt,
callback = self.master.set_stickycookie
)
def palette(self):
self.master.view_palette_picker()