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

145 lines
3.9 KiB
Python

# -*- coding: utf-8 -*-
"""Force /ui → /ui/ with site-level redir; verify."""
import sys
import time
import paramiko
import httpx
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
SITE = "/etc/caddy/sites/dy.nomadro.com.caddy"
NEW = r"""# Physical app — dy.nomadro.com → WG 10.8.0.2
# Do not edit dylive.nomadro.com.caddy
dy.nomadro.com {
encode gzip
request_body {
max_size 200MB
}
# Zashboard: /ui without slash must redirect (browsers often open /ui#/… → blank)
@ui_noslash {
path /ui
not path /ui/
not path /ui/*
}
redir @ui_noslash /ui/ 308
handle /api/* {
reverse_proxy 10.8.0.2:8014 {
header_up Host {host}
}
}
handle /covers/* {
reverse_proxy 10.8.0.2:8014 {
header_up Host {host}
}
}
handle /neko/1 {
redir /neko/1/ 308
}
handle_path /neko/1/* {
reverse_proxy 10.8.0.2:9200 {
header_up Host {host}
header_up X-Forwarded-Proto {scheme}
}
}
handle /neko/2 {
redir /neko/2/ 308
}
handle_path /neko/2/* {
reverse_proxy 10.8.0.2:9201 {
header_up Host {host}
header_up X-Forwarded-Proto {scheme}
}
}
handle /neko/3 {
redir /neko/3/ 308
}
handle_path /neko/3/* {
reverse_proxy 10.8.0.2:9202 {
header_up Host {host}
header_up X-Forwarded-Proto {scheme}
}
}
handle /neko/4 {
redir /neko/4/ 308
}
handle_path /neko/4/* {
reverse_proxy 10.8.0.2:9203 {
header_up Host {host}
header_up X-Forwarded-Proto {scheme}
}
}
handle /_/* {
reverse_proxy 10.8.0.2:8092 {
header_up Host {host}
}
}
handle /douyin-covers/* {
reverse_proxy 10.8.0.2:8333 {
header_up Host {host}
}
}
handle /shellcrash-ui {
redir /shellcrash-ui/ 308
}
handle_path /shellcrash-ui/* {
reverse_proxy 10.8.0.2:9999 {
header_up Host {host}
header_up X-Forwarded-Proto {scheme}
}
}
@clash path /ui/ /ui/* /version /proxies /proxies/* /configs /configs/* /rules /rules/* /connections /connections/* /providers /providers/* /cache /cache/* /dns /dns/* /debug /debug/* /traffic /logs /memory /restart /upgrade /upgrade/* /group /group/* /script /script/* /fakeip /fakeip/* /endpoint /endpoint/* /runtime /runtime/* /meta /meta/* /schema /schema/* /flushfakeip /externaloverride /externaloverride/* /storage /storage/*
handle @clash {
reverse_proxy 10.8.0.2:9999 {
header_up Host {host}
}
}
handle {
reverse_proxy 10.8.0.2:4015 {
header_up Host {host}
}
}
}
"""
def main():
v = paramiko.SSHClient()
v.set_missing_host_key_policy(paramiko.AutoAddPolicy())
v.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
sftp = v.open_sftp()
bak = SITE + f".bak.{int(time.time())}"
_, o, _ = v.exec_command(f"cp -a {SITE} {bak}")
o.channel.recv_exit_status()
with sftp.file(SITE, "w") as f:
f.write(NEW)
sftp.close()
_, o, e = v.exec_command("caddy validate --config /etc/caddy/Caddyfile && systemctl reload caddy && echo CADDY_OK", timeout=60)
print((o.read() + e.read()).decode()[-500:], flush=True)
_, o, e = v.exec_command(
"curl -sS -o /dev/null -w 'h1:%{http_code} loc:%{redirect_url}\\n' --http1.1 https://dy.nomadro.com/ui; "
"curl -sS -o /dev/null -w 'h1slash:%{http_code}\\n' --http1.1 https://dy.nomadro.com/ui/; "
"curl -sS -o /dev/null -w 'js:%{http_code}\\n' --http1.1 https://dy.nomadro.com/ui/assets/index-C5rfNEL8.js; "
"curl -sS --http1.1 https://dy.nomadro.com/ui/ | head -c 300; echo",
timeout=60,
)
print((o.read() + e.read()).decode(), flush=True)
v.close()
with httpx.Client(timeout=25, follow_redirects=False, http2=False) as c:
r = c.get("https://dy.nomadro.com/ui")
print("client /ui", r.status_code, r.headers.get("location"), len(r.content), flush=True)
with httpx.Client(timeout=25, follow_redirects=True, http2=False) as c:
r = c.get("https://dy.nomadro.com/ui")
print("follow", r.url, "base" in r.text, '<base href="/ui/"' in r.text, flush=True)
if __name__ == "__main__":
main()