Skip to content

Commit

Permalink
Merge pull request #159 from Icinga/feature/restrictions
Browse files Browse the repository at this point in the history
Restrictions
  • Loading branch information
nilmerg authored Mar 12, 2021
2 parents fa2b9d5 + aae4c01 commit e14cf93
Show file tree
Hide file tree
Showing 26 changed files with 482 additions and 320 deletions.
2 changes: 1 addition & 1 deletion application/controllers/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function init()
$query->getSelectBase()
->where(['comment.name = ?' => $name]);

$this->applyMonitoringRestriction($query);
$this->applyRestrictions($query);

$comment = $query->first();
if ($comment === null) {
Expand Down
13 changes: 0 additions & 13 deletions application/controllers/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Icinga\Module\Icingadb\Forms\DatabaseConfigForm;
use Icinga\Module\Icingadb\Forms\RedisConfigForm;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Monitoring\Forms\Config\SecurityConfigForm;
use Icinga\Web\Form;
use Icinga\Web\Widget\Tab;
use Icinga\Web\Widget\Tabs;
Expand Down Expand Up @@ -47,18 +46,6 @@ public function redisAction()
$this->addFormToContent($form);
}

public function securityAction()
{
$form = (new SecurityConfigForm())
->setIniConfig(Config::module('monitoring'));

$form->handleRequest();

$this->mergeTabs($this->Module()->getConfigTabs()->activate('security'));

$this->addFormToContent($form);
}

protected function addFormToContent(Form $form)
{
$this->addContent(new HtmlString($form->render()));
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/DowntimeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function init()
$query->getSelectBase()
->where(['downtime.name = ?' => $name]);

$this->applyMonitoringRestriction($query);
$this->applyRestrictions($query);

$downtime = $query->first();
if ($downtime === null) {
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/HealthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public function indexAction()
$hoststateSummary = HoststateSummary::on($db)->with('state');
$servicestateSummary = ServicestateSummary::on($db)->with('state');

$this->applyMonitoringRestriction($hoststateSummary);
$this->applyMonitoringRestriction($servicestateSummary);
$this->applyRestrictions($hoststateSummary);
$this->applyRestrictions($servicestateSummary);

yield $this->export($instance, $hoststateSummary, $servicestateSummary);

Expand Down
6 changes: 4 additions & 2 deletions application/controllers/HostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function init()
$query->getSelectBase()
->where(['host.name = ?' => $name]);

$this->applyMonitoringRestriction($query);
$this->applyRestrictions($query);

/** @var Host $host */
$host = $query->first();
Expand All @@ -56,6 +56,8 @@ public function indexAction()
$serviceSummary->getSelectBase()
->where(['host_id = ?' => $this->host->id]);

$this->applyRestrictions($serviceSummary);

if ($this->host->state->is_overdue) {
$this->controls->addAttributes(['class' => 'overdue']);
}
Expand Down Expand Up @@ -203,7 +205,7 @@ public function servicesAction()
->getSelectBase()
->where(['service_host.id = ?' => $this->host->id]);

$this->applyMonitoringRestriction($services);
$this->applyRestrictions($services);

$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($services);
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/HostgroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function init()
$query
);

$this->applyMonitoringRestriction($query);
$this->applyRestrictions($query);

$hostgroup = $query->first();
if ($hostgroup === null) {
Expand All @@ -48,7 +48,7 @@ public function indexAction()
$hosts = Host::on($db)->with('state')->utilize('hostgroup');

$hosts->getSelectBase()->where(['host_hostgroup.id = ?' => $this->hostgroup->id]);
$this->applyMonitoringRestriction($hosts);
$this->applyRestrictions($hosts);

$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($hosts);
Expand Down
7 changes: 6 additions & 1 deletion application/controllers/HostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public function detailsAction()

$comments = Host::on($db)->with(['comment']);
$comments->getWith()['host.comment']->setJoinType('INNER');
// TODO: This should be automatically done by the model/resolver and added as ON condition
FilterProcessor::apply(Filter::equal('comment.object_type', 'host'), $comments);
$this->filter($comments);
$summary->comments_total = $comments->count();

Expand Down Expand Up @@ -206,6 +208,9 @@ public function getCommandTargetsUrl()

protected function getFeatureStatus()
{
return new FeatureStatus('host', HoststateSummary::on($this->getDb())->with(['state'])->first());
$summary = HoststateSummary::on($this->getDb())->with(['state']);
$this->filter($summary);

return new FeatureStatus('host', $summary->first());
}
}
2 changes: 1 addition & 1 deletion application/controllers/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function init()
->where(['service.name = ?' => $name])
->where(['service_host.name = ?' => $hostName]);

$this->applyMonitoringRestriction($query);
$this->applyRestrictions($query);

/** @var Service $service */
$service = $query->first();
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/ServicegroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function init()
$query
);

$this->applyMonitoringRestriction($query);
$this->applyRestrictions($query);

$servicegroup = $query->first();
if ($servicegroup === null) {
Expand All @@ -52,7 +52,7 @@ public function indexAction()
])->utilize('servicegroup');

$services->getSelectBase()->where(['service_servicegroup.id = ?' => $this->servicegroup->id]);
$this->applyMonitoringRestriction($services);
$this->applyRestrictions($services);

$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($services);
Expand Down
5 changes: 4 additions & 1 deletion application/controllers/ServicesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ public function getCommandTargetsUrl()

protected function getFeatureStatus()
{
return new FeatureStatus('service', ServicestateSummary::on($this->getDb())->with(['state'])->first());
$summary = ServicestateSummary::on($this->getDb())->with(['state']);
$this->filter($summary);

return new FeatureStatus('service', $summary->first());
}
}
2 changes: 1 addition & 1 deletion application/controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function init()
$query->getSelectBase()
->where(['user.name = ?' => $name]);

$this->applyMonitoringRestriction($query);
$this->applyRestrictions($query);

$user = $query->first();
if ($user === null) {
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/UsergroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function init()
$query->getSelectBase()
->where(['usergroup.name = ?' => $name]);

$this->applyMonitoringRestriction($query);
$this->applyRestrictions($query);

$usergroup = $query->first();
if ($usergroup === null) {
Expand Down
30 changes: 25 additions & 5 deletions configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@

$this->provideSetupWizard('Icinga\Module\Icingadb\Setup\IcingaDbWizard');

$this->provideRestriction(
'icingadb/filter/objects',
$this->translate('Restrict access to the Icinga objects that match the filter')
);

$this->provideRestriction(
'icingadb/filter/hosts',
$this->translate('Restrict access to the Icinga hosts and services that match the filter')
);

$this->provideRestriction(
'icingadb/filter/services',
$this->translate('Restrict access to the Icinga services that match the filter')
);

$this->provideRestriction(
'icingadb/blacklist/variables',
$this->translate('Hide custom variables of Icinga objects that are part of the list')
);

$this->provideRestriction(
'icingadb/protect/variables',
$this->translate('Obfuscate custom variable values of Icinga objects that are part of the list')
);

if (! $this::exists('monitoring')) {
/**
* Search urls
Expand Down Expand Up @@ -214,11 +239,6 @@
'title' => t('Configure command transports'),
'url' => 'command-transport'
]);
$this->provideConfigTab('security', [
'label' => t('Security'),
'title' => t('Configure security related settings'),
'url' => 'config/security'
]);

try {
// TODO: Remove this before the stable release!!!1!11
Expand Down
Loading

0 comments on commit e14cf93

Please sign in to comment.