dns/bind - use separate tables for master and slave domains

This commit is contained in:
Patrick M. Hausen 2022-08-14 16:20:50 +02:00 committed by Franco Fichtner
parent 4546aeb47d
commit 2fceec5835
7 changed files with 173 additions and 45 deletions

View file

@ -1,5 +1,5 @@
PLUGIN_NAME= bind PLUGIN_NAME= bind
PLUGIN_VERSION= 1.23 PLUGIN_VERSION= 1.24
PLUGIN_COMMENT= BIND domain name service PLUGIN_COMMENT= BIND domain name service
PLUGIN_DEPENDS= bind916 PLUGIN_DEPENDS= bind916
PLUGIN_MAINTAINER= m.muenz@gmail.com PLUGIN_MAINTAINER= m.muenz@gmail.com

View file

@ -9,6 +9,10 @@ WWW: https://www.isc.org
Plugin Changelog Plugin Changelog
================ ================
1.24
* Separate tables for master and slave zones in UI (contributed by Patrick M. Hausen and Manuel Faux)
1.23 1.23
* Avoid errors with repeated primary servers and keys (contributed by Michael Newton) * Avoid errors with repeated primary servers and keys (contributed by Michael Newton)

View file

@ -39,12 +39,20 @@ class DomainController extends ApiMutableModelControllerBase
protected static $internalModelName = 'domain'; protected static $internalModelName = 'domain';
protected static $internalModelClass = '\OPNsense\Bind\Domain'; protected static $internalModelClass = '\OPNsense\Bind\Domain';
public function searchDomainAction() public function searchMasterDomainAction()
{ {
return $this->searchBase('domains.domain', array( return $this->searchBase('domains.domain',
"enabled", "type", "masterip", "domainname", "allowtransfer", "allowquery", "ttl", [ "enabled", "type", "domainname", "ttl", "refresh", "retry", "expire", "negative" ],
"refresh", "retry", "expire", "negative", "mailadmin", "dnsserver" "domainname", function($record){return $record->type->getNodeData()["master"]["selected"] === 1;}
)); );
}
public function searchSlaveDomainAction()
{
return $this->searchBase('domains.domain',
[ "enabled", "type", "domainname", "masterip" ],
"domainname", function($record){return $record->type->getNodeData()["slave"]["selected"] === 1;}
);
} }
public function getDomainAction($uuid = null) public function getDomainAction($uuid = null)
@ -53,9 +61,14 @@ class DomainController extends ApiMutableModelControllerBase
return $this->getBase('domain', 'domains.domain', $uuid); return $this->getBase('domain', 'domains.domain', $uuid);
} }
public function addDomainAction($uuid = null) public function addMasterDomainAction($uuid = null)
{ {
return $this->addBase('domain', 'domains.domain'); return $this->addBase('domain', 'domains.domain', ['type' => 'master']);
}
public function addSlaveDomainAction($uuid = null)
{
return $this->addBase('domain', 'domains.domain', ['type' => 'slave']);
} }
public function delDomainAction($uuid) public function delDomainAction($uuid)

View file

@ -35,7 +35,8 @@ class GeneralController extends \OPNsense\Base\IndexController
$this->view->generalForm = $this->getForm("general"); $this->view->generalForm = $this->getForm("general");
$this->view->dnsblForm = $this->getForm("dnsbl"); $this->view->dnsblForm = $this->getForm("dnsbl");
$this->view->formDialogEditBindAcl = $this->getForm("dialogEditBindAcl"); $this->view->formDialogEditBindAcl = $this->getForm("dialogEditBindAcl");
$this->view->formDialogEditBindDomain = $this->getForm("dialogEditBindDomain"); $this->view->formDialogEditBindMasterDomain = $this->getForm("dialogEditBindMasterDomain");
$this->view->formDialogEditBindSlaveDomain = $this->getForm("dialogEditBindSlaveDomain");
$this->view->formDialogEditBindRecord = $this->getForm("dialogEditBindRecord"); $this->view->formDialogEditBindRecord = $this->getForm("dialogEditBindRecord");
$this->view->pick('OPNsense/Bind/general'); $this->view->pick('OPNsense/Bind/general');
} }

View file

