From patchwork Tue Jul 13 16:58:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 4519 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) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4GPRgC27hFz3xGY for ; Tue, 13 Jul 2021 16:59:03 +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 4GPRgB05X1z1PC; Tue, 13 Jul 2021 16:59:02 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4GPRg95Dfcz2xmx; Tue, 13 Jul 2021 16:59:01 +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) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4GPRg74RMjz2xKH for ; Tue, 13 Jul 2021 16:58:59 +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 4GPRg66yqPz17t; Tue, 13 Jul 2021 16:58:58 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1626195539; 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=Ya9awHGXxuIMsTy80qmmbByvL8adM14IHy73BWEoTXU=; b=DI6+p2ed5KiwrVgSi8oH3mqbgDSMM1449tNLH94+Go5p8IO2ogZC6MgwB+y3+KlxcjAw2H JjdoVPM0fIK19BAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1626195539; 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=Ya9awHGXxuIMsTy80qmmbByvL8adM14IHy73BWEoTXU=; b=hcxNnBxrcXqN5RbLud7VZjZhSUF7UMqCH/xALk3mNkWZlj+xDQbP4mDgKip8v0UCTZKxp1 euw2Z9aj1WSWoLlZ/tOXFGQRKiKnySv2EFrEn9xREZB0ecq4UEFELRyit8aqPpWpWLLDtD fpQzSOmOWNVQcfUORMxb+g61FV6X2f4eyn8rcqyPgjXWQEAw0qTeMinFLTwquFxK1VYIET CTETZdrHKvVaCwe2HvqucRsSLnRrh9tRxuuffPgiS9jvtpAMnYSYBg/ov9ufmAUl3StMxI 7ulI/rlmclVS3qTSYIY8aO+TKxp5v1KERMSuLSKqWow7g2ePtBIhDfFCGTkk8g== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH] firewalllog.dat: Proper display protocol names. Date: Tue, 13 Jul 2021 18:58:51 +0200 Message-Id: <20210713165851.3261-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..529585863 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 <