From ab1668213d3119e83adc3c7bd1304437e8d38595 Mon Sep 17 00:00:00 2001 From: "Joseph.Rawlings" Date: Thu, 4 Dec 2025 22:35:23 -0500 Subject: [PATCH] feat: improve firewall log matching logic with relaxed port checks for better accuracy --- .../Servers/Proxmox/Livewire/Firewall.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/extensions/Servers/Proxmox/Livewire/Firewall.php b/extensions/Servers/Proxmox/Livewire/Firewall.php index 2fab9c37b..666bc6182 100644 --- a/extensions/Servers/Proxmox/Livewire/Firewall.php +++ b/extensions/Servers/Proxmox/Livewire/Firewall.php @@ -1702,14 +1702,29 @@ class Firewall extends Component $protocolMatch = (strtoupper(trim($protocol)) === $stateProtocol); } - // Check port match (more lenient - check if either port matches) + // Check port match - focus on destination port which is the service port + // Source port is usually ephemeral and not relevant for matching $portMatch = true; if (!empty($destPort) && $destPort !== '-') { $destPortNum = (int)$destPort; + // Match if either state's source or destination port equals the log's destination port + // This handles bidirectional connections $portMatch = ($stateDestPort === $destPortNum || $stateSourcePort === $destPortNum); } - if (($sourceMatch || $reverseMatch) && $protocolMatch && $portMatch) { + // Also consider matching without port if IPs and protocol match + // This is useful for firewall logs that don't include source port + $relaxedMatch = false; + if (!$sourceMatch && !$reverseMatch && empty($sourcePort)) { + // If no source port in log, be more lenient with matching + if (($normalizedStateSourceIP === $normalizedSourceIP || $normalizedStateDestIP === $normalizedSourceIP) && + ($normalizedStateSourceIP === $normalizedDestIP || $normalizedStateDestIP === $normalizedDestIP) && + $protocolMatch && $portMatch) { + $relaxedMatch = true; + } + } + + if (($sourceMatch || $reverseMatch || $relaxedMatch) && $protocolMatch && $portMatch) { $bytes = (int)($state['bytes_total'] ?? $state['bytes'] ?? 0); $packets = (int)($state['packets_total'] ?? $state['packets'] ?? 0); $stateName = strtoupper($state['state'] ?? 'UNKNOWN');