Skip to content

Commit

Permalink
5.3.2, fix GAE web_control bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-X-Net committed Jul 10, 2023
1 parent 99e09fe commit 5a9c075
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 31 deletions.
40 changes: 23 additions & 17 deletions code/default/gae_proxy/local/web_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,18 @@ def do_POST(self):
def req_log_handler(self):
req = urlparse(self.path).query
reqs = parse_qs(req, keep_blank_values=True)
reqs = self.unpack_reqs(reqs)
data = ''

cmd = "get_last"
if reqs["cmd"]:
cmd = reqs["cmd"][0]
cmd = reqs["cmd"]

if cmd == "get_last":
max_line = int(reqs["max_line"][0])
max_line = int(reqs["max_line"])
data = xlog.get_last_lines(max_line)
elif cmd == "get_new":
last_no = int(reqs["last_no"][0])
last_no = int(reqs["last_no"])
data = xlog.get_new_lines(last_no)
else:
xlog.error('WebUI log from:%s unknown cmd:%s path:%s ', self.address_string(), self.command, self.path)
Expand Down Expand Up @@ -368,7 +369,7 @@ def req_config_handler(self):
}
data = json.dumps(ret_config, default=lambda o: o.__dict__)
elif reqs['cmd'] == ['set_config']:
appids = self.postvars['appid'][0]
appids = self.postvars['appid']
if appids != "|".join(config.GAE_APPIDS):
if appids and (front.ip_manager.good_ipv4_num + front.ip_manager.good_ipv6_num):
fail_appid_list = test_appids(appids)
Expand Down Expand Up @@ -398,7 +399,7 @@ def req_config_handler(self):
data = '{"res":"success"}'
#http_request("http://127.0.0.1:8085/init_module?module=gae_proxy&cmd=restart")
elif reqs['cmd'] == ['set_config_level']:
setting_level = self.postvars['setting_level'][0]
setting_level = self.postvars['setting_level']
if setting_level:
xlog.info("set globa config level to %s", setting_level)
config.set_level(setting_level)
Expand All @@ -408,7 +409,7 @@ def req_config_handler(self):
front.ip_manager.remove_slowest_ip()
front.ip_manager.search_more_ip()

connect_receive_buffer = int(self.postvars['connect_receive_buffer'][0])
connect_receive_buffer = int(self.postvars['connect_receive_buffer'])
if 8192 <= connect_receive_buffer <= 2097152 and connect_receive_buffer != config.connect_receive_buffer:
xlog.info("set connect receive buffer to %dKB", connect_receive_buffer // 1024)
config.connect_receive_buffer = connect_receive_buffer
Expand Down Expand Up @@ -438,8 +439,8 @@ def req_deploy_handler(self):
time_now = datetime.datetime.today().strftime('%H:%M:%S-%a/%d/%b/%Y')

if reqs['cmd'] == ['deploy']:
appid = self.postvars['appid'][0]
debug = int(self.postvars['debug'][0])
appid = self.postvars['appid']
debug = int(self.postvars['debug'])

if deploy_proc and deploy_proc.poll() == None:
xlog.warn("deploy is running, request denied.")
Expand Down Expand Up @@ -495,7 +496,7 @@ def req_importip_handler(self):

if reqs['cmd'] == ['importip']:
count = 0
ip_list = self.postvars['ipList'][0]
ip_list = self.postvars['ipList']
lines = ip_list.split("\n")
for line in lines:
addresses = line.split('|')
Expand All @@ -522,8 +523,9 @@ def req_importip_handler(self):
def req_test_ip_handler(self):
req = urlparse(self.path).query
reqs = parse_qs(req, keep_blank_values=True)
reqs = self.unpack_reqs(reqs)

ip = reqs['ip'][0]
ip = reqs['ip']
result = front.check_ip.check_ip(ip)
if not result or not result.ok:
data = "{'res':'fail'}"
Expand Down Expand Up @@ -596,12 +598,14 @@ def req_ip_list_handler(self):
def req_scan_ip_handler(self):
req = urlparse(self.path).query
reqs = parse_qs(req, keep_blank_values=True)
reqs = self.unpack_reqs(reqs)

data = ""
if reqs['cmd'] == ['get_range']:
if reqs['cmd'] == 'get_range':
data = front.ipv4_source.load_range_content()
elif reqs['cmd'] == ['update']:
elif reqs['cmd'] == 'update':
#update ip_range if needed
content = self.postvars['ip_range'][0]
content = self.postvars['ip_range']

#check ip_range checksums, update if needed
default_digest = hashlib.md5(utils.to_bytes(front.ipv4_source.load_range_content(default=True))).hexdigest()
Expand All @@ -619,10 +623,10 @@ def req_scan_ip_handler(self):
front.ipv4_source.load_ip_range()

#update auto_adjust_scan_ip and scan_ip_thread_num
should_auto_adjust_scan_ip = int(self.postvars['auto_adjust_scan_ip_thread_num'][0])
thread_num_for_scan_ip = int(self.postvars['scan_ip_thread_num'][0])
should_auto_adjust_scan_ip = int(self.postvars['auto_adjust_scan_ip_thread_num'])
thread_num_for_scan_ip = int(self.postvars['scan_ip_thread_num'])

use_ipv6 = self.postvars['use_ipv6'][0]
use_ipv6 = self.postvars['use_ipv6']
if config.use_ipv6 != use_ipv6:
xlog.debug("use_ipv6 change to %s", use_ipv6)
config.use_ipv6 = use_ipv6
Expand Down Expand Up @@ -719,6 +723,7 @@ def req_debug_handler(self):
def req_ipv6_tunnel_handler(self):
req = urlparse(self.path).query
reqs = parse_qs(req, keep_blank_values=True)
reqs = self.unpack_reqs(reqs)
data = ''

log_path = os.path.join(data_path, "ipv6_tunnel.log")
Expand All @@ -733,7 +738,7 @@ def req_ipv6_tunnel_handler(self):
['test_teredo_usability'],
['test_teredo_server'],
['set_best_server']]:
cmd = reqs['cmd'][0]
cmd = reqs['cmd']
xlog.info("ipv6_tunnel switch %s", cmd)

