From c2a4c95b6e3f75d596c4d08ec43640ab2b2358a1 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sun, 30 Oct 2022 19:09:14 +0530 Subject: [PATCH] zone.js: updated implementation to support dynamic updates security policy feature. --- DnsServerCore/www/js/zone.js | 164 ++++++++++++++++++++--------------- 1 file changed, 92 insertions(+), 72 deletions(-) diff --git a/DnsServerCore/www/js/zone.js b/DnsServerCore/www/js/zone.js index bf24622d..f790116e 100644 --- a/DnsServerCore/www/js/zone.js +++ b/DnsServerCore/www/js/zone.js @@ -17,6 +17,8 @@ along with this program. If not, see . */ +var zoneOptionsAvailableTsigKeyNames; + $(function () { $("input[type=radio][name=rdAddZoneType]").change(function () { $("#divAddZonePrimaryNameServerAddresses").hide(); @@ -267,28 +269,6 @@ $(function () { break; } }); - - $("#optZoneOptionsQuickTsigKeyNames2").change(function () { - var selectedOption = $("#optZoneOptionsQuickTsigKeyNames2").val(); - switch (selectedOption) { - case "blank": - break; - - case "none": - $("#txtDynamicUpdateTsigKeyNames").val(""); - break; - - default: - var existingList = $("#txtDynamicUpdateTsigKeyNames").val(); - - if (existingList.indexOf(selectedOption) < 0) { - existingList += selectedOption + "\n"; - $("#txtDynamicUpdateTsigKeyNames").val(existingList); - } - - break; - } - }); }); function refreshZones(checkDisplay) { @@ -612,6 +592,50 @@ function deleteZone(objBtn) { }); } +function addZoneOptionsDynamicUpdatesSecurityPolicyRow(id, tsigKeyName, domain, allowedTypes) { + var tbodyDynamicUpdateSecurityPolicy = $("#tbodyDynamicUpdateSecurityPolicy"); + + if (id == null) { + id = Math.floor(Math.random() * 10000); + + if (tbodyDynamicUpdateSecurityPolicy.is(":empty")) { + tsigKeyName = null; + domain = $("#lblZoneOptionsZoneName").attr("data-zone"); + allowedTypes = 'A,AAAA'.split(','); + } + } + + var tableHtmlRow = ""; + tableHtmlRow += ""; + tableHtmlRow += ""; + tableHtmlRow += ""; + + tbodyDynamicUpdateSecurityPolicy.append(tableHtmlRow); +} + function showZoneOptionsModal(zone) { var divZoneOptionsAlert = $("#divZoneOptionsAlert"); var divZoneOptionsLoader = $("#divZoneOptionsLoader"); @@ -721,63 +745,59 @@ function showZoneOptionsModal(zone) { $("#txtZoneNotifyNameServers").val(value); } - //dynamic update - switch (responseJSON.response.update) { - case "Allow": - $("#rdDynamicUpdateAllow").prop("checked", true); - break; + if (responseJSON.response.type == "Primary") { + //dynamic update + switch (responseJSON.response.update) { + case "Allow": + $("#rdDynamicUpdateAllow").prop("checked", true); + break; - case "AllowOnlyZoneNameServers": - $("#rdDynamicUpdateAllowOnlyZoneNameServers").prop("checked", true); - break; + case "AllowOnlyZoneNameServers": + $("#rdDynamicUpdateAllowOnlyZoneNameServers").prop("checked", true); + break; - case "AllowOnlySpecifiedIpAddresses": - $("#rdDynamicUpdateAllowOnlySpecifiedIpAddresses").prop("checked", true); - $("#txtDynamicUpdateIpAddresses").prop("disabled", false); - break; + case "AllowOnlySpecifiedIpAddresses": + $("#rdDynamicUpdateAllowOnlySpecifiedIpAddresses").prop("checked", true); + $("#txtDynamicUpdateIpAddresses").prop("disabled", false); + break; - case "AllowBothZoneNameServersAndSpecifiedIpAddresses": - $("#rdDynamicUpdateAllowBothZoneNameServersAndSpecifiedIpAddresses").prop("checked", true); - $("#txtDynamicUpdateIpAddresses").prop("disabled", false); - break; + case "AllowBothZoneNameServersAndSpecifiedIpAddresses": + $("#rdDynamicUpdateAllowBothZoneNameServersAndSpecifiedIpAddresses").prop("checked", true); + $("#txtDynamicUpdateIpAddresses").prop("disabled", false); + break; - case "Deny": - default: - $("#rdDynamicUpdateDeny").prop("checked", true); - break; - } + case "Deny": + default: + $("#rdDynamicUpdateDeny").prop("checked", true); + break; + } - { - var value = ""; + { + var value = ""; - for (var i = 0; i < responseJSON.response.updateIpAddresses.length; i++) - value += responseJSON.response.updateIpAddresses[i] + "\r\n"; + for (var i = 0; i < responseJSON.response.updateIpAddresses.length; i++) + value += responseJSON.response.updateIpAddresses[i] + "\r\n"; - $("#txtDynamicUpdateIpAddresses").val(value); - } + $("#txtDynamicUpdateIpAddresses").val(value); + } - { - var value = ""; + { + $("#tbodyDynamicUpdateSecurityPolicy").html(""); + zoneOptionsAvailableTsigKeyNames = responseJSON.response.availableTsigKeyNames; - if (responseJSON.response.updateTsigKeyNames != null) { - for (var i = 0; i < responseJSON.response.updateTsigKeyNames.length; i++) { - value += responseJSON.response.updateTsigKeyNames[i] + "\r\n"; + if (responseJSON.response.updateSecurityPolicies != null) { + for (var i = 0; i < responseJSON.response.updateSecurityPolicies.length; i++) + addZoneOptionsDynamicUpdatesSecurityPolicyRow(i, responseJSON.response.updateSecurityPolicies[i].tsigKeyName, responseJSON.response.updateSecurityPolicies[i].domain, responseJSON.response.updateSecurityPolicies[i].allowedTypes); } } - $("#txtDynamicUpdateTsigKeyNames").val(value); + $("#tabListZoneOptionsUpdate").show(); } - - { - var options = ""; - - if (responseJSON.response.availableTsigKeyNames != null) { - for (var i = 0; i < responseJSON.response.availableTsigKeyNames.length; i++) { - options += ""; - } - } - - $("#optZoneOptionsQuickTsigKeyNames2").html(options); + else { + $("#tabListZoneOptionsUpdate").hide(); + $("#rdDynamicUpdateDeny").prop("checked", true); + $("#txtDynamicUpdateIpAddresses").val(""); + $("#tbodyDynamicUpdateSecurityPolicy").html(""); } $("#tabListZoneOptionsZoneTranfer").addClass("active"); @@ -844,12 +864,12 @@ function saveZoneOptions() { else $("#txtDynamicUpdateIpAddresses").val(updateIpAddresses.replace(/,/g, "\n")); - var updateTsigKeyNames = cleanTextList($("#txtDynamicUpdateTsigKeyNames").val()); + var updateSecurityPolicies = serializeTableData($("#tableDynamicUpdateSecurityPolicy"), 3, divZoneOptionsAlert); + if (updateSecurityPolicies === false) + return; - if ((updateTsigKeyNames.length === 0) || (updateTsigKeyNames === ",")) - updateTsigKeyNames = false; - else - $("#txtDynamicUpdateTsigKeyNames").val(updateTsigKeyNames.replace(/,/g, "\n")); + if (updateSecurityPolicies.length === 0) + updateSecurityPolicies = false; var btn = $("#btnSaveZoneOptions"); btn.button('loading'); @@ -858,7 +878,7 @@ function saveZoneOptions() { url: "/api/zones/options/set?token=" + sessionData.token + "&zone=" + zone + "&zoneTransfer=" + zoneTransfer + "&zoneTransferNameServers=" + encodeURIComponent(zoneTransferNameServers) + "&zoneTransferTsigKeyNames=" + encodeURIComponent(zoneTransferTsigKeyNames) + "¬ify=" + notify + "¬ifyNameServers=" + encodeURIComponent(notifyNameServers) - + "&update=" + update + "&updateIpAddresses=" + encodeURIComponent(updateIpAddresses) + "&updateTsigKeyNames=" + encodeURIComponent(updateTsigKeyNames), + + "&update=" + update + "&updateIpAddresses=" + encodeURIComponent(updateIpAddresses) + "&updateSecurityPolicies=" + encodeURIComponent(updateSecurityPolicies), success: function (responseJSON) { btn.button('reset'); $("#modalZoneOptions").modal("hide");