Example #1
0
    def keypress(self, size, key):
        conn = None  # type: Optional[Union[models.HTTPRequest, models.HTTPResponse]]
        if self.tab_offset == TAB_REQ:
            conn = self.flow.request
        elif self.tab_offset == TAB_RESP:
            conn = self.flow.response

        key = super(self.__class__, self).keypress(size, key)

        # Special case: Space moves over to the next flow.
        # We need to catch that before applying common.shortcuts()
        if key == " ":
            self.view_next_flow(self.flow)
            return

        key = common.shortcuts(key)
        if key in ("up", "down", "page up", "page down"):
            # Pass scroll events to the wrapped widget
            self._w.keypress(size, key)
        elif key == "a":
            self.flow.accept_intercept(self.master)
            signals.flow_change.send(self, flow=self.flow)
        elif key == "A":
            self.master.accept_all()
            signals.flow_change.send(self, flow=self.flow)
        elif key == "d":
            if self.state.flow_count() == 1:
                self.master.view_flowlist()
            elif self.state.view.index(self.flow) == len(self.state.view) - 1:
                self.view_prev_flow(self.flow)
            else:
                self.view_next_flow(self.flow)
            f = self.flow
            if not f.reply.acked:
                f.kill(self.master)
            self.state.delete_flow(f)
        elif key == "D":
            f = self.master.duplicate_flow(self.flow)
            signals.pop_view_state.send(self)
            self.master.view_flow(f)
            signals.status_message.send(message="Duplicated.")
        elif key == "p":
            self.view_prev_flow(self.flow)
        elif key == "r":
            r = self.master.replay_request(self.flow)
            if r:
                signals.status_message.send(message=r)
            signals.flow_change.send(self, flow=self.flow)
        elif key == "V":
            if self.flow.modified():
                self.state.revert(self.flow)
                signals.flow_change.send(self, flow=self.flow)
                signals.status_message.send(message="Reverted.")
            else:
                signals.status_message.send(message="Flow not modified.")
        elif key == "W":
            signals.status_prompt_path.send(prompt="Save this flow",
                                            callback=self.master.save_one_flow,
                                            args=(self.flow, ))
        elif key == "|":
            signals.status_prompt_path.send(
                prompt="Send flow to script",
                callback=self.master.run_script_once,
                args=(self.flow, ))
        elif key == "e":
            if self.tab_offset == TAB_REQ:
                signals.status_prompt_onekey.send(prompt="Edit request",
                                                  keys=(
                                                      ("cookies", "c"),
                                                      ("query", "q"),
                                                      ("path", "p"),
                                                      ("url", "u"),
                                                      ("header", "h"),
                                                      ("form", "f"),
                                                      ("raw body", "r"),
                                                      ("method", "m"),
                                                  ),
                                                  callback=self.edit)
            elif self.tab_offset == TAB_RESP:
                signals.status_prompt_onekey.send(prompt="Edit response",
                                                  keys=(
                                                      ("cookies", "c"),
                                                      ("code", "o"),
                                                      ("message", "m"),
                                                      ("header", "h"),
                                                      ("raw body", "r"),
                                                  ),
                                                  callback=self.edit)
            else:
                signals.status_message.send(
                    message="Tab to the request or response", expire=1)
        elif key in set("bfgmxvzEC") and not conn:
            signals.status_message.send(
                message="Tab to the request or response", expire=1)
            return
        elif key == "b":
            if self.tab_offset == TAB_REQ:
                common.ask_save_body("q", self.flow)
            else:
                common.ask_save_body("s", self.flow)
        elif key == "f":
            signals.status_message.send(message="Loading all body data...")
            self.state.add_flow_setting(self.flow,
                                        (self.tab_offset, "fullcontents"),
                                        True)
            signals.flow_change.send(self, flow=self.flow)
            signals.status_message.send(message="")
        elif key == "m":
            p = list(contentviews.view_prompts)
            p.insert(0, ("Clear", "C"))
            signals.status_prompt_onekey.send(
                self,
                prompt="Display mode",
                keys=p,
                callback=self.change_this_display_mode)
        elif key == "E":
            if self.tab_offset == TAB_REQ:
                scope = "q"
            else:
                scope = "s"
            signals.status_prompt_onekey.send(
                self,
                prompt="Export to file",
                keys=[(e[0], e[1]) for e in export.EXPORTERS],
                callback=common.export_to_clip_or_file,
                args=(scope, self.flow, common.ask_save_path))
        elif key == "C":
            if self.tab_offset == TAB_REQ:
                scope = "q"
            else:
                scope = "s"
            signals.status_prompt_onekey.send(
                self,
                prompt="Export to clipboard",
                keys=[(e[0], e[1]) for e in export.EXPORTERS],
                callback=common.export_to_clip_or_file,
                args=(scope, self.flow, common.copy_to_clipboard_or_prompt))
        elif key == "x":
            conn.content = None
            signals.flow_change.send(self, flow=self.flow)
        elif key == "v":
            if conn.raw_content:
                t = conn.headers.get("content-type")
                if "EDITOR" in os.environ or "PAGER" in os.environ:
                    self.master.spawn_external_viewer(
                        conn.get_content(strict=False), t)
                else:
                    signals.status_message.send(
                        message="Error! Set $EDITOR or $PAGER.")
        elif key == "z":
            self.flow.backup()
            e = conn.headers.get("content-encoding", "identity")
            if e != "identity":
                try:
                    conn.decode()
                except ValueError:
                    signals.status_message.send(
                        message="Could not decode - invalid data?")
            else:
                signals.status_prompt_onekey.send(
                    prompt="Select encoding: ",
                    keys=(
                        ("gzip", "z"),
                        ("deflate", "d"),
                        ("brotli", "b"),
                    ),
                    callback=self.encode_callback,
                    args=(conn, ))
            signals.flow_change.send(self, flow=self.flow)
        else:
            # Key is not handled here.
            return key
