Ejemplo n.º 1
0
    def makeService(self, options):
        
        factory = bashplex.DelimitedBashReceiverFactory()
        factory.pingInterval=int(options['pingInterval'])
        factory.pingTimeout=int(options['pingTimeout'])
        factory.startupCommands = self.filterBash('/usr/share/epoptes/client-functions')

        if config.system['ENCRYPTION']:
            clientService = internet.SSLServer(int(config.system['PORT']),
                factory, ServerContextFactory())
        else:
            clientService = internet.TCPServer(int(config.system['PORT']),
                factory)

        gid = grp.getgrnam(config.system['SOCKET_GROUP'])[2]
        
        if not os.path.isdir(config.system['DIR']):
            #TODO: for some reason this does 0750 instead
            os.makedirs(config.system['DIR'], 02770)
        os.chmod(config.system['DIR'], 02770)
        os.chown(config.system['DIR'], -1, gid)

        guiService = internet.UNIXServer(
            "%s/epoptes.socket" % config.system['DIR'],
            guiplex.GUIFactory())

        topService = service.MultiService()
        topService.addService(clientService)
        topService.addService(guiService)

        return topService
    def makeService(self, options):
        config = yaml.load(open(options['config']))
        sockfp = filepath.FilePath("/run/docker/plugins/xylem.sock")
        if not sockfp.parent().exists():
            sockfp.parent().makedirs()

        return internet.UNIXServer(config.get('socket', sockfp.path),
                                   server.Site(service.DockerService(config)))
Ejemplo n.º 3
0
def setupControlSocket(configuration, director):
    """
    This is for the functionaity that Apple introduced in the patches from its
    Calendar Server project.
    """
    control = service.Service()
    socket = configuration.control.socket
    if socket != None:
        control = internet.UNIXServer(socket, manager.ControlFactory(director))
    control.setName('control')
    return control
Ejemplo n.º 4
0
 def testStoppingServer(self):
     factory = protocol.ServerFactory()
     factory.protocol = wire.Echo
     t = internet.UNIXServer("echo.skt", factory)
     t.startService()
     t.stopService()
     self.assertFalse(t.running)
     factory = protocol.ClientFactory()
     d = defer.Deferred()
     factory.clientConnectionFailed = lambda *args: d.callback(None)
     reactor.connectUNIX("echo.skt", factory)
     return d
Ejemplo n.º 5
0
 def testStoppingServer(self):
     if not interfaces.IReactorUNIX(reactor, None):
         raise unittest.SkipTest, "This reactor does not support UNIX domain sockets"
     factory = protocol.ServerFactory()
     factory.protocol = wire.Echo
     t = internet.UNIXServer('echo.skt', factory)
     t.startService()
     t.stopService()
     self.failIf(t.running)
     factory = protocol.ClientFactory()
     d = defer.Deferred()
     factory.clientConnectionFailed = lambda *args: d.callback(None)
     reactor.connectUNIX('echo.skt', factory)
     return d
Ejemplo n.º 6
0
 def testStoppingServer(self):
     if not interfaces.IReactorUNIX(reactor, None):
         raise unittest.SkipTest, "This reactor does not support UNIX domain sockets"
     factory = protocol.ServerFactory()
     factory.protocol = wire.Echo
     t = internet.UNIXServer('echo.skt', factory)
     t.startService()
     t.stopService()
     self.failIf(t.running)
     factory = protocol.ClientFactory()
     l = []
     factory.clientConnectionFailed = lambda *args: l.append(None)
     reactor.connectUNIX('echo.skt', factory)
     util.spinWhile(lambda: not l)
     self.assertEqual(l, [None])
Ejemplo n.º 7
0
def main():
    plugins_dir = FilePath("/run/docker/plugins/")
    if not plugins_dir.exists():
        plugins_dir.makedirs()

    dvol_path = FilePath("/var/lib/dvol/volumes")
    if not dvol_path.exists():
        dvol_path.makedirs()
    voluminous = Voluminous(dvol_path.path)

    sock = plugins_dir.child("%s.sock" % (VOLUME_DRIVER_NAME, ))
    if sock.exists():
        sock.remove()

    adapterServer = internet.UNIXServer(sock.path, getAdapter(voluminous))
    reactor.callWhenRunning(adapterServer.startService)
    reactor.run()
