Esempio n. 1
0
class QueryEditor(base.FocusEditor):
    title = "Edit Query"
    columns = [
        col_text.Column("Key"),
        col_text.Column("Value")
    ]

    def get_data(self, flow):
        return flow.request.query.items(multi=True)

    def set_data(self, vals, flow):
        flow.request.query = vals
Esempio n. 2
0
class CookieEditor(base.FocusEditor):
    title = "Edit Cookies"
    columns = [
        col_text.Column("Name"),
        col_text.Column("Value"),
    ]

    def get_data(self, flow):
        return flow.request.cookies.items(multi=True)

    def set_data(self, vals, flow):
        flow.request.cookies = vals
Esempio n. 3
0
class RequestFormEditor(base.FocusEditor):
    title = "Editing URL-encoded form"
    columns = [
        col_text.Column("Key"),
        col_text.Column("Value")
    ]

    def get_data(self, flow):
        return flow.request.urlencoded_form.items(multi=True)

    def set_data(self, vals, flow):
        flow.request.urlencoded_form = vals
Esempio n. 4
0
class RequestMultipartEditor(base.FocusEditor):
    title = "Edit Multipart Form"
    columns = [
        col_text.Column("Key"),
        col_text.Column("Value")
    ]

    def get_data(self, flow):

        return flow.request.multipart_form.items(multi=True)

    def set_data(self, vals, flow):
        flow.request.multipart_form = vals
Esempio n. 5
0
class SetHeadersEditor(base.GridEditor):
    title = "Editing header set patterns"
    columns = [
        col_text.Column("Filter"),
        col_text.Column("Header"),
        col_text.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().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
class CookieAttributeEditor(base.GridEditor):
    title = "Editing Set-Cookie attributes"
    columns = [
        col_text.Column("Name"),
        col_text.Column("Value"),
    ]

    def data_in(self, data):
        return [(k, v or "") for k, v in data]

    def data_out(self, data):
        ret = []
        for i in data:
            if not i[1]:
                ret.append([i[0], None])
            else:
                ret.append(i)
        return ret
Esempio n. 7
0
class ReplaceEditor(base.GridEditor):
    title = "Editing replacement patterns"
    columns = [
        col_text.Column("Filter"),
        col_text.Column("Regex"),
        col_text.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
Esempio n. 8
0
class SetCookieEditor(base.GridEditor):
    title = "Editing response SetCookie header"
    columns = [
        col_text.Column("Name"),
        col_text.Column("Value"),
        col_subgrid.Column("Attributes", CookieAttributeEditor),
    ]

    def data_in(self, data):
        flattened = []
        for key, (value, attrs) in data:
            flattened.append([key, value, attrs.items(multi=True)])
        return flattened

    def data_out(self, data):
        vals = []
        for key, value, attrs in data:
            vals.append([key, (value, attrs)])
        return vals
Esempio n. 9
0
class ScriptEditor(base.GridEditor):
    title = "Editing scripts"
    columns = [
        col_text.Column("Command"),
    ]

    def is_error(self, col, val):
        try:
            script.parse_command(val)
        except exceptions.OptionsError as e:
            return str(e)
Esempio n. 10
0
class ReplaceEditor(base.GridEditor):
    title = "Editing replacement patterns"
    columns = [
        col_text.Column("Filter"),
        col_text.Column("Regex"),
        col_text.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."
        elif col == 2:
            if val.startswith("@") and not os.path.isfile(os.path.expanduser(val[1:])):
                return "Invalid file path"
        return False
Esempio n. 11
0
class PathEditor(base.GridEditor):
    # TODO: Next row on enter?

    title = "Editing URL path components"
    columns = [
        col_text.Column("Component"),
    ]

    def data_in(self, data):
        return [[i] for i in data]

    def data_out(self, data):
        return [i[0] for i in data]
Esempio n. 12
0
class HostPatternEditor(base.GridEditor):
    title = "Editing host patterns"
    columns = [col_text.Column("Regex (matched on hostname:port / ip:port)")]

    def is_error(self, col, val):
        try:
            re.compile(val, re.IGNORECASE)
        except re.error as e:
            return "Invalid regex: %s" % str(e)

    def data_in(self, data):
        return [[i] for i in data]

    def data_out(self, data):
        return [i[0] for i in data]
class OptionsEditor(base.GridEditor, layoutwidget.LayoutWidget):
    title = None  # type: str
    columns = [col_text.Column("")]

    def __init__(self, master, name, vals):
        self.name = name
        super().__init__(master, [[i] for i in vals], self.callback)

    def callback(self, vals):
        try:
            setattr(self.master.options, self.name, [i[0] for i in vals])
        except exceptions.OptionsError as v:
            signals.status_message.send(message=str(v))

    def is_error(self, col, val):
        pass
Esempio n. 14
0
class PathEditor(base.FocusEditor):
    # TODO: Next row on enter?
    title = "Edit Path Components"
    columns = [
        col_text.Column("Component"),
    ]

    def data_in(self, data):
        return [[i] for i in data]

    def data_out(self, data):
        return [i[0] for i in data]

    def get_data(self, flow):
        return self.data_in(flow.request.path_components)

    def set_data(self, vals, flow):
        flow.request.path_components = self.data_out(vals)
Esempio n. 15
0
class URLEncodedFormEditor(base.GridEditor):
    title = "Editing URL-encoded form"
    columns = [col_text.Column("Key"), col_text.Column("Value")]
Esempio n. 16
0
class QueryEditor(base.GridEditor):
    title = "Editing query"
    columns = [col_text.Column("Key"), col_text.Column("Value")]
Esempio n. 17
0
class CookieEditor(base.GridEditor):
    title = "Editing request Cookie header"
    columns = [
        col_text.Column("Name"),
        col_text.Column("Value"),
    ]