Skip to content

Commit

Permalink
Add password and integer validation
Browse files Browse the repository at this point in the history
refs #3761
  • Loading branch information
Johannes Meyer committed Oct 9, 2013
1 parent 62ebe20 commit 5e8e210
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 11 deletions.
4 changes: 2 additions & 2 deletions install/application/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private function getDatabaseDetails($session)
* Validate the given database details
*
* @return bool Whether the details are valid
* @todo Validate db connection and auth
* @todo Validate db connection
*/
private function validateDatabaseDetails($session)
{
Expand Down Expand Up @@ -170,7 +170,7 @@ private function getAuthenticationDetails($session)
* Validate the given authentication details
*
* @return bool Whether the details are valid
* @todo Validate auth ... and ldap?
* @todo Validate ldap
*/
private function validateAuthenticationDetails($session)
{
Expand Down
11 changes: 6 additions & 5 deletions install/application/forms/AuthConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

namespace Icinga\Installer\Pages;

use \Icinga\Installer\Validators\PasswordValidator;

/**
* Wizard-page that prompts the user to configure the authentication
*/
Expand Down Expand Up @@ -108,7 +110,6 @@ public function create()
'allowEmpty' => false
)
);

$this->addElement(
'text',
'auth_ldap_root_dn',
Expand All @@ -118,7 +119,6 @@ public function create()
'allowEmpty' => false
)
);

$this->addElement(
'text',
'auth_ldap_bind_dn',
Expand All @@ -128,7 +128,6 @@ public function create()
'allowEmpty' => false
)
);

$this->addElement(
'text',
'auth_ldap_bind_pw',
Expand All @@ -138,7 +137,6 @@ public function create()
'allowEmpty' => false
)
);

$this->addElement(
'text',
'auth_ldap_user_class',
Expand All @@ -148,7 +146,6 @@ public function create()
'allowEmpty' => false
)
);

$this->addElement(
'text',
'auth_ldap_user_name_attributes',
Expand All @@ -161,6 +158,10 @@ public function create()
}
}

$passwordValidator = new PasswordValidator();
$passwordValidator->setCounterpart('auth_password2');
$this->getElement('auth_password')->addValidator($passwordValidator);

$this->setSubmitLabel('Continue');
}

Expand Down
3 changes: 2 additions & 1 deletion install/application/forms/BackendConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ public function create()
array(
'label' => 'Port',
'helptext' => 'The port of this database. (Leave blank to use the default.)',
'allowEmpty' => true
'allowEmpty' => true,
'validators' => array('int')
)
);
$this->addElement(
Expand Down
4 changes: 2 additions & 2 deletions install/application/forms/ConfirmationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ public function create()
'<br />',
array(
'Backend name: ' . $session->backendDetails['backend_name'],
'Resource to use: ' . (in_array(intval($session->backendDetails['backend_selection']), $resources) ?
'Resource to use: ' . (array_key_exists($session->backendDetails['backend_selection'], $resources) ?
$resources[$session->backendDetails['backend_selection']] :
'Other existing database')
)
)
);

if (!in_array(intval($session->backendDetails['backend_selection']), $resources)) {
if (!array_key_exists($session->backendDetails['backend_selection'], $resources)) {
$this->addNote('Database store', 4);

$this->addNote(
Expand Down
9 changes: 8 additions & 1 deletion install/application/forms/DbConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

namespace Icinga\Installer\Pages;

use \Icinga\Installer\Validators\PasswordValidator;

/**
* Wizard-Page that prompts the user for database configuration details
*/
Expand Down Expand Up @@ -78,7 +80,8 @@ public function create()
array(
'label' => 'Port',
'helptext' => 'The port of this database. (Leave blank to use the default.)',
'allowEmpty' => true
'allowEmpty' => true,
'validators' => array('int')
)
);
$this->addElement(
Expand Down Expand Up @@ -124,6 +127,10 @@ public function create()
)
);

$passwordValidator = new PasswordValidator();
$passwordValidator->setCounterpart('db_password2');
$this->getElement('db_password')->addValidator($passwordValidator);

$this->setSubmitLabel('Continue');
}

Expand Down
1 change: 1 addition & 0 deletions install/application/forms/WizardForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
require_once 'Zend/Form/Element/Xhtml.php';
require_once 'Zend/Form/Element/Submit.php';
require_once 'Zend/Form/Decorator/Abstract.php';
require_once realpath(__DIR__ . '/../validators/PasswordValidator.php');
require_once realpath(__DIR__ . '/../../../library/Icinga/Web/Form.php');
require_once realpath(__DIR__ . '/../../../library/Icinga/Web/Form/Element/Note.php');
require_once realpath(__DIR__ . '/../../../library/Icinga/Web/Form/Decorator/HelpText.php');
Expand Down
86 changes: 86 additions & 0 deletions install/application/validators/PasswordValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Installer\Validators;

require_once 'Zend/Validate/Abstract.php';

use \Zend_Validate_Abstract;

/**
* Validator that compares the given value with another one
*/
class PasswordValidator extends Zend_Validate_Abstract
{
/**
* The messages to write on different error states
*
* @var array
* @see Zend_Validate_Abstract::$_messageTemplates
*/
// @codingStandardsIgnoreStart
protected $_messageTemplates = array(
'NOT_EQUAL' => 'The two passwords do not match'
);
// @codingStandardsIgnoreEnd

/**
* The name of the counterpart element
*
* @var string
*/
private $counterpartInput;

/**
* Set the name of the counterpart element
*
* @param string $name The name of the counterpart element
*/
public function setCounterpart($name)
{
$this->counterpartInput = $name;
}

/**
* Check whether the given value is equal to its counterpart element
*
* @param string $value The submitted value
* @param mixed $context The context of the form
* @return bool Whether the submitted value is valid or not
* @see Zend_Validate_Abstract::isValid()
*/
public function isValid($value, $context = null)
{
$this->_setValue($value);
if (!array_key_exists($this->counterpartInput, $context) || $value !== $context[$this->counterpartInput]) {
$this->_error('NOT_EQUAL');
return false;
}
return true;
}
}

0 comments on commit 5e8e210

Please sign in to comment.