Beispiel #1
0
def run():
    iptables.init_fq_chains()
    shutdown_hook.add(iptables.flush_fq_chain)
    iptables.insert_rules(DNS_RULES)
    shutdown_hook.add(functools.partial(iptables.delete_rules, DNS_RULES))
    iptables.insert_rules(SOCKS_RULES)
    shutdown_hook.add(functools.partial(iptables.delete_rules, SOCKS_RULES))
    wifi.setup_lo_alias()
    try:
        comp_scrambler.start()
        shutdown_hook.add(comp_scrambler.stop)
    except:
        LOGGER.exception('failed to start comp_scrambler')
        comp_scrambler.stop()
    try:
        comp_shortcut.start()
        shutdown_hook.add(comp_shortcut.stop)
    except:
        LOGGER.exception('failed to start comp_shortcut')
        comp_shortcut.stop()
    args = [
        '--log-level', 'INFO',
        '--log-file', '/data/data/fq.router2/log/fqsocks.log',
        '--ifconfig-command', '/data/data/fq.router2/busybox',
        '--ip-command', '/data/data/fq.router2/busybox',
        '--outbound-ip', '10.1.2.3',
        '--tcp-gateway-listen', '10.1.2.3:12345',
        '--dns-server-listen', '10.1.2.3:12345']
    args = config.configure_fqsocks(args)
    fqsocks.fqsocks.main(args)
Beispiel #2
0
def run():
    iptables.init_fq_chains()
    shutdown_hook.add(iptables.flush_fq_chain)
    iptables.insert_rules(DNS_RULES)
    shutdown_hook.add(functools.partial(iptables.delete_rules, DNS_RULES))
    iptables.insert_rules(SOCKS_RULES)
    shutdown_hook.add(functools.partial(iptables.delete_rules, SOCKS_RULES))
    wifi.setup_lo_alias()
    args = [
        '--log-level', 'INFO',
        '--log-file', '/data/data/fq.router2/log/fqsocks.log',
        '--ifconfig-command', '/data/data/fq.router2/busybox',
        '--ip-command', '/data/data/fq.router2/busybox',
        '--outbound-ip', '10.1.2.3',
        '--tcp-gateway-listen', '10.1.2.3:12345',
        '--dns-server-listen', '10.1.2.3:12345']
    if shell.USE_SU:
        args.append('--no-tcp-scrambler')
    args = config.configure_fqsocks(args)
    fqsocks.fqsocks.init_config(args)
    if fqsocks.config_file.read_config()['tcp_scrambler_enabled']:
        try:
            comp_scrambler.start()
            shutdown_hook.add(comp_scrambler.stop)
        except:
            LOGGER.exception('failed to start comp_scrambler')
            comp_scrambler.stop()
    if fqsocks.config_file.read_config()['china_shortcut_enabled']:
        try:
            comp_shortcut.start()
            shutdown_hook.add(comp_shortcut.stop)
        except:
            LOGGER.exception('failed to start comp_shortcut')
            comp_shortcut.stop()
    fqsocks.fqsocks.main()
Beispiel #3
0
def start():
    setup_lo_alias()
    return [
        ('POST', 'wifi-repeater/start', handle_start),
        ('POST', 'wifi-repeater/stop', handle_stop),
        ('GET', 'wifi-repeater/is-started', handle_is_started),
    ]
Beispiel #4
0
def start():
    setup_lo_alias()
    return [
        ('POST', 'wifi/start', handle_start),
        ('POST', 'wifi/stop', handle_stop),
        ('GET', 'wifi/started', handle_started),
    ]
Beispiel #5
0
def start():
    setup_lo_alias()
    return [
        ('POST', 'wifi/start', handle_start),
        ('POST', 'wifi/stop', handle_stop),
        ('GET', 'wifi/started', handle_started),
        ('POST', 'wifi/setup', handle_setup)
    ]
Beispiel #6
0
def start():
    try:
        setup_lo_alias()
    except:
        LOGGER.exception('failed to setup lo alias')
    return [
        ('POST', 'wifi-repeater/start', handle_start),
        ('POST', 'wifi-repeater/stop', handle_stop),
        ('POST', 'wifi-repeater/reset', handle_reset),
        ('GET', 'wifi-repeater/is-started', handle_is_started),
    ]
Beispiel #7
0
def start():
    try:
        setup_lo_alias()
    except:
        LOGGER.exception('failed to setup lo alias')
    return [
        ('POST', 'wifi-repeater/start', handle_start),
        ('POST', 'wifi-repeater/stop', handle_stop),
        ('POST', 'wifi-repeater/reset', handle_reset),
        ('GET', 'wifi-repeater/is-started', handle_is_started),
    ]
