comparison libervia/backend/plugins/plugin_dbg_manhole.py @ 4071:4b842c1fb686

refactoring: renamed `sat` package to `libervia.backend`
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 11:49:51 +0200
parents sat/plugins/plugin_dbg_manhole.py@524856bd7b19
children 0d7bb4df2343
comparison
equal deleted inserted replaced
4070:d10748475025 4071:4b842c1fb686
1 #!/usr/bin/env python3
2
3
4 # SAT plugin for debugging, using a manhole
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
16
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 from libervia.backend.core.i18n import _
21 from libervia.backend.core.constants import Const as C
22 from libervia.backend.core.log import getLogger
23 from twisted.conch.insults import insults
24 from twisted.conch.telnet import TelnetTransport, TelnetBootstrapProtocol
25 from twisted.internet import reactor, protocol, defer
26 from twisted.words.protocols.jabber import jid
27 from twisted.conch.manhole import ColoredManhole
28
29 log = getLogger(__name__)
30
31 PLUGIN_INFO = {
32 C.PI_NAME: "Manhole debug plugin",
33 C.PI_IMPORT_NAME: "manhole",
34 C.PI_TYPE: "DEBUG",
35 C.PI_PROTOCOLS: [],
36 C.PI_DEPENDENCIES: [],
37 C.PI_MAIN: "Manhole",
38 C.PI_HANDLER: "no",
39 C.PI_DESCRIPTION: _("""Debug plugin to have a telnet server"""),
40 }
41
42
43
44 class Manhole(object):
45
46 def __init__(self, host):
47 self.host = host
48 port = int(host.memory.config_get(None, "manhole_debug_dangerous_port_int", 0))
49 if port:
50 self.start_manhole(port)
51
52 def start_manhole(self, port):
53 log.warning(_("/!\\ Manhole debug server activated, be sure to not use it in "
54 "production, this is dangerous /!\\"))
55 log.info(_("You can connect to manhole server using telnet on port {port}")
56 .format(port=port))
57 f = protocol.ServerFactory()
58 namespace = {
59 "host": self.host,
60 "C": C,
61 "jid": jid,
62 "d": defer.ensureDeferred,
63 }
64 f.protocol = lambda: TelnetTransport(TelnetBootstrapProtocol,
65 insults.ServerProtocol,
66 ColoredManhole,
67 namespace=namespace,
68 )
69 reactor.listenTCP(port, f)