Exemplo n.º 1
0
def makeService(configuration):
    settings = Config([''])
    settings.load(configuration)
    if not settings.header:
        sys.exit(1)

    #
    # Setup Logging
    #
    root_logger = reflogging.RootLogger()
    root_logger.set_app_name('network')
    # accuire root log_level
    log_level = settings.headerGetInt('/server/logging/@log_level') or 30
    if 'LOG_LEVEL' in os.environ:
        log_level = int(os.environ['LOG_LEVEL'])
    if log_level not in (10, 20, 30, 40, 50):
        raise ValueError(
            "Unsupported log level %d. Supported log levels "
            "are DEBUG(10), INFO(20), WARNING(30), ERROR(40), CRITICAL(50)." % (log_level,)
        )
    root_logger.set_level(log_level)
    for node in settings.header.xpathEval('/server/logging/*'):
        _name = node.name
        _log_level_node = node.xpathEval('@log_level')
        _log_level = int(_log_level_node[0].content) if _log_level_node else 30
        if _name in ('stream', 'colorstream'):
            _output_node = node.xpathEval('@output')
            _output = _output_node[0].content if _output_node else 'stdout'
            if _output in ('stdout', '-'):
                _output = orig_stdout
            elif _output == 'stderr':
                _output = orig_stderr
            else:
                if _output.startswith('-'):
                    _output = open(_output[1:], 'w')
                else:
                    _output = open(_output, 'a')
            if _name == 'stream':
                _handler = StreamHandler(_output)
            elif _name == 'colorstream':
                _handler = ColorStreamHandler(_output)
        if _name == 'gelf':
            _host_node = node.xpathEval('@host')
            _port_node = node.xpathEval('@port')
            _host = _host_node[0].content if _host_node else 'localhost'
            _port = _port_node[0].content if _port_node else 12201
            _handler = GELFHandler(_host, _port)
        if _name == 'syslog':
            _handler = SyslogHandler('pokernetwork', 0)
        _handler.set_level(_log_level)
        root_logger.add_handler(_handler)

    serviceCollection = service.MultiService()
    poker_service = PokerService(settings)
    poker_service.setServiceParent(serviceCollection)

    poker_factory = IPokerFactory(poker_service)

    #
    # Poker protocol (with or without SSL)
    #
    tcp_port = settings.headerGetInt("/server/listen/@tcp")
    internet.TCPServer(tcp_port, poker_factory).setServiceParent(serviceCollection)

    tcp_ssl_port = settings.headerGetInt("/server/listen/@tcp_ssl")
    if HAS_OPENSSL and tcp_ssl_port:
        internet.SSLServer(tcp_ssl_port, poker_factory, SSLContextFactory(settings)).setServiceParent(serviceCollection)

    rest_site = PokerSite(settings, PokerRestTree(poker_service))

    #
    # HTTP (with or without SLL) that implements REST
    #
    rest_port = settings.headerGetInt("/server/listen/@rest")
    if rest_port:
        internet.TCPServer(rest_port, rest_site).setServiceParent(serviceCollection)

    rest_ssl_port = settings.headerGetInt("/server/listen/@rest_ssl")
    if HAS_OPENSSL and rest_ssl_port:
        internet.SSLServer(rest_ssl_port, rest_site, SSLContextFactory(settings)).setServiceParent(serviceCollection)

    http_site = server.Site(PokerTree(poker_service))

    #
    # HTTP (with or without SLL) that implements XML-RPC and SOAP
    #
    http_port = settings.headerGetInt("/server/listen/@http")
    if http_port:
        internet.TCPServer(http_port, http_site).setServiceParent(serviceCollection)

    http_ssl_port = settings.headerGetInt("/server/listen/@http_ssl")
    if HAS_OPENSSL and http_ssl_port:
        internet.SSLServer(http_ssl_port, http_site, SSLContextFactory(settings)).setServiceParent(serviceCollection)

    #
    # SSh twisted.conch.manhole
    #
    manhole_port = settings.headerGetInt("/server/listen/@manhole")
    if manhole_port:
        manhole_service = makeManholeService(manhole_port, {
            'poker_service': poker_service,
            'poker_site': rest_site
        })
        manhole_service.name = 'manhole'
        manhole_service.setServiceParent(serviceCollection)
        log.warn(
            "PokerManhole: manhole is useful for debugging, however, "
            "it can be a security risk and should be used only during debugging"
        )

    return serviceCollection
