Author: Lars Michelsen <[email protected]>
Date: Sun Jul 31 01:34:32 2011 +0200
Committer: Lars Michelsen <[email protected]>
Commit-Date: Sun Jul 31 01:34:32 2011 +0200
Fixed maincfg WUI editing problems with multiple files
* Bugfix: Fixed comment line mixup in main config when using multiple config
files
* Bugfix: Not storing config options from other config files like the OMD
site config in nagvis.ini.php anymore
---
ChangeLog | 4 ++
share/server/core/classes/GlobalMainCfg.php | 64 ++++++++++++++++++++++----
2 files changed, 58 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 0c6e878..d582003 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,10 @@ Core
* omd_install: Installing missing doc/ dir now; Cleaning cache files on
install
* Checking read permissions before reading directory contents
* Bugfix: Added backgrounds/styles [paths] options to main cfg definitions
+ * Bugfix: Fixed comment line mixup in main config when using multiple
+ config files
+ * Bugfix: Not storing config options from other config files like the OMD
+ site config in nagvis.ini.php anymore
Automap
* Improved coordinate parsing regex to match graphviz output of more versions
diff --git a/share/server/core/classes/GlobalMainCfg.php
b/share/server/core/classes/GlobalMainCfg.php
index d9ef9b0..36c9e9c 100644
--- a/share/server/core/classes/GlobalMainCfg.php
+++ b/share/server/core/classes/GlobalMainCfg.php
@@ -30,6 +30,7 @@ class GlobalMainCfg {
private $CACHE;
protected $config = Array();
+ protected $preUserConfig = null;
protected $runtimeConfig = Array();
protected $stateWeight;
@@ -1023,18 +1024,22 @@ class GlobalMainCfg {
// Use the newest file as indicator for using the cache or not
$this->CACHE = new GlobalFileCache(GlobalCore::getInstance(),
$newestFile, CONST_MAINCFG_CACHE.'-'.CONST_VERSION.'-cache');
+ $this->PUCACHE = new GlobalFileCache(GlobalCore::getInstance(),
$newestFile, CONST_MAINCFG_CACHE.'-pre-user-'.CONST_VERSION.'-cache');
if($this->CACHE->isCached(false) === -1) {
// The cache is too old. Load all config files
foreach($this->configFiles AS $configFile) {
// Only proceed when the configuration file exists and is
readable
if(!GlobalCore::getInstance()->checkExisting($configFile,
true) || !GlobalCore::getInstance()->checkReadable($configFile, true))
return false;
- $this->readConfig($configFile, true);
+ $this->readConfig($configFile, true, $configFile ==
end($this->configFiles));
}
$this->CACHE->writeCache($this->config, true);
+ if($this->preUserConfig !== null)
+ $this->PUCACHE->writeCache($this->preUserConfig, true);
} else {
// Use the cache!
$this->config = $this->CACHE->getCache();
+ $this->preUserConfig = $this->PUCACHE->getCache();
}
// Update the cache time
@@ -1153,7 +1158,7 @@ class GlobalMainCfg {
* @return Boolean Is Successful?
* @author Lars Michelsen <[email protected]>
*/
- private function readConfig($configFile, $printErr=1) {
+ private function readConfig($configFile, $printErr=1, $isUserMainCfg =
False) {
$numComments = 0;
$sec = '';
@@ -1163,6 +1168,15 @@ class GlobalMainCfg {
// Count the lines before the loop (only counts once)
$countLines = count($file);
+ // Separate the options from the site configuration and add it later
+ // when the user did not define anything different.
+ // This is needed to keep the lines of the maincfg file in correct
order
+ $tmpConfig = null;
+ if($isUserMainCfg) {
+ $this->preUserConfig = $this->config;
+ $this->config = Array();
+ }
+
// loop trough array
for ($i = 0; $i < $countLines; $i++) {
// cut spaces from beginning and end
@@ -1175,14 +1189,16 @@ class GlobalMainCfg {
// check what's in this line
if($firstChar == ';') {
- // comment...
- $key = 'comment_'.($numComments++);
- $val = trim($line);
+ if($isUserMainCfg) {
+ // comment...
+ $key = 'comment_'.($numComments++);
+ $val = trim($line);
- if(isset($sec) && $sec != '') {
- $this->config[$sec][$key] = $val;
- } else {
- $this->config[$key] = $val;
+ if(isset($sec) && $sec != '') {
+ $this->config[$sec][$key] = $val;
+ } else {
+ $this->config[$key] = $val;
+ }
}
} elseif ((substr($line, 0, 1) == '[') && (substr($line, -1,
1)) == ']') {
// section
@@ -1270,10 +1286,24 @@ class GlobalMainCfg {
}
} else {
$sec = '';
- $this->config['comment_'.($numComments++)] = '';
+ if($isUserMainCfg)
+ $this->config['comment_'.($numComments++)] = '';
+ }
+ }
+
+ // Reapply the separated config
+ if($isUserMainCfg && $this->preUserConfig !== null) {
+ foreach($this->preUserConfig AS $sec => $opts) {
+ foreach($opts AS $opt => $val) {
+ if(!isset($this->config[$sec]))
+ $this->config[$sec] = $opts;
+ elseif(!isset($this->config[$sec][$opt]))
+ $this->config[$sec][$opt] = $val;
+ }
}
}
+
return $this->checkMainConfigIsValid(1);
}
@@ -1744,6 +1774,13 @@ class GlobalMainCfg {
$content .= $item2."\n";
} else {
if(is_numeric($item2) || is_bool($item2)) {
+ // Don't apply config options which are set to the
same
+ // value in the pre user config files
+ if($this->preUserConfig !== null
+ && isset($this->preUserConfig[$key])
+ && isset($this->preUserConfig[$key][$key2])
+ && $item2 == $this->preUserConfig[$key][$key2])
+ continue;
$content .= $key2."=".$item2."\n";
} else {
if(is_array($item2) && preg_match('/^rotation_/i',
$key) && $key2 == 'maps') {
@@ -1774,6 +1811,13 @@ class GlobalMainCfg {
// Don't write the backendid/rotationid attributes
(Are internal)
if($key2 !== 'backendid' && $key2 !==
'rotationid') {
+ // Don't apply config options which are set to
the same
+ // value in the pre user config files
+ if($this->preUserConfig !== null
+ && isset($this->preUserConfig[$key])
+ && isset($this->preUserConfig[$key][$key2])
+ && $item2 ==
$this->preUserConfig[$key][$key2])
+ continue;
if(isset($this->validConfig[$key][$key2]['array']) &&
$this->validConfig[$key][$key2]['array'] === true)
$item2 = implode(',', $item2);
------------------------------------------------------------------------------
Got Input? Slashdot Needs You.
Take our quick survey online. Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins