Skip to content

Commit

Permalink
Add form as Page to InstallationController
Browse files Browse the repository at this point in the history
refs #6134
  • Loading branch information
majentsch committed May 28, 2014
1 parent ff9d35e commit 526ca70
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 37 deletions.
4 changes: 2 additions & 2 deletions application/controllers/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ protected function createWizard()
// t('Welcome') => 'Icinga\Form\Install\WelcomePage',
// t('Requirements') => 'Icinga\Form\Install\RequirementsPage',
// t('Authentication') => 'Icinga\Form\Install\AuthenticationPage',
// t('Administration') => 'Icinga\Form\Install\AdministrationPage',
t('Administration') => 'Icinga\Form\Install\AdministrationPage',
// t('Preferences') => 'Icinga\Form\Install\PreferencesPage',
t('Logging') => 'Icinga\Form\Install\LoggingPage',
// t('Logging') => 'Icinga\Form\Install\LoggingPage',
// t('Database Setup') => 'Icinga\Form\Install\DatabasePage',
// t('Summary') => 'Icinga\Form\Install\SummaryPage'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,97 @@
*/
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Form\Config;
namespace Icinga\Form\Install;

use Icinga\Web\Wizard\Page;
use Zend_Config;
use Icinga\Web\Form;
use Zend_Validate_Identical;

/**
* Form class for setting the application wide logging configuration
*/
class AdministratorForm extends Form
class AdministrationPage extends Page
{
private $authenticationMode = 'database';
/**
* Administration account is authenticated using a database
*
* Available users can be listed and a new user can be created.
*/
const AUTHENTICATION_MODE_DATABASE = 'database';

/**
* Administration account is authenticated using ldap
*
* All available users can be listed, a new user cannot be created.
*/
const AUTHENTICATION_MODE_LDAP = 'ldap';

/**
* Administration account is authenticated using an external authentication backend
*
* Available users can not be listed and users cannot be created.
*/
const AUTHENTICATION_MODE_EXTERNAL = 'external';

/**
* Defines where the administrative user is authenticated and whether a
* new user can be created.
*
* @var string
*/
private $authenticationMode = self::AUTHENTICATION_MODE_DATABASE;

/**
* The title of this wizard-page.
*
* @var string
*/
protected $title = '';

private $users = array('jdoe' => 'jdoe', 'foo' => 'foo', 'bar' => 'bar');
/**
* Contains all available users.
*
* @var array
*/
private $users = array();

public function setUsers(array $users)
/**
* Initialise this form.
*/
public function init()
{
$this->users = $users;
$this->setName('administration');
$this->title = t('Administration');
}

/**
* Create this logging configuration form
* Create this administration form.
*
* @see Form::create()
*/
public function create()
{
$this->setName('form_config_administrator');
$administratorConfig = $this->getConfig();
$config = $this->getConfig();

if (empty($users) && $this->authenticationMode === self::AUTHENTICATION_MODE_LDAP) {
$this->addErrorMessage(
t(
'No users available in the given LDAP backend, installation not possible.'
. ' Create a new user .'
)
);
return;
}
if ($this->authenticationMode === 'external') {
$this->addElement(
'text',
'external_administrator',
array(
'required' => true,
'label' => t('Administrator user name.'),
'helptext' => t('The name of the user that should get administrator privileges.'),
'value' => $administratorConfig->get('external_administrator', $_SERVER['REMOTE_USER'])
'helptext' => t('Give administration privileges to this user.'),
'value' => $config->get('external_administrator', $_SERVER['REMOTE_USER'])
)
);
} else {
Expand All @@ -74,25 +127,27 @@ public function create()
'internal_administrator_select_type',
array(
'required' => true,
'label' => t('Create a new user.'),
'helptext' => t('Do you want to create a new user as administrator?'),
'value' => 0
'disableHidden' => true,
'label' => t('Create User?'),
'helptext' => t('Do you want to give administration privileges to a new user or an existing one?')
)
);
$this->enableAutoSubmit(array('internal_administrator_select_type'));

if ($administratorConfig->get('internal_administrator_select_type', 0) === 0 && !(empty($this->users))) {
if ($this->getRequest()->getParam('internal_administrator_select_type', 0) === 0 && !(empty($this->users))) {
$this->addElement(
'select',
'internal_administrator_existing_username',
array(
'required' => true,
'label' => t('Administrator username'),
'helptext' => t('Choose the IcingaWeb administrator.'),
'value' => $administratorConfig->get('internal_administrator_existing', key($this->users)),
'label' => t('Username'),
'helptext' => t('Give administration privileges to the selected user.'),
'value' => $config->get('internal_administrator_existing', key($this->users)),
'multiOptions' => $this->users
)
);
} else {

if (empty($users)) {
$this->addErrorMessage(
t('No users available, you need to create a new one.')
Expand All @@ -106,9 +161,9 @@ public function create()
'internal_administrator_new_username',
array(
'required' => true,
'label' => t('Administrator username'),
'label' => t('Username'),
'helptext' => t('Create a new IcingaWeb administrator.'),
'value' => $administratorConfig->get('internal_administrator_new', 0)
'value' => $config->get('internal_administrator_new', '')
)
);

Expand All @@ -119,7 +174,7 @@ public function create()
'required' => true,
'label' => t('Password'),
'helptext' => t('Provide the password of the new administrator.'),
'value' => $administratorConfig->get('internal_administrator_new_password', ''),
'value' => $config->get('internal_administrator_new_password', ''),
'validators' => array(array('NotEmpty'))
)
);
Expand All @@ -131,26 +186,21 @@ public function create()
'required' => true,
'label' => t('Confirm Password'),
'helptext' => t('Confirm the password of the new administrator.'),
'value' => $administratorConfig->get('internal_administrator_new_confirm_password', ''),
'value' => $config->get('internal_administrator_new_confirm_password', ''),
'validators' => array(new Zend_Validate_Identical('internal_administrator_new_password'))
)
);
}
}

$this->addElement(
'button',
'btn_submit',
array(
'type' => 'submit',
'escape' => false,
'value' => '1',
'label' => $this->getView()->icon('save.png', 'Save Changes')
. ' Save changes',
)
);
}

/**
* Return if the given set of data is valid.
*
* @param array $data The form data.
*
* @return bool If the data is valid.
*/
public function isValid($data) {
foreach ($this->getElements() as $key => $element) {
// Initialize all empty elements with their default values.
Expand All @@ -175,7 +225,10 @@ public function getConfig()
$cfg['external_administrator'] = $values['external_administrator'];
}
} else {
if ($values['internal_administrator_select_type']) {
if (
array_key_exists('internal_administrator_select_type', $values)
&& $values['internal_administrator_select_type']
) {
if (array_key_exists('internal_administrator_existing_username', $values)) {
$cfg['username'] = $values['internal_administrator_existing_username'];
}
Expand Down

0 comments on commit 526ca70

Please sign in to comment.