From: Stefan Schantl Date: Thu, 1 Apr 2021 14:02:04 +0000 (+0200) Subject: ids-functions.pl: Introduce get_ruleset_date() function. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f580aa8caa691855f443c14c1e9e5a047028beef;p=people%2Fstevee%2Fipfire-2.x.git ids-functions.pl: Introduce get_ruleset_date() function. This function is used to get the creation date of the stored rules files of a given provider. Signed-off-by: Stefan Schantl --- diff --git a/config/cfgroot/ids-functions.pl b/config/cfgroot/ids-functions.pl index 245a267bf2..ee522f6f2f 100644 --- a/config/cfgroot/ids-functions.pl +++ b/config/cfgroot/ids-functions.pl @@ -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. #