Merge branch 'master' into feature/remove-autotools-files-7505
This commit is contained in:
commit
f097299534
|
@ -76,7 +76,7 @@ __function createService(service_type, num) {
|
|||
enable_active_checks = (service_type != "pending")
|
||||
vars.check_type = service_type
|
||||
|
||||
assign where match("*" + service_type + "*", host.vars.check_config)
|
||||
assign where service_type in host.vars.check_config
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,12 +102,12 @@ __function createHost(checkType, checkConfig, num, checkEnabled) {
|
|||
}
|
||||
|
||||
__for (num in range(10)) {
|
||||
createHost("ok", "ok", num, true)
|
||||
createHost("random", "random,flapping", num, true)
|
||||
createHost("down", "warning,critical", num, true)
|
||||
createHost("unreachable", "unknown", num, true)
|
||||
createHost("pending", "pending", num, false)
|
||||
createHost("flap", "flapping", num, true)
|
||||
createHost("ok", [ "ok" ], num, true)
|
||||
createHost("random", [ "random", "flapping" ], num, true)
|
||||
createHost("down", [ "warning", "critical" ], num, true)
|
||||
createHost("unreachable", [ "unknown" ], num, true)
|
||||
createHost("pending", [ "pending" ], num, false)
|
||||
createHost("flap", [ "flapping" ], num, true)
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
|
|
@ -601,27 +601,15 @@ exec { 'create-pgsql-icingaweb-db':
|
|||
require => Service['postgresql']
|
||||
}
|
||||
|
||||
exec { 'populate-icingaweb-mysql-db-accounts':
|
||||
exec { 'populate-icingaweb-mysql-db-tables':
|
||||
unless => 'mysql -uicingaweb -picingaweb icingaweb -e "SELECT * FROM account;" &> /dev/null',
|
||||
command => 'mysql -uicingaweb -picingaweb icingaweb < /vagrant/etc/schema/accounts.mysql.sql',
|
||||
command => 'mysql -uicingaweb -picingaweb icingaweb < /vagrant/etc/schema/mysql.sql',
|
||||
require => [ Exec['create-mysql-icingaweb-db'] ]
|
||||
}
|
||||
|
||||
exec { 'populate-icingweba-pgsql-db-accounts':
|
||||
exec { 'populate-icingweba-pgsql-db-tables':
|
||||
unless => 'psql -U icingaweb -d icingaweb -c "SELECT * FROM account;" &> /dev/null',
|
||||
command => 'sudo -u postgres psql -U icingaweb -d icingaweb -f /vagrant/etc/schema/accounts.pgsql.sql',
|
||||
require => [ Exec['create-pgsql-icingaweb-db'] ]
|
||||
}
|
||||
|
||||
exec { 'populate-icingaweb-mysql-db-preferences':
|
||||
unless => 'mysql -uicingaweb -picingaweb icingaweb -e "SELECT * FROM preference;" &> /dev/null',
|
||||
command => 'mysql -uicingaweb -picingaweb icingaweb < /vagrant/etc/schema/preferences.mysql.sql',
|
||||
require => [ Exec['create-mysql-icingaweb-db'] ]
|
||||
}
|
||||
|
||||
exec { 'populate-icingweba-pgsql-db-preferences':
|
||||
unless => 'psql -U icingaweb -d icingaweb -c "SELECT * FROM preference;" &> /dev/null',
|
||||
command => 'sudo -u postgres psql -U icingaweb -d icingaweb -f /vagrant/etc/schema/preferences.pgsql.sql',
|
||||
command => 'sudo -u postgres psql -U icingaweb -d icingaweb -f /vagrant/etc/schema/pgsql.sql',
|
||||
require => [ Exec['create-pgsql-icingaweb-db'] ]
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
namespace Icinga\Clicommands;
|
||||
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Cli\Command;
|
||||
use Icinga\Exception\IcingaException;
|
||||
|
||||
|
@ -30,7 +31,7 @@ class WebCommand extends Command
|
|||
// throw new IcingaException('Socket is required');
|
||||
}
|
||||
if ($basedir === null) {
|
||||
$basedir = dirname(ICINGAWEB_APPDIR) . '/public';
|
||||
$basedir = Icinga::app()->getBaseDir('public');
|
||||
if (! file_exists($basedir) || ! is_dir($basedir)) {
|
||||
throw new IcingaException('Basedir is required');
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ use Icinga\Web\Controller\ActionController;
|
|||
use Icinga\Form\Authentication\LoginForm;
|
||||
use Icinga\Authentication\AuthChain;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Exception\AuthenticationException;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
|
@ -33,6 +33,17 @@ class AuthenticationController extends ActionController
|
|||
*/
|
||||
public function loginAction()
|
||||
{
|
||||
if (@file_exists(Config::$configDir . '/setup.token')) {
|
||||
try {
|
||||
$config = Config::app()->toArray();
|
||||
if (empty($config)) {
|
||||
$this->redirectNow(Url::fromPath('setup'));
|
||||
}
|
||||
} catch (NotReadableError $e) {
|
||||
// Gets thrown in case of insufficient permission only
|
||||
}
|
||||
}
|
||||
|
||||
$auth = $this->Auth();
|
||||
$this->view->form = $form = new LoginForm();
|
||||
$this->view->title = $this->translate('Icingaweb Login');
|
||||
|
@ -93,30 +104,30 @@ class AuthenticationController extends ActionController
|
|||
}
|
||||
}
|
||||
if ($backendsTried === 0) {
|
||||
throw new ConfigurationError(
|
||||
$this->view->form->addError(
|
||||
$this->translate(
|
||||
'No authentication methods available. Did you create'
|
||||
. ' authentication.ini when installing Icinga Web 2?'
|
||||
. ' authentication.ini when setting up Icinga Web 2?'
|
||||
)
|
||||
);
|
||||
}
|
||||
if ($backendsTried === $backendsWithError) {
|
||||
throw new ConfigurationError(
|
||||
} else if ($backendsTried === $backendsWithError) {
|
||||
$this->view->form->addError(
|
||||
$this->translate(
|
||||
'All configured authentication methods failed.'
|
||||
. ' Please check the system log or Icinga Web 2 log for more information.'
|
||||
)
|
||||
);
|
||||
}
|
||||
if ($backendsWithError) {
|
||||
$this->view->form->getElement('username')->addError(
|
||||
} elseif ($backendsWithError) {
|
||||
$this->view->form->addError(
|
||||
$this->translate(
|
||||
'Please note that not all authentication methods were available.'
|
||||
. ' Check the system log or Icinga Web 2 log for more information.'
|
||||
)
|
||||
);
|
||||
}
|
||||
$this->view->form->getElement('password')->addError($this->translate('Incorrect username or password'));
|
||||
if ($backendsTried > 0 && $backendsTried !== $backendsWithError) {
|
||||
$this->view->form->getElement('password')->addError($this->translate('Incorrect username or password'));
|
||||
}
|
||||
} elseif ($request->isGet()) {
|
||||
$user = new User('');
|
||||
foreach ($chain as $backend) {
|
||||
|
@ -134,6 +145,8 @@ class AuthenticationController extends ActionController
|
|||
} catch (Exception $e) {
|
||||
$this->view->errorInfo = $e->getMessage();
|
||||
}
|
||||
|
||||
$this->view->configMissing = is_dir(Config::$configDir) === false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,7 +7,7 @@ use Icinga\Web\Notification;
|
|||
use Icinga\Application\Modules\Module;
|
||||
use Icinga\Web\Widget;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Application\Config as IcingaConfig;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Form\Config\GeneralConfigForm;
|
||||
use Icinga\Form\Config\AuthenticationBackendReorderForm;
|
||||
use Icinga\Form\Config\AuthenticationBackendConfigForm;
|
||||
|
@ -46,7 +46,7 @@ class ConfigController extends ActionController
|
|||
public function indexAction()
|
||||
{
|
||||
$form = new GeneralConfigForm();
|
||||
$form->setIniConfig(IcingaConfig::app());
|
||||
$form->setIniConfig(Config::app());
|
||||
$form->handleRequest();
|
||||
|
||||
$this->view->form = $form;
|
||||
|
@ -99,7 +99,7 @@ class ConfigController extends ActionController
|
|||
Notification::success(sprintf($this->translate('Module "%s" enabled'), $module));
|
||||
$this->rerenderLayout()->reloadCss()->redirectNow('config/modules');
|
||||
} catch (Exception $e) {
|
||||
$this->view->exceptionMesssage = $e->getMessage();
|
||||
$this->view->exceptionMessage = $e->getMessage();
|
||||
$this->view->moduleName = $module;
|
||||
$this->view->action = 'enable';
|
||||
$this->render('module-configuration-error');
|
||||
|
@ -131,7 +131,7 @@ class ConfigController extends ActionController
|
|||
public function authenticationAction()
|
||||
{
|
||||
$form = new AuthenticationBackendReorderForm();
|
||||
$form->setIniConfig(IcingaConfig::app('authentication'));
|
||||
$form->setIniConfig(Config::app('authentication'));
|
||||
$form->handleRequest();
|
||||
|
||||
$this->view->form = $form;
|
||||
|
@ -145,7 +145,7 @@ class ConfigController extends ActionController
|
|||
public function createauthenticationbackendAction()
|
||||
{
|
||||
$form = new AuthenticationBackendConfigForm();
|
||||
$form->setIniConfig(IcingaConfig::app('authentication'));
|
||||
$form->setIniConfig(Config::app('authentication'));
|
||||
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
|
||||
$form->setRedirectUrl('config/authentication');
|
||||
$form->handleRequest();
|
||||
|
@ -161,7 +161,7 @@ class ConfigController extends ActionController
|
|||
public function editauthenticationbackendAction()
|
||||
{
|
||||
$form = new AuthenticationBackendConfigForm();
|
||||
$form->setIniConfig(IcingaConfig::app('authentication'));
|
||||
$form->setIniConfig(Config::app('authentication'));
|
||||
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
|
||||
$form->setRedirectUrl('config/authentication');
|
||||
$form->handleRequest();
|
||||
|
@ -179,7 +179,7 @@ class ConfigController extends ActionController
|
|||
$form = new ConfirmRemovalForm(array(
|
||||
'onSuccess' => function ($request) {
|
||||
$configForm = new AuthenticationBackendConfigForm();
|
||||
$configForm->setIniConfig(IcingaConfig::app('authentication'));
|
||||
$configForm->setIniConfig(Config::app('authentication'));
|
||||
$authBackend = $request->getQuery('auth_backend');
|
||||
|
||||
try {
|
||||
|
@ -212,7 +212,7 @@ class ConfigController extends ActionController
|
|||
*/
|
||||
public function resourceAction()
|
||||
{
|
||||
$this->view->resources = IcingaConfig::app('resources', true)->toArray();
|
||||
$this->view->resources = Config::app('resources', true)->toArray();
|
||||
$this->view->tabs->activate('resources');
|
||||
}
|
||||
|
||||
|
@ -222,7 +222,7 @@ class ConfigController extends ActionController
|
|||
public function createresourceAction()
|
||||
{
|
||||
$form = new ResourceConfigForm();
|
||||
$form->setIniConfig(IcingaConfig::app('resources'));
|
||||
$form->setIniConfig(Config::app('resources'));
|
||||
$form->setRedirectUrl('config/resource');
|
||||
$form->handleRequest();
|
||||
|
||||
|
@ -236,7 +236,7 @@ class ConfigController extends ActionController
|
|||
public function editresourceAction()
|
||||
{
|
||||
$form = new ResourceConfigForm();
|
||||
$form->setIniConfig(IcingaConfig::app('resources'));
|
||||
$form->setIniConfig(Config::app('resources'));
|
||||
$form->setRedirectUrl('config/resource');
|
||||
$form->handleRequest();
|
||||
|
||||
|
@ -252,7 +252,7 @@ class ConfigController extends ActionController
|
|||
$form = new ConfirmRemovalForm(array(
|
||||
'onSuccess' => function ($request) {
|
||||
$configForm = new ResourceConfigForm();
|
||||
$configForm->setIniConfig(IcingaConfig::app('resources'));
|
||||
$configForm->setIniConfig(Config::app('resources'));
|
||||
$resource = $request->getQuery('resource');
|
||||
|
||||
try {
|
||||
|
@ -274,7 +274,7 @@ class ConfigController extends ActionController
|
|||
|
||||
// Check if selected resource is currently used for authentication
|
||||
$resource = $this->getRequest()->getQuery('resource');
|
||||
$authConfig = IcingaConfig::app('authentication')->toArray();
|
||||
$authConfig = Config::app('authentication')->toArray();
|
||||
foreach ($authConfig as $backendName => $config) {
|
||||
if (array_key_exists('resource', $config) && $config['resource'] === $resource) {
|
||||
$form->addError(sprintf(
|
||||
|
|
|
@ -2,16 +2,16 @@
|
|||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Config\PreservingIniWriter;
|
||||
use Icinga\Application\Config as IcingaConfig;
|
||||
use Icinga\Web\Widget\Dashboard;
|
||||
use Icinga\Form\Dashboard\AddUrlForm;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Web\Controller\ActionController;
|
||||
use Icinga\Exception\IcingaException;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Icinga\File\Ini\IniWriter;
|
||||
use Icinga\Form\Dashboard\AddUrlForm;
|
||||
use Icinga\Web\Controller\ActionController;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Web\Widget\Dashboard;
|
||||
|
||||
/**
|
||||
* Handle creation, removal and displaying of dashboards, panes and components
|
||||
|
@ -36,7 +36,7 @@ class DashboardController extends ActionController
|
|||
{
|
||||
$dashboard = new Dashboard();
|
||||
try {
|
||||
$dashboardConfig = IcingaConfig::app($config);
|
||||
$dashboardConfig = Config::app($config);
|
||||
if (count($dashboardConfig) === 0) {
|
||||
return null;
|
||||
}
|
||||
|
@ -92,8 +92,8 @@ class DashboardController extends ActionController
|
|||
ltrim($form->getValue('url'), '/')
|
||||
);
|
||||
|
||||
$configFile = IcingaConfig::app('dashboard/dashboard')->getConfigFile();
|
||||
if ($this->writeConfiguration(new Zend_Config($dashboard->toArray()), $configFile)) {
|
||||
$configFile = Config::app('dashboard/dashboard')->getConfigFile();
|
||||
if ($this->writeConfiguration(new Config($dashboard->toArray()), $configFile)) {
|
||||
$this->redirectNow(Url::fromPath('dashboard', array('pane' => $form->getValue('pane'))));
|
||||
} else {
|
||||
$this->render('showConfiguration');
|
||||
|
@ -125,7 +125,7 @@ class DashboardController extends ActionController
|
|||
$dashboard->activate($pane);
|
||||
}
|
||||
|
||||
$this->view->configPath = IcingaConfig::resolvePath(self::DEFAULT_CONFIG);
|
||||
$this->view->configPath = Config::resolvePath(self::DEFAULT_CONFIG);
|
||||
|
||||
if ($dashboard === null) {
|
||||
$this->view->title = 'Dashboard';
|
||||
|
@ -151,14 +151,14 @@ class DashboardController extends ActionController
|
|||
/**
|
||||
* Store the given configuration as INI file
|
||||
*
|
||||
* @param Zend_Config $config The configuration to store
|
||||
* @param string $target The path where to store the configuration
|
||||
* @param Config $config The configuration to store
|
||||
* @param string $target The path where to store the configuration
|
||||
*
|
||||
* @return bool Whether the configuartion has been successfully stored
|
||||
*/
|
||||
protected function writeConfiguration(Zend_Config $config, $target)
|
||||
protected function writeConfiguration(Config $config, $target)
|
||||
{
|
||||
$writer = new PreservingIniWriter(array('config' => $config, 'filename' => $target));
|
||||
$writer = new IniWriter(array('config' => $config, 'filename' => $target));
|
||||
|
||||
try {
|
||||
$writer->write();
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
// namespace Icinga\Application\Controllers;
|
||||
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Web\Controller\ActionController;
|
||||
use Icinga\Application\Icinga;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use Icinga\Web\Controller\ActionController;
|
||||
use Icinga\Filter\Filter;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
|
||||
/**
|
||||
* Application wide interface for filtering
|
||||
|
|
|
@ -3,11 +3,9 @@
|
|||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
use Icinga\Module\Monitoring\Controller;
|
||||
use Icinga\Web\Hook;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Logger\Writer\FileWriter;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Protocol\File\FileReader;
|
||||
use \Zend_Controller_Action_Exception as ActionError;
|
||||
|
||||
|
@ -50,7 +48,7 @@ class ListController extends Controller
|
|||
. ' - (?<message>.*)$/'; // message
|
||||
|
||||
$loggerWriter = Logger::getInstance()->getWriter();
|
||||
$resource = new FileReader(new Zend_Config(array(
|
||||
$resource = new FileReader(new Config(array(
|
||||
'filename' => $loggerWriter->getPath(),
|
||||
'fields' => $pattern
|
||||
)));
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use Icinga\Web\Controller\ActionController;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Web\FileCache;
|
||||
use Zend_Controller_Action_Exception as ActionException;
|
||||
|
||||
|
|
|
@ -31,7 +31,9 @@ class AutologinBackendForm extends Form
|
|||
array(
|
||||
'required' => true,
|
||||
'label' => t('Backend Name'),
|
||||
'description' => t('The name of this authentication backend'),
|
||||
'description' => t(
|
||||
'The name of this authentication provider that is used to differentiate it from others'
|
||||
),
|
||||
'validators' => array(
|
||||
array(
|
||||
'Regex',
|
||||
|
@ -50,9 +52,8 @@ class AutologinBackendForm extends Form
|
|||
'text',
|
||||
'strip_username_regexp',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Backend Domain Pattern'),
|
||||
'description' => t('The domain pattern of this authentication backend'),
|
||||
'label' => t('Filter Pattern'),
|
||||
'description' => t('The regular expression to use to strip specific parts off from usernames. Leave empty if you do not want to strip off anything'),
|
||||
'value' => '/\@[^$]+$/',
|
||||
'validators' => array(
|
||||
new Zend_Validate_Callback(function ($value) {
|
||||
|
@ -82,7 +83,7 @@ class AutologinBackendForm extends Form
|
|||
*
|
||||
* @return bool Whether validation succeeded or not
|
||||
*/
|
||||
public function isValidAuthenticationBackend(Form $form)
|
||||
public static function isValidAuthenticationBackend(Form $form)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
namespace Icinga\Form\Config\Authentication;
|
||||
|
||||
use Exception;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Web\Request;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
|
@ -54,7 +55,9 @@ class DbBackendForm extends Form
|
|||
array(
|
||||
'required' => true,
|
||||
'label' => t('Backend Name'),
|
||||
'description' => t('The name of this authentication provider'),
|
||||
'description' => t(
|
||||
'The name of this authentication provider that is used to differentiate it from others'
|
||||
),
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
|
@ -88,7 +91,7 @@ class DbBackendForm extends Form
|
|||
*/
|
||||
public function onSuccess(Request $request)
|
||||
{
|
||||
if (false === $this->isValidAuthenticationBackend($this)) {
|
||||
if (false === static::isValidAuthenticationBackend($this)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -100,21 +103,29 @@ class DbBackendForm extends Form
|
|||
*
|
||||
* @return bool Whether validation succeeded or not
|
||||
*/
|
||||
public function isValidAuthenticationBackend(Form $form)
|
||||
public static function isValidAuthenticationBackend(Form $form)
|
||||
{
|
||||
$element = $form->getElement('resource');
|
||||
|
||||
try {
|
||||
$dbUserBackend = new DbUserBackend(ResourceFactory::create($element->getValue()));
|
||||
$dbUserBackend = new DbUserBackend(ResourceFactory::createResource($form->getResourceConfig()));
|
||||
if ($dbUserBackend->count() < 1) {
|
||||
$element->addError(t('No users found under the specified database backend'));
|
||||
$form->addError(t('No users found under the specified database backend'));
|
||||
return false;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$element->addError(sprintf(t('Using the specified backend failed: %s'), $e->getMessage()));
|
||||
$form->addError(sprintf(t('Using the specified backend failed: %s'), $e->getMessage()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configuration for the chosen resource
|
||||
*
|
||||
* @return Config
|
||||
*/
|
||||
public function getResourceConfig()
|
||||
{
|
||||
return ResourceFactory::getResourceConfig($this->getValue('resource'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,11 @@
|
|||
namespace Icinga\Form\Config\Authentication;
|
||||
|
||||
use Exception;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Web\Request;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Exception\AuthenticationException;
|
||||
use Icinga\Authentication\Backend\LdapUserBackend;
|
||||
|
||||
/**
|
||||
|
@ -54,7 +56,9 @@ class LdapBackendForm extends Form
|
|||
array(
|
||||
'required' => true,
|
||||
'label' => t('Backend Name'),
|
||||
'description' => t('The name of this authentication backend')
|
||||
'description' => t(
|
||||
'The name of this authentication provider that is used to differentiate it from others'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
|
@ -97,7 +101,16 @@ class LdapBackendForm extends Form
|
|||
'value' => 'ldap'
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'base_dn',
|
||||
array(
|
||||
'required' => false,
|
||||
'label' => t('Base DN'),
|
||||
'description' => t('The path where users can be found on the ldap server. ' .
|
||||
' Leave empty to select all users available on the specified resource.')
|
||||
)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -108,7 +121,7 @@ class LdapBackendForm extends Form
|
|||
*/
|
||||
public function onSuccess(Request $request)
|
||||
{
|
||||
if (false === $this->isValidAuthenticationBackend($this)) {
|
||||
if (false === static::isValidAuthenticationBackend($this)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -120,22 +133,34 @@ class LdapBackendForm extends Form
|
|||
*
|
||||
* @return bool Whether validation succeeded or not
|
||||
*/
|
||||
public function isValidAuthenticationBackend(Form $form)
|
||||
public static function isValidAuthenticationBackend(Form $form)
|
||||
{
|
||||
$element = $form->getElement('resource');
|
||||
|
||||
try {
|
||||
$ldapUserBackend = new LdapUserBackend(
|
||||
ResourceFactory::create($element->getValue()),
|
||||
ResourceFactory::createResource($form->getResourceConfig()),
|
||||
$form->getElement('user_class')->getValue(),
|
||||
$form->getElement('user_name_attribute')->getValue()
|
||||
$form->getElement('user_name_attribute')->getValue(),
|
||||
$form->getElement('base_dn')->getValue()
|
||||
);
|
||||
$ldapUserBackend->assertAuthenticationPossible();
|
||||
} catch (AuthenticationException $e) {
|
||||
$form->addError($e->getMessage());
|
||||
return false;
|
||||
} catch (Exception $e) {
|
||||
$element->addError(sprintf(t('Connection validation failed: %s'), $e->getMessage()));
|
||||
$form->addError(sprintf(t('Unable to validate authentication: %s'), $e->getMessage()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configuration for the chosen resource
|
||||
*
|
||||
* @return Config
|
||||
*/
|
||||
public function getResourceConfig()
|
||||
{
|
||||
return ResourceFactory::getResourceConfig($this->getValue('resource'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ use Icinga\Form\ConfigForm;
|
|||
use Icinga\Web\Notification;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Platform;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Form\Config\Authentication\DbBackendForm;
|
||||
use Icinga\Form\Config\Authentication\LdapBackendForm;
|
||||
|
@ -39,8 +40,6 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
|||
* @param Config $resources The resource configuration
|
||||
*
|
||||
* @return self
|
||||
*
|
||||
* @throws ConfigurationError In case no resources are available for authentication
|
||||
*/
|
||||
public function setResourceConfig(Config $resourceConfig)
|
||||
{
|
||||
|
@ -49,10 +48,6 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
|||
$resources[strtolower($resource->type)][] = $name;
|
||||
}
|
||||
|
||||
if (empty($resources)) {
|
||||
throw new ConfigurationError(t('Could not find any resources for authentication'));
|
||||
}
|
||||
|
||||
$this->resources = $resources;
|
||||
return $this;
|
||||
}
|
||||
|
@ -201,7 +196,7 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
|||
{
|
||||
if (($el = $this->getElement('force_creation')) === null || false === $el->isChecked()) {
|
||||
$backendForm = $this->getBackendForm($this->getElement('type')->getValue());
|
||||
if (false === $backendForm->isValidAuthenticationBackend($this)) {
|
||||
if (false === $backendForm::isValidAuthenticationBackend($this)) {
|
||||
$this->addElement($this->getForceCreationCheckbox());
|
||||
return false;
|
||||
}
|
||||
|
@ -251,6 +246,17 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
|||
$configValues['type'] = $configValues['backend'];
|
||||
$configValues['name'] = $authBackend;
|
||||
$this->populate($configValues);
|
||||
} elseif (empty($this->resources)) {
|
||||
$autologinBackends = array_filter(
|
||||
$this->config->toArray(),
|
||||
function ($authBackendCfg) {
|
||||
return isset($authBackendCfg['backend']) && $authBackendCfg['backend'] === 'autologin';
|
||||
}
|
||||
);
|
||||
|
||||
if (false === empty($autologinBackends)) {
|
||||
throw new ConfigurationError(t('Could not find any resources for authentication'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -280,7 +286,7 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
|||
public function createElements(array $formData)
|
||||
{
|
||||
$backendTypes = array();
|
||||
$backendType = isset($formData['type']) ? $formData['type'] : 'db';
|
||||
$backendType = isset($formData['type']) ? $formData['type'] : null;
|
||||
|
||||
if (isset($this->resources['db'])) {
|
||||
$backendTypes['db'] = t('Database');
|
||||
|
@ -299,6 +305,10 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
|||
$backendTypes['autologin'] = t('Autologin');
|
||||
}
|
||||
|
||||
if ($backendType === null) {
|
||||
$backendType = key($backendTypes);
|
||||
}
|
||||
|
||||
$this->addElement(
|
||||
'select',
|
||||
'type',
|
||||
|
@ -307,7 +317,7 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
|||
'required' => true,
|
||||
'autosubmit' => true,
|
||||
'label' => t('Backend Type'),
|
||||
'description' => t('The type of the resource to use for this authenticaton backend'),
|
||||
'description' => t('The type of the resource to use for this authenticaton provider'),
|
||||
'multiOptions' => $backendTypes
|
||||
)
|
||||
);
|
||||
|
@ -319,4 +329,14 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
|||
|
||||
$this->addElements($this->getBackendForm($backendType)->createElements($formData)->getElements());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configuration for the chosen resource
|
||||
*
|
||||
* @return Config
|
||||
*/
|
||||
public function getResourceConfig()
|
||||
{
|
||||
return ResourceFactory::getResourceConfig($this->getValue('resource'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,11 @@
|
|||
namespace Icinga\Form\Config\General;
|
||||
|
||||
use DateTimeZone;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Util\Translator;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Util\Translator;
|
||||
use Icinga\Web\Form;
|
||||
|
||||
|
||||
/**
|
||||
* Form class to modify the general application configuration
|
||||
|
@ -71,12 +73,12 @@ class ApplicationConfigForm extends Form
|
|||
array(
|
||||
'label' => t('Module Path'),
|
||||
'required' => true,
|
||||
'value' => implode(':', Icinga::app()->getModuleManager()->getModuleDirs()),
|
||||
'description' => t(
|
||||
'Contains the directories that will be searched for available modules, separated by '
|
||||
. 'colons. Modules that don\'t exist in these directories can still be symlinked in '
|
||||
. 'the module folder, but won\'t show up in the list of disabled modules.'
|
||||
),
|
||||
'value' => realpath(ICINGAWEB_APPDIR . '/../modules')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
namespace Icinga\Form\Config\General;
|
||||
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Web\Form\Validator\WritablePathValidator;
|
||||
|
||||
|
@ -30,13 +30,13 @@ class LoggingConfigForm extends Form
|
|||
'logging_log',
|
||||
array(
|
||||
'required' => true,
|
||||
'class' => 'autosubmit',
|
||||
'autosubmit' => true,
|
||||
'label' => t('Logging Type'),
|
||||
'description' => t('The type of logging to utilize.'),
|
||||
'multiOptions' => array(
|
||||
'syslog' => 'Syslog',
|
||||
'file' => t('File'),
|
||||
'none' => t('None')
|
||||
'file' => t('File', 'app.config.logging.type'),
|
||||
'none' => t('None', 'app.config.logging.type')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
@ -50,16 +50,16 @@ class LoggingConfigForm extends Form
|
|||
'label' => t('Logging Level'),
|
||||
'description' => t('The maximum logging level to emit.'),
|
||||
'multiOptions' => array(
|
||||
Logger::$levels[Logger::ERROR] => t('Error'),
|
||||
Logger::$levels[Logger::WARNING] => t('Warning'),
|
||||
Logger::$levels[Logger::INFO] => t('Information'),
|
||||
Logger::$levels[Logger::DEBUG] => t('Debug')
|
||||
Logger::$levels[Logger::ERROR] => t('Error', 'app.config.logging.level'),
|
||||
Logger::$levels[Logger::WARNING] => t('Warning', 'app.config.logging.level'),
|
||||
Logger::$levels[Logger::INFO] => t('Information', 'app.config.logging.level'),
|
||||
Logger::$levels[Logger::DEBUG] => t('Debug', 'app.config.logging.level')
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($formData['logging_log']) && $formData['logging_log'] === 'syslog') {
|
||||
if (false === isset($formData['logging_log']) || $formData['logging_log'] === 'syslog') {
|
||||
$this->addElement(
|
||||
'text',
|
||||
'logging_application',
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
namespace Icinga\Form\Config\Resource;
|
||||
|
||||
use Exception;
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Web\Request;
|
||||
use Icinga\Web\Form\Element\Number;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Application\Platform;
|
||||
|
||||
/**
|
||||
* Form class for adding/modifying database resources
|
||||
|
@ -29,6 +30,23 @@ class DbResourceForm extends Form
|
|||
*/
|
||||
public function createElements(array $formData)
|
||||
{
|
||||
$dbChoices = array();
|
||||
if (Platform::zendClassExists('Zend_Db_Adapter_Pdo_Mysql')) {
|
||||
$dbChoices['mysql'] = 'MySQL';
|
||||
}
|
||||
if (Platform::zendClassExists('Zend_Db_Adapter_Pdo_Pgsql')) {
|
||||
$dbChoices['pgsql'] = 'PostgreSQL';
|
||||
}
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'name',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Resource Name'),
|
||||
'description' => t('The unique name of this resource')
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
'select',
|
||||
'db',
|
||||
|
@ -36,11 +54,7 @@ class DbResourceForm extends Form
|
|||
'required' => true,
|
||||
'label' => t('Database Type'),
|
||||
'description' => t('The type of SQL database'),
|
||||
'multiOptions' => array(
|
||||
'mysql' => 'MySQL',
|
||||
'pgsql' => 'PostgreSQL'
|
||||
//'oracle' => 'Oracle'
|
||||
)
|
||||
'multiOptions' => $dbChoices
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
|
@ -103,7 +117,7 @@ class DbResourceForm extends Form
|
|||
*/
|
||||
public function onSuccess(Request $request)
|
||||
{
|
||||
if (false === $this->isValidResource($this)) {
|
||||
if (false === static::isValidResource($this)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -115,10 +129,10 @@ class DbResourceForm extends Form
|
|||
*
|
||||
* @return bool Whether validation succeeded or not
|
||||
*/
|
||||
public function isValidResource(Form $form)
|
||||
public static function isValidResource(Form $form)
|
||||
{
|
||||
try {
|
||||
$resource = ResourceFactory::createResource(new Zend_Config($form->getValues()));
|
||||
$resource = ResourceFactory::createResource(new Config($form->getValues()));
|
||||
$resource->getConnection()->getConnection();
|
||||
} catch (Exception $e) {
|
||||
$form->addError(t('Connectivity validation failed, connection to the given resource not possible.'));
|
||||
|
|
|
@ -25,6 +25,15 @@ class FileResourceForm extends Form
|
|||
*/
|
||||
public function createElements(array $formData)
|
||||
{
|
||||
$this->addElement(
|
||||
'text',
|
||||
'name',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Resource Name'),
|
||||
'description' => t('The unique name of this resource')
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'filename',
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
namespace Icinga\Form\Config\Resource;
|
||||
|
||||
use Exception;
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Web\Request;
|
||||
use Icinga\Web\Form\Element\Number;
|
||||
|
@ -29,6 +29,15 @@ class LdapResourceForm extends Form
|
|||
*/
|
||||
public function createElements(array $formData)
|
||||
{
|
||||
$this->addElement(
|
||||
'text',
|
||||
'name',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Resource Name'),
|
||||
'description' => t('The unique name of this resource')
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'hostname',
|
||||
|
@ -56,7 +65,7 @@ class LdapResourceForm extends Form
|
|||
array(
|
||||
'required' => true,
|
||||
'label' => t('Root DN'),
|
||||
'description' => t('The path where users can be found on the ldap server')
|
||||
'description' => t('Only the root and its child nodes will be accessible on this resource.')
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
|
@ -89,7 +98,7 @@ class LdapResourceForm extends Form
|
|||
*/
|
||||
public function onSuccess(Request $request)
|
||||
{
|
||||
if (false === $this->isValidResource($this)) {
|
||||
if (false === static::isValidResource($this)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -101,11 +110,17 @@ class LdapResourceForm extends Form
|
|||
*
|
||||
* @return bool Whether validation succeeded or not
|
||||
*/
|
||||
public function isValidResource(Form $form)
|
||||
public static function isValidResource(Form $form)
|
||||
{
|
||||
try {
|
||||
$resource = ResourceFactory::createResource(new Zend_Config($form->getValues()));
|
||||
$resource->connect();
|
||||
$resource = ResourceFactory::createResource(new Config($form->getValues()));
|
||||
if (false === $resource->testCredentials(
|
||||
$form->getElement('bind_dn')->getValue(),
|
||||
$form->getElement('bind_pw')->getValue()
|
||||
)
|
||||
) {
|
||||
throw new Exception();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$form->addError(t('Connectivity validation failed, connection to the given resource not possible.'));
|
||||
return false;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
namespace Icinga\Form\Config\Resource;
|
||||
|
||||
use Exception;
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Web\Request;
|
||||
use Icinga\Application\Icinga;
|
||||
|
@ -29,6 +29,15 @@ class LivestatusResourceForm extends Form
|
|||
*/
|
||||
public function createElements(array $formData)
|
||||
{
|
||||
$this->addElement(
|
||||
'text',
|
||||
'name',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Resource Name'),
|
||||
'description' => t('The unique name of this resource')
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'socket',
|
||||
|
@ -50,7 +59,7 @@ class LivestatusResourceForm extends Form
|
|||
*/
|
||||
public function onSuccess(Request $request)
|
||||
{
|
||||
if (false === $this->isValidResource($this)) {
|
||||
if (false === static::isValidResource($this)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -62,10 +71,10 @@ class LivestatusResourceForm extends Form
|
|||
*
|
||||
* @return bool Whether validation succeeded or not
|
||||
*/
|
||||
public function isValidResource(Form $form)
|
||||
public static function isValidResource(Form $form)
|
||||
{
|
||||
try {
|
||||
$resource = ResourceFactory::createResource(new Zend_Config($form->getValues()));
|
||||
$resource = ResourceFactory::createResource(new Config($form->getValues()));
|
||||
$resource->connect()->disconnect();
|
||||
} catch (Exception $e) {
|
||||
$form->addError(t('Connectivity validation failed, connection to the given resource not possible.'));
|
||||
|
|
|
@ -132,7 +132,7 @@ class ResourceConfigForm extends ConfigForm
|
|||
{
|
||||
if (($el = $this->getElement('force_creation')) === null || false === $el->isChecked()) {
|
||||
$resourceForm = $this->getResourceForm($this->getElement('type')->getValue());
|
||||
if (method_exists($resourceForm, 'isValidResource') && false === $resourceForm->isValidResource($this)) {
|
||||
if (method_exists($resourceForm, 'isValidResource') && false === $resourceForm::isValidResource($this)) {
|
||||
$this->addElement($this->getForceCreationCheckbox());
|
||||
return false;
|
||||
}
|
||||
|
@ -220,15 +220,6 @@ class ResourceConfigForm extends ConfigForm
|
|||
$resourceTypes['db'] = t('SQL Database');
|
||||
}
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'name',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Resource Name'),
|
||||
'description' => t('The unique name of this resource')
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
'select',
|
||||
'type',
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace Icinga\Form;
|
|||
use Exception;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Config\PreservingIniWriter;
|
||||
use Icinga\File\Ini\IniWriter;
|
||||
|
||||
/**
|
||||
* Form base-class providing standard functionality for configuration forms
|
||||
|
@ -43,7 +43,7 @@ class ConfigForm extends Form
|
|||
*/
|
||||
public function save()
|
||||
{
|
||||
$writer = new PreservingIniWriter(
|
||||
$writer = new IniWriter(
|
||||
array(
|
||||
'config' => $this->config,
|
||||
'filename' => $this->config->getConfigFile()
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Icinga\Form\Dashboard;
|
||||
|
||||
use Icinga\Application\Config as IcingaConfig;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Web\Widget\Dashboard;
|
||||
use Icinga\Web\Form;
|
||||
|
||||
|
@ -110,7 +110,7 @@ class AddUrlForm extends Form
|
|||
protected function getDashboardPaneSelectionValues()
|
||||
{
|
||||
$dashboard = new Dashboard();
|
||||
$dashboard->readConfig(IcingaConfig::app('dashboard/dashboard'));
|
||||
$dashboard->readConfig(Config::app('dashboard/dashboard'));
|
||||
return $dashboard->getPaneKeyTitleArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,213 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Form;
|
||||
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Protocol\Ldap\Exception as LdapException;
|
||||
use Icinga\Protocol\Ldap\Connection;
|
||||
use Icinga\Protocol\Dns;
|
||||
use Icinga\Web\Form\Element\Note;
|
||||
use Icinga\Web\Form;
|
||||
|
||||
/**
|
||||
* Form class for application-wide and logging specific settings
|
||||
*/
|
||||
class LdapDiscoveryForm extends Form
|
||||
{
|
||||
/**
|
||||
* The discovered server settings
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $capabilities = null;
|
||||
|
||||
/**
|
||||
* The discovered root_dn
|
||||
*
|
||||
* @var null
|
||||
*/
|
||||
private $namingContext = null;
|
||||
|
||||
/**
|
||||
* The working domain name
|
||||
*
|
||||
* @var null
|
||||
*/
|
||||
private $domain = null;
|
||||
|
||||
/**
|
||||
* The working port name
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $port = 389;
|
||||
|
||||
/**
|
||||
* Initialize this page
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->setName('form_ldap_discovery');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Form::createElements()
|
||||
*/
|
||||
public function createElements(array $formData)
|
||||
{
|
||||
$this->addElement(
|
||||
'text',
|
||||
'domain',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Search Domain'),
|
||||
'description' => t('Search this domain for records of available servers.'),
|
||||
)
|
||||
);
|
||||
|
||||
if (false) {
|
||||
$this->addElement(
|
||||
new Note(
|
||||
'additional_description',
|
||||
array(
|
||||
'value' => t('No Ldap servers found on this domain.'
|
||||
. ' You can try to specify host and port and try again, or just skip this step and '
|
||||
. 'configure the server manually.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'hostname',
|
||||
array(
|
||||
'required' => false,
|
||||
'label' => t('Host'),
|
||||
'description' => t('IP or host name to search.'),
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'port',
|
||||
array(
|
||||
'required' => false,
|
||||
'label' => t('Port'),
|
||||
'description' => t('Port', 389),
|
||||
)
|
||||
);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isValid($data)
|
||||
{
|
||||
if (false === parent::isValid($data)) {
|
||||
return false;
|
||||
}
|
||||
if ($this->discover($this->getValue('domain'))) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private function discover($domain)
|
||||
{
|
||||
// Attempt 1: Connect to the domain directly
|
||||
if ($this->discoverCapabilities(array(
|
||||
'hostname' => $domain,
|
||||
'port' => 389)
|
||||
)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Attempt 2: Discover all available ldap dns records and connect to the first one
|
||||
$cap = false;
|
||||
$records = array_merge(Dns::getSrvRecords($domain, 'ldap'), Dns::getSrvRecords($domain, 'ldaps'));
|
||||
if (isset($records[0])) {
|
||||
$record = $records[0];
|
||||
if (isset($record['port'])) {
|
||||
$cap = $this->discoverCapabilities(array(
|
||||
'hostname' => $record['target'],
|
||||
'port' => $record['port']
|
||||
));
|
||||
} else {
|
||||
$cap = $this->discoverCapabilities(array(
|
||||
'hostname' => $record['target'],
|
||||
'port' => 389
|
||||
));
|
||||
}
|
||||
}
|
||||
return $cap;
|
||||
}
|
||||
|
||||
private function discoverCapabilities($config)
|
||||
{
|
||||
$conn = new Connection(new Config($config));
|
||||
try {
|
||||
$conn->connect();
|
||||
$this->capabilities = $conn->getCapabilities();
|
||||
$this->namingContext = $conn->getDefaultNamingContext();
|
||||
$this->port = $config['port'];
|
||||
$this->domain = $config['hostname'];
|
||||
return true;
|
||||
} catch (LdapException $e) {
|
||||
Logger::info(
|
||||
'Ldap discovery for ' . $config['hostname'] . ':' . $config['port'] . ' failed: ' . $e->getMessage()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function suggestResourceSettings()
|
||||
{
|
||||
if (! isset($this->capabilities)) {
|
||||
return array();
|
||||
}
|
||||
if ($this->capabilities->msCapabilities->ActiveDirectoryOid) {
|
||||
return array(
|
||||
'hostname' => $this->domain,
|
||||
'port' => $this->port,
|
||||
'root_dn' => $this->namingContext
|
||||
);
|
||||
} else {
|
||||
return array(
|
||||
'hostname' => $this->domain,
|
||||
'port' => $this->port,
|
||||
'root_dn' => $this->namingContext
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function hasSuggestion()
|
||||
{
|
||||
return isset($this->capabilities);
|
||||
}
|
||||
|
||||
public function suggestBackendSettings()
|
||||
{
|
||||
if (! isset($this->capabilities)) {
|
||||
return array();
|
||||
}
|
||||
if ($this->capabilities->msCapabilities->ActiveDirectoryOid) {
|
||||
return array(
|
||||
'base_dn' => $this->namingContext,
|
||||
'user_class' => 'user',
|
||||
'user_name_attribute' => 'sAMAccountName'
|
||||
);
|
||||
} else {
|
||||
return array(
|
||||
'base_dn' => $this->namingContext,
|
||||
'user_class' => 'inetOrgPerson',
|
||||
'user_name_attribute' => 'uid'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function isAd()
|
||||
{
|
||||
return $this->capabilities->msCapabilities->ActiveDirectoryOid;
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ namespace Icinga\Form;
|
|||
|
||||
use Exception;
|
||||
use DateTimeZone;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\User\Preferences;
|
||||
use Icinga\User\Preferences\PreferencesStore;
|
||||
use Icinga\Util\TimezoneDetect;
|
||||
|
@ -100,10 +100,7 @@ class PreferenceForm extends Form
|
|||
}
|
||||
$this->preferences->icingaweb = $webPreferences;
|
||||
|
||||
// TODO: Is this even necessary in case the session is written on response?
|
||||
$session = Session::getSession();
|
||||
$session->user->setPreferences($this->preferences);
|
||||
$session->write();
|
||||
Session::getSession()->user->setPreferences($this->preferences);
|
||||
|
||||
try {
|
||||
$this->save();
|
||||
|
|
|
@ -15,5 +15,17 @@
|
|||
<?php endif ?>
|
||||
<?= $this->form ?>
|
||||
<div class="footer">Icinga Web 2 © 2013-2014 Icinga Team</div>
|
||||
<?php if ($configMissing): ?>
|
||||
<div class="config-note"><?= sprintf(
|
||||
t(
|
||||
'You seem not to have Icinga Web 2 configured yet so it\'s not possible to log in without any defined '
|
||||
. 'authentication method. Please define a authentication method by following the instructions in the'
|
||||
. ' %1$sdocumentation%3$s or by using our %2$sweb-based setup-wizard%3$s.'
|
||||
),
|
||||
'<a href="http://docs.icinga.org/" title="Icinga Web 2 Documentation">', // TODO: Documentation link
|
||||
'<a href="' . $this->href('setup') . '" title="Icinga Web 2 Setup-Wizard">',
|
||||
'</a>'
|
||||
); ?></div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
|
||||
use Icinga\Web\Url;
|
||||
|
||||
if ($xAxisPaginator->count() <= 1 && $yAxisPaginator->count() <= 1) {
|
||||
return; // Display this pagination only if there are multiple pages
|
||||
}
|
||||
|
||||
$fromTo = t('%s: %d to %d of %d');
|
||||
$xAxisPages = $xAxisPaginator->getPages('all');
|
||||
$yAxisPages = $yAxisPaginator->getPages('all');
|
||||
|
||||
$totalYAxisPages = $yAxisPaginator->count();
|
||||
$currentYAxisPage = $yAxisPaginator->getCurrentPageNumber();
|
||||
$prevYAxisPage = $currentYAxisPage > 1 ? $currentYAxisPage - 1 : null;
|
||||
$nextYAxisPage = $currentYAxisPage < $totalYAxisPages ? $currentYAxisPage + 1 : null;
|
||||
|
||||
$totalXAxisPages = $xAxisPaginator->count();
|
||||
$currentXAxisPage = $xAxisPaginator->getCurrentPageNumber();
|
||||
$prevXAxisPage = $currentXAxisPage > 1 ? $currentXAxisPage - 1 : null;
|
||||
$nextXAxisPage = $currentXAxisPage < $totalXAxisPages ? $currentXAxisPage + 1 : null;
|
||||
|
||||
?>
|
||||
|
||||
<table class="joystick-pagination">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>
|
||||
<?php if ($prevYAxisPage): ?>
|
||||
<a target="_self" href="<?= Url::fromRequest()->overwriteParams(array(
|
||||
'page' => $currentXAxisPage . ',' . $prevYAxisPage
|
||||
))->getAbsoluteUrl(); ?>" title="<?= sprintf(
|
||||
$fromTo,
|
||||
t('Hosts'),
|
||||
($prevYAxisPage - 1) * $yAxisPages->itemCountPerPage + 1,
|
||||
$prevYAxisPage * $yAxisPages->itemCountPerPage,
|
||||
$yAxisPages->totalItemCount
|
||||
); ?>"><?= $this->icon('up_petrol.png'); ?></a>
|
||||
<?php else: ?>
|
||||
<?= $this->icon('up.png'); ?>
|
||||
<?php endif ?>
|
||||
</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<?php if ($prevXAxisPage): ?>
|
||||
<a target="_self" href="<?= Url::fromRequest()->overwriteParams(array(
|
||||
'page' => $prevXAxisPage . ',' . $currentYAxisPage
|
||||
))->getAbsoluteUrl(); ?>" title="<?= sprintf(
|
||||
$fromTo,
|
||||
t('Services'),
|
||||
($prevXAxisPage - 1) * $xAxisPages->itemCountPerPage + 1,
|
||||
$prevXAxisPage * $xAxisPages->itemCountPerPage,
|
||||
$xAxisPages->totalItemCount
|
||||
); ?>"><?= $this->icon('prev_petrol.png'); ?></a>
|
||||
<?php else: ?>
|
||||
<?= $this->icon('prev.png'); ?>
|
||||
<?php endif ?>
|
||||
</td>
|
||||
<td> </td>
|
||||
<td>
|
||||
<?php if ($nextXAxisPage): ?>
|
||||
<a target="_self" href="<?= Url::fromRequest()->overwriteParams(array(
|
||||
'page' => $nextXAxisPage . ',' . $currentYAxisPage
|
||||
))->getAbsoluteUrl(); ?>" title="<?= sprintf(
|
||||
$fromTo,
|
||||
t('Services'),
|
||||
$currentXAxisPage * $xAxisPages->itemCountPerPage + 1,
|
||||
$nextXAxisPage * $xAxisPages->itemCountPerPage,
|
||||
$xAxisPages->totalItemCount
|
||||
); ?>"><?= $this->icon('next_petrol.png'); ?></a>
|
||||
<?php else: ?>
|
||||
<?= $this->icon('next.png'); ?>
|
||||
<?php endif ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>
|
||||
<?php if ($nextYAxisPage): ?>
|
||||
<a target="_self" href="<?= Url::fromRequest()->overwriteParams(array(
|
||||
'page' => $currentXAxisPage . ',' . $nextYAxisPage
|
||||
))->getAbsoluteUrl(); ?>" title="<?= sprintf(
|
||||
$fromTo,
|
||||
t('Hosts'),
|
||||
$currentYAxisPage * $yAxisPages->itemCountPerPage + 1,
|
||||
$nextYAxisPage * $yAxisPages->itemCountPerPage,
|
||||
$yAxisPages->totalItemCount
|
||||
); ?>"><?= $this->icon('down_petrol.png'); ?></a>
|
||||
<?php else: ?>
|
||||
<?= $this->icon('down.png'); ?>
|
||||
<?php endif ?>
|
||||
</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
|
@ -1,6 +1,9 @@
|
|||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
use Icinga\Application\Cli;
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
require_once dirname(__DIR__) . '/library/Icinga/Application/Cli.php';
|
||||
Cli::start()->dispatch();
|
||||
|
||||
Icinga\Application\Cli::start()->dispatch();
|
||||
|
|
|
@ -74,8 +74,7 @@ create all database tables. You will find the installation guides for the differ
|
|||
>
|
||||
> RPM packages install the schema into /usr/share/doc/icingaweb-<version>/schema
|
||||
|
||||
bash$ mysql -u root -p icingaweb < etc/schema/accounts.mysql.sql
|
||||
bash$ mysql -u root -p icingaweb < etc/schema/preferences.mysql.sql
|
||||
bash$ mysql -u root -p icingaweb < etc/schema/mysql.sql
|
||||
|
||||
|
||||
#### PostgreSQL
|
||||
|
@ -108,8 +107,7 @@ And restart your database ('service postgresql restart' or '/etc/init.d/postgres
|
|||
>
|
||||
> RPM packages install the schema into /usr/share/doc/icingaweb-<version>/schema
|
||||
|
||||
bash$ psql -U icingaweb -a -f etc/schema/accounts.pgsql.sql
|
||||
bash$ psql -U icingaweb -a -f etc/schema/preferences.pgsql.sql
|
||||
bash$ psql -U icingaweb -a -f etc/schema/pgsql.sql
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
create table account (
|
||||
`username` varchar(255) COLLATE latin1_general_ci NOT NULL,
|
||||
`salt` varchar(255) NOT NULL,
|
||||
`password` varchar(255) NOT NULL,
|
||||
`active` tinyint(1) DEFAULT NULL,
|
||||
PRIMARY KEY (`username`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
|
||||
/*
|
||||
* user: icingaadmin
|
||||
* password: icinga
|
||||
*/
|
||||
INSERT INTO account (
|
||||
`username`,
|
||||
`salt`,
|
||||
`password`,
|
||||
`active`
|
||||
)
|
||||
VALUES (
|
||||
'icingaadmin',
|
||||
'57cfd5746224be4f60c25d4e8514bec35ad2d01810723a138756b285898e71b2',
|
||||
'43f8e0588eb39f1a41383b48def0b1fdc45e79b8f67194cccee4453eb3f4ea13',
|
||||
1
|
||||
);
|
|
@ -1,28 +0,0 @@
|
|||
create table "account" (
|
||||
"username" character varying(255) NOT NULL,
|
||||
"salt" character varying(255),
|
||||
"password" character varying(255) NOT NULL,
|
||||
"active" boolean
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY "account"
|
||||
ADD CONSTRAINT account_pkey PRIMARY KEY ("username");
|
||||
|
||||
CREATE UNIQUE INDEX username_lower_unique_idx ON "account" USING btree (lower((username)::text));
|
||||
|
||||
/*
|
||||
* user: icingaadmin
|
||||
* password: icinga
|
||||
*/
|
||||
INSERT INTO "account" (
|
||||
"username",
|
||||
"salt",
|
||||
"password",
|
||||
"active"
|
||||
)
|
||||
VALUES (
|
||||
'icingaadmin',
|
||||
'57cfd5746224be4f60c25d4e8514bec35ad2d01810723a138756b285898e71b2',
|
||||
'43f8e0588eb39f1a41383b48def0b1fdc45e79b8f67194cccee4453eb3f4ea13',
|
||||
true
|
||||
);
|
|
@ -0,0 +1,96 @@
|
|||
/**
|
||||
* Table "icingaweb_group"
|
||||
*/
|
||||
CREATE TABLE "icingaweb_group" (
|
||||
"name" character varying(64) NOT NULL,
|
||||
"parent" character varying(64) NULL DEFAULT NULL,
|
||||
"ctime" timestamp NULL DEFAULT NULL,
|
||||
"mtime" timestamp NULL DEFAULT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY "icingaweb_group"
|
||||
ADD CONSTRAINT pk_icingaweb_group
|
||||
PRIMARY KEY (
|
||||
"name"
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX idx_icingaweb_group
|
||||
ON "icingaweb_group"
|
||||
USING btree (
|
||||
lower((name)::text)
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Table "icingaweb_group_membership"
|
||||
*/
|
||||
CREATE TABLE "icingaweb_group_membership" (
|
||||
"group_name" character varying(64) NOT NULL,
|
||||
"username" character varying(64) NOT NULL,
|
||||
"ctime" timestamp NULL DEFAULT NULL,
|
||||
"mtime" timestamp NULL DEFAULT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY "icingaweb_group_membership"
|
||||
ADD CONSTRAINT pk_icingaweb_group_membership
|
||||
PRIMARY KEY (
|
||||
"group_name",
|
||||
"username"
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX idx_icingaweb_group_membership
|
||||
ON "icingaweb_group_membership"
|
||||
USING btree (
|
||||
lower((group_name)::text),
|
||||
lower((username)::text)
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Table "icingaweb_user"
|
||||
*/
|
||||
CREATE TABLE "icingaweb_user" (
|
||||
"name" character varying(64) NOT NULL,
|
||||
"active" smallint NOT NULL,
|
||||
"password_hash" bytea NOT NULL,
|
||||
"ctime" timestamp NULL DEFAULT NULL,
|
||||
"mtime" timestamp NULL DEFAULT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY "icingaweb_user"
|
||||
ADD CONSTRAINT pk_icingaweb_user
|
||||
PRIMARY KEY (
|
||||
"name"
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX idx_icingaweb_user
|
||||
ON "icingaweb_user"
|
||||
USING btree (
|
||||
lower((name)::text)
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Table "icingaweb_user_preference"
|
||||
*/
|
||||
CREATE TABLE "icingaweb_user_preference" (
|
||||
"username" character varying(64) NOT NULL,
|
||||
"name" character varying(64) NOT NULL,
|
||||
"value" character varying(255) NOT NULL,
|
||||
"ctime" timestamp NULL DEFAULT NULL,
|
||||
"mtime" timestamp NULL DEFAULT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY "icingaweb_user_preference"
|
||||
ADD CONSTRAINT pk_icingaweb_user_preference
|
||||
PRIMARY KEY (
|
||||
"username",
|
||||
"name"
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX idx_icingaweb_user_preference
|
||||
ON "icingaweb_user_preference"
|
||||
USING btree (
|
||||
lower((username)::text),
|
||||
lower((name)::text)
|
||||
);
|
|
@ -1,6 +0,0 @@
|
|||
create table `preference`(
|
||||
`username` VARCHAR(255) COLLATE latin1_general_ci NOT NULL,
|
||||
`key` VARCHAR(100) COLLATE latin1_general_ci NOT NULL,
|
||||
`value` VARCHAR(255) NOT NULL,
|
||||
PRIMARY KEY (`username`, `key`)
|
||||
) ENGINE=InnoDB;
|
|
@ -1,10 +0,0 @@
|
|||
create table "preference"(
|
||||
"username" VARCHAR(255) NOT NULL,
|
||||
"key" VARCHAR(100) NOT NULL,
|
||||
"value" VARCHAR(255) NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY "preference"
|
||||
ADD CONSTRAINT preference_pkey PRIMARY KEY ("username", "key");
|
||||
|
||||
CREATE UNIQUE INDEX username_and_key_lower_unique_idx ON "preference" USING btree (lower((username)::text), lower((key)::text));
|
|
@ -6,14 +6,14 @@ namespace Icinga\Application;
|
|||
|
||||
use ErrorException;
|
||||
use Exception;
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Modules\Manager as ModuleManager;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
use Icinga\Util\Translator;
|
||||
use Icinga\File\Ini\IniWriter;
|
||||
use Icinga\Exception\IcingaException;
|
||||
|
||||
/**
|
||||
|
@ -40,6 +40,43 @@ use Icinga\Exception\IcingaException;
|
|||
*/
|
||||
abstract class ApplicationBootstrap
|
||||
{
|
||||
/**
|
||||
* Base directory
|
||||
*
|
||||
* Parent folder for at least application, bin, modules, library/vendor and public
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $baseDir;
|
||||
|
||||
/**
|
||||
* Application directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $appDir;
|
||||
|
||||
/**
|
||||
* Vendor library directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $vendorDir;
|
||||
|
||||
/**
|
||||
* Library directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $libDir;
|
||||
|
||||
/**
|
||||
* Configuration directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $configDir;
|
||||
|
||||
/**
|
||||
* Icinga auto loader
|
||||
*
|
||||
|
@ -47,34 +84,13 @@ abstract class ApplicationBootstrap
|
|||
*/
|
||||
private $loader;
|
||||
|
||||
/**
|
||||
* Library directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $libDir;
|
||||
|
||||
/**
|
||||
* Config object
|
||||
*
|
||||
* @var Zend_Config
|
||||
* @var Config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Configuration directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $configDir;
|
||||
|
||||
/**
|
||||
* Application directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $appDir;
|
||||
|
||||
/**
|
||||
* Module manager
|
||||
*
|
||||
|
@ -98,27 +114,20 @@ abstract class ApplicationBootstrap
|
|||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $baseDir Icinga Web 2 base directory
|
||||
* @param string $configDir Path to Icinga Web 2's configuration files
|
||||
*/
|
||||
protected function __construct($configDir = null)
|
||||
protected function __construct($baseDir = null, $configDir = null)
|
||||
{
|
||||
if ($baseDir === null) {
|
||||
$baseDir = dirname($this->getBootstrapDirectory());
|
||||
}
|
||||
$this->baseDir = $baseDir;
|
||||
$this->appDir = $baseDir . '/application';
|
||||
$this->vendorDir = $baseDir . '/library/vendor';
|
||||
$this->libDir = realpath(__DIR__ . '/../..');
|
||||
|
||||
if (!defined('ICINGA_LIBDIR')) {
|
||||
define('ICINGA_LIBDIR', $this->libDir);
|
||||
}
|
||||
|
||||
if (defined('ICINGAWEB_APPDIR')) {
|
||||
$this->appDir = ICINGAWEB_APPDIR;
|
||||
} elseif (array_key_exists('ICINGAWEB_APPDIR', $_SERVER)) {
|
||||
$this->appDir = $_SERVER['ICINGAWEB_APPDIR'];
|
||||
} else {
|
||||
$this->appDir = realpath($this->libDir. '/../application');
|
||||
}
|
||||
|
||||
if (!defined('ICINGAWEB_APPDIR')) {
|
||||
define('ICINGAWEB_APPDIR', $this->appDir);
|
||||
}
|
||||
|
||||
if ($configDir === null) {
|
||||
if (array_key_exists('ICINGAWEB_CONFIGDIR', $_SERVER)) {
|
||||
$configDir = $_SERVER['ICINGAWEB_CONFIGDIR'];
|
||||
|
@ -196,44 +205,6 @@ abstract class ApplicationBootstrap
|
|||
return $this->isWeb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for application dir
|
||||
*
|
||||
* Optional append sub directory
|
||||
*
|
||||
* @param string $subdir optional subdir
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getApplicationDir($subdir = null)
|
||||
{
|
||||
return $this->getDirWithSubDir($this->appDir, $subdir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for config dir
|
||||
*
|
||||
* @param string $subdir
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getConfigDir($subdir = null)
|
||||
{
|
||||
return $this->getDirWithSubDir($this->configDir, $subdir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the bootstrapping directory.
|
||||
*
|
||||
* This is usually /public for Web and EmbeddedWeb
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBootstrapDirecory()
|
||||
{
|
||||
return dirname($_SERVER['SCRIPT_FILENAME']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to glue directories together
|
||||
*
|
||||
|
@ -252,15 +223,76 @@ abstract class ApplicationBootstrap
|
|||
}
|
||||
|
||||
/**
|
||||
* Starting concrete bootstrap classes
|
||||
* Get the base directory
|
||||
*
|
||||
* @param string $configDir
|
||||
* @param string $subDir Optional sub directory to get
|
||||
*
|
||||
* @return ApplicationBootstrap
|
||||
* @return string
|
||||
*/
|
||||
public static function start($configDir = null)
|
||||
public function getBaseDir($subDir = null)
|
||||
{
|
||||
$application = new static($configDir);
|
||||
return $this->getDirWithSubDir($this->baseDir, $subDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the application directory
|
||||
*
|
||||
* @param string $subDir Optional sub directory to get
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getApplicationDir($subDir = null)
|
||||
{
|
||||
return $this->getDirWithSubDir($this->appDir, $subDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the vendor library directory
|
||||
*
|
||||
* @param string $subDir Optional sub directory to get
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVendorDir($subDir = null)
|
||||
{
|
||||
return $this->getDirWithSubDir($this->vendorDir, $subDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configuration directory
|
||||
*
|
||||
* @param string $subDir Optional sub directory to get
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getConfigDir($subDir = null)
|
||||
{
|
||||
return $this->getDirWithSubDir($this->configDir, $subDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the bootstrapping directory
|
||||
*
|
||||
* This is usually /public for Web and EmbeddedWeb and /bin for the CLI
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBootstrapDirectory()
|
||||
{
|
||||
return dirname(realpath($_SERVER['SCRIPT_FILENAME']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the bootstrap
|
||||
*
|
||||
* @param string $baseDir Icinga Web 2 base directory
|
||||
* @param string $configDir Path to Icinga Web 2's configuration files
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function start($baseDir = null, $configDir = null)
|
||||
{
|
||||
$application = new static($baseDir, $configDir);
|
||||
$application->bootstrap();
|
||||
return $application;
|
||||
}
|
||||
|
@ -313,16 +345,26 @@ abstract class ApplicationBootstrap
|
|||
$this->moduleManager = new ModuleManager(
|
||||
$this,
|
||||
$this->configDir . '/enabledModules',
|
||||
explode(
|
||||
':',
|
||||
$this->config->global !== null
|
||||
? $this->config->global->get('modulePath', ICINGAWEB_APPDIR . '/../modules')
|
||||
: ICINGAWEB_APPDIR . '/../modules'
|
||||
)
|
||||
explode(':', $this->config->fromSection('global', 'modulePath', $this->baseDir . '/modules'))
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all core modules
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
protected function loadCoreModules()
|
||||
{
|
||||
try {
|
||||
$this->moduleManager->loadCoreModules();
|
||||
} catch (NotReadableError $e) {
|
||||
Logger::error(new IcingaException('Cannot load core modules. An exception was thrown:', $e));
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all enabled modules
|
||||
*
|
||||
|
@ -346,7 +388,7 @@ abstract class ApplicationBootstrap
|
|||
protected function setupLogging()
|
||||
{
|
||||
Logger::create(
|
||||
new Zend_Config(
|
||||
new Config(
|
||||
array(
|
||||
'log' => 'syslog'
|
||||
)
|
||||
|
@ -363,12 +405,14 @@ abstract class ApplicationBootstrap
|
|||
protected function loadConfig()
|
||||
{
|
||||
Config::$configDir = $this->configDir;
|
||||
|
||||
try {
|
||||
$this->config = Config::app();
|
||||
} catch (NotReadableError $e) {
|
||||
Logger::error(new IcingaException('Cannot load application configuration. An exception was thrown:', $e));
|
||||
$this->config = new Zend_Config(array());
|
||||
$this->config = new Config();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -388,6 +432,7 @@ abstract class ApplicationBootstrap
|
|||
return false; // Continue with the normal error handler
|
||||
}
|
||||
switch($errno) {
|
||||
case E_WARNING:
|
||||
case E_STRICT:
|
||||
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
|
||||
}
|
||||
|
@ -403,9 +448,9 @@ abstract class ApplicationBootstrap
|
|||
*/
|
||||
protected function setupLogger()
|
||||
{
|
||||
if ($this->config->logging !== null) {
|
||||
if (($loggingConfig = $this->config->logging) !== null) {
|
||||
try {
|
||||
Logger::create($this->config->logging);
|
||||
Logger::create($loggingConfig);
|
||||
} catch (ConfigurationError $e) {
|
||||
Logger::error($e);
|
||||
}
|
||||
|
@ -444,7 +489,7 @@ abstract class ApplicationBootstrap
|
|||
if (! $default) {
|
||||
$default = 'UTC';
|
||||
}
|
||||
$timeZoneString = $this->config->global !== null ? $this->config->global->get('timezone', $default) : $default;
|
||||
$timeZoneString = $this->config->fromSection('global', 'timezone', $default);
|
||||
date_default_timezone_set($timeZoneString);
|
||||
DateTimeFactory::setConfig(array('timezone' => $timeZoneString));
|
||||
return $this;
|
||||
|
|
|
@ -4,15 +4,15 @@
|
|||
|
||||
namespace Icinga\Application;
|
||||
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Platform;
|
||||
use Icinga\Application\ApplicationBootstrap;
|
||||
use Icinga\Cli\Params;
|
||||
use Icinga\Cli\Loader;
|
||||
use Icinga\Cli\Screen;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Application\Benchmark;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Zend_Config;
|
||||
|
||||
require_once __DIR__ . '/ApplicationBootstrap.php';
|
||||
|
||||
|
@ -43,17 +43,17 @@ class Cli extends ApplicationBootstrap
|
|||
->parseBasicParams()
|
||||
->setupLogger()
|
||||
->setupResourceFactory()
|
||||
->setupModuleManager();
|
||||
->setupModuleManager()
|
||||
->loadCoreModules();
|
||||
}
|
||||
|
||||
protected function setupLogging()
|
||||
{
|
||||
Logger::create(
|
||||
new Zend_Config(
|
||||
new Config(
|
||||
array(
|
||||
'level' => Logger::INFO,
|
||||
'log' => 'file',
|
||||
'file' => 'php://stderr'
|
||||
'log' => 'stdout',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
|
@ -4,14 +4,17 @@
|
|||
|
||||
namespace Icinga\Application;
|
||||
|
||||
use Zend_Config;
|
||||
use Zend_Config_Ini;
|
||||
use Iterator;
|
||||
use Countable;
|
||||
use ArrayAccess;
|
||||
use LogicException;
|
||||
use UnexpectedValueException;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
|
||||
/**
|
||||
* Global registry of application and module configuration.
|
||||
* Container for configuration values and global registry of application and module related configuration.
|
||||
*/
|
||||
class Config extends Zend_Config
|
||||
class Config implements Countable, Iterator, ArrayAccess
|
||||
{
|
||||
/**
|
||||
* Configuration directory where ALL (application and module) configuration is located
|
||||
|
@ -20,13 +23,6 @@ class Config extends Zend_Config
|
|||
*/
|
||||
public static $configDir;
|
||||
|
||||
/**
|
||||
* The INI file this configuration has been loaded from or should be written to
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $configFile;
|
||||
|
||||
/**
|
||||
* Application config instances per file
|
||||
*
|
||||
|
@ -42,95 +38,34 @@ class Config extends Zend_Config
|
|||
protected static $modules = array();
|
||||
|
||||
/**
|
||||
* Load configuration from the given INI file
|
||||
* This config's data
|
||||
*
|
||||
* @param string $file The file to parse
|
||||
*
|
||||
* @throws NotReadableError When the file does not exist or cannot be read
|
||||
* @var array
|
||||
*/
|
||||
public static function fromIni($file)
|
||||
{
|
||||
$config = new static(array(), true);
|
||||
$filepath = realpath($file);
|
||||
|
||||
if ($filepath === false) {
|
||||
$config->setConfigFile($file);
|
||||
} elseif (is_readable($filepath)) {
|
||||
$config->setConfigFile($filepath);
|
||||
$config->merge(new Zend_Config_Ini($filepath));
|
||||
} else {
|
||||
throw new NotReadableError('Cannot read config file "%s". Permission denied', $filepath);
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* Retrieve a application config instance
|
||||
* The INI file this configuration has been loaded from or should be written to
|
||||
*
|
||||
* @param string $configname The configuration name (without ini suffix) to read and return
|
||||
* @param bool $fromDisk When set true, the configuration will be read from the disk, even
|
||||
* if it already has been read
|
||||
*
|
||||
* @return Config The configuration object that has been requested
|
||||
* @var string
|
||||
*/
|
||||
public static function app($configname = 'config', $fromDisk = false)
|
||||
{
|
||||
if (!isset(self::$app[$configname]) || $fromDisk) {
|
||||
self::$app[$configname] = Config::fromIni(self::resolvePath($configname . '.ini'));
|
||||
}
|
||||
return self::$app[$configname];
|
||||
}
|
||||
protected $configFile;
|
||||
|
||||
/**
|
||||
* Set module config
|
||||
* Create a new config
|
||||
*
|
||||
* @param string $moduleName
|
||||
* @param string $configName
|
||||
* @param Zend_Config $config
|
||||
* @param array $data The data to initialize the new config with
|
||||
*/
|
||||
public static function setModuleConfig($moduleName, $configName, Zend_Config $config)
|
||||
public function __construct(array $data = array())
|
||||
{
|
||||
self::$modules[$moduleName][$configName] = $config;
|
||||
}
|
||||
$this->data = array();
|
||||
|
||||
/**
|
||||
* Retrieve a module config instance
|
||||
*
|
||||
* @param string $modulename The name of the module to look for configurations
|
||||
* @param string $configname The configuration name (without ini suffix) to read and return
|
||||
* @param string $fromDisk Whether to read the configuration from disk
|
||||
*
|
||||
* @return Config The configuration object that has been requested
|
||||
*/
|
||||
public static function module($modulename, $configname = 'config', $fromDisk = false)
|
||||
{
|
||||
if (!isset(self::$modules[$modulename])) {
|
||||
self::$modules[$modulename] = array();
|
||||
}
|
||||
$moduleConfigs = self::$modules[$modulename];
|
||||
if (!isset($moduleConfigs[$configname]) || $fromDisk) {
|
||||
$moduleConfigs[$configname] = Config::fromIni(
|
||||
self::resolvePath('modules/' . $modulename . '/' . $configname . '.ini')
|
||||
);
|
||||
}
|
||||
return $moduleConfigs[$configname];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve names of accessible sections or properties
|
||||
*
|
||||
* @param $name
|
||||
* @return array
|
||||
*/
|
||||
public function keys($name = null)
|
||||
{
|
||||
if ($name === null) {
|
||||
return array_keys($this->toArray());
|
||||
} elseif ($this->$name === null) {
|
||||
return array();
|
||||
} else {
|
||||
return array_keys($this->$name->toArray());
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$this->data[$key] = new static($value);
|
||||
} else {
|
||||
$this->data[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,13 +93,375 @@ class Config extends Zend_Config
|
|||
}
|
||||
|
||||
/**
|
||||
* Prepend configuration base dir if input is relative
|
||||
* Deep clone this config
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
$array = array();
|
||||
foreach ($this->data as $key => $value) {
|
||||
if ($value instanceof self) {
|
||||
$array[$key] = clone $value;
|
||||
} else {
|
||||
$array[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$this->data = $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the count of available sections and properties
|
||||
*
|
||||
* @param string $path Input path
|
||||
* @return string Absolute path
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the current position of $this->data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
return reset($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the section's or property's value of the current iteration
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
return current($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the position of the current iteration is valid
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
return key($this->data) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the section's or property's name of the current iteration
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
return key($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Advance the position of the current iteration and return the new section's or property's value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
return next($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the given section or property is set
|
||||
*
|
||||
* @param string $key The name of the section or property
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($key)
|
||||
{
|
||||
return isset($this->data[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value for the given property or the config for the given section
|
||||
*
|
||||
* @param string $key The name of the property or section
|
||||
*
|
||||
* @return mixed|NULL The value or NULL in case $key does not exist
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
if (array_key_exists($key, $this->data)) {
|
||||
return $this->data[$key];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new property or section
|
||||
*
|
||||
* @param string $key The name of the new property or section
|
||||
* @param mixed $value The value to set for the new property or section
|
||||
*/
|
||||
public function __set($key, $value)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
$this->data[$key] = new static($value);
|
||||
} else {
|
||||
$this->data[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the given property or section
|
||||
*
|
||||
* @param string $key The property or section to remove
|
||||
*/
|
||||
public function __unset($key)
|
||||
{
|
||||
unset($this->data[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the given section or property is set
|
||||
*
|
||||
* @param string $key The name of the section or property
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function offsetExists($key)
|
||||
{
|
||||
return isset($this->$key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value for the given property or the config for the given section
|
||||
*
|
||||
* @param string $key The name of the property or section
|
||||
*
|
||||
* @return mixed|NULL The value or NULL in case $key does not exist
|
||||
*/
|
||||
public function offsetGet($key)
|
||||
{
|
||||
return $this->$key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new property or section
|
||||
*
|
||||
* @param string $key The name of the new property or section
|
||||
* @param mixed $value The value to set for the new property or section
|
||||
*/
|
||||
public function offsetSet($key, $value)
|
||||
{
|
||||
if ($key === null) {
|
||||
throw new LogicException('Appending values without an explicit key is not supported');
|
||||
}
|
||||
|
||||
$this->$key = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the given property or section
|
||||
*
|
||||
* @param string $key The property or section to remove
|
||||
*/
|
||||
public function offsetUnset($key)
|
||||
{
|
||||
unset($this->$key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this config has any data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return $this->count() === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value for the given property or the config for the given section
|
||||
*
|
||||
* @param string $key The name of the property or section
|
||||
* @param mixed $default The value to return in case the property or section is missing
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
$value = $this->$key;
|
||||
if ($default !== null && $value === null) {
|
||||
$value = $default;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all section and property names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function keys()
|
||||
{
|
||||
return array_keys($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this config's data as associative array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
$array = array();
|
||||
foreach ($this->data as $key => $value) {
|
||||
if ($value instanceof self) {
|
||||
$array[$key] = $value->toArray();
|
||||
} else {
|
||||
$array[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge the given data with this config
|
||||
*
|
||||
* @param array|Config $data An array or a config
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function merge($data)
|
||||
{
|
||||
if ($data instanceof self) {
|
||||
$data = $data->toArray();
|
||||
}
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if (array_key_exists($key, $this->data)) {
|
||||
if (is_array($value)) {
|
||||
if ($this->data[$key] instanceof self) {
|
||||
$this->data[$key]->merge($value);
|
||||
} else {
|
||||
$this->data[$key] = new static($value);
|
||||
}
|
||||
} else {
|
||||
$this->data[$key] = $value;
|
||||
}
|
||||
} else {
|
||||
$this->data[$key] = is_array($value) ? new static($value) : $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value from a section's property
|
||||
*
|
||||
* @param string $section The section where the given property can be found
|
||||
* @param string $key The section's property to fetch the value from
|
||||
* @param mixed $default The value to return in case the section or the property is missing
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws UnexpectedValueException In case the given section does not hold any configuration
|
||||
*/
|
||||
public function fromSection($section, $key, $default = null)
|
||||
{
|
||||
$value = $this->$section;
|
||||
if ($value instanceof self) {
|
||||
$value = $value->$key;
|
||||
} elseif ($value !== null) {
|
||||
throw new UnexpectedValueException(
|
||||
sprintf('Value "%s" is not of type "Config" or a sub-type of it', $value)
|
||||
);
|
||||
}
|
||||
|
||||
if ($value === null && $default !== null) {
|
||||
$value = $default;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load configuration from the given INI file
|
||||
*
|
||||
* @param string $file The file to parse
|
||||
*
|
||||
* @throws NotReadableError When the file does not exist or cannot be read
|
||||
*/
|
||||
public static function fromIni($file)
|
||||
{
|
||||
$config = new static();
|
||||
|
||||
$filepath = realpath($file);
|
||||
if ($filepath === false) {
|
||||
$config->setConfigFile($file);
|
||||
} elseif (is_readable($filepath)) {
|
||||
$config->setConfigFile($filepath);
|
||||
$config->merge(parse_ini_file($filepath, true));
|
||||
} else {
|
||||
throw new NotReadableError(t('Cannot read config file "%s". Permission denied'), $filepath);
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend configuration base dir to the given relative path
|
||||
*
|
||||
* @param string $path A relative path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function resolvePath($path)
|
||||
{
|
||||
return self::$configDir . DIRECTORY_SEPARATOR . ltrim($path, DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a application config
|
||||
*
|
||||
* @param string $configname The configuration name (without ini suffix) to read and return
|
||||
* @param bool $fromDisk When set true, the configuration will be read from disk, even
|
||||
* if it already has been read
|
||||
*
|
||||
* @return Config The requested configuration
|
||||
*/
|
||||
public static function app($configname = 'config', $fromDisk = false)
|
||||
{
|
||||
if (!isset(self::$app[$configname]) || $fromDisk) {
|
||||
self::$app[$configname] = static::fromIni(static::resolvePath($configname . '.ini'));
|
||||
}
|
||||
|
||||
return self::$app[$configname];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a module config
|
||||
*
|
||||
* @param string $modulename The name of the module where to look for the requested configuration
|
||||
* @param string $configname The configuration name (without ini suffix) to read and return
|
||||
* @param string $fromDisk When set true, the configuration will be read from disk, even
|
||||
* if it already has been read
|
||||
*
|
||||
* @return Config The requested configuration
|
||||
*/
|
||||
public static function module($modulename, $configname = 'config', $fromDisk = false)
|
||||
{
|
||||
if (!isset(self::$modules[$modulename])) {
|
||||
self::$modules[$modulename] = array();
|
||||
}
|
||||
|
||||
$moduleConfigs = self::$modules[$modulename];
|
||||
if (!isset($moduleConfigs[$configname]) || $fromDisk) {
|
||||
$moduleConfigs[$configname] = static::fromIni(
|
||||
static::resolvePath('modules/' . $modulename . '/' . $configname . '.ini')
|
||||
);
|
||||
}
|
||||
|
||||
return $moduleConfigs[$configname];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ class EmbeddedWeb extends ApplicationBootstrap
|
|||
->setupErrorHandling()
|
||||
->setupTimezone()
|
||||
->setupModuleManager()
|
||||
->loadCoreModules()
|
||||
->loadEnabledModules();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Logger;
|
||||
namespace Icinga\Application;
|
||||
|
||||
use Exception;
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Logger\Writer\FileWriter;
|
||||
use Icinga\Application\Logger\Writer\SyslogWriter;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Logger\Writer\FileWriter;
|
||||
use Icinga\Logger\Writer\SyslogWriter;
|
||||
|
||||
/**
|
||||
* Logger
|
||||
|
@ -57,7 +57,7 @@ class Logger
|
|||
/**
|
||||
* Log writer
|
||||
*
|
||||
* @var \Icinga\Logger\LogWriter
|
||||
* @var \Icinga\Application\Logger\LogWriter
|
||||
*/
|
||||
protected $writer;
|
||||
|
||||
|
@ -71,12 +71,12 @@ class Logger
|
|||
/**
|
||||
* Create a new logger object
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @param Config $config
|
||||
*
|
||||
* @throws ConfigurationError If the logging configuration directive 'log' is missing or if the logging level is
|
||||
* not defined
|
||||
*/
|
||||
public function __construct(Zend_Config $config)
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
if ($config->log === null) {
|
||||
throw new ConfigurationError('Required logging configuration directive \'log\' missing');
|
||||
|
@ -118,11 +118,11 @@ class Logger
|
|||
/**
|
||||
* Create a new logger object
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @param Config $config
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function create(Zend_Config $config)
|
||||
public static function create(Config $config)
|
||||
{
|
||||
static::$instance = new static($config);
|
||||
return static::$instance;
|
||||
|
@ -131,14 +131,14 @@ class Logger
|
|||
/**
|
||||
* Create a log writer
|
||||
*
|
||||
* @param Zend_Config $config The configuration to initialize the writer with
|
||||
* @param Config $config The configuration to initialize the writer with
|
||||
*
|
||||
* @return \Icinga\Logger\LogWriter The requested log writer
|
||||
* @throws ConfigurationError If the requested writer cannot be found
|
||||
* @return \Icinga\Application\Logger\LogWriter The requested log writer
|
||||
* @throws ConfigurationError If the requested writer cannot be found
|
||||
*/
|
||||
protected function createWriter(Zend_Config $config)
|
||||
protected function createWriter(Config $config)
|
||||
{
|
||||
$class = 'Icinga\\Logger\\Writer\\' . ucfirst(strtolower($config->log)) . 'Writer';
|
||||
$class = 'Icinga\\Application\\Logger\\Writer\\' . ucfirst(strtolower($config->log)) . 'Writer';
|
||||
if (! class_exists($class)) {
|
||||
throw new ConfigurationError(
|
||||
'Cannot find log writer of type "%s"',
|
||||
|
@ -258,7 +258,7 @@ class Logger
|
|||
/**
|
||||
* Get the log writer to use
|
||||
*
|
||||
* @return \Icinga\Logger\LogWriter
|
||||
* @return \Icinga\Application\Logger\LogWriter
|
||||
*/
|
||||
public function getWriter()
|
||||
{
|
|
@ -2,19 +2,27 @@
|
|||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Logger;
|
||||
namespace Icinga\Application\Logger;
|
||||
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Config;
|
||||
|
||||
/**
|
||||
* Abstract class for writers that write messages to a log
|
||||
*/
|
||||
abstract class LogWriter
|
||||
{
|
||||
/**
|
||||
* @var Zend_Config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Create a new log writer initialized with the given configuration
|
||||
*/
|
||||
abstract public function __construct(Zend_Config $config);
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message with the given severity
|
|
@ -2,13 +2,13 @@
|
|||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Logger\Writer;
|
||||
namespace Icinga\Application\Logger\Writer;
|
||||
|
||||
use Exception;
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Application\Logger\LogWriter;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Logger\LogWriter;
|
||||
use Icinga\Util\File;
|
||||
|
||||
/**
|
||||
|
@ -26,12 +26,12 @@ class FileWriter extends LogWriter
|
|||
/**
|
||||
* Create a new file log writer
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @param Config $config
|
||||
*
|
||||
* @throws ConfigurationError If the configuration directive 'file' is missing or if the path to 'file' does
|
||||
* not exist or if writing to 'file' is not possible
|
||||
*/
|
||||
public function __construct(Zend_Config $config)
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
if ($config->file === null) {
|
||||
throw new ConfigurationError('Required logging configuration directive \'file\' missing');
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Application\Logger\Writer;
|
||||
|
||||
use Icinga\Cli\Screen;
|
||||
use Icinga\Application\Logger\Logger;
|
||||
use Icinga\Application\Logger\LogWriter;
|
||||
use Zend_Config;
|
||||
|
||||
/**
|
||||
* Class to write log messages to STDOUT
|
||||
*/
|
||||
class StdoutWriter extends LogWriter
|
||||
{
|
||||
protected $screen;
|
||||
|
||||
protected function screen()
|
||||
{
|
||||
if ($this->screen === null) {
|
||||
$this->screen = Screen::instance();
|
||||
}
|
||||
return $this->screen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message with the given severity
|
||||
*
|
||||
* @param int $severity The severity to use
|
||||
* @param string $message The message to log
|
||||
*/
|
||||
public function log($severity, $message)
|
||||
{
|
||||
$color = 'black';
|
||||
switch ($severity) {
|
||||
case Logger::$ERROR:
|
||||
$color = 'red';
|
||||
break;
|
||||
case Logger::$WARNING:
|
||||
$color = 'orange';
|
||||
break;
|
||||
case Logger::$INFO:
|
||||
$color = 'green';
|
||||
break;
|
||||
case Logger::$DEBUG:
|
||||
$color = 'blue';
|
||||
break;
|
||||
}
|
||||
file_put_contents('php://stderr', $this->screen()->colorize($message, $color) . "\n");
|
||||
}
|
||||
}
|
|
@ -2,11 +2,11 @@
|
|||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Logger\Writer;
|
||||
namespace Icinga\Application\Logger\Writer;
|
||||
|
||||
use Zend_Config;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Logger\LogWriter;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Application\Logger\LogWriter;
|
||||
|
||||
/**
|
||||
* Log to the syslog service
|
||||
|
@ -51,9 +51,9 @@ class SyslogWriter extends LogWriter
|
|||
/**
|
||||
* Create a new syslog log writer
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @param Config $config
|
||||
*/
|
||||
public function __construct(Zend_Config $config)
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->ident = $config->get('application', 'icingaweb');
|
||||
$this->facility = static::$facilities['user'];
|
|
@ -6,7 +6,7 @@ namespace Icinga\Application\Modules;
|
|||
|
||||
use Icinga\Application\ApplicationBootstrap;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Data\DataArray\ArrayDatasource;
|
||||
use Icinga\Data\SimpleQuery;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
|
@ -67,6 +67,18 @@ class Manager
|
|||
*/
|
||||
private $modulePaths = array();
|
||||
|
||||
/**
|
||||
* The core modules
|
||||
*
|
||||
* Core modules do not need to be enabled to load and cannot be disabled
|
||||
* by the user. This must not be writable programmatically!
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $coreModules = array(
|
||||
'setup'
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a new instance of the module manager
|
||||
*
|
||||
|
@ -157,7 +169,21 @@ class Manager
|
|||
}
|
||||
|
||||
/**
|
||||
* Try to set all enabled modules in loaded sate
|
||||
* Try to set all core modules in loaded state
|
||||
*
|
||||
* @return self
|
||||
* @see Manager::loadModule()
|
||||
*/
|
||||
public function loadCoreModules()
|
||||
{
|
||||
foreach ($this->coreModules as $name) {
|
||||
$this->loadModule($name);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to set all enabled modules in loaded state
|
||||
*
|
||||
* @return self
|
||||
* @see Manager::loadModule()
|
||||
|
@ -211,6 +237,8 @@ class Manager
|
|||
'Cannot enable module "%s". Module is not installed.',
|
||||
$name
|
||||
);
|
||||
} elseif (in_array($name, $this->coreModules)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
clearstatcache(true);
|
||||
|
@ -427,7 +455,7 @@ class Manager
|
|||
}
|
||||
|
||||
$installed = $this->listInstalledModules();
|
||||
foreach ($installed as $name) {
|
||||
foreach (array_diff($installed, $this->coreModules) as $name) {
|
||||
$info[$name] = (object) array(
|
||||
'name' => $name,
|
||||
'path' => $this->installedBaseDirs[$name],
|
||||
|
@ -487,11 +515,14 @@ class Manager
|
|||
/**
|
||||
* Detect installed modules from every path provided in modulePaths
|
||||
*
|
||||
* @param array $availableDirs Installed modules location
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function detectInstalledModules()
|
||||
public function detectInstalledModules(array $availableDirs = null)
|
||||
{
|
||||
foreach ($this->modulePaths as $basedir) {
|
||||
$modulePaths = $availableDirs !== null ? $availableDirs : $this->modulePaths;
|
||||
foreach ($modulePaths as $basedir) {
|
||||
$canonical = realpath($basedir);
|
||||
if ($canonical === false) {
|
||||
Logger::warning('Module path "%s" does not exist', $basedir);
|
||||
|
@ -528,4 +559,14 @@ class Manager
|
|||
ksort($this->installedBaseDirs);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the directories where to look for installed modules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getModuleDirs()
|
||||
{
|
||||
return $this->modulePaths;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,19 +5,19 @@
|
|||
namespace Icinga\Application\Modules;
|
||||
|
||||
use Exception;
|
||||
use Zend_Config;
|
||||
use Zend_Controller_Router_Route_Abstract;
|
||||
use Zend_Controller_Router_Route as Route;
|
||||
use Zend_Controller_Router_Route_Regex as RegexRoute;
|
||||
use Icinga\Application\ApplicationBootstrap;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Util\Translator;
|
||||
use Icinga\Web\Hook;
|
||||
use Icinga\Web\Menu;
|
||||
use Icinga\Web\Widget;
|
||||
use Icinga\Web\Widget\Dashboard\Pane;
|
||||
use Icinga\Module\Setup\SetupWizard;
|
||||
use Icinga\Util\File;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Exception\IcingaException;
|
||||
|
@ -134,6 +134,13 @@ class Module
|
|||
*/
|
||||
private $configTabs = array();
|
||||
|
||||
/**
|
||||
* Provided setup wizard
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $setupWizard;
|
||||
|
||||
/**
|
||||
* Icinga application
|
||||
*
|
||||
|
@ -235,7 +242,7 @@ class Module
|
|||
if (array_key_exists($name, $this->menuItems)) {
|
||||
$this->menuItems[$name]->setProperties($properties);
|
||||
} else {
|
||||
$this->menuItems[$name] = new Menu($name, new Zend_Config($properties));
|
||||
$this->menuItems[$name] = new Menu($name, new Config($properties));
|
||||
}
|
||||
|
||||
return $this->menuItems[$name];
|
||||
|
@ -642,6 +649,31 @@ class Module
|
|||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this module provides a setup wizard
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function providesSetupWizard()
|
||||
{
|
||||
$this->launchConfigScript();
|
||||
if (class_exists($this->setupWizard)) {
|
||||
$wizard = new $this->setupWizard;
|
||||
return $wizard instanceof SetupWizard;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this module's setup wizard
|
||||
*
|
||||
* @return SetupWizard
|
||||
*/
|
||||
public function getSetupWizard()
|
||||
{
|
||||
return new $this->setupWizard;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a named permission
|
||||
|
@ -705,6 +737,19 @@ class Module
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a setup wizard
|
||||
*
|
||||
* @param string $className The name of the class
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
protected function provideSetupWizard($className)
|
||||
{
|
||||
$this->setupWizard = $className;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register new namespaces on the autoloader
|
||||
*
|
||||
|
|
|
@ -30,6 +30,16 @@ class Platform
|
|||
*/
|
||||
protected static $fqdn;
|
||||
|
||||
/**
|
||||
* Return the operating system's name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getOperatingSystemName()
|
||||
{
|
||||
return php_uname('s');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of windows
|
||||
*
|
||||
|
@ -37,7 +47,7 @@ class Platform
|
|||
*/
|
||||
public static function isWindows()
|
||||
{
|
||||
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
|
||||
return strtoupper(substr(self::getOperatingSystemName(), 0, 3)) === 'WIN';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,7 +57,7 @@ class Platform
|
|||
*/
|
||||
public static function isLinux()
|
||||
{
|
||||
return strtoupper(substr(PHP_OS, 0, 5)) === 'LINUX';
|
||||
return strtoupper(substr(self::getOperatingSystemName(), 0, 5)) === 'LINUX';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,7 +126,35 @@ class Platform
|
|||
if (substr(self::$fqdn, 0, strlen(self::$hostname)) === self::$hostname) {
|
||||
self::$domain = substr(self::$fqdn, strlen(self::$hostname) + 1);
|
||||
} else {
|
||||
self::$domain = array_shift(preg_split('~\.~', self::$hostname, 2));
|
||||
$parts = preg_split('~\.~', self::$hostname, 2);
|
||||
self::$domain = array_shift($parts);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the version of PHP
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getPhpVersion()
|
||||
{
|
||||
return phpversion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the username PHP is running as
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getPhpUser()
|
||||
{
|
||||
if (static::isWindows()) {
|
||||
return get_current_user(); // http://php.net/manual/en/function.get-current-user.php#75059
|
||||
}
|
||||
|
||||
if (function_exists('posix_geteuid')) {
|
||||
$userInfo = posix_getpwuid(posix_geteuid());
|
||||
return $userInfo['name'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,4 +169,32 @@ class Platform
|
|||
{
|
||||
return extension_loaded($extensionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value for the given PHP configuration option
|
||||
*
|
||||
* @param string $option The option name for which to return the value
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public static function getPhpConfig($option)
|
||||
{
|
||||
return ini_get($option);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the given Zend framework class exists
|
||||
*
|
||||
* @param string $name The name of the class to check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function zendClassExists($name)
|
||||
{
|
||||
if (class_exists($name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (@include str_replace('_', '/', $name) . '.php') !== false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ require_once __DIR__ . '/ApplicationBootstrap.php';
|
|||
use Icinga\Authentication\Manager as AuthenticationManager;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Util\TimezoneDetect;
|
||||
use Icinga\Web\Request;
|
||||
use Icinga\Web\Response;
|
||||
|
@ -92,6 +92,7 @@ class Web extends ApplicationBootstrap
|
|||
->setupZendMvc()
|
||||
->setupFormNamespace()
|
||||
->setupModuleManager()
|
||||
->loadCoreModules()
|
||||
->loadEnabledModules()
|
||||
->setupRoute()
|
||||
->setupPagination();
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
namespace Icinga\Authentication;
|
||||
|
||||
use Iterator;
|
||||
use Zend_Config;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
|
||||
/**
|
||||
|
@ -17,7 +17,7 @@ class AuthChain implements Iterator
|
|||
/**
|
||||
* User backends configuration
|
||||
*
|
||||
* @var Zend_Config
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
|
@ -31,9 +31,9 @@ class AuthChain implements Iterator
|
|||
/**
|
||||
* Create a new authentication chain from config
|
||||
*
|
||||
* @param Zend_Config $config User backends configuration
|
||||
* @param Config $config User backends configuration
|
||||
*/
|
||||
public function __construct(Zend_Config $config)
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Icinga\Authentication\Backend;
|
||||
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Authentication\UserBackend;
|
||||
use Icinga\User;
|
||||
|
||||
|
@ -23,9 +23,9 @@ class AutoLoginBackend extends UserBackend
|
|||
/**
|
||||
* Create new autologin backend
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @param Config $config
|
||||
*/
|
||||
public function __construct(Zend_Config $config)
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->stripUsernameRegexp = $config->get('strip_username_regexp');
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ class AutoLoginBackend extends UserBackend
|
|||
if (isset($_SERVER['REMOTE_USER'])) {
|
||||
$username = $_SERVER['REMOTE_USER'];
|
||||
$user->setRemoteUserInformation($username, 'REMOTE_USER');
|
||||
if ($this->stripUsernameRegexp !== null) {
|
||||
if ($this->stripUsernameRegexp) {
|
||||
$stripped = preg_replace($this->stripUsernameRegexp, '', $username);
|
||||
if ($stripped !== false) {
|
||||
// TODO(el): PHP issues a warning when PHP cannot compile the regular expression. Should we log an
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
namespace Icinga\Authentication\Backend;
|
||||
|
||||
use PDO;
|
||||
use Icinga\Authentication\UserBackend;
|
||||
use Icinga\Data\Db\DbConnection;
|
||||
use Icinga\User;
|
||||
|
@ -11,16 +12,29 @@ use Icinga\Exception\AuthenticationException;
|
|||
use Exception;
|
||||
use Zend_Db_Expr;
|
||||
use Zend_Db_Select;
|
||||
use Icinga\Exception\IcingaException;
|
||||
|
||||
class DbUserBackend extends UserBackend
|
||||
{
|
||||
/**
|
||||
* The algorithm to use when hashing passwords
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const HASH_ALGORITHM = '$1$'; // MD5
|
||||
|
||||
/**
|
||||
* The length of the salt to use when hashing a password
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const SALT_LENGTH = 12; // 12 is required by MD5
|
||||
|
||||
/**
|
||||
* Connection to the database
|
||||
*
|
||||
* @var DbConnection
|
||||
*/
|
||||
private $conn;
|
||||
protected $conn;
|
||||
|
||||
public function __construct(DbConnection $conn)
|
||||
{
|
||||
|
@ -36,45 +50,69 @@ class DbUserBackend extends UserBackend
|
|||
*/
|
||||
public function hasUser(User $user)
|
||||
{
|
||||
$select = new Zend_Db_Select($this->conn->getConnection());
|
||||
$row = $select->from('account', array(new Zend_Db_Expr(1)))
|
||||
->where('username = ?', $user->getUsername())
|
||||
$select = new Zend_Db_Select($this->conn->getDbAdapter());
|
||||
$row = $select->from('icingaweb_user', array(new Zend_Db_Expr(1)))
|
||||
->where('name = ?', $user->getUsername())
|
||||
->query()->fetchObject();
|
||||
|
||||
return ($row !== false) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate the given user and return true on success, false on failure and null on error
|
||||
* Add a new user
|
||||
*
|
||||
* @param string $username The name of the new user
|
||||
* @param string $password The new user's password
|
||||
* @param bool $active Whether the user is active
|
||||
*/
|
||||
public function addUser($username, $password, $active = true)
|
||||
{
|
||||
$passwordHash = $this->hashPassword($password);
|
||||
|
||||
$stmt = $this->conn->getDbAdapter()->prepare(
|
||||
'INSERT INTO icingaweb_user VALUES (:name, :active, :password_hash, now(), DEFAULT);'
|
||||
);
|
||||
$stmt->bindParam(':name', $username, PDO::PARAM_STR);
|
||||
$stmt->bindParam(':active', $active, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':password_hash', $passwordHash, PDO::PARAM_LOB);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the hashed password for the given user
|
||||
*
|
||||
* @param string $username The name of the user
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getPasswordHash($username)
|
||||
{
|
||||
$stmt = $this->conn->getDbAdapter()->prepare(
|
||||
'SELECT password_hash FROM icingaweb_user WHERE name = :name AND active = 1'
|
||||
);
|
||||
$stmt->execute(array(':name' => $username));
|
||||
$stmt->bindColumn(1, $lob, PDO::PARAM_LOB);
|
||||
$stmt->fetch(PDO::FETCH_BOUND);
|
||||
return is_resource($lob) ? stream_get_contents($lob) : $lob;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate the given user and return true on success, false on failure and throw an exception on error
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $password
|
||||
*
|
||||
* @return bool|null
|
||||
* @return bool
|
||||
*
|
||||
* @throws AuthenticationException
|
||||
*/
|
||||
public function authenticate(User $user, $password)
|
||||
{
|
||||
try {
|
||||
$salt = $this->getSalt($user->getUsername());
|
||||
if ($salt === null) {
|
||||
return false;
|
||||
}
|
||||
if ($salt === '') {
|
||||
throw new IcingaException(
|
||||
'Cannot find salt for user %s',
|
||||
$user->getUsername()
|
||||
);
|
||||
}
|
||||
|
||||
$select = new Zend_Db_Select($this->conn->getConnection());
|
||||
$row = $select->from('account', array(new Zend_Db_Expr(1)))
|
||||
->where('username = ?', $user->getUsername())
|
||||
->where('active = ?', true)
|
||||
->where('password = ?', $this->hashPassword($password, $salt))
|
||||
->query()->fetchObject();
|
||||
|
||||
return ($row !== false) ? true : false;
|
||||
$passwordHash = $this->getPasswordHash($user->getUsername());
|
||||
$passwordSalt = $this->getSalt($passwordHash);
|
||||
$hashToCompare = $this->hashPassword($password, $passwordSalt);
|
||||
return $hashToCompare === $passwordHash;
|
||||
} catch (Exception $e) {
|
||||
throw new AuthenticationException(
|
||||
'Failed to authenticate user "%s" against backend "%s". An exception was thrown:',
|
||||
|
@ -86,29 +124,40 @@ class DbUserBackend extends UserBackend
|
|||
}
|
||||
|
||||
/**
|
||||
* Get salt by username
|
||||
* Extract salt from the given password hash
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $hash The hashed password
|
||||
*
|
||||
* @return string|null
|
||||
* @return string
|
||||
*/
|
||||
private function getSalt($username)
|
||||
protected function getSalt($hash)
|
||||
{
|
||||
$select = new Zend_Db_Select($this->conn->getConnection());
|
||||
$row = $select->from('account', array('salt'))->where('username = ?', $username)->query()->fetchObject();
|
||||
return ($row !== false) ? $row->salt : null;
|
||||
return substr($hash, strlen(self::HASH_ALGORITHM), self::SALT_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a random salt
|
||||
*
|
||||
* The returned salt is safe to be used for hashing a user's password
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generateSalt()
|
||||
{
|
||||
return openssl_random_pseudo_bytes(self::SALT_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash a password
|
||||
*
|
||||
* @param string $password
|
||||
* @param string $salt
|
||||
* @param string $password
|
||||
* @param string $salt
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function hashPassword($password, $salt) {
|
||||
return hash_hmac('sha256', $password, $salt);
|
||||
protected function hashPassword($password, $salt = null)
|
||||
{
|
||||
return crypt($password, self::HASH_ALGORITHM . ($salt !== null ? $salt : $this->generateSalt()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,12 +167,29 @@ class DbUserBackend extends UserBackend
|
|||
*/
|
||||
public function count()
|
||||
{
|
||||
$select = new Zend_Db_Select($this->conn->getConnection());
|
||||
$select = new Zend_Db_Select($this->conn->getDbAdapter());
|
||||
$row = $select->from(
|
||||
'account',
|
||||
'icingaweb_user',
|
||||
array('count' => 'COUNT(*)')
|
||||
)->query()->fetchObject();
|
||||
|
||||
return ($row !== false) ? $row->count : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the names of all available users
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listUsers()
|
||||
{
|
||||
$query = $this->conn->select()->from('icingaweb_user', array('name'));
|
||||
|
||||
$users = array();
|
||||
foreach ($query->fetchAll() as $row) {
|
||||
$users[] = $row->name;
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
namespace Icinga\Authentication\Backend;
|
||||
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\User;
|
||||
use Icinga\Authentication\UserBackend;
|
||||
use Icinga\Protocol\Ldap\Connection;
|
||||
|
@ -20,20 +19,36 @@ class LdapUserBackend extends UserBackend
|
|||
**/
|
||||
protected $conn;
|
||||
|
||||
protected $baseDn;
|
||||
|
||||
protected $userClass;
|
||||
|
||||
protected $userNameAttribute;
|
||||
|
||||
protected $groupOptions;
|
||||
|
||||
public function __construct(Connection $conn, $userClass, $userNameAttribute, $groupOptions = null)
|
||||
public function __construct(Connection $conn, $userClass, $userNameAttribute, $baseDn, $groupOptions = null)
|
||||
{
|
||||
$this->conn = $conn;
|
||||
$this->baseDn = trim($baseDn) !== '' ? $baseDn : $conn->getDN();
|
||||
$this->userClass = $userClass;
|
||||
$this->userNameAttribute = $userNameAttribute;
|
||||
$this->groupOptions = $groupOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Icinga\Protocol\Ldap\Query
|
||||
*/
|
||||
protected function selectUsers()
|
||||
{
|
||||
return $this->conn->select()->setBase($this->baseDn)->from(
|
||||
$this->userClass,
|
||||
array(
|
||||
$this->userNameAttribute
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create query
|
||||
*
|
||||
|
@ -41,14 +56,9 @@ class LdapUserBackend extends UserBackend
|
|||
*
|
||||
* @return \Icinga\Protocol\Ldap\Query
|
||||
**/
|
||||
protected function createQuery($username)
|
||||
protected function selectUser($username)
|
||||
{
|
||||
return $this->conn->select()
|
||||
->from(
|
||||
$this->userClass,
|
||||
array($this->userNameAttribute)
|
||||
)
|
||||
->where(
|
||||
return $this->selectUsers()->where(
|
||||
$this->userNameAttribute,
|
||||
str_replace('*', '', $username)
|
||||
);
|
||||
|
@ -68,13 +78,18 @@ class LdapUserBackend extends UserBackend
|
|||
*/
|
||||
public function assertAuthenticationPossible()
|
||||
{
|
||||
$q = $this->conn->select()->from($this->userClass);
|
||||
$result = $q->fetchRow();
|
||||
try {
|
||||
$q = $this->conn->select()->setBase($this->baseDn)->from($this->userClass);
|
||||
$result = $q->fetchRow();
|
||||
} catch (LdapException $e) {
|
||||
throw new AuthenticationException('Connection not possible.', $e);
|
||||
}
|
||||
|
||||
if (! isset($result)) {
|
||||
throw new AuthenticationException(
|
||||
'No objects with objectClass="%s" in DN="%s" found.',
|
||||
$this->userClass,
|
||||
$this->conn->getDN()
|
||||
$this->baseDn
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -94,12 +109,12 @@ class LdapUserBackend extends UserBackend
|
|||
*
|
||||
* @param string $dn
|
||||
*
|
||||
* @return array|null
|
||||
* @return array
|
||||
*/
|
||||
public function getGroups($dn)
|
||||
{
|
||||
if (empty($this->groupOptions) || ! isset($this->groupOptions['group_base_dn'])) {
|
||||
return null;
|
||||
return array();
|
||||
}
|
||||
|
||||
$q = $this->conn->select()
|
||||
|
@ -135,7 +150,7 @@ class LdapUserBackend extends UserBackend
|
|||
public function hasUser(User $user)
|
||||
{
|
||||
$username = $user->getUsername();
|
||||
return $this->conn->fetchOne($this->createQuery($username)) === $username;
|
||||
return $this->conn->fetchOne($this->selectUser($username)) === $username;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -158,7 +173,7 @@ class LdapUserBackend extends UserBackend
|
|||
} catch (AuthenticationException $e) {
|
||||
// Authentication not possible
|
||||
throw new AuthenticationException(
|
||||
'Authentication against backend "%s" not possible: ',
|
||||
'Authentication against backend "%s" not possible.',
|
||||
$this->getName(),
|
||||
$e
|
||||
);
|
||||
|
@ -168,7 +183,7 @@ class LdapUserBackend extends UserBackend
|
|||
return false;
|
||||
}
|
||||
try {
|
||||
$userDn = $this->conn->fetchDN($this->createQuery($user->getUsername()));
|
||||
$userDn = $this->conn->fetchDN($this->selectUser($user->getUsername()));
|
||||
$authenticated = $this->conn->testCredentials(
|
||||
$userDn,
|
||||
$password
|
||||
|
@ -198,14 +213,20 @@ class LdapUserBackend extends UserBackend
|
|||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->conn->count($this->selectUsers());
|
||||
}
|
||||
|
||||
return $this->conn->count(
|
||||
$this->conn->select()->from(
|
||||
$this->userClass,
|
||||
array(
|
||||
$this->userNameAttribute
|
||||
)
|
||||
)
|
||||
);
|
||||
/**
|
||||
* Return the names of all available users
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listUsers()
|
||||
{
|
||||
$users = array();
|
||||
foreach ($this->selectUsers()->fetchAll() as $row) {
|
||||
$users[] = $row->{$this->userNameAttribute};
|
||||
}
|
||||
return $users;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,10 @@
|
|||
namespace Icinga\Authentication;
|
||||
|
||||
use Exception;
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Exception\IcingaException;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\User;
|
||||
use Icinga\User\Preferences;
|
||||
use Icinga\User\Preferences\PreferencesStore;
|
||||
|
@ -62,7 +61,7 @@ class Manager
|
|||
$e
|
||||
)
|
||||
);
|
||||
$config = new Zend_Config(array());
|
||||
$config = new Config();
|
||||
}
|
||||
if (($preferencesConfig = $config->preferences) !== null) {
|
||||
try {
|
||||
|
@ -120,10 +119,7 @@ class Manager
|
|||
*/
|
||||
public function persistCurrentUser()
|
||||
{
|
||||
$session = Session::getSession();
|
||||
$session->set('user', $this->user);
|
||||
$session->write();
|
||||
$session->refreshId();
|
||||
Session::getSession()->set('user', $this->user)->refreshId();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace Icinga\Authentication;
|
|||
|
||||
use Countable;
|
||||
use Icinga\Authentication\Backend\AutoLoginBackend;
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Authentication\Backend\DbUserBackend;
|
||||
use Icinga\Authentication\Backend\LdapUserBackend;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
|
@ -45,7 +45,7 @@ abstract class UserBackend implements Countable
|
|||
return $this->name;
|
||||
}
|
||||
|
||||
public static function create($name, Zend_Config $backendConfig)
|
||||
public static function create($name, Config $backendConfig)
|
||||
{
|
||||
if ($backendConfig->name !== null) {
|
||||
$name = $backendConfig->name;
|
||||
|
@ -103,6 +103,7 @@ abstract class UserBackend implements Countable
|
|||
$resource,
|
||||
$backendConfig->get('user_class', 'user'),
|
||||
$backendConfig->get('user_name_attribute', 'sAMAccountName'),
|
||||
$backendConfig->get('base_dn', $resource->getDN()),
|
||||
$groupOptions
|
||||
);
|
||||
break;
|
||||
|
@ -129,6 +130,7 @@ abstract class UserBackend implements Countable
|
|||
$resource,
|
||||
$backendConfig->user_class,
|
||||
$backendConfig->user_name_attribute,
|
||||
$backendConfig->get('base_dn', $resource->getDN()),
|
||||
$groupOptions
|
||||
);
|
||||
break;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Icinga\Authentication;
|
||||
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Authentication\Backend\DbUserGroupBackend;
|
||||
use Icinga\Authentication\Backend\IniUserGroupBackend;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
|
@ -50,13 +50,13 @@ abstract class UserGroupBackend
|
|||
/**
|
||||
* Create a user group backend
|
||||
*
|
||||
* @param string $name
|
||||
* @param Zend_Config $backendConfig
|
||||
* @param string $name
|
||||
* @param Config $backendConfig
|
||||
*
|
||||
* @return DbUserGroupBackend|IniUserGroupBackend
|
||||
* @throws ConfigurationError If the backend configuration is invalid
|
||||
*/
|
||||
public static function create($name, Zend_Config $backendConfig)
|
||||
public static function create($name, Config $backendConfig)
|
||||
{
|
||||
if ($backendConfig->name !== null) {
|
||||
$name = $backendConfig->name;
|
||||
|
|
|
@ -66,7 +66,7 @@ class Loader
|
|||
public function __construct(App $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->coreAppDir = ICINGAWEB_APPDIR . '/clicommands';
|
||||
$this->coreAppDir = $app->getBaseDir('clicommands');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
|
||||
namespace Icinga\Data\Db;
|
||||
|
||||
use PDO;
|
||||
use Zend_Db;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Benchmark;
|
||||
use Icinga\Data\Db\DbQuery;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Data\Selectable;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use PDO;
|
||||
use Zend_Config;
|
||||
use Zend_Db;
|
||||
|
||||
/**
|
||||
* Encapsulate database connections and query creation
|
||||
|
@ -21,7 +21,7 @@ class DbConnection implements Selectable
|
|||
/**
|
||||
* Connection config
|
||||
*
|
||||
* @var Zend_Config
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
|
@ -59,9 +59,9 @@ class DbConnection implements Selectable
|
|||
/**
|
||||
* Create a new connection object
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @param Config $config
|
||||
*/
|
||||
public function __construct(Zend_Config $config = null)
|
||||
public function __construct(Config $config = null)
|
||||
{
|
||||
$this->config = $config;
|
||||
if (isset($config->prefix)) {
|
||||
|
@ -216,7 +216,10 @@ class DbConnection implements Selectable
|
|||
*/
|
||||
public function fetchRow(DbQuery $query)
|
||||
{
|
||||
return $this->dbAdapter->fetchRow($query->getSelectQuery());
|
||||
Benchmark::measure('DB is fetching row');
|
||||
$result = $this->dbAdapter->fetchRow($query->getSelectQuery());
|
||||
Benchmark::measure('DB row done');
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -79,7 +79,7 @@ abstract class Filter
|
|||
}
|
||||
}
|
||||
|
||||
krsort($operators, SORT_NATURAL);
|
||||
krsort($operators, version_compare(PHP_VERSION, '5.4.0') >= 0 ? SORT_NATURAL : SORT_REGULAR);
|
||||
foreach ($operators as $id => $operator) {
|
||||
$f = $filter->getById($id);
|
||||
if ($f->getOperatorName() !== $operator) {
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
namespace Icinga\Data;
|
||||
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Util\ConfigAwareFactory;
|
||||
|
@ -22,14 +21,14 @@ class ResourceFactory implements ConfigAwareFactory
|
|||
/**
|
||||
* Resource configuration
|
||||
*
|
||||
* @var Zend_Config
|
||||
* @var Config
|
||||
*/
|
||||
private static $resources;
|
||||
|
||||
/**
|
||||
* Set resource configurations
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @param Config $config
|
||||
*/
|
||||
public static function setConfig($config)
|
||||
{
|
||||
|
@ -41,7 +40,7 @@ class ResourceFactory implements ConfigAwareFactory
|
|||
*
|
||||
* @param $resourceName String The resource's name
|
||||
*
|
||||
* @return Zend_Config The configuration of the resource
|
||||
* @return Config The configuration of the resource
|
||||
*
|
||||
* @throws ConfigurationError
|
||||
*/
|
||||
|
@ -62,7 +61,7 @@ class ResourceFactory implements ConfigAwareFactory
|
|||
*
|
||||
* @param String|null $type Fetch only resources that have the given type.
|
||||
*
|
||||
* @return Zend_Config The configuration containing all resources
|
||||
* @return Config The configuration containing all resources
|
||||
*/
|
||||
public static function getResourceConfigs($type = null)
|
||||
{
|
||||
|
@ -76,7 +75,7 @@ class ResourceFactory implements ConfigAwareFactory
|
|||
$resources[$name] = $resource;
|
||||
}
|
||||
}
|
||||
return new Zend_Config($resources);
|
||||
return new Config($resources);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,13 +99,13 @@ class ResourceFactory implements ConfigAwareFactory
|
|||
* NOTE: The factory does not test if the given configuration is valid and the resource is accessible, this
|
||||
* depends entirely on the implementation of the returned resource.
|
||||
*
|
||||
* @param Zend_Config $config The configuration for the created resource.
|
||||
* @param Config $config The configuration for the created resource.
|
||||
*
|
||||
* @return DbConnection|LdapConnection|LivestatusConnection An object that can be used to access
|
||||
* the given resource. The returned class depends on the configuration property 'type'.
|
||||
* @throws ConfigurationError When an unsupported type is given
|
||||
*/
|
||||
public static function createResource(Zend_Config $config)
|
||||
public static function createResource(Config $config)
|
||||
{
|
||||
switch (strtolower($config->type)) {
|
||||
case 'db':
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Config;
|
||||
namespace Icinga\File\Ini;
|
||||
|
||||
/**
|
||||
* Edit the sections and keys of an ini in-place
|
||||
|
@ -433,6 +433,9 @@ class IniEditor
|
|||
*/
|
||||
private function formatKey(array $key)
|
||||
{
|
||||
foreach ($key as $i => $separator) {
|
||||
$key[$i] = $this->sanitize($separator);
|
||||
}
|
||||
return implode($this->nestSeparator, $key);
|
||||
}
|
||||
|
||||
|
@ -599,7 +602,7 @@ class IniEditor
|
|||
}
|
||||
|
||||
/**
|
||||
* Prepare a value for INe
|
||||
* Prepare a value for INI
|
||||
*
|
||||
* @param $value The value of the string
|
||||
*
|
||||
|
@ -613,10 +616,12 @@ class IniEditor
|
|||
return $value;
|
||||
} elseif (is_bool($value)) {
|
||||
return ($value ? 'true' : 'false');
|
||||
} elseif (strpos($value, '"') === false) {
|
||||
return '"' . $value . '"';
|
||||
} else {
|
||||
return '"' . str_replace('"', '\"', $value) . '"';
|
||||
}
|
||||
return '"' . str_replace('"', '\"', $this->sanitize($value)) . '"';
|
||||
}
|
||||
|
||||
private function sanitize($value)
|
||||
{
|
||||
return str_replace('\n', '', $value);
|
||||
}
|
||||
}
|
|
@ -2,17 +2,18 @@
|
|||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Config;
|
||||
namespace Icinga\File\Ini;
|
||||
|
||||
use Zend_Config;
|
||||
use Zend_Config_Ini;
|
||||
use Zend_Config_Exception;
|
||||
use Zend_Config_Writer_FileAbstract;
|
||||
use Icinga\Config\IniEditor;
|
||||
use Icinga\Application\Config;
|
||||
|
||||
/**
|
||||
* A ini file adapter that respects the file structure and the comments of already existing ini files
|
||||
* A INI file adapter that respects the file structure and the comments of already existing ini files
|
||||
*/
|
||||
class PreservingIniWriter extends Zend_Config_Writer_FileAbstract
|
||||
class IniWriter extends Zend_Config_Writer_FileAbstract
|
||||
{
|
||||
/**
|
||||
* Stores the options
|
||||
|
@ -22,10 +23,17 @@ class PreservingIniWriter extends Zend_Config_Writer_FileAbstract
|
|||
protected $options;
|
||||
|
||||
/**
|
||||
* Create a new PreservingIniWriter
|
||||
* The mode to set on new files
|
||||
*
|
||||
* @param array $options Supports all options of Zend_Config_Writer and additional
|
||||
* options for the internal IniEditor:
|
||||
* @var int
|
||||
*/
|
||||
public static $fileMode = 0664;
|
||||
|
||||
/**
|
||||
* Create a new INI writer
|
||||
*
|
||||
* @param array $options Supports all options of Zend_Config_Writer and additional options:
|
||||
* * filemode: The mode to set on new files
|
||||
* * valueIndentation: The indentation level of the values
|
||||
* * commentIndentation: The indentation level of the comments
|
||||
* * sectionSeparators: The amount of newlines between sections
|
||||
|
@ -34,49 +42,16 @@ class PreservingIniWriter extends Zend_Config_Writer_FileAbstract
|
|||
*/
|
||||
public function __construct(array $options = null)
|
||||
{
|
||||
if (isset($options['config']) && $options['config'] instanceof Config) {
|
||||
// As this class inherits from Zend_Config_Writer_FileAbstract we must
|
||||
// not pass the config directly as it needs to be of type Zend_Config
|
||||
$options['config'] = new Zend_Config($options['config']->toArray(), true);
|
||||
}
|
||||
|
||||
$this->options = $options;
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all keys containing dots and convert it to a nested configuration
|
||||
*
|
||||
* Ensure that configurations with the same ini representation the have
|
||||
* similarly nested Zend_Config objects. The configuration may be altered
|
||||
* during that process.
|
||||
*
|
||||
* @param Zend_Config $config The configuration to normalize
|
||||
* @return Zend_Config The normalized config
|
||||
*/
|
||||
private function normalizeKeys(Zend_Config $config)
|
||||
{
|
||||
foreach ($config as $key => $value) {
|
||||
if (preg_match('/\./', $key) > 0) {
|
||||
// remove old key
|
||||
unset ($config->$key);
|
||||
|
||||
// insert new key
|
||||
$nests = explode('.', $key);
|
||||
$current = $config;
|
||||
$i = 0;
|
||||
for (; $i < count($nests) - 1; $i++) {
|
||||
if (! isset($current->{$nests[$i]})) {
|
||||
// configuration key doesn't exist, create a new nesting level
|
||||
$current->{$nests[$i]} = new Zend_Config (array(), true);
|
||||
}
|
||||
// move to next nesting level
|
||||
$current = $current->{$nests[$i]};
|
||||
}
|
||||
// reached last nesting level, insert value
|
||||
$current->{$nests[$i]} = $value;
|
||||
}
|
||||
if ($value instanceof Zend_Config) {
|
||||
$config->$key = $this->normalizeKeys ($value);
|
||||
}
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the Zend_Config into a config file string
|
||||
*
|
||||
|
@ -90,23 +65,37 @@ class PreservingIniWriter extends Zend_Config_Writer_FileAbstract
|
|||
$oldconfig = new Zend_Config(array());
|
||||
}
|
||||
|
||||
// create an internal copy of the given configuration, since the user of this class
|
||||
// won't expect that a configuration will ever be altered during
|
||||
// the rendering process.
|
||||
$extends = $this->_config->getExtends();
|
||||
$this->_config = new Zend_Config ($this->_config->toArray(), true);
|
||||
foreach ($extends as $extending => $extended) {
|
||||
$this->_config->setExtend($extending, $extended);
|
||||
}
|
||||
$this->_config = $this->normalizeKeys($this->_config);
|
||||
|
||||
$newconfig = $this->_config;
|
||||
$editor = new IniEditor(file_get_contents($this->_filename), $this->options);
|
||||
$editor = new IniEditor(@file_get_contents($this->_filename), $this->options);
|
||||
$this->diffConfigs($oldconfig, $newconfig, $editor);
|
||||
$this->updateSectionOrder($newconfig, $editor);
|
||||
return $editor->getText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write configuration to file and set file mode in case it does not exist yet
|
||||
*
|
||||
* @param string $filename
|
||||
* @param Zend_Config $config
|
||||
* @param bool $exclusiveLock
|
||||
*/
|
||||
public function write($filename = null, Zend_Config $config = null, $exclusiveLock = null)
|
||||
{
|
||||
$filePath = $filename !== null ? $filename : $this->_filename;
|
||||
$setMode = false === file_exists($filePath);
|
||||
|
||||
parent::write($filename, $config, $exclusiveLock);
|
||||
|
||||
if ($setMode) {
|
||||
$mode = isset($this->options['filemode']) ? $this->options['filemode'] : static::$fileMode;
|
||||
$old = umask(0); // Make sure that the mode we're going to set doesn't get mangled
|
||||
if (is_int($mode) && false === @chmod($filePath, $mode)) {
|
||||
throw new Zend_Config_Exception(sprintf('Failed to set file mode "%o" on file "%s"', $mode, $filePath));
|
||||
}
|
||||
umask($old);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a property diff and apply the changes to the editor
|
||||
*
|
|
@ -49,7 +49,7 @@ class Pdf extends DOMPDF
|
|||
$layout->content = $controller->getResponse();
|
||||
$html = $layout->render();
|
||||
$imgDir = Url::fromPath('img');
|
||||
$html = preg_replace('~src="' . $imgDir . '/~', 'src="' . Icinga::app()->getBootstrapDirecory() . '/img/', $html);
|
||||
$html = preg_replace('~src="' . $imgDir . '/~', 'src="' . Icinga::app()->getBootstrapDirectory() . '/img/', $html);
|
||||
$html = preg_replace('~src="/svg/chart.php(.*)"~', 'class="icon" src="http://master1.com/png/chart.php$1"', $html);
|
||||
$this->load_html($html);
|
||||
$this->render();
|
||||
|
|
|
@ -9,7 +9,6 @@ namespace Icinga\Protocol;
|
|||
*/
|
||||
class Dns
|
||||
{
|
||||
|
||||
/**
|
||||
* Discover all service records on a given domain
|
||||
*
|
||||
|
@ -17,21 +16,12 @@ class Dns
|
|||
* @param string $service The type of the service, like for example 'ldaps' or 'ldap'
|
||||
* @param string $protocol The transport protocol used by the service, defaults to 'tcp'
|
||||
*
|
||||
* @return array|null An array of all service domains
|
||||
* @return array An array of all found service records
|
||||
*/
|
||||
public static function getSrvRecords($domain, $service, $protocol = 'tcp')
|
||||
{
|
||||
$records = dns_get_record('_' . $service . '._' . $protocol . '.' . $domain, DNS_SRV);
|
||||
if ($records === false) {
|
||||
return null;
|
||||
}
|
||||
$targets = array();
|
||||
foreach ($records as $record) {
|
||||
if (array_key_exists('target', $record)) {
|
||||
$targets[] = $record['target'];
|
||||
}
|
||||
}
|
||||
return $targets;
|
||||
return $records === false ? array() : $records;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
namespace Icinga\Protocol\File;
|
||||
|
||||
use Icinga\Data\Selectable;
|
||||
use Countable;
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Data\Selectable;
|
||||
|
||||
/**
|
||||
* Read file line by line
|
||||
|
@ -30,11 +30,11 @@ class FileReader implements Selectable, Countable
|
|||
/**
|
||||
* Create a new reader
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @param Config $config
|
||||
*
|
||||
* @throws FileReaderException If a required $config directive (filename or fields) is missing
|
||||
*/
|
||||
public function __construct(Zend_Config $config)
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
foreach (array('filename', 'fields') as $key) {
|
||||
if (isset($config->{$key})) {
|
||||
|
|
|
@ -7,8 +7,7 @@ namespace Icinga\Protocol\Ldap;
|
|||
use Icinga\Protocol\Ldap\Exception as LdapException;
|
||||
use Icinga\Application\Platform;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Logger\Logger;
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Logger;
|
||||
|
||||
/**
|
||||
* Backend class managing all the LDAP stuff for you.
|
||||
|
@ -101,9 +100,9 @@ class Connection
|
|||
*
|
||||
* TODO: Allow to pass port and SSL options
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @param Config $config
|
||||
*/
|
||||
public function __construct(Zend_Config $config)
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->hostname = $config->hostname;
|
||||
$this->bind_dn = $config->bind_dn;
|
||||
|
@ -336,9 +335,9 @@ class Connection
|
|||
|
||||
public function testCredentials($username, $password)
|
||||
{
|
||||
$ds = $this->prepareNewConnection();
|
||||
$this->connect();
|
||||
|
||||
$r = @ldap_bind($ds, $username, $password);
|
||||
$r = @ldap_bind($this->ds, $username, $password);
|
||||
if ($r) {
|
||||
Logger::debug(
|
||||
'Successfully tested LDAP credentials (%s / %s)',
|
||||
|
@ -351,7 +350,7 @@ class Connection
|
|||
'Testing LDAP credentials (%s / %s) failed: %s',
|
||||
$username,
|
||||
'***',
|
||||
ldap_error($ds)
|
||||
ldap_error($this->ds)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
@ -364,7 +363,7 @@ class Connection
|
|||
*/
|
||||
protected function getConfigDir($sub = null)
|
||||
{
|
||||
$dir = Config::getInstance()->getConfigDir() . '/ldap';
|
||||
$dir = Config::$configDir . '/ldap';
|
||||
if ($sub !== null) {
|
||||
$dir .= '/' . $sub;
|
||||
}
|
||||
|
@ -388,7 +387,19 @@ class Connection
|
|||
}
|
||||
|
||||
$ds = ldap_connect($this->hostname, $this->port);
|
||||
list($cap, $namingContexts) = $this->discoverCapabilities($ds);
|
||||
try {
|
||||
$capabilities = $this->discoverCapabilities($ds);
|
||||
list($cap, $namingContexts) = $capabilities;
|
||||
} catch (LdapException $e) {
|
||||
|
||||
// discovery failed, guess defaults
|
||||
$cap = (object) array(
|
||||
'supports_ldapv3' => true,
|
||||
'supports_starttls' => false,
|
||||
'msCapabilities' => array()
|
||||
);
|
||||
$namingContexts = null;
|
||||
}
|
||||
$this->capabilities = $cap;
|
||||
$this->namingContexts = $namingContexts;
|
||||
|
||||
|
@ -626,7 +637,8 @@ class Connection
|
|||
if (! $result) {
|
||||
throw new LdapException(
|
||||
sprintf(
|
||||
'Capability query failed (%s:%d): %s',
|
||||
'Capability query failed (%s:%d): %s. Check if hostname and port of the ldap resource are correct '
|
||||
. ' and if anonymous access is permitted.',
|
||||
$this->hostname,
|
||||
$this->port,
|
||||
ldap_error($ds)
|
||||
|
@ -634,6 +646,16 @@ class Connection
|
|||
);
|
||||
}
|
||||
$entry = ldap_first_entry($ds, $result);
|
||||
if ($entry === false) {
|
||||
throw new LdapException(
|
||||
sprintf(
|
||||
'Capabilities not available (%s:%d): %s. Discovery of root DSE probably not permitted.',
|
||||
$this->hostname,
|
||||
$this->port,
|
||||
ldap_error($ds)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$cap = (object) array(
|
||||
'supports_ldapv3' => false,
|
||||
|
@ -641,10 +663,6 @@ class Connection
|
|||
'msCapabilities' => array()
|
||||
);
|
||||
|
||||
if ($entry === false) {
|
||||
// TODO: Is it OK to have no capabilities?
|
||||
return false;
|
||||
}
|
||||
$ldapAttributes = ldap_get_attributes($ds, $entry);
|
||||
$result = $this->cleanupAttributes($ldapAttributes);
|
||||
$cap->supports_ldapv3 = $this->hasCapabilityLdapV3($result);
|
||||
|
|
|
@ -24,9 +24,9 @@ namespace Icinga\Test {
|
|||
use Exception;
|
||||
use RuntimeException;
|
||||
use Mockery;
|
||||
use Zend_Config;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Data\Db\DbConnection;
|
||||
|
@ -191,17 +191,17 @@ namespace Icinga\Test {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create Zend_Config for database configuration
|
||||
* Create Config for database configuration
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return Zend_Config
|
||||
* @return Config
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
protected function createDbConfigFor($name)
|
||||
{
|
||||
if (array_key_exists($name, self::$dbConfiguration)) {
|
||||
return new Zend_Config(self::$dbConfiguration[$name]);
|
||||
return new Config(self::$dbConfiguration[$name]);
|
||||
}
|
||||
|
||||
throw new RuntimeException('Configuration for database type not available: ' . $name);
|
||||
|
|
|
@ -4,13 +4,12 @@
|
|||
|
||||
namespace Icinga\User\Preferences;
|
||||
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\User;
|
||||
use Icinga\User\Preferences;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Data\Db\DbConnection;
|
||||
use Icinga\Application\Config as IcingaConfig;
|
||||
|
||||
/**
|
||||
* Preferences store factory
|
||||
|
@ -19,13 +18,13 @@ use Icinga\Application\Config as IcingaConfig;
|
|||
* <code>
|
||||
* <?php
|
||||
*
|
||||
* use Zend_Config;
|
||||
* use Icinga\Application\Config;
|
||||
* use Icinga\User\Preferences;
|
||||
* use Icinga\User\Preferences\PreferencesStore;
|
||||
*
|
||||
* // Create a INI store
|
||||
* $store = PreferencesStore::create(
|
||||
* new Zend_Config(
|
||||
* new Config(
|
||||
* 'type' => 'ini',
|
||||
* 'config_path' => '/path/to/preferences'
|
||||
* ),
|
||||
|
@ -42,7 +41,7 @@ abstract class PreferencesStore
|
|||
/**
|
||||
* Store config
|
||||
*
|
||||
* @var Zend_Config
|
||||
* @var Config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
|
@ -56,10 +55,10 @@ abstract class PreferencesStore
|
|||
/**
|
||||
* Create a new store
|
||||
*
|
||||
* @param Zend_Config $config The config for this adapter
|
||||
* @param User $user The user to which these preferences belong
|
||||
* @param Config $config The config for this adapter
|
||||
* @param User $user The user to which these preferences belong
|
||||
*/
|
||||
public function __construct(Zend_Config $config, User $user)
|
||||
public function __construct(Config $config, User $user)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->user = $user;
|
||||
|
@ -69,7 +68,7 @@ abstract class PreferencesStore
|
|||
/**
|
||||
* Getter for the store config
|
||||
*
|
||||
* @return Zend_Config
|
||||
* @return Config
|
||||
*/
|
||||
public function getStoreConfig()
|
||||
{
|
||||
|
@ -108,14 +107,14 @@ abstract class PreferencesStore
|
|||
/**
|
||||
* Create preferences storage adapter from config
|
||||
*
|
||||
* @param Zend_Config $config The config for the adapter
|
||||
* @param User $user The user to which these preferences belong
|
||||
* @param Config $config The config for the adapter
|
||||
* @param User $user The user to which these preferences belong
|
||||
*
|
||||
* @return self
|
||||
*
|
||||
* @throws ConfigurationError When the configuration defines an invalid storage type
|
||||
*/
|
||||
public static function create(Zend_Config $config, User $user)
|
||||
public static function create(Config $config, User $user)
|
||||
{
|
||||
if (($type = $config->type) === null) {
|
||||
throw new ConfigurationError(
|
||||
|
@ -133,7 +132,7 @@ abstract class PreferencesStore
|
|||
}
|
||||
|
||||
if ($type === 'Ini') {
|
||||
$config->location = IcingaConfig::resolvePath('preferences');
|
||||
$config->location = Config::resolvePath('preferences');
|
||||
} elseif ($type === 'Db') {
|
||||
$config->connection = new DbConnection(ResourceFactory::getResourceConfig($config->resource));
|
||||
}
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
|
||||
namespace Icinga\User\Preferences\Store;
|
||||
|
||||
use Zend_Config;
|
||||
use Icinga\Util\File;
|
||||
use Icinga\Config\PreservingIniWriter;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Icinga\Exception\NotWritableError;
|
||||
use Icinga\File\Ini\IniWriter;
|
||||
use Icinga\User\Preferences;
|
||||
use Icinga\User\Preferences\PreferencesStore;
|
||||
use Icinga\Util\File;
|
||||
|
||||
/**
|
||||
* Load and save user preferences from and to INI files
|
||||
|
@ -34,7 +34,7 @@ class IniStore extends PreferencesStore
|
|||
/**
|
||||
* Writer which stores the preferences
|
||||
*
|
||||
* @var PreservingIniWriter
|
||||
* @var IniWriter
|
||||
*/
|
||||
protected $writer;
|
||||
|
||||
|
@ -114,9 +114,9 @@ class IniStore extends PreferencesStore
|
|||
);
|
||||
}
|
||||
|
||||
$this->writer = new PreservingIniWriter(
|
||||
$this->writer = new IniWriter(
|
||||
array(
|
||||
'config' => new Zend_Config($this->preferences),
|
||||
'config' => new Config($this->preferences),
|
||||
'filename' => $this->preferencesFile
|
||||
)
|
||||
);
|
||||
|
|
|
@ -224,6 +224,7 @@ class Translator
|
|||
}
|
||||
}
|
||||
}
|
||||
sort($codes);
|
||||
|
||||
return $codes;
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@ use Icinga\File\Pdf;
|
|||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Web\Session;
|
||||
use Icinga\Web\UrlParams;
|
||||
use Icinga\Session\SessionNamespace;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Zend_Controller_Action;
|
||||
use Zend_Controller_Action_HelperBroker as ActionHelperBroker;
|
||||
use Zend_Controller_Request_Abstract as Request;
|
||||
|
@ -325,14 +323,24 @@ class ActionController extends Zend_Controller_Action
|
|||
$this->getResponse()->setHeader('X-Icinga-Reload-Css', 'now');
|
||||
}
|
||||
|
||||
$this->shutdownSession();
|
||||
|
||||
$this->getResponse()
|
||||
->setHeader('X-Icinga-Redirect', rawurlencode($url->getAbsoluteUrl()))
|
||||
->sendHeaders();
|
||||
|
||||
// TODO: Session shutdown?
|
||||
exit;
|
||||
}
|
||||
|
||||
protected function redirectHttp($url)
|
||||
{
|
||||
if (! $url instanceof Url) {
|
||||
$url = Url::fromPath($url);
|
||||
}
|
||||
$this->shutdownSession();
|
||||
$this->_helper->Redirector->gotoUrlAndExit($url->getRelativeUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to a specific url, updating the browsers URL field
|
||||
*
|
||||
|
@ -343,10 +351,7 @@ class ActionController extends Zend_Controller_Action
|
|||
if ($this->isXhr()) {
|
||||
$this->redirectXhr($url);
|
||||
} else {
|
||||
if (! $url instanceof Url) {
|
||||
$url = Url::fromPath($url);
|
||||
}
|
||||
$this->_helper->Redirector->gotoUrlAndExit($url->getRelativeUrl());
|
||||
$this->redirectHttp($url);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -374,6 +379,7 @@ class ActionController extends Zend_Controller_Action
|
|||
|
||||
if ($req->getParam('format') === 'pdf') {
|
||||
$layout->setLayout('pdf');
|
||||
$this->shutdownSession();
|
||||
$this->sendAsPdf();
|
||||
exit;
|
||||
}
|
||||
|
@ -381,6 +387,8 @@ class ActionController extends Zend_Controller_Action
|
|||
if ($this->isXhr()) {
|
||||
$this->postDispatchXhr();
|
||||
}
|
||||
|
||||
$this->shutdownSession();
|
||||
}
|
||||
|
||||
protected function postDispatchXhr()
|
||||
|
@ -430,6 +438,14 @@ class ActionController extends Zend_Controller_Action
|
|||
$pdf->renderControllerAction($this);
|
||||
}
|
||||
|
||||
protected function shutdownSession()
|
||||
{
|
||||
$session = Session::getSession();
|
||||
if ($session->hasChanged()) {
|
||||
$session->write();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the benchmark
|
||||
*
|
||||
|
|
|
@ -100,11 +100,11 @@ class Form extends Zend_Form
|
|||
* @var array
|
||||
*/
|
||||
public static $defaultElementDecorators = array(
|
||||
'ViewHelper',
|
||||
'Errors',
|
||||
array('Description', array('tag' => 'span', 'class' => 'description')),
|
||||
'Label',
|
||||
array('HtmlTag', array('tag' => 'div'))
|
||||
array('ViewHelper', array('separator' => '')),
|
||||
array('Errors', array('separator' => '')),
|
||||
array('Description', array('tag' => 'span', 'class' => 'description', 'separator' => '')),
|
||||
array('Label', array('separator' => '')),
|
||||
array('HtmlTag', array('tag' => 'div', 'class' => 'element'))
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -463,7 +463,15 @@ class Form extends Zend_Form
|
|||
$el = parent::createElement($type, $name, $options);
|
||||
|
||||
if ($el && $el->getAttrib('autosubmit')) {
|
||||
$el->addDecorator(new NoScriptApply()); // Non-JS environments
|
||||
$noScript = new NoScriptApply(); // Non-JS environments
|
||||
$decorators = $el->getDecorators();
|
||||
$pos = array_search('Zend_Form_Decorator_ViewHelper', array_keys($decorators)) + 1;
|
||||
$el->setDecorators(
|
||||
array_slice($decorators, 0, $pos, true)
|
||||
+ array(get_class($noScript) => $noScript)
|
||||
+ array_slice($decorators, $pos, count($decorators) - $pos, true)
|
||||
);
|
||||
|
||||
$class = $el->getAttrib('class');
|
||||
if (is_array($class)) {
|
||||
$class[] = 'autosubmit';
|
||||
|
@ -473,6 +481,7 @@ class Form extends Zend_Form
|
|||
$class .= ' autosubmit';
|
||||
}
|
||||
$el->setAttrib('class', $class); // JS environments
|
||||
|
||||
unset($el->autosubmit);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Web\Form\Decorator;
|
||||
|
||||
use Zend_Form_Element;
|
||||
use Zend_Form_Decorator_Abstract;
|
||||
|
||||
/**
|
||||
* A decorator that will double a single element of a display group
|
||||
*
|
||||
* The options `condition', `double' and `attributes' can be passed to the constructor and are used to affect whether
|
||||
* the doubling should take effect, which element should be doubled and which HTML attributes should be applied to the
|
||||
* doubled element, respectively.
|
||||
*
|
||||
* `condition' must be an element's name that when it's part of the display group causes the condition to be met.
|
||||
* `double' must be an element's name and must be part of the display group.
|
||||
* `attributes' is just an array of key-value pairs.
|
||||
*
|
||||
* You can also pass `placement' to control whether the doubled element is prepended or appended.
|
||||
*/
|
||||
class ElementDoubler extends Zend_Form_Decorator_Abstract
|
||||
{
|
||||
/**
|
||||
* Return the display group's elements with an additional copy of an element being added if the condition is met
|
||||
*
|
||||
* @param string $content The HTML rendered so far
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($content)
|
||||
{
|
||||
$group = $this->getElement();
|
||||
if ($group->getElement($this->getOption('condition')) !== null) {
|
||||
if ($this->getPlacement() === static::APPEND) {
|
||||
return $content . $this->applyAttributes($group->getElement($this->getOption('double')))->render();
|
||||
} else { // $this->getPlacement() === static::PREPEND
|
||||
return $this->applyAttributes($group->getElement($this->getOption('double')))->render() . $content;
|
||||
}
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply all element attributes
|
||||
*
|
||||
* @param Zend_Form_Element $element The element to apply the attributes to
|
||||
*
|
||||
* @return Zend_Form_Element
|
||||
*/
|
||||
protected function applyAttributes(Zend_Form_Element $element)
|
||||
{
|
||||
$attributes = $this->getOption('attributes');
|
||||
if ($attributes !== null) {
|
||||
foreach ($attributes as $name => $value) {
|
||||
$element->setAttrib($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
}
|
|
@ -5,7 +5,6 @@
|
|||
namespace Icinga\Web\Form\Element;
|
||||
|
||||
use Zend_Form_Element;
|
||||
use Icinga\Web\Form;
|
||||
|
||||
/**
|
||||
* A note
|
||||
|
@ -32,7 +31,15 @@ class Note extends Zend_Form_Element
|
|||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->setDecorators(Form::$defaultElementDecorators);
|
||||
if (count($this->getDecorators()) === 0) {
|
||||
$this->setDecorators(array(
|
||||
'ViewHelper',
|
||||
array(
|
||||
'HtmlTag',
|
||||
array('tag' => 'p')
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
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
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
namespace Icinga\Web;
|
||||
|
||||
use Exception;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
|
||||
/**
|
||||
|
|
|
@ -67,7 +67,7 @@ class JavaScript
|
|||
public static function send($minified = false)
|
||||
{
|
||||
header('Content-Type: application/javascript');
|
||||
$basedir = Icinga::app()->getBootstrapDirecory();
|
||||
$basedir = Icinga::app()->getBootstrapDirectory();
|
||||
|
||||
$js = $out = '';
|
||||
$min = $minified ? '.min' : '';
|
||||
|
|
|
@ -6,10 +6,9 @@ namespace Icinga\Web;
|
|||
|
||||
use Icinga\Web\Menu\MenuItemRenderer;
|
||||
use RecursiveIterator;
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Web\Url;
|
||||
|
@ -79,10 +78,10 @@ class Menu implements RecursiveIterator
|
|||
/**
|
||||
* Create a new menu
|
||||
*
|
||||
* @param int $id The id of this menu
|
||||
* @param Zend_Config $config The configuration for this menu
|
||||
* @param int $id The id of this menu
|
||||
* @param Config $config The configuration for this menu
|
||||
*/
|
||||
public function __construct($id, Zend_Config $config = null, Menu $parent = null)
|
||||
public function __construct($id, Config $config = null, Menu $parent = null)
|
||||
{
|
||||
$this->id = $id;
|
||||
if ($parent !== null) {
|
||||
|
@ -94,7 +93,7 @@ class Menu implements RecursiveIterator
|
|||
/**
|
||||
* Set all given properties
|
||||
*
|
||||
* @param array|Zend_Config $props Property list
|
||||
* @param array|Config $props Property list
|
||||
*/
|
||||
public function setProperties($props = null)
|
||||
{
|
||||
|
@ -415,11 +414,11 @@ class Menu implements RecursiveIterator
|
|||
* Add a sub menu to this menu
|
||||
*
|
||||
* @param string $id The id of the menu to add
|
||||
* @param Zend_Config $itemConfig The config with which to initialize the menu
|
||||
* @param Config $itemConfig The config with which to initialize the menu
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function addSubMenu($id, Zend_Config $menuConfig = null)
|
||||
public function addSubMenu($id, Config $menuConfig = null)
|
||||
{
|
||||
if (false === ($pos = strpos($id, '.'))) {
|
||||
$subMenu = new self($id, $menuConfig, $this);
|
||||
|
@ -509,7 +508,7 @@ class Menu implements RecursiveIterator
|
|||
*/
|
||||
public function add($name, $config = array())
|
||||
{
|
||||
return $this->addSubMenu($name, new Zend_Config($config));
|
||||
return $this->addSubMenu($name, new Config($config));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Web\Menu;
|
||||
|
||||
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||
use Icinga\Web\Menu;
|
||||
use Icinga\Web\Url;
|
||||
|
||||
class MonitoringMenuItemRenderer implements MenuItemRenderer {
|
||||
|
||||
protected static $summary;
|
||||
|
||||
protected $columns = array();
|
||||
|
||||
protected static function summary($column = null)
|
||||
{
|
||||
if (self::$summary === null) {
|
||||
self::$summary = MonitoringBackend::instance()->select()->from(
|
||||
'statusSummary',
|
||||
array(
|
||||
'hosts_down_unhandled',
|
||||
'services_critical_unhandled'
|
||||
)
|
||||
)->getQuery()->fetchRow();
|
||||
}
|
||||
|
||||
if ($column === null) {
|
||||
return self::$summary;
|
||||
} elseif (isset(self::$summary->$column)) {
|
||||
return self::$summary->$column;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected function getBadgeTitle()
|
||||
{
|
||||
$translations = array(
|
||||
'hosts_down_unhandled' => mt('monitoring', '%d unhandled hosts down'),
|
||||
'services_critical_unhandled' => mt('monitoring', '%d unhandled services critical')
|
||||
);
|
||||
|
||||
$titles = array();
|
||||
$sum = $this->summary();
|
||||
|
||||
foreach ($this->columns as $col) {
|
||||
if (isset($sum->$col) && $sum->$col > 0) {
|
||||
$titles[] = sprintf($translations[$col], $sum->$col);
|
||||
}
|
||||
}
|
||||
|
||||
return implode(', ', $titles);
|
||||
}
|
||||
|
||||
protected function countItems()
|
||||
{
|
||||
$sum = self::summary();
|
||||
$count = 0;
|
||||
|
||||
foreach ($this->columns as $col) {
|
||||
if (isset($sum->$col)) {
|
||||
$count += $sum->$col;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
public function render(Menu $menu)
|
||||
{
|
||||
$count = $this->countItems();
|
||||
$badge = '';
|
||||
if ($count) {
|
||||
$badge = sprintf(
|
||||
'<div title="%s" class="badge-container"><span class="badge badge-critical">%s</span></div>',
|
||||
$this->getBadgeTitle(),
|
||||
$count
|
||||
);
|
||||
}
|
||||
return sprintf(
|
||||
'<a href="%s">%s%s%s</a>',
|
||||
$menu->getUrl() ?: '#',
|
||||
$menu->getIcon() ? '<img src="' . Url::fromPath($menu->getIcon()) . '" class="icon" /> ' : '',
|
||||
htmlspecialchars($menu->getTitle()),
|
||||
$badge
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,39 +1,11 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Web\Menu;
|
||||
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Web\Menu;
|
||||
use Icinga\Web\Url;
|
||||
|
||||
class ProblemMenuItemRenderer implements MenuItemRenderer {
|
||||
|
||||
public function render(Menu $menu)
|
||||
{
|
||||
$statusSummary = Backend::createBackend()
|
||||
->select()->from(
|
||||
'statusSummary',
|
||||
array(
|
||||
'hosts_down_unhandled',
|
||||
'services_critical_unhandled'
|
||||
)
|
||||
)->getQuery()->fetchRow();
|
||||
$unhandled = $statusSummary->hosts_down_unhandled + $statusSummary->services_critical_unhandled;
|
||||
$badge = '';
|
||||
if ($unhandled) {
|
||||
$badge = sprintf(
|
||||
'<div class="badge-container"><span class="badge badge-critical">%s</span></div>',
|
||||
$unhandled
|
||||
);
|
||||
}
|
||||
return sprintf(
|
||||
'<a href="%s">%s%s %s</a>',
|
||||
$menu->getUrl() ?: '#',
|
||||
$menu->getIcon() ? '<img src="' . Url::fromPath($menu->getIcon()) . '" class="icon" /> ' : '',
|
||||
htmlspecialchars($menu->getTitle()),
|
||||
$badge
|
||||
);
|
||||
}
|
||||
class ProblemMenuItemRenderer extends MonitoringMenuItemRenderer
|
||||
{
|
||||
protected $columns = array(
|
||||
'hosts_down_unhandled',
|
||||
'services_critical_unhandled'
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,38 +1,12 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Web\Menu;
|
||||
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Web\Menu;
|
||||
use Icinga\Web\Url;
|
||||
|
||||
class UnhandledHostMenuItemRenderer implements MenuItemRenderer {
|
||||
|
||||
public function render(Menu $menu)
|
||||
{
|
||||
$statusSummary = Backend::createBackend()
|
||||
->select()->from(
|
||||
'statusSummary',
|
||||
array(
|
||||
'hosts_down_unhandled'
|
||||
)
|
||||
)->getQuery()->fetchRow();
|
||||
$badge = '';
|
||||
if ($statusSummary->hosts_down_unhandled) {
|
||||
$badge = sprintf(
|
||||
'<div title="%s" class="badge-container"><span class="badge badge-critical">%s</span></div>',
|
||||
t(sprintf('%d unhandled host problems', $statusSummary->hosts_down_unhandled)),
|
||||
$statusSummary->hosts_down_unhandled
|
||||
);
|
||||
}
|
||||
return sprintf(
|
||||
'<a href="%s">%s%s %s</a>',
|
||||
$menu->getUrl() ?: '#',
|
||||
$menu->getIcon() ? '<img src="' . Url::fromPath($menu->getIcon()) . '" class="icon" /> ' : '',
|
||||
htmlspecialchars($menu->getTitle()),
|
||||
$badge
|
||||
);
|
||||
}
|
||||
class UnhandledHostMenuItemRenderer extends MonitoringMenuItemRenderer
|
||||
{
|
||||
protected $columns = array(
|
||||
'hosts_down_unhandled',
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,38 +1,12 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Web\Menu;
|
||||
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Web\Menu;
|
||||
use Icinga\Web\Url;
|
||||
|
||||
class UnhandledServiceMenuItemRenderer implements MenuItemRenderer {
|
||||
|
||||
public function render(Menu $menu)
|
||||
{
|
||||
$statusSummary = Backend::createBackend()
|
||||
->select()->from(
|
||||
'statusSummary',
|
||||
array(
|
||||
'services_critical_unhandled'
|
||||
)
|
||||
)->getQuery()->fetchRow();
|
||||
$badge = '';
|
||||
if ($statusSummary->services_critical_unhandled) {
|
||||
$badge = sprintf(
|
||||
'<div title="%s" class="badge-container"><span class="badge badge-critical">%s</span></div>',
|
||||
t(sprintf('%d unhandled service problems', $statusSummary->services_critical_unhandled)),
|
||||
$statusSummary->services_critical_unhandled
|
||||
);
|
||||
}
|
||||
return sprintf(
|
||||
'<a href="%s">%s%s %s</a>',
|
||||
$menu->getUrl() ?: '#',
|
||||
$menu->getIcon() ? '<img src="' . Url::fromPath($menu->getIcon()) . '" class="icon" /> ' : '',
|
||||
htmlspecialchars($menu->getTitle()),
|
||||
$badge
|
||||
);
|
||||
}
|
||||
class UnhandledServiceMenuItemRenderer extends MonitoringMenuItemRenderer
|
||||
{
|
||||
protected $columns = array(
|
||||
'services_critical_unhandled'
|
||||
);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace Icinga\Web;
|
|||
|
||||
use Exception;
|
||||
use RecursiveIteratorIterator;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
|
||||
/**
|
||||
* A renderer to draw a menu with its sub-menus using an unordered html list
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace Icinga\Web;
|
|||
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Application\Platform;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Web\Session;
|
||||
|
||||
/**
|
||||
|
@ -75,35 +75,28 @@ class Notification
|
|||
return;
|
||||
}
|
||||
|
||||
$mo = (object) array(
|
||||
$messages = & Session::getSession()->getByRef('messages');
|
||||
$messages[] = (object) array(
|
||||
'type' => $type,
|
||||
'message' => $message,
|
||||
);
|
||||
|
||||
// Get, change, set - just to be on the safe side:
|
||||
$session = Session::getSession();
|
||||
$msgs = $session->messages;
|
||||
$msgs[] = $mo;
|
||||
$session->messages = $msgs;
|
||||
$session->write();
|
||||
}
|
||||
|
||||
public function hasMessages()
|
||||
{
|
||||
$session = Session::getSession();
|
||||
return !empty($session->messages);
|
||||
return false === empty($session->messages);
|
||||
}
|
||||
|
||||
public function getMessages()
|
||||
{
|
||||
$session = Session::getSession();
|
||||
$msgs = $session->messages;
|
||||
if (false === empty($msgs)) {
|
||||
$messages = $session->messages;
|
||||
if (false === empty($messages)) {
|
||||
$session->messages = array();
|
||||
$session->write();
|
||||
}
|
||||
|
||||
return $msgs;
|
||||
return $messages;
|
||||
}
|
||||
|
||||
final private function __construct()
|
||||
|
|
|
@ -21,6 +21,12 @@ class Response extends Zend_Controller_Response_Http
|
|||
} else {
|
||||
$this->setRedirect($url->getAbsoluteUrl());
|
||||
}
|
||||
|
||||
$session = Session::getSession();
|
||||
if ($session->hasChanged()) {
|
||||
$session->write();
|
||||
}
|
||||
|
||||
$this->sendHeaders();
|
||||
exit;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Icinga\Web\Session;
|
||||
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
|
||||
/**
|
||||
|
@ -121,7 +121,7 @@ class PhpSession extends Session
|
|||
|
||||
foreach ($_SESSION as $key => $value) {
|
||||
if (strpos($key, self::NAMESPACE_PREFIX) === 0) {
|
||||
$namespace = new SessionNamespace($this);
|
||||
$namespace = new SessionNamespace();
|
||||
$namespace->setAll($value);
|
||||
$this->namespaces[substr($key, strlen(self::NAMESPACE_PREFIX))] = $namespace;
|
||||
} else {
|
||||
|
|
|
@ -75,7 +75,7 @@ abstract class Session extends SessionNamespace
|
|||
unset($this->removedNamespaces[array_search($identifier, $this->removedNamespaces)]);
|
||||
}
|
||||
|
||||
$this->namespaces[$identifier] = new SessionNamespace($this);
|
||||
$this->namespaces[$identifier] = new SessionNamespace();
|
||||
}
|
||||
|
||||
return $this->namespaces[$identifier];
|
||||
|
@ -104,13 +104,22 @@ abstract class Session extends SessionNamespace
|
|||
$this->removedNamespaces[] = $identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the session has changed
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasChanged()
|
||||
{
|
||||
return parent::hasChanged() || false === empty($this->namespaces) || false === empty($this->removedNamespaces);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all values and namespaces from the session cache
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->values = array();
|
||||
$this->removed = array();
|
||||
parent::clear();
|
||||
$this->namespaces = array();
|
||||
$this->removedNamespaces = array();
|
||||
}
|
||||
|
|
|
@ -14,13 +14,6 @@ use IteratorAggregate;
|
|||
*/
|
||||
class SessionNamespace implements IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* The session this namespace is associated to
|
||||
*
|
||||
* @var Session
|
||||
*/
|
||||
protected $session;
|
||||
|
||||
/**
|
||||
* The actual values stored in this container
|
||||
*
|
||||
|
@ -35,16 +28,6 @@ class SessionNamespace implements IteratorAggregate
|
|||
*/
|
||||
protected $removed = array();
|
||||
|
||||
/**
|
||||
* Create a new session namespace
|
||||
*
|
||||
* @param Session $session The session this namespace is associated to
|
||||
*/
|
||||
public function __construct(Session $session = null)
|
||||
{
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an iterator for all values in this namespace
|
||||
*
|
||||
|
@ -120,7 +103,18 @@ class SessionNamespace implements IteratorAggregate
|
|||
$this->values[$key] = $value;
|
||||
|
||||
if (in_array($key, $this->removed)) {
|
||||
unset($this->removed[array_search($key, $this->values)]);
|
||||
unset($this->removed[array_search($key, $this->removed)]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setByRef($key, &$value)
|
||||
{
|
||||
$this->values[$key] = & $value;
|
||||
|
||||
if (in_array($key, $this->removed)) {
|
||||
unset($this->removed[array_search($key, $this->removed)]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
@ -139,6 +133,16 @@ class SessionNamespace implements IteratorAggregate
|
|||
return isset($this->values[$key]) ? $this->values[$key] : $default;
|
||||
}
|
||||
|
||||
public function & getByRef($key, $default = null)
|
||||
{
|
||||
$value = $default;
|
||||
if (isset($this->values[$key])) {
|
||||
$value = & $this->values[$key];
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the given value from the session
|
||||
*
|
||||
|
@ -177,14 +181,21 @@ class SessionNamespace implements IteratorAggregate
|
|||
}
|
||||
|
||||
/**
|
||||
* Save the session this namespace is associated to
|
||||
* Return whether the session namespace has been changed
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function write()
|
||||
public function hasChanged()
|
||||
{
|
||||
if (!$this->session) {
|
||||
throw new IcingaException('Cannot save, session not set');
|
||||
}
|
||||
return false === empty($this->values) || false === empty($this->removed);
|
||||
}
|
||||
|
||||
$this->session->write();
|
||||
/**
|
||||
* Clear all values from the session namespace
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->values = array();
|
||||
$this->removed = array();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ class StyleSheet
|
|||
'css/icinga/main-content.less',
|
||||
'css/icinga/tabs.less',
|
||||
'css/icinga/forms.less',
|
||||
'css/icinga/setup.less',
|
||||
'css/icinga/widgets.less',
|
||||
'css/icinga/pagination.less',
|
||||
'css/icinga/monitoring-colors.less',
|
||||
|
@ -30,7 +31,7 @@ class StyleSheet
|
|||
public static function compileForPdf()
|
||||
{
|
||||
$less = new LessCompiler();
|
||||
$basedir = Icinga::app()->getBootstrapDirecory();
|
||||
$basedir = Icinga::app()->getBootstrapDirectory();
|
||||
foreach (self::$lessFiles as $file) {
|
||||
$less->addFile($basedir . '/' . $file);
|
||||
}
|
||||
|
@ -56,7 +57,7 @@ class StyleSheet
|
|||
public static function send($minified = false)
|
||||
{
|
||||
$app = Icinga::app();
|
||||
$basedir = $app->getBootstrapDirecory();
|
||||
$basedir = $app->getBootstrapDirectory();
|
||||
foreach (self::$lessFiles as $file) {
|
||||
$lessFiles[] = $basedir . '/' . $file;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace Icinga\Web\Widget\Chart;
|
|||
use Icinga\Web\Widget\AbstractWidget;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Util\Format;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
|
||||
/**
|
||||
* A SVG-PieChart intended to be displayed as a small icon next to labels, to offer a better visualization of the
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
namespace Icinga\Web\Widget;
|
||||
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Application\Config as IcingaConfig;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Web\Widget\Dashboard\Pane;
|
||||
|
@ -26,7 +26,7 @@ class Dashboard extends AbstractWidget
|
|||
/**
|
||||
* The configuration containing information about this dashboard
|
||||
*
|
||||
* @var IcingaConfig;
|
||||
* @var Config;
|
||||
*/
|
||||
private $config;
|
||||
|
||||
|
@ -140,11 +140,11 @@ class Dashboard extends AbstractWidget
|
|||
/**
|
||||
* Populate this dashboard via the given configuration file
|
||||
*
|
||||
* @param IcingaConfig $config The configuration file to populate this dashboard with
|
||||
* @param Config $config The configuration file to populate this dashboard with
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function readConfig(IcingaConfig $config)
|
||||
public function readConfig(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->panes = array();
|
||||
|
|
|
@ -4,16 +4,12 @@
|
|||
|
||||
namespace Icinga\Web\Widget\Dashboard;
|
||||
|
||||
use Icinga\Exception\IcingaException;
|
||||
use Icinga\Util\Dimension;
|
||||
use Zend_Form_Element_Button;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Web\Widget\AbstractWidget;
|
||||
use Icinga\Web\View;
|
||||
use Zend_Config;
|
||||
use Zend_Form_Element_Submit;
|
||||
use Zend_Form_Element_Button;
|
||||
use Exception;
|
||||
use Icinga\Exception\IcingaException;
|
||||
|
||||
/**
|
||||
* A dashboard pane component
|
||||
|
@ -218,13 +214,13 @@ EOD;
|
|||
/**
|
||||
* Create a @see Component instance from the given Zend config, using the provided title
|
||||
*
|
||||
* @param $title The title for this component
|
||||
* @param Zend_Config $config The configuration defining url, parameters, height, width, etc.
|
||||
* @param Pane $pane The pane this component belongs to
|
||||
* @param $title The title for this component
|
||||
* @param Config $config The configuration defining url, parameters, height, width, etc.
|
||||
* @param Pane $pane The pane this component belongs to
|
||||
*
|
||||
* @return Component A newly created Component for use in the Dashboard
|
||||
* @return Component A newly created Component for use in the Dashboard
|
||||
*/
|
||||
public static function fromIni($title, Zend_Config $config, Pane $pane)
|
||||
public static function fromIni($title, Config $config, Pane $pane)
|
||||
{
|
||||
$height = null;
|
||||
$width = null;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Icinga\Web\Widget\Dashboard;
|
||||
|
||||
use Zend_Config;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Web\Widget\AbstractWidget;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
|
@ -253,11 +253,11 @@ class Pane extends AbstractWidget
|
|||
* Create a new pane with the title $title from the given configuration
|
||||
*
|
||||
* @param $title The title for this pane
|
||||
* @param Zend_Config $config The configuration to use for setup
|
||||
* @param Config $config The configuration to use for setup
|
||||
*
|
||||
* @return Pane
|
||||
*/
|
||||
public static function fromIni($title, Zend_Config $config)
|
||||
public static function fromIni($title, Config $config)
|
||||
{
|
||||
$pane = new Pane($title);
|
||||
if ($config->get('title', false)) {
|
||||
|
|
|
@ -201,7 +201,7 @@ class Tab extends AbstractWidget
|
|||
$caption = $view->escape($this->title);
|
||||
|
||||
if ($this->icon !== null) {
|
||||
$caption = $view->img($this->icon, array('class' => 'icon')) . ' ' . $caption;
|
||||
$caption = $view->img($this->icon, array('class' => 'icon')) . $caption;
|
||||
}
|
||||
if ($this->url !== null) {
|
||||
$this->url->overwriteParams($this->urlParams);
|
||||
|
|
|
@ -0,0 +1,522 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Web;
|
||||
|
||||
use LogicException;
|
||||
use InvalidArgumentException;
|
||||
use Icinga\Web\Session\SessionNamespace;
|
||||
use Icinga\Web\Form\Decorator\ElementDoubler;
|
||||
|
||||
/**
|
||||
* Container and controller for form based wizards
|
||||
*/
|
||||
class Wizard
|
||||
{
|
||||
/**
|
||||
* An integer describing the wizard's forward direction
|
||||
*/
|
||||
const FORWARD = 0;
|
||||
|
||||
/**
|
||||
* An integer describing the wizard's backward direction
|
||||
*/
|
||||
const BACKWARD = 1;
|
||||
|
||||
/**
|
||||
* An integer describing that the wizard does not change its position
|
||||
*/
|
||||
const NO_CHANGE = 2;
|
||||
|
||||
/**
|
||||
* The name of the button to advance the wizard's position
|
||||
*/
|
||||
const BTN_NEXT = 'btn_next';
|
||||
|
||||
/**
|
||||
* The name of the button to rewind the wizard's position
|
||||
*/
|
||||
const BTN_PREV = 'btn_prev';
|
||||
|
||||
/**
|
||||
* The name of the wizard's current page
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $currentPage;
|
||||
|
||||
/**
|
||||
* The pages being part of this wizard
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $pages = array();
|
||||
|
||||
/**
|
||||
* Initialize a new wizard
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run additional initialization routines
|
||||
*
|
||||
* Should be implemented by subclasses to add pages to the wizard.
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the pages being part of this wizard
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPages()
|
||||
{
|
||||
return $this->pages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the page with the given name
|
||||
*
|
||||
* @param string $name The name of the page to return
|
||||
*
|
||||
* @return null|Form The page or null in case there is no page with the given name
|
||||
*/
|
||||
public function getPage($name)
|
||||
{
|
||||
foreach ($this->getPages() as $page) {
|
||||
if ($name === $page->getName()) {
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new page to this wizard
|
||||
*
|
||||
* @param Form $page The page to add to the wizard
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function addPage(Form $page)
|
||||
{
|
||||
$this->pages[] = $page;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add multiple pages to this wizard
|
||||
*
|
||||
* @param array $pages The pages to add to the wizard
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function addPages(array $pages)
|
||||
{
|
||||
foreach ($pages as $page) {
|
||||
$this->addPage($page);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that this wizard has any pages
|
||||
*
|
||||
* @throws LogicException In case this wizard has no pages
|
||||
*/
|
||||
protected function assertHasPages()
|
||||
{
|
||||
$pages = $this->getPages();
|
||||
if (count($pages) < 2) {
|
||||
throw new LogicException("Although Chuck Norris can advance a wizard with less than two pages, you can't.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current page of this wizard
|
||||
*
|
||||
* @return Form
|
||||
*
|
||||
* @throws LogicException In case the name of the current page currently being set is invalid
|
||||
*/
|
||||
public function getCurrentPage()
|
||||
{
|
||||
if ($this->currentPage === null) {
|
||||
$this->assertHasPages();
|
||||
$pages = $this->getPages();
|
||||
$this->currentPage = $this->getSession()->get('current_page', $pages[0]->getName());
|
||||
}
|
||||
|
||||
if (($page = $this->getPage($this->currentPage)) === null) {
|
||||
throw new LogicException(sprintf('No page found with name "%s"', $this->currentPage));
|
||||
}
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current page of this wizard
|
||||
*
|
||||
* @param Form $page The page to set as current page
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setCurrentPage(Form $page)
|
||||
{
|
||||
$this->currentPage = $page->getName();
|
||||
$this->getSession()->set('current_page', $this->currentPage);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the given page that is either going to be displayed or validated
|
||||
*
|
||||
* Implement this method in a subclass to populate default values and/or other data required to process the form.
|
||||
*
|
||||
* @param Form $page The page to setup
|
||||
* @param Request $request The current request
|
||||
*/
|
||||
public function setupPage(Form $page, Request $request)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the given request using this wizard
|
||||
*
|
||||
* Validate the request data using the current page, update the wizard's
|
||||
* position and redirect to the page's redirect url upon success.
|
||||
*
|
||||
* @param Request $request The request to be processed
|
||||
*
|
||||
* @return Request The request supposed to be processed
|
||||
*/
|
||||
public function handleRequest(Request $request = null)
|
||||
{
|
||||
$page = $this->getCurrentPage();
|
||||
|
||||
if ($request === null) {
|
||||
$request = $page->getRequest();
|
||||
}
|
||||
|
||||
$this->setupPage($page, $request);
|
||||
$requestData = $page->getRequestData($request);
|
||||
if ($page->wasSent($requestData)) {
|
||||
if (($requestedPage = $this->getRequestedPage($requestData)) !== null) {
|
||||
$isValid = false;
|
||||
$direction = $this->getDirection($request);
|
||||
if ($direction === static::FORWARD && $page->isValid($requestData)) {
|
||||
$isValid = true;
|
||||
if ($this->isLastPage($page)) {
|
||||
$this->setIsFinished();
|
||||
}
|
||||
} elseif ($direction === static::BACKWARD) {
|
||||
$page->populate($requestData);
|
||||
$isValid = true;
|
||||
}
|
||||
|
||||
if ($isValid) {
|
||||
$pageData = & $this->getPageData();
|
||||
$pageData[$page->getName()] = $page->getValues();
|
||||
$this->setCurrentPage($this->getNewPage($requestedPage, $page));
|
||||
$page->getResponse()->redirectAndExit($page->getRedirectUrl());
|
||||
}
|
||||
} else {
|
||||
$page->isValidPartial($requestData);
|
||||
}
|
||||
} elseif (($pageData = $this->getPageData($page->getName())) !== null) {
|
||||
$page->populate($pageData);
|
||||
}
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the requested page
|
||||
*
|
||||
* @param array $requestData The request's data
|
||||
*
|
||||
* @return null|string The name of the requested page or null in case no page has been requested
|
||||
*/
|
||||
protected function getRequestedPage(array $requestData)
|
||||
{
|
||||
if (isset($requestData[static::BTN_NEXT])) {
|
||||
return $requestData[static::BTN_NEXT];
|
||||
} elseif (isset($requestData[static::BTN_PREV])) {
|
||||
return $requestData[static::BTN_PREV];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the direction of this wizard using the given request
|
||||
*
|
||||
* @param Request $request The request to use
|
||||
*
|
||||
* @return int The direction @see Wizard::FORWARD @see Wizard::BACKWARD @see Wizard::NO_CHANGE
|
||||
*/
|
||||
protected function getDirection(Request $request = null)
|
||||
{
|
||||
$currentPage = $this->getCurrentPage();
|
||||
|
||||
if ($request === null) {
|
||||
$request = $currentPage->getRequest();
|
||||
}
|
||||
|
||||
$requestData = $currentPage->getRequestData($request);
|
||||
if (isset($requestData[static::BTN_NEXT])) {
|
||||
return static::FORWARD;
|
||||
} elseif (isset($requestData[static::BTN_PREV])) {
|
||||
return static::BACKWARD;
|
||||
}
|
||||
|
||||
return static::NO_CHANGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the new page to set as current page
|
||||
*
|
||||
* Permission is checked by verifying that the requested page's previous page has page data available.
|
||||
* The requested page is automatically permitted without any checks if the origin page is its previous
|
||||
* page or one that occurs later in order.
|
||||
*
|
||||
* @param string $requestedPage The name of the requested page
|
||||
* @param Form $originPage The origin page
|
||||
*
|
||||
* @return Form The new page
|
||||
*
|
||||
* @throws InvalidArgumentException In case the requested page does not exist or is not permitted yet
|
||||
*/
|
||||
protected function getNewPage($requestedPage, Form $originPage)
|
||||
{
|
||||
if (($page = $this->getPage($requestedPage)) !== null) {
|
||||
$permitted = true;
|
||||
|
||||
$pages = $this->getPages();
|
||||
if (($index = array_search($page, $pages, true)) > 0) {
|
||||
$previousPage = $pages[$index - 1];
|
||||
if ($originPage === null || ($previousPage->getName() !== $originPage->getName()
|
||||
&& array_search($originPage, $pages, true) < $index))
|
||||
{
|
||||
$permitted = $this->hasPageData($previousPage->getName());
|
||||
}
|
||||
}
|
||||
|
||||
if ($permitted) {
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('"%s" is either an unknown page or one you are not permitted to view', $requestedPage)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the given page is this wizard's last page
|
||||
*
|
||||
* @param Form $page The page to check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isLastPage(Form $page)
|
||||
{
|
||||
$pages = $this->getPages();
|
||||
return $page->getName() === end($pages)->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this wizard has been completed
|
||||
*
|
||||
* @param bool $state Whether this wizard has been completed
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setIsFinished($state = true)
|
||||
{
|
||||
$this->getSession()->set('isFinished', $state);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this wizard has been completed
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isFinished()
|
||||
{
|
||||
return $this->getSession()->get('isFinished', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the overall page data or one for a particular page
|
||||
*
|
||||
* Note that this method returns by reference so in order to update the
|
||||
* returned array set this method's return value also by reference.
|
||||
*
|
||||
* @param string $pageName The page for which to return the data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function & getPageData($pageName = null)
|
||||
{
|
||||
$session = $this->getSession();
|
||||
|
||||
if (false === isset($session->page_data)) {
|
||||
$session->page_data = array();
|
||||
}
|
||||
|
||||
$pageData = & $session->getByRef('page_data');
|
||||
if ($pageName !== null) {
|
||||
$data = null;
|
||||
if (isset($pageData[$pageName])) {
|
||||
$data = & $pageData[$pageName];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
return $pageData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether there is any data for the given page
|
||||
*
|
||||
* @param string $pageName The name of the page to check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPageData($pageName)
|
||||
{
|
||||
return $this->getPageData($pageName) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a session to be used by this wizard
|
||||
*
|
||||
* @return SessionNamespace
|
||||
*/
|
||||
public function getSession()
|
||||
{
|
||||
return Session::getSession()->getNamespace(get_class($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the session being used by this wizard
|
||||
*/
|
||||
public function clearSession()
|
||||
{
|
||||
$this->getSession()->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add buttons to the given page based on its position in the page-chain
|
||||
*
|
||||
* @param Form $page The page to add the buttons to
|
||||
*/
|
||||
protected function addButtons(Form $page)
|
||||
{
|
||||
$pages = $this->getPages();
|
||||
$index = array_search($page, $pages, true);
|
||||
if ($index === 0) {
|
||||
$page->addElement(
|
||||
'button',
|
||||
static::BTN_NEXT,
|
||||
array(
|
||||
'type' => 'submit',
|
||||
'value' => $pages[1]->getName(),
|
||||
'label' => t('Next'),
|
||||
'decorators' => array('ViewHelper')
|
||||
)
|
||||
);
|
||||
} elseif ($index < count($pages) - 1) {
|
||||
$page->addElement(
|
||||
'button',
|
||||
static::BTN_PREV,
|
||||
array(
|
||||
'type' => 'submit',
|
||||
'value' => $pages[$index - 1]->getName(),
|
||||
'label' => t('Back'),
|
||||
'decorators' => array('ViewHelper')
|
||||
)
|
||||
);
|
||||
$page->addElement(
|
||||
'button',
|
||||
static::BTN_NEXT,
|
||||
array(
|
||||
'type' => 'submit',
|
||||
'value' => $pages[$index + 1]->getName(),
|
||||
'label' => t('Next'),
|
||||
'decorators' => array('ViewHelper')
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$page->addElement(
|
||||
'button',
|
||||
static::BTN_PREV,
|
||||
array(
|
||||
'type' => 'submit',
|
||||
'value' => $pages[$index - 1]->getName(),
|
||||
'label' => t('Back'),
|
||||
'decorators' => array('ViewHelper')
|
||||
)
|
||||
);
|
||||
$page->addElement(
|
||||
'button',
|
||||
static::BTN_NEXT,
|
||||
array(
|
||||
'type' => 'submit',
|
||||
'value' => $page->getName(),
|
||||
'label' => t('Finish'),
|
||||
'decorators' => array('ViewHelper')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$page->addDisplayGroup(
|
||||
array(static::BTN_PREV, static::BTN_NEXT),
|
||||
'buttons',
|
||||
array(
|
||||
'decorators' => array(
|
||||
'FormElements',
|
||||
new ElementDoubler(array(
|
||||
'double' => static::BTN_NEXT,
|
||||
'condition' => static::BTN_PREV,
|
||||
'placement' => ElementDoubler::PREPEND,
|
||||
'attributes' => array('tabindex' => -1, 'class' => 'double')
|
||||
)),
|
||||
array('HtmlTag', array('tag' => 'div', 'class' => 'buttons'))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current page of this wizard with appropriate buttons being added
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
public function getForm()
|
||||
{
|
||||
$form = $this->getCurrentPage();
|
||||
$form->create(); // Make sure that buttons are displayed at the very bottom
|
||||
$this->addButtons($form);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current page of this wizard rendered as HTML
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return (string) $this->getForm();
|
||||
}
|
||||
}
|
|
@ -4,22 +4,19 @@
|
|||
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Module\Monitoring\Form\Command\DisableNotificationWithExpireForm;
|
||||
use Icinga\Module\Monitoring\Form\Command\SingleArgumentCommandForm;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Web\Notification;
|
||||
use Icinga\Module\Monitoring\Controller;
|
||||
use Icinga\Protocol\Commandpipe\CommandPipe;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\MissingParameterException;
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Module\Monitoring\Form\Command\AcknowledgeForm;
|
||||
use Icinga\Module\Monitoring\Form\Command\CommentForm;
|
||||
use Icinga\Module\Monitoring\Form\Command\CommandForm;
|
||||
use Icinga\Module\Monitoring\Form\Command\CommandWithIdentifierForm;
|
||||
use Icinga\Module\Monitoring\Form\Command\CustomNotificationForm;
|
||||
use Icinga\Module\Monitoring\Form\Command\DelayNotificationForm;
|
||||
use Icinga\Module\Monitoring\Form\Command\RescheduleNextCheckForm;
|
||||
|
|
|
@ -296,7 +296,7 @@ class Monitoring_ListController extends Controller
|
|||
->order('downtime_scheduled_start', 'DESC');
|
||||
|
||||
$this->applyFilters($query);
|
||||
$this->view->downtimes = $query->paginate();
|
||||
|
||||
$this->setupSortControl(array(
|
||||
'downtime_is_in_effect' => $this->translate('Is In Effect'),
|
||||
'downtime_host' => $this->translate('Host / Service'),
|
||||
|
@ -308,6 +308,8 @@ class Monitoring_ListController extends Controller
|
|||
'downtime_scheduled_end' => $this->translate('Scheduled End'),
|
||||
'downtime_duration' => $this->translate('Duration'),
|
||||
));
|
||||
|
||||
$this->view->downtimes = $query->paginate();
|
||||
$this->view->delDowntimeForm = new DeleteDowntimeCommandForm();
|
||||
}
|
||||
|
||||
|
@ -570,12 +572,12 @@ class Monitoring_ListController extends Controller
|
|||
$this->view->history = $query->paginate();
|
||||
}
|
||||
|
||||
public function servicematrixAction()
|
||||
public function servicegridAction()
|
||||
{
|
||||
if ($url = $this->hasBetterUrl()) {
|
||||
return $this->redirectNow($url);
|
||||
}
|
||||
$this->addTitleTab('servicematrix');
|
||||
$this->addTitleTab('servicegrid', $this->translate('Service Grid'));
|
||||
$this->setAutorefreshInterval(15);
|
||||
$query = $this->backend->select()->from('serviceStatus', array(
|
||||
'host_name',
|
||||
|
|
|
@ -4,16 +4,13 @@
|
|||
|
||||
use \DateTime;
|
||||
use \DateInterval;
|
||||
use \Zend_Config;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Util\Format;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
use Icinga\Module\Monitoring\Controller;
|
||||
use Icinga\Module\Monitoring\Timeline\TimeLine;
|
||||
use Icinga\Module\Monitoring\Timeline\TimeRange;
|
||||
use Icinga\Module\Monitoring\Web\Widget\SelectBox;
|
||||
use Icinga\Module\Monitoring\DataView\EventHistory as EventHistoryView;
|
||||
|
||||
class Monitoring_TimelineController extends Controller
|
||||
{
|
||||
|
@ -257,22 +254,6 @@ class Monitoring_TimelineController extends Controller
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the application's global configuration or an empty one
|
||||
*
|
||||
* @return Zend_Config
|
||||
*/
|
||||
private function getGlobalConfiguration()
|
||||
{
|
||||
$globalConfig = Config::app()->global;
|
||||
|
||||
if ($globalConfig === null) {
|
||||
$globalConfig = new Zend_Config(array());
|
||||
}
|
||||
|
||||
return $globalConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's preferred time format or the application's default
|
||||
*
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Form\Command;
|
||||
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||
use Icinga\Module\Monitoring\Command\Transport\CommandTransport;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Web\Request;
|
||||
|
@ -24,11 +24,11 @@ abstract class CommandForm extends Form
|
|||
/**
|
||||
* Set the monitoring backend
|
||||
*
|
||||
* @param Backend $backend
|
||||
* @param MonitoringBackend $backend
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBackend(Backend $backend)
|
||||
public function setBackend(MonitoringBackend $backend)
|
||||
{
|
||||
$this->backend = $backend;
|
||||
return $this;
|
||||
|
|
|
@ -225,15 +225,31 @@ class BackendConfigForm extends ConfigForm
|
|||
'value' => $resourceType
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
|
||||
$resourceElement = $this->createElement(
|
||||
'select',
|
||||
'resource',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => mt('monitoring', 'Resource'),
|
||||
'description' => mt('monitoring', 'The resource to use'),
|
||||
'multiOptions' => $this->resources[$resourceType]
|
||||
'multiOptions' => $this->resources[$resourceType],
|
||||
'autosubmit' => true
|
||||
)
|
||||
);
|
||||
|
||||
$resourceName = (isset($formData['resource'])) ? $formData['resource'] : $this->getValue('resource');
|
||||
if ($resourceElement) {
|
||||
$resourceElement->getDecorator('Description')->setEscape(false);
|
||||
$link = sprintf(
|
||||
'<a href="%s" data-base-target="_main">%s</a>',
|
||||
$this->getView()->href('/icingaweb/config/editresource', array('resource' => $resourceName)),
|
||||
mt('monitoring', 'Show resource configuration')
|
||||
);
|
||||
$resourceElement->setDescription($resourceElement->getDescription() . ' (' . $link . ')');
|
||||
}
|
||||
|
||||
$this->addElement($resourceElement);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,8 @@ class SecurityConfigForm extends ConfigForm
|
|||
'text',
|
||||
'protected_customvars',
|
||||
array(
|
||||
'required' => true,
|
||||
'allowEmpty' => true,
|
||||
'value' => '*pw*,*pass*,community',
|
||||
'label' => mt('monitoring', 'Protected Custom Variables'),
|
||||
'description' => mt('monitoring',
|
||||
'Comma separated case insensitive list of protected custom variables.'
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Form\Setup;
|
||||
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Web\Form\Element\Note;
|
||||
use Icinga\Application\Platform;
|
||||
|
||||
class BackendPage extends Form
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$this->setName('setup_monitoring_backend');
|
||||
}
|
||||
|
||||
public function createElements(array $formData)
|
||||
{
|
||||
$this->addElement(
|
||||
new Note(
|
||||
'title',
|
||||
array(
|
||||
'value' => mt('monitoring', 'Monitoring Backend', 'setup.page.title'),
|
||||
'decorators' => array(
|
||||
'ViewHelper',
|
||||
array('HtmlTag', array('tag' => 'h2'))
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
new Note(
|
||||
'description',
|
||||
array(
|
||||
'value' => mt(
|
||||
'monitoring',
|
||||
'Please configure below how Icinga Web 2 should retrieve monitoring information.'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'name',
|
||||
array(
|
||||
'required' => true,
|
||||
'value' => 'icinga',
|
||||
'label' => mt('monitoring', 'Backend Name'),
|
||||
'description' => mt('monitoring', 'The identifier of this backend')
|
||||
)
|
||||
);
|
||||
|
||||
$resourceTypes = array();
|
||||
if (Platform::extensionLoaded('mysql') || Platform::extensionLoaded('pgsql')) {
|
||||
$resourceTypes['ido'] = 'IDO';
|
||||
}
|
||||
$resourceTypes['livestatus'] = 'Livestatus';
|
||||
|
||||
$this->addElement(
|
||||
'select',
|
||||
'type',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => mt('monitoring', 'Backend Type'),
|
||||
'description' => mt('monitoring', 'The data source used for retrieving monitoring information'),
|
||||
'multiOptions' => $resourceTypes
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue