"
- }
-
- 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 = "
";
-
- for (var i = 0; i < records.length; i++) {
- list += renderResourceRecord(records[i], domain);
- }
-
- list += renderAddResourceRecordForm();
-
- list += "
";
-
- //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 += "
");
+
+ 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 += "