douyinWEB/scripts/_fix_zash_setup_url.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

76 lines
2.9 KiB
Python

# -*- coding: utf-8 -*-
"""Disable Zashboard PWA SW; deploy web_panel setup URL with HTTPS backend."""
from __future__ import annotations
import base64
import json
import sys
import time
from pathlib import Path
import httpx
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
ROOT = Path(__file__).resolve().parents[1]
HUB = ROOT / "backend" / "app" / "shellcrash_hub.py"
VPS = "107.173.30.245"
GUEST_USER, GUEST_PASS, GUEST_PORT = "eric", "4669805", 4014
PATCH = r"""#!/usr/bin/env bash
set -euo pipefail
IDX=/etc/ShellCrash/ui/index.html
# keep base href
grep -q 'href="/ui/"' "$IDX" || sed -i 's|<head>|<head>\n <base href="/ui/" />|' "$IDX"
# remove PWA register (can confuse navigation / mix with site SW)
sed -i '/vite-plugin-pwa:register-sw/d' "$IDX"
sed -i '/registerSW\.js/d' "$IDX"
# neutralize SW file if requested somehow
printf '%s\n' '// disabled — use /ui/#/setup?hostname=…&port=443&protocol=https' > /etc/ShellCrash/ui/sw.js
printf '%s\n' '// disabled' > /etc/ShellCrash/ui/registerSW.js
echo '--- index head ---'
head -n 55 "$IDX"
"""
def main():
g = paramiko.SSHClient()
g.set_missing_host_key_policy(paramiko.AutoAddPolicy())
g.connect(VPS, GUEST_PORT, GUEST_USER, GUEST_PASS, timeout=40, banner_timeout=80, allow_agent=False, look_for_keys=False)
b64 = base64.b64encode(PATCH.encode()).decode()
_, o, e = g.exec_command(
f"echo {b64} | base64 -d > /tmp/patch_zash.sh && echo '{GUEST_PASS}' | sudo -S -p '' bash /tmp/patch_zash.sh",
timeout=60,
)
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
sftp = g.open_sftp()
sftp.put(str(HUB), "/tmp/_up_shellcrash_hub.py")
sftp.close()
_, o, e = g.exec_command(
f"echo '{GUEST_PASS}' | sudo -S -p '' bash -c '"
"install -m 644 /tmp/_up_shellcrash_hub.py /opt/douyinWEB/backend/app/shellcrash_hub.py; "
"systemctl restart douyinweb-api'",
timeout=60,
)
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
for _ in range(12):
time.sleep(2)
_, o2, _ = g.exec_command("curl -sS -m 3 -o /dev/null -w '%{http_code}' http://127.0.0.1:8014/api/health")
if o2.read().decode().strip() == "200":
break
g.close()
with httpx.Client(base_url="https://dy.nomadro.com", timeout=25, follow_redirects=True) as c:
c.post("/api/auth/login", json={"username": "hackrobot", "password": "Xiao4669805@"})
wp = c.post("/api/network/shellcrash/web_panel").json()
print(json.dumps({k: wp.get(k) for k in ("url", "proxies_url", "direct_url", "ok")}, ensure_ascii=False, indent=2), flush=True)
html = c.get("/ui/").text
print("has_registerSW", "registerSW" in html, "has_base", '<base href="/ui/"' in html, flush=True)
# controller reachable same-origin
print("version", c.get("/version").status_code, c.get("/version").text[:60], flush=True)
if __name__ == "__main__":
main()