Added all DNS functionality

This commit is contained in:
2020-01-18 17:50:00 -05:00
parent 4e033be21b
commit 1ffa87a980
29 changed files with 2980 additions and 1 deletions

View File

@ -0,0 +1,43 @@
/*
* 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-add {
padding: 0px 15px 15px;
}
.master-section {
display: none;
}
.slave-section {
display: none;
}
tbody:not(.lmc-tbody-head) tr:last-of-type {
border: none;
}
tbody:not(.lmc-tbody-head) tr td:first-of-type {
font-weight: bold;
text-align: right;
}
td:nth-of-type(3):not(.info) {
text-align: right;
}

View File

@ -0,0 +1,243 @@
/*
* 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, apiPost, parseParams, setupHeader } from "/global.js";
(function()
{
// Element names specific to this page
elements.addMaster = "add-master";
elements.addSlave = "add-slave";
elements.email = "email";
elements.linode = "linode";
elements.masterDomain = "master-domain";
elements.masters = "masters";
elements.masterSection = "master-section";
elements.no = "no";
elements.slaveDomain = "slave-domain";
elements.slaveSection = "slave-section";
elements.yes = "yes";
// Data recieved from API calls
var data = {};
data.linodes = [];
// Static references to UI elements
var ui = {};
ui.addMaster = {};
ui.addSlave = {};
ui.email = {};
ui.linode = {};
ui.masterDomain = {};
ui.masters = {};
ui.masterSection = [];
ui.no = {};
ui.slaveDomain = {};
ui.slaveSection = [];
ui.yes = {};
// Temporary state
var state = {};
state.did = 0;
state.returned = 0;
state.total = 0;
// Add initial records to new domain
var addRecords = function(response)
{
// Find the selected linode
var linode = null;
for (var i = 0; i < data.linodes.length; i++) {
if (data.linodes[i].id == parseInt(ui.linode.value)) {
linode = data.linodes[i];
break;
}
}
if (!linode) {
location.href = "/dns/domain?did=" + response.id;
return;
}
// Create record requests
state.did = response.id;
var callback = function(response) {
state.returned++;
if (state.returned >= state.total)
location.href = "/dns/domain?did=" + state.did;
}
var reqs = [
{
"type": "A",
"name": "",
"target": linode.ipv4[0]
},
{
"type": "A",
"name": "mail",
"target": linode.ipv4[0]
},
{
"type": "A",
"name": "www",
"target": linode.ipv4[0]
},
{
"type": "AAAA",
"name": "",
"target": linode.ipv6.split("/")[0]
},
{
"type": "AAAA",
"name": "mail",
"target": linode.ipv6.split("/")[0]
},
{
"type": "AAAA",
"name": "www",
"target": linode.ipv6.split("/")[0]
},
{
"type": "MX",
"target": "mail.meredithlaboon.com",
"priority": 10,
"name": ""
}
];
state.total = reqs.length;
for (var i = 0; i < reqs.length; i++)
apiPost("/domains/" + response.id + "/records", reqs[i], callback);
};
// Callback for Linodes API call
var displayLinodes = function(response)
{
// Add linodes to array
data.linodes = data.linodes.concat(response.data);
// Request the next page if there are more pages
if (response.page != response.pages) {
apiGet("/linode/instances?page=" + (response.page + 1), displayLinodes, null);
return;
}
// Add linodes to selector
for (var i = 0; i < data.linodes.length; i++) {
var option = document.createElement("option");
option.value = data.linodes[i].id;
option.innerHTML = data.linodes[i].label;
ui.linode.appendChild(option);
}
ui.addMaster.disabled = false;
};
// Click handler for add master button
var handleAddMaster = function(event)
{
if (event.currentTarget.disabled)
return;
// This request takes a few seconds
ui.addMaster.disabled = true;
var req = {
"domain": ui.masterDomain.value,
"type": "master",
"soa_email": ui.email.value
};
var callback = function(response)
{
location.href = "/dns/domain?did=" + response.id;
};
if (ui.yes.checked)
callback = addRecords;
apiPost("/domains", req, callback);
};
// Click handler for add slave button
var handleAddSlave = function(event)
{
if (event.currentTarget.disabled)
return;
// This request takes a few seconds
ui.addSlave.disabled = true;
var ips = [];
var masterLines = ui.masters.value.split("\n");
for (var i = 0; i < masterLines.length; i++)
ips = ips.concat(masterLines[i].split(";"));
var req = {
"domain": ui.slaveDomain.value,
"type": "slave",
"master_ips": ips
};
apiPost("/domains", req, function(response)
{
location.href = "/dns/domain?did=" + response.id;
});
};
// Initial setup
var setup = function()
{
// Parse URL parameters
data.params = parseParams();
setupHeader();
// Get element references
ui.addMaster = document.getElementById(elements.addMaster);
ui.addSlave = document.getElementById(elements.addSlave);
ui.email = document.getElementById(elements.email);
ui.linode = document.getElementById(elements.linode);
ui.masterDomain = document.getElementById(elements.masterDomain);
ui.masters = document.getElementById(elements.masters);
ui.masterSection = document.getElementsByClassName(elements.masterSection);
ui.no = document.getElementById(elements.no);
ui.slaveDomain = document.getElementById(elements.slaveDomain);
ui.slaveSection = document.getElementsByClassName(elements.slaveSection);
ui.yes = document.getElementById(elements.yes);
// Display desired section
var section = null;
if (data.params.type && data.params.type == "slave")
section = ui.slaveSection;
else
section = ui.masterSection;
for (var i = 0; i < section.length; i++)
section[i].style.display = "table-row-group";
// Attach event handlers
ui.addMaster.addEventListener("click", handleAddMaster);
ui.addSlave.addEventListener("click", handleAddSlave);
// Get data from API
if (!data.params.type || data.params.type != "slave")
apiGet("/linode/instances", displayLinodes, null);
};
// Attach onload handler
window.addEventListener("load", setup);
})();

View File

@ -0,0 +1,91 @@
<!--
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 - Add a Zone</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="domain_add.css" />
<script src="domain_add.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 class="top-links-title">Add a Zone</span></div>
<div id="domain-add">
<table class="lmc-table">
<thead class="master-section">
<tr>
<td colspan="3">Add a Master Zone</td>
</tr>
</thead>
<tbody class="master-section">
<tr class="lmc-tr3">
<td>Domain</td>
<td><input id="master-domain" type="text" size="30" /></td>
<td></td>
</tr>
<tr class="lmc-tr3">
<td>SOA Email</td>
<td><input id="email" type="text" size="30" placeholder="you@example.com" /></td>
<td></td>
</tr>
<tr class="lmc-tr3">
<td>Insert Default Records</td>
<td>
<input checked id="yes" type="radio" name="insert-records" /><label for="yes">Yes, insert a few records to get me started, using this Linode: </label><select id="linode"></select><br />
<input id="no" type="radio" name="insert-records" /><label for="no">No, I want the zone empty</label>
</td>
<td></td>
</tr>
<tr class="lmc-tr3">
<td></td>
<td><button disabled id="add-master" type="button">Add a Master Zone »</button></td>
<td><a href="/dns/domain_add?type=slave">I wanted a slave zone</a></td>
</tr>
</tbody>
<tbody class="slave-section lmc-tbody-head">
<tr>
<td colspan="3">Add a Slave Zone</td>
</tr>
</tbody>
<tbody class="slave-section">
<tr class="lmc-tr3">
<td>Domain</td>
<td><input id="slave-domain" type="text" size="30" /></td>
<td></td>
</tr>
<tr class="lmc-tr3">
<td>Masters</td>
<td><textarea id="masters" cols="35" rows="4"></textarea></td>
<td class="info">
The IP addresses of the master DNS servers for this zone.<br />
Semicolon or new line delimited.
</td>
</tr>
<tr class="lmc-tr3">
<td></td>
<td><button id="add-slave" type="button">Add a Slave Zone »</button></td>
<td><a href="/dns/domain_add?type=master">I wanted a master zone</a></td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>