From 79fb8b1e0dcea0866955a3ddde8743e2460885f8 Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Mon, 2 Jun 2014 14:41:17 +0200 Subject: [PATCH] Config: Remove base path subsitution Test for leading slash and prepend base path to allow absolute configuration files. fixes #5556 --- library/Icinga/Application/Config.php | 25 ++++++++----------- library/Icinga/Logger/Writer/FileWriter.php | 2 +- .../User/Preferences/PreferencesStore.php | 2 +- .../Form/Validator/WritablePathValidator.php | 1 - 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/library/Icinga/Application/Config.php b/library/Icinga/Application/Config.php index be0c43a60..596e1fe2b 100644 --- a/library/Icinga/Application/Config.php +++ b/library/Icinga/Application/Config.php @@ -82,7 +82,7 @@ class Config extends Zend_Config $filepath = realpath($filename); if ($filepath === false) { $this->configFile = $filename; - } else if (is_readable($filepath)) { + } elseif (is_readable($filepath)) { $this->configFile = $filepath; $this->merge(new Zend_Config_Ini($filepath)); } else { @@ -102,8 +102,7 @@ class Config extends Zend_Config public static function app($configname = 'config', $fromDisk = false) { if (!isset(self::$app[$configname]) || $fromDisk) { - $filename = self::$configDir . '/' . $configname . '.ini'; - self::$app[$configname] = new Config($filename); + self::$app[$configname] = new Config(self::resolvePath($configname . '.ini')); } return self::$app[$configname]; } @@ -125,7 +124,7 @@ class Config extends Zend_Config $moduleConfigs = self::$modules[$modulename]; if (!isset($moduleConfigs[$configname]) || $fromDisk) { $moduleConfigs[$configname] = new Config( - self::$configDir . '/modules/' . $modulename . '/' . $configname . '.ini' + self::resolvePath('modules/' . $modulename . '/' . $configname . '.ini') ); } 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 The path to resolve - * - * @return string The resolved path + * @param string $path Input path + * @return string Absolute path */ public static function resolvePath($path) { - try { - $appDir = realpath(Icinga::app()->getApplicationDir() . '/..'); - } catch (ProgrammingError $appNotStarted) { - $appDir = realpath(__DIR__ . '/../../..'); + if (strpos($path, DIRECTORY_SEPARATOR) === 0) { + return $path; } - return str_replace('{app}', $appDir, $path); + + return self::$configDir . DIRECTORY_SEPARATOR . $path; } } diff --git a/library/Icinga/Logger/Writer/FileWriter.php b/library/Icinga/Logger/Writer/FileWriter.php index 1208f3f3b..e77c0c577 100644 --- a/library/Icinga/Logger/Writer/FileWriter.php +++ b/library/Icinga/Logger/Writer/FileWriter.php @@ -28,7 +28,7 @@ class FileWriter extends LogWriter */ public function __construct(Zend_Config $config) { - $this->path = Config::resolvePath($config->target); + $this->path = $config->target; $this->setup(); } diff --git a/library/Icinga/User/Preferences/PreferencesStore.php b/library/Icinga/User/Preferences/PreferencesStore.php index 80b43a330..381bb39c0 100644 --- a/library/Icinga/User/Preferences/PreferencesStore.php +++ b/library/Icinga/User/Preferences/PreferencesStore.php @@ -132,7 +132,7 @@ abstract class PreferencesStore } if ($type === 'Ini') { - $config->location = IcingaConfig::resolvePath($config->config_path); + $config->location = $config->config_path; } elseif ($type === 'Db') { $config->connection = new DbConnection(ResourceFactory::getResourceConfig($config->resource)); } diff --git a/library/Icinga/Web/Form/Validator/WritablePathValidator.php b/library/Icinga/Web/Form/Validator/WritablePathValidator.php index 3d9cb5dbc..888f6bd1b 100644 --- a/library/Icinga/Web/Form/Validator/WritablePathValidator.php +++ b/library/Icinga/Web/Form/Validator/WritablePathValidator.php @@ -81,7 +81,6 @@ class WritablePathValidator extends Zend_Validate_Abstract $value = (string) $value; $this->_setValue($value); - $value = IcingaConfig::resolvePath($value); if ($this->requireExistence && !file_exists($value)) { $this->_error('DOES_NOT_EXIST'); return false;