Move summary HTML generation from the view script to each install step

refs #7163
This commit is contained in:
Johannes Meyer 2014-10-23 15:15:59 +02:00
parent 216c072024
commit a6cbde54c5
5 changed files with 262 additions and 220 deletions

View File

@ -1,227 +1,25 @@
<?php <?php
use Icinga\Web\Wizard; use Icinga\Web\Wizard;
use Icinga\Logger\Logger;
use Icinga\Application\Config;
$summary = $form->getSummary();
$prefType = $summary['setup_preferences_type']['type'];
$authType = $summary['setup_authentication_type']['type'];
$adminType = $summary['setup_admin_account']['user_type'];
$loggingType = $summary['setup_general_config']['logging_log'];
?> ?>
<p><?= t( <p><?= t(
'The wizard is now complete. You can review the changes supposed to be made before issuing the actual installation' 'The wizard is now complete. You can review the changes supposed to be made before issuing the actual installation'
. ' of Icinga Web 2. Make sure that everything is correct (Feel free to navigate back to make any corrections!) so' . ' of Icinga Web 2. Make sure that everything is correct (Feel free to navigate back to make any corrections!) so'
. ' that you can start using Icinga Web 2 right after the installation has been finished.' . ' that you can start using Icinga Web 2 right after the installation has been finished.'
); ?></p> ); ?></p>
<div class="summary"> <div class="summary">
<?php if ($authType !== 'autologin' || $prefType === 'db'): ?> <?php foreach ($form->getSummary() as $pageHtml): ?>
<div class="page"> <div class="page">
<h2><?= $authType === 'ldap' && $prefType === 'db' ? t('Resources') : t('Resource'); ?></h2> <?= $pageHtml; ?>
<?php if ($authType === 'db' || $prefType === 'db'): ?>
<div class="topic">
<p>
<?= $authType === 'db' && $prefType === 'db'
? t('The following database will be used to authenticate users and to store preferences.') : (
$authType === 'db' ? t('The following database will be used to authenticate users.') : (
t('The following database will be used to store preferences.')
)
);
?>
</p>
<h3><?= t('Database'); ?></h3>
<table>
<tbody>
<tr>
<td><strong><?= t('Resource Name'); ?></strong></td>
<td><?= $summary['setup_db_resource']['name']; ?></td>
</tr>
<tr>
<td><strong><?= t('Database Type'); ?></strong></td>
<td><?= $summary['setup_db_resource']['db']; ?></td>
</tr>
<tr>
<td><strong><?= t('Host'); ?></strong></td>
<td><?= $summary['setup_db_resource']['host']; ?></td>
</tr>
<tr>
<td><strong><?= t('Port'); ?></strong></td>
<td><?= $summary['setup_db_resource']['port']; ?></td>
</tr>
<tr>
<td><strong><?= t('Database Name'); ?></strong></td>
<td><?= $summary['setup_db_resource']['dbname']; ?></td>
</tr>
<tr>
<td><strong><?= t('Username'); ?></strong></td>
<td><?= $summary['setup_db_resource']['username']; ?></td>
</tr>
<tr>
<td><strong><?= t('Password'); ?></strong></td>
<td><?= str_repeat('*', strlen($summary['setup_db_resource']['password'])); ?></td>
</tr>
</tbody>
</table>
</div>
<?php endif ?>
<?php if ($authType === 'ldap'): ?>
<div class="topic">
<p><?= t('The following LDAP connection will be used to authenticate users.'); ?></p>
<h3>LDAP</h3>
<table>
<tbody>
<tr>
<td><strong><?= t('Resource Name'); ?></strong></td>
<td><?= $summary['setup_ldap_resource']['name']; ?></td>
</tr>
<tr>
<td><strong><?= t('Host'); ?></strong></td>
<td><?= $summary['setup_ldap_resource']['hostname']; ?></td>
</tr>
<tr>
<td><strong><?= t('Port'); ?></strong></td>
<td><?= $summary['setup_ldap_resource']['port']; ?></td>
</tr>
<tr>
<td><strong><?= t('Root DN'); ?></strong></td>
<td><?= $summary['setup_ldap_resource']['root_dn']; ?></td>
</tr>
<tr>
<td><strong><?= t('Bind DN'); ?></strong></td>
<td><?= $summary['setup_ldap_resource']['bind_dn']; ?></td>
</tr>
<tr>
<td><strong><?= t('Bind Password'); ?></strong></td>
<td><?= str_repeat('*', strlen($summary['setup_ldap_resource']['bind_pw'])); ?></td>
</tr>
</tbody>
</table>
</div>
<?php endif ?>
</div> </div>
<?php endif ?> <?php endforeach ?>
<div class="page"> </div>
<h2><?= t('Authentication'); ?></h2> <form id="<?= $form->getName(); ?>" name="<?= $form->getName(); ?>" enctype="<?= $form->getEncType(); ?>" method="<?= $form->getMethod(); ?>">
<div class="topic"> <?= $form->getElement($form->getTokenElementName()); ?>
<p><?= sprintf( <?= $form->getElement($form->getUidElementName()); ?>
t('Users will authenticate using %s.', 'setup.summary.auth'), <div class="buttons">
$authType === 'db' ? t('a database', 'setup.summary.auth.type') : ( <?= $form->getElement(Wizard::BTN_PREV); ?>
$authType === 'ldap' ? 'LDAP' : t('webserver authentication', 'setup.summary.auth.type') <?= $form->getElement(Wizard::BTN_NEXT)->setAttrib('class', 'install'); ?>
)
); ?></p>
<h3><?= t('Backend Configuration'); ?></h3>
<table>
<tbody>
<tr>
<td><strong><?= t('Backend Name'); ?></strong></td>
<td><?= $summary['setup_authentication_backend']['name']; ?></td>
</tr>
<?php if ($authType === 'ldap'): ?>
<tr>
<td><strong><?= t('User Object Class'); ?></strong></td>
<td><?= $summary['setup_authentication_backend']['user_class']; ?></td>
</tr>
<tr>
<td><strong><?= t('User Name Attribute'); ?></strong></td>
<td><?= $summary['setup_authentication_backend']['user_name_attribute']; ?></td>
</tr>
<?php elseif ($authType === 'autologin'): ?>
<tr>
<td><strong><?= t('Backend Domain Pattern'); ?></strong></td>
<td><?= $summary['setup_authentication_backend']['strip_username_regexp']; ?></td>
</tr>
<?php endif ?>
</tbody>
</table>
</div>
<div class="topic">
<h3><?= t('Initial Administrative Account'); ?></h3>
<p><?= $adminType === 'by_name' || $adminType === 'existing_user' ? sprintf(
t('Administrative rights will initially be granted to an existing account called "%s".'),
$summary['setup_admin_account'][$adminType]
) : sprintf(
t('Administrative rights will initially be granted to a new account called "%s".'),
$summary['setup_admin_account'][$adminType]
); ?>
</div>
</div> </div>
<div class="page"> </form>
<h2><?= t('Application Configuration'); ?></h2>
<div class="topic">
<h3><?= t('General', 'app.config'); ?></h3>
<ul>
<li><?= sprintf(
t('Icinga Web 2 will look for modules at: %s'),
$summary['setup_general_config']['global_modulePath']
); ?></li>
<li><?= sprintf(
t('Icinga Web 2 will save new configuration files using the mode "%s".'),
$summary['setup_general_config']['global_filemode']
); ?></li>
<li><?= sprintf(
$prefType === 'ini' ? sprintf(
t('Preferences will be stored per user account in INI files at: %s'),
Config::$configDir . '/preferences'
) : (
$prefType === 'db' ? t('Preferences will be stored using a database.') : (
t('Preferences will not be persisted across browser sessions.')
)
)
); ?></li>
</ul>
</div>
<div class="topic">
<h3><?= t('Logging', 'app.config'); ?></h3>
<?php if ($loggingType === 'none'): ?>
<p><?= t('Logging will be disabled.'); ?></p>
<?php else: ?>
<table>
<tbody>
<tr>
<td><strong><?= t('Type', 'app.config.logging'); ?></strong></td>
<td><?= $loggingType === 'syslog' ? 'Syslog' : t('File', 'app.config.logging.type'); ?></td>
</tr>
<tr>
<td><strong><?= t('Level', 'app.config.logging'); ?></strong></td>
<?php $loggingLevel = $summary['setup_general_config']['logging_level']; ?>
<td><?= $loggingLevel === Logger::$levels[Logger::ERROR] ? t('Error', 'app.config.logging.level') : (
$loggingLevel === Logger::$levels[Logger::WARNING] ? t('Warning', 'app.config.logging.level') : (
$loggingLevel === Logger::$levels[Logger::INFO] ? t('Information', 'app.config.logging.level') : (
t('Debug', 'app.config.logging.level')
)
)
); ?></td>
</tr>
<?php if ($loggingType === 'syslog'): ?>
<tr>
<td><strong><?= t('Application Prefix'); ?></strong></td>
<td><?= $summary['setup_general_config']['logging_application']; ?></td>
</tr>
<?php else: ?>
<tr>
<td><strong><?= t('Filepath'); ?></strong></td>
<td><?= $summary['setup_general_config']['logging_file']; ?></td>
</tr>
<?php endif ?>
</tbody>
</table>
<?php endif ?>
</div>
</div>
<?php if (isset($summary['setup_db_resource'])): ?>
<div class="page">
<h2><?= t('Database Setup'); ?></h2>
<p><?= $summary['database_info']; ?></p>
</div>
<?php endif ?>
<form id="<?= $form->getName(); ?>" name="<?= $form->getName(); ?>" enctype="<?= $form->getEncType(); ?>" method="<?= $form->getMethod(); ?>">
<?= $form->getElement($form->getTokenElementName()); ?>
<?= $form->getElement($form->getUidElementName()); ?>
<div class="buttons">
<?= $form->getElement(Wizard::BTN_PREV); ?>
<?= $form->getElement(Wizard::BTN_NEXT)->setAttrib('class', 'install'); ?>
</div>
</form>
</div>

