99 lines
3.7 KiB
Python
99 lines
3.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Read-only: current ShellClash/TUIC/VLESS selection on phys + VPS."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import http.cookiejar as cookiejar
|
|
import urllib.request
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def call(base, path, op=None, timeout=40):
|
|
req = urllib.request.Request(base + path, headers={"Content-Type": "application/json"})
|
|
opener = op or urllib.request.build_opener()
|
|
with opener.open(req, timeout=timeout) as r:
|
|
return json.loads(r.read().decode())
|
|
|
|
|
|
def login(base):
|
|
cj = cookiejar.CookieJar()
|
|
op = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
|
|
data = json.dumps({"username": "hackrobot", "password": "Xiao4669805@"}).encode()
|
|
req = urllib.request.Request(
|
|
base + "/api/auth/login", data=data, method="POST", headers={"Content-Type": "application/json"}
|
|
)
|
|
op.open(req, timeout=25)
|
|
return op
|
|
|
|
|
|
def ssh_probe(label, host, port, user, pw, sudo=False):
|
|
print(f"\n===== {label} =====")
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(host, port, user, pw, timeout=40, allow_agent=False, look_for_keys=False)
|
|
|
|
def run(cmd, t=60):
|
|
if sudo:
|
|
cmd = f"echo '{pw}' | sudo -S -p '' bash -lc {repr(cmd)}"
|
|
_, o, e = c.exec_command(cmd, timeout=t)
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
print(run(
|
|
"grep -E 'DY_SHELLCRASH|DEFAULT_NODE|VLESS|TUIC' /etc/systemd/system/douyinweb-api.service "
|
|
"/etc/systemd/system/douyinweb-api.service.d/* 2>/dev/null | sed -n '1,40p'"
|
|
))
|
|
print(run(
|
|
"grep -nE 'default_node|VLESS|TUIC|pick_best|hy2|hysteria|tuic' "
|
|
"/opt/douyinWEB/backend/app/shellcrash_hub.py 2>/dev/null | sed -n '1,40p'"
|
|
))
|
|
# clash API now-node if available
|
|
print(run(
|
|
"curl -sS -m 5 http://127.0.0.1:9999/proxies 2>/dev/null | python3 -c "
|
|
"\"import sys,json; d=json.load(sys.stdin); "
|
|
"ps=d.get('proxies') or {}; "
|
|
"keys=['GLOBAL','PROXY','Select','自动选择','节点选择','FINAL']; "
|
|
"[print(k, (ps.get(k) or {}).get('now'), (ps.get(k) or {}).get('type')) for k in keys if k in ps]; "
|
|
"nows=[(k,v.get('now')) for k,v in ps.items() if isinstance(v,dict) and v.get('type')=='Selector']; "
|
|
"print('selectors', len(nows)); "
|
|
"[print(' ',k,n) for k,n in nows[:12]]\" 2>/dev/null || echo no_clash_api"
|
|
))
|
|
print(run(
|
|
"python3 - <<'PY'\n"
|
|
"import re\n"
|
|
"from pathlib import Path\n"
|
|
"for p in [Path('/tmp/ShellCrash/config.yaml'), Path('/opt/douyinWEB/backend/data/shellcrash/config.yaml')]:\n"
|
|
" if not p.exists():\n"
|
|
" print('missing', p); continue\n"
|
|
" t=p.read_text(encoding='utf-8',errors='replace')\n"
|
|
" print(p, 'len', len(t))\n"
|
|
" for pat in ['tuic','hysteria','vless','interface-name']:\n"
|
|
" print(' ',pat, len(re.findall(pat,t,re.I)))\n"
|
|
"PY"
|
|
))
|
|
c.close()
|
|
|
|
|
|
for base in ["https://dy.nomadro.com", "https://dylive.nomadro.com"]:
|
|
try:
|
|
op = login(base)
|
|
for path in [
|
|
"/api/network/shellcrash/status",
|
|
"/api/network/status",
|
|
]:
|
|
try:
|
|
d = call(base, path, op, timeout=35)
|
|
# scrub secrets
|
|
s = json.dumps(d, ensure_ascii=False)[:500]
|
|
print(base, path, s)
|
|
except Exception as ex:
|
|
print(base, path, "ERR", ex)
|
|
except Exception as ex:
|
|
print(base, "login ERR", ex)
|
|
|
|
ssh_probe("PHYS", "107.173.30.245", 4014, "eric", "4669805", sudo=True)
|
|
ssh_probe("VPS", "107.173.30.245", 22, "root", "Xiao4669805", sudo=False)
|