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

View File

@ -0,0 +1,98 @@
<!--
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 - Volumes</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="settings.css" />
<script src="settings.js" type="module"></script>
</head>
<body>
<!--#include virtual="/include/header.html"-->
<div id="main-content" class="wrapper">
<div id="top-links"><a href="/volumes">Volumes</a> » <span id="volume-label" class="top-links-title"></span></div>
<div id="settings">
<table class="lmc-table">
<thead>
<tr>
<td colspan="3">Block Storage Volume Settings</td>
</tr>
</thead>
<tbody>
<tr class="lmc-tr3">
<td>Label</td>
<td><input id="label" type="text" /></td>
<td class="info">A unique name for this volume</td>
</tr>
<tr class="lmc-tr3">
<td>Status</td>
<td id="status"></td>
<td class="info">The current status of the volume</td>
</tr>
<tr class="lmc-tr3">
<td>Attachment</td>
<td>
<select id="attachment">
<option selected value="0">No attachment</option>
</select>
<span id="attached"><a id="linode-label"></a> | <a href="/volumes/detach?vid=0">Detach</a></span>
</td>
<td class="info">The Linode this volume is attached to</td>
</tr>
<tr class="lmc-tr3">
<td>Size</td>
<td><input id="size" type="number" min="10" /></td>
<td class="info">The size of the volume in GiB</td>
</tr>
<tr class="lmc-tr3">
<td>Location</td>
<td id="location"></td>
<td class="info">The datacenter where this volume is located</td>
</tr>
<tr class="lmc-tr3">
<td>Filesystem Path</td>
<td id="path"></td>
<td class="info">The path that this volume is accessible through when attached to a running Linode</td>
</tr>
<tr class="lmc-tr3">
<td></td>
<td><button disabled id="save-button" type="button">Save Changes</button></td>
<td></td>
</tr>
</tbody>
<tbody class="lmc-tbody-head">
<tr>
<td colspan="3">Instructions</td>
</tr>
</tbody>
</table>
<div id="instructions">
<p>To get started with a new volume, you'll want to create a filesystem on it:</p>
<code>mkfs.ext4 /dev/disk/by-id/scsi-0Linode_Volume_test_volume</code>
<p>Once the volume has a filesystem, you can create a mountpoint for it:</p>
<code>mkdir /mnt/test_volume</code>
<p>Then you can mount the new volume:</p>
<code>mount /dev/disk/by-id/scsi-0Linode_Volume_test_volume /mnt/test_volume</code>
<p>If you want the volume to automatically mount every time your Linode boots, you'll want to add a line like the following to your <strong>/etc/fstab</strong> file:</p>
<code>/dev/disk/by-id/scsi-0Linode_Volume_test_volume /mnt/test_volume ext4 defaults,noatime,nofail 0 2</code>
</div>
</div>
</div>
</body>
</html>

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');
#attached {
display: none;
}
code {
border: 1px solid #E7E6E6;
display: block;
padding: 10px;
}
#instructions {
color: #333;
font-size: 13px;
padding: 0 60px;
}
#settings {
padding: 0px 15px 15px;
}
tbody:not(.lmc-tbody-head) tr td:first-of-type {
font-weight: bold;
text-align: right;
}

View File

@ -0,0 +1,209 @@
/*
* 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, regionNames, apiGet, apiPost, apiPut, parseParams, setupHeader } from "/global.js";
(function()
{
// Element names specific to this page
elements.attached = "attached";
elements.attachment = "attachment";
elements.label = "label";
elements.linodeLabel = "linode-label";
elements.location = "location";
elements.path = "path";
elements.saveButton = "save-button";
elements.size = "size";
elements.status = "status";
elements.volumeLabel = "volume-label";
// Data recieved from API calls
var data = {};
data.volume = {};
// Static references to UI elements
var ui = {};
ui.attached = {};
ui.attachment = {};
ui.label = {};
ui.linodeLabel = {};
ui.location = {};
ui.path = {};
ui.saveButton = {};
ui.size = {};
ui.status = {};
ui.volumeLabel = {};
// Temporary state
var state = {};
state.redirect = "/volumes";
state.requests = 0;
state.returns = 0;
// Callback for attached linode API call
var displayLinode = function(response)
{
ui.linodeLabel.innerHTML = response.label;
};
// Callback for linodes API call
var displayLinodes = function(response)
{
// Add linodes to selector
for (var i = 0; i < response.data.length; i++) {
var linode = document.createElement("option");
linode.value = response.data[i].id;
linode.innerHTML = response.data[i].label;
ui.attachment.appendChild(linode);
if (data.volume.linode_id && data.volume.linode_id == response.data[i].id)
ui.attachment.value = response.data[i].id;
}
// Request the next page if there are more pages
if (response.page != response.pages) {
var filter = {
"region": data.volume.region
};
apiGet("/linode/instances?page=" + (response.page + 1), displayLinodes, null);
return;
}
};
// Callback for volume API call
var displayVolume = function(response)
{
data.volume = response;
// Set page title and header stuff
document.title += " // " + data.volume.label;
ui.volumeLabel.innerHTML = data.volume.label;
// Fill in details
ui.label.value = data.volume.label;
ui.status.innerHTML = data.volume.status;
ui.size.value = data.volume.size;
ui.size.min = data.volume.size;
if (regionNames[data.volume.region])
ui.location.innerHTML = regionNames[data.volume.region];
else
ui.location.innerHTML = data.volume.region;
ui.path.innerHTML = data.volume.filesystem_path;
if (data.volume.linode_id) {
ui.attachment.style.display = "none";
ui.attached.style.display = "initial";
ui.linodeLabel.href = "/linodes/dashboard?lid=" + data.volume.linode_id;
apiGet("/linode/instances/" + data.volume.linode_id, displayLinode, null);
} else {
// Get linodes in the same DC
var filter = {
"region": data.volume.region
};
apiGet("/linode/instances", displayLinodes, filter);
}
ui.saveButton.disabled = false;
};
// Click handler for save button
var handleSave = function(event)
{
if (event.currentTarget.disabled)
return;
state.requests = 0;
state.returns = 0;
// Common callback
var callback = function(response)
{
state.returns++;
if (state.returns >= state.requests)
location.href = state.redirect;
};
// Attach request
if (!data.volume.linode_id && ui.attachment.value != "0") {
state.requests++;
state.redirect = "/linodes/dashboard?lid=" + ui.attachment.value;
var attachReq = {
"linode_id": parseInt(ui.attachment.value)
};
apiPost("/volumes/" + data.params.vid + "/attach", attachReq, callback);
}
// Label change request
if (ui.label.value != data.volume.label) {
state.requests++;
var labelReq = {
"label": ui.label.value
};
apiPut("/volumes/" + data.params.vid, labelReq, callback);
}
// Size change
var size = parseInt(ui.size.value);
if (size > data.volume.size) {
state.requests++;
var sizeReq = {
"size": size
};
apiPost("/volumes/" + data.params.vid + "/resize", sizeReq, callback);
}
};
// Initial setup
var setup = function()
{
// Parse URL parameters
data.params = parseParams();
// We need a volume ID, so die if we don't have it
if (!data.params.vid) {
alert("No volume ID supplied!");
return;
}
setupHeader();
// Update links on page to include proper volume ID
var anchors = document.getElementsByTagName("a");
for (var i = 0; i < anchors.length; i++)
anchors[i].href = anchors[i].href.replace("vid=0", "vid=" + data.params.vid);
// Get element references
ui.attached = document.getElementById(elements.attached);
ui.attachment = document.getElementById(elements.attachment);
ui.label = document.getElementById(elements.label);
ui.linodeLabel = document.getElementById(elements.linodeLabel);
ui.location = document.getElementById(elements.location);
ui.path = document.getElementById(elements.path);
ui.saveButton = document.getElementById(elements.saveButton);
ui.size = document.getElementById(elements.size);
ui.status = document.getElementById(elements.status);
ui.volumeLabel = document.getElementById(elements.volumeLabel);
// Attach event handlers
ui.saveButton.addEventListener("click", handleSave);
// Get data from API
apiGet("/volumes/" + data.params.vid, displayVolume, null);
};
// Attach onload handler
window.addEventListener("load", setup);
})();