In test filters also priorize .local filters over .conf filters and return always also the explicit used filter path in results

This commit is contained in:
2025-12-06 13:11:15 +01:00
parent 5a3c59ae0d
commit 8268e37651
7 changed files with 101 additions and 31 deletions

View File

@@ -1325,12 +1325,15 @@ func TestFilterHandler(c *gin.Context) {
return
}
output, err := conn.TestFilter(c.Request.Context(), req.FilterName, req.LogLines)
output, filterPath, err := conn.TestFilter(c.Request.Context(), req.FilterName, req.LogLines)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to test filter: " + err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"output": output})
c.JSON(http.StatusOK, gin.H{
"output": output,
"filterPath": filterPath,
})
}
// ApplyFail2banSettings updates /etc/fail2ban/jail.local [DEFAULT] with our JSON

View File

@@ -78,7 +78,7 @@ function testSelectedFilter() {
showToast('Error testing filter: ' + data.error, 'error');
return;
}
renderTestResults(data.output || '');
renderTestResults(data.output || '', data.filterPath || '');
})
.catch(err => {
showToast('Error testing filter: ' + err, 'error');
@@ -86,9 +86,18 @@ function testSelectedFilter() {
.finally(() => showLoading(false));
}
function renderTestResults(output) {
function renderTestResults(output, filterPath) {
const testResultsEl = document.getElementById('testResults');
let html = '<h5 class="text-lg font-medium text-white mb-4" data-i18n="filter_debug.test_results_title">Test Results</h5>';
// Show which filter file was used
if (filterPath) {
html += '<div class="mb-3 p-2 bg-gray-800 rounded text-sm">';
html += '<span class="text-gray-400">Used Filter (exact file):</span> ';
html += '<span class="text-yellow-300 font-mono">' + escapeHtml(filterPath) + '</span>';
html += '</div>';
}
if (!output || output.trim() === '') {
html += '<p class="text-gray-400" data-i18n="filter_debug.no_matches">No output received.</p>';
} else {