73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Locate dy.com Neko reverse_proxy targets and align to :1920x if needed."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
v = paramiko.SSHClient()
|
|
v.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
v.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False)
|
|
|
|
|
|
def vr(cmd, t=90):
|
|
_, o, e = v.exec_command(cmd, timeout=t)
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
|
|
print(vr("ls -la /etc/caddy/; wc -l /etc/caddy/Caddyfile; head -5 /etc/caddy/Caddyfile"))
|
|
print(vr("rg -n 'dy\\.nomadro|neko|1920|9200|ops-neko' /etc/caddy/ -g '!*.bak' 2>/dev/null | head -80"))
|
|
print(vr("caddy adapt --config /etc/caddy/Caddyfile 2>/dev/null | python3 -c \"import sys,json; d=json.load(sys.stdin); print('ok')\" 2>&1 | head"))
|
|
# dump site blocks containing neko
|
|
print(vr(
|
|
"python3 - <<'PY'\n"
|
|
"from pathlib import Path\n"
|
|
"p=Path('/etc/caddy/Caddyfile')\n"
|
|
"text=p.read_text(encoding='utf-8',errors='replace')\n"
|
|
"print('len',len(text))\n"
|
|
"for key in ['dy.nomadro.com','dy.nomadro.cn','dylive.nomadro.com','/neko','19200','9200','ops-neko']:\n"
|
|
" print(key, text.count(key))\n"
|
|
"idx=text.find('dy.nomadro.com')\n"
|
|
"print('first dy.com idx', idx)\n"
|
|
"if idx>=0:\n"
|
|
" print(text[idx:idx+2500])\n"
|
|
"PY"
|
|
))
|
|
v.close()
|
|
|
|
# phys with correct sudo
|
|
p = paramiko.SSHClient()
|
|
p.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
p.connect("107.173.30.245", 4014, "eric", "4669805", timeout=40, allow_agent=False, look_for_keys=False)
|
|
|
|
|
|
def pr(cmd, t=90):
|
|
# avoid nested quotes issues: write script
|
|
return None
|
|
|
|
|
|
sftp = p.open_sftp()
|
|
script = r'''#!/bin/bash
|
|
set +e
|
|
wg show wg-dy-cn | egrep 'handshake|transfer'
|
|
ping -c1 -W2 10.9.0.1 | tail -2
|
|
for port in 9200 9201 9202 9203 9204 9205 9206 9207 18200 18201; do
|
|
code=$(curl -sS -m 2 -o /dev/null -w '%{http_code}' http://127.0.0.1:$port/ || echo x)
|
|
echo port_$port=$code
|
|
done
|
|
for N in douyinweb-neko-1 douyinweb-neko-3 douyinweb-ops-neko-1; do
|
|
echo ==$N==
|
|
docker exec "$N" supervisorctl status 2>/dev/null | head -10
|
|
done
|
|
'''
|
|
with sftp.file("/tmp/_neko_check.sh", "w") as f:
|
|
f.write(script)
|
|
sftp.close()
|
|
_, o, e = p.exec_command("echo '4669805' | sudo -S -p '' bash /tmp/_neko_check.sh", timeout=90)
|
|
print("=== PHYS ===")
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
p.close()
|