mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-28 08:14:03 +02:00
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:
parent
5559cf6c2b
commit
79fb8b1e0d
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user