diff --git a/etc/apache2-nagvis.conf-sample b/etc/apache2-nagvis.conf-sample index be8e09f69..2803f707c 100644 --- a/etc/apache2-nagvis.conf-sample +++ b/etc/apache2-nagvis.conf-sample @@ -5,6 +5,10 @@ Alias @NAGVIS_WEB@ "@NAGVIS_PATH@" + + # If want to customize config location + #SetEnv NAGVIS_CONFIG "@NAGVIS_PATH@/../etc/nagvis.ini.php" + Options FollowSymLinks AllowOverride None diff --git a/etc/nagvis.ini.php-sample b/etc/nagvis.ini.php-sample index fa878384b..f76af02b7 100644 --- a/etc/nagvis.ini.php-sample +++ b/etc/nagvis.ini.php-sample @@ -221,6 +221,8 @@ ;htmlbase="/nagvis" ; absolute html NagVis cgi path ;htmlcgi="/nagios/cgi-bin" +; absolute etc NagVis path +;data="/usr/local/nagvis/etc" ; Default values which get inherited to the maps and its objects [defaults] diff --git a/share/server/core/classes/GlobalMainCfg.php b/share/server/core/classes/GlobalMainCfg.php index 1e3812085..cf2a1af4a 100644 --- a/share/server/core/classes/GlobalMainCfg.php +++ b/share/server/core/classes/GlobalMainCfg.php @@ -772,6 +772,10 @@ public function __construct() { 'editable' => 1, 'default' => '', 'match' => MATCH_STRING_PATH), + 'data' => Array('must' => 0, + 'editable' => 1, + 'default' => '', + 'match' => MATCH_STRING_PATH), 'local_base' => Array('must' => 0, 'editable' => 1, 'default' => '', @@ -1494,7 +1498,14 @@ public function __construct() { // Try to get the base path via $_SERVER['SCRIPT_FILENAME'] $this->validConfig['paths']['base']['default'] = $this->getBasePath(); - $this->setPathsByBase($this->getValue('paths','base'), $this->getValue('paths','htmlbase')); + $base = $this->getValue('paths', 'base'); + $htmlBase = $this->getValue('paths', 'htmlbase'); + $data = $this->getValue('paths', 'data'); + if (empty($data)) { + $data = $base; + } + + $this->setPathsByBase($base, $htmlBase, $data); // Define the main configuration files $this->setConfigFiles($this->getConfigFiles()); @@ -1579,11 +1590,23 @@ public function init($onlyUserConfig = false, $cacheSuffix = '') { $this->useCache = $this->CACHE->isCached(false); // want to reduce the paths in the NagVis config, but don't want to hardcode the paths relative from the bases - $this->setPathsByBase($this->getValue('paths','base'),$this->getValue('paths','htmlbase')); + $base = $this->getValue('paths', 'base'); + $htmlBase = $this->getValue('paths', 'htmlbase'); + $data = $this->getValue('paths', 'data'); + if (empty($data)) { + $data = $base; + } + $this->setPathsByBase($base, $htmlBase, $data); } catch (Exception $e) { // Try our best to set the correct paths - even in case of exceptions - $this->setPathsByBase($this->getValue('paths','base'),$this->getValue('paths','htmlbase')); + $base = $this->getValue('paths', 'base'); + $htmlBase = $this->getValue('paths', 'htmlbase'); + $data = $this->getValue('paths', 'data'); + if (empty($data)) { + $data = $base; + } + $this->setPathsByBase($base, $htmlBase, $data); throw $e; } @@ -1638,12 +1661,12 @@ private function getBackendValidConf() { * @param Boolean $printErr * @author Lars Michelsen */ - private function setPathsByBase($base, $htmlBase) { - $this->validConfig['paths']['cfg']['default'] = $base.'etc/'; - $this->validConfig['paths']['mapcfg']['default'] = $base.'etc/maps/'; - $this->validConfig['paths']['geomap']['default'] = $base.'etc/geomap'; - $this->validConfig['paths']['profiles']['default'] = $base.'etc/profiles'; - $this->validConfig['global']['authorisation_group_perms_file']['default'] = $base.'etc/perms.db'; + private function setPathsByBase($base, $htmlBase, $data) { + $this->validConfig['paths']['cfg']['default'] = $data.'etc/'; + $this->validConfig['paths']['mapcfg']['default'] = $data.'etc/maps/'; + $this->validConfig['paths']['geomap']['default'] = $data.'etc/geomap'; + $this->validConfig['paths']['profiles']['default'] = $data.'etc/profiles'; + $this->validConfig['global']['authorisation_group_perms_file']['default'] = $data.'etc/perms.db'; $this->validConfig['paths']['var']['default'] = $base.'var/'; $this->validConfig['paths']['sharedvar']['default'] = $base.HTDOCS_DIR.'/var/'; diff --git a/share/server/core/defines/global.php b/share/server/core/defines/global.php index 04a03eed7..bdad40ecf 100644 --- a/share/server/core/defines/global.php +++ b/share/server/core/defines/global.php @@ -75,12 +75,21 @@ // The last value wins. // // Path to the main configuration file -define('CONST_MAINCFG', '../../../etc/nagvis.ini.php'); + + + +if (getenv('NAGVIS_CONFIG') !== false && getenv('NAGVIS_CONFIG') !== '') { + $nagvis_config = getenv('NAGVIS_CONFIG'); + $nagvis_config_dir = dirname($nagvis_config); + define('CONST_MAINCFG', $nagvis_config); + define('CONST_MAINCFG_DIR', $nagvis_config_dir . '/conf.d'); +} else { + define('CONST_MAINCFG', '../../../etc/nagvis.ini.php'); + // Path to the main configuration conf.d directory + define('CONST_MAINCFG_DIR', '../../../etc/conf.d'); +} define('CONST_MAINCFG_CACHE', '../../../var/nagvis-conf'); -// Path to the main configuration conf.d directory -define('CONST_MAINCFG_DIR', '../../../etc/conf.d'); - // The directory below the NagVis root which is shared by the webserver define('HTDOCS_DIR', 'share');