Refactoring

This commit is contained in:
Carsten Graf
2026-01-23 14:13:18 +01:00
parent 33c62a7a2a
commit a0acd188a8
22 changed files with 2392 additions and 1611 deletions

View File

@@ -0,0 +1,34 @@
// LDAP-Scheduler Service
const { db } = require('../database');
const LDAPService = require('../ldap-service');
// Automatische LDAP-Synchronisation einrichten
function setupLDAPScheduler() {
// Prüfe alle 5 Minuten, ob eine Synchronisation notwendig ist
setInterval(() => {
db.get('SELECT * FROM ldap_config WHERE id = 1 AND enabled = 1 AND sync_interval > 0', (err, config) => {
if (err || !config) {
return; // Keine aktive Konfiguration
}
const now = new Date();
const lastSync = config.last_sync ? new Date(config.last_sync) : null;
const syncIntervalMs = config.sync_interval * 60 * 1000; // Minuten in Millisekunden
// Prüfe ob Synchronisation fällig ist
if (!lastSync || (now - lastSync) >= syncIntervalMs) {
console.log('Starte automatische LDAP-Synchronisation...');
LDAPService.performSync('scheduled', (err, result) => {
if (err) {
console.error('Fehler bei automatischer LDAP-Synchronisation:', err.message);
} else {
console.log(`Automatische LDAP-Synchronisation abgeschlossen: ${result.synced} Benutzer synchronisiert`);
}
});
}
});
}, 5 * 60 * 1000); // Alle 5 Minuten prüfen
}
module.exports = { setupLDAPScheduler };