Files
ykxmz/_build/fix_admin_button.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

119 lines
4.3 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 -*-
"""修管理页删除按钮的幽灵按键。
根因:
生成的 JS 里,字符串字面量中间出现了**真实换行**:
if (!confirm('删除设备「' + name + '」(配对码 ' + code + ')?
'
原因是 Python 源码里写的是普通(非 raw)字符串里的 \\n,
于是变成了真的换行符。对 HTML 来说没问题,
但 JS 里字符串不能跨行 -> SyntaxError -> 整段 script 不执行
-> 所有 onclick 都没绑上 -> 按钮点了没反应("幽灵按键")。
修法:
把 JS 字符串里的换行写成 \\\\n(两个字符:反斜杠 + n),
这样生成的 JS 才是合法的 '...\\n...'。
"""
from __future__ import annotations
import sys
from pathlib import Path
RELAY = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\relay"
r"\relay.py")
# 这几行里的 \n 都在 JS 字符串字面量内部,必须变成 \\n(字面量)
FIXES = [
# 删除确认框
(""" if (!confirm('删除设备「' + name + '」(配对码 ' + code + ')?\\n\\n'""",
""" if (!confirm('删除设备「' + name + '」(配对码 ' + code + ')?\\\\n\\\\n'"""),
(""" + '这会:\\n 1. 断开它现在的手表连接\\n'""",
""" + '这会:\\\\n 1. 断开它现在的手表连接\\\\n'"""),
(""" + ' 2. 从服务器删掉这台设备\\n'""",
""" + ' 2. 从服务器删掉这台设备\\\\n'"""),
(""" + ' 3. 清掉它的配对码绑定')) return;""",
""" + ' 3. 清掉它的配对码绑定')) return;"""),
# 删除成功提示
(""" alert('已删除「' + (j.name || name) + '」\\n'""",
""" alert('已删除「' + (j.name || name) + '」\\\\n'"""),
# 清场确认框
(""" if (!confirm('删除**全部**设备(连同所有配对码)?\\n\\n清场用,删完所有电脑都要重新设码。'))""",
""" if (!confirm('删除**全部**设备(连同所有配对码)?\\\\n\\\\n清场用,删完所有电脑都要重新设码。'))"""),
]
def main() -> int:
text = RELAY.read_text(encoding="utf-8")
ok = True
changed = 0
for old, new in FIXES:
if old == new:
continue
if old in text:
text = text.replace(old, new, 1)
changed += 1
else:
# 可能已经修过(\\n 已经是两个反斜杠)
print(f" [跳过] 锚点没找到(可能已修): {old.strip()[:56]}")
if changed:
RELAY.write_text(text, encoding="utf-8", newline="\n")
print(f" 改了 {changed} 处")
else:
print(" 没有需要改的(可能已修)")
import ast
try:
ast.parse(text)
print(" relay.py 语法 OK")
except SyntaxError as exc:
print(f" relay.py 语法错误: {exc}")
ok = False
# ---------------- 复核:生成的 JS 里不该有跨行字符串 ----------------
print()
print(" 复核:模拟生成 JS,检查有没有字符串跨行")
# 把 f-string 里的 {{ }} 还原成 { },再看每行
import re
start = text.find("<script>")
end = text.find("</script>", start)
if start < 0:
print(" [失败] 找不到 script 段")
return 1
block = text[start:end]
# 粗还原:{{ -> {, }} -> }
rendered = block.replace("{{", "{").replace("}}", "}")
# 把 \\n 变成真正的换行(模拟 Python 的转义)
rendered = rendered.replace("\\\\n", "\n")
bad = []
inside = False
quote = ""
for lineno, line in enumerate(rendered.splitlines(), 1):
stripped = line.strip()
if inside:
# 上一行开了字符串但没闭合
if quote in stripped:
inside = False
else:
bad.append(lineno)
continue
# 统计这一行的单引号(简单判断,忽略转义的)
count = len(re.findall(r"(?<!\\)'", line))
if count % 2 == 1 and "//" not in stripped:
inside = True
quote = "'"
if bad:
print(f" [失败] 这些行是跨行字符串的续行:{bad}")
ok = False
else:
print(" ✓ JS 里没有跨行字符串了")
return 0 if ok else 1
if __name__ == "__main__":
sys.exit(main())