mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-25 23:04:51 +02:00
Add install routines for all INI files
This is just a quick&dirty implementation. Once we know how modules are being processed/installed this needs to be revisited. refs #7163
This commit is contained in:
parent
450ec2add0
commit
ad7965228c
@ -0,0 +1,14 @@
|
|||||||
|
<div class="report">
|
||||||
|
<?php foreach ($report as $entry): ?>
|
||||||
|
<p class="<?= $entry->state ? 'ok' : 'failure'; ?>">
|
||||||
|
<?= $entry->message; ?>
|
||||||
|
</p>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</div>
|
||||||
|
<div class="buttons">
|
||||||
|
<?php if ($success): ?>
|
||||||
|
<a href="<?= $this->href('authentication/login'); ?>" class="button-like login"><?= t('Login to Icinga Web 2'); ?></a>
|
||||||
|
<?php else: ?>
|
||||||
|
<a href="<?= $this->href(); ?>" class="button-like"><?= t('Back'); ?></a>
|
||||||
|
<?php endif ?>
|
||||||
|
</div>
|
@ -4,10 +4,13 @@
|
|||||||
|
|
||||||
namespace Icinga\Application;
|
namespace Icinga\Application;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Zend_Config;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
use Icinga\Web\Setup\DbTool;
|
use Icinga\Web\Setup\DbTool;
|
||||||
use Icinga\Application\Config;
|
use Icinga\Application\Config;
|
||||||
use Icinga\Web\Setup\Installer;
|
use Icinga\Web\Setup\Installer;
|
||||||
|
use Icinga\Config\PreservingIniWriter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Icinga Web 2 Installer
|
* Icinga Web 2 Installer
|
||||||
@ -21,6 +24,13 @@ class WebInstaller implements Installer
|
|||||||
*/
|
*/
|
||||||
protected $pageData;
|
protected $pageData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The report entries
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $report;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new web installer
|
* Create a new web installer
|
||||||
*
|
*
|
||||||
@ -29,6 +39,7 @@ class WebInstaller implements Installer
|
|||||||
public function __construct(array $pageData)
|
public function __construct(array $pageData)
|
||||||
{
|
{
|
||||||
$this->pageData = $pageData;
|
$this->pageData = $pageData;
|
||||||
|
$this->report = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,7 +47,164 @@ class WebInstaller implements Installer
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
return true;
|
$success = true;
|
||||||
|
|
||||||
|
$configIniPath = Config::resolvePath('config.ini');
|
||||||
|
try {
|
||||||
|
$this->writeConfigIni($configIniPath);
|
||||||
|
$this->report[] = (object) array(
|
||||||
|
'state' => true,
|
||||||
|
'message' => sprintf(t('Successfully created: %s'), $configIniPath)
|
||||||
|
);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$success = false;
|
||||||
|
$this->report[] = (object) array(
|
||||||
|
'state' => false,
|
||||||
|
'message' => sprintf(t('Unable to create: %s (%s)'), $configIniPath, $e->getMessage())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$resourcesIniPath = Config::resolvePath('resources.ini');
|
||||||
|
try {
|
||||||
|
$this->writeResourcesIni($resourcesIniPath);
|
||||||
|
$this->report[] = (object) array(
|
||||||
|
'state' => true,
|
||||||
|
'message' => sprintf(t('Successfully created: %s'), $resourcesIniPath)
|
||||||
|
);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$success = false;
|
||||||
|
$this->report[] = (object) array(
|
||||||
|
'state' => false,
|
||||||
|
'message' => sprintf(t('Unable to create: %s (%s)'), $resourcesIniPath, $e->getMessage())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$authenticationIniPath = Config::resolvePath('authentication.ini');
|
||||||
|
try {
|
||||||
|
$this->writeAuthenticationIni($authenticationIniPath);
|
||||||
|
$this->report[] = (object) array(
|
||||||
|
'state' => true,
|
||||||
|
'message' => sprintf(t('Successfully created: %s'), $authenticationIniPath)
|
||||||
|
);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$success = false;
|
||||||
|
$this->report[] = (object) array(
|
||||||
|
'state' => false,
|
||||||
|
'message' => sprintf(t('Unable to create: %s (%s)'), $authenticationIniPath, $e->getMessage())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write application configuration to the given filepath
|
||||||
|
*
|
||||||
|
* @param string $configPath
|
||||||
|
*/
|
||||||
|
protected function writeConfigIni($configPath)
|
||||||
|
{
|
||||||
|
$preferencesConfig = array();
|
||||||
|
$preferencesConfig['type'] = $this->pageData['setup_preferences_type']['type'];
|
||||||
|
if ($this->pageData['setup_preferences_type']['type'] === 'db') {
|
||||||
|
$preferencesConfig['resource'] = $this->pageData['setup_db_resource']['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$loggingConfig = array();
|
||||||
|
$loggingConfig['type'] = $this->pageData['setup_general_config']['logging_type'];
|
||||||
|
$loggingConfig['level'] = $this->pageData['setup_general_config']['logging_level'];
|
||||||
|
if ($this->pageData['setup_general_config']['logging_type'] === 'syslog') {
|
||||||
|
$loggingConfig['application'] = $this->pageData['setup_general_config']['logging_application'];
|
||||||
|
$loggingConfig['facility'] = $this->pageData['setup_general_config']['logging_facility'];
|
||||||
|
} else { // $this->pageData['setup_general_config']['logging_type'] === 'file'
|
||||||
|
$loggingConfig['target'] = $this->pageData['setup_general_config']['logging_target'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$config = array(
|
||||||
|
'global' => array(
|
||||||
|
'modulepath' => $this->pageData['setup_general_config']['global_modulePath']
|
||||||
|
),
|
||||||
|
'preferences' => $preferencesConfig,
|
||||||
|
'logging' => $loggingConfig
|
||||||
|
);
|
||||||
|
|
||||||
|
$writer = new PreservingIniWriter(array('config' => new Zend_Config($config), 'filename' => $configPath));
|
||||||
|
$writer->write();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write resource configuration to the given filepath
|
||||||
|
*
|
||||||
|
* @param string $configPath
|
||||||
|
*/
|
||||||
|
protected function writeResourcesIni($configPath)
|
||||||
|
{
|
||||||
|
$resourceConfig = array();
|
||||||
|
if (isset($this->pageData['setup_db_resource'])) {
|
||||||
|
$resourceConfig[$this->pageData['setup_db_resource']['name']] = array(
|
||||||
|
'type' => $this->pageData['setup_db_resource']['type'],
|
||||||
|
'db' => $this->pageData['setup_db_resource']['db'],
|
||||||
|
'host' => $this->pageData['setup_db_resource']['host'],
|
||||||
|
'port' => $this->pageData['setup_db_resource']['port'],
|
||||||
|
'dbname' => $this->pageData['setup_db_resource']['dbname'],
|
||||||
|
'username' => $this->pageData['setup_db_resource']['username'],
|
||||||
|
'password' => $this->pageData['setup_db_resource']['password']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($this->pageData['setup_ldap_resource'])) {
|
||||||
|
$resourceConfig[$this->pageData['setup_ldap_resource']['name']] = array(
|
||||||
|
'hostname' => $this->pageData['setup_ldap_resource']['hostname'],
|
||||||
|
'port' => $this->pageData['setup_ldap_resource']['port'],
|
||||||
|
'bind_dn' => $this->pageData['setup_ldap_resource']['bind_dn'],
|
||||||
|
'bind_pw' => $this->pageData['setup_ldap_resource']['bind_pw']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($resourceConfig)) {
|
||||||
|
return; // No need to write nothing :)
|
||||||
|
}
|
||||||
|
|
||||||
|
$writer = new PreservingIniWriter(array(
|
||||||
|
'config' => new Zend_Config($resourceConfig),
|
||||||
|
'filename' => $configPath
|
||||||
|
));
|
||||||
|
$writer->write();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write authentication backend configuration to the given filepath
|
||||||
|
*
|
||||||
|
* @param string $configPath
|
||||||
|
*/
|
||||||
|
protected function writeAuthenticationIni($configPath)
|
||||||
|
{
|
||||||
|
$backendConfig = array();
|
||||||
|
if ($this->pageData['setup_authentication_type']['type'] === 'db') {
|
||||||
|
$backendConfig[$this->pageData['setup_authentication_backend']['name']] = array(
|
||||||
|
'backend' => $this->pageData['setup_authentication_backend']['backend'],
|
||||||
|
'resource' => $this->pageData['setup_db_resource']['name']
|
||||||
|
);
|
||||||
|
} elseif ($this->pageData['setup_authentication_type']['type'] === 'ldap') {
|
||||||
|
$backendConfig[$this->pageData['setup_authentication_backend']['backend']] = array(
|
||||||
|
'backend' => $this->pageData['setup_authentication_backend']['backend'],
|
||||||
|
'resource' => $this->pageData['setup_ldap_resource']['name'],
|
||||||
|
//'root_dn' => $this->pageData['setup_ldap_resource']['root_dn'],
|
||||||
|
'user_class' => $this->pageData['setup_authentication_backend']['user_class'],
|
||||||
|
'user_name_attribute' => $this->pageData['setup_authentication_backend']['user_name_attribute']
|
||||||
|
);
|
||||||
|
} else { // $this->pageData['setup_authentication_type']['type'] === 'autologin'
|
||||||
|
$backendConfig[$this->pageData['setup_authentication_backend']['name']] = array(
|
||||||
|
'backend' => $this->pageData['setup_authentication_backend']['backend'],
|
||||||
|
'strip_username_regexp' => $this->pageData['setup_authentication_backend']['strip_username_regexp']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$writer = new PreservingIniWriter(array(
|
||||||
|
'config' => new Zend_Config($backendConfig),
|
||||||
|
'filename' => $configPath
|
||||||
|
));
|
||||||
|
$writer->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -224,6 +392,6 @@ class WebInstaller implements Installer
|
|||||||
*/
|
*/
|
||||||
public function getReport()
|
public function getReport()
|
||||||
{
|
{
|
||||||
return array();
|
return $this->report;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,4 +59,18 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#setup div.report {
|
||||||
|
p {
|
||||||
|
margin: 1em;
|
||||||
|
|
||||||
|
&.ok {
|
||||||
|
color: green;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.failure {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user