Skip to content

Commit

Permalink
Refractor resource forms and add AuthenticationPage
Browse files Browse the repository at this point in the history
refs #6141
  • Loading branch information
majentsch committed May 28, 2014
1 parent 288c97b commit 4f3acfc
Show file tree
Hide file tree
Showing 6 changed files with 633 additions and 147 deletions.
2 changes: 1 addition & 1 deletion application/controllers/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function createWizard()
array(
// t('Welcome') => 'Icinga\Form\Install\WelcomePage',
// t('Requirements') => 'Icinga\Form\Install\RequirementsPage',
// t('Authentication') => 'Icinga\Form\Install\AuthenticationPage',
t('Authentication') => 'Icinga\Form\Install\AuthenticationPage',
t('Administration') => 'Icinga\Form\Install\AdministrationPage',
// t('Preferences') => 'Icinga\Form\Install\PreferencesPage',
t('Logging') => 'Icinga\Form\Install\LoggingPage',
Expand Down
163 changes: 163 additions & 0 deletions application/forms/Config/Resource/DbResourceForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?php
/**
* Created by PhpStorm.
* User: mjentsch
* Date: 19.05.14
* Time: 17:13
*/

namespace Icinga\Form\Config\Resource;

use Exception;
use Icinga\Data\ResourceFactory;
use Icinga\Web\Form\Element\Number;
use Icinga\Web\Form;
use Zend_Config;

/**
* Contains the properties needed to create a basic SQL-Database resource.
*/
class DbResourceForm extends Form {

private $resource = null;

/**
* Set the resource configuration to edit.
*
* @param Zend_Config $resource The config to set
*/
public function setResource(Zend_Config $resource)
{
$this->resource = $resource;
}

public function getResource()
{
return $this->resource;
}

public function getConfig()
{
$values = $this->getValues();
$result = array();
foreach ($values as $key => $value) {
$configKey = explode('_', $key, 3);
if (count($configKey) === 3) {
$result[$configKey[2]] = $value;
}
}
return new Zend_Config($result);
}

public function create() {
$this->addElement(
'select',
'resource_db_db',
array(
'required' => true,
'label' => t('Database Type'),
'helptext' => t('The type of SQL database you want to create.'),
'value' => $this->getResource()->get('db', 'mysql'),
'multiOptions' => array(
'mysql' => 'MySQL',
'pgsql' => 'PostgreSQL'
//'oracle' => 'Oracle'
)
)
);

$this->addElement(
'text',
'resource_db_host',
array (
'required' => true,
'label' => t('Host'),
'helptext' => t('The hostname of the database.'),
'value' => $this->getResource()->get('host', 'localhost')
)
);

$this->addElement(
new Number(
array(
'name' => 'resource_db_port',
'required' => true,
'label' => t('Port'),
'helptext' => t('The port to use.'),
'value' => $this->getResource()->get('port', 3306)
)
)
);

$this->addElement(
'text',
'resource_db_dbname',
array(
'required' => true,
'label' => t('Database Name'),
'helptext' => t('The name of the database to use'),
'value' => $this->getResource()->get('dbname', '')
)
);

$this->addElement(
'text',
'resource_db_username',
array (
'required' => true,
'label' => t('Username'),
'helptext' => t('The user name to use for authentication.'),
'value' => $this->getResource()->get('username', '')
)
);

$this->addElement(
'password',
'resource_db_password',
array(
'required' => true,
'renderPassword' => true,
'label' => t('Password'),
'helptext' => t('The password to use for authentication'),
'value' => $this->getResource()->get('password', '')
)
);
}

/**
* Test if this is a valid resource.
*
* @return bool
*/
public function isValidResource()
{
try {
$config = $this->getConfig();
/*
* It should be possible to run icingaweb without the pgsql or mysql extension or Zend-Pdo-Classes,
* in case they aren't actually used. When the user tries to create a resource that depends on an
* uninstalled extension, an error should be displayed.
*/
if ($config->db === 'mysql' && !ResourceFactory::mysqlAvailable()) {
$this->addErrorMessage(
t('You need to install the php extension "mysql" and the ' .
'Zend_Pdo_Mysql classes to use MySQL database resources.')
);
return false;
}
if ($config->db === 'pgsql' && !ResourceFactory::pgsqlAvailable()) {
$this->addErrorMessage(
t('You need to install the php extension "pgsql" and the ' .
'Zend_Pdo_Pgsql classes to use PostgreSQL database resources.')
);
return false;
}

$resource = ResourceFactory::createResource($config);
$resource->getConnection()->getConnection();
} catch (Exception $e) {
$this->addErrorMessage(t('Connectivity validation failed, connection to the given resource not possible.'));
return false;
}
}
}
115 changes: 115 additions & 0 deletions application/forms/Config/Resource/LdapResourceForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php
/**
* Created by PhpStorm.
* User: mjentsch
* Date: 19.05.14
* Time: 17:22
*/

namespace Icinga\Form\Config\Resource;

use Exception;
use Icinga\Web\Form;
use Zend_Config;

/**
* Contains the properties needed to create a basic LDAP resource.
*/
class LdapResourceForm extends Form {

private $resource = null;

/**
* Set the resource configuration to edit.
*
* @param Zend_Config $resource The config to set
*/
public function setResource(Zend_Config $resource)
{
$this->resource = $resource;
}

public function getResource()
{
return $this->resource;
}

public function getConfig()
{
$values = $this->getValues();
$result = array();
foreach ($values as $key => $value) {
$configKey = explode('_', $key, 3);
if (count($configKey) === 3) {
$result[$configKey[2]] = $value;
}
}
return new Zend_Config($result);
}

public function create() {
$this->addElement(
'text',
'resource_ldap_hostname',
array(
'required' => true,
'allowEmpty' => false,
'label' => t('Host'),
'helptext' => t('The hostname or address of the LDAP server to use for authentication'),
'value' => $this->getResource()->get('hostname', 'localhost')
)
);

$this->addElement(
'text',
'resource_ldap_root_dn',
array(
'required' => true,
'label' => t('Root DN'),
'helptext' => t('The path where users can be found on the ldap server'),
'value' => $this->getResource()->get('root_dn', 'ou=people,dc=icinga,dc=org')
)
);

$this->addElement(
'text',
'resource_ldap_bind_dn',
array(
'required' => true,
'label' => t('Bind DN'),
'helptext' => t('The user dn to use for querying the ldap server'),
'value' => $this->getResource()->get('bind_dn', 'cn=admin,cn=config')
)
);

$this->addElement(
'password',
'resource_ldap_bind_pw',
array(
'required' => true,
'renderPassword' => true,
'label' => t('Bind Password'),
'helptext' => t('The password to use for querying the ldap server'),
'value' => $this->getResource()->get('bind_pw', '')
)
);
}

/**
* Test if this is a valid resource.
*
* @return bool
*/
public function isValidResource()
{
$config = $this->getConfig();
try {
$resource = ResourceFactory::createResource($config);
$resource->connect();
} catch (Exception $e) {
$this->addErrorMessage(t('Connectivity validation failed, connection to the given resource not possible.'));
return false;
}
return true;
}
}

0 comments on commit 4f3acfc

Please sign in to comment.