Beispiel #1
0
        def setupService(self):
            """
            Setup the application component.
            """
            is_secure, host, port, resource, path, params = parse_ws_url(self.url)

            # factory for use ApplicationSession
            def create():
                cfg = ComponentConfig(self.realm, self.extra)
                session = self.make(cfg)
                return session

            # create a WAMP-over-WebSocket transport client factory
            transport_factory = self.factory(create, url=self.url)

            # setup the client from a Twisted endpoint

            if is_secure:
                from twisted.application.internet import SSLClient
                ctx = self.context_factory
                if ctx is None:
                    from twisted.internet.ssl import optionsForClientTLS
                    ctx = optionsForClientTLS(host)
                client = SSLClient(host, port, transport_factory, contextFactory=ctx)
            else:
                if self.context_factory is not None:
                    raise Exception("context_factory specified on non-secure URI")
                from twisted.application.internet import TCPClient
                client = TCPClient(host, port, transport_factory)

            client.setServiceParent(self)
Beispiel #2
0
        def setupService(self):
            """
            Setup the application component.
            """
            is_secure, host, port, resource, path, params = parse_ws_url(self.url)

            # factory for use ApplicationSession
            def create():
                cfg = ComponentConfig(self.realm, self.extra)
                session = self.make(cfg)
                return session

            # create a WAMP-over-WebSocket transport client factory
            transport_factory = self.factory(create, url=self.url)

            # setup the client from a Twisted endpoint

            if is_secure:
                from twisted.application.internet import SSLClient
                ctx = self.context_factory
                if ctx is None:
                    from twisted.internet.ssl import optionsForClientTLS
                    ctx = optionsForClientTLS(host)
                client = SSLClient(host, port, transport_factory, contextFactory=ctx)
            else:
                if self.context_factory is not None:
                    raise Exception("context_factory specified on non-secure URI")
                from twisted.application.internet import TCPClient
                client = TCPClient(host, port, transport_factory)

            client.setServiceParent(self)
Beispiel #3
0
class BackupBroker(pb.Referenceable):
    def __init__(self, server='localhost', port=8123,
                 hostname=socket.gethostname(), secret_key=''):
        self.server = server
        self.port = port
        self.hostname = hostname
        self.secret_key = secret_key
        self.connected = False
        self.factory = pb.PBClientFactory()
        self.service = SSLClient(self.server, self.port, self.factory,
                                 ClientContextFactory())

    def get_paths(self):
        return self.perspective.callRemote('get_paths')

    def get_present_state(self, path):
        return self.perspective.callRemote('get_present_state', path)

    def check_index(self, path, index):
        return self.perspective.callRemote('check_index', path, index)

    def check_file(self, path, attrs):
        return self.perspective.callRemote('check_file', path, attrs)

    def delete_item(self, path):
        return self.perspective.callRemote('delete_item', path)

    def create_item(self, path, type='f'):
        return self.perspective.callRemote('create_item', path, type)

    def put_file(self, path, mtime, size):
        return self.perspective.callRemote('put_file', path, mtime, size)

    def login(self, client):
        return self.factory.login(
            cred.credentials.UsernamePassword(
                self.hostname,
                self.secret_key
            ),
            client=client
        )

    def _error(self, failure):
        raise ConnectionError(failure)

    def connect(self, client=None):
        self.service.startService()
        return self.login(client or self).addCallbacks(self._logged_in,
                                                       self._error)

    def _logged_in(self, perspective):
        self.perspective = perspective
        self.connected = True
        return self
