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

70 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""Test: remove hysteria ports hop temporarily and re-delay."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace", line_buffering=True)
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 4014, "eric", "4669805", timeout=25, banner_timeout=40, allow_agent=False, look_for_keys=False)
print("connected guest", flush=True)
cmd = r'''
echo 4669805 | sudo -S -p '' bash -lc '
set -e
# backup runtime config
cp -a /tmp/ShellCrash/config.yaml /tmp/ShellCrash/config.yaml.bak.hysteria_ports
# remove ONLY the ports line under hysteria5 block (first occurrence after the name)
python3 - <<PY
from pathlib import Path
p = Path("/tmp/ShellCrash/config.yaml")
lines = p.read_text(encoding="utf-8").splitlines(True)
out = []
in_h5 = False
removed = 0
for i, line in enumerate(lines):
if "name: 1d2da142-singbox_hysteria5" in line:
in_h5 = True
out.append(line)
continue
if in_h5 and line.startswith(" - name:"):
in_h5 = False
if in_h5 and line.strip().startswith("ports:"):
removed += 1
continue
out.append(line)
p.write_text("".join(out), encoding="utf-8")
print("removed_ports_lines", removed)
PY
# also sync etc copy used by some reloads
cp -a /tmp/ShellCrash/config.yaml /etc/ShellCrash/config.yaml
# soft reload CrashCore if possible
systemctl restart shellcrash.service
sleep 4
systemctl is-active shellcrash
curl -sS -m 5 http://127.0.0.1:9999/version; echo
curl -sS -m 15 -G "http://127.0.0.1:9999/proxies/1d2da142-singbox_hysteria5/delay" --data-urlencode "url=http://www.gstatic.com/generate_204" --data-urlencode "timeout=8000"; echo
curl -sS -m 10 -G "http://127.0.0.1:9999/proxies/1d2da142-singbox_tuic5/delay" --data-urlencode "url=http://www.gstatic.com/generate_204" --data-urlencode "timeout=5000"; echo
grep -A12 "name: 1d2da142-singbox_hysteria5" /tmp/ShellCrash/config.yaml | head -15
'
'''
_i, o, e = c.exec_command(cmd, timeout=90)
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)
c.close()
print("DONE", flush=True)