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

63
linodes/disk/disk.css Normal file
View File

@ -0,0 +1,63 @@
/*
* 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');
#disk {
padding: 0px 15px 15px;
}
h3 {
border-bottom: 1px solid #E8E8E8;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 18px;
font-weight: lighter;
margin-bottom: 0px;
}
.resize {
display: none;
}
#space-warning {
display: none;
}
.stats-box {
border-right: 1px solid #E8E8E8;
display: inline-block;
font-size: 11px;
padding: 5px 12px 0;
}
.stats-box:last-of-type {
border-right: none;
}
.stats-box span {
font-size: 13.3px;
font-weight: bold;
}
tbody tr:last-of-type {
border: none;
}
tbody tr td:first-of-type {
font-weight: bold;
text-align: right;
}

297
linodes/disk/disk.js Normal file
View File

@ -0,0 +1,297 @@
/*
* 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, apiPut, parseParams, setupHeader } from "/global.js";
(function()
{
// Element names specific to this page
elements.currentSize = "current-size";
elements.currentSizeRow = "current-size-row";
elements.currentType = "current-type";
elements.duplicateButton = "duplicate-button";
elements.imageButton = "image-button";
elements.label = "label";
elements.linodeLabel = "linode-label";
elements.linodeTag = "linode-tag";
elements.linodeTagLink = "linode-tag-link";
elements.maxSize = "max-size";
elements.resizeAddl = "resize-addl";
elements.saveButton = "save-button";
elements.size = "size";
elements.spaceAllocated = "space-allocated";
elements.spaceFree = "space-free";
elements.spaceTotal = "space-total";
elements.spaceWarning = "space-warning";
elements.subnav = "subnav-link";
elements.subnavActive = "subnav-link-active";
elements.type = "type";
// Data recieved from API calls
var data = {};
data.disks = [];
data.linode = {};
// Static references to UI elements
var ui = {};
ui.currentSize = {};
ui.currentSizeRow = {};
ui.currentType = {};
ui.duplicateButton = {};
ui.imageButton = {};
ui.label = {};
ui.linodeLabel = {};
ui.linodeTag = {};
ui.linodeTagLink = {};
ui.maxSize = {};
ui.resizeAddl = {};
ui.saveButton = {};
ui.size = {};
ui.spaceAllocated = {};
ui.spaceFree = {};
ui.spaceTotal = {};
ui.spaceWarning = {};
ui.type = {};
// Temporary state
var state = {};
state.haveDisks = false;
// 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";
}
if (state.haveDisks)
displayStorage();
};
// 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
if (response.page != response.pages) {
apiGet("/linode/instances/" + data.params.lid + "/disks?page=" + (response.page + 1), displayDisks, null);
return;
}
for (var i = 0; i < data.disks.length; i++) {
if (data.disks[i].id == data.params.did) {
data.disk = data.disks[i];
break;
}
}
state.haveDisks = true;
if (data.linode.specs)
displayStorage();
if (!data.disk)
return;
// Update form
ui.label.value = data.disk.label;
ui.currentType.innerHTML = data.disk.filesystem;
ui.currentSize.innerHTML = data.disk.size;
ui.size.value = data.disk.size;
if (data.disk.filesystem != "raw" && data.disk.filesystem != "swap")
ui.imageButton.disabled = false;
};
// Show storage totals
var displayStorage = function()
{
var storageUsed = 0;
for (var i = 0; i < data.disks.length; i++)
storageUsed += data.disks[i].size;
var storageFree = data.linode.specs.disk - storageUsed;
ui.spaceAllocated.innerHTML = storageUsed;
ui.spaceFree.innerHTML = storageFree;
ui.spaceTotal.innerHTML = data.linode.specs.disk;
if (data.params.did == 0) {
ui.size.max = storageFree;
ui.maxSize.innerHTML = storageFree;
if (storageFree <= 0)
ui.spaceWarning.style.display = "block";
else
ui.saveButton.disabled = false;
}
if (!data.disk)
return;
ui.size.max = storageFree + data.disk.size;
ui.maxSize.innerHTML = storageFree + data.disk.size;
ui.saveButton.disabled = false;
if (storageFree >= data.disk.size)
ui.duplicateButton.disabled = false;
};
// Duplicate button handler
var handleDuplicate = function(event)
{
if (event.currentTarget.disabled)
return;
apiPost("/linode/instances/" + data.params.lid + "/disks/" + data.params.did + "/clone", {}, function(response)
{
location.href = "/linodes/dashboard?lid=" + data.params.lid;
});
};
// Image button handler
var handleImage = function(event)
{
if (event.currentTarget.disabled)
return;
location.href = "/images/create?lid=" + data.params.lid + "&did=" + data.params.did;
};
// Save button handler
var handleSave = function(event)
{
if (event.currentTarget.disabled)
return;
var diskSize = parseInt(ui.size.value);
var standardCallback = function(response)
{
location.href = "/linodes/dashboard?lid=" + data.params.lid;
};
if (data.params.did == 0) {
var req = {
"label": ui.label.value,
"size": diskSize,
"filesystem": ui.type.value
};
apiPost("/linode/instances/" + data.params.lid + "/disks", req, standardCallback);
} else {
var labelReq = {
"label": ui.label.value
};
var resizeReq = {
"size": diskSize
};
if (data.disk.size != diskSize) {
if (data.disk.label != ui.label.value) {
apiPut("/linode/instances/" + data.params.lid + "/disks/" + data.params.did, labelReq, function(response)
{
apiPost("/linode/instances/" + data.params.lid + "/disks/" + data.params.did + "/resize", resizeReq, standardCallback);
});
} else {
apiPost("/linode/instances/" + data.params.lid + "/disks/" + data.params.did + "/resize", resizeReq, standardCallback);
}
} else if (data.disk.label != ui.label.value) {
apiPut("/linode/instances/" + data.params.lid + "/disks/" + data.params.did, labelReq, standardCallback);
} else {
location.href = "/linodes/dashboard?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;
}
// We also need a disk ID
if (!data.params.did) {
alert("No disk 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=00", data.params.lid);
anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid);
}
// Highlight the dashboard subnav link
var subnavLinks = document.getElementsByClassName(elements.subnav);
for (var i = 0; i < subnavLinks.length; i++) {
if (subnavLinks[i].pathname == "/linodes/dashboard")
subnavLinks[i].className += " " + elements.subnavActive;
}
// Get element references
ui.currentSize = document.getElementById(elements.currentSize);
ui.currentSizeRow = document.getElementById(elements.currentSizeRow);
ui.currentType = document.getElementById(elements.currentType);
ui.duplicateButton = document.getElementById(elements.duplicateButton);
ui.imageButton = document.getElementById(elements.imageButton);
ui.label = document.getElementById(elements.label);
ui.linodeLabel = document.getElementById(elements.linodeLabel);
ui.linodeTag = document.getElementById(elements.linodeTag);
ui.linodeTagLink = document.getElementById(elements.linodeTagLink);
ui.maxSize = document.getElementById(elements.maxSize);
ui.resizeAddl = document.getElementById(elements.resizeAddl);
ui.saveButton = document.getElementById(elements.saveButton);
ui.size = document.getElementById(elements.size);
ui.spaceAllocated = document.getElementById(elements.spaceAllocated);
ui.spaceFree = document.getElementById(elements.spaceFree);
ui.spaceTotal = document.getElementById(elements.spaceTotal);
ui.spaceWarning = document.getElementById(elements.spaceWarning);
ui.type = document.getElementById(elements.type);
if (data.params.did != 0) {
ui.currentSizeRow.style.display = "table-row";
ui.duplicateButton.style.display = "initial";
ui.imageButton.style.display = "initial";
ui.type.style.display = "none";
ui.resizeAddl.style.display = "initial";
}
// Register event handlers
ui.duplicateButton.addEventListener("click", handleDuplicate);
ui.imageButton.addEventListener("click", handleImage);
ui.saveButton.addEventListener("click", handleSave);
// Get data from API
apiGet("/linode/instances/" + data.params.lid, displayDetails, null);
apiGet("/linode/instances/" + data.params.lid + "/disks", displayDisks, null);
};
// Attach onload handler
window.addEventListener("load", setup);
})();

92
linodes/disk/index.shtml Normal file
View File

@ -0,0 +1,92 @@
<!--
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 Disk</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="disk.css" />
<script src="disk.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">Edit Disk</span></div>
<div id="disk">
<p id="space-warning" class="warning">Not enough free disk space to create any more disk images</p>
<table class="lmc-table">
<thead>
<tr>
<td colspan="3">Edit Disk</td>
</tr>
</thead>
<tbody>
<tr class="lmc-tr3">
<td>Label</td>
<td colspan="2"><input id="label" type="text" value="New Disk Label" maxlength="48" size="50" /></td>
</tr>
<tr class="lmc-tr3">
<td>Type</td>
<td colspan="2">
<select id="type">
<option selected value="ext4">ext4</option>
<option value="ext3">ext3</option>
<option value="swap">swap</option>
<option value="raw">unformatted / raw</option>
<option value="initrd">initrd (uncompressed initrd, ext2, max: 32 MB)</option>
</select>
<span id="current-type"></span>
</td>
</tr>
<tr id="current-size-row" class="lmc-tr3 resize">
<td>Current Size</td>
<td colspan="2"><span id="current-size"></span> MB</td>
</tr>
<tr class="lmc-tr3">
<td>Size</td>
<td><input id="size" type="number" min="1" value="1" /> MB</td>
<td><span class="info">Enter a size between 1 and <span id="max-size"></span><span id="resize-addl" class="resize"> to resize this disk</span></span></td>
</tr>
<tr class="lmc-tr3">
<td></td>
<td colspan="2">
<button disabled id="save-button" type="button">Save Changes</button>
<button disabled id="duplicate-button" class="resize" type="button">Duplicate Disk</button>
<button disabled id="image-button" class="resize" type="button">Create Image</button>
</td>
</tr>
</tbody>
</table>
<h3>Storage Stats</h3>
<div class="stats-box">
<span><span id="space-allocated"></span> MB</span><br />
Allocated
</div>
<div class="stats-box">
<span><span id="space-free"></span> MB</span><br />
Free
</div>
<div class="stats-box">
<span><span id="space-total"></span> MB</span><br />
Total
</div>
</div>
</div>
</body>
</html>