Browse Source

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

pull/4/head
L. Bradley LaBoon 7 months ago
parent
commit
c58e2fc545
  1. 4
      README.md
  2. 27
      account/oauth_apps/app/app.css
  3. 137
      account/oauth_apps/app/app.js
  4. 63
      account/oauth_apps/app/index.shtml
  5. 53
      account/oauth_apps/index.shtml
  6. 32
      account/oauth_apps/oauth_apps.css
  7. 163
      account/oauth_apps/oauth_apps.js
  8. BIN
      favicon.ico
  9. 2
      global.css
  10. 84
      global.js
  11. 3
      include/account_subnav.html
  12. 10
      include/profile_subnav.html
  13. 4
      linodes/backup_details/backup_details.css
  14. 2
      linodes/backup_details/index.shtml
  15. 9
      linodes/dashboard/dashboard.js
  16. 73
      linodes/linodes.js
  17. 57
      profile/api/add/add.css
  18. 191
      profile/api/add/add.js
  19. 93
      profile/api/add/index.shtml
  20. 41
      profile/api/api.css
  21. 327
      profile/api/api.js
  22. 67
      profile/api/index.shtml
  23. 31
      profile/auth/auth.css
  24. 164
      profile/auth/auth.js
  25. 80
      profile/auth/index.shtml
  26. 93
      profile/index.shtml
  27. 87
      profile/lish/index.shtml
  28. 39
      profile/lish/lish.css
  29. 115
      profile/lish/lish.js
  30. 31
      profile/profile.css
  31. 127
      profile/profile.js
  32. 62
      profile/referrals/index.shtml
  33. 35
      profile/referrals/referrals.css
  34. 75
      profile/referrals/referrals.js
  35. 27
      profile/ssh/add/add.css
  36. 69
      profile/ssh/add/add.js
  37. 55
      profile/ssh/add/index.shtml
  38. 51
      profile/ssh/index.shtml
  39. 36
      profile/ssh/remove/index.shtml
  40. 22
      profile/ssh/remove/remove.css
  41. 80
      profile/ssh/remove/remove.js
  42. 31
      profile/ssh/ssh.css
  43. 120
      profile/ssh/ssh.js
  44. 98
      profile/twofactor/index.shtml
  45. 52
      profile/twofactor/twofactor.css
  46. 95
      profile/twofactor/twofactor.js
  47. 2
      user/index.shtml
  48. 69
      user/user.js

4
README.md

@ -16,13 +16,13 @@ This project is currently a work in progress. The following list provides a high
- [x] Block Storage (Volumes)
- [x] Images
- [x] DNS
- [x] Account Details (exluding PayPal support)
- [x] Account Details (excluding PayPal support)
- [x] User Profile Settings
- [ ] PayPal payments
- [ ] Graphs
- [ ] StackScripts
- [ ] NodeBalancers
- [ ] Longview
- [ ] User Profile Settings
- [ ] Support Tickets
Eventually I plan to also implement features which were never available in the original manager, including Object Storage, One-Click Apps, and LKE.

27
account/oauth_apps/app/app.css

@ -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;
}

137
account/oauth_apps/app/app.js

@ -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);
})();

63
account/oauth_apps/app/index.shtml

@ -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>

53
account/oauth_apps/index.shtml

@ -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>

32
account/oauth_apps/oauth_apps.css

@ -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;
}

163
account/oauth_apps/oauth_apps.js

@ -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);
})();

BIN
favicon.ico

2
global.css