Example #2
0
    def keypress(self, size, key):
        key = super(self.__class__, self).keypress(size, key)

        if key == " ":
            self.view_next_flow(self.flow)
            return

        key = common.shortcuts(key)
        if self.tab_offset == TAB_REQ:
            conn = self.flow.request
        elif self.tab_offset == TAB_RESP:
            conn = self.flow.response
        else:
            conn = None

        if key in ("up", "down", "page up", "page down"):
            # Why doesn't this just work??
            self._w.keypress(size, key)
        elif key == "a":
            self.flow.accept_intercept(self.master)
            signals.flow_change.send(self, flow=self.flow)
        elif key == "A":
            self.master.accept_all()
            signals.flow_change.send(self, flow=self.flow)
        elif key == "d":
            if self.state.flow_count() == 1:
                self.master.view_flowlist()
            elif self.state.view.index(self.flow) == len(self.state.view) - 1:
                self.view_prev_flow(self.flow)
            else:
                self.view_next_flow(self.flow)
            f = self.flow
            f.kill(self.master)
            self.state.delete_flow(f)
        elif key == "D":
            f = self.master.duplicate_flow(self.flow)
            self.master.view_flow(f)
            signals.status_message.send(message="Duplicated.")
        elif key == "p":
            self.view_prev_flow(self.flow)
        elif key == "r":
            r = self.master.replay_request(self.flow)
            if r:
                signals.status_message.send(message=r)
            signals.flow_change.send(self, flow=self.flow)
        elif key == "V":
            if not self.flow.modified():
                signals.status_message.send(message="Flow not modified.")
                return
            self.state.revert(self.flow)
            signals.flow_change.send(self, flow=self.flow)
            signals.status_message.send(message="Reverted.")
        elif key == "W":
            signals.status_prompt_path.send(prompt="Save this flow",
                                            callback=self.master.save_one_flow,
                                            args=(self.flow, ))
        elif key == "E":
            signals.status_prompt_onekey.send(self,
                                              prompt="Export",
                                              keys=(
                                                  ("as curl command", "c"),
                                                  ("as python code", "p"),
                                                  ("as raw request", "r"),
                                                  ("as locust code", "l"),
                                                  ("as locust task", "t"),
                                              ),
                                              callback=common.export_prompt,
                                              args=(self.flow, ))
        elif key == "|":
            signals.status_prompt_path.send(
                prompt="Send flow to script",
                callback=self.master.run_script_once,
                args=(self.flow, ))

        if not conn and key in set(list("befgmxvz")):
            signals.status_message.send(
                message="Tab to the request or response", expire=1)
        elif conn:
            if key == "b":
                if self.tab_offset == TAB_REQ:
                    common.ask_save_body("q", self.master, self.state,
                                         self.flow)
                else:
                    common.ask_save_body("s", self.master, self.state,
                                         self.flow)
            elif key == "e":
                if self.tab_offset == TAB_REQ:
                    signals.status_prompt_onekey.send(prompt="Edit request",
                                                      keys=(
                                                          ("cookies", "c"),
                                                          ("query", "q"),
                                                          ("path", "p"),
                                                          ("url", "u"),
                                                          ("header", "h"),
                                                          ("form", "f"),
                                                          ("raw body", "r"),
                                                          ("method", "m"),
                                                      ),
                                                      callback=self.edit)
                else:
                    signals.status_prompt_onekey.send(prompt="Edit response",
                                                      keys=(
                                                          ("cookies", "c"),
                                                          ("code", "o"),
                                                          ("message", "m"),
                                                          ("header", "h"),
                                                          ("raw body", "r"),
                                                      ),
                                                      callback=self.edit)
                key = None
            elif key == "f":
                signals.status_message.send(message="Loading all body data...")
                self.state.add_flow_setting(self.flow,
                                            (self.tab_offset, "fullcontents"),
                                            True)
                signals.flow_change.send(self, flow=self.flow)
                signals.status_message.send(message="")
            elif key == "P":
                if self.tab_offset == TAB_REQ:
                    scope = "q"
                else:
                    scope = "s"
                common.ask_copy_part(scope, self.flow, self.master, self.state)
            elif key == "m":
                p = list(contentviews.view_prompts)
                p.insert(0, ("Clear", "C"))
                signals.status_prompt_onekey.send(
                    self,
                    prompt="Display mode",
                    keys=p,
                    callback=self.change_this_display_mode)
                key = None
            elif key == "x":
                signals.status_prompt_onekey.send(prompt="Delete body",
                                                  keys=(
                                                      ("completely", "c"),
                                                      ("mark as missing", "m"),
                                                  ),
                                                  callback=self.delete_body)
                key = None
            elif key == "v":
                if conn.content:
                    t = conn.headers.get("content-type")
                    if "EDITOR" in os.environ or "PAGER" in os.environ:
                        self.master.spawn_external_viewer(conn.content, t)
                    else:
                        signals.status_message.send(
                            message="Error! Set $EDITOR or $PAGER.")
            elif key == "z":
                self.flow.backup()
                e = conn.headers.get("content-encoding", "identity")
                if e != "identity":
                    if not conn.decode():
                        signals.status_message.send(
                            message="Could not decode - invalid data?")
                else:
                    signals.status_prompt_onekey.send(
                        prompt="Select encoding: ",
                        keys=(
                            ("gzip", "z"),
                            ("deflate", "d"),
                        ),
                        callback=self.encode_callback,
                        args=(conn, ))
                signals.flow_change.send(self, flow=self.flow)
        return key
