From 7afc617e626b22ed6cb44b4dc6154f7e9e51b333 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Fri, 25 May 2018 12:39:30 +0200 Subject: [PATCH] [Rebranding] Implemented server rebranding through environment vars --- pandora_server/bin/pandora_server | 8 +++--- pandora_server/lib/PandoraFMS/Config.pm | 38 +++++++++++++++++++------ pandora_server/lib/PandoraFMS/Tools.pm | 13 +++++---- pandora_server/util/pandora_db.pl | 10 +++---- 4 files changed, 47 insertions(+), 22 deletions(-) diff --git a/pandora_server/bin/pandora_server b/pandora_server/bin/pandora_server index 49d3c97cba..7e60690ae1 100755 --- a/pandora_server/bin/pandora_server +++ b/pandora_server/bin/pandora_server @@ -519,7 +519,7 @@ sub main() { # Daemonize and put in background if ($Config{'daemon'} == 1) { - print_message (\%Config, " [*] Backgrounding Pandora FMS Server process.\n", 1); + print_message (\%Config, " [*] Backgrounding " . pandora_get_initial_product_name() . " Server process.\n", 1); pandora_daemonize (\%Config); } @@ -528,8 +528,8 @@ sub main() { print_message (\%Config, " [*] Pandora FMS Enterprise module not available.", 1); logger (\%Config, " [*] Pandora FMS Enterprise module not available.", 1); } else { - print_message (\%Config, " [*] Pandora FMS Enterprise module loaded.", 1); - logger (\%Config, " [*] Pandora FMS Enterprise module loaded.", 1); + print_message (\%Config, " [*] " . pandora_get_initial_product_name() . " Enterprise module loaded.", 1); + logger (\%Config, " [*] " . pandora_get_initial_product_name() . " Enterprise module loaded.", 1); if($Config{'policy_manager'} == 1) { # Start thread to patrol policy queue @@ -687,7 +687,7 @@ $SIG{__DIE__} = 'pandora_crash'; $SIG{'ALRM'} = 'IGNORE'; # Initialize -pandora_init(\%Config, 'Pandora FMS Server'); +pandora_init(\%Config, pandora_get_initial_product_name() . ' Server'); pandora_load_config (\%Config); # Parse command line options. diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index 6941a7d9f3..179fa75c72 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -39,6 +39,8 @@ our @EXPORT = qw( pandora_start_log pandora_get_sharedconfig pandora_get_tconfig_token + pandora_get_initial_product_name + pandora_get_initial_copyright_notice ); # version: Defines actual version of Pandora Server for this module only @@ -56,7 +58,7 @@ my %pa_config; ########################################################################## sub help_screen { - print "\nSyntax: \n\n pandora_server [ options ] < fullpathname to configuration file (pandora_server.conf) > \n\n"; + print "\nSyntax: \n\n pandora_server [ options ] < fullpathname to configuration file > \n\n"; print "Following options are optional : \n"; print " -v : Verbose mode activated. Writes more information in the logfile \n"; print " -d : Debug mode activated. Writes extensive information in the logfile \n"; @@ -77,13 +79,13 @@ sub help_screen { sub pandora_init { my $pa_config = $_[0]; my $init_string = $_[1]; - print "\n$init_string $pandora_version Build $pandora_build Copyright (c) 2004-2015 ArticaST\n"; + print "\n$init_string $pandora_version Build $pandora_build Copyright (c) 2004-2018 " . pandora_get_initial_copyright_notice() . "\n"; print "This program is OpenSource, licensed under the terms of GPL License version 2.\n"; - print "You can download latest versions and documentation at http://www.pandorafms.org \n\n"; + print "You can download latest versions and documentation at official web page.\n\n"; # Load config file from command line if ($#ARGV == -1 ){ - print "I need at least one parameter: Complete path to Pandora FMS Server configuration file \n"; + print "I need at least one parameter: Complete path to " . pandora_get_initial_product_name() . " Server configuration file \n"; help_screen; exit; } @@ -124,7 +126,7 @@ sub pandora_init { } } if ($pa_config->{"pandora_path"} eq ""){ - print " [ERROR] I need at least one parameter: Complete path to Pandora FMS configuration file. \n"; + print " [ERROR] I need at least one parameter: Complete path to " . pandora_get_initial_product_name() . " configuration file. \n"; print " For example: ./pandora_server /etc/pandora/pandora_server.conf \n\n"; exit; } @@ -496,7 +498,7 @@ sub pandora_load_config { # Check for file if ( ! -f $archivo_cfg ) { printf "\n [ERROR] Cannot open configuration file at $archivo_cfg. \n"; - printf " Please specify a valid Pandora FMS configuration file in command line. \n"; + printf " Please specify a valid " . pandora_get_initial_product_name() ." configuration file in command line. \n"; print " Standard configuration file is at /etc/pandora/pandora_server.conf \n"; exit 1; } @@ -1165,10 +1167,10 @@ sub pandora_start_log ($){ my $pa_config = shift; # Dump all errors to errorlog - open (STDERR, ">> " . $pa_config->{'errorlog_file'}) or die " [ERROR] Pandora FMS can't write to Errorlog. Aborting : \n $! \n"; + open (STDERR, ">> " . $pa_config->{'errorlog_file'}) or die " [ERROR] " . pandora_get_initial_product_name() . " can't write to Errorlog. Aborting : \n $! \n"; my $mode = 0664; chmod $mode, $pa_config->{'errorlog_file'}; - print STDERR strftime ("%Y-%m-%d %H:%M:%S", localtime()) . ' - ' . $pa_config->{'servername'} . " Starting Pandora FMS Server. Error logging activated.\n"; + print STDERR strftime ("%Y-%m-%d %H:%M:%S", localtime()) . ' - ' . $pa_config->{'servername'} . " Starting " . pandora_get_initial_product_name() . " Server. Error logging activated.\n"; } ########################################################################## @@ -1185,6 +1187,26 @@ sub pandora_get_tconfig_token ($$$) { return $default_value; } +########################################################################## +# Get the product name in previous tasks to read from database. +########################################################################## +sub pandora_get_initial_product_name { + # PandoraFMS product name + my $product_name = $ENV{'PANDORA_RB_PRODUCT_NAME'}; + return 'Pandora FMS' unless (defined ($product_name) && $product_name ne ''); + return $product_name; +} + +########################################################################## +# Get the copyright notice. +########################################################################## +sub pandora_get_initial_copyright_notice { + # PandoraFMS product name + my $name = $ENV{'PANDORA_RB_COPYRIGHT_NOTICE'}; + return 'Artica ST' unless (defined ($name) && $name ne ''); + return $name; +} + # End of function declaration # End of defined Code diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index a81aa6bfb5..c257e2de57 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -399,7 +399,7 @@ sub pandora_daemonize { # check if pandora_server is running if (kill (0, $pid)) { - die "[FATAL] pandora_server already running, pid: $pid."; + die "[FATAL] " . pandora_get_initial_product_name() . " Server already running, pid: $pid."; } logger ($pa_config, '[W] Stale PID file, overwriting.', 1); } @@ -673,12 +673,15 @@ sub enterprise_load ($) { else { eval 'require PandoraFMS::Enterprise;'; } - - - + # Ops if ($@) { - + # Remove the rebranding if open version + if ($^O ne 'MSWin32') { + `unset PANDORA_RB_PRODUCT_NAME`; + `unset PANDORA_RB_COPYRIGHT_NOTICE`; + } + # Enterprise.pm not found. return 0 if ($@ =~ m/PandoraFMS\/Enterprise\.pm.*\@INC/); diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 1f79725fb0..6dcbdda778 100644 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -555,9 +555,9 @@ sub pandora_compactdb ($$) { sub pandora_init ($) { my $conf = shift; - log_message ('', "\nDB Tool $version Copyright (c) 2004-2018 Artica ST\n"); + log_message ('', "\nDB Tool $version Copyright (c) 2004-2018 " . pandora_get_initial_copyright_notice() . "\n"); log_message ('', "This program is Free Software, licensed under the terms of GPL License v2\n"); - log_message ('', "You can download latest versions and documentation at http://www.pandorafms.org\n\n"); + log_message ('', "You can download latest versions and documentation at official web\n\n"); # Load config file from command line help_screen () if ($#ARGV < 0); @@ -897,7 +897,7 @@ sub pandora_checkdb_consistency { # Print a help screen and exit. ############################################################################## sub help_screen{ - log_message ('', "Usage: $0 [options]\n\n"); + log_message ('', "Usage: $0 [options]\n\n"); log_message ('', "\t\t-p Only purge and consistency check, skip compact.\n"); log_message ('', "\t\t-f Force execution event if another instance of $0 is running.\n\n"); exit -1; @@ -1031,10 +1031,10 @@ pandora_load_config (\%conf); # Load enterprise module if (enterprise_load (\%conf) == 0) { - log_message ('', " [*] Pandora FMS Enterprise module not available.\n\n"); + log_message ('', " [*] " . pandora_get_initial_product_name() . " Enterprise module not available.\n\n"); } else { - log_message ('', " [*] Pandora FMS Enterprise module loaded.\n\n"); + log_message ('', " [*] " . pandora_get_initial_product_name() . " Enterprise module loaded.\n\n"); } # Connect to the DB