Merge branch 'dns-slave-fix' of lb.laboon/lmc into master

This commit is contained in:
L. Bradley LaBoon 2020-01-30 18:51:23 -05:00 committed by Gitea
commit c2f7f1b6bd
5 changed files with 268 additions and 2 deletions

View File

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

View File

@ -320,6 +320,12 @@ import { settings, elements, apiGet, parseParams, setupHeader } from "/global.js
{ {
data.domain = response; 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 // Set page title and header stuff
document.title += " // " + data.domain.domain; document.title += " // " + data.domain.domain;
ui.domainLabel.innerHTML = data.domain.domain; ui.domainLabel.innerHTML = data.domain.domain;

View File

@ -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;
}

View File

@ -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);
})();

View File

@ -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>