Example #3
0
 def keypress(self, xxx_todo_changeme, key):
     (maxcol,) = xxx_todo_changeme
     key = common.shortcuts(key)
     if key == "a":
         self.flow.accept_intercept(self.master)
         signals.flowlist_change.send(self)
     elif key == "d":
         self.flow.kill(self.master)
         self.state.delete_flow(self.flow)
         signals.flowlist_change.send(self)
     elif key == "D":
         f = self.master.duplicate_flow(self.flow)
         self.master.view_flow(f)
     elif key == "m":
         if self.state.flow_marked(self.flow):
             self.state.set_flow_marked(self.flow, False)
         else:
             self.state.set_flow_marked(self.flow, True)
         signals.flowlist_change.send(self)
     elif key == "r":
         r = self.master.replay_request(self.flow)
         if r:
             signals.status_message.send(message=r)
         signals.flowlist_change.send(self)
     elif key == "S":
         if not self.master.server_playback:
             signals.status_prompt_onekey.send(
                 prompt = "Server Replay",
                 keys = (
                     ("all flows", "a"),
                     ("this flow", "t"),
                     ("file", "f"),
                 ),
                 callback = self.server_replay_prompt,
             )
         else:
             signals.status_prompt_onekey.send(
                 prompt = "Stop current server replay?",
                 keys = (
                     ("yes", "y"),
                     ("no", "n"),
                 ),
                 callback = self.stop_server_playback_prompt,
             )
     elif key == "U":
         for f in self.state.flows:
             self.state.set_flow_marked(f, False)
         signals.flowlist_change.send(self)
     elif key == "V":
         if not self.flow.modified():
             signals.status_message.send(message="Flow not modified.")
             return
         self.state.revert(self.flow)
         signals.flowlist_change.send(self)
         signals.status_message.send(message="Reverted.")
     elif key == "w":
         signals.status_prompt_onekey.send(
             self,
             prompt = "Save",
             keys = (
                 ("all flows", "a"),
                 ("this flow", "t"),
                 ("marked flows", "m"),
             ),
             callback = self.save_flows_prompt,
         )
     elif key == "X":
         self.flow.kill(self.master)
     elif key == "enter":
         if self.flow.request:
             self.master.view_flow(self.flow)
     elif key == "|":
         signals.status_prompt_path.send(
             prompt = "Send flow to script",
             callback = self.master.run_script_once,
             args = (self.flow,)
         )
     elif key == "P":
         common.ask_copy_part("a", self.flow, self.master, self.state)
     elif key == "E":
         signals.status_prompt_onekey.send(
             self,
             prompt = "Export",
             keys = (
                 ("as curl command", "c"),
                 ("as python code", "p"),
                 ("as raw request", "r"),
                 ("as locust code", "l"),
                 ("as locust task", "t"),
             ),
             callback = common.export_prompt,
             args = (self.flow,)
         )
     elif key == "b":
         common.ask_save_body(None, self.master, self.state, self.flow)
     else:
         return key
