2017-07-03 07:04:31 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Web\Tabs;
|
|
|
|
|
|
|
|
use Icinga\Authentication\Auth;
|
|
|
|
use Icinga\Module\Director\Objects\IcingaObject;
|
|
|
|
use ipl\Translation\TranslationHelper;
|
2017-07-20 10:19:32 +02:00
|
|
|
use ipl\Web\Widget\Tabs;
|
2017-07-03 07:04:31 +02:00
|
|
|
|
|
|
|
class ObjectTabs extends Tabs
|
|
|
|
{
|
|
|
|
use TranslationHelper;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $type;
|
|
|
|
|
|
|
|
/** @var Auth */
|
|
|
|
private $auth;
|
|
|
|
|
|
|
|
/** @var IcingaObject $object */
|
|
|
|
private $object;
|
|
|
|
|
|
|
|
private $allowedExternals = array(
|
|
|
|
'apiuser',
|
|
|
|
'endpoint'
|
|
|
|
);
|
|
|
|
|
|
|
|
public function __construct($type, Auth $auth, IcingaObject $object = null)
|
|
|
|
{
|
|
|
|
$this->type = $type;
|
|
|
|
$this->auth = $auth;
|
|
|
|
$this->object = $object;
|
|
|
|
// We are not a BaseElement, not yet
|
|
|
|
$this->assemble();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function assemble()
|
|
|
|
{
|
|
|
|
if (null === $this->object) {
|
|
|
|
$this->addTabsForNewObject();
|
|
|
|
} else {
|
|
|
|
$this->addTabsForExistingObject();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function addTabsForNewObject()
|
|
|
|
{
|
|
|
|
$type = $this->type;
|
|
|
|
$this->add('add', array(
|
|
|
|
'url' => sprintf('director/%s/add', $type),
|
|
|
|
'label' => sprintf($this->translate('Add %s'), ucfirst($type)),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function addTabsForExistingObject()
|
|
|
|
{
|
|
|
|
$type = $this->type;
|
|
|
|
$auth = $this->auth;
|
|
|
|
$object = $this->object;
|
|
|
|
$params = $object->getUrlParams();
|
|
|
|
|
|
|
|
if (! $object->isExternal()
|
|
|
|
|| in_array($object->getShortTableName(), $this->allowedExternals)
|
|
|
|
) {
|
|
|
|
$this->add('modify', array(
|
|
|
|
'url' => sprintf('director/%s', $type),
|
|
|
|
'urlParams' => $params,
|
|
|
|
'label' => $this->translate(ucfirst($type))
|
|
|
|
));
|
|
|
|
}
|
2017-07-29 00:13:20 +02:00
|
|
|
if ($object->getShortTableName() === 'host') {
|
|
|
|
$this->add('services', [
|
|
|
|
'url' => 'director/host/services',
|
|
|
|
'urlParams' => $params,
|
|
|
|
'label' => $this->translate('Services')
|
|
|
|
]);
|
|
|
|
}
|
2017-07-03 07:04:31 +02:00
|
|
|
|
|
|
|
if ($auth->hasPermission('director/showconfig')) {
|
|
|
|
$this->add('render', array(
|
|
|
|
'url' => sprintf('director/%s/render', $type),
|
|
|
|
'urlParams' => $params,
|
|
|
|
'label' => $this->translate('Preview'),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($auth->hasPermission('director/audit')) {
|
|
|
|
$this->add('history', array(
|
|
|
|
'url' => sprintf('director/%s/history', $type),
|
|
|
|
'urlParams' => $params,
|
|
|
|
'label' => $this->translate('History')
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($auth->hasPermission('director/admin') && $this->hasFields()) {
|
|
|
|
$this->add('fields', array(
|
|
|
|
'url' => sprintf('director/%s/fields', $type),
|
|
|
|
'urlParams' => $params,
|
|
|
|
'label' => $this->translate('Fields')
|
|
|
|
));
|
|
|
|
}
|
2017-07-11 08:33:03 +02:00
|
|
|
|
2017-07-11 14:05:49 +02:00
|
|
|
// TODO: remove table check once we resolve all group types
|
|
|
|
if ($object->isGroup() && $object->getShortTableName() === 'hostgroup') {
|
2017-07-11 08:33:03 +02:00
|
|
|
$this->add('membership', [
|
|
|
|
'url' => sprintf('director/%s/membership', $type),
|
|
|
|
'urlParams' => $params,
|
|
|
|
'label' => $this->translate('Members')
|
|
|
|
]);
|
|
|
|
}
|
2017-07-13 07:52:48 +02:00
|
|
|
|
2017-07-28 16:50:15 +02:00
|
|
|
if ($object->supportsRanges()) {
|
|
|
|
$this->add('ranges', [
|
|
|
|
'url' => 'director/timeperiod/ranges',
|
2017-07-28 23:20:58 +02:00
|
|
|
'urlParams' => $params,
|
2017-07-28 16:50:15 +02:00
|
|
|
'label' => $this->translate('Ranges')
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-07-13 07:52:48 +02:00
|
|
|
if ($object->getShortTableName() === 'endpoint') {
|
|
|
|
$this->add('inspect', [
|
|
|
|
'url' => 'director/inspect/types',
|
|
|
|
'urlParams' => ['endpoint' => $object->getObjectName()],
|
|
|
|
'label' => $this->translate('Inspect')
|
|
|
|
]);
|
|
|
|
}
|
2017-07-28 23:20:58 +02:00
|
|
|
|
|
|
|
if ($object->getShortTableName() === 'host') {
|
2017-07-29 00:13:20 +02:00
|
|
|
$this->add('agent', [
|
2017-07-28 23:20:58 +02:00
|
|
|
'url' => 'director/host/agent',
|
|
|
|
'urlParams' => $params,
|
|
|
|
'label' => $this->translate('Agent')
|
|
|
|
]);
|
|
|
|
}
|
2017-07-03 07:04:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function hasFields()
|
|
|
|
{
|
|
|
|
if (! ($object = $this->object)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $object->hasBeenLoadedFromDb()
|
|
|
|
&& $object->supportsFields()
|
|
|
|
&& ($object->isTemplate() || $this->type === 'command');
|
|
|
|
}
|
|
|
|
}
|