Initial commit. Implemented OAuth, Linodes, volumes, and images

This commit is contained in:
2020-01-10 00:24:59 -05:00
commit 9915ef3413
121 changed files with 14776 additions and 0 deletions

84
linodes/clone/clone.css Normal file
View 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/>.
*/
@import url('/global.css');
#clone {
padding: 0px 15px 15px;
}
#clone-table tbody:last-of-type tr:last-of-type {
font-weight: bold;
}
#clone-table tbody:last-of-type tr:last-of-type td:nth-of-type(2) {
text-align: right;
}
#clone-table td:first-of-type {
width: 100%;
}
#config-table {
margin-bottom: 20px;
text-align: center;
}
#config-table td:nth-of-type(2) {
text-align: left;
width: 100%;
}
#config-table td:nth-of-type(3) {
text-align: left;
}
#dest-table tbody:not(.lmc-tbody-head) td:first-of-type {
font-weight: bold;
padding-left: 100px;
text-align: right;
}
#dest-table tbody:not(.lmc-tbody-head) tr:last-of-type {
border: none;
}
#dest-table td:last-of-type {
width: 100%;
}
#disk-table {
margin-bottom: 20px;
text-align: center;
}
#disk-table td:nth-of-type(2) {
text-align: left;
width: 100%;
}
.lmc-table td {
white-space: nowrap;
}
.lmc-table thead tr:first-of-type {
text-align: left;
}
optgroup {
display: none;
}

558
linodes/clone/clone.js Normal file
View File

