初版:小白超人(从线上实例导出)

This commit is contained in:
deploy
2026-10-29 15:20:39 +08:00
commit b77a309873
100 changed files with 32168 additions and 0 deletions
+76
View File
@@ -0,0 +1,76 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""重打 1.zip:最新代码,不含安装包(160MB 抓包工具)与任何数据/凭据。
范围:源码+模板+静态+测试+脚本(与 git 最新提交一致)。
排除:exe/db(含wal,shm)/pem/key/crt/zip/token|smtp|admin|secret 配置及备份/
缓存/日志/artifacts/backups/打包基线快照。
打包后:逐条目审计 + 关键文件校验。
"""
import zipfile
from pathlib import Path
ROOT = Path(__file__).parent.parent
ZIP = ROOT / "1.zip"
EXCLUDE_DIR_PARTS = {"__pycache__", ".pytest_cache", ".reasonix", "backups",
"artifacts", ".git", "downloads"}
EXCLUDE_SUFFIX = (".pyc", ".pyo", ".log", ".tmp", ".bak", ".zip", ".db", ".db-wal",
".db-shm", ".pem", ".key", ".crt", ".exe", ".sqlite")
EXCLUDE_STEMS = ("token_config", "smtp_config", "admin_config", "secret_key")
def excluded(rel: Path) -> bool:
if set(rel.parts) & EXCLUDE_DIR_PARTS:
return True
if rel.suffix.lower() in EXCLUDE_SUFFIX:
return True
stem = rel.name.lower()
if stem == ".pack_baseline.json":
return True
if any(stem.startswith(p) for p in EXCLUDE_STEMS):
return True
return False
files = [(p, p.relative_to(ROOT).as_posix())
for p in sorted(ROOT.rglob("*"))
if p.is_file() and not excluded(p.relative_to(ROOT))]
if ZIP.exists():
ZIP.unlink()
with zipfile.ZipFile(ZIP, "w", zipfile.ZIP_DEFLATED, compresslevel=9) as zf:
for p, arc in files:
zf.write(p, arc)
# ---------- 审计 ----------
zf = zipfile.ZipFile(ZIP)
names = zf.namelist()
size_mb = ZIP.stat().st_size / 1048576
print(f"OK 1.zip 打包完成: {len(names)} 个文件, {size_mb:.2f} MB")
bad = [n for n in names
if n.lower().endswith((".exe", ".db", ".pem", ".key", ".crt", ".zip", ".log"))
or any(k in n.lower() for k in
("token_config", "smtp_config", "admin_config", "secret_key",
"users.db", "pack_baseline"))]
print(f"敏感/大文件审计: {'发现!! ' + str(bad) if bad else '干净(无 exe/db/密钥/token)'}")
required = ["app.py", "db.py", "campus.py", "alerts.py", "subscribe.py",
"wechat.py", "timer.py", "email_utils.py", "email_verify.py",
"routes/rental.py", "routes/admin.py", "routes/share.py",
"routes/auth.py", "routes/map_api.py", "routes/export.py",
"routes/subscribe.py", "routes/download.py",
"templates/map.html", "templates/admin.html", "templates/analysis.html",
"static/js/map.js", "static/css/map.css",
"scripts/pack_zip.ps1",
"tests/test_history_30d.py", "tests/test_rounds_and_preview.py",
"tests/test_code_mail.py"]
missing = [r for r in required if r not in names]
print(f"关键文件校验: {'缺失!! ' + str(missing) if missing else f'全部在位({len(required)} 项)'}")
# 最新修复是否入包(登录门 DOM 修复在 map.html,聚类修复在 map.js)
newest = ["templates/map.html", "static/js/map.js"]
print(f"最新提交产物: {'在位' if all(n in names for n in newest) else '!! 缺失'}")
zf.close()