From patchwork Thu Jul 15 08:16:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 4530 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4GQRzM254Dz3xGl for ; Thu, 15 Jul 2021 08:16:31 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4GQRzK4tt1z161; Thu, 15 Jul 2021 08:16:29 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4GQRzJ6dZQz2y38; Thu, 15 Jul 2021 08:16:28 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4GQRzJ1GmJz2xSn for ; Thu, 15 Jul 2021 08:16:28 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4GQRzH0pNNz161; Thu, 15 Jul 2021 08:16:27 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1626336987; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=BSZUST6dRks1+hwIeKMn4l7+wJS6eWRjiKIFisra9rA=; b=ki0AOp2YYWCWN0REp5ZdJ6hL5LqvzPdrwaXCKCc9lSpYpTso7Wk9cq4H3F6VzHnVUAoS7J y5+eKPctjrM6YvDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1626336987; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=BSZUST6dRks1+hwIeKMn4l7+wJS6eWRjiKIFisra9rA=; b=O7U+TL5FN6Cdwt6tXIxKrXC0LqKceFXVzriM7DGaBBms47PC7DjlOrE9qWI+IygqfiEFzt cC6r42Qr4koQzukBHqNueSeJsUuIOu7W2vQKImKbN+PW3q5X+xq3xcT/5+TQS42fK9Ec6x 6yGFu2/esx0AgM/0SpJqBR3+uvcUlIy/dQ3/O9mBmfVTeJ/qphCwWfrQB+vRVacuvZ8x9u erLgNOq6kzindDzmXh9XYgwSuD7kSlWneg2YerNhEk5G0dcrJz3imOWNEnKL4P4UZi9v+5 jl5+hZHuW1WTTbhH+KYJwpN60Lnb6eR5KGVD9HhT+LX4O5zYY7Hi7wE3kJT1Bg== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCHv2] firewalllog.dat: Proper display protocol names. Date: Thu, 15 Jul 2021 10:16:18 +0200 Message-Id: <20210715081618.2279-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" In some cases iptables logs the protocol number instead of the name. When accessing the logs via the WUI, this number has been displayed as used protocol, which is very hard to read and understand. This commit adds a new function to the general-functions.pl, which generates a hash to translate the protocol number into the protocol name. Fixes #11282. Signed-off-by: Stefan Schantl Reviewed-by: Michael Tremer Reviewed-by: Bernhard Bitsch --- config/cfgroot/general-functions.pl | 36 +++++++++++++++++++++++++++ html/cgi-bin/logs.cgi/firewalllog.dat | 8 ++++++ 2 files changed, 44 insertions(+) diff --git a/config/cfgroot/general-functions.pl b/config/cfgroot/general-functions.pl index 550afcf82..1da1218ab 100644 --- a/config/cfgroot/general-functions.pl +++ b/config/cfgroot/general-functions.pl @@ -1363,6 +1363,42 @@ sub formatBytes { return sprintf("%.2f %s", $bytes, $unit); } +# Function to collect and generate a hash for translating protocol numbers into +# their names. +sub generateProtoTransHash () { + # File which contains the protocol definitions. + my $protocols_file = "/etc/protocols"; + + my %protocols = (); + + # Open protocols file. + open(FILE, "$protocols_file") or die "Could not open $protocols_file. $!\n"; + + # Loop through the file. + while (my $line = ) { + # Skip comments. + next if ($line =~ /^\#/); + + # Skip blank lines. + next if ($line =~ /^\s*$/); + + # Remove any newlines. + chomp($line); + + # Split line content. + my ($protocol_lc, $number, $protocol_uc, $comment) = split(' ', $line); + + # Add proto details to the hash of protocols. + $protocols{$number} = $protocol_uc; + } + + # Close file handle. + close(FILE); + + # Return the hash. + return %protocols; +} + # Cloud Stuff sub running_in_cloud() { diff --git a/html/cgi-bin/logs.cgi/firewalllog.dat b/html/cgi-bin/logs.cgi/firewalllog.dat index e326d65c0..73596d8cd 100644 --- a/html/cgi-bin/logs.cgi/firewalllog.dat +++ b/html/cgi-bin/logs.cgi/firewalllog.dat @@ -325,6 +325,8 @@ print <