From 04a0d07c97087c9d66e09155058beacee031d627 Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Wed, 26 Dec 2018 16:05:46 +0100 Subject: [PATCH] ids-functions.pl: Add function to get the version of suricata The get_suricata_version() function is used to get the version of the on the system installed version of suricata. You can specify the how detailed the returned result should be "major" will return only the major version, were "minor" will provide the major and minor version (1.2 for example). All other calls will be answered with the full version string (1.2.3). Signed-off-by: Stefan Schantl --- config/cfgroot/ids-functions.pl | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/config/cfgroot/ids-functions.pl b/config/cfgroot/ids-functions.pl index e444272996..7c6b884c51 100644 --- a/config/cfgroot/ids-functions.pl +++ b/config/cfgroot/ids-functions.pl @@ -709,4 +709,41 @@ sub write_modify_sids_file($) { close(FILE); } +# +## Function to gather the version of suricata. +# +sub get_suricata_version($) { + my ($format) = @_; + + # Execute piped suricata command and return the version information. + open(SURICATA, "suricata -V |") or die "Couldn't execute program: $!"; + + # Grab and store the output of the piped program. + my $version_string = ; + + # Close pipe. + close(SURICATA); + + # Remove newlines. + chomp($version_string); + + # Grab the version from the version string. + $version_string =~ /([0-9]+([.][0-9]+)+)/; + + # Splitt the version into single chunks. + my ($major_ver, $minor_ver, $patchlevel) = split(/\./, $1); + + # Check and return the requested version sheme. + if ($format eq "major") { + # Return the full version. + return "$major_ver"; + } elsif ($format eq "minor") { + # Return the major and minor part. + return "$major_ver.$minor_ver"; + } else { + # Return the full version string. + return "$major_ver.$minor_ver.$patchlevel"; + } +} + 1; -- 2.39.2