summaryrefslogtreecommitdiffstats
path: root/library/Director/Web/Tabs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:43:12 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:43:12 +0000
commitcd989f9c3aff968e19a3aeabc4eb9085787a6673 (patch)
treefbff2135e7013f196b891bbde54618eb050e4aaf /library/Director/Web/Tabs
parentInitial commit. (diff)
downloadicingaweb2-module-director-cd989f9c3aff968e19a3aeabc4eb9085787a6673.tar.xz
icingaweb2-module-director-cd989f9c3aff968e19a3aeabc4eb9085787a6673.zip
Adding upstream version 1.10.2.upstream/1.10.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Director/Web/Tabs')
-rw-r--r--library/Director/Web/Tabs/DataTabs.php34
-rw-r--r--library/Director/Web/Tabs/ImportTabs.php30
-rw-r--r--library/Director/Web/Tabs/ImportsourceTabs.php58
-rw-r--r--library/Director/Web/Tabs/InfraTabs.php49
-rw-r--r--library/Director/Web/Tabs/MainTabs.php85
-rw-r--r--library/Director/Web/Tabs/ObjectTabs.php160
-rw-r--r--library/Director/Web/Tabs/ObjectsTabs.php85
-rw-r--r--library/Director/Web/Tabs/SyncRuleTabs.php54
8 files changed, 555 insertions, 0 deletions
diff --git a/library/Director/Web/Tabs/DataTabs.php b/library/Director/Web/Tabs/DataTabs.php
new file mode 100644
index 0000000..ac29310
--- /dev/null
+++ b/library/Director/Web/Tabs/DataTabs.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Icinga\Module\Director\Web\Tabs;
+
+use gipfl\Translation\TranslationHelper;
+use gipfl\IcingaWeb2\Widget\Tabs;
+
+class DataTabs extends Tabs
+{
+ use TranslationHelper;
+
+ public function __construct()
+ {
+ // We are not a BaseElement, not yet
+ $this->assemble();
+ }
+
+ protected function assemble()
+ {
+ $this->add('datafield', [
+ 'label' => $this->translate('Data fields'),
+ 'url' => 'director/data/fields'
+ ])->add('datafieldcategory', [
+ 'label' => $this->translate('Data field categories'),
+ 'url' => 'director/data/fieldcategories'
+ ])->add('datalist', [
+ 'label' => $this->translate('Data lists'),
+ 'url' => 'director/data/lists'
+ ])->add('customvars', [
+ 'label' => $this->translate('Custom Variables'),
+ 'url' => 'director/data/vars'
+ ]);
+ }
+}
diff --git a/library/Director/Web/Tabs/ImportTabs.php b/library/Director/Web/Tabs/ImportTabs.php
new file mode 100644
index 0000000..e6c6807
--- /dev/null
+++ b/library/Director/Web/Tabs/ImportTabs.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Icinga\Module\Director\Web\Tabs;
+
+use gipfl\Translation\TranslationHelper;
+use gipfl\IcingaWeb2\Widget\Tabs;
+
+class ImportTabs extends Tabs
+{
+ use TranslationHelper;
+
+ public function __construct()
+ {
+ $this->assemble();
+ }
+
+ protected function assemble()
+ {
+ $this->add('importsource', [
+ 'label' => $this->translate('Import source'),
+ 'url' => 'director/importsources'
+ ])->add('syncrule', [
+ 'label' => $this->translate('Sync rule'),
+ 'url' => 'director/syncrules'
+ ])->add('jobs', [
+ 'label' => $this->translate('Jobs'),
+ 'url' => 'director/jobs'
+ ]);
+ }
+}
diff --git a/library/Director/Web/Tabs/ImportsourceTabs.php b/library/Director/Web/Tabs/ImportsourceTabs.php
new file mode 100644
index 0000000..74dedb3
--- /dev/null
+++ b/library/Director/Web/Tabs/ImportsourceTabs.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Icinga\Module\Director\Web\Tabs;
+
+use gipfl\Translation\TranslationHelper;
+use gipfl\IcingaWeb2\Widget\Tabs;
+
+class ImportsourceTabs extends Tabs
+{
+ use TranslationHelper;
+
+ protected $id;
+
+ public function __construct($id = null)
+ {
+ $this->id = $id;
+ $this->assemble();
+ }
+
+ public function activateMainWithPostfix($postfix)
+ {
+ $mainTab = 'index';
+ $tab = $this->get($mainTab);
+ $tab->setLabel($tab->getLabel() . ": $postfix");
+ $this->activate($mainTab);
+
+ return $this;
+ }
+
+ protected function assemble()
+ {
+ if ($id = $this->id) {
+ $params = ['id' => $id];
+ $this->add('index', [
+ 'url' => 'director/importsource',
+ 'urlParams' => $params,
+ 'label' => $this->translate('Import source'),
+ ])->add('modifier', [
+ 'url' => 'director/importsource/modifier',
+ 'urlParams' => ['source_id' => $id],
+ 'label' => $this->translate('Modifiers'),
+ ])->add('history', [
+ 'url' => 'director/importsource/history',
+ 'urlParams' => $params,
+ 'label' => $this->translate('History'),
+ ])->add('preview', [
+ 'url' => 'director/importsource/preview',
+ 'urlParams' => $params,
+ 'label' => $this->translate('Preview'),
+ ]);
+ } else {
+ $this->add('add', [
+ 'url' => 'director/importsource/add',
+ 'label' => $this->translate('New import source'),
+ ])->activate('add');
+ }
+ }
+}
diff --git a/library/Director/Web/Tabs/InfraTabs.php b/library/Director/Web/Tabs/InfraTabs.php
new file mode 100644
index 0000000..8a65c4e
--- /dev/null
+++ b/library/Director/Web/Tabs/InfraTabs.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace Icinga\Module\Director\Web\Tabs;
+
+use Icinga\Authentication\Auth;
+use gipfl\Translation\TranslationHelper;
+use gipfl\IcingaWeb2\Widget\Tabs;
+
+class InfraTabs extends Tabs
+{
+ use TranslationHelper;
+
+ /** @var Auth */
+ protected $auth;
+
+ public function __construct(Auth $auth)
+ {
+ $this->auth = $auth;
+ // We are not a BaseElement, not yet
+ $this->assemble();
+ }
+
+ protected function assemble()
+ {
+ $auth = $this->auth;
+
+ if ($auth->hasPermission('director/audit')) {
+ $this->add('activitylog', [
+ 'label' => $this->translate('Activity Log'),
+ 'url' => 'director/config/activities'
+ ]);
+ }
+
+ if ($auth->hasPermission('director/deploy')) {
+ $this->add('deploymentlog', [
+ 'label' => $this->translate('Deployments'),
+ 'url' => 'director/config/deployments'
+ ]);
+ }
+
+ if ($auth->hasPermission('director/admin')) {
+ $this->add('infrastructure', [
+ 'label' => $this->translate('Infrastructure'),
+ 'url' => 'director/dashboard',
+ 'urlParams' => ['name' => 'infrastructure']
+ ]);
+ }
+ }
+}
diff --git a/library/Director/Web/Tabs/MainTabs.php b/library/Director/Web/Tabs/MainTabs.php
new file mode 100644
index 0000000..5ea2e9b
--- /dev/null
+++ b/library/Director/Web/Tabs/MainTabs.php
@@ -0,0 +1,85 @@
+<?php
+
+namespace Icinga\Module\Director\Web\Tabs;
+
+use gipfl\Translation\TranslationHelper;
+use gipfl\IcingaWeb2\Widget\Tabs;
+use Icinga\Authentication\Auth;
+use Icinga\Module\Director\Web\Widget\Daemon\BackgroundDaemonState;
+use Icinga\Module\Director\Db;
+use Icinga\Module\Director\Health;
+use Icinga\Module\Director\Web\Widget\HealthCheckPluginOutput;
+
+class MainTabs extends Tabs
+{
+ use TranslationHelper;
+
+ protected $auth;
+
+ protected $dbResourceName;
+
+ public function __construct(Auth $auth, $dbResourceName)
+ {
+ $this->auth = $auth;
+ $this->dbResourceName = $dbResourceName;
+ $this->add('main', [
+ 'label' => $this->translate('Overview'),
+ 'url' => 'director'
+ ]);
+ if ($this->auth->hasPermission('director/admin')) {
+ $this->add('health', [
+ 'label' => $this->translate('Health'),
+ 'url' => 'director/health'
+ ])->add('daemon', [
+ 'label' => $this->translate('Daemon'),
+ 'url' => 'director/daemon'
+ ]);
+ }
+ }
+
+ public function render()
+ {
+ if ($this->auth->hasPermission('director/admin')) {
+ if ($this->getActiveName() !== 'health') {
+ $state = $this->getHealthState();
+ if ($state->isProblem()) {
+ $this->get('health')->setTagParams([
+ 'class' => 'state-' . strtolower($state->getName())
+ ]);
+ }
+ }
+
+ if ($this->getActiveName() !== 'daemon') {
+ try {
+ $daemon = new BackgroundDaemonState(Db::fromResourceName($this->dbResourceName));
+ if ($daemon->isRunning()) {
+ $state = 'ok';
+ } else {
+ $state = 'critical';
+ }
+ } catch (\Exception $e) {
+ $state = 'unknown';
+ }
+ if ($state !== 'ok') {
+ $this->get('daemon')->setTagParams([
+ 'class' => 'state-' . $state
+ ]);
+ }
+ }
+ }
+
+ return parent::render();
+ }
+
+ /**
+ * @return \Icinga\Module\Director\CheckPlugin\PluginState
+ */
+ protected function getHealthState()
+ {
+ $health = new Health();
+ $health->setDbResourceName($this->dbResourceName);
+ $output = new HealthCheckPluginOutput($health);
+
+ return $output->getState();
+ }
+}
diff --git a/library/Director/Web/Tabs/ObjectTabs.php b/library/Director/Web/Tabs/ObjectTabs.php
new file mode 100644
index 0000000..cbd3f15
--- /dev/null
+++ b/library/Director/Web/Tabs/ObjectTabs.php
@@ -0,0 +1,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');
+ }
+}
diff --git a/library/Director/Web/Tabs/ObjectsTabs.php b/library/Director/Web/Tabs/ObjectsTabs.php
new file mode 100644
index 0000000..4f9e5a8
--- /dev/null
+++ b/library/Director/Web/Tabs/ObjectsTabs.php
@@ -0,0 +1,85 @@
+<?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 ObjectsTabs extends Tabs
+{
+ use TranslationHelper;
+
+ public function __construct($type, Auth $auth, $typeUrl)
+ {
+ $object = IcingaObject::createByType($type);
+ if ($object->isGroup()) {
+ $object = IcingaObject::createByType(substr($typeUrl, 0, -5));
+ }
+ $shortName = $object->getShortTableName();
+
+ $plType = strtolower(preg_replace('/cys$/', 'cies', $shortName . 's'));
+ $plType = str_replace('_', '-', $plType);
+ if ($auth->hasPermission("director/${plType}")) {
+ $this->add('index', array(
+ 'url' => sprintf('director/%s', $plType),
+ 'label' => $this->translate(ucfirst($plType)),
+ ));
+ }
+
+ if ($object->getShortTableName() === 'command') {
+ $this->add('external', array(
+ 'url' => sprintf('director/%s', strtolower($plType)),
+ 'urlParams' => ['type' => 'external_object'],
+ 'label' => $this->translate('External'),
+ ));
+ }
+
+ if ($auth->hasPermission('director/admin') || (
+ $object->getShortTableName() === 'notification'
+ && $auth->hasPermission('director/notifications')
+ ) || (
+ $object->getShortTableName() === 'scheduled_downtime'
+ && $auth->hasPermission('director/scheduled-downtimes')
+ )) {
+ if ($object->supportsApplyRules()) {
+ $this->add('applyrules', array(
+ 'url' => sprintf('director/%s/applyrules', $plType),
+ 'label' => $this->translate('Apply')
+ ));
+ }
+ }
+
+ if ($auth->hasPermission('director/admin') && $type !== 'zone') {
+ if ($object->supportsImports()) {
+ $this->add('templates', array(
+ 'url' => sprintf('director/%s/templates', $plType),
+ 'label' => $this->translate('Templates'),
+ ));
+ }
+
+ if ($object->supportsGroups()) {
+ $this->add('groups', array(
+ 'url' => sprintf('director/%sgroups', $typeUrl),
+ 'label' => $this->translate('Groups')
+ ));
+ }
+ }
+
+ if ($auth->hasPermission('director/admin')) {
+ if ($object->supportsChoices()) {
+ $this->add('choices', array(
+ 'url' => sprintf('director/templatechoices/%s', $shortName),
+ 'label' => $this->translate('Choices')
+ ));
+ }
+ }
+ if ($object->supportsSets() && $auth->hasPermission("director/${typeUrl}sets")) {
+ $this->add('sets', array(
+ 'url' => sprintf('director/%s/sets', $plType),
+ 'label' => $this->translate('Sets')
+ ));
+ }
+ }
+}
diff --git a/library/Director/Web/Tabs/SyncRuleTabs.php b/library/Director/Web/Tabs/SyncRuleTabs.php
new file mode 100644
index 0000000..d64ff81
--- /dev/null
+++ b/library/Director/Web/Tabs/SyncRuleTabs.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Icinga\Module\Director\Web\Tabs;
+
+use Icinga\Module\Director\Objects\SyncRule;
+use gipfl\Translation\TranslationHelper;
+use gipfl\IcingaWeb2\Widget\Tabs;
+
+class SyncRuleTabs extends Tabs
+{
+ use TranslationHelper;
+
+ protected $rule;
+
+ public function __construct(SyncRule $rule = null)
+ {
+ $this->rule = $rule;
+ // We are not a BaseElement, not yet
+ $this->assemble();
+ }
+
+ protected function assemble()
+ {
+ if ($this->rule) {
+ $id = $this->rule->get('id');
+ $this->add('show', [
+ 'url' => 'director/syncrule',
+ 'urlParams' => ['id' => $id],
+ 'label' => $this->translate('Sync rule'),
+ ])->add('preview', [
+ 'url' => 'director/syncrule/preview',
+ 'urlParams' => ['id' => $id],
+ 'label' => $this->translate('Preview'),
+ ])->add('edit', [
+ 'url' => 'director/syncrule/edit',
+ 'urlParams' => ['id' => $id],
+ 'label' => $this->translate('Modify'),
+ ])->add('property', [
+ 'label' => $this->translate('Properties'),
+ 'url' => 'director/syncrule/property',
+ 'urlParams' => ['rule_id' => $id]
+ ])->add('history', [
+ 'label' => $this->translate('History'),
+ 'url' => 'director/syncrule/history',
+ 'urlParams' => ['id' => $id]
+ ]);
+ } else {
+ $this->add('add', [
+ 'url' => 'director/syncrule/add',
+ 'label' => $this->translate('Sync rule'),
+ ]);
+ }
+ }
+}