Beispiel #1
0
class HeaderEditor(base.GridEditor):
    title = "Editing headers"
    columns = [col_bytes.Column("Key"), col_bytes.Column("Value")]

    def make_help(self):
        h = super().make_help()
        text = [urwid.Text([("text", "Special keys:\n")])]
        keys = [
            ("U", "add User-Agent header"),
        ]
        text.extend(
            common.format_keyvals(keys, key="key", val="text", indent=4))
        text.append(urwid.Text([("text", "\n")]))
        text.extend(h)
        return text

    def set_user_agent(self, k):
        ua = user_agents.get_by_shortcut(k)
        if ua:
            self.walker.add_value([b"User-Agent", ua[2].encode()])

    def handle_key(self, key):
        if key == "U":
            signals.status_prompt_onekey.send(
                prompt="Add User-Agent header:",
                keys=[(i[0], i[1]) for i in user_agents.UASTRINGS],
                callback=self.set_user_agent,
            )
            return True
Beispiel #2
0
class SetHeadersEditor(base.GridEditor):
    title = "Editing header set patterns"
    columns = [
        col_text.Column("Filter"),
        col_bytes.Column("Header"),
        col_bytes.Column("Value"),
    ]

    def is_error(self, col, val):
        if col == 0:
            if not flowfilter.parse(val):
                return "Invalid filter specification"
        return False

    def make_help(self):
        h = super(SetHeadersEditor, self).make_help()
        text = [
            urwid.Text([("text", "Special keys:\n")])
        ]
        keys = [
            ("U", "add User-Agent header"),
        ]
        text.extend(
            common.format_keyvals(keys, key="key", val="text", indent=4)
        )
        text.append(urwid.Text([("text", "\n")]))
        text.extend(h)
        return text

    def set_user_agent(self, k):
        ua = user_agents.get_by_shortcut(k)
        if ua:
            self.walker.add_value(
                [
                    ".*",
                    b"User-Agent",
                    ua[2].encode()
                ]
            )

    def handle_key(self, key):
        if key == "U":
            signals.status_prompt_onekey.send(
                prompt="Add User-Agent header:",
                keys=[(i[0], i[1]) for i in user_agents.UASTRINGS],
                callback=self.set_user_agent,
            )
            return True
Beispiel #3
0
class ReplaceEditor(base.GridEditor):
    title = "Editing replacement patterns"
    columns = [
        col_text.Column("Filter"),
        col_bytes.Column("Regex"),
        col_bytes.Column("Replacement"),
    ]

    def is_error(self, col, val):
        if col == 0:
            if not flowfilter.parse(val):
                return "Invalid filter specification."
        elif col == 1:
            try:
                re.compile(val)
            except re.error:
                return "Invalid regular expression."
        return False
Beispiel #4
0
class URLEncodedFormEditor(base.GridEditor):
    title = "Editing URL-encoded form"
    columns = [col_bytes.Column("Key"), col_bytes.Column("Value")]