mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-26 15:24:05 +02:00
Create configuration sub directories as part of the setup wizard
refs #7163
This commit is contained in:
parent
85f7dcf825
commit
98acc24869
102
library/Icinga/Application/Installation/MakeDirStep.php
Normal file
102
library/Icinga/Application/Installation/MakeDirStep.php
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Application\Installation;
|
||||||
|
|
||||||
|
use Icinga\Web\Setup\Step;
|
||||||
|
|
||||||
|
class MakeDirStep extends Step
|
||||||
|
{
|
||||||
|
protected $paths;
|
||||||
|
|
||||||
|
protected $dirmode;
|
||||||
|
|
||||||
|
protected $errors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $paths
|
||||||
|
* @param string $dirmode
|
||||||
|
*/
|
||||||
|
public function __construct($paths, $dirmode)
|
||||||
|
{
|
||||||
|
$this->paths = $paths;
|
||||||
|
$this->dirmode = octdec($dirmode) | octdec('111'); // Make sure that the directories can be traversed
|
||||||
|
$this->errors = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function apply()
|
||||||
|
{
|
||||||
|
$success = true;
|
||||||
|
foreach ($this->paths as $path) {
|
||||||
|
if (false === file_exists($path)) {
|
||||||
|
if (false === @mkdir($path)) {
|
||||||
|
$this->errors[$path] = error_get_last();
|
||||||
|
$success = false;
|
||||||
|
} else {
|
||||||
|
$this->errors[$path] = null;
|
||||||
|
$old = umask(0);
|
||||||
|
chmod($path, $this->dirmode);
|
||||||
|
umask($old);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSummary()
|
||||||
|
{
|
||||||
|
$pageHtml = '';
|
||||||
|
$pageTitle = t('Directory Creation');
|
||||||
|
$createMsg = t('The setup will create the following directories:');
|
||||||
|
$existsMsg = t('The setup does not need to create the following already existing directories:');
|
||||||
|
|
||||||
|
$toBeCreated = array_filter($this->paths, function ($p) { return false === file_exists($p); });
|
||||||
|
if (false === empty($toBeCreated)) {
|
||||||
|
$pageHtml .= '<p>' . $createMsg . '</p>';
|
||||||
|
|
||||||
|
$pageHtml .= '<ul>';
|
||||||
|
foreach ($toBeCreated as $path) {
|
||||||
|
$pageHtml .= '<li>' . $path . '</li>';
|
||||||
|
}
|
||||||
|
$pageHtml .= '</ul>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$existing = array_diff($this->paths, $toBeCreated);
|
||||||
|
if (false === empty($existing)) {
|
||||||
|
$pageHtml .= '<p>' . $existsMsg . '</p>';
|
||||||
|
|
||||||
|
$pageHtml .= '<ul>';
|
||||||
|
foreach ($existing as $path) {
|
||||||
|
$pageHtml .= '<li>' . $path . '</li>';
|
||||||
|
}
|
||||||
|
$pageHtml .= '</ul>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '<h2>' . $pageTitle . '</h2>' . $pageHtml;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getReport()
|
||||||
|
{
|
||||||
|
$okMessage = t('Directory "%s" in "%s" has been successfully created.');
|
||||||
|
$existsMessage = t('Directory "%s" does already exist in "%s". Nothing to do.');
|
||||||
|
$failMessage = t('Unable to create directory "%s" in "%s". An error occured:');
|
||||||
|
|
||||||
|
$report = '';
|
||||||
|
foreach ($this->paths as $path) {
|
||||||
|
if (array_key_exists($path, $this->errors)) {
|
||||||
|
if (is_array($this->errors[$path])) {
|
||||||
|
$report .= '<p class="error">' . sprintf($failMessage, basename($path), dirname($path)) . '</p>'
|
||||||
|
. '<p>' . $this->errors[$path]['message'] . '</p>';
|
||||||
|
} else {
|
||||||
|
$report .= '<p>' . sprintf($okMessage, basename($path), dirname($path)) . '</p>';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$report .= '<p>' . sprintf($existsMessage, basename($path), dirname($path)) . '</p>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $report;
|
||||||
|
}
|
||||||
|
}
|
@ -19,6 +19,7 @@ use Icinga\Form\Setup\RequirementsPage;
|
|||||||
use Icinga\Form\Setup\GeneralConfigPage;
|
use Icinga\Form\Setup\GeneralConfigPage;
|
||||||
use Icinga\Form\Setup\AuthenticationPage;
|
use Icinga\Form\Setup\AuthenticationPage;
|
||||||
use Icinga\Form\Setup\DatabaseCreationPage;
|
use Icinga\Form\Setup\DatabaseCreationPage;
|
||||||
|
use Icinga\Application\Installation\MakeDirStep;
|
||||||
use Icinga\Application\Installation\DatabaseStep;
|
use Icinga\Application\Installation\DatabaseStep;
|
||||||
use Icinga\Application\Installation\GeneralConfigStep;
|
use Icinga\Application\Installation\GeneralConfigStep;
|
||||||
use Icinga\Application\Installation\ResourceStep;
|
use Icinga\Application\Installation\ResourceStep;
|
||||||
@ -313,6 +314,18 @@ class WebSetup extends Wizard implements SetupWizard
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$configDir = $this->getConfigDir();
|
||||||
|
$installer->addStep(
|
||||||
|
new MakeDirStep(
|
||||||
|
array(
|
||||||
|
$configDir . '/modules',
|
||||||
|
$configDir . '/preferences',
|
||||||
|
$configDir . '/enabledModules'
|
||||||
|
),
|
||||||
|
$pageData['setup_general_config']['global_filemode']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
foreach ($this->getPage('setup_modules')->getWizards() as $wizard) {
|
foreach ($this->getPage('setup_modules')->getWizards() as $wizard) {
|
||||||
if ($wizard->isFinished()) {
|
if ($wizard->isFinished()) {
|
||||||
$installer->addSteps($wizard->getInstaller()->getSteps());
|
$installer->addSteps($wizard->getInstaller()->getSteps());
|
||||||
@ -410,7 +423,6 @@ class WebSetup extends Wizard implements SetupWizard
|
|||||||
$pgsqlAdapterFound ? t('The Zend database adapter for PostgreSQL is available.') : (
|
$pgsqlAdapterFound ? t('The Zend database adapter for PostgreSQL is available.') : (
|
||||||
t('The Zend database adapter for PostgreSQL is missing.')
|
t('The Zend database adapter for PostgreSQL is missing.')
|
||||||
)
|
)
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$defaultTimezone = Platform::getPhpConfig('date.timezone');
|
$defaultTimezone = Platform::getPhpConfig('date.timezone');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user