Shell Python administrativo sobre SSH para tu servidor Twisted en 10 líneas

entre tu reactor.listeTCP(puerto, factory) y reactor.run():

from twisted.conch import manhole, manhole_ssh
from twisted.cred import portal, checkers 
 
def getManholeFactory(namespace, **passwords):
    realm = manhole_ssh.TerminalRealm()
    def getManhole(_): return manhole.Manhole(namespace)
    realm.chainedProtocolFactory.protocolFactory = getManhole
    p = portal.Portal(realm)
    p.registerChecker(
    checkers.InMemoryUsernamePasswordDatabaseDontUse(**passwords))
    f = manhole_ssh.ConchFactory(p)
    return f
 
reactor.listenTCP(2222, getManholeFactory(globals(), admin='aaa'))

Los aplausos para este tutorial.

About Juanjo

Mi nombre es Juanjo Conti, vivo en Santa Fe y soy Ingeniero en Sistemas de Información. Mi lenguaje de programación de cabecera es Python; lo uso para trabajar, estudiar y jugar. Como hobby escribí un libro de cuentos que se puede descargar gratuitamente.
This entry was posted in Aprendiendo Python, Twisted and tagged , . Bookmark the permalink.
  • Juanjo

    Muy útil para debuggear para puede ser muy riesgoso.
    Un ejemplo: si en el shell hacemos un while True, el cotrol no vuelve al reactor y el servidor se cuelga.