예제 #1
0
파일: launch.py 프로젝트: Mrkebubun/sputnik
def main(pm):
    from sputnik.webserver.router.twisted.wamp import RouterFactory
    router_factory = RouterFactory()
    router_factory.router = SputnikRouter

    router_factory.authz_plugins = \
            pm.services.get("sputnik.webserver.plugins.authz", [])
    router_factory.schema_plugins = \
            pm.services.get("sputnik.webserver.plugins.schema", [])

    from sputnik.webserver.router.twisted.wamp import RouterSessionFactory
    session_factory = RouterSessionFactory(router_factory)
    session_factory.session = SputnikRouterSession

    authn_stack = [("ip.IPFilter", "requisite"),
                   ("anonymous.AnonymousLogin", "sufficient"),
                   ("cookie.CookieLogin", "sufficient"),
                   ("wampcra.WAMPCRALogin", "requisite"),
                   ("totp.TOTPVerification", "requisite")]
    session_factory.plugins = []
    for plugin_name, flag in authn_stack:
        path = "sputnik.webserver.plugins.authn." + plugin_name
        session_factory.plugins.append((pm.plugins[path], flag))

    rpc_plugins = pm.services.get("sputnik.webserver.plugins.rpc", [])
    feeds_plugins = pm.services.get("sputnik.webserver.plugins.feeds", [])
    svc_plugins = rpc_plugins + feeds_plugins
    for plugin in svc_plugins:
        component_session = plugin
        component_session.config.realm = u"sputnik"
        session_factory.add(component_session,
                plugin.plugin_path.decode("ascii"), u"trusted")

    uri = "ws://"
    if config.getboolean("webserver", "ssl"):
        uri = "wss://"

    address = config.get("webserver", "ws_address")
    port = config.getint("webserver", "ws_port")
    uri += "%s:%s/" % (address, port)

    from autobahn.twisted.websocket import WampWebSocketServerFactory
    transport_factory = WampWebSocketServerFactory(session_factory,
            uri, debug = False, debug_wamp = False)
    transport_factory.setProtocolOptions(failByDrop = False)
    watchdog(config.get("watchdog", "webserver"))

    from twisted.web.server import Site
    from autobahn.twisted.resource import WebSocketResource

    root = Root()
    ws_resource = WebSocketResource(transport_factory)
    rest_resource = pm.plugins['sputnik.webserver.rest.RESTProxy']
    root.putChild("ws", ws_resource)
    root.putChild("api", rest_resource)
    site = Site(root)
    site.noisy = False
    site.log = lambda _: None

    from twisted.internet.endpoints import serverFromString, quoteStringArgument
    if config.getboolean("webserver", "ssl"):
        key = config.get("webserver", "ssl_key")
        cert = config.get("webserver", "ssl_cert")
        cert_chain = config.get("webserver", "ssl_cert_chain")
        # TODO: Add dhparameters
        # See https://twistedmatrix.com/documents/14.0.0/core/howto/endpoints.html
        server = serverFromString(reactor, b"ssl:%d:privateKey=%s:certKey=%s:extraCertChain=%s:sslmethod=TLSv1_METHOD"
                                  % (port,
                                     quoteStringArgument(key),
                                     quoteStringArgument(cert),
                                     quoteStringArgument(cert_chain)))
    else:
        server = serverFromString(reactor, b"tcp:%d" % port)

    server.listen(site)
