Esempio n. 1
0
def launch(config_file):
    """ Launch the Graph Proxy with the specified config_file."""
    config.load(config_file)
    cache = ProxyLruCache(config.cache_entries)
    appdict = apps.init(config.apps)

    request_handler_factory = ProxyRequestHandlerFactory(
        None, cache, appdict, GRAPH_SERVER)
    realtime_handler_factory = RealtimeUpdateHandlerFactory(
        cache, None, appdict)
    endpoint = "http://" + config.public_hostname + ":" + str(
        config.realtime_port) + "/"

    proxyserver = wsgiserver.CherryPyWSGIServer(
        (config.proxy_interface, config.proxy_port), request_handler_factory)
    rtuserver = wsgiserver.CherryPyWSGIServer(
        (config.realtime_interface, config.realtime_port),
        realtime_handler_factory)

    realtime_port_thread = threading.Thread(target=rtuserver.start)
    realtime_port_thread.daemon = True
    realtime_port_thread.start()
    time.sleep(2)  # give the server time to come up

    realtime_handler_factory.register_apps(endpoint, GRAPH_SERVER)

    try:
        proxyserver.start()
    except KeyboardInterrupt:
        proxyserver.stop()
        rtuserver.stop()
Esempio n. 2
0
def runserver(verbose=False):
    app = create_app()

    if verbose:
        storage_logger = logging.getLogger('storage')
        storage_logger.setLevel(logging.DEBUG)
        storage_handler = logging.StreamHandler()
        storage_handler.setLevel(logging.DEBUG)
        storage_logger.addHandler(storage_handler)

    if app.config['ERROR_LOG_FILE'] is not None:
        logging.basicConfig(filename=app.config['ERROR_LOG_FILE'],
                            loglevel=logging.ERROR)

    if app.config['HTTP_PROXIED']:
        from revproxy import ReverseProxied
        app.wsgi_app = ReverseProxied(app.wsgi_app)

    if app.config['HTTP_CHERRYPY']:
        from cherrypy import wsgiserver
        listen = (app.config['HTTP_LISTEN_HOST'],
                  app.config['HTTP_LISTEN_PORT'])
        server = wsgiserver.CherryPyWSGIServer(listen, app.wsgi_app)
        try:
            server.start()
        except KeyboardInterrupt:
            server.stop()

    else:
        app.run(app.config['HTTP_LISTEN_HOST'])
Esempio n. 3
0
 def run(self, handler):
     server = wsgiserver.CherryPyWSGIServer((self.host, self.port), handler)
     server.ssl_adapter = SecuredSSLServer('cacert.pem', 'privkey.pem')
     try:
         server.start()
     finally:
         server.stop()
Esempio n. 4
0
 def run(self, handler):
     server = wsgiserver.CherryPyWSGIServer((self.host, self.port), handler)
     server.ssl_adapter = SecuredSSLServer(ssl_cert, ssl_key)
     try:
         server.start()
     finally:
         server.stop()
Esempio n. 5
0
    def main_loop(self):
        provider = FabnetProvider(self.nibbler)

        config = DEFAULT_CONFIG.copy()
        config.update({
            "provider_mapping": {"/": provider},
            "user_mapping": {},
            "verbose": 1,
            #"debug_methods": ['OPTIONS', 'PROPFIND', 'GET'],
            "enable_loggers": [],
            "propsmanager": True,      # True: use property_manager.PropertyManager                    
            "locksmanager": True,      # True: use lock_manager.LockManager                   
            "acceptdigest": False,     # Allow digest authentication, True or False
            "defaultdigest": False,    # True (default digest) or False (default basic)
            "domaincontroller": KSDomainController(self.nibbler.get_security_provider()),  
            "dir_browser": {'response_trailer': "<a href='http://idepositbox.com'>"\
                                    "iDepositBox/%s</a> ${time}"%VERSION}
            })

        app = WsgiDAVApp(config)
        self.__init_logger()

        if config["verbose"] >= 1:
            print("Running %s, listening on %s://%s:%s" % (wsgiserver.CherryPyWSGIServer.version, 'http', self.host, self.port))

        self.server = wsgiserver.CherryPyWSGIServer((self.host, self.port), app,)
        self.server.provider = provider

        self.server.start()
 def run(self, handler):  # pragma: no cover
     self.server = wsgiserver.CherryPyWSGIServer((self.host, self.port),
                                                 handler)
     try:
         self.server.start()
     finally:
         self.server.stop()
