From 297a05ff2d6b605bc11df27fd43e1bafb6bb8144 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 26 Mar 2022 12:18:25 +0530 Subject: [PATCH] zone.js: Updated code for auto key rollover feature implementation changes. Updated code for DNSSEC API changes. --- DnsServerCore/www/js/zone.js | 134 ++++++++++++++++++++--------------- 1 file changed, 78 insertions(+), 56 deletions(-) diff --git a/DnsServerCore/www/js/zone.js b/DnsServerCore/www/js/zone.js index 207643be..b98d22c6 100644 --- a/DnsServerCore/www/js/zone.js +++ b/DnsServerCore/www/js/zone.js @@ -127,8 +127,23 @@ $(function () { } }); - $("#optDnssecPropertiedGenerateKeyAlgorithm").change(function () { - var algorithm = $("#optDnssecPropertiedGenerateKeyAlgorithm").val(); + $("#optDnssecPropertiesGenerateKeyKeyType").change(function () { + var keyType = $("#optDnssecPropertiesGenerateKeyKeyType").val(); + switch (keyType) { + case "ZoneSigningKey": + $("#divDnssecPropertiesGenerateKeyAutomaticRollover").show(); + $("#txtDnssecPropertiesGenerateKeyAutomaticRollover").val(90); + break; + + default: + $("#divDnssecPropertiesGenerateKeyAutomaticRollover").hide(); + $("#txtDnssecPropertiesGenerateKeyAutomaticRollover").val(0); + break; + } + }); + + $("#optDnssecPropertiesGenerateKeyAlgorithm").change(function () { + var algorithm = $("#optDnssecPropertiesGenerateKeyAlgorithm").val(); switch (algorithm) { case "RSA": $("#divDnssecPropertiesGenerateKeyRsaParameters").show(); @@ -984,7 +999,7 @@ function showEditZone(domain) { tableHtmlRows += "" + htmlEncode(records[i].rData.ipAddress); if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -1003,7 +1018,7 @@ function showEditZone(domain) { } if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -1014,7 +1029,7 @@ function showEditZone(domain) { tableHtmlRows += "" + htmlEncode(records[i].rData.cname); if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -1055,7 +1070,7 @@ function showEditZone(domain) { } if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -1072,7 +1087,7 @@ function showEditZone(domain) { tableHtmlRows += "" + htmlEncode(records[i].rData.ptrName); if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -1084,7 +1099,7 @@ function showEditZone(domain) { "
Exchange: " + htmlEncode(records[i].rData.exchange); if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -1096,7 +1111,7 @@ function showEditZone(domain) { tableHtmlRows += "" + htmlEncode(records[i].rData.text); if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -1110,7 +1125,7 @@ function showEditZone(domain) { "
Target: " + htmlEncode(records[i].rData.target); if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -1124,7 +1139,7 @@ function showEditZone(domain) { tableHtmlRows += "" + htmlEncode(records[i].rData.dname); if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -1138,7 +1153,7 @@ function showEditZone(domain) { "
Digest: " + htmlEncode(records[i].rData.digest); if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -1160,7 +1175,7 @@ function showEditZone(domain) { "
Signature: " + htmlEncode(records[i].rData.signature); if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -1181,7 +1196,7 @@ function showEditZone(domain) { "
Types: " + htmlEncode(nsecTypes); if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -1207,7 +1222,7 @@ function showEditZone(domain) { } if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -1232,7 +1247,7 @@ function showEditZone(domain) { "
Types: " + htmlEncode(nsec3Types); if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -1246,7 +1261,7 @@ function showEditZone(domain) { "
Salt: " + htmlEncode(records[i].rData.salt); if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -1259,7 +1274,7 @@ function showEditZone(domain) { "
Authority: " + htmlEncode(records[i].rData.value); if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -1272,7 +1287,7 @@ function showEditZone(domain) { tableHtmlRows += "" + htmlEncode(records[i].rData.aname); if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -1293,7 +1308,7 @@ function showEditZone(domain) { } if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -1313,10 +1328,10 @@ function showEditZone(domain) { case "APP": tableHtmlRows += "App Name: " + htmlEncode(records[i].rData.appName) + "
Class Path: " + htmlEncode(records[i].rData.classPath) + - "
Record Data: " + (records[i].rData.data == "" ? "" : "
" + htmlEncode(records[i].rData.data) + "
"); + "
Record Data: " + (records[i].rData.data == "" ? "" : "
" + htmlEncode(records[i].rData.data) + "
"); if ((records[i].comments != null) && (records[i].comments.length > 0)) - tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; + tableHtmlRows += "

Comments:
" + htmlEncode(records[i].comments) + "
"; tableHtmlRows += ""; @@ -3027,12 +3042,14 @@ function showDnssecPropertiesModal(zoneName) { $("#lblDnssecPropertiesZoneName").text(zoneName); $("#divDnssecPropertiesGenerateKey").collapse("hide"); - $("#optDnssecPropertiedGenerateKeyKeyType").val("KeySigningKey"); + $("#optDnssecPropertiesGenerateKeyKeyType").val("KeySigningKey"); + $("#divDnssecPropertiesGenerateKeyAutomaticRollover").hide(); + $("#txtDnssecPropertiesGenerateKeyAutomaticRollover").val(0); $("#divDnssecPropertiesGenerateKeyRsaParameters").hide(); $("#optDnssecPropertiesGenerateKeyRsaHashAlgorithm").val("SHA256"); $("#optDnssecPropertiesGenerateKeyRsaKeySize").val("1024"); $("#divDnssecPropertiesGenerateKeyEcdsaParameters").show(); - $("#optDnssecPropertiedGenerateKeyAlgorithm").val("ECDSA"); + $("#optDnssecPropertiesGenerateKeyAlgorithm").val("ECDSA"); divDnssecPropertiesLoader.show(); divDnssecProperties.hide(); @@ -3060,18 +3077,22 @@ function refreshDnssecProperties(divDnssecPropertiesLoader) { + "" + responseJSON.response.dnssecPrivateKeys[i].algorithm + "" + "" + responseJSON.response.dnssecPrivateKeys[i].state + "" + "" + moment(responseJSON.response.dnssecPrivateKeys[i].stateChangedOn).local().format("YYYY-MM-DD HH:mm") + "" + + "" + (responseJSON.response.dnssecPrivateKeys[i].keyType === "ZoneSigningKey" ? + "" + + "" + : "-") + "" + ""; switch (responseJSON.response.dnssecPrivateKeys[i].state) { case "Generated": - tableHtmlRows += ""; + tableHtmlRows += ""; break; case "Ready": case "Active": if (!responseJSON.response.dnssecPrivateKeys[i].isRetiring) { tableHtmlRows += ""; - tableHtmlRows += ""; + tableHtmlRows += ""; } break; } @@ -3106,7 +3127,6 @@ function refreshDnssecProperties(divDnssecPropertiesLoader) { } $("#txtDnssecPropertiesDnsKeyTtl").val(responseJSON.response.dnsKeyTtl); - $("#txtDnssecPropertiesZskAutoRollover").val(responseJSON.response.zskRolloverDays); if (divDnssecPropertiesLoader != null) divDnssecPropertiesLoader.hide(); @@ -3126,6 +3146,33 @@ function refreshDnssecProperties(divDnssecPropertiesLoader) { }); } +function updateDnssecPrivateKey(keyTag, objBtn) { + var btn = $(objBtn); + var id = btn.attr("data-id"); + var divDnssecPropertiesAlert = $("#divDnssecPropertiesAlert"); + var zone = $("#lblDnssecPropertiesZoneName").text(); + var rolloverDays = $("#txtDnssecPropertiesPrivateKeyAutomaticRollover" + id).val(); + + btn.button('loading'); + + HTTPRequest({ + url: "/api/zone/dnssec/updatePrivateKey?token=" + token + "&zone=" + zone + "&keyTag=" + keyTag + "&rolloverDays=" + rolloverDays, + success: function (responseJSON) { + btn.button('reset'); + showAlert("success", "Updated!", "The DNSKEY automatic rollover config was updated successfully.", divDnssecPropertiesAlert); + }, + error: function () { + btn.button('reset'); + }, + invalidToken: function () { + btn.button('reset'); + $("#modalDnssecProperties").modal("hide"); + showPageLogin(); + }, + objAlertPlaceholder: divDnssecPropertiesAlert + }); +} + function deleteDnssecPrivateKey(keyTag, objBtn) { if (!confirm("Are you sure to permanently delete the private key?")) return; @@ -3241,8 +3288,9 @@ function generateAndAddDnssecPrivateKey(objBtn) { var btn = $(objBtn); var divDnssecPropertiesAlert = $("#divDnssecPropertiesAlert"); var zone = $("#lblDnssecPropertiesZoneName").text(); - var keyType = $("#optDnssecPropertiedGenerateKeyKeyType").val(); - var algorithm = $("#optDnssecPropertiedGenerateKeyAlgorithm").val(); + var keyType = $("#optDnssecPropertiesGenerateKeyKeyType").val(); + var algorithm = $("#optDnssecPropertiesGenerateKeyAlgorithm").val(); + var rolloverDays = $("#txtDnssecPropertiesGenerateKeyAutomaticRollover").val(); var additionalParameters = ""; @@ -3264,7 +3312,7 @@ function generateAndAddDnssecPrivateKey(objBtn) { btn.button('loading'); HTTPRequest({ - url: "/api/zone/dnssec/generatePrivateKey?token=" + token + "&zone=" + zone + "&keyType=" + keyType + "&algorithm=" + algorithm + additionalParameters, + url: "/api/zone/dnssec/generatePrivateKey?token=" + token + "&zone=" + zone + "&keyType=" + keyType + "&rolloverDays=" + rolloverDays + "&algorithm=" + algorithm + additionalParameters, success: function (responseJSON) { $("#divDnssecPropertiesGenerateKey").collapse("hide"); refreshDnssecProperties(); @@ -3392,29 +3440,3 @@ function updateDnssecDnsKeyTtl(objBtn) { objAlertPlaceholder: divDnssecPropertiesAlert }); } - -function updateDnssecDnsKeyAutomaticRollover(objBtn) { - var btn = $(objBtn); - var divDnssecPropertiesAlert = $("#divDnssecPropertiesAlert"); - var zone = $("#lblDnssecPropertiesZoneName").text(); - var zskRolloverDays = $("#txtDnssecPropertiesZskAutoRollover").val(); - - btn.button('loading'); - - HTTPRequest({ - url: "/api/zone/dnssec/updateDnsKeyRollover?token=" + token + "&zone=" + zone + "&zskRolloverDays=" + zskRolloverDays, - success: function (responseJSON) { - btn.button('reset'); - showAlert("success", "Rollover Updated!", "The DNSKEY automatic rollover config was updated successfully.", divDnssecPropertiesAlert); - }, - error: function () { - btn.button('reset'); - }, - invalidToken: function () { - btn.button('reset'); - $("#modalDnssecProperties").modal("hide"); - showPageLogin(); - }, - objAlertPlaceholder: divDnssecPropertiesAlert - }); -}