From f81af8b437a9edf535b480ce96601ee9264b391c Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Tue, 15 Nov 2016 11:28:52 +0100 Subject: [PATCH] Added support for loading .enc files for XML::Parser. (cherry picked from commit 11e1f5eb1f41f6162d3464abda74c15b2cb733fa) --- pandora_server/lib/PandoraFMS/Config.pm | 6 ++++++ pandora_server/lib/PandoraFMS/DataServer.pm | 24 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index 295b526e24..cecb66c6eb 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -426,6 +426,9 @@ sub pandora_load_config { $pa_config->{"warmup_unknown_on"} = 1; # 6.1 #$pa_config->{'include_agents'} = 0; #6.1 + # + # External .enc files for XML::Parser. + $pa_config->{"enc_dir"} = ""; # > 6.0SP4 # Check for UID0 if ($pa_config->{"quiet"} != 0){ @@ -956,6 +959,9 @@ sub pandora_load_config { #elsif ($parametro =~ m/^include_agents\s+([0-1])/i) { # $pa_config->{'include_agents'}= clean_blank($1); #} + elsif ($parametro =~ m/^enc_dir\s+(.*)/i) { + $pa_config->{'enc_dir'} = clean_blank($1); + } } # end of loop for parameter # # Set to RDBMS' standard port diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index a2eb9ca19e..75dd17a46c 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -25,6 +25,7 @@ use threads::shared; use Thread::Semaphore; use Time::Local; +use XML::Parser::Expat; use XML::Simple; use POSIX qw(setsid strftime); @@ -71,6 +72,29 @@ sub new ($$;$) { # Call the constructor of the parent class my $self = $class->SUPER::new($config, DATASERVER, \&PandoraFMS::DataServer::data_producer, \&PandoraFMS::DataServer::data_consumer, $dbh); + # Load external .enc files for XML::Parser. + if ($config->{'enc_dir'} ne '') { + if (opendir(my $dh, $config->{'enc_dir'})) { + while (my $enc_file = readdir($dh)) { + + # Ignore unknown files. + next unless ($enc_file =~ m/.enc$/); + + # Load the .enc file. + eval { + local $SIG{__DIE__} = {}; + XML::Parser::Expat::load_encoding($config->{'enc_dir'} . '/' . $enc_file); + }; + if ($@) { + print_message ($config, " [WARNING] Error loading encoding file: $enc_file", 1); + } + } + closedir($dh); + } else { + print_message($config, " [WARNING] Error opening directory " . $config->{'enc_dir'} . ": $!", 1); + } + } + bless $self, $class; return $self; }