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 handle_free_internet_connect(environ, start_response):
    global is_free_internet_connected
    is_free_internet_connected = True
    args = config.configure_fqsocks([])
    argument_parser = argparse.ArgumentParser()
    argument_parser.add_argument('--proxy', action='append', default=[])
    args, _ = argument_parser.parse_known_args(args)
    for props in args.proxy:
        props = props.split(',')
        prop_dict = dict(p.split('=') for p in props[1:])
        fqsocks.gateways.proxy_client.add_proxies(props[0], prop_dict)
    fqsocks.gateways.proxy_client.last_refresh_started_at = 0
    gevent.spawn(fqsocks.gateways.proxy_client.init_proxies)
    start_response(httplib.OK, [('Content-Type', 'text/plain')])
    return []
Beispiel #4
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 #5
0
     gevent.monkey.patch_ssl()
 except:
     LOGGER.exception('failed to patch ssl')
 args = [
     '--log-level',
     'INFO',
     '--log-file',
     '/data/data/fq.router2/log/fqsocks.log',
     '--tcp-gateway-listen',
     '10.25.1.1:12345',
     '--dns-server-listen',
     '10.25.1.1:12345',
     '--no-http-manager',  # already started before
     '--no-tcp-scrambler',  # no root permission
 ]
 args = config.configure_fqsocks(args)
 fqsocks.fqsocks.init_config(args)
 fqsocks.config_file.path = '/data/data/fq.router2/etc/fqsocks.json'
 http_manager_port = fqsocks.config_file.read_config(
 )['http_manager']['port']
 try:
     response = urllib2.urlopen(
         'http://127.0.0.1:%s/exit' % http_manager_port, '').read()
     if 'EXITING' == response:
         LOGGER.critical('!!! find previous instance, exiting !!!')
         gevent.sleep(3)
 except:
     LOGGER.exception('failed to exit previous')
 fqsocks.httpd.LISTEN_IP, fqsocks.httpd.LISTEN_PORT = '', http_manager_port
 fqsocks.httpd.server_greenlet = gevent.spawn(fqsocks.httpd.serve_forever)
 try:
Beispiel #6
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 #7
0
    except:
        LOGGER.exception('failed to patch ssl')
    fqsocks.config_file.path = '/data/data/fq.router2/etc/fqsocks.json'
    http_manager_port = fqsocks.config_file.read_config()['http_manager']['port']
    try:
        response = urllib2.urlopen('http://127.0.0.1:%s/exit' % http_manager_port, '').read()
        if 'EXITING' == response:
            LOGGER.critical('!!! find previous instance, exiting !!!')
            gevent.sleep(3)
    except:
        LOGGER.exception('failed to exit previous')
    fqsocks.httpd.LISTEN_IP, fqsocks.httpd.LISTEN_PORT = '', http_manager_port
    fqsocks.httpd.server_greenlet = gevent.spawn(fqsocks.httpd.serve_forever)
    try:
        tun_fd = read_tun_fd_until_ready()
        LOGGER.info('tun fd: %s' % tun_fd)
    except:
        LOGGER.exception('failed to get tun fd')
        sys.exit(1)
    greenlet = gevent.spawn(redirect_tun_traffic, tun_fd)
    args = [
        '--log-level', 'INFO',
        '--log-file', '/data/data/fq.router2/log/fqsocks.log',
        '--tcp-gateway-listen', '10.25.1.1:12345',
        '--dns-server-listen', '10.25.1.1:12345',
        '--no-http-manager', # already started before
    ]
    args = config.configure_fqsocks(args)
    gevent.spawn(fqsocks.fqsocks.main, args)
    greenlet.join()