/
Setup.php
190 lines (170 loc) · 6.61 KB
/
Setup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring;
use Icinga\Web\Form;
use Icinga\Web\Wizard;
use Icinga\Web\Request;
use Icinga\Web\Setup\Installer;
use Icinga\Web\Setup\MakeDirStep;
use Icinga\Web\Setup\EnableModuleStep;
use Icinga\Web\Setup\SetupWizard;
use Icinga\Web\Setup\Requirements;
use Icinga\Module\Monitoring\Installation\BackendStep;
use Icinga\Module\Monitoring\Installation\InstanceStep;
use Icinga\Module\Monitoring\Installation\SecurityStep;
use Icinga\Form\Setup\SummaryPage;
use Icinga\Module\Monitoring\Form\Setup\WelcomePage;
use Icinga\Module\Monitoring\Form\Setup\BackendPage;
use Icinga\Module\Monitoring\Form\Setup\InstancePage;
use Icinga\Module\Monitoring\Form\Setup\SecurityPage;
use Icinga\Module\Monitoring\Form\Setup\IdoResourcePage;
use Icinga\Module\Monitoring\Form\Setup\LivestatusResourcePage;
/**
* Monitoring Module Setup Wizard
*/
class Setup extends Wizard implements SetupWizard
{
/**
* @see Wizard::init()
*/
public function init()
{
$this->addPage(new WelcomePage());
$this->addPage(new BackendPage());
$this->addPage(new IdoResourcePage());
$this->addPage(new LivestatusResourcePage());
$this->addPage(new InstancePage());
$this->addPage(new SecurityPage());
$this->addPage(new SummaryPage());
}
/**
* @see Wizard::setupPage()
*/
public function setupPage(Form $page, Request $request)
{
if ($page->getName() === 'setup_requirements') {
$page->setRequirements($this->getRequirements());
} elseif ($page->getName() === 'setup_summary') {
$page->setSummary($this->getInstaller()->getSummary());
$page->setSubjectTitle(mt('monitoring', 'the monitoring module', 'setup.summary.subject'));
} elseif (
$this->getDirection() === static::FORWARD
&& ($page->getName() === 'setup_monitoring_ido' || $page->getName() === 'setup_monitoring_livestatus')
) {
if ((($dbResourceData = $this->getPageData('setup_db_resource')) !== null
&& $dbResourceData['name'] === $request->getPost('name'))
|| (($ldapResourceData = $this->getPageData('setup_ldap_resource')) !== null
&& $ldapResourceData['name'] === $request->getPost('name'))
) {
$page->addError(mt('monitoring', 'The given resource name is already in use.'));
}
}
}
/**
* @see Wizard::getNewPage()
*/
protected function getNewPage($requestedPage, Form $originPage)
{
$skip = false;
$newPage = parent::getNewPage($requestedPage, $originPage);
if ($newPage->getName() === 'setup_monitoring_ido') {
$backendData = $this->getPageData('setup_monitoring_backend');
$skip = $backendData['type'] !== 'ido';
} elseif ($newPage->getName() === 'setup_monitoring_livestatus') {
$backendData = $this->getPageData('setup_monitoring_backend');
$skip = $backendData['type'] !== 'livestatus';
}
if ($skip) {
if ($this->hasPageData($newPage->getName())) {
$pageData = & $this->getPageData();
unset($pageData[$newPage->getName()]);
}
$pages = $this->getPages();
if ($this->getDirection() === static::FORWARD) {
$nextPage = $pages[array_search($newPage, $pages, true) + 1];
$newPage = $this->getNewPage($nextPage->getName(), $newPage);
} else { // $this->getDirection() === static::BACKWARD
$previousPage = $pages[array_search($newPage, $pages, true) - 1];
$newPage = $this->getNewPage($previousPage->getName(), $newPage);
}
}
return $newPage;
}
/**
* @see Wizard::addButtons()
*/
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(
mt('monitoring', 'Install the monitoring module for Icinga Web 2', 'setup.summary.btn.finish')
);
}
}
/**
* @see SetupWizard::getInstaller()
*/
public function getInstaller()
{
$pageData = $this->getPageData();
$installer = new Installer();
$installer->addStep(
new MakeDirStep(
array($this->getConfigDir() . '/modules/monitoring'),
$pageData['setup_general_config']['global_filemode']
)
);
$installer->addStep(
new BackendStep(array(
'backendConfig' => $pageData['setup_monitoring_backend'],
'resourceConfig' => isset($pageData['setup_monitoring_ido'])
? array_diff_key($pageData['setup_monitoring_ido'], array('skip_validation' => null))
: array_diff_key($pageData['setup_monitoring_livestatus'], array('skip_validation' => null)),
'fileMode' => $pageData['setup_general_config']['global_filemode']
))
);
$installer->addStep(
new InstanceStep(array(
'instanceConfig' => $pageData['setup_monitoring_instance'],
'fileMode' => $pageData['setup_general_config']['global_filemode']
))
);
$installer->addStep(
new SecurityStep(array(
'securityConfig' => $pageData['setup_monitoring_security'],
'fileMode' => $pageData['setup_general_config']['global_filemode']
))
);
$installer->addStep(new EnableModuleStep('monitoring'));
return $installer;
}
/**
* @see SetupWizard::getRequirements()
*/
public function getRequirements()
{
return new Requirements();
}
/**
* Return the configuration directory of Icinga Web 2
*
* @return string
*/
protected function getConfigDir()
{
if (array_key_exists('ICINGAWEB_CONFIGDIR', $_SERVER)) {
$configDir = $_SERVER['ICINGAWEB_CONFIGDIR'];
} else {
$configDir = '/etc/icingaweb';
}
$canonical = realpath($configDir);
return $canonical ? $canonical : $configDir;
}
}