diff --git a/application/forms/IcingaHostForm.php b/application/forms/IcingaHostForm.php index d7bca9c31..b9c03ce94 100644 --- a/application/forms/IcingaHostForm.php +++ b/application/forms/IcingaHostForm.php @@ -2,6 +2,7 @@ namespace Icinga\Module\Director\Forms; +use Exception; use Icinga\Exception\AuthenticationException; use Icinga\Module\Director\Auth\Permission; use Icinga\Module\Director\Auth\Restriction; @@ -83,7 +84,13 @@ protected function addClusteringElements() 'class' => 'autosubmit', ]); - if ($this->getSentOrResolvedObjectValue('has_agent') === 'y') { + try { + $hasAgent = $this->getSentOrResolvedObjectValue('has_agent') === 'y'; + } catch (Exception $e) { + $hasAgent = false; + } + + if ($hasAgent) { $this->addBoolean('master_should_connect', [ 'label' => $this->translate('Establish connection'), 'description' => $this->translate( diff --git a/application/forms/ImportRowModifierForm.php b/application/forms/ImportRowModifierForm.php index 7033f4c12..a9fdcf1a2 100644 --- a/application/forms/ImportRowModifierForm.php +++ b/application/forms/ImportRowModifierForm.php @@ -214,4 +214,13 @@ public function setSource(ImportSource $source) return $this; } + + public function onSuccess() + { + if ($this->getValue('use_filter') === 'n') { + $this->getObject()->set('filter_expression', null); + } + + parent::onSuccess(); + } } diff --git a/doc/02-Installation.md.d/From-Source.md b/doc/02-Installation.md.d/From-Source.md index 96045a415..c8c5d1ea6 100644 --- a/doc/02-Installation.md.d/From-Source.md +++ b/doc/02-Installation.md.d/From-Source.md @@ -41,7 +41,7 @@ and extract it to a folder named `director` in one of your Icinga Web module pat You might want to use a script as follows for this task: ```shell -MODULE_VERSION="1.11.2" +MODULE_VERSION="1.11.3" ICINGAWEB_MODULEPATH="/usr/share/icingaweb2/modules" REPO_URL="https://github.com/icinga/icingaweb2-module-director" TARGET_DIR="${ICINGAWEB_MODULEPATH}/director" @@ -60,7 +60,7 @@ Simply clone the repository in one of your Icinga web module path directories. You might want to use a script as follows for this task: ```shell -MODULE_VERSION="1.11.2" +MODULE_VERSION="1.11.3" ICINGAWEB_MODULEPATH="/usr/share/icingaweb2/modules" REPO_URL="https://github.com/icinga/icingaweb2-module-director" TARGET_DIR="${ICINGAWEB_MODULEPATH}/director" diff --git a/doc/82-Changelog.md b/doc/82-Changelog.md index 038d58f54..7ca8c3303 100644 --- a/doc/82-Changelog.md +++ b/doc/82-Changelog.md @@ -4,6 +4,17 @@ Please make sure to always read our [Upgrading](05-Upgrading.md) documentation before switching to a new version. +v1.11.3 +------- + +### UI +* FIX: Property sort tables does not cause CSRF token validation anymore (#2937) +* FIX: No error when clicking `modify` action link for services belonging to service set in Icinga DB (#2938) +* FIX: No crashing of Host template form when invalid check command is entered (#2941) + +### Internals +* FIX: Filter can be now removed in import source modifiers (#2939) + v1.11.2 ------- diff --git a/library/Director/DirectorObject/Lookup/ServiceSetServiceInfo.php b/library/Director/DirectorObject/Lookup/ServiceSetServiceInfo.php index a980da887..d8e81cb3a 100644 --- a/library/Director/DirectorObject/Lookup/ServiceSetServiceInfo.php +++ b/library/Director/DirectorObject/Lookup/ServiceSetServiceInfo.php @@ -3,6 +3,7 @@ namespace Icinga\Module\Director\DirectorObject\Lookup; use gipfl\IcingaWeb2\Url; +use Icinga\Module\Director\Db\DbUtil; use Icinga\Module\Director\Objects\IcingaHost; use Icinga\Module\Director\Repository\IcingaTemplateRepository; use Ramsey\Uuid\Uuid; @@ -75,7 +76,7 @@ public static function find(IcingaHost $host, $serviceName) $host->getObjectName(), $serviceName, $row->service_set_name, - Uuid::fromBytes($row->uuid) + Uuid::fromBytes(DbUtil::binaryResult($row->uuid)) ); } diff --git a/library/Director/Web/Form/PropertyTableSortForm.php b/library/Director/Web/Form/PropertyTableSortForm.php index 27aa6c5ea..7950c7d98 100644 --- a/library/Director/Web/Form/PropertyTableSortForm.php +++ b/library/Director/Web/Form/PropertyTableSortForm.php @@ -2,15 +2,13 @@ namespace Icinga\Module\Director\Web\Form; -use Icinga\Web\Session; +use ipl\Html\Contract\FormElement; use ipl\Html\Form; +use ipl\Html\FormElement\HiddenElement; use ipl\Html\ValidHtml; -use ipl\Web\Common\CsrfCounterMeasure; class PropertyTableSortForm extends Form { - use CsrfCounterMeasure; - protected $method = 'POST'; /** @var string Name of the form */ @@ -28,7 +26,38 @@ public function __construct(string $name, ValidHtml $table) protected function assemble() { $this->addElement('hidden', '__FORM_NAME', ['value' => $this->name]); - $this->addElement($this->createCsrfCounterMeasure(Session::getSession()->getId())); + $this->addElement($this->createCsrfCounterMeasure()); $this->addHtml($this->table); } + + /** + * Create a form element to countermeasure CSRF attacks + * + * @return FormElement + */ + protected function createCsrfCounterMeasure(): FormElement + { + $token = CsrfToken::generate(); + + $options = [ + 'ignore' => true, + 'required' => true, + 'validators' => ['Callback' => function ($token) { + return CsrfToken::isValid($token); + }] + ]; + + $element = new class (QuickForm::CSRF, $options) extends HiddenElement { + public function hasValue(): bool + { + return true; // The validator must run even if the value is empty + } + }; + + $element->getAttributes()->registerAttributeCallback('value', function () use ($token) { + return $token; + }); + + return $element; + } } diff --git a/library/Director/Web/Table/ObjectsTableSetMembers.php b/library/Director/Web/Table/ObjectsTableSetMembers.php index 6b18ac9a6..aaafb1007 100644 --- a/library/Director/Web/Table/ObjectsTableSetMembers.php +++ b/library/Director/Web/Table/ObjectsTableSetMembers.php @@ -8,6 +8,7 @@ use gipfl\IcingaWeb2\Table\ZfQueryBasedTable; use gipfl\IcingaWeb2\Url; use Icinga\Module\Director\Db\DbSelectParenthesis; +use Icinga\Module\Director\Db\DbUtil; use Icinga\Module\Director\Db\IcingaObjectFilterHelper; use Icinga\Module\Director\Objects\IcingaObject; use Icinga\Module\Director\Restriction\FilterByNameRestriction; @@ -97,7 +98,7 @@ public function renderRow($row) { $url = Url::fromPath('director/service/edit', [ 'name' => $row->object_name, - 'uuid' => Uuid::fromBytes($row->uuid)->toString(), + 'uuid' => Uuid::fromBytes(DbUtil::binaryResult($row->uuid))->toString(), ]); return static::tr([ diff --git a/library/Director/Web/Table/PropertymodifierTable.php b/library/Director/Web/Table/PropertymodifierTable.php index 37e14ac90..356c87d8b 100644 --- a/library/Director/Web/Table/PropertymodifierTable.php +++ b/library/Director/Web/Table/PropertymodifierTable.php @@ -12,6 +12,7 @@ use gipfl\IcingaWeb2\Table\ZfQueryBasedTable; use gipfl\IcingaWeb2\Url; use Icinga\Module\Director\Web\Form\PropertyTableSortForm; +use Icinga\Module\Director\Web\Form\QuickForm; use ipl\Html\Form; use ipl\Html\HtmlString; @@ -59,7 +60,7 @@ public function render() return (new PropertyTableSortForm($this->getUniqueFormName(), new HtmlString(parent::render()))) ->setAction($this->request->getUrl()->getAbsoluteUrl()) ->on(Form::ON_SENT, function (PropertyTableSortForm $form) { - $csrf = $form->getElement('CSRFToken'); + $csrf = $form->getElement(QuickForm::CSRF); if ($csrf !== null && $csrf->isValid()) { $this->reallyHandleSortPriorityActions(); } diff --git a/library/Director/Web/Table/SyncpropertyTable.php b/library/Director/Web/Table/SyncpropertyTable.php index c0b282029..47edcad5a 100644 --- a/library/Director/Web/Table/SyncpropertyTable.php +++ b/library/Director/Web/Table/SyncpropertyTable.php @@ -8,6 +8,7 @@ use gipfl\IcingaWeb2\Table\Extension\ZfSortablePriority; use gipfl\IcingaWeb2\Table\ZfQueryBasedTable; use Icinga\Module\Director\Web\Form\PropertyTableSortForm; +use Icinga\Module\Director\Web\Form\QuickForm; use ipl\Html\Form; use ipl\Html\HtmlString; @@ -44,7 +45,7 @@ public function render() return (new PropertyTableSortForm($this->getUniqueFormName(), new HtmlString(parent::render()))) ->setAction($this->request->getUrl()->getAbsoluteUrl()) ->on(Form::ON_SENT, function (PropertyTableSortForm $form) { - $csrf = $form->getElement('CSRFToken'); + $csrf = $form->getElement(QuickForm::CSRF); if ($csrf !== null && $csrf->isValid()) { $this->reallyHandleSortPriorityActions(); } diff --git a/module.info b/module.info index 841ad297e..1c448edf4 100644 --- a/module.info +++ b/module.info @@ -1,5 +1,5 @@ Name: Icinga Director -Version: 1.11.2 +Version: 1.11.3 Depends: reactbundle (>=0.9.0), ipl (>=0.5.0), incubator (>=0.22.0) Description: Director - Config tool for Icinga 2 Icinga Director is a configuration tool that has been designed to make