View File

@ -95,7 +95,53 @@ class AuthenticationStep extends Step
public function getSummary() public function getSummary()
{ {
return ''; $pageTitle = '<h2>' . t('Authentication') . '</h2>';
$backendTitle = '<h3>' . t('Backend Configuration') . '</h3>';
$adminTitle = '<h3>' . t('Initial Administrative Account') . '</h3>';
$authType = $this->data['backendConfig']['backend'];
$backendDesc = '<p>' . sprintf(
t('Users will authenticate using %s.', 'setup.summary.auth'),
$authType === 'db' ? t('a database', 'setup.summary.auth.type') : (
$authType === 'ldap' ? 'LDAP' : t('webserver authentication', 'setup.summary.auth.type')
)
) . '</p>';
$backendHtml = ''
. '<table>'
. '<tbody>'
. '<tr>'
. '<td><strong>' . t('Backend Name') . '</strong></td>'
. '<td>' . $this->data['backendConfig']['name'] . '</td>'
. '</tr>'
. ($authType === 'ldap' ? (
'<tr>'
. '<td><strong>' . t('User Object Class') . '</strong></td>'
. '<td>' . $this->data['backendConfig']['user_class'] . '</td>'
. '</tr>'
. '<tr>'
. '<td><strong>' . t('User Name Attribute') . '</strong></td>'
. '<td>' . $this->data['backendConfig']['user_name_attribute'] . '</td>'
. '</tr>'
) : ($authType === 'autologin' ? (
'<tr>'
. '<td><strong>' . t('Filter Pattern') . '</strong></td>'
. '<td>' . $this->data['backendConfig']['strip_username_regexp'] . '</td>'
. '</tr>'
) : ''))
. '</tbody>'
. '</table>';
$adminHtml = '<p>' . (isset($this->data['adminAccountData']['resourceConfig']) ? sprintf(
t('Administrative rights will initially be granted to an existing account called "%s".'),
$this->data['adminAccountData']['username']
) : sprintf(
t('Administrative rights will initially be granted to a new account called "%s".'),
$this->data['adminAccountData']['username']
)) . '</p>';
return $pageTitle . '<div class="topic">' . $backendDesc . $backendTitle . $backendHtml . '</div>'
. '<div class="topic">' . $adminTitle . $adminHtml . '</div>';
} }
public function getReport() public function getReport()