Example #4
0
    def keypress(self, xxx_todo_changeme, key):
        (maxcol, ) = xxx_todo_changeme
        key = common.shortcuts(key)
        if key == "a":
            self.flow.accept_intercept(self.master)
            signals.flowlist_change.send(self)
        elif key == "d":
            if self.flow.killable:
                self.flow.kill(self.master)
            self.state.delete_flow(self.flow)
            signals.flowlist_change.send(self)
        elif key == "D":
            f = self.master.duplicate_flow(self.flow)
            self.master.state.set_focus_flow(f)
            signals.flowlist_change.send(self)
        elif key == "m":
            self.flow.marked = not self.flow.marked
            signals.flowlist_change.send(self)
        elif key == "M":
            if self.state.mark_filter:
                self.state.disable_marked_filter()
            else:
                self.state.enable_marked_filter()
            signals.flowlist_change.send(self)
        elif key == "r":
            try:
                self.master.replay_request(self.flow)
            except exceptions.ReplayException as e:
                signals.add_log("Replay error: %s" % e, "warn")
            signals.flowlist_change.send(self)
        elif key == "S":

            def stop_server_playback(response):
                if response == "y":
                    self.master.options.server_replay = []

            a = self.master.addons.get("serverplayback")
            if a.count():
                signals.status_prompt_onekey.send(
                    prompt="Stop current server replay?",
                    keys=(
                        ("yes", "y"),
                        ("no", "n"),
                    ),
                    callback=stop_server_playback,
                )
            else:
                signals.status_prompt_onekey.send(
                    prompt="Server Replay",
                    keys=(
                        ("all flows", "a"),
                        ("this flow", "t"),
                    ),
                    callback=self.server_replay_prompt,
                )
        elif key == "U":
            for f in self.state.flows:
                f.marked = False
            signals.flowlist_change.send(self)
        elif key == "V":
            if not self.flow.modified():
                signals.status_message.send(message="Flow not modified.")
                return
            self.state.revert(self.flow)
            signals.flowlist_change.send(self)
            signals.status_message.send(message="Reverted.")
        elif key == "w":
            signals.status_prompt_onekey.send(
                self,
                prompt="Save",
                keys=(
                    ("listed flows", "l"),
                    ("this flow", "t"),
                ),
                callback=self.save_flows_prompt,
            )
        elif key == "X":
            if self.flow.killable:
                self.flow.kill(self.master)
        elif key == "enter":
            if self.flow.request:
                self.master.view_flow(self.flow)
        elif key == "|":
            signals.status_prompt_path.send(
                prompt="Send flow to script",
                callback=self.master.run_script_once,
                args=(self.flow, ))
        elif key == "E":
            signals.status_prompt_onekey.send(
                self,
                prompt="Export to file",
                keys=[(e[0], e[1]) for e in export.EXPORTERS],
                callback=common.export_to_clip_or_file,
                args=(None, self.flow, common.ask_save_path))
        elif key == "C":
            signals.status_prompt_onekey.send(
                self,
                prompt="Export to clipboard",
                keys=[(e[0], e[1]) for e in export.EXPORTERS],
                callback=common.export_to_clip_or_file,
                args=(None, self.flow, common.copy_to_clipboard_or_prompt))
        elif key == "b":
            common.ask_save_body(None, self.flow)
        else:
            return key
Example #5
0
    def keypress(self, size, key):
        conn = None  # type: Optional[Union[models.HTTPRequest, models.HTTPResponse]]
        if self.tab_offset == TAB_REQ:
            conn = self.flow.request
        elif self.tab_offset == TAB_RESP:
            conn = self.flow.response

        key = super(self.__class__, self).keypress(size, key)

        # Special case: Space moves over to the next flow.
        # We need to catch that before applying common.shortcuts()
        if key == " ":
            self.view_next_flow(self.flow)
            return

        key = common.shortcuts(key)
        if key in ("up", "down", "page up", "page down"):
            # Pass scroll events to the wrapped widget
            self._w.keypress(size, key)
        elif key == "a":
            self.flow.accept_intercept(self.master)
            signals.flow_change.send(self, flow = self.flow)
        elif key == "A":
            self.master.accept_all()
            signals.flow_change.send(self, flow = self.flow)
        elif key == "d":
            if self.state.flow_count() == 1:
                self.master.view_flowlist()
            elif self.state.view.index(self.flow) == len(self.state.view) - 1:
                self.view_prev_flow(self.flow)
            else:
                self.view_next_flow(self.flow)
            f = self.flow
            if f.killable:
                f.kill(self.master)
            self.state.delete_flow(f)
        elif key == "D":
            f = self.master.duplicate_flow(self.flow)
            signals.pop_view_state.send(self)
            self.master.view_flow(f)
            signals.status_message.send(message="Duplicated.")
        elif key == "p":
            self.view_prev_flow(self.flow)
        elif key == "r":
            self.master.replay_request(self.flow)
            signals.flow_change.send(self, flow = self.flow)
        elif key == "V":
            if self.flow.modified():
                self.state.revert(self.flow)
                signals.flow_change.send(self, flow = self.flow)
                signals.status_message.send(message="Reverted.")
            else:
                signals.status_message.send(message="Flow not modified.")
        elif key == "W":
            signals.status_prompt_path.send(
                prompt = "Save this flow",
                callback = self.master.save_one_flow,
                args = (self.flow,)
            )
        elif key == "|":
            signals.status_prompt_path.send(
                prompt = "Send flow to script",
                callback = self.master.run_script_once,
                args = (self.flow,)
            )
        elif key == "e":
            if self.tab_offset == TAB_REQ:
                signals.status_prompt_onekey.send(
                    prompt="Edit request",
                    keys=(
                        ("cookies", "c"),
                        ("query", "q"),
                        ("path", "p"),
                        ("url", "u"),
                        ("header", "h"),
                        ("form", "f"),
                        ("raw body", "r"),
                        ("method", "m"),
                    ),
                    callback=self.edit
                )
            elif self.tab_offset == TAB_RESP:
                signals.status_prompt_onekey.send(
                    prompt="Edit response",
                    keys=(
                        ("cookies", "c"),
                        ("code", "o"),
                        ("message", "m"),
                        ("header", "h"),
                        ("raw body", "r"),
                    ),
                    callback=self.edit
                )
            else:
                signals.status_message.send(
                    message="Tab to the request or response",
                    expire=1
                )
        elif key in set("bfgmxvzEC") and not conn:
            signals.status_message.send(
                message = "Tab to the request or response",
                expire = 1
            )
            return
        elif key == "b":
            if self.tab_offset == TAB_REQ:
                common.ask_save_body("q", self.flow)
            else:
                common.ask_save_body("s", self.flow)
        elif key == "f":
            signals.status_message.send(message="Loading all body data...")
            self.state.add_flow_setting(
                self.flow,
                (self.tab_offset, "fullcontents"),
                True
            )
            signals.flow_change.send(self, flow = self.flow)
            signals.status_message.send(message="")
        elif key == "m":
            p = list(contentviews.view_prompts)
            p.insert(0, ("Clear", "C"))
            signals.status_prompt_onekey.send(
                self,
                prompt = "Display mode",
                keys = p,
                callback = self.change_this_display_mode
            )
        elif key == "E":
            if self.tab_offset == TAB_REQ:
                scope = "q"
            else:
                scope = "s"
            signals.status_prompt_onekey.send(
                self,
                prompt = "Export to file",
                keys = [(e[0], e[1]) for e in export.EXPORTERS],
                callback = common.export_to_clip_or_file,
                args = (scope, self.flow, common.ask_save_path)
            )
        elif key == "C":
            if self.tab_offset == TAB_REQ:
                scope = "q"
            else:
                scope = "s"
            signals.status_prompt_onekey.send(
                self,
                prompt = "Export to clipboard",
                keys = [(e[0], e[1]) for e in export.EXPORTERS],
                callback = common.export_to_clip_or_file,
                args = (scope, self.flow, common.copy_to_clipboard_or_prompt)
            )
        elif key == "x":
            conn.content = None
            signals.flow_change.send(self, flow=self.flow)
        elif key == "v":
            if conn.raw_content:
                t = conn.headers.get("content-type")
                if "EDITOR" in os.environ or "PAGER" in os.environ:
                    self.master.spawn_external_viewer(conn.get_content(strict=False), t)
                else:
                    signals.status_message.send(
                        message = "Error! Set $EDITOR or $PAGER."
                    )
        elif key == "z":
            self.flow.backup()
            e = conn.headers.get("content-encoding", "identity")
            if e != "identity":
                try:
                    conn.decode()
                except ValueError:
                    signals.status_message.send(
                        message = "Could not decode - invalid data?"
                    )
            else:
                signals.status_prompt_onekey.send(
                    prompt = "Select encoding: ",
                    keys = (
                        ("gzip", "z"),
                        ("deflate", "d"),
                        ("brotli", "b"),
                    ),
                    callback = self.encode_callback,
                    args = (conn,)
                )
            signals.flow_change.send(self, flow = self.flow)
        else:
            # Key is not handled here.
            return key
