unbound: validate against service's dns_ports

This commit is contained in:
Franco Fichtner 2023-05-03 12:42:57 +02:00
parent 558026763f
commit d893feaeab

View File

@ -1,6 +1,7 @@
<?php
/*
* Copyright (C) 2023 Deciso B.V.
* Copyright (C) 2021 Michael Muenz <m.muenz@gmail.com>
* All rights reserved.
*
@ -28,9 +29,9 @@
namespace OPNsense\Unbound;
use Phalcon\Messages\Message;
use OPNsense\Base\BaseModel;
use OPNsense\Core\Config;
use OPNsense\Core\Backend;
use Phalcon\Messages\Message;
class Unbound extends BaseModel
{
@ -38,17 +39,21 @@ class Unbound extends BaseModel
{
$messages = parent::performValidation($validateFullModel);
if ($validateFullModel || $this->general->enabled->isFieldChanged() || $this->general->port->isFieldChanged()) {
$config = Config::getInstance()->object();
$dnsmasq_port = !empty((string)$config->dnsmasq->port) ? (string)$config->dnsmasq->port : '53';
$unbound_port = (string)$this->general->port;
if (!empty((string)$this->general->enabled) && !empty((string)$config->dnsmasq->enable) && $unbound_port == $dnsmasq_port) {
$messages->appendMessage(new Message(
gettext('Dnsmasq is currently using this port.'),
'general.' . $this->general->port->getInternalXMLTagName()
));
if (
($validateFullModel || $this->general->enabled->isFieldChanged() || $this->general->port->isFieldChanged()) &&
!empty((string)$this->general->enabled)
) {
foreach (json_decode((new Backend())->configdpRun('service list'), true) as $service) {
if (empty($service['dns_ports'])) {
continue;
}
if ($service['name'] != 'unbound' && in_array((string)$this->general->port, $service['dns_ports'])) {
$messages->appendMessage(new Message(
sprintf(gettext('%s is currently using this port.'), $service['description']),
'general.' . $this->general->port->getInternalXMLTagName()
));
break;
}
}
}