View File

@ -152,7 +152,65 @@ class DatabaseStep extends Step
public function getSummary() public function getSummary()
{ {
return ''; $resourceConfig = $this->data['resourceConfig'];
if (isset($this->data['adminName'])) {
$resourceConfig['username'] = $this->data['adminName'];
if (isset($this->data['adminPassword'])) {
$resourceConfig['password'] = $this->data['adminPassword'];
}
}
$db = new DbTool($resourceConfig);
try {
$db->connectToDb();
if (array_search('account', $db->listTables()) === false) {
$message = sprintf(
t(
'The database user "%s" will be used to setup the missing'
. ' schema required by Icinga Web 2 in database "%s".'
),
$resourceConfig['username'],
$resourceConfig['dbname']
);
} else {
$message = sprintf(
t('The database "%s" already seems to be fully set up. No action required.'),
$resourceConfig['dbname']
);
}
} catch (PDOException $e) {
try {
$db->connectToHost();
if ($db->hasLogin($this->data['resourceConfig']['username'])) {
$message = sprintf(
t(
'The database user "%s" will be used to create the missing '
. 'database "%s" with the schema required by Icinga Web 2.'
),
$resourceConfig['username'],
$resourceConfig['dbname']
);
} else {
$message = sprintf(
t(
'The database user "%s" will be used to create the missing database "%s" '
. 'with the schema required by Icinga Web 2 and a new login called "%s".'
),
$resourceConfig['username'],
$resourceConfig['dbname'],
$this->data['resourceConfig']['username']
);
}
} catch (Exception $ex) {
$message = t(
'No connection to database host possible. You\'ll need to setup the'
. ' database with the schema required by Icinga Web 2 manually.'
);
}
}
return '<h2>' . t('Database Setup') . '</h2><p>' . $message . '</p>';
} }
public function getReport() public function getReport()

