🎉 Feature: Enhanced log management & firewall integration in backend

This commit is contained in:
2025-06-01 13:54:05 +02:00
parent d6f00ab40d
commit 38202de49f
9 changed files with 799 additions and 118 deletions

View File

@ -624,6 +624,7 @@ class MaintenanceModal {
this.triggerBtn = document.getElementById('maintenance-btn');
this.closeBtn = document.getElementById('close-maintenance-modal');
this.isOpen = false;
this.isLoading = false;
this.initializeEventListeners();
}
@ -705,28 +706,101 @@ class MaintenanceModal {
}
}
setLoadingState(loading) {
this.isLoading = loading;
const buttons = this.modal.querySelectorAll('button:not(#close-maintenance-modal)');
buttons.forEach(button => {
if (loading) {
button.disabled = true;
button.style.opacity = '0.6';
button.style.cursor = 'not-allowed';
// Spinner hinzufügen
if (!button.querySelector('.loading-spinner')) {
const spinner = document.createElement('div');
spinner.className = 'loading-spinner inline-block w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin mr-2';
button.insertBefore(spinner, button.firstChild);
}
} else {
button.disabled = false;
button.style.opacity = '1';
button.style.cursor = 'pointer';
// Spinner entfernen
const spinner = button.querySelector('.loading-spinner');
if (spinner) {
spinner.remove();
}
}
});
// Loading-Overlay anzeigen/verstecken
const loadingOverlay = document.getElementById('loading-overlay');
if (loadingOverlay) {
if (loading) {
loadingOverlay.classList.remove('hidden');
} else {
loadingOverlay.classList.add('hidden');
}
}
}
async executeAction(actionType) {
if (this.isLoading) return;
try {
this.setLoadingState(true);
let endpoint = '';
let confirmMessage = '';
let successMessage = '';
switch (actionType) {
case 'clearCache':
await clearCache();
endpoint = '/api/admin/maintenance/clear-cache';
confirmMessage = 'Möchten Sie den Cache wirklich leeren?';
successMessage = 'Cache erfolgreich geleert';
break;
case 'optimizeDatabase':
await optimizeDatabase();
endpoint = '/api/admin/maintenance/optimize-database';
confirmMessage = 'Möchten Sie die Datenbank optimieren? Dies kann einige Minuten dauern.';
successMessage = 'Datenbank erfolgreich optimiert';
break;
case 'createBackup':
await createBackup();
endpoint = '/api/admin/maintenance/create-backup';
confirmMessage = 'Möchten Sie ein Backup erstellen?';
successMessage = 'Backup erfolgreich erstellt';
break;
default:
throw new Error(`Unbekannte Aktion: ${actionType}`);
}
this.closeModal();
if (!confirm(confirmMessage)) {
this.setLoadingState(false);
return;
}
const response = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': getCsrfToken()
}
});
const result = await response.json();
if (response.ok && result.success) {
showNotification(successMessage, 'success');
this.closeModal();
} else {
showNotification(result.message || 'Fehler bei der Ausführung der Wartungsaktion', 'error');
}
} catch (error) {
console.error('Fehler bei Wartungsaktion:', error);
showNotification('Fehler bei der Ausführung der Wartungsaktion', 'error');
showNotification('Fehler bei der Ausführung der Wartungsaktion: ' + error.message, 'error');
} finally {
this.setLoadingState(false);
}
@ -734,7 +808,8 @@ class MaintenanceModal {
navigateToSettings() {
try {
window.location.href = '{{ url_for("optimization_settings") }}';
// Direkte Navigation zu den Optimierungs-Einstellungen
window.location.href = '/api/optimization/settings';
} catch (error) {
console.error('Fehler beim Navigieren zu den Einstellungen:', error);
showNotification('Fehler beim Öffnen der Einstellungen', 'error');
@ -742,9 +817,15 @@ class MaintenanceModal {
}
}
// Globale Wartungs-Modal Instanz
let maintenanceModal = null;
// Initialisierung nach DOM-Laden
document.addEventListener('DOMContentLoaded', function() {
new MaintenanceModal();
// Nur einmal initialisieren
if (!maintenanceModal) {
maintenanceModal = new MaintenanceModal();
}
});
// Notification anzeigen
@ -763,6 +844,11 @@ function showNotification(message, type = 'info') {
${type === 'success' ? '✅' : type === 'error' ? '❌' : ''}
</div>
<div class="text-sm font-medium">${message}</div>
<button onclick="this.parentElement.parentElement.remove()" class="ml-auto text-white hover:text-gray-200">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
</svg>
</button>
</div>
`;
@ -776,13 +862,15 @@ function showNotification(message, type = 'info') {
// Automatisch entfernen nach 5 Sekunden
setTimeout(() => {
notification.style.transform = 'translateX(100%)';
notification.style.opacity = '0';
setTimeout(() => {
if (notification.parentNode) {
notification.parentNode.removeChild(notification);
}
}, 300);
if (notification.parentNode) {
notification.style.transform = 'translateX(100%)';
notification.style.opacity = '0';
setTimeout(() => {
if (notification.parentNode) {
notification.parentNode.removeChild(notification);
}
}, 300);
}
}, 5000);
}
@ -791,102 +879,5 @@ function getCsrfToken() {
const token = document.querySelector('meta[name="csrf-token"]');
return token ? token.getAttribute('content') : '';
}
// Cache leeren
async function clearCache() {
if (!confirm('Möchten Sie den Cache wirklich leeren?')) return;
try {
showNotification('Cache wird geleert...', 'info');
const response = await fetch('/api/admin/cache/clear', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': getCsrfToken()
}
});
const result = await response.json();
if (response.ok && result.success) {
showNotification('Cache erfolgreich geleert', 'success');
// Modal schließen
document.getElementById('maintenance-modal').classList.add('hidden');
} else {
showNotification(result.message || 'Fehler beim Leeren des Cache', 'error');
}
} catch (error) {
showNotification('Netzwerkfehler: ' + error.message, 'error');
}
}
// Datenbank optimieren
async function optimizeDatabase() {
if (!confirm('Möchten Sie die Datenbank optimieren? Dies kann einige Minuten dauern.')) return;
try {
showNotification('Datenbank wird optimiert...', 'info');
const response = await fetch('/api/admin/database/optimize', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': getCsrfToken()
}
});
const result = await response.json();
if (response.ok && result.success) {
showNotification('Datenbank erfolgreich optimiert', 'success');
// Modal schließen
document.getElementById('maintenance-modal').classList.add('hidden');
} else {
showNotification(result.message || 'Fehler bei der Datenbankoptimierung', 'error');
}
} catch (error) {
showNotification('Netzwerkfehler: ' + error.message, 'error');
}
}
// Backup erstellen
async function createBackup() {
if (!confirm('Möchten Sie ein Backup erstellen?')) return;
try {
showNotification('Backup wird erstellt...', 'info');
const response = await fetch('/api/admin/backup/create', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': getCsrfToken()
}
});
const result = await response.json();
if (response.ok && result.success) {
showNotification('Backup erfolgreich erstellt', 'success');
// Modal schließen
document.getElementById('maintenance-modal').classList.add('hidden');
} else {
showNotification(result.message || 'Fehler beim Erstellen des Backups', 'error');
}
} catch (error) {
showNotification('Netzwerkfehler: ' + error.message, 'error');
}
}
// Escape-Taste um Modal zu schließen
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
const modal = document.getElementById('maintenance-modal');
if (!modal.classList.contains('hidden')) {
modal.classList.add('hidden');
}
}
});
</script>
{% endblock %}