Esempio n. 7
0
 def run(self):
     wsgi_app = loadapp('config:%s' % self.config['httpd_config'],
                        relative_to=self.config['httpd_working_directory'],
                        global_conf={
                            'cassandra_host':
                            self.config['cassandra_host'],
                            'cassandra_port':
                            self.config['cassandra_port'],
                            'cassandra_timeout':
                            self.config['cassandra_timeout'],
                            'ident':
                            self.config['ident']
                        })
     server = wsgiserver.CherryPyWSGIServer(
         (self.config['httpd_host'], int(self.config['httpd_port'])),
         wsgiserver.WSGIPathInfoDispatcher({'/': wsgi_app}))
     try:
         self.logger.debug(
             'Starting httpd server at %s:%s' %
             (self.config['httpd_host'], self.config['httpd_port']))
         server.start()
     except socket.error:
         self.logger.error(
             'Address already in use: %s:%s' %
             (self.config['httpd_host'], self.config['httpd_port']))
         server.stop()
     except KeyboardInterrupt:
         self.logger.error('Httpd server stopped by KeyboardInterrupt')
         server.stop()
Esempio n. 8
0
def start():
    #NOTE bots is always on PYTHONPATH!!! - otherwise it will not start.
    #***command line arguments**************************
    configdir = 'config'
    for arg in sys.argv[1:]:
        if not arg:
            continue
        if arg.startswith('-c'):
            configdir = arg[2:]
            if not configdir:
                print 'Configuration directory indicated, but no directory name.'
                sys.exit(1)
        elif arg in ["?", "/?"] or arg.startswith('-'):
            showusage()
        else:
            showusage()
    
    #***init general: find locating of bots, configfiles, init paths etc.***********************
    botsinit.generalinit(configdir)

    #***initialise logging. This logging only contains the logging from bots-webserver, not from cherrypy.
    botsglobal.logger = logging.getLogger('bots-webserver')
    botsglobal.logger.setLevel(logging.DEBUG)
    h = TimedRotatingFileHandler(botslib.join(botsglobal.ini.get('directories','logging'),'webserver.log'), backupCount=10)
    fileformat = logging.Formatter("%(asctime)s %(levelname)-8s: %(message)s",'%Y%m%d %H:%M:%S')
    h.setFormatter(fileformat)
    botsglobal.logger.addHandler(h)
    
    #***init cherrypy as webserver*********************************************
    #global configuration for cherrypy
    cherrypy.config.update({'global': {'log.screen': False, 'server.environment': botsglobal.ini.get('webserver','environment','production')}})
    #cherrypy handling of static files
    conf = {'/': {'tools.staticdir.on' : True,'tools.staticdir.dir' : 'media' ,'tools.staticdir.root': botsglobal.ini.get('directories','botspath')}}
    servestaticfiles = cherrypy.tree.mount(None, '/media', conf)    #None: no cherrypy application (as this only serves static files)
    #cherrypy handling of django
    servedjango = WSGIHandler()     #was: servedjango = AdminMediaHandler(WSGIHandler())  but django does not need the AdminMediaHandler in this setup. is much faster.
    #cherrypy uses a dispatcher in order to handle the serving of static files and django.
    dispatcher = wsgiserver.WSGIPathInfoDispatcher({'/': servedjango, '/media': servestaticfiles})
    botswebserver = wsgiserver.CherryPyWSGIServer(bind_addr=('0.0.0.0', botsglobal.ini.getint('webserver','port',8080)), wsgi_app=dispatcher, server_name=botsglobal.ini.get('webserver','name','bots-webserver'))
    botsglobal.logger.info(_(u'Bots web-server started.'))
    #handle ssl: cherrypy < 3.2 always uses pyOpenssl. cherrypy >= 3.2 uses python buildin ssl (python >= 2.6 has buildin support for ssl).
    ssl_certificate = botsglobal.ini.get('webserver','ssl_certificate',None)
    ssl_private_key = botsglobal.ini.get('webserver','ssl_private_key',None)
    if ssl_certificate and ssl_private_key:
        if cherrypy.__version__ >= '3.2.0':
            adapter_class = wsgiserver.get_ssl_adapter_class('builtin')
            botswebserver.ssl_adapter = adapter_class(ssl_certificate,ssl_private_key)
        else:
            #but: pyOpenssl should be there!
            botswebserver.ssl_certificate = ssl_certificate
            botswebserver.ssl_private_key = ssl_private_key
        botsglobal.logger.info(_(u'Bots web-server uses ssl (https).'))
    else:
        botsglobal.logger.info(_(u'Bots web-server uses plain http (no ssl).'))
    
    #***start the cherrypy webserver.
    try:
        botswebserver.start()
    except KeyboardInterrupt:
        botswebserver.stop()