Beispiel #8
0
def run():
    setup_logging(LOG_FILE)
    LOGGER.info('environment: %s' % os.environ.items())
    wifi.setup_lo_alias()
    dns_service.run()
    tcp_service.run()
    full_proxy_service.run()
    lan_service.run()
    LOGGER.info('services started')
    try:
        httpd = wsgiref.simple_server.make_server(
            '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()
Beispiel #9
0
def run():
    iptables.init_fq_chains()
    shutdown_hook.add(iptables.flush_fq_chain)
    iptables.insert_rules(DNS_RULES)
    shutdown_hook.add(functools.partial(iptables.delete_rules, DNS_RULES))
    iptables.insert_rules(SOCKS_RULES)
    shutdown_hook.add(functools.partial(iptables.delete_rules, SOCKS_RULES))
    wifi.setup_lo_alias()
    args = [
        '--log-level', 'INFO',
        '--log-file', '/data/data/fq.router2/log/fqsocks.log',
        '--ifconfig-command', '/data/data/fq.router2/busybox',
        '--ip-command', '/data/data/fq.router2/busybox',
        '--outbound-ip', '10.1.2.3',
        '--tcp-gateway-listen', '10.1.2.3:12345',
        '--dns-server-listen', '10.1.2.3:12345']
    if shell.USE_SU:
        args.append('--no-tcp-scrambler')
    args = config.configure_fqsocks(args)
    fqsocks.fqsocks.init_config(args)
    if fqsocks.config_file.read_config()['tcp_scrambler_enabled']:
        try:
            comp_scrambler.start()
            shutdown_hook.add(comp_scrambler.stop)
        except:
            LOGGER.exception('failed to start comp_scrambler')
            comp_scrambler.stop()
    if fqsocks.config_file.read_config()['china_shortcut_enabled']:
        try:
            comp_shortcut.start()
            shutdown_hook.add(comp_shortcut.stop)
        except:
            LOGGER.exception('failed to start comp_shortcut')
            comp_shortcut.stop()
    fqsocks.fqsocks.DNS_HANDLER.set_dns_bypass(fqsocks.config_file.read_config()['dns']['bypass'])
    fqsocks.fqsocks.get_default_dns_server = config.get_default_dns_server
    fqsocks.fqsocks.main()
Beispiel #10
0
def run():
    iptables.tables = {}
    iptables.init_fq_chains()
    shutdown_hook.add(iptables.flush_fq_chain)
    if not os.getenv('NO_FQDNS'):
        iptables.insert_rules(DNS_RULES)
        shutdown_hook.add(functools.partial(iptables.delete_rules, DNS_RULES))
    setup_nat()
    iptables.insert_rules(SOCKS_RULES)
    shutdown_hook.add(functools.partial(iptables.delete_rules, SOCKS_RULES))
    wifi.setup_lo_alias()

    if not os.getenv('NO_TEREDO'):
        LOGGER.info('init teredo and tun')
        sock = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
        sock.bind(('10.1.2.3', 0))
        teredo_client = teredo.teredo_client(
            sock, teredo.get_default_teredo_server())
        teredo_ip = None
        try:
            teredo_ip = teredo_client.start()
        except:
            LOGGER.exception('start teredo fail')
        if not teredo_ip:
            LOGGER.error('start teredo client fail, use default:%s' %
                         default_loacl_teredo_ip)
            teredo_ip = default_loacl_teredo_ip
        else:
            LOGGER.info('teredo start succeed, teredo ip:%s' % teredo_ip)

        tun_fd = init_tun(teredo_ip)
        if not tun_fd:
            LOGGER.error('init tun fail!')
        else:
            teredo.tun_fd = tun_fd
            teredo_client.server_forever(teredo_ip)
            gevent.spawn(redirect_tun_traffic, tun_fd, teredo_client)

    args = [
        '--log-level',
        'DEBUG' if os.getenv('DEBUG') else 'INFO',
        '--log-file',
        LOG_DIR + '/fqsocks.log',
        '--ifconfig-command',
        home_path + '/../busybox',
        #'--ip-command', 'ip',
        '--outbound-ip',
        '10.1.2.3',
        '--tcp-gateway-listen',
        '10.1.2.3:12345',
        '--dns-server-listen',
        '10.1.2.3:12345'
    ]
    if shell.USE_SU:
        args.append('--no-tcp-scrambler')
    args = config.configure_fqsocks(args)
    fqsocks.fqsocks.init_config(args)
    if fqsocks.config_file.read_config()['tcp_scrambler_enabled']:
        try:
            comp_scrambler.start()
            shutdown_hook.add(comp_scrambler.stop)
        except:
            LOGGER.exception('failed to start comp_scrambler')
            comp_scrambler.stop()
    if fqsocks.config_file.read_config(
    )['china_shortcut_enabled'] and comp_shortcut_enabled:
        try:
            comp_shortcut.start()
            shutdown_hook.add(comp_shortcut.stop)
        except:
            LOGGER.exception('failed to start comp_shortcut')
            comp_shortcut.stop()
    iptables.tables = {}
    fqsocks.fqsocks.main()
Beispiel #11
0
        lines = []
    for line in lines:
        yield line


def get_http_response(code):
    return '%s %s' % (code, httplib.responses[code])


class MultiThreadedWSGIServer(ThreadingMixIn, wsgiref.simple_server.WSGIServer):
    pass


if '__main__' == __name__:
    LOGGER.info('environment: %s' % os.environ.items())
    dns_service.run()
    tcp_service.run()
    full_proxy_service.run()
    lan_service.run()
    wifi.setup_lo_alias()
    LOGGER.info('services started')
    try:
        httpd = wsgiref.simple_server.make_server(
            '127.0.0.1', 8318, handle_request,
            server_class=MultiThreadedWSGIServer)
        LOGGER.info('serving HTTP on port 8318...')
    except:
        LOGGER.exception('failed to start HTTP server on port 8318')
        sys.exit(1)
    httpd.serve_forever()