Ejemplo n.º 8
0
    def makeService(self, options):
        application = service.MultiService()

        logserver_factory = LogServerFactory(options["path"],
                                             int(options["size"]))

        tcp_news_server = internet.TCPServer(int(options["port"]),
                                             logserver_factory)
        tcp_news_server.setServiceParent(application)

        if os.path.exists(options["unix_socket"]):
            os.remove(options["unix_socket"])
        unix_news_server = internet.UNIXServer(options["unix_socket"],
                                               logserver_factory)
        unix_news_server.setServiceParent(application)

        return application
Ejemplo n.º 9
0
def makeService(config):
    s = service.MultiService()
    if config['root']:
        root = config['root']
        if config['indexes']:
            config['root'].indexNames = config['indexes']
    else:
        # This really ought to be web.Admin or something
        root = demo.Test()

    if isinstance(root, static.File):
        root.registry.setComponent(interfaces.IServiceCollection, s)

    if config['logfile']:
        site = server.Site(root, logPath=config['logfile'])
    else:
        site = server.Site(root)

    site.displayTracebacks = not config["notracebacks"]

    if config['personal']:
        import pwd, os

        pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell \
                 = pwd.getpwuid(os.getuid())
        i = internet.UNIXServer(
            os.path.join(pw_dir, distrib.UserDirectory.userSocketName),
            pb.BrokerFactory(distrib.ResourcePublisher(site)))
        i.setServiceParent(s)
    else:
        if config['https']:
            from twisted.internet.ssl import DefaultOpenSSLContextFactory
            i = internet.SSLServer(
                int(config['https']), site,
                DefaultOpenSSLContextFactory(config['privkey'],
                                             config['certificate']))
            i.setServiceParent(s)
        strports.service(config['port'], site).setServiceParent(s)

    flashport = config.get('flashconduit', None)
    if flashport:
        from twisted.web.woven.flashconduit import FlashConduitFactory
        i = internet.TCPServer(int(flashport), FlashConduitFactory(site))
        i.setServiceParent(s)
    return s
Ejemplo n.º 10
0
 def testUNIX(self):
     # FIXME: This test is far too dense.  It needs comments.
     #  -- spiv, 2004-11-07
     s = service.MultiService()
     s.startService()
     factory = protocol.ServerFactory()
     factory.protocol = TestEcho
     TestEcho.d = defer.Deferred()
     t = internet.UNIXServer("echo.skt", factory)
     t.setServiceParent(s)
     factory = protocol.ClientFactory()
     factory.protocol = Foo
     factory.d = defer.Deferred()
     factory.line = None
     internet.UNIXClient("echo.skt", factory).setServiceParent(s)
     factory.d.addCallback(self.assertEqual, b"lalala")
     factory.d.addCallback(lambda x: s.stopService())
     factory.d.addCallback(lambda x: TestEcho.d)
     factory.d.addCallback(self._cbTestUnix, factory, s)
     return factory.d
Ejemplo n.º 11
0
 def testUNIX(self):
     # FIXME: This test is far too dense.  It needs comments.
     #  -- spiv, 2004-11-07
     if not interfaces.IReactorUNIX(reactor, None):
         raise unittest.SkipTest, "This reactor does not support UNIX domain sockets"
     s = service.MultiService()
     s.startService()
     factory = protocol.ServerFactory()
     factory.protocol = TestEcho
     TestEcho.d = defer.Deferred()
     t = internet.UNIXServer('echo.skt', factory)
     t.setServiceParent(s)
     factory = protocol.ClientFactory()
     factory.protocol = Foo
     factory.d = defer.Deferred()
     factory.line = None
     internet.UNIXClient('echo.skt', factory).setServiceParent(s)
     factory.d.addCallback(self.assertEqual, 'lalala')
     factory.d.addCallback(lambda x: s.stopService())
     factory.d.addCallback(lambda x: TestEcho.d)
     factory.d.addCallback(self._cbTestUnix, factory, s)
     return factory.d
