From f66ab8dae2f3d0418759f81a3a64dc9517a62449 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:17:31 +0200 Subject: Adding upstream version 1.10.2. Signed-off-by: Daniel Baumann --- library/Director/Web/Tabs/DataTabs.php | 34 ++++++ library/Director/Web/Tabs/ImportTabs.php | 30 +++++ library/Director/Web/Tabs/ImportsourceTabs.php | 58 +++++++++ library/Director/Web/Tabs/InfraTabs.php | 49 ++++++++ library/Director/Web/Tabs/MainTabs.php | 85 +++++++++++++ library/Director/Web/Tabs/ObjectTabs.php | 160 +++++++++++++++++++++++++ library/Director/Web/Tabs/ObjectsTabs.php | 85 +++++++++++++ library/Director/Web/Tabs/SyncRuleTabs.php | 54 +++++++++ 8 files changed, 555 insertions(+) create mode 100644 library/Director/Web/Tabs/DataTabs.php create mode 100644 library/Director/Web/Tabs/ImportTabs.php create mode 100644 library/Director/Web/Tabs/ImportsourceTabs.php create mode 100644 library/Director/Web/Tabs/InfraTabs.php create mode 100644 library/Director/Web/Tabs/MainTabs.php create mode 100644 library/Director/Web/Tabs/ObjectTabs.php create mode 100644 library/Director/Web/Tabs/ObjectsTabs.php create mode 100644 library/Director/Web/Tabs/SyncRuleTabs.php (limited to 'library/Director/Web/Tabs') 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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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'), + ]); + } + } +} -- cgit v1.2.3