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

45 lines
1.4 KiB
Python

#!/usr/bin/env python3
"""Restore ShellCrash config from backup after unauthorized edit. Live flush."""
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", flush=True)
cmd = r'''
echo 4669805 | sudo -S -p '' bash -lc '
set -e
if [ -f /tmp/ShellCrash/config.yaml.bak.hysteria_ports ]; then
cp -a /tmp/ShellCrash/config.yaml.bak.hysteria_ports /tmp/ShellCrash/config.yaml
echo restored_from_bak
else
echo NO_BACKUP
fi
grep -A12 "name: 1d2da142-singbox_hysteria5" /tmp/ShellCrash/config.yaml | head -14
systemctl restart shellcrash.service
sleep 4
systemctl is-active shellcrash
'
'''
_i, o, e = c.exec_command(cmd, timeout=60)
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)