Exemplo n.º 2
0
def makeService(configuration):
    settings = Config([''])
    settings.load(configuration)
    if not settings.header:
        sys.exit(1)

    serviceCollection = service.MultiService()
    poker_service = PokerService(settings)
    poker_service.setServiceParent(serviceCollection)

    poker_factory = IPokerFactory(poker_service)

    #
    # Poker protocol (with or without SSL)
    #
    tcp_port = settings.headerGetInt("/server/listen/@tcp")
    internet.TCPServer(tcp_port,
                       poker_factory).setServiceParent(serviceCollection)

    tcp_ssl_port = settings.headerGetInt("/server/listen/@tcp_ssl")
    if HAS_OPENSSL and tcp_ssl_port:
        internet.SSLServer(
            tcp_ssl_port, poker_factory,
            SSLContextFactory(settings)).setServiceParent(serviceCollection)

    rest_site = PokerSite(settings, PokerRestTree(poker_service))

    #
    # HTTP (with or without SLL) that implements REST
    #
    rest_port = settings.headerGetInt("/server/listen/@rest")
    if rest_port:
        internet.TCPServer(rest_port,
                           rest_site).setServiceParent(serviceCollection)

    rest_ssl_port = settings.headerGetInt("/server/listen/@rest_ssl")
    if HAS_OPENSSL and rest_ssl_port:
        internet.SSLServer(
            rest_ssl_port, rest_site,
            SSLContextFactory(settings)).setServiceParent(serviceCollection)

    http_site = server.Site(PokerTree(poker_service))

    #
    # HTTP (with or without SLL) that implements XML-RPC and SOAP
    #
    http_port = settings.headerGetInt("/server/listen/@http")
    if http_port:
        internet.TCPServer(http_port,
                           http_site).setServiceParent(serviceCollection)

    http_ssl_port = settings.headerGetInt("/server/listen/@http_ssl")
    if HAS_OPENSSL and http_ssl_port:
        internet.SSLServer(
            http_ssl_port, http_site,
            SSLContextFactory(settings)).setServiceParent(serviceCollection)

    #
    # TELNET twisted.manhole (without SSL)
    #
    manhole_port = settings.headerGetInt("/server/listen/@manhole")
    if manhole_port:
        manhole_factory = telnet.ShellFactory()
        manhole_factory.namespace['poker_service'] = poker_service
        manhole_factory.namespace['poker_site'] = rest_site
        manhole_service = internet.TCPServer(manhole_port,
                                             manhole_factory,
                                             interface='127.0.0.1')
        manhole_service.setName("manhole")
        manhole_service.setServiceParent(serviceCollection)
        if settings.headerGetInt("/server/@verbose") > 0:
            print "PokerManhole: manhole is useful for debugging, use with telnet admin/admin, however, it can be a security risk and should be used only during debugging"

    return serviceCollection
