From 7b01de01f51b783ba73fae6e162a5da231013659 Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Thu, 1 Apr 2021 16:02:04 +0200 Subject: [PATCH] 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 --- config/cfgroot/ids-functions.pl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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. # -- 2.39.5