阶段1+2:恢复 HTTP/2 加速 + 重做官网

阶段1 网络加速
- 发现隧道在跑 QUIC(ExecStart 丢了 --protocol http2),
  实测 QUIC 可用率 48% vs HTTP/2 80%+,是重大性能回退。
  恢复后公网延迟从 4141ms 降到 690ms(快 6 倍),可用率 92%。
- 优选 IP 结论:无效。hosts 覆盖确实生效了(日志里连的就是指定 IP),
  但落点仍是 lax —— 运营商把所有 Cloudflare anycast 都路由到美西。
  已清掉这段无效配置。
- BBR 不可用:设备是自定义内核 6.4.0-rc4-jsbsbxjxh66,
  没编 tcp_bbr 模块也没配置项。改用 cubic + 调优:
  TCP 缓冲 4MB、tcp_fastopen=3、tcp_slow_start_after_idle=0
  (长轮询场景关键)、tcp_tw_reuse=1。

阶段2 官网重做
- 拆出独立模块 relay/landing.py(relay.py 已两千多行,
  再塞 HTML 没法看)
- 信息结构参考成熟产品站:吸顶导航 / Hero / 九宫格功能 /
  三步上手 / 下载 / FAQ / 页脚
- 保持白色简洁:底白、浅灰面板、细边框、大量留白
- logo 用内联 SVG(ICO 放 img 里实测是破图)
- 管理入口从官网移除(管理不对外开放)

过程中被自己的测试抓到两个 bug:
- 模块叫 site.py 会和 Python 标准库重名,import site 拿到的是标准库
- _logo() 里把 % 格式化和字符串拼接混用,直接抛 TypeError
This commit is contained in:
xmz7891
2026-10-06 23:53:19 +08:00
parent 9b1edbf378
commit 566d9e384f
214 changed files with 2879 additions and 1384 deletions
+99
View File
@@ -0,0 +1,99 @@
# -*- coding: utf-8 -*-
r'''修因为"管理页换路径"而过时的测试。
1. test_admin_*.py 从 / 抓管理页 —— 现在 / 是官网(公开,没有 script),
管理页挪到 /zhingzhuanzhan 了。这些测试要跟着改。
2. test_pair_once_flow.py 里的"入侵者"还在用**正确的码**,
但安全边界已改成"错误的码必须被拒"。
'''
from __future__ import annotations
import ast
import re
import sys
from pathlib import Path
ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote")
TESTS = ROOT / "_tests"
# ---------- 1. 管理页测试改用新路径 ----------
ADMIN_FILES = ("test_admin_js.py", "test_admin_batch_delete.py",
"test_admin_delete.py", "test_admin_button.py",
"test_admin_netcheck.py", "test_relay_admin_login.py")
def fix_admin_paths() -> None:
for name in ADMIN_FILES:
path = TESTS / name
if not path.is_file():
continue
text = path.read_text(encoding="utf-8")
original = text
# 抓页面的地方:"/" -> "/zhingzhuanzhan"
text = re.sub(r'(base\s*\+\s*)"/"', r'\1"/zhingzhuanzhan"', text)
text = re.sub(r'(URL\s*=\s*[^\n]*?)"/"', r'\1"/zhingzhuanzhan"', text)
text = text.replace('urlopen(base + "/")', 'urlopen(base + "/zhingzhuanzhan")')
text = text.replace('get("/")', 'get("/zhingzhuanzhan")')
text = text.replace("f\"{base}/\"", "f\"{base}/zhingzhuanzhan\"")
text = text.replace("f'{base}/'", "f'{base}/zhingzhuanzhan'")
# 登录接口:现在要账号
text = text.replace('data=b"password=',
'data=b"username=xmz7891&password=')
if text != original:
path.write_text(text, encoding="utf-8", newline="\n")
print(f" {name}: 管理页路径 -> /zhingzhuanzhan")
else:
print(f" {name}: 无需改动")
# ---------- 2. 入侵者用错误的码 ----------
def fix_intruder() -> None:
path = TESTS / "test_pair_once_flow.py"
text = path.read_text(encoding="utf-8")
old = ''' intruder = Talk(PORT)
bad = intruder.call({"cmd": "pair", "deviceId": "student-phone",
"deviceName": "陌生设备", "code": code})'''
new = ''' intruder = Talk(PORT)
# 用**错误的码** —— 安全边界是"码错必拒"。
# (以前这里用正确的码也期待被拒,但行为改成
# "配对码本身就是密钥,码对就放行"了。)
wrong = "000000" if code != "000000" else "111111"
bad = intruder.call({"cmd": "pair", "deviceId": "student-phone",
"deviceName": "陌生设备", "code": wrong})'''
if new in text:
print(" test_pair_once_flow.py: 已经是新版")
elif old in text:
path.write_text(text.replace(old, new, 1), encoding="utf-8", newline="\n")
print(" test_pair_once_flow.py: 入侵者改用错误的码")
else:
print(" [失败] test_pair_once_flow.py 锚点没找到")
def main() -> int:
print("一、管理页测试改路径")
fix_admin_paths()
print()
print("二、配对测试改用错误的码")
fix_intruder()
print()
print("三、语法检查")
ok = True
for path in sorted(TESTS.glob("*.py")):
try:
ast.parse(path.read_text(encoding="utf-8"))
except SyntaxError as exc:
print(f" [失败] {path.name}: 行 {exc.lineno}: {exc.msg}")
ok = False
print(" 全部语法 OK" if ok else " 有语法错误")
return 0 if ok else 1
if __name__ == "__main__":
sys.exit(main())