diff --git a/DnsServerCore/www/css/main.css b/DnsServerCore/www/css/main.css index 66ecc671..c53cec0f 100644 --- a/DnsServerCore/www/css/main.css +++ b/DnsServerCore/www/css/main.css @@ -176,10 +176,6 @@ a { display: none; } - .zone-viewer-pane .resource-record { - background-color: #f5f5f5; - } - .log-list-pane { float: left; width: 17%; @@ -210,11 +206,6 @@ a { color: #ffffff; } - .stats-panel .cache-hit { - background-color: rgba(111, 84, 153, 0.7); - color: #ffffff; - } - .stats-panel .no-error { background-color: rgba(92, 184, 92, 0.7); color: #ffffff; @@ -235,26 +226,31 @@ a { color: #ffffff; } + .stats-panel .auth-hit { + background-color: rgba(150, 150, 0, 0.7); + color: #ffffff; + } + + .stats-panel .cache-hit { + background-color: rgba(111, 84, 153, 0.7); + color: #ffffff; + } + .stats-panel .blocked { background-color: rgba(255, 165, 0, 0.7); color: #ffffff; } + .stats-panel .recursions { + background-color: rgba(23, 162, 184, 0.7); + color: #ffffff; + } + .stats-panel .clients { background-color: rgba(51, 122, 183, 0.7); color: #ffffff; } - .stats-panel .allowedZones { - background-color: rgba(51, 122, 183, 0.7); - color: #ffffff; - } - - .stats-panel .blockedZones { - background-color: rgba(51, 122, 183, 0.7); - color: #ffffff; - } - .stats-panel .stats-item { width: 9.7%; float: left; @@ -277,6 +273,40 @@ a { font-weight: bold; } +.zone-stats-panel { + height: 70px; + padding: 6px 0 6px 4px; + margin-bottom: 10px; +} + + .zone-stats-panel .allowed-zones { + background-color: rgba(51, 122, 183, 0.7); + color: #ffffff; + } + + .zone-stats-panel .blocked-zones { + background-color: rgba(51, 122, 183, 0.7); + color: #ffffff; + } + + .zone-stats-panel .stats-item { + width: 49%; + float: left; + padding: 6px 10px; + margin-right: 1%; + } + + .zone-stats-panel .stats-item .number { + font-size: 16px; + font-weight: bold; + padding: 6px 0; + } + + .zone-stats-panel .stats-item .title { + font-size: 12px; + font-weight: bold; + } + .about p { color: rgb(119, 119, 119); text-align: center; diff --git a/DnsServerCore/www/index.html b/DnsServerCore/www/index.html index 2f2758cf..0a03f0a6 100644 --- a/DnsServerCore/www/index.html +++ b/DnsServerCore/www/index.html @@ -19,6 +19,7 @@ + @@ -92,7 +93,7 @@
-
-
10
-
0%
-
Cache Hit
-
-
70
0%
@@ -164,6 +159,24 @@
Refused
+
+
10
+
0%
+
Authoritative
+
+ +
+
10
+
0%
+
Recursive
+
+ +
+
10
+
0%
+
Cached
+
+
10
0%
@@ -175,18 +188,6 @@
 
Clients
- -
-
10
-
Zones
-
Allowed
-
- -
-
10
-
Zones
-
Blocked
-
@@ -195,10 +196,27 @@
-
-
Top Query Type
+
- +
+
+
10
+
Zones Allowed
+
+ +
+
10
+
Zones Blocked
+
+
+ +
+ +
+ +
+ +
@@ -277,281 +295,74 @@
+
-
-
-
- +
+
+
+
-
- - -
- - - + + + + + + + + + + + + + + + + + +
Zone
localhostEdit Disable Delete
Total Records: 1
-
-
-
-
technitium.com
-
- - - -
+
@@ -1176,7 +989,7 @@
@@ -1196,7 +1009,7 @@ Lease Expires - + Default 00-00-00-00-00-00 @@ -1207,6 +1020,9 @@ 6/15/2019 3:39 PM + + Total Leases: 1 +
@@ -1217,7 +1033,7 @@
- +
@@ -1231,7 +1047,7 @@ - + Default 192.168.10.1 - 192.168.10.100 @@ -1240,6 +1056,9 @@ Edit Delete + + Total Leases: 1 +
@@ -1535,8 +1354,8 @@
@@ -1567,6 +1386,210 @@
+ + + + + +
@@ -1610,8 +1633,8 @@ diff --git a/DnsServerCore/www/js/common.js b/DnsServerCore/www/js/common.js index e78cebf9..18436225 100644 --- a/DnsServerCore/www/js/common.js +++ b/DnsServerCore/www/js/common.js @@ -1,6 +1,6 @@ /* Technitium DNS Server -Copyright (C) 2018 Shreyas Zare (shreyas@technitium.com) +Copyright (C) 2019 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 @@ -254,3 +254,57 @@ function hideAlert(objAlertPlaceholder) { objAlertPlaceholder.html(""); } + +function sortTable(tableId, n) { + var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0; + table = document.getElementById(tableId); + switching = true; + // Set the sorting direction to ascending: + dir = "asc"; + /* Make a loop that will continue until + no switching has been done: */ + while (switching) { + // Start by saying: no switching is done: + switching = false; + rows = table.rows; + /* Loop through all table rows */ + for (i = 0; i < (rows.length - 1); i++) { + // Start by saying there should be no switching: + shouldSwitch = false; + /* Get the two elements you want to compare, + one from current row and one from the next: */ + x = rows[i].getElementsByTagName("TD")[n]; + y = rows[i + 1].getElementsByTagName("TD")[n]; + /* Check if the two rows should switch place, + based on the direction, asc or desc: */ + if (dir == "asc") { + if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) { + // If so, mark as a switch and break the loop: + shouldSwitch = true; + break; + } + } else if (dir == "desc") { + if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) { + // If so, mark as a switch and break the loop: + shouldSwitch = true; + break; + } + } + } + if (shouldSwitch) { + /* If a switch has been marked, make the switch + and mark that a switch has been done: */ + rows[i].parentNode.insertBefore(rows[i + 1], rows[i]); + switching = true; + // Each time a switch is done, increase this count by 1: + switchcount++; + } else { + /* If no switching has been done AND the direction is "asc", + set the direction to "desc" and run the while loop again. */ + if (switchcount == 0 && dir == "asc") { + dir = "desc"; + switching = true; + } + } + } +} diff --git a/DnsServerCore/www/js/main.js b/DnsServerCore/www/js/main.js index b3fe77cc..a1bbda95 100644 --- a/DnsServerCore/www/js/main.js +++ b/DnsServerCore/www/js/main.js @@ -71,7 +71,6 @@ function showPageMain(username) { loadDnsSettings(); refreshDashboard(); - refreshZonesList(); refreshCachedZonesList(); refreshAllowedZonesList(); refreshBlockedZonesList(); @@ -81,8 +80,6 @@ function showPageMain(username) { var type = $('input[name=rdStatType]:checked').val(); if (type === "lastHour") refreshDashboard(true); - - refreshZonesList(true); }, 60000); } @@ -232,7 +229,7 @@ $(function () { case "cloudflare-json": $("#txtForwarders").val("https://cloudflare-dns.com/dns-query"); - $("#rdForwarderProtocolHttpJsons").prop("checked", true); + $("#rdForwarderProtocolHttpsJson").prop("checked", true); break; case "cloudflare-tor": @@ -281,9 +278,14 @@ $(function () { $("#rdForwarderProtocolTls").prop("checked", true); break; + case "google-https": + $("#txtForwarders").val("https://dns.google/dns-query"); + $("#rdForwarderProtocolHttps").prop("checked", true); + break; + case "google-json": - $("#txtForwarders").val("https://dns.google.com/resolve"); - $("#rdForwarderProtocolHttpJsons").prop("checked", true); + $("#txtForwarders").val("https://dns.google/resolve"); + $("#rdForwarderProtocolHttpsJson").prop("checked", true); break; @@ -634,7 +636,7 @@ function loadDnsSettings() { break; case "httpsjson": - $("#rdForwarderProtocolHttpJsons").prop("checked", true); + $("#rdForwarderProtocolHttpsJson").prop("checked", true); break; default: @@ -858,30 +860,41 @@ function refreshDashboard(hideLoader) { //stats $("#divDashboardStatsTotalQueries").text(responseJSON.response.stats.totalQueries.toLocaleString()); - $("#divDashboardStatsTotalCacheHit").text(responseJSON.response.stats.totalCacheHit.toLocaleString()); $("#divDashboardStatsTotalNoError").text(responseJSON.response.stats.totalNoError.toLocaleString()); $("#divDashboardStatsTotalServerFailure").text(responseJSON.response.stats.totalServerFailure.toLocaleString()); $("#divDashboardStatsTotalNameError").text(responseJSON.response.stats.totalNameError.toLocaleString()); $("#divDashboardStatsTotalRefused").text(responseJSON.response.stats.totalRefused.toLocaleString()); + + $("#divDashboardStatsTotalAuthHit").text(responseJSON.response.stats.totalAuthHit.toLocaleString()); + $("#divDashboardStatsTotalRecursions").text(responseJSON.response.stats.totalRecursions.toLocaleString()); + $("#divDashboardStatsTotalCacheHit").text(responseJSON.response.stats.totalCacheHit.toLocaleString()); $("#divDashboardStatsTotalBlocked").text(responseJSON.response.stats.totalBlocked.toLocaleString()); + $("#divDashboardStatsTotalClients").text(responseJSON.response.stats.totalClients.toLocaleString()); + $("#divDashboardStatsAllowedZones").text(responseJSON.response.stats.allowedZones.toLocaleString()); $("#divDashboardStatsBlockedZones").text(responseJSON.response.stats.blockedZones.toLocaleString()); if (responseJSON.response.stats.totalQueries > 0) { - $("#divDashboardStatsTotalCacheHitPercentage").text((responseJSON.response.stats.totalCacheHit * 100 / responseJSON.response.stats.totalQueries).toFixed(2) + "%"); $("#divDashboardStatsTotalNoErrorPercentage").text((responseJSON.response.stats.totalNoError * 100 / responseJSON.response.stats.totalQueries).toFixed(2) + "%"); $("#divDashboardStatsTotalServerFailurePercentage").text((responseJSON.response.stats.totalServerFailure * 100 / responseJSON.response.stats.totalQueries).toFixed(2) + "%"); $("#divDashboardStatsTotalNameErrorPercentage").text((responseJSON.response.stats.totalNameError * 100 / responseJSON.response.stats.totalQueries).toFixed(2) + "%"); $("#divDashboardStatsTotalRefusedPercentage").text((responseJSON.response.stats.totalRefused * 100 / responseJSON.response.stats.totalQueries).toFixed(2) + "%"); + + $("#divDashboardStatsTotalAuthHitPercentage").text((responseJSON.response.stats.totalAuthHit * 100 / responseJSON.response.stats.totalQueries).toFixed(2) + "%"); + $("#divDashboardStatsTotalRecursionsPercentage").text((responseJSON.response.stats.totalRecursions * 100 / responseJSON.response.stats.totalQueries).toFixed(2) + "%"); + $("#divDashboardStatsTotalCacheHitPercentage").text((responseJSON.response.stats.totalCacheHit * 100 / responseJSON.response.stats.totalQueries).toFixed(2) + "%"); $("#divDashboardStatsTotalBlockedPercentage").text((responseJSON.response.stats.totalBlocked * 100 / responseJSON.response.stats.totalQueries).toFixed(2) + "%"); } else { - $("#divDashboardStatsTotalCacheHitPercentage").text("0%"); $("#divDashboardStatsTotalNoErrorPercentage").text("0%"); $("#divDashboardStatsTotalServerFailurePercentage").text("0%"); $("#divDashboardStatsTotalNameErrorPercentage").text("0%"); $("#divDashboardStatsTotalRefusedPercentage").text("0%"); + + $("#divDashboardStatsTotalAuthHitPercentage").text("0%"); + $("#divDashboardStatsTotalRecursionsPercentage").text("0%"); + $("#divDashboardStatsTotalCacheHitPercentage").text("0%"); $("#divDashboardStatsTotalBlockedPercentage").text("0%"); } @@ -913,18 +926,32 @@ function refreshDashboard(hideLoader) { window.chartDashboardMain.update(); } - //query type chart + //query response chart if (window.chartDashboardPie == null) { var contextDashboardPie = document.getElementById("canvasDashboardPie").getContext('2d'); window.chartDashboardPie = new Chart(contextDashboardPie, { + type: 'doughnut', + data: responseJSON.response.queryResponseChartData + }); + } + else { + window.chartDashboardPie.data = responseJSON.response.queryResponseChartData; + window.chartDashboardPie.update(); + } + + //query type chart + if (window.chartDashboardPie2 == null) { + var contextDashboardPie2 = document.getElementById("canvasDashboardPie2").getContext('2d'); + + window.chartDashboardPie2 = new Chart(contextDashboardPie2, { type: 'doughnut', data: responseJSON.response.queryTypeChartData }); } else { - window.chartDashboardPie.data = responseJSON.response.queryTypeChartData; - window.chartDashboardPie.update(); + window.chartDashboardPie2.data = responseJSON.response.queryTypeChartData; + window.chartDashboardPie2.update(); } //top clients @@ -988,11 +1015,6 @@ function refreshDashboard(hideLoader) { divDashboardLoader.hide(); divDashboard.show(); } - - if ($("#divTopClients").height() > 330) - $("#divTopQueryType").height($("#divTopClients").height()); - else - $("#divTopQueryType").height("330px"); }, invalidToken: function () { showPageLogin(); @@ -1452,1305 +1474,6 @@ function refreshBlockedZonesList(domain, direction) { return false; } -function refreshZonesList(hideLoader) { - - if (hideLoader == null) - hideLoader = false; - - var lstZones = $("#lstZones"); - var divLoader; - - if (!hideLoader) - divLoader = lstZones; - - HTTPRequest({ - url: "/api/listZones?token=" + token, - success: function (responseJSON) { - var zones = responseJSON.response.zones; - - var list = ""; - - for (var i = 0; i < zones.length; i++) { - var zoneName = htmlEncode(zones[i].zoneName); - - if (zoneName === "") - zoneName = "."; - - list += "
" + zoneName + "
" - } - - lstZones.html(list); - }, - invalidToken: function () { - showPageLogin(); - }, - objLoaderPlaceholder: divLoader, - dontHideAlert: hideLoader - }); - - return false; -} - -function addZone() { - - var domain = $("#txtAddZone").val(); - - if ((domain === null) || (domain === "")) { - showAlert("warning", "Missing!", "Please enter a domain name to add zone."); - $("#txtAddZone").focus(); - return false; - } - - var btn = $("#btnAddZone").button('loading'); - - HTTPRequest({ - url: "/api/createZone?token=" + token + "&domain=" + domain, - success: function (responseJSON) { - refreshZonesList(); - - viewZone(responseJSON.response.domain, false); - - $("#txtAddZone").val(""); - btn.button('reset'); - - showAlert("success", "Zone Added!", "Zone was added successfully."); - }, - error: function () { - btn.button('reset'); - }, - invalidToken: function () { - btn.button('reset'); - showPageLogin(); - } - }); - - return false; -} - -function deleteZone() { - - var domain = $("#spanZoneViewerTitle").text(); - - if (!confirm("Are you sure you want to permanently delete the zone '" + domain + "' and all its records?")) - return false; - - var btn = $("#btnDeleteZone").button('loading'); - - HTTPRequest({ - url: "/api/deleteZone?token=" + token + "&domain=" + domain, - success: function (responseJSON) { - refreshZonesList(); - - $("#divZoneViewer").hide(); - btn.button('reset'); - - showAlert("success", "Zone Deleted!", "Zone was deleted successfully."); - }, - error: function () { - btn.button('reset'); - }, - invalidToken: function () { - btn.button('reset'); - showPageLogin(); - } - }); - - return false; -} - -function enableZone() { - - var domain = $("#spanZoneViewerTitle").text(); - - if (!confirm("Are you sure you want to enable the zone '" + domain + "'?")) - return false; - - var btn = $("#btnEnableZone").button('loading'); - - HTTPRequest({ - url: "/api/enableZone?token=" + token + "&domain=" + domain, - success: function (responseJSON) { - refreshZonesList(); - - $("#btnEnableZone").hide(); - $("#btnDisableZone").show(); - - btn.button('reset'); - - showAlert("success", "Zone Enabled!", "Zone was enabled successfully."); - }, - error: function () { - btn.button('reset'); - }, - invalidToken: function () { - btn.button('reset'); - showPageLogin(); - } - }); - - return false; -} - -function disableZone() { - - var domain = $("#spanZoneViewerTitle").text(); - - if (!confirm("Are you sure you want to disable the zone '" + domain + "'?")) - return false; - - var btn = $("#btnDisableZone").button('loading'); - - HTTPRequest({ - url: "/api/disableZone?token=" + token + "&domain=" + domain, - success: function (responseJSON) { - refreshZonesList(); - - $("#btnEnableZone").show(); - $("#btnDisableZone").hide(); - - btn.button('reset'); - - showAlert("success", "Zone Disabled!", "Zone was disabled successfully."); - }, - error: function () { - btn.button('reset'); - }, - invalidToken: function () { - btn.button('reset'); - showPageLogin(); - } - }); - - return false; -} - -function viewZone(domain, disabled) { - - var divZoneViewer = $("#divZoneViewer"); - var divZoneViewerBody = $("#divZoneViewerBody"); - var divZoneViewerLoader = $("#divZoneViewerLoader"); - - $("#spanZoneViewerTitle").text(domain); - - if (disabled) { - $("#btnEnableZone").show(); - $("#btnDisableZone").hide(); - } - else { - $("#btnEnableZone").hide(); - $("#btnDisableZone").show(); - } - - $("#spanZoneViewerTitleLink").html(""); - - divZoneViewerLoader.show(); - divZoneViewerBody.hide(); - divZoneViewer.show(); - - HTTPRequest({ - url: "/api/getRecords?token=" + token + "&domain=" + domain, - success: function (responseJSON) { - var records = responseJSON.response.records; - - var list = ""; - - divZoneViewerBody.html(list); - - divZoneViewerLoader.hide(); - divZoneViewerBody.show(); - }, - invalidToken: function () { - showPageLogin(); - }, - objLoaderPlaceholder: divZoneViewerLoader - }); - - return false; -} - -function renderResourceRecord(record, domain) { - switch (record.type) { - case "SOA": - return renderSOAResourceRecord(record, domain); - - case "MX": - return renderMXResourceRecord(record, domain); - - case "SRV": - return renderSRVResourceRecord(record, domain); - - default: - return renderStandardResourceRecord(record, domain); - } -} - -function renderStandardResourceRecord(record, domain) { - - var id = Math.floor(Math.random() * 10000); - - var html = "
  • "; - html += "
    "; - - //label - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //name - var name = record.name.toLowerCase(); - - if (name === domain) - name = "@"; - else - name = name.replace("." + domain, ""); - - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //value - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //ttl - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //buttons - html += "
    "; - html += "
    "; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - - html += "
    "; - - html += "
    "; - html += "
  • "; - - return html; -} - -function renderMXResourceRecord(record, domain) { - - var id = Math.floor(Math.random() * 10000); - - var html = "
  • "; - html += "
    "; - - //label - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //name - var name = record.name.toLowerCase(); - - if (name === domain) - name = "@"; - else - name = name.replace("." + domain, ""); - - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //exchange - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //preference - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //ttl - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //buttons - html += "
    "; - html += "
    "; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += "
    "; - - html += "
    "; - html += "
  • "; - - return html; -} - -function renderSOAResourceRecord(record, domain) { - - var id = Math.floor(Math.random() * 10000); - - var html = "
  • "; - html += "
    "; - - //label - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //name - var name = record.name.toLowerCase(); - - if (name === domain) - name = "@"; - else - name = name.replace("." + domain, ""); - - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //master name server - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //responsible person - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //serial - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //refresh - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //retry - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //expire - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //minimum - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //ttl - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //buttons - html += "
    "; - html += ""; - html += ""; - html += ""; - html += "
    "; - - html += "
    "; - html += "
  • "; - - return html; -} - -function renderSRVResourceRecord(record, domain) { - - var id = Math.floor(Math.random() * 10000); - - var html = "
  • "; - html += "
    "; - - //label - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //parse name, service and protocol - var nameParts = record.name.toLowerCase().split("."); - var name; - var service = nameParts[0]; - var protocol = nameParts[1]; - - for (var i = 2; i < nameParts.length; i++) { - if (name == null) - name = nameParts[i]; - else - name += "." + nameParts[i]; - } - - if (name === domain) - name = "@"; - else - name = name.replace("." + domain, ""); - - if (service.startsWith("_")) - service = service.substr(1); - - if (protocol.startsWith("_")) - protocol = protocol.substr(1); - - //name - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //service - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //protocol - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //priority - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //weight - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //port - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //target - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //ttl - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //buttons - html += "
    "; - html += "
    "; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += ""; - html += "
    "; - - html += "
    "; - html += "
  • "; - - return html; -} - -function renderAddResourceRecordForm() { - - var html = "
  • "; - html += "
    "; - - //label - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //name - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //value - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //value MX Exchange - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //value MX Preference - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //value SRV Service - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //value SRV Protocol - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //value SRV Priority - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //value SRV Weight - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //value SRV Port - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //value SRV Target - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //ttl - html += "
    "; - html += ""; - html += ""; - html += "
    "; - - //buttons - html += "
    "; - html += ""; - html += "
    "; - - html += "
    "; - html += "
  • "; - - return html; -} - -function editResourceRecord(btnObj) { - - var btnEdit = $(btnObj); - var id = btnEdit.attr("data-id"); - - var type = $("#optType" + id).val(); - - $("#btnEdit" + id).hide(); - $("#btnUpdate" + id).show(); - $("#btnCancelEdit" + id).show(); - - switch (type) { - case "MX": - $("#btnDelete" + id).hide(); - $("#btnDisable" + id).hide(); - $("#btnEnable" + id).hide(); - - $("#txtName" + id).prop("disabled", false); - $("#txtExchange" + id).prop("disabled", false); - $("#txtPreference" + id).prop("disabled", false); - break; - - case "SOA": - $("#txtMasterNameServer" + id).prop("disabled", false); - $("#txtResponsiblePerson" + id).prop("disabled", false); - $("#txtSerial" + id).prop("disabled", false); - $("#txtRefresh" + id).prop("disabled", false); - $("#txtRetry" + id).prop("disabled", false); - $("#txtExpire" + id).prop("disabled", false); - $("#txtMinimum" + id).prop("disabled", false); - break; - - case "SRV": - $("#btnDelete" + id).hide(); - $("#btnDisable" + id).hide(); - $("#btnEnable" + id).hide(); - - $("#txtName" + id).prop("disabled", false); - $("#txtService" + id).prop("disabled", false); - $("#txtProtocol" + id).prop("disabled", false); - $("#txtPriority" + id).prop("disabled", false); - $("#txtWeight" + id).prop("disabled", false); - $("#txtPort" + id).prop("disabled", false); - $("#txtTarget" + id).prop("disabled", false); - break; - - default: - $("#btnDelete" + id).hide(); - $("#btnDisable" + id).hide(); - $("#btnEnable" + id).hide(); - - $("#txtName" + id).prop("disabled", false); - $("#txtValue" + id).prop("disabled", false); - break; - } - - $("#txtTtl" + id).prop("disabled", false); -} - -function cancelEditResourceRecord(btnObj) { - - var btnCancelEdit = $(btnObj); - var id = btnCancelEdit.attr("data-id"); - - var divData = $("#data" + id); - var disabled = (divData.attr("data-record-disabled") === "true"); - - var type = $("#optType" + id).val(); - - $("#btnEdit" + id).show(); - $("#btnUpdate" + id).hide(); - $("#btnCancelEdit" + id).hide(); - - switch (type) { - case "MX": - $("#btnDelete" + id).show(); - - if (disabled) - $("#btnEnable" + id).show(); - else - $("#btnDisable" + id).show(); - - $("#txtName" + id).prop("disabled", true); - $("#txtExchange" + id).prop("disabled", true); - $("#txtPreference" + id).prop("disabled", true); - break; - - case "SOA": - $("#txtMasterNameServer" + id).prop("disabled", true); - $("#txtResponsiblePerson" + id).prop("disabled", true); - $("#txtSerial" + id).prop("disabled", true); - $("#txtRefresh" + id).prop("disabled", true); - $("#txtRetry" + id).prop("disabled", true); - $("#txtExpire" + id).prop("disabled", true); - $("#txtMinimum" + id).prop("disabled", true); - break; - - case "SRV": - $("#btnDelete" + id).show(); - - if (disabled) - $("#btnEnable" + id).show(); - else - $("#btnDisable" + id).show(); - - $("#txtName" + id).prop("disabled", true); - $("#txtService" + id).prop("disabled", true); - $("#txtProtocol" + id).prop("disabled", true); - $("#txtPriority" + id).prop("disabled", true); - $("#txtWeight" + id).prop("disabled", true); - $("#txtPort" + id).prop("disabled", true); - $("#txtTarget" + id).prop("disabled", true); - break; - - default: - $("#btnDelete" + id).show(); - - if (disabled) - $("#btnEnable" + id).show(); - else - $("#btnDisable" + id).show(); - - $("#txtName" + id).prop("disabled", true); - $("#txtValue" + id).prop("disabled", true); - break; - } - - $("#txtTtl" + id).prop("disabled", true); -} - -function modifyAddRecordForm() { - - var type = $("#optAddRecordType").val(); - - switch (type) { - case "MX": - $("#divAddRecordName").show(); - $("#divAddRecordValue").hide(); - - $("#divAddRecordMXExchange").show(); - $("#divAddRecordMXPreference").show(); - - $("#divAddRecordSRVService").hide(); - $("#divAddRecordSRVProtocol").hide(); - $("#divAddRecordSRVPriority").hide(); - $("#divAddRecordSRVWeight").hide(); - $("#divAddRecordSRVPort").hide(); - $("#divAddRecordSRVTarget").hide(); - break; - - case "SRV": - $("#divAddRecordName").show(); - $("#divAddRecordValue").hide(); - - $("#divAddRecordMXExchange").hide(); - $("#divAddRecordMXPreference").hide(); - - $("#divAddRecordSRVService").show(); - $("#divAddRecordSRVProtocol").show(); - $("#divAddRecordSRVPriority").show(); - $("#divAddRecordSRVWeight").show(); - $("#divAddRecordSRVPort").show(); - $("#divAddRecordSRVTarget").show(); - break; - - default: - $("#divAddRecordName").show(); - $("#divAddRecordValue").show(); - - $("#divAddRecordMXExchange").hide(); - $("#divAddRecordMXPreference").hide(); - - $("#divAddRecordSRVService").hide(); - $("#divAddRecordSRVProtocol").hide(); - $("#divAddRecordSRVPriority").hide(); - $("#divAddRecordSRVWeight").hide(); - $("#divAddRecordSRVPort").hide(); - $("#divAddRecordSRVTarget").hide(); - break; - } -} - -function addResourceRecord() { - - var domain = $("#spanZoneViewerTitle").text(); - - var type = $("#optAddRecordType").val(); - var subDomain = $("#txtAddRecordName").val(); - var ttl = $("#txtAddRecordTtl").val(); - - if ((subDomain === null) || (subDomain === "")) { - subDomain = "@"; - } - - var name; - - if (subDomain === "@") - name = domain; - else if (domain === ".") - name = subDomain; - else - name = subDomain + "." + domain; - - var value; - var preference; - - var priority; - var weight; - var port; - - switch (type) { - case "MX": - value = $("#txtAddRecordExchange").val(); - preference = $("#txtAddRecordPreference").val(); - - if ((value === null) || (value === "")) { - showAlert("warning", "Missing!", "Please enter an mail exchange domain name into the exchange field."); - $("#txtAddRecordExchange").focus(); - return false; - } - - if ((preference === null) || (preference === "")) { - preference = 1; - } - break; - - case "SRV": - var service = $("#txtAddRecordSRVService").val(); - - if ((service === null) || (service === "")) { - showAlert("warning", "Missing!", "Please enter a suitable service name."); - $("#txtAddRecordSRVService").focus(); - return false; - } - - var protocol = $("#txtAddRecordSRVProtocol").val(); - - if ((protocol === null) || (protocol === "")) { - showAlert("warning", "Missing!", "Please enter a suitable protocol name."); - $("#txtAddRecordSRVProtocol").focus(); - return false; - } - - if (!service.startsWith("_")) - service = "_" + service; - - if (!protocol.startsWith("_")) - protocol = "_" + protocol; - - name = service + "." + protocol + "." + name; - - priority = $("#txtAddRecordSRVPriority").val(); - - if ((priority === null) || (priority === "")) { - showAlert("warning", "Missing!", "Please enter a suitable priority."); - $("#txtAddRecordSRVPriority").focus(); - return false; - } - - weight = $("#txtAddRecordSRVWeight").val(); - - if ((weight === null) || (weight === "")) { - showAlert("warning", "Missing!", "Please enter a suitable weight."); - $("#txtAddRecordSRVWeight").focus(); - return false; - } - - port = $("#txtAddRecordSRVPort").val(); - - if ((port === null) || (port === "")) { - showAlert("warning", "Missing!", "Please enter a suitable port number."); - $("#txtAddRecordSRVPort").focus(); - return false; - } - - value = $("#txtAddRecordSRVTarget").val(); - - if ((value === null) || (value === "")) { - showAlert("warning", "Missing!", "Please enter a suitable value into the target field."); - $("#txtAddRecordSRVTarget").focus(); - return false; - } - break; - - default: - value = $("#txtAddRecordValue").val(); - - if ((value === null) || (value === "")) { - showAlert("warning", "Missing!", "Please enter a suitable value into the value field."); - $("#txtAddRecordValue").focus(); - return false; - } - break; - } - - if ((ttl === null) || (ttl === "")) { - ttl = 3600; - } - - var apiUrl = "/api/addRecord?token=" + token + "&domain=" + encodeURIComponent(name) + "&type=" + type + "&ttl=" + ttl + "&value=" + encodeURIComponent(value); - - switch (type) { - case "MX": - apiUrl += "&preference=" + preference; - break; - - case "SRV": - apiUrl += "&priority=" + priority + "&weight=" + weight + "&port=" + port; - break; - } - - var btn = $("#btnAddRecord").button('loading'); - - HTTPRequest({ - url: apiUrl, - success: function (responseJSON) { - $("#txtAddRecordName").val(""); - $("#txtAddRecordValue").val(""); - - $("#txtAddRecordExchange").val(""); - $("#txtAddRecordPreference").val(""); - - $("#txtAddRecordSRVService").val(""); - $("#txtAddRecordSRVProtocol").val(""); - $("#txtAddRecordSRVPriority").val(""); - $("#txtAddRecordSRVWeight").val(""); - $("#txtAddRecordSRVPort").val(""); - $("#txtAddRecordSRVTarget").val(""); - - var record = { "name": name, "type": type, "ttl": ttl, "rData": { "value": value, "preference": preference, "priority": priority, "weight": weight, "port": port } }; - var html = renderResourceRecord(record, domain); - - $("#addRecordFormItem").before(html); - btn.button('reset'); - - showAlert("success", "Record Added!", "Resource record was added successfully."); - }, - error: function () { - btn.button('reset'); - }, - invalidToken: function () { - btn.button('reset'); - showPageLogin(); - } - }); - - return false; -} - -function deleteResourceRecord(objBtn) { - - var btnDelete = $(objBtn); - var id = btnDelete.attr("data-id"); - var divData = $("#data" + id); - - var type = $("#optType" + id).val(); - var name = divData.attr("data-record-name"); - var value = divData.attr("data-record-value"); - - if (name === "") - name = "."; - - if (!confirm("Are you sure to permanently delete the " + type + " record '" + name + "' with value '" + value + "'?")) - return false; - - var apiUrl = "/api/deleteRecord?token=" + token + "&domain=" + name + "&type=" + type + "&value=" + encodeURIComponent(value); - - if (type === "SRV") { - var port = $("#txtPort" + id).val(); - - apiUrl += "&port=" + port; - } - - btnDelete.button('loading'); - - HTTPRequest({ - url: apiUrl, - success: function (responseJSON) { - $("#li" + id).remove(); - - showAlert("success", "Record Deleted!", "Resource record was deleted successfully."); - }, - error: function () { - btnDelete.button('reset'); - }, - invalidToken: function () { - btnDelete.button('reset'); - showPageLogin(); - } - }); - - return false; -} - -function updateResourceRecord(objBtn, disable) { - - var btnUpdate = $(objBtn); - var id = btnUpdate.attr("data-id"); - var divData = $("#data" + id); - - if (disable === undefined) - disable = (divData.attr("data-record-disabled") === "true"); - - var domain = $("#spanZoneViewerTitle").text(); - var type = $("#optType" + id).val(); - - var newName = $("#txtName" + id).val(); - var ttl = $("#txtTtl" + id).val(); - - if (newName === "@") - newName = domain; - else if (domain === ".") - newName = newName + "."; - else - newName = newName + "." + domain; - - if ((ttl === null) || (ttl === "")) { - ttl = 3600; - } - - var oldName = divData.attr("data-record-name"); - var oldValue = divData.attr("data-record-value"); - var newValue; - - var preference; - - var masterNameServer; - var responsiblePerson; - var serial; - var refresh; - var retry; - var expire; - var minimum; - - var oldPort; - var priority; - var weight; - var port; - - switch (type) { - case "MX": - newValue = $("#txtExchange" + id).val(); - preference = $("#txtPreference" + id).val(); - - if ((newValue === null) || (newValue === "")) { - showAlert("warning", "Missing!", "Please enter an mail exchange domain name into the exchange field."); - $("#txtExchange" + id).focus(); - return false; - } - - if ((preference === null) || (preference === "")) { - preference = 1; - } - break; - - case "SOA": - masterNameServer = $("#txtMasterNameServer" + id).val(); - responsiblePerson = $("#txtResponsiblePerson" + id).val(); - serial = $("#txtSerial" + id).val(); - refresh = $("#txtRefresh" + id).val(); - retry = $("#txtRetry" + id).val(); - expire = $("#txtExpire" + id).val(); - minimum = $("#txtMinimum" + id).val(); - - if ((masterNameServer === null) || (masterNameServer === "")) { - showAlert("warning", "Missing!", "Please enter a master name server domain name."); - $("#txtMasterNameServer" + id).focus(); - return false; - } - - if ((responsiblePerson === null) || (responsiblePerson === "")) { - showAlert("warning", "Missing!", "Please enter a responsible person email address in domain name format."); - $("#txtResponsiblePerson" + id).focus(); - return false; - } - - if ((serial === null) || (serial === "")) { - showAlert("warning", "Missing!", "Please enter a serial number."); - $("#txtSerial" + id).focus(); - return false; - } - - if ((refresh === null) || (refresh === "")) { - showAlert("warning", "Missing!", "Please enter a refresh value."); - $("#txtRefresh" + id).focus(); - return false; - } - - if ((retry === null) || (retry === "")) { - showAlert("warning", "Missing!", "Please enter a retry value."); - $("#txtRetry" + id).focus(); - return false; - } - - if ((expire === null) || (expire === "")) { - showAlert("warning", "Missing!", "Please enter an expire value."); - $("#txtExpire" + id).focus(); - return false; - } - - if ((minimum === null) || (minimum === "")) { - showAlert("warning", "Missing!", "Please enter a minimum value."); - $("#txtMinimum" + id).focus(); - return false; - } - break; - - case "SRV": - var service = $("#txtService" + id).val(); - - if ((service === null) || (service === "")) { - showAlert("warning", "Missing!", "Please enter a suitable service name."); - $("#txtService" + id).focus(); - return false; - } - - var protocol = $("#txtProtocol" + id).val(); - - if ((protocol === null) || (protocol === "")) { - showAlert("warning", "Missing!", "Please enter a suitable protocol name."); - $("#txtProtocol" + id).focus(); - return false; - } - - if (!service.startsWith("_")) - service = "_" + service; - - if (!protocol.startsWith("_")) - protocol = "_" + protocol; - - newName = service + "." + protocol + "." + newName; - - oldPort = divData.attr("data-record-port"); - - priority = $("#txtPriority" + id).val(); - - if ((priority === null) || (priority === "")) { - showAlert("warning", "Missing!", "Please enter a suitable priority."); - $("#txtPriority" + id).focus(); - return false; - } - - weight = $("#txtWeight" + id).val(); - - if ((weight === null) || (weight === "")) { - showAlert("warning", "Missing!", "Please enter a suitable weight."); - $("#txtWeight" + id).focus(); - return false; - } - - port = $("#txtPort" + id).val(); - - if ((port === null) || (port === "")) { - showAlert("warning", "Missing!", "Please enter a suitable port number."); - $("#txtPort" + id).focus(); - return false; - } - - newValue = $("#txtTarget" + id).val(); - - if ((newValue === null) || (newValue === "")) { - showAlert("warning", "Missing!", "Please enter a suitable value into the target field."); - $("#txtTarget" + id).focus(); - return false; - } - - break; - - default: - newValue = $("#txtValue" + id).val(); - - if ((newValue === null) || (newValue === "")) { - showAlert("warning", "Missing!", "Please enter a suitable value into the value field."); - $("#txtValue" + id).focus(); - return false; - } - - break; - } - - var apiUrl = "/api/updateRecord?token=" + token + "&type=" + type + "&domain=" + newName + "&oldDomain=" + oldName + "&value=" + encodeURIComponent(newValue) + "&oldValue=" + encodeURIComponent(oldValue) + "&ttl=" + ttl + "&disable=" + disable; - - switch (type) { - case "MX": - apiUrl += "&preference=" + preference; - break; - - case "SOA": - apiUrl += "&masterNameServer=" + masterNameServer + "&responsiblePerson=" + responsiblePerson + "&serial=" + serial + "&refresh=" + refresh + "&retry=" + retry + "&expire=" + expire + "&minimum=" + minimum; - break; - - case "SRV": - apiUrl += "&oldPort=" + oldPort + "&priority=" + priority + "&weight=" + weight + "&port=" + port; - break; - } - - btnUpdate.button('loading'); - - HTTPRequest({ - url: apiUrl, - success: function (responseJSON) { - - switch (type) { - case "SOA": - break; - - case "SRV": - divData.attr("data-record-name", newName); - divData.attr("data-record-value", newValue); - divData.attr("data-record-port", port); - divData.attr("data-record-disabled", disable); - break; - - default: - divData.attr("data-record-name", newName); - divData.attr("data-record-value", newValue); - divData.attr("data-record-disabled", disable); - break; - } - - btnUpdate.button('reset'); - cancelEditResourceRecord(objBtn); - - if (disable) { - $("#btnDisable" + id).hide(); - $("#btnEnable" + id).show(); - $("#li" + id).addClass("disabled"); - } - else { - $("#btnDisable" + id).show(); - $("#btnEnable" + id).hide(); - $("#li" + id).removeClass("disabled"); - } - - showAlert("success", "Record Updated!", "Resource record was updated successfully."); - }, - error: function () { - btnUpdate.button('reset'); - }, - invalidToken: function () { - btnUpdate.button('reset'); - showPageLogin(); - } - }); - - return false; -} - function resolveQuery(importRecords) { if (importRecords == null) @@ -3054,4 +1777,4 @@ function exportCustomBlockedZones() { showAlert("success", "Exported!", "Custom blocked zones were exported successfully."); return false; -} \ No newline at end of file +} diff --git a/DnsServerCore/www/js/zone.js b/DnsServerCore/www/js/zone.js new file mode 100644 index 00000000..ed82fb1d --- /dev/null +++ b/DnsServerCore/www/js/zone.js @@ -0,0 +1,1056 @@ +/* +Technitium DNS Server +Copyright (C) 2019 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 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/listZones?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 zoneName = zones[i].zoneName; + + if (zoneName === "") + zoneName = "."; + + tableHtmlRows += "" + htmlEncode(zoneName) + ""; + tableHtmlRows += ""; + tableHtmlRows += ""; + tableHtmlRows += ""; + tableHtmlRows += ""; + } + + $("#tableZonesBody").html(tableHtmlRows); + + if (zones.length > 0) + $("#tableZonesFooter").html("Total Zones: " + zones.length + ""); + else + $("#tableZonesFooter").html("No Zones Found"); + + divViewZonesLoader.hide(); + divViewZones.show(); + }, + error: function () { + divViewZonesLoader.hide(); + divViewZones.show(); + }, + invalidToken: function () { + showPageLogin(); + }, + objLoaderPlaceholder: divViewZonesLoader + }); +} + +function enableZone(objBtn, domain) { + var btn = $(objBtn); + var id = btn.attr("data-id"); + + btn.button('loading'); + + HTTPRequest({ + url: "/api/enableZone?token=" + token + "&domain=" + domain, + success: function (responseJSON) { + btn.button('reset'); + + $("#btnEnableZone" + id).hide(); + $("#btnDisableZone" + id).show(); + + showAlert("success", "Zone Enabled!", "Zone was enabled successfully."); + }, + error: function () { + btn.button('reset'); + }, + invalidToken: function () { + showPageLogin(); + } + }); +} + +function disableZone(objBtn, domain) { + if (!confirm("Are you sure you want to disable the zone '" + domain + "'?")) + return false; + + var btn = $(objBtn); + var id = btn.attr("data-id"); + + btn.button('loading'); + + HTTPRequest({ + url: "/api/disableZone?token=" + token + "&domain=" + domain, + success: function (responseJSON) { + btn.button('reset'); + + $("#btnEnableZone" + id).show(); + $("#btnDisableZone" + id).hide(); + + showAlert("success", "Zone Disabled!", "Zone was disabled successfully."); + }, + error: function () { + btn.button('reset'); + }, + invalidToken: function () { + showPageLogin(); + } + }); +} + +function deleteZone(objBtn, domain) { + if (!confirm("Are you sure you want to permanently delete the zone '" + domain + "' and all its records?")) + return false; + + var btn = $(objBtn); + var id = btn.attr("data-id"); + + btn.button('loading'); + + HTTPRequest({ + url: "/api/deleteZone?token=" + token + "&domain=" + domain, + success: function (responseJSON) { + $("#trZone" + id).remove(); + + var totalZones = $('#tableZones >tbody >tr').length; + + if (totalZones > 0) + $("#tableZonesFooter").html("Total Zones: " + totalZones + ""); + else + $("#tableZonesFooter").html("No Zones Found"); + + showAlert("success", "Zone Deleted!", "Zone was deleted successfully."); + }, + error: function () { + btn.button('reset'); + }, + invalidToken: function () { + showPageLogin(); + } + }); +} + +function showAddZoneModal() { + $("#divAddZoneAlert").html(""); + + $("#txtAddZone").val(""); + $("#btnAddZone").button('reset'); + + $("#modalAddZone").modal("show"); +} + +function addZone() { + var divAddZoneAlert = $("#divAddZoneAlert"); + var domain = $("#txtAddZone").val(); + + if ((domain === null) || (domain === "")) { + showAlert("warning", "Missing!", "Please enter a domain name to add zone.", divAddZoneAlert); + $("#txtAddZone").focus(); + return; + } + + var btn = $("#btnAddZone").button('loading'); + + HTTPRequest({ + url: "/api/createZone?token=" + token + "&domain=" + domain, + success: function (responseJSON) { + $("#modalAddZone").modal("hide"); + showEditZone(domain); + + showAlert("success", "Zone Added!", "Zone was added successfully."); + }, + error: function () { + btn.button('reset'); + }, + invalidToken: function () { + showPageLogin(); + }, + objAlertPlaceholder: divAddZoneAlert + }); +} + +function showEditZone(domain) { + var divViewZonesLoader = $("#divViewZonesLoader"); + var divViewZones = $("#divViewZones"); + var divEditZone = $("#divEditZone"); + + divViewZones.hide(); + divEditZone.hide(); + divViewZonesLoader.show(); + + HTTPRequest({ + url: "/api/getRecords?token=" + token + "&domain=" + domain, + success: function (responseJSON) { + var records = responseJSON.response.records; + var tableHtmlRows = ""; + + for (var i = 0; i < records.length; i++) { + var id = Math.floor(Math.random() * 10000); + + var name = records[i].name.toLowerCase(); + if (name === "") + name = "."; + + if (name === domain) + name = "@"; + else + name = name.replace("." + domain, ""); + + tableHtmlRows += "" + htmlEncode(name) + ""; + tableHtmlRows += "" + records[i].type + ""; + tableHtmlRows += "" + records[i].ttl + ""; + + var additionalDataAttributes = ""; + + switch (records[i].type.toUpperCase()) { + case "A": + case "NS": + case "CNAME": + case "PTR": + case "TXT": + case "AAAA": + tableHtmlRows += "" + htmlEncode(records[i].rData.value) + ""; + break; + + case "SOA": + tableHtmlRows += "Master Name Server: " + htmlEncode(records[i].rData.masterNameServer) + + "
    Responsible Person: " + htmlEncode(records[i].rData.responsiblePerson) + + "
    Serial: " + htmlEncode(records[i].rData.serial) + + "
    Refresh: " + htmlEncode(records[i].rData.refresh) + + "
    Retry: " + htmlEncode(records[i].rData.retry) + + "
    Expire: " + htmlEncode(records[i].rData.expire) + + "
    Minimum: " + htmlEncode(records[i].rData.minimum) + ""; + + additionalDataAttributes = "data-record-mname=\"" + htmlEncode(records[i].rData.masterNameServer) + "\" " + + "data-record-rperson=\"" + htmlEncode(records[i].rData.responsiblePerson) + "\" " + + "data-record-serial=\"" + htmlEncode(records[i].rData.serial) + "\" " + + "data-record-refresh=\"" + htmlEncode(records[i].rData.refresh) + "\" " + + "data-record-retry=\"" + htmlEncode(records[i].rData.retry) + "\" " + + "data-record-expire=\"" + htmlEncode(records[i].rData.expire) + "\" " + + "data-record-minimum=\"" + htmlEncode(records[i].rData.minimum) + "\" "; + break; + + case "MX": + tableHtmlRows += "Preference: " + htmlEncode(records[i].rData.preference) + + "
    Exchange: " + htmlEncode(records[i].rData.value) + ""; + + additionalDataAttributes = "data-record-preference=\"" + htmlEncode(records[i].rData.preference) + "\" "; + break; + + case "SRV": + tableHtmlRows += "Priority: " + htmlEncode(records[i].rData.priority) + + "
    Weight: " + htmlEncode(records[i].rData.weight) + + "
    Port: " + htmlEncode(records[i].rData.port) + + "
    Target: " + htmlEncode(records[i].rData.value) + ""; + + additionalDataAttributes = "data-record-priority=\"" + htmlEncode(records[i].rData.priority) + "\" " + + "data-record-weight=\"" + htmlEncode(records[i].rData.weight) + "\" " + + "data-record-port=\"" + htmlEncode(records[i].rData.port) + "\" "; + break; + + case "CAA": + tableHtmlRows += "Flags: " + htmlEncode(records[i].rData.flags) + + "
    Tag: " + htmlEncode(records[i].rData.tag) + + "
    Authority: " + htmlEncode(records[i].rData.value) + ""; + + additionalDataAttributes = "data-record-flags=\"" + htmlEncode(records[i].rData.flags) + "\" " + + "data-record-tag=\"" + htmlEncode(records[i].rData.tag) + "\" "; + break; + + default: + tableHtmlRows += "RDATA: " + htmlEncode(records[i].rData.value) + ""; + break; + } + + tableHtmlRows += ""; + tableHtmlRows += "
    "; + tableHtmlRows += ""; + tableHtmlRows += ""; + tableHtmlRows += ""; + tableHtmlRows += ""; + } + + $("#titleEditZone").text(domain); + $("#tableEditZoneBody").html(tableHtmlRows); + + if (records.length > 0) + $("#tableEditZoneFooter").html("Total Records: " + records.length + ""); + else + $("#tableEditZoneFooter").html("No Records Found"); + + divViewZonesLoader.hide(); + divEditZone.show(); + }, + error: function () { + divViewZonesLoader.hide(); + divViewZones.show(); + }, + invalidToken: function () { + showPageLogin(); + }, + objLoaderPlaceholder: divViewZonesLoader + }); +} + +function clearAddEditForm() { + $("#divAddEditRecordAlert").html(""); + + $("#optAddEditRecordType").prop("disabled", false); + $("#txtAddEditRecordName").prop("disabled", false); + + $("#txtAddEditRecordName").val(""); + $("#optAddEditRecordType").val("A"); + $("#txtAddEditRecordTtl").val(""); + + $("#divAddEditRecordData").show(); + $("#lblAddEditRecordDataValue").text("IPv4 Address"); + $("#txtAddEditRecordDataValue").val(""); + + $("#divEditRecordDataSoa").hide(); + $("#txtEditRecordDataSoaMasterNameServer").val(""); + $("#txtEditRecordDataSoaResponsiblePerson").val(""); + $("#txtEditRecordDataSoaSerial").val(""); + $("#txtEditRecordDataSoaRefresh").val(""); + $("#txtEditRecordDataSoaRetry").val(""); + $("#txtEditRecordDataSoaExpire").val(""); + $("#txtEditRecordDataSoaMinimum").val(""); + + $("#divAddEditRecordDataMx").hide(); + $("#txtAddEditRecordDataMxPreference").val(""); + $("#txtAddEditRecordDataMxExchange").val(""); + + $("#divAddEditRecordDataSrv").hide(); + $("#txtAddEditRecordDataSrvPriority").val(""); + $("#txtAddEditRecordDataSrvWeight").val(""); + $("#txtAddEditRecordDataSrvPort").val(""); + $("#txtAddEditRecordDataSrvTarget").val(""); + + $("#divAddEditRecordDataCaa").hide(); + $("#txtAddEditRecordDataCaaFlags").val(""); + $("#txtAddEditRecordDataCaaTag").val(""); + $("#txtAddEditRecordDataCaaValue").val(""); + + $("#btnAddEditRecord").button("reset"); +} + +function showAddRecordModal() { + clearAddEditForm(); + + $("#titleAddEditRecord").text("Add Record"); + $("#optEditRecordTypeSoa").hide(); + $("#btnAddEditRecord").attr("onclick", "addRecord(); return false;"); + + $("#modalAddEditRecord").modal("show"); +} + +function modifyAddRecordForm() { + $("#divAddEditRecordAlert").html(""); + + $("#txtAddEditRecordName").prop("placeholder", "@"); + + var type = $("#optAddEditRecordType").val(); + + switch (type) { + case "A": + $("#lblAddEditRecordDataValue").text("IPv4 Address"); + $("#txtAddEditRecordDataValue").val(""); + $("#divAddEditRecordData").show(); + $("#divEditRecordDataSoa").hide(); + $("#divAddEditRecordDataMx").hide(); + $("#divAddEditRecordDataSrv").hide(); + $("#divAddEditRecordDataCaa").hide(); + break; + + case "NS": + $("#lblAddEditRecordDataValue").text("Domain Name"); + $("#txtAddEditRecordDataValue").val(""); + $("#divAddEditRecordData").show(); + $("#divEditRecordDataSoa").hide(); + $("#divAddEditRecordDataMx").hide(); + $("#divAddEditRecordDataSrv").hide(); + $("#divAddEditRecordDataCaa").hide(); + break; + + case "SOA": + $("#txtEditRecordDataSoaMasterNameServer").val(""); + $("#txtEditRecordDataSoaResponsiblePerson").val(""); + $("#txtEditRecordDataSoaSerial").val(""); + $("#txtEditRecordDataSoaRefresh").val(""); + $("#txtEditRecordDataSoaRetry").val(""); + $("#txtEditRecordDataSoaExpire").val(""); + $("#txtEditRecordDataSoaMinimum").val(""); + $("#divAddEditRecordData").hide(); + $("#divEditRecordDataSoa").show(); + $("#divAddEditRecordDataMx").hide(); + $("#divAddEditRecordDataSrv").hide(); + $("#divAddEditRecordDataCaa").hide(); + break; + + case "CNAME": + $("#lblAddEditRecordDataValue").text("Domain Name"); + $("#txtAddEditRecordDataValue").val(""); + $("#divAddEditRecordData").show(); + $("#divEditRecordDataSoa").hide(); + $("#divAddEditRecordDataMx").hide(); + $("#divAddEditRecordDataSrv").hide(); + $("#divAddEditRecordDataCaa").hide(); + break; + + case "PTR": + $("#lblAddEditRecordDataValue").text("Domain Name"); + $("#txtAddEditRecordDataValue").val(""); + $("#divAddEditRecordData").show(); + $("#divEditRecordDataSoa").hide(); + $("#divAddEditRecordDataMx").hide(); + $("#divAddEditRecordDataSrv").hide(); + $("#divAddEditRecordDataCaa").hide(); + break; + + case "MX": + $("#txtAddEditRecordDataMxPreference").val(""); + $("#txtAddEditRecordDataMxExchange").val(""); + $("#divAddEditRecordData").hide(); + $("#divEditRecordDataSoa").hide(); + $("#divAddEditRecordDataMx").show(); + $("#divAddEditRecordDataSrv").hide(); + $("#divAddEditRecordDataCaa").hide(); + break; + + case "TXT": + $("#lblAddEditRecordDataValue").text("Text Data"); + $("#txtAddEditRecordDataValue").val(""); + $("#divAddEditRecordData").show(); + $("#divEditRecordDataSoa").hide(); + $("#divAddEditRecordDataMx").hide(); + $("#divAddEditRecordDataSrv").hide(); + $("#divAddEditRecordDataCaa").hide(); + break; + + case "AAAA": + $("#lblAddEditRecordDataValue").text("IPv6 Address"); + $("#txtAddEditRecordDataValue").val(""); + $("#divAddEditRecordData").show(); + $("#divEditRecordDataSoa").hide(); + $("#divAddEditRecordDataMx").hide(); + $("#divAddEditRecordDataSrv").hide(); + $("#divAddEditRecordDataCaa").hide(); + break; + + case "SRV": + $("#txtAddEditRecordName").prop("placeholder", "_service._protocol.name"); + $("#txtAddEditRecordDataSrvPriority").val(""); + $("#txtAddEditRecordDataSrvWeight").val(""); + $("#txtAddEditRecordDataSrvPort").val(""); + $("#txtAddEditRecordDataSrvTarget").val(""); + $("#divAddEditRecordData").hide(); + $("#divEditRecordDataSoa").hide(); + $("#divAddEditRecordDataMx").hide(); + $("#divAddEditRecordDataSrv").show(); + $("#divAddEditRecordDataCaa").hide(); + break; + + case "CAA": + $("#txtAddEditRecordDataCaaFlags").val(""); + $("#txtAddEditRecordDataCaaTag").val(""); + $("#txtAddEditRecordDataCaaValue").val(""); + $("#divAddEditRecordData").hide(); + $("#divEditRecordDataSoa").hide(); + $("#divAddEditRecordDataMx").hide(); + $("#divAddEditRecordDataSrv").hide(); + $("#divAddEditRecordDataCaa").show(); + break; + } +} + +function addRecord() { + var btn = $("#btnAddEditRecord"); + var divAddEditRecordAlert = $("#divAddEditRecordAlert"); + + var domain; + { + var subDomain = $("#txtAddEditRecordName").val(); + if (subDomain === "") + subDomain = "@"; + + var zone = $("#titleEditZone").text(); + + if (subDomain === "@") + domain = zone; + else if (zone === ".") + domain = subDomain + "."; + else + domain = subDomain + "." + zone; + } + + var type = $("#optAddEditRecordType").val(); + + var ttl = $("#txtAddEditRecordTtl").val(); + if (ttl === "") + ttl = 3600; + + var apiUrl = "/api/addRecord?token=" + token + "&domain=" + encodeURIComponent(domain) + "&type=" + type + "&ttl=" + ttl; + + switch (type) { + case "A": + case "NS": + case "PTR": + case "TXT": + case "AAAA": + var value = $("#txtAddEditRecordDataValue").val(); + if (value === "") { + showAlert("warning", "Missing!", "Please enter a suitable value to add the record.", divAddEditRecordAlert); + $("#txtAddEditRecordDataValue").focus(); + return; + } + + apiUrl += "&value=" + encodeURIComponent(value); + break; + + case "CNAME": + var subDomainName = $("#txtAddEditRecordName").val(); + if ((subDomainName === "") || (subDomainName === "@")) { + showAlert("warning", "Missing!", "Please enter a name for the CNAME record.", divAddEditRecordAlert); + $("#txtAddEditRecordName").focus(); + return; + } + + var value = $("#txtAddEditRecordDataValue").val(); + if (value === "") { + showAlert("warning", "Missing!", "Please enter a suitable value to add the record.", divAddEditRecordAlert); + $("#txtAddEditRecordDataValue").focus(); + return; + } + + apiUrl += "&value=" + encodeURIComponent(value); + break; + + case "MX": + var preference = $("#txtAddEditRecordDataMxPreference").val(); + if (preference === "") + preference = 1; + + var value = $("#txtAddEditRecordDataMxExchange").val(); + if (value === "") { + showAlert("warning", "Missing!", "Please enter an mail exchange domain name into the exchange field.", divAddEditRecordAlert); + $("#txtAddEditRecordDataMxExchange").focus(); + return; + } + + apiUrl += "&preference=" + preference + "&value=" + encodeURIComponent(value); + break; + + case "SRV": + if ($("#txtAddEditRecordName").val() === "") { + showAlert("warning", "Missing!", "Please enter a name that includes service and protocol labels.", divAddEditRecordAlert); + $("#txtAddEditRecordName").focus(); + return; + } + + var priority = $("#txtAddEditRecordDataSrvPriority").val(); + if (priority === "") { + showAlert("warning", "Missing!", "Please enter a suitable priority.", divAddEditRecordAlert); + $("#txtAddEditRecordDataSrvPriority").focus(); + return; + } + + var weight = $("#txtAddEditRecordDataSrvWeight").val(); + if (weight === "") { + showAlert("warning", "Missing!", "Please enter a suitable weight.", divAddEditRecordAlert); + $("#txtAddEditRecordDataSrvWeight").focus(); + return; + } + + var port = $("#txtAddEditRecordDataSrvPort").val(); + if (port === "") { + showAlert("warning", "Missing!", "Please enter a suitable port number.", divAddEditRecordAlert); + $("#txtAddEditRecordDataSrvPort").focus(); + return; + } + + var value = $("#txtAddEditRecordDataSrvTarget").val(); + if (value === "") { + showAlert("warning", "Missing!", "Please enter a suitable value into the target field.", divAddEditRecordAlert); + $("#txtAddEditRecordDataSrvTarget").focus(); + return; + } + + apiUrl += "&priority=" + priority + "&weight=" + weight + "&port=" + port + "&value=" + encodeURIComponent(value); + break; + + case "CAA": + var flags = $("#txtAddEditRecordDataCaaFlags").val(); + if (flags === "") + flags = 0; + + var tag = $("#txtAddEditRecordDataCaaTag").val(); + if (tag === "") + tag = "issue"; + + var value = $("#txtAddEditRecordDataCaaValue").val(); + if (value === "") { + showAlert("warning", "Missing!", "Please enter a suitable value into the authority field.", divAddEditRecordAlert); + $("#txtAddEditRecordDataCaaValue").focus(); + return; + } + + apiUrl += "&flags=" + flags + "&tag=" + encodeURIComponent(tag) + "&value=" + encodeURIComponent(value); + break; + } + + btn.button("loading"); + + HTTPRequest({ + url: apiUrl, + success: function (responseJSON) { + $("#modalAddEditRecord").modal("hide"); + showEditZone(zone); + showAlert("success", "Record Added!", "Resource record was added successfully."); + }, + error: function () { + btn.button('reset'); + }, + invalidToken: function () { + showPageLogin(); + }, + objAlertPlaceholder: divAddEditRecordAlert + }); +} + +function showEditRecordModal(objBtn) { + var btn = $(objBtn); + var id = btn.attr("data-id"); + var divData = $("#data" + id); + + var zone = $("#titleEditZone").text(); + var name = divData.attr("data-record-name"); + var type = divData.attr("data-record-type"); + var ttl = divData.attr("data-record-ttl"); + + if (name === zone) + name = "@"; + else + name = name.replace("." + zone, ""); + + clearAddEditForm(); + $("#titleAddEditRecord").text("Edit Record"); + $("#optEditRecordTypeSoa").show(); + $("#optAddEditRecordType").val(type); + modifyAddRecordForm(); + + $("#txtAddEditRecordName").val(name); + $("#txtAddEditRecordTtl").val(ttl) + + switch (type) { + case "A": + case "NS": + case "CNAME": + case "PTR": + case "TXT": + case "AAAA": + $("#txtAddEditRecordDataValue").val(divData.attr("data-record-value")); + break; + + case "SOA": + $("#txtEditRecordDataSoaMasterNameServer").val(divData.attr("data-record-mname")); + $("#txtEditRecordDataSoaResponsiblePerson").val(divData.attr("data-record-rperson")); + $("#txtEditRecordDataSoaSerial").val(divData.attr("data-record-serial")); + $("#txtEditRecordDataSoaRefresh").val(divData.attr("data-record-refresh")); + $("#txtEditRecordDataSoaRetry").val(divData.attr("data-record-retry")); + $("#txtEditRecordDataSoaExpire").val(divData.attr("data-record-expire")); + $("#txtEditRecordDataSoaMinimum").val(divData.attr("data-record-minimum")); + break; + + case "MX": + $("#txtAddEditRecordDataMxPreference").val(divData.attr("data-record-preference")); + $("#txtAddEditRecordDataMxExchange").val(divData.attr("data-record-value")); + break; + + case "SRV": + $("#txtAddEditRecordDataSrvPriority").val(divData.attr("data-record-priority")); + $("#txtAddEditRecordDataSrvWeight").val(divData.attr("data-record-weight")); + $("#txtAddEditRecordDataSrvPort").val(divData.attr("data-record-port")); + $("#txtAddEditRecordDataSrvTarget").val(divData.attr("data-record-value")); + break; + + case "CAA": + $("#txtAddEditRecordDataCaaFlags").val(divData.attr("data-record-flags")); + $("#txtAddEditRecordDataCaaTag").val(divData.attr("data-record-tag")); + $("#txtAddEditRecordDataCaaValue").val(divData.attr("data-record-value")); + break; + + default: + showAlert("warning", "Not Supported!", "Record type not supported for edit."); + return; + } + + $("#txtAddEditRecordName").prop("disabled", (type === "SOA")); + $("#optAddEditRecordType").prop("disabled", true); + + $("#btnAddEditRecord").attr("data-id", id); + $("#btnAddEditRecord").attr("onclick", "updateRecord(); return false;"); + + $("#modalAddEditRecord").modal("show"); +} + +function updateRecord() { + var btn = $("#btnAddEditRecord"); + var divAddEditRecordAlert = $("#divAddEditRecordAlert"); + + var id = btn.attr("data-id"); + var divData = $("#data" + id); + + var zone = $("#titleEditZone").text(); + var type = divData.attr("data-record-type"); + var domain = divData.attr("data-record-name"); + + if (domain === "") + domain = "."; + + var newDomain; + { + var newSubDomain = $("#txtAddEditRecordName").val(); + if (newSubDomain === "") + newSubDomain = "@"; + + if (newSubDomain === "@") + newDomain = zone; + else if (zone === ".") + newDomain = newSubDomain + "."; + else + newDomain = newSubDomain + "." + zone; + } + + var ttl = $("#txtAddEditRecordTtl").val(); + if (ttl === "") + ttl = 3600; + + var value = divData.attr("data-record-value"); + var disable = (divData.attr("data-record-disabled") === "true"); + + var apiUrl = "/api/updateRecord?token=" + token + "&type=" + type + "&domain=" + encodeURIComponent(domain) + "&newDomain=" + encodeURIComponent(newDomain) + "&ttl=" + ttl + "&value=" + encodeURIComponent(value) + "&disable=" + disable; + + switch (type) { + case "A": + case "NS": + case "PTR": + case "TXT": + case "AAAA": + var newValue = $("#txtAddEditRecordDataValue").val(); + if (newValue === "") { + showAlert("warning", "Missing!", "Please enter a suitable value to add the record.", divAddEditRecordAlert); + $("#txtAddEditRecordDataValue").focus(); + return; + } + + apiUrl += "&newValue=" + encodeURIComponent(newValue); + break; + + case "CNAME": + var subDomainName = $("#txtAddEditRecordName").val(); + if ((subDomainName === "") || (subDomainName === "@")) { + showAlert("warning", "Missing!", "Please enter a name for the CNAME record.", divAddEditRecordAlert); + $("#txtAddEditRecordName").focus(); + return; + } + + var newValue = $("#txtAddEditRecordDataValue").val(); + if (newValue === "") { + showAlert("warning", "Missing!", "Please enter a suitable value to add the record.", divAddEditRecordAlert); + $("#txtAddEditRecordDataValue").focus(); + return; + } + + apiUrl += "&newValue=" + encodeURIComponent(newValue); + break; + + case "SOA": + var masterNameServer = $("#txtEditRecordDataSoaMasterNameServer").val(); + if (masterNameServer === "") { + showAlert("warning", "Missing!", "Please enter a value for master name server.", divAddEditRecordAlert); + $("#txtEditRecordDataSoaMasterNameServer").focus(); + return; + } + + var responsiblePerson = $("#txtEditRecordDataSoaResponsiblePerson").val(); + if (responsiblePerson === "") { + showAlert("warning", "Missing!", "Please enter a value for responsible person.", divAddEditRecordAlert); + $("#txtEditRecordDataSoaResponsiblePerson").focus(); + return; + } + + var serial = $("#txtEditRecordDataSoaSerial").val(); + if (serial === "") { + showAlert("warning", "Missing!", "Please enter a value for serial.", divAddEditRecordAlert); + $("#txtEditRecordDataSoaSerial").focus(); + return; + } + + var refresh = $("#txtEditRecordDataSoaRefresh").val(); + if (refresh === "") { + showAlert("warning", "Missing!", "Please enter a value for refresh.", divAddEditRecordAlert); + $("#txtEditRecordDataSoaRefresh").focus(); + return; + } + + var retry = $("#txtEditRecordDataSoaRetry").val(); + if (retry === "") { + showAlert("warning", "Missing!", "Please enter a value for retry.", divAddEditRecordAlert); + $("#txtEditRecordDataSoaRetry").focus(); + return; + } + + var expire = $("#txtEditRecordDataSoaExpire").val(); + if (expire === "") { + showAlert("warning", "Missing!", "Please enter a value for expire.", divAddEditRecordAlert); + $("#txtEditRecordDataSoaExpire").focus(); + return; + } + + var minimum = $("#txtEditRecordDataSoaMinimum").val(); + if (minimum === "") { + showAlert("warning", "Missing!", "Please enter a value for minimum.", divAddEditRecordAlert); + $("#txtEditRecordDataSoaMinimum").focus(); + return; + } + + apiUrl += "&masterNameServer=" + encodeURIComponent(masterNameServer) + + "&responsiblePerson=" + encodeURIComponent(responsiblePerson) + + "&serial=" + encodeURIComponent(serial) + + "&refresh=" + encodeURIComponent(refresh) + + "&retry=" + encodeURIComponent(retry) + + "&expire=" + encodeURIComponent(expire) + + "&minimum=" + encodeURIComponent(minimum); + break; + + case "MX": + var preference = $("#txtAddEditRecordDataMxPreference").val(); + if (preference === "") + preference = 1; + + var newValue = $("#txtAddEditRecordDataMxExchange").val(); + if (newValue === "") { + showAlert("warning", "Missing!", "Please enter an mail exchange domain name into the exchange field.", divAddEditRecordAlert); + $("#txtAddEditRecordDataMxExchange").focus(); + return; + } + + apiUrl += "&preference=" + preference + "&newValue=" + encodeURIComponent(newValue); + break; + + case "SRV": + if ($("#txtAddEditRecordName").val() === "") { + showAlert("warning", "Missing!", "Please enter a name that includes service and protocol labels.", divAddEditRecordAlert); + $("#txtAddEditRecordName").focus(); + return; + } + + var port = divData.attr("data-record-port"); + + var priority = $("#txtAddEditRecordDataSrvPriority").val(); + if (priority === "") { + showAlert("warning", "Missing!", "Please enter a suitable priority.", divAddEditRecordAlert); + $("#txtAddEditRecordDataSrvPriority").focus(); + return; + } + + var weight = $("#txtAddEditRecordDataSrvWeight").val(); + if (weight === "") { + showAlert("warning", "Missing!", "Please enter a suitable weight.", divAddEditRecordAlert); + $("#txtAddEditRecordDataSrvWeight").focus(); + return; + } + + var newPort = $("#txtAddEditRecordDataSrvPort").val(); + if (newPort === "") { + showAlert("warning", "Missing!", "Please enter a suitable port number.", divAddEditRecordAlert); + $("#txtAddEditRecordDataSrvPort").focus(); + return; + } + + var newValue = $("#txtAddEditRecordDataSrvTarget").val(); + if (newValue === "") { + showAlert("warning", "Missing!", "Please enter a suitable value into the target field.", divAddEditRecordAlert); + $("#txtAddEditRecordDataSrvTarget").focus(); + return; + } + + apiUrl += "&port=" + port + "&priority=" + priority + "&weight=" + weight + "&newPort=" + newPort + "&newValue=" + encodeURIComponent(newValue); + break; + + case "CAA": + var flags = divData.attr("data-record-flags"); + var tag = divData.attr("data-record-tag"); + + var newFlags = $("#txtAddEditRecordDataCaaFlags").val(); + if (newFlags === "") + newFlags = 0; + + var newTag = $("#txtAddEditRecordDataCaaTag").val(); + if (newTag === "") + newTag = "issue"; + + var newValue = $("#txtAddEditRecordDataCaaValue").val(); + if (newValue === "") { + showAlert("warning", "Missing!", "Please enter a suitable value into the authority field.", divAddEditRecordAlert); + $("#txtAddEditRecordDataCaaValue").focus(); + return; + } + + apiUrl += "&flags=" + flags + "&tag=" + encodeURIComponent(tag) + "&newFlags=" + newFlags + "&newTag=" + encodeURIComponent(newTag) + "&newValue=" + encodeURIComponent(newValue); + break; + } + + btn.button('loading'); + + HTTPRequest({ + url: apiUrl, + success: function (responseJSON) { + $("#modalAddEditRecord").modal("hide"); + showEditZone(zone); + showAlert("success", "Record Updated!", "Resource record was updated successfully."); + }, + error: function () { + btn.button('reset'); + }, + invalidToken: function () { + showPageLogin(); + }, + objAlertPlaceholder: divAddEditRecordAlert + }); +} + +function updateRecordState(objBtn, disable) { + var btn = $(objBtn); + var id = btn.attr("data-id"); + var divData = $("#data" + id); + + var type = divData.attr("data-record-type"); + var domain = divData.attr("data-record-name"); + var ttl = divData.attr("data-record-ttl"); + var value = divData.attr("data-record-value"); + + if (domain === "") + domain = "."; + + if (disable && !confirm("Are you sure to disable the " + type + " record '" + domain + "' with value '" + value + "'?")) + return; + + var apiUrl = "/api/updateRecord?token=" + token + "&type=" + type + "&domain=" + encodeURIComponent(domain) + "&ttl=" + ttl + "&value=" + encodeURIComponent(value) + "&disable=" + disable; + + switch (type) { + case "MX": + apiUrl += "&preference=" + divData.attr("data-record-preference"); + break; + + case "SRV": + apiUrl += "&port=" + divData.attr("data-record-port") + "&priority=" + divData.attr("data-record-priority") + "&weight=" + divData.attr("data-record-weight"); + break; + + case "CAA": + apiUrl += "&flags=" + divData.attr("data-record-flags") + "&tag=" + encodeURIComponent(divData.attr("data-record-tag")); + break; + } + + btn.button('loading'); + + HTTPRequest({ + url: apiUrl, + success: function (responseJSON) { + btn.button('reset'); + + if (disable) { + $("#btnEnableRecord" + id).show(); + $("#btnDisableRecord" + id).hide(); + + showAlert("success", "Record Disabled!", "Resource record was disabled successfully."); + } + else { + $("#btnEnableRecord" + id).hide(); + $("#btnDisableRecord" + id).show(); + + showAlert("success", "Record Enabled!", "Resource record was enabled successfully."); + } + }, + error: function () { + btn.button('reset'); + }, + invalidToken: function () { + showPageLogin(); + } + }); +} + +function deleteRecord(objBtn) { + var btn = $(objBtn); + var id = btn.attr("data-id"); + var divData = $("#data" + id); + + var domain = divData.attr("data-record-name"); + var type = divData.attr("data-record-type"); + var value = divData.attr("data-record-value"); + + if (domain === "") + domain = "."; + + if (!confirm("Are you sure to permanently delete the " + type + " record '" + domain + "' with value '" + value + "'?")) + return false; + + var apiUrl = "/api/deleteRecord?token=" + token + "&domain=" + domain + "&type=" + type + "&value=" + encodeURIComponent(value); + + switch (type) { + case "SRV": + apiUrl += "&port=" + divData.attr("data-record-port"); + break; + + case "CAA": + apiUrl += "&flags=" + divData.attr("data-record-flags") + "&tag=" + encodeURIComponent(divData.attr("data-record-tag")); + break; + } + + btn.button('loading'); + + HTTPRequest({ + url: apiUrl, + success: function (responseJSON) { + $("#tr" + id).remove(); + $("#tableEditZoneFooter").html("Total Records: " + $('#tableEditZone >tbody >tr').length + ""); + + showAlert("success", "Record Deleted!", "Resource record was deleted successfully."); + }, + error: function () { + btn.button('reset'); + }, + invalidToken: function () { + showPageLogin(); + } + }); +}