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

31
profile/auth/auth.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');
#auth {
padding: 15px 15px 15px;
}
tbody:not(.lmc-tbody-head) tr td:first-of-type {
font-weight: bold;
text-align: right;
}
.tfa {
display: none;
}

164
profile/auth/auth.js Normal file
View File

@ -0,0 +1,164 @@
/*
* 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, timeString } from "/global.js";
(function()
{
// Element names specific to this page
elements.pwReset = "pw-reset";
elements.tfa = "tfa";
elements.tfaDisable = "tfa-disable";
elements.tfaEnable = "tfa-enable";
elements.tfaStatus = "tfa-status";
elements.trusted = "trusted";
elements.untrust = "untrust";
// Data received from API calls
var data = {};
// Static references to UI elements
var ui = {};
ui.pwReset = {};
ui.tfa = [];
ui.tfaDisable = {};
ui.tfaEnable = {};
ui.tfaStatus = {};
ui.trusted = {};
// Creates a row for the trusted devices list
var createTrustedRow = function(device)
{
var row = document.createElement("div");
row.id = elements.trusted + "-" + device.id;
var br = document.createElement("br");
row.appendChild(br);
var userAgent = document.createElement("span");
userAgent.innerHTML = device.user_agent;
row.appendChild(userAgent);
row.appendChild(br.cloneNode(true));
var lastAuth = document.createElement("span");
var now = new Date();
var authDt = new Date(device.last_authenticated + "Z");
lastAuth.innerHTML = "Last authenticated " + timeString(now - authDt, true) + " from " + device.last_remote_addr;
row.appendChild(lastAuth);
row.appendChild(br.cloneNode(true));
var expiry = document.createElement("span");
var expireDt = new Date(device.expiry + "Z");
expiry.innerHTML = "Expires in " + timeString(expireDt - now, false) + " - ";
row.appendChild(expiry);
var untrust = document.createElement("a");
untrust.id = elements.untrust + "-" + device.id;
untrust.href = "#";
untrust.innerHTML = "untrust";
untrust.addEventListener("click", handleUntrust);
row.appendChild(untrust);
return row;
};
// Callback for profile API call
var displayProfile = function(response)
{
ui.pwReset.href += response.username;
if (response.two_factor_auth) {
apiGet("/profile/devices", displayTrusted, null);
ui.tfaStatus.innerHTML = "Enabled";
ui.tfaEnable.innerHTML = "Reset Two-Factor Authentication";
for (var i = 0; i < ui.tfa.length; i++) {
if (ui.tfa[i].tagName == "TR")
ui.tfa[i].style.display = "table-row";
else
ui.tfa[i].style.display = "initial";
}
} else {
ui.tfaStatus.innerHTML = "Disabled";
}
ui.tfaEnable.disabled = false;
};
// Callback for trusted devices API call
var displayTrusted = function(response)
{
for (var i = 0; i < response.data.length; i++)
ui.trusted.appendChild(createTrustedRow(response.data[i]));
};
// Click handler for disable 2FA link
var handleDisableTFA = function(event)
{
if (!confirm("Are you sure you want to disable two-factor authentication?"))
return;
apiPost("/profile/tfa-disable", {}, function(response)
{
location.reload();
});
};
// Click handler for enable/reset 2FA button
var handleEnableTFA = function(event)
{
if (event.currentTarget.disabled)
return;
location.href = "/profile/twofactor";
};
// Click handler for untrust links
var handleUntrust = function(event)
{
var deviceID = parseInt(event.currentTarget.id.split("-")[1]);
apiDelete("/profile/devices/" + deviceID, function(response)
{
var row = document.getElementById(elements.trusted + "-" + deviceID);
row.remove();
});
};
// Initial setup
var setup = function()
{
// Parse URL parameters
data.params = parseParams();
setupHeader();
// Get element references
ui.pwReset = document.getElementById(elements.pwReset);
ui.tfa = document.getElementsByClassName(elements.tfa);
ui.tfaDisable = document.getElementById(elements.tfaDisable);
ui.tfaEnable = document.getElementById(elements.tfaEnable);
ui.tfaStatus = document.getElementById(elements.tfaStatus);
ui.trusted = document.getElementById(elements.trusted);
// Register event handlers
ui.tfaDisable.addEventListener("click", handleDisableTFA);
ui.tfaEnable.addEventListener("click", handleEnableTFA);
// Get data from API
apiGet("/profile", displayProfile, null);
};
// Attach onload handler
window.addEventListener("load", setup);
})();

80
profile/auth/index.shtml Normal file
View File

@ -0,0 +1,80 @@
<!--
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 // Password & Authentication</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="auth.css" />
<script src="auth.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="auth">
<table class="lmc-table">
<thead>
<tr>
<td colspan="2">Authentication</td>
</tr>
<tr>
<td colspan="2">Change Password</td>
</tr>
</thead>
<tbody>
<tr class="lmc-tr3">
<td>Reset Password</td>
<td><a id="pw-reset" href="https://login.linode.com/forgot/password?username=" target="_blank">Click here to reset your password</a></td>
</tr>
</tbody>
<tbody class="lmc-tbody-head">
<tr class="noshow">
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2">Two-Factor Authentication</td>
</tr>
</tbody>
<tbody>
<tr class="lmc-tr3">
<td>Description</td>
<td>When two-factor authentication is enabled, you'll need to provide a token before you can log in to your Linode account.</td>
</tr>
<tr class="lmc-tr3">
<td>Status</td>
<td>Two-factor authentication is currently: <strong><span id="tfa-status"></span></strong><span class="tfa"> - <a id="tfa-disable" href="#">disable</a></span></td>
</tr>
<tr class="lmc-tr3 tfa">
<td>Scratch Code</td>
<td>One-time use emergency scratch code is shown only once.</td>
</tr>
<tr class="lmc-tr3 tfa">
<td>Trusted Computers</td>
<td id="trusted">The following computers can skip two-factor authentication:</td>
</tr>
<tr class="lmc-tr3">
<td></td>
<td><button disabled id="tfa-enable" type="button">Enable Two-Factor Authentication</button></td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>