171 lines
7.0 KiB
Python
171 lines
7.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Avatar URLs + live API cover fields + dy Seaweed identity / anonymous GET."""
|
|
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")
|
|
CTX = ssl.create_default_context()
|
|
|
|
|
|
def http_get(url: str, headers=None, cookiejar=None):
|
|
opener = urllib.request.build_opener(
|
|
urllib.request.HTTPSHandler(context=CTX),
|
|
urllib.request.HTTPCookieProcessor(cookiejar or CookieJar()),
|
|
)
|
|
req = urllib.request.Request(url, headers=headers or {"User-Agent": "diag"})
|
|
with opener.open(req, timeout=25) as r:
|
|
return r.status, r.read(), dict(r.headers)
|
|
|
|
|
|
SCRIPT = r"""
|
|
set +e
|
|
cd /opt/douyinWEB/backend
|
|
echo '=== avatar_url samples ==='
|
|
./.venv/bin/python - <<'PY'
|
|
from app.db import _connect, _lock
|
|
with _lock:
|
|
conn=_connect()
|
|
for r in conn.execute("SELECT id, substr(avatar_url,1,180) FROM rooms WHERE avatar_url IS NOT NULL AND avatar_url!='' LIMIT 8").fetchall():
|
|
print('avatar', r[0], r[1])
|
|
# how many http avatars
|
|
n=conn.execute("SELECT COUNT(*) FROM rooms WHERE avatar_url LIKE 'http%'").fetchone()[0]
|
|
print('http_avatars', n)
|
|
# cover_path host distribution
|
|
for r in conn.execute("SELECT CASE WHEN cover_path LIKE 'https://s3.nomadro.com%' THEN 's3.nomadro' WHEN cover_path LIKE 'https://dy.nomadro.live%' THEN 'dy.live' WHEN cover_path LIKE 'http%' THEN 'other_http' ELSE 'local' END AS k, COUNT(*) FROM sessions WHERE cover_path IS NOT NULL AND cover_path!='' GROUP BY 1").fetchall():
|
|
print('cover_host', r[0], r[1])
|
|
PY
|
|
echo
|
|
echo '=== seaweed identity / config ==='
|
|
ls /etc/seaweed* /var/lib/seaweed* /opt/seaweed* 2>/dev/null | head
|
|
systemctl cat seaweed-s3.service douyinweb-s3.service 2>/dev/null | head -80
|
|
# find identity.json / config.json
|
|
find /etc /var/lib /opt /root -name '*identity*' 2>/dev/null | head -20
|
|
find /etc /var/lib /opt -path '*seaweed*' -name '*.json' 2>/dev/null | head -30
|
|
echo
|
|
echo '=== anonymous GET local s3 object ==='
|
|
# pick a key
|
|
KEY=$(cd /opt/douyinWEB/backend && ./.venv/bin/python - <<'PY'
|
|
from app.db import _connect, _lock
|
|
with _lock:
|
|
conn=_connect()
|
|
r=conn.execute("SELECT cover_path FROM sessions WHERE cover_path LIKE '%/covers/%' ORDER BY rowid DESC LIMIT 1").fetchone()
|
|
print((r[0] if r else '').split('/douyin-covers/',1)[-1] if r else '')
|
|
PY
|
|
)
|
|
echo key_path=$KEY
|
|
curl -sS -m 5 -o /dev/null -w "anon_local_8333:%{http_code}\n" "http://127.0.0.1:8333/douyin-covers/$KEY"
|
|
curl -sS -m 5 -o /dev/null -w "anon_local_8333_root:%{http_code}\n" "http://127.0.0.1:8333/$KEY"
|
|
# with AWS style path
|
|
curl -sS -m 5 -D- -o /tmp/s3obj.bin "http://127.0.0.1:8333/douyin-covers/$(echo $KEY | sed 's#^covers/##;s#^#covers/#')" 2>&1 | head -20
|
|
file /tmp/s3obj.bin 2>/dev/null | head -1
|
|
echo
|
|
echo '=== frp 28333 on this host? ==='
|
|
ss -lntp | grep -E '28333|8333' | head
|
|
echo HOST_DONE
|
|
"""
|
|
|
|
for label, host, site in [
|
|
("dylive", "107.173.30.245", "https://dylive.nomadro.com"),
|
|
("dy", "108.174.50.68", "https://dy.nomadro.live"),
|
|
]:
|
|
print(f"\n######## {label} {host} ########", flush=True)
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(6):
|
|
try:
|
|
c.connect(host, 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False, banner_timeout=120)
|
|
break
|
|
except Exception as e:
|
|
print("retry", e, flush=True)
|
|
time.sleep(2)
|
|
else:
|
|
raise SystemExit("ssh fail")
|
|
_i, o, e = c.exec_command(SCRIPT, timeout=120)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
|
|
c.close()
|
|
|
|
# login + fetch sessions/active sample cover fields
|
|
print(f"--- API sessions cover fields {site} ---", flush=True)
|
|
cj = CookieJar()
|
|
opener = urllib.request.build_opener(
|
|
urllib.request.HTTPSHandler(context=CTX),
|
|
urllib.request.HTTPCookieProcessor(cj),
|
|
)
|
|
login_body = json.dumps({"username": "hackrobot", "password": "Xiao4669805@"}).encode()
|
|
req = urllib.request.Request(
|
|
site + "/api/auth/login",
|
|
data=login_body,
|
|
headers={"Content-Type": "application/json", "User-Agent": "diag"},
|
|
method="POST",
|
|
)
|
|
try:
|
|
with opener.open(req, timeout=25) as r:
|
|
print("login", r.status, flush=True)
|
|
except Exception as ex:
|
|
print("login_err", ex, flush=True)
|
|
continue
|
|
for path in ("/api/sessions/active", "/api/rooms"):
|
|
try:
|
|
req2 = urllib.request.Request(site + path, headers={"User-Agent": "diag"})
|
|
with opener.open(req2, timeout=30) as r:
|
|
data = json.loads(r.read().decode("utf-8", "replace"))
|
|
items = data.get("sessions") or data.get("rooms") or data.get("items") or data
|
|
if isinstance(items, dict):
|
|
items = items.get("sessions") or items.get("rooms") or []
|
|
if not isinstance(items, list):
|
|
print(path, "unexpected", type(items), flush=True)
|
|
continue
|
|
print(path, "count", len(items), flush=True)
|
|
for it in items[:5]:
|
|
print(
|
|
" sample",
|
|
{
|
|
"id": str(it.get("id") or "")[:12],
|
|
"cover_url": (it.get("cover_url") or "")[:100],
|
|
"cover_proxy_url": (it.get("cover_proxy_url") or "")[:80],
|
|
"avatar_url": (it.get("avatar_url") or "")[:100],
|
|
"cover_path": (it.get("cover_path") or "")[:100],
|
|
},
|
|
flush=True,
|
|
)
|
|
except Exception as ex:
|
|
print(path, "ERR", ex, flush=True)
|
|
|
|
# VPS: check dy.nomadro.live caddy target 28333 and probe
|
|
print("\n######## VPS caddy dy.nomadro.live S3 path ########", flush=True)
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False, banner_timeout=120)
|
|
_i, o, e = c.exec_command(
|
|
r"""
|
|
set +e
|
|
echo '=== active dy.nomadro.live site snippet ==='
|
|
# prefer live domain file if any
|
|
ls /etc/caddy/sites/ | grep -i dy
|
|
sed -n '1,80p;560,590p' /etc/caddy/sites/dy.nomadro.com.caddy 2>/dev/null
|
|
echo
|
|
# is there dy.nomadro.live site?
|
|
grep -Rnl 'dy.nomadro.live' /etc/caddy/sites 2>/dev/null | head
|
|
for f in /etc/caddy/sites/*live*; do echo FILE=$f; grep -nE 'douyin-covers|8333|28333|covers' "$f" 2>/dev/null | head -20; done
|
|
echo
|
|
echo '=== local 28333 ==='
|
|
ss -lntp | grep 28333 || true
|
|
curl -sS -m 5 -o /dev/null -w "vps_28333:%{http_code}\n" "http://127.0.0.1:28333/"
|
|
curl -sS -m 5 -o /dev/null -w "obj28333:%{http_code}\n" "http://127.0.0.1:28333/douyin-covers/covers/ab13d4f5-9639-40db-a40f-6af8443f3757.jpg"
|
|
curl -sS -m 5 -o /dev/null -w "obj_wg_dy:%{http_code}\n" "http://10.8.0.2:8333/douyin-covers/covers/ab13d4f5-9639-40db-a40f-6af8443f3757.jpg"
|
|
""",
|
|
timeout=60,
|
|
)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
|
|
c.close()
|
|
print("ALL_DONE", flush=True)
|