From c9ae1d1ee57648eb02ccb5c1585bf77a7ffa83ab Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 7 Jan 2016 13:57:04 +0000 Subject: [PATCH 1/2] Change manhole to use ssh --- synapse/app/homeserver.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index 0807def6c..2c0b6d7b4 100755 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -42,6 +42,12 @@ from synapse.storage.prepare_database import UpgradeDatabaseException from synapse.server import HomeServer +from twisted.conch.manhole import ColoredManhole +from twisted.conch.insults import insults +from twisted.conch import manhole_ssh +from twisted.cred import checkers, portal + + from twisted.internet import reactor, task, defer from twisted.application import service from twisted.enterprise import adbapi @@ -67,7 +73,6 @@ from synapse.metrics.resource import MetricsResource, METRICS_PREFIX from synapse import events from daemonize import Daemonize -import twisted.manhole.telnet import synapse @@ -248,10 +253,21 @@ class SynapseHomeServer(HomeServer): if listener["type"] == "http": self._listener_http(config, listener) elif listener["type"] == "manhole": - f = twisted.manhole.telnet.ShellFactory() - f.username = "matrix" - f.password = "rabbithole" - f.namespace['hs'] = self + checker = checkers.InMemoryUsernamePasswordDatabaseDontUse( + matrix="rabbithole" + ) + + rlm = manhole_ssh.TerminalRealm() + rlm.chainedProtocolFactory = lambda: insults.ServerProtocol( + ColoredManhole, + { + "__name__": "__console__", + "hs": self, + } + ) + + f = manhole_ssh.ConchFactory(portal.Portal(rlm, [checker])) + reactor.listenTCP( listener["port"], f, From 5dc5e29b9cd688af5c71d6b465ccac3c8e1d3c14 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 7 Jan 2016 14:02:57 +0000 Subject: [PATCH 2/2] s/telnet/ssh/ --- synapse/config/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/config/server.py b/synapse/config/server.py index 187edd516..ed0e8c9fe 100644 --- a/synapse/config/server.py +++ b/synapse/config/server.py @@ -200,7 +200,7 @@ class ServerConfig(Config): - names: [federation] compress: false - # Turn on the twisted telnet manhole service on localhost on the given + # Turn on the twisted ssh manhole service on localhost on the given # port. # - port: 9000 # bind_address: 127.0.0.1