35 lines
1.3 KiB
JavaScript
35 lines
1.3 KiB
JavaScript
// 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 };
|