@ -0,0 +1,54 @@
<form>
<field>
<id>domain.enabled</id>
<label>Enabled</label>
<type>checkbox</type>
<help>This will enable or disable this zone.</help>
</field>
<field>
<id>domain.domainname</id>
<label>Zone Name</label>
<type>text</type>
<help>Set the name for this zone. Both forward and reverse zones may be specified, i.e. example.com or 0.168.192.in-addr.arpa.</help>
</field>
<field>
<id>domain.allowtransfer</id>
<label>Allow Transfer</label>
<type>dropdown</type>
<help>Define an ACL where you allow which server can retrieve this zone.</help>
</field>
<field>
<id>domain.allowquery</id>
<label>Allow Query</label>
<type>dropdown</type>
<help>Define an ACL where you allow which client are allowed to query this zone.</help>
</field>
<field>
<id>domain.masterip</id>
<label>Master IP</label>
<style>tokenize</style>
<type>select_multiple</type>
<allownew>true</allownew>
<help>Set the IP address of master server when using slave mode.</help>
</field>
<field>
<id>domain.transferkeyalgo</id>
<label>Transfer Key Algorithm</label>
<type>dropdown</type>
<help>Set the authentication algorithm for the TSIG key.</help>
</field>
<field>
<id>domain.transferkey</id>
<label>Transfer Key</label>
<type>text</type>
<help>The TSIG key used to transfer domain data from the master server.</help>
</field>
<field>
<id>domain.allownotifyslave</id>
<label>Allow Notfiy</label>
<style>tokenize</style>
<type>select_multiple</type>
<allownew>true</allownew>
<help>A list of allowed IP addresses to receive notifies from.</help>
</field>
</form>

View file

