2
from twisted.internet import protocol
3
from twisted.cred import credentials, portal
4
from twisted.application import internet
5
from twisted.protocols import policies
7
from twisted.conch import telnet
8
from twisted.conch.insults import insults
10
from pottery import ipottery
11
from pottery.wiring import textserver
13
class PotteryTelnetFactory(protocol.ServerFactory):
14
def __init__(self, realm, portal, applicationProtocolFactory):
17
self.applicationProtocolFactory = applicationProtocolFactory
20
return telnet.TelnetTransport(
21
telnet.TelnetBootstrapProtocol,
22
insults.ServerProtocol,
23
self.applicationProtocolFactory)
25
def login(self, username, password):
26
return self.portal.login(
27
credentials.UsernamePassword(username, password),
31
def create(self, username, password):
32
return self.realm.create(username, password)
34
def makeService(realm, port, applicationProtocolFactory=textserver.TextServer, debug=True):
35
p = portal.Portal(realm)
36
p.registerChecker(realm)
38
factory = PotteryTelnetFactory(realm, p, applicationProtocolFactory)
41
factory = policies.TrafficLoggingFactory(factory, 'telnet')
43
netsvc = internet.TCPServer(port, factory)