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');