From 15cd02a49b903ff6d27f45f72e7ba1c560815181 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 12 Apr 2019 13:45:13 +0200 Subject: [PATCH] fix v1 Former-commit-id: f217f78e8085a81df68b9899513e547e148fca0d --- pandora_server/lib/PandoraFMS/Tools.pm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index a03ebb83d5..02bb9f05ea 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -120,6 +120,7 @@ our @EXPORT = qw( month_have_days translate_obj valid_regex + read_file set_file_permissions uri_encode check_server_threads @@ -330,6 +331,28 @@ my @ServerThreads; # Keep threads running. our $THRRUN :shared = 1; +########################################################################## +## Reads a file and returns entire content or undef if error. +########################################################################## +sub read_file { + my $path = shift; + + my $_FILE; + if( !open($_FILE, "<", $path) ) { + # failed to open, return undef + return undef; + } + + # Slurp configuration file content. + my $content = do { local $/; <$_FILE> }; + + # Close file + close($_FILE); + + return $content; +} + + ############################################################################### # Sets user:group owner for the given file ###############################################################################