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,51 @@
/*
* 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');
#backups {
padding: 0px 15px 15px;
}
#cancel-link {
text-align: center;
}
#in-progress {
display: none;
}
#schedule-updated {
background-color: #ADD370;
display: none;
font-size: 16px;
margin-top: 0;
padding: 7px;
}
table {
margin-bottom: 30px;
}
table:first-of-type tbody:not(.lmc-tbody-head) tr td:first-of-type {
font-weight: bold;
text-align: right;
}
tbody:not(.lmc-tbody-head) tr:last-of-type {
border: none;
}

270
linodes/backups/backups.js Normal file
View File

@ -0,0 +1,270 @@
/*
* 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, timeString } from "/global.js";
(function()
{
// Element names specific to this page
elements.backupDay = "backup-day";
elements.backupTable = "backup-table";
elements.backupWindow = "backup-window";
elements.inProgress = "in-progress";
elements.linodeLabel = "linode-label";
elements.linodeTag = "linode-tag";
elements.linodeTagLink = "linode-tag-link";
elements.lmcRow = "lmc-tr3";
elements.saveButton = "save-button";
elements.scheduleUpdated = "schedule-updated";
elements.snapshotButton = "snapshot-button";
elements.snapshotLabel = "snapshot-label";
elements.timezone = "timezone";
elements.window = "window";
// Data recieved from API calls
var data = {};
data.backups = {};
data.backupsSorted = [];
data.linode = {};
data.profile = {};
// Static references to UI elements
var ui = {};
ui.backupDay = {};
ui.backupTable = {};
ui.backupWindow = {};
ui.inProgress = {};
ui.linodeLabel = {};
ui.linodeTag = {};
ui.linodeTagLink = {};
ui.saveButton = {};
ui.scheduleUpdated = {};
ui.snapshotButton = {};
ui.snapshotLabel = {};
ui.timezone = {};
ui.windows = [];
// Generate a backup table row
var createBackupRow = function(backup)
{
var row = document.createElement("tr");
row.className = elements.lmcRow;
var type = document.createElement("td");
type.innerHTML = backup.type;
row.appendChild(type);
var started = document.createElement("td");
var startedDate = new Date(backup.created + "Z");
started.innerHTML = startedDate.toLocaleString();
row.appendChild(started);
var finished = document.createElement("td");
if (backup.finished) {
var finishedDate = new Date(backup.finished + "Z");
finished.innerHTML = finishedDate.toLocaleString();
}
row.appendChild(finished);
var duration = document.createElement("td");
if (backup.finished)
duration.innerHTML = timeString(finishedDate - startedDate, false);
row.appendChild(duration);
var status = document.createElement("td");
status.innerHTML = backup.status;
row.appendChild(status);
var restore = document.createElement("td");
if (backup.status == "successful") {
var restoreLink = document.createElement("a");
restoreLink.href = "/linodes/backup_details?lid=" + data.params.lid + "&bid=" + backup.id;
restoreLink.innerHTML = "Restore to...";
restore.appendChild(restoreLink);
}
row.appendChild(restore);
return row;
};
// Callback for backups API call
var displayBackups = function(response)
{
data.backups = response;
// Enable snapshot button if there's no snapshot in progress
if (!data.backups.snapshot.in_progress) {
ui.snapshotButton.disabled = false;
} else {
ui.snapshotButton.style.display = "none";
ui.snapshotLabel.style.display = "none";
ui.inProgress.style.display = "initial";
ui.backupTable.appendChild(createBackupRow(data.backups.snapshot.in_progress));
}
// Sort backups by date
data.backupsSorted = data.backups.automatic;
if (data.backups.snapshot.current)
data.backupsSorted.push(data.backups.snapshot.current);
data.backupsSorted.sort(function(a, b)
{
var startA = new Date(a.created + "Z");
var startB = new Date(b.created + "Z");
return startB - startA;
});
// Add them to the table
for (var i = 0; i < data.backupsSorted.length; i++)
ui.backupTable.appendChild(createBackupRow(data.backupsSorted[i]));
};
// 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";
}
// Redirect to enable page if backups not enabled
if (!data.linode.backups.enabled)
location.href = "/linodes/backups_enable?lid=" + data.params.lid;
// Set backup settings
ui.backupWindow.value = data.linode.backups.schedule.window;
ui.backupDay.value = data.linode.backups.schedule.day;
ui.saveButton.disabled = false;
};
// Handler for save button
var handleSave = function(event)
{
if (event.currentTarget.disabled)
return;
var req = {
"backups": {
"schedule": {
"day": ui.backupDay.value,
"window": ui.backupWindow.value
}
}
};
apiPut("/linode/instances/" + data.params.lid, req, function(response)
{
ui.scheduleUpdated.style.display = "block";
});
};
// Handler for snapshot button
var handleSnapshot = function(event)
{
if (event.currentTarget.disabled)
return;
if (!confirm("Taking a snapshot will back up your Linode in its current state, over-writing your previous snapshot. Are you sure?"))
return;
var req = {
"label": ui.snapshotLabel.value
};
apiPost("/linode/instances/" + data.params.lid + "/backups", req, function(response)
{
location.reload();
});
};
// 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.backupDay = document.getElementById(elements.backupDay);
ui.backupTable = document.getElementById(elements.backupTable);
ui.backupWindow = document.getElementById(elements.backupWindow);
ui.inProgress = document.getElementById(elements.inProgress);
ui.linodeLabel = document.getElementById(elements.linodeLabel);
ui.linodeTag = document.getElementById(elements.linodeTag);
ui.linodeTagLink = document.getElementById(elements.linodeTagLink);
ui.saveButton = document.getElementById(elements.saveButton);
ui.scheduleUpdated = document.getElementById(elements.scheduleUpdated);
ui.snapshotButton = document.getElementById(elements.snapshotButton);
ui.snapshotLabel = document.getElementById(elements.snapshotLabel);
ui.timezone = document.getElementById(elements.timezone);
ui.windows = document.getElementsByClassName(elements.window);
// Display timezone info
var now = new Date();
var offset = now.getTimezoneOffset() / -60;
var offsetHours = Math.floor(offset);
var offsetMins = now.getTimezoneOffset() % 60;
if (offsetMins < 10)
offsetMins = "0" + offsetMins;
ui.timezone.innerHTML = "GMT";
if (offset >= 0)
ui.timezone.innerHTML += "+";
ui.timezone.innerHTML += offset;
for (var i = 0; i < ui.windows.length; i++) {
var windowNum = parseInt(ui.windows[i].value.substring(1));
var startHour = windowNum + offsetHours;
if (startHour < 0)
startHour += 24;
if (startHour < 10)
startHour = "0" + startHour;
var endHour = windowNum + offsetHours + 2;
if (endHour < 0)
endHour += 24;
if (endHour < 10)
endHour = "0" + endHour;
ui.windows[i].innerHTML = startHour + ":" + offsetMins + " - " + endHour + ":" + offsetMins;
}
// Attach button handlers
ui.saveButton.addEventListener("click", handleSave);
ui.snapshotButton.addEventListener("click", handleSnapshot);
// Get data from API
apiGet("/linode/instances/" + data.params.lid, displayDetails, null);
apiGet("/linode/instances/" + data.params.lid + "/backups", displayBackups, null);
};
// Attach onload handler
window.addEventListener("load", setup);
})();

122
linodes/backups/index.shtml Normal file
View File

@ -0,0 +1,122 @@
<!--
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 - Backups</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="backups.css" />
<script src="backups.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">Backups</span></div>
<div id="backups">
<p id="schedule-updated">Backup schedule updated.</p>
<table class="lmc-table">
<thead>
<tr>
<td colspan="2">Backup Settings</td>
</tr>
<tr>
<td colspan="2">Schedule</td>
</tr>
</thead>
<tbody>
<tr class="lmc-tr3">
<td>Backup Window (<span id="timezone"></span>)</td>
<td>
<select id="backup-window">
<option selected disabled value="Scheduling">Choose a time</option>
<option class="window" value="W0">00:00 - 02:00</option>
<option class="window" value="W2">02:00 - 04:00</option>
<option class="window" value="W4">04:00 - 06:00</option>
<option class="window" value="W6">06:00 - 08:00</option>
<option class="window" value="W8">08:00 - 10:00</option>
<option class="window" value="W10">10:00 - 12:00</option>
<option class="window" value="W12">12:00 - 14:00</option>
<option class="window" value="W14">14:00 - 16:00</option>
<option class="window" value="W16">16:00 - 18:00</option>
<option class="window" value="W18">18:00 - 20:00</option>
<option class="window" value="W20">20:00 - 22:00</option>
<option class="window" value="W22">22:00 - 00:00</option>
</select>
</td>
</tr>
<tr class="lmc-tr3">
<td>Weekly Backup</td>
<td>
<select id="backup-day">
<option selected disabled value="Scheduling">Choose a day</option>
<option value="Sunday">Sunday</option>
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
<option value="Saturday">Saturday</option>
</select>
</td>
</tr>
<tr class="lmc-tr3">
<td></td>
<td><button disabled id="save-button" type="button">Save Changes</button></td>
</tr>
</tbody>
<tbody class="lmc-tbody-head">
<tr class="noshow">
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2">Manual Snapshot</td>
</tr>
</tbody>
<tbody>
<tr class="lmc-tr3">
<td></td>
<td>
<span id="in-progress">— Snapshot In Progress —<br /></span>
<input id="snapshot-label" type="text" placeholder="My New Snapshot Label" minlength="1" maxlength="255" size="32" />
<button disabled id="snapshot-button" type="button">Take a New Snapshot Now</button>
</td>
</tr>
</tbody>
</table>
<table class="lmc-table">
<thead>
<tr>
<td colspan="6">Available Backups</td>
</tr>
<tr>
<td>Type</td>
<td>Started</td>
<td>Finished</td>
<td>Duration</td>
<td>Status</td>
<td>Restore</td>
</tr>
</thead>
<tbody id="backup-table"></tbody>
</table>
<p id="cancel-link"><a href="/linodes/backups_cancel?lid=0">Cancel Backups</a></p>
</div>
</div>
</body>
</html>