lmc/dns/domain_soa/domain_soa.js

165 lines
4.9 KiB
JavaScript
Raw Permalink Normal View History

2020-01-18 17:50:00 -05:00
/*
* This file is part of Linode Manager Classic.
*
* Linode Manager Classic 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.
*
* Linode Manager Classic 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 Linode Manager Classic. If not, see <https://www.gnu.org/licenses/>.
*/
import { settings, elements, apiGet, apiPut, parseParams, setupHeader } from "/global.js";
(function()
{
// Element names specific to this page
elements.axfr = "axfr";
elements.email = "email";
elements.expire = "expire";
elements.domain = "domain";
elements.domainLabel = "domain-label";
elements.domainTag = "domain-tag";
elements.domainTagLink = "domain-tag-link";
elements.refresh = "refresh";
elements.retry = "retry";
elements.saveButton = "save-button";
elements.status = "status";
elements.tags = "tags";
elements.ttl = "ttl";
// Data recieved from API calls
var data = {};
data.domain = {};
// Static references to UI elements
var ui = {};
ui.axfr = {};
ui.email = {};
ui.expire = {};
ui.domain = {};
ui.domainLabel = {};
ui.domainTag = {};
ui.domainTagLink = {};
ui.refresh = {};
ui.retry = {};
ui.saveButton = {};
ui.status = {};
ui.tags = {};
ui.ttl = {};
// Callback for domain details API call
var displayDetails = function(response)
{
data.domain = response;
// Set page title and header stuff
document.title += " // " + data.domain.domain;
ui.domainLabel.innerHTML = data.domain.domain;
if (data.domain.tags.length == 1) {
ui.domainTagLink.href = "/dns?tag=" + data.domain.tags[0];
ui.domainTagLink.innerHTML = "(" + data.domain.tags[0] + ")";
ui.domainTag.style.display = "inline";
}
// Set form info
ui.domain.value = data.domain.domain;
ui.email.value = data.domain.soa_email;
ui.status.value = data.domain.status;
ui.tags.value = data.domain.tags.join(",");
ui.axfr.value = data.domain.axfr_ips.join("\n");
ui.ttl.value = data.domain.ttl_sec;
ui.refresh.value = data.domain.refresh_sec;
ui.retry.value = data.domain.retry_sec;
ui.expire.value = data.domain.expire_sec;
ui.saveButton.disabled = false;
};
// Click handler for save button
var handleSave = function(event)
{
if (event.currentTarget.disabled)
return;
// This request can take a few seconds,
// so disable the button to prevent antsy users from double-submitting
ui.saveButton.disabled = true;
var req = {
"domain": ui.domain.value,
"soa_email": ui.email.value,
"status": ui.status.value,
"tags": [],
"axfr_ips": [],
"ttl_sec": parseInt(ui.ttl.value),
"refresh_sec": parseInt(ui.refresh.value),
"retry_sec": parseInt(ui.retry.value),
"expire_sec": parseInt(ui.expire.value)
};
if (ui.tags.value.length)
req.tags = ui.tags.value.split(",");
if (ui.axfr.value.length) {
var axfrLines = ui.axfr.value.split("\n");
for (var i = 0; i < axfrLines.length; i++)
req.axfr_ips = req.axfr_ips.concat(axfrLines[i].split(";"));
}
apiPut("/domains/" + data.params.did, req, function(response)
{
location.href = "/dns/domain?did=" + data.params.did;
});
};
// Initial setup
var setup = function()
{
// Parse URL parameters
data.params = parseParams();
// We need a domain ID, so die if we don't have it
if (!data.params.did) {
alert("No domain ID supplied!");
return;
}
setupHeader();
// Update links on page to include proper Linode ID
var anchors = document.getElementsByTagName("a");
for (var i = 0; i < anchors.length; i++)
anchors[i].href = anchors[i].href.replace("did=0", "did=" + data.params.did);
// Get element references
ui.axfr = document.getElementById(elements.axfr);
ui.email = document.getElementById(elements.email);
ui.expire = document.getElementById(elements.expire);
ui.domain = document.getElementById(elements.domain);
ui.domainLabel = document.getElementById(elements.domainLabel);
ui.domainTag = document.getElementById(elements.domainTag);
ui.domainTagLink = document.getElementById(elements.domainTagLink);
ui.refresh = document.getElementById(elements.refresh);
ui.retry = document.getElementById(elements.retry);
ui.saveButton = document.getElementById(elements.saveButton);
ui.status = document.getElementById(elements.status);
ui.tags = document.getElementById(elements.tags);
ui.ttl = document.getElementById(elements.ttl);
// Attach event handlers
ui.saveButton.addEventListener("click", handleSave);
// Get data from API
apiGet("/domains/" + data.params.did, displayDetails, null);
};
// Attach onload handler
window.addEventListener("load", setup);
})();