mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-04-08 17:15:08 +02:00
Implement {app} placeholder and Icinga\Config::resolvePath()
refs #4642
This commit is contained in:
parent
3af7e2591b
commit
0b515e39ac
config
library/Icinga
Application
Authentication
User/Preferences
Web/Form/Validator
test/php/library/Icinga/Web/Form/Validator
@ -1,6 +1,6 @@
|
||||
[global]
|
||||
environment = "development"
|
||||
timezone = "Europe/Berlin"
|
||||
timezone = "Europe/Minsk"
|
||||
indexModule = "monitoring"
|
||||
indexController = "dashboard"
|
||||
; The moduleFolder directive is currently not used anywhere but configureable
|
||||
@ -13,16 +13,16 @@ timeFormat = "g:i A"
|
||||
|
||||
[logging]
|
||||
; General log
|
||||
enable = "1"
|
||||
enable = 1
|
||||
type = "stream"
|
||||
verbose = "1"
|
||||
target = "/etc/icinga2-web/icinga2.log"
|
||||
target = "{app}/var/log/icinga.log"
|
||||
|
||||
; For development and debug purposes: Logs additional (non critical) events to a
|
||||
; seperate log
|
||||
debug.enable = "1"
|
||||
debug.enable = 1
|
||||
debug.type = "stream"
|
||||
debug.target = "/etc/icinga2-web/icinga2.debug.log"
|
||||
debug.target = "{app}/var/log/icinga.debug.log"
|
||||
|
||||
; Use ini store to store preferences on local disk
|
||||
[preferences]
|
||||
@ -33,4 +33,4 @@ type = "ini"
|
||||
;type=db
|
||||
;resource=icingaweb-mysql
|
||||
|
||||
configPath = "/vagrant/config/preferences"
|
||||
configPath = "{app}/config/preferences"
|
||||
|
@ -28,7 +28,8 @@
|
||||
|
||||
namespace Icinga\Application;
|
||||
|
||||
use Zend_Config_Ini;
|
||||
use \Icinga\Exception\ProgrammingError;
|
||||
use \Zend_Config_Ini;
|
||||
|
||||
/**
|
||||
* Global registry of application and module configuration.
|
||||
@ -143,8 +144,32 @@ class Config extends Zend_Config_Ini
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the application wide config file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getConfigFile()
|
||||
{
|
||||
return $this->configFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the input path with resolved path variables
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
public static function resolvePath($path)
|
||||
{
|
||||
try {
|
||||
$appDir = realpath(Icinga::app()->getApplicationDir() . '/..');
|
||||
} catch (ProgrammingError $appNotStarted) {
|
||||
$appDir = realpath(__DIR__ . '/../../..');
|
||||
}
|
||||
return str_replace('{app}', $appDir, $path);
|
||||
}
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ final class Logger
|
||||
|
||||
try {
|
||||
/** @var Zend_Log_Writer_Abstract $writer */
|
||||
$writer = new $writerClass($target);
|
||||
$writer = new $writerClass(Config::resolvePath($target));
|
||||
$writer->addFilter(new Zend_Log_Filter_Priority($priority));
|
||||
$this->logger->addWriter($writer);
|
||||
$this->writers[] = $writer;
|
||||
|
@ -249,7 +249,8 @@ class Web extends ApplicationBootstrap
|
||||
$preferences->attach($sessionStore);
|
||||
|
||||
if ($this->getConfig()->preferences !== null) {
|
||||
if (is_dir($this->getConfig()->preferences->configPath) === false) {
|
||||
$path = Config::resolvePath($this->getConfig()->preferences->configPath);
|
||||
if (is_dir($path) === false) {
|
||||
Logger::error(
|
||||
'Path for preferences not found (IniStore, "%s"). Using default one: "%s"',
|
||||
$this->getConfig()->preferences->configPath,
|
||||
|
@ -62,4 +62,4 @@ interface UserBackend
|
||||
* @return int
|
||||
*/
|
||||
public function getUserCount();
|
||||
}
|
||||
}
|
||||
|
@ -28,13 +28,16 @@
|
||||
|
||||
namespace Icinga\User\Preferences;
|
||||
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Protocol\Ldap\Exception;
|
||||
use \SplObserver;
|
||||
use \SplSubject;
|
||||
use Icinga\User;
|
||||
use Icinga\User\Preferences;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use \Icinga\User;
|
||||
use \Icinga\User\Preferences;
|
||||
use \Icinga\Exception\ConfigurationError;
|
||||
use \Icinga\Exception\ProgrammingError;
|
||||
use \Zend_Config;
|
||||
use \Icinga\Application\Config as IcingaConfig;
|
||||
use \Zend_Config_Writer_Ini;
|
||||
|
||||
/**
|
||||
@ -84,7 +87,7 @@ class IniStore implements LoadInterface, FlushObserverInterface
|
||||
*
|
||||
* @param string|null $configPath
|
||||
*/
|
||||
public function __construct($configPath=null)
|
||||
public function __construct($configPath = null)
|
||||
{
|
||||
if ($configPath !== null) {
|
||||
$this->setConfigPath($configPath);
|
||||
@ -99,6 +102,7 @@ class IniStore implements LoadInterface, FlushObserverInterface
|
||||
*/
|
||||
public function setConfigPath($configPath)
|
||||
{
|
||||
$configPath = IcingaConfig::resolvePath($configPath);
|
||||
if (!is_dir($configPath)) {
|
||||
throw new ConfigurationError('Config dir dos not exist: '. $configPath);
|
||||
}
|
||||
@ -124,18 +128,22 @@ class IniStore implements LoadInterface, FlushObserverInterface
|
||||
if (file_exists($this->preferencesFile) === false) {
|
||||
$this->createDefaultIniFile();
|
||||
}
|
||||
try {
|
||||
$this->iniConfig = new Zend_Config(
|
||||
parse_ini_file($this->preferencesFile),
|
||||
true
|
||||
);
|
||||
|
||||
$this->iniConfig = new Zend_Config(
|
||||
parse_ini_file($this->preferencesFile),
|
||||
true
|
||||
);
|
||||
|
||||
$this->iniWriter = new Zend_Config_Writer_Ini(
|
||||
array(
|
||||
'config' => $this->iniConfig,
|
||||
'filename' => $this->preferencesFile
|
||||
)
|
||||
);
|
||||
$this->iniWriter = new Zend_Config_Writer_Ini(
|
||||
array(
|
||||
'config' => $this->iniConfig,
|
||||
'filename' => $this->preferencesFile
|
||||
)
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
Logger::error('Could not create IniStore backend: %s', $e->getMessage());
|
||||
throw new \RuntimeException("Creating user preference backend failed");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,6 +29,7 @@
|
||||
namespace Icinga\Web\Form\Validator;
|
||||
|
||||
use \Zend_Validate_Abstract;
|
||||
use \Icinga\Application\Config as IcingaConfig;
|
||||
|
||||
/**
|
||||
* Validator that interprets the value as a path and checks if it's writable
|
||||
@ -77,8 +78,9 @@ class WritablePathValidator extends Zend_Validate_Abstract
|
||||
public function isValid($value, $context = null)
|
||||
{
|
||||
$value = (string) $value;
|
||||
$this->_setValue($value);
|
||||
|
||||
$this->_setValue($value);
|
||||
$value = IcingaConfig::resolvePath($value);
|
||||
if ($this->requireExistence && !file_exists($value)) {
|
||||
$this->_error('DOES_NOT_EXIST');
|
||||
return false;
|
||||
|
@ -30,6 +30,7 @@ namespace Test\Icinga\Web\Form\Validator;
|
||||
|
||||
require_once('Zend/Validate/Abstract.php');
|
||||
require_once(realpath('../../library/Icinga/Web/Form/Validator/WritablePathValidator.php'));
|
||||
require_once(realpath('../../library/Icinga/Application/Config.php'));
|
||||
|
||||
use \PHPUnit_Framework_TestCase;
|
||||
use \Icinga\Web\Form\Validator\WritablePathValidator;
|
||||
|
Loading…
x
Reference in New Issue
Block a user