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, parseParams, setupHeader } from "/global.js";
|
|
|
|
|
|
|
|
(function()
|
|
|
|
{
|
|
|
|
// Element names specific to this page
|
|
|
|
elements.a = "a";
|
|
|
|
elements.caa = "caa";
|
|
|
|
elements.cname = "cname";
|
|
|
|
elements.domainLabel = "domain-label";
|
|
|
|
elements.domainTag = "domain-tag";
|
|
|
|
elements.domainTagLink = "domain-tag-link";
|
|
|
|
elements.email = "email";
|
|
|
|
elements.expire = "expire";
|
|
|
|
elements.lmcRow = "lmc-tr1";
|
|
|
|
elements.lmcRowAlt = "lmc-tr2";
|
|
|
|
elements.mx = "mx";
|
|
|
|
elements.ns = "ns";
|
|
|
|
elements.refresh = "refresh";
|
|
|
|
elements.retry = "retry";
|
|
|
|
elements.srv = "srv";
|
|
|
|
elements.subdomain = "subdomain";
|
|
|
|
elements.ttl = "ttl";
|
|
|
|
elements.txt = "txt";
|
|
|
|
|
|
|
|
// Data recieved from API calls
|
|
|
|
var data = {};
|
|
|
|
data.domain = {};
|
|
|
|
data.records = [];
|
|
|
|
|
|
|
|
// Static references to UI elements
|
|
|
|
var ui = {};
|
|
|
|
ui.a = {};
|
|
|
|
ui.caa = {};
|
|
|
|
ui.cname = {};
|
|
|
|
ui.domainLabel = {};
|
|
|
|
ui.domainTag = {};
|
|
|
|
ui.domainTagLink = {};
|
|
|
|
ui.email = {};
|
|
|
|
ui.expire = {};
|
|
|
|
ui.mx = {};
|
|
|
|
ui.ns = {};
|
|
|
|
ui.refresh = {};
|
|
|
|
ui.retry = {};
|
|
|
|
ui.srv = {};
|
|
|
|
ui.subdomains = [];
|
|
|
|
ui.ttl = {};
|
|
|
|
ui.txt = {};
|
|
|
|
|
|
|
|
// Creates an A record table row
|
|
|
|
var createARow = function(record, alt)
|
|
|
|
{
|
|
|
|
var row = document.createElement("tr");
|
|
|
|
if (alt)
|
|
|
|
row.className = elements.lmcRowAlt;
|
|
|
|
else
|
|
|
|
row.className = elements.lmcRow;
|
|
|
|
|
|
|
|
var hostname = document.createElement("td");
|
|
|
|
hostname.innerHTML = record.name;
|
|
|
|
row.appendChild(hostname);
|
|
|
|
|
|
|
|
var ip = document.createElement("td");
|
|
|
|
ip.innerHTML = record.target;
|
|
|
|
row.appendChild(ip);
|
|
|
|
|
|
|
|
var ttl = document.createElement("td");
|
|
|
|
if (record.ttl_sec == 0)
|
|
|
|
ttl.innerHTML = "Default";
|
|
|
|
else
|
|
|
|
ttl.innerHTML = record.ttl_sec;
|
|
|
|
row.appendChild(ttl);
|
|
|
|
|
|
|
|
row.appendChild(createOptions(record));
|
|
|
|
|
|
|
|
return row;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Creates a CAA record table row
|
|
|
|
var createCAARow = function(record, alt)
|
|
|
|
{
|
|
|
|
var row = document.createElement("tr");
|
|
|
|
if (alt)
|
|
|
|
row.className = elements.lmcRowAlt;
|
|
|
|
else
|
|
|
|
row.className = elements.lmcRow;
|
|
|
|
|
|
|
|
var name = document.createElement("td");
|
|
|
|
name.innerHTML = record.name;
|
|
|
|
row.appendChild(name);
|
|
|
|
|
|
|
|
var tag = document.createElement("td");
|
|
|
|
tag.innerHTML = record.tag;
|
|
|
|
row.appendChild(tag);
|
|
|
|
|
|
|
|
var value = document.createElement("td");
|
|
|
|
value.innerHTML = record.target;
|
|
|
|
row.appendChild(value);
|
|
|
|
|
|
|
|
var ttl = document.createElement("td");
|
|
|
|
if (record.ttl_sec == 0)
|
|
|
|
ttl.innerHTML = "Default";
|
|
|
|
else
|
|
|
|
ttl.innerHTML = record.ttl_sec;
|
|
|
|
row.appendChild(ttl);
|
|
|
|
|
|
|
|
row.appendChild(createOptions(record));
|
|
|
|
|
|
|
|
return row;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Creates a CNAME record table row
|
|
|
|
var createCNAMERow = function(record, alt)
|
|
|
|
{
|
|
|
|
var row = document.createElement("tr");
|
|
|
|
if (alt)
|
|
|
|
row.className = elements.lmcRowAlt;
|
|
|
|
else
|
|
|
|
row.className = elements.lmcRow;
|
|
|
|
|
|
|
|
var hostname = document.createElement("td");
|
|
|
|
hostname.innerHTML = record.name;
|
|
|
|
row.appendChild(hostname);
|
|
|
|
|
|
|
|
var alias = document.createElement("td");
|
|
|
|
alias.innerHTML = record.target;
|
|
|
|
row.appendChild(alias);
|
|
|
|
|
|
|
|
var ttl = document.createElement("td");
|
|
|
|
if (record.ttl_sec == 0)
|
|
|
|
ttl.innerHTML = "Default";
|
|
|
|
else
|
|
|
|
ttl.innerHTML = record.ttl_sec;
|
|
|
|
row.appendChild(ttl);
|
|
|
|
|
|
|
|
row.appendChild(createOptions(record));
|
|
|
|
|
|
|
|
return row;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Creates an MX record table row
|
|
|
|
var createMXRow = function(record, alt)
|
|
|
|
{
|
|
|
|
var row = document.createElement("tr");
|
|
|
|
if (alt)
|
|
|
|
row.className = elements.lmcRowAlt;
|
|
|
|
else
|
|
|
|
row.className = elements.lmcRow;
|
|
|
|
|
|
|
|
var server = document.createElement("td");
|
|
|
|
server.innerHTML = record.target;
|
|
|
|
row.appendChild(server);
|
|
|
|
|
|
|
|
var preference = document.createElement("td");
|
|
|
|
preference.innerHTML = record.priority;
|
|
|
|
row.appendChild(preference);
|
|
|
|
|
|
|
|
var subdomain = document.createElement("td");
|
|
|
|
subdomain.innerHTML = record.name;
|
|
|
|
row.appendChild(subdomain);
|
|
|
|
|
|
|
|
var ttl = document.createElement("td");
|
|
|
|
if (record.ttl_sec == 0)
|
|
|
|
ttl.innerHTML = "Default";
|
|
|
|
else
|
|
|
|
ttl.innerHTML = record.ttl_sec;
|
|
|
|
row.appendChild(ttl);
|
|
|
|
|
|
|
|
row.appendChild(createOptions(record));
|
|
|
|
|
|
|
|
return row;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Creates an NS record table row
|
|
|
|
var createNSRow = function(record, alt)
|
|
|
|
{
|
|
|
|
var row = document.createElement("tr");
|
|
|
|
if (alt)
|
|
|
|
row.className = elements.lmcRowAlt;
|
|
|
|
else
|
|
|
|
row.className = elements.lmcRow;
|
|
|
|
|
|
|
|
var nameserver = document.createElement("td");
|
|
|
|
nameserver.innerHTML = record.target;
|
|
|
|
row.appendChild(nameserver);
|
|
|
|
|
|
|
|
var subdomain = document.createElement("td");
|
|
|
|
subdomain.className = elements.subdomain;
|
|
|
|
if (record.name)
|
|
|
|
subdomain.innerHTML = record.name;
|
|
|
|
else if (data.domain.domain)
|
|
|
|
subdomain.innerHTML = data.domain.domain;
|
|
|
|
row.appendChild(subdomain);
|
|
|
|
|
|
|
|
var ttl = document.createElement("td");
|
|
|
|
if (record.ttl_sec == 0)
|
|
|
|
ttl.innerHTML = "Default";
|
|
|
|
else
|
|
|
|
ttl.innerHTML = record.ttl_sec;
|
|
|
|
row.appendChild(ttl);
|
|
|
|
|
|
|
|
row.appendChild(createOptions(record));
|
|
|
|
|
|
|
|
return row;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Creates the options section for a record
|
|
|
|
var createOptions = function(record)
|
|
|
|
{
|
|
|
|
var options = document.createElement("td");
|
|
|
|
var editLink = document.createElement("a");
|
|
|
|
editLink.href = "/dns/resource?did=" + data.params.did + "&rid=" + record.id;
|
|
|
|
editLink.innerHTML = "Edit";
|
|
|
|
var separator = document.createElement("span");
|
|
|
|
separator.innerHTML = " | ";
|
|
|
|
var removeLink = document.createElement("a");
|
|
|
|
removeLink.href = "/dns/resource_delete?did=" + data.params.did + "&rid=" + record.id;
|
|
|
|
removeLink.innerHTML = "Remove";
|
|
|
|
options.appendChild(editLink);
|
|
|
|
options.appendChild(separator);
|
|
|
|
options.appendChild(removeLink);
|
|
|
|
|
|
|
|
return options;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Creates an SRV record table row
|
|
|
|
var createSRVRow = function(record, alt)
|
|
|
|
{
|
|
|
|
var row = document.createElement("tr");
|
|
|
|
if (alt)
|
|
|
|
row.className = elements.lmcRowAlt;
|
|
|
|
else
|
|
|
|
row.className = elements.lmcRow;
|
|
|
|
|
|
|
|
var service = document.createElement("td");
|
|
|
|
service.innerHTML = record.name;
|
|
|
|
row.appendChild(service);
|
|
|
|
|
|
|
|
var domain = document.createElement("td");
|
|
|
|
domain.className = elements.subdomain;
|
|
|
|
if (data.domain.domain)
|
|
|
|
domain.innerHTML = data.domain.domain;
|
|
|
|
row.appendChild(domain);
|
|
|
|
|
|
|
|
var priority = document.createElement("td");
|
|
|
|
priority.innerHTML = record.priority;
|
|
|
|
row.appendChild(priority);
|
|
|
|
|
|
|
|
var weight = document.createElement("td");
|
|
|
|
weight.innerHTML = record.weight;
|
|
|
|
row.appendChild(weight);
|
|
|
|
|
|
|
|
var port = document.createElement("td");
|
|
|
|
port.innerHTML = record.port;
|
|
|
|
row.appendChild(port);
|
|
|
|
|
|
|
|
var target = document.createElement("td");
|
|
|
|
target.innerHTML = record.target;
|
|
|
|
row.appendChild(target);
|
|
|
|
|
|
|
|
var ttl = document.createElement("td");
|
|
|
|
if (record.ttl_sec == 0)
|
|
|
|
ttl.innerHTML = "Default";
|
|
|
|
else
|
|
|
|
ttl.innerHTML = record.ttl_sec;
|
|
|
|
row.appendChild(ttl);
|
|
|
|
|
|
|
|
row.appendChild(createOptions(record));
|
|
|
|
|
|
|
|
return row;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Creates a TXT record table row
|
|
|
|
var createTXTRow = function(record, alt)
|
|
|
|
{
|
|
|
|
var row = document.createElement("tr");
|
|
|
|
if (alt)
|
|
|
|
row.className = elements.lmcRowAlt;
|
|
|
|
else
|
|
|
|
row.className = elements.lmcRow;
|
|
|
|
|
|
|
|
var name = document.createElement("td");
|
|
|
|
name.innerHTML = record.name;
|
|
|
|
row.appendChild(name);
|
|
|
|
|
|
|
|
var value = document.createElement("td");
|
|
|
|
value.innerHTML = record.target;
|
|
|
|
row.appendChild(value);
|
|
|
|
|
|
|
|
var ttl = document.createElement("td");
|
|
|
|
if (record.ttl_sec == 0)
|
|
|
|
ttl.innerHTML = "Default";
|
|
|
|
else
|
|
|
|
ttl.innerHTML = record.ttl_sec;
|
|
|
|
row.appendChild(ttl);
|
|
|
|
|
|
|
|
row.appendChild(createOptions(record));
|
|
|
|
|
|
|
|
return row;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Callback for domain details API call
|
|
|
|
var displayDetails = function(response)
|
|
|
|
{
|
|
|
|
data.domain = response;
|
|
|
|
|
2020-01-30 18:48:19 -05:00
|
|
|
// Redirect if this is a slave zone
|
|
|
|
if (data.domain.type == "slave") {
|
|
|
|
location.href = "/dns/domain_slave?did=" + data.domain.id;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-18 17:50:00 -05:00
|
|
|
// 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 SOA info
|
|
|
|
ui.email.innerHTML = data.domain.soa_email;
|
|
|
|
if (data.domain.ttl_sec == 0)
|
|
|
|
ui.ttl.innerHTML = "Default";
|
|
|
|
else
|
|
|
|
ui.ttl.innerHTML = data.domain.ttl_sec;
|
|
|
|
if (data.domain.refresh_sec == 0)
|
|
|
|
ui.refresh.innerHTML = "Default";
|
|
|
|
else
|
|
|
|
ui.refresh.innerHTML = data.domain.refresh_sec;
|
|
|
|
if (data.domain.retry_sec == 0)
|
|
|
|
ui.retry.innerHTML = "Default";
|
|
|
|
else
|
|
|
|
ui.retry.innerHTML = data.domain.retry_sec;
|
|
|
|
if (data.domain.expire_sec == 0)
|
|
|
|
ui.expire.innerHTML = "Default";
|
|
|
|
else
|
|
|
|
ui.expire.innerHTML = data.domain.expire_sec;
|
|
|
|
|
|
|
|
// Set NS subdomain labels
|
|
|
|
ui.subdomains = document.getElementsByClassName(elements.subdomain);
|
|
|
|
for (var i = 0; i < ui.subdomains.length; i++)
|
|
|
|
ui.subdomains[i].innerHTML = data.domain.domain;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Callback for records API call
|
|
|
|
var displayRecords = function(response)
|
|
|
|
{
|
|
|
|
// Add records to array
|
|
|
|
data.records = data.records.concat(response.data);
|
|
|
|
|
|
|
|
// Request the next page if there are more pages
|
|
|
|
if (response.page != response.pages) {
|
|
|
|
apiGet("/domains/" + data.params.did + "/records?page=" + (response.page + 1), displayRecords, null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort records by type
|
|
|
|
data.records.sort(function(a, b)
|
|
|
|
{
|
|
|
|
return a.type.localeCompare(b.type);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Add records into record tables
|
|
|
|
for (var i = 0; i < data.records.length; i++) {
|
|
|
|
switch (data.records[i].type) {
|
|
|
|
case "A":
|
|
|
|
case "AAAA":
|
|
|
|
ui.a.appendChild(createARow(data.records[i], ui.a.children.length % 2));
|
|
|
|
break;
|
|
|
|
case "CAA":
|
|
|
|
ui.caa.appendChild(createCAARow(data.records[i], ui.caa.children.length % 2));
|
|
|
|
break;
|
|
|
|
case "CNAME":
|
|
|
|
ui.cname.appendChild(createCNAMERow(data.records[i], ui.cname.children.length % 2));
|
|
|
|
break;
|
|
|
|
case "MX":
|
|
|
|
ui.mx.appendChild(createMXRow(data.records[i], ui.mx.children.length % 2));
|
|
|
|
break;
|
|
|
|
case "NS":
|
|
|
|
ui.ns.appendChild(createNSRow(data.records[i], ui.ns.children.length % 2));
|
|
|
|
break;
|
|
|
|
case "SRV":
|
|
|
|
ui.srv.appendChild(createSRVRow(data.records[i], ui.srv.children.length % 2));
|
|
|
|
break;
|
|
|
|
case "TXT":
|
|
|
|
ui.txt.appendChild(createTXTRow(data.records[i], ui.txt.children.length % 2));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log(data.records[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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.a = document.getElementById(elements.a);
|
|
|
|
ui.caa = document.getElementById(elements.caa);
|
|
|
|
ui.cname = document.getElementById(elements.cname);
|
|
|
|
ui.domainLabel = document.getElementById(elements.domainLabel);
|
|
|
|
ui.domainTag = document.getElementById(elements.domainTag);
|
|
|
|
ui.domainTagLink = document.getElementById(elements.domainTagLink);
|
|
|
|
ui.email = document.getElementById(elements.email);
|
|
|
|
ui.expire = document.getElementById(elements.expire);
|
|
|
|
ui.mx = document.getElementById(elements.mx);
|
|
|
|
ui.ns = document.getElementById(elements.ns);
|
|
|
|
ui.refresh = document.getElementById(elements.refresh);
|
|
|
|
ui.retry = document.getElementById(elements.retry);
|
|
|
|
ui.srv = document.getElementById(elements.srv);
|
|
|
|
ui.ttl = document.getElementById(elements.ttl);
|
|
|
|
ui.txt = document.getElementById(elements.txt);
|
|
|
|
|
|
|
|
// Get data from API
|
|
|
|
apiGet("/domains/" + data.params.did, displayDetails, null);
|
|
|
|
apiGet("/domains/" + data.params.did + "/records", displayRecords, null);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Attach onload handler
|
|
|
|
window.addEventListener("load", setup);
|
|
|
|
})();
|