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

31
images/create/create.css Normal file
View File

@ -0,0 +1,31 @@
/*
* 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');
#create {
padding: 0px 15px 15px;
}
tbody tr:last-of-type {
border: none;
}
tbody tr td:first-of-type {
font-weight: bold;
text-align: right;
}

155
images/create/create.js Normal file
View File

@ -0,0 +1,155 @@
/*
* 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, parseParams, setupHeader, timeString } from "/global.js";
(function()
{
// Element names specific to this page
elements.createButton = "create-button";
elements.description = "description";
elements.diskLabel = "disk-label";
elements.label = "label";
elements.linodeLabel = "linode-label";
elements.linodeTag = "linode-tag";
elements.linodeTagLink = "linode-tag-link";
elements.nav = "navlink";
elements.navActive = "navlink-active";
elements.size = "size";
elements.type = "type";
// Data recieved from API calls
var data = {};
data.disk = {};
data.linode = {};
// Static references to UI elements
var ui = {};
ui.createButton = {};
ui.description = {};
ui.diskLabel = {};
ui.label = {};
ui.linodeLabel = {};
ui.linodeTag = {};
ui.linodeTagLink = {};
ui.size = {};
ui.type = {};
// Create button handler
var handleCreate = function(event)
{
if (event.currentTarget.disabled)
return;
var req = {
"disk_id": data.disk.id,
"label": ui.label.value
};
if (ui.description.value.length)
req.description = ui.description.value;
apiPost("/images", req, function(response)
{
location.href = "/linodes/dashboard?lid=" + data.params.lid;
});
};
// Callback for linode details API call
var displayDetails = function(response)
{
data.linode = response;
// Set page title and header stuff
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";
}
};
// Callback for image API call
var displayDisk = function(response)
{
data.disk = response;
// Display disk label in page header
ui.diskLabel.innerHTML = data.disk.label;
// Fill in details
ui.label.value = data.disk.label;
ui.type.innerHTML = data.disk.filesystem;
ui.size.innerHTML = data.disk.size;
ui.createButton.disabled = false;
};
// Initial setup
var setup = function()
{
// Parse URL parameters
data.params = parseParams();
// We need an 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 and disk IDs
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);
anchors[i].href = anchors[i].href.replace("did=0", "did=" + data.params.did);
}
// Highlight the Linodes nav link
var navLinks = document.getElementsByClassName(elements.nav);
for (var i = 0; i < navLinks.length; i++) {
if (navLinks[i].pathname == "/linodes/")
navLinks[i].className = elements.navActive;
}
// Get element references
ui.createButton = document.getElementById(elements.createButton);
ui.description = document.getElementById(elements.description);
ui.diskLabel = document.getElementById(elements.diskLabel);
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.size = document.getElementById(elements.size);
ui.type = document.getElementById(elements.type);
// Attach event handlers
ui.createButton.addEventListener("click", handleCreate);
// Get data from API
apiGet("/linode/instances/" + data.params.lid, displayDetails, null);
apiGet("/linode/instances/" + data.params.lid + "/disks/" + data.params.did, displayDisk, null);
};
// Attach onload handler
window.addEventListener("load", setup);
})();

68
images/create/index.shtml Normal file
View File

@ -0,0 +1,68 @@
<!--
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 - Create Image</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="create.css" />
<script src="create.js" type="module"></script>
</head>
<body>
<!--#include virtual="/include/header.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 id="disk-label" href="/linodes/disk?did=0&lid=0"></a> » <span class="top-links-title">Imageize Disk Image</span></div>
<div id="create">
<table class="lmc-table">
<thead>
<tr>
<td colspan="3">Image</td>
</tr>
</thead>
<tbody>
<tr class="lmc-tr3">
<td>Label</td>
<td><input id="label" type="text" size="50" /></td>
<td><span class="info">See also: <a href="https://www.linode.com/docs/platform/linode-images" target="_blank">Using Linode Images</a></span></td>
</tr>
<tr class="lmc-tr3">
<td>Type</td>
<td id="type"></td>
<td></td>
</tr>
<tr class="lmc-tr3">
<td>Disk Size</td>
<td><span id="size"></span> MB</td>
<td></td>
</tr>
<tr class="lmc-tr3">
<td>Description</td>
<td><textarea id="description" rows="4" cols="78"></textarea></td>
<td></td>
</tr>
<tr class="lmc-tr3">
<td></td>
<td><button disabled id="create-button" type="button">Create Image</button></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>