douyinWEB/scripts/_fix_shellcrash_ui_frp.py
2026-09-13 22:10:49 -05:00

117 lines
3.6 KiB
Python

#!/usr/bin/env python3
"""Fix ShellCrash /ui: FRP-aux forward :9999 + Caddy point to 127.0.0.1:9999."""
from __future__ import annotations
import sys
import time
import httpx
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace", line_buffering=True)
def connect():
for i in range(10):
try:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(
"107.173.30.245",
22,
"root",
"Xiao4669805",
timeout=25,
banner_timeout=40,
allow_agent=False,
look_for_keys=False,
)
print("connected", flush=True)
return c
except Exception as ex:
print(f"retry {i} {ex}", flush=True)
time.sleep(2)
raise RuntimeError("ssh fail")
def run(c, cmd, t=90):
print(f"$ {cmd[:200]}", flush=True)
_i, o, e = c.exec_command(cmd, timeout=t)
while not o.channel.exit_status_ready():
if o.channel.recv_ready():
sys.stdout.write(o.channel.recv(4096).decode("utf-8", "replace"))
sys.stdout.flush()
if o.channel.recv_stderr_ready():
sys.stdout.write(o.channel.recv_stderr(4096).decode("utf-8", "replace"))
sys.stdout.flush()
time.sleep(0.1)
sys.stdout.write((o.read() + e.read()).decode("utf-8", "replace"))
sys.stdout.flush()
print("->", o.channel.recv_exit_status(), flush=True)
REMOTE = r'''
set -e
FORWARDS="-L 127.0.0.1:18014:127.0.0.1:8014 -L 127.0.0.1:14015:127.0.0.1:4015 -L 127.0.0.1:9999:127.0.0.1:9999"
for p in $(seq 9200 9207); do
FORWARDS="$FORWARDS -L 127.0.0.1:$p:127.0.0.1:$p"
done
cat >/etc/systemd/system/dy-frp-http-aux.service <<EOF
[Unit]
Description=dy.nomadro.com FRP-aux tunnels (HTTP+ShellCrash+Neko via :4014)
After=network-online.target frpp.service
Wants=network-online.target
[Service]
Type=simple
Restart=always
RestartSec=3
Environment=SSHPASS=4669805
ExecStart=/usr/bin/sshpass -e ssh -N -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ServerAliveInterval=15 -o ServerAliveCountMax=3 -o ExitOnForwardFailure=yes $FORWARDS -p 4014 eric@127.0.0.1
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl restart dy-frp-http-aux
sleep 3
systemctl is-active dy-frp-http-aux
ss -lntp | grep -E ':(9999|18014)\b' || true
curl -sS -m 8 -o /dev/null -w 'aux_ui=%{http_code}\n' http://127.0.0.1:9999/ui/
curl -sS -m 8 -o /dev/null -w 'aux_root=%{http_code}\n' http://127.0.0.1:9999/
SITE=/etc/caddy/sites/dy.nomadro.com.caddy
cp -a "$SITE" "$SITE.bak.scui.$(date +%s)"
sed -i 's/reverse_proxy 10\.8\.0\.2:9999/reverse_proxy 127.0.0.1:9999/g' "$SITE"
grep -n '9999' "$SITE" | head -10
caddy validate --config /etc/caddy/Caddyfile >/tmp/cv.txt 2>&1 && echo caddy_ok || (tail -15 /tmp/cv.txt; exit 1)
systemctl reload caddy
systemctl is-active caddy
'''
c = connect()
run(c, REMOTE, t=120)
c.close()
print("## public", flush=True)
with httpx.Client(follow_redirects=False, timeout=20) as cl:
for u in [
"https://dy.nomadro.com/ui/",
"https://dy.nomadro.com/ui",
"https://dy.nomadro.com/api/health",
"https://dy.nomadro.cn/ui/",
]:
try:
r = cl.get(u)
print(
f"{u} -> {r.status_code} ctype={r.headers.get('content-type','')[:35]} "
f"body={r.text[:60]!r}",
flush=True,
)
except Exception as ex:
print(f"{u} ERR {ex}", flush=True)
print("DONE", flush=True)