From 1e2d2c0408810e0e26cde707d96018133c61360c Mon Sep 17 00:00:00 2001 From: daragh Date: Sun, 24 Dec 2023 22:15:06 +0000 Subject: [PATCH 01/18] feat : added frontend for getting ssh keys --- src/ssh.html | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/ssh.html diff --git a/src/ssh.html b/src/ssh.html new file mode 100644 index 0000000..879ad51 --- /dev/null +++ b/src/ssh.html @@ -0,0 +1,90 @@ + + + + + SSH + + + + +
+ +
+

SSH

+

+ Add / Remove SSH Keys from your account. +

+ Enter Username and Password to see your current keys. +

+
+ + + + + + + + + + + + +


+
+

+ + +
+
+ UL Computer Society 2023-2023 + +
+
+ + -- 2.46.1 From 115f0257e5a914abc48bceb9c490e218c3a49525 Mon Sep 17 00:00:00 2001 From: daragh Date: Sat, 30 Dec 2023 01:47:41 +0000 Subject: [PATCH 02/18] feat : frontend for adding & deleting keys --- src/scripts/ssh.js | 127 ++++++++++++++++++++++++++++++++++++++++++++ src/ssh.html | 128 ++++++++++++++++++++------------------------- 2 files changed, 185 insertions(+), 70 deletions(-) create mode 100644 src/scripts/ssh.js diff --git a/src/scripts/ssh.js b/src/scripts/ssh.js new file mode 100644 index 0000000..b791691 --- /dev/null +++ b/src/scripts/ssh.js @@ -0,0 +1,127 @@ +let got_keys = false; + +function get_keys() { + console.log("get_keys running , got_keys = ", got_keys); + let username = document.getElementById("user").value; + let password = document.getElementById("pass").value; + let request = {auth: {user: username, pass: password}}; + + fetch('http://127.0.0.1:8087/ldap/ssh', { + method: 'POST', + body: JSON.stringify(request), + mode: 'cors', + }).then(res => { + if (res.status === 200) { + return res.json(); + } else { + document.getElementById('formStatus').innerHTML = "Failed to fetch"; + } + }).then(data => { + if (data.result === "success") { + document.getElementById('formStatus').innerHTML = "Success : Got keys"; + let keys = data.success; + document.getElementById('key_table').style.display = "table"; + got_keys = true; + keys.forEach(key => { + add_to_table(key); + }) + } else { + document.getElementById('formStatus').innerHTML = "Failed to get keys"; + } + }).catch(err => { + console.log(err); + }); +} + +function add_key() { + let username = document.getElementById("user").value; + let password = document.getElementById("pass").value; + let key = document.getElementById("key_input").value; + let request = {auth: {user: username, pass: password}, key: key}; + if (key === "") { + document.getElementById('formStatus').innerHTML = "Key cannot be empty"; + return; + } + fetch('http://127.0.0.1:8087/ldap/add', { + method: 'POST', + body: JSON.stringify(request), + mode: 'cors', + }).then(res => { + if (res.status === 200) { + return res.json(); + } else { + document.getElementById('formStatus').innerHTML = "Failed to fetch"; + } + + }).then(data => { + if (data.result === "success") { + document.getElementById('formStatus').innerHTML = "Success : Key added"; + document.getElementById('key_table').style.display = "table"; + add_to_table(key); + } else { + document.getElementById('formStatus').innerHTML = "Failed to add"; + } + }).catch(err => { + document.getElementById('formStatus').innerHTML = "Error "; + console.log(err); + }); +} + +function delete_key(row_idx) { + let table = document.getElementById("key_table"); + let key = table.rows[row_idx].cells[0].innerHTML; + let username = document.getElementById("user").value; + let password = document.getElementById("pass").value; + let request = {auth: {user: username, pass: password}, key: key}; + + fetch('http://127.0.0.1:8087/ldap/delete', { + method: 'DELETE', + body: JSON.stringify(request), + mode: 'cors', + }).then(res => { + if (res.status === 200) { + return res.json(); + } else { + document.getElementById('formStatus').innerHTML = "Failed to fetch"; + } + }).then(data => { + if (data.result === "success") { + table.deleteRow(row_idx); + document.getElementById('formStatus').innerHTML = "Success : Key deleted"; + } else { + document.getElementById('formStatus').innerHTML = "Failed to delete"; + } + }).catch(err => { + document.getElementById('formStatus').innerHTML = "Error "; + console.log(err); + }) +} + +function add_to_table(key) { + let table = document.getElementById("key_table"); + let row = table.insertRow(); + let cell1 = row.insertCell(0); + cell1.innerHTML = key; + let cell2 = row.insertCell(1); + + let button = document.createElement("button"); + button.innerHTML = "Delete"; + cell2.appendChild(button); + //cell2.appendChild(document.createElement("button")).innerHTML = "Delete"; + button.addEventListener("click", function () { + delete_key(row.rowIndex); + }); +} + +document.addEventListener("DOMContentLoaded", () => { + document.getElementById("get_keys").addEventListener("click", function () { + if (got_keys) { + console.log("got keys already"); + document.getElementById('formStatus').innerHTML = "Got keys already"; + } else { + get_keys(); + } + }); + document.getElementById("add_key_button").addEventListener("click", add_key); +}); + diff --git a/src/ssh.html b/src/ssh.html index 879ad51..be524f3 100644 --- a/src/ssh.html +++ b/src/ssh.html @@ -1,90 +1,78 @@ - + SSH - - -
- +

SSH

- Add / Remove SSH Keys from your account. -

- Enter Username and Password to see your current keys. + Add / Remove SSH Keys from your account.

- - - - - - - - - - - - -


+ + + + + + + + + + + + +


+ +

- - -
-
+ + + + + + + +
KeyRemove
+ + +
UL Computer Society 2023-2023 -
-
- + + + -- 2.46.1 From 0af81c6efa79522abbdce86942aea13f738cffb0 Mon Sep 17 00:00:00 2001 From: daragh Date: Sat, 30 Dec 2023 01:55:45 +0000 Subject: [PATCH 03/18] fix : fetch paths --- src/scripts/ssh.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/scripts/ssh.js b/src/scripts/ssh.js index b791691..b4ec2dd 100644 --- a/src/scripts/ssh.js +++ b/src/scripts/ssh.js @@ -7,6 +7,7 @@ function get_keys() { let request = {auth: {user: username, pass: password}}; fetch('http://127.0.0.1:8087/ldap/ssh', { + // can switch this to get with auth headers i think method: 'POST', body: JSON.stringify(request), mode: 'cors', @@ -42,7 +43,7 @@ function add_key() { document.getElementById('formStatus').innerHTML = "Key cannot be empty"; return; } - fetch('http://127.0.0.1:8087/ldap/add', { + fetch('http://127.0.0.1:8087/ldap/ssh/add', { method: 'POST', body: JSON.stringify(request), mode: 'cors', @@ -74,7 +75,7 @@ function delete_key(row_idx) { let password = document.getElementById("pass").value; let request = {auth: {user: username, pass: password}, key: key}; - fetch('http://127.0.0.1:8087/ldap/delete', { + fetch('http://127.0.0.1:8087/ldap/ssh', { method: 'DELETE', body: JSON.stringify(request), mode: 'cors', -- 2.46.1 From 7f40a4b259cea66884a8508a88b8faa667af4847 Mon Sep 17 00:00:00 2001 From: daragh Date: Sat, 30 Dec 2023 04:07:35 +0000 Subject: [PATCH 04/18] feat : added link to SSH page from main page Might also need to remove SSH stuff from modify page --- src/index.html | 94 +++++++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 43 deletions(-) diff --git a/src/index.html b/src/index.html index e1faf23..91bb0fa 100644 --- a/src/index.html +++ b/src/index.html @@ -1,65 +1,73 @@ - + Skynet Self Service - - -
- +
-

- Sign-up -

-

- Please use this if you have yet to activate an account on Skynet before. -

+

+ Sign-up +

+

+ Please use this if you have yet to activate an account on Skynet before. +

-

- Change Password -

-

- Please use this service to change your Skynet password -

+

+ Change Password +

+

+ Please use this service to change your Skynet password. +

-

- Account modification -

-

- Please use this service to modify your user data (email, login ssh key, etc.) -

+

+ Account modification +

+

+ Please use this service to modify your user data (email, login ssh key, etc.). +

-

- Forgot your username? -

-

- Please use this service to get a reminder email with your Skynet username -

+

+ Forgot your username? +

+

+ Please use this service to get a reminder email with your Skynet username. +

-

- Forgot your password? -

-

- Please use this service to reset your password. -

+

+ Forgot your password? +

+

+ Please use this service to reset your password. +

-
-
+
+

+ SSH +

+

+ Please use this service to manage your SSH keys. +

+
+ +
UL Computer Society 2023-2023 -
-
- + + + \ No newline at end of file -- 2.46.1 From 128794648c3b918f068962cb4a48330b5a2e04df Mon Sep 17 00:00:00 2001 From: daragh Date: Sat, 30 Dec 2023 23:27:32 +0000 Subject: [PATCH 05/18] feat : made input for new key textarea, split keys on their comment to display in table. Made js code use async/await instead of then. Works fine with mockoon but might need more testing with actual LDAP server. --- src/index.html | 2 +- src/scripts/ssh.js | 128 ----------------------------- src/{ssh.html => ssh/index.html} | 27 ++++--- src/ssh/ssh.js | 134 +++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+), 138 deletions(-) delete mode 100644 src/scripts/ssh.js rename src/{ssh.html => ssh/index.html} (68%) create mode 100644 src/ssh/ssh.js diff --git a/src/index.html b/src/index.html index 91bb0fa..aaa5fcd 100644 --- a/src/index.html +++ b/src/index.html @@ -55,7 +55,7 @@

- SSH + SSH

Please use this service to manage your SSH keys. diff --git a/src/scripts/ssh.js b/src/scripts/ssh.js deleted file mode 100644 index b4ec2dd..0000000 --- a/src/scripts/ssh.js +++ /dev/null @@ -1,128 +0,0 @@ -let got_keys = false; - -function get_keys() { - console.log("get_keys running , got_keys = ", got_keys); - let username = document.getElementById("user").value; - let password = document.getElementById("pass").value; - let request = {auth: {user: username, pass: password}}; - - fetch('http://127.0.0.1:8087/ldap/ssh', { - // can switch this to get with auth headers i think - method: 'POST', - body: JSON.stringify(request), - mode: 'cors', - }).then(res => { - if (res.status === 200) { - return res.json(); - } else { - document.getElementById('formStatus').innerHTML = "Failed to fetch"; - } - }).then(data => { - if (data.result === "success") { - document.getElementById('formStatus').innerHTML = "Success : Got keys"; - let keys = data.success; - document.getElementById('key_table').style.display = "table"; - got_keys = true; - keys.forEach(key => { - add_to_table(key); - }) - } else { - document.getElementById('formStatus').innerHTML = "Failed to get keys"; - } - }).catch(err => { - console.log(err); - }); -} - -function add_key() { - let username = document.getElementById("user").value; - let password = document.getElementById("pass").value; - let key = document.getElementById("key_input").value; - let request = {auth: {user: username, pass: password}, key: key}; - if (key === "") { - document.getElementById('formStatus').innerHTML = "Key cannot be empty"; - return; - } - fetch('http://127.0.0.1:8087/ldap/ssh/add', { - method: 'POST', - body: JSON.stringify(request), - mode: 'cors', - }).then(res => { - if (res.status === 200) { - return res.json(); - } else { - document.getElementById('formStatus').innerHTML = "Failed to fetch"; - } - - }).then(data => { - if (data.result === "success") { - document.getElementById('formStatus').innerHTML = "Success : Key added"; - document.getElementById('key_table').style.display = "table"; - add_to_table(key); - } else { - document.getElementById('formStatus').innerHTML = "Failed to add"; - } - }).catch(err => { - document.getElementById('formStatus').innerHTML = "Error "; - console.log(err); - }); -} - -function delete_key(row_idx) { - let table = document.getElementById("key_table"); - let key = table.rows[row_idx].cells[0].innerHTML; - let username = document.getElementById("user").value; - let password = document.getElementById("pass").value; - let request = {auth: {user: username, pass: password}, key: key}; - - fetch('http://127.0.0.1:8087/ldap/ssh', { - method: 'DELETE', - body: JSON.stringify(request), - mode: 'cors', - }).then(res => { - if (res.status === 200) { - return res.json(); - } else { - document.getElementById('formStatus').innerHTML = "Failed to fetch"; - } - }).then(data => { - if (data.result === "success") { - table.deleteRow(row_idx); - document.getElementById('formStatus').innerHTML = "Success : Key deleted"; - } else { - document.getElementById('formStatus').innerHTML = "Failed to delete"; - } - }).catch(err => { - document.getElementById('formStatus').innerHTML = "Error "; - console.log(err); - }) -} - -function add_to_table(key) { - let table = document.getElementById("key_table"); - let row = table.insertRow(); - let cell1 = row.insertCell(0); - cell1.innerHTML = key; - let cell2 = row.insertCell(1); - - let button = document.createElement("button"); - button.innerHTML = "Delete"; - cell2.appendChild(button); - //cell2.appendChild(document.createElement("button")).innerHTML = "Delete"; - button.addEventListener("click", function () { - delete_key(row.rowIndex); - }); -} - -document.addEventListener("DOMContentLoaded", () => { - document.getElementById("get_keys").addEventListener("click", function () { - if (got_keys) { - console.log("got keys already"); - document.getElementById('formStatus').innerHTML = "Got keys already"; - } else { - get_keys(); - } - }); - document.getElementById("add_key_button").addEventListener("click", add_key); -}); - diff --git a/src/ssh.html b/src/ssh/index.html similarity index 68% rename from src/ssh.html rename to src/ssh/index.html index be524f3..955f38f 100644 --- a/src/ssh.html +++ b/src/ssh/index.html @@ -3,15 +3,25 @@ SSH - - - + + + -

+
+

+ Forgot your 2FA code? +

+

+ Please use this service to reset your 2FA code. +

+