99 lines
2.7 KiB
Python
99 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Scan physical assign + ops-neko for dual chrome / TM health."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
SCRIPT = r"""#!/bin/bash
|
|
set +e
|
|
probe() {
|
|
local N="$1"
|
|
docker inspect "$N" >/dev/null 2>&1 || { echo "$N MISSING"; return; }
|
|
docker exec -i "$N" python3 - <<'PY'
|
|
import os, json, urllib.request
|
|
from pathlib import Path
|
|
name=os.environ.get("HOSTNAME","?")
|
|
mains=[]; load=False
|
|
for pid in os.listdir("/proc"):
|
|
if not pid.isdigit(): continue
|
|
try: raw=open(f"/proc/{pid}/cmdline","rb").read()
|
|
except: continue
|
|
if not raw: continue
|
|
if b"google-chrome" in raw and b"--type=" not in raw and b"crashpad" not in raw and b"browser-launch" not in raw:
|
|
mains.append(pid)
|
|
if b"load-extension" in raw and b"dhdgff" in raw: load=True
|
|
sw=-1; tabs_n=0
|
|
try:
|
|
tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list",timeout=3).read())
|
|
tabs_n=len(tabs)
|
|
sw=sum(1 for t in tabs if t.get("type")=="service_worker" and "dhdgff" in (t.get("url") or ""))
|
|
except Exception as e:
|
|
sw=-1
|
|
les=Path("/home/neko/.config/google-chrome/Default/Local Extension Settings/dhdgffkkebhmkfjojejmpbldmpobfkfo/000003.log")
|
|
ad=False
|
|
if les.exists():
|
|
ad=b"YouTube Studio Auto Dismiss" in les.read_bytes()
|
|
trap=False
|
|
try:
|
|
trap=b"on_supervisor_stop" in open("/etc/neko/browser-launch.sh","rb").read()
|
|
except Exception:
|
|
pass
|
|
print(f"mains={len(mains)} load_ext={load} tm_sw={sw} tabs={tabs_n} auto_dismiss={ad} stop_trap={trap}")
|
|
PY
|
|
}
|
|
|
|
echo "=== assign ==="
|
|
for i in 1 2 3 4 5 6 7 8; do
|
|
echo -n "neko-$i "
|
|
probe douyinweb-neko-$i
|
|
done
|
|
echo "=== ops ==="
|
|
for i in 1 2; do
|
|
echo -n "ops-neko-$i "
|
|
# ops container names may vary
|
|
for cand in douyinweb-ops-neko-$i ops-neko-$i; do
|
|
if docker inspect "$cand" >/dev/null 2>&1; then
|
|
echo -n "($cand) "
|
|
probe "$cand"
|
|
break
|
|
fi
|
|
done
|
|
done
|
|
echo "=== browser-launch host ==="
|
|
grep -n on_supervisor_stop /opt/douyinWEB/backend/neko/browser-launch.sh | head
|
|
"""
|
|
|
|
|
|
def main() -> None:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
"107.173.30.245",
|
|
4014,
|
|
"eric",
|
|
"4669805",
|
|
timeout=45,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=120,
|
|
)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/_scan_phys_neko_tm.sh", "w") as f:
|
|
f.write(SCRIPT)
|
|
sftp.close()
|
|
_i, o, e = c.exec_command(
|
|
"echo '4669805' | sudo -S -p '' bash /tmp/_scan_phys_neko_tm.sh",
|
|
timeout=180,
|
|
)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|