2014-10-29 15:40:34 +01:00
|
|
|
|
<?php
|
2016-02-08 15:41:00 +01:00
|
|
|
|
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
2014-10-29 15:40:34 +01:00
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Monitoring;
|
|
|
|
|
|
2023-08-14 15:13:40 +02:00
|
|
|
|
use Icinga\Module\Setup\Forms\RequirementsPage;
|
2014-10-29 15:40:34 +01:00
|
|
|
|
use Icinga\Web\Form;
|
|
|
|
|
use Icinga\Web\Wizard;
|
|
|
|
|
use Icinga\Web\Request;
|
2014-11-10 16:31:40 +01:00
|
|
|
|
use Icinga\Module\Setup\Setup;
|
|
|
|
|
use Icinga\Module\Setup\SetupWizard;
|
2015-03-09 09:05:56 +01:00
|
|
|
|
use Icinga\Module\Setup\RequirementSet;
|
2014-11-14 11:01:16 +01:00
|
|
|
|
use Icinga\Module\Setup\Forms\SummaryPage;
|
2014-11-14 11:17:22 +01:00
|
|
|
|
use Icinga\Module\Monitoring\Forms\Setup\WelcomePage;
|
|
|
|
|
use Icinga\Module\Monitoring\Forms\Setup\SecurityPage;
|
2015-08-26 15:52:36 +02:00
|
|
|
|
use Icinga\Module\Monitoring\Forms\Setup\TransportPage;
|
2014-11-14 11:17:22 +01:00
|
|
|
|
use Icinga\Module\Monitoring\Forms\Setup\IdoResourcePage;
|
2015-02-25 13:39:59 +01:00
|
|
|
|
use Icinga\Module\Setup\Requirement\PhpModuleRequirement;
|
2014-10-29 15:40:34 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Monitoring Module Setup Wizard
|
|
|
|
|
*/
|
2014-11-10 10:30:52 +01:00
|
|
|
|
class MonitoringWizard extends Wizard implements SetupWizard
|
2014-10-29 15:40:34 +01:00
|
|
|
|
{
|
|
|
|
|
/**
|
2015-07-02 09:42:59 +02:00
|
|
|
|
* Register all pages for this wizard
|
2014-10-29 15:40:34 +01:00
|
|
|
|
*/
|
|
|
|
|
public function init()
|
|
|
|
|
{
|
|
|
|
|
$this->addPage(new WelcomePage());
|
|
|
|
|
$this->addPage(new IdoResourcePage());
|
2015-08-26 15:52:36 +02:00
|
|
|
|
$this->addPage(new TransportPage());
|
2014-10-29 15:40:34 +01:00
|
|
|
|
$this->addPage(new SecurityPage());
|
2015-01-21 11:44:44 +01:00
|
|
|
|
$this->addPage(new SummaryPage(array('name' => 'setup_monitoring_summary')));
|
2014-10-29 15:40:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-07-02 09:42:59 +02:00
|
|
|
|
* Setup the given page that is either going to be displayed or validated
|
|
|
|
|
*
|
2023-08-14 15:13:40 +02:00
|
|
|
|
* @param Form|RequirementsPage|SummaryPage $page The page to setup
|
|
|
|
|
* @param Request $request The current request
|
2014-10-29 15:40:34 +01:00
|
|
|
|
*/
|
|
|
|
|
public function setupPage(Form $page, Request $request)
|
|
|
|
|
{
|
|
|
|
|
if ($page->getName() === 'setup_requirements') {
|
|
|
|
|
$page->setRequirements($this->getRequirements());
|
2015-01-21 11:44:44 +01:00
|
|
|
|
} elseif ($page->getName() === 'setup_monitoring_summary') {
|
2014-11-10 10:30:52 +01:00
|
|
|
|
$page->setSummary($this->getSetup()->getSummary());
|
2014-10-29 15:40:34 +01:00
|
|
|
|
$page->setSubjectTitle(mt('monitoring', 'the monitoring module', 'setup.summary.subject'));
|
2017-01-27 14:48:59 +01:00
|
|
|
|
} elseif ($this->getDirection() === static::FORWARD
|
2017-09-28 15:36:52 +02:00
|
|
|
|
&& ($page->getName() === 'setup_monitoring_ido')
|
2014-10-29 15:40:34 +01:00
|
|
|
|
) {
|
2017-01-27 14:48:59 +01:00
|
|
|
|
if ((($authDbResourceData = $this->getPageData('setup_auth_db_resource')) !== null
|
2015-07-01 14:24:48 +02:00
|
|
|
|
&& $authDbResourceData['name'] === $request->getPost('name'))
|
2015-07-01 16:02:40 +02:00
|
|
|
|
|| (($configDbResourceData = $this->getPageData('setup_config_db_resource')) !== null
|
|
|
|
|
&& $configDbResourceData['name'] === $request->getPost('name'))
|
|
|
|
|
|| (($ldapResourceData = $this->getPageData('setup_ldap_resource')) !== null
|
|
|
|
|
&& $ldapResourceData['name'] === $request->getPost('name'))
|
2014-10-29 15:40:34 +01:00
|
|
|
|
) {
|
2015-07-02 09:45:00 +02:00
|
|
|
|
$page->error(mt('monitoring', 'The given resource name is already in use.'));
|
2014-10-29 15:40:34 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-07-02 09:42:59 +02:00
|
|
|
|
* Add buttons to the given page based on its position in the page-chain
|
|
|
|
|
*
|
|
|
|
|
* @param Form $page The page to add the buttons to
|
2017-11-20 10:01:30 +01:00
|
|
|
|
*
|
|
|
|
|
* @todo This is never called, because its a sub-wizard only
|
2017-11-21 13:46:29 +01:00
|
|
|
|
* @todo This is missing the ´transport_validation´ case
|
2017-11-20 10:01:30 +01:00
|
|
|
|
* @see WebWizard::addButtons which does some of the needed work
|
2014-10-29 15:40:34 +01:00
|
|
|
|
*/
|
|
|
|
|
protected function addButtons(Form $page)
|
|
|
|
|
{
|
|
|
|
|
parent::addButtons($page);
|
|
|
|
|
|
|
|
|
|
$pages = $this->getPages();
|
|
|
|
|
$index = array_search($page, $pages, true);
|
|
|
|
|
if ($index === 0) {
|
|
|
|
|
// Used t() here as "Start" is too generic and already translated in the icinga domain
|
|
|
|
|
$page->getElement(static::BTN_NEXT)->setLabel(t('Start', 'setup.welcome.btn.next'));
|
|
|
|
|
} elseif ($index === count($pages) - 1) {
|
|
|
|
|
$page->getElement(static::BTN_NEXT)->setLabel(
|
2014-11-10 10:30:52 +01:00
|
|
|
|
mt('monitoring', 'Setup the monitoring module for Icinga Web 2', 'setup.summary.btn.finish')
|
2014-10-29 15:40:34 +01:00
|
|
|
|
);
|
|
|
|
|
}
|
2015-07-29 10:52:32 +02:00
|
|
|
|
|
|
|
|
|
if ($page->getName() === 'setup_monitoring_ido') {
|
|
|
|
|
$page->addElement(
|
|
|
|
|
'submit',
|
|
|
|
|
'backend_validation',
|
|
|
|
|
array(
|
2015-08-20 15:48:41 +02:00
|
|
|
|
'ignore' => true,
|
|
|
|
|
'label' => t('Validate Configuration'),
|
|
|
|
|
'data-progress-label' => t('Validation In Progress'),
|
2021-04-13 16:07:06 +02:00
|
|
|
|
'decorators' => array('ViewHelper'),
|
|
|
|
|
'formnovalidate' => 'formnovalidate'
|
2015-07-29 10:52:32 +02:00
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$page->getDisplayGroup('buttons')->addElement($page->getElement('backend_validation'));
|
|
|
|
|
}
|
2014-10-29 15:40:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-07-02 09:42:59 +02:00
|
|
|
|
* Return the setup for this wizard
|
|
|
|
|
*
|
|
|
|
|
* @return Setup
|
2014-10-29 15:40:34 +01:00
|
|
|
|
*/
|
2014-11-10 10:30:52 +01:00
|
|
|
|
public function getSetup()
|
2014-10-29 15:40:34 +01:00
|
|
|
|
{
|
|
|
|
|
$pageData = $this->getPageData();
|
2014-11-10 10:30:52 +01:00
|
|
|
|
$setup = new Setup();
|
2014-10-29 15:40:34 +01:00
|
|
|
|
|
2014-11-10 10:30:52 +01:00
|
|
|
|
$setup->addStep(
|
2014-10-29 15:40:34 +01:00
|
|
|
|
new BackendStep(array(
|
2021-06-30 18:54:47 +02:00
|
|
|
|
'backendConfig' => ['name' => 'icinga', 'type' => 'ido'],
|
2019-12-04 11:01:35 +01:00
|
|
|
|
'resourceConfig' => array_diff_key(
|
|
|
|
|
$pageData['setup_monitoring_ido'], //TODO: Prefer a new backend once implemented.
|
|
|
|
|
array('skip_validation' => null)
|
|
|
|
|
)
|
2014-10-29 15:40:34 +01:00
|
|
|
|
))
|
|
|
|
|
);
|
|
|
|
|
|
2014-11-10 10:30:52 +01:00
|
|
|
|
$setup->addStep(
|
2015-08-26 15:52:36 +02:00
|
|
|
|
new TransportStep(array(
|
2015-08-26 15:43:30 +02:00
|
|
|
|
'transportConfig' => $pageData['setup_command_transport']
|
2014-10-29 15:40:34 +01:00
|
|
|
|
))
|
|
|
|
|
);
|
|
|
|
|
|
2014-11-10 10:30:52 +01:00
|
|
|
|
$setup->addStep(
|
2014-10-29 15:40:34 +01:00
|
|
|
|
new SecurityStep(array(
|
2014-11-12 09:39:18 +01:00
|
|
|
|
'securityConfig' => $pageData['setup_monitoring_security']
|
2014-10-29 15:40:34 +01:00
|
|
|
|
))
|
|
|
|
|
);
|
|
|
|
|
|
2014-11-10 10:30:52 +01:00
|
|
|
|
return $setup;
|
2014-10-29 15:40:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-07-02 09:42:59 +02:00
|
|
|
|
* Return the requirements of this wizard
|
|
|
|
|
*
|
|
|
|
|
* @return RequirementSet
|
2014-10-29 15:40:34 +01:00
|
|
|
|
*/
|
|
|
|
|
public function getRequirements()
|
|
|
|
|
{
|
2015-03-09 09:05:56 +01:00
|
|
|
|
$set = new RequirementSet();
|
2017-02-01 15:37:52 +01:00
|
|
|
|
$set->add(new PhpModuleRequirement(array(
|
|
|
|
|
'optional' => true,
|
|
|
|
|
'condition' => 'curl',
|
|
|
|
|
'alias' => 'cURL',
|
|
|
|
|
'description' => mt(
|
|
|
|
|
'monitoring',
|
|
|
|
|
'To send external commands over Icinga 2\'s API the cURL module for PHP is required.'
|
|
|
|
|
)
|
|
|
|
|
)));
|
2015-02-26 10:50:45 +01:00
|
|
|
|
|
2015-03-09 09:05:56 +01:00
|
|
|
|
return $set;
|
2014-10-29 15:40:34 +01:00
|
|
|
|
}
|
|
|
|
|
}
|