feat: config history (diff/rollback) + friendly backup scheduling (v0.12.3-beta)

Configuration History:
- Per-device snapshots from the full RouterOS /export (.rsc) — config-only, so
  counters/operational state no longer cause phantom changes; deduped by content hash
- New Config History tab: snapshot timeline, readable line diff, on-demand Capture
  (with honest 'no changes' feedback), one-click rollback via the linked .rsc backup
- Snapshot and its backup are one artifact: badged 'Config Snapshot' on the Backups
  page, FK ON DELETE CASCADE keeps them in lockstep; delete is gated by a warning modal
- New config_drift alert event (off by default); periodic snapshot poll with
  configurable cadence/retention (config_snapshot_interval_min/_retention)
- New endpoints under /api/config-history (list/get/diff/capture/rollback/delete)

Scheduled Backups:
- Replaced the raw cron textbox in Settings with Frequency (Daily/Weekly/Monthly)
  + time + day pickers; cron is generated/parsed behind the scenes
- Fixed cronMatchesNow to evaluate day-of-month/month/day-of-week (it previously
  only checked minute/hour, so weekly/monthly schedules ran every day)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2GT-Rich
2026-06-06 16:01:58 -07:00
co-authored by Claude Opus 4.8
parent 4ff5ed805c
commit 367034c2d6
20 changed files with 1075 additions and 81 deletions
+17
View File
@@ -183,6 +183,20 @@ ALTER TABLE devices ADD COLUMN IF NOT EXISTS latest_ros_version VARCHAR(20);
ALTER TABLE devices ADD COLUMN IF NOT EXISTS routerboard_upgrade_available BOOLEAN DEFAULT FALSE;
ALTER TABLE devices ADD COLUMN IF NOT EXISTS upgrade_firmware_version VARCHAR(20);
-- Config history / drift detection: each snapshot stores the canonical /export
-- .rsc text (config_text), deduped by content hash, and links to the restorable
-- backup that holds the same .rsc. The snapshot and its backup are one artifact,
-- so deleting the backup cascades to remove the snapshot (kept consistent).
ALTER TABLE device_configs ADD COLUMN IF NOT EXISTS config_hash VARCHAR(64);
ALTER TABLE device_configs ADD COLUMN IF NOT EXISTS change_summary TEXT;
ALTER TABLE device_configs ADD COLUMN IF NOT EXISTS config_text TEXT;
ALTER TABLE device_configs ADD COLUMN IF NOT EXISTS backup_id INTEGER REFERENCES backups(id) ON DELETE SET NULL;
-- Upgrade the backup_id FK from SET NULL to CASCADE so a snapshot and its backup
-- stay in lockstep (deleting the backup removes the now-unrestorable snapshot).
ALTER TABLE device_configs DROP CONSTRAINT IF EXISTS device_configs_backup_id_fkey;
ALTER TABLE device_configs ADD CONSTRAINT device_configs_backup_id_fkey
FOREIGN KEY (backup_id) REFERENCES backups(id) ON DELETE CASCADE;
-- Cached IPv4/IPv6 addresses from /ip/address (per device) for topology resolution:
-- neighbors seen only by IP (CDP/MNDP) can be matched to managed devices even
-- when the address is not the device's management IP.
@@ -407,6 +421,9 @@ const DEFAULT_SETTINGS = [
{ key: 'ap_scan_interval_hours', value: 24 },
{ key: 'login_rate_limit_window_sec', value: 60 },
{ key: 'login_rate_limit_max', value: 10 },
{ key: 'config_snapshot_enabled', value: true },
{ key: 'config_snapshot_interval_min', value: 60 },
{ key: 'config_snapshot_retention', value: 30 },
];
export async function runMigrations(): Promise<void> {