def req_config_handler(self): req = urlparse.urlparse(self.path).query reqs = urlparse.parse_qs(req, keep_blank_values=True) data = '' appid_updated = False try: if reqs['cmd'] == ['get_config']: data = json.dumps(user_config.user_special, default=lambda o: o.__dict__) elif reqs['cmd'] == ['set_config']: appids = self.postvars['appid'][0] if appids != user_config.user_special.appid: if appids: fail_appid_list = test_appid.test_appids(appids) if len(fail_appid_list): fail_appid = "|".join(fail_appid_list) return self.send_response('text/html', '{"res":"fail", "reason":"appid fail:%s"}' % fail_appid) appid_updated = True user_config.user_special.appid = appids user_config.user_special.password = self.postvars['password'][0] user_config.user_special.proxy_enable = self.postvars['proxy_enable'][0] user_config.user_special.proxy_type = self.postvars['proxy_type'][0] user_config.user_special.proxy_host = self.postvars['proxy_host'][0] user_config.user_special.proxy_port = self.postvars['proxy_port'][0] if not user_config.user_special.proxy_port: user_config.user_special.proxy_port = 0 user_config.user_special.proxy_user = self.postvars['proxy_user'][0] user_config.user_special.proxy_passwd = self.postvars['proxy_passwd'][0] user_config.user_special.host_appengine_mode = self.postvars['host_appengine_mode'][0] use_ipv6 = int(self.postvars['use_ipv6'][0]) if user_config.user_special.use_ipv6 != use_ipv6: if use_ipv6: if not check_ip.check_ipv6(): xlog.warn("Enable Ipv6 but check failed.") return self.send_response('text/html', '{"res":"fail", "reason":"IPv6 fail"}') user_config.user_special.use_ipv6 = use_ipv6 user_config.save() config.load() appid_manager.reset_appid() import connect_manager connect_manager.load_proxy_config() connect_manager.https_manager.load_config() if appid_updated: connect_manager.https_manager.clean_old_connection() google_ip.reset() check_ip.load_proxy_config() data = '{"res":"success"}' self.send_response('text/html', data) #http_request("http://127.0.0.1:8085/init_module?module=gae_proxy&cmd=restart") return except Exception as e: xlog.exception("req_config_handler except:%s", e) data = '{"res":"fail", "except":"%s"}' % e self.send_response('text/html', data)
def run(args): global proc_handler, ready, g if not proc_handler: return False if "gae_proxy" in proc_handler: g.gae_proxy = proc_handler["gae_proxy"]["imp"].local else: xlog.debug("gae_proxy not running") if "x_tunnel" in proc_handler: g.x_tunnel = proc_handler["x_tunnel"]["imp"].local else: xlog.debug("x_tunnel not running") load_config() g.gfwlist = gfwlist.GfwList() g.ip_region = ip_region.IpRegion() g.domain_cache = host_records.DomainRecords( os.path.join(data_path, "domain_records.txt"), capacity=g.config.dns_cache_size, ttl=g.config.dns_ttl) g.ip_cache = host_records.IpRecord(os.path.join(data_path, "ip_records.txt"), capacity=g.config.ip_cache_size) g.user_rules = user_rules.Config() connect_manager.load_proxy_config() g.connect_manager = connect_manager.ConnectManager() g.pipe_socks = pipe_socks.PipeSocks(g.config.pip_cache_size) g.pipe_socks.run() g.dns_client = dns_server.DnsClient() allow_remote = args.get("allow_remote", 0) if allow_remote: listen_ip = "0.0.0.0" else: listen_ip = g.config.proxy_bind_ip g.proxy_server = simple_http_server.HTTPServer( (listen_ip, g.config.proxy_port), proxy_handler.ProxyServer, logger=xlog) g.proxy_server.start() xlog.info("Proxy server listen:%s:%d.", listen_ip, g.config.proxy_port) allow_remote = args.get("allow_remote", 0) if allow_remote: listen_ip = "0.0.0.0" else: listen_ip = g.config.dns_bind_ip g.dns_srv = dns_server.DnsServer(bind_ip=listen_ip, port=g.config.dns_port, backup_port=g.config.dns_backup_port, ttl=g.config.dns_ttl) ready = True g.dns_srv.server_forever()
def run(args): global proc_handler, ready, g if not proc_handler: return False if "gae_proxy" in proc_handler: g.gae_proxy = proc_handler["gae_proxy"]["imp"].local g.gae_proxy_listen_port = g.gae_proxy.config.config.listen_port else: xlog.debug("gae_proxy not running") if "x_tunnel" in proc_handler: g.x_tunnel = proc_handler["x_tunnel"]["imp"].local g.x_tunnel_socks_port = g.x_tunnel.global_var.config.socks_port else: xlog.debug("x_tunnel not running") load_config() g.gfwlist = gfwlist.GfwList() g.ip_region = ip_region.IpRegion() g.domain_cache = host_records.DomainRecords(os.path.join(data_path, "domain_records.txt"), capacity=g.config.dns_cache_size, ttl=g.config.dns_ttl) g.ip_cache = host_records.IpRecord(os.path.join(data_path, "ip_records.txt"), capacity=g.config.ip_cache_size) g.user_rules = user_rules.Config() connect_manager.load_proxy_config() g.connect_manager = connect_manager.ConnectManager() g.pipe_socks = pipe_socks.PipeSocks(g.config.pip_cache_size) g.pipe_socks.run() g.dns_client = dns_server.DnsClient() allow_remote = args.get("allow_remote", 0) if allow_remote: listen_ip = "0.0.0.0" else: listen_ip = g.config.proxy_bind_ip g.proxy_server = simple_http_server.HTTPServer((listen_ip, g.config.proxy_port), proxy_handler.ProxyServer, logger=xlog) g.proxy_server.start() xlog.info("Proxy server listen:%s:%d.", listen_ip, g.config.proxy_port) allow_remote = args.get("allow_remote", 0) if allow_remote: listen_ip = "0.0.0.0" else: listen_ip = g.config.dns_bind_ip g.dns_srv = dns_server.DnsServer( bind_ip=listen_ip, port=g.config.dns_port, backup_port=g.config.dns_backup_port, ttl=g.config.dns_ttl) ready = True g.dns_srv.server_forever()
def req_config_handler(self): req = urlparse.urlparse(self.path).query reqs = urlparse.parse_qs(req, keep_blank_values=True) data = '' try: if reqs['cmd'] == ['get_config']: data = json.dumps(user_config.user_special, default=lambda o: o.__dict__) elif reqs['cmd'] == ['set_config']: user_config.user_special.appid = self.postvars['appid'][0] user_config.user_special.password = self.postvars['password'][ 0] user_config.user_special.proxy_enable = self.postvars[ 'proxy_enable'][0] user_config.user_special.proxy_type = self.postvars[ 'proxy_type'][0] user_config.user_special.proxy_host = self.postvars[ 'proxy_host'][0] user_config.user_special.proxy_port = self.postvars[ 'proxy_port'][0] user_config.user_special.proxy_user = self.postvars[ 'proxy_user'][0] user_config.user_special.proxy_passwd = self.postvars[ 'proxy_passwd'][0] user_config.user_special.host_appengine_mode = self.postvars[ 'host_appengine_mode'][0] user_config.user_special.ip_connect_interval = int( self.postvars['ip_connect_interval'][0]) user_config.user_special.use_ipv6 = int( self.postvars['use_ipv6'][0]) user_config.user_special.connect_interval = int( self.postvars['connect_interval'][0]) user_config.save() config.load() appid_manager.reset_appid() import connect_manager connect_manager.load_proxy_config() connect_manager.https_manager.load_config() connect_manager.forwork_manager.load_config() google_ip.reset() check_ip.load_proxy_config() data = '{"res":"success"}' self.send_response('text/html', data) #http_request("http://127.0.0.1:8085/init_module?module=gae_proxy&cmd=restart") return except Exception as e: xlog.exception("req_config_handler except:%s", e) data = '{"res":"fail", "except":"%s"}' % e self.send_response('text/html', data)
def set_proxy(args): xlog.info("set_proxy:%s", args) g.config.PROXY_ENABLE = args["enable"] g.config.PROXY_TYPE = args["type"] g.config.PROXY_HOST = args["host"] try: g.config.PROXY_PORT = int(args["port"]) except: g.config.PROXY_POT = 0 g.config.PROXY_USER = args["user"] g.config.PROXY_PASSWD = args["passwd"] g.config.save() connect_manager.load_proxy_config()
def req_config_handler(self): req = urlparse.urlparse(self.path).query reqs = urlparse.parse_qs(req, keep_blank_values=True) data = "" try: if reqs["cmd"] == ["get_config"]: data = json.dumps(user_config.user_special, default=lambda o: o.__dict__) elif reqs["cmd"] == ["set_config"]: user_config.user_special.appid = self.postvars["appid"][0] user_config.user_special.password = self.postvars["password"][0] user_config.user_special.proxy_enable = self.postvars["proxy_enable"][0] user_config.user_special.proxy_type = self.postvars["proxy_type"][0] user_config.user_special.proxy_host = self.postvars["proxy_host"][0] user_config.user_special.proxy_port = self.postvars["proxy_port"][0] user_config.user_special.proxy_user = self.postvars["proxy_user"][0] user_config.user_special.proxy_passwd = self.postvars["proxy_passwd"][0] user_config.user_special.host_appengine_mode = self.postvars["host_appengine_mode"][0] user_config.user_special.ip_connect_interval = int(self.postvars["ip_connect_interval"][0]) user_config.user_special.use_ipv6 = int(self.postvars["use_ipv6"][0]) user_config.user_special.connect_interval = int(self.postvars["connect_interval"][0]) user_config.save() config.load() appid_manager.reset_appid() import connect_manager connect_manager.load_proxy_config() connect_manager.https_manager.load_config() connect_manager.forwork_manager.load_config() google_ip.reset() check_ip.load_proxy_config() data = '{"res":"success"}' self.send_response("text/html", data) # http_request("http://127.0.0.1:8085/init_module?module=gae_proxy&cmd=restart") return except Exception as e: xlog.exception("req_config_handler except:%s", e) data = '{"res":"fail", "except":"%s"}' % e self.send_response("text/html", data)
def req_config_handler(self): req = urlparse.urlparse(self.path).query reqs = urlparse.parse_qs(req, keep_blank_values=True) data = '' appid_updated = False try: if reqs['cmd'] == ['get_config']: data = json.dumps(user_config.user_special, default=lambda o: o.__dict__) elif reqs['cmd'] == ['set_config']: appids = self.postvars['appid'][0] if appids != user_config.user_special.appid: if appids and google_ip.good_ip_num: fail_appid_list = test_appid.test_appids(appids) if len(fail_appid_list): fail_appid = "|".join(fail_appid_list) return self.send_response_nc( 'text/html', '{"res":"fail", "reason":"appid fail:%s"}' % fail_appid) appid_updated = True user_config.user_special.appid = appids user_config.user_special.proxy_enable = self.postvars[ 'proxy_enable'][0] user_config.user_special.proxy_type = self.postvars[ 'proxy_type'][0] user_config.user_special.proxy_host = self.postvars[ 'proxy_host'][0] user_config.user_special.proxy_port = self.postvars[ 'proxy_port'][0] try: user_config.user_special.proxy_port = int( user_config.user_special.proxy_port) except: user_config.user_special.proxy_port = 0 user_config.user_special.proxy_user = self.postvars[ 'proxy_user'][0] user_config.user_special.proxy_passwd = self.postvars[ 'proxy_passwd'][0] user_config.user_special.host_appengine_mode = self.postvars[ 'host_appengine_mode'][0] use_ipv6 = int(self.postvars['use_ipv6'][0]) if user_config.user_special.use_ipv6 != use_ipv6: if use_ipv6: if not check_local_network.check_ipv6(): xlog.warn("IPv6 was enabled, but check failed.") return self.send_response_nc( 'text/html', '{"res":"fail", "reason":"IPv6 fail"}') user_config.user_special.use_ipv6 = use_ipv6 user_config.save() config.load() appid_manager.reset_appid() import connect_manager connect_manager.load_proxy_config() connect_manager.https_manager.load_config() if appid_updated: http_dispatch.close_all_worker() google_ip.reset() check_ip.load_proxy_config() data = '{"res":"success"}' self.send_response_nc('text/html', data) #http_request("http://127.0.0.1:8085/init_module?module=gae_proxy&cmd=restart") return except Exception as e: xlog.exception("req_config_handler except:%s", e) data = '{"res":"fail", "except":"%s"}' % e self.send_response_nc('text/html', data)