Example #6
0
    def keypress(self, size, key):
        key = super(self.__class__, self).keypress(size, key)

        if key == " ":
            self.view_next_flow(self.flow)
            return

        key = common.shortcuts(key)
        if self.tab_offset == TAB_REQ:
            conn = self.flow.request
        elif self.tab_offset == TAB_RESP:
            conn = self.flow.response
        else:
            conn = None

        if key in ("up", "down", "page up", "page down"):
            # Why doesn't this just work??
            self._w.keypress(size, key)
        elif key == "a":
            self.flow.accept_intercept(self.master)
            signals.flow_change.send(self, flow = self.flow)
        elif key == "A":
            self.master.accept_all()
            signals.flow_change.send(self, flow = self.flow)
        elif key == "d":
            if self.state.flow_count() == 1:
                self.master.view_flowlist()
            elif self.state.view.index(self.flow) == len(self.state.view) - 1:
                self.view_prev_flow(self.flow)
            else:
                self.view_next_flow(self.flow)
            f = self.flow
            f.kill(self.master)
            self.state.delete_flow(f)
        elif key == "D":
            f = self.master.duplicate_flow(self.flow)
            self.master.view_flow(f)
            signals.status_message.send(message="Duplicated.")
        elif key == "p":
            self.view_prev_flow(self.flow)
        elif key == "r":
            r = self.master.replay_request(self.flow)
            if r:
                signals.status_message.send(message=r)
            signals.flow_change.send(self, flow = self.flow)
        elif key == "V":
            if not self.flow.modified():
                signals.status_message.send(message="Flow not modified.")
                return
            self.state.revert(self.flow)
            signals.flow_change.send(self, flow = self.flow)
            signals.status_message.send(message="Reverted.")
        elif key == "W":
            signals.status_prompt_path.send(
                prompt = "Save this flow",
                callback = self.master.save_one_flow,
                args = (self.flow,)
            )
        elif key == "E":
            signals.status_prompt_onekey.send(
                self,
                prompt = "Export",
                keys = (
                    ("as curl command", "c"),
                    ("as python code", "p"),
                    ("as raw request", "r"),
                    ("as locust code", "l"),
                    ("as locust task", "t"),
                ),
                callback = common.export_prompt,
                args = (self.flow,)
            )
        elif key == "|":
            signals.status_prompt_path.send(
                prompt = "Send flow to script",
                callback = self.master.run_script_once,
                args = (self.flow,)
            )

        if not conn and key in set(list("befgmxvz")):
            signals.status_message.send(
                message = "Tab to the request or response",
                expire = 1
            )
        elif conn:
            if key == "b":
                if self.tab_offset == TAB_REQ:
                    common.ask_save_body(
                        "q", self.master, self.state, self.flow
                    )
                else:
                    common.ask_save_body(
                        "s", self.master, self.state, self.flow
                    )
            elif key == "e":
                if self.tab_offset == TAB_REQ:
                    signals.status_prompt_onekey.send(
                        prompt = "Edit request",
                        keys = (
                            ("cookies", "c"),
                            ("query", "q"),
                            ("path", "p"),
                            ("url", "u"),
                            ("header", "h"),
                            ("form", "f"),
                            ("raw body", "r"),
                            ("method", "m"),
                        ),
                        callback = self.edit
                    )
                else:
                    signals.status_prompt_onekey.send(
                        prompt = "Edit response",
                        keys = (
                            ("cookies", "c"),
                            ("code", "o"),
                            ("message", "m"),
                            ("header", "h"),
                            ("raw body", "r"),
                        ),
                        callback = self.edit
                    )
                key = None
            elif key == "f":
                signals.status_message.send(message="Loading all body data...")
                self.state.add_flow_setting(
                    self.flow,
                    (self.tab_offset, "fullcontents"),
                    True
                )
                signals.flow_change.send(self, flow = self.flow)
                signals.status_message.send(message="")
            elif key == "P":
                if self.tab_offset == TAB_REQ:
                    scope = "q"
                else:
                    scope = "s"
                common.ask_copy_part(scope, self.flow, self.master, self.state)
            elif key == "m":
                p = list(contentviews.view_prompts)
                p.insert(0, ("Clear", "C"))
                signals.status_prompt_onekey.send(
                    self,
                    prompt = "Display mode",
                    keys = p,
                    callback = self.change_this_display_mode
                )
                key = None
            elif key == "x":
                signals.status_prompt_onekey.send(
                    prompt = "Delete body",
                    keys = (
                        ("completely", "c"),
                        ("mark as missing", "m"),
                    ),
                    callback = self.delete_body
                )
                key = None
            elif key == "v":
                if conn.content:
                    t = conn.headers.get("content-type")
                    if "EDITOR" in os.environ or "PAGER" in os.environ:
                        self.master.spawn_external_viewer(conn.content, t)
                    else:
                        signals.status_message.send(
                            message = "Error! Set $EDITOR or $PAGER."
                        )
            elif key == "z":
                self.flow.backup()
                e = conn.headers.get("content-encoding", "identity")
                if e != "identity":
                    if not conn.decode():
                        signals.status_message.send(
                            message = "Could not decode - invalid data?"
                        )
                else:
                    signals.status_prompt_onekey.send(
                        prompt = "Select encoding: ",
                        keys = (
                            ("gzip", "z"),
                            ("deflate", "d"),
                        ),
                        callback = self.encode_callback,
                        args = (conn,)
                    )
                signals.flow_change.send(self, flow = self.flow)
        return key
