Config: Remove base path subsitution

Test for leading slash and prepend base path to allow
absolute configuration files.

fixes #5556
This commit is contained in:
Marius Hein 2014-06-02 14:41:17 +02:00
parent 5559cf6c2b
commit 79fb8b1e0d
4 changed files with 12 additions and 18 deletions

View File

@ -82,7 +82,7 @@ class Config extends Zend_Config
$filepath = realpath($filename); $filepath = realpath($filename);
if ($filepath === false) { if ($filepath === false) {
$this->configFile = $filename; $this->configFile = $filename;
} else if (is_readable($filepath)) { } elseif (is_readable($filepath)) {
$this->configFile = $filepath; $this->configFile = $filepath;
$this->merge(new Zend_Config_Ini($filepath)); $this->merge(new Zend_Config_Ini($filepath));
} else { } else {
@ -102,8 +102,7 @@ class Config extends Zend_Config
public static function app($configname = 'config', $fromDisk = false) public static function app($configname = 'config', $fromDisk = false)
{ {
if (!isset(self::$app[$configname]) || $fromDisk) { if (!isset(self::$app[$configname]) || $fromDisk) {
$filename = self::$configDir . '/' . $configname . '.ini'; self::$app[$configname] = new Config(self::resolvePath($configname . '.ini'));
self::$app[$configname] = new Config($filename);
} }
return self::$app[$configname]; return self::$app[$configname];
} }
@ -125,7 +124,7 @@ class Config extends Zend_Config
$moduleConfigs = self::$modules[$modulename]; $moduleConfigs = self::$modules[$modulename];
if (!isset($moduleConfigs[$configname]) || $fromDisk) { if (!isset($moduleConfigs[$configname]) || $fromDisk) {
$moduleConfigs[$configname] = new Config( $moduleConfigs[$configname] = new Config(
self::$configDir . '/modules/' . $modulename . '/' . $configname . '.ini' self::resolvePath('modules/' . $modulename . '/' . $configname . '.ini')
); );
} }
return $moduleConfigs[$configname]; return $moduleConfigs[$configname];
@ -159,21 +158,17 @@ class Config extends Zend_Config
} }
/** /**
* Return the input path with resolved path variables * Prepend configuration base dir if input is relative
* *
* Currently only %app% is considered a path variable and points to the application paths * @param string $path Input path
* * @return string Absolute path
* @param string $path The path to resolve
*
* @return string The resolved path
*/ */
public static function resolvePath($path) public static function resolvePath($path)
{ {
try { if (strpos($path, DIRECTORY_SEPARATOR) === 0) {
$appDir = realpath(Icinga::app()->getApplicationDir() . '/..'); return $path;
} catch (ProgrammingError $appNotStarted) {
$appDir = realpath(__DIR__ . '/../../..');
} }
return str_replace('{app}', $appDir, $path);
return self::$configDir . DIRECTORY_SEPARATOR . $path;
} }
} }

View File

@ -28,7 +28,7 @@ class FileWriter extends LogWriter
*/ */
public function __construct(Zend_Config $config) public function __construct(Zend_Config $config)
{ {
$this->path = Config::resolvePath($config->target); $this->path = $config->target;
$this->setup(); $this->setup();
} }

View File

@ -132,7 +132,7 @@ abstract class PreferencesStore
} }
if ($type === 'Ini') { if ($type === 'Ini') {
$config->location = IcingaConfig::resolvePath($config->config_path); $config->location = $config->config_path;
} elseif ($type === 'Db') { } elseif ($type === 'Db') {
$config->connection = new DbConnection(ResourceFactory::getResourceConfig($config->resource)); $config->connection = new DbConnection(ResourceFactory::getResourceConfig($config->resource));
} }

View File

@ -81,7 +81,6 @@ class WritablePathValidator extends Zend_Validate_Abstract
$value = (string) $value; $value = (string) $value;
$this->_setValue($value); $this->_setValue($value);
$value = IcingaConfig::resolvePath($value);
if ($this->requireExistence && !file_exists($value)) { if ($this->requireExistence && !file_exists($value)) {
$this->_error('DOES_NOT_EXIST'); $this->_error('DOES_NOT_EXIST');
return false; return false;