Ejemplo n.º 12
0
    def testVolatile(self):
        factory = protocol.ServerFactory()
        factory.protocol = wire.Echo
        t = internet.UNIXServer("echo.skt", factory)
        t.startService()
        self.failIfIdentical(t._port, None)
        t1 = copy.copy(t)
        self.assertIsNone(t1._port)
        t.stopService()
        self.assertIsNone(t._port)
        self.assertFalse(t.running)

        factory = protocol.ClientFactory()
        factory.protocol = wire.Echo
        t = internet.UNIXClient("echo.skt", factory)
        t.startService()
        self.failIfIdentical(t._connection, None)
        t1 = copy.copy(t)
        self.assertIsNone(t1._connection)
        t.stopService()
        self.assertIsNone(t._connection)
        self.assertFalse(t.running)
Ejemplo n.º 13
0
    def testUNIX(self):
        # FIXME: This test is far too dense.  It needs comments.
        #  -- spiv, 2004-11-07
        if not interfaces.IReactorUNIX(reactor, None):
            raise unittest.SkipTest, "This reactor does not support UNIX domain sockets"
        s = service.MultiService()
        s.startService()
        factory = protocol.ServerFactory()
        factory.protocol = TestEcho
        TestEcho.d = defer.Deferred()
        t = internet.UNIXServer('echo.skt', factory)
        t.setServiceParent(s)

        class Foo(basic.LineReceiver):
            def connectionMade(self):
                self.transport.write('lalala\r\n')

            def lineReceived(self, line):
                self.factory.line = line
                self.transport.loseConnection()

        factory = protocol.ClientFactory()
        factory.protocol = Foo
        factory.line = None
        internet.UNIXClient('echo.skt', factory).setServiceParent(s)
        util.spinWhile(lambda: factory.line is None)
        self.assertEqual(factory.line, 'lalala')
        util.wait(defer.maybeDeferred(s.stopService))
        util.wait(TestEcho.d)

        TestEcho.d = defer.Deferred()
        factory.line = None
        s.startService()
        util.spinWhile(lambda: factory.line is None)
        self.assertEqual(factory.line, 'lalala')

        # Cleanup the reactor
        util.wait(defer.maybeDeferred(s.stopService))
        util.wait(TestEcho.d)
Ejemplo n.º 14
0
    def makeService(self, options):
        application = service.MultiService()

        logserver_factory = LogServerFactory(options["path"],
                                             int(options["size"]))

        tcp_news_server = internet.TCPServer(int(options["port"]),
                                             logserver_factory)
        tcp_news_server.setServiceParent(application)

        if os.path.exists(options["unix_socket"]):
            os.remove(options["unix_socket"])
        unix_news_server = internet.UNIXServer(options["unix_socket"],
                                               logserver_factory)
        unix_news_server.setServiceParent(application)
        log.startLogging(sys.stdout)
        log.msg("Log Service started with parameters: port: {} path:{} "
                "size:{} unix_socket:{}".format(options.get("port"),
                                                options.get("port"),
                                                options.get("size"),
                                                options.get("unix_socket")))
        return application