Exemplo n.º 3
0
def makeService(configuration):
    settings = Config([''])
    settings.load(configuration)
    if not settings.header:
        sys.exit(1)

    serviceCollection = service.MultiService()

    poker_database = pokerdatabase.PokerDatabase(settings)
    poker_service = PokerService(settings, poker_database)
    poker_service.setServiceParent(serviceCollection)

    poker_factory = IPokerFactory(poker_service)

    #
    # Poker protocol (with or without SSL)
    #
    tcp_port = settings.headerGetInt("/server/listen/@tcp")
    internet.TCPServer(tcp_port, poker_factory
                       ).setServiceParent(serviceCollection)

    tcp_ssl_port = settings.headerGetInt("/server/listen/@tcp_ssl")
    if HAS_OPENSSL and tcp_ssl_port:
            internet.SSLServer(tcp_ssl_port, poker_factory, SSLContextFactory(settings)
                           ).setServiceParent(serviceCollection)

    rest_site = PokerSite(settings, PokerRestTree(poker_service))

    #
    # HTTP (with or without SLL) that implements REST
    #
    rest_port = settings.headerGetInt("/server/listen/@rest")
    if rest_port:
            internet.TCPServer(rest_port, rest_site
                               ).setServiceParent(serviceCollection)

    rest_ssl_port = settings.headerGetInt("/server/listen/@rest_ssl")
    if HAS_OPENSSL and rest_ssl_port:
            internet.SSLServer(rest_ssl_port, rest_site, SSLContextFactory(settings)
                               ).setServiceParent(serviceCollection)

    http_site = server.Site(PokerTree(poker_service))

    #
    # HTTP (with or without SLL) that implements XML-RPC and SOAP
    #
    http_port = settings.headerGetInt("/server/listen/@http")
    if http_port:
            internet.TCPServer(http_port, http_site
                               ).setServiceParent(serviceCollection)

    http_ssl_port = settings.headerGetInt("/server/listen/@http_ssl")
    if HAS_OPENSSL and http_ssl_port:
            internet.SSLServer(http_ssl_port, http_site, SSLContextFactory(settings)
                               ).setServiceParent(serviceCollection)

    # API
    api_ssl_port = settings.headerGetInt("/server/listen/@api_ssl")
    if HAS_OPENSSL and api_ssl_port:
        from pokernetwork import apiserver, apiservice
        secret_store = apiserver.APIUserStore(poker_database)
        api_service = apiservice.APIService(poker_service)
        api_site = server.Site(apiserver.Root(api_service, secret_store))
        internet.SSLServer(api_ssl_port, api_site, SSLContextFactory(settings)
                          ).setServiceParent(serviceCollection)
    else:
        print 'Could not create API service!'

    #
    # TELNET twisted.manhole (without SSL)
    #
    manhole_port = settings.headerGetInt("/server/listen/@manhole")
    if manhole_port:
	    manhole_factory = telnet.ShellFactory()
	    manhole_factory.namespace['poker_service'] = poker_service
	    manhole_factory.namespace['poker_site'] = rest_site
	    manhole_service = internet.TCPServer(manhole_port, manhole_factory, interface = '127.0.0.1')
	    manhole_service.setName("manhole")
	    manhole_service.setServiceParent(serviceCollection)
	    if settings.headerGetInt("/server/@verbose") > 0:
		    print  "PokerManhole: manhole is useful for debugging, use with telnet admin/admin, however, it can be a security risk and should be used only during debugging"

    return serviceCollection
