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

View File

@ -0,0 +1,27 @@
/*
* 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');
#app {
padding: 15px 15px 15px;
}
tbody:not(.lmc-tbody-head) tr td:first-of-type {
font-weight: bold;
text-align: right;
}

View File

@ -0,0 +1,137 @@
/*
* 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.callback = "callback";
elements.label = "label";
elements.pub = "public";
elements.saveButton = "save-button";
elements.thumbnail = "thumbnail";
// Data received from API calls
var data = {};
data.app = {};
// Static references to UI elements
var ui = {};
ui.callback = {};
ui.label = {};
ui.pub = {};
ui.saveButton = {};
ui.thumbnail = {};
// Temporary state
var state = {};
state.sentApp = false;
state.sentThumb = false;
// Callback for app details API call
var displayApp = function(response)
{
data.app = response;
ui.label.value = data.app.label;
ui.callback.value = data.app.redirect_uri;
ui.pub.checked = data.app.public;
ui.saveButton.disabled = false;
};
// Click handler for save button
var handleSave = function(event)
{
if (event.currentTarget.disabled)
return;
var req = {
"label": ui.label.value,
"redirect_uri": ui.callback.value
};
if (data.params.aid != "0") {
if (ui.thumbnail.files.length && ui.thumbnail.files[0].type.startsWith("image/")) {
apiPut("/account/oauth-clients/" + data.params.aid + "/thumbnail", ui.thumbnail.files[0], function(response)
{
state.sentThumb = true;
if (state.sentApp)
location.href = "/account/oauth_apps";
});
} else {
state.sentThumb = true;
}
apiPut("/account/oauth-clients/" + data.params.aid, req, function(response)
{
state.sentApp = true;
if (state.sentThumb)
location.href = "/account/oauth_apps";
});
} else {
req.public = ui.pub.checked;
apiPost("/account/oauth-clients", req, function(response)
{
alert("Here is your client secret! Store it securely, as it won't be shown again.\n" + response.secret);
if (ui.thumbnail.files.length && ui.thumbnail.files[0].type.startsWith("image/")) {
apiPut("/account/oauth-clients/" + response.id + "/thumbnail", ui.thumbnail.files[0], function(response)
{
location.href = "/account/oauth_apps";
});
} else {
location.href = "/account/oauth_apps";
}
});
}
ui.saveButton.disabled = true;
};
// Initial setup
var setup = function()
{
// Parse URL parameters
data.params = parseParams();
// Assume 0 if no app ID supplied
if (!data.params.aid)
data.params.aid = "0";
setupHeader();
// Get element references
ui.callback = document.getElementById(elements.callback);
ui.label = document.getElementById(elements.label);
ui.pub = document.getElementById(elements.pub);
ui.saveButton = document.getElementById(elements.saveButton);
ui.thumbnail = document.getElementById(elements.thumbnail);
// Fetch app details if specified
if (data.params.aid != "0") {
apiGet("/account/oauth-clients/" + data.params.aid, displayApp, null);
} else {
ui.pub.disabled = false;
ui.saveButton.disabled = false;
}
// Register event handlers
ui.saveButton.addEventListener("click", handleSave);
};
// Attach onload handler
window.addEventListener("load", setup);
})();

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/>.
-->
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LMC - Account // Edit OAuth App</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="app.css" />
<script src="app.js" type="module"></script>
</head>
<body>
<!--#include virtual="/include/header.html"-->
<!--#include virtual="/include/account_subnav.html"-->
<div id="main-content" class="wrapper">
<div id="app">
<table class="lmc-table">
<thead>
<tr>
<td colspan="2">Add/Edit an OAuth App</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>Callback URL</td>
<td><input id="callback" type="text" size="30" /></td>
</tr>
<tr class="lmc-tr3">
<td>Public</td>
<td><input disabled id="public" type="checkbox" /></td>
</tr>
<tr class="lmc-tr3">
<td>Thumbnail</td>
<td><input id="thumbnail" type="file" accept="image/*" /></td>
</tr>
<tr class="lmc-tr3">
<td></td>
<td><button disabled id="save-button" type="button">Save Changes</button></td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,53 @@
<!--
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 - Account // OAuth Apps</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="oauth_apps.css" />
<script src="oauth_apps.js" type="module"></script>
</head>
<body>
<!--#include virtual="/include/header.html"-->
<!--#include virtual="/include/account_subnav.html"-->
<div id="main-content" class="wrapper">
<div id="oauth_apps">
<table class="lmc-table">
<thead>
<tr>
<td colspan="6">OAuth Apps</td>
</tr>
<tr>
<td></td>
<td>Label</td>
<td>Access</td>
<td>ID</td>
<td>Callback URL</td>
<td>Options</td>
</tr>
</thead>
<tbody id="oauth-apps"></tbody>
</table>
<p class="sub-links">
<a href="/account/oauth_apps/app?aid=0">Add an OAuth App</a>
</p>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,32 @@
/*
* 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');
.app-img {
height: 36px;
vertical-align: middle;
width: 36px;
}
#oauth_apps {
padding: 15px 15px 15px;
}
td:nth-of-type(6) {
text-align: center;
}

View File

@ -0,0 +1,163 @@
/*
* 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, apiDelete, apiGet, apiPost, parseParams, setupHeader } from "/global.js";
(function()
{
// Element names specific to this page
elements.appImg = "app-img";
elements.lmcRow = "lmc-tr1";
elements.lmcRowAlt = "lmc-tr2";
elements.oauthApps = "oauth-apps";
// Data received from API calls
var data = {};
data.apps = [];
// Static references to UI elements
var ui = {};
ui.oauthApps = {};
// Creates a row in the authorized apps table
var createAppRow = function(app, alt)
{
var row = document.createElement("tr");
if (alt)
row.className = elements.lmcRowAlt;
else
row.className = elements.lmcRow;
var thumb = document.createElement("td");
if (app.thumbnail_url && app.thumbnail_url.length) {
var thumbImg = document.createElement("img");
thumbImg.className = elements.appImg;
thumbImg.src = settings.apiURL + app.thumbnail_url;
thumbImg.alt = app.label;
thumb.appendChild(thumbImg);
}
row.appendChild(thumb);
var label = document.createElement("td");
label.innerHTML = app.label;
row.appendChild(label);
var access = document.createElement("td");
if (app.public)
access.innerHTML = "Public";
else
access.innerHTML = "Private";
row.appendChild(access);
var id = document.createElement("td");
id.innerHTML = app.id;
row.appendChild(id);
var callback = document.createElement("td");
callback.innerHTML = app.redirect_uri;
row.appendChild(callback);
var options = document.createElement("td");
var editLink = document.createElement("a");
editLink.href = "/account/oauth_apps/app?aid=" + app.id;
editLink.innerHTML = "Edit";
var separator = document.createElement("span");
separator.innerHTML = " | ";
var resetLink = document.createElement("a");
resetLink.id = "reset-app-" + app.id;
resetLink.href = "#";
resetLink.innerHTML = "Reset Secret";
resetLink.addEventListener("click", resetApp);
var removeLink = document.createElement("a");
removeLink.id = "remove-app-" + app.id;
removeLink.href = "#";
removeLink.innerHTML = "Remove";
removeLink.addEventListener("click", removeApp);
options.appendChild(editLink);
options.appendChild(separator);
options.appendChild(resetLink);
options.appendChild(separator.cloneNode(true));
options.appendChild(removeLink);
row.appendChild(options);
return row;
};
// Callback for authorized apps API call
var displayApps = function(response)
{
data.apps = data.apps.concat(response.data);
// Request the next page if there are more
if (response.page != response.pages) {
apiGet("/account/oauth-clients?page=" + (response.page + 1), displayApps, null);
return;
}
// Redirect to add page if there are no OAuth apps
if (!data.apps.length)
location.href = "/account/oauth_apps/app?aid=0";
// Add apps to table
for (var i = 0; i < data.apps.length; i++)
ui.oauthApps.appendChild(createAppRow(data.apps[i], i % 2));
};
// Handle removing an OAuth app
var removeApp = function(event)
{
var id = event.currentTarget.id.split("-")[2];
if (!confirm("Are you sure you want to permanently delete this app?"))
return;
apiDelete("/account/oauth-clients/" + id, function(response)
{
location.reload();
});
};
// Handle resetting an OAuth app secret
var resetApp = function(event)
{
var id = event.currentTarget.id.split("-")[2];
if (!confirm("Are you sure you want to permanently reset the secret for this app?"))
return;
apiPost("/account/oauth-clients/" + id + "/reset-secret", {}, function(response)
{
alert("Here is your client secret! Store it securely, as it won't be shown again.\n" + response.secret);
});
};
// Initial setup
var setup = function()
{
// Parse URL parameters
data.params = parseParams();
setupHeader();
// Get element references
ui.oauthApps = document.getElementById(elements.oauthApps);
// Get data from API
apiGet("/account/oauth-clients", displayApps, null);
};
// Attach onload handler
window.addEventListener("load", setup);
})();