From b261a2e92e4ddc9fdeefe79772bbbf708c8c1633 Mon Sep 17 00:00:00 2001 From: Michael Reber Date: Mon, 17 Nov 2025 10:29:48 +0100 Subject: [PATCH] Add basic whois and logs modal to view stored events from local db --- internal/locales/de.json | 6 ++ internal/locales/de_ch.json | 6 ++ internal/locales/en.json | 6 ++ internal/locales/es.json | 10 ++- internal/locales/fr.json | 10 ++- internal/locales/it.json | 10 ++- pkg/web/templates/index.html | 149 ++++++++++++++++++++++++++++++++++- 7 files changed, 190 insertions(+), 7 deletions(-) diff --git a/internal/locales/de.json b/internal/locales/de.json index b74f74f..7d9c094 100644 --- a/internal/locales/de.json +++ b/internal/locales/de.json @@ -47,6 +47,12 @@ "logs.table.ip": "IP", "logs.table.time": "Zeit", "logs.table.country": "Land", + "logs.table.actions": "Aktionen", + "logs.actions.whois": "Whois", + "logs.actions.logs": "Logs", + "logs.modal.whois_title": "Whois-Informationen", + "logs.modal.logs_title": "Logs", + "logs.modal.jail": "Jail", "filter_debug.title": "Filter-Debug", "filter_debug.select_filter": "Wählen Sie einen Filter", "filter_debug.log_lines": "Logzeilen", diff --git a/internal/locales/de_ch.json b/internal/locales/de_ch.json index fb4df41..945d511 100644 --- a/internal/locales/de_ch.json +++ b/internal/locales/de_ch.json @@ -47,6 +47,12 @@ "logs.table.ip": "IP", "logs.table.time": "Zyt", "logs.table.country": "Land", + "logs.table.actions": "Aktione", + "logs.actions.whois": "Whois", + "logs.actions.logs": "Logs", + "logs.modal.whois_title": "Whois-Informatione", + "logs.modal.logs_title": "Logs", + "logs.modal.jail": "Jail", "filter_debug.title": "Filter Debug", "filter_debug.select_filter": "Wähl en Filter us", "filter_debug.log_lines": "Log-Zile", diff --git a/internal/locales/en.json b/internal/locales/en.json index b51712b..a12f4c9 100644 --- a/internal/locales/en.json +++ b/internal/locales/en.json @@ -47,6 +47,12 @@ "logs.table.ip": "IP", "logs.table.time": "Time", "logs.table.country": "Country", + "logs.table.actions": "Actions", + "logs.actions.whois": "Whois", + "logs.actions.logs": "Logs", + "logs.modal.whois_title": "Whois Information", + "logs.modal.logs_title": "Logs", + "logs.modal.jail": "Jail", "filter_debug.title": "Filter Debug", "filter_debug.select_filter": "Select a Filter", "filter_debug.log_lines": "Log Lines", diff --git a/internal/locales/es.json b/internal/locales/es.json index 5cf2397..e5a620a 100644 --- a/internal/locales/es.json +++ b/internal/locales/es.json @@ -45,8 +45,14 @@ "logs.table.count": "Cantidad", "logs.table.jail": "Jail", "logs.table.ip": "IP", - "logs.table.time": "Hora", - "logs.table.country": "País", + "logs.table.time": "Hora", + "logs.table.country": "País", + "logs.table.actions": "Acciones", + "logs.actions.whois": "Whois", + "logs.actions.logs": "Registros", + "logs.modal.whois_title": "Información Whois", + "logs.modal.logs_title": "Registros", + "logs.modal.jail": "Jail", "filter_debug.title": "Depuración de filtros", "filter_debug.select_filter": "Selecciona un filtro", "filter_debug.log_lines": "Líneas de log", diff --git a/internal/locales/fr.json b/internal/locales/fr.json index 77a599c..de51d7d 100644 --- a/internal/locales/fr.json +++ b/internal/locales/fr.json @@ -45,8 +45,14 @@ "logs.table.count": "Nombre", "logs.table.jail": "Jail", "logs.table.ip": "IP", - "logs.table.time": "Heure", - "logs.table.country": "Pays", + "logs.table.time": "Heure", + "logs.table.country": "Pays", + "logs.table.actions": "Actions", + "logs.actions.whois": "Whois", + "logs.actions.logs": "Journaux", + "logs.modal.whois_title": "Informations Whois", + "logs.modal.logs_title": "Journaux", + "logs.modal.jail": "Jail", "filter_debug.title": "Débogage des filtres", "filter_debug.select_filter": "Sélectionnez un filtre", "filter_debug.log_lines": "Lignes de log", diff --git a/internal/locales/it.json b/internal/locales/it.json index b3bf6a0..f307e7b 100644 --- a/internal/locales/it.json +++ b/internal/locales/it.json @@ -45,8 +45,14 @@ "logs.table.count": "Conteggio", "logs.table.jail": "Jail", "logs.table.ip": "IP", - "logs.table.time": "Ora", - "logs.table.country": "Paese", + "logs.table.time": "Ora", + "logs.table.country": "Paese", + "logs.table.actions": "Azioni", + "logs.actions.whois": "Whois", + "logs.actions.logs": "Log", + "logs.modal.whois_title": "Informazioni Whois", + "logs.modal.logs_title": "Log", + "logs.modal.jail": "Jail", "filter_debug.title": "Debug Filtro", "filter_debug.select_filter": "Seleziona un filtro", "filter_debug.log_lines": "Righe di log", diff --git a/pkg/web/templates/index.html b/pkg/web/templates/index.html index fd56a20..e74f003 100644 --- a/pkg/web/templates/index.html +++ b/pkg/web/templates/index.html @@ -823,6 +823,68 @@ + + + + + + + @@ -1470,10 +1532,13 @@ + ' Jail' + ' IP' + ' Country' + + ' Actions' + ' ' + ' ' + ' '; - latestBanEvents.forEach(function(event) { + latestBanEvents.forEach(function(event, index) { + var hasWhois = event.whois && event.whois.trim().length > 0; + var hasLogs = event.logs && event.logs.trim().length > 0; html += '' + ' ' + ' ' + escapeHtml(formatDateTime(event.occurredAt || event.createdAt)) + '' @@ -1481,6 +1546,12 @@ + ' ' + escapeHtml(event.jail || '') + '' + ' ' + escapeHtml(event.ip || '') + '' + ' ' + escapeHtml(event.country || '—') + '' + + ' ' + + '
' + + (hasWhois ? ' ' : ' ') + + (hasLogs ? ' ' : ' ') + + '
' + + ' ' + ' '; }); html += ' '; @@ -2052,6 +2123,82 @@ }); } + // Function: openWhoisModal + // Opens the whois modal with data from the event at the given index + function openWhoisModal(eventIndex) { + if (!latestBanEvents || !latestBanEvents[eventIndex]) { + showToast("Event not found", 'error'); + return; + } + var event = latestBanEvents[eventIndex]; + if (!event.whois || !event.whois.trim()) { + showToast("No whois data available for this event", 'info'); + return; + } + + document.getElementById('whoisModalIP').textContent = event.ip || 'N/A'; + var contentEl = document.getElementById('whoisModalContent'); + contentEl.textContent = event.whois; + openModal('whoisModal'); + } + + // Function: openLogsModal + // Opens the logs modal with data from the event at the given index + // Highlights the line that caused the block + function openLogsModal(eventIndex) { + if (!latestBanEvents || !latestBanEvents[eventIndex]) { + showToast("Event not found", 'error'); + return; + } + var event = latestBanEvents[eventIndex]; + if (!event.logs || !event.logs.trim()) { + showToast("No logs data available for this event", 'info'); + return; + } + + document.getElementById('logsModalIP').textContent = event.ip || 'N/A'; + document.getElementById('logsModalJail').textContent = event.jail || 'N/A'; + + var logs = event.logs; + var ip = event.ip || ''; + var logLines = logs.split('\n'); + + // Find the line that likely caused the block + // Look for lines containing the IP address, prefer the last one + var highlightedLineIndex = -1; + for (var i = logLines.length - 1; i >= 0; i--) { + if (ip && logLines[i].indexOf(ip) !== -1) { + highlightedLineIndex = i; + break; + } + } + + // If no line with IP found, highlight the last line + if (highlightedLineIndex === -1 && logLines.length > 0) { + highlightedLineIndex = logLines.length - 1; + } + + // Build HTML with highlighted line + var contentEl = document.getElementById('logsModalContent'); + if (highlightedLineIndex >= 0) { + var html = ''; + for (var i = 0; i < logLines.length; i++) { + var line = escapeHtml(logLines[i] || ''); + if (i === highlightedLineIndex) { + // Highlight the entire line - use inline span that covers the full width + html += '' + line + ''; + } else { + html += line + '\n'; + } + } + contentEl.innerHTML = html; + } else { + contentEl.textContent = logs; + } + + openModal('logsModal'); + } + // Function: openManageJailsModal // Fetches the full-list of all jails (from /jails/manage) and builds a list with toggle switches. function openManageJailsModal() {