feat(admin): rebuild admin panel as out-of-band login with backups

- Separate admin login (ADMIN_USERNAME/ADMIN_PASSWORD) with its own JWT,
  no longer a seeded user account; lockout after 5 failed attempts
- Admin panel tabs: Users, Notifications, Backups, Reset
- Ntfy settings moved from .env/compose into admin_settings (token encrypted)
- Scheduled and on-demand mariadb-dump backups to NFS volume, with
  restore (entries only or all) and retention pruning
- Reset all entries, guarded by an automatic safety backup
- Remove user impersonation and the admin link in the user nav
- Login page falls back to admin login; nginx sends Cache-Control: no-cache

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
derekcandClaude Opus 5.5 committed 2026-11-23 00:24:19 -08:00
1 parent c54d2b251f
commit 6272322f31
28 files changed
+1523 -461

No files matched your search

+11 -6
View File
@@ -17,14 +17,18 @@ def verify_password(plain: str, hashed: str) -> bool:
return pwd_context.verify(plain, hashed)
def create_token(user_id: int, admin_id: Optional[int] = None) -> str:
def create_token(user_id: int) -> str:
expire = datetime.now(timezone.utc) + timedelta(minutes=settings.access_token_expire_minutes)
payload: dict = {"sub": str(user_id), "exp": expire}
if admin_id is not None:
payload["admin_id"] = admin_id
return jwt.encode(payload, settings.secret_key, algorithm=settings.algorithm)
def create_admin_token() -> str:
# No "sub" claim, so decode_token() rejects it as a user token.
expire = datetime.now(timezone.utc) + timedelta(minutes=settings.access_token_expire_minutes)
return jwt.encode({"admin": True, "exp": expire}, settings.secret_key, algorithm=settings.algorithm)
def decode_token(token: str) -> Optional[int]:
try:
payload = jwt.decode(token, settings.secret_key, algorithms=[settings.algorithm])
@@ -36,8 +40,9 @@ def decode_token(token: str) -> Optional[int]:
return None
def decode_token_full(token: str) -> Optional[dict]:
def is_admin_token(token: str) -> bool:
try:
return jwt.decode(token, settings.secret_key, algorithms=[settings.algorithm])
payload = jwt.decode(token, settings.secret_key, algorithms=[settings.algorithm])
except JWTError:
return None
return False
return payload.get("admin") is True