Lagt till diagnostic och mer inställningar
This commit is contained in:
+43
-7
@@ -4,7 +4,8 @@ const cors = require('cors');
|
||||
|
||||
const { requireAuth } = require('./auth');
|
||||
const { ensureDefaultAdmin } = require('./users');
|
||||
const audit = require('./audit');
|
||||
const audit = require('./audit');
|
||||
const settings = require('./settings');
|
||||
const secrets = require('./secrets');
|
||||
const schedule = require('node-schedule');
|
||||
|
||||
@@ -12,6 +13,7 @@ const zonesRouter = require('./routes/zones');
|
||||
const secretsRouter = require('./routes/secrets');
|
||||
const ipamRouter = require('./routes/ipam');
|
||||
const healthRouter = require('./routes/health');
|
||||
const diag = require('./diag');
|
||||
const recordsRouter = require('./routes/records');
|
||||
const settingsRouter = require('./routes/settings');
|
||||
const authRouter = require('./routes/auth');
|
||||
@@ -36,7 +38,22 @@ app.use('/api/settings', requireAuth, settingsRouter);
|
||||
app.use('/api/users', usersRouter);
|
||||
app.use('/api/secrets', secretsRouter);
|
||||
app.use('/api/ipam', ipamRouter);
|
||||
app.use('/api/health', healthRouter); // requireAuth applied inside router
|
||||
app.use('/api/health', healthRouter);
|
||||
|
||||
app.get('/api/diag', requireAuth, (req, res) => {
|
||||
const { provider, ok, limit, offset } = req.query;
|
||||
res.json(diag.getEntries({
|
||||
provider,
|
||||
ok: ok !== undefined ? ok === 'true' : undefined,
|
||||
limit: Math.min(parseInt(limit) || 100, 200),
|
||||
offset: parseInt(offset) || 0,
|
||||
}));
|
||||
});
|
||||
|
||||
app.delete('/api/diag', requireAuth, (req, res) => {
|
||||
diag.clearLog();
|
||||
res.json({ success: true });
|
||||
}); // requireAuth applied inside router
|
||||
|
||||
app.get('/api/audit', requireAuth, (req, res) => {
|
||||
const { limit, offset, user, action, provider, category } = req.query;
|
||||
@@ -107,12 +124,31 @@ async function checkSecretExpiryOnce() {
|
||||
await checkSecretExpiry();
|
||||
}
|
||||
|
||||
// Run at startup only if not already checked today (persisted to disk), then every day at 08:00
|
||||
// Build cron string from HH:MM setting
|
||||
function getSecretCron() {
|
||||
const time = settings.get().notifications?.secret_check_time ?? '08:00';
|
||||
const [h, m] = time.split(':').map(Number);
|
||||
return `${m ?? 0} ${h ?? 8} * * *`;
|
||||
}
|
||||
|
||||
let secretJob = null;
|
||||
|
||||
function scheduleSecretCheck() {
|
||||
if (secretJob) secretJob.cancel();
|
||||
const notif = settings.get().notifications ?? {};
|
||||
const tz = notif.timezone || 'UTC';
|
||||
secretJob = schedule.scheduleJob({ rule: getSecretCron(), tz }, () => {
|
||||
saveLastCheckDate('');
|
||||
const { notifications } = settings.get();
|
||||
if (notifications?.secret_check !== false) checkSecretExpiry();
|
||||
});
|
||||
console.log(`Secret check scheduled at ${notif.secret_check_time ?? '08:00'} (${tz})`);
|
||||
}
|
||||
|
||||
// Run at startup only if not already checked today, then on schedule
|
||||
checkSecretExpiryOnce();
|
||||
schedule.scheduleJob('0 8 * * *', () => {
|
||||
saveLastCheckDate(''); // clear so the scheduled job always fires
|
||||
checkSecretExpiry();
|
||||
});
|
||||
scheduleSecretCheck();
|
||||
module.exports = { scheduleSecretCheck };
|
||||
|
||||
const PORT = process.env.PORT || 3001;
|
||||
app.listen(PORT, () => console.log(`Sloth Manager backend running on port ${PORT}`));
|
||||
|
||||
Reference in New Issue
Block a user