/*
Technitium DNS Server
Copyright (C) 2022 Shreyas Zare (shreyas@technitium.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
$(function () {
$("input[type=radio][name=rdAddZoneType]").change(function () {
$("#divAddZonePrimaryNameServerAddresses").hide();
$("#divAddZoneZoneTransferProtocol").hide();
$("#divAddZoneTsigKeyName").hide();
$("#divAddZoneForwarderProtocol").hide();
$("#divAddZoneForwarder").hide();
$("#divAddZoneForwarderDnssecValidation").hide();
$("#divAddZoneForwarderProxy").hide();
var zoneType = $('input[name=rdAddZoneType]:checked').val();
switch (zoneType) {
case "Primary":
break;
case "Secondary":
$("#divAddZonePrimaryNameServerAddresses").show();
$("#divAddZoneZoneTransferProtocol").show();
$("#divAddZoneTsigKeyName").show();
break;
case "Stub":
$("#divAddZonePrimaryNameServerAddresses").show();
break;
case "Forwarder":
$("#divAddZoneForwarderProtocol").show();
$("#divAddZoneForwarder").show();
$("#divAddZoneForwarderDnssecValidation").show();
$("#divAddZoneForwarderProxy").show();
break;
}
});
$("input[type=radio][name=rdAddZoneForwarderProtocol]").change(function () {
var protocol = $('input[name=rdAddZoneForwarderProtocol]:checked').val();
switch (protocol) {
case "Udp":
case "Tcp":
$("#txtAddZoneForwarder").attr("placeholder", "8.8.8.8 or [2620:fe::10]")
break;
case "Tls":
$("#txtAddZoneForwarder").attr("placeholder", "dns.quad9.net (9.9.9.9:853)")
break;
case "Https":
case "HttpsJson":
$("#txtAddZoneForwarder").attr("placeholder", "https://cloudflare-dns.com/dns-query (1.1.1.1)")
break;
}
});
$("input[type=radio][name=rdAddZoneForwarderProxyType]").change(function () {
var proxyType = $('input[name=rdAddZoneForwarderProxyType]:checked').val();
$("#txtAddZoneForwarderProxyAddress").prop("disabled", (proxyType === "None"));
$("#txtAddZoneForwarderProxyPort").prop("disabled", (proxyType === "None"));
$("#txtAddZoneForwarderProxyUsername").prop("disabled", (proxyType === "None"));
$("#txtAddZoneForwarderProxyPassword").prop("disabled", (proxyType === "None"));
});
$("input[type=radio][name=rdZoneTransfer]").change(function () {
var zoneTransfer = $('input[name=rdZoneTransfer]:checked').val();
if (zoneTransfer === "AllowOnlySpecifiedNameServers") {
$("#txtZoneTransferNameServers").prop("disabled", false);
}
else {
$("#txtZoneTransferNameServers").prop("disabled", true);
}
});
$("input[type=radio][name=rdZoneNotify]").change(function () {
var zoneTransfer = $('input[name=rdZoneNotify]:checked').val();
if (zoneTransfer === "SpecifiedNameServers") {
$("#txtZoneNotifyNameServers").prop("disabled", false);
}
else {
$("#txtZoneNotifyNameServers").prop("disabled", true);
}
});
$("input[type=radio][name=rdDnssecSignZoneAlgorithm]").change(function () {
var algorithm = $("input[name=rdDnssecSignZoneAlgorithm]:checked").val();
switch (algorithm) {
case "RSA":
$("#divDnssecSignZoneRsaParameters").show();
$("#divDnssecSignZoneEcdsaParameters").hide();
break;
case "ECDSA":
$("#divDnssecSignZoneRsaParameters").hide();
$("#divDnssecSignZoneEcdsaParameters").show();
break;
}
});
$("input[type=radio][name=rdDnssecSignZoneNxProof]").change(function () {
var nxProof = $("input[name=rdDnssecSignZoneNxProof]:checked").val();
switch (nxProof) {
case "NSEC":
$("#divDnssecSignZoneNSEC3Parameters").hide();
break;
case "NSEC3":
$("#divDnssecSignZoneNSEC3Parameters").show();
break;
}
});
$("#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();
$("#divDnssecPropertiesGenerateKeyEcdsaParameters").hide();
break;
case "ECDSA":
$("#divDnssecPropertiesGenerateKeyRsaParameters").hide();
$("#divDnssecPropertiesGenerateKeyEcdsaParameters").show();
break;
}
});
$("input[type=radio][name=rdDnssecPropertiesNxProof]").change(function () {
var nxProof = $("input[name=rdDnssecPropertiesNxProof]:checked").val();
switch (nxProof) {
case "NSEC":
$("#divDnssecPropertiesNSEC3Parameters").hide();
break;
case "NSEC3":
$("#divDnssecPropertiesNSEC3Parameters").show();
break;
}
});
$("#chkAddEditRecordDataPtr").click(function () {
var addPtrRecord = $("#chkAddEditRecordDataPtr").prop('checked');
$("#chkAddEditRecordDataCreatePtrZone").prop('disabled', !addPtrRecord);
});
$("input[type=radio][name=rdAddEditRecordDataForwarderProtocol]").change(updateAddEditFormForwarderPlaceholder);
$("input[type=radio][name=rdAddEditRecordDataForwarderProxyType]").change(updateAddEditFormForwarderProxyType);
$("#optAddEditRecordDataAppName").change(function () {
if (appsList == null)
return;
var appName = $("#optAddEditRecordDataAppName").val();
var optClassPaths = "";
for (var i = 0; i < appsList.length; i++) {
if (appsList[i].name == appName) {
for (var j = 0; j < appsList[i].dnsApps.length; j++) {
if (appsList[i].dnsApps[j].isAppRecordRequestHandler)
optClassPaths += "";
}
break;
}
}
$("#optAddEditRecordDataClassPath").html(optClassPaths);
$("#txtAddEditRecordDataData").val("");
});
$("#optAddEditRecordDataClassPath").change(function () {
if (appsList == null)
return;
var appName = $("#optAddEditRecordDataAppName").val();
var classPath = $("#optAddEditRecordDataClassPath").val();
for (var i = 0; i < appsList.length; i++) {
if (appsList[i].name == appName) {
for (var j = 0; j < appsList[i].dnsApps.length; j++) {
if (appsList[i].dnsApps[j].classPath == classPath) {
$("#txtAddEditRecordDataData").val(appsList[i].dnsApps[j].recordDataTemplate);
return;
}
}
}
}
$("#txtAddEditRecordDataData").val("");
});
$("#optZoneOptionsQuickTsigKeyNames").change(function () {
var selectedOption = $("#optZoneOptionsQuickTsigKeyNames").val();
switch (selectedOption) {
case "blank":
break;
case "none":
$("#txtZoneOptionsZoneTransferTsigKeyNames").val("");
break;
default:
var existingList = $("#txtZoneOptionsZoneTransferTsigKeyNames").val();
if (existingList.indexOf(selectedOption) < 0) {
existingList += selectedOption + "\n";
$("#txtZoneOptionsZoneTransferTsigKeyNames").val(existingList);
}
break;
}
});
});
function refreshZones(checkDisplay) {
if (checkDisplay == null)
checkDisplay = false;
var divViewZones = $("#divViewZones");
if (checkDisplay && (divViewZones.css('display') === "none"))
return;
var divViewZonesLoader = $("#divViewZonesLoader");
var divEditZone = $("#divEditZone");
divViewZones.hide();
divEditZone.hide();
divViewZonesLoader.show();
HTTPRequest({
url: "/api/zone/list?token=" + token,
success: function (responseJSON) {
var zones = responseJSON.response.zones;
var tableHtmlRows = "";
for (var i = 0; i < zones.length; i++) {
var id = Math.floor(Math.random() * 10000);
var name = zones[i].name;
if (name === "")
name = ".";
var type;
if (zones[i].internal)
type = "Internal";
else
type = "" + zones[i].type + "";
var dnssecStatus = "";
switch (zones[i].dnssecStatus) {
case "SignedWithNSEC":
case "SignedWithNSEC3":
dnssecStatus = "DNSSEC";
break;
}
var status = "";
if (zones[i].disabled)
status = "Disabled";
else if (zones[i].isExpired)
status = "Expired";
else
status = "Enabled";
var expiry = zones[i].expiry;
if (expiry == null)
expiry = " ";
else
expiry = moment(expiry).local().format("YYYY-MM-DD HH:mm");
var isReadOnlyZone = zones[i].internal;
var disableOptions;
switch (zones[i].type) {
case "Primary":
case "Secondary":
disableOptions = zones[i].internal;
break;
default:
disableOptions = true;
break;
}
tableHtmlRows += "