Hub v1: install API, licences, health dashboard, alerts
- Protocol 1 (docs/hub-protocol.md): public key, register, signed heartbeats - Ed25519 licence tokens (30-day validity, status, expiry, grace, limits) - Dashboard: installs, install detail, customers and licences, alerts, settings and audit log; two-factor login required - Alert checks every 5 minutes, emailed once; heartbeat roll-up after 30 days - Unit tests for encryption, tokens, signatures, TOTP and alert rules Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012mt6TCv85T9VKRq3cV7rXq
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
const prisma = require('../config/db');
|
||||
|
||||
// Hub settings Joshua edits on the Settings page, with their defaults.
|
||||
const DEFAULTS = {
|
||||
latest_version: '',
|
||||
alert_email: '',
|
||||
// Alert thresholds
|
||||
offline_minutes: '60',
|
||||
backup_max_age_hours: '48',
|
||||
disk_min_free_percent: '10',
|
||||
errors_per_day: '50',
|
||||
licence_expiry_warning_days: '14',
|
||||
};
|
||||
|
||||
async function getSettings() {
|
||||
const rows = await prisma.setting.findMany();
|
||||
const saved = Object.fromEntries(rows.map(r => [r.key, r.value]));
|
||||
return { ...DEFAULTS, ...saved };
|
||||
}
|
||||
|
||||
async function setSettings(values) {
|
||||
const updates = Object.entries(values || {}).filter(([k]) => k in DEFAULTS);
|
||||
for (const [key, value] of updates) {
|
||||
await prisma.setting.upsert({ where: { key }, update: { value: String(value ?? '') }, create: { key, value: String(value ?? '') } });
|
||||
}
|
||||
return getSettings();
|
||||
}
|
||||
|
||||
module.exports = { DEFAULTS, getSettings, setSettings };
|
||||
Reference in New Issue
Block a user