Implemented user profile settings, OAuth apps, and maintenance windows. Other minor fixes/improvements

This commit is contained in:
2021-03-11 10:37:07 -05:00
parent a020009c47
commit c58e2fc545
48 changed files with 3152 additions and 36 deletions

57
profile/api/add/add.css Normal file
View File

@ -0,0 +1,57 @@
/*
* 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');
#add {
padding: 15px 15px 15px;
}
.lmc-table>tbody:not(.lmc-tbody-head)>tr>td:first-of-type {
font-weight: bold;
text-align: right;
}
#scopes-table {
border-bottom: 1px solid #4C4C4C;
border-collapse: separate;
border-left: 1px solid #B2B2B2;
border-right: 1px solid #4C4C4C;
border-spacing: 2px;
border-top: 1px solid #B2B2B2;
margin-bottom: 30px;
}
#scopes-table label {
display: block;
}
#scopes-table tbody td {
text-align: center;
}
#scopes-table tbody td:first-of-type {
text-align: left;
}
#scopes-table td {
border-bottom: 1px solid #B2B2B2;
border-left: 1px solid #4C4C4C;
border-right: 1px solid #B2B2B2;
border-top: 1px solid #4C4C4C;
padding: 2px;
}

191
profile/api/add/add.js Normal file
View File

@ -0,0 +1,191 @@
/*
* 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, apiPost, oauthScopes, parseParams, setupHeader } from "/global.js";
(function()
{
// Element names specific to this page
elements.addButton = "add-button";
elements.expiry = "expiry";
elements.label = "label";
elements.scopeBox = "scope-box";
elements.scopes = "scopes";
elements.selectNone = "select-none";
elements.selectRo = "select-read_only";
elements.selectRw = "select-read_write";
// Data received from API calls
var data = {};
// Static references to UI elements
var ui = {};
ui.addButton = {};
ui.expiry = {};
ui.label = {};
ui.scopes = {};
ui.selectNone = {};
ui.selectRo = {};
ui.selectRw = {};
// Display OAuth scopes in scope selector
var displayScopes = function()
{
for (var scope in oauthScopes) {
var row = document.createElement("tr");
var label = document.createElement("td");
label.innerHTML = oauthScopes[scope];
row.appendChild(label);
var none = document.createElement("td");
var noneLabel = document.createElement("label");
noneLabel.htmlFor = "scope-" + scope + "-none";
var noneBox = document.createElement("input");
noneBox.id = "scope-" + scope + "-none";
noneBox.className = elements.scopeBox;
noneBox.type = "radio";
noneBox.name = "scope-" + scope;
noneBox.checked = true;
noneBox.addEventListener("input", handleSelectScope);
noneLabel.appendChild(noneBox);
none.appendChild(noneLabel);
row.appendChild(none);
var ro = document.createElement("td");
var roLabel = document.createElement("label");
roLabel.htmlFor = "scope-" + scope + "-read_only";
var roBox = document.createElement("input");
roBox.id = "scope-" + scope + "-read_only";
roBox.className = elements.scopeBox;
roBox.type = "radio";
roBox.name = "scope-" + scope;
roBox.addEventListener("input", handleSelectScope);
roLabel.appendChild(roBox);
ro.appendChild(roLabel);
row.appendChild(ro);
var rw = document.createElement("td");
var rwLabel = document.createElement("label");
rwLabel.htmlFor = "scope-" + scope + "-read_write";
var rwBox = document.createElement("input");
rwBox.id = "scope-" + scope + "-read_write";
rwBox.className = elements.scopeBox;
rwBox.type = "radio";
rwBox.name = "scope-" + scope;
rwBox.addEventListener("input", handleSelectScope);
rwLabel.appendChild(rwBox);
rw.appendChild(rwLabel);
row.appendChild(rw);
ui.scopes.appendChild(row);
}
};
// Click handler for add button
var handleAdd = function(event)
{
var req = {
"label": ui.label.value
};
var expiry = parseInt(ui.expiry.value);
if (expiry) {
var expireDt = new Date(Date.now() + expiry).toISOString();
req.expiry = expireDt.slice(0, expireDt.indexOf("."));
}
if (ui.selectRw.checked) {
req.scopes = "*";
} else {
req.scopes = [];
var buttons = document.getElementsByClassName(elements.scopeBox);
for (var i = 0; i < buttons.length; i++) {
if (!buttons[i].checked)
continue;
var attrs = buttons[i].id.split("-");
if (attrs[2] == "none")
continue;
req.scopes.push(attrs[1] + ":" + attrs[2]);
}
req.scopes = req.scopes.join(" ");
if (!req.scopes.length) {
alert("You must select some permissions.");
return;
}
}
apiPost("/profile/tokens", req, function(response)
{
alert("Your API token has been created. Store this secret - it won't be shown again.\n" + response.token);
location.href = "/profile/api";
});
};
// Handler for the "select all" row
var handleSelectAll = function(event)
{
var column = event.currentTarget.id.split("-")[1];
var buttons = document.getElementsByClassName(elements.scopeBox);
for (var i = 0; i < buttons.length; i++) {
if (buttons[i].id.split("-")[2] == column)
buttons[i].checked = true;
}
};
// Handler for individual scope selectors
var handleSelectScope = function(event)
{
ui.selectNone.checked = false;
ui.selectRo.checked = false;
ui.selectRw.checked = false;
};
// Initial setup
var setup = function()
{
// Parse URL parameters
data.params = parseParams();
setupHeader();
// Get element references
ui.addButton = document.getElementById(elements.addButton);
ui.expiry = document.getElementById(elements.expiry);
ui.label = document.getElementById(elements.label);
ui.scopes = document.getElementById(elements.scopes);
ui.selectNone = document.getElementById(elements.selectNone);
ui.selectRo = document.getElementById(elements.selectRo);
ui.selectRw = document.getElementById(elements.selectRw);
// Add scopes to tables
displayScopes();
ui.selectNone.checked = false;
ui.selectRo.checked = false;
ui.selectRw.checked = false;
// Register event handlers
ui.addButton.addEventListener("click", handleAdd);
ui.selectNone.addEventListener("change", handleSelectAll);
ui.selectRo.addEventListener("change", handleSelectAll);
ui.selectRw.addEventListener("change", handleSelectAll);
};
// Attach onload handler
window.addEventListener("load", setup);
})();

View File

@ -0,0 +1,93 @@
<!--
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 - My Profile // Add API Key</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="add.css" />
<script src="add.js" type="module"></script>
</head>
<body>
<!--#include virtual="/include/header.html"-->
<!--#include virtual="/include/profile_subnav.html"-->
<div id="main-content" class="wrapper">
<div id="add">
<table class="lmc-table">
<thead>
<tr>
<td colspan="2">Add an SSH Key</td>
</tr>
</thead>
<tbody>
<tr class="lmc-tr3">
<td>Label</td>
<td><input id="label" type="text" size="30" /></td>
</tr>
<tr class="lmc-tr3">
<td>Expires</td>
<td>
<select id="expiry">
<!-- The values are milliseconds, in case you were wondering -->
<option value="0">Never</option>
<option value="3600000">1 hour</option>
<option value="21600000">6 hours</option>
<option value="43200000">12 hours</option>
<option value="86400000">1 day</option>
<option value="172800000">2 days</option>
<option value="604800000">1 week</option>
<option value="1209600000">2 weeks</option>
<option value="2419200000">4 weeks</option>
<option value="15768000000">6 months</option>
<option value="31536000000">12 months</option>
</select>
</td>
</tr>
<tr class="lmc-tr3">
<td>Scopes</td>
<td>
<table id="scopes-table">
<thead>
<tr>
<td>Access</td>
<td>None</td>
<td>Read Only</td>
<td>Read/Write</td>
</tr>
</thead>
<tbody id="scopes">
<tr>
<td><strong>Select All</strong></td>
<td><label for="select-none"><input id="select-none" type="radio" name="select-all" /></label></td>
<td><label for="select-read_only"><input id="select-read_only" type="radio" name="select-all" /></label></td>
<td><label for="select-read_write"><input id="select-read_write" type="radio" name="select-all" /></label></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr class="lmc-tr3">
<td></td>
<td><button id="add-button" type="button">Create API Key</button></td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>