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

166 lines
5.6 KiB
Python

#!/usr/bin/env python3
"""Dual verify: keys API/UI + timeslot neko health on dy + dylive."""
from __future__ import annotations
import json
import ssl
import sys
import time
import urllib.error
import urllib.request
from http.cookiejar import CookieJar
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
SITES = [
("dy", "https://dy.nomadro.live", "108.174.50.68", "douyinweb-neko-10"),
("dylive", "https://dylive.nomadro.com", "107.173.30.245", "douyinweb-neko-12"),
]
USER = "hackrobot"
PASS = "Xiao4669805@"
SSH_PASS = "Xiao4669805"
CTX = ssl.create_default_context()
def login_opener(base: str):
cj = CookieJar()
op = urllib.request.build_opener(
urllib.request.HTTPCookieProcessor(cj),
urllib.request.HTTPSHandler(context=CTX),
)
req = urllib.request.Request(
f"{base}/api/auth/login",
data=json.dumps({"username": USER, "password": PASS}).encode(),
headers={"Content-Type": "application/json"},
method="POST",
)
with op.open(req, timeout=45) as r:
body = r.read().decode("utf-8", "replace")
print(f" login {r.status} {body[:120]}")
return op
def get(op, url: str):
try:
with op.open(url, timeout=45) as r:
raw = r.read()
return r.status, raw
except urllib.error.HTTPError as e:
return e.code, e.read()
except Exception as e:
return 0, str(e).encode()
def ssh_check(host: str, neko: str):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(8):
try:
c.connect(
host,
22,
"root",
SSH_PASS,
timeout=50,
allow_agent=False,
look_for_keys=False,
banner_timeout=180,
)
break
except Exception as e:
print(f" ssh_retry {i}: {e}")
time.sleep(2 + i)
else:
return "ssh_fail"
cmd = f"""
set +e
docker ps --filter name={neko} --format '{{{{.Names}}}} {{{{.Status}}}}'
docker exec {neko} sh -c '
supervisorctl status google-chrome 2>/dev/null | head -1
grep -n "js-flags" /etc/neko/browser-launch.sh | head -1
curl -sS -m 3 http://127.0.0.1:9222/json/version 2>/dev/null | head -c 100; echo
python3 - <<"PY"
import json,urllib.request
try:
tabs=json.load(urllib.request.urlopen("http://127.0.0.1:9222/json",timeout=5))
studio=[t for t in tabs if "studio.youtube" in (t.get("url") or "")]
print("tabs",len(tabs),"studio",len(studio))
for t in studio[:2]:
print(" ", (t.get("url") or "")[:100])
except Exception as e:
print("tabs_err",e)
PY
'
# free mem snapshot
free -m | head -2
docker ps --format '{{{{.Names}}}} {{{{.Status}}}}' | grep -v douyinweb | head -20
"""
_i, o, e = c.exec_command(cmd, timeout=90)
out = (o.read() + e.read()).decode("utf-8", "replace")
c.close()
return out
def main():
for name, base, host, neko in SITES:
print(f"\n======== {name} {base} ========", flush=True)
op = login_opener(base)
for path in ("/youtube", "/youtube/keys"):
st, raw = get(op, base + path)
text = raw.decode("utf-8", "replace") if isinstance(raw, (bytes, bytearray)) else str(raw)
hit = "youtube/keys" in text or "stream-key" in text or "Key" in text or "key表" in text
print(f" GET {path} -> {st} bytes={len(raw) if isinstance(raw, (bytes, bytearray)) else 0} hint={hit}")
st, raw = get(op, base + "/api/youtube/stream-keys")
try:
data = json.loads(raw.decode() if isinstance(raw, (bytes, bytearray)) else raw)
except Exception:
data = {"_raw": (raw[:200] if isinstance(raw, (bytes, bytearray)) else raw)}
items = data.get("items") or data.get("keys") or data if isinstance(data, list) else []
if isinstance(data, dict) and not items:
# try nested
for k in ("data", "registry", "entries"):
if isinstance(data.get(k), list):
items = data[k]
break
print(f" stream-keys API {st} type={type(data).__name__} items={len(items) if isinstance(items, list) else '?'}")
if isinstance(items, list) and items:
sample = items[0] if isinstance(items[0], dict) else {}
sk = sample.get("stream_key") or sample.get("key") or ""
print(f" sample keys={list(sample.keys())[:12]} stream_key_len={len(str(sk))} prefix={(str(sk)[:6]+'…') if sk else 'EMPTY'}")
st, raw = get(op, base + "/api/youtube/assign/groups?include_secret=1")
try:
groups = json.loads(raw.decode() if isinstance(raw, (bytes, bytearray)) else raw)
except Exception:
groups = []
if isinstance(groups, dict):
groups = groups.get("groups") or groups.get("items") or []
full = 0
masked = 0
if isinstance(groups, list):
for g in groups:
if not isinstance(g, dict):
continue
sk = str(g.get("stream_key") or "")
if not sk:
continue
if "*" in sk or sk.endswith("…") or len(sk) < 12:
masked += 1
else:
full += 1
print(f" assign groups {st} n={len(groups)} full_keys={full} masked_or_short={masked}")
else:
print(f" assign groups {st} unexpected {type(groups)}")
print(" --- neko ---")
print(ssh_check(host, neko))
print("\nALL_DONE", flush=True)
if __name__ == "__main__":
main()