-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refractor resource forms and add AuthenticationPage
refs #6141
- Loading branch information
Showing
6 changed files
with
633 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.