From ca1f4a07abec374b319c29e2f08fce621483bdd0 Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Thu, 15 Jul 2021 10:16:18 +0200 Subject: [PATCH] firewalllog.dat: Proper display protocol names. 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 Signed-off-by: Arne Fitzenreiter --- 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 c7df46489..de608e38b 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 <