mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 12:30:44 +00:00
被控端 - 修复 MTU 问题:夹 MSS + 路径 MTU 探测(公网可用率 48% -> 100%) - 复用 HTTP 连接(免掉每次新建 TLS 的 30% 握手失败) - 每分钟回头找局域网,自动切回快 400 倍的路径 - 画面心跳帧:静止时省流量,客户端仍知道流是活的 - 锁屏时给出可操作的提示 手表端 - 内置 GTS Root R4 / GlobalSign Root CA,修 SSLHandshakeException - 连接错误翻译成人话(证书/时间/解析/超时分别提示) - 经中转连上后用服务器报的地址刷新已配对记录 - 新增局域网连接页面、服务器延迟检测 服务器端 - 支持 chunked 请求体(修每 16 秒一次的连接错乱与大面积 502) - 网络调优脚本 net-tune.sh(开机自动应用) - 管理页:批量删除、网络体检、下载区 - 隧道改 HTTP/2 + 双连接 文档 - 许可协议 / 安装前必读 / 安装后须知(作者:小麦子)
119 lines
4.4 KiB
Python
119 lines
4.4 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""改名收尾:防火墙规则名 + verify_all 路径。
|
||
|
||
1. firewall.py 的 PROGRAM_RULE_NAMES
|
||
这是"修复防火墙时要删掉哪些旧规则"的清单。
|
||
新程序叫 ykxmz.exe,所以得加进去;
|
||
旧的 lanremote-agent.exe 也**保留** —— 老用户升级上来时,
|
||
那条旧规则还躺在他机器上,不清掉会两条打架。
|
||
|
||
2. _tests/verify_all.ps1 还指向 dist_exe\\LanRemote-Agent
|
||
|
||
3. 测试里的期望值跟着改
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote")
|
||
FIREWALL = ROOT / "windows" / "lanremote" / "firewall.py"
|
||
VERIFY = ROOT / "_tests" / "verify_all.ps1"
|
||
FW_TEST = ROOT / "_tests" / "test_firewall.py"
|
||
|
||
# ---------- 1. firewall.py ----------
|
||
|
||
RULE_OLD = '''PROGRAM_RULE_NAMES = ("lanremote-agent.exe", "python.exe", "pythonw.exe")'''
|
||
RULE_NEW = '''# 修复防火墙时要清掉的旧规则名。
|
||
# ykxmz.exe 是现在的名字;lanremote-agent.exe 是改名前的老名字 ——
|
||
# 保留它,好让老用户升级上来时把旧规则清掉,不然会两条打架。
|
||
PROGRAM_RULE_NAMES = ("ykxmz.exe", "lanremote-agent.exe",
|
||
"python.exe", "pythonw.exe")'''
|
||
|
||
# ---------- 2. verify_all.ps1(注意 BOM)----------
|
||
|
||
VERIFY_OLD = '''$exe = Join-Path $root "dist_exe\\LanRemote-Agent\\LanRemote-Agent.exe"'''
|
||
VERIFY_NEW = '''$exe = Join-Path $root "dist_exe\\ykxmz\\ykxmz.exe"'''
|
||
|
||
VERIFY_PROC_OLD = '''Get-Process LanRemote-Agent -ErrorAction SilentlyContinue |'''
|
||
VERIFY_PROC_NEW = '''Get-Process ykxmz -ErrorAction SilentlyContinue |'''
|
||
|
||
# ---------- 3. 测试期望值 ----------
|
||
|
||
TEST_RULES = [
|
||
('names == {"lanremote-agent.exe"}, str(names))',
|
||
'names == {"ykxmz.exe"}, str(names))'),
|
||
('check("脚本删除了 lanremote-agent.exe 的规则",\n'
|
||
' \'delete rule name="lanremote-agent.exe" dir=in\' in script)',
|
||
'check("脚本删除了 ykxmz.exe 的规则",\n'
|
||
' \'delete rule name="ykxmz.exe" dir=in\' in script)'),
|
||
('zh.get("RuleName") == "lanremote-agent.exe", str(zh.get("RuleName")))',
|
||
'zh.get("RuleName") == "ykxmz.exe", str(zh.get("RuleName")))'),
|
||
('(zh.get("Program") or "").lower().endswith("lanremote-agent.exe"),',
|
||
'(zh.get("Program") or "").lower().endswith("ykxmz.exe"),'),
|
||
('en.get("RuleName") == "lanremote-agent.exe", str(en.get("RuleName")))',
|
||
'en.get("RuleName") == "ykxmz.exe", str(en.get("RuleName")))'),
|
||
]
|
||
|
||
|
||
def main() -> int:
|
||
ok = True
|
||
|
||
# firewall.py
|
||
text = FIREWALL.read_text(encoding="utf-8")
|
||
if "ykxmz.exe" in text:
|
||
print(" firewall.py: 已经改过")
|
||
elif RULE_OLD in text:
|
||
text = text.replace(RULE_OLD, RULE_NEW, 1)
|
||
FIREWALL.write_text(text, encoding="utf-8", newline="\n")
|
||
print(" firewall.py: PROGRAM_RULE_NAMES 加上 ykxmz.exe")
|
||
else:
|
||
print(" [失败] firewall.py 锚点没找到")
|
||
ok = False
|
||
|
||
# verify_all.ps1(保持 BOM)
|
||
raw = VERIFY.read_bytes()
|
||
had_bom = raw.startswith(b"\xef\xbb\xbf")
|
||
text = raw.decode("utf-8-sig")
|
||
changed = 0
|
||
if VERIFY_OLD in text:
|
||
text = text.replace(VERIFY_OLD, VERIFY_NEW, 1)
|
||
changed += 1
|
||
if VERIFY_PROC_OLD in text:
|
||
text = text.replace(VERIFY_PROC_OLD, VERIFY_PROC_NEW, 1)
|
||
changed += 1
|
||
if changed:
|
||
body = text.replace("\r\n", "\n").encode("utf-8")
|
||
VERIFY.write_bytes((b"\xef\xbb\xbf" if had_bom else b"") + body)
|
||
print(f" verify_all.ps1: 改了 {changed} 处(BOM {'保留' if had_bom else '无'})")
|
||
else:
|
||
print(" verify_all.ps1: 没变化")
|
||
|
||
# 测试期望值
|
||
text = FW_TEST.read_text(encoding="utf-8")
|
||
changed = 0
|
||
for old, new in TEST_RULES:
|
||
if old in text:
|
||
text = text.replace(old, new)
|
||
changed += 1
|
||
if changed:
|
||
FW_TEST.write_text(text, encoding="utf-8", newline="\n")
|
||
print(f" 测试期望值: 改了 {changed} 处")
|
||
else:
|
||
print(" 测试期望值: 没变化")
|
||
|
||
# 语法
|
||
import ast
|
||
for label, path in (("firewall.py", FIREWALL), ("test_firewall.py", FW_TEST)):
|
||
try:
|
||
ast.parse(path.read_text(encoding="utf-8"))
|
||
print(f" {label} 语法 OK")
|
||
except SyntaxError as exc:
|
||
print(f" {label} 语法错误: {exc}")
|
||
ok = False
|
||
return 0 if ok else 1
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|