/*
Technitium DNS Server
Copyright (C) 2026 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 () {
$("#chkDhcpScopeDnsUpdates").on("click", function () {
var checked = $("#chkDhcpScopeDnsUpdates").prop("checked");
$("#chkDnsOverwriteForDynamicLease").prop("disabled", !checked);
});
});
function refreshDhcpTab() {
if ($("#dhcpTabListLeases").hasClass("active"))
refreshDhcpLeases();
else if ($("#dhcpTabListScopes").hasClass("active"))
refreshDhcpScopes(true);
else
refreshDhcpLeases();
}
function refreshDhcpLeases() {
var node = $("#optDhcpClusterNode").val();
var divDhcpLeasesLoader = $("#divDhcpLeasesLoader");
var divDhcpLeases = $("#divDhcpLeases");
divDhcpLeases.hide();
divDhcpLeasesLoader.show();
HTTPRequest({
url: "api/dhcp/leases/list?node=" + encodeURIComponent(node),
token: sessionData.token,
success: function (responseJSON) {
var dhcpLeases = responseJSON.response.leases;
var tableHtmlRows = "";
for (var i = 0; i < dhcpLeases.length; i++) {
tableHtmlRows += "
";
}
$("#tableDhcpScopesBody").html(tableHtmlRows);
if (dhcpScopes.length > 0)
$("#tableDhcpScopesFooter").html("
Total Scopes: " + dhcpScopes.length + "
");
else
$("#tableDhcpScopesFooter").html("
No Scope Found
");
divDhcpViewScopesLoader.hide();
divDhcpViewScopes.show();
},
invalidToken: function () {
showPageLogin();
},
objLoaderPlaceholder: divDhcpViewScopesLoader
});
}
function addDhcpScopeStaticRouteRow(destination, subnetMask, router) {
var id = Math.floor(Math.random() * 10000);
var tableHtmlRows = "
";
tableHtmlRows += "
";
tableHtmlRows += "
";
tableHtmlRows += "
";
$("#tableDhcpScopeStaticRoutes").append(tableHtmlRows);
}
function addDhcpScopeVendorInfoRow(identifier, information) {
var id = Math.floor(Math.random() * 10000);
var tableHtmlRows = "
";
tableHtmlRows += "
";
tableHtmlRows += "
";
$("#tableDhcpScopeVendorInfo").append(tableHtmlRows);
}
function addDhcpScopeGenericOptionsRow(optionCode, hexValue) {
var id = Math.floor(Math.random() * 10000);
var tableHtmlRows = "
";
tableHtmlRows += "
";
tableHtmlRows += "
";
$("#tableDhcpScopeGenericOptions").append(tableHtmlRows);
}
function addDhcpScopeExclusionRow(startingAddress, endingAddress) {
var id = Math.floor(Math.random() * 10000);
var tableHtmlRows = "
";
tableHtmlRows += "
";
tableHtmlRows += "
";
$("#tableDhcpScopeExclusions").append(tableHtmlRows);
}
function addDhcpScopeReservedLeaseRow(hostName, hardwareAddress, address, comments) {
var id = Math.floor(Math.random() * 10000);
var tableHtmlRows = "
";
tableHtmlRows += "
";
tableHtmlRows += "
";
tableHtmlRows += "
";
tableHtmlRows += "
";
tableHtmlRows += "
";
$("#tableDhcpScopeReservedLeases").append(tableHtmlRows);
}
function clearDhcpScopeForm() {
$("#txtDhcpScopeName").attr("data-name", "");
$("#txtDhcpScopeName").val("");
$("#txtDhcpScopeStartingAddress").val("");
$("#txtDhcpScopeEndingAddress").val("");
$("#txtDhcpScopeSubnetMask").val("");
$("#txtDhcpScopeLeaseTimeDays").val("1");
$("#txtDhcpScopeLeaseTimeHours").val("0");
$("#txtDhcpScopeLeaseTimeMinutes").val("0");
$("#txtDhcpScopeOfferDelayTime").val("0");
$("#chkDhcpScopePingCheckEnabled").prop("checked", false);
$("#txtDhcpScopePingCheckTimeout").val("1000");
$("#txtDhcpScopePingCheckRetries").val("2");
$("#txtDhcpScopeDomainName").val("");
$("#txtDhcpScopeDomainSearchStrings").val("");
$("#chkDhcpScopeDnsUpdates").prop("checked", true);
$("#chkDnsOverwriteForDynamicLease").prop("disabled", false);
$("#chkDnsOverwriteForDynamicLease").prop("checked", false);
$("#txtDhcpScopeDnsTtl").val("900");
$("#txtDhcpScopeServerAddress").val("");
$("#txtDhcpScopeServerHostName").val("");
$("#txtDhcpScopeBootFileName").val("");
$("#txtDhcpScopeRouterAddress").val("");
$("#chkUseThisDnsServer").prop("checked", false);
$('#txtDhcpScopeDnsServers').prop("disabled", false);
$("#txtDhcpScopeDnsServers").val("");
$("#txtDhcpScopeWinsServers").val("");
$("#txtDhcpScopeNtpServers").val("");
$("#txtDhcpScopeNtpServerDomainNames").val("");
$("#tableDhcpScopeStaticRoutes").html("");
$("#tableDhcpScopeVendorInfo").html("");
$("#txtDhcpScopeCAPWAPApIpAddresses").val("");
$("#txtDhcpScopeTftpServerAddresses").val("");
$("#tableDhcpScopeGenericOptions").html("");
$("#tableDhcpScopeExclusions").html("");
$("#tableDhcpScopeReservedLeases").html("");
$("#chkAllowOnlyReservedLeases").prop("checked", false);
$("#chkBlockLocallyAdministeredMacAddresses").prop("checked", false);
$("#chkIgnoreClientIdentifierOption").prop("checked", true);
$("#btnSaveDhcpScope").button("reset");
}
function showAddDhcpScope() {
clearDhcpScopeForm();
$("#titleDhcpEditScope").html("Add Scope");
$("#chkUseThisDnsServer").prop("checked", true);
$('#txtDhcpScopeDnsServers').prop("disabled", true);
$("#divDhcpViewScopes").hide();
$("#divDhcpViewScopesLoader").hide();
$("#divDhcpEditScope").show();
}
function showEditDhcpScope(scopeName) {
clearDhcpScopeForm();
var node = $("#optDhcpClusterNode").val();
$("#titleDhcpEditScope").html("Edit Scope");
var divDhcpViewScopesLoader = $("#divDhcpViewScopesLoader");
var divDhcpViewScopes = $("#divDhcpViewScopes");
var divDhcpEditScope = $("#divDhcpEditScope");
divDhcpViewScopes.hide();
divDhcpEditScope.hide();
divDhcpViewScopesLoader.show();
HTTPRequest({
url: "api/dhcp/scopes/get?name=" + encodeURIComponent(scopeName) + "&node=" + encodeURIComponent(node),
token: sessionData.token,
success: function (responseJSON) {
$("#txtDhcpScopeName").attr("data-name", responseJSON.response.name);
$("#txtDhcpScopeName").val(responseJSON.response.name);
$("#txtDhcpScopeStartingAddress").val(responseJSON.response.startingAddress);
$("#txtDhcpScopeEndingAddress").val(responseJSON.response.endingAddress);
$("#txtDhcpScopeSubnetMask").val(responseJSON.response.subnetMask);
$("#txtDhcpScopeLeaseTimeDays").val(responseJSON.response.leaseTimeDays);
$("#txtDhcpScopeLeaseTimeHours").val(responseJSON.response.leaseTimeHours);
$("#txtDhcpScopeLeaseTimeMinutes").val(responseJSON.response.leaseTimeMinutes);
$("#txtDhcpScopeOfferDelayTime").val(responseJSON.response.offerDelayTime);
$("#chkDhcpScopePingCheckEnabled").prop("checked", responseJSON.response.pingCheckEnabled);
$("#txtDhcpScopePingCheckTimeout").val(responseJSON.response.pingCheckTimeout);
$("#txtDhcpScopePingCheckRetries").val(responseJSON.response.pingCheckRetries);
if (responseJSON.response.domainName != null)
$("#txtDhcpScopeDomainName").val(responseJSON.response.domainName);
if (responseJSON.response.domainSearchList != null)
$("#txtDhcpScopeDomainSearchStrings").val(responseJSON.response.domainSearchList.join("\n"));
$("#chkDhcpScopeDnsUpdates").prop("checked", responseJSON.response.dnsUpdates);
$("#chkDnsOverwriteForDynamicLease").prop("disabled", !responseJSON.response.dnsUpdates);
$("#chkDnsOverwriteForDynamicLease").prop("checked", responseJSON.response.dnsOverwriteForDynamicLease);
$("#txtDhcpScopeDnsTtl").val(responseJSON.response.dnsTtl);
if (responseJSON.response.serverAddress != null)
$("#txtDhcpScopeServerAddress").val(responseJSON.response.serverAddress);
if (responseJSON.response.serverHostName != null)
$("#txtDhcpScopeServerHostName").val(responseJSON.response.serverHostName);
if (responseJSON.response.bootFileName != null)
$("#txtDhcpScopeBootFileName").val(responseJSON.response.bootFileName);
if (responseJSON.response.routerAddress != null)
$("#txtDhcpScopeRouterAddress").val(responseJSON.response.routerAddress);
$("#chkUseThisDnsServer").prop("checked", responseJSON.response.useThisDnsServer);
$('#txtDhcpScopeDnsServers').prop("disabled", responseJSON.response.useThisDnsServer);
if (responseJSON.response.dnsServers != null)
$("#txtDhcpScopeDnsServers").val(responseJSON.response.dnsServers.join("\n"));
if (responseJSON.response.winsServers != null)
$("#txtDhcpScopeWinsServers").val(responseJSON.response.winsServers.join("\n"));
if (responseJSON.response.ntpServers != null)
$("#txtDhcpScopeNtpServers").val(responseJSON.response.ntpServers.join("\n"));
if (responseJSON.response.ntpServerDomainNames != null)
$("#txtDhcpScopeNtpServerDomainNames").val(responseJSON.response.ntpServerDomainNames.join("\n"));
if (responseJSON.response.staticRoutes != null) {
for (var i = 0; i < responseJSON.response.staticRoutes.length; i++) {
addDhcpScopeStaticRouteRow(responseJSON.response.staticRoutes[i].destination, responseJSON.response.staticRoutes[i].subnetMask, responseJSON.response.staticRoutes[i].router);
}
}
if (responseJSON.response.vendorInfo != null) {
for (var i = 0; i < responseJSON.response.vendorInfo.length; i++) {
addDhcpScopeVendorInfoRow(responseJSON.response.vendorInfo[i].identifier, responseJSON.response.vendorInfo[i].information);
}
}
if (responseJSON.response.capwapAcIpAddresses != null)
$("#txtDhcpScopeCAPWAPApIpAddresses").val(responseJSON.response.capwapAcIpAddresses.join("\n"));
if (responseJSON.response.tftpServerAddresses != null)
$("#txtDhcpScopeTftpServerAddresses").val(responseJSON.response.tftpServerAddresses.join("\n"));
if (responseJSON.response.genericOptions != null) {
for (var i = 0; i < responseJSON.response.genericOptions.length; i++) {
addDhcpScopeGenericOptionsRow(responseJSON.response.genericOptions[i].code, responseJSON.response.genericOptions[i].value);
}
}
if (responseJSON.response.exclusions != null) {
for (var i = 0; i < responseJSON.response.exclusions.length; i++) {
addDhcpScopeExclusionRow(responseJSON.response.exclusions[i].startingAddress, responseJSON.response.exclusions[i].endingAddress);
}
}
if (responseJSON.response.reservedLeases != null) {
for (var i = 0; i < responseJSON.response.reservedLeases.length; i++) {
addDhcpScopeReservedLeaseRow(responseJSON.response.reservedLeases[i].hostName, responseJSON.response.reservedLeases[i].hardwareAddress, responseJSON.response.reservedLeases[i].address, responseJSON.response.reservedLeases[i].comments);
}
}
$("#chkAllowOnlyReservedLeases").prop("checked", responseJSON.response.allowOnlyReservedLeases);
$("#chkBlockLocallyAdministeredMacAddresses").prop("checked", responseJSON.response.blockLocallyAdministeredMacAddresses);
$("#chkIgnoreClientIdentifierOption").prop("checked", responseJSON.response.ignoreClientIdentifierOption);
$("#optDhcpClusterNode").prop("disabled", true);
divDhcpViewScopesLoader.hide();
divDhcpEditScope.show();
},
invalidToken: function () {
showPageLogin();
},
objLoaderPlaceholder: divDhcpViewScopesLoader
});
}
function saveDhcpScope() {
var oldName = $("#txtDhcpScopeName").attr("data-name");
var name = $("#txtDhcpScopeName").val();
var newName = null;
if ((oldName !== "") && (oldName != name)) {
newName = name;
name = oldName;
}
var startingAddress = $("#txtDhcpScopeStartingAddress").val();
var endingAddress = $("#txtDhcpScopeEndingAddress").val();
var subnetMask = $("#txtDhcpScopeSubnetMask").val();
var leaseTimeDays = $("#txtDhcpScopeLeaseTimeDays").val();
var leaseTimeHours = $("#txtDhcpScopeLeaseTimeHours").val();
var leaseTimeMinutes = $("#txtDhcpScopeLeaseTimeMinutes").val();
var offerDelayTime = $("#txtDhcpScopeOfferDelayTime").val();
var pingCheckEnabled = $("#chkDhcpScopePingCheckEnabled").prop("checked");
var pingCheckTimeout = $("#txtDhcpScopePingCheckTimeout").val();
var pingCheckRetries = $("#txtDhcpScopePingCheckRetries").val();
var domainName = $("#txtDhcpScopeDomainName").val();
var domainSearchList = cleanTextList($("#txtDhcpScopeDomainSearchStrings").val());
var dnsUpdates = $("#chkDhcpScopeDnsUpdates").prop("checked");
var dnsOverwriteForDynamicLease = $("#chkDnsOverwriteForDynamicLease").prop("checked");
var dnsTtl = $("#txtDhcpScopeDnsTtl").val();
var serverAddress = $("#txtDhcpScopeServerAddress").val();
var serverHostName = $("#txtDhcpScopeServerHostName").val();
var bootFileName = $("#txtDhcpScopeBootFileName").val();
var routerAddress = $("#txtDhcpScopeRouterAddress").val();
var useThisDnsServer = $("#chkUseThisDnsServer").prop('checked');
var dnsServers = cleanTextList($("#txtDhcpScopeDnsServers").val());
var winsServers = cleanTextList($("#txtDhcpScopeWinsServers").val());
var ntpServers = cleanTextList($("#txtDhcpScopeNtpServers").val());
var ntpServerDomainNames = cleanTextList($("#txtDhcpScopeNtpServerDomainNames").val());
var staticRoutes = serializeTableData($("#tableDhcpScopeStaticRoutes"), 3);
if (staticRoutes === false)
return;
var vendorInfo = serializeTableData($("#tableDhcpScopeVendorInfo"), 2);
if (vendorInfo === false)
return;
var capwapAcIpAddresses = cleanTextList($("#txtDhcpScopeCAPWAPApIpAddresses").val());
var tftpServerAddresses = cleanTextList($("#txtDhcpScopeTftpServerAddresses").val());
var genericOptions = serializeTableData($("#tableDhcpScopeGenericOptions"), 2);
if (genericOptions === false)
return;
var exclusions = serializeTableData($("#tableDhcpScopeExclusions"), 2);
if (exclusions === false)
return;
var reservedLeases = serializeTableData($("#tableDhcpScopeReservedLeases"), 4);
if (reservedLeases === false)
return;
var allowOnlyReservedLeases = $("#chkAllowOnlyReservedLeases").prop('checked');
var blockLocallyAdministeredMacAddresses = $("#chkBlockLocallyAdministeredMacAddresses").prop('checked');
var ignoreClientIdentifierOption = $("#chkIgnoreClientIdentifierOption").prop('checked');
var node = $("#optDhcpClusterNode").val();
var btn = $("#btnSaveDhcpScope");
btn.button("loading");
HTTPRequest({
url: "api/dhcp/scopes/set?node=" + encodeURIComponent(node),
token: sessionData.token,
method: "POST",
data: "name=" + encodeURIComponent(name) + (newName == null ? "" : "&newName=" + encodeURIComponent(newName)) + "&startingAddress=" + encodeURIComponent(startingAddress) + "&endingAddress=" + encodeURIComponent(endingAddress) + "&subnetMask=" + encodeURIComponent(subnetMask) +
"&leaseTimeDays=" + leaseTimeDays + "&leaseTimeHours=" + leaseTimeHours + "&leaseTimeMinutes=" + leaseTimeMinutes + "&offerDelayTime=" + offerDelayTime + "&pingCheckEnabled=" + pingCheckEnabled + "&pingCheckTimeout=" + pingCheckTimeout + "&pingCheckRetries=" + pingCheckRetries +
"&domainName=" + encodeURIComponent(domainName) + "&domainSearchList=" + encodeURIComponent(domainSearchList) + "&dnsUpdates=" + dnsUpdates + "&dnsOverwriteForDynamicLease=" + dnsOverwriteForDynamicLease + "&dnsTtl=" + dnsTtl + "&serverAddress=" + encodeURIComponent(serverAddress) + "&serverHostName=" + encodeURIComponent(serverHostName) + "&bootFileName=" + encodeURIComponent(bootFileName) +
"&routerAddress=" + encodeURIComponent(routerAddress) + "&useThisDnsServer=" + useThisDnsServer + (useThisDnsServer ? "" : "&dnsServers=" + encodeURIComponent(dnsServers)) + "&winsServers=" + encodeURIComponent(winsServers) + "&ntpServers=" + encodeURIComponent(ntpServers) + "&ntpServerDomainNames=" + encodeURIComponent(ntpServerDomainNames) +
"&staticRoutes=" + encodeURIComponent(staticRoutes) + "&vendorInfo=" + encodeURIComponent(vendorInfo) + "&capwapAcIpAddresses=" + encodeURIComponent(capwapAcIpAddresses) + "&tftpServerAddresses=" + encodeURIComponent(tftpServerAddresses) + "&genericOptions=" + encodeURIComponent(genericOptions) + "&exclusions=" + encodeURIComponent(exclusions) + "&reservedLeases=" + encodeURIComponent(reservedLeases) + "&allowOnlyReservedLeases=" + allowOnlyReservedLeases + "&blockLocallyAdministeredMacAddresses=" + blockLocallyAdministeredMacAddresses + "&ignoreClientIdentifierOption=" + ignoreClientIdentifierOption,
processData: false,
success: function (responseJSON) {
refreshDhcpScopes();
btn.button("reset");
showAlert("success", "Scope Saved!", "DHCP Scope was saved successfully.");
},
error: function () {
btn.button("reset");
},
invalidToken: function () {
btn.button("reset");
showPageLogin();
}
});
}
function disableDhcpScope(scopeName) {
if (!confirm("Are you sure you want to disable the DHCP scope '" + scopeName + "'?"))
return;
var node = $("#optDhcpClusterNode").val();
var divDhcpViewScopesLoader = $("#divDhcpViewScopesLoader");
var divDhcpViewScopes = $("#divDhcpViewScopes");
var divDhcpEditScope = $("#divDhcpEditScope");
divDhcpViewScopes.hide();
divDhcpEditScope.hide();
divDhcpViewScopesLoader.show();
HTTPRequest({
url: "api/dhcp/scopes/disable?name=" + encodeURIComponent(scopeName) + "&node=" + encodeURIComponent(node),
token: sessionData.token,
success: function (responseJSON) {
refreshDhcpScopes();
showAlert("success", "Scope Disabled!", "DHCP Scope was disabled successfully.");
},
error: function () {
divDhcpViewScopesLoader.hide();
divDhcpViewScopes.show();
},
invalidToken: function () {
showPageLogin();
},
objLoaderPlaceholder: divDhcpViewScopesLoader
});
}
function enableDhcpScope(scopeName) {
var node = $("#optDhcpClusterNode").val();
var divDhcpViewScopesLoader = $("#divDhcpViewScopesLoader");
var divDhcpViewScopes = $("#divDhcpViewScopes");
var divDhcpEditScope = $("#divDhcpEditScope");
divDhcpViewScopes.hide();
divDhcpEditScope.hide();
divDhcpViewScopesLoader.show();
HTTPRequest({
url: "api/dhcp/scopes/enable?name=" + encodeURIComponent(scopeName) + "&node=" + encodeURIComponent(node),
token: sessionData.token,
success: function (responseJSON) {
refreshDhcpScopes();
showAlert("success", "Scope Enabled!", "DHCP Scope was enabled successfully.");
},
error: function () {
divDhcpViewScopesLoader.hide();
divDhcpViewScopes.show();
},
invalidToken: function () {
showPageLogin();
},
objLoaderPlaceholder: divDhcpViewScopesLoader
});
}
function deleteDhcpScope(index, scopeName) {
if (!confirm("Are you sure you want to delete the DHCP scope '" + scopeName + "'?"))
return;
var node = $("#optDhcpClusterNode").val();
var divDhcpViewScopesLoader = $("#divDhcpViewScopesLoader");
var divDhcpViewScopes = $("#divDhcpViewScopes");
var divDhcpEditScope = $("#divDhcpEditScope");
divDhcpViewScopes.hide();
divDhcpEditScope.hide();
divDhcpViewScopesLoader.show();
HTTPRequest({
url: "api/dhcp/scopes/delete?name=" + encodeURIComponent(scopeName) + "&node=" + encodeURIComponent(node),
token: sessionData.token,
success: function (responseJSON) {
$("#trDhcpScopeRow" + index).remove();
var dhcpLeasesLength = $('#tableDhcpScopesBody >tr').length;
if (dhcpLeasesLength > 0)
$("#tableDhcpScopesFooter").html("
Total Scopes: " + dhcpLeasesLength + "
");
else
$("#tableDhcpScopesFooter").html("
No Scope Found
");
divDhcpViewScopes.show();
divDhcpViewScopesLoader.hide();
showAlert("success", "Scope Deleted!", "DHCP Scope was deleted successfully.");
},
error: function () {
divDhcpViewScopesLoader.hide();
divDhcpViewScopes.show();
},
invalidToken: function () {
showPageLogin();
},
objLoaderPlaceholder: divDhcpViewScopesLoader
});
}