예제 #2
0
파일: cashier.py 프로젝트: ysobolev/sputnik
def main():
    log.startLogging(sys.stdout)

    accountant = AccountantProxy("dealer",
            config.get("accountant", "cashier_export"),
            config.getint("accountant", "cashier_export_base_port"))

    session = db.make_session()
    bitcoin_conf = config.get("cashier", "bitcoin_conf")

    log.msg('connecting to bitcoin client')

    bitcoinrpc = {'BTC': BitcoinRpc(bitcoin_conf, 1)}
    compropago = Compropago(config.get("cashier", "compropago_key"))
    cold_wallet_period = config.getint("cashier", "cold_wallet_period")
    sendmail=Sendmail(config.get("administrator", "email"))
    minimum_confirmations = config.getint("cashier", "minimum_confirmations")
    alerts_proxy = AlertsProxy(config.get("alerts", "export"))
    bitgo_config = {'use_production': not config.getboolean("cashier", "testnet"),
                    'client_id': config.get("bitgo", "client_id"),
                    'client_secret': config.get("bitgo", "client_secret")}
    bitgo = BitGo(**bitgo_config)
    bitgo_private_key_file = config.get("cashier", "bitgo_private_key_file")

    cashier = Cashier(session, accountant, bitcoinrpc, compropago,
                      cold_wallet_period=cold_wallet_period,
                      sendmail=sendmail,
                      minimum_confirmations=minimum_confirmations,
                      alerts=alerts_proxy,
                      bitgo=bitgo,
                      bitgo_private_key_file=bitgo_private_key_file,
                      testnet=config.getboolean("cashier", "testnet"),
    )

    administrator_export = AdministratorExport(cashier)
    accountant_export = AccountantExport(cashier)
    webserver_export = WebserverExport(cashier)

    watchdog(config.get("watchdog", "cashier"))
    router_share_async(administrator_export,
                     config.get("cashier", "administrator_export"))
    pull_share_async(accountant_export,
                    config.get("cashier", "accountant_export"))
    router_share_async(webserver_export,
                       config.get("cashier", "webserver_export"))

    public_server = Resource()
    public_server.putChild('compropago', CompropagoHook(cashier))
    private_server = Resource()
    private_server.putChild('bitcoin', BitcoinNotify(cashier))


    if config.getboolean("webserver", "ssl"):
        key = config.get("webserver", "ssl_key")
        cert = config.get("webserver", "ssl_cert")
        cert_chain = config.get("webserver", "ssl_cert_chain")
        contextFactory = ssl.ChainedOpenSSLContextFactory(key, cert_chain)

        reactor.listenSSL(config.getint("cashier", "public_port"),
                      Site(public_server), contextFactory,
                      interface=config.get("cashier", "public_interface"))
    else:
        reactor.listenTCP(config.getint("cashier", "public_port"),
                      Site(public_server),
                      interface=config.get("cashier", "public_interface"))

    reactor.listenTCP(config.getint("cashier", "private_port"), Site(private_server),
                      interface=config.get("cashier", "private_interface"))

    reactor.run()
예제 #3
0
파일: launch.py 프로젝트: ysobolev/sputnik
def run(pm, reactor):
    from sputnik.webserver.router.twisted.wamp import RouterFactory
    router_factory = RouterFactory()
    router_factory.router = SputnikRouter

    router_factory.authz_plugins = \
            pm.services.get("sputnik.webserver.plugins.authz", [])
    router_factory.schema_plugins = \
            pm.services.get("sputnik.webserver.plugins.schema", [])

    from sputnik.webserver.router.twisted.wamp import RouterSessionFactory
    session_factory = RouterSessionFactory(router_factory)
    session_factory.session = SputnikRouterSession

    authn_stack = [("ip.IPFilter", "requisite"),
                   ("anonymous.AnonymousLogin", "sufficient"),
                   ("cookie.CookieLogin", "sufficient"),
                   ("wampcra.WAMPCRALogin", "requisite"),
                   ("totp.TOTPVerification", "requisite")]
    session_factory.plugins = []
    for plugin_name, flag in authn_stack:
        path = "sputnik.webserver.plugins.authn." + plugin_name
        session_factory.plugins.append((pm.plugins[path], flag))

    rpc_plugins = pm.services.get("sputnik.webserver.plugins.rpc", [])
    feeds_plugins = pm.services.get("sputnik.webserver.plugins.feeds", [])
    svc_plugins = rpc_plugins + feeds_plugins
    for plugin in svc_plugins:
        component_session = plugin
        component_session.config.realm = u"sputnik"
        session_factory.add(component_session,
                            plugin.plugin_path.decode("ascii"), u"trusted")

    uri = "ws://"
    if config.getboolean("webserver", "ssl"):
        uri = "wss://"

    address = config.get("webserver", "ws_address")
    port = config.getint("webserver", "ws_port")
    uri += "%s:%s/" % (address, port)

    from autobahn.twisted.websocket import WampWebSocketServerFactory
    transport_factory = WampWebSocketServerFactory(session_factory,
                                                   uri,
                                                   debug=False,
                                                   debug_wamp=False)
    transport_factory.setProtocolOptions(failByDrop=False)
    watchdog(config.get("watchdog", "webserver"))

    from twisted.web.server import Site
    from autobahn.twisted.resource import WebSocketResource

    root = Root()
    ws_resource = WebSocketResource(transport_factory)
    rest_resource = pm.plugins['sputnik.webserver.rest.RESTProxy']
    root.putChild("ws", ws_resource)
    root.putChild("api", rest_resource)
    site = Site(root)
    site.noisy = False
    site.log = lambda _: None

    from twisted.internet.endpoints import serverFromString, quoteStringArgument
    if config.getboolean("webserver", "ssl"):
        key = config.get("webserver", "ssl_key")
        cert = config.get("webserver", "ssl_cert")
        cert_chain = config.get("webserver", "ssl_cert_chain")
        # TODO: Add dhparameters
        # See https://twistedmatrix.com/documents/14.0.0/core/howto/endpoints.html
        server = serverFromString(
            reactor,
            b"ssl:%d:privateKey=%s:certKey=%s:extraCertChain=%s:sslmethod=TLSv1_METHOD"
            % (port, quoteStringArgument(key), quoteStringArgument(cert),
               quoteStringArgument(cert_chain)))
    else:
        server = serverFromString(reactor, b"tcp:%d" % port)

    server.listen(site)