@ -32,7 +32,8 @@ POSSIBILITY OF SUCH DAMAGE.
<li class="active"><a data-toggle="tab" href="#general">{{ lang._('General') }}</a></li> <li class="active"><a data-toggle="tab" href="#general">{{ lang._('General') }}</a></li>
<li><a data-toggle="tab" href="#dnsbl">{{ lang._('DNSBL') }}</a></li> <li><a data-toggle="tab" href="#dnsbl">{{ lang._('DNSBL') }}</a></li>
<li><a data-toggle="tab" href="#acls">{{ lang._('ACLs') }}</a></li> <li><a data-toggle="tab" href="#acls">{{ lang._('ACLs') }}</a></li>
<li><a data-toggle="tab" href="#domains">{{ lang._('Zones') }}</a></li> <li><a data-toggle="tab" href="#master-domains">{{ lang._('Master Zones') }}</a></li>
<li><a data-toggle="tab" href="#slave-domains">{{ lang._('Slave Zones') }}</a></li>
</ul> </ul>
<div class="tab-content content-box tab-content"> <div class="tab-content content-box tab-content">
@ -83,11 +84,11 @@ POSSIBILITY OF SUCH DAMAGE.
<br /><br /> <br /><br />
</div> </div>
</div> </div>
<div id="domains" class="tab-pane fade in"> <div id="master-domains" class="tab-pane fade in">
<div class="alert alert-warning" role="alert" style="min-height:65px;"> <div class="col-md-12">
<div style="margin-top: 8px;">{{ lang._('Zone management is still in experimental state, use with caution.') }}</div> <h2>{{ lang._('Zones') }}</h2>
</div> </div>
<table id="grid-domains" class="table table-condensed table-hover table-striped table-responsive" data-editAlert="ChangeMessage" data-editDialog="dialogEditBindDomain"> <table id="grid-master-domains" class="table table-condensed table-hover table-striped table-responsive" data-editAlert="ChangeMessage" data-editDialog="dialogEditBindMasterDomain">
<thead> <thead>
<tr> <tr>
<th data-column-id="enabled" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th> <th data-column-id="enabled" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
@ -109,17 +110,16 @@ POSSIBILITY OF SUCH DAMAGE.
<td colspan="5"></td> <td colspan="5"></td>
<td> <td>
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button> <button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
<button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button>
</td> </td>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
<hr/> <hr/>
<div class="col-md-12"> <div id="master-record-area">
<h2>{{ lang._('Records') }}</h2> <div class="col-md-12">
</div> <h2>{{ lang._('Records') }}</h2>
<div id="record-area"> </div>
<table id="grid-records" class="table table-condensed table-hover table-striped table-responsive" data-editAlert="ChangeMessage" data-editDialog="dialogEditBindRecord"> <table id="grid-master-records" class="table table-condensed table-hover table-striped table-responsive" data-editAlert="ChangeMessage" data-editDialog="dialogEditBindRecord">
<thead> <thead>
<tr> <tr>
<th data-column-id="enabled" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th> <th data-column-id="enabled" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
@ -149,14 +149,51 @@ POSSIBILITY OF SUCH DAMAGE.
{{ lang._('After changing settings, please remember to apply them with the button below') }} {{ lang._('After changing settings, please remember to apply them with the button below') }}
</div> </div>
<hr /> <hr />
<button class="btn btn-primary" id="saveAct_domain" type="button"><b>{{ lang._('Save') }}</b> <i id="saveAct_domain_progress"></i></button> <button class="btn btn-primary saveAct_domain" type="button"><b>{{ lang._('Save') }}</b> <i class="saveAct_domain_progress"></i></button>
<br /><br />
</div>
</div>
<div id="slave-domains" class="tab-pane fade in">
<div class="col-md-12">
<h2>{{ lang._('Zones') }}</h2>
</div>
<table id="grid-slave-domains" class="table table-condensed table-hover table-striped table-responsive" data-editAlert="ChangeMessage" data-editDialog="dialogEditBindSlaveDomain">
<thead>
<tr>
<th data-column-id="enabled" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
<th data-column-id="type" data-type="string" data-visible="true">{{ lang._('Type') }}</th>
<th data-column-id="domainname" data-type="string" data-visible="true">{{ lang._('Zone') }}</th>
<th data-column-id="masterip" data-type="string" data-visible="true">{{ lang._('Master IPs') }}</th>
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
<th data-column-id="commands" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td colspan="5"></td>
<td>
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
</td>
</tr>
</tfoot>
</table>
<hr/>
<div class="col-md-12">
<div id="ChangeMessage" class="alert alert-info" style="display: none" role="alert">
{{ lang._('After changing settings, please remember to apply them with the button below') }}
</div>
<hr />
<button class="btn btn-primary saveAct_domain" type="button"><b>{{ lang._('Save') }}</b> <i class="saveAct_domain_progress"></i></button>
<br /><br /> <br /><br />
</div> </div>
</div> </div>
</div> </div>
{{ partial("layout_partials/base_dialog",['fields':formDialogEditBindAcl,'id':'dialogEditBindAcl','label':lang._('Edit ACL')])}} {{ 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 Zone')])}} {{ partial("layout_partials/base_dialog",['fields':formDialogEditBindMasterDomain,'id':'dialogEditBindMasterDomain','label':lang._('Edit Master Zone')])}}
{{ partial("layout_partials/base_dialog",['fields':formDialogEditBindSlaveDomain,'id':'dialogEditBindSlaveDomain','label':lang._('Edit Slave Zone')])}}
{{ partial("layout_partials/base_dialog",['fields':formDialogEditBindRecord,'id':'dialogEditBindRecord','label':lang._('Edit Record')])}} {{ partial("layout_partials/base_dialog",['fields':formDialogEditBindRecord,'id':'dialogEditBindRecord','label':lang._('Edit Record')])}}
<script> <script>
@ -184,11 +221,12 @@ $( document ).ready(function() {
'toggle':'/api/bind/acl/toggleAcl/' 'toggle':'/api/bind/acl/toggleAcl/'
} }
); );
$("#grid-domains").UIBootgrid({
'search':'/api/bind/domain/searchDomain', $("#grid-master-domains").UIBootgrid({
'search':'/api/bind/domain/searchMasterDomain',
'get':'/api/bind/domain/getDomain/', 'get':'/api/bind/domain/getDomain/',
'set':'/api/bind/domain/setDomain/', 'set':'/api/bind/domain/setDomain/',
'add':'/api/bind/domain/addDomain/', 'add':'/api/bind/domain/addMasterDomain/',
'del':'/api/bind/domain/delDomain/', 'del':'/api/bind/domain/delDomain/',
'toggle':'/api/bind/domain/toggleDomain/', 'toggle':'/api/bind/domain/toggleDomain/',
options:{ options:{
@ -198,17 +236,37 @@ $( document ).ready(function() {
rowCount: [3,7,14,20,50,100,-1] rowCount: [3,7,14,20,50,100,-1]
} }
}).on("selected.rs.jquery.bootgrid", function(e, rows) { }).on("selected.rs.jquery.bootgrid", function(e, rows) {
$("#grid-records").bootgrid('reload'); $("#grid-master-records").bootgrid('reload');
}).on("deselected.rs.jquery.bootgrid", function(e, rows) { }).on("deselected.rs.jquery.bootgrid", function(e, rows) {
$("#grid-records").bootgrid('reload'); $("#grid-master-records").bootgrid('reload');
}).on("loaded.rs.jquery.bootgrid", function (e) { }).on("loaded.rs.jquery.bootgrid", function (e) {
let ids = $("#grid-domains").bootgrid("getCurrentRows"); let ids = $("#grid-master-domains").bootgrid("getCurrentRows");
if (ids.length > 0) { if (ids.length > 0) {
$("#grid-domains").bootgrid('select', [ids[0].uuid]); $("#grid-master-domains").bootgrid('select', [ids[0].uuid]);
} }
}); });
$("#grid-records").UIBootgrid({ $("#grid-slave-domains").UIBootgrid({
'search':'/api/bind/domain/searchSlaveDomain',
'get':'/api/bind/domain/getDomain/',
'set':'/api/bind/domain/setDomain/',
'add':'/api/bind/domain/addSlaveDomain/',
'del':'/api/bind/domain/delDomain/',
'toggle':'/api/bind/domain/toggleDomain/',
options:{
selection: false,
multiSelect: false,
rowSelect: false,
rowCount: [7,14,20,50,100,-1]
}
}).on("loaded.rs.jquery.bootgrid", function (e) {
let ids = $("#grid-slave-domains").bootgrid("getCurrentRows");
if (ids.length > 0) {
$("#grid-slave-domains").bootgrid('select', [ids[0].uuid]);
}
});
$("#grid-master-records").UIBootgrid({
'search':'/api/bind/record/searchRecord', 'search':'/api/bind/record/searchRecord',
'get':'/api/bind/record/getRecord/', 'get':'/api/bind/record/getRecord/',
'set':'/api/bind/record/setRecord/', 'set':'/api/bind/record/setRecord/',
@ -218,17 +276,17 @@ $( document ).ready(function() {
options:{ options:{
useRequestHandlerOnGet: true, useRequestHandlerOnGet: true,
requestHandler: function(request) { requestHandler: function(request) {
let ids = $("#grid-domains").bootgrid("getSelectedRows"); let ids = $("#grid-master-domains").bootgrid("getSelectedRows");
if (ids.length > 0) { if (ids.length > 0) {
request['domain'] = ids[0]; request['domain'] = ids[0];
$("#recordAddBtn").show(); $("#recordAddBtn").show();
$("#recordDelBtn").show(); $("#recordDelBtn").show();
$("#record-area").show(); $("#master-record-area").show();
} else { } else {
request['domain'] = 'not_found'; request['domain'] = 'not_found';
$("#recordAddBtn").hide(); $("#recordAddBtn").hide();
$("#recordDelBtn").hide(); $("#recordDelBtn").hide();
$("#record-area").hide(); $("#master-record-area").hide();
} }
return request; return request;
} }
@ -267,11 +325,11 @@ $( document ).ready(function() {
}); });
}); });
$("#saveAct_domain").click(function(){ $(".saveAct_domain").click(function(){
$("#saveAct_domain_progress").addClass("fa fa-spinner fa-pulse"); $(".saveAct_domain_progress").addClass("fa fa-spinner fa-pulse");
ajaxCall("/api/bind/service/reconfigure", {}, function(data,status) { ajaxCall("/api/bind/service/reconfigure", {}, function(data,status) {
updateServiceControlUI('bind'); updateServiceControlUI('bind');
$("#saveAct_domain_progress").removeClass("fa fa-spinner fa-pulse"); $(".saveAct_domain_progress").removeClass("fa fa-spinner fa-pulse");
}); });
}); });
@ -283,14 +341,12 @@ $( document ).ready(function() {
} }
}); });
// Hide options that are irrelevant in this context. // update history on tab state and implement navigation
$('#dialogEditBindDomain').on('shown.bs.modal', function (e) { if(window.location.hash != "") {
$("#domain\\.type").change(function(){ $('a[href="' + window.location.hash + '"]').click()
$(".zone_type").hide(); }
$(".zone_type_"+$(this).val()).show(); $('.nav-tabs a').on('shown.bs.tab', function (e) {
}); history.pushState(null, null, e.target.hash);
$("#domain\\.type").change(); });
})
}); });
</script> </script>