Mercurial > libervia-backend
annotate sat/plugins/plugin_dbg_manhole.py @ 3934:e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
OpenPGP for XMPP Pubsub (https://xmpp.org/extensions/inbox/pubsub-encryption.html,
currently a protoXEP) is implemented and activated when `encrypted` is set to `True` in
pubsub's `extra` data.
On item retrieval, the decryption is transparent if the key is known, except if the
`decrypt` key in `extra` is set to `False` (notably useful when one wants to checks that
data is well encrypted).
Methods and corresponding bridge methods have been implemented to manage shared secrets
(to share, revoke or rotate the secrets).
plugin XEP-0060's `XEP-0060_publish` trigger point as been move before actual publish so
item can be modified (here e2ee) by the triggers. A new `XEP-0060_items` trigger point has
also been added.
`encrypted` flag can be used with plugin XEP-0277's microblog data
rel 380
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 15 Oct 2022 20:36:53 +0200 |
parents | be6d91572633 |
children | 524856bd7b19 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 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 | 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 |
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from sat.core.i18n import _ |
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from sat.core.constants import Const as C |
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from sat.core.log import getLogger |
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 | 32 C.PI_NAME: "Manhole debug plugin", |
33 C.PI_IMPORT_NAME: "manhole", | |
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 | 37 C.PI_MAIN: "Manhole", |
38 C.PI_HANDLER: "no", | |
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 |
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 class Manhole(object): |
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 |
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 def __init__(self, host): |
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 self.host = host |
3082
9211c0d8b50c
plugin manhole: fixed default value
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
48 port = int(host.memory.getConfig(None, "manhole_debug_dangerous_port_int", 0)) |
2755
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 if port: |
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 self.startManhole(port) |
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 |
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 def startManhole(self, port): |
3028 | 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}") | |
2755
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 .format(port=port)) |
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 f = protocol.ServerFactory() |
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 namespace = { |
3028 | 59 "host": self.host, |
3126
2b0f739f8a46
plugin manhole: added "C" to namespace
Goffi <goffi@goffi.org>
parents:
3082
diff
changeset
|
60 "C": C, |
3028 | 61 "jid": jid, |
3134
48eafdab1c34
plugin manhole: added `d` to namespace as shortcut for defer.ensureDeferred
Goffi <goffi@goffi.org>
parents:
3126
diff
changeset
|
62 "d": defer.ensureDeferred, |
2755
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 } |
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 f.protocol = lambda: TelnetTransport(TelnetBootstrapProtocol, |
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 insults.ServerProtocol, |
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 ColoredManhole, |
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 namespace=namespace, |
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 ) |
12d1ca646af1
plugin manhole: manhole debug plugin, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 reactor.listenTCP(port, f) |