예제 #4
0
파일: cashier.py 프로젝트: ysobolev/sputnik
def main():
    log.startLogging(sys.stdout)

    accountant = AccountantProxy(
        "dealer", config.get("accountant", "cashier_export"),
        config.getint("accountant", "cashier_export_base_port"))

    session = db.make_session()
    bitcoin_conf = config.get("cashier", "bitcoin_conf")

    log.msg('connecting to bitcoin client')

    bitcoinrpc = {'BTC': BitcoinRpc(bitcoin_conf, 1)}
    compropago = Compropago(config.get("cashier", "compropago_key"))
    cold_wallet_period = config.getint("cashier", "cold_wallet_period")
    sendmail = Sendmail(config.get("administrator", "email"))
    minimum_confirmations = config.getint("cashier", "minimum_confirmations")
    alerts_proxy = AlertsProxy(config.get("alerts", "export"))
    bitgo_config = {
        'use_production': not config.getboolean("cashier", "testnet"),
        'client_id': config.get("bitgo", "client_id"),
        'client_secret': config.get("bitgo", "client_secret")
    }
    bitgo = BitGo(**bitgo_config)
    bitgo_private_key_file = config.get("cashier", "bitgo_private_key_file")

    cashier = Cashier(
        session,
        accountant,
        bitcoinrpc,
        compropago,
        cold_wallet_period=cold_wallet_period,
        sendmail=sendmail,
        minimum_confirmations=minimum_confirmations,
        alerts=alerts_proxy,
        bitgo=bitgo,
        bitgo_private_key_file=bitgo_private_key_file,
        testnet=config.getboolean("cashier", "testnet"),
    )

    administrator_export = AdministratorExport(cashier)
    accountant_export = AccountantExport(cashier)
    webserver_export = WebserverExport(cashier)

    watchdog(config.get("watchdog", "cashier"))
    router_share_async(administrator_export,
                       config.get("cashier", "administrator_export"))
    pull_share_async(accountant_export,
                     config.get("cashier", "accountant_export"))
    router_share_async(webserver_export,
                       config.get("cashier", "webserver_export"))

    public_server = Resource()
    public_server.putChild('compropago', CompropagoHook(cashier))
    private_server = Resource()
    private_server.putChild('bitcoin', BitcoinNotify(cashier))

    if config.getboolean("webserver", "ssl"):
        key = config.get("webserver", "ssl_key")
        cert = config.get("webserver", "ssl_cert")
        cert_chain = config.get("webserver", "ssl_cert_chain")
        contextFactory = ssl.ChainedOpenSSLContextFactory(key, cert_chain)

        reactor.listenSSL(config.getint("cashier", "public_port"),
                          Site(public_server),
                          contextFactory,
                          interface=config.get("cashier", "public_interface"))
    else:
        reactor.listenTCP(config.getint("cashier", "public_port"),
                          Site(public_server),
                          interface=config.get("cashier", "public_interface"))

    reactor.listenTCP(config.getint("cashier", "private_port"),
                      Site(private_server),
                      interface=config.get("cashier", "private_interface"))

    reactor.run()