Пример #1
0
    def run(self):
        self.ui = urwid.raw_display.Screen()
        self.ui.set_terminal_properties(256)
        self.set_palette(self.options, None)
        self.options.subscribe(
            self.set_palette,
            ["console_palette", "console_palette_transparent"])
        self.loop = urwid.MainLoop(
            urwid.SolidFill("x"),
            screen=self.ui,
            handle_mouse=self.options.console_mouse,
        )

        self.window = window.Window(self)
        self.loop.widget = self.window
        self.window.refresh()

        self.loop.set_alarm_in(0.01, self.ticker)

        self.start()
        try:
            self.loop.run()
        except Exception:
            self.loop.stop()
            sys.stdout.flush()
            print(traceback.format_exc(), file=sys.stderr)
            print("mitmproxy has crashed!", file=sys.stderr)
            print("Please lodge a bug report at:", file=sys.stderr)
            print("\thttps://github.com/mitmproxy/mitmproxy", file=sys.stderr)
            print("Shutting down...", file=sys.stderr)
        finally:
            sys.stderr.flush()
            super().shutdown()
Пример #2
0
 def view_grideditor(self, ge):
     signals.push_view_state.send(self,
                                  window=window.Window(
                                      self, ge, None,
                                      statusbar.StatusBar(
                                          self, grideditor.base.FOOTER),
                                      ge.make_help()))
Пример #3
0
 def view_help(self):
     hc = self.view_stack[-1].helpctx
     signals.push_view_state.send(
         self,
         window=window.Window(self, help.HelpView(hc), None,
                              statusbar.StatusBar(self, help.footer), None,
                              "help"))
Пример #4
0
    def run(self):
        if not sys.stdout.isatty():
            print("Error: mitmproxy's console interface requires a tty. "
                  "Please run mitmproxy in an interactive shell environment.", file=sys.stderr)
            sys.exit(1)

        self.ui = window.Screen()
        self.ui.set_terminal_properties(256)
        self.set_palette(self.options, None)
        self.options.subscribe(
            self.set_palette,
            ["console_palette", "console_palette_transparent"]
        )
        self.loop = urwid.MainLoop(
            urwid.SolidFill("x"),
            event_loop=urwid.AsyncioEventLoop(loop=asyncio.get_event_loop()),
            screen = self.ui,
            handle_mouse = self.options.console_mouse,
        )
        self.window = window.Window(self)
        self.loop.widget = self.window
        self.window.refresh()

        if self.start_err:
            def display_err(*_):
                self.sig_add_log(None, self.start_err)
                self.start_err = None
            self.loop.set_alarm_in(0.01, display_err)

        super().run_loop(self.loop.run)
Пример #5
0
 def view_flow(self, flow, tab_offset=0):
     self.view.focus.flow = flow
     signals.push_view_state.send(
         self,
         window=window.Window(
             self, flowview.FlowView(self, self.view, flow, tab_offset),
             flowview.FlowViewHeader(self, flow),
             statusbar.StatusBar(self, flowview.footer),
             flowview.help_context))
Пример #6
0
 def view_commands(self):
     for i in self.view_stack:
         if isinstance(i["body"], commands.Commands):
             return
     signals.push_view_state.send(
         self,
         window=window.Window(self, commands.Commands(self), None,
                              statusbar.StatusBar(self, commands.footer),
                              commands.help_context, "commands"))
Пример #7
0
 def view_options(self):
     for i in self.view_stack:
         if isinstance(i["body"], options.Options):
             return
     signals.push_view_state.send(
         self,
         window=window.Window(self, options.Options(self), None,
                              statusbar.StatusBar(self, options.footer),
                              options.help_context, "options"))
Пример #8
0
 def view_palette_picker(self):
     signals.push_view_state.send(self,
                                  window=window.Window(
                                      self,
                                      palettepicker.PalettePicker(self),
                                      None,
                                      statusbar.StatusBar(
                                          self, palettepicker.footer),
                                      palettepicker.help_context,
                                  ))
Пример #9
0
 def view_help(self, helpctx):
     signals.push_view_state.send(
         self,
         window = window.Window(
             self,
             help.HelpView(helpctx),
             None,
             statusbar.StatusBar(self, help.footer),
             None
         )
     )
Пример #10
0
    def view_flowlist(self):
        if self.ui.started:
            self.ui.clear()

        if self.options.eventlog:
            body = flowlist.BodyPile(self)
        else:
            body = flowlist.FlowListBox(self)

        signals.push_view_state.send(
            self,
            window=window.Window(self, body, None,
                                 statusbar.StatusBar(self, flowlist.footer),
                                 flowlist.help_context))