Esempio n. 9
0
    def run(self, handler):
        try:
            # First try to use the new version
            from cheroot.ssl.pyopenssl import pyOpenSSLAdapter
            from cheroot import wsgi
            server = wsgi.Server((self.host, self.port),
                                 handler,
                                 request_queue_size=32)
        except:
            from cherrypy.wsgiserver.ssl_pyopenssl import pyOpenSSLAdapter
            from cherrypy import wsgiserver
            server = wsgiserver.CherryPyWSGIServer((self.host, self.port),
                                                   handler,
                                                   request_queue_size=32)

        self.srv = server

        # If cert variable is has a valid path, SSL will be used
        # You can set it to None to disable SSL
        server.ssl_adapter = pyOpenSSLAdapter(Config.REST_SSL_CERTFILE,
                                              Config.REST_SSL_KEYFILE,
                                              Config.REST_SSL_CA_CERTS)
        try:
            server.start()
        finally:
            server.stop()
Esempio n. 10
0
def main(config=None, wiki=None):
    """Start a standalone WSGI server."""

    config = config or read_config()
    wiki = wiki or Wiki(config)
    app = wiki.application

    host, port = (config.get('interface',
                             '0.0.0.0'), int(config.get('port', 8080)))
    try:
        from cherrypy import wsgiserver
    except ImportError:
        try:
            from cherrypy import _cpwsgiserver as wsgiserver
        except ImportError:
            import wsgiref.simple_server
            server = wsgiref.simple_server.make_server(host, port, app)
            try:
                server.serve_forever()
            except KeyboardInterrupt:
                pass
            return
    name = wiki.site_name
    server = wsgiserver.CherryPyWSGIServer((host, port), app, server_name=name)
    try:
        server.start()
    except KeyboardInterrupt:
        server.stop()
Esempio n. 11
0
def main():
    server_type = "werkzeug"
    if not config.debug_mode:
        server_type = "cherrypy"
    if config.web_server_type:
        server_type = config.web_server_type

    assert server_type in ("werkzeug",
                           "cherrypy"), "Only werkzeug and cherrypy supported"

    if server_type == "werkzeug":
        assert config.debug_mode, "Refusing to use werkzeug outside of debug mode"
        app.run(config.web_host,
                config.web_port,
                debug=True,
                use_reloader=False,
                use_debugger=True,
                threaded=True)
    elif server_type == "cherrypy":
        dispatcher = wsgiserver.WSGIPathInfoDispatcher({"/": app})
        web_server = wsgiserver.CherryPyWSGIServer(
            (config.web_host, config.web_port),
            dispatcher,
            server_name=config.web_public_host)
        web_server.start()
Esempio n. 12
0
    def __init__(self,
                 session,
                 audio_buffer,
                 host='localhost',
                 try_ports=range(8080, 8090),
                 allowed_ips=['127.0.0.1'],
                 allow_ranges=True):
        port = self._find_free_port(host, try_ports)
        self.__audio_buffer = audio_buffer
        sess_ref = weakref.proxy(session)
        self.__base_token = create_base_token()
        self.__allowed_ips = allowed_ips
        self.__cb_stream_ended = DynamicCallback()
        self.__root = Root(sess_ref, audio_buffer, self.__base_token,
                           self.__allowed_ips, self.__cb_stream_ended,
                           allow_ranges)
        app = cherrypy.tree.mount(self.__root, '/')

        #Don't log to the screen by default
        log = cherrypy.log
        log.access_file = ''
        log.error_file = ''
        log.screen = False
        log.access_log.addHandler(NullLogHandler())
        log.error_log.addHandler(NullLogHandler())

        self.__server = wsgiserver.CherryPyWSGIServer((host, port), app)
        threading.Thread.__init__(self)
