Files
ykxmz/_build/patch_fw_severity.py
xmz7891 b62ac865ea ykxmz 1.5.0:修复手表端 TLS 证书校验 + MTU 修复网络稳定性
被控端
- 修复 MTU 问题:夹 MSS + 路径 MTU 探测(公网可用率 48% -> 100%)
- 复用 HTTP 连接(免掉每次新建 TLS 的 30% 握手失败)
- 每分钟回头找局域网,自动切回快 400 倍的路径
- 画面心跳帧:静止时省流量,客户端仍知道流是活的
- 锁屏时给出可操作的提示

手表端
- 内置 GTS Root R4 / GlobalSign Root CA,修 SSLHandshakeException
- 连接错误翻译成人话(证书/时间/解析/超时分别提示)
- 经中转连上后用服务器报的地址刷新已配对记录
- 新增局域网连接页面、服务器延迟检测

服务器端
- 支持 chunked 请求体(修每 16 秒一次的连接错乱与大面积 502)
- 网络调优脚本 net-tune.sh(开机自动应用)
- 管理页:批量删除、网络体检、下载区
- 隧道改 HTTP/2 + 双连接

文档
- 许可协议 / 安装前必读 / 安装后须知(作者:小麦子)
2026-10-06 19:01:05 +08:00

192 lines
7.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""修正防火墙检测的措辞分级。
原来的问题:
ok = 端口放行 and 程序级放行 and 无阻止规则
只要"程序级规则"不存在或路径对不上,就报「防火墙未放行,手表连不上」——
但如果端口放行规则在、又没有阻止规则,实际上**是能连上的**,
这样报红属于误报,会让人白折腾。
改成三级:
ok 完全正常
warn 现在能连,但程序级规则不对,以后可能复发(黄色提示)
error 连不上,必须修(红色提示)
"""
from __future__ import annotations
import ast
import sys
from pathlib import Path
ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote")
FIREWALL = ROOT / "windows" / "lanremote" / "firewall.py"
UI = ROOT / "windows" / "lanremote" / "ui.py"
OLD_CHECK = ''' tcp = rule_exists(RULE_TCP)
udp = rule_exists(RULE_UDP)
app_rule = app_rule_ok()
blocked = list_block_rules()
elevated = is_elevated()
# 有阻止规则时,放行规则等于无效
ok = tcp and udp and app_rule and not blocked
if ok:
message = "防火墙已放行"
elif blocked:
message = f"存在 {len(blocked)} 条阻止规则(优先级高于放行,必须清掉)"
elif not app_rule:
want = executable_path()
got = app_rule_program()
if app_rule_exists() and got and want:
message = ("程序级放行规则指向的不是当前程序"
f"(规则={os.path.basename(got)},"
f"实际={os.path.basename(want)}),"
"系统仍会重建阻止规则")
else:
message = ("缺少程序级放行规则:系统会反复重建阻止规则,"
"需要修复一次才能根治")
elif elevated:
message = "防火墙未放行(当前是管理员,可直接修复)"
else:
message = "防火墙未放行,其他设备无法连接"
'''
NEW_CHECK = ''' tcp = rule_exists(RULE_TCP)
udp = rule_exists(RULE_UDP)
app_rule = app_rule_ok()
blocked = list_block_rules()
elevated = is_elevated()
# 「能不能连上」只看两件事:端口放行在不在 + 有没有阻止规则。
# 程序级放行影响的是「以后会不会复发」,不影响当下能不能连。
ok = tcp and udp and not blocked
if not ok:
severity = "error"
if blocked:
message = f"存在 {len(blocked)} 条阻止规则(优先级高于放行,必须清掉)"
elif not (tcp and udp):
message = ("端口放行规则缺失,其他设备连不上"
if not elevated
else "端口放行规则缺失(当前是管理员,可直接修复)")
else:
message = "防火墙未放行,其他设备无法连接"
elif not app_rule:
severity = "warn"
got = app_rule_program()
if app_rule_exists() and got:
message = ("能连上。但程序级放行规则指向的不是当前这份程序,"
"以后系统可能再生成阻止规则,建议修复一次")
else:
message = ("能连上。但缺少程序级放行规则,"
"以后系统可能再生成阻止规则,建议修复一次")
else:
severity = "ok"
message = "防火墙已放行"
'''
OLD_RETURN = ''' "blocked_count": len(blocked),
"ok": ok,
"elevated": elevated,
"message": message,
'''
NEW_RETURN = ''' "blocked_count": len(blocked),
"ok": ok,
"severity": severity,
"elevated": elevated,
"message": message,
'''
OLD_UI = ''' def refresh_firewall(self) -> None:
port = self.server.port if self.server else 8765
status = firewall_check(port, DISCOVERY_PORT)
self._firewall_ok = bool(status.get("ok"))
'''
NEW_UI = ''' def refresh_firewall(self) -> None:
port = self.server.port if self.server else 8765
status = firewall_check(port, DISCOVERY_PORT)
severity = str(status.get("severity") or ("ok" if status.get("ok") else "error"))
self._firewall_ok = severity == "ok"
'''
OLD_UI_MSG = ''' blocked = int(status.get("blocked_count") or 0)
if blocked:
# 真机上最常见的坑:阻止规则优先级高于放行规则
text = (f"检测到 {blocked} 条「阻止」规则,它压过「放行」。\\n"
f"手表能搜到但连不上。\\n"
f"点右边按钮清理(需管理员确认)")
else:
text = ("防火墙未放行,手表连不上。\\n"
"点右边按钮自动放行(需管理员确认)")
'''
NEW_UI_MSG = ''' blocked = int(status.get("blocked_count") or 0)
if severity == "warn":
# 现在能连,但规则不完整,以后可能复发 —— 用黄色轻提示
text = ("能连上,但程序级放行规则不完整,\\n"
"以后系统可能再生成阻止规则。\\n"
"建议顺手修一次(需管理员确认)")
box_bg, box_line = "#fff8c5", "#d4a72c"
else:
box_bg, box_line = "#ffeef0", "#cf222e"
if blocked:
# 真机上最常见的坑:阻止规则优先级高于放行规则
text = (f"检测到 {blocked} 条「阻止」规则,它压过「放行」。\\n"
f"手表能搜到但连不上。\\n"
f"点右边按钮清理(需管理员确认)")
else:
text = ("防火墙未放行,手表连不上。\\n"
"点右边按钮自动放行(需管理员确认)")
try:
self.fire_box.configure(bg=box_bg, highlightbackground=box_line)
self.lbl_fire.configure(bg=box_bg,
fg=WARN if severity == "warn" else DANGER)
self.btn_fire.configure(bg=WARN if severity == "warn" else DANGER)
except tk.TclError:
pass
'''
def main() -> int:
ok = True
text = FIREWALL.read_text(encoding="utf-8")
for old, new, tag in ((OLD_CHECK, NEW_CHECK, "check分级"),
(OLD_RETURN, NEW_RETURN, "返回severity")):
if old not in text:
print(f" [失败] firewall.py {tag} 未匹配")
ok = False
else:
text = text.replace(old, new, 1)
if ok:
FIREWALL.write_text(text, encoding="utf-8")
print(" firewall.py: 已改为 ok/warn/error 三级")
text = UI.read_text(encoding="utf-8")
for old, new, tag in ((OLD_UI, NEW_UI, "refresh_firewall"),
(OLD_UI_MSG, NEW_UI_MSG, "提示文案")):
if old not in text:
print(f" [失败] ui.py {tag} 未匹配")
ok = False
else:
text = text.replace(old, new, 1)
if ok:
UI.write_text(text, encoding="utf-8")
print(" ui.py: 警告条区分黄色(建议)与红色(必须)")
print("\n语法检查:")
for name, path in (("firewall.py", FIREWALL), ("ui.py", UI)):
try:
ast.parse(path.read_text(encoding="utf-8"))
print(f" {name}: OK")
except SyntaxError as exc:
print(f" {name}: 语法错误 {exc}")
ok = False
return 0 if ok else 1
if __name__ == "__main__":
sys.exit(main())