Include basic detection mech of bad, loglines that could cause a ban

This commit is contained in:
2025-11-17 11:25:50 +01:00
parent b261a2e92e
commit ff21a3a5ed

View File

@@ -2163,42 +2163,82 @@
var ip = event.ip || ''; var ip = event.ip || '';
var logLines = logs.split('\n'); var logLines = logs.split('\n');
// Find the line that likely caused the block // Determine which lines are suspicious (bad requests)
// Look for lines containing the IP address, prefer the last one var suspiciousIndices = [];
var highlightedLineIndex = -1; for (var i = 0; i < logLines.length; i++) {
for (var i = logLines.length - 1; i >= 0; i--) { if (isSuspiciousLogLine(logLines[i], ip)) {
if (ip && logLines[i].indexOf(ip) !== -1) { suspiciousIndices.push(i);
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'); var contentEl = document.getElementById('logsModalContent');
if (highlightedLineIndex >= 0) { if (suspiciousIndices.length) {
var highlightMap = {};
suspiciousIndices.forEach(function(idx) { highlightMap[idx] = true; });
var html = ''; var html = '';
for (var i = 0; i < logLines.length; i++) { for (var j = 0; j < logLines.length; j++) {
var line = escapeHtml(logLines[i] || ''); var safeLine = escapeHtml(logLines[j] || '');
if (i === highlightedLineIndex) { if (highlightMap[j]) {
// Highlight the entire line - use inline span that covers the full width html += '<span style="display: block; background-color: #d97706; color: #fef3c7; padding: 0.25rem 0.5rem; margin: 0.125rem 0; border-radius: 0.25rem;">' + safeLine + '</span>';
html += '<span style="display: block; background-color: #d97706; color: #fef3c7; padding: 0.25rem 0.5rem; margin: 0.125rem 0; border-radius: 0.25rem;">' + line + '</span>';
} else { } else {
html += line + '\n'; html += safeLine + '\n';
} }
} }
contentEl.innerHTML = html; contentEl.innerHTML = html;
} else { } else {
// No suspicious lines detected; show raw logs without highlighting
contentEl.textContent = logs; contentEl.textContent = logs;
} }
openModal('logsModal'); openModal('logsModal');
} }
function isSuspiciousLogLine(line, ip) {
if (!line) {
return false;
}
var containsIP = ip && line.indexOf(ip) !== -1;
var lowered = line.toLowerCase();
// Detect HTTP status codes (>= 300 considered problematic)
var statusMatch = line.match(/"[^"]*"\s+(\d{3})\b/);
if (!statusMatch) {
statusMatch = line.match(/\s(\d{3})\s+(?:\d+|-)/);
}
var statusCode = statusMatch ? parseInt(statusMatch[1], 10) : NaN;
var hasBadStatus = !isNaN(statusCode) && statusCode >= 300;
// Detect common attack indicators in URLs/payloads
var indicators = [
'../',
'%2e%2e',
'%252e%252e',
'%24%7b',
'${',
'/etc/passwd',
'select%20',
'union%20',
'cmd=',
'wget',
'curl ',
'nslookup',
'/xmlrpc.php',
'/wp-admin',
'/cgi-bin',
'content-length: 0'
];
var hasIndicator = indicators.some(function(ind) {
return lowered.indexOf(ind) !== -1;
});
if (containsIP) {
return hasBadStatus || hasIndicator;
}
return (hasBadStatus || hasIndicator) && !ip;
}
// Function: openManageJailsModal // Function: openManageJailsModal
// Fetches the full-list of all jails (from /jails/manage) and builds a list with toggle switches. // Fetches the full-list of all jails (from /jails/manage) and builds a list with toggle switches.
function openManageJailsModal() { function openManageJailsModal() {