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>
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Emergency rollback Caddy + Neko DNAT to legacy wg-dy 10.8.0.2."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
if hasattr(sys.stdout, "reconfigure"):
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
OVERSEAS = "107.173.30.245"
|
|
OVERSEAS_PASS = "Xiao4669805"
|
|
LEGACY = "10.8.0.2"
|
|
|
|
|
|
def ssh(host, port, user, pw):
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(host, port, user, pw, timeout=45, allow_agent=False, look_for_keys=False)
|
|
return c
|
|
|
|
|
|
def run(c, cmd, timeout=60):
|
|
_, o, e = c.exec_command(cmd, timeout=timeout)
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
|
|
def main():
|
|
v = ssh(OVERSEAS, 22, "root", OVERSEAS_PASS)
|
|
site = "/etc/caddy/sites/dy.nomadro.com.caddy"
|
|
print(run(v, f"sed -i 's/10.9.0.2/{LEGACY}/g' {site} && caddy validate --config /etc/caddy/Caddyfile && systemctl reload caddy", 45))
|
|
print(run(v, "curl -sS -m 8 -o /dev/null -w 'dy=%{http_code} t=%{time_total}s\\n' https://dy.nomadro.com/api/health", 20))
|
|
v.close()
|
|
|
|
# restore neko dnat script with legacy target
|
|
fix = Path(__file__).resolve().parent / "_fix_neko_webrtc_forward_legacy.py"
|
|
fix.write_text(
|
|
open(Path(__file__).resolve().parent / "_fix_neko_webrtc_forward.py", encoding="utf-8")
|
|
.read()
|
|
.replace('PVE_WG = "10.9.0.2"', f'PVE_WG = "{LEGACY}"'),
|
|
encoding="utf-8",
|
|
)
|
|
r = subprocess.run([sys.executable, str(fix)], capture_output=True, text=True)
|
|
print(r.stdout)
|
|
fix.unlink(missing_ok=True)
|
|
print("rollback done")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|