diff --git a/config/config.ini b/config/config.ini index 1f58cd4e0..9425d2765 100755 --- a/config/config.ini +++ b/config/config.ini @@ -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" diff --git a/library/Icinga/Application/Config.php b/library/Icinga/Application/Config.php index 7464b6003..ba55da19f 100644 --- a/library/Icinga/Application/Config.php +++ b/library/Icinga/Application/Config.php @@ -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); + } } diff --git a/library/Icinga/Application/Logger.php b/library/Icinga/Application/Logger.php index d34c6c33a..185d54379 100755 --- a/library/Icinga/Application/Logger.php +++ b/library/Icinga/Application/Logger.php @@ -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; diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php index 7bf792667..703f32b3c 100644 --- a/library/Icinga/Application/Web.php +++ b/library/Icinga/Application/Web.php @@ -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, diff --git a/library/Icinga/Authentication/UserBackend.php b/library/Icinga/Authentication/UserBackend.php index 6c5fe85d3..1b8a0b652 100644 --- a/library/Icinga/Authentication/UserBackend.php +++ b/library/Icinga/Authentication/UserBackend.php @@ -62,4 +62,4 @@ interface UserBackend * @return int */ public function getUserCount(); -} \ No newline at end of file +} diff --git a/library/Icinga/User/Preferences/IniStore.php b/library/Icinga/User/Preferences/IniStore.php index 823c8b07e..4a88383e9 100644 --- a/library/Icinga/User/Preferences/IniStore.php +++ b/library/Icinga/User/Preferences/IniStore.php @@ -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"); + } } /** diff --git a/library/Icinga/Web/Form/Validator/WritablePathValidator.php b/library/Icinga/Web/Form/Validator/WritablePathValidator.php index 0447a4f42..573d7f529 100644 --- a/library/Icinga/Web/Form/Validator/WritablePathValidator.php +++ b/library/Icinga/Web/Form/Validator/WritablePathValidator.php @@ -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; diff --git a/test/php/library/Icinga/Web/Form/Validator/WritablePathValidatorTest.php b/test/php/library/Icinga/Web/Form/Validator/WritablePathValidatorTest.php index b9b579b29..c4d9b50bb 100644 --- a/test/php/library/Icinga/Web/Form/Validator/WritablePathValidatorTest.php +++ b/test/php/library/Icinga/Web/Form/Validator/WritablePathValidatorTest.php @@ -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;