@ -0,0 +1,558 @@
/*
* 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, migrateETA, parseParams, regionNames, setupHeader, translateKernel } from "/global.js";
(function()
{
// Element names specific to this page
elements.cloneButton = "clone-button";
elements.configCloneTable = "config-clone-table";
elements.configDiskRow = "config-disk-row";
elements.configsNone = "configs-none";
elements.configTable = "config-table-body";
elements.destBackups = "dest-backups";
elements.destBackupsPrice = "dest-backups-price";
elements.destLabel = "dest-label";
elements.destLinode = "dest-linode";
elements.destLocation = "dest-location";
elements.destPlan = "dest-plan";
elements.destPlanPrice = "dest-plan-price";
elements.diskCloneTable = "disk-clone-table";
elements.disksNone = "disks-none";
elements.diskTable = "disk-table-body";
elements.etaLocal = "eta-local";
elements.etaRemote = "eta-remote";
elements.etaRow = "eta-row";
elements.linodeLabel = "linode-label";
elements.linodeTag = "linode-tag";
elements.linodeTagLink = "linode-tag-link";
elements.lmcRow = "lmc-tr1";
elements.lmcRowAlt = "lmc-tr2";
elements.lmcRowThree = "lmc-tr3";
elements.loadingConfigs = "loading-configs";
elements.loadingDisks = "loading-disks";
elements.newLinode = "new-linode";
elements.sourceLocation = "source-location";
// Data recieved from API calls
var data = {};
data.configs = [];
data.disks = [];
data.linode = {};
data.types = [];
// Static references to UI elements
var ui = {};
ui.cloneButton = {};
ui.configCloneTable = {};
ui.configsNone = {};
ui.configTable = {};
ui.destBackups = {};
ui.destBackupsPrice = {};
ui.destLabel = {};
ui.destLinode = {};
ui.destLocation = {};
ui.destPlan = {};
ui.destPlanPrice = {};
ui.diskCloneTable = {};
ui.disksNone = {};
ui.diskTable = {};
ui.etaLocal = {};
ui.etaRemote = {};
ui.etaRow = {};
ui.linodeLabel = {};
ui.linodeTag = {};
ui.linodeTagLink = {};
ui.loadingConfigs = {};
ui.loadingDisks = {};
ui.newLinode = [];
ui.sourceLocation = {};
// Temporary state
var state = {};
state.configs = [];
state.disks = [];
// Generate a config profile table row for clone section
var createCloneConfigRow = function(config)
{
var row = document.createElement("tr");
row.className = elements.lmcRowThree + " " + elements.configDiskRow;
var label = document.createElement("td");
label.colSpan = ui.configsNone.children[0].colSpan;
label.innerHTML = config.label;
row.appendChild(label);
return row;
};
// Create a disk table row for clone section
var createCloneDiskRow = function(disk)
{
var row = document.createElement("tr");
row.className = elements.lmcRowThree + " " + elements.configDiskRow;
// Label
var label = document.createElement("td");
label.innerHTML = disk.label;
row.appendChild(label);
// Size
var size = document.createElement("td");
size.innerHTML = disk.size + " MB";
row.appendChild(size);
// Local copy ETA
var local = document.createElement("td");
local.innerHTML = migrateETA(disk.size, true);
row.appendChild(local);
// Remote copy ETA
var remote = document.createElement("td");
remote.innerHTML = migrateETA(disk.size, false);
row.appendChild(remote);
return row;
};
// Generate a config profile table row
var createConfigRow = function(config, alt)
{
var row = document.createElement("tr");
if (alt)
row.className = elements.lmcRowAlt;
else
row.className = elements.lmcRow;
// Select checkbox
var selectCell = document.createElement("td");
var select = document.createElement("input");
select.id = "config-" + config.id;
select.type = "checkbox";
select.addEventListener("input", handleSelect);
selectCell.appendChild(select);
row.appendChild(selectCell);
// Config profile name
var nameCell = document.createElement("td");
nameCell.innerHTML = config.label;
row.appendChild(nameCell);
// Kernel
var kernel = document.createElement("td");
translateKernel(config.kernel, kernel);
row.appendChild(kernel);
// Number of disks
var disks = document.createElement("td");
var numDisks = 0;
for (var disk in config.devices) {
if (config.devices[disk] && config.devices[disk].disk_id)
numDisks++;
}
disks.innerHTML = numDisks;
row.appendChild(disks);
return row;
};
// Generate a disk table row
var createDiskRow = function(disk, alt)
{
var row = document.createElement("tr");
if (alt)
row.className = elements.lmcRowAlt;
else
row.className = elements.lmcRow;
// Select checkbox
var selectCell = document.createElement("td");
var select = document.createElement("input");
select.id = "disk-" + disk.id;
select.type = "checkbox";
select.addEventListener("input", handleSelect);
selectCell.appendChild(select);
row.appendChild(selectCell);
// Disk name
var nameCell = document.createElement("td");
nameCell.innerHTML = disk.label;
row.appendChild(nameCell);
// Disk type
var typeCell = document.createElement("td");
typeCell.innerHTML = disk.filesystem;
row.appendChild(typeCell);
// Disk size
var sizeCell = document.createElement("td");
sizeCell.innerHTML = disk.size + " MB";
row.appendChild(sizeCell);
return row;
};
// Callback for config profiles API call
var displayConfigs = function(response)
{
// Add configs to array
data.configs = data.configs.concat(response.data);
// Request the next page if there are more
if (response.page != response.pages) {
apiGet("/linode/instances/" + data.params.lid + "/configs?page=" + (response.page + 1), displayConfigs, null);
return;
}
// Remove loading row
ui.loadingConfigs.remove();
// Insert config profile rows into table
for (var i = 0; i < data.configs.length; i++)
ui.configTable.appendChild(createConfigRow(data.configs[i], i % 2));
};
// 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;
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";
}
// Display the source location
if (regionNames[data.linode.region])
ui.sourceLocation.innerHTML = regionNames[data.linode.region];
else
ui.sourceLocation.innerHTML = data.linode.region;
};
// Callback for linode disks API call
var displayDisks = function(response)
{
// Add disks to array
data.disks = data.disks.concat(response.data);
// Request the next page if there are more pages
if (response.page != response.pages) {
apiGet("/linode/instances/" + data.params.lid + "/disks?page=" + (response.page + 1), displayDisks, null);
return;
}
// Remove loading row
ui.loadingDisks.remove();
// Insert disk rows into table
for (var i = 0; i < data.disks.length; i++)
ui.diskTable.appendChild(createDiskRow(data.disks[i], i % 2));
};
// Callback for linodes API call
var displayLinodes = function(response)
{
// Add linodes to selector
for (var i = 0; i < response.data.length; i++) {
if (response.data[i].id == data.params.lid)
continue;
var linode = document.createElement("option");
linode.value = response.data[i].id;
linode.innerHTML = response.data[i].label;
var optgroup = document.getElementById(response.data[i].region);
optgroup.appendChild(linode);
optgroup.style.display = "initial";
}
// Request the next page if there are more pages
if (response.page != response.pages)
apiGet("/linode/instances?page=" + (response.page + 1), displayLinodes, null);
};
// Callback for regions API call
var displayRegions = function(response)
{
for (var i = 0; i < response.data.length; i++) {
// Add regions to selector
var dc = document.createElement("option");
dc.value = response.data[i].id;
if (regionNames[response.data[i].id])
dc.innerHTML = regionNames[response.data[i].id];
else
dc.innerHTML = response.data[i].id;
ui.destLocation.appendChild(dc);
// Add optgroups to linode selector
var optgroup = document.createElement("optgroup");
optgroup.id = response.data[i].id;
if (regionNames[response.data[i].id])
optgroup.label = regionNames[response.data[i].id];
else
optgroup.label = response.data[i].label;
ui.destLinode.appendChild(optgroup);
}
// Request the next page if there are more pages
if (response.page != response.pages) {
apiGet("/regions?page=" + (response.page + 1), displayRegions, null);
return;
}
apiGet("/linode/instances", displayLinodes, null);
};
// Callback for linode types API call
var displayTypes = function(response)
{
// Add types to array
data.types = data.types.concat(response.data);
// Request the next page if there are more pages
if (response.page != response.pages) {
apiGet("/linode/types?page=" + (response.page + 1), displayTypes, null);
return;
}
// Insert types into selector
for (var i = 0; i < data.types.length; i++) {
var type = document.createElement("option");
type.value = data.types[i].id;
type.innerHTML = data.types[i].label;
ui.destPlan.appendChild(type);
}
updatePrices(null);
};
// Clone button handler
var handleClone = function(event)
{
if (event.currentTarget.disabled)
return;
var req = {
"configs": state.configs,
"disks": state.disks
};
var destLinode = parseInt(ui.destLinode.value);
if (destLinode == 0) {
req.region = ui.destLocation.value;
req.type = ui.destPlan.value;
if (ui.destLabel.value.length)
req.label = ui.destLabel.value;
req.backups_enabled = ui.destBackups.checked;
} else {
req.linode_id = destLinode;
}
apiPost("/linode/instances/" + data.params.lid + "/clone", req, function(response)
{
location.href = "/linodes/dashboard?lid=" + data.params.lid;
});
};
// Handler for checkbox selections
var handleSelect = function(event)
{
// Determine whether we're working with configs or disks
var arr = state.configs;
if (event.currentTarget.id.split("-")[0] == "disk")
arr = state.disks;
// Get the ID of the thing
var id = parseInt(event.currentTarget.id.split("-")[1]);
var index = arr.indexOf(id);
// If the box is checked, add the ID, otherwise remove it
if (event.currentTarget.checked && index == -1)
arr.push(id);
else if (index != -1)
arr.splice(index, 1);
updateClone();
};
// 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);
// Get element references
ui.cloneButton = document.getElementById(elements.cloneButton);
ui.configCloneTable = document.getElementById(elements.configCloneTable);
ui.configsNone = document.getElementById(elements.configsNone);
ui.configTable = document.getElementById(elements.configTable);
ui.destBackups = document.getElementById(elements.destBackups);
ui.destBackupsPrice = document.getElementById(elements.destBackupsPrice);
ui.destLabel = document.getElementById(elements.destLabel);
ui.destLinode = document.getElementById(elements.destLinode);
ui.destLocation = document.getElementById(elements.destLocation);
ui.destPlan = document.getElementById(elements.destPlan);
ui.destPlanPrice = document.getElementById(elements.destPlanPrice);
ui.diskCloneTable = document.getElementById(elements.diskCloneTable);
ui.disksNone = document.getElementById(elements.disksNone);
ui.diskTable = document.getElementById(elements.diskTable);
ui.etaLocal = document.getElementById(elements.etaLocal);
ui.etaRemote = document.getElementById(elements.etaRemote);
ui.etaRow = document.getElementById(elements.etaRow);
ui.linodeLabel = document.getElementById(elements.linodeLabel);
ui.linodeTag = document.getElementById(elements.linodeTag);
ui.linodeTagLink = document.getElementById(elements.linodeTagLink);
ui.loadingConfigs = document.getElementById(elements.loadingConfigs);
ui.loadingDisks = document.getElementById(elements.loadingDisks);
ui.newLinode = document.getElementsByClassName(elements.newLinode);
ui.sourceLocation = document.getElementById(elements.sourceLocation);
// Register event handlers
ui.cloneButton.addEventListener("click", handleClone);
ui.destLinode.addEventListener("input", updateDestination);
ui.destPlan.addEventListener("input", updatePrices);
// Get data from API
apiGet("/linode/instances/" + data.params.lid, displayDetails, null);
apiGet("/linode/instances/" + data.params.lid + "/configs", displayConfigs, null);
apiGet("/linode/instances/" + data.params.lid + "/disks", displayDisks, null);
apiGet("/linode/types", displayTypes, null);
apiGet("/regions", displayRegions, null);
};
// Update clone config and disk info
var updateClone = function()
{
// Remove all config and disk rows
var configDiskRows = document.getElementsByClassName(elements.configDiskRow);
for (var i = configDiskRows.length - 1; i >= 0; i--)
configDiskRows[i].remove();
var allDisks = [];
// Loop through configs and create rows
for (var i = 0; i < state.configs.length; i++) {
// Find config
var config = null;
for (var j = 0; j < data.configs.length; j++) {
if (state.configs[i] == data.configs[j].id) {
config = data.configs[j];
break;
}
}
if (!config)
continue;
// Add config to table
ui.configCloneTable.appendChild(createCloneConfigRow(config));
// Loop through config's disks and add them to array
for (var disk in config.devices) {
if (config.devices[disk] && config.devices[disk].disk_id && allDisks.indexOf(config.devices[disk].disk_id) == -1)
allDisks.push(config.devices[disk].disk_id);
}
}
// Add independent disks to array
for (var i = 0; i < state.disks.length; i++) {
if (allDisks.indexOf(state.disks[i]) == -1)
allDisks.push(state.disks[i]);
}
// Loop through disks and create rows
var totalSize = 0;
for (var i = 0; i < allDisks.length; i++) {
// Find disk
var disk = null;
for (var j = 0; j < data.disks.length; j++) {
if (allDisks[i] == data.disks[j].id) {
disk = data.disks[j];
break;
}
}
if (!disk)
continue;
totalSize += disk.size;
// Add disk to table
ui.diskCloneTable.insertBefore(createCloneDiskRow(disk), ui.etaRow);
}
// Show/hide the "none" rows
if (state.configs.length > 0)
ui.configsNone.style.display = "none";
else
ui.configsNone.style.display = "table-row";
if (allDisks.length > 0)
ui.disksNone.style.display = "none";
else
ui.disksNone.style.display = "table-row";
// Compute total ETAs
ui.etaLocal.innerHTML = migrateETA(totalSize, true);
ui.etaRemote.innerHTML = migrateETA(totalSize, false);
};
// Update destination form
var updateDestination = function(event)
{
var display = "none";
if (ui.destLinode.value == "0")
display = "table-row";
for (var i = 0; i < ui.newLinode.length; i++)
ui.newLinode[i].style.display = display;
};
// Update price labels
var updatePrices = function(event)
{
// Find the selected type
var type = null;
for (var i = 0; i < data.types.length; i++) {
if (data.types[i].id == ui.destPlan.value) {
type = data.types[i];
break;
}
}
if (!type)
return;
ui.destPlanPrice.innerHTML = type.price.monthly;
ui.destBackupsPrice.innerHTML = type.addons.backups.price.monthly;
};
// Attach onload handler
window.addEventListener("load", setup);
})();

174
linodes/clone/index.shtml Normal file
View File

@ -0,0 +1,174 @@
<!--
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 - Clone</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="clone.css" />
<script src="clone.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> » <span class="top-links-title">Clone</span></div>
<div id="clone">
<table id="config-table" class="lmc-table">
<thead>
<tr>
<td colspan="4">Configuration Profiles</td>
</tr>
<tr>
<td>Select</td>
<td>Configuration Profiles</td>
<td>Kernel</td>
<td>Disks Attached</td>
</tr>
</thead>
<tbody id="config-table-body">
<tr id="loading-configs" class="lmc-tr3">
<td></td>
<td>Loading configuration profiles...</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<table id="disk-table" class="lmc-table">
<thead>
<tr>
<td colspan="4">Disks</td>
</tr>
<tr>
<td>Select</td>
<td>Disks</td>
<td>Type</td>
<td>Size</td>
</tr>
</thead>
<tbody id="disk-table-body">
<tr id="loading-disks" class="lmc-tr3">
<td></td>
<td>Loading disks...</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<table id="clone-table" class="lmc-table">
<thead>
<tr>
<td colspan="4">Clone</td>
</tr>
<tr>
<td colspan="4">Config Profiles</td>
</tr>
</thead>
<tbody id="config-clone-table">
<tr id="configs-none" class="lmc-tr3">
<td colspan="4">- None -</td>
</tr>
</tbody>
<tbody class="lmc-tbody-head">
<tr class="noshow">
<td colspan="4"></td>
</tr>
<tr>
<td>Disks</td>
<td>Size</td>
<td>Time to copy: Local</td>
<td>To another Datacenter</td>
</tr>
</tbody>
<tbody id="disk-clone-table">
<tr id="disks-none" class="lmc-tr3">
<td colspan="4">- None -</td>
</tr>
<tr id="eta-row" class="lmc-tr3">
<td></td>
<td>TOTAL ESTIMATED TIME:</td>
<td id="eta-local">0 minutes</td>
<td id="eta-remote">0 minutes</td>
</tr>
</tbody>
</table>
<table id="dest-table" class="lmc-table">
<thead>
<tr class="noshow">
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2">Source</td>
</tr>
</thead>
<tbody>
<tr class="lmc-tr3">
<td>Current Datacenter</td>
<td id="source-location"></td>
</tr>
</tbody>
<tbody class="lmc-tbody-head">
<tr class="noshow">
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2">Select Destination</td>
</tr>
</tbody>
<tbody>
<tr class="lmc-tr3">
<td>Destination Linode</td>
<td>
<select id="dest-linode">
<option selected value="0">New Linode</option>
</select>
</td>
</tr>
<tr class="lmc-tr3 new-linode">
<td>Location</td>
<td><select id="dest-location"></select></td>
</tr>
<tr class="lmc-tr3 new-linode">
<td>Plan</td>
<td>
<select id="dest-plan"></select>
$<span id="dest-plan-price"></span> per month
</td>
</tr>
<tr class="lmc-tr3 new-linode">
<td>Label</td>
<td><input id="dest-label" type="text" /></td>
</tr>
<tr class="lmc-tr3 new-linode">
<td>Backups</td>
<td>
<input id="dest-backups" type="checkbox" />
<label for="dest-backups">$<span id="dest-backups-price"></span> per month</label>
</td>
</tr>
<tr class="lmc-tr3">
<td></td>
<td><button id="clone-button" type="button">Clone</button></td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>