Example #7
0
    def keypress(self, xxx_todo_changeme, key):
        (maxcol,) = xxx_todo_changeme
        key = common.shortcuts(key)

        # Test keys are number 1 to 6, flow must me marked before run test on it.
        if key == "1":
            for f in self.state.flows:
                if f.marked:
                    f.authentication = self.test_authentication(f)
                    signals.flowlist_change.send(self)

        if key == "2":
            for f in self.state.flows:
                if f.marked:
                    f.authentication = self.gather_authentication_result(f)
                    signals.flowlist_change.send(self)

        if key == "3":
            cnt = 1
            for f in self.state.flows:
                if f.marked:
                    f.authorization = self.test_authorization(f)
                    signals.flowlist_change.send(self)

        if key == "4":
            for f in self.state.flows:
                if f.marked:
                    f.authorization = self.gather_authorization_result(f)
                    signals.flowlist_change.send(self)

        # payu salt in req or resp
        if key == "5":
            for f in self.state.flows:
                if f.marked:
                    f.payu_salt_leak = self.test_payu_salt_leak(f)
                    signals.flowlist_change.send(self) 

        # otp in resp
        if key == "6":
            for f in self.state.flows:
                if f.marked:
                    f.otp_leak = self.test_otp_leak(f)
                    signals.flowlist_change.send(self)


        if key == "R":
            self.master.repeater(self.flow)
            signals.status_message.send(message="Repeating request 64 times")
            signals.flowlist_change.send(self)
        if key == "a":
            self.flow.accept_intercept(self.master)
            signals.flowlist_change.send(self)
        elif key == "d":
            if self.flow.killable:
                self.flow.kill(self.master)
            self.state.delete_flow(self.flow)
            signals.flowlist_change.send(self)
        elif key == "D":
            f = self.master.duplicate_flow(self.flow)
            self.master.state.set_focus_flow(f)
            signals.flowlist_change.send(self)
        elif key == "f1":
            self.flow.authentication += 1
            self.flow.authentication %= 3
            signals.flowlist_change.send(self)
        elif key == "f2":
            self.flow.authorization += 1
            self.flow.authorization %= 3
            signals.flowlist_change.send(self)
        elif key == "f3":
            self.flow.payu_salt_leak += 1
            self.flow.payu_salt_leak %= 3
            signals.flowlist_change.send(self)
        elif key == "f4":
            self.flow.otp_leak += 1
            self.flow.otp_leak %= 3
            signals.flowlist_change.send(self)
        elif key == "u":
            for f in self.master.state.view:
                f.marked = not f.marked
            signals.flowlist_change.send(self)
        elif key == "m":
            self.flow.marked = not self.flow.marked
            signals.flowlist_change.send(self)
        elif key == "M":
            if self.state.mark_filter:
                self.state.disable_marked_filter()
            else:
                self.state.enable_marked_filter()
            signals.flowlist_change.send(self)
        elif key == "N":

            self.state.set_view_filter("!(.gif) & !(.js) & !(.css) & !(.ttf) & !(.png) & !(.svg) & !(gstatic) & !(.ico) & !(.jpg) & !(.jpeg) & !(.woff) & !(.woff2) & !(fbcdn) & !(google) & !(facebook)")
            signals.flowlist_change.send(self)
        elif key == "v":
            self.state.set_view_filter("")
            signals.flowlist_change.send(self)
        elif key == "r":
            try:
                self.master.replay_request(self.flow)
            except exceptions.ReplayException as e:
                signals.add_log("Replay error: %s" % e, "warn")
            signals.flowlist_change.send(self)
        elif key == "S":
            def stop_server_playback(response):
                if response == "y":
                    self.master.options.server_replay = []
            a = self.master.addons.get("serverplayback")
            if a.count():
                signals.status_prompt_onekey.send(
                    prompt = "Stop current server replay?",
                    keys = (
                        ("yes", "y"),
                        ("no", "n"),
                    ),
                    callback = stop_server_playback,
                )
            else:
                signals.status_prompt_onekey.send(
                    prompt = "Server Replay",
                    keys = (
                        ("all flows", "a"),
                        ("this flow", "t"),
                    ),
                    callback = self.server_replay_prompt,
                )
        elif key == "U":
            for f in self.state.flows:
                f.marked = False
            signals.flowlist_change.send(self)
        elif key == "V":
            if not self.flow.modified():
                signals.status_message.send(message="Flow not modified.")
                return
            self.state.revert(self.flow)
            signals.flowlist_change.send(self)
            signals.status_message.send(message="Reverted.")
        elif key == "w":
            signals.status_prompt_onekey.send(
                self,
                prompt = "Save",
                keys = (("listed flows as swagger", "s"),
                    ("listed flows as report", "r"),
                    ("listed flows as har", "h"),
                    ("listed flows", "l"),
                    ("this flow", "t"),
                ),
                callback = self.save_flows_prompt,
            )
        elif key == "X":
            if self.flow.killable:
                self.flow.kill(self.master)
        elif key == "z":
            # create a copy since used in for loop
            copy_of_state_view = self.state.view[:]
            for f in copy_of_state_view:
                signals.add_log("Len of state.view %d " % len(self.state.view), level="info")
                if f.killable:
                    f.kill(self.master)
                self.state.delete_flow(f)
            signals.flowlist_change.send(self)
        elif key == "enter":
            if self.flow.request:
                self.flow = common.add_key_log(self.flow, "enter")
                signals.flowlist_change.send(self)
                self.master.view_flow(self.flow)
        elif key == "|":
            signals.status_prompt_path.send(
                prompt = "Send flow to script",
                callback = self.master.run_script_once,
                args = (self.flow,)
            )
        elif key == "E":
            signals.status_prompt_onekey.send(
                self,
                prompt = "Export to file",
                keys = [(e[0], e[1]) for e in export.EXPORTERS],
                callback = common.export_to_clip_or_file,
                args = (None, self.flow, common.ask_save_path)
            )
        elif key == "C":
            signals.status_prompt_onekey.send(
                self,
                prompt = "Export to clipboard",
                keys = [(e[0], e[1]) for e in export.EXPORTERS],
                callback = common.export_to_clip_or_file,
                args = (None, self.flow, common.copy_to_clipboard_or_prompt)
            )
        elif key == "b":
            common.ask_save_body(None, self.flow)
        else:
            return key
