示例#1
0
文件: main.py 项目: no2key/fqrouter
def run():
    skipped_components = []
    LOGGER.info('environment: %s' % os.environ.items())
    if not config.read().getboolean('fqrouter', 'BypassDirectlyEnabled'):
        LOGGER.info('scrambler component disabled by config')
        COMPONENTS.remove(comp_scrambler)
    for comp in COMPONENTS:
        try:
            shutdown_hook.add(comp.stop)
            handlers = comp.start()
            for method, url, handler in handlers or []:
                HANDLERS[(method, url)] = handler
            LOGGER.info('started component: %s' % comp.__name__)
        except:
            LOGGER.exception('failed to start component: %s' % comp.__name__)
            comp.stop()
            if getattr(comp, '__MANDATORY__', False):
                raise
            skipped_components.append(comp.__name__)
    LOGGER.info('all components started except: %s' % skipped_components)
    try:
        httpd = WSGIServer(('127.0.0.1', 8318), handle_request)
        LOGGER.info('serving HTTP on port 8318...')
    except:
        LOGGER.exception('failed to start HTTP server on port 8318')
        sys.exit(1)
    httpd.serve_forever()
示例#2
0
文件: main.py 项目: no2key/fqrouter
def run():
    skipped_components = []
    LOGGER.info('environment: %s' % os.environ.items())
    if not config.read().getboolean('fqrouter', 'BypassDirectlyEnabled'):
        LOGGER.info('scrambler component disabled by config')
        COMPONENTS.remove(comp_scrambler)
    for comp in COMPONENTS:
        try:
            shutdown_hook.add(comp.stop)
            handlers = comp.start()
            for method, url, handler in handlers or []:
                HANDLERS[(method, url)] = handler
            LOGGER.info('started component: %s' % comp.__name__)
        except:
            LOGGER.exception('failed to start component: %s' % comp.__name__)
            comp.stop()
            if getattr(comp, '__MANDATORY__', False):
                raise
            skipped_components.append(comp.__name__)
    LOGGER.info('all components started except: %s' % skipped_components)
    try:
        httpd = WSGIServer(('127.0.0.1', 8318), handle_request)
        LOGGER.info('serving HTTP on port 8318...')
    except:
        LOGGER.exception('failed to start HTTP server on port 8318')
        sys.exit(1)
    httpd.serve_forever()
示例#3
0
def start_components(*components):
    for comp in components:
        try:
            shutdown_hook.add(comp.stop)
            handlers = comp.start()
            for method, url, handler in handlers or []:
                httpd.HANDLERS[(method, url)] = handler
            LOGGER.info('started component: %s' % comp.__name__)
        except:
            LOGGER.exception('failed to start component: %s' % comp.__name__)
            comp.stop()
            if getattr(comp, '__MANDATORY__', False):
                raise
            LOGGER.info('skipped component: %s' % comp.__name__)
示例#4
0
文件: main.py 项目: JustLin/fqrouter
def run():
    iptables.init_fq_chains()
    shutdown_hook.add(iptables.flush_fq_chain)
    if config.read().get('comp_wifi_enabled', True):
        start_components(comp_wifi, comp_lan)
    else:
        LOGGER.info('wifi component disabled by config')
        comp_wifi.setup_lo_alias()
        start_components(comp_lan)
    httpd.HANDLERS[('GET', 'ping')] = handle_ping
    httpd.HANDLERS[('POST', 'free-internet/connect')] = handle_free_internet_connect
    httpd.HANDLERS[('POST', 'free-internet/disconnect')] = handle_free_internet_disconnect
    httpd.HANDLERS[('GET', 'free-internet/is-connected')] = handle_free_internet_is_connected
    httpd.serve_forever()
示例#5
0
def run():
    iptables.init_fq_chains()
    shutdown_hook.add(iptables.flush_fq_chain)
    if config.read().get('comp_wifi_enabled', True):
        start_components(comp_wifi, comp_lan)
    else:
        LOGGER.info('wifi component disabled by config')
        comp_wifi.setup_lo_alias()
        start_components(comp_lan)
    httpd.HANDLERS[('GET', 'ping')] = handle_ping
    httpd.HANDLERS[('POST', 'free-internet/connect')] = handle_free_internet_connect
    httpd.HANDLERS[('POST', 'free-internet/disconnect')] = handle_free_internet_disconnect
    httpd.HANDLERS[('GET', 'free-internet/is-connected')] = handle_free_internet_is_connected
    gevent.spawn(check_ping)
    httpd.serve_forever()
示例#6
0
文件: main.py 项目: erizhang/fqrouter
def start_components(*components):
    LOGGER.info('environment: %s' % os.environ.items())
    for comp in components:
        try:
            shutdown_hook.add(comp.stop)
            handlers = comp.start()
            for method, url, handler in handlers or []:
                httpd.HANDLERS[(method, url)] = handler
            LOGGER.info('started component: %s' % comp.__name__)
        except:
            LOGGER.exception('failed to start component: %s' % comp.__name__)
            comp.stop()
            if getattr(comp, '__MANDATORY__', False):
                raise
            LOGGER.info('skipped component: %s' % comp.__name__)
示例#7
0
文件: main.py 项目: DrayChou/fqrouter
def run():
    skipped_components = []
    LOGGER.info('environment: %s' % os.environ.items())
    if not config.read()['tcp_scrambler_enabled']:
        LOGGER.info('scrambler component disabled by config')
        COMPONENTS.remove(comp_scrambler)
    for comp in COMPONENTS:
        try:
            shutdown_hook.add(comp.stop)
            handlers = comp.start()
            for method, url, handler in handlers or []:
                httpd.HANDLERS[(method, url)] = handler
            LOGGER.info('started component: %s' % comp.__name__)
        except:
            LOGGER.exception('failed to start component: %s' % comp.__name__)
            comp.stop()
            if getattr(comp, '__MANDATORY__', False):
                raise
            skipped_components.append(comp.__name__)
    LOGGER.info('all components started except: %s' % skipped_components)
    httpd.HANDLERS[('GET', 'ping')] = handle_ping
    httpd.serve_forever()