aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/console/window.py
blob: d686f61dd79e5a29ea5f14ee0a6784171ffa3ab0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import urwid
from . import common, grideditor, signals, contentview

class Window(urwid.Frame):
    def __init__(self, master, body, header, footer):
        urwid.Frame.__init__(self, body, header=header, footer=footer)
        self.master = master
        signals.focus.connect(self.sig_focus)

    def sig_focus(self, sender, section):
        self.focus_position = section

    def keypress(self, size, k):
        k = urwid.Frame.keypress(self, self.master.loop.screen_size, k)
        if k == "?":
            self.master.view_help()
        elif k == "c":
            if not self.master.client_playback:
                signals.status_prompt_path.send(
                    self,
                    prompt = "Client replay",
                    callback = self.master.client_playback_path
                )
            else:
                signals.status_prompt_onekey.send(
                    self,
                    prompt = "Stop current client replay?",
                    keys = (
                        ("yes", "y"),
                        ("no", "n"),
                    ),
                    callback = self.master.stop_client_playback_prompt,
                )
        elif k == "H":
            self.master.view_grideditor(
                grideditor.SetHeadersEditor(
                    self.master,
                    self.master.setheaders.get_specs(),
                    self.master.setheaders.set
                )
            )
        elif k == "I":
            self.master.view_grideditor(
                grideditor.HostPatternEditor(
                    self.master,
                    [[x] for x in self.master.get_ignore_filter()],
                    self.master.edit_ignore_filter
                )
            )
        elif k == "T":
            self.master.view_grideditor(
                grideditor.HostPatternEditor(
                    self.master,
                    [[x] for x in self.master.get_tcp_filter()],
                    self.master.edit_tcp_filter
                )
            )
        elif k == "i":
            signals.status_prompt.send(
                self,
                prompt = "Intercept filter",
                text = self.master.state.intercept_txt,
                callback = self.master.set_intercept
            )
        elif k == "Q":
            raise urwid.ExitMainLoop
        elif k == "q":
            signals.status_prompt_onekey.send(
                self,
                prompt = "Quit",
                keys = (
                    ("yes", "y"),
                    ("no", "n"),
                ),
                callback = self.master.quit,
            )
        elif k == "M":
            signals.status_prompt_onekey.send(
                prompt = "Global default display mode",
                keys = contentview.view_prompts,
                callback = self.master.change_default_display_mode
            )
        elif k == "R":
            self.master.view_grideditor(
                grideditor.ReplaceEditor(
                    self.master,
                    self.master.replacehooks.get_specs(),
                    self.master.replacehooks.set
                )
            )
        elif k == "s":
            self.master.view_grideditor(
                grideditor.ScriptEditor(
                    self.master,
                    [[i.command] for i in self.master.scripts],
                    self.master.edit_scripts
                )
            )
        elif k == "S":
            if not self.master.server_playback:
                signals.status_prompt_path.send(
                    self,
                    prompt = "Server replay path",
                    callback = self.master.server_playback_path
                )
            else:
                signals.status_prompt_onekey.send(
                    self,
                    prompt = "Stop current server replay?",
                    keys = (
                        ("yes", "y"),
                        ("no", "n"),
                    ),
                    callback = self.master.stop_server_playback_prompt,
                )
        elif k == "o":
            signals.status_prompt_onekey.send(
                prompt = "Options",
                keys = (
                    ("anticache", "a"),
                    ("anticomp", "c"),
                    ("showhost", "h"),
                    ("killextra", "k"),
                    ("norefresh", "n"),
                    ("no-upstream-certs", "u"),
                ),
                callback = self.master._change_options
            )
        elif k == "t":
            signals.status_prompt.send(
                prompt = "Sticky cookie filter",
                text = self.master.stickycookie_txt,
                callback = self.master.set_stickycookie
            )
        elif k == "u":
            signals.status_prompt.send(
                prompt = "Sticky auth filter",
                text = self.master.stickyauth_txt,
                callback = self.master.set_stickyauth
            )
        else:
            return k