Пример #11
0
    def run(self):
        if not sys.stdout.isatty():
            print(
                "Error: mitmproxy's console interface requires a tty. "
                "Please run mitmproxy in an interactive shell environment.",
                file=sys.stderr)
            sys.exit(1)

        self.ui = window.Screen()
        self.ui.set_terminal_properties(256)
        self.set_palette(self.options, None)
        self.options.subscribe(
            self.set_palette,
            ["console_palette", "console_palette_transparent"])
        self.loop = urwid.MainLoop(
            urwid.SolidFill("x"),
            event_loop=urwid.AsyncioEventLoop(loop=asyncio.get_event_loop()),
            screen=self.ui,
            handle_mouse=self.options.console_mouse,
        )

        self.window = window.Window(self)
        self.loop.widget = self.window
        self.window.refresh()

        if self.start_err:

            def display_err(*_):
                self.sig_add_log(None, self.start_err)
                self.start_err = None

            self.loop.set_alarm_in(0.01, display_err)

        self.start()
        try:
            self.loop.run()
        except Exception:
            self.loop.stop()
            sys.stdout.flush()
            print(traceback.format_exc(), file=sys.stderr)
            print("mitmproxy has crashed!", file=sys.stderr)
            print("Please lodge a bug report at:", file=sys.stderr)
            print("\thttps://github.com/mitmproxy/mitmproxy", file=sys.stderr)
            print("Shutting down...", file=sys.stderr)
        finally:
            sys.stderr.flush()
            super().shutdown()
        self.addons.trigger("done")
Пример #12
0
    async def running(self) -> None:
        if not sys.stdout.isatty():
            print(
                "Error: mitmproxy's console interface requires a tty. "
                "Please run mitmproxy in an interactive shell environment.",
                file=sys.stderr)
            sys.exit(1)

        if os.name != "nt" and "utf" not in urwid.detected_encoding.lower():
            print(
                f"mitmproxy expects a UTF-8 console environment, not {urwid.detected_encoding!r}. "
                f"Set your LANG environment variable to something like en_US.UTF-8.",
                file=sys.stderr)
            # Experimental (04/2022): We just don't exit here and see if/how that affects users.
            # sys.exit(1)
        urwid.set_encoding("utf8")

        signals.call_in.connect(self.sig_call_in)
        self.ui = window.Screen()
        self.ui.set_terminal_properties(256)
        self.set_palette(self.options, None)
        self.options.subscribe(
            self.set_palette,
            ["console_palette", "console_palette_transparent"])

        loop = asyncio.get_running_loop()
        if isinstance(loop, getattr(asyncio, "ProactorEventLoop", tuple())):
            patch_tornado()
            # fix for https://bugs.python.org/issue37373
            loop = AddThreadSelectorEventLoop(loop)  # type: ignore
        self.loop = urwid.MainLoop(
            urwid.SolidFill("x"),
            event_loop=urwid.AsyncioEventLoop(loop=loop),
            screen=self.ui,
            handle_mouse=self.options.console_mouse,
        )
        self.window = window.Window(self)
        self.loop.widget = self.window
        self.window.refresh()

        self.loop.start()

        await super().running()
Пример #13
0
    def run(self):
        if not sys.stdout.isatty():
            print(
                "Error: mitmproxy's console interface requires a tty. "
                "Please run mitmproxy in an interactive shell environment.",
                file=sys.stderr)
            sys.exit(1)

        signals.call_in.connect(self.sig_call_in)
        self.ui = window.Screen()
        self.ui.set_terminal_properties(256)
        self.set_palette(self.options, None)
        self.options.subscribe(
            self.set_palette,
            ["console_palette", "console_palette_transparent"])
        loop = asyncio.get_event_loop()
        if isinstance(loop, getattr(asyncio, "ProactorEventLoop", tuple())):
            # fix for https://bugs.python.org/issue37373
            loop = AddThreadSelectorEventLoop(loop)
        self.loop = urwid.MainLoop(
            urwid.SolidFill("x"),
            event_loop=urwid.AsyncioEventLoop(loop=loop),
            screen=self.ui,
            handle_mouse=self.options.console_mouse,
        )
        self.window = window.Window(self)
        self.loop.widget = self.window
        self.window.refresh()

        if self.start_err:

            def display_err(*_):
                self.sig_add_log(None, self.start_err)
                self.start_err = None

            self.loop.set_alarm_in(0.01, display_err)

        super().run_loop(self.loop.run)