2017-02-08 10:08:29 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Businessprocess\Web\Form;
|
|
|
|
|
|
|
|
|
|
use Icinga\Application\Config;
|
2021-11-12 06:07:40 -05:00
|
|
|
use Icinga\Application\Icinga;
|
2017-02-08 10:08:29 -05:00
|
|
|
use Icinga\Authentication\Auth;
|
|
|
|
|
use Icinga\Module\Businessprocess\BpConfig;
|
2023-07-25 06:58:16 -04:00
|
|
|
use Icinga\Module\Businessprocess\Storage\Storage;
|
|
|
|
|
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
|
|
|
|
use Icinga\Web\Session\SessionNamespace;
|
|
|
|
|
use ipl\Sql\Connection as IcingaDbConnection;
|
2017-02-08 10:08:29 -05:00
|
|
|
|
|
|
|
|
abstract class BpConfigBaseForm extends QuickForm
|
|
|
|
|
{
|
2023-07-25 06:58:16 -04:00
|
|
|
/** @var Storage */
|
2017-02-08 10:08:29 -05:00
|
|
|
protected $storage;
|
|
|
|
|
|
|
|
|
|
/** @var BpConfig */
|
2023-07-25 06:58:16 -04:00
|
|
|
protected $bp;
|
|
|
|
|
|
|
|
|
|
/** @var MonitoringBackend|IcingaDbConnection*/
|
|
|
|
|
protected $backend;
|
|
|
|
|
|
|
|
|
|
/** @var SessionNamespace */
|
|
|
|
|
protected $session;
|
2017-02-08 10:08:29 -05:00
|
|
|
|
|
|
|
|
protected function listAvailableBackends()
|
|
|
|
|
{
|
2021-11-12 06:07:40 -05:00
|
|
|
$keys = [];
|
|
|
|
|
$moduleManager = Icinga::app()->getModuleManager();
|
|
|
|
|
if ($moduleManager->hasEnabled('monitoring')) {
|
|
|
|
|
$keys = array_keys(Config::module('monitoring', 'backends')->toArray());
|
|
|
|
|
$keys = array_combine($keys, $keys);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-27 19:08:24 -04:00
|
|
|
return $keys;
|
2017-02-08 10:08:29 -05:00
|
|
|
}
|
|
|
|
|
|
2023-07-25 06:58:16 -04:00
|
|
|
/**
|
|
|
|
|
* Set the storage to use
|
|
|
|
|
*
|
|
|
|
|
* @param Storage $storage
|
|
|
|
|
*
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
|
|
|
|
public function setStorage(Storage $storage): self
|
2017-02-08 10:08:29 -05:00
|
|
|
{
|
|
|
|
|
$this->storage = $storage;
|
2023-07-25 06:58:16 -04:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the config to use
|
|
|
|
|
*
|
|
|
|
|
* @param BpConfig $config
|
|
|
|
|
*
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
|
|
|
|
public function setProcess(BpConfig $config): self
|
|
|
|
|
{
|
|
|
|
|
$this->bp = $config;
|
|
|
|
|
$this->setBackend($config->getBackend());
|
|
|
|
|
|
2017-02-08 10:08:29 -05:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-25 06:58:16 -04:00
|
|
|
/**
|
|
|
|
|
* Set the backend to use
|
|
|
|
|
*
|
|
|
|
|
* @param MonitoringBackend|IcingaDbConnection $backend
|
|
|
|
|
*
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
|
|
|
|
public function setBackend($backend): self
|
2017-02-08 10:08:29 -05:00
|
|
|
{
|
2023-07-25 06:58:16 -04:00
|
|
|
$this->backend = $backend;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the session namespace to use
|
|
|
|
|
*
|
|
|
|
|
* @param SessionNamespace $session
|
|
|
|
|
*
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
|
|
|
|
public function setSession(SessionNamespace $session): self
|
|
|
|
|
{
|
|
|
|
|
$this->session = $session;
|
|
|
|
|
|
2017-02-08 10:08:29 -05:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function prepareMetadata(BpConfig $config)
|
|
|
|
|
{
|
|
|
|
|
$meta = $config->getMetadata();
|
|
|
|
|
$auth = Auth::getInstance();
|
|
|
|
|
$meta->set('Owner', $auth->getUser()->getUsername());
|
2019-02-18 07:43:06 -05:00
|
|
|
|
|
|
|
|
if ($auth->hasPermission('businessprocess/showall')) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-08 10:08:29 -05:00
|
|
|
$prefixes = $auth->getRestrictions('businessprocess/prefix');
|
|
|
|
|
if (! empty($prefixes) && ! $meta->nameIsPrefixedWithOneOf($prefixes)) {
|
|
|
|
|
if (count($prefixes) === 1) {
|
|
|
|
|
$this->getElement('name')->addError(sprintf(
|
|
|
|
|
$this->translate('Please prefix the name with "%s"'),
|
|
|
|
|
current($prefixes)
|
|
|
|
|
));
|
|
|
|
|
} else {
|
|
|
|
|
$this->getElement('name')->addError(sprintf(
|
|
|
|
|
$this->translate('Please prefix the name with one of "%s"'),
|
|
|
|
|
implode('", "', $prefixes)
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-07-25 07:05:38 -04:00
|
|
|
|
|
|
|
|
protected function setPreferredDecorators()
|
|
|
|
|
{
|
|
|
|
|
parent::setPreferredDecorators();
|
|
|
|
|
|
|
|
|
|
$this->setAttrib('class', $this->getAttrib('class') . ' bp-form');
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
2017-02-08 10:08:29 -05:00
|
|
|
}
|