Initial commit. Implemented OAuth, Linodes, volumes, and images
This commit is contained in:
84
linodes/ip_swap/index.shtml
Normal file
84
linodes/ip_swap/index.shtml
Normal file
@ -0,0 +1,84 @@
|
||||
<!--
|
||||
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 - IP Swap</title>
|
||||
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<link rel="stylesheet" type="text/css" href="ip_swap.css" />
|
||||
<script src="ip_swap.js" type="module"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!--#include virtual="/include/header.html"-->
|
||||
<!--#include virtual="/include/linode_subnav.html"-->
|
||||
<div id="main-content" class="wrapper">
|
||||
<div id="top-links"><a href="/linodes">Linodes</a> » <span id="linode-tag"><a id="linode-tag-link" href=""></a> » </span><a id="linode-label" href="/linodes/dashboard?lid=0"></a> » <a href="/linodes/remote_access?lid=0">Remote Access</a> » <span class="top-links-title">IP Swap</span></div>
|
||||
<div id="ip-swap">
|
||||
<table id="select-table" class="lmc-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<td colspan="2">Swap IPs</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="lmc-tr3">
|
||||
<td>With Linode</td>
|
||||
<td><select id="linode-select"></select></td>
|
||||
</tr>
|
||||
<tr class="lmc-tr3">
|
||||
<td></td>
|
||||
<td><button disabled id="select-button" type="button">Select</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table id="swap-table" class="lmc-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<td id="src-linode" colspan="2"></td>
|
||||
<td></td>
|
||||
<td id="dest-linode" colspan="2"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>IP Address</td>
|
||||
<td>Move It</td>
|
||||
<td></td>
|
||||
<td>Move It</td>
|
||||
<td>IP Address</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="public-ips"></tbody>
|
||||
<tbody class="lmc-tbody-head">
|
||||
<tr class="noshow">
|
||||
<td colspan="5"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Private IP Address</td>
|
||||
<td>Move It</td>
|
||||
<td></td>
|
||||
<td>Move It</td>
|
||||
<td>Private IP Address</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tbody id="private-ips"></tbody>
|
||||
</table>
|
||||
<button disabled id="do-it" type="button">Do it.</button>
|
||||
<p>Note: This IP Address transfer will take effect immediately however there may be a short delay before both addresses become available.</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
91
linodes/ip_swap/ip_swap.css
Normal file
91
linodes/ip_swap/ip_swap.css
Normal 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/>.
|
||||
*/
|
||||
|
||||
@import url('/global.css');
|
||||
|
||||
#ip-swap {
|
||||
padding: 0px 15px 15px;
|
||||
}
|
||||
|
||||
p {
|
||||
margin-top: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#select-table tbody tr td:first-of-type {
|
||||
font-weight: bold;
|
||||
text-align: right;
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
#swap-table tr td:nth-of-type(5) {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
#swap-table tbody:not(.lmc-tbody-head) td:nth-of-type(2) {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#swap-table tbody:not(.lmc-tbody-head) td:nth-of-type(3) {
|
||||
font-size: 30px;
|
||||
padding: 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#swap-table tbody:not(.lmc-tbody-head) td:nth-of-type(4) {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#swap-table tbody.lmc-tbody-head tr:nth-of-type(1) td:nth-of-type(2) {
|
||||
background-color: #FFF;
|
||||
}
|
||||
|
||||
#swap-table tbody.lmc-tbody-head tr:nth-of-type(2) td:nth-of-type(2) {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#swap-table tbody.lmc-tbody-head tr:nth-of-type(2) td:nth-of-type(3) {
|
||||
background-color: #FFF;
|
||||
}
|
||||
|
||||
#swap-table tbody.lmc-tbody-head tr:nth-of-type(2) td:nth-of-type(4) {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#swap-table thead tr:nth-of-type(1) td:nth-of-type(2) {
|
||||
background-color: #FFF;
|
||||
}
|
||||
|
||||
#swap-table thead tr:nth-of-type(2) td:nth-of-type(2) {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#swap-table thead tr:nth-of-type(2) td:nth-of-type(3) {
|
||||
background-color: #FFF;
|
||||
}
|
||||
|
||||
#swap-table thead tr:nth-of-type(2) td:nth-of-type(4) {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
table {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
tbody:not(.lmc-tbody-head) tr:last-of-type {
|
||||
border: none;
|
||||
}
|
374
linodes/ip_swap/ip_swap.js
Normal file
374
linodes/ip_swap/ip_swap.js
Normal file
@ -0,0 +1,374 @@
|
||||
/*
|
||||
* 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.destClass = "dest-ip";
|
||||
elements.destLinode = "dest-linode";
|
||||
elements.doIt = "do-it";
|
||||
elements.info = "info";
|
||||
elements.linodeLabel = "linode-label";
|
||||
elements.linodeSelect = "linode-select";
|
||||
elements.linodeTag = "linode-tag";
|
||||
elements.linodeTagLink = "linode-tag-link";
|
||||
elements.lmcRow = "lmc-tr3";
|
||||
elements.privateIPs = "private-ips";
|
||||
elements.publicIPs = "public-ips";
|
||||
elements.selectButton = "select-button";
|
||||
elements.srcClass = "src-ip";
|
||||
elements.srcLinode = "src-linode";
|
||||
elements.subnav = "subnav-link";
|
||||
elements.subnavActive = "subnav-link-active";
|
||||
|
||||
// Data recieved from API calls
|
||||
var data = {};
|
||||
data.destNet = {};
|
||||
data.linode = {};
|
||||
data.linodes = [];
|
||||
data.srcNet = {};
|
||||
|
||||
// Static references to UI elements
|
||||
var ui = {};
|
||||
ui.destLinode = {};
|
||||
ui.doIt = {};
|
||||
ui.linodeLabel = {};
|
||||
ui.linodeSelect = {};
|
||||
ui.linodeTag = {};
|
||||
ui.linodeTagLink = {};
|
||||
ui.privateIPs = {};
|
||||
ui.publicIPs = {};
|
||||
ui.selectButton = {};
|
||||
ui.srcLinode = {};
|
||||
|
||||
// Temporary state
|
||||
var state = {};
|
||||
state.destIndex = -1;
|
||||
state.haveDest = false;
|
||||
state.haveSrc = false;
|
||||
|
||||
// Callback for destination linode network details API call
|
||||
var displayDestNet = function(response)
|
||||
{
|
||||
data.destNet = response;
|
||||
state.haveDest = true;
|
||||
if (state.haveSrc)
|
||||
displayIPs();
|
||||
};
|
||||
|
||||
// Callback for linode details API call
|
||||
var displayDetails = function(response)
|
||||
{
|
||||
data.linode = response;
|
||||
|
||||
// Set page title and header stuff
|
||||
document.title += " // " + data.linode.label;
|
||||
ui.linodeLabel.innerHTML = data.linode.label;
|
||||
ui.srcLinode.innerHTML = data.linode.label;
|
||||
if (data.linode.tags.length == 1) {
|
||||
ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0];
|
||||
ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")";
|
||||
ui.linodeTag.style.display = "inline";
|
||||
}
|
||||
|
||||
// Get other Linodes in the same DC
|
||||
var filter = {
|
||||
"region": data.linode.region
|
||||
};
|
||||
apiGet("/linode/instances", displayLinodes, filter);
|
||||
apiGet("/linode/instances/" + data.params.lid + "/ips", displaySrcNet, null);
|
||||
};
|
||||
|
||||
// Populate swap table with source and dest IPs
|
||||
var displayIPs = function()
|
||||
{
|
||||
// Add public IPs
|
||||
var numIPs = Math.max(data.srcNet.ipv4["public"].length, data.destNet.ipv4["public"].length);
|
||||
for (var i = 0; i < numIPs; i++) {
|
||||
var row = document.createElement("tr");
|
||||
row.className = elements.lmcRow;
|
||||
|
||||
var srcAddr = document.createElement("td");
|
||||
var srcMove = document.createElement("td");
|
||||
if (data.srcNet.ipv4["public"][i]) {
|
||||
var ip = document.createElement("span");
|
||||
ip.innerHTML = data.srcNet.ipv4["public"][i].address;
|
||||
var br = document.createElement("br");
|
||||
var rdns = document.createElement("span");
|
||||
rdns.className = elements.info;
|
||||
rdns.innerHTML = data.srcNet.ipv4["public"][i].rdns;
|
||||
srcAddr.appendChild(ip);
|
||||
srcAddr.appendChild(br);
|
||||
srcAddr.appendChild(rdns);
|
||||
|
||||
var move = document.createElement("input");
|
||||
move.id = data.srcNet.ipv4["public"][i].address;
|
||||
move.className = elements.srcClass;
|
||||
move.type = "checkbox";
|
||||
srcMove.appendChild(move);
|
||||
}
|
||||
|
||||
row.appendChild(srcAddr);
|
||||
row.appendChild(srcMove);
|
||||
var arrow = document.createElement("td");
|
||||
arrow.innerHTML = "↔";
|
||||
row.appendChild(arrow);
|
||||
|
||||
var destAddr = document.createElement("td");
|
||||
var destMove = document.createElement("td");
|
||||
if (data.destNet.ipv4["public"][i]) {
|
||||
var ip = document.createElement("span");
|
||||
ip.innerHTML = data.destNet.ipv4["public"][i].address;
|
||||
var br = document.createElement("br");
|
||||
var rdns = document.createElement("span");
|
||||
rdns.className = elements.info;
|
||||
rdns.innerHTML = data.destNet.ipv4["public"][i].rdns;
|
||||
destAddr.appendChild(ip);
|
||||
destAddr.appendChild(br);
|
||||
destAddr.appendChild(rdns);
|
||||
|
||||
var move = document.createElement("input");
|
||||
move.id = data.destNet.ipv4["public"][i].address;
|
||||
move.className = elements.destClass;
|
||||
move.type = "checkbox";
|
||||
destMove.appendChild(move);
|
||||
}
|
||||
|
||||
row.appendChild(destMove);
|
||||
row.appendChild(destAddr);
|
||||
ui.publicIPs.appendChild(row);
|
||||
}
|
||||
|
||||
// Add private IPs
|
||||
var numIPs = Math.max(data.srcNet.ipv4["private"].length, data.destNet.ipv4["private"].length);
|
||||
for (var i = 0; i < numIPs; i++) {
|
||||
var row = document.createElement("tr");
|
||||
row.className = elements.lmcRow;
|
||||
|
||||
var srcAddr = document.createElement("td");
|
||||
var srcMove = document.createElement("td");
|
||||
if (data.srcNet.ipv4["private"][i]) {
|
||||
var ip = document.createElement("span");
|
||||
ip.innerHTML = data.srcNet.ipv4["private"][i].address;
|
||||
var br = document.createElement("br");
|
||||
var rdns = document.createElement("span");
|
||||
rdns.className = elements.info;
|
||||
rdns.innerHTML = data.srcNet.ipv4["private"][i].rdns;
|
||||
srcAddr.appendChild(ip);
|
||||
srcAddr.appendChild(br);
|
||||
srcAddr.appendChild(rdns);
|
||||
|
||||
var move = document.createElement("input");
|
||||
move.id = data.srcNet.ipv4["private"][i].address;
|
||||
move.className = elements.srcClass;
|
||||
move.type = "checkbox";
|
||||
srcMove.appendChild(move);
|
||||
}
|
||||
|
||||
row.appendChild(srcAddr);
|
||||
row.appendChild(srcMove);
|
||||
var arrow = document.createElement("td");
|
||||
arrow.innerHTML = "↔";
|
||||
row.appendChild(arrow);
|
||||
|
||||
var destAddr = document.createElement("td");
|
||||
var destMove = document.createElement("td");
|
||||
if (data.destNet.ipv4["private"][i]) {
|
||||
var ip = document.createElement("span");
|
||||
ip.innerHTML = data.destNet.ipv4["private"][i].address;
|
||||
var br = document.createElement("br");
|
||||
var rdns = document.createElement("span");
|
||||
rdns.className = elements.info;
|
||||
rdns.innerHTML = data.destNet.ipv4["private"][i].rdns;
|
||||
destAddr.appendChild(ip);
|
||||
destAddr.appendChild(br);
|
||||
destAddr.appendChild(rdns);
|
||||
|
||||
var move = document.createElement("input");
|
||||
move.id = data.destNet.ipv4["private"][i].address;
|
||||
move.className = elements.destClass;
|
||||
move.type = "checkbox";
|
||||
destMove.appendChild(move);
|
||||
}
|
||||
|
||||
row.appendChild(destMove);
|
||||
row.appendChild(destAddr);
|
||||
ui.privateIPs.appendChild(row);
|
||||
}
|
||||
|
||||
ui.doIt.disabled = false;
|
||||
ui.selectButton.disabled = false;
|
||||
};
|
||||
|
||||
// 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) {
|
||||
var filter = {
|
||||
"region": data.linode.region
|
||||
};
|
||||
apiGet("/linode/instances?page=" + (response.page + 1), displayLinodes, filter);
|
||||
return;
|
||||
}
|
||||
|
||||
// Add linodes to selector
|
||||
for (var i = 0; i < data.linodes.length; i++) {
|
||||
if (data.linodes[i].id == data.linode.id)
|
||||
continue;
|
||||
|
||||
var option = document.createElement("option");
|
||||
option.value = data.linodes[i].id;
|
||||
option.innerHTML = data.linodes[i].label;
|
||||
ui.linodeSelect.appendChild(option);
|
||||
}
|
||||
ui.selectButton.disabled = false;
|
||||
};
|
||||
|
||||
// Callback for source linode network details API call
|
||||
var displaySrcNet = function(response)
|
||||
{
|
||||
data.srcNet = response;
|
||||
state.haveSrc = true;
|
||||
if (state.haveDest)
|
||||
displayIPs();
|
||||
};
|
||||
|
||||
// Handler for select button
|
||||
var handleSelect = function(event)
|
||||
{
|
||||
if (event.currentTarget.disabled)
|
||||
return;
|
||||
|
||||
state.haveDest = false;
|
||||
|
||||
var lid = parseInt(ui.linodeSelect.value);
|
||||
for (var i = 0; i < data.linodes.length; i++) {
|
||||
if (data.linodes[i].id == lid) {
|
||||
state.destIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (state.destIndex == -1)
|
||||
return;
|
||||
|
||||
ui.doIt.disabled = true;
|
||||
ui.selectButton.disabled = true;
|
||||
ui.publicIPs.innerHTML = "";
|
||||
ui.privateIPs.innerHTML = "";
|
||||
ui.destLinode.innerHTML = data.linodes[state.destIndex].label;
|
||||
apiGet("/linode/instances/" + data.linodes[state.destIndex].id + "/ips", displayDestNet, null);
|
||||
};
|
||||
|
||||
// Handler for "do it" button
|
||||
var handleSwap = function(event)
|
||||
{
|
||||
if (event.currentTarget.disabled)
|
||||
return;
|
||||
|
||||
var assignments = [];
|
||||
|
||||
// Assign all checked source IPs to the destination Linode
|
||||
var srcBoxes = document.getElementsByClassName(elements.srcClass);
|
||||
for (var i = 0; i < srcBoxes.length; i++) {
|
||||
if (!srcBoxes[i].checked)
|
||||
continue;
|
||||
|
||||
assignments.push({
|
||||
"address": srcBoxes[i].id,
|
||||
"linode_id": data.linodes[state.destIndex].id
|
||||
});
|
||||
}
|
||||
|
||||
// Assign all checked destination IPs to the source Linode
|
||||
var destBoxes = document.getElementsByClassName(elements.destClass);
|
||||
for (var i = 0; i < destBoxes.length; i++) {
|
||||
if (!destBoxes[i].checked)
|
||||
continue;
|
||||
|
||||
assignments.push({
|
||||
"address": destBoxes[i].id,
|
||||
"linode_id": data.linode.id
|
||||
});
|
||||
}
|
||||
|
||||
if (!assignments.length)
|
||||
return;
|
||||
|
||||
var req = {
|
||||
"assignments": assignments,
|
||||
"region": data.linode.region
|
||||
};
|
||||
apiPost("/networking/ipv4/assign", req, function(response) {
|
||||
location.href = "/linodes/remote_access?lid=" + data.params.lid;
|
||||
});
|
||||
};
|
||||
|
||||
// Initial setup
|
||||
var setup = function()
|
||||
{
|
||||
// Parse URL parameters
|
||||
data.params = parseParams();
|
||||
|
||||
// We need a Linode ID, so die if we don't have it
|
||||
if (!data.params.lid) {
|
||||
alert("No Linode 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("lid=0", "lid=" + data.params.lid);
|
||||
|
||||
// Highlight the remote access subnav link
|
||||
var subnavLinks = document.getElementsByClassName(elements.subnav);
|
||||
for (var i = 0; i < subnavLinks.length; i++) {
|
||||
if (subnavLinks[i].pathname == "/linodes/remote_access")
|
||||
subnavLinks[i].className += " " + elements.subnavActive;
|
||||
}
|
||||
|
||||
// Get element references
|
||||
ui.destLinode = document.getElementById(elements.destLinode);
|
||||
ui.doIt = document.getElementById(elements.doIt);
|
||||
ui.linodeLabel = document.getElementById(elements.linodeLabel);
|
||||
ui.linodeSelect = document.getElementById(elements.linodeSelect);
|
||||
ui.linodeTag = document.getElementById(elements.linodeTag);
|
||||
ui.linodeTagLink = document.getElementById(elements.linodeTagLink);
|
||||
ui.privateIPs = document.getElementById(elements.privateIPs);
|
||||
ui.publicIPs = document.getElementById(elements.publicIPs);
|
||||
ui.selectButton = document.getElementById(elements.selectButton);
|
||||
ui.srcLinode = document.getElementById(elements.srcLinode);
|
||||
|
||||
// Add event handlers
|
||||
ui.selectButton.addEventListener("click", handleSelect);
|
||||
ui.doIt.addEventListener("click", handleSwap);
|
||||
|
||||
// Get data from API
|
||||
apiGet("/linode/instances/" + data.params.lid, displayDetails, null);
|
||||
};
|
||||
|
||||
// Attach onload handler
|
||||
window.addEventListener("load", setup);
|
||||
})();
|
Reference in New Issue
Block a user