Exemplo n.º 4
0
def makeService(configuration):
    settings = Config([''])
    settings.load(configuration)
    if not settings.header:
        sys.exit(1)

    #
    # Setup Logging
    #
    root_logger = reflogging.RootLogger()
    root_logger.set_app_name('network')
    # accuire root log_level
    log_level = settings.headerGetInt('/server/logging/@log_level') or 30
    if 'LOG_LEVEL' in os.environ:
        log_level = int(os.environ['LOG_LEVEL'])
    if log_level not in (10, 20, 30, 40, 50):
        raise ValueError(
            "Unsupported log level %d. Supported log levels "
            "are DEBUG(10), INFO(20), WARNING(30), ERROR(40), CRITICAL(50)." %
            (log_level, ))
    root_logger.set_level(log_level)
    for node in settings.header.xpathEval('/server/logging/*'):
        _name = node.name
        _log_level_node = node.xpathEval('@log_level')
        _log_level = int(_log_level_node[0].content) if _log_level_node else 30
        if _name in ('stream', 'colorstream'):
            _output_node = node.xpathEval('@output')
            _output = _output_node[0].content if _output_node else 'stdout'
            if _output in ('stdout', '-'):
                _output = orig_stdout
            elif _output == 'stderr':
                _output = orig_stderr
            else:
                if _output.startswith('-'):
                    _output = open(_output[1:], 'w')
                else:
                    _output = open(_output, 'a')
            if _name == 'stream':
                _handler = StreamHandler(_output)
            elif _name == 'colorstream':
                _handler = ColorStreamHandler(_output)
        if _name == 'gelf':
            _host_node = node.xpathEval('@host')
            _port_node = node.xpathEval('@port')
            _host = _host_node[0].content if _host_node else 'localhost'
            _port = _port_node[0].content if _port_node else 12201
            _handler = GELFHandler(_host, _port)
        if _name == 'syslog':
            _handler = SyslogHandler('pokernetwork', 0)
        _handler.set_level(_log_level)
        root_logger.add_handler(_handler)

    serviceCollection = service.MultiService()
    poker_service = PokerService(settings)
    poker_service.setServiceParent(serviceCollection)

    poker_factory = IPokerFactory(poker_service)

    #
    # Poker protocol (with or without SSL)
    #
    tcp_port = settings.headerGetInt("/server/listen/@tcp")
    internet.TCPServer(tcp_port,
                       poker_factory).setServiceParent(serviceCollection)

    tcp_ssl_port = settings.headerGetInt("/server/listen/@tcp_ssl")
    if HAS_OPENSSL and tcp_ssl_port:
        internet.SSLServer(
            tcp_ssl_port, poker_factory,
            SSLContextFactory(settings)).setServiceParent(serviceCollection)

    rest_site = PokerSite(settings, PokerRestTree(poker_service))

    #
    # HTTP (with or without SLL) that implements REST
    #
    rest_port = settings.headerGetInt("/server/listen/@rest")
    if rest_port:
        internet.TCPServer(rest_port,
                           rest_site).setServiceParent(serviceCollection)

    rest_ssl_port = settings.headerGetInt("/server/listen/@rest_ssl")
    if HAS_OPENSSL and rest_ssl_port:
        internet.SSLServer(
            rest_ssl_port, rest_site,
            SSLContextFactory(settings)).setServiceParent(serviceCollection)

    http_site = server.Site(PokerTree(poker_service))

    #
    # HTTP (with or without SLL) that implements XML-RPC and SOAP
    #
    http_port = settings.headerGetInt("/server/listen/@http")
    if http_port:
        internet.TCPServer(http_port,
                           http_site).setServiceParent(serviceCollection)

    http_ssl_port = settings.headerGetInt("/server/listen/@http_ssl")
    if HAS_OPENSSL and http_ssl_port:
        internet.SSLServer(
            http_ssl_port, http_site,
            SSLContextFactory(settings)).setServiceParent(serviceCollection)

    #
    # SSh twisted.conch.manhole
    #
    manhole_port = settings.headerGetInt("/server/listen/@manhole")
    if manhole_port:
        manhole_service = makeManholeService(manhole_port, {
            'poker_service': poker_service,
            'poker_site': rest_site
        })
        manhole_service.name = 'manhole'
        manhole_service.setServiceParent(serviceCollection)
        log.warn(
            "PokerManhole: manhole is useful for debugging, however, "
            "it can be a security risk and should be used only during debugging"
        )

    return serviceCollection
