fqsocks.networking.DNS_HANDLER = DNS_HANDLER if '__main__' == __name__: setup_logging() LOGGER.info('running vpn.py') LOGGER.info('environment: %s' % os.environ.items()) LOGGER.info('default dns server: %s' % default_dns_server) # FQROUTER_VERSION = os.getenv('FQROUTER_VERSION') try: gevent.monkey.patch_ssl() except: LOGGER.exception('failed to patch ssl') teredo_sock = create_teredo_sock_until_ready() teredo_client = teredo.teredo_client(teredo_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_client.server_forever(default_loacl_teredo_ip) send_message('TEREDO FAIL,%s' % default_loacl_teredo_ip) else: LOGGER.info('teredo start succeed, teredo ip:%s' % teredo_ip) teredo_client.server_forever(teredo_ip) send_message('TEREDO READY,%s' % teredo_ip) TUN_IP = sys.argv[1]
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()
fqsocks.networking.DNS_HANDLER = DNS_HANDLER if '__main__' == __name__: setup_logging() LOGGER.info('running vpn.py') LOGGER.info('environment: %s' % os.environ.items()) LOGGER.info('default dns server: %s' % default_dns_server) # FQROUTER_VERSION = os.getenv('FQROUTER_VERSION') try: gevent.monkey.patch_ssl() except: LOGGER.exception('failed to patch ssl') teredo_sock = create_teredo_sock_until_ready() teredo_client = teredo.teredo_client(teredo_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_client.server_forever(default_loacl_teredo_ip) send_message('TEREDO FAIL,%s' % default_loacl_teredo_ip) else: LOGGER.info('teredo start succeed, teredo ip:%s' % teredo_ip) teredo_client.server_forever(teredo_ip) send_message('TEREDO READY,%s' % teredo_ip)