feat: audit log всех действий + GLM-5.1 + домен infosmeta.ru

- Таблица audit_log + middleware для логирования всех API-запросов
- Раздел "Журнал" в админке с фильтрами по пользователю/действию
- Переход на GLM-5.1 с отключённым reasoning (thinking: disabled)
- max_tokens 2000→4096, timeout 60→120с
- Домен smeta.kazin.ru → infosmeta.ru во всех файлах

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
anor
2026-04-09 15:51:54 +10:00
co-authored by Claude Opus 4.6
parent adeb92f4d0
commit 1afa7adbaf
8 changed files with 235 additions and 14 deletions
+47
View File
@@ -40,6 +40,20 @@ CREATE TABLE IF NOT EXISTS invites (
created_at REAL NOT NULL,
expires_at REAL NOT NULL
);
CREATE TABLE IF NOT EXISTS audit_log (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp REAL NOT NULL,
username TEXT,
action TEXT NOT NULL,
method TEXT NOT NULL,
path TEXT NOT NULL,
detail TEXT,
ip TEXT,
status_code INTEGER
);
CREATE INDEX IF NOT EXISTS idx_audit_ts ON audit_log(timestamp);
CREATE INDEX IF NOT EXISTS idx_audit_user ON audit_log(username);
"""
@@ -201,6 +215,39 @@ def get_history_any_user(tab_id: str, limit: int = 100) -> list[dict]:
return [dict(r) for r in reversed(rows)]
# === Audit Log ===
def log_action(username: str | None, action: str, method: str, path: str,
detail: str | None = None, ip: str | None = None,
status_code: int | None = None):
with _conn() as conn:
conn.execute(
"INSERT INTO audit_log (timestamp, username, action, method, path, detail, ip, status_code) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
(time.time(), username, action, method, path, detail, ip, status_code),
)
def get_audit_log(limit: int = 100, offset: int = 0,
username: str | None = None,
action: str | None = None) -> list[dict]:
where, params = [], []
if username:
where.append("username = ?")
params.append(username)
if action:
where.append("action = ?")
params.append(action)
clause = ("WHERE " + " AND ".join(where)) if where else ""
params += [limit, offset]
with _conn() as conn:
rows = conn.execute(
f"SELECT * FROM audit_log {clause} ORDER BY id DESC LIMIT ? OFFSET ?",
params,
).fetchall()
return [dict(r) for r in rows]
def list_sessions(username: str) -> list[dict]:
"""List all chat sessions for a user with last message preview."""
with _conn() as conn: