Browse Source

Properly handle DNS slave zones

pull/2/head
L. Bradley LaBoon 2 years ago
parent
commit
772b24ad8f
  1. 10
      dns/dns.js
  2. 6
      dns/domain/domain.js
  3. 32
      dns/domain_slave/domain_slave.css
  4. 149
      dns/domain_slave/domain_slave.js
  5. 73
      dns/domain_slave/index.shtml

10
dns/dns.js

@ -51,7 +51,10 @@ import { settings, elements, apiGet, parseParams, setupHeader } from "/global.js
var name = document.createElement("td");
var nameLink = document.createElement("a");
nameLink.href = "/dns/domain?did=" + domain.id;
if (domain.type == "master")
nameLink.href = "/dns/domain?did=" + domain.id;
else
nameLink.href = "/dns/domain_slave?did=" + domain.id;
nameLink.innerHTML = domain.domain;
name.appendChild(nameLink);
row.appendChild(name);
@ -71,7 +74,10 @@ import { settings, elements, apiGet, parseParams, setupHeader } from "/global.js
var options = document.createElement("td");
options.className = elements.centerCell;
var editLink = document.createElement("a");
editLink.href = "/dns/domain?did=" + domain.id;
if (domain.type == "master")
editLink.href = "/dns/domain?did=" + domain.id;
else
editLink.href = "/dns/domain_slave?did=" + domain.id;
editLink.innerHTML = "Edit";
var separator = document.createElement("span");
separator.innerHTML = " | ";

6
dns/domain/domain.js

@ -320,6 +320,12 @@ import { settings, elements, apiGet, parseParams, setupHeader } from "/global.js
{
data.domain = response;
// Redirect if this is a slave zone
if (data.domain.type == "slave") {
location.href = "/dns/domain_slave?did=" + data.domain.id;
return;
}
// Set page title and header stuff
document.title += " // " + data.domain.domain;
ui.domainLabel.innerHTML = data.domain.domain;

32
dns/domain_slave/domain_slave.css

@ -0,0 +1,32 @@
/*
* 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 url('/global.css');
#domain-slave {
padding: 0px 15px 15px;
}
tbody tr td:first-of-type {
font-weight: bold;
text-align: right;
white-space: nowrap;
}
tbody tr:last-of-type {
border: none;
}

149
dns/domain_slave/domain_slave.js

@ -0,0 +1,149 @@
/*
* 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.domain = "domain";
elements.domainLabel = "domain-label";
elements.domainTag = "domain-tag";
elements.domainTagLink = "domain-tag-link";
elements.masters = "masters";
elements.saveButton = "save-button";
elements.tags = "tags";
elements.transfers = "transfers";
// Data recieved from API calls
var data = {};
data.domain = {};
// Static references to UI elements
var ui = {};
ui.domain = {};
ui.domainLabel = {};
ui.domainTag = {};
ui.domainTagLink = {};
ui.masters = {};
ui.saveButton = {};
ui.tags = {};
ui.transfers = {};
// Callback for domain details API call
var displayDetails = function(response)
{
data.domain = response;
// Redirect if this is a master zone
if (data.domain.type == "master") {
location.href = "/dns/domain?did=" + data.domain.id;
return;
}
// 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.tags.value = data.domain.tags.join(",");
ui.masters.value = data.domain.master_ips.join("\n");
ui.transfers.value = data.domain.axfr_ips.join("\n");
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,
"tags": [],
"master_ips": [],
"axfr_ips": []
};
if (ui.tags.value.length)
req.tags = ui.tags.value.split(",");
if (ui.masters.value.length)
var masterLines = ui.masters.value.split("\n");
for (var i = 0; i < masterLines.length; i++)
req.master_ips = req.master_ips.concat(masterLines[i].split(";"));
if (ui.transfers.value.length) {
var transferLines = ui.transfers.value.split("\n");
for (var i = 0; i < transferLines.length; i++)
req.axfr_ips = req.axfr_ips.concat(transferLines[i].split(";"));
}
apiPut("/domains/" + data.params.did, req, function(response)
{
location.href = "/dns";
});
};
// 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.domain = document.getElementById(elements.domain);
ui.domainLabel = document.getElementById(elements.domainLabel);
ui.domainTag = document.getElementById(elements.domainTag);
ui.domainTagLink = document.getElementById(elements.domainTagLink);
ui.masters = document.getElementById(elements.masters);
ui.saveButton = document.getElementById(elements.saveButton);
ui.tags = document.getElementById(elements.tags);
ui.transfers = document.getElementById(elements.transfers);
// 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);
})();

73
dns/domain_slave/index.shtml

@ -0,0 +1,73 @@
<!--
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/>.
-->
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LMC - Edit Domain</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="domain_slave.css" />
<script src="domain_slave.js" type="module"></script>
</head>
<body>
<!--#include virtual="/include/header.html"-->
<div id="main-content" class="wrapper">
<div id="top-links"><a href="/dns">DNS Manager</a> » <span id="domain-tag"><a id="domain-tag-link" href=""></a> » </span><a id="domain-label" href="/dns/domain_slave?did=0"></a> » <span class="top-links-title">Edit SOA Record</span></div>
<div id="domain-slave">
<table class="lmc-table">
<thead>
<tr>
<td colspan="3">Edit a Slave Zone</td>
</tr>
</thead>
<tbody>
<tr class="lmc-tr3">
<td>Domain</td>
<td><input id="domain" type="text" size="30" /></td>
<td></td>
</tr>
<tr class="lmc-tr3">
<td>Tags</td>
<td><input id="tags" type="text" size="25" /></td>
<td class="info">Group domains together using tags! (comma-separated)</td>
</tr>
<tr class="lmc-tr3">
<td>Masters</td>
<td><textarea id="masters" rows="4" cols="40"></textarea></td>
<td class="info">
The IP addresses of the master DNS servers for this zone.<br />
Semicolon or new line delimited. (maximum: 6)
</td>
</tr>
<tr class="lmc-tr3">
<td>Domain Transfers</td>
<td><textarea id="transfers" rows="4" cols="40"></textarea></td>
<td class="info">
The IP addresses allowed to AXFR this entire zone.<br />
Semicolon or new line delimited. (maximum: 6)
</td>
</tr>
<tr class="lmc-tr3">
<td></td>
<td colspan="2"><button disabled id="save-button" type="button">Save Changes</button></td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
Loading…
Cancel
Save