Example #8
0
 def keypress(self, xxx_todo_changeme, key):
     (maxcol, ) = xxx_todo_changeme
     key = common.shortcuts(key)
     if key == "a":
         self.flow.accept_intercept(self.master)
         signals.flowlist_change.send(self)
     elif key == "d":
         self.flow.kill(self.master)
         self.state.delete_flow(self.flow)
         signals.flowlist_change.send(self)
     elif key == "D":
         f = self.master.duplicate_flow(self.flow)
         self.master.view_flow(f)
     elif key == "m":
         if self.state.flow_marked(self.flow):
             self.state.set_flow_marked(self.flow, False)
         else:
             self.state.set_flow_marked(self.flow, True)
         signals.flowlist_change.send(self)
     elif key == "M":
         if self.state.mark_filter:
             self.state.disable_marked_filter()
         else:
             self.state.enable_marked_filter()
         signals.flowlist_change.send(self)
     elif key == "r":
         r = self.master.replay_request(self.flow)
         if r:
             signals.status_message.send(message=r)
         signals.flowlist_change.send(self)
     elif key == "S":
         if not self.master.server_playback:
             signals.status_prompt_onekey.send(
                 prompt="Server Replay",
                 keys=(
                     ("all flows", "a"),
                     ("this flow", "t"),
                     ("file", "f"),
                 ),
                 callback=self.server_replay_prompt,
             )
         else:
             signals.status_prompt_onekey.send(
                 prompt="Stop current server replay?",
                 keys=(
                     ("yes", "y"),
                     ("no", "n"),
                 ),
                 callback=self.stop_server_playback_prompt,
             )
     elif key == "U":
         for f in self.state.flows:
             self.state.set_flow_marked(f, False)
         signals.flowlist_change.send(self)
     elif key == "V":
         if not self.flow.modified():
             signals.status_message.send(message="Flow not modified.")
             return
         self.state.revert(self.flow)
         signals.flowlist_change.send(self)
         signals.status_message.send(message="Reverted.")
     elif key == "w":
         signals.status_prompt_onekey.send(
             self,
             prompt="Save",
             keys=(
                 ("all flows", "a"),
                 ("this flow", "t"),
                 ("marked flows", "m"),
             ),
             callback=self.save_flows_prompt,
         )
     elif key == "X":
         self.flow.kill(self.master)
     elif key == "enter":
         if self.flow.request:
             self.master.view_flow(self.flow)
     elif key == "|":
         signals.status_prompt_path.send(
             prompt="Send flow to script",
             callback=self.master.run_script_once,
             args=(self.flow, ))
     elif key == "P":
         common.ask_copy_part("a", self.flow, self.master, self.state)
     elif key == "E":
         signals.status_prompt_onekey.send(self,
                                           prompt="Export",
                                           keys=(
                                               ("as curl command", "c"),
                                               ("as python code", "p"),
                                               ("as raw request", "r"),
                                               ("as locust code", "l"),
                                               ("as locust task", "t"),
                                           ),
                                           callback=common.export_prompt,
                                           args=(self.flow, ))
     elif key == "b":
         common.ask_save_body(None, self.master, self.state, self.flow)
     else:
         return key
