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:
1 parent
c54d2b251f
commit
6272322f31
28 files changed
+1523
-461
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import logging
|
||||
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
from apscheduler.triggers.cron import CronTrigger
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.database import AsyncSessionLocal
|
||||
from app.models.admin_settings import AdminSettings
|
||||
from app.services.backup import run_backup
|
||||
|
||||
logger = logging.getLogger("bourbonacci.scheduler")
|
||||
|
||||
_JOB_ID = "scheduled_backup"
|
||||
_scheduler = AsyncIOScheduler(timezone="UTC")
|
||||
|
||||
|
||||
async def _run_scheduled_backup() -> None:
|
||||
async with AsyncSessionLocal() as db:
|
||||
try:
|
||||
await run_backup(db)
|
||||
except Exception:
|
||||
logger.exception("Scheduled backup failed")
|
||||
|
||||
|
||||
def reschedule(enabled: bool, frequency: str, hour: int, weekday: int) -> None:
|
||||
if _scheduler.get_job(_JOB_ID):
|
||||
_scheduler.remove_job(_JOB_ID)
|
||||
if not enabled:
|
||||
return
|
||||
trigger = CronTrigger(
|
||||
hour=hour,
|
||||
minute=0,
|
||||
day_of_week=weekday if frequency == "weekly" else "*",
|
||||
timezone="UTC",
|
||||
)
|
||||
_scheduler.add_job(_run_scheduled_backup, trigger, id=_JOB_ID, replace_existing=True)
|
||||
|
||||
|
||||
async def start() -> None:
|
||||
async with AsyncSessionLocal() as db:
|
||||
row = (await db.execute(select(AdminSettings).where(AdminSettings.id == 1))).scalar_one_or_none()
|
||||
if row:
|
||||
reschedule(row.backup_enabled, row.backup_frequency, row.backup_hour, row.backup_weekday)
|
||||
_scheduler.start()
|
||||
|
||||
|
||||
def shutdown() -> None:
|
||||
_scheduler.shutdown(wait=False)
|
||||
Reference in new issue
Block a user