1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
<?php
namespace Icinga\Module\Director\Web\Tabs;
use Icinga\Authentication\Auth;
use Icinga\Module\Director\Objects\IcingaObject;
use gipfl\Translation\TranslationHelper;
use gipfl\IcingaWeb2\Widget\Tabs;
class ObjectTabs extends Tabs
{
use TranslationHelper;
/** @var string */
private $type;
/** @var Auth */
private $auth;
/** @var IcingaObject $object */
private $object;
private $allowedExternals = [
'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))
));
}
if ($object->getShortTableName() === 'host') {
$this->add('services', [
'url' => 'director/host/services',
'urlParams' => $params,
'label' => $this->translate('Services')
]);
}
if ($auth->hasPermission('director/showconfig')) {
if ($object->getShortTableName() !== 'service'
|| $object->get('service_set_id') === null
) {
$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')
));
}
// TODO: remove table check once we resolve all group types
if ($object->isGroup() &&
($object->getShortTableName() === 'hostgroup' || $object->getShortTableName() === 'servicegroup')
) {
$this->add('membership', [
'url' => sprintf('director/%s/membership', $type),
'urlParams' => $params,
'label' => $this->translate('Members')
]);
}
if ($object->supportsRanges()) {
$this->add('ranges', [
'url' => "director/${type}/ranges",
'urlParams' => $params,
'label' => $this->translate('Ranges')
]);
}
if ($object->getShortTableName() === 'endpoint'
&& $object->get('apiuser_id')
) {
$this->add('inspect', [
'url' => 'director/inspect/types',
'urlParams' => ['endpoint' => $object->getObjectName()],
'label' => $this->translate('Inspect')
]);
$this->add('packages', [
'url' => 'director/inspect/packages',
'urlParams' => ['endpoint' => $object->getObjectName()],
'label' => $this->translate('Packages')
]);
}
if ($object->getShortTableName() === 'host' && $auth->hasPermission('director/hosts')) {
$this->add('agent', [
'url' => 'director/host/agent',
'urlParams' => $params,
'label' => $this->translate('Agent')
]);
}
}
protected function hasFields()
{
if (! ($object = $this->object)) {
return false;
}
return $object->hasBeenLoadedFromDb()
&& $object->supportsFields()
&& ($object->isTemplate() || $this->type === 'command');
}
}
|