commit
c27c0bdf6e
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
namespace Icinga\Clicommands;
|
||||
|
||||
|
@ -117,3 +118,4 @@ class AutocompleteCommand extends Command
|
|||
}
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
namespace Icinga\Clicommands;
|
||||
|
||||
|
@ -40,3 +41,4 @@ class HelpCommand extends Command
|
|||
);
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
namespace Icinga\Clicommands;
|
||||
|
||||
|
@ -211,3 +212,4 @@ class ModuleCommand extends Command
|
|||
$this->fail("Not implemented yet");
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
namespace Icinga\Clicommands;
|
||||
|
||||
|
@ -80,3 +81,4 @@ class WebCommand extends Command
|
|||
}
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -138,3 +139,4 @@ class AuthenticationController extends ActionController
|
|||
}
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -31,17 +31,14 @@ use \Icinga\Web\Controller\BaseConfigController;
|
|||
use \Icinga\Web\Widget\Tab;
|
||||
use \Icinga\Web\Widget\AlertMessageBox;
|
||||
use \Icinga\Web\Url;
|
||||
use \Icinga\Web\Hook\Configuration\ConfigurationTabBuilder;
|
||||
use \Icinga\User\Message;
|
||||
use \Icinga\Application\Icinga;
|
||||
use \Icinga\Application\Config as IcingaConfig;
|
||||
use \Icinga\Data\ResourceFactory;
|
||||
use \Icinga\Form\Config\GeneralForm;
|
||||
use \Icinga\Authentication\Manager as AuthenticationManager;
|
||||
use \Icinga\Form\Config\Authentication\ReorderForm;
|
||||
use \Icinga\Form\Config\Authentication\LdapBackendForm;
|
||||
use \Icinga\Form\Config\Authentication\DbBackendForm;
|
||||
use \Icinga\Form\Config\Resource\EditResourceForm;
|
||||
use \Icinga\Form\Config\Resource\ResourceForm;
|
||||
use \Icinga\Form\Config\LoggingForm;
|
||||
use \Icinga\Form\Config\ConfirmRemovalForm;
|
||||
use \Icinga\Config\PreservingIniWriter;
|
||||
|
@ -207,36 +204,38 @@ class ConfigController extends BaseConfigController
|
|||
/**
|
||||
* Action for creating a new authentication backend
|
||||
*/
|
||||
public function authenticationAction($showOnly = false)
|
||||
public function authenticationAction()
|
||||
{
|
||||
$config = IcingaConfig::app('authentication', true);
|
||||
$this->view->tabs->activate('authentication');
|
||||
|
||||
$order = array_keys($config->toArray());
|
||||
$this->view->backends = array();
|
||||
$this->view->messageBox = new AlertMessageBox(true);
|
||||
|
||||
foreach ($config as $backend=>$backendConfig) {
|
||||
$backends = array();
|
||||
foreach ($order as $backend) {
|
||||
$form = new ReorderForm();
|
||||
$form->setName('form_reorder_backend_' . $backend);
|
||||
$form->setAuthenticationBackend($backend);
|
||||
$form->setBackendName($backend);
|
||||
$form->setCurrentOrder($order);
|
||||
$form->setRequest($this->_request);
|
||||
|
||||
if (!$showOnly && $form->isSubmittedAndValid()) {
|
||||
if ($form->isSubmittedAndValid()) {
|
||||
if ($this->writeAuthenticationFile($form->getReorderedConfig($config))) {
|
||||
$this->addSuccessMessage('Authentication Order Updated');
|
||||
$this->redirectNow('config/authentication');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->view->backends[] = (object) array(
|
||||
'name' => $backend,
|
||||
'reorderForm' => $form
|
||||
$backends[] = (object) array(
|
||||
'name' => $backend,
|
||||
'reorderForm' => $form
|
||||
);
|
||||
}
|
||||
$this->render('authentication');
|
||||
|
||||
$this->view->backends = $backends;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -398,7 +397,7 @@ class ConfigController extends BaseConfigController
|
|||
{
|
||||
$this->view->resourceTypes = $this->resourceTypes;
|
||||
$resources = IcingaConfig::app('resources', true);
|
||||
$form = new EditResourceForm();
|
||||
$form = new ResourceForm();
|
||||
$form->setRequest($this->_request);
|
||||
if ($form->isSubmittedAndValid()) {
|
||||
$name = $form->getName();
|
||||
|
@ -430,7 +429,7 @@ class ConfigController extends BaseConfigController
|
|||
$this->render('resource/modify');
|
||||
return;
|
||||
}
|
||||
$form = new EditResourceForm();
|
||||
$form = new ResourceForm();
|
||||
if ($this->_request->isPost() === false) {
|
||||
$form->setOldName($name);
|
||||
$form->setName($name);
|
||||
|
@ -558,4 +557,4 @@ class ConfigController extends BaseConfigController
|
|||
}
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -142,4 +142,4 @@ class DashboardController extends ActionController
|
|||
$this->view->dashboard = $dashboard;
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -77,4 +77,4 @@ class ErrorController extends ActionController
|
|||
$this->view->request = $error->request;
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -26,7 +27,6 @@
|
|||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// @codingStandardsIgnoreStart
|
||||
|
||||
use Icinga\Web\Controller\ActionController;
|
||||
use Icinga\Filter\Filter;
|
||||
|
@ -117,4 +117,4 @@ class FilterController extends ActionController
|
|||
}
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -61,4 +61,4 @@ class IndexController extends ActionController
|
|||
{
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
|
@ -43,4 +43,4 @@ class LayoutController extends ActionController
|
|||
$this->renderScript('parts/topbar.phtml');
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -79,4 +79,4 @@ class ListController extends Controller
|
|||
}
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -83,4 +83,4 @@ class PreferenceController extends BasePreferenceController
|
|||
$this->view->form = $form;
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
* Icinga (http://www.icinga.org)
|
||||
*
|
||||
* @copyright 2014 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.icinga.org/license/gpl2 GPL, version 2
|
||||
*/
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
use Icinga\Web\Controller\ActionController;
|
||||
use Icinga\Application\Icinga;
|
||||
|
@ -50,3 +45,4 @@ class SearchController extends ActionController
|
|||
$this->view->tabs = $dashboard->getTabs();
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -185,4 +185,4 @@ class StaticController extends ActionController
|
|||
$lessCompiler->printStack();
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -76,3 +77,4 @@ class LoginForm extends Form
|
|||
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -30,9 +30,10 @@
|
|||
namespace Icinga\Form\Config\Authentication;
|
||||
|
||||
use \Zend_Config;
|
||||
use \Icinga\Web\Form\Decorator\HelpText;
|
||||
use \Icinga\Data\ResourceFactory;
|
||||
use \Icinga\Web\Form;
|
||||
use \Zend_Form_Element_Checkbox;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Web\Form\Decorator\HelpText;
|
||||
|
||||
/**
|
||||
* Base form for authentication backend forms
|
||||
|
@ -46,26 +47,26 @@ abstract class BaseBackendForm extends Form
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $backendName = '';
|
||||
protected $backendName = '';
|
||||
|
||||
/**
|
||||
* The backend configuration as a Zend_Config object
|
||||
*
|
||||
* @var Zend_Config
|
||||
*/
|
||||
private $backend;
|
||||
protected $backend;
|
||||
|
||||
/**
|
||||
* The resources to use instead of the factory provided ones (use for testing)
|
||||
*
|
||||
* @var Zend_Config
|
||||
*/
|
||||
private $resources;
|
||||
protected $resources;
|
||||
|
||||
/**
|
||||
* Set the name of the currently displayed backend
|
||||
*
|
||||
* @param string $name The name to be stored as the section when persisting
|
||||
* @param string $name The name to be stored as the section when persisting
|
||||
*/
|
||||
public function setBackendName($name)
|
||||
{
|
||||
|
@ -75,7 +76,7 @@ abstract class BaseBackendForm extends Form
|
|||
/**
|
||||
* Return the backend name of this form
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getBackendName()
|
||||
{
|
||||
|
@ -85,7 +86,7 @@ abstract class BaseBackendForm extends Form
|
|||
/**
|
||||
* Return the backend configuration or a empty Zend_Config object if none is given
|
||||
*
|
||||
* @return Zend_Config
|
||||
* @return Zend_Config
|
||||
*/
|
||||
public function getBackend()
|
||||
{
|
||||
|
@ -95,7 +96,7 @@ abstract class BaseBackendForm extends Form
|
|||
/**
|
||||
* Set the backend configuration for initial population
|
||||
*
|
||||
* @param Zend_Config $backend The backend to display in this form
|
||||
* @param Zend_Config $backend The backend to display in this form
|
||||
*/
|
||||
public function setBackend(Zend_Config $backend)
|
||||
{
|
||||
|
@ -104,9 +105,8 @@ abstract class BaseBackendForm extends Form
|
|||
|
||||
/**
|
||||
* Set an alternative array of resources that should be used instead of the DBFactory resource set
|
||||
* (used for testing)
|
||||
*
|
||||
* @param array $resources The resources to use for populating the db selection field
|
||||
* @param array $resources The resources to use for populating the db selection field
|
||||
*/
|
||||
public function setResources(array $resources)
|
||||
{
|
||||
|
@ -114,9 +114,9 @@ abstract class BaseBackendForm extends Form
|
|||
}
|
||||
|
||||
/**
|
||||
* Return content of the resources.ini or previously set resources for displaying in the database selection field
|
||||
* Return content of the resources.ini or previously set resources
|
||||
*
|
||||
* @return array
|
||||
* @return array
|
||||
*/
|
||||
public function getResources()
|
||||
{
|
||||
|
@ -130,13 +130,13 @@ abstract class BaseBackendForm extends Form
|
|||
/**
|
||||
* Add checkbox at the beginning of the form which allows to skip logic connection validation
|
||||
*/
|
||||
private function addForceCreationCheckbox()
|
||||
protected function addForceCreationCheckbox()
|
||||
{
|
||||
$checkbox = new \Zend_Form_Element_Checkbox(
|
||||
$checkbox = new Zend_Form_Element_Checkbox(
|
||||
array(
|
||||
'name' => 'backend_force_creation',
|
||||
'label' => 'Force Changes',
|
||||
'helptext' => 'Check this box to enforce changes without connectivity validation',
|
||||
'label' => t('Force Changes'),
|
||||
'helptext' => t('Check this box to enforce changes without connectivity validation'),
|
||||
'order' => 0
|
||||
)
|
||||
);
|
||||
|
@ -150,16 +150,16 @@ abstract class BaseBackendForm extends Form
|
|||
* If logic validation fails, the 'backend_force_creation' checkbox is prepended to the form to allow users to
|
||||
* skip the logic connection validation.
|
||||
*
|
||||
* @param array $data The form input to validate
|
||||
* @param array $data The form input to validate
|
||||
*
|
||||
* @return bool True when validation succeeded, false if not
|
||||
* @return bool Whether validation succeeded or not
|
||||
*/
|
||||
public function isValid($data)
|
||||
{
|
||||
if (!parent::isValid($data)) {
|
||||
return false;
|
||||
}
|
||||
if ($this->getRequest()->getPost('backend_force_creation')) {
|
||||
if (isset($data['backend_force_creation']) && $data['backend_force_creation']) {
|
||||
return true;
|
||||
}
|
||||
if (!$this->isValidAuthenticationBackend()) {
|
||||
|
@ -173,7 +173,7 @@ abstract class BaseBackendForm extends Form
|
|||
* Return an array containing all sections defined by this form as the key and all settings
|
||||
* as an key-value sub-array
|
||||
*
|
||||
* @return array
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getConfig();
|
||||
|
||||
|
@ -183,7 +183,7 @@ abstract class BaseBackendForm extends Form
|
|||
* An implementation should not throw any exception, but use the add/setErrorMessages method of
|
||||
* Zend_Form. If the 'backend_force_creation' checkbox is set, this method won't be called.
|
||||
*
|
||||
* @return bool True when validation succeeded, otherwise false
|
||||
* @return bool Whether validation succeeded or not
|
||||
*/
|
||||
abstract public function isValidAuthenticationBackend();
|
||||
}
|
||||
|
|
|
@ -29,8 +29,10 @@
|
|||
|
||||
namespace Icinga\Form\Config\Authentication;
|
||||
|
||||
use \Icinga\Authentication\Backend\DbUserBackend;
|
||||
use \Exception;
|
||||
use \Zend_Config;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Authentication\UserBackend;
|
||||
|
||||
/**
|
||||
* Form class for adding/modifying database authentication backends
|
||||
|
@ -38,21 +40,23 @@ use \Zend_Config;
|
|||
class DbBackendForm extends BaseBackendForm
|
||||
{
|
||||
/**
|
||||
* Return a list of all database resource ready to be used as the multiOptions
|
||||
* attribute in a Zend_Form_Element_Select object
|
||||
* Return content of the resources.ini or previously set resources
|
||||
*
|
||||
* @return array
|
||||
* @return array
|
||||
*/
|
||||
private function getDatabaseResources()
|
||||
public function getResources()
|
||||
{
|
||||
$backends = array();
|
||||
foreach ($this->getResources() as $resname => $resource) {
|
||||
if ($resource['type'] !== 'db') {
|
||||
continue;
|
||||
if ($this->resources === null) {
|
||||
$res = ResourceFactory::getResourceConfigs('db')->toArray();
|
||||
|
||||
foreach (array_keys($res) as $key) {
|
||||
$res[$key] = $key;
|
||||
}
|
||||
$backends[$resname] = $resname;
|
||||
|
||||
return $res;
|
||||
} else {
|
||||
return $this->resources;
|
||||
}
|
||||
return $backends;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,9 +74,9 @@ class DbBackendForm extends BaseBackendForm
|
|||
'backend_' . $name . '_name',
|
||||
array(
|
||||
'required' => true,
|
||||
'allowEmpty' => false,
|
||||
'label' => 'Backend Name',
|
||||
'helptext' => 'The name of this authentication provider',
|
||||
'allowEmpty' => false,
|
||||
'label' => t('Backend Name'),
|
||||
'helptext' => t('The name of this authentication provider'),
|
||||
'value' => $this->getBackendName()
|
||||
)
|
||||
);
|
||||
|
@ -81,12 +85,12 @@ class DbBackendForm extends BaseBackendForm
|
|||
'select',
|
||||
'backend_' . $name . '_resource',
|
||||
array(
|
||||
'label' => 'Database Connection',
|
||||
'required' => true,
|
||||
'allowEmpty' => false,
|
||||
'helptext' => 'The database connection to use for authenticating with this provider',
|
||||
'value' => $this->getBackend()->get('resource'),
|
||||
'multiOptions' => $this->getDatabaseResources()
|
||||
'required' => true,
|
||||
'allowEmpty' => false,
|
||||
'label' => t('Database Connection'),
|
||||
'helptext' => t('The database connection to use for authenticating with this provider'),
|
||||
'value' => $this->getBackend()->get('resource'),
|
||||
'multiOptions' => $this->getResources()
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -112,53 +116,39 @@ class DbBackendForm extends BaseBackendForm
|
|||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
$name = $this->getBackendName();
|
||||
$prefix = 'backend_' . $this->filterName($name) . '_';
|
||||
|
||||
$prefix = 'backend_' . $this->filterName($this->getBackendName()) . '_';
|
||||
$section = $this->getValue($prefix . 'name');
|
||||
$cfg = array(
|
||||
'backend' => 'db',
|
||||
'target' => 'user',
|
||||
'resource' => $this->getValue($prefix . 'resource'),
|
||||
);
|
||||
return array(
|
||||
$section => $cfg
|
||||
'backend' => 'db',
|
||||
'resource' => $this->getValue($prefix . 'resource'),
|
||||
);
|
||||
|
||||
return array($section => $cfg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the current configuration by creating a backend and requesting the user count
|
||||
*
|
||||
* @return bool True when the backend is valid, false otherwise
|
||||
* @return bool Whether validation succeeded or not
|
||||
*
|
||||
* @see BaseBackendForm::isValidAuthenticationBackend
|
||||
*/
|
||||
public function isValidAuthenticationBackend()
|
||||
{
|
||||
// @TODO fix validation of authentication backends (AK #5712)
|
||||
return true;
|
||||
try {
|
||||
$name = $this->getBackendName();
|
||||
$dbBackend = new DbUserBackend(
|
||||
new Zend_Config(
|
||||
array(
|
||||
'backend' => 'db',
|
||||
'target' => 'user',
|
||||
'resource' => $this->getValue('backend_' . $this->filterName($name) . '_resource'),
|
||||
)
|
||||
)
|
||||
);
|
||||
$dbBackend->connect();
|
||||
if ($dbBackend->getUserCount() < 1) {
|
||||
$this->addErrorMessage("No users found under the specified database backend");
|
||||
$cfg = $this->getConfig();
|
||||
$backendName = key($cfg);
|
||||
$testConn = UserBackend::create($backendName, new Zend_Config($cfg[$backendName]));
|
||||
|
||||
if ($testConn->count() === 0) {
|
||||
$this->addErrorMessage(t('No users found under the specified database backend'));
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->addErrorMessage("Using the specified backend failed: " . $e->getMessage());
|
||||
return false;
|
||||
} catch (\Zend_Db_Statement_Exception $e) {
|
||||
$this->addErrorMessage("Using the specified backend failed: " . $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
$this->addErrorMessage(sprintf(t('Using the specified backend failed: %s'), $e->getMessage()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,11 +30,10 @@
|
|||
namespace Icinga\Form\Config\Authentication;
|
||||
|
||||
use \Exception;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use \Zend_Config;
|
||||
use \Icinga\Web\Form;
|
||||
use \Icinga\Authentication\Backend\LdapUserBackend;
|
||||
use \Icinga\Protocol\Ldap\Connection as LdapConnection;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Authentication\UserBackend;
|
||||
|
||||
/**
|
||||
* Form for adding or modifying LDAP authentication backends
|
||||
|
@ -42,14 +41,31 @@ use \Icinga\Protocol\Ldap\Connection as LdapConnection;
|
|||
class LdapBackendForm extends BaseBackendForm
|
||||
{
|
||||
/**
|
||||
* Create this form and add all required elements
|
||||
* Return content of the resources.ini or previously set resources
|
||||
*
|
||||
* @param $options Only useful for testing purposes:
|
||||
* 'resources' => All available resources.
|
||||
* @return array
|
||||
*/
|
||||
public function getResources()
|
||||
{
|
||||
if ($this->resources === null) {
|
||||
$res = ResourceFactory::getResourceConfigs('ldap')->toArray();
|
||||
|
||||
foreach (array_keys($res) as $key) {
|
||||
$res[$key] = $key;
|
||||
}
|
||||
|
||||
return $res;
|
||||
} else {
|
||||
return $this->resources;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create this form and add all required elements
|
||||
*
|
||||
* @see Form::create()
|
||||
*/
|
||||
public function create($options = array())
|
||||
public function create()
|
||||
{
|
||||
$this->setName('form_modify_backend');
|
||||
$name = $this->filterName($this->getBackendName());
|
||||
|
@ -57,12 +73,12 @@ class LdapBackendForm extends BaseBackendForm
|
|||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'backend_'.$name.'_name',
|
||||
'backend_' . $name . '_name',
|
||||
array(
|
||||
'required' => true,
|
||||
'allowEmpty' => false,
|
||||
'label' => 'Backend Name',
|
||||
'helptext' => 'The name of this authentication backend',
|
||||
'allowEmpty' => false,
|
||||
'label' => t('Backend Name'),
|
||||
'helptext' => t('The name of this authentication backend'),
|
||||
'value' => $this->getBackendName()
|
||||
)
|
||||
);
|
||||
|
@ -71,13 +87,12 @@ class LdapBackendForm extends BaseBackendForm
|
|||
'select',
|
||||
'backend_' . $name . '_resource',
|
||||
array(
|
||||
'label' => 'Database Connection',
|
||||
'required' => true,
|
||||
'allowEmpty' => false,
|
||||
'helptext' => 'The database connection to use for authenticating with this provider',
|
||||
'value' => $this->getBackend()->get('resource'),
|
||||
'multiOptions' => array_key_exists('resources', $options) ?
|
||||
$options['resources'] : $this->getLdapResources()
|
||||
'required' => true,
|
||||
'allowEmpty' => false,
|
||||
'label' => t('LDAP Resource'),
|
||||
'helptext' => t('The resource to use for authenticating with this provider'),
|
||||
'value' => $this->getBackend()->get('resource'),
|
||||
'multiOptions' => $this->getResources()
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -85,10 +100,10 @@ class LdapBackendForm extends BaseBackendForm
|
|||
'text',
|
||||
'backend_' . $name . '_user_class',
|
||||
array(
|
||||
'label' => 'LDAP User Object Class',
|
||||
'value' => $backend->get('user_class', 'inetOrgPerson'),
|
||||
'helptext' => 'The object class used for storing users on the ldap server',
|
||||
'required' => true
|
||||
'required' => true,
|
||||
'label' => t('LDAP User Object Class'),
|
||||
'helptext' => t('The object class used for storing users on the ldap server'),
|
||||
'value' => $backend->get('user_class', 'inetOrgPerson')
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -96,10 +111,10 @@ class LdapBackendForm extends BaseBackendForm
|
|||
'text',
|
||||
'backend_' . $name . '_user_name_attribute',
|
||||
array(
|
||||
'label' => 'LDAP User Name Attribute',
|
||||
'value' => $backend->get('user_name_attribute', 'uid'),
|
||||
'helptext' => 'The attribute name used for storing the user name on the ldap server',
|
||||
'required' => true
|
||||
'required' => true,
|
||||
'label' => t('LDAP User Name Attribute'),
|
||||
'helptext' => t('The attribute name used for storing the user name on the ldap server'),
|
||||
'value' => $backend->get('user_name_attribute', 'uid')
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -125,52 +140,41 @@ class LdapBackendForm extends BaseBackendForm
|
|||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
$name = $this->getBackendName();
|
||||
$prefix = 'backend_' . $this->filterName($name) . '_';
|
||||
|
||||
$prefix = 'backend_' . $this->filterName($this->getBackendName()) . '_';
|
||||
$section = $this->getValue($prefix . 'name');
|
||||
$cfg = array(
|
||||
'target' => 'user',
|
||||
'resource' => $this->getValue($prefix . 'resource'),
|
||||
'user_class' => $this->getValue($prefix . 'user_class'),
|
||||
'user_name_attribute' => $this->getValue($prefix . 'user_name_attribute')
|
||||
);
|
||||
return array(
|
||||
$section => $cfg
|
||||
'backend' => 'ldap',
|
||||
'resource' => $this->getValue($prefix . 'resource'),
|
||||
'user_class' => $this->getValue($prefix . 'user_class'),
|
||||
'user_name_attribute' => $this->getValue($prefix . 'user_name_attribute')
|
||||
);
|
||||
|
||||
return array($section => $cfg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the current configuration by creating a backend and requesting the user count
|
||||
*
|
||||
* @return bool True when the backend is valid, false otherwise
|
||||
* @return bool Whether validation succeeded or not
|
||||
*
|
||||
* @see BaseBackendForm::isValidAuthenticationBacken
|
||||
*/
|
||||
public function isValidAuthenticationBackend()
|
||||
{
|
||||
try {
|
||||
$cfg = $this->getConfig();
|
||||
$backendName = 'backend_' . $this->filterName($this->getBackendName()) . '_name';
|
||||
$backendConfig = new Zend_Config($cfg[$this->getValue($backendName)]);
|
||||
$testConn = new LdapUserBackend($backendConfig);
|
||||
if ($testConn->getUserCount() === 0) {
|
||||
throw new Exception('No Users Found On Directory Server');
|
||||
$backendName = key($cfg);
|
||||
$testConn = UserBackend::create($backendName, new Zend_Config($cfg[$backendName]));
|
||||
|
||||
if ($testConn->count() === 0) {
|
||||
$this->addErrorMessage(t('No users found on directory server'));
|
||||
return false;
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$this->addErrorMessage(
|
||||
'Connection Validation Failed:' . $exc->getMessage()
|
||||
);
|
||||
$this->addErrorMessage(sprintf(t('Connection validation failed: %s'), $exc->getMessage()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getLdapResources()
|
||||
{
|
||||
$res = ResourceFactory::getResourceConfigs('ldap')->toArray();
|
||||
foreach ($res as $key => $value) {
|
||||
$res[$key] = $key;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,12 +30,10 @@
|
|||
namespace Icinga\Form\Config\Authentication;
|
||||
|
||||
use \Zend_Config;
|
||||
use \Icinga\Web\Form;
|
||||
use \Icinga\Web\Url;
|
||||
use Icinga\Web\Form;
|
||||
|
||||
/**
|
||||
* Form for modifying the authentication provider order.
|
||||
*
|
||||
* Form for modifying the authentication provider order
|
||||
*/
|
||||
class ReorderForm extends Form
|
||||
{
|
||||
|
@ -44,19 +42,20 @@ class ReorderForm extends Form
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $backend = null;
|
||||
protected $backend;
|
||||
|
||||
/**
|
||||
* The current ordering of all backends, required to determine possible changes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $currentOrder = array();
|
||||
protected $currentOrder = array();
|
||||
|
||||
/**
|
||||
* Set an array with the current order of all backends
|
||||
*
|
||||
* @param array $order An array containing backend names in the order they are defined in the authentication.ini
|
||||
* @param array $order An array containing backend names in the order
|
||||
* they are defined in the authentication.ini
|
||||
*/
|
||||
public function setCurrentOrder(array $order)
|
||||
{
|
||||
|
@ -66,20 +65,17 @@ class ReorderForm extends Form
|
|||
/**
|
||||
* Set the name of the authentication backend for which to create the form
|
||||
*
|
||||
* @param string $backend The name of the authentication backend
|
||||
* @param string $backend The name of the authentication backend
|
||||
*/
|
||||
public function setAuthenticationBackend($backend)
|
||||
public function setBackendName($backend)
|
||||
{
|
||||
$this->backend = $backend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the currently set backend as it will appear in the forms
|
||||
* Return the name of the currently set backend as it will appear in the form
|
||||
*
|
||||
* This calls the Zend Filtername function in order to filter specific chars
|
||||
*
|
||||
* @return string The filtered name of the backend
|
||||
* @see Form::filterName()
|
||||
* @return string The name of the backend
|
||||
*/
|
||||
public function getBackendName()
|
||||
{
|
||||
|
@ -87,28 +83,24 @@ class ReorderForm extends Form
|
|||
}
|
||||
|
||||
/**
|
||||
* Create this form.
|
||||
*
|
||||
* Note: The form action will be set here to the authentication overview
|
||||
* Create this form
|
||||
*
|
||||
* @see Form::create
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$this->upForm = new Form();
|
||||
$this->downForm = new Form();
|
||||
|
||||
if ($this->moveElementUp($this->backend, $this->currentOrder) !== $this->currentOrder) {
|
||||
$upForm = new Form();
|
||||
|
||||
$this->upForm->addElement(
|
||||
$upForm->addElement(
|
||||
'hidden',
|
||||
'form_backend_order',
|
||||
array(
|
||||
'required' => true,
|
||||
'value' => join(',', $this->moveElementUp($this->backend, $this->currentOrder))
|
||||
'value' => join(',', $this->moveElementUp($this->backend, $this->currentOrder))
|
||||
)
|
||||
);
|
||||
$this->upForm->addElement(
|
||||
$upForm->addElement(
|
||||
'button',
|
||||
'btn_' . $this->getBackendName() . '_reorder_up',
|
||||
array(
|
||||
|
@ -116,21 +108,25 @@ class ReorderForm extends Form
|
|||
'escape' => false,
|
||||
'value' => 'btn_' . $this->getBackendName() . '_reorder_up',
|
||||
'name' => 'btn_' . $this->getBackendName() . '_reorder_up',
|
||||
'label' => $this->getView()->icon('up.png', 'Move up in authentication order'),
|
||||
'label' => $this->getView()->icon('up.png', t('Move up in authentication order'))
|
||||
)
|
||||
);
|
||||
|
||||
$this->addSubForm($upForm, 'btn_reorder_up');
|
||||
}
|
||||
|
||||
if ($this->moveElementDown($this->backend, $this->currentOrder) !== $this->currentOrder) {
|
||||
$this->downForm->addElement(
|
||||
$downForm = new Form();
|
||||
|
||||
$downForm->addElement(
|
||||
'hidden',
|
||||
'form_backend_order',
|
||||
array(
|
||||
'required' => true,
|
||||
'value' => join(',', $this->moveElementDown($this->backend, $this->currentOrder))
|
||||
'value' => join(',', $this->moveElementDown($this->backend, $this->currentOrder))
|
||||
)
|
||||
);
|
||||
$this->downForm->addElement(
|
||||
$downForm->addElement(
|
||||
'button',
|
||||
'btn_' . $this->getBackendName() . '_reorder_down',
|
||||
array(
|
||||
|
@ -138,72 +134,68 @@ class ReorderForm extends Form
|
|||
'escape' => false,
|
||||
'value' => 'btn_' . $this->getBackendName() . '_reorder_down',
|
||||
'name' => 'btn_' . $this->getBackendName() . '_reorder_down',
|
||||
'label' => $this->getView()->icon('down.png', 'Move down in authentication order'),
|
||||
|
||||
'label' => $this->getView()->icon('down.png', t('Move down in authentication order'))
|
||||
)
|
||||
);
|
||||
|
||||
$this->addSubForm($downForm, 'btn_reorder_down');
|
||||
}
|
||||
$this->setAction(Url::fromPath("config/authentication", array())->getAbsoluteUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the result of $this->getValues but flatten the result
|
||||
* Return the flattened result of $this->getValues
|
||||
*
|
||||
* The result will be a key=>value array without subarrays
|
||||
* @return array The currently set values
|
||||
*
|
||||
* @param bool $supressArrayNotation passed to getValues
|
||||
*
|
||||
* @return array The currently set values
|
||||
* @see Form::getValues()
|
||||
*/
|
||||
public function getFlattenedValues($supressArrayNotation = false)
|
||||
protected function getFlattenedValues()
|
||||
{
|
||||
$values = parent::getValues($supressArrayNotation);
|
||||
$result = array();
|
||||
foreach ($values as $key => &$value) {
|
||||
foreach (parent::getValues() as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$result += $value;
|
||||
} else {
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether this form is submitted by testing the submit buttons of both subforms
|
||||
*
|
||||
* @return bool True when the form is submitted, otherwise false
|
||||
* @return bool Whether the form has been submitted or not
|
||||
*/
|
||||
public function isSubmitted()
|
||||
{
|
||||
$checkData = $this->getRequest()->getParams();
|
||||
return isset ($checkData['btn_' . $this->getBackendName() . '_reorder_up']) ||
|
||||
isset ($checkData['btn_' . $this->getBackendName() . '_reorder_down']);
|
||||
return isset($checkData['btn_' . $this->getBackendName() . '_reorder_up']) ||
|
||||
isset($checkData['btn_' . $this->getBackendName() . '_reorder_down']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the reordered configuration after a reorder button has been submited
|
||||
* Return the reordered configuration after a reorder button has been submitted
|
||||
*
|
||||
* @param Zend_Config $config The configuration to reorder
|
||||
* @param Zend_Config $config The configuration to reorder
|
||||
*
|
||||
* @return array An array containing the reordered configuration
|
||||
* @return array An array containing the reordered configuration
|
||||
*/
|
||||
public function getReorderedConfig(Zend_Config $config)
|
||||
{
|
||||
$originalConfig = $config->toArray();
|
||||
$reordered = array();
|
||||
$newOrder = $this->getFlattenedValues();
|
||||
$order = explode(',', $newOrder['form_backend_order']);
|
||||
|
||||
$reordered = array();
|
||||
foreach ($order as $key) {
|
||||
if (!isset($originalConfig[$key])) {
|
||||
continue;
|
||||
if (isset($originalConfig[$key])) {
|
||||
$reordered[$key] = $originalConfig[$key];
|
||||
}
|
||||
$reordered[$key] = $originalConfig[$key];
|
||||
}
|
||||
|
||||
return $reordered;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -216,28 +208,27 @@ class ReorderForm extends Form
|
|||
* moveElementUp('third', $array); // returns ['first', 'third', 'second']
|
||||
* </pre>
|
||||
*
|
||||
* @param string $key The key to bubble up one slot
|
||||
* @param array $array The array to work with
|
||||
* @param string $key The key to bubble up one slot
|
||||
* @param array $array The array to work with
|
||||
*
|
||||
* @return array The modified array
|
||||
* @return array The modified array
|
||||
*/
|
||||
private static function moveElementUp($key, array $array)
|
||||
protected static function moveElementUp($key, array $array)
|
||||
{
|
||||
$swap = null;
|
||||
for ($i=0; $i<count($array)-1; $i++) {
|
||||
if ($array[$i+1] !== $key) {
|
||||
continue;
|
||||
for ($i = 0; $i < count($array) - 1; $i++) {
|
||||
if ($array[$i + 1] === $key) {
|
||||
$swap = $array[$i];
|
||||
$array[$i] = $array[$i + 1];
|
||||
$array[$i + 1] = $swap;
|
||||
return $array;
|
||||
}
|
||||
$swap = $array[$i];
|
||||
$array[$i] = $array[$i+1];
|
||||
$array[$i+1] = $swap;
|
||||
return $array;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Static helper for moving an element in an array one slot up, if possible
|
||||
* Static helper for moving an element in an array one slot down, if possible
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
|
@ -246,23 +237,22 @@ class ReorderForm extends Form
|
|||
* moveElementDown('first', $array); // returns ['second', 'first', 'third']
|
||||
* </pre>
|
||||
*
|
||||
* @param string $key The key to bubble up one slot
|
||||
* @param array $array The array to work with
|
||||
* @param string $key The key to bubble up one slot
|
||||
* @param array $array The array to work with
|
||||
*
|
||||
* @return array The modified array
|
||||
* @return array The modified array
|
||||
*/
|
||||
private static function moveElementDown($key, array $array)
|
||||
protected static function moveElementDown($key, array $array)
|
||||
{
|
||||
$swap = null;
|
||||
for ($i=0; $i<count($array)-1; $i++) {
|
||||
if ($array[$i] !== $key) {
|
||||
continue;
|
||||
for ($i = 0; $i < count($array) - 1; $i++) {
|
||||
if ($array[$i] === $key) {
|
||||
$swap = $array[$i + 1];
|
||||
$array[$i + 1] = $array[$i];
|
||||
$array[$i] = $swap;
|
||||
return $array;
|
||||
}
|
||||
$swap = $array[$i+1];
|
||||
$array[$i+1] = $array[$i];
|
||||
$array[$i] = $swap;
|
||||
return $array;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -92,3 +93,4 @@ class ConfirmRemovalForm extends Form
|
|||
);
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -439,3 +440,4 @@ class GeneralForm extends Form
|
|||
return $cfg;
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -212,3 +213,4 @@ class LoggingForm extends Form
|
|||
return new Zend_Config($cfg);
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Monitoring\Form\Config\Backend;
|
||||
|
||||
use Icinga\Module\Monitoring\Form\Config\Backend\EditResourceForm;
|
||||
|
||||
class CreateResourceForm extends EditResourceForm
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -1,462 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Form\Config\Resource;
|
||||
|
||||
use \Zend_Config;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Web\Form\Decorator\HelpText;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
|
||||
/**
|
||||
* Form for modifying a monitoring backend
|
||||
*/
|
||||
class EditResourceForm extends Form
|
||||
{
|
||||
/**
|
||||
* The currently edited resource.
|
||||
*
|
||||
* @var Zend_Config
|
||||
*/
|
||||
private $resource;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $oldName = '';
|
||||
|
||||
/**
|
||||
* Return the current resource name.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return void|\Zend_Form
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->getValue('resource_all_name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the original name of the resource. This value is persisted using
|
||||
* a hidden field.
|
||||
*
|
||||
* @param $name
|
||||
*/
|
||||
public function setOldName($name)
|
||||
{
|
||||
$this->oldName = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the resource name that was initially set.
|
||||
*/
|
||||
public function getOldName()
|
||||
{
|
||||
return $this->getValue('resource_all_name_old');
|
||||
}
|
||||
|
||||
private function addDbForm()
|
||||
{
|
||||
$this->addElement(
|
||||
'select',
|
||||
'resource_db_db',
|
||||
array(
|
||||
'label' => 'Database Type',
|
||||
'value' => $this->getResource()->get('db', 'mysql'),
|
||||
'required' => true,
|
||||
'helptext' => 'The type of SQL database you want to create.',
|
||||
'multiOptions' => array(
|
||||
'mysql' => 'MySQL',
|
||||
'pgsql' => 'PostgreSQL'
|
||||
//'oracle' => 'Oracle'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_db_host',
|
||||
array (
|
||||
'label' => 'Host',
|
||||
'value' => $this->getResource()->get('host', 'localhost'),
|
||||
'required' => true,
|
||||
'helptext' => 'The hostname of the database.'
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_db_port',
|
||||
array(
|
||||
'label' => 'Port',
|
||||
'value' => $this->getResource()->get('port', 3306),
|
||||
'required' => true,
|
||||
'validators' => array(
|
||||
array('regex', false, '/^[0-9]+$/')
|
||||
),
|
||||
'helptext' => 'The port number to use.'
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_db_dbname',
|
||||
array(
|
||||
'label' => 'Database Name',
|
||||
'value' => $this->getResource()->get('dbname', ''),
|
||||
'required' => true,
|
||||
'helptext' => 'The name of the database to use'
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_db_username',
|
||||
array (
|
||||
'label' => 'Username',
|
||||
'value' => $this->getResource()->get('username', ''),
|
||||
'required' => true,
|
||||
'helptext' => 'The user name to use for authentication.'
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'password',
|
||||
'resource_db_password',
|
||||
array(
|
||||
'label' => 'Password',
|
||||
'renderPassword' => true,
|
||||
'value' => $this->getResource()->get('password', ''),
|
||||
'helptext' => 'The password to use for authentication',
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function addStatusdatForm()
|
||||
{
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_statusdat_status_file',
|
||||
array(
|
||||
'label' => 'Status.dat File',
|
||||
'value' => $this->getResource()->get('status_file', '/usr/local/icinga/var/status.dat'),
|
||||
'required' => true,
|
||||
'helptext' => 'Location of your icinga status.dat file'
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_statusdat_object_file',
|
||||
array(
|
||||
'label' => 'Objects.cache File',
|
||||
'value' => $this->getResource()->get('status_file', '/usr/local/icinga/var/objects.cache'),
|
||||
'required' => true,
|
||||
'helptext' => 'Location of your icinga objects.cache file'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function addLivestatusForm()
|
||||
{
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_livestatus_socket',
|
||||
array(
|
||||
'label' => 'Livestatus Socket Location',
|
||||
'required' => true,
|
||||
'helptext' => 'The path to your livestatus socket used for querying monitoring data',
|
||||
'value' => $this->getResource()->socket,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function addLdapForm()
|
||||
{
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_ldap_hostname',
|
||||
array(
|
||||
'label' => 'LDAP Server Host',
|
||||
'allowEmpty' => false,
|
||||
'value' => $this->getResource()->get('hostname', 'localhost'),
|
||||
'helptext' => 'The hostname or address of the LDAP server to use for authentication',
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_ldap_root_dn',
|
||||
array(
|
||||
'label' => 'LDAP Root DN',
|
||||
'value' => $this->getResource()->get('root_dn', 'ou=people,dc=icinga,dc=org'),
|
||||
'helptext' => 'The path where users can be found on the ldap server',
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_ldap_bind_dn',
|
||||
array(
|
||||
'label' => 'LDAP Bind DN',
|
||||
'value' => $this->getResource()->get('bind_dn', 'cn=admin,cn=config'),
|
||||
'helptext' => 'The user dn to use for querying the ldap server',
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'password',
|
||||
'resource_ldap_bind_pw',
|
||||
array(
|
||||
'label' => 'LDAP Bind Password',
|
||||
'renderPassword' => true,
|
||||
'value' => $this->getResource()->get('bind_pw', ''),
|
||||
'helptext' => 'The password to use for querying the ldap server',
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the resource configuration to edit.
|
||||
*
|
||||
* @param Zend_Config $resource
|
||||
*/
|
||||
public function setResource(Zend_Config $resource)
|
||||
{
|
||||
$this->resource = $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current resource configuration.
|
||||
*
|
||||
* @return Zend_Config
|
||||
*/
|
||||
public function getResource()
|
||||
{
|
||||
if (!isset($this->resource)) {
|
||||
// Init empty resource
|
||||
$this->resource = new Zend_Config(
|
||||
array('type' => 'db')
|
||||
);
|
||||
}
|
||||
return $this->resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a field to change the resource name and one hidden field
|
||||
* to save the previous resource name.
|
||||
*/
|
||||
private function addNameFields()
|
||||
{
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_all_name',
|
||||
array(
|
||||
'label' => 'Resource Name',
|
||||
'value' => $this->name,
|
||||
'helptext' => 'The unique name of this resource',
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
'hidden',
|
||||
'resource_all_name_old',
|
||||
array(
|
||||
'value' => $this->oldName
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add checkbox at the beginning of the form which allows to skip logic connection validation
|
||||
*/
|
||||
private function addForceCreationCheckbox()
|
||||
{
|
||||
$checkbox = new \Zend_Form_Element_Checkbox(
|
||||
array(
|
||||
'name' => 'backend_force_creation',
|
||||
'label' => 'Force Changes',
|
||||
'helptext' => 'Check this box to enforce changes without connectivity validation',
|
||||
'order' => 0
|
||||
)
|
||||
);
|
||||
$checkbox->addDecorator(new HelpText());
|
||||
$this->addElement($checkbox);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a select box for choosing the type to use for this backend
|
||||
*/
|
||||
private function addTypeSelectionBox()
|
||||
{
|
||||
$this->addElement(
|
||||
'select',
|
||||
'resource_type',
|
||||
array(
|
||||
'label' => 'Resource Type',
|
||||
'value' => $this->getResource()->type,
|
||||
'required' => true,
|
||||
'helptext' => 'The type of resource.',
|
||||
'multiOptions' => array(
|
||||
'db' => 'SQL Database',
|
||||
'ldap' => 'Ldap',
|
||||
'statusdat' => 'Status.dat',
|
||||
'livestatus' => 'Livestatus'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->enableAutoSubmit(array('resource_type'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate this form with the Zend validation mechanism and perform a validation of the connection.
|
||||
*
|
||||
* If validation fails, the 'backend_force_creation' checkbox is prepended to the form to allow users to
|
||||
* skip the logic connection validation.
|
||||
*
|
||||
* @param array $data The form input to validate
|
||||
*
|
||||
* @return bool True when validation succeeded, false if not
|
||||
*/
|
||||
public function isValid($data)
|
||||
{
|
||||
if (!parent::isValid($data)) {
|
||||
return false;
|
||||
}
|
||||
if ($this->getRequest()->getPost('backend_force_creation')) {
|
||||
return true;
|
||||
}
|
||||
if (!$this->isValidResource()) {
|
||||
$this->addForceCreationCheckbox();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the changed resource is a valid resource, by instantiating it and
|
||||
* checking if connection is possible.
|
||||
*
|
||||
* @return bool True when connection to the resource is possible.
|
||||
*/
|
||||
private function isValidResource()
|
||||
{
|
||||
try {
|
||||
$config = $this->getConfig();
|
||||
switch ($config->type) {
|
||||
case 'db':
|
||||
$resource = ResourceFactory::createResource($config);
|
||||
$resource->getConnection()->getConnection();
|
||||
break;
|
||||
case 'statusdat':
|
||||
if (!file_exists($config->object_file) || !file_exists($config->status_file)) {
|
||||
$this->addErrorMessage(
|
||||
'Connectivity validation failed, the provided file or socket does not exist.'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'livestatus':
|
||||
// TODO: Implement check
|
||||
break;
|
||||
case 'ldap':
|
||||
$resource = ResourceFactory::createResource($config);
|
||||
$resource->connect();
|
||||
break;
|
||||
}
|
||||
} catch (\Exception $exc) {
|
||||
$this->addErrorMessage('Connectivity validation failed, connection to the given resource not possible.');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->addNameFields();
|
||||
$this->addTypeSelectionBox();
|
||||
switch ($this->getRequest()->getParam('resource_type', $this->getResource()->type)) {
|
||||
case 'db':
|
||||
$this->addDbForm();
|
||||
break;
|
||||
case 'statusdat':
|
||||
$this->addStatusdatForm();
|
||||
break;
|
||||
case 'livestatus':
|
||||
$this->addLivestatusForm();
|
||||
break;
|
||||
case 'ldap':
|
||||
$this->addLdapForm();
|
||||
break;
|
||||
}
|
||||
$this->setSubmitLabel('{{SAVE_ICON}} Save Changes');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a configuration containing the backend settings entered in this form
|
||||
*
|
||||
* @return Zend_Config The updated configuration for this backend
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
$values = $this->getValues();
|
||||
$type = $values['resource_type'];
|
||||
$result = array('type' => $type);
|
||||
foreach ($values as $key => $value) {
|
||||
if ($key !== 'resource_type' && $key !== 'resource_all_name' && $key !== 'resource_all_name_old') {
|
||||
$configKey = explode('_', $key, 3);
|
||||
if (sizeof($configKey) < 3) {
|
||||
Logger::warning('EditResourceForm: invalid form key "' . $key . '" was ignored.');
|
||||
continue;
|
||||
}
|
||||
$result[$configKey[2]] = $value;
|
||||
}
|
||||
}
|
||||
return new Zend_Config($result);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,511 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Form\Config\Resource;
|
||||
|
||||
use Exception;
|
||||
use Zend_Config;
|
||||
use Zend_Form_Element_Checkbox;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Web\Form\Element\Number;
|
||||
use Icinga\Web\Form\Decorator\HelpText;
|
||||
|
||||
class ResourceForm extends Form
|
||||
{
|
||||
/**
|
||||
* The resource
|
||||
*
|
||||
* @var Zend_Config
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* The (new) name of the resource
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* The old name of the resource
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $oldName;
|
||||
|
||||
/**
|
||||
* Set the current resource name
|
||||
*
|
||||
* @param string $name The name to set
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current resource name
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
$name = $this->getValue('resource_all_name');
|
||||
if (!$name) {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the original name of the resource
|
||||
*
|
||||
* @param string $name The name to set
|
||||
*/
|
||||
public function setOldName($name)
|
||||
{
|
||||
$this->oldName = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the resource name that was initially set
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getOldName()
|
||||
{
|
||||
$oldName = $this->getValue('resource_all_name_old');
|
||||
if (!$oldName) {
|
||||
return $this->oldName;
|
||||
}
|
||||
|
||||
return $oldName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the resource configuration to edit.
|
||||
*
|
||||
* @param Zend_Config $resource The config to set
|
||||
*/
|
||||
public function setResource(Zend_Config $resource)
|
||||
{
|
||||
$this->resource = $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current resource configuration.
|
||||
*
|
||||
* @return Zend_Config
|
||||
*/
|
||||
public function getResource()
|
||||
{
|
||||
if (!isset($this->resource)) {
|
||||
$this->resource = new Zend_Config(array('type' => 'db'));
|
||||
}
|
||||
|
||||
return $this->resource;
|
||||
}
|
||||
|
||||
protected function addDbForm()
|
||||
{
|
||||
$this->addElement(
|
||||
'select',
|
||||
'resource_db_db',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Database Type'),
|
||||
'helptext' => t('The type of SQL database you want to create.'),
|
||||
'value' => $this->getResource()->get('db', 'mysql'),
|
||||
'multiOptions' => array(
|
||||
'mysql' => 'MySQL',
|
||||
'pgsql' => 'PostgreSQL'
|
||||
//'oracle' => 'Oracle'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_db_host',
|
||||
array (
|
||||
'required' => true,
|
||||
'label' => t('Host'),
|
||||
'helptext' => t('The hostname of the database.'),
|
||||
'value' => $this->getResource()->get('host', 'localhost')
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
new Number(
|
||||
array(
|
||||
'name' => 'resource_db_port',
|
||||
'required' => true,
|
||||
'label' => t('Port'),
|
||||
'helptext' => t('The port to use.'),
|
||||
'value' => $this->getResource()->get('port', 3306)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_db_dbname',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Database Name'),
|
||||
'helptext' => t('The name of the database to use'),
|
||||
'value' => $this->getResource()->get('dbname', '')
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_db_username',
|
||||
array (
|
||||
'required' => true,
|
||||
'label' => t('Username'),
|
||||
'helptext' => t('The user name to use for authentication.'),
|
||||
'value' => $this->getResource()->get('username', '')
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'password',
|
||||
'resource_db_password',
|
||||
array(
|
||||
'required' => true,
|
||||
'renderPassword' => true,
|
||||
'label' => t('Password'),
|
||||
'helptext' => t('The password to use for authentication'),
|
||||
'value' => $this->getResource()->get('password', '')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function addStatusdatForm()
|
||||
{
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_statusdat_status_file',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Filepath'),
|
||||
'helptext' => t('Location of your icinga status.dat file'),
|
||||
'value' => $this->getResource()->get('status_file', '/usr/local/icinga/var/status.dat')
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_statusdat_object_file',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Filepath'),
|
||||
'helptext' => t('Location of your icinga objects.cache file'),
|
||||
'value' => $this->getResource()->get('status_file', '/usr/local/icinga/var/objects.cache')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function addLivestatusForm()
|
||||
{
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_livestatus_socket',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Socket'),
|
||||
'helptext' => t('The path to your livestatus socket used for querying monitoring data'),
|
||||
'value' => $this->getResource()->get('socket', '/usr/local/icinga/var/rw/livestatus')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function addLdapForm()
|
||||
{
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_ldap_hostname',
|
||||
array(
|
||||
'required' => true,
|
||||
'allowEmpty' => false,
|
||||
'label' => t('Host'),
|
||||
'helptext' => t('The hostname or address of the LDAP server to use for authentication'),
|
||||
'value' => $this->getResource()->get('hostname', 'localhost')
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_ldap_root_dn',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Root DN'),
|
||||
'helptext' => t('The path where users can be found on the ldap server'),
|
||||
'value' => $this->getResource()->get('root_dn', 'ou=people,dc=icinga,dc=org')
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_ldap_bind_dn',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Bind DN'),
|
||||
'helptext' => t('The user dn to use for querying the ldap server'),
|
||||
'value' => $this->getResource()->get('bind_dn', 'cn=admin,cn=config')
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'password',
|
||||
'resource_ldap_bind_pw',
|
||||
array(
|
||||
'required' => true,
|
||||
'renderPassword' => true,
|
||||
'label' => t('Bind Password'),
|
||||
'helptext' => t('The password to use for querying the ldap server'),
|
||||
'value' => $this->getResource()->get('bind_pw', '')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function addFileForm()
|
||||
{
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_file_filename',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Filepath'),
|
||||
'helptext' => t('The filename to fetch information from'),
|
||||
'value' => $this->getResource()->get('filename', '')
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_file_fields',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Pattern'),
|
||||
'helptext' => t('The regular expression by which to identify columns'),
|
||||
'value' => $this->getResource()->get('fields', '')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function addNameFields()
|
||||
{
|
||||
$this->addElement(
|
||||
'text',
|
||||
'resource_all_name',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Resource Name'),
|
||||
'helptext' => t('The unique name of this resource'),
|
||||
'value' => $this->getName()
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElement(
|
||||
'hidden',
|
||||
'resource_all_name_old',
|
||||
array(
|
||||
'value' => $this->getOldName()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add checkbox at the beginning of the form which allows to skip connection validation
|
||||
*/
|
||||
protected function addForceCreationCheckbox()
|
||||
{
|
||||
$checkbox = new Zend_Form_Element_Checkbox(
|
||||
array(
|
||||
'order' => 0,
|
||||
'name' => 'resource_force_creation',
|
||||
'label' => t('Force Changes'),
|
||||
'helptext' => t('Check this box to enforce changes without connectivity validation')
|
||||
)
|
||||
);
|
||||
$checkbox->addDecorator(new HelpText());
|
||||
$this->addElement($checkbox);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a select box for choosing the type to use for this backend
|
||||
*/
|
||||
protected function addTypeSelectionBox()
|
||||
{
|
||||
$this->addElement(
|
||||
'select',
|
||||
'resource_type',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Resource Type'),
|
||||
'helptext' => t('The type of resource'),
|
||||
'value' => $this->getResource()->type,
|
||||
'multiOptions' => array(
|
||||
'db' => t('SQL Database'),
|
||||
'ldap' => 'LDAP',
|
||||
'statusdat' => 'Status.dat',
|
||||
'livestatus' => 'Livestatus',
|
||||
'file' => t('File')
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->enableAutoSubmit(array('resource_type'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate this form with the Zend validation mechanism and perform a validation of the connection
|
||||
*
|
||||
* If validation fails, the 'resource_force_creation' checkbox is prepended to the form to allow users to
|
||||
* skip the connection validation
|
||||
*
|
||||
* @param array $data The form input to validate
|
||||
*
|
||||
* @return bool True when validation succeeded, false if not
|
||||
*/
|
||||
public function isValid($data)
|
||||
{
|
||||
if (!parent::isValid($data)) {
|
||||
return false;
|
||||
}
|
||||
if (isset($data['resource_force_creation']) && $data['resource_force_creation']) {
|
||||
return true;
|
||||
}
|
||||
if (!$this->isValidResource()) {
|
||||
$this->addForceCreationCheckbox();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the changed resource is a valid resource, by instantiating it and
|
||||
* checking if a connection is possible
|
||||
*
|
||||
* @return bool True when a connection to the resource is possible
|
||||
*/
|
||||
public function isValidResource()
|
||||
{
|
||||
$config = $this->getConfig();
|
||||
|
||||
try {
|
||||
switch ($config->type) {
|
||||
case 'db':
|
||||
$resource = ResourceFactory::createResource($config);
|
||||
$resource->getConnection()->getConnection();
|
||||
break;
|
||||
case 'statusdat':
|
||||
if (!file_exists($config->object_file) || !file_exists($config->status_file)) {
|
||||
$this->addErrorMessage(
|
||||
t('Connectivity validation failed, the provided file does not exist.')
|
||||
);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'livestatus':
|
||||
$resource = ResourceFactory::createResource($config);
|
||||
$resource->connect()->disconnect();
|
||||
break;
|
||||
case 'ldap':
|
||||
$resource = ResourceFactory::createResource($config);
|
||||
$resource->connect();
|
||||
break;
|
||||
case 'file':
|
||||
if (!file_exists($config->filename)) {
|
||||
$this->addErrorMessage(
|
||||
t('Connectivity validation failed, the provided file does not exist.')
|
||||
);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->addErrorMessage(t('Connectivity validation failed, connection to the given resource not possible.'));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->addNameFields();
|
||||
$this->addTypeSelectionBox();
|
||||
|
||||
switch ($this->getRequest()->getParam('resource_type', $this->getResource()->type)) {
|
||||
case 'db':
|
||||
$this->addDbForm();
|
||||
break;
|
||||
case 'statusdat':
|
||||
$this->addStatusdatForm();
|
||||
break;
|
||||
case 'livestatus':
|
||||
$this->addLivestatusForm();
|
||||
break;
|
||||
case 'ldap':
|
||||
$this->addLdapForm();
|
||||
break;
|
||||
case 'file':
|
||||
$this->addFileForm();
|
||||
break;
|
||||
}
|
||||
|
||||
$this->setSubmitLabel('{{SAVE_ICON}} Save Changes');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a configuration containing the backend settings entered in this form
|
||||
*
|
||||
* @return Zend_Config The updated configuration for this backend
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
$values = $this->getValues();
|
||||
|
||||
$result = array('type' => $values['resource_type']);
|
||||
foreach ($values as $key => $value) {
|
||||
if ($key !== 'resource_type' && $key !== 'resource_all_name' && $key !== 'resource_all_name_old') {
|
||||
$configKey = explode('_', $key, 3);
|
||||
if (count($configKey) === 3) {
|
||||
$result[$configKey[2]] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Zend_Config($result);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -29,7 +30,7 @@
|
|||
|
||||
namespace Icinga\Form\Dashboard;
|
||||
|
||||
use \Icinga\Application\Config as IcingaConfig;
|
||||
use Icinga\Application\Config as IcingaConfig;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Web\Widget\Dashboard;
|
||||
use Zend_Form_Element_Text;
|
||||
|
@ -39,7 +40,6 @@ use Zend_Form_Element_Select;
|
|||
|
||||
/**
|
||||
* Form to add an url a dashboard pane
|
||||
*
|
||||
*/
|
||||
class AddUrlForm extends Form
|
||||
{
|
||||
|
@ -51,7 +51,6 @@ class AddUrlForm extends Form
|
|||
*/
|
||||
private function addPaneSelectionBox(Dashboard $dashboard)
|
||||
{
|
||||
|
||||
$selectPane = new Zend_Form_Element_Select(
|
||||
'pane',
|
||||
array(
|
||||
|
@ -84,7 +83,6 @@ class AddUrlForm extends Form
|
|||
|
||||
/**
|
||||
* Add a textfield for creating a new pane to this form
|
||||
*
|
||||
*/
|
||||
private function addNewPaneTextField($showExistingButton = true)
|
||||
{
|
||||
|
@ -130,7 +128,6 @@ class AddUrlForm extends Form
|
|||
|
||||
/**
|
||||
* Add elements to this form (used by extending classes)
|
||||
*
|
||||
*/
|
||||
protected function create()
|
||||
{
|
||||
|
@ -167,6 +164,6 @@ class AddUrlForm extends Form
|
|||
)
|
||||
);
|
||||
$this->setSubmitLabel("Add To Dashboard");
|
||||
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -285,3 +286,4 @@ class GeneralForm extends Form
|
|||
);
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Form;
|
||||
|
||||
class TestForm
|
||||
{
|
||||
}
|
|
@ -1,6 +1,4 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -29,10 +27,10 @@
|
|||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
use \Icinga\Application\Icinga;
|
||||
use \Icinga\Application\Config;
|
||||
use \Icinga\Util\DateTimeFactory;
|
||||
use \Icinga\Web\Form\Validator\DateTimeValidator;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
use Icinga\Web\Form\Validator\DateTimeValidator;
|
||||
|
||||
/**
|
||||
* Helper to format date and time. Utilizes DateTimeFactory to ensure time zone awareness
|
||||
|
@ -46,7 +44,7 @@ class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
|
|||
*
|
||||
* @var Zend_Controller_Request_Abstract
|
||||
*/
|
||||
private $request;
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -79,6 +77,7 @@ class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
|
|||
*
|
||||
* @param int $timestamp
|
||||
* @param string $format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function format($timestamp, $format)
|
||||
|
@ -89,6 +88,7 @@ class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
|
|||
} else {
|
||||
return $timestamp;
|
||||
}
|
||||
|
||||
return $dt->format($format);
|
||||
}
|
||||
|
||||
|
@ -96,6 +96,7 @@ class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
|
|||
* Format date according to user's format
|
||||
*
|
||||
* @param int $timestamp A unix timestamp
|
||||
*
|
||||
* @return string The formatted date string
|
||||
*/
|
||||
public function formatDate($timestamp)
|
||||
|
@ -107,6 +108,7 @@ class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
|
|||
* Format time according to user's format
|
||||
*
|
||||
* @param int $timestamp A unix timestamp
|
||||
*
|
||||
* @return string The formatted time string
|
||||
*/
|
||||
public function formatTime($timestamp)
|
||||
|
@ -133,7 +135,8 @@ class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
|
|||
public function getDateFormat()
|
||||
{
|
||||
return $this->request->getUser()->getPreferences()->get(
|
||||
'app.dateFormat', Config::app()->global !== null ? Config::app()->global->get('dateFormat', 'd/m/Y') : 'd/m/Y'
|
||||
'app.dateFormat',
|
||||
Config::app()->global !== null ? Config::app()->global->get('dateFormat', 'd/m/Y') : 'd/m/Y'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -145,7 +148,8 @@ class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
|
|||
public function getTimeFormat()
|
||||
{
|
||||
return $this->request->getUser()->getPreferences()->get(
|
||||
'app.timeFormat', Config::app()->global !== null ? Config::app()->global->get('timeFormat', 'g:i A') : 'g:i A'
|
||||
'app.timeFormat',
|
||||
Config::app()->global !== null ? Config::app()->global->get('timeFormat', 'g:i A') : 'g:i A'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -159,5 +163,3 @@ class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
|
|||
return $this->getDateFormat() . ' ' . $this->getTimeFormat();
|
||||
}
|
||||
}
|
||||
|
||||
// @codingStandardsIgnoreStop
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -95,5 +94,4 @@ class Zend_View_Helper_FormDateTime extends Zend_View_Helper_FormElement
|
|||
return $xhtml;
|
||||
}
|
||||
}
|
||||
|
||||
// @codingStandardsIgnoreStop
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -55,5 +54,4 @@ class Zend_View_Helper_FormNumber extends \Zend_View_Helper_FormText
|
|||
. $this->getClosingBracket();
|
||||
}
|
||||
}
|
||||
|
||||
// @codingStandardsIgnoreStop
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -64,3 +63,4 @@ class Zend_View_Helper_FormTriStateCheckbox extends Zend_View_Helper_FormElement
|
|||
return $xhtml . '</div>';
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -0,0 +1,384 @@
|
|||
./modules/doc/application/controllers/IndexController.php
|
||||
./modules/doc/application/controllers/ModuleController.php
|
||||
./modules/doc/library/Doc/DocParser.php
|
||||
./modules/doc/library/Doc/Controller.php
|
||||
./modules/doc/library/Doc/DocException.php
|
||||
./modules/doc/library/Doc/MarkdownFileIterator.php
|
||||
./modules/translation/application/clicommands/CompileCommand.php
|
||||
./modules/translation/application/clicommands/RefreshCommand.php
|
||||
./modules/translation/library/Translation/Cli/TranslationCommand.php
|
||||
./modules/translation/library/Translation/Util/GettextTranslationHelper.php
|
||||
./modules/monitoring/application/forms/Config/Backend/EditBackendForm.php
|
||||
./modules/monitoring/application/forms/Config/Backend/CreateBackendForm.php
|
||||
./modules/monitoring/application/forms/Config/ConfirmRemovalForm.php
|
||||
./modules/monitoring/application/forms/Config/Instance/CreateInstanceForm.php
|
||||
./modules/monitoring/application/forms/Config/Instance/EditInstanceForm.php
|
||||
./modules/monitoring/application/forms/Command/DelayNotificationForm.php
|
||||
./modules/monitoring/application/forms/Command/SubmitPassiveCheckResultForm.php
|
||||
./modules/monitoring/application/forms/Command/CommandForm.php
|
||||
./modules/monitoring/application/forms/Command/WithChildrenCommandForm.php
|
||||
./modules/monitoring/application/forms/Command/CustomNotificationForm.php
|
||||
./modules/monitoring/application/forms/Command/AcknowledgeForm.php
|
||||
./modules/monitoring/application/forms/Command/CommentForm.php
|
||||
./modules/monitoring/application/forms/Command/MultiCommandFlagForm.php
|
||||
./modules/monitoring/application/forms/Command/RescheduleNextCheckForm.php
|
||||
./modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php
|
||||
./modules/monitoring/application/forms/Command/SingleArgumentCommandForm.php
|
||||
./modules/monitoring/application/forms/Command/DisableNotificationWithExpireForm.php
|
||||
./modules/monitoring/application/views/helpers/MonitoringFlags.php
|
||||
./modules/monitoring/application/views/helpers/MonitoringProperties.php
|
||||
./modules/monitoring/application/views/helpers/CommandForm.php
|
||||
./modules/monitoring/application/views/helpers/RuntimeVariables.php
|
||||
./modules/monitoring/application/views/helpers/CheckPerformance.php
|
||||
./modules/monitoring/application/views/helpers/PluginOutput.php
|
||||
./modules/monitoring/application/views/helpers/Perfdata.php
|
||||
./modules/monitoring/application/views/helpers/_RenderServicePerfdata.php
|
||||
./modules/monitoring/application/views/helpers/SelectionToolbar.php
|
||||
./modules/monitoring/application/views/helpers/ContactFlags.php
|
||||
./modules/monitoring/application/views/helpers/ResolveMacros.php
|
||||
./modules/monitoring/application/views/helpers/MonitoringState.php
|
||||
./modules/monitoring/application/views/helpers/ResolveComments.php
|
||||
./modules/monitoring/application/clicommands/NrpeCommand.php
|
||||
./modules/monitoring/application/clicommands/ConferenceCommand.php
|
||||
./modules/monitoring/application/clicommands/ListCommand.php
|
||||
./modules/monitoring/application/controllers/ShowController.php
|
||||
./modules/monitoring/application/controllers/ConfigController.php
|
||||
./modules/monitoring/application/controllers/MultiController.php
|
||||
./modules/monitoring/application/controllers/ListController.php
|
||||
./modules/monitoring/application/controllers/CommandController.php
|
||||
./modules/monitoring/application/controllers/MonitoringCommands.php
|
||||
./modules/monitoring/application/controllers/ChartController.php
|
||||
./modules/monitoring/application/controllers/TimelineController.php
|
||||
./modules/monitoring/application/controllers/TacticalController.php
|
||||
./modules/monitoring/application/controllers/ProcessController.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Contactgroup.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Notification.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Comment.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Customvar.php
|
||||
./modules/monitoring/library/Monitoring/DataView/EventHistory.php
|
||||
./modules/monitoring/library/Monitoring/DataView/StatusSummary.php
|
||||
./modules/monitoring/library/Monitoring/DataView/DataView.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Runtimesummary.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Servicegroup.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Runtimevariables.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Contact.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Programstatus.php
|
||||
./modules/monitoring/library/Monitoring/DataView/StateHistorySummary.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Downtime.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Groupsummary.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Hostgroup.php
|
||||
./modules/monitoring/library/Monitoring/DataView/HostStatus.php
|
||||
./modules/monitoring/library/Monitoring/DataView/ServiceStatus.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/StatusdatQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/ContactgroupQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/ServicegroupsummaryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/HostgroupQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/CommentQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/DowntimeQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/StatusSummaryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/GroupsummaryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/ContactQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/ServicegroupQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/HostlistQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/StatusQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/ServicelistQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Livestatus/Query/StatusQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/CustomvarQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeendhistoryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/StatehistoryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/ProgramstatusQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/EventHistoryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusSummaryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/GroupsummaryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/RuntimevariablesQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/CommenthistoryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/StateHistorySummaryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/AllcontactsQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimestarthistoryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/RuntimesummaryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php
|
||||
./modules/monitoring/library/Monitoring/Environment.php
|
||||
./modules/monitoring/library/Monitoring/Controller.php
|
||||
./modules/monitoring/library/Monitoring/Timeline/TimeEntry.php
|
||||
./modules/monitoring/library/Monitoring/Timeline/TimeRange.php
|
||||
./modules/monitoring/library/Monitoring/Timeline/TimeLine.php
|
||||
./modules/monitoring/library/Monitoring/Object/Service.php
|
||||
./modules/monitoring/library/Monitoring/Object/Host.php
|
||||
./modules/monitoring/library/Monitoring/Object/AbstractObject.php
|
||||
./modules/monitoring/library/Monitoring/Filter/Type/StatusFilter.php
|
||||
./modules/monitoring/library/Monitoring/Filter/Registry.php
|
||||
./modules/monitoring/library/Monitoring/Filter/UrlViewFilter.php
|
||||
./modules/monitoring/library/Monitoring/Exception/UnsupportedBackendException.php
|
||||
./modules/monitoring/library/Monitoring/Web/Widget/TimelineIntervalBox.php
|
||||
./modules/monitoring/library/Monitoring/Web/Hook/TimelineProvider.php
|
||||
./modules/monitoring/library/Monitoring/Web/Hook/TopBar.php
|
||||
./modules/monitoring/library/Monitoring/Command/SubmitPassiveCheckresultCommand.php
|
||||
./modules/monitoring/library/Monitoring/Command/AcknowledgeCommand.php
|
||||
./modules/monitoring/library/Monitoring/Command/ScheduleDowntimeCommand.php
|
||||
./modules/monitoring/library/Monitoring/Command/ScheduleCheckCommand.php
|
||||
./modules/monitoring/library/Monitoring/Command/DisableNotificationWithExpireCommand.php
|
||||
./modules/monitoring/library/Monitoring/Command/SingleArgumentCommand.php
|
||||
./modules/monitoring/library/Monitoring/Command/AddCommentCommand.php
|
||||
./modules/monitoring/library/Monitoring/Command/CustomNotificationCommand.php
|
||||
./modules/monitoring/library/Monitoring/Command/DelayNotificationCommand.php
|
||||
./modules/monitoring/library/Monitoring/Plugin.php
|
||||
./modules/monitoring/library/Monitoring/Cli/CliUtils.php
|
||||
./modules/monitoring/library/Monitoring/Backend.php
|
||||
./modules/monitoring/library/Monitoring/Plugin/Perfdata.php
|
||||
./modules/monitoring/library/Monitoring/Plugin/PerfdataSet.php
|
||||
./modules/monitoring/run.php
|
||||
./modules/monitoring/configuration.php
|
||||
./modules/monitoring/bin/action/list.inc.php
|
||||
./etc/module_skeleton/application/controllers/IndexController.php
|
||||
./application/forms/Authentication/LoginForm.php
|
||||
./application/forms/Config/GeneralForm.php
|
||||
./application/forms/Config/Authentication/LdapBackendForm.php
|
||||
./application/forms/Config/Authentication/ReorderForm.php
|
||||
./application/forms/Config/Authentication/BaseBackendForm.php
|
||||
./application/forms/Config/Authentication/DbBackendForm.php
|
||||
./application/forms/Config/LoggingForm.php
|
||||
./application/forms/Config/ConfirmRemovalForm.php
|
||||
./application/forms/Config/Resource/CreateResourceForm.php
|
||||
./application/forms/Config/Resource/EditResourceForm.php
|
||||
./application/forms/TestForm.php
|
||||
./application/forms/Dashboard/AddUrlForm.php
|
||||
./application/forms/Preference/GeneralForm.php
|
||||
./application/views/helpers/FormNumber.php
|
||||
./application/views/helpers/DateFormat.php
|
||||
./application/views/helpers/FormDateTime.php
|
||||
./application/views/helpers/FormTriStateCheckbox.php
|
||||
./application/views/helpers/Util.php
|
||||
./application/clicommands/HelpCommand.php
|
||||
./application/clicommands/ModuleCommand.php
|
||||
./application/clicommands/AutocompleteCommand.php
|
||||
./application/clicommands/WebCommand.php
|
||||
./application/controllers/ConfigController.php
|
||||
./application/controllers/ListController.php
|
||||
./application/controllers/IndexController.php
|
||||
./application/controllers/LayoutController.php
|
||||
./application/controllers/PreferenceController.php
|
||||
./application/controllers/DashboardController.php
|
||||
./application/controllers/FilterController.php
|
||||
./application/controllers/StaticController.php
|
||||
./application/controllers/SearchController.php
|
||||
./application/controllers/ErrorController.php
|
||||
./application/controllers/AuthenticationController.php
|
||||
./library/Icinga/Logger/Logger.php
|
||||
./library/Icinga/Logger/Writer/StreamWriter.php
|
||||
./library/Icinga/Logger/Writer/SyslogWriter.php
|
||||
./library/Icinga/Logger/LogWriter.php
|
||||
./library/Icinga/User/Preferences.php
|
||||
./library/Icinga/User/Message.php
|
||||
./library/Icinga/User/Preferences/Store/IniStore.php
|
||||
./library/Icinga/User/Preferences/Store/DbStore.php
|
||||
./library/Icinga/User/Preferences/PreferencesStore.php
|
||||
./library/Icinga/Authentication/UserBackend.php
|
||||
./library/Icinga/Authentication/Backend/DbUserBackend.php
|
||||
./library/Icinga/Authentication/Backend/LdapUserBackend.php
|
||||
./library/Icinga/Authentication/Membership.php
|
||||
./library/Icinga/Authentication/Manager.php
|
||||
./library/Icinga/Authentication/AdmissionLoader.php
|
||||
./library/Icinga/Authentication/AuthChain.php
|
||||
./library/Icinga/Data/Db/Query.php
|
||||
./library/Icinga/Data/Db/TreeToSqlParser.php
|
||||
./library/Icinga/Data/Db/Connection.php
|
||||
./library/Icinga/Data/PivotTable.php
|
||||
./library/Icinga/Data/DatasourceInterface.php
|
||||
./library/Icinga/Data/DataArray/Query.php
|
||||
./library/Icinga/Data/DataArray/Datasource.php
|
||||
./library/Icinga/Data/ResourceFactory.php
|
||||
./library/Icinga/Data/BaseQuery.php
|
||||
./library/Icinga/File/Pdf.php
|
||||
./library/Icinga/File/Csv.php
|
||||
./library/Icinga/File/Csv/Query.php
|
||||
./library/Icinga/Test/DbTest.php
|
||||
./library/Icinga/Test/BaseTestCase.php
|
||||
./library/Icinga/Test/FormTest.php
|
||||
./library/Icinga/Protocol/Ldap/Root.php
|
||||
./library/Icinga/Protocol/Ldap/Query.php
|
||||
./library/Icinga/Protocol/Ldap/Exception.php
|
||||
./library/Icinga/Protocol/Ldap/LdapUtils.php
|
||||
./library/Icinga/Protocol/Ldap/Node.php
|
||||
./library/Icinga/Protocol/Ldap/Connection.php
|
||||
./library/Icinga/Protocol/File/Query.php
|
||||
./library/Icinga/Protocol/File/Reader.php
|
||||
./library/Icinga/Protocol/Statusdat/Parser.php
|
||||
./library/Icinga/Protocol/Statusdat/Query.php
|
||||
./library/Icinga/Protocol/Statusdat/Query/IQueryPart.php
|
||||
./library/Icinga/Protocol/Statusdat/Query/Group.php
|
||||
./library/Icinga/Protocol/Statusdat/Query/Expression.php
|
||||
./library/Icinga/Protocol/Statusdat/View/AccessorStrategy.php
|
||||
./library/Icinga/Protocol/Statusdat/View/MonitoringObjectList.php
|
||||
./library/Icinga/Protocol/Statusdat/ObjectContainer.php
|
||||
./library/Icinga/Protocol/Statusdat/Exception/ParsingException.php
|
||||
./library/Icinga/Protocol/Statusdat/Reader.php
|
||||
./library/Icinga/Protocol/Statusdat/IReader.php
|
||||
./library/Icinga/Protocol/Statusdat/PrintableObject.php
|
||||
./library/Icinga/Protocol/Statusdat/TreeToStatusdatQueryParser.php
|
||||
./library/Icinga/Protocol/Statusdat/RuntimeStateContainer.php
|
||||
./library/Icinga/Protocol/Nrpe/Packet.php
|
||||
./library/Icinga/Protocol/Nrpe/Connection.php
|
||||
./library/Icinga/Protocol/Livestatus/Query.php
|
||||
./library/Icinga/Protocol/Livestatus/Connection.php
|
||||
./library/Icinga/Protocol/Commandpipe/Transport/Transport.php
|
||||
./library/Icinga/Protocol/Commandpipe/Transport/LocalPipe.php
|
||||
./library/Icinga/Protocol/Commandpipe/Transport/SecureShell.php
|
||||
./library/Icinga/Protocol/Commandpipe/Comment.php
|
||||
./library/Icinga/Protocol/Commandpipe/Exception/InvalidCommandException.php
|
||||
./library/Icinga/Protocol/Commandpipe/PropertyModifier.php
|
||||
./library/Icinga/Protocol/Commandpipe/Command.php
|
||||
./library/Icinga/Protocol/Commandpipe/CommandPipe.php
|
||||
./library/Icinga/Application/Platform.php
|
||||
./library/Icinga/Application/Benchmark.php
|
||||
./library/Icinga/Application/functions.php
|
||||
./library/Icinga/Application/LegacyWeb.php
|
||||
./library/Icinga/Application/Config.php
|
||||
./library/Icinga/Application/EmbeddedWeb.php
|
||||
./library/Icinga/Application/ApplicationBootstrap.php
|
||||
./library/Icinga/Application/Cli.php
|
||||
./library/Icinga/Application/webrouter.php
|
||||
./library/Icinga/Application/Modules/Module.php
|
||||
./library/Icinga/Application/Modules/Manager.php
|
||||
./library/Icinga/Application/Loader.php
|
||||
./library/Icinga/Application/Icinga.php
|
||||
./library/Icinga/Application/Web.php
|
||||
./library/Icinga/Chart/Primitive/Animation.php
|
||||
./library/Icinga/Chart/Primitive/Text.php
|
||||
./library/Icinga/Chart/Primitive/Animatable.php
|
||||
./library/Icinga/Chart/Primitive/Drawable.php
|
||||
./library/Icinga/Chart/Primitive/Circle.php
|
||||
./library/Icinga/Chart/Primitive/Styleable.php
|
||||
./library/Icinga/Chart/Primitive/RawElement.php
|
||||
./library/Icinga/Chart/Primitive/Rect.php
|
||||
./library/Icinga/Chart/Primitive/Line.php
|
||||
./library/Icinga/Chart/Primitive/Canvas.php
|
||||
./library/Icinga/Chart/Primitive/PieSlice.php
|
||||
./library/Icinga/Chart/Primitive/Path.php
|
||||
./library/Icinga/Chart/Graph/LineGraph.php
|
||||
./library/Icinga/Chart/Graph/StackedGraph.php
|
||||
./library/Icinga/Chart/Graph/BarGraph.php
|
||||
./library/Icinga/Chart/Axis.php
|
||||
./library/Icinga/Chart/Palette.php
|
||||
./library/Icinga/Chart/Unit/AxisUnit.php
|
||||
./library/Icinga/Chart/Unit/LinearUnit.php
|
||||
./library/Icinga/Chart/Unit/StaticAxis.php
|
||||
./library/Icinga/Chart/Unit/CalendarUnit.php
|
||||
./library/Icinga/Chart/PieChart.php
|
||||
./library/Icinga/Chart/GridChart.php
|
||||
./library/Icinga/Chart/SVGRenderer.php
|
||||
./library/Icinga/Chart/Legend.php
|
||||
./library/Icinga/Chart/Inline/PieChart.php
|
||||
./library/Icinga/Chart/Inline/Inline.php
|
||||
./library/Icinga/Chart/Chart.php
|
||||
./library/Icinga/Chart/Render/RenderContext.php
|
||||
./library/Icinga/Chart/Render/LayoutBox.php
|
||||
./library/Icinga/Config/IniEditor.php
|
||||
./library/Icinga/Config/PreservingIniWriter.php
|
||||
./library/Icinga/User.php
|
||||
./library/Icinga/Filter/Query/Tree.php
|
||||
./library/Icinga/Filter/Query/Node.php
|
||||
./library/Icinga/Filter/FilterAttribute.php
|
||||
./library/Icinga/Filter/Type/FilterType.php
|
||||
./library/Icinga/Filter/Type/BooleanFilter.php
|
||||
./library/Icinga/Filter/Type/TextFilter.php
|
||||
./library/Icinga/Filter/Type/TimeRangeSpecifier.php
|
||||
./library/Icinga/Filter/QueryProposer.php
|
||||
./library/Icinga/Filter/Registry.php
|
||||
./library/Icinga/Filter/Filter.php
|
||||
./library/Icinga/Filter/Filterable.php
|
||||
./library/Icinga/Filter/Domain.php
|
||||
./library/Icinga/Exception/NotWritableError.php
|
||||
./library/Icinga/Exception/MissingParameterException.php
|
||||
./library/Icinga/Exception/NotImplementedError.php
|
||||
./library/Icinga/Exception/ConfigurationError.php
|
||||
./library/Icinga/Exception/NotReadableError.php
|
||||
./library/Icinga/Exception/SystemPermissionException.php
|
||||
./library/Icinga/Exception/ProgrammingError.php
|
||||
./library/Icinga/Web/JavaScript.php
|
||||
./library/Icinga/Web/Notification.php
|
||||
./library/Icinga/Web/MenuItem.php
|
||||
./library/Icinga/Web/Widget/Dashboard.php
|
||||
./library/Icinga/Web/Widget/FilterBox.php
|
||||
./library/Icinga/Web/Widget/AlertMessageBox.php
|
||||
./library/Icinga/Web/Widget/Tabextension/DashboardAction.php
|
||||
./library/Icinga/Web/Widget/Tabextension/BasketAction.php
|
||||
./library/Icinga/Web/Widget/Tabextension/Tabextension.php
|
||||
./library/Icinga/Web/Widget/Tabextension/OutputFormat.php
|
||||
./library/Icinga/Web/Widget/Chart/InlinePie.php
|
||||
./library/Icinga/Web/Widget/Chart/HistoryColorGrid.php
|
||||
./library/Icinga/Web/Widget/AbstractWidget.php
|
||||
./library/Icinga/Web/Widget/FilterBadgeRenderer.php
|
||||
./library/Icinga/Web/Widget/Dashboard/Component.php
|
||||
./library/Icinga/Web/Widget/Dashboard/Pane.php
|
||||
./library/Icinga/Web/Widget/Tabs.php
|
||||
./library/Icinga/Web/Widget/Tab.php
|
||||
./library/Icinga/Web/Widget/Widget.php
|
||||
./library/Icinga/Web/Widget/SortBox.php
|
||||
./library/Icinga/Web/Hook.php
|
||||
./library/Icinga/Web/View/helpers/generic.php
|
||||
./library/Icinga/Web/View/helpers/url.php
|
||||
./library/Icinga/Web/View/helpers/format.php
|
||||
./library/Icinga/Web/Menu.php
|
||||
./library/Icinga/Web/Session.php
|
||||
./library/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorder.php
|
||||
./library/Icinga/Web/Paginator/Adapter/QueryAdapter.php
|
||||
./library/Icinga/Web/ViewStream.php
|
||||
./library/Icinga/Web/Url.php
|
||||
./library/Icinga/Web/Session/SessionNamespace.php
|
||||
./library/Icinga/Web/Session/Session.php
|
||||
./library/Icinga/Web/Session/PhpSession.php
|
||||
./library/Icinga/Web/StyleSheet.php
|
||||
./library/Icinga/Web/Hook/Ticket.php
|
||||
./library/Icinga/Web/Hook/Configuration/ConfigurationTabInterface.php
|
||||
./library/Icinga/Web/Hook/Configuration/ConfigurationTab.php
|
||||
./library/Icinga/Web/Hook/Configuration/ConfigurationTabBuilder.php
|
||||
./library/Icinga/Web/Hook/TopBar.php
|
||||
./library/Icinga/Web/Hook/Grapher.php
|
||||
./library/Icinga/Web/Request.php
|
||||
./library/Icinga/Web/View.php
|
||||
./library/Icinga/Web/Widget.php
|
||||
./library/Icinga/Web/Controller/ActionController.php
|
||||
./library/Icinga/Web/Controller/BaseConfigController.php
|
||||
./library/Icinga/Web/Controller/BasePreferenceController.php
|
||||
./library/Icinga/Web/Controller/ControllerTabCollector.php
|
||||
./library/Icinga/Web/LessCompiler.php
|
||||
./library/Icinga/Web/Form.php
|
||||
./library/Icinga/Web/Form/Element/Number.php
|
||||
./library/Icinga/Web/Form/Element/DateTimePicker.php
|
||||
./library/Icinga/Web/Form/Element/TriStateCheckbox.php
|
||||
./library/Icinga/Web/Form/Element/Note.php
|
||||
./library/Icinga/Web/Form/Decorator/ConditionalHidden.php
|
||||
./library/Icinga/Web/Form/Decorator/BootstrapForm.php
|
||||
./library/Icinga/Web/Form/Decorator/HelpText.php
|
||||
./library/Icinga/Web/Form/Validator/DateFormatValidator.php
|
||||
./library/Icinga/Web/Form/Validator/TriStateValidator.php
|
||||
./library/Icinga/Web/Form/Validator/DateTimeValidator.php
|
||||
./library/Icinga/Web/Form/Validator/TimeFormatValidator.php
|
||||
./library/Icinga/Web/Form/Validator/WritablePathValidator.php
|
||||
./library/Icinga/Web/Form/InvalidCSRFTokenException.php
|
||||
./library/Icinga/Cli/Documentation/CommentParser.php
|
||||
./library/Icinga/Cli/Params.php
|
||||
./library/Icinga/Cli/Documentation.php
|
||||
./library/Icinga/Cli/Screen/AnsiScreen.php
|
||||
./library/Icinga/Cli/Loader.php
|
||||
./library/Icinga/Cli/Command.php
|
||||
./library/Icinga/Cli/Screen.php
|
||||
./library/Icinga/Util/File.php
|
||||
./library/Icinga/Util/Dimension.php
|
||||
./library/Icinga/Util/DateTimeFactory.php
|
||||
./library/Icinga/Util/Color.php
|
||||
./library/Icinga/Util/String.php
|
||||
./library/Icinga/Util/Format.php
|
||||
./library/Icinga/Util/ConfigAwareFactory.php
|
||||
./library/Icinga/Util/Translator.php
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -456,13 +457,8 @@ abstract class ApplicationBootstrap
|
|||
protected function setupTimezone()
|
||||
{
|
||||
$timeZoneString = $this->config->global !== null ? $this->config->global->get('timezone', 'UTC') : 'UTC';
|
||||
try {
|
||||
$tz = new DateTimeZone($timeZoneString);
|
||||
} catch (Exception $e) {
|
||||
throw new ConfigurationError(t('Invalid timezone') . ' "' . $timeZoneString . '"');
|
||||
}
|
||||
date_default_timezone_set($timeZoneString);
|
||||
DateTimeFactory::setConfig(array('timezone' => $tz));
|
||||
DateTimeFactory::setConfig(array('timezone' => $timeZoneString));
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -492,3 +488,4 @@ abstract class ApplicationBootstrap
|
|||
return $this;
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -317,3 +318,4 @@ class Benchmark
|
|||
{
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -183,3 +184,4 @@ class Cli extends ApplicationBootstrap
|
|||
throw new ProgrammingError('Icinga is not running on CLI');
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -61,3 +62,4 @@ class EmbeddedWeb extends ApplicationBootstrap
|
|||
->loadEnabledModules();
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -55,3 +56,4 @@ class LegacyWeb extends Web
|
|||
return $this->legacyBasedir;
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -92,3 +93,4 @@ class Platform
|
|||
}
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -337,13 +338,12 @@ class Web extends ApplicationBootstrap
|
|||
}
|
||||
|
||||
try {
|
||||
$tz = new DateTimeZone($userTimezone);
|
||||
} catch (Exception $e) {
|
||||
DateTimeFactory::setConfig(array('timezone' => $userTimezone));
|
||||
date_default_timezone_set($userTimezone);
|
||||
} catch (ConfigurationError $e) {
|
||||
return parent::setupTimezone();
|
||||
}
|
||||
|
||||
date_default_timezone_set($userTimezone);
|
||||
DateTimeFactory::setConfig(array('timezone' => $tz));
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -372,3 +372,4 @@ class Web extends ApplicationBootstrap
|
|||
return $this;
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -29,14 +29,13 @@
|
|||
|
||||
namespace Icinga\Config;
|
||||
|
||||
use \Zend_Config;
|
||||
use \Zend_Config_Ini;
|
||||
use \Zend_Config_Writer_FileAbstract;
|
||||
use \Icinga\Config\IniEditor;
|
||||
use Zend_Config;
|
||||
use Zend_Config_Ini;
|
||||
use Zend_Config_Writer_FileAbstract;
|
||||
use Icinga\Config\IniEditor;
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
|
@ -45,7 +44,7 @@ class PreservingIniWriter extends Zend_Config_Writer_FileAbstract
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
private $options;
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* Create a new PreservingIniWriter
|
||||
|
@ -67,7 +66,7 @@ class PreservingIniWriter extends Zend_Config_Writer_FileAbstract
|
|||
/**
|
||||
* Render the Zend_Config into a config file string
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
|
@ -86,12 +85,12 @@ class PreservingIniWriter extends Zend_Config_Writer_FileAbstract
|
|||
/**
|
||||
* Create a property diff and apply the changes to the editor
|
||||
*
|
||||
* @param Zend_Config $oldconfig The config representing the state before the change
|
||||
* @param Zend_Config $newconfig The config representing the state after the change
|
||||
* @param IniEditor $editor The editor that should be used to edit the old config file
|
||||
* @param array $parents The parent keys that should be respected when editing the config
|
||||
* @param Zend_Config $oldconfig The config representing the state before the change
|
||||
* @param Zend_Config $newconfig The config representing the state after the change
|
||||
* @param IniEditor $editor The editor that should be used to edit the old config file
|
||||
* @param array $parents The parent keys that should be respected when editing the config
|
||||
*/
|
||||
private function diffConfigs(
|
||||
protected function diffConfigs(
|
||||
Zend_Config $oldconfig,
|
||||
Zend_Config $newconfig,
|
||||
IniEditor $editor,
|
||||
|
@ -102,13 +101,10 @@ class PreservingIniWriter extends Zend_Config_Writer_FileAbstract
|
|||
}
|
||||
|
||||
/**
|
||||
* Update the order of the sections in the ini file to match
|
||||
* the order of the new config
|
||||
* Update the order of the sections in the ini file to match the order of the new config
|
||||
*/
|
||||
private function updateSectionOrder(
|
||||
Zend_Config $newconfig,
|
||||
IniEditor $editor
|
||||
) {
|
||||
protected function updateSectionOrder(Zend_Config $newconfig, IniEditor $editor)
|
||||
{
|
||||
$order = array();
|
||||
foreach ($newconfig as $key => $value) {
|
||||
if ($value instanceof Zend_Config) {
|
||||
|
@ -126,48 +122,35 @@ class PreservingIniWriter extends Zend_Config_Writer_FileAbstract
|
|||
* @param IniEditor $editor The editor that should be used to edit the old config file
|
||||
* @param array $parents The parent keys that should be respected when editing the config
|
||||
*/
|
||||
private function diffPropertyUpdates(
|
||||
protected function diffPropertyUpdates(
|
||||
Zend_Config $oldconfig,
|
||||
Zend_Config $newconfig,
|
||||
IniEditor $editor,
|
||||
array $parents = array()
|
||||
) {
|
||||
/*
|
||||
* The current section. This value is null when processing
|
||||
* the section-less root element
|
||||
*/
|
||||
// The current section. This value is null when processing the section-less root element
|
||||
$section = empty($parents) ? null : $parents[0];
|
||||
|
||||
/*
|
||||
* Iterate over all properties in the new configuration file and search for changes
|
||||
*/
|
||||
// Iterate over all properties in the new configuration file and search for changes
|
||||
foreach ($newconfig as $key => $value) {
|
||||
$oldvalue = $oldconfig->get($key);
|
||||
$nextParents = array_merge($parents, array($key));
|
||||
$keyIdentifier = empty($parents) ?
|
||||
array($key) : array_slice($nextParents, 1, null, true);
|
||||
$keyIdentifier = empty($parents) ? array($key) : array_slice($nextParents, 1, null, true);
|
||||
|
||||
if ($value instanceof Zend_Config) {
|
||||
/*
|
||||
* The value is a nested Zend_Config, handle it recursively
|
||||
*/
|
||||
if (!isset($section)) {
|
||||
/*
|
||||
* Update the section declaration
|
||||
*/
|
||||
// The value is a nested Zend_Config, handle it recursively
|
||||
if ($section === null) {
|
||||
// Update the section declaration
|
||||
$extends = $newconfig->getExtends();
|
||||
$extend = array_key_exists($key, $extends) ?
|
||||
$extends[$key] : null;
|
||||
$extend = array_key_exists($key, $extends) ? $extends[$key] : null;
|
||||
$editor->setSection($key, $extend);
|
||||
}
|
||||
if (!isset($oldvalue)) {
|
||||
if ($oldvalue === null) {
|
||||
$oldvalue = new Zend_Config(array());
|
||||
}
|
||||
$this->diffConfigs($oldvalue, $value, $editor, $nextParents);
|
||||
} else {
|
||||
/*
|
||||
* The value is a plain value, use the editor to set it
|
||||
*/
|
||||
// The value is a plain value, use the editor to set it
|
||||
if (is_numeric($key)) {
|
||||
$editor->setArrayElement($keyIdentifier, $value, $section);
|
||||
} else {
|
||||
|
@ -185,41 +168,30 @@ class PreservingIniWriter extends Zend_Config_Writer_FileAbstract
|
|||
* @param IniEditor $editor The editor that should be used to edit the old config file
|
||||
* @param array $parents The parent keys that should be respected when editing the config
|
||||
*/
|
||||
private function diffPropertyDeletions(
|
||||
protected function diffPropertyDeletions(
|
||||
Zend_Config $oldconfig,
|
||||
Zend_Config $newconfig,
|
||||
IniEditor $editor,
|
||||
array $parents = array()
|
||||
) {
|
||||
/*
|
||||
* The current section. This value is null when processing
|
||||
* the section-less root element
|
||||
*/
|
||||
// The current section. This value is null when processing the section-less root element
|
||||
$section = empty($parents) ? null : $parents[0];
|
||||
|
||||
/*
|
||||
* Iterate over all properties in the old configuration file and search for
|
||||
* deleted properties
|
||||
*/
|
||||
// Iterate over all properties in the old configuration file and search for deleted properties
|
||||
foreach ($oldconfig as $key => $value) {
|
||||
$nextParents = array_merge($parents, array($key));
|
||||
$newvalue = $newconfig->get($key);
|
||||
$keyIdentifier = empty($parents) ?
|
||||
array($key) : array_slice($nextParents, 1, null, true);
|
||||
$keyIdentifier = empty($parents) ? array($key) : array_slice($nextParents, 1, null, true);
|
||||
|
||||
if (!isset($newvalue)) {
|
||||
if ($newvalue === null) {
|
||||
if ($value instanceof Zend_Config) {
|
||||
/*
|
||||
* The deleted value is a nested Zend_Config, handle it recursively
|
||||
*/
|
||||
// The deleted value is a nested Zend_Config, handle it recursively
|
||||
$this->diffConfigs($value, new Zend_Config(array()), $editor, $nextParents);
|
||||
if (!isset($section)) {
|
||||
if ($section === null) {
|
||||
$editor->removeSection($key);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* The deleted value is a plain value, use the editor to delete it
|
||||
*/
|
||||
// The deleted value is a plain value, use the editor to delete it
|
||||
if (is_numeric($key)) {
|
||||
$editor->resetArrayElement($keyIdentifier, $section);
|
||||
} else {
|
||||
|
|
|
@ -142,9 +142,4 @@ class ResourceFactory implements ConfigAwareFactory
|
|||
}
|
||||
return $resource;
|
||||
}
|
||||
|
||||
public static function getBackendType($resource)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\File;
|
||||
|
||||
|
@ -10,6 +12,7 @@ class Csv
|
|||
|
||||
protected function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function fromQuery(BaseQuery $query)
|
||||
|
@ -40,6 +43,7 @@ class Csv
|
|||
}
|
||||
$csv .= implode(',', $out) . "\r\n";
|
||||
}
|
||||
|
||||
return $csv;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
namespace Icinga\File;
|
||||
|
||||
|
@ -215,3 +216,4 @@ class Pdf extends DOMPDF
|
|||
// }
|
||||
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Icinga\Logger;
|
||||
|
||||
use \Zend_Config;
|
||||
use Zend_Config;
|
||||
|
||||
/**
|
||||
* Abstract class for writers that write messages to a log
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
namespace Icinga\Logger;
|
||||
|
||||
use \Exception;
|
||||
use \Zend_Config;
|
||||
use Exception;
|
||||
use Zend_Config;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
|
||||
namespace Icinga\Logger\Writer;
|
||||
|
||||
use \Zend_Config;
|
||||
use Exception;
|
||||
use Zend_Config;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Logger\LogWriter;
|
||||
use Icinga\Application\Config;
|
||||
|
@ -87,11 +88,17 @@ class StreamWriter extends LogWriter
|
|||
* Write a message to the stream
|
||||
*
|
||||
* @param string $text The message to write
|
||||
*
|
||||
* @throws Exception In case write acess to the stream failed
|
||||
*/
|
||||
protected function write($text)
|
||||
{
|
||||
$fd = fopen($this->stream, 'a');
|
||||
fwrite($fd, $text . PHP_EOL);
|
||||
|
||||
if ($fd === false || fwrite($fd, $text . PHP_EOL) === false) {
|
||||
throw new Exception('Failed to write to log file "' . $this->stream . '"');
|
||||
}
|
||||
|
||||
fclose($fd);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Logger\Writer;
|
||||
|
||||
use \Exception;
|
||||
use \Zend_Config;
|
||||
use Exception;
|
||||
use Zend_Config;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Logger\LogWriter;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
|
@ -106,3 +107,4 @@ class SyslogWriter extends LogWriter
|
|||
closelog();
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -273,6 +273,15 @@ class Connection
|
|||
}
|
||||
}
|
||||
|
||||
public function connect()
|
||||
{
|
||||
if (!$this->connection) {
|
||||
$this->getConnection();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function disconnect()
|
||||
{
|
||||
if ($this->connection) {
|
||||
|
|
|
@ -21,12 +21,12 @@ namespace {
|
|||
|
||||
namespace Icinga\Test {
|
||||
|
||||
use \Exception;
|
||||
use \DateTimeZone;
|
||||
use \RuntimeException;
|
||||
use \Mockery;
|
||||
use \Zend_Config;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
use Exception;
|
||||
use RuntimeException;
|
||||
use Mockery;
|
||||
use Zend_Config;
|
||||
use Zend_Controller_Request_Abstract;
|
||||
use Zend_Test_PHPUnit_ControllerTestCase;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
|
@ -86,7 +86,7 @@ namespace Icinga\Test {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $dbConfiguration = array(
|
||||
protected static $dbConfiguration = array(
|
||||
'mysql' => array(
|
||||
'type' => 'db',
|
||||
'db' => 'mysql',
|
||||
|
@ -113,7 +113,7 @@ namespace Icinga\Test {
|
|||
public static function setupTimezone()
|
||||
{
|
||||
date_default_timezone_set('UTC');
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
DateTimeFactory::setConfig(array('timezone' => 'UTC'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,23 +143,25 @@ namespace Icinga\Test {
|
|||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->setupIcingaMock();
|
||||
|
||||
$requestMock = Mockery::mock('Icinga\Web\Request');
|
||||
$requestMock->shouldReceive('getPathInfo')->andReturn('')
|
||||
->shouldReceive('getBaseUrl')->andReturn('/')
|
||||
->shouldReceive('getQuery')->andReturn(array());
|
||||
$this->setupIcingaMock($requestMock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup mock object for the application's bootstrap
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request The request to be returned by
|
||||
* Icinga::app()->getFrontController()->getRequest()
|
||||
*/
|
||||
protected function setupIcingaMock()
|
||||
protected function setupIcingaMock(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
$bootstrapMock = Mockery::mock('Icinga\Application\ApplicationBootstrap')->shouldDeferMissing();
|
||||
$bootstrapMock->shouldReceive('getFrontController->getRequest')->andReturnUsing(
|
||||
function () {
|
||||
return Mockery::mock('Request')
|
||||
->shouldReceive('getPathInfo')->andReturn('')
|
||||
->shouldReceive('getBaseUrl')->andReturn('/')
|
||||
->shouldReceive('getQuery')->andReturn(array())
|
||||
->getMock();
|
||||
}
|
||||
function () use ($request) { return $request; }
|
||||
)->shouldReceive('getApplicationDir')->andReturn(self::$appDir);
|
||||
|
||||
Icinga::setApp($bootstrapMock, true);
|
||||
|
|
|
@ -29,18 +29,15 @@
|
|||
|
||||
namespace Icinga;
|
||||
|
||||
use \DateTimeZone;
|
||||
use \Exception;
|
||||
use \InvalidArgumentException;
|
||||
use DateTimeZone;
|
||||
use InvalidArgumentException;
|
||||
use Icinga\User\Preferences;
|
||||
use Icinga\User\Message;
|
||||
use Icinga\Application\Config;
|
||||
|
||||
/**
|
||||
* This class represents an authorized user
|
||||
*
|
||||
* You can retrieve authorization information (@TODO: Not implemented yet) or
|
||||
* to retrieve user information
|
||||
* You can retrieve authorization information (@TODO: Not implemented yet) or user information
|
||||
*/
|
||||
class User
|
||||
{
|
||||
|
@ -49,85 +46,85 @@ class User
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $username;
|
||||
protected $username;
|
||||
|
||||
/**
|
||||
* Firstname
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $firstname;
|
||||
protected $firstname;
|
||||
|
||||
/**
|
||||
* Lastname
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $lastname;
|
||||
protected $lastname;
|
||||
|
||||
/**
|
||||
* Users email address
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $email;
|
||||
protected $email;
|
||||
|
||||
/**
|
||||
* Domain
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $domain;
|
||||
protected $domain;
|
||||
|
||||
/**
|
||||
* More information about user
|
||||
* More information about this user
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $additionalInformation = array();
|
||||
protected $additionalInformation = array();
|
||||
|
||||
/**
|
||||
* Set of permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $permissions = array();
|
||||
protected $permissions = array();
|
||||
|
||||
/**
|
||||
* Set of restrictions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $restrictions = array();
|
||||
protected $restrictions = array();
|
||||
|
||||
/**
|
||||
* Groups for this user
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $groups = array();
|
||||
protected $groups = array();
|
||||
|
||||
/**
|
||||
* Preferences object
|
||||
*
|
||||
* @var Preferences
|
||||
*/
|
||||
private $preferences;
|
||||
protected $preferences;
|
||||
|
||||
/**
|
||||
* Queued notifications for this user.
|
||||
*
|
||||
* @var array()
|
||||
*/
|
||||
private $messages;
|
||||
protected $messages;
|
||||
|
||||
/**
|
||||
* Creates a user object given the provided information
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $firstname
|
||||
* @param string $lastname
|
||||
* @param string $email
|
||||
* @param string $username
|
||||
* @param string $firstname
|
||||
* @param string $lastname
|
||||
* @param string $email
|
||||
*/
|
||||
public function __construct($username, $firstname = null, $lastname = null, $email = null)
|
||||
{
|
||||
|
@ -149,7 +146,7 @@ class User
|
|||
/**
|
||||
* Setter for preferences
|
||||
*
|
||||
* @param Preferences $preferences
|
||||
* @param Preferences $preferences
|
||||
*/
|
||||
public function setPreferences(Preferences $preferences)
|
||||
{
|
||||
|
@ -159,20 +156,21 @@ class User
|
|||
/**
|
||||
* Getter for preferences
|
||||
*
|
||||
* @return Preferences
|
||||
* @return Preferences
|
||||
*/
|
||||
public function getPreferences()
|
||||
{
|
||||
if ($this->preferences === null) {
|
||||
$this->preferences = new Preferences();
|
||||
}
|
||||
|
||||
return $this->preferences;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all groups this user belongs to
|
||||
*
|
||||
* @return array
|
||||
* @return array
|
||||
*/
|
||||
public function getGroups()
|
||||
{
|
||||
|
@ -181,6 +179,8 @@ class User
|
|||
|
||||
/**
|
||||
* Set the groups this user belongs to
|
||||
*
|
||||
* @param array $groups
|
||||
*/
|
||||
public function setGroups(array $groups)
|
||||
{
|
||||
|
@ -190,8 +190,9 @@ class User
|
|||
/**
|
||||
* Return true if the user is a member of this group
|
||||
*
|
||||
* @param string $group
|
||||
* @return boolean
|
||||
* @param string $group
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isMemberOf($group)
|
||||
{
|
||||
|
@ -201,7 +202,7 @@ class User
|
|||
/**
|
||||
* Return permission information for this user
|
||||
*
|
||||
* @return Array
|
||||
* @return array
|
||||
*/
|
||||
public function getPermissions()
|
||||
{
|
||||
|
@ -211,7 +212,7 @@ class User
|
|||
/**
|
||||
* Setter for permissions
|
||||
*
|
||||
* @param array $permissions
|
||||
* @param array $permissions
|
||||
*/
|
||||
public function setPermissions(array $permissions)
|
||||
{
|
||||
|
@ -222,6 +223,7 @@ class User
|
|||
* Return restriction information for this user
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRestrictions($name)
|
||||
|
@ -229,13 +231,14 @@ class User
|
|||
if (array_key_exists($name, $this->restrictions)) {
|
||||
return $this->restrictions[$name];
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Settter for restrictions
|
||||
*
|
||||
* @param array $restrictions
|
||||
* @param array $restrictions
|
||||
*/
|
||||
public function setRestrictions(array $restrictions)
|
||||
{
|
||||
|
@ -245,7 +248,7 @@ class User
|
|||
/**
|
||||
* Getter for username
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getUsername()
|
||||
{
|
||||
|
@ -255,7 +258,7 @@ class User
|
|||
/**
|
||||
* Setter for username
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
*/
|
||||
public function setUsername($name)
|
||||
{
|
||||
|
@ -265,7 +268,7 @@ class User
|
|||
/**
|
||||
* Getter for firstname
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getFirstname()
|
||||
{
|
||||
|
@ -275,7 +278,7 @@ class User
|
|||
/**
|
||||
* Setter for firstname
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
*/
|
||||
public function setFirstname($name)
|
||||
{
|
||||
|
@ -285,7 +288,7 @@ class User
|
|||
/**
|
||||
* Getter for lastname
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getLastname()
|
||||
{
|
||||
|
@ -295,7 +298,7 @@ class User
|
|||
/**
|
||||
* Setter for lastname
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
*/
|
||||
public function setLastname($name)
|
||||
{
|
||||
|
@ -305,7 +308,7 @@ class User
|
|||
/**
|
||||
* Getter for email
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
|
@ -315,8 +318,9 @@ class User
|
|||
/**
|
||||
* Setter for mail
|
||||
*
|
||||
* @param string $mail
|
||||
* @throws InvalidArgumentException When an invalid mail is provided
|
||||
* @param string $mail
|
||||
*
|
||||
* @throws InvalidArgumentException When an invalid mail is provided
|
||||
*/
|
||||
public function setEmail($mail)
|
||||
{
|
||||
|
@ -330,7 +334,7 @@ class User
|
|||
/**
|
||||
* Setter for domain
|
||||
*
|
||||
* @param string $domain
|
||||
* @param string $domain
|
||||
*/
|
||||
public function setDomain($domain)
|
||||
{
|
||||
|
@ -340,7 +344,7 @@ class User
|
|||
/**
|
||||
* Getter for domain
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getDomain()
|
||||
{
|
||||
|
@ -351,8 +355,8 @@ class User
|
|||
/**
|
||||
* Set additional information about user
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*/
|
||||
public function setAdditional($key, $value)
|
||||
{
|
||||
|
@ -362,14 +366,15 @@ class User
|
|||
/**
|
||||
* Getter for additional information
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed|null
|
||||
* @param string $key
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function getAdditional($key)
|
||||
{
|
||||
if (isset($this->additionalInformation[$key])) {
|
||||
return $this->additionalInformation[$key];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -386,6 +391,7 @@ class User
|
|||
if ($tz === null) {
|
||||
$tz = date_default_timezone_get();
|
||||
}
|
||||
|
||||
return new DateTimeZone($tz);
|
||||
}
|
||||
|
||||
|
@ -394,7 +400,7 @@ class User
|
|||
*
|
||||
* This function does NOT automatically write to the session, messages will not be persisted until you do.
|
||||
*
|
||||
* @param Message $msg The message
|
||||
* @param Message $msg The message
|
||||
*/
|
||||
public function addMessage(Message $msg)
|
||||
{
|
||||
|
@ -404,7 +410,7 @@ class User
|
|||
/**
|
||||
* Get all currently pending messages
|
||||
*
|
||||
* @return array the messages
|
||||
* @return array The messages
|
||||
*/
|
||||
public function getMessages()
|
||||
{
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
namespace Icinga\User;
|
||||
|
||||
use \Zend_Log;
|
||||
use Zend_Log;
|
||||
|
||||
/**
|
||||
* Class Message
|
||||
|
@ -55,3 +56,4 @@ class Message
|
|||
return $this->level;
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -44,8 +44,6 @@ use Countable;
|
|||
*
|
||||
* $preferences = new Preferences(array('aPreference' => 'value')); // Start with initial preferences
|
||||
*
|
||||
* $prefrences = $user->getPreferences(); // Retrieve preferences from a \Icinga\User instance
|
||||
*
|
||||
* $preferences->aNewPreference = 'value'; // Set a preference
|
||||
*
|
||||
* unset($preferences->aPreference); // Unset a preference
|
||||
|
@ -60,12 +58,12 @@ class Preferences implements Countable
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
private $preferences = array();
|
||||
protected $preferences = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $preferences Preferences key-value array
|
||||
* @param array $preferences Preferences key-value array
|
||||
*/
|
||||
public function __construct(array $preferences = array())
|
||||
{
|
||||
|
@ -75,7 +73,7 @@ class Preferences implements Countable
|
|||
/**
|
||||
* Count all preferences
|
||||
*
|
||||
* @return int The number of preferences
|
||||
* @return int The number of preferences
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
|
@ -85,7 +83,7 @@ class Preferences implements Countable
|
|||
/**
|
||||
* Determine whether a preference exists
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -97,8 +95,8 @@ class Preferences implements Countable
|
|||
/**
|
||||
* Write data to a preference
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
|
@ -108,8 +106,8 @@ class Preferences implements Countable
|
|||
/**
|
||||
* Retrieve a preference and return $default if the preference is not set
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $default
|
||||
* @param string $name
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
|
@ -118,13 +116,14 @@ class Preferences implements Countable
|
|||
if (array_key_exists($name, $this->preferences)) {
|
||||
return $this->preferences[$name];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method so that $obj->value will work.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
|
@ -136,7 +135,7 @@ class Preferences implements Countable
|
|||
/**
|
||||
* Remove a given preference
|
||||
*
|
||||
* @param string $name Preference name
|
||||
* @param string $name Preference name
|
||||
*/
|
||||
public function remove($name)
|
||||
{
|
||||
|
@ -146,7 +145,8 @@ class Preferences implements Countable
|
|||
/**
|
||||
* Determine if a preference is set and is not NULL
|
||||
*
|
||||
* @param string $name Preference name
|
||||
* @param string $name Preference name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($name)
|
||||
|
@ -157,7 +157,7 @@ class Preferences implements Countable
|
|||
/**
|
||||
* Unset a given preference
|
||||
*
|
||||
* @param string $name Preference name
|
||||
* @param string $name Preference name
|
||||
*/
|
||||
public function __unset($name)
|
||||
{
|
||||
|
@ -167,7 +167,7 @@ class Preferences implements Countable
|
|||
/**
|
||||
* Get preferences as array
|
||||
*
|
||||
* @return array
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
namespace Icinga\User\Preferences\Store;
|
||||
|
||||
use \Exception;
|
||||
use \Zend_Db_Select;
|
||||
use Exception;
|
||||
use Zend_Db_Select;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
use Icinga\Exception\NotWritableError;
|
||||
use Icinga\User\Preferences;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Icinga\User\Preferences\Store;
|
||||
|
||||
use \Zend_Config;
|
||||
use Zend_Config;
|
||||
use Icinga\Util\File;
|
||||
use Icinga\Config\PreservingIniWriter;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
|
|
|
@ -29,8 +29,9 @@
|
|||
|
||||
namespace Icinga\Util;
|
||||
|
||||
use \DateTime;
|
||||
use \DateTimeZone;
|
||||
use Exception;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Icinga\Util\ConfigAwareFactory;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
|
||||
|
@ -41,35 +42,42 @@ class DateTimeFactory implements ConfigAwareFactory
|
|||
{
|
||||
/**
|
||||
* Time zone used throughout DateTime object creation
|
||||
*
|
||||
* @var DateTimeZone
|
||||
*/
|
||||
private static $timeZone;
|
||||
protected static $timeZone;
|
||||
|
||||
/**
|
||||
* Set the factory's config
|
||||
*
|
||||
* Set the factory's time zone via key timezone in the given config array
|
||||
*
|
||||
* @param array $config
|
||||
* @throws \Icinga\Exception\ConfigurationError if the given config is not valid
|
||||
* @param array $config An array with key 'timezone'
|
||||
*
|
||||
* @throws ConfigurationError if the given array misses the key 'timezone'
|
||||
*/
|
||||
public static function setConfig($config)
|
||||
{
|
||||
if (!array_key_exists('timezone', $config)) {
|
||||
throw new ConfigurationError(t('"DateTimeFactory" expects a valid time zone to be set via "setConfig"'));
|
||||
try {
|
||||
$tz = new DateTimeZone(isset($config['timezone']) ? $config['timezone'] : '');
|
||||
} catch (Exception $e) {
|
||||
throw new ConfigurationError('"DateTimeFactory" expects a valid time zone be set via "setConfig"');
|
||||
}
|
||||
self::$timeZone = $config['timezone'];
|
||||
|
||||
self::$timeZone = $tz;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return new DateTime object using the given format, time and set time zone
|
||||
* Return new DateTime object using the given format, time and set timezone
|
||||
*
|
||||
* Wraps DateTime::createFromFormat()
|
||||
*
|
||||
* @param string $format
|
||||
* @param string $time
|
||||
* @param DateTimeZone $timeZone
|
||||
*
|
||||
* @return DateTime
|
||||
*
|
||||
* @see DateTime::createFromFormat()
|
||||
*/
|
||||
public static function parse($time, $format, DateTimeZone $timeZone = null)
|
||||
|
@ -84,46 +92,13 @@ class DateTimeFactory implements ConfigAwareFactory
|
|||
*
|
||||
* @param string $time
|
||||
* @param DateTimeZone $timeZone
|
||||
*
|
||||
* @return DateTime
|
||||
*
|
||||
* @see DateTime::__construct()
|
||||
*/
|
||||
public static function create($time = 'now', DateTimeZone $timeZone = null)
|
||||
{
|
||||
return new DateTime($time, $timeZone !== null ? $timeZone : self::$timeZone);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the amount of seconds based on the given month
|
||||
*
|
||||
* @param DateTime $dateTime The date and time to use
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getSecondsByMonth(DateTime $dateTime)
|
||||
{
|
||||
return (int) $dateTime->format('t') * 24 * 3600;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the amount of seconds based on the given year
|
||||
*
|
||||
* @param DateTime $dateTime The date and time to use
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getSecondsByYear(DateTime $dateTime)
|
||||
{
|
||||
return (self::isLeapYear($dateTime) ? 366 : 365) * 24 * 3600;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the given year is a leap year
|
||||
*
|
||||
* @param DateTime $dateTime The date and time to check
|
||||
* @return bool
|
||||
*/
|
||||
public static function isLeapYear(DateTime $dateTime)
|
||||
{
|
||||
return $dateTime->format('L') == 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
|
@ -11,4 +12,5 @@ class File
|
|||
fclose(fopen($filename, 'a'));
|
||||
chmod($filename, $mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
namespace Icinga\Util;
|
||||
|
||||
use DateTime;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
|
||||
class Format
|
||||
|
@ -150,4 +151,50 @@ class Format
|
|||
$units[$pow]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the amount of seconds based on the given month
|
||||
*
|
||||
* @param DateTime|int $dateTimeOrTimestamp The date and time to use
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function secondsByMonth($dateTimeOrTimestamp)
|
||||
{
|
||||
if (!($dt = $dateTimeOrTimestamp) instanceof DateTime) {
|
||||
$dt = new DateTime();
|
||||
$dt->setTimestamp($dateTimeOrTimestamp);
|
||||
}
|
||||
|
||||
return (int) $dt->format('t') * 24 * 3600;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the amount of seconds based on the given year
|
||||
*
|
||||
* @param DateTime|int $dateTimeOrTimestamp The date and time to use
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function secondsByYear($dateTimeOrTimestamp)
|
||||
{
|
||||
return (self::isLeapYear($dateTimeOrTimestamp) ? 366 : 365) * 24 * 3600;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the given year is a leap year
|
||||
*
|
||||
* @param DateTime|int $dateTimeOrTimestamp The date and time to use
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isLeapYear($dateTimeOrTimestamp)
|
||||
{
|
||||
if (!($dt = $dateTimeOrTimestamp) instanceof DateTime) {
|
||||
$dt = new DateTime();
|
||||
$dt->setTimestamp($dateTimeOrTimestamp);
|
||||
}
|
||||
|
||||
return $dt->format('L') == 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
namespace Icinga\Util;
|
||||
|
||||
use \Exception;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Helper class to ease internationalization when using gettext
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -464,3 +465,4 @@ class ActionController extends Zend_Controller_Action
|
|||
return parent::__call($name, $params);
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -29,7 +30,7 @@
|
|||
|
||||
namespace Icinga\Web\Controller;
|
||||
|
||||
use \Zend_Log;
|
||||
use Zend_Log;
|
||||
use Icinga\Web\Session;
|
||||
use Icinga\User\Message;
|
||||
use Icinga\Authentication\Manager as AuthenticationManager;
|
||||
|
@ -95,3 +96,4 @@ class BaseConfigController extends ActionController
|
|||
$this->view->tabs = ControllerTabCollector::collectControllerTabs('ConfigController');
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -91,3 +92,4 @@ class BasePreferenceController extends ActionController
|
|||
$store->save($currentPreferences);
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -29,18 +30,16 @@
|
|||
|
||||
namespace Icinga\Web\Controller;
|
||||
|
||||
use \Icinga\Application\Modules\Module;
|
||||
use \Icinga\Application\Icinga;
|
||||
use \Icinga\Web\Widget\Tabs;
|
||||
use Icinga\Application\Modules\Module;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Web\Widget\Tabs;
|
||||
|
||||
/**
|
||||
* Static helper class that collects tabs provided by the 'createProvidedTabs' method
|
||||
* of controllers.
|
||||
*
|
||||
*/
|
||||
class ControllerTabCollector
|
||||
{
|
||||
|
||||
/**
|
||||
* Scan all controllers with the provided name
|
||||
* in the application and (loaded) module folders and collects their provided tabs
|
||||
|
@ -124,3 +123,4 @@ class ControllerTabCollector
|
|||
return array();
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -29,18 +29,18 @@
|
|||
|
||||
namespace Icinga\Web;
|
||||
|
||||
use \Zend_Controller_Request_Abstract;
|
||||
use \Zend_Form;
|
||||
use \Zend_Config;
|
||||
use \Zend_Form_Element_Submit;
|
||||
use \Zend_Form_Element_Reset;
|
||||
use \Zend_View_Interface;
|
||||
use \Icinga\Web\Form\Element\Note;
|
||||
use \Icinga\Exception\ProgrammingError;
|
||||
use \Icinga\Web\Form\Decorator\HelpText;
|
||||
use \Icinga\Web\Form\Decorator\BootstrapForm;
|
||||
use \Icinga\Web\Form\InvalidCSRFTokenException;
|
||||
use \Icinga\Application\Config as IcingaConfig;
|
||||
use Zend_Controller_Request_Abstract;
|
||||
use Zend_Form;
|
||||
use Zend_Config;
|
||||
use Zend_Form_Element_Submit;
|
||||
use Zend_Form_Element_Reset;
|
||||
use Zend_View_Interface;
|
||||
use Icinga\Web\Form\Element\Note;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Web\Form\Decorator\HelpText;
|
||||
use Icinga\Web\Form\Decorator\BootstrapForm;
|
||||
use Icinga\Web\Form\InvalidCSRFTokenException;
|
||||
use Icinga\Application\Config as IcingaConfig;
|
||||
|
||||
/**
|
||||
* Base class for forms providing CSRF protection, confirmation logic and auto submission
|
||||
|
@ -52,7 +52,7 @@ class Form extends Zend_Form
|
|||
*
|
||||
* @var Zend_Controller_Request_Abstract
|
||||
*/
|
||||
private $request;
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Main configuration
|
||||
|
@ -61,14 +61,14 @@ class Form extends Zend_Form
|
|||
*
|
||||
* @var IcingaConfig
|
||||
*/
|
||||
private $config;
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* The preference object to use instead of the one from the user (used for testing)
|
||||
*
|
||||
* @var Zend_Config
|
||||
*/
|
||||
private $preferences;
|
||||
protected $preferences;
|
||||
|
||||
/**
|
||||
* Whether this form should NOT add random generated "challenge" tokens that are associated with the user's current
|
||||
|
@ -84,21 +84,21 @@ class Form extends Zend_Form
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $tokenElementName = 'CSRFToken';
|
||||
protected $tokenElementName = 'CSRFToken';
|
||||
|
||||
/**
|
||||
* Flag to indicate that form is already build
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $created = false;
|
||||
protected $created = false;
|
||||
|
||||
/**
|
||||
* Session id used for CSRF token generation
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $sessionId;
|
||||
protected $sessionId;
|
||||
|
||||
/**
|
||||
* Label for submit button
|
||||
|
@ -107,7 +107,7 @@ class Form extends Zend_Form
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $submitLabel;
|
||||
protected $submitLabel;
|
||||
|
||||
/**
|
||||
* Label for cancel button
|
||||
|
@ -116,7 +116,7 @@ class Form extends Zend_Form
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $cancelLabel;
|
||||
protected $cancelLabel;
|
||||
|
||||
/**
|
||||
* Last used note-id
|
||||
|
@ -125,21 +125,7 @@ class Form extends Zend_Form
|
|||
*
|
||||
* @var int
|
||||
*/
|
||||
private $last_note_id = 0;
|
||||
|
||||
/**
|
||||
* Decorator that replaces the DtDd Zend-Form default
|
||||
*
|
||||
* @var Form\Decorator\BootstrapFormDecorator
|
||||
*/
|
||||
private $formDecorator;
|
||||
|
||||
/**
|
||||
* Whether to ignore users leaving the form with unsaved changes
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $ignoreChangeDiscarding = false;
|
||||
protected $last_note_id = 0;
|
||||
|
||||
/**
|
||||
* Getter for the session ID
|
||||
|
@ -147,26 +133,14 @@ class Form extends Zend_Form
|
|||
* If the ID has never been set, the ID from session_id() is returned
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @see session_id()
|
||||
* @see setSessionId()
|
||||
*/
|
||||
public function getSessionId()
|
||||
{
|
||||
if (!$this->sessionId) {
|
||||
$this->sessionId = session_id();
|
||||
}
|
||||
return $this->sessionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to inform a user when he is about to discard changes (false, default) or not
|
||||
*
|
||||
* @param boolean $bool False to not inform users when they leave modified forms, otherwise true
|
||||
*/
|
||||
public function setIgnoreChangeDiscarding($bool)
|
||||
{
|
||||
$this->ignoreChangeDiscarding = (boolean) $bool;
|
||||
return $this->sessionId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -174,7 +148,7 @@ class Form extends Zend_Form
|
|||
*
|
||||
* This method should be used for testing purposes only
|
||||
*
|
||||
* @param string $sessionId
|
||||
* @param string $sessionId
|
||||
*/
|
||||
public function setSessionId($sessionId)
|
||||
{
|
||||
|
@ -184,7 +158,7 @@ class Form extends Zend_Form
|
|||
/**
|
||||
* Return the HTML element name of the CSRF token field
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getTokenElementName()
|
||||
{
|
||||
|
@ -194,7 +168,7 @@ class Form extends Zend_Form
|
|||
/**
|
||||
* Render the form to HTML
|
||||
*
|
||||
* @param Zend_View_Interface $view
|
||||
* @param Zend_View_Interface $view
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
@ -210,6 +184,7 @@ class Form extends Zend_Form
|
|||
*/
|
||||
protected function create()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -217,12 +192,13 @@ class Form extends Zend_Form
|
|||
*/
|
||||
protected function preValidation(array $data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the request
|
||||
*
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
* @param Zend_Controller_Request_Abstract $request
|
||||
*/
|
||||
public function setRequest(Zend_Controller_Request_Abstract $request)
|
||||
{
|
||||
|
@ -232,7 +208,7 @@ class Form extends Zend_Form
|
|||
/**
|
||||
* Getter for the request
|
||||
*
|
||||
* @return Zend_Controller_Request_Abstract
|
||||
* @return Zend_Controller_Request_Abstract
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
|
@ -242,7 +218,7 @@ class Form extends Zend_Form
|
|||
/**
|
||||
* Set the configuration to be used for this form when no preferences are set yet
|
||||
*
|
||||
* @param IcingaConfig $cfg
|
||||
* @param IcingaConfig $cfg
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
|
@ -257,20 +233,21 @@ class Form extends Zend_Form
|
|||
*
|
||||
* Returns the set configuration or an empty default one.
|
||||
*
|
||||
* @return Zend_Config
|
||||
* @return Zend_Config
|
||||
*/
|
||||
public function getConfiguration()
|
||||
{
|
||||
if ($this->config === null) {
|
||||
$this->config = new Zend_Config(array(), true);
|
||||
}
|
||||
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set preferences to be used instead of the one from the user object (used for testing)
|
||||
*
|
||||
* @param Zend_Config $prefs
|
||||
* @param Zend_Config $prefs
|
||||
*/
|
||||
public function setUserPreferences($prefs)
|
||||
{
|
||||
|
@ -280,13 +257,14 @@ class Form extends Zend_Form
|
|||
/**
|
||||
* Return the preferences of the user or the overwritten ones
|
||||
*
|
||||
* @return Zend_Config
|
||||
* @return Zend_Config
|
||||
*/
|
||||
public function getUserPreferences()
|
||||
{
|
||||
if ($this->preferences) {
|
||||
return $this->preferences;
|
||||
}
|
||||
|
||||
return $this->getRequest()->getUser()->getPreferences();
|
||||
}
|
||||
|
||||
|
@ -297,7 +275,6 @@ class Form extends Zend_Form
|
|||
*/
|
||||
public function buildForm()
|
||||
{
|
||||
|
||||
if ($this->created === false) {
|
||||
$this->initCsrfToken();
|
||||
$this->create();
|
||||
|
@ -314,18 +291,15 @@ class Form extends Zend_Form
|
|||
if (!$this->getAction() && $this->getRequest()) {
|
||||
$this->setAction($this->getRequest()->getRequestUri());
|
||||
}
|
||||
$this->addElementDecorators();
|
||||
|
||||
$this->created = true;
|
||||
if (!$this->ignoreChangeDiscarding) {
|
||||
//$this->setAttrib('data-icinga-component', 'app/form');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the cancel label
|
||||
*
|
||||
* @param string $cancelLabel
|
||||
* @param string $cancelLabel
|
||||
*/
|
||||
public function setCancelLabel($cancelLabel)
|
||||
{
|
||||
|
@ -335,22 +309,23 @@ class Form extends Zend_Form
|
|||
/**
|
||||
* Add cancel button to form
|
||||
*/
|
||||
private function addCancelButton()
|
||||
protected function addCancelButton()
|
||||
{
|
||||
$cancelLabel = new Zend_Form_Element_Reset(
|
||||
array(
|
||||
'name' => 'btn_reset',
|
||||
'label' => $this->cancelLabel,
|
||||
'class' => 'btn pull-right'
|
||||
$this->addElement(
|
||||
new Zend_Form_Element_Reset(
|
||||
array(
|
||||
'name' => 'btn_reset',
|
||||
'label' => $this->cancelLabel,
|
||||
'class' => 'btn pull-right'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->addElement($cancelLabel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the submit label
|
||||
*
|
||||
* @param string $submitLabel
|
||||
* @param string $submitLabel
|
||||
*/
|
||||
public function setSubmitLabel($submitLabel)
|
||||
{
|
||||
|
@ -360,22 +335,23 @@ class Form extends Zend_Form
|
|||
/**
|
||||
* Add submit button to form
|
||||
*/
|
||||
private function addSubmitButton()
|
||||
protected function addSubmitButton()
|
||||
{
|
||||
$submitButton = new Zend_Form_Element_Submit(
|
||||
array(
|
||||
'name' => 'btn_submit',
|
||||
'label' => $this->submitLabel,
|
||||
$this->addElement(
|
||||
new Zend_Form_Element_Submit(
|
||||
array(
|
||||
'name' => 'btn_submit',
|
||||
'label' => $this->submitLabel
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->addElement($submitButton);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add message to form
|
||||
*
|
||||
* @param string $message The message to be displayed
|
||||
* @param int $headingType Whether it should be displayed as heading (1-6) or not (null)
|
||||
* @param string $message The message to be displayed
|
||||
* @param int $headingType Whether it should be displayed as heading (1-6) or not (null)
|
||||
*/
|
||||
public function addNote($message, $headingType = null)
|
||||
{
|
||||
|
@ -399,17 +375,16 @@ class Form extends Zend_Form
|
|||
*
|
||||
* Enables automatic submission of this form once the user edits specific elements
|
||||
*
|
||||
* @param array $triggerElements The element names which should auto-submit the form
|
||||
* @param array $triggerElements The element names which should auto-submit the form
|
||||
*
|
||||
* @throws ProgrammingError When an element is found which does not yet exist
|
||||
* @throws ProgrammingError When an element is found which does not yet exist
|
||||
*/
|
||||
final public function enableAutoSubmit($triggerElements)
|
||||
public function enableAutoSubmit($triggerElements)
|
||||
{
|
||||
foreach ($triggerElements as $elementName) {
|
||||
$element = $this->getElement($elementName);
|
||||
if ($element !== null) {
|
||||
$element->setAttrib('onchange', '$(this.form).submit();');
|
||||
$element->setAttrib('data-icinga-form-autosubmit', true);
|
||||
} else {
|
||||
throw new ProgrammingError(
|
||||
'You need to add the element "' . $elementName . '" to' .
|
||||
|
@ -425,9 +400,7 @@ class Form extends Zend_Form
|
|||
* Ensures that the current request method is POST, that the form was manually submitted and that the data provided
|
||||
* in the request is valid and gets repopulated in case its invalid.
|
||||
*
|
||||
* @return bool True when the form is submitted and valid, otherwise false
|
||||
* @see Form::isValid()
|
||||
* @see Form::isSubmitted()
|
||||
* @return bool True when the form is submitted and valid, otherwise false
|
||||
*/
|
||||
public function isSubmittedAndValid()
|
||||
{
|
||||
|
@ -457,7 +430,7 @@ class Form extends Zend_Form
|
|||
* Per default, this checks whether the button set with the 'setSubmitLabel' method
|
||||
* is being submitted. For custom submission logic, this method must be overwritten
|
||||
*
|
||||
* @return bool True when the form is marked as submitted, otherwise false
|
||||
* @return bool True when the form is marked as submitted, otherwise false
|
||||
*/
|
||||
public function isSubmitted()
|
||||
{
|
||||
|
@ -466,6 +439,7 @@ class Form extends Zend_Form
|
|||
$checkData = $this->getRequest()->getParams();
|
||||
$submitted = isset($checkData['btn_submit']);
|
||||
}
|
||||
|
||||
return $submitted;
|
||||
}
|
||||
|
||||
|
@ -474,13 +448,13 @@ class Form extends Zend_Form
|
|||
*
|
||||
* This method should be used for testing purposes only
|
||||
*
|
||||
* @param bool $disabled Set true in order to disable CSRF tokens in this form (default: true), otherwise false
|
||||
*
|
||||
* @see tokenDisabled
|
||||
* @param bool $disabled Set true in order to disable CSRF tokens in
|
||||
* this form (default: true), otherwise false
|
||||
*/
|
||||
final public function setTokenDisabled($disabled = true)
|
||||
public function setTokenDisabled($disabled = true)
|
||||
{
|
||||
$this->tokenDisabled = (boolean) $disabled;
|
||||
|
||||
if ($disabled === true) {
|
||||
$this->removeElement($this->tokenElementName);
|
||||
}
|
||||
|
@ -489,54 +463,47 @@ class Form extends Zend_Form
|
|||
/**
|
||||
* Add CSRF counter measure field to form
|
||||
*/
|
||||
final public function initCsrfToken()
|
||||
public function initCsrfToken()
|
||||
{
|
||||
if ($this->tokenDisabled || $this->getElement($this->tokenElementName)) {
|
||||
return;
|
||||
if (!$this->tokenDisabled && $this->getElement($this->tokenElementName) === null) {
|
||||
$this->addElement(
|
||||
'hidden',
|
||||
$this->tokenElementName,
|
||||
array(
|
||||
'value' => $this->generateCsrfTokenAsString()
|
||||
)
|
||||
);
|
||||
}
|
||||
$this->addElement(
|
||||
'hidden',
|
||||
$this->tokenElementName,
|
||||
array(
|
||||
'value' => $this->generateCsrfTokenAsString(),
|
||||
'decorators' => array('ViewHelper')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the submitted data for a correct CSRF token
|
||||
*
|
||||
* @param array $checkData The POST data send by the user
|
||||
* @param array $checkData The POST data send by the user
|
||||
*
|
||||
* @throws InvalidCSRFTokenException When CSRF Validation fails
|
||||
*/
|
||||
final public function assertValidCsrfToken(array $checkData)
|
||||
public function assertValidCsrfToken(array $checkData)
|
||||
{
|
||||
if ($this->tokenDisabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($checkData[$this->tokenElementName])
|
||||
|| !$this->hasValidCsrfToken($checkData[$this->tokenElementName])
|
||||
) {
|
||||
throw new InvalidCSRFTokenException();
|
||||
if (!$this->tokenDisabled) {
|
||||
if (!isset($checkData[$this->tokenElementName])
|
||||
|| !$this->hasValidCsrfToken($checkData[$this->tokenElementName])
|
||||
) {
|
||||
throw new InvalidCSRFTokenException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the form's CSRF token-field has a valid value
|
||||
*
|
||||
* @param string $elementValue Value from the form element
|
||||
* @param string $elementValue Value from the form element
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasValidCsrfToken($elementValue)
|
||||
protected function hasValidCsrfToken($elementValue)
|
||||
{
|
||||
if ($this->getElement($this->tokenElementName) === null) {
|
||||
return false;
|
||||
}
|
||||
if (strpos($elementValue, '|') === false) {
|
||||
if ($this->getElement($this->tokenElementName) === null || strpos($elementValue, '|') === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -549,26 +516,12 @@ class Form extends Zend_Form
|
|||
return $token === hash('sha256', $this->getSessionId() . $seed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add element decorators which apply to all elements
|
||||
*
|
||||
* Adds `HelpText` decorator
|
||||
*
|
||||
* @see HelpText
|
||||
*/
|
||||
private function addElementDecorators()
|
||||
{
|
||||
foreach ($this->getElements() as $element) {
|
||||
$element->addDecorator(new HelpText());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a new (seed, token) pair
|
||||
*
|
||||
* @return array
|
||||
* @return array
|
||||
*/
|
||||
final public function generateCsrfToken()
|
||||
public function generateCsrfToken()
|
||||
{
|
||||
$seed = mt_rand();
|
||||
$hash = hash('sha256', $this->getSessionId() . $seed);
|
||||
|
@ -579,9 +532,9 @@ class Form extends Zend_Form
|
|||
/**
|
||||
* Return the string representation of the CSRF seed/token pair
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
final public function generateCsrfTokenAsString()
|
||||
public function generateCsrfTokenAsString()
|
||||
{
|
||||
list ($seed, $token) = $this->generateCsrfToken($this->getSessionId());
|
||||
return sprintf('%s|%s', $seed, $token);
|
||||
|
@ -593,31 +546,29 @@ class Form extends Zend_Form
|
|||
* Additionally, all DtDd tags will be removed and the Bootstrap compatible
|
||||
* BootstrapForm decorator will be added to the elements
|
||||
*
|
||||
*
|
||||
* @param string|Zend_Form_Element $element String element type, or an object of type Zend_Form_Element
|
||||
* @param string $name The name of the element to add if $element is a string
|
||||
* @param array $options The settings for the element if $element is a string
|
||||
*
|
||||
* @return Form
|
||||
* @return self
|
||||
* @see Zend_Form::addElement()
|
||||
*/
|
||||
public function addElement($element, $name = null, $options = null)
|
||||
{
|
||||
parent::addElement($element, $name, $options);
|
||||
$el = $name ? $this->getElement($name) : $element;
|
||||
|
||||
// Do not add structural elements to invisible elements
|
||||
// which produces ugly views
|
||||
if (strpos(strtolower(get_class($el)), 'hidden') !== false) {
|
||||
$el->setDecorators(array('ViewHelper'));
|
||||
return $this;
|
||||
}
|
||||
$el = $name !== null ? $this->getElement($name) : $element;
|
||||
|
||||
if ($el) {
|
||||
$el->removeDecorator('HtmlTag');
|
||||
$el->removeDecorator('Label');
|
||||
$el->removeDecorator('DtDdWrapper');
|
||||
$el->addDecorator(new BootstrapForm());
|
||||
if (strpos(strtolower(get_class($el)), 'hidden') !== false) {
|
||||
// Do not add structural elements to invisible elements which produces ugly views
|
||||
$el->setDecorators(array('ViewHelper'));
|
||||
} else {
|
||||
$el->removeDecorator('HtmlTag');
|
||||
$el->removeDecorator('Label');
|
||||
$el->removeDecorator('DtDdWrapper');
|
||||
$el->addDecorator(new BootstrapForm());
|
||||
$el->addDecorator(new HelpText());
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
@ -626,7 +577,9 @@ class Form extends Zend_Form
|
|||
/**
|
||||
* Load the default decorators
|
||||
*
|
||||
* @return Zend_Form
|
||||
* Overwrites Zend_Form::loadDefaultDecorators to avoid having the HtmlTag-Decorator added
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function loadDefaultDecorators()
|
||||
{
|
||||
|
@ -637,8 +590,10 @@ class Form extends Zend_Form
|
|||
$decorators = $this->getDecorators();
|
||||
if (empty($decorators)) {
|
||||
$this->addDecorator('FormElements')
|
||||
->addDecorator('Form');
|
||||
//->addDecorator('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form'))
|
||||
->addDecorator('Form');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -103,3 +104,4 @@ class BootstrapForm extends Zend_Form_Decorator_Abstract
|
|||
. '</div>';
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -59,3 +60,4 @@ class ConditionalHidden extends Zend_Form_Decorator_Abstract
|
|||
return $content;
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -29,7 +30,7 @@
|
|||
|
||||
namespace Icinga\Web\Form\Decorator;
|
||||
|
||||
use \Zend_Form_Decorator_Abstract;
|
||||
use Zend_Form_Decorator_Abstract;
|
||||
|
||||
/**
|
||||
* Decorator that automatically adds a helptext to an input element
|
||||
|
@ -60,3 +61,4 @@ class HelpText extends Zend_Form_Decorator_Abstract
|
|||
return $content;
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -29,16 +29,38 @@
|
|||
|
||||
namespace Icinga\Web\Form\Element;
|
||||
|
||||
use Zend_Form_Element_Xhtml;
|
||||
|
||||
/**
|
||||
* Number form element
|
||||
*
|
||||
* @TODO: The given label for this element is not displayed. (Reason unknown)
|
||||
*/
|
||||
class Number extends \Zend_Form_Element_Xhtml
|
||||
class Number extends Zend_Form_Element_Xhtml
|
||||
{
|
||||
/**
|
||||
* Default form view helper to use for rendering
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $helper = "formNumber";
|
||||
|
||||
/**
|
||||
* Check whether $value is of type integer
|
||||
*
|
||||
* @param string $value The value to check
|
||||
* @param mixed $context Context to use
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid($value, $context = null)
|
||||
{
|
||||
if (parent::isValid($value, $context)) {
|
||||
if (is_numeric($value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->addError(t('Please enter a number.'));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,9 +29,9 @@
|
|||
|
||||
namespace Icinga\Web;
|
||||
|
||||
use Exception;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Icinga Web Hook registry
|
||||
|
@ -79,9 +79,9 @@ class Hook
|
|||
/**
|
||||
* Whether someone registered itself for the given hook name
|
||||
*
|
||||
* @param string $name One of the predefined hook names
|
||||
* @param string $name One of the predefined hook names
|
||||
*
|
||||
* @return bool
|
||||
* @return bool
|
||||
*/
|
||||
public static function has($name)
|
||||
{
|
||||
|
@ -89,72 +89,29 @@ class Hook
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the first registered instance for the given hook name
|
||||
* Create or return an instance of a given hook
|
||||
*
|
||||
* TODO: Multiple instances are not handled yet
|
||||
* TODO: Should return some kind of a hook interface
|
||||
*
|
||||
* @param string $name One of the predefined hook names
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ProgrammingError
|
||||
*/
|
||||
public static function get($name)
|
||||
{
|
||||
if (! self::has($name)) {
|
||||
return null;
|
||||
}
|
||||
if (! array_key_exists($name, self::$instances)) {
|
||||
$class = self::$hooks[$name];
|
||||
try {
|
||||
$obj = new $class();
|
||||
} catch (\Exception $e) {
|
||||
// TODO: Persist unloading for "some time" or "current session"
|
||||
Logger::debug(
|
||||
'Hook "%s" (%s) failed, will be unloaded: %s',
|
||||
$name,
|
||||
$class,
|
||||
$e->getMessage()
|
||||
);
|
||||
unset(self::$hooks[$name]);
|
||||
return null;
|
||||
}
|
||||
$base_class = 'Icinga\\Web\\Hook\\' . ucfirst($name);
|
||||
if (! $obj instanceof $base_class) {
|
||||
throw new ProgrammingError(
|
||||
sprintf(
|
||||
'%s is not an instance of %s',
|
||||
get_class($obj),
|
||||
$base_class
|
||||
)
|
||||
);
|
||||
}
|
||||
self::$instances[$name] = $obj;
|
||||
|
||||
}
|
||||
return self::$instances[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or return an instance of the hook
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $key
|
||||
* @return stdClass
|
||||
* @param string $name One of the predefined hook names
|
||||
* @param string $key The identifier of a specific subtype
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function createInstance($name, $key)
|
||||
{
|
||||
if (!self::has($name, $key)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset(self::$instances[$name][$key])) {
|
||||
return self::$instances[$name][$key];
|
||||
}
|
||||
|
||||
$class = self::$hooks[$name][$key];
|
||||
try {
|
||||
$instance = new $class();
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
Logger::debug(
|
||||
'Hook "%s" (%s) (%s) failed, will be unloaded: %s',
|
||||
$name,
|
||||
|
@ -162,9 +119,11 @@ class Hook
|
|||
$class,
|
||||
$e->getMessage()
|
||||
);
|
||||
// TODO: Persist unloading for "some time" or "current session"
|
||||
unset(self::$hooks[$name][$key]);
|
||||
return null;
|
||||
}
|
||||
|
||||
self::assertValidHook($instance, $name);
|
||||
self::$instances[$name][$key] = $instance;
|
||||
return $instance;
|
||||
|
@ -173,11 +132,12 @@ class Hook
|
|||
/**
|
||||
* Test for a valid class name
|
||||
*
|
||||
* @param stdClass $instance
|
||||
* @param string $name
|
||||
* @throws ProgrammingError
|
||||
* @param mixed $instance
|
||||
* @param string $name
|
||||
*
|
||||
* @throws ProgrammingError
|
||||
*/
|
||||
private static function assertValidHook(&$instance, $name)
|
||||
private static function assertValidHook($instance, $name)
|
||||
{
|
||||
$base_class = self::$BASE_NS . ucfirst($name);
|
||||
if (!$instance instanceof $base_class) {
|
||||
|
@ -194,43 +154,45 @@ class Hook
|
|||
/**
|
||||
* Return all instances of a specific name
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name One of the predefined hook names
|
||||
*
|
||||
* @return array
|
||||
* @return array
|
||||
*/
|
||||
public static function all($name)
|
||||
{
|
||||
if (!self::has($name)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
foreach (self::$hooks[$name] as $key => $hook) {
|
||||
if (self::createInstance($name, $key) === null) {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
return self::$instances[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first hook
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name One of the predefined hook names
|
||||
*
|
||||
* @return stdClass
|
||||
* @return null|mixed
|
||||
*/
|
||||
public static function first($name)
|
||||
{
|
||||
return self::createInstance($name, key(self::$hooks[$name]));
|
||||
if (self::has($name)) {
|
||||
return self::createInstance($name, key(self::$hooks[$name]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register your hook
|
||||
*
|
||||
* @param string $name One of the predefined hook names
|
||||
* @param string $key
|
||||
* @param string $class Your class name, must inherit one of the classes
|
||||
* in the Icinga/Web/Hook folder
|
||||
* Alias for Hook::registerClass()
|
||||
*
|
||||
* @see Hook::registerClass()
|
||||
*/
|
||||
public static function register($name, $key, $class)
|
||||
{
|
||||
|
@ -240,12 +202,17 @@ class Hook
|
|||
/**
|
||||
* Register a class
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $key
|
||||
* @param string $class
|
||||
* @param string $name One of the predefined hook names
|
||||
* @param string $key The identifier of a specific subtype
|
||||
* @param string $class Your class name, must inherit one of the
|
||||
* classes in the Icinga/Web/Hook folder
|
||||
*/
|
||||
public static function registerClass($name, $key, $class)
|
||||
{
|
||||
if (!class_exists($class)) {
|
||||
throw new ProgrammingError('"' . $class . '" is not an existing class');
|
||||
}
|
||||
|
||||
if (!isset(self::$hooks[$name])) {
|
||||
self::$hooks[$name] = array();
|
||||
}
|
||||
|
@ -256,23 +223,23 @@ class Hook
|
|||
/**
|
||||
* Register an object
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $key
|
||||
* @param object $object
|
||||
* @param string $name One of the predefined hook names
|
||||
* @param string $key The identifier of a specific subtype
|
||||
* @param object $object The instantiated hook to register
|
||||
*
|
||||
* @throws ProgrammingError
|
||||
* @throws ProgrammingError
|
||||
*/
|
||||
public static function registerObject($name, $key, $object)
|
||||
{
|
||||
if (!is_object($object)) {
|
||||
throw new ProgrammingError('object is not an instantiated class');
|
||||
throw new ProgrammingError('"' . $object . '" is not an instantiated class');
|
||||
}
|
||||
|
||||
if (!isset(self::$instances[$name])) {
|
||||
self::$instances[$name] = array();
|
||||
}
|
||||
|
||||
self::$instances[$name][$key] =& $object;
|
||||
self::$instances[$name][$key] = $object;
|
||||
self::registerClass($name, $key, get_class($object));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ class ConfigurationTabBuilder
|
|||
{
|
||||
/** @var ConfigurationTab $configTab */
|
||||
$configTab = null;
|
||||
foreach (Hook::get(self::HOOK_NAMESPACE) as $configTab) {
|
||||
foreach (Hook::all(self::HOOK_NAMESPACE) as $configTab) {
|
||||
if (!$configTab instanceof ConfigurationTabInterface) {
|
||||
throw new ProgrammingError('tab not instance of ConfigTabInterface');
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -112,3 +113,4 @@ class Grapher
|
|||
throw new Exception('This backend has no images');
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
/**
|
||||
* Icinga Web Ticket Hook
|
||||
|
@ -42,3 +43,4 @@ abstract class Ticket
|
|||
abstract public function createLink($match);
|
||||
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
namespace Icinga\Web;
|
||||
|
||||
|
@ -83,3 +84,4 @@ class JavaScript
|
|||
echo $out;
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -194,3 +195,4 @@ class LessCompiler
|
|||
}
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -29,9 +29,9 @@
|
|||
|
||||
namespace Icinga\Web;
|
||||
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Exception\NotReadableError;
|
||||
|
||||
class Menu extends MenuItem
|
||||
|
@ -39,34 +39,49 @@ class Menu extends MenuItem
|
|||
/**
|
||||
* Create menu from the application's menu config file plus the config files from all enabled modules
|
||||
*
|
||||
* @return Menu
|
||||
* @return self
|
||||
*/
|
||||
public static function fromConfig()
|
||||
{
|
||||
$menu = new static('menu');
|
||||
$manager = Icinga::app()->getModuleManager();
|
||||
$manager = Icinga::app()->getModuleManager();
|
||||
|
||||
try {
|
||||
$menuConfigs = array(Config::app('menu'));
|
||||
} catch (NotReadableError $e) {
|
||||
Logger::error($e);
|
||||
$menuConfigs = array();
|
||||
}
|
||||
try {
|
||||
|
||||
foreach ($manager->listEnabledModules() as $moduleName) {
|
||||
$moduleMenuConfig = Config::module($moduleName, 'menu');
|
||||
if ($moduleMenuConfig) {
|
||||
$menuConfigs[] = $moduleMenuConfig;
|
||||
}
|
||||
}
|
||||
try {
|
||||
$modules = $manager->listEnabledModules();
|
||||
} catch (NotReadableError $e) {
|
||||
Logger::error($e);
|
||||
$modules = array();
|
||||
}
|
||||
|
||||
foreach ($modules as $moduleName) {
|
||||
try {
|
||||
$moduleMenuConfig = Config::module($moduleName, 'menu');
|
||||
} catch (NotReadableError $e) {
|
||||
Logger::error($e);
|
||||
$moduleMenuConfig = array();
|
||||
}
|
||||
|
||||
if (!empty($moduleMenuConfig)) {
|
||||
$menuConfigs[] = $moduleMenuConfig;
|
||||
}
|
||||
}
|
||||
|
||||
return $menu->loadMenuItems($menu->flattenConfigs($menuConfigs));
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten configs into a key-value array
|
||||
* Flatten configs
|
||||
*
|
||||
* @param array $configs An two dimensional array of menu configurations
|
||||
*
|
||||
* @return array The flattened config, as key-value array
|
||||
*/
|
||||
public function flattenConfigs(array $configs)
|
||||
{
|
||||
|
@ -79,18 +94,23 @@ class Menu extends MenuItem
|
|||
$flattened[$section] = $itemConfig;
|
||||
}
|
||||
}
|
||||
ksort($flattened);
|
||||
|
||||
return $flattened;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load menu items from a key-value array
|
||||
* Load menu items
|
||||
*
|
||||
* @param array $items The items to load, as key-value array
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function loadMenuItems(array $flattened)
|
||||
public function loadMenuItems(array $items)
|
||||
{
|
||||
foreach ($flattened as $id => $itemConfig) {
|
||||
foreach ($items as $id => $itemConfig) {
|
||||
$this->addChild($id, $itemConfig);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ class MenuItem
|
|||
*
|
||||
* @type string
|
||||
*/
|
||||
private $id;
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* Item title
|
||||
|
@ -22,7 +22,7 @@ class MenuItem
|
|||
*
|
||||
* @type string
|
||||
*/
|
||||
private $title;
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
* Item priority
|
||||
|
@ -31,44 +31,48 @@ class MenuItem
|
|||
*
|
||||
* @type int
|
||||
*/
|
||||
private $priority = 100;
|
||||
protected $priority = 100;
|
||||
|
||||
/**
|
||||
* Item url
|
||||
*
|
||||
* @type string
|
||||
*/
|
||||
private $url;
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* Item icon path
|
||||
*
|
||||
* @type string
|
||||
*/
|
||||
private $icon;
|
||||
protected $icon;
|
||||
|
||||
/**
|
||||
* Item icon class
|
||||
*
|
||||
* @type string
|
||||
*/
|
||||
private $iconClass;
|
||||
protected $iconClass;
|
||||
|
||||
/**
|
||||
* Item's children
|
||||
*
|
||||
* @type array
|
||||
*/
|
||||
private $children = array();
|
||||
|
||||
private $attribs = array();
|
||||
protected $children = array();
|
||||
|
||||
/**
|
||||
* HTML anchor tag attributes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attribs = array();
|
||||
|
||||
/**
|
||||
* Create a new MenuItem
|
||||
*
|
||||
* @param int $id
|
||||
* @param object $config
|
||||
* @param int $id
|
||||
* @param object $config
|
||||
*/
|
||||
public function __construct($id, $config = null)
|
||||
{
|
||||
|
@ -81,7 +85,7 @@ class MenuItem
|
|||
/**
|
||||
* Setter for id
|
||||
*
|
||||
* @param string $id
|
||||
* @param string $id
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
|
@ -104,7 +108,7 @@ class MenuItem
|
|||
/**
|
||||
* Setter for title
|
||||
*
|
||||
* @param string $title
|
||||
* @param string $title
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
|
@ -114,11 +118,10 @@ class MenuItem
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Getter for title
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
|
@ -128,7 +131,7 @@ class MenuItem
|
|||
/**
|
||||
* Setter for priority
|
||||
*
|
||||
* @param int $priority
|
||||
* @param int $priority
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
|
@ -141,7 +144,7 @@ class MenuItem
|
|||
/**
|
||||
* Getter for priority
|
||||
*
|
||||
* @return int
|
||||
* @return int
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
|
@ -151,7 +154,7 @@ class MenuItem
|
|||
/**
|
||||
* Setter for URL
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $url
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
|
@ -164,7 +167,7 @@ class MenuItem
|
|||
/**
|
||||
* Getter for URL
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
|
@ -174,7 +177,7 @@ class MenuItem
|
|||
/**
|
||||
* Setter for icon path
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $path
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
|
@ -187,7 +190,7 @@ class MenuItem
|
|||
/**
|
||||
* Getter for icon path
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getIcon()
|
||||
{
|
||||
|
@ -197,7 +200,7 @@ class MenuItem
|
|||
/**
|
||||
* Setter for icon class
|
||||
*
|
||||
* @param string $iconClass
|
||||
* @param string $iconClass
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
|
@ -210,7 +213,7 @@ class MenuItem
|
|||
/**
|
||||
* Getter for icon class
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getIconClass()
|
||||
{
|
||||
|
@ -220,7 +223,7 @@ class MenuItem
|
|||
/**
|
||||
* Set the configuration for the item
|
||||
*
|
||||
* @param object $config
|
||||
* @param Zend_Config $config
|
||||
*/
|
||||
public function setConfig($config)
|
||||
{
|
||||
|
@ -249,18 +252,21 @@ class MenuItem
|
|||
} else {
|
||||
// Submenu item
|
||||
list($parentId, $id) = explode('.', $id, 2);
|
||||
|
||||
if ($this->hasChild($parentId)) {
|
||||
$parent = $this->getChild($parentId);
|
||||
} else {
|
||||
$parent = $this->addChild($parentId);
|
||||
}
|
||||
|
||||
$menuItem = $parent->addChild($id, $itemConfig);
|
||||
}
|
||||
|
||||
return $menuItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the item has children
|
||||
* Check whether the item has any children
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -270,10 +276,11 @@ class MenuItem
|
|||
}
|
||||
|
||||
/**
|
||||
* Get children sorted
|
||||
* Get sorted children
|
||||
*
|
||||
* @return array
|
||||
* @see cmpChildren()
|
||||
*
|
||||
* @see MenuItem::cmpChildren()
|
||||
*/
|
||||
public function getChildren()
|
||||
{
|
||||
|
@ -282,11 +289,11 @@ class MenuItem
|
|||
}
|
||||
|
||||
/**
|
||||
* Whether a given child id exists
|
||||
* Return whether a given child id exists
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return self|$default
|
||||
* @return bool
|
||||
*/
|
||||
public function hasChild($id)
|
||||
{
|
||||
|
@ -300,20 +307,22 @@ class MenuItem
|
|||
* @param mixed $default
|
||||
*
|
||||
* @return MenuItem
|
||||
*
|
||||
* @throws ProgrammingError
|
||||
*/
|
||||
public function getChild($id)
|
||||
{
|
||||
if ($this->hasChild($id)) {
|
||||
return $this->children[$id];
|
||||
if (!$this->hasChild($id)) {
|
||||
throw new ProgrammingError(sprintf('Trying to get invalid Menu child "%s"', $id));
|
||||
}
|
||||
throw new ProgrammingError(sprintf('Trying to get invalid Menu child "%s"', $id));
|
||||
|
||||
return $this->children[$id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set HTML a tag attributes
|
||||
* Set HTML anchor tag attributes
|
||||
*
|
||||
* @param array $attribs
|
||||
* @param array $attribs
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
|
@ -324,9 +333,9 @@ class MenuItem
|
|||
}
|
||||
|
||||
/**
|
||||
* Get HTML a tag attributes
|
||||
* Get HTML anchor tag attributes
|
||||
*
|
||||
* @return array
|
||||
* @return array
|
||||
*/
|
||||
public function getAttribs()
|
||||
{
|
||||
|
@ -336,8 +345,8 @@ class MenuItem
|
|||
/**
|
||||
* Compare children based on priority and title
|
||||
*
|
||||
* @param MenuItem $a
|
||||
* @param MenuItem $b
|
||||
* @param MenuItem $a
|
||||
* @param MenuItem $b
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
|
@ -346,6 +355,7 @@ class MenuItem
|
|||
if ($a->priority === $b->priority) {
|
||||
return ($a->getTitle() > $b->getTitle()) ? 1 : -1;
|
||||
}
|
||||
|
||||
return ($a->priority > $b->priority) ? 1 : -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -64,3 +65,4 @@ class Request extends Zend_Controller_Request_Http
|
|||
return $this->user;
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -78,3 +79,4 @@ class Session
|
|||
return self::$session;
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
namespace Icinga\Web;
|
||||
|
||||
|
@ -67,3 +68,4 @@ class StyleSheet
|
|||
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -30,16 +30,16 @@
|
|||
namespace Icinga\Web;
|
||||
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
|
||||
/**
|
||||
* Url class that provides convenient access to parameters, allows to modify query parameters and
|
||||
* returns Urls reflecting all changes made to the url and to the parameters.
|
||||
* Url class that provides convenient access to parameters, allows to modify query parameters and
|
||||
* returns Urls reflecting all changes made to the url and to the parameters.
|
||||
*
|
||||
* Direct instantiation is prohibited and should be done either with @see Url::fromRequest() or
|
||||
* @see Url::fromUrlString()
|
||||
*
|
||||
* Currently, protocol, host and port are ignored and will be implemented when required
|
||||
* Direct instantiation is prohibited and should be done either with @see Url::fromRequest() or
|
||||
* @see Url::fromUrlString()
|
||||
*
|
||||
* Currently, protocol, host and port are ignored and will be implemented when required
|
||||
*/
|
||||
class Url
|
||||
{
|
||||
|
@ -48,28 +48,28 @@ class Url
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
private $params = array();
|
||||
protected $params = array();
|
||||
|
||||
/**
|
||||
* An array to map aliases to valid parameters
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $aliases = array();
|
||||
protected $aliases = array();
|
||||
|
||||
/**
|
||||
* The site anchor after the '#'
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $anchor = '';
|
||||
protected $anchor = '';
|
||||
|
||||
/**
|
||||
* The relative path of this Url, without query parameters
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $path = '';
|
||||
protected $path = '';
|
||||
|
||||
/**
|
||||
* The baseUrl that will be appended to @see Url::$path in order to
|
||||
|
@ -77,10 +77,11 @@ class Url
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $baseUrl = '/';
|
||||
protected $baseUrl = '/';
|
||||
|
||||
private function __construct()
|
||||
protected function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,11 +90,10 @@ class Url
|
|||
* If $params are given, those will be added to the request's parameters
|
||||
* and overwrite any existing parameters
|
||||
*
|
||||
* @param string $url The string representation of the Url to parse
|
||||
* @param array $params Parameters that should additionally be considered for the Url
|
||||
* @param Zend_Request $request A request to use instead of the default one
|
||||
* @param array $params Parameters that should additionally be considered for the url
|
||||
* @param Zend_Request $request A request to use instead of the default one
|
||||
*
|
||||
* @return Url
|
||||
* @return Url
|
||||
*/
|
||||
public static function fromRequest(array $params = array(), $request = null)
|
||||
{
|
||||
|
@ -111,9 +111,9 @@ class Url
|
|||
/**
|
||||
* Return a request object that should be used for determining the URL
|
||||
*
|
||||
* @return Zend_Abstract_Request
|
||||
* @return Zend_Abstract_Request
|
||||
*/
|
||||
private static function getRequest()
|
||||
protected static function getRequest()
|
||||
{
|
||||
return Icinga::app()->getFrontController()->getRequest();
|
||||
}
|
||||
|
@ -124,38 +124,45 @@ class Url
|
|||
* If $params are given, those will be added to the urls parameters
|
||||
* and overwrite any existing parameters
|
||||
*
|
||||
* @param string $url The string representation of the Url to parse
|
||||
* @param array $params An array of parameters that should additionally be considered for the Url
|
||||
* @param Zend_Request $request A request to use instead of the default one
|
||||
* @param string $url The string representation of the url to parse
|
||||
* @param array $params An array of parameters that should additionally be considered for the url
|
||||
* @param Zend_Request $request A request to use instead of the default one
|
||||
*
|
||||
* @return Url
|
||||
* @return Url
|
||||
*/
|
||||
public static function fromPath($url, array $params = array(), $request = null)
|
||||
{
|
||||
$urlObject = new Url();
|
||||
if ($request === null) {
|
||||
$request = self::getRequest();
|
||||
}
|
||||
|
||||
if (!is_string($url)) {
|
||||
throw new ProgrammingError(sprintf('url "%s" is not a string', $url));
|
||||
}
|
||||
|
||||
$urlObject = new Url();
|
||||
$urlObject->setBaseUrl($request->getBaseUrl());
|
||||
|
||||
/*
|
||||
* Fetch fragment manually and remove it from the url, to 'help' the parse_url() function
|
||||
* parsing the url properly. Otherwise calling the function with a fragment, but without a
|
||||
* query will cause unpredictable behaviour.
|
||||
*/
|
||||
$fragment = self::getUrlFragment($url);
|
||||
// Fetch fragment manually and remove it from the url, to 'help' the parse_url() function
|
||||
// parsing the url properly. Otherwise calling the function with a fragment, but without a
|
||||
// query will cause unpredictable behaviour.
|
||||
$url = self::stripUrlFragment($url);
|
||||
|
||||
$urlParts = parse_url($url);
|
||||
|
||||
if (isset($urlParts["path"])) {
|
||||
$urlObject->setPath($urlParts["path"]);
|
||||
if (strpos($urlParts["path"], $request->getBaseUrl()) === 0) {
|
||||
$urlObject->setPath(substr($urlParts["path"], strlen($request->getBaseUrl())));
|
||||
} else {
|
||||
$urlObject->setPath($urlParts["path"]);
|
||||
}
|
||||
}
|
||||
if (isset($urlParts["query"])) {
|
||||
$urlParams = array();
|
||||
parse_str($urlParts["query"], $urlParams);
|
||||
$params = array_merge($urlParams, $params);
|
||||
}
|
||||
|
||||
$fragment = self::getUrlFragment($url);
|
||||
if ($fragment !== '') {
|
||||
$urlObject->setAnchor($fragment);
|
||||
}
|
||||
|
@ -167,11 +174,11 @@ class Url
|
|||
/**
|
||||
* Get the fragment of a given url
|
||||
*
|
||||
* @param $url The url containing the fragment.
|
||||
* @param string $url The url containing the fragment.
|
||||
*
|
||||
* @return string The fragment without the '#'
|
||||
* @return string The fragment without the '#'
|
||||
*/
|
||||
private static function getUrlFragment($url)
|
||||
protected static function getUrlFragment($url)
|
||||
{
|
||||
$url = parse_url($url);
|
||||
if (isset($url['fragment'])) {
|
||||
|
@ -184,11 +191,11 @@ class Url
|
|||
/**
|
||||
* Remove the fragment-part of a given url
|
||||
*
|
||||
* @param $url string The url to strip from its fragment
|
||||
* @param string $url The url to strip from its fragment
|
||||
*
|
||||
* @return string The url without the fragment.
|
||||
* @return string The url without the fragment
|
||||
*/
|
||||
private static function stripUrlFragment($url)
|
||||
protected static function stripUrlFragment($url)
|
||||
{
|
||||
return preg_replace('/#.*$/', '', $url);
|
||||
}
|
||||
|
@ -209,9 +216,9 @@ class Url
|
|||
/**
|
||||
* Return the parameter for the given alias
|
||||
*
|
||||
* @param string $alias The alias to translate
|
||||
* @param string $alias The alias to translate
|
||||
*
|
||||
* @return string The parameter name
|
||||
* @return string The parameter name
|
||||
*/
|
||||
public function translateAlias($alias)
|
||||
{
|
||||
|
@ -219,26 +226,28 @@ class Url
|
|||
}
|
||||
|
||||
/**
|
||||
* Overwrite the baseUrl.
|
||||
* Overwrite the baseUrl
|
||||
*
|
||||
* If an empty Url is given '/' is used as the base
|
||||
*
|
||||
* @param string $baseUrl The url path to use as the Url Base
|
||||
* @return $this
|
||||
* @param string $baseUrl The url path to use as the Url Base
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setBaseUrl($baseUrl)
|
||||
{
|
||||
if (trim($baseUrl) == '') {
|
||||
if (($baseUrl = rtrim($baseUrl, '/ ')) === '') {
|
||||
$baseUrl = '/';
|
||||
}
|
||||
|
||||
$this->baseUrl = $baseUrl;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the baseUrl set for this Url
|
||||
* Return the baseUrl set for this url
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getBaseUrl()
|
||||
{
|
||||
|
@ -248,19 +257,22 @@ class Url
|
|||
/**
|
||||
* Set the relative path of this url, without query parameters
|
||||
*
|
||||
* @param string $path The path to set
|
||||
* @param string $path The path to set
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setPath($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
$this->path = ltrim($path, '/');
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the relative path of this Url, without query parameters
|
||||
* Return the relative path of this url, without query parameters
|
||||
*
|
||||
* If you want the relative path with query parameters use getRelativeUrl
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
|
@ -270,36 +282,38 @@ class Url
|
|||
/**
|
||||
* Return the relative url with query parameters as a string
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getRelativeUrl()
|
||||
{
|
||||
if (empty($this->params)) {
|
||||
return ltrim($this->path, '/') . $this->anchor;
|
||||
return $this->path . $this->anchor;
|
||||
}
|
||||
|
||||
$params = array();
|
||||
foreach ($this->params as $param => $value) {
|
||||
$params[$this->translateAlias($param)] = $value;
|
||||
}
|
||||
return ltrim($this->path, '/') . '?' . http_build_query($params, '', '&') . $this->anchor;
|
||||
|
||||
return $this->path . '?' . http_build_query($params, '', '&') . $this->anchor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the absolute url with query parameters as a string
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getAbsoluteUrl()
|
||||
{
|
||||
$url = $this->getRelativeUrl();
|
||||
return preg_replace('/\/{2,}/', '/', '/'.$this->baseUrl.'/'.$url);
|
||||
return $this->baseUrl . ($this->baseUrl !== '/' ? '/' : '') . $this->getRelativeUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a set of parameters to the query part if the keys don't exist yet
|
||||
*
|
||||
* @param array $params The parameters to add
|
||||
* @return self
|
||||
* @param array $params The parameters to add
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function addParams(array $params)
|
||||
{
|
||||
|
@ -310,8 +324,9 @@ class Url
|
|||
/**
|
||||
* Set and overwrite the given params if one if the same key already exists
|
||||
*
|
||||
* @param array $params The parameters to set
|
||||
* @return self
|
||||
* @param array $params The parameters to set
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function overwriteParams(array $params)
|
||||
{
|
||||
|
@ -322,8 +337,9 @@ class Url
|
|||
/**
|
||||
* Overwrite the parameters used in the query part
|
||||
*
|
||||
* @param array $params The new parameters to use for the query part
|
||||
* @return $this
|
||||
* @param array $params The new parameters to use for the query part
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setParams(array $params)
|
||||
{
|
||||
|
@ -334,7 +350,7 @@ class Url
|
|||
/**
|
||||
* Return all parameters that will be used in the query part
|
||||
*
|
||||
* @return array An associative key => value array containing all parameters
|
||||
* @return array An associative key => value array containing all parameters
|
||||
*/
|
||||
public function getParams()
|
||||
{
|
||||
|
@ -342,48 +358,52 @@ class Url
|
|||
}
|
||||
|
||||
/**
|
||||
* Return true if the Urls' query parameter with $key exists, otherwise false
|
||||
* Return true if a urls' query parameter exists, otherwise false
|
||||
*
|
||||
* @param $key A key to check for existing
|
||||
* @return bool
|
||||
* @param string $param The url parameter name to check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasParam($key)
|
||||
public function hasParam($param)
|
||||
{
|
||||
return array_key_exists($key, $this->params);
|
||||
return array_key_exists($param, $this->params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Url's query parameter with the name $key if exists, otherwise $default
|
||||
* Return a url's query parameter if it exists, otherwise $default
|
||||
*
|
||||
* @param $key A query parameter name to return if existing
|
||||
* @param mixed $default A value to return when the parameter doesn't exist
|
||||
* @return mixed
|
||||
* @param string $param A query parameter name to return if existing
|
||||
* @param mixed $default A value to return when the parameter doesn't exist
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParam($key, $default = null)
|
||||
public function getParam($param, $default = null)
|
||||
{
|
||||
if ($this->hasParam($key)) {
|
||||
return $this->params[$key];
|
||||
if ($this->hasParam($param)) {
|
||||
return $this->params[$param];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single parameter $key, overwriting existing ones with the same key
|
||||
* Set a single parameter, overwriting any existing one with the same name
|
||||
*
|
||||
* @param string $key A string representing the key of the parameter
|
||||
* @param array|string $value An array or string to set as the parameter value
|
||||
* @return $this
|
||||
* @param string $param The query parameter name
|
||||
* @param array|string $value An array or string to set as the parameter value
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setParam($key, $value)
|
||||
public function setParam($param, $value)
|
||||
{
|
||||
$this->params[$key] = $value;
|
||||
$this->params[$param] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the url anchor-part
|
||||
*
|
||||
* @param $anchor The site's anchor string without the '#'
|
||||
* @param string $anchor The site's anchor string without the '#'
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
|
@ -396,9 +416,9 @@ class Url
|
|||
/**
|
||||
* Remove provided key (if string) or keys (if array of string) from the query parameter array
|
||||
*
|
||||
* @param string|array $keyOrArrayOfKeys An array of strings or a string representing the key(s)
|
||||
* @param string|array $keyOrArrayOfKeys An array of strings or a string representing the key(s)
|
||||
* of the parameters to be removed
|
||||
* @return $this
|
||||
* @return self
|
||||
*/
|
||||
public function remove($keyOrArrayOfKeys)
|
||||
{
|
||||
|
@ -407,45 +427,51 @@ class Url
|
|||
} else {
|
||||
$this->removeKey($keyOrArrayOfKeys);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all parameters with the parameter names in the $keys array
|
||||
*
|
||||
* @param array $keys An array of strings containing parameter names to remove
|
||||
* @return $this
|
||||
* @param array $keys An array of strings containing parameter names to remove
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function removeKeys(array $keys)
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
$this->removeKey($key);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a single parameter with the provided parameter name $key
|
||||
*
|
||||
* @param string $key The key to remove from the Url
|
||||
* @return $this
|
||||
* @param string $key The key to remove from the url
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function removeKey($key)
|
||||
{
|
||||
if (isset($this->params[$key])) {
|
||||
unset($this->params[$key]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a copy of this url without the parameter given
|
||||
*
|
||||
* The argument can either a single query parameter name or an array of parameter names to
|
||||
* The argument can be either a single query parameter name or an array of parameter names to
|
||||
* remove from the query list
|
||||
*
|
||||
* @param string|array $keyOrArrayOfKeys A single string or an array containing parameter names
|
||||
* @return Url
|
||||
* @param string|array $keyOrArrayOfKeys A single string or an array containing parameter names
|
||||
*
|
||||
* @return Url
|
||||
*/
|
||||
public function getUrlWithout($keyOrArrayOfKeys)
|
||||
{
|
||||
|
@ -456,7 +482,8 @@ class Url
|
|||
|
||||
/**
|
||||
* Alias for @see Url::getAbsoluteUrl()
|
||||
* @return mixed
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -205,3 +206,4 @@ class View extends Zend_View_Abstract
|
|||
}
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -29,8 +29,11 @@
|
|||
|
||||
namespace Icinga\Web;
|
||||
|
||||
use Zend_View_Stream as ZfViewStream;
|
||||
use Zend_View_Stream;
|
||||
|
||||
class ViewStream extends ZfViewStream
|
||||
/**
|
||||
* Is used in Icinga\Web\View to imitate PHP's short_open_tag
|
||||
*/
|
||||
class ViewStream extends Zend_View_Stream
|
||||
{
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
/**
|
||||
* Web widget class
|
||||
|
@ -50,4 +51,4 @@ class Widget
|
|||
return $widget;
|
||||
}
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
/**
|
||||
* Web Widget abstract class
|
||||
*/
|
||||
namespace Icinga\Web\Widget;
|
||||
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
|
@ -124,3 +122,4 @@ abstract class AbstractWidget
|
|||
return (string) $html;
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
namespace Icinga\Web\Widget;
|
||||
|
||||
use \Zend_Log;
|
||||
use \Zend_Form;
|
||||
use \Zend_View_Abstract;
|
||||
use Zend_Log;
|
||||
use Zend_Form;
|
||||
use Zend_View_Abstract;
|
||||
use Icinga\User;
|
||||
use Icinga\User\Message;
|
||||
use Icinga\Web\Session;
|
||||
|
@ -129,3 +130,4 @@ class AlertMessageBox implements \Icinga\Web\Widget\Widget
|
|||
return $html;
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -343,3 +344,4 @@ class HistoryColorGrid extends AbstractWidget {
|
|||
return $this->renderVertical($grid);
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -231,4 +232,4 @@ EOD;
|
|||
return $template;
|
||||
}
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -38,7 +38,6 @@ use Icinga\Web\Widget\AbstractWidget;
|
|||
use Icinga\Web\Widget\Dashboard\Pane;
|
||||
use Icinga\Web\Widget\Dashboard\Component as DashboardComponent;
|
||||
use Icinga\Web\Url;
|
||||
use Zend_View_Abstract;
|
||||
|
||||
/**
|
||||
* Dashboards display multiple views on a single page
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -185,3 +186,4 @@ EOT;
|
|||
return $this->nodeToBadge(Tree::normalizeTree($this->tree->root));
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -110,10 +111,10 @@ EOT;
|
|||
$query = $form->getElement('query')->setDecorators(array('ViewHelper'));
|
||||
|
||||
$badges = new FilterBadgeRenderer($this->initialFilter);
|
||||
$form->setIgnoreChangeDiscarding(true);
|
||||
return '<div class="pull-right">' . $badges->render($view) . '</div>' . $form;
|
||||
$html = str_replace('{{FORM}}', $form->render($view), self::$TPL);
|
||||
$html = '<div class="input-append">' . $html . '</div>';
|
||||
return str_replace('{{BADGES}}', $badges->render($view), $html);
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -29,11 +30,10 @@
|
|||
|
||||
namespace Icinga\Web\Widget;
|
||||
|
||||
use Zend_Form_Element_Submit;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Web\Request;
|
||||
use Zend_View_Abstract;
|
||||
use Icinga\Web\Form\Decorator\ConditionalHidden;
|
||||
use Zend_Form_Element_Submit;
|
||||
|
||||
/**
|
||||
* Sortbox widget
|
||||
|
@ -174,3 +174,4 @@ class SortBox extends AbstractWidget
|
|||
return $form;
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -29,8 +30,8 @@
|
|||
|
||||
namespace Icinga\Web\Widget\Tabextension;
|
||||
|
||||
use \Icinga\Web\Widget\Tabs;
|
||||
use \Icinga\Web\Url;
|
||||
use Icinga\Web\Widget\Tabs;
|
||||
use Icinga\Web\Url;
|
||||
|
||||
/**
|
||||
* Tabextension that adds the basket command
|
||||
|
@ -58,3 +59,4 @@ class BasketAction implements Tabextension
|
|||
);
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -29,10 +30,8 @@
|
|||
|
||||
namespace Icinga\Web\Widget\Tabextension;
|
||||
|
||||
use \Icinga\Web\Url;
|
||||
use \Icinga\Config\Config as IcingaConfig;
|
||||
use \Icinga\Web\Widget\Tabs;
|
||||
use \Icinga\Web\Widget\Dashboard;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Web\Widget\Tabs;
|
||||
|
||||
/**
|
||||
* Tabextension that allows to add the current URL to a dashboard
|
||||
|
@ -61,3 +60,4 @@ class DashboardAction implements Tabextension
|
|||
);
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
// @codeCoverageIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -29,10 +30,9 @@
|
|||
|
||||
namespace Icinga\Web\Widget\Tabextension;
|
||||
|
||||
use \Icinga\Logger\Logger;
|
||||
use \Icinga\Web\Widget\Tab;
|
||||
use \Icinga\Web\Widget\Tabs;
|
||||
use \Icinga\Web\Url;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Web\Widget\Tab;
|
||||
use Icinga\Web\Widget\Tabs;
|
||||
|
||||
/**
|
||||
* Tabextension that offers different output formats for the user in the dropdown area
|
||||
|
@ -97,24 +97,17 @@ class OutputFormat implements Tabextension
|
|||
* is added, so this class offers to remove specific types instead of adding ones
|
||||
*
|
||||
* @param array $disabled An array of output types to <b>not</b> show.
|
||||
*
|
||||
*/
|
||||
public function __construct(array $disabled = array())
|
||||
{
|
||||
foreach ($this->supportedTypes as $type => $values) {
|
||||
if (in_array($type, $disabled)) {
|
||||
continue;
|
||||
foreach ($this->supportedTypes as $type => $tabConfig) {
|
||||
if (!in_array($type, $disabled)) {
|
||||
$tabConfig['url'] = Url::fromRequest();
|
||||
$tabConfig['tagParams'] = array(
|
||||
'target' => '_blank'
|
||||
);
|
||||
$this->tabs[] = new Tab($tabConfig);
|
||||
}
|
||||
if (!isset($this->supportedTypes[$type])) {
|
||||
Logger::error('Tried to add an unsupported output type: %s', $type);
|
||||
continue;
|
||||
}
|
||||
$tabConfig = $this->supportedTypes[$type];
|
||||
$tabConfig['url'] = Url::fromRequest();
|
||||
$tabConfig['tagParams'] = array(
|
||||
'target' => '_blank'
|
||||
);
|
||||
$this->tabs[] = new Tab($tabConfig);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,3 +125,4 @@ class OutputFormat implements Tabextension
|
|||
}
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
namespace Icinga\Web\Widget\Tabextension;
|
||||
|
||||
use \Icinga\Web\Widget\Tabs;
|
||||
use Icinga\Web\Widget\Tabs;
|
||||
|
||||
/**
|
||||
* Tabextension interface that allows to extend a tabbar with reusable components
|
||||
|
|
|
@ -74,7 +74,7 @@ class Monitoring_ListController extends Controller
|
|||
public function init()
|
||||
{
|
||||
$this->backend = Backend::createBackend($this->_getParam('backend'));
|
||||
$this->view->grapher = Hook::get('grapher');
|
||||
$this->view->grapher = Hook::first('grapher');
|
||||
$this->createTabs();
|
||||
$this->view->activeRowHref = $this->getParam('detail');
|
||||
$this->view->compact = ($this->_request->getParam('view') === 'compact');
|
||||
|
|
|
@ -6,6 +6,7 @@ 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\Web\Controller\ActionController;
|
||||
|
@ -170,13 +171,13 @@ class Monitoring_TimelineController extends ActionController
|
|||
case '1m':
|
||||
$dateCopy = clone $dateTime;
|
||||
for ($i = 0; $i < 6; $i++) {
|
||||
$dateCopy->sub(new DateInterval('PT' . DateTimeFactory::getSecondsByMonth($dateCopy) . 'S'));
|
||||
$dateCopy->sub(new DateInterval('PT' . Format::secondsByMonth($dateCopy) . 'S'));
|
||||
}
|
||||
return $dateCopy->add(new DateInterval('PT1S'))->diff($dateTime);
|
||||
case '1y':
|
||||
$dateCopy = clone $dateTime;
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
$dateCopy->sub(new DateInterval('PT' . DateTimeFactory::getSecondsByYear($dateCopy) . 'S'));
|
||||
$dateCopy->sub(new DateInterval('PT' . Format::secondsByYear($dateCopy) . 'S'));
|
||||
}
|
||||
return $dateCopy->add(new DateInterval('PT1S'))->diff($dateTime);
|
||||
default:
|
||||
|
|
|
@ -56,7 +56,6 @@ class Zend_View_Helper_CommandForm extends Zend_View_Helper_Abstract
|
|||
{
|
||||
$form = new Form();
|
||||
$form->setAttrib('class', 'inline');
|
||||
$form->setIgnoreChangeDiscarding(true);
|
||||
$form->setRequest(Zend_Controller_Front::getInstance()->getRequest());
|
||||
|
||||
// Filter work only from get parts. Put important
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue