mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 17:10:43 +00:00
用户报了三件事,一起处理。
== 一、发行版介绍里泄漏了服务器公网 IP ==
_build/CHANGELOG.md 的 2.1.3 那节写了服务器公网 IP,而发布脚本
把这个文件当"更新说明"传给 Gitee,于是发行版介绍里就带出去了。
为什么 IP 不该公开:直接打 IP 就绕过 Cloudflare 了 ——
没有 CDN、没有防护、没有速率限制。源站本来就不该被人知道是谁
(这也是为什么 nginx 那层只认域名、中转只绑 127.0.0.1)。
处理:
* 已发的 v2.1.3 发行版介绍用 API 改掉(扫了全部 11 个发行版,只它一个)
* 仓库里 16 个文件里的 IP 全部换成域名或占位符
* 运维脚本改成从环境变量读,公开仓库里不留具体地址
顺手发现**更严重的一处**:旧管理员密码硬编码在
docs/AFTER-INSTALL.txt(会打进服务端 zip)和
installer/license-combined.txt(**安装包的许可页,每个装的人都能看到**)里。
而用户当前密码就含这个串,等于公开了一半。一并清掉,
公开材料里改成"密码在你服务器上"的说明。
== 二、手表端填了地址却连不上 ==
用户截图:填域名(没写协议头)-> 点「检查服务器」报
MalformedURLException: no protocol: <域名>/v1/health
根因:补协议头的逻辑只写在连接那条路(RelayTransport 的构造函数)上,
checkServer() 直接拿原始字符串拼 URL —— 同一个地址,连接能用、检查却崩。
修法:把规范化收到 relayUrl() 这**唯一一个入口**,所有调用方都从那里取。
规则和电脑端一致:IP / localhost / *.local -> http,域名 -> https。
顺带补了 _tests/test_relay_url_normalize.py 盯住它(含 9 个用例实算)。
== 三、Gitee 的 README 被判"可能含有违规信息" ==
Gitee 挂的是软性公告(可自行修改或申诉),但确实挂在那。
逐项看了 README,改掉几处**不准确**且容易误判的表述:
* 原文写"看看学生机是不是在打游戏" —— 这是**错的**:
被控端只装在一台电脑上(讲台那台),根本看不到别的机器。
既不准确又像监控软件,改成"作用于被控端那一台"
* 课堂那几项功能如实说明:改的是本机 hosts、结束的是本机进程,
都可逆,下课点「一键恢复全部」就还原
* "免杀对抗""伪装成系统进程"这类词(虽然是在说"我们不做这些")
本身就在审核词库里,换成正面的说法
* 成品文件名从 1.8.2 更新到当前版本,并且以后发版自动跟着改
(把 README 加进了 bump 脚本;以前一直停在 1.8.2,
用户照着 README 去 releases 根本找不到那个文件)
== 四、做这件事时自己踩的坑(都写进注释了)==
* 批量替换时**没排除 gitignore 的文件**,把本地密码文件也改了
* 替换时往字典字面量中间塞注释,**弄坏了 5 个文件的语法**
* 修的时候手写"坏文件列表",漏了 2 个 ——
改成全仓库扫模式(列表是观察到的,不是穷尽的)
* 清理工具自己又成了泄漏点(脚本里写了要匹配的 IP/密码),
加了 _build/precommit_leak_gate.py 当闸门才抓到
教训:批量替换要先排除不该碰的文件,而且不能往表达式中间塞东西。
== 按用户要求:测完再提交 ==
全量回归 41 个阶段全 PASS(2 项因锁屏 SKIP)
601 个 Python 文件语法通过
pyflakes 干净
安装包完整周期 20/20
对外材料清洁度 15/15
提交前泄漏闸门通过
(这条信息是补写的:上一个提交因为 heredoc 把提交说明打到屏幕而不是
文件,信息变成空的 "remove temp" 了,内容本身是对的。)
152 lines
5.3 KiB
Python
152 lines
5.3 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""量出管理页在窄屏下是哪个元素把页面撑宽了。
|
||
|
||
做法:抓一份管理页 HTML,注入一段脚本把"最宽的元素"写进 title,
|
||
然后用 Edge 无头 + --dump-dom 读回来。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import http.cookiejar
|
||
import json
|
||
import os
|
||
import re
|
||
import shutil
|
||
import subprocess
|
||
import sys
|
||
import tempfile
|
||
import time
|
||
import urllib.error
|
||
import urllib.parse
|
||
import urllib.request
|
||
from pathlib import Path
|
||
|
||
|
||
# ⚠ 不再把密码写死在脚本里(这个仓库是公开的)。
|
||
# 从环境变量或 _build/.admin_password(已 gitignore)读,读不到就报错。
|
||
def _admin_password() -> str:
|
||
import os
|
||
env = os.environ.get("YKXMZ_ADMIN_PASSWORD", "").strip()
|
||
if env:
|
||
return env
|
||
f = Path(__file__).resolve().parent / ".admin_password"
|
||
if f.is_file():
|
||
return f.read_text(encoding="utf-8").strip()
|
||
raise SystemExit(
|
||
"没拿到管理密码:设 YKXMZ_ADMIN_PASSWORD,或写 _build/.admin_password")
|
||
|
||
|
||
ROOT = Path(__file__).resolve().parent.parent
|
||
UA = {"User-Agent": "LanRemote/1.4.0"}
|
||
PORT = 8111
|
||
BASE = f"http://127.0.0.1:{PORT}"
|
||
|
||
EDGE = next((p for p in (
|
||
Path(r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"),
|
||
Path(r"C:\Program Files\Microsoft\Edge\Application\msedge.exe"))
|
||
if p.is_file()), None)
|
||
|
||
PROBE = """
|
||
<script>
|
||
setTimeout(() => {
|
||
const vw = document.documentElement.clientWidth;
|
||
const rows = [];
|
||
document.querySelectorAll('*').forEach(el => {
|
||
const r = el.getBoundingClientRect();
|
||
if (r.right > vw + 1 || r.width > vw + 1) {
|
||
rows.push(Math.round(r.width) + 'x' + Math.round(r.height)
|
||
+ ' right=' + Math.round(r.right)
|
||
+ ' <' + el.tagName.toLowerCase()
|
||
+ (el.className ? '.' + String(el.className).split(' ').join('.') : '')
|
||
+ '>');
|
||
}
|
||
});
|
||
document.title = 'VW=' + vw + ' BODY=' + document.body.scrollWidth
|
||
+ ' || ' + rows.slice(0, 12).join(' ;; ');
|
||
});
|
||
</script>
|
||
"""
|
||
|
||
|
||
def main() -> int:
|
||
work = Path(tempfile.mkdtemp(prefix="admin_probe_"))
|
||
relay = None
|
||
try:
|
||
data = work / "d"
|
||
data.mkdir(parents=True, exist_ok=True)
|
||
env = dict(os.environ)
|
||
env.update({"RELAY_PORT": str(PORT), "RELAY_BIND": "127.0.0.1",
|
||
"RELAY_DATA": str(data),
|
||
"PYTHONIOENCODING": "utf-8", "PYTHONUNBUFFERED": "1"})
|
||
relay = subprocess.Popen(
|
||
[sys.executable, "-u", str(ROOT / "relay" / "relay.py")], env=env,
|
||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||
for _ in range(40):
|
||
time.sleep(0.5)
|
||
try:
|
||
urllib.request.urlopen(urllib.request.Request(
|
||
BASE + "/v1/health", headers=UA), timeout=2)
|
||
break
|
||
except Exception: # noqa: BLE001
|
||
continue
|
||
|
||
for index, (name, code) in enumerate(
|
||
[("书房台式机", "482913"), ("笔记本", "771204")], start=1):
|
||
body = json.dumps({"deviceId": f"pc-{index}", "code": code,
|
||
"name": name, "version": "1.4.0"}).encode()
|
||
urllib.request.urlopen(urllib.request.Request(
|
||
BASE + "/v1/agent/register", data=body, method="POST",
|
||
headers={**UA, "Content-Type": "application/json"}),
|
||
timeout=10).read()
|
||
|
||
jar = http.cookiejar.CookieJar()
|
||
opener = urllib.request.build_opener(
|
||
urllib.request.HTTPCookieProcessor(jar))
|
||
form = urllib.parse.urlencode({"password": _admin_password()}).encode()
|
||
req = urllib.request.Request(BASE + "/admin/login", data=form,
|
||
method="POST", headers=UA)
|
||
req.add_header("Content-Type", "application/x-www-form-urlencoded")
|
||
try:
|
||
opener.open(req, timeout=15).read()
|
||
except urllib.error.HTTPError:
|
||
pass
|
||
|
||
html = opener.open(urllib.request.Request(BASE + "/", headers=UA),
|
||
timeout=15).read().decode("utf-8")
|
||
html = html.replace("</body>", PROBE + "</body>")
|
||
page = work / "probe.html"
|
||
page.write_text(html, encoding="utf-8")
|
||
|
||
if not EDGE:
|
||
print(" 没有 Edge")
|
||
return 1
|
||
|
||
proc = subprocess.run(
|
||
[str(EDGE), "--headless=new", "--disable-gpu",
|
||
"--window-size=420,900", "--virtual-time-budget=3000",
|
||
"--dump-dom", page.as_uri()],
|
||
capture_output=True, text=True, encoding="utf-8",
|
||
errors="replace", timeout=90)
|
||
match = re.search(r"<title>(.*?)</title>", proc.stdout or "", re.S)
|
||
if not match:
|
||
print(" 没拿到 title")
|
||
print((proc.stdout or "")[:300])
|
||
return 1
|
||
for part in match.group(1).split(";;"):
|
||
print(" " + part.strip()[:150])
|
||
return 0
|
||
finally:
|
||
if relay is not None:
|
||
try:
|
||
relay.terminate()
|
||
relay.wait(timeout=8)
|
||
except Exception: # noqa: BLE001
|
||
try:
|
||
relay.kill()
|
||
except Exception: # noqa: BLE001
|
||
pass
|
||
time.sleep(0.5)
|
||
shutil.rmtree(work, ignore_errors=True)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main()) |