Add audit log viewer to Settings page

This commit is contained in:
Gan, Jimmy
2026-02-22 12:34:21 +08:00
parent 19b3de3c91
commit a32588a7cc
2 changed files with 44 additions and 2 deletions
+16 -2
View File
@@ -4,8 +4,8 @@ import psutil
import platform
import time
import httpx
from fastapi import APIRouter
from config import TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID
from fastapi import APIRouter, Query
from config import TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID, VOLUME_ROOT
router = APIRouter()
@@ -54,3 +54,17 @@ def system_stats():
"uptime": f"{days}d {hours}h",
"platform": platform.platform(),
}
@router.get("/audit-log")
def audit_log(lines: int = Query(100, le=500)):
log_path = os.path.join(VOLUME_ROOT, "docker/nas-dashboard/audit.log")
if not os.path.exists(log_path):
return {"lines": []}
with open(log_path, "rb") as f:
f.seek(0, 2)
size = f.tell()
buf = min(size, lines * 200)
f.seek(max(0, size - buf))
data = f.read().decode(errors="replace").splitlines()
return {"lines": data[-lines:]}