def makeService(self, options): rpc = TriggerXMLRPCServer(allowNone=True, useDateTime=True) xmlrpc.addIntrospection(rpc) site_factory = server.Site(rpc) # Try to setup SSL if ssl is not None: ctx = ssl.DefaultOpenSSLContextFactory(options['ssl-keyfile'], options['ssl-certfile']) xmlrpc_service = SSLServer(int(options['port']), site_factory, ctx) # Or fallback to clear-text =( else: xmlrpc_service = TCPServer(int(options['port']), site_factory) # SSH Manhole service console_service = makeConsoleService( { 'sshPort': 'tcp:%s' % options['ssh-port'], 'telnetPort': None, 'passwd': options['ssh-users'], 'namespace': { 'service': rpc, 'rebuild': rebuild, 'factory': site_factory, } } ) svc = MultiService() xmlrpc_service.setServiceParent(svc) console_service.setServiceParent(svc) return svc
def makeService(self, options): rpc = TriggerXMLRPCServer(allowNone=True, useDateTime=True) xmlrpc.addIntrospection(rpc) site_factory = server.Site(rpc) # Try to setup SSL if ssl is not None: ctx = ssl.DefaultOpenSSLContextFactory(options['ssl-keyfile'], options['ssl-certfile']) xmlrpc_service = SSLServer(int(options['port']), site_factory, ctx, interface=options['listen-address']) # Or fallback to clear-text =( else: xmlrpc_service = TCPServer(int(options['port']), site_factory, interface=options['listen-address']) # SSH Manhole service console_service = makeConsoleService({ 'sshPort': 'tcp:%s:interface=%s' % (options['ssh-port'], options['listen-address']), 'sshKeyDir': options['ssh-keydir'], 'sshKeyName': options['ssh-keyname'], 'sshKeySize': options['ssh-keysize'], 'telnetPort': None, 'passwd': options['ssh-users'], 'namespace': { 'service': rpc, 'rebuild': rebuild, 'factory': site_factory, } }) svc = MultiService() xmlrpc_service.setServiceParent(svc) console_service.setServiceParent(svc) return svc
def main(): """To daemonize as a twistd plugin! Except this doesn't work and these""" from twisted.application.internet import TCPServer, SSLServer from twisted.application.service import Application from twisted.internet import ssl rpc = TriggerXMLRPCServer() xmlrpc.addIntrospection(rpc) server_factory = server.Site(rpc) application = Application('trigger_xmlrpc') #xmlrpc_service = TCPServer(8000, server_factory) ctx = ssl.DefaultOpenSSLContextFactory('server.key', 'cacert.pem') xmlrpc_service = SSLServer(8000, server_factory, ctx) xmlrpc_service.setServiceParent(application) return application
def make_application(*config_file_paths): """Parse configuration and launch a kaoz client/server process. Args: config_file_paths: list of paths to search for configuration files. Returns: A twisted Application object """ config = ConfigParser.SafeConfigParser() config.read(*config_file_paths) application = Application("Kaoz Irc-Notifier") client_factory = PublisherFactory(config) server_factory = ListenerFactory(config, client_factory) listen_port = config.getint('listener', 'port') if config.getboolean('listener', 'ssl'): assert has_ssl, "SSL support requested but not available" ssl_context = DefaultOpenSSLContextFactory( config.get('listener', 'ssl_cert'), # The key config.get('listener', 'ssl_cert'), # The certificate ) server = SSLServer(listen_port, server_factory, ssl_context) else: server = TCPServer(listen_port, server_factory) server.setServiceParent(application) # IRC irc_server = config.get('irc', 'server') irc_port = config.getint('irc', 'port') if config.getboolean('irc', 'ssl'): assert has_ssl, "SSL support requested but not available" ssl_context = ClientContextFactory() ircservice = SSLClient(irc_server, irc_port, client_factory, ssl_context) else: ircservice = TCPClient(irc_server, irc_port, client_factory) ircservice.setServiceParent(application) return application
class ProxyService(MultiService): """A class wrapping the whole things a s single twisted service.""" def __init__(self, ssl_cert, ssl_key, ssl_cert_chain, ssl_port, dest_host, dest_port, server_name, status_port): """ Create a rageServerService. @param ssl_cert: the certificate text. @param ssl_key: the key text. @param ssl_port: the port to listen on with ssl. @param dest_host: destination hostname. @param dest_port: destination port. @param server_name: name of this server. """ MultiService.__init__(self) self.heartbeat_writer = None if server_name is None: server_name = "anonymous_instance" self.server_name = server_name self.factory = SSLProxyFactory(ssl_port, dest_host, dest_port, self.server_name) ssl_context_factory = ProxyContextFactory(ssl_cert, ssl_key, ssl_cert_chain) self.ssl_service = SSLServer(ssl_port, self.factory, ssl_context_factory) self.ssl_service.setName("SSL") self.ssl_service.setServiceParent(self) # setup the status service self.status_service = create_status_service(self.factory, status_port) self.status_service.setServiceParent(self) # disable ssl compression if config.ssl_proxy.disable_ssl_compression: disable_ssl_compression(logger) @property def port(self): """The port with ssl.""" return get_service_port(self.ssl_service) @property def status_port(self): """The status service port.""" return get_service_port(self.status_service) @defer.inlineCallbacks def startService(self): """Start listening on two ports.""" logger.info("- - - - - SERVER STARTING") # setup stats in the factory yield MultiService.startService(self) # only start the HeartbeatWriter if the interval is > 0 heartbeat_interval = float(config.ssl_proxy.heartbeat_interval) if heartbeat_interval > 0: self.heartbeat_writer = stdio.StandardIO( supervisor_utils.HeartbeatWriter(heartbeat_interval, logger)) @defer.inlineCallbacks def stopService(self): """Stop listening on both ports.""" logger.info("- - - - - SERVER STOPPING") yield MultiService.stopService(self) if self.heartbeat_writer: self.heartbeat_writer.loseConnection() self.heartbeat_writer = None logger.info("- - - - - SERVER STOPPED")
class ProxyService(MultiService): """A class wrapping the whole things a s single twisted service.""" def __init__(self, ssl_cert, ssl_key, ssl_cert_chain, ssl_port, dest_host, dest_port, server_name, status_port): """ Create a rageServerService. @param ssl_cert: the certificate text. @param ssl_key: the key text. @param ssl_port: the port to listen on with ssl. @param dest_host: destination hostname. @param dest_port: destination port. @param server_name: name of this server. """ MultiService.__init__(self) self.heartbeat_writer = None if server_name is None: server_name = "anonymous_instance" self.server_name = server_name self.factory = SSLProxyFactory(ssl_port, dest_host, dest_port, self.server_name) ssl_context_factory = ProxyContextFactory(ssl_cert, ssl_key, ssl_cert_chain) self.ssl_service = SSLServer(ssl_port, self.factory, ssl_context_factory) self.ssl_service.setName("SSL") self.ssl_service.setServiceParent(self) # setup the status service self.status_service = create_status_service(self.factory, status_port) self.status_service.setServiceParent(self) # disable ssl compression if config.ssl_proxy.disable_ssl_compression: disable_ssl_compression(logger) @property def port(self): """The port with ssl.""" return get_service_port(self.ssl_service) @property def status_port(self): """The status service port.""" return get_service_port(self.status_service) @defer.inlineCallbacks def startService(self): """Start listening on two ports.""" logger.info("- - - - - SERVER STARTING") # setup stats in the factory yield MultiService.startService(self) # only start the HeartbeatWriter if the interval is > 0 heartbeat_interval = float(config.ssl_proxy.heartbeat_interval) if heartbeat_interval > 0: self.heartbeat_writer = stdio.StandardIO( supervisor_utils.HeartbeatWriter(heartbeat_interval, logger)) @defer.inlineCallbacks def stopService(self): """Stop listening on both ports.""" logger.info("- - - - - SERVER STOPPING") yield MultiService.stopService(self) if self.heartbeat_writer: self.heartbeat_writer.loseConnection() self.heartbeat_writer = None logger.info("- - - - - SERVER STOPPED")
def render(self, request): request.setResponseCode(self.status) request.setHeader(b"content-type", b"text/html; charset=utf-8") return self.page def getChild(self, chnam, request): return self class NoResource(ErrorResource): def __init__(self): ErrorResource.__init__(self, NOT_FOUND) application = Application("static-server") plainSite = Site(RedirectResource()) plainSite.displayTracebacks = False plainService6 = TCPServer(INSECURE_PORT, plainSite, interface='::') plainService6.setServiceParent(application) files = File(DOCUMENTS.path) files.childNotFound = NoResource() secureSite = Site(HSTSResource(files)) secureSite.displayTracebacks = False secureService6 = SSLServer(SECURE_PORT, secureSite, ctxFactory, interface='::') secureService6.setServiceParent(application)
request.setHeader(b"content-type", b"text/html; charset=utf-8") return self.page def getChild(self, chnam, request): return self class NoResource(ErrorResource): def __init__(self): ErrorResource.__init__(self, NOT_FOUND) application = Application("static-server") plainSite = Site(RedirectResource()) plainSite.displayTracebacks = False plainService6 = TCPServer(INSECURE_PORT, plainSite, interface='::') plainService6.setServiceParent(application) files = File(DOCUMENTS.path) files.childNotFound = NoResource() secureSite = Site(HSTSResource(files)) secureSite.displayTracebacks = False secureService6 = SSLServer(SECURE_PORT, secureSite, ctxFactory, interface='::') secureService6.setServiceParent(application)