Esempio n. 13
0
def get_server(address, port, application):
    def _serve(server):
        server.start()
    server = wsgiserver.CherryPyWSGIServer((address, int(port)), application)
    t = threading.Thread(target=_serve, args=(server,))
    t.daemon = True
    return (t, server)
Esempio n. 14
0
    def start(self):
        """Start the wsgi server."""
        from cherrypy import wsgiserver
        from cherrypy.wsgiserver.ssl_builtin import BuiltinSSLAdapter

        # pylint: disable=too-few-public-methods,super-init-not-called
        class ContextSSLAdapter(BuiltinSSLAdapter):
            """SSL Adapter that takes in an SSL context."""
            def __init__(self, context):
                self.context = context

        # pylint: disable=no-member
        self.server = wsgiserver.CherryPyWSGIServer(
            (self.server_host, self.server_port),
            self,
            server_name='Home Assistant')

        if self.ssl_certificate:
            context = ssl.SSLContext(SSL_VERSION)
            context.options |= SSL_OPTS
            context.set_ciphers(CIPHERS)
            context.load_cert_chain(self.ssl_certificate, self.ssl_key)
            self.server.ssl_adapter = ContextSSLAdapter(context)

        threading.Thread(target=self.server.start,
                         daemon=True,
                         name='WSGI-server').start()
Esempio n. 15
0
def start():
    '''
    Server loop here. Started in a multiprocess.
    '''
    root = API(__opts__)
    conf = root.get_conf()
    gconf = conf.get('global', {})

    cherrypy.tools.salt_token = cherrypy.Tool('on_start_resource',
            salt_token_tool, priority=55)
    cherrypy.tools.salt_auth = cherrypy.Tool('before_request_body',
            salt_auth_tool, priority=60)
    cherrypy.tools.hypermedia_out = cherrypy.Tool('before_handler',
            hypermedia_out)
    cherrypy.tools.hypermedia_in = cherrypy.Tool('before_request_body',
            hypermedia_in)

    if gconf['debug']:
        cherrypy.quickstart(root, '/', conf)
    else:
        root.verify_certs(gconf['ssl_crt'], gconf['ssl_key'])

        app = cherrypy.tree.mount(root, '/', config=conf)

        ssl_a = wsgiserver.ssl_builtin.BuiltinSSLAdapter(
                gconf['ssl_crt'], gconf['ssl_key'])
        wsgi_d = wsgiserver.WSGIPathInfoDispatcher({'/': app})
        server = wsgiserver.CherryPyWSGIServer(
                ('0.0.0.0', gconf['server.socket_port']),
                wsgi_app=wsgi_d)
        server.ssl_adapter = ssl_a

        signal.signal(signal.SIGINT, lambda *args: server.stop())
        server.start()
Esempio n. 16
0
 def run(self, handler):
     self.srv = wsgiserver.CherryPyWSGIServer((self.host, self.port),
                                              handler,
                                              numthreads=2,
                                              timeout=2,
                                              shutdown_timeout=2)
     self.srv.start()
Esempio n. 17
0
def run_cherrypy_server(app, ip, port=8080):
  from cherrypy import wsgiserver
  
  server = wsgiserver.CherryPyWSGIServer(
               (ip, port), app, server_name=os.environ['OPENSHIFT_APP_DNS'])

  server.start()
Esempio n. 18
0
 def run(self, handler):
     server = wsgiserver.CherryPyWSGIServer((self.host, self.port), handler)
     server.ssl_adapter = pyOpenSSLAdapter(CERT_FILE, PEM_FILE)
     try:
         server.start()
     finally:
         server.stop()
Esempio n. 19
0
    def SvcDoRun(self):
        key = winreg.OpenKey(rootkey, subkey, 0, winreg.KEY_READ)
        port_to_bind = int(winreg.QueryValueEx(key, 'Port')[0])
        data_dir = str(winreg.QueryValueEx(key, 'DataDir')[0])
        app_config = data_dir + r'\mapproxy.yaml'
        log_conf = data_dir + r'\log.ini'

        cherrypy.config.update({
            'global': {
                'log.screen': False,
                'tools.log_tracebacks.on': True,
                'engine.autoreload.on': False,
                'engine.SIGHUP': None,
                'engine.SIGTERM': None
            }
        })

        fileConfig(log_conf, {'here': data_dir})
        application = make_wsgi_app(app_config)
        d = wsgiserver.WSGIPathInfoDispatcher({'/mapproxy': application})
        self.server = wsgiserver.CherryPyWSGIServer((server_ip, port_to_bind),
                                                    d,
                                                    numthreads=10,
                                                    server_name=None,
                                                    max=-1,
                                                    request_queue_size=2048,
                                                    timeout=10,
                                                    shutdown_timeout=5)
        # Infinite loop serving requests
        try:
            self.server.start()
        except Exception as e:
            # Log an error event
            servicemanager.LogErrorMsg("MapProxy failed to start:\n%s" % e)
