예제 #1
0
    def run_remote_client(cls,t=TRAN,h=HOST,p=PORT):

        #start_system_logging()
                
        factory = pb.PBClientFactory()

        client_protocol = cls()
        client_connection_string = 'tcp:host={h}:port={p}'.format(h=h,p=p)    
        
        client_protocol.log("Creating Client Endpoint: {}".format(client_connection_string))
        enpt = endpoints.clientFromString(reactor,client_connection_string)
        
        def do_connection(broker): 
            d = factory.getRootObject()
            d.addCallback(client_protocol.connect)
            d.addErrback(lambda e: print(e))        

            client_protocol.log("Got Client: {}".format( client_protocol ))
        
        reconnectingService = appnet.ClientService( enpt, factory)
        onConnected = reconnectingService.whenConnected()
        onConnected.addCallback(do_connection)

        client_protocol.log("Starting Client")
        reconnectingService.startService()       
예제 #2
0
 def __attrs_post_init__(self):
     self._trace = None
     self._ws = None
     f = WSFactory(self, self._url)
     f.setProtocolOptions(autoPingInterval=60, autoPingTimeout=600)
     p = urlparse(self._url)
     ep = self._make_endpoint(p.hostname, p.port or 80)
     # TODO: change/wrap ClientService to fail if the first attempt fails
     self._connector = internet.ClientService(ep, f)
     self._debug_record_inbound_f = None
예제 #3
0
    def __attrs_post_init__(self):
        self._have_made_a_successful_connection = False
        self._stopping = False

        self._trace = None
        self._ws = None
        f = WSFactory(self, self._url)
        f.setProtocolOptions(autoPingInterval=60, autoPingTimeout=600)
        p = urlparse(self._url)
        ep = self._make_endpoint(p.hostname, p.port or 80)
        self._connector = internet.ClientService(ep, f)
        faf = None if self._have_made_a_successful_connection else 1
        d = self._connector.whenConnected(failAfterFailures=faf)
        # if the initial connection fails, signal an error and shut down. do
        # this in a different reactor turn to avoid some hazards
        d.addBoth(lambda res: task.deferLater(self._reactor, 0.0, lambda: res))
        d.addErrback(self._initial_connection_failed)
        self._debug_record_inbound_f = None
예제 #4
0
def makeService(config):
    # finger on port 79
    s = service.MultiService()
    f = FingerService(config["file"])
    h = strports.service("tcp:1079", IFingerFactory(f))
    h.setServiceParent(s)

    # website on port 8000
    r = resource.IResource(f)
    r.templateDirectory = config["templates"]
    site = server.Site(r)
    j = strports.service("tcp:8000", site)
    j.setServiceParent(s)

    # ssl on port 443
    #    if config.get('ssl'):
    #        k = strports.service(
    #            "ssl:port=443:certKey=cert.pem:privateKey=key.pem", site
    #        )
    #        k.setServiceParent(s)

    # irc fingerbot
    if "ircnick" in config:
        i = IIRCClientFactory(f)
        i.nickname = config["ircnick"]
        ircserver = config["ircserver"]
        b = internet.ClientService(
            endpoints.HostnameEndpoint(reactor, ircserver, 6667), i)
        b.setServiceParent(s)

    # Pespective Broker on port 8889
    if "pbport" in config:
        m = internet.StreamServerEndpointService(
            endpoints.TCP4ServerEndpoint(reactor, int(config["pbport"])),
            pb.PBServerFactory(IPerspectiveFinger(f)),
        )
        m.setServiceParent(s)

    return s
예제 #5
0
def makeService(options):
    parts = urlsplit(options["backend"])
    host = parts.hostname
    path = parts.path.encode("utf-8")

    if parts.scheme == "http":
        port = int(parts.port) if parts.port is not None else 80
        backend_strports = f"tcp:{host}:{port}"
    else:
        port = int(parts.port) if parts.port is not None else 443
        backend_strports = f"ssl:{host}:{port}"

    hostport = (f"{host}:{port}" if parts.port else f"{host}").encode("ascii")

    s = service.MultiService()

    ext = internet.ClientService(
        endpoints.clientFromString(reactor, "exiftool"),
        ExiftoolProtocolFactory.forProtocol(ExiftoolProtocol, 2**22)
    )
    ext.setServiceParent(s)

    backend = endpoints.clientFromString(reactor, backend_strports)
    root = resource.Resource()
    root.putChild(b"json", ExiftoolJSONMetadataReverseProxyResource(
        ext, backend, hostport, path))
    root.putChild(b"xmp", ExiftoolXMPMetadataReverseProxyResource(
        ext, backend, hostport, path))
    root.putChild(b"preview", ExiftoolPreviewReverseProxyResource(
        ext, backend, hostport, path))
    root.putChild(b"pageimage", ExiftoolPageimagesReverseProxyResource(
        ext, backend, hostport, path))
    srv = strports.service(options["listen"], server.Site(root))
    srv.setServiceParent(s)

    return s
