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 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 #4
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()