forked from gemrb/gemrb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanhole.py
33 lines (28 loc) · 1.17 KB
/
manhole.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# This is a script that allows you to talk to the embedded python interpreter
# using ssh. To use it, put it in the GUIScript directory and then add the
# following to include.py, or issue using the python console
#
# import manhole
# manhole.createManhole(port = 2222, users = { 'gemrb': 'password' })
#
# Then you can connect using ssh to the given port and issue python commands.
import GemRB
from twisted.internet import reactor
reactor.startRunning()
GemRB.SetTimer(lambda: reactor.iterate())
from twisted.conch import manhole, manhole_ssh
from twisted.conch.insults import insults
from twisted.cred import checkers, portal
def createManhole(port = 2222, users = { 'gemrb': 'password' }):
"""Create a twisted manhole for accessing the embedded python interpreter"""
namespace = { 'GemRB' : GemRB }
def makeProtocol():
return insults.ServerProtocol(manhole.ColoredManhole, namespace)
r = manhole_ssh.TerminalRealm()
r.chainedProtocolFactory = makeProtocol
c = checkers.InMemoryUsernamePasswordDatabaseDontUse()
for (username, password) in users.iteritems():
c.addUser(username, password)
p = portal.Portal(r, [c])
f = manhole_ssh.ConchFactory(p)
return reactor.listenTCP(port, f)