douyinWEB/scripts/_deploy_default_admin.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

53 lines
1.8 KiB
Python

# -*- coding: utf-8 -*-
"""Deploy default admin credential policy and sync server DB hash."""
import time
import paramiko
HOST = "107.173.30.245"
REPO = "/opt/douyinWEB"
LOCAL = r"C:/Users/admin/Desktop/douyinWEB"
FILES = [
"backend/app/config.py",
"backend/app/session_auth.py",
"backend/app/main.py",
]
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
def run(cmd: str, timeout: int = 180) -> str:
_, o, e = c.exec_command(cmd, timeout=timeout)
out = o.read().decode("utf-8", "replace").strip()
err = e.read().decode("utf-8", "replace").strip()
return (out + ("\n" + err if err else "")).strip()
ts = int(time.time())
print("[backup db]", run(f"cp -a {REPO}/backend/data/monitor.db /tmp/monitor.db.bak_admin_{ts} && ls -lh /tmp/monitor.db.bak_admin_{ts}"))
sftp = c.open_sftp()
for rel in FILES:
print("[upload]", rel)
sftp.put(f"{LOCAL}/{rel.replace(chr(92), '/')}", f"{REPO}/{rel.replace(chr(92), '/')}")
sftp.close()
print("[sync admin hash]", run(
f"cd {REPO}/backend && .venv/bin/python -c \""
"from app.session_auth import ensure_default_admin_credentials; "
"ensure_default_admin_credentials(); "
"from app.session_auth import get_admin_credentials; "
"u,h=get_admin_credentials(); "
"print('user', u, 'hash_prefix', h[:12])\""
))
print("[api restart]", run("systemctl restart douyinweb-api; sleep 5; systemctl is-active douyinweb-api"))
print("[login test]", run(
"curl -s -o /dev/null -w '%{http_code}' -X POST http://127.0.0.1:8014/api/auth/login "
"-H 'Content-Type: application/json' "
"-d '{\"username\":\"hackrobot\",\"password\":\"Xiao4669805@\"}'"
))
c.close()
print("DONE")