2014-07-25 14:51:42 +02:00
|
|
|
<?php
|
2016-02-08 15:41:00 +01:00
|
|
|
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
2014-07-25 14:51:42 +02:00
|
|
|
|
2015-06-02 09:58:57 +02:00
|
|
|
namespace Icinga\Forms\Config\UserBackend;
|
2014-07-25 14:51:42 +02:00
|
|
|
|
|
|
|
use Zend_Validate_Callback;
|
2014-08-29 15:16:13 +02:00
|
|
|
use Icinga\Web\Form;
|
2014-07-25 14:51:42 +02:00
|
|
|
|
2014-08-22 12:04:14 +02:00
|
|
|
/**
|
2015-06-02 09:58:57 +02:00
|
|
|
* Form class for adding/modifying user backends of type "external"
|
2014-08-22 12:04:14 +02:00
|
|
|
*/
|
2015-01-27 09:49:36 +01:00
|
|
|
class ExternalBackendForm extends Form
|
2014-07-25 14:51:42 +02:00
|
|
|
{
|
2014-08-22 12:15:02 +02:00
|
|
|
/**
|
|
|
|
* Initialize this form
|
|
|
|
*/
|
|
|
|
public function init()
|
|
|
|
{
|
2015-01-27 09:49:36 +01:00
|
|
|
$this->setName('form_config_authbackend_external');
|
2014-08-22 12:15:02 +02:00
|
|
|
}
|
|
|
|
|
2014-08-22 12:04:14 +02:00
|
|
|
/**
|
|
|
|
* @see Form::createElements()
|
|
|
|
*/
|
2014-07-25 14:51:42 +02:00
|
|
|
public function createElements(array $formData)
|
|
|
|
{
|
2014-09-03 12:21:31 +02:00
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'name',
|
|
|
|
array(
|
|
|
|
'required' => true,
|
2015-01-19 11:26:23 +01:00
|
|
|
'label' => $this->translate('Backend Name'),
|
|
|
|
'description' => $this->translate(
|
2014-10-21 16:15:04 +02:00
|
|
|
'The name of this authentication provider that is used to differentiate it from others'
|
2014-07-25 14:51:42 +02:00
|
|
|
)
|
2014-09-03 12:21:31 +02:00
|
|
|
)
|
|
|
|
);
|
2015-02-12 08:54:56 +01:00
|
|
|
$callbackValidator = new Zend_Validate_Callback(function ($value) {
|
|
|
|
return @preg_match($value, '') !== false;
|
|
|
|
});
|
|
|
|
$callbackValidator->setMessage(
|
2015-03-06 09:49:15 +01:00
|
|
|
$this->translate('"%value%" is not a valid regular expression.'),
|
2015-02-12 08:54:56 +01:00
|
|
|
Zend_Validate_Callback::INVALID_VALUE
|
|
|
|
);
|
2014-09-03 12:21:31 +02:00
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'strip_username_regexp',
|
|
|
|
array(
|
2015-01-19 11:26:23 +01:00
|
|
|
'label' => $this->translate('Filter Pattern'),
|
|
|
|
'description' => $this->translate(
|
2015-03-06 09:49:15 +01:00
|
|
|
'The filter to use to strip specific parts off from usernames.'
|
|
|
|
. ' Leave empty if you do not want to strip off anything.'
|
2014-12-29 15:56:32 +01:00
|
|
|
),
|
2015-03-06 09:49:15 +01:00
|
|
|
'requirement' => $this->translate('The filter pattern must be a valid regular expression.'),
|
2015-02-12 08:54:56 +01:00
|
|
|
'validators' => array($callbackValidator)
|
2014-07-25 14:51:42 +02:00
|
|
|
)
|
|
|
|
);
|
2014-09-03 12:21:31 +02:00
|
|
|
$this->addElement(
|
|
|
|
'hidden',
|
|
|
|
'backend',
|
|
|
|
array(
|
2014-11-18 15:06:36 +01:00
|
|
|
'disabled' => true,
|
2015-01-27 09:49:36 +01:00
|
|
|
'value' => 'external'
|
2014-09-03 12:21:31 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this;
|
2014-07-25 14:51:42 +02:00
|
|
|
}
|
2014-08-22 12:18:26 +02:00
|
|
|
|
|
|
|
/**
|
2014-08-29 15:16:13 +02:00
|
|
|
* Validate the configuration by creating a backend and requesting the user count
|
2014-08-22 12:18:26 +02:00
|
|
|
*
|
2015-01-27 09:49:36 +01:00
|
|
|
* Returns always true as backends of type "external" are just "passive" backends.
|
2014-08-22 12:18:26 +02:00
|
|
|
*
|
2014-08-29 15:16:13 +02:00
|
|
|
* @param Form $form The form to fetch the configuration values from
|
|
|
|
*
|
|
|
|
* @return bool Whether validation succeeded or not
|
2014-08-22 12:18:26 +02:00
|
|
|
*/
|
2015-06-02 09:58:57 +02:00
|
|
|
public static function isValidUserBackend(Form $form)
|
2014-08-22 12:18:26 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2014-07-25 14:51:42 +02:00
|
|
|
}
|