Beispiel #4
0
    def __init__(self, amqp_url=None, publish_confirms=True):
        """Initialize the service."""
        service.MultiService.__init__(self)
        self._parameters = pika.URLParameters(amqp_url
                                              or config.conf["amqp_url"])
        self._confirms = publish_confirms
        if amqp_url.startswith("amqps"):
            _configure_tls_parameters(self._parameters)
        if self._parameters.client_properties is None:
            self._parameters.client_properties = config.conf[
                "client_properties"]

        factory = FedoraMessagingFactoryV2(self._parameters, self._confirms)
        if self._parameters.ssl_options:
            self._service = SSLClient(
                host=self._parameters.host,
                port=self._parameters.port,
                factory=factory,
                contextFactory=_ssl_context_factory(self._parameters),
            )
        else:
            self._service = TCPClient(host=self._parameters.host,
                                      port=self._parameters.port,
                                      factory=factory)
        self._service.factory = factory
        name = "{}{}:{}".format(
            "ssl:" if self._parameters.ssl_options else "",
            self._parameters.host,
            self._parameters.port,
        )
        self._service.setName(name)
        self._service.setServiceParent(self)
    def makeService(self, options):

        service = MultiService()

        contextFactory = DefaultOpenSSLContextFactory(options["key"], options["certificate"])
        apnsFactory = APNSClientFactory()
        apnsService = SSLClient(options["apns-host"], int(options["apns-port"]), apnsFactory, contextFactory)
        apnsService.setServiceParent(service)

        database = RegistrationDatabase(options["database"])
        topicName = parseTopicFromCertificate(options["certificate"])

        xapsService = UNIXServer(options["socket"], XAPSFactory(database, topicName, apnsFactory))
        xapsService.setServiceParent(service)

        return service
Beispiel #6
0
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
Beispiel #7
0
 def __init__(self, server='localhost', port=8123,
              hostname=socket.gethostname(), secret_key=''):
     self.server = server
     self.port = port
     self.hostname = hostname
     self.secret_key = secret_key
     self.connected = False
     self.factory = pb.PBClientFactory()
     self.service = SSLClient(self.server, self.port, self.factory,
                              ClientContextFactory())
Beispiel #8
0
    def makeService(self, options):

        service = MultiService()

        contextFactory = DefaultOpenSSLContextFactory(options["key"],
                                                      options["certificate"])
        apnsFactory = APNSClientFactory()
        apnsService = SSLClient(options["apns-host"],
                                int(options["apns-port"]), apnsFactory,
                                contextFactory)
        apnsService.setServiceParent(service)

        database = RegistrationDatabase(options["database"])
        topicName = parseTopicFromCertificate(options["certificate"])

        xapsService = UNIXServer(options["socket"],
                                 XAPSFactory(database, topicName, apnsFactory))
        xapsService.setServiceParent(service)

        return service
 def connect(self):
     factory = self.factoryClass(self._parameters, self._bindings)
     if self._parameters.ssl_options:
         serv = SSLClient(
             host=self._parameters.host,
             port=self._parameters.port,
             factory=factory,
             contextFactory=_ssl_context_factory(self._parameters),
         )
     else:
         serv = TCPClient(
             host=self._parameters.host, port=self._parameters.port, factory=factory
         )
     serv.factory = factory
     name = "{}{}:{}".format(
         "ssl:" if self._parameters.ssl_options else "",
         self._parameters.host,
         self._parameters.port,
     )
     serv.setName(name)
     serv.setServiceParent(self)
Beispiel #10
0
 def connect(self):
     factory = self.factoryClass(self._parameters, self._bindings)
     if self._parameters.ssl_options:
         serv = SSLClient(
             host=self._parameters.host,
             port=self._parameters.port,
             factory=factory,
             contextFactory=ssl.ClientContextFactory(),
         )
     else:
         serv = TCPClient(
             host=self._parameters.host,
             port=self._parameters.port,
             factory=factory,
         )
     serv.factory = factory
     name = '{}{}:{}'.format(
         'ssl:' if self._parameters.ssl_options else '',
         self._parameters.host,
         self._parameters.port,
     )
     serv.setName(name)
     serv.setServiceParent(self)
Beispiel #11
0
    
    for host in factory.hosts:
        if (host.use_ssl):
            reactor.connectSSL(host.address, host.port, factory,
                               ssl.ClientContextFactory())
        else:
            reactor.connectTCP(host.address, host.port, factory)
    
    reactor.run()
else:
    from twisted.application.service import Application
    from twisted.application.internet import SSLClient, TCPClient
    from twisted.python.logfile import DailyLogFile
    from twisted.python.log import ILogObserver, FileLogObserver
    
    application = Application("BLFProxy")

    log_file = DailyLogFile("blfproxy.log", "/var/log")
    application.setComponent(ILogObserver, FileLogObserver(log_file).emit)
    
    factory = AMIClientFactory('/etc/blfproxy/blfproxy.conf')
    
    for host in factory.hosts:
        if (host.use_ssl):  
            service = SSLClient(host.address, host.port, factory,
                                ssl.ClientContextFactory())
            service.setServiceParent(application)
        else:
            service = TCPClient(host.address, host.port, factory)
            service.setServiceParent(application)