120 lines
3.6 KiB
Python
120 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Verify yt-long quota persist + start qemu-guest-agent (no reboot/neko)."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import urllib.request
|
|
import http.cookiejar
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def api_check(base: str, label: str) -> None:
|
|
cj = http.cookiejar.CookieJar()
|
|
op = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
|
|
req = urllib.request.Request(
|
|
base + "/api/auth/login",
|
|
data=json.dumps({"username": "hackrobot", "password": "Xiao4669805@"}).encode(),
|
|
headers={"Content-Type": "application/json"},
|
|
method="POST",
|
|
)
|
|
print(label, "login", op.open(req, timeout=25).status, flush=True)
|
|
# set 7
|
|
req2 = urllib.request.Request(
|
|
base + "/api/yt-long/settings",
|
|
data=json.dumps({"yt_long_channel_daily_max": 7, "apply_channel_daily_max": True, "enabled_only": True}).encode(),
|
|
headers={"Content-Type": "application/json"},
|
|
method="POST",
|
|
)
|
|
r = json.loads(op.open(req2, timeout=45).read())
|
|
print(
|
|
label,
|
|
"apply",
|
|
"settings=",
|
|
r.get("settings", {}).get("yt_long_channel_daily_max"),
|
|
"top=",
|
|
r.get("channel_daily_max"),
|
|
"quota_apply=",
|
|
r.get("quota_apply"),
|
|
flush=True,
|
|
)
|
|
st = json.loads(op.open(base + "/api/yt-long/status", timeout=45).read())
|
|
print(
|
|
label,
|
|
"status",
|
|
st.get("settings", {}).get("yt_long_channel_daily_max"),
|
|
"top",
|
|
st.get("channel_daily_max"),
|
|
flush=True,
|
|
)
|
|
# board channel sample
|
|
chans = (st.get("board") or {}).get("channels") or []
|
|
if not chans:
|
|
# try channels list endpoint if any
|
|
try:
|
|
cl = json.loads(op.open(base + "/api/yt-long/channels", timeout=30).read())
|
|
chans = cl.get("channels") or []
|
|
except Exception as e:
|
|
print(label, "channels_err", e, flush=True)
|
|
sample = [
|
|
{"name": c.get("name"), "daily_max": c.get("daily_max"), "enabled": c.get("enabled")}
|
|
for c in chans[:5]
|
|
]
|
|
print(label, "channels_sample", sample, flush=True)
|
|
|
|
|
|
AGENT = r"""#!/bin/bash
|
|
set -e
|
|
echo '=== before ==='
|
|
free -h | head -2
|
|
grep MemTotal /proc/meminfo
|
|
systemctl is-active qemu-guest-agent 2>/dev/null || true
|
|
if ! dpkg -l qemu-guest-agent 2>/dev/null | grep -q '^ii'; then
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
apt-get update -qq
|
|
apt-get install -y -qq qemu-guest-agent
|
|
fi
|
|
systemctl enable --now qemu-guest-agent
|
|
sleep 1
|
|
systemctl is-active qemu-guest-agent
|
|
echo '=== after mem ==='
|
|
free -h | head -2
|
|
grep -E 'MemTotal|MemAvailable|SwapTotal|SwapFree' /proc/meminfo
|
|
"""
|
|
|
|
|
|
def phys_agent() -> None:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 4014, "eric", "4669805", timeout=40, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/_ga_start.sh", "w") as f:
|
|
f.write(AGENT)
|
|
sftp.close()
|
|
print("===== PHYS guest-agent =====", flush=True)
|
|
_, o, e = c.exec_command("echo '4669805' | sudo -S -p '' bash /tmp/_ga_start.sh", timeout=180)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
|
|
c.close()
|
|
|
|
|
|
def main() -> int:
|
|
for base, label in (
|
|
("https://dy.nomadro.com", "dy"),
|
|
("https://dylive.nomadro.com", "dylive"),
|
|
):
|
|
try:
|
|
api_check(base, label)
|
|
except Exception as ex:
|
|
print(label, "ERR", ex, flush=True)
|
|
print("---", flush=True)
|
|
phys_agent()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|