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

113 lines
4.0 KiB
Python

# -*- coding: utf-8 -*-
"""Clear leftover LAN Clash proxy on guest; check ShellCrash egress."""
from __future__ import annotations
import sys
import httpx
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
GUEST_PW = "4669805"
def main() -> int:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(
"107.173.30.245",
4014,
"eric",
GUEST_PW,
timeout=40,
banner_timeout=80,
allow_agent=False,
look_for_keys=False,
)
script = r"""
set -e
echo '=== find proxy refs ==='
grep -RIn --exclude-dir=proc --exclude-dir=sys -E '192\.168\.21\.36:7897|http_proxy|HTTP_PROXY|ALL_PROXY' \
/etc/environment /etc/profile /etc/profile.d /etc/bash.bashrc \
/home/eric/.bashrc /home/eric/.profile /home/eric/.bash_profile \
/root/.bashrc /root/.profile 2>/dev/null | head -80 || true
ls -la /etc/apt/apt.conf.d/*proxy* 2>/dev/null || true
echo '=== clear persistent proxy ==='
rm -f /etc/apt/apt.conf.d/95proxy /etc/apt/apt.conf.d/99douyinweb-tmp-proxy /etc/apt/apt.conf.d/99live-proxy
# scrub /etc/environment proxy lines
if [ -f /etc/environment ]; then
sed -i -E '/^(export[[:space:]]+)?(http_proxy|https_proxy|HTTP_PROXY|HTTPS_PROXY|ALL_PROXY|all_proxy|no_proxy|NO_PROXY)=/d' /etc/environment
fi
for f in /etc/profile.d/*proxy* /etc/profile.d/*clash* /etc/profile.d/*ShellCrash*; do
[ -f "$f" ] || continue
echo remove "$f"; rm -f "$f"
done
# scrub user profiles
for f in /home/eric/.bashrc /home/eric/.profile /root/.bashrc /root/.profile; do
[ -f "$f" ] || continue
sed -i -E '/192\.168\.21\.36:7897/d' "$f"
sed -i -E '/^(export[[:space:]]+)?(http_proxy|https_proxy|HTTP_PROXY|HTTPS_PROXY|ALL_PROXY|all_proxy)=/d' "$f"
done
echo '=== after ==='
ls /etc/apt/apt.conf.d/*proxy* 2>/dev/null || echo no_apt_proxy
grep -E 'proxy|7897' /etc/environment 2>/dev/null || echo env_clean
# login shell env (fresh)
sudo -u eric env -i HOME=/home/eric USER=eric bash -lc 'env | grep -i proxy || echo eric_login_clean'
echo '=== shellcrash ==='
systemctl is-active shellcrash
journalctl -u shellcrash -n 30 --no-pager || true
ls -la /etc/ShellCrash/yamls/config.yaml /tmp/ShellCrash/config.yaml /tmp/ShellCrash/CrashCore 2>/dev/null || true
# direct vs mixed
curl -sS -m 5 -o /dev/null -w 'direct:%{http_code}\n' https://www.google.com/generate_204 || echo direct:fail
curl -sS -m 8 -o /dev/null -w 'mixed:%{http_code}\n' -x http://127.0.0.1:7890 https://www.google.com/generate_204 || echo mixed:fail
curl -sS -m 3 http://127.0.0.1:9999/ 2>/dev/null | head -c 200 || true
echo
"""
_, o, e = c.exec_command(f"echo '{GUEST_PW}' | sudo -S -p '' bash -c {repr(script)}", timeout=90)
# repr adds quotes wrong for remote - use heredoc via sftp instead
c.close()
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(
"107.173.30.245",
4014,
"eric",
GUEST_PW,
timeout=40,
banner_timeout=80,
allow_agent=False,
look_for_keys=False,
)
sftp = c.open_sftp()
with sftp.file("/tmp/_clear_proxy.sh", "w") as f:
f.write(script.replace("\r\n", "\n"))
sftp.close()
_, o, e = c.exec_command(
f"echo '{GUEST_PW}' | sudo -S -p '' bash /tmp/_clear_proxy.sh",
timeout=90,
)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()
with httpx.Client(base_url="https://dy.nomadro.com", timeout=20.0) as client:
client.post("/api/auth/login", json={"username": "hackrobot", "password": "Xiao4669805@"})
sc = (client.get("/api/network").json() or {}).get("shellcrash") or {}
print(
"api sc",
sc.get("installed"),
sc.get("running"),
sc.get("unit"),
sc.get("mixed_port"),
flush=True,
)
print("dylive", httpx.get("https://dylive.nomadro.com/api/health", timeout=15).status_code)
return 0
if __name__ == "__main__":
raise SystemExit(main())