From f4af6160dbbad4982bb461d4be9552d0e9b94c58 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 14 Nov 2020 16:52:47 +0530 Subject: [PATCH] webapp: implemented vendor specific info option changes. Implemented setDhcpScope api changes. --- DnsServerCore/www/js/dhcp.js | 56 +++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/DnsServerCore/www/js/dhcp.js b/DnsServerCore/www/js/dhcp.js index 9451a186..9ce8f625 100644 --- a/DnsServerCore/www/js/dhcp.js +++ b/DnsServerCore/www/js/dhcp.js @@ -117,20 +117,31 @@ function addDhcpScopeStaticRouteRow(destination, subnetMask, router) { var id = Math.floor(Math.random() * 10000); - var tableHtmlRows = ""; - tableHtmlRows += ""; - tableHtmlRows += ""; + 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 addDhcpScopeExclusionRow(startingAddress, endingAddress) { var id = Math.floor(Math.random() * 10000); - var tableHtmlRows = ""; - tableHtmlRows += ""; + var tableHtmlRows = ""; + tableHtmlRows += ""; tableHtmlRows += ""; $("#tableDhcpScopeExclusions").append(tableHtmlRows); @@ -141,26 +152,26 @@ function addDhcpScopeReservedLeaseRow(hostName, hardwareAddress, address, commen var id = Math.floor(Math.random() * 10000); var tableHtmlRows = "" + (hostName == null ? "" : htmlEncode(hostName)) + ""; - tableHtmlRows += ""; - tableHtmlRows += ""; + tableHtmlRows += ""; + tableHtmlRows += ""; tableHtmlRows += ""; tableHtmlRows += ""; $("#tableDhcpScopeReservedLeases").append(tableHtmlRows); } -function getTableCsv(table, columns) { +function serializeTableData(table, columns) { var data = table.find('input:text'); - var csv = ""; + var output = ""; for (var i = 0; i < data.length; i += columns) { if (i > 0) - csv += ","; + output += "|"; for (var j = 0; j < columns; j++) { if (j > 0) - csv += ";"; + output += "|"; var cell = $(data[i + j]); var cellValue = cell.val(); @@ -172,11 +183,11 @@ function getTableCsv(table, columns) { return false; } - csv += htmlDecode(cellValue); + output += htmlDecode(cellValue); } } - return csv; + return output; } function clearDhcpScopeForm() { @@ -201,6 +212,7 @@ function clearDhcpScopeForm() { $("#txtDhcpScopeWinsServers").val(""); $("#txtDhcpScopeNtpServers").val(""); $("#tableDhcpScopeStaticRoutes").html(""); + $("#tableDhcpScopeVendorInfo").html(""); $("#tableDhcpScopeExclusions").html(""); $("#tableDhcpScopeReservedLeases").html(""); $("#chkAllowOnlyReservedLeases").prop("checked", false); @@ -280,6 +292,12 @@ function showEditDhcpScope(scopeName) { } } + 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.exclusions != null) { for (var i = 0; i < responseJSON.response.exclusions.length; i++) { addDhcpScopeExclusionRow(responseJSON.response.exclusions[i].startingAddress, responseJSON.response.exclusions[i].endingAddress); @@ -337,15 +355,19 @@ function saveDhcpScope() { var winsServers = cleanTextList($("#txtDhcpScopeWinsServers").val()); var ntpServers = cleanTextList($("#txtDhcpScopeNtpServers").val()); - var staticRoutes = getTableCsv($("#tableDhcpScopeStaticRoutes"), 3); + var staticRoutes = serializeTableData($("#tableDhcpScopeStaticRoutes"), 3); if (staticRoutes === false) return; - var exclusions = getTableCsv($("#tableDhcpScopeExclusions"), 2); + var vendorInfo = serializeTableData($("#tableDhcpScopeVendorInfo"), 2); + if (vendorInfo === false) + return; + + var exclusions = serializeTableData($("#tableDhcpScopeExclusions"), 2); if (exclusions === false) return; - var reservedLeases = getTableCsv($("#tableDhcpScopeReservedLeases"), 3); + var reservedLeases = serializeTableData($("#tableDhcpScopeReservedLeases"), 3); if (reservedLeases === false) return; @@ -357,7 +379,7 @@ function saveDhcpScope() { url: "/api/setDhcpScope?token=" + token + "&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 + "&domainName=" + encodeURIComponent(domainName) + "&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) + - "&staticRoutes=" + encodeURIComponent(staticRoutes) + "&exclusions=" + encodeURIComponent(exclusions) + "&reservedLeases=" + encodeURIComponent(reservedLeases) + "&allowOnlyReservedLeases=" + allowOnlyReservedLeases, + "&staticRoutes=" + encodeURIComponent(staticRoutes) + "&vendorInfo=" + encodeURIComponent(vendorInfo) + "&exclusions=" + encodeURIComponent(exclusions) + "&reservedLeases=" + encodeURIComponent(reservedLeases) + "&allowOnlyReservedLeases=" + allowOnlyReservedLeases, success: function (responseJSON) { refreshDhcpScopes(); btn.button('reset');