2015-04-03 01:10:57 +00:00
|
|
|
import urwid
|
|
|
|
|
2015-09-12 11:49:16 +00:00
|
|
|
from .. import contentviews
|
2015-09-02 18:28:25 +00:00
|
|
|
from . import common, signals, grideditor
|
2015-04-07 03:59:38 +00:00
|
|
|
from . import select, palettes
|
2015-04-03 01:10:57 +00:00
|
|
|
|
2015-04-03 01:47:55 +00:00
|
|
|
footer = [
|
|
|
|
('heading_key', "enter/space"), ":toggle ",
|
|
|
|
('heading_key', "C"), ":clear all ",
|
|
|
|
]
|
2015-04-03 01:10:57 +00:00
|
|
|
|
2015-05-30 00:03:28 +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(
|
2015-04-06 04:46:51 +00:00
|
|
|
"Header Set Patterns",
|
|
|
|
"H",
|
|
|
|
lambda: master.setheaders.count(),
|
|
|
|
self.setheaders
|
|
|
|
),
|
2015-04-06 05:45:36 +00:00
|
|
|
select.Option(
|
2015-04-06 04:46:51 +00:00
|
|
|
"Ignore Patterns",
|
2015-04-06 05:02:51 +00:00
|
|
|
"I",
|
|
|
|
lambda: master.server.config.check_ignore,
|
|
|
|
self.ignorepatterns
|
2015-04-06 04:46:51 +00:00
|
|
|
),
|
2015-04-06 05:45:36 +00:00
|
|
|
select.Option(
|
2015-04-06 04:46:51 +00:00
|
|
|
"Replacement Patterns",
|
2015-04-06 05:05:52 +00:00
|
|
|
"R",
|
|
|
|
lambda: master.replacehooks.count(),
|
|
|
|
self.replacepatterns
|
2015-04-06 04:46:51 +00:00
|
|
|
),
|
2015-04-06 05:45:36 +00:00
|
|
|
select.Option(
|
2015-04-06 04:46:51 +00:00
|
|
|
"Scripts",
|
2015-04-06 05:11:02 +00:00
|
|
|
"S",
|
|
|
|
lambda: master.scripts,
|
|
|
|
self.scripts
|
2015-04-06 04:46:51 +00:00
|
|
|
),
|
|
|
|
|
2015-04-06 05:45:36 +00:00
|
|
|
select.Heading("Interface"),
|
|
|
|
select.Option(
|
2015-04-06 04:46:51 +00:00
|
|
|
"Default Display Mode",
|
2015-04-06 05:14:32 +00:00
|
|
|
"M",
|
|
|
|
self.has_default_displaymode,
|
|
|
|
self.default_displaymode
|
2015-04-06 04:46:51 +00:00
|
|
|
),
|
2015-04-06 20:42:40 +00:00
|
|
|
select.Option(
|
|
|
|
"Palette",
|
|
|
|
"P",
|
2015-04-07 03:59:38 +00:00
|
|
|
lambda: self.master.palette != palettes.DEFAULT,
|
2015-04-06 20:42:40 +00:00
|
|
|
self.palette
|
|
|
|
),
|
2015-04-06 05:45:36 +00:00
|
|
|
select.Option(
|
2015-04-06 04:46:51 +00:00
|
|
|
"Show Host",
|
|
|
|
"w",
|
|
|
|
lambda: master.showhost,
|
|
|
|
self.toggle_showhost
|
|
|
|
),
|
|
|
|
|
2015-04-06 05:45:36 +00:00
|
|
|
select.Heading("Network"),
|
|
|
|
select.Option(
|
2015-04-06 04:46:51 +00:00
|
|
|
"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(
|
2015-04-06 04:46:51 +00:00
|
|
|
"TCP Proxying",
|
2015-04-06 05:19:52 +00:00
|
|
|
"T",
|
|
|
|
lambda: master.server.config.check_tcp,
|
|
|
|
self.tcp_proxy
|
2015-04-06 04:46:51 +00:00
|
|
|
),
|
|
|
|
|
2015-04-06 05:45:36 +00:00
|
|
|
select.Heading("Utility"),
|
|
|
|
select.Option(
|
2015-04-03 01:10:57 +00:00
|
|
|
"Anti-Cache",
|
2015-04-03 01:47:55 +00:00
|
|
|
"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",
|
2015-04-03 01:38:04 +00:00
|
|
|
"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",
|
2015-04-06 04:46:51 +00:00
|
|
|
"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",
|
2015-04-06 04:46:51 +00:00
|
|
|
"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(
|
2015-04-06 04:46:51 +00:00
|
|
|
"Sticky Auth",
|
2015-04-06 05:27:46 +00:00
|
|
|
"A",
|
|
|
|
lambda: master.stickyauth_txt,
|
|
|
|
self.sticky_auth
|
2015-04-06 04:46:51 +00:00
|
|
|
),
|
2015-04-06 05:45:36 +00:00
|
|
|
select.Option(
|
2015-04-06 04:46:51 +00:00
|
|
|
"Sticky Cookies",
|
2015-04-06 05:27:46 +00:00
|
|
|
"t",
|
|
|
|
lambda: master.stickycookie_txt,
|
|
|
|
self.sticky_cookie
|
2015-04-03 01:10:57 +00:00
|
|
|
),
|
|
|
|
]
|
|
|
|
)
|
2015-04-06 20:42:40 +00:00
|
|
|
title = urwid.Text("Options")
|
2015-04-03 01:10:57 +00:00
|
|
|
title = urwid.Padding(title, align="left", width=("relative", 100))
|
2015-04-06 20:42:40 +00:00
|
|
|
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
|
|
|
|
2015-04-03 01:47:55 +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
|
2015-04-06 04:46:51 +00:00
|
|
|
self.master.setheaders.clear()
|
2015-04-06 05:05:52 +00:00
|
|
|
self.master.replacehooks.clear()
|
2015-04-06 05:02:51 +00:00
|
|
|
self.master.set_ignore_filter([])
|
2015-04-06 05:19:52 +00:00
|
|
|
self.master.set_tcp_filter([])
|
2015-04-06 05:11:02 +00:00
|
|
|
self.master.scripts = []
|
2015-04-06 05:27:46 +00:00
|
|
|
self.master.set_stickyauth(None)
|
|
|
|
self.master.set_stickycookie(None)
|
2015-09-12 11:49:16 +00:00
|
|
|
self.master.state.default_body_view = contentviews.get("Auto")
|
2015-04-06 05:27:46 +00:00
|
|
|
|
2015-04-03 01:47:55 +00:00
|
|
|
signals.update_settings.send(self)
|
|
|
|
signals.status_message.send(
|
2015-04-06 05:45:36 +00:00
|
|
|
message = "All select.Options cleared",
|
2015-04-03 01:47:55 +00:00
|
|
|
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)
|
2015-04-06 04:46:51 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
)
|
2015-04-06 05:02:51 +00:00
|
|
|
|
|
|
|
def ignorepatterns(self):
|
|
|
|
def _set(ignore):
|
2015-04-17 00:54:29 +00:00
|
|
|
self.master.set_ignore_filter(ignore)
|
2015-04-06 05:02:51 +00:00
|
|
|
signals.update_settings.send(self)
|
|
|
|
self.master.view_grideditor(
|
|
|
|
grideditor.HostPatternEditor(
|
|
|
|
self.master,
|
2015-04-17 00:54:29 +00:00
|
|
|
self.master.get_ignore_filter(),
|
2015-04-06 05:02:51 +00:00
|
|
|
_set
|
|
|
|
)
|
|
|
|
)
|
2015-04-06 05:05:52 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
)
|
2015-04-06 05:14:32 +00:00
|
|
|
|
|
|
|
def default_displaymode(self):
|
|
|
|
signals.status_prompt_onekey.send(
|
|
|
|
prompt = "Global default display mode",
|
2015-09-12 11:49:16 +00:00
|
|
|
keys = contentviews.view_prompts,
|
2015-04-06 05:14:32 +00:00
|
|
|
callback = self.master.change_default_display_mode
|
|
|
|
)
|
|
|
|
|
|
|
|
def has_default_displaymode(self):
|
|
|
|
return self.master.state.default_body_view.name != "Auto"
|
2015-04-06 05:19:52 +00:00
|
|
|
|
|
|
|
def tcp_proxy(self):
|
|
|
|
def _set(tcp):
|
2015-04-17 00:54:29 +00:00
|
|
|
self.master.set_tcp_filter(tcp)
|
2015-04-06 05:19:52 +00:00
|
|
|
signals.update_settings.send(self)
|
|
|
|
self.master.view_grideditor(
|
|
|
|
grideditor.HostPatternEditor(
|
|
|
|
self.master,
|
2015-04-17 00:54:29 +00:00
|
|
|
self.master.get_tcp_filter(),
|
2015-04-06 05:19:52 +00:00
|
|
|
_set
|
|
|
|
)
|
|
|
|
)
|
2015-04-06 05:27:46 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
)
|
2015-04-06 20:42:40 +00:00
|
|
|
|
|
|
|
def palette(self):
|
|
|
|
self.master.view_palette_picker()
|