View File

@ -6,6 +6,7 @@ namespace Icinga\Application\Installation;
use Exception; use Exception;
use Zend_Config; use Zend_Config;
use Icinga\Logger\Logger;
use Icinga\Web\Setup\Step; use Icinga\Web\Setup\Step;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\Config\PreservingIniWriter; use Icinga\Config\PreservingIniWriter;
@ -52,7 +53,69 @@ class GeneralConfigStep extends Step
public function getSummary() public function getSummary()
{ {
return ''; $pageTitle = '<h2>' . t('Application Configuration') . '</h2>';
$generalTitle = '<h3>' . t('General', 'app.config') . '</h3>';
$loggingTitle = '<h3>' . t('Logging', 'app.config') . '</h3>';
$generalHtml = ''
. '<ul>'
. '<li>' . sprintf(
t('Icinga Web 2 will look for modules at: %s'),
$this->data['generalConfig']['global_modulePath']
) . '</li>'
. '<li>' . sprintf(
t('Icinga Web 2 will save new configuration files using the mode "%s".'),
$this->data['generalConfig']['global_filemode']
) . '</li>'
. '<li>' . sprintf(
$this->data['preferencesType'] === 'ini' ? sprintf(
t('Preferences will be stored per user account in INI files at: %s'),
Config::resolvePath('preferences')
) : (
$this->data['preferencesType'] === 'db' ? t('Preferences will be stored using a database.') : (
t('Preferences will not be persisted across browser sessions.')
)
)
) . '</li>'
. '</ul>';
$type = $this->data['generalConfig']['logging_log'];
if ($type === 'none') {
$loggingHtml = '<p>' . t('Logging will be disabled.') . '</p>';
} else {
$level = $this->data['generalConfig']['logging_level'];
$loggingHtml = ''
. '<table>'
. '<tbody>'
. '<tr>'
. '<td><strong>' . t('Type', 'app.config.logging') . '</strong></td>'
. '<td>' . ($type === 'syslog' ? 'Syslog' : t('File', 'app.config.logging.type')) . '</td>'
. '</tr>'
. '<tr>'
. '<td><strong>' . t('Level', 'app.config.logging') . '</strong></td>'
. '<td>' . ($level === Logger::$levels[Logger::ERROR] ? t('Error', 'app.config.logging.level') : (
$level === Logger::$levels[Logger::WARNING] ? t('Warning', 'app.config.logging.level') : (
$level === Logger::$levels[Logger::INFO] ? t('Information', 'app.config.logging.level') : (
t('Debug', 'app.config.logging.level')
)
)
)) . '</td>'
. '</tr>'
. '<tr>'
. ($type === 'syslog' ? (
'<td><strong>' . t('Application Prefix') . '</strong></td>'
. '<td>' . $this->data['generalConfig']['logging_application'] . '</td>'
) : (
'<td><strong>' . t('Filepath') . '</strong></td>'
. '<td>' . $this->data['generalConfig']['logging_file'] . '</td>'
))
. '</tr>'
. '</tbody>'
. '</table>';
}
return $pageTitle . '<div class="topic">' . $generalTitle . $generalHtml . '</div>'
. '<div class="topic">' . $loggingTitle . $loggingHtml . '</div>';
} }
public function getReport() public function getReport()

