From 0a1bba1a1d3ec8995f482b291d25c84374d11085 Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Thu, 20 Dec 2018 11:55:13 +0100 Subject: [PATCH] ids.cgi: Access ruleset by its own name This improves accessing the single rules of a rule category. Signed-off-by: Stefan Schantl --- html/cgi-bin/ids.cgi | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/html/cgi-bin/ids.cgi b/html/cgi-bin/ids.cgi index fb0aeebd7a..ae7f8b4273 100644 --- a/html/cgi-bin/ids.cgi +++ b/html/cgi-bin/ids.cgi @@ -951,10 +951,6 @@ if (%idsrules) { # Output display table for rule files print "\n"; - # Local variable required for java script to show/hide - # rules of a rulefile. - my $rulesetcount = 1; - # Loop over each rule file foreach my $rulefile (sort keys(%idsrules)) { my $rulechecked = ''; @@ -964,6 +960,9 @@ if (%idsrules) { $rulechecked = 'CHECKED'; } + # Convert rulefile name into category name. + my $categoryname = &_rulefile_to_category($rulefile); + # Table and rows for the rule files. print"\n"; print"\n"; print"\n"; print"\n"; print"\n"; # Rows which will be hidden per default and will contain the single rules. - print"\n"; + print"\n"; print"
\n"; @@ -971,12 +970,12 @@ if (%idsrules) { print"$rulefile\n"; - print"SHOW\n"; + print"SHOW\n"; print"
"; - - # Finished whith the rule file, increase count. - $rulesetcount++; } # Close display table @@ -1361,3 +1357,27 @@ sub read_enabled_disabled_sids_file($) { # Return the hash. return %temphash; } + +# +## Private function to convert a given rulefile to a category name. +## ( No file extension anymore and if the name contained a dot, it +## would be replaced by a underline sign.) +# +sub _rulefile_to_category($) { + my ($filename) = @_; + + # Splitt the filename into single chunks and store them in a + # temorary array. + my @parts = split(/\./, $filename); + + # Return / Remove last element of the temporary array. + # This removes the file extension. + pop @parts; + + # Join together the single elements of the temporary array. + # If these are more than one, use a "underline" for joining. + my $category = join '_', @parts; + + # Return the converted filename. + return $category; +} -- 2.39.2