Exemplo n.º 5
0
def makeService(configuration):
    settings = Config([''])
    settings.load(configuration)
    if not settings.header:
        sys.exit(1)

    #
    # Setup Logging
    #
    root_logger = reflogging.RootLogger()
    root_logger.set_app_name('network')
    # acquire root log_level
    log_level = settings.headerGetInt('/server/logging/@log_level') or 30
    if 'LOG_LEVEL' in os.environ:
        log_level = int(os.environ['LOG_LEVEL'])
    if log_level not in (10, 20, 30, 40, 50):
        raise ValueError(
            "Unsupported log level %d. Supported log levels "
            "are DEBUG(10), INFO(20), WARNING(30), ERROR(40), CRITICAL(50)." % (log_level,)
        )
    root_logger.set_level(log_level)
    for node in settings.header.xpathEval('/server/logging/*'):
        _name = node.name
        _log_level_node = node.xpathEval('@log_level')
        _log_level = int(_log_level_node[0].content) if _log_level_node else 30
        if _name in ('stream', 'colorstream'):
            _output_node = node.xpathEval('@output')
            _output = _output_node[0].content if _output_node else 'stdout'
            if _output in ('stdout', '-'):
                _output = orig_stdout
            elif _output == 'stderr':
                _output = orig_stderr
            else:
                if _output.startswith('-'):
                    _output = open(_output[1:], 'w')
                else:
                    _output = open(_output, 'a')
            if _name == 'stream':
                _handler = StreamHandler(_output)
            elif _name == 'colorstream':
                _handler = ColorStreamHandler(_output)
        if _name == 'gelf':
            _host_node = node.xpathEval('@host')
            _port_node = node.xpathEval('@port')
            _host = _host_node[0].content if _host_node else 'localhost'
            _port = _port_node[0].content if _port_node else 12201
            _handler = GELFHandler(_host, _port)
        if _name == 'syslog':
            f = node.xpathEval('@facility')
            facility = {
                'user': syslog.LOG_USER,
                'daemon': syslog.LOG_DAEMON,
                'cron': syslog.LOG_CRON,
                'local0': syslog.LOG_LOCAL0,
                'local1': syslog.LOG_LOCAL1,
                'local2': syslog.LOG_LOCAL2,
                'local3': syslog.LOG_LOCAL3,
                'local4': syslog.LOG_LOCAL4,
                'local5': syslog.LOG_LOCAL5,
                'local6': syslog.LOG_LOCAL6,
                'local7': syslog.LOG_LOCAL7,
            }[f[0].content if f else 'user']
            _handler = SyslogHandler('pokernetwork', 0, facility=facility)
        _handler.set_level(_log_level)
        root_logger.add_handler(_handler)

    serviceCollection = service.MultiService()
    poker_service = PokerService(settings)
    poker_service.setServiceParent(serviceCollection)


    #
    # Poker protocol (with or without SSL)
    #
    poker_factory = IPokerFactory(poker_service)
    tcp_port = settings.headerGetInt("/server/listen/@tcp")
    internet.TCPServer(tcp_port, poker_factory).setServiceParent(serviceCollection)

    tcp_ssl_port = settings.headerGetInt("/server/listen/@tcp_ssl")
    if HAS_OPENSSL and tcp_ssl_port:
        internet.SSLServer(tcp_ssl_port, poker_factory, SSLContextFactory(settings)).setServiceParent(serviceCollection)

    #
    # msgpack protocol
    #
    msgpack_port = settings.headerGetInt("/server/listen/@msgpack")
    if msgpack_port:
        msgpack_factory = IPokerFactory(poker_service)
        msgpack_factory.setProtocol(ServerMsgpackProtocol)
        internet.TCPServer(msgpack_port, msgpack_factory).setServiceParent(serviceCollection)

    #
    # HTTP (with or without SLL) that implements REST
    #
    rest_site = PokerSite(settings, PokerRestTree(poker_service))
    rest_port = settings.headerGetInt("/server/listen/@rest")
    if rest_port:
        internet.TCPServer(rest_port, rest_site).setServiceParent(serviceCollection)

    rest_ssl_port = settings.headerGetInt("/server/listen/@rest_ssl")
    if HAS_OPENSSL and rest_ssl_port:
        internet.SSLServer(rest_ssl_port, rest_site, SSLContextFactory(settings)).setServiceParent(serviceCollection)

    #
    # SSh twisted.conch.manhole
    #
    manhole_port = settings.headerGetInt("/server/listen/@manhole")
    if manhole_port:
        manhole_service = makeManholeService(manhole_port, {
            'poker_service': poker_service,
            'poker_site': rest_site
        })
        manhole_service.name = 'manhole'
        manhole_service.setServiceParent(serviceCollection)

    #
    # Pub/Sub
    #
    pub_port = settings.headerGetInt("/server/listen/@pub")
    if pub_port:
        pub_service = internet.TCPServer(pub_port, PubService(poker_service))
        pub_service.name = 'pub'
        pub_service.setServiceParent(serviceCollection)

    return serviceCollection
Exemplo n.º 6
0
 def tourneyRemovePlayer(self, tourney, serial, now=False):
     return PokerService.tourneyRemovePlayer(self, tourney, serial, now=now)
Exemplo n.º 7
0
 def tourneyNewState(self, tourney, old_state, new_state):
     return PokerService.tourneyNewState(self, tourney, old_state,
                                         new_state)
