Beispiel #1
0
def makeService(options):
    """
    Construct a Pantheon SSH service.
    """
    from twisted.internet import reactor

    factory = SSHFactory()
    key = options["host-key"]
    factory.privateKeys = {key.sshType(): key}
    factory.publicKeys = {key.sshType(): key.public()}
    realm = PantheonRealm(
        reactor,
        options['auth-host'], options['auth-port'],
        options['client-key'].path, options['client-cert'].path)
    checker = PantheonHTTPChecker(
        reactor,
        options['auth-host'], options['auth-port'],
        options['client-key'].path, options['client-cert'].path)
    factory.portal = Portal(realm, [checker])

    service = MultiService()
    for endpoint in options["listen"]:
        child = StreamServerEndpointService(endpoint, factory)
        child.setServiceParent(service)
    return service
Beispiel #2
0
    def makeService(self, options):
        greatPath = FilePath(great.__file__).parent()
        staticPath = greatPath.child("static")
        templatesPath = greatPath.child("templates")

        rootResource = Resource()
        rootResource.putChild("", File(staticPath.child("index.html").path))
        rootResource.putChild("static", File(staticPath.path))
        rootResource.putChild("templates", File(templatesPath.path))

        rootResource.putChild("great", MinionResource(create_app()))

        greatService = StreamServerEndpointService(
            endpoint=options["endpoint"],
            factory=server.Site(rootResource),
        )

        redirects = options["redirects"]
        if not redirects:
            return greatService

        service = MultiService()
        greatService.setServiceParent(service)

        for redirect in redirects:
            redirectService = StreamServerEndpointService(
                endpoint=redirect,
                factory=server.Site(Redirect(options["canonical_url"])),
            )
            redirectService.setServiceParent(service)

        return service
Beispiel #3
0
    def startService(self):
        MultiService.startService(self)

        staticPath = FilePath(__file__).sibling("static")
        root = NoListDirFile(staticPath.path)
        root.putChild('api',
                      SockJSResource(Factory.forProtocol(DaneDoctorProtocol)))

        webService = StreamServerEndpointService(
            serverFromString(self._reactor, "tcp:8080"), Site(root))
        webService.setServiceParent(self)
Beispiel #4
0
Datei: tap.py Projekt: hynek/tnw
    def startService(self):
        MultiService.startService(self)

        staticPath = FilePath(__file__).sibling("static")
        root = NoListDirFile(staticPath.path)
        root.putChild('api', SockJSResource(
            Factory.forProtocol(DaneDoctorProtocol))
        )

        webService = StreamServerEndpointService(
            serverFromString(self._reactor, "tcp:8080"),
            Site(root)
        )
        webService.setServiceParent(self)
Beispiel #5
0
    def makeService(self, options):
        reactor = self.reactor
        if reactor is None:
            from twisted.internet import reactor

        resolver = self.resolver
        if resolver is None:
            resolver = getResolver()

        with open(options.config) as infile:
            config = yaml.safe_load(infile)

        multiService = MultiService()

        for proxy in config['proxies']:
            client = endpoints.clientFromString(reactor, str(proxy['client']))
            server = endpoints.serverFromString(reactor, str(proxy['server']))
            fac = ProxyFactory(client, resolver, proxy)
            service = StreamServerEndpointService(server, fac)
            service.setServiceParent(multiService)

        return multiService
Beispiel #6
0
    def makeService(self, options):
        pi = Pi(audience=options["canonical_url"])
        piService = StreamServerEndpointService(
            endpoint=options["endpoint"],
            factory=server.Site(pi.app.resource()),
        )

        redirects = options["redirects"]
        if not redirects:
            return piService

        service = MultiService()
        piService.setServiceParent(service)

        for redirect in redirects:
            redirectService = StreamServerEndpointService(
                endpoint=redirect,
                factory=server.Site(Redirect(options["canonical_url"])),
            )
            redirectService.setServiceParent(service)

        return service
Beispiel #7
0
# coding:utf-8

'''
@author = super_fazai
@File    : basic_server.py
@connect : [email protected]
'''

"""
设置监听amp服务器

AMP运行在面向流的基于连接的协议上,例如TCP或SSL。在使用AMP协议的任何功能之前,您需要连接。用于建立AMP连接的协议类是AMP。连接设置与Twisted中几乎所有协议的工作方式相同。
"""

from twisted.protocols.amp import AMP
from twisted.internet import reactor
from twisted.internet.protocol import Factory
from twisted.internet.endpoints import TCP4ServerEndpoint
from twisted.application.service import Application
from twisted.application.internet import StreamServerEndpointService

application = Application("basic AMP server")

endpoint = TCP4ServerEndpoint(reactor, 8751)
factory = Factory()
factory.protocol = AMP
service = StreamServerEndpointService(endpoint, factory)
service.setServiceParent(application)
Beispiel #8
0
            self.setContextFactory(name, connection)
        else:
            log.msg('SNI not provided, closing SSL connection')
            connection.shutdown()

    def getContext(self):
        return self._context


sslContext = SNIContextFactory(depl, config)

ports = [
    endpoints.TCP4ServerEndpoint(reactor, config.getint('master', 'port')),
    endpoints.SSL4ServerEndpoint(reactor, config.getint('master', 'sslport'),
                                 sslContext),
]

logfile = filepath.FilePath(config.get('master', 'http_logfile'))
if not logfile.parent().exists():
    logfile.parent().makedirs()

depl.root.putChild('_admin', resources.VhostListing(depl))
site = server.Site(depl.root, logPath=logfile.path)

application = service.Application('appserver')
depl.setServiceParent(application)

for port in ports:
    svc = StreamServerEndpointService(port, site)
    svc.setServiceParent(application)