From 363069a983cf0d1bafcc79f21e1d4bcacf52e718 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 27 Mar 2019 19:16:50 +0100 Subject: [PATCH] dns/bind: full zone management (#1276) --- dns/bind/Makefile | 3 +- dns/bind/pkg-descr | 4 + .../OPNsense/Bind/Api/DomainController.php | 74 ++++++++++ .../OPNsense/Bind/Api/RecordController.php | 127 ++++++++++++++++++ .../OPNsense/Bind/GeneralController.php | 4 +- .../Bind/forms/dialogEditBindDomain.xml | 80 +++++++++++ .../Bind/forms/dialogEditBindRecord.xml | 32 +++++ .../mvc/app/models/OPNsense/Bind/Domain.php | 67 +++++++++ .../mvc/app/models/OPNsense/Bind/Domain.xml | 98 ++++++++++++++ .../mvc/app/models/OPNsense/Bind/Record.php | 46 +++++++ .../mvc/app/models/OPNsense/Bind/Record.xml | 46 +++++++ .../mvc/app/views/OPNsense/Bind/general.volt | 124 ++++++++++++++++- .../service/templates/OPNsense/Bind/+TARGETS | 1 + .../service/templates/OPNsense/Bind/domain.db | 17 +++ .../templates/OPNsense/Bind/named.conf | 12 ++ 15 files changed, 728 insertions(+), 7 deletions(-) create mode 100644 dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/Api/DomainController.php create mode 100644 dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/Api/RecordController.php create mode 100644 dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/forms/dialogEditBindDomain.xml create mode 100644 dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/forms/dialogEditBindRecord.xml create mode 100644 dns/bind/src/opnsense/mvc/app/models/OPNsense/Bind/Domain.php create mode 100644 dns/bind/src/opnsense/mvc/app/models/OPNsense/Bind/Domain.xml create mode 100644 dns/bind/src/opnsense/mvc/app/models/OPNsense/Bind/Record.php create mode 100644 dns/bind/src/opnsense/mvc/app/models/OPNsense/Bind/Record.xml create mode 100644 dns/bind/src/opnsense/service/templates/OPNsense/Bind/domain.db diff --git a/dns/bind/Makefile b/dns/bind/Makefile index 3292b6db6..e41785350 100644 --- a/dns/bind/Makefile +++ b/dns/bind/Makefile @@ -1,6 +1,5 @@ PLUGIN_NAME= bind -PLUGIN_VERSION= 1.4 -PLUGIN_REVISION= 1 +PLUGIN_VERSION= 1.5.d PLUGIN_COMMENT= BIND domain name service PLUGIN_DEPENDS= bind912 PLUGIN_MAINTAINER= m.muenz@gmail.com diff --git a/dns/bind/pkg-descr b/dns/bind/pkg-descr index 85705e64c..67647a915 100644 --- a/dns/bind/pkg-descr +++ b/dns/bind/pkg-descr @@ -8,6 +8,10 @@ necessary for asking and answering name service questions. Plugin Changelog ================ +1.5 + +* Add basic zone management + 1.4 * Add Bing and DuckDuckGo Strict Search diff --git a/dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/Api/DomainController.php b/dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/Api/DomainController.php new file mode 100644 index 000000000..d4894ed4d --- /dev/null +++ b/dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/Api/DomainController.php @@ -0,0 +1,74 @@ + + * Copyright (C) 2019 Deciso B.V. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +namespace OPNsense\Bind\Api; + +use \OPNsense\Base\ApiMutableModelControllerBase; +use \OPNsense\Core\Backend; + +class DomainController extends ApiMutableModelControllerBase +{ + protected static $internalModelName = 'domain'; + protected static $internalModelClass = '\OPNsense\Bind\Domain'; + + public function searchDomainAction() + { + return $this->searchBase('domains.domain', array( + "enabled", "type", "masterip", "domainname", "allowtransfer", "allowquery", "ttl", + "refresh", "retry", "expire", "negative", "mailadmin", "dnsserver" + )); + } + + public function getDomainAction($uuid = null) + { + $this->sessionClose(); + return $this->getBase('domain', 'domains.domain', $uuid); + } + + public function addDomainAction($uuid = null) + { + return $this->addBase('domain', 'domains.domain'); + } + + public function delDomainAction($uuid) + { + return $this->delBase('domains.domain', $uuid); + } + + public function setDomainAction($uuid = null) + { + return $this->setBase('domain', 'domains.domain', $uuid); + } + + public function toggleDomainAction($uuid) + { + return $this->toggleBase('domains.domain', $uuid); + } +} diff --git a/dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/Api/RecordController.php b/dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/Api/RecordController.php new file mode 100644 index 000000000..786ef1be8 --- /dev/null +++ b/dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/Api/RecordController.php @@ -0,0 +1,127 @@ + + * Copyright (C) 2019 Deciso B.V. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +namespace OPNsense\Bind\Api; + +use \OPNsense\Base\ApiMutableModelControllerBase; +use \OPNsense\Bind\Domain; +use \OPNsense\Core\Config; + +class RecordController extends ApiMutableModelControllerBase +{ + protected static $internalModelName = 'record'; + protected static $internalModelClass = '\OPNsense\Bind\Record'; + + /** + * update parent domain serial + * @param $uuid string + * @throws \OPNsense\Base\ModelException + * @throws \ReflectionException + */ + private function setDomainSerial($uuid) + { + if ($this->request->isPost()) { + $record = $this->getModel()->getRecord($uuid); + if ($record !== null) { + (new Domain)->updateSerial((string)$record->domain)->serializeToConfig(); + Config::getInstance()->save(); + } + } + } + + public function searchRecordAction() + { + $domain = $this->request->get('domain'); + $filter_funct = null; + if (!empty($domain)) { + $filter_funct = function($record) use ($domain) { + return $record->domain == $domain; + }; + } + + return $this->searchBase('records.record', + array("enabled", "domain", "name", "type", "value"), null, $filter_funct + ); + } + + public function getRecordAction($uuid = null) + { + $this->sessionClose(); + $domain = $this->request->get('domain'); + $result = $this->getBase('record', 'records.record', $uuid); + if ($uuid == null && !empty($result['record']['domain'])) { + // set domain selection + foreach ($result['record']['domain'] as $key => &$value) { + if ($key == $domain) { + $value['selected'] = 1; + } else { + $value['selected'] = 0; + } + } + } + return $result; + } + + public function addRecordAction() + { + $result = $this->addBase('record', 'records.record'); + if (!empty($result['uuid'])) { + $this->setDomainSerial($result['uuid']); + } + return $result; + } + + public function delRecordAction($uuid) + { + $result = $this->delBase('records.record', $uuid); + if ($result['result'] == 'deleted') { + $this->setDomainSerial($uuid); + } + return $result; + } + + public function setRecordAction($uuid = null) + { + $result = $this->setBase('record', 'records.record', $uuid); + if ($result['result'] == 'saved') { + $this->setDomainSerial($uuid); + } + return $result; + } + + public function toggleRecordAction($uuid) + { + $result = $this->toggleBase('records.record', $uuid); + if (!empty($result['changed'])) { + $this->setDomainSerial($uuid); + } + return $result; + } +} diff --git a/dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/GeneralController.php b/dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/GeneralController.php index 991941f1a..3f0b046b8 100644 --- a/dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/GeneralController.php +++ b/dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/GeneralController.php @@ -1,7 +1,7 @@ + Copyright (C) 2018-2019 Michael Muenz All rights reserved. Redistribution and use in source and binary forms, with or without @@ -35,6 +35,8 @@ class GeneralController extends \OPNsense\Base\IndexController $this->view->generalForm = $this->getForm("general"); $this->view->dnsblForm = $this->getForm("dnsbl"); $this->view->formDialogEditBindAcl = $this->getForm("dialogEditBindAcl"); + $this->view->formDialogEditBindDomain = $this->getForm("dialogEditBindDomain"); + $this->view->formDialogEditBindRecord = $this->getForm("dialogEditBindRecord"); $this->view->pick('OPNsense/Bind/general'); } } diff --git a/dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/forms/dialogEditBindDomain.xml b/dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/forms/dialogEditBindDomain.xml new file mode 100644 index 000000000..4d864dca9 --- /dev/null +++ b/dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/forms/dialogEditBindDomain.xml @@ -0,0 +1,80 @@ +
+ + domain.enabled + + checkbox + This will enable or disable the ACL. + + + domain.type + + dropdown + Set the type for this domain. + + + domain.masterip + + text + Set the IP address of master server when using slave mode. + + + domain.domainname + + text + Set the name for this ACL. + + + domain.allowtransfer + + dropdown + Define an ACL where you allow which server can retrieve your zone. + + + domain.allowquery + + dropdown + Define an ACL where you allow which client are allowed to query this domain. + + + domain.ttl + + text + Set the general TTL for this domain. + + + domain.refresh + + text + Set the time in seconds. + + + domain.retry + + text + Set the time in seconds. + + + domain.expire + + text + Set the time in seconds. + + + domain.negative + + text + Set the time in seconds. + + + domain.mailadmin + + text + Set the mail address of domain admin. Please replace @ with a dot. + + + domain.dnsserver + + text + Set the DNS Server hosting this file. This should be the FQDN of your Firewall. + +
diff --git a/dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/forms/dialogEditBindRecord.xml b/dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/forms/dialogEditBindRecord.xml new file mode 100644 index 000000000..4a23a93cf --- /dev/null +++ b/dns/bind/src/opnsense/mvc/app/controllers/OPNsense/Bind/forms/dialogEditBindRecord.xml @@ -0,0 +1,32 @@ +
+ + record.enabled + + checkbox + This will enable or disable the ACL. + + + record.domain + + dropdown + Set the type for this record. + + + record.name + + text + Set the name for this ACL. + + + record.type + + dropdown + Set the time in seconds. + + + record.value + + text + Set the time in seconds. + +
diff --git a/dns/bind/src/opnsense/mvc/app/models/OPNsense/Bind/Domain.php b/dns/bind/src/opnsense/mvc/app/models/OPNsense/Bind/Domain.php new file mode 100644 index 000000000..625f62d7a --- /dev/null +++ b/dns/bind/src/opnsense/mvc/app/models/OPNsense/Bind/Domain.php @@ -0,0 +1,67 @@ + + All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +namespace OPNsense\Bind; + +use OPNsense\Base\BaseModel; + +class Domain extends BaseModel +{ + /** + * {@inheritdoc} + */ + public function serializeToConfig($validateFullModel = false, $disable_validation = false) + { + $serialsToSet = array(); + // collected changed records + foreach ($this->getFlatNodes() as $key => $node) { + if ($node->isFieldChanged() && (string)$node !== "") { + $domain = $node->getParentNode(); + if (empty($serialsToSet[$domain->getAttribute('uuid')])) { + $serialsToSet[$domain->getAttribute('uuid')] = $domain; + } + } + } + // new serials on changed records + foreach ($serialsToSet as $domain) { + $domain->serial = (string)date("YmdHis"); + } + return parent::serializeToConfig($validateFullModel, $disable_validation); + } + + /** + * @param $uuid string domain uuid to update + * @return Domain + */ + public function updateSerial($uuid) + { + foreach ($this->domains->domain->iterateItems() as $domain) { + if ($domain->getAttribute('uuid') == $uuid) { + $domain->serial = (string)date("YmdHis"); + return $this; + } + } + return $this; + } +} diff --git a/dns/bind/src/opnsense/mvc/app/models/OPNsense/Bind/Domain.xml b/dns/bind/src/opnsense/mvc/app/models/OPNsense/Bind/Domain.xml new file mode 100644 index 000000000..d70383914 --- /dev/null +++ b/dns/bind/src/opnsense/mvc/app/models/OPNsense/Bind/Domain.xml @@ -0,0 +1,98 @@ + + //OPNsense/bind/domain + BIND domain configuration + 1.0.0 + + + + + 1 + Y + + + master + Y + + master + slave + + + + N + + + + Y + + + + + + N + N + + + + + + N + N + + + N + + + 86400 + Y + 60 + 86400 + Set a value between 60 and 86400. + + + 21600 + Y + 60 + 86400 + Set a value between 60 and 86400. + + + 3600 + Y + 60 + 86400 + Set a value between 60 and 86400. + + + 3542400 + Y + 60 + 10000000 + Set a value between 60 and 10000000. + + + 3600 + Y + 60 + 86400 + Set a value between 60 and 86400. + + + mail.opnsense.localdomain + Y + + + opnsense.localdomain + Y + + + + + diff --git a/dns/bind/src/opnsense/mvc/app/models/OPNsense/Bind/Record.php b/dns/bind/src/opnsense/mvc/app/models/OPNsense/Bind/Record.php new file mode 100644 index 000000000..f3e157cfd --- /dev/null +++ b/dns/bind/src/opnsense/mvc/app/models/OPNsense/Bind/Record.php @@ -0,0 +1,46 @@ + + Copyright (C) 2019 Deciso B.V. + + All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +namespace OPNsense\Bind; + +use OPNsense\Base\BaseModel; + +class Record extends BaseModel +{ + /** + * @param $uuid string record uuid + * @return mixed record + */ + public function getRecord($uuid) + { + foreach ($this->records->record->iterateItems() as $record) { + if ($record->getAttribute('uuid') == $uuid) { + return $record; + } + } + return null; + } +} diff --git a/dns/bind/src/opnsense/mvc/app/models/OPNsense/Bind/Record.xml b/dns/bind/src/opnsense/mvc/app/models/OPNsense/Bind/Record.xml new file mode 100644 index 000000000..629be39b2 --- /dev/null +++ b/dns/bind/src/opnsense/mvc/app/models/OPNsense/Bind/Record.xml @@ -0,0 +1,46 @@ + + //OPNsense/bind/record + BIND record configuration + 1.0.0 + + + + + 1 + Y + + + Y + + + + + + + N + + + A + Y + + A + AAAA + CNAME + MX + NS + PTR + SRV + TXT + + + + Y + + + + + diff --git a/dns/bind/src/opnsense/mvc/app/views/OPNsense/Bind/general.volt b/dns/bind/src/opnsense/mvc/app/views/OPNsense/Bind/general.volt index 736489d1a..396259dba 100644 --- a/dns/bind/src/opnsense/mvc/app/views/OPNsense/Bind/general.volt +++ b/dns/bind/src/opnsense/mvc/app/views/OPNsense/Bind/general.volt @@ -1,7 +1,7 @@ {# -OPNsense® is Copyright © 2014 – 2018 by Deciso B.V. -This file is Copyright © 2018 by Michael Muenz +OPNsense® is Copyright © 2014 – 2019 by Deciso B.V. +This file is Copyright © 2018 - 2019 by Michael Muenz All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
  • {{ lang._('General') }}
  • {{ lang._('DNSBL') }}
  • {{ lang._('ACLs') }}
  • +
  • {{ lang._('Domains') }}
  • @@ -81,19 +82,80 @@ POSSIBILITY OF SUCH DAMAGE.

    +
    + + + + + + + + + + + + + + + + + + + + + + + +
    {{ lang._('Enabled') }}{{ lang._('Type') }}{{ lang._('Domain') }}{{ lang._('TTL') }}{{ lang._('Refresh') }}{{ lang._('Retry') }}{{ lang._('Expire') }}{{ lang._('Negative TTL') }}{{ lang._('ID') }}{{ lang._('Commands') }}
    + +
    +
    +
    + + + + + + + + + + + + + + + + + + + + +
    {{ lang._('Enabled') }}{{ lang._('Domain') }}{{ lang._('Name') }}{{ lang._('Type') }}{{ lang._('Value') }}{{ lang._('ID') }}{{ lang._('Commands') }}
    + +
    +
    +
    +
    + +

    +
    +
    {{ partial("layout_partials/base_dialog",['fields':formDialogEditBindAcl,'id':'dialogEditBindAcl','label':lang._('Edit ACL')])}} +{{ partial("layout_partials/base_dialog",['fields':formDialogEditBindDomain,'id':'dialogEditBindDomain','label':lang._('Edit Domains')])}} +{{ partial("layout_partials/base_dialog",['fields':formDialogEditBindRecord,'id':'dialogEditBindRecord','label':lang._('Edit Records')])}} diff --git a/dns/bind/src/opnsense/service/templates/OPNsense/Bind/+TARGETS b/dns/bind/src/opnsense/service/templates/OPNsense/Bind/+TARGETS index bf8b53508..33d000bba 100644 --- a/dns/bind/src/opnsense/service/templates/OPNsense/Bind/+TARGETS +++ b/dns/bind/src/opnsense/service/templates/OPNsense/Bind/+TARGETS @@ -1,5 +1,6 @@ bing.db:/usr/local/etc/namedb/master/bing.db blacklist.db:/usr/local/etc/namedb/master/blacklist.db +domain.db:/usr/local/etc/namedb/master/[OPNsense.bind.domain.domains.domain.%.domainname].db duckduckgo.db:/usr/local/etc/namedb/master/duckduckgo.db google.db:/usr/local/etc/namedb/master/google.db named:/etc/rc.conf.d/named diff --git a/dns/bind/src/opnsense/service/templates/OPNsense/Bind/domain.db b/dns/bind/src/opnsense/service/templates/OPNsense/Bind/domain.db new file mode 100644 index 000000000..c5e2edf91 --- /dev/null +++ b/dns/bind/src/opnsense/service/templates/OPNsense/Bind/domain.db @@ -0,0 +1,17 @@ +{% if helpers.exists('OPNsense.bind.general.enabled') and OPNsense.bind.general.enabled == '1' %} +{% if helpers.exists('OPNsense.bind.domain.domains.domain') %} +{% for domaindb in helpers.toList('OPNsense.bind.domain.domains.domain') %} +{% if TARGET_FILTERS['OPNsense.bind.domain.domains.domain.' ~ loop.index0] %} +{% if domaindb.enabled == '1' and domaindb.type == 'master' %} +$TTL {{ domaindb.ttl }} +@ IN SOA {{ domaindb.dnsserver }}. {{ domaindb.mailadmin }}. ( {{ domaindb.serial|trim }} {{ domaindb.refresh }} {{ domaindb.retry }} {{ domaindb.expire }} {{ domaindb.negative }} ) +{% for record in helpers.sortDictList(OPNsense.bind.record.records.record, 'name', 'type' ) %} +{% if record.domain == domaindb['@uuid'] %} +{{ record.name }} {{ record.type }} {{ record.value }} +{% endif %} +{% endfor %} +{% endif %} +{% endif %} +{% endfor %} +{% endif %} +{% endif %} diff --git a/dns/bind/src/opnsense/service/templates/OPNsense/Bind/named.conf b/dns/bind/src/opnsense/service/templates/OPNsense/Bind/named.conf index d27afa622..1995dc309 100644 --- a/dns/bind/src/opnsense/service/templates/OPNsense/Bind/named.conf +++ b/dns/bind/src/opnsense/service/templates/OPNsense/Bind/named.conf @@ -103,6 +103,18 @@ zone "rpzyoutube" { type master; file "/usr/local/etc/namedb/master/youtube.db"; zone "rpzbing" { type master; file "/usr/local/etc/namedb/master/bing.db"; notify no; check-names ignore; }; {% endif %} {% endif %} + +{% if helpers.exists('OPNsense.bind.domain.domains.domain') %} +{% for domain in helpers.toList('OPNsense.bind.domain.domains.domain') %} +{% if domain.enabled == '1' %} +{% set allow_transfer = helpers.getUUID(domain.allowtransfer) %} +{% set allow_query = helpers.getUUID(domain.allowquery) %} +zone "{{ domain.domainname }}" { type {{ domain.type }}; {% if domain.type == 'slave' %}masters { {{ domain.masterip }}; }; file "/usr/local/etc/namedb/slave/{{ domain.domainname }}.db"; {% else %}file "/usr/local/etc/namedb/master/{{ domain.domainname }}.db"; {% endif %}{% if domain.allowtransfer is defined %} allow-transfer { {{ allow_transfer.name }}; };{% endif %}{% if domain.allowquery is defined %} allow-query { {{ allow_query.name }}; };{% endif %} }; +{% endif %} +{% endfor %} +{% endif %} + + logging { channel default_log { file "/var/log/named/named.log" versions 3 size {{ OPNsense.bind.general.logsize }}m;