# Don't remove log file at here.
Expand All @@ -752,6 +757,7 @@ def req_ipv6_tunnel_handler(self):
result = ipv6_tunnel.set_best_server(is_local)
else:
xlog.warn("unknown cmd:%s", cmd)
result = None

xlog.info("ipv6_tunnel switch %s, result: %s", cmd, result)

Expand Down
6 changes: 3 additions & 3 deletions code/default/launcher/tests/integrate_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ def xtunnel_login(self):
"Content-Type": "application/json"
}
data = {
"username": [os.getenv("XTUNNEL_USER"),],
"password": [os.getenv("XTUNNEL_PASS"),],
"is_register": [0,]
"username": os.getenv("XTUNNEL_USER"),
"password": os.getenv("XTUNNEL_PASS"),
"is_register": 0
}
data = json.dumps(data)
res = simple_http_client.request("POST", "http://127.0.0.1:8085/module/x_tunnel/control/login",
Expand Down
2 changes: 1 addition & 1 deletion code/default/lib/noarch/front_base/ip_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ def scan_ip_worker(self):
self.scan_fail_count = 0
else:
self.scan_fail_count += 1
if self.scan_fail_count / self.scan_thread_count > 3:
if self.scan_thread_count and self.scan_fail_count / self.scan_thread_count > 3:
self.scan_fail_count = 0
self.check_local_network.report_fail(ip_str)
recheck_ip = True
Expand Down
6 changes: 3 additions & 3 deletions code/default/lib/tests/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_get(self):
print(data)

def test_get2(self):
url = "https://raw.githubusercontent.com/XX-net/XX-Net/master/code/default/update_v4.txt"
url = "https://raw.githubusercontent.com/XX-net/XX-Net/master/code/default/update_v5.txt"

client = simple_http_client.Client(timeout=10)
res = client.request("GET", url)
Expand All @@ -34,14 +34,14 @@ def test_get_fail(self):
def test_get_bulk(self):
timeout = 5
client = simple_http_client.Client(timeout=timeout)
url = "https://raw.githubusercontent.com/XX-net/XX-Net/master/code/default/update_v4.txt"
url = "https://raw.githubusercontent.com/XX-net/XX-Net/master/code/default/update_v5.txt"

start_time = time.time()
req = client.request("GET", url, read_payload=False)
self.assertIsNotNone(req)

tp = tempfile.gettempdir()
filename = os.path.join(tp, "v4.txt")
filename = os.path.join(tp, "v5.txt")
if req.chunked:
downloaded = 0
with open(filename, 'wb') as fp:
Expand Down
2 changes: 1 addition & 1 deletion code/default/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.3.1
5.3.2
22 changes: 16 additions & 6 deletions code/default/x_tunnel/local/cloudflare_front/ip_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,30 @@ def get_ip_sni_host(self):

return None, None, None

def _get_domain(self, top_domain):
self.domain_map.setdefault(top_domain, {
"links": 0,
"fail_times": 0
})
return self.domain_map[top_domain]

def report_connect_fail(self, ip_str, sni=None, reason=""):
ip, _ = utils.get_ip_port(ip_str)
ip = utils.to_str(ip)
top_domain = ".".join(sni.split(".")[1:])

self.domain_map[top_domain]["fail_times"] += 1
self.domain_map[top_domain]["links"] -= 1
info = self._get_domain(top_domain)
info["fail_times"] += 1
info["links"] -= 1
self.logger.debug("ip %s sni:%s connect fail, reason:%s", ip, sni, reason)

def update_ip(self, ip_str, sni, handshake_time):
ip, _ = utils.get_ip_port(ip_str)
ip = utils.to_str(ip)
# ip, _ = utils.get_ip_port(ip_str)
# ip = utils.to_str(ip)
top_domain = ".".join(sni.split(".")[1:])

self.domain_map[top_domain]["fail_times"] = 0
info = self._get_domain(top_domain)
info["fail_times"] = 0
# self.logger.debug("ip %s sni:%s connect success, rtt:%f", ip, sni, handshake_time)

def ssl_closed(self, ip_str, sni=None, reason=""):
Expand All @@ -97,7 +106,8 @@ def ssl_closed(self, ip_str, sni=None, reason=""):
top_domain = ".".join(sni.split(".")[1:])

try:
self.domain_map[top_domain]["links"] -= 1
info = self._get_domain(top_domain)
info["links"] -= 1
self.logger.debug("ip %s sni:%s connect closed reason %s", ip, sni, reason)
except Exception as e:
self.logger.warn("ssl_closed %s sni:%s reason:%s except:%r", ip_str, sni, reason, e)

0 comments on commit 5a9c075

Please sign in to comment.