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