View File

@ -56,7 +56,84 @@ class ResourceStep extends Step
public function getSummary() public function getSummary()
{ {
return ''; if (isset($this->data['dbResourceConfig']) && isset($this->data['ldapResourceConfig'])) {
$pageTitle = '<h2>' . t('Resources') . '</h2>';
} else {
$pageTitle = '<h2>' . t('Resource') . '</h2>';
}
if (isset($this->data['dbResourceConfig'])) {
$dbTitle = '<h3>' . t('Database') . '</h3>';
$dbHtml = ''
. '<table>'
. '<tbody>'
. '<tr>'
. '<td><strong>' . t('Resource Name') . '</strong></td>'
. '<td>' . $this->data['dbResourceConfig']['name'] . '</td>'
. '</tr>'
. '<tr>'
. '<td><strong>' . t('Database Type') . '</strong></td>'
. '<td>' . $this->data['dbResourceConfig']['db'] . '</td>'
. '</tr>'
. '<tr>'
. '<td><strong>' . t('Host') . '</strong></td>'
. '<td>' . $this->data['dbResourceConfig']['host'] . '</td>'
. '</tr>'
. '<tr>'
. '<td><strong>' . t('Port') . '</strong></td>'
. '<td>' . $this->data['dbResourceConfig']['port'] . '</td>'
. '</tr>'
. '<tr>'
. '<td><strong>' . t('Database Name') . '</strong></td>'
. '<td>' . $this->data['dbResourceConfig']['dbname'] . '</td>'
. '</tr>'
. '<tr>'
. '<td><strong>' . t('Username') . '</strong></td>'
. '<td>' . $this->data['dbResourceConfig']['username'] . '</td>'
. '</tr>'
. '<tr>'
. '<td><strong>' . t('Password') . '</strong></td>'
. '<td>' . str_repeat('*', strlen($this->data['dbResourceConfig']['password'])) . '</td>'
. '</tr>'
. '</tbody>'
. '</table>';
}
if (isset($this->data['ldapResourceConfig'])) {
$ldapTitle = '<h3>LDAP</h3>';
$ldapHtml = ''
. '<table>'
. '<tbody>'
. '<tr>'
. '<td><strong>' . t('Resource Name') . '</strong></td>'
. '<td>' . $this->data['ldapResourceConfig']['name'] . '</td>'
. '</tr>'
. '<tr>'
. '<td><strong>' . t('Host') . '</strong></td>'
. '<td>' . $this->data['ldapResourceConfig']['hostname'] . '</td>'
. '</tr>'
. '<tr>'
. '<td><strong>' . t('Port') . '</strong></td>'
. '<td>' . $this->data['ldapResourceConfig']['port'] . '</td>'
. '</tr>'
. '<tr>'
. '<td><strong>' . t('Root DN') . '</strong></td>'
. '<td>' . $this->data['ldapResourceConfig']['root_dn'] . '</td>'
. '</tr>'
. '<tr>'
. '<td><strong>' . t('Bind DN') . '</strong></td>'
. '<td>' . $this->data['ldapResourceConfig']['bind_dn'] . '</td>'
. '</tr>'
. '<tr>'
. '<td><strong>' . t('Bind Password') . '</strong></td>'
. '<td>' . str_repeat('*', strlen($this->data['ldapResourceConfig']['bind_pw'])) . '</td>'
. '</tr>'
. '</tbody>'
. '</table>';
}
return $pageTitle . (isset($dbTitle) ? '<div class="topic">' . $dbTitle . $dbHtml . '</div>' : '')
. (isset($ldapTitle) ? '<div class="topic">' . $ldapTitle . $ldapHtml . '</div>' : '');
} }
public function getReport() public function getReport()