feat: show node connection status and traffic stats in admin panel

Enable sing-box Clash/V2Ray APIs for per-user metrics, persist cumulative
traffic in SQLite, and refresh the dashboard every five seconds.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-16 09:57:16 +08:00
parent f0a3317e8b
commit ccf7e2a4c7
12 changed files with 595 additions and 3 deletions
+25 -2
View File
@@ -54,9 +54,14 @@ def build_config(env: dict[str, str], nodes: list[dict]) -> dict:
raise SystemExit(f".env 缺少 {key}")
vless_users = [{"uuid": n["uuid"], "flow": "xtls-rprx-vision"} for n in nodes]
hy2_users = [{"password": n["hy2_password"]} for n in nodes]
# name 与 VLESS uuid 一致,便于 v2ray/clash API 按用户统计流量
hy2_users = [
{"name": n["uuid"], "password": n["hy2_password"]} for n in nodes
]
user_ids = [n["uuid"] for n in nodes]
clash_secret = env.get("CLASH_API_SECRET", "")
return {
config = {
"log": {"level": "warn", "timestamp": True},
"inbounds": [
{
@@ -100,6 +105,24 @@ def build_config(env: dict[str, str], nodes: list[dict]) -> dict:
},
}
experimental: dict = {
"clash_api": {
"external_controller": "127.0.0.1:9090",
},
"v2ray_api": {
"listen": "127.0.0.1:9091",
"stats": {
"enabled": True,
"inbounds": ["vless-reality-in", "hysteria2-in"],
"users": user_ids,
},
},
}
if clash_secret:
experimental["clash_api"]["secret"] = clash_secret
config["experimental"] = experimental
return config
def main() -> None:
env = load_env(ENV_FILE)