Exemplo n.º 8
0
 def tourneyMovePlayer(self, tourney, from_game_id, to_game_id, serial):
     return PokerService.tourneyMovePlayer(self, tourney, from_game_id,
                                           to_game_id, serial)
Exemplo n.º 9
0
 def tourneyNewState(self, tourney, old_state, new_state):
     return PokerService.tourneyNewState(self, tourney, old_state, new_state)
Exemplo n.º 10
0
 def tourneyRemovePlayer(self, tourney, serial, now=False):
     return PokerService.tourneyRemovePlayer(self, tourney, serial, now=now)
Exemplo n.º 11
0
 def tourneyMovePlayer(self, tourney, from_game_id, to_game_id, serial):
     return PokerService.tourneyMovePlayer(self, tourney, from_game_id, to_game_id, serial)
Exemplo n.º 12
0
def makeService(configuration):
    settings = Config([''])
    settings.load(configuration)
    if not settings.header:
        sys.exit(1)

    serviceCollection = service.MultiService()
    poker_service = PokerService(settings)
    poker_service.setServiceParent(serviceCollection)

    poker_factory = IPokerFactory(poker_service)

    #
    # Setup Logging
    #
    log_level = int(os.environ['LOG_LEVEL']) if \
        'LOG_LEVEL' in os.environ else \
        settings.headerGetInt("/server/@log_level")
    logger = logging.getLogger()
    handler = TwistedHandler(twisted_log.theLogPublisher)
    handler.setFormatter(SingleLineFormatter('[%(refs)s] %(message)s'))
    logger.addHandler(handler)
    if log_level:
        if log_level not in (10, 20, 30, 40, 50):
            raise ValueError("Unsupported log level %d. Supported log levels "
                "are DEBUG(10), INFO(20), WARNING(30), ERROR(40), CRITICAL(50)." % (log_level,)
            )
        logger.setLevel(log_level)
    else:
        logger.setLevel(logging.WARNING)

    #
    # Poker protocol (with or without SSL)
    #
    tcp_port = settings.headerGetInt("/server/listen/@tcp")
    internet.TCPServer(tcp_port, poker_factory).setServiceParent(serviceCollection)

    tcp_ssl_port = settings.headerGetInt("/server/listen/@tcp_ssl")
    if HAS_OPENSSL and tcp_ssl_port:
        internet.SSLServer(tcp_ssl_port, poker_factory, SSLContextFactory(settings)).setServiceParent(serviceCollection)

    rest_site = PokerSite(settings, PokerRestTree(poker_service))

    #
    # HTTP (with or without SLL) that implements REST
    #
    rest_port = settings.headerGetInt("/server/listen/@rest")
    if rest_port:
        internet.TCPServer(rest_port, rest_site).setServiceParent(serviceCollection)

    rest_ssl_port = settings.headerGetInt("/server/listen/@rest_ssl")
    if HAS_OPENSSL and rest_ssl_port:
        internet.SSLServer(rest_ssl_port, rest_site, SSLContextFactory(settings)).setServiceParent(serviceCollection)

    http_site = server.Site(PokerTree(poker_service))

    #
    # HTTP (with or without SLL) that implements XML-RPC and SOAP
    #
    http_port = settings.headerGetInt("/server/listen/@http")
    if http_port:
        internet.TCPServer(http_port, http_site).setServiceParent(serviceCollection)

    http_ssl_port = settings.headerGetInt("/server/listen/@http_ssl")
    if HAS_OPENSSL and http_ssl_port:
        internet.SSLServer(http_ssl_port, http_site, SSLContextFactory(settings)).setServiceParent(serviceCollection)

    #
    # SSh twisted.conch.manhole
    #
    manhole_port = settings.headerGetInt("/server/listen/@manhole")
    if manhole_port:
        makeManholeService(
            manhole_port,
            {
                'poker_service': poker_service,
                'poker_site': rest_site
            }
        ).setServiceParent(serviceCollection)
        log.warn("PokerManhole: manhole is useful for debugging, however, "
            "it can be a security risk and should be used only during debugging")

    return serviceCollection