From 65612dad8abd77772b4c25ac17b815c291d8e07c Mon Sep 17 00:00:00 2001 From: Michael Reber Date: Mon, 27 Jan 2025 11:35:21 +0100 Subject: [PATCH] Add basic IP-search --- pkg/web/templates/index.html | 45 ++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/pkg/web/templates/index.html b/pkg/web/templates/index.html index f0562f0..3753765 100644 --- a/pkg/web/templates/index.html +++ b/pkg/web/templates/index.html @@ -329,13 +329,21 @@ function fetchSummary() { function renderDashboard(data) { var html = ""; + // Add a search bar + html += ` +
+ + +
+ `; + // Jails table if (!data.jails || data.jails.length === 0) { html += '

No jails found.

'; } else { html += '' + '

Overview

' - + '' + + '
' + ' ' + ' ' + ' ' @@ -349,7 +357,7 @@ function renderDashboard(data) { data.jails.forEach(function(jail) { var bannedHTML = renderBannedIPs(jail.jailName, jail.bannedIPs); html += '' - + '' + + '' + '
Jail Name
' + ' ' + jail.jailName @@ -417,6 +425,39 @@ function renderBannedIPs(jailName, ips) { return content; } +// Filter IPs on dashboard table +function filterIPs() { + const query = document.getElementById("ipSearch").value.toLowerCase(); // Get the search query + const rows = document.querySelectorAll("#jailsTable .jail-row"); // Get all jail rows + + rows.forEach((row) => { + const ipSpans = row.querySelectorAll("ul li span"); // Find all IP span elements in this row + let matchFound = false; // Reset match flag for the row + + ipSpans.forEach((span) => { + const originalText = span.textContent; // The full original text + const ipText = originalText.toLowerCase(); + + if (query && ipText.includes(query)) { + matchFound = true; // Match found in this row + + // Highlight the matching part + const highlightedText = originalText.replace( + new RegExp(query, "gi"), // Case-insensitive match + (match) => `${match}` // Wrap match in + ); + span.innerHTML = highlightedText; // Update span's HTML with highlighting + } else { + // Remove highlighting if no match or search is cleared + span.innerHTML = originalText; + } + }); + + // Show the row if a match is found or the query is empty + row.style.display = matchFound || !query ? "" : "none"; + }); +} + //******************************************************************* //* Functions to manage IP-bans : * //*******************************************************************