]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
ids-functions.pl: Introduce get_ruleset_date() function.
authorStefan Schantl <stefan.schantl@ipfire.org>
Thu, 1 Apr 2021 14:02:04 +0000 (16:02 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sun, 19 Dec 2021 12:23:42 +0000 (13:23 +0100)
This function is used to get the creation date of the stored rules files
of a given provider.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
config/cfgroot/ids-functions.pl

index 245a267bf264ab0ef09d8b11c0852509ee01130d..ee522f6f2fd90c7e007534ce3baf0ee695abd08c 100644 (file)
@@ -1354,6 +1354,35 @@ END
        close(FILE);
 }
 
+#
+## Function to get the ruleset date for a given provider.
+##
+## The function simply return the creation date in a human read-able format
+## of the stored providers rulesfile.
+#
+sub get_ruleset_date($) {
+       my ($provider) = @_;
+
+       # Load neccessary perl modules for file stat and to format the timestamp.
+       use File::stat;
+       use POSIX qw( strftime );
+
+       # Get the stored rulesfile for this provider.
+       my $stored_rulesfile = &_get_dl_rulesfile($provider);
+
+       # Call stat on the rulestarball.
+       my $stat = stat("$stored_rulesfile");
+
+       # Get timestamp the file creation.
+       my $mtime = $stat->mtime;
+
+       # Convert into human read-able format.
+       my $date = strftime('%Y-%m-%d %H:%M:%S', localtime($mtime));
+
+       # Return the date.
+       return $date;
+}
+
 #
 ## Function to gather the version of suricata.
 #