@ -90,7 +90,7 @@ header {
border-bottom: 1px solid #E8E8E8;
}
.lmc-table tbody:not(.lmc-tbody-head) tr:last-of-type {
.lmc-table tbody:not(.lmc-tbody-head):last-of-type tr:last-of-type {
border: none;
}

84
global.js

@ -77,6 +77,13 @@ var eventTitles = {
"dns_zone_delete": "Delete DNS Zone",
"dns_zone_import": "Import DNS Zone",
"dns_zone_update": "Update DNS Zone",
"firewall_create": "Create Firewall",
"firewall_delete": "Delete Firewall",
"firewall_disable": "Disable Firewall",
"firewall_enable": "Enable Firewall",
"firewall_update": "Update Firewall",
"firewall_device_add": "Add Firewall Device",
"firewall_device_remove": "Remove Firewall Device",
"host_reboot": "Host Initiated Restart",
"image_delete": "Delete Image",
"image_update": "Update Image",
@ -104,6 +111,10 @@ var eventTitles = {
"linode_config_create": "Create Configuration Profile",
"linode_config_delete": "Delete Configuration Profile",
"linode_config_update": "Update Configuration Profile",
"lke_node_create": "Create LKE Node",
"longviewclient_create": "Create Longview Client",
"longviewclient_delete": "Delete Longview Client",
"longviewclient_update": "Update Longview Client",
"managed_disabled": "Managed Service Disabled",
"managed_enabled": "Managed Service Enabled",
"managed_service_create": "Create Managed Service",
@ -117,6 +128,10 @@ var eventTitles = {
"nodebalancer_node_create": "Create NodeBalancer Node",
"nodebalancer_node_delete": "Delete NodeBalancer Node",
"nodebalancer_node_update": "Update NodeBalancer Node",
"oauth_client_create": "Create OAuth Client",
"oauth_client_delete": "Delete OAuth Client",
"oauth_client_secret_reset": "Reset OAuth Client Secret",
"oauth_client_update": "Update OAuth Client",
"password_reset": "Change Root Password",
"payment_submitted": "Payment Submitted",
"profile_update": "Update Profile",
@ -125,12 +140,21 @@ var eventTitles = {
"stackscript_update": "Update StackScript",
"stackscript_publicize": "Publish StackScript",
"stackscript_revise": "Revise StackScript",
"tag_create": "Create Tag",
"tag_delete": "Delete Tag",
"tfa_disabled": "2FA Disabled",
"tfs_enabled": "2FA Enabled",
"ticket_attachment_upload": "Uploaded Ticket Attachment",
"ticket_create": "Create Ticket",
"ticket_update": "Update Ticket",
"token_create": "Create API Token",
"token_delete": "Delete API Token",
"token_update": "Update API Token",
"user_create": "Create User",
"user_delete": "Delete User",
"user_update": "Update User",
"user_ssh_key_add": "Add SSH Key",
"user_ssh_key_delete": "Delete SSH Key",
"user_ssh_key_update": "Update SSH Key",
"vlan_attach": "Attach VLAN",
"vlan_detach": "Detach VLAN",
@ -143,6 +167,24 @@ var eventTitles = {
"volume_resize": "Resize Volume"
};
// A list of OAuth scopes
var oauthScopes = {
"account": "Account",
"databases": "Databases",
"domains": "Domains",
"events": "Events",
"firewall": "Firewalls",
"images": "Images",
"ips": "IPs",
"linodes": "Linodes",
"lke": "Kubernetes",
"longview": "Longview",
"nodebalancers": "NodeBalancers",
"object_storage": "Object Storage",
"stackscripts": "StackScripts",
"volumes": "Volumes"
};
// Make an HTTP DELETE request to the Linode API
function apiDelete(endpoint, callback)
{
@ -249,6 +291,10 @@ function apiGet(endpoint, callback, filters)
location.href = "/";
}
// Redirect to linodes page if unauthorized
if (xmlhttp.status == 403)
location.href = "/linodes";
return;
}
@ -281,7 +327,10 @@ function apiPost(endpoint, data, callback)
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", settings.apiURL + endpoint, true);
xmlhttp.setRequestHeader("Authorization", localStorage.apiKey);
xmlhttp.setRequestHeader("Content-Type", "application/json");
if (data instanceof File)
xmlhttp.setRequestHeader("Content-Type", data.type);
else
xmlhttp.setRequestHeader("Content-Type", "application/json");
xmlhttp.onreadystatechange = function()
{
@ -314,7 +363,10 @@ function apiPost(endpoint, data, callback)
callback(response);
};
xmlhttp.send(JSON.stringify(data));
if (data instanceof File)
xmlhttp.send(data);
else
xmlhttp.send(JSON.stringify(data));
}
// Make an HTTP PUT request to the Linode API
@ -339,7 +391,10 @@ function apiPut(endpoint, data, callback)
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("PUT", settings.apiURL + endpoint, true);
xmlhttp.setRequestHeader("Authorization", localStorage.apiKey);
xmlhttp.setRequestHeader("Content-Type", "application/json");
if (data instanceof File)
xmlhttp.setRequestHeader("Content-Type", data.type);
else
xmlhttp.setRequestHeader("Content-Type", "application/json");
xmlhttp.onreadystatechange = function()
{
@ -372,7 +427,10 @@ function apiPut(endpoint, data, callback)
callback(response);
};
xmlhttp.send(JSON.stringify(data));
if (data instanceof File)
xmlhttp.send(data);
else
xmlhttp.send(JSON.stringify(data));
}
// Callback for user info API call
@ -389,15 +447,23 @@ function displayUser(response)
// Display profile pic
var profilePic = document.getElementById(elements.profilePic);
profilePic.src = "https://www.gravatar.com/avatar/" + md5(response.email);
profilePic.src = "https://www.gravatar.com/avatar/" + md5(response.email, false);
profilePic.style = "display: initial;";
}
// Return an MD5 hash of the given string
function md5(str)
function md5(str, binary)
{
// Convert string to bytes
var data = new TextEncoder("utf-8").encode(str);
var data;
if (binary) {
var strBytes = [];
for (var i = 0; i < str.length; i++)
strBytes[i] = str.charCodeAt(i);
data = new Uint8Array(strBytes);
} else {
data = new TextEncoder("utf-8").encode(str);
}
// Constants
var s = new Uint32Array([
@ -504,6 +570,8 @@ function md5(str)
if (bytes[j] < 0x10)
md5Str += "0";
md5Str += bytes[j].toString(16);
if (binary && (i != 3 || j != 3))
md5Str += ":";
}
}
@ -698,4 +766,4 @@ function translateKernel(slug, element)
apiGet("/linode/kernels/" + slug, callback, null);
}
export { settings, elements, regionNames, apiDelete, apiGet, apiPost, apiPut, md5, migrateETA, oauthPost, parseParams, setupHeader, eventTitles, timeString, translateKernel };
export { settings, elements, regionNames, apiDelete, apiGet, apiPost, apiPut, md5, migrateETA, oauthPost, oauthScopes, parseParams, setupHeader, eventTitles, timeString, translateKernel };

3
include/account_subnav.html

@ -5,7 +5,8 @@
<a class="subnav-link" href="/account/creditcard">Update Credit Card</a>
<a class="subnav-link" href="/account/make_a_payment">Make A Payment</a>
<a class="subnav-link" href="/account/billing_history">Billing History</a>
<a class="subnav-link" href="/user">Users and Permissions</a>
<a class="subnav-link" href="/user">Users</a>
<a class="subnav-link" href="/account/oauth_apps">OAuth Apps</a>
<a class="subnav-link" href="/account/settings">Account Settings</a>
</nav>
<!--End account subnav-->

10
include/profile_subnav.html

@ -0,0 +1,10 @@
<!--Begin account subnav-->
<nav id="subnav" class="wrapper">
<a class="subnav-link" href="/profile">My Profile</a>
<a class="subnav-link" href="/profile/auth">Password & Authentication</a>
<a class="subnav-link" href="/profile/referrals">Referrals</a>
<a class="subnav-link" href="/profile/ssh">SSH Keys</a>
<a class="subnav-link" href="/profile/lish">Lish Settings</a>
<a class="subnav-link" href="/profile/api">API Keys</a>
</nav>
<!--End account subnav-->

4
linodes/backup_details/backup_details.css

@ -34,10 +34,6 @@ table:first-of-type tbody tr td:first-of-type {
text-align: right;
}
td {
white-space: nowrap;
}
ul {
display: inline;
list-style-position: inside;

2
linodes/backup_details/index.shtml

@ -77,7 +77,7 @@ along with Linode Manager Classic. If not, see <https://www.gnu.org/licenses/>.
<td>Linode</td>
<td>Plan</td>
<td>Location</td>
<td>Unallocated/Free Space</td>
<td>Free Space</td>
<td>Select</td>
</tr>
</thead>

9
linodes/dashboard/dashboard.js

@ -618,6 +618,15 @@ import { settings, elements, apiDelete, apiGet, apiPost, eventTitles, parseParam
if (!data.notifications[i].entity || data.notifications[i].entity.type != "linode" || data.notifications[i].entity.id != data.params.lid)
continue;
if (data.notifications[i].type == "maintenance") {
var now = new Date();
var maintStart = new Date(data.notifications[i].when + "Z");
data.notifications[i].label = "Maintenance Scheduled";
data.notifications[i].message = "This Linode's physical host will be undergoing maintenance on " + maintStart.toLocaleString() + " (in " + timeString(maintStart - now, false) + ").";
data.notifications[i].message += " During this time, your Linode will be shut down and remain offline, then returned to its last state (running or powered off).";
data.notifications[i].message += " For more information, please see your open support tickets.";
}
var notification = document.createElement("div");
notification.className = elements.notification;
var header = document.createElement("h1");

73
linodes/linodes.js

@ -56,6 +56,11 @@ import { settings, elements, regionNames, apiGet, parseParams, setupHeader } fro
ui.loading = {};
ui.notifications = {};
// Temporary state
var state = {};
state.haveLinodes = false;
state.haveNotifications = false;
var createLinodeRow = function(linode, alt)
{
var row = document.createElement("tr");
@ -69,7 +74,19 @@ import { settings, elements, regionNames, apiGet, parseParams, setupHeader } fro
nameLink.innerHTML = linode.label;
name.appendChild(nameLink);
var status = document.createElement("td");
status.innerHTML = linode.status.charAt(0).toUpperCase() + linode.status.slice(1).replace(/_/g, " ");
if (linode.lmc_maint) {
var maintStart = new Date(linode.lmc_maint + "Z");
var line1 = document.createElement("strong");
line1.innerHTML = "Maintenance Scheduled";
var br = document.createElement("br");
var line2 = document.createElement("span");
line2.innerHTML = maintStart.toLocaleString();
status.appendChild(line1);
status.appendChild(br);
status.appendChild(line2);
} else {
status.innerHTML = linode.status.charAt(0).toUpperCase() + linode.status.slice(1).replace(/_/g, " ");
}
var plan = document.createElement("td");
if (linode.type)
plan.innerHTML = getPlanLabel(linode.type);
@ -248,6 +265,8 @@ import { settings, elements, regionNames, apiGet, parseParams, setupHeader } fro
return a.label.toLowerCase().localeCompare(b.label.toLowerCase());
});
state.haveLinodes = true;
// Create tables
ui.loading.remove();
if (data.noTag)
@ -256,13 +275,8 @@ import { settings, elements, regionNames, apiGet, parseParams, setupHeader } fro
createLinodeTable(data.linodeTags[i]);
// Insert linodes
for (var i = 0; i < data.linodes.length; i++) {
if (data.linodes[i].tags.length == 0)
ui.linodeTables[""].appendChild(createLinodeRow(data.linodes[i], ui.linodeTables[""].children.length % 2));
for (var j = 0; j < data.linodes[i].tags.length; j++)
ui.linodeTables[data.linodes[i].tags[j]].appendChild(createLinodeRow(data.linodes[i], ui.linodeTables[data.linodes[i].tags[j]].children.length % 2));
}
if (state.haveNotifications)
insertLinodes();
};
var displayNotifications = function(response)
@ -276,6 +290,8 @@ import { settings, elements, regionNames, apiGet, parseParams, setupHeader } fro
return;
}
state.haveNotifications = true;
// Display notifications
for (var i = 0; i < data.notifications.length; i++) {
if (data.notifications[i].entity && data.notifications[i].entity.type == "linode")
@ -286,11 +302,25 @@ import { settings, elements, regionNames, apiGet, parseParams, setupHeader } fro
var header = document.createElement("h1");
header.innerHTML = data.notifications[i].label;
var body = document.createElement("p");
body.innerHTML = data.notifications[i].message;
// Insert ticket link for ticket notifications
if (data.notifications[i].type == "ticket_important" && data.notifications[i].entity) {
var ticketLink = document.createElement("a");
ticketLink.href = "/support/ticket?tid=" + data.notifications[i].entity.id;
ticketLink.innerHTML = data.notifications[i].entity.label;
body.appendChild(ticketLink);
} else {
body.innerHTML = data.notifications[i].message;
}
// Replace "this facility" with actual location for outages
if (data.notifications[i].type == "outage" && data.notifications[i].entity && data.notifications[i].entity.type == "region" && regionNames[data.notifications[i].entity.id])
header.innerHTML = header.innerHTML.replace("this facility", regionNames[data.notifications[i].entity.id]);
notification.appendChild(header);
notification.appendChild(body);
ui.notifications.appendChild(notification);
}
if (state.haveLinodes)
insertLinodes();
};
var displayTransfer = function(response)
@ -358,6 +388,31 @@ import { settings, elements, regionNames, apiGet, parseParams, setupHeader } fro
apiGet("/linode/instances", displayLinodes, filters);
};
var insertLinodes = function()
{
// Add maintenance windows from notifications
for (var i = 0; i < data.notifications.length; i++) {
if (data.notifications[i].type != "maintenance")
continue;
for (var j = 0; j < data.linodes.length; j++) {
if (data.linodes[j].id == data.notifications[i].entity.id) {
data.linodes[j].lmc_maint = data.notifications[i].when;
break;
}
}
}
// Insert linodes into tables
for (var i = 0; i < data.linodes.length; i++) {
if (data.linodes[i].tags.length == 0)
ui.linodeTables[""].appendChild(createLinodeRow(data.linodes[i], ui.linodeTables[""].children.length % 2));
for (var j = 0; j < data.linodes[i].tags.length; j++)
ui.linodeTables[data.linodes[i].tags[j]].appendChild(createLinodeRow(data.linodes[i], ui.linodeTables[data.linodes[i].tags[j]].children.length % 2));
}
};
var setup = function()
{
// Parse URL parameters

57
profile/api/add/add.css

@ -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

@ -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);
})();

