From a32588a7ccfd7f29d9d3f2f39ad247d0cc305cec Mon Sep 17 00:00:00 2001 From: "Gan, Jimmy" Date: Sun, 22 Feb 2026 12:34:21 +0800 Subject: [PATCH] Add audit log viewer to Settings page --- dashboard/backend/routers/system.py | 18 ++++++++++-- dashboard/frontend/src/routes/Settings.svelte | 28 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/dashboard/backend/routers/system.py b/dashboard/backend/routers/system.py index 2e5fdab..8395543 100644 --- a/dashboard/backend/routers/system.py +++ b/dashboard/backend/routers/system.py @@ -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:]} diff --git a/dashboard/frontend/src/routes/Settings.svelte b/dashboard/frontend/src/routes/Settings.svelte index 3b090c4..8114324 100644 --- a/dashboard/frontend/src/routes/Settings.svelte +++ b/dashboard/frontend/src/routes/Settings.svelte @@ -113,6 +113,18 @@ } saving = false; } + + let auditLines = $state([]); + let auditLoading = $state(false); + + async function loadAuditLog() { + auditLoading = true; + try { + const res = await get("/system/audit-log?lines=100"); + auditLines = res.lines.reverse(); + } catch {} + auditLoading = false; + }
@@ -189,4 +201,20 @@ {/if}
+ +
+
+

Audit Log

+ +
+ {#if auditLines.length > 0} +
+
{auditLines.join('\n')}
+
+ {:else if !auditLoading} +

Click Load to view recent audit log entries

+ {/if} +