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
+76 -8
View File
@@ -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 };