#!/usr/bin/env python3 # -*- coding: utf-8 -*- """验证 /sim/sys/ (release/sim_sys_server.py) 恢复后: 页面能出 + 脱敏回扫干净。""" import sys import urllib.request import zipfile import pathlib ROOT = pathlib.Path(r"F:\temp\guanlan-rudong-v2_0.2.0") sys.path.insert(0, str(ROOT)) from src.windscada import deid_public as DP def readable(name): try: return name.encode('cp437').decode('utf-8') except UnicodeError: return name zip_path = ROOT / 'release' / '如东SWT40_控制律仿真台_20260906.zip' with zipfile.ZipFile(zip_path) as z: pages = [readable(n.rsplit('/', 1)[-1]) for n in z.namelist() if n.endswith('.html') and readable(n.rsplit('/', 1)[-1])[:1] in {'0', '1', '2', '3', '4'}] print(f"页面 {len(pages)} 个") bad = 0 for name in sorted(pages): url = 'http://127.0.0.1:18792/' + urllib.parse.quote(name) try: with urllib.request.urlopen(url, timeout=20) as r: body = r.read().decode('utf-8') code = r.status except Exception as ex: print(f" [X] {name}: {ex.__class__.__name__}: {ex}") bad += 1 continue leaks = DP.audit(body) leak_txt = '干净' if not leaks else '; '.join(f'{n}×{c} {s}' for n, c, s in leaks) print(f" [{code}] {name:28s} {len(body):7d} 字节 回扫: {leak_txt}") bad += bool(leaks) print("\n网关路由:") for path in ('/healthz', '/sim/sys/'): try: with urllib.request.urlopen('http://127.0.0.1:28084' + path, timeout=20) as r: txt = r.read().decode('utf-8', 'replace') if path == '/healthz': import json d = json.loads(txt) print(f" [{r.status}] {path} status={d['status']} {d['mode']}") for m in d['modules']: print(f" {'ok ' if m['ok'] else 'DOWN'} {m['path']} {m['name']}") else: print(f" [{r.status}] {path} {len(txt)} 字节, 含返回链接: {'guanlan-top' in txt}") except Exception as ex: print(f" [X] {path}: {ex.__class__.__name__}: {ex}") bad += 1 print("\n结论:", "全部通过" if not bad else f"有 {bad} 项需要注意") sys.exit(0 if not bad else 1)