Example #9
0
 def keypress(self, xxx_todo_changeme, key):
     (maxcol,) = xxx_todo_changeme
     key = common.shortcuts(key)
     if key == "a":
         self.flow.accept_intercept(self.master)
         signals.flowlist_change.send(self)
     elif key == "d":
         if not self.flow.reply.acked:
             self.flow.kill(self.master)
         self.state.delete_flow(self.flow)
         signals.flowlist_change.send(self)
     elif key == "D":
         f = self.master.duplicate_flow(self.flow)
         self.master.state.set_focus_flow(f)
         signals.flowlist_change.send(self)
     elif key == "m":
         self.flow.marked = not self.flow.marked
         signals.flowlist_change.send(self)
     elif key == "M":
         if self.state.mark_filter:
             self.state.disable_marked_filter()
         else:
             self.state.enable_marked_filter()
         signals.flowlist_change.send(self)
     elif key == "r":
         r = self.master.replay_request(self.flow)
         if r:
             signals.status_message.send(message=r)
         signals.flowlist_change.send(self)
     elif key == "S":
         if not self.master.server_playback:
             signals.status_prompt_onekey.send(
                 prompt = "Server Replay",
                 keys = (
                     ("all flows", "a"),
                     ("this flow", "t"),
                     ("file", "f"),
                 ),
                 callback = self.server_replay_prompt,
             )
         else:
             signals.status_prompt_onekey.send(
                 prompt = "Stop current server replay?",
                 keys = (
                     ("yes", "y"),
                     ("no", "n"),
                 ),
                 callback = self.stop_server_playback_prompt,
             )
     elif key == "U":
         for f in self.state.flows:
             f.marked = False
         signals.flowlist_change.send(self)
     elif key == "V":
         if not self.flow.modified():
             signals.status_message.send(message="Flow not modified.")
             return
         self.state.revert(self.flow)
         signals.flowlist_change.send(self)
         signals.status_message.send(message="Reverted.")
     elif key == "w":
         signals.status_prompt_onekey.send(
             self,
             prompt = "Save",
             keys = (
                 ("listed flows", "l"),
                 ("this flow", "t"),
             ),
             callback = self.save_flows_prompt,
         )
     elif key == "X":
         if not self.flow.reply.acked:
             self.flow.kill(self.master)
     elif key == "enter":
         if self.flow.request:
             self.master.view_flow(self.flow)
     elif key == "|":
         signals.status_prompt_path.send(
             prompt = "Send flow to script",
             callback = self.master.run_script_once,
             args = (self.flow,)
         )
     elif key == "E":
         signals.status_prompt_onekey.send(
             self,
             prompt = "Export to file",
             keys = [(e[0], e[1]) for e in export.EXPORTERS],
             callback = common.export_to_clip_or_file,
             args = (None, self.flow, common.ask_save_path)
         )
     elif key == "C":
         signals.status_prompt_onekey.send(
             self,
             prompt = "Export to clipboard",
             keys = [(e[0], e[1]) for e in export.EXPORTERS],
             callback = common.export_to_clip_or_file,
             args = (None, self.flow, common.copy_to_clipboard_or_prompt)
         )
     elif key == "b":
         common.ask_save_body(None, self.flow)
     else:
         return key