annotate libervia/backend/plugins/plugin_dbg_manhole.py @ 4271:a5d27f69eedb

plugin misc list: Comments node creation can now be specified with `comments` field in `extra`.
author Goffi <goffi@goffi.org>
date Thu, 20 Jun 2024 14:36:09 +0200
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2837
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
2755
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin for debugging, using a manhole
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
2755
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
20 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
21 from libervia.backend.core.constants import Const as C
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
22 from libervia.backend.core.log import getLogger
2755
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from twisted.conch.insults import insults
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from twisted.conch.telnet import TelnetTransport, TelnetBootstrapProtocol
3134
48eafdab1c34 plugin manhole: added `d` to namespace as shortcut for defer.ensureDeferred
Goffi <goffi@goffi.org>
parents: 3126
diff changeset
25 from twisted.internet import reactor, protocol, defer
2837
e2005dd39c92 plugin manhole: added "jid" module to globals
Goffi <goffi@goffi.org>
parents: 2755
diff changeset
26 from twisted.words.protocols.jabber import jid
2755
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.conch.manhole import ColoredManhole
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 log = getLogger(__name__)
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 PLUGIN_INFO = {
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2837
diff changeset
32 C.PI_NAME: "Manhole debug plugin",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2837
diff changeset
33 C.PI_IMPORT_NAME: "manhole",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2837
diff changeset
34 C.PI_TYPE: "DEBUG",
2755
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 C.PI_PROTOCOLS: [],
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 C.PI_DEPENDENCIES: [],
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2837
diff changeset
37 C.PI_MAIN: "Manhole",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2837
diff changeset
38 C.PI_HANDLER: "no",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2837
diff changeset
39 C.PI_DESCRIPTION: _("""Debug plugin to have a telnet server"""),
2755
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 }
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 class Manhole(object):
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 def __init__(self, host):
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.host = host
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
47 port = int(host.memory.config_get(None, "manhole_debug_dangerous_port_int", 0))
2755
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 if port:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
49 self.start_manhole(port)
2755
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
51 def start_manhole(self, port):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
52 log.warning(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
53 _(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
54 "/!\\ Manhole debug server activated, be sure to not use it in "
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
55 "production, this is dangerous /!\\"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
56 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
57 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
58 log.info(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
59 _("You can connect to manhole server using telnet on port {port}").format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
60 port=port
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
61 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
62 )
2755
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 f = protocol.ServerFactory()
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 namespace = {
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2837
diff changeset
65 "host": self.host,
3126
2b0f739f8a46 plugin manhole: added "C" to namespace
Goffi <goffi@goffi.org>
parents: 3082
diff changeset
66 "C": C,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2837
diff changeset
67 "jid": jid,
3134
48eafdab1c34 plugin manhole: added `d` to namespace as shortcut for defer.ensureDeferred
Goffi <goffi@goffi.org>
parents: 3126
diff changeset
68 "d": defer.ensureDeferred,
2755
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 }
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
70 f.protocol = lambda: TelnetTransport(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
71 TelnetBootstrapProtocol,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
72 insults.ServerProtocol,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
73 ColoredManhole,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
74 namespace=namespace,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
75 )
2755
12d1ca646af1 plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 reactor.listenTCP(port, f)