summaryrefslogtreecommitdiffstats
path: root/library/Director/ProvidedHook
diff options
context:
space:
mode:
Diffstat (limited to 'library/Director/ProvidedHook')
-rw-r--r--library/Director/ProvidedHook/IcingaDbCubeLinks.php13
-rw-r--r--library/Director/ProvidedHook/Icingadb/HostActions.php78
-rw-r--r--library/Director/ProvidedHook/Icingadb/IcingadbSupport.php10
-rw-r--r--library/Director/ProvidedHook/Icingadb/ServiceActions.php87
-rw-r--r--library/Director/ProvidedHook/Monitoring/HostActions.php18
-rw-r--r--library/Director/ProvidedHook/Monitoring/ServiceActions.php16
6 files changed, 197 insertions, 25 deletions
diff --git a/library/Director/ProvidedHook/IcingaDbCubeLinks.php b/library/Director/ProvidedHook/IcingaDbCubeLinks.php
index 234f61f..f3fe402 100644
--- a/library/Director/ProvidedHook/IcingaDbCubeLinks.php
+++ b/library/Director/ProvidedHook/IcingaDbCubeLinks.php
@@ -7,6 +7,7 @@ use Icinga\Exception\ProgrammingError;
use Icinga\Module\Cube\Hook\IcingaDbActionsHook;
use Icinga\Module\Cube\IcingaDb\IcingaDbCube;
use Icinga\Module\Cube\IcingaDb\IcingaDbHostStatusCube;
+use ipl\Stdlib\Filter\Condition;
class IcingaDbCubeLinks extends IcingaDbActionsHook
{
@@ -25,17 +26,19 @@ class IcingaDbCubeLinks extends IcingaDbActionsHook
if ($filterChain->count() === 1) {
$url = 'director/host/edit?';
- $params = ['name' => $filterChain->getIterator()->current()->getValue()];
+ /** @var Condition $rule */
+ $rule = $filterChain->getIterator()->current();
+ /** @var string $name */
+ $name = $rule->getValue();
+ $params = ['name' => $name];
$title = t('Modify a host');
- $description = sprintf(
- t('This allows you to modify properties for "%s"'),
- $filterChain->getIterator()->current()->getValue()
- );
+ $description = sprintf(t('This allows you to modify properties for "%s"'), $name);
} else {
$params = null;
$urlFilter = Filter::matchAny();
+ /** @var Condition $filter */
foreach ($filterChain as $filter) {
$urlFilter->addFilter(
Filter::matchAny(
diff --git a/library/Director/ProvidedHook/Icingadb/HostActions.php b/library/Director/ProvidedHook/Icingadb/HostActions.php
new file mode 100644
index 0000000..d7332ea
--- /dev/null
+++ b/library/Director/ProvidedHook/Icingadb/HostActions.php
@@ -0,0 +1,78 @@
+<?php
+
+namespace Icinga\Module\Director\ProvidedHook\Icingadb;
+
+use Exception;
+use Icinga\Application\Config;
+use Icinga\Module\Director\Auth\Permission;
+use Icinga\Module\Director\Db;
+use Icinga\Module\Director\Integration\Icingadb\IcingadbBackend;
+use Icinga\Module\Director\Objects\IcingaHost;
+use Icinga\Module\Director\Util;
+use Icinga\Module\Icingadb\Hook\HostActionsHook;
+use Icinga\Module\Icingadb\Model\Host;
+use ipl\Web\Url;
+use ipl\Web\Widget\Link;
+
+class HostActions extends HostActionsHook
+{
+ public function getActionsForObject(Host $host): array
+ {
+ try {
+ return $this->getThem($host);
+ } catch (Exception $e) {
+ return [];
+ }
+ }
+
+ protected function getThem(Host $host): array
+ {
+ $actions = [];
+ $db = $this->db();
+ if (! $db) {
+ return $actions;
+ }
+ $hostname = $host->name;
+ if (Util::hasPermission(Permission::INSPECT)) {
+ $actions[] = new Link(
+ mt('director', 'Inspect'),
+ Url::fromPath(
+ 'director/inspect/object',
+ ['type' => 'host', 'plural' => 'hosts', 'name' => $hostname]
+ )
+ );
+ }
+
+ $allowEdit = false;
+ if (Util::hasPermission(Permission::HOSTS) && IcingaHost::exists($hostname, $db)) {
+ $allowEdit = true;
+ }
+ if (Util::hasPermission(Permission::ICINGADB_HOSTS)) {
+ if ((new IcingadbBackend())->canModifyHost($hostname)) {
+ $allowEdit = IcingaHost::exists($hostname, $db);
+ }
+ }
+
+ if ($allowEdit) {
+ $label = mt('director', 'Modify');
+ $actions[] = new Link(
+ $label,
+ Url::fromPath('director/host/edit', [
+ 'name' => $hostname
+ ])
+ );
+ }
+
+ return $actions;
+ }
+
+ protected function db()
+ {
+ $resourceName = Config::module('director')->get('db', 'resource');
+ if (! $resourceName) {
+ return false;
+ }
+
+ return Db::fromResourceName($resourceName);
+ }
+}
diff --git a/library/Director/ProvidedHook/Icingadb/IcingadbSupport.php b/library/Director/ProvidedHook/Icingadb/IcingadbSupport.php
new file mode 100644
index 0000000..5a59304
--- /dev/null
+++ b/library/Director/ProvidedHook/Icingadb/IcingadbSupport.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Icinga\Module\Director\ProvidedHook\Icingadb;
+
+use Icinga\Module\Icingadb\Hook\IcingadbSupportHook;
+
+class IcingadbSupport extends IcingadbSupportHook
+{
+
+}
diff --git a/library/Director/ProvidedHook/Icingadb/ServiceActions.php b/library/Director/ProvidedHook/Icingadb/ServiceActions.php
new file mode 100644
index 0000000..1603dc3
--- /dev/null
+++ b/library/Director/ProvidedHook/Icingadb/ServiceActions.php
@@ -0,0 +1,87 @@
+<?php
+
+namespace Icinga\Module\Director\ProvidedHook\Icingadb;
+
+use Exception;
+use Icinga\Application\Config;
+use Icinga\Module\Director\Auth\Permission;
+use Icinga\Module\Director\Db;
+use Icinga\Module\Director\Integration\Icingadb\IcingadbBackend;
+use Icinga\Module\Director\Objects\IcingaHost;
+use Icinga\Module\Director\Util;
+use Icinga\Module\Icingadb\Hook\ServiceActionsHook;
+use Icinga\Module\Icingadb\Model\Service;
+use ipl\Web\Url;
+use ipl\Web\Widget\Link;
+
+class ServiceActions extends ServiceActionsHook
+{
+ public function getActionsForObject(Service $service): array
+ {
+ try {
+ return $this->getThem($service);
+ } catch (Exception $e) {
+ return [];
+ }
+ }
+
+ /**
+ * @param Service $service
+ * @return array
+ * @throws \Icinga\Exception\ProgrammingError
+ */
+ protected function getThem(Service $service)
+ {
+ $actions = [];
+ $db = $this->db();
+ if (! $db) {
+ return [];
+ }
+
+ $hostname = $service->host->name;
+ $serviceName = $service->name;
+ if (Util::hasPermission(Permission::INSPECT)) {
+ $actions[] = new Link(
+ mt('director', 'Inspect'),
+ Url::fromPath('director/inspect/object', [
+ 'type' => 'service',
+ 'plural' => 'services',
+ 'name' => sprintf('%s!%s', $hostname, $serviceName)
+ ])
+ );
+ }
+
+ $title = null;
+ if (Util::hasPermission(Permission::HOSTS)) {
+ $title = mt('director', 'Modify');
+ } elseif (Util::hasPermission(Permission::ICINGADB_SERVICES)) {
+ if ((new IcingadbBackend())->canModifyService($hostname, $serviceName)) {
+ $title = mt('director', 'Modify');
+ }
+ } elseif (Util::hasPermission(Permission::ICINGADB_SERVICES_RO)) {
+ $title = mt('director', 'Configuration');
+ }
+
+ if ($title && IcingaHost::exists($hostname, $db)) {
+ $actions[] = new Link(
+ $title,
+ Url::fromPath('director/host/findservice', [
+ 'name' => $hostname,
+ 'service' => $serviceName
+ ])
+ );
+ }
+
+ return $actions;
+ }
+
+ protected function db()
+ {
+ $resourceName = Config::module('director')->get('db', 'resource');
+ if (! $resourceName) {
+ return false;
+ }
+
+ return Db::fromResourceName($resourceName);
+ }
+}
diff --git a/library/Director/ProvidedHook/Monitoring/HostActions.php b/library/Director/ProvidedHook/Monitoring/HostActions.php
index 2e3fba0..2d0469d 100644
--- a/library/Director/ProvidedHook/Monitoring/HostActions.php
+++ b/library/Director/ProvidedHook/Monitoring/HostActions.php
@@ -5,8 +5,9 @@ namespace Icinga\Module\Director\ProvidedHook\Monitoring;
use Exception;
use Icinga\Application\Config;
use Icinga\Authentication\Auth;
+use Icinga\Module\Director\Auth\Permission;
use Icinga\Module\Director\Db;
-use Icinga\Module\Director\Monitoring;
+use Icinga\Module\Director\Integration\MonitoringModule\Monitoring;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Util;
use Icinga\Module\Monitoring\Hook\HostActionsHook;
@@ -32,7 +33,7 @@ class HostActions extends HostActionsHook
return $actions;
}
$hostname = $host->host_name;
- if (Util::hasPermission('director/inspect')) {
+ if (Util::hasPermission(Permission::INSPECT)) {
$actions[mt('director', 'Inspect')] = Url::fromPath(
'director/inspect/object',
array('type' => 'host', 'plural' => 'hosts', 'name' => $hostname)
@@ -40,22 +41,17 @@ class HostActions extends HostActionsHook
}
$allowEdit = false;
- if (Util::hasPermission('director/hosts') && IcingaHost::exists($hostname, $db)) {
+ if (Util::hasPermission(Permission::HOSTS) && IcingaHost::exists($hostname, $db)) {
$allowEdit = true;
}
- $auth = Auth::getInstance();
- if (Util::hasPermission('director/monitoring/hosts')) {
- $monitoring = new Monitoring();
- if ($monitoring->isAvailable() && $monitoring->authCanEditHost($auth, $hostname)) {
+ if (Util::hasPermission(Permission::MONITORING_HOSTS)) {
+ if ((new Monitoring(Auth::getInstance()))->canModifyHost($hostname)) {
$allowEdit = IcingaHost::exists($hostname, $db);
}
}
if ($allowEdit) {
- $actions[mt('director', 'Modify')] = Url::fromPath(
- 'director/host/edit',
- array('name' => $hostname)
- );
+ $actions[mt('director', 'Modify')] = Url::fromPath('director/host/edit', ['name' => $hostname]);
}
return $actions;
diff --git a/library/Director/ProvidedHook/Monitoring/ServiceActions.php b/library/Director/ProvidedHook/Monitoring/ServiceActions.php
index b2e303a..834b166 100644
--- a/library/Director/ProvidedHook/Monitoring/ServiceActions.php
+++ b/library/Director/ProvidedHook/Monitoring/ServiceActions.php
@@ -5,8 +5,9 @@ namespace Icinga\Module\Director\ProvidedHook\Monitoring;
use Exception;
use Icinga\Application\Config;
use Icinga\Authentication\Auth;
+use Icinga\Module\Director\Auth\Permission;
use Icinga\Module\Director\Db;
-use Icinga\Module\Director\Monitoring;
+use Icinga\Module\Director\Integration\MonitoringModule\Monitoring;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Util;
use Icinga\Module\Monitoring\Hook\ServiceActionsHook;
@@ -39,7 +40,7 @@ class ServiceActions extends ServiceActionsHook
$hostname = $service->host_name;
$serviceName = $service->service_description;
- if (Util::hasPermission('director/inspect')) {
+ if (Util::hasPermission(Permission::INSPECT)) {
$actions[mt('director', 'Inspect')] = Url::fromPath('director/inspect/object', [
'type' => 'service',
'plural' => 'services',
@@ -52,16 +53,13 @@ class ServiceActions extends ServiceActionsHook
}
$title = null;
- if (Util::hasPermission('director/hosts')) {
+ if (Util::hasPermission(Permission::HOSTS)) {
$title = mt('director', 'Modify');
- } elseif (Util::hasPermission('director/monitoring/services')) {
- $monitoring = new Monitoring();
- if ($monitoring->isAvailable()
- && $monitoring->authCanEditService(Auth::getInstance(), $hostname, $serviceName)
- ) {
+ } elseif (Util::hasPermission(Permission::MONITORING_SERVICES)) {
+ if ((new Monitoring(Auth::getInstance()))->canModifyService($hostname, $serviceName)) {
$title = mt('director', 'Modify');
}
- } elseif (Util::hasPermission('director/monitoring/services-ro')) {
+ } elseif (Util::hasPermission(Permission::MONITORING_SERVICES_RO)) {
$title = mt('director', 'Configuration');
}