Ejemplo n.º 15
0
    def startService(self):
        """
            Starts the service. It supports a unix socket and a tcp networking
            port. Configure it by setting tcpServer.modes in the config file:
            socket, tcp

            unix socket: You can set the path where the socket file is
            created by setting tcpServer.socket.path to a filesystem path
            writable by the bot user

            tcp networking: You can set the port of the port of the connection
            with tcpServer.tcp.port and the interface with
            tcpServer.tcp.interface. Default is that the port is only
            accessible from localhost.
        """
        modes = self.config.get("modes", ["socket"], "main.tcpServer")
        self.factory = tcpServerFactory(self.root, self)
        if "socket" in modes:
            path = self.config.get("socket.path", "otfbot.sock",
                                   "main.tcpServer")
            server = internet.UNIXServer(address=path, factory=self.factory)
            self.addService(server)
        if "tcp" in modes:
            port = int(self.config.get("tcp.port", "7001", "main.tcpServer"))
            interface = self.config.get("tcp.interface", "127.0.0.1",
                                        "main.tcpServer")
            server = internet.TCPServer(port=port,
                                        factory=self.factory,
                                        interface=interface)
            self.addService(server)
        if "tcp" in modes or "socket" in modes:
            try:
                service.MultiService.startService(self)
            except CannotListenError as e:
                self.logger.warning(e)
            except Exception as e:
                self.logger.error(repr(e))
                self.logger.error(e)
Ejemplo n.º 16
0
    def testVolatile(self):
        if not interfaces.IReactorUNIX(reactor, None):
            raise unittest.SkipTest, "This reactor does not support UNIX domain sockets"
        factory = protocol.ServerFactory()
        factory.protocol = wire.Echo
        t = internet.UNIXServer('echo.skt', factory)
        t.startService()
        self.failIfIdentical(t._port, None)
        t1 = copy.copy(t)
        self.assertIdentical(t1._port, None)
        t.stopService()
        self.assertIdentical(t._port, None)
        self.failIf(t.running)

        factory = protocol.ClientFactory()
        factory.protocol = wire.Echo
        t = internet.UNIXClient('echo.skt', factory)
        t.startService()
        self.failIfIdentical(t._connection, None)
        t1 = copy.copy(t)
        self.assertIdentical(t1._connection, None)
        t.stopService()
        self.assertIdentical(t._connection, None)
        self.failIf(t.running)
Ejemplo n.º 17
0
 def listenUNIX(self, filename, factory, backlog=50, mode=0666):
     s = internet.UNIXServer(filename, factory, backlog, mode)
     s.privileged = 1
     s.setServiceParent(self.app)
Ejemplo n.º 18
0
    def makeService(self, options):
        srv = service.MultiService()
        s = None

        if "app" in options and (options["app"] or "")[-3:].lower() == ".py":
            options["filename"] = options["app"]

        if "filename" in options and os.path.exists(options["filename"]):
            n = os.path.splitext(os.path.split(options["filename"])[-1])[0]
            appmod = imp.load_source(n, options["filename"])
            for name in dir(appmod):
                kls = getattr(appmod, name)
                if (inspect.isclass(kls)
                        and issubclass(kls, cyclone.web.Application)):
                    options["app"] = kls
                    if ssl_support and os.path.exists(options["ssl-cert"]):
                        options["ssl-app"] = kls

        # http
        if options["app"]:
            if callable(options["app"]):
                appmod = options["app"]
            else:
                appmod = reflect.namedAny(options["app"])

            if options["appopts"]:
                app = appmod(options["appopts"])
            else:
                app = appmod()

            unix = options.get("unix")
            if unix:
                s = internet.UNIXServer(unix, app)
            else:
                s = internet.TCPServer(options["port"],
                                       app,
                                       interface=options["listen"])
            s.setServiceParent(srv)

        # https
        if options["ssl-app"]:
            if ssl_support:
                if callable(options["ssl-app"]):
                    appmod = options["ssl-app"]
                else:
                    appmod = reflect.namedAny(options["ssl-app"])

                if options["ssl-appopts"]:
                    app = appmod(options["ssl-appopts"])
                else:
                    app = appmod()
                s = internet.SSLServer(options["ssl-port"],
                                       app,
                                       ssl.DefaultOpenSSLContextFactory(
                                           options["ssl-key"],
                                           options["ssl-cert"]),
                                       interface=options["ssl-listen"])
                s.setServiceParent(srv)
            else:
                print("SSL support is disabled. "
                      "Install PyOpenSSL and try again.")

        if s is None:
            print("usage: cyclone run [server.py|--help]")
            sys.exit(1)

        return srv