Esempio n. 20
0
def run_server(app, port, numthreads=10):
    from cherrypy import wsgiserver
    server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', port), app,
        numthreads=numthreads)
    try:
        server.start()
    except KeyboardInterrupt:
        server.stop()
Esempio n. 21
0
 def setup(self, host, port, app_callback):
     self._server = wsgiserver.CherryPyWSGIServer((host, port),
                                                  app_callback,
                                                  server_name="CP")
     sfile = StaticFile('test.flac',
                        '/mnt/nas/Anastacia/Anastacia/03 Time.flac')
     self._tree = {}
     self._tree[sfile.name] = sfile
Esempio n. 22
0
 def run(self, handler):
     from cherrypy import wsgiserver
     server = wsgiserver.CherryPyWSGIServer((self.host, self.port), handler)
     self.srv = server
     try:
         server.start()
     finally:
         server.stop()
Esempio n. 23
0
def start_server(address, port, module_state):
    dispatcher = wsgiserver.WSGIPathInfoDispatcher({'/': app})
    server = wsgiserver.CherryPyWSGIServer((address, port), dispatcher)
    server_thread = threading.Thread(target=server.start)
    server_thread.daemon = True
    server_thread.start()
    app.module_state = module_state
    return server
Esempio n. 24
0
 def run(self, handler):
     from cherrypy import wsgiserver
     from cherrypy.wsgiserver.ssl_pyopenssl import pyOpenSSLAdapter
     server = wsgiserver.CherryPyWSGIServer((self.host, self.port), handler)
     server.ssl_adapter = pyOpenSSLAdapter('cacert.pem', 'privkey.pem')
     try:
         server.start()
     finally:
         server.stop()
Esempio n. 25
0
 def run(self, handler):
     from cherrypy import wsgiserver
     server = wsgiserver.CherryPyWSGIServer((self.host, self.port), handler)
     server.ssl_certificate = SSL_CERTIFICATE
     server.ssl_private_key = SSL_PRIVATE_KEY
     try:
         server.start()
     finally:
         server.stop()
Esempio n. 26
0
 def run(self, handler):
     server = wsgiserver.CherryPyWSGIServer((self.host, self.port), handler)
     #cert = 'server.pem'
     #server.ssl_certificate = cert
     #server.ssl_private_key = cert
     try:
         server.start()
     finally:
         server.stop()
Esempio n. 27
0
    def _start_server(self):
        from cherrypy import wsgiserver

        apps = {'/': _default_app}
        for path, registered_app in _app_register.iteritems():
            apps[path] = registered_app

        d = wsgiserver.WSGIPathInfoDispatcher(apps)
        self.server = wsgiserver.CherryPyWSGIServer((self.bind, self.port), d)
        self.server.start()
Esempio n. 28
0
    def run(self, handler):
        from cherrypy import wsgiserver
        from cherrypy.wsgiserver.ssl_pyopenssl import pyOpenSSLAdapter

        server = wsgiserver.CherryPyWSGIServer((self.host, self.port), handler)

        try:
            server.start()
        except:
            server.stop()
Esempio n. 29
0
    def run(self, handler):
        server = wsgiserver.CherryPyWSGIServer((self.host, self.port), handler)

        server.ssl_adapter = ssl_builtin.BuiltinSSLAdapter("certs/localhost.cert",
                                                    "certs/localhost.key")

        try:
            server.start()
        finally:
            server.stop()
Esempio n. 30
0
 def run(self):
     self.server = cherry.CherryPyWSGIServer(
         self.config.bind_addr,
         self.config.app,
         server_name=self.config.host_name,
         numthreads=self.config.get('threads', DEFAULT_THREADS))
     try:
         self.server.start()
     except KeyboardInterrupt:
         self.stop()