| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
""" |
|---|
| 7 |
I am the support module for making a manhole server with twistd. |
|---|
| 8 |
""" |
|---|
| 9 |
|
|---|
| 10 |
from twisted.manhole import service |
|---|
| 11 |
from twisted.spread import pb |
|---|
| 12 |
from twisted.python import usage, util |
|---|
| 13 |
from twisted.cred import portal, checkers |
|---|
| 14 |
from twisted.application import strports |
|---|
| 15 |
import os, sys |
|---|
| 16 |
|
|---|
| 17 |
class Options(usage.Options): |
|---|
| 18 |
synopsis = "[options]" |
|---|
| 19 |
optParameters = [ |
|---|
| 20 |
["user", "u", "admin", "Name of user to allow to log in"], |
|---|
| 21 |
["port", "p", str(pb.portno), "Port to listen on"], |
|---|
| 22 |
] |
|---|
| 23 |
|
|---|
| 24 |
optFlags = [ |
|---|
| 25 |
["tracebacks", "T", "Allow tracebacks to be sent over the network"], |
|---|
| 26 |
] |
|---|
| 27 |
zsh_actions = {"user" : "_users"} |
|---|
| 28 |
|
|---|
| 29 |
def opt_password(self, password): |
|---|
| 30 |
"""Required. '-' will prompt or read a password from stdin. |
|---|
| 31 |
""" |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
if password in ('', '-'): |
|---|
| 36 |
self['password'] = util.getPassword(confirm=1) |
|---|
| 37 |
else: |
|---|
| 38 |
self['password'] = password |
|---|
| 39 |
opt_w = opt_password |
|---|
| 40 |
|
|---|
| 41 |
def postOptions(self): |
|---|
| 42 |
if not self.has_key('password'): |
|---|
| 43 |
self.opt_password('-') |
|---|
| 44 |
|
|---|
| 45 |
def makeService(config): |
|---|
| 46 |
port, user, password = config['port'], config['user'], config['password'] |
|---|
| 47 |
p = portal.Portal( |
|---|
| 48 |
service.Realm(service.Service(config["tracebacks"], config.get('namespace'))), |
|---|
| 49 |
[checkers.InMemoryUsernamePasswordDatabaseDontUse(**{user: password})] |
|---|
| 50 |
) |
|---|
| 51 |
return strports.service(port, pb.PBServerFactory(p, config["tracebacks"])) |
|---|