93
profile/api/add/index.shtml

@ -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>

41
profile/api/api.css

@ -0,0 +1,41 @@
/*
* 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');
#api {
padding: 15px 15px 15px;
}
.app-img {
height: 36px;
vertical-align: middle;
width: 36px;
}
.hover-info {
cursor: help;
text-decoration: dotted underline;
}
td:nth-of-type(5) {
text-align: center;
}
thead span.info {
font-size: 12px;
}

327
profile/api/api.js

@ -0,0 +1,327 @@
/*
* 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, apiPut, oauthScopes, parseParams, setupHeader, timeString } from "/global.js";
(function()
{
// Element names specific to this page
elements.apiKeys = "api-keys";
elements.appImg = "app-img";
elements.authorizedApps = "authorized-apps";
elements.hoverInfo = "hover-info";
elements.info = "info";
elements.lmcRow = "lmc-tr1";
elements.lmcRowAlt = "lmc-tr2";
// Data received from API calls
var data = {};
data.apps = [];
data.keys = [];
// Static references to UI elements
var ui = {};
ui.apiKeys = {};
ui.authorizedApps = {};
// 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");
if (app.website && app.website.length) {
var link = document.createElement("a");
link.href = app.website;
link.target = "_blank";
link.innerHTML = app.label;
label.appendChild(link);
} else {
label.innerHTML = app.label;
}
row.appendChild(label);
var created = document.createElement("td");
var created1 = document.createElement("span");
var now = new Date();
var createDt = new Date(app.created + "Z");
created1.innerHTML = timeString(now - createDt, true);
var created2 = document.createElement("span");
created2.className = elements.info;
created2.innerHTML = createDt.toLocaleString();
created.appendChild(created1);
created.appendChild(document.createElement("br"));
created.appendChild(created2);
row.appendChild(created);
var expires = document.createElement("td");
if (app.expiry) {
var expires1 = document.createElement("span");
var expireDt = new Date(app.expiry + "Z");
expires1.innerHTML = timeString(now - expireDt, true);
var expires2 = document.createElement("span");
expires2.className = elements.info;
expires2.innerHTML = expireDt.toLocaleString();
expires.appendChild(expires1);
expires.appendChild(document.createElement("br"));
expires.appendChild(expires2);
} else {
expires.innerHTML = "Never";
}
row.appendChild(expires);
var options = document.createElement("td");
var scopesLink = document.createElement("a");
scopesLink.id = "scopes-app-" + app.id;
scopesLink.href = "#";
scopesLink.innerHTML = "View Scopes";
scopesLink.addEventListener("click", viewScopes);
var separator = document.createElement("span");
separator.innerHTML = " | ";
var removeLink = document.createElement("a");
removeLink.id = "revoke-app-" + app.id;
removeLink.href = "#";
removeLink.innerHTML = "Revoke";
removeLink.addEventListener("click", revoke);
options.appendChild(scopesLink);
options.appendChild(separator);
options.appendChild(removeLink);
row.appendChild(options);
return row;
};
// Creates a row in the API keys table
var createKeyRow = function(key, alt)
{
var row = document.createElement("tr");
if (alt)
row.className = elements.lmcRowAlt;
else
row.className = elements.lmcRow;
var label = document.createElement("td");
label.innerHTML = key.label;
row.appendChild(label);
var prefix = document.createElement("td");
prefix.innerHTML = key.token + "...";
row.appendChild(prefix);
var created = document.createElement("td");
var created1 = document.createElement("span");
var now = new Date();
var createDt = new Date(key.created + "Z");
created1.innerHTML = timeString(now - createDt, true);
var created2 = document.createElement("span");
created2.className = elements.info;
created2.innerHTML = createDt.toLocaleString();
created.appendChild(created1);
created.appendChild(document.createElement("br"));
created.appendChild(created2);
row.appendChild(created);
var expires = document.createElement("td");
if (key.expiry) {
var expires1 = document.createElement("span");
var expireDt = new Date(key.expiry + "Z");
expires1.innerHTML = timeString(now - expireDt, true);
var expires2 = document.createElement("span");
expires2.className = elements.info;
expires2.innerHTML = expireDt.toLocaleString();
expires.appendChild(expires1);
expires.appendChild(document.createElement("br"));
expires.appendChild(expires2);
} else {
expires.innerHTML = "Never";
}
row.appendChild(expires);
var options = document.createElement("td");
var scopesLink = document.createElement("a");
scopesLink.id = "scopes-key-" + key.id;
scopesLink.href = "#";
scopesLink.innerHTML = "View Scopes";
scopesLink.addEventListener("click", viewScopes);
var separator = document.createElement("span");
separator.innerHTML = " | ";
var renameLink = document.createElement("a");
renameLink.id = "rename-" + key.id;
renameLink.href = "#";
renameLink.innerHTML = "Rename";
renameLink.addEventListener("click", handleRename);
var removeLink = document.createElement("a");
removeLink.id = "revoke-key-" + key.id;
removeLink.href = "#";
removeLink.innerHTML = "Revoke";
removeLink.addEventListener("click", revoke);
options.appendChild(scopesLink);
options.appendChild(separator);
options.appendChild(renameLink);
options.appendChild(separator.cloneNode(true));
options.appendChild(removeLink);
row.appendChild(options);