예제 #6
0
        return defer.succeed(self.users.keys())

    def startService(self):
        self._read()
        service.Service.startService(self)

    def stopService(self):
        service.Service.stopService(self)
        self.call.cancel()



application = service.Application('finger', uid=1, gid=1)
f = FingerService('/etc/users')
serviceCollection = service.IServiceCollection(application)
f.setServiceParent(serviceCollection)
strports.service("tcp:79", IFingerFactory(f)
                   ).setServiceParent(serviceCollection)
site = server.Site(resource.IResource(f))
strports.service("tcp:8000", site,
                   ).setServiceParent(serviceCollection)
strports.service("ssl:port=443:certKey=cert.pem:privateKey=key.pem", site
                   ).setServiceParent(serviceCollection)
i = IIRCClientFactory(f)
i.nickname = 'fingerbot'
internet.ClientService(
    endpoints.clientFromString(reactor, "tcp:irc.freenode.org:6667"),
    i).setServiceParent(serviceCollection)
strports.service("tcp:8889", pb.PBServerFactory(IPerspectiveFinger(f))
                   ).setServiceParent(serviceCollection)
예제 #7
0
    def __init__(self):
        service.MultiService.__init__(self)
        self.email_producer = None
        self.irc_producer = None
        self.irc_client = None

        # Map queue names to service instances
        self._queues = {}
        self._irc_queues = {}
        self._email_queues = {}
        self._irc_services = []
        self._email_services = []

        db.initialize(config.conf)

        if config.conf["IRC_ENABLED"]:
            queues, bindings = self.get_queues(db.DeliveryType.irc)
            consumers = {q["queue"]: self._dispatch_irc for q in queues}
            producer = FedoraMessagingService(
                queues=queues, bindings=bindings, consumers=consumers)
            producer.setName("irc-{}".format(len(self._irc_services)))
            self._irc_services.append(producer)
            for queue in queues:
                self._queues[queue["queue"]] = producer
            self.addService(producer)

        if config.conf["EMAIL_ENABLED"]:
            queues, bindings = self.get_queues(db.DeliveryType.email)
            consumers = {q["queue"]: mail.deliver for q in queues}
            producer = FedoraMessagingService(
                queues=queues, bindings=bindings, consumers=consumers)
            producer.setName("email-{}".format(len(self._email_services)))
            self._email_services.append(producer)
            for queue in queues:
                self._queues[queue["queue"]] = producer
            self.addService(producer)

        amqp_endpoint = endpoints.clientFromString(
            reactor, 'tcp:localhost:5672'
        )
        params = pika.URLParameters('amqp://')
        control_queue = {
            "queue": "fedora-notifications-control-queue",
            "durable": True,
        }
        factory = FedoraMessagingFactory(
            params,
            queues=[control_queue],
        )
        factory.consume(self._manage_service, control_queue["queue"])
        self.amqp_service = internet.ClientService(amqp_endpoint, factory)
        self.addService(self.amqp_service)
        # TODO set up a listener for messages about new queues.
        # Then we need an API to poke a message service to start a new subscription
        # or stop an existing one.

        if self._irc_services:
            irc_endpoint = endpoints.clientFromString(
                reactor, config.conf["IRC_ENDPOINT"]
            )
            irc_factory = protocol.Factory.forProtocol(irc.IrcProtocol)
            self.irc_client = internet.ClientService(irc_endpoint, irc_factory)
            self.addService(self.irc_client)
예제 #8
0
    def getIRCBot(self, nickname):
        f = protocol.ClientFactory()
        f.protocol = IRCReplyBot
        f.nickname = nickname
        f.getUser = self.getUser
        return f

    def startService(self):
        self._read()
        service.Service.startService(self)

    def stopService(self):
        service.Service.stopService(self)
        self.call.cancel()


application = service.Application('finger', uid=1, gid=1)
f = FingerService('c:/work/users.txt')

serviceCollection = service.IServiceCollection(application)

f.setServiceParent(serviceCollection)

strports.service("tcp:79",
                 f.getFingerFactory()).setServiceParent(serviceCollection)
strports.service("tcp:8000", server.Site(
    f.getResource())).setServiceParent(serviceCollection)
internet.ClientService(
    endpoints.clientFromString(reactor, "tcp:irc.freenode.org:6667"),
    f.getIRCBot('fingerbot997')).setServiceParent(serviceCollection)