]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
ids-functions.pl: Add function to get the version of suricata
authorStefan Schantl <stefan.schantl@ipfire.org>
Wed, 26 Dec 2018 15:05:46 +0000 (16:05 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Wed, 26 Dec 2018 15:05:46 +0000 (16:05 +0100)
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 <stefan.schantl@ipfire.org>
config/cfgroot/ids-functions.pl

index e4442729966ebe74713bcef606c17c8dbb62b101..7c6b884c51f38c68248528f181f34dac33907184 100644 (file)
@@ -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 = <SURICATA>;
+
+       # 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;