From 509ea616fc8b1ea844ecdbec64bcee85a9290c46 Mon Sep 17 00:00:00 2001 From: Will Nilges Date: Sat, 10 Sep 2022 09:48:46 -0400 Subject: [PATCH 1/3] Allow admins to cleanup vnc sessions with a button Puts a button on the "settings" page that will run the 'cleanup vnc sessions' task manually. Useful for debugging, or if something is really busted. --- proxstar/__init__.py | 2 ++ proxstar/static/js/script.js | 26 +++++++++++++++++++++++++- proxstar/templates/settings.html | 7 +++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/proxstar/__init__.py b/proxstar/__init__.py index 5d5e1a6..54e04b4 100644 --- a/proxstar/__init__.py +++ b/proxstar/__init__.py @@ -568,6 +568,8 @@ def settings(): templates=templates, ignored_pools=db_ignored_pools, allowed_users=db_allowed_users, + vnc_cleanup_token=app.config['VNC_CLEANUP_TOKEN'], + server_name=app.config['SERVER_NAME'] ) else: return abort(403) diff --git a/proxstar/static/js/script.js b/proxstar/static/js/script.js index 53bd1cd..c30a761 100644 --- a/proxstar/static/js/script.js +++ b/proxstar/static/js/script.js @@ -627,6 +627,31 @@ $(".add-ignored-pool").click(function(){ }); }); +$("#generate-pool-cache-task-button").click(function(){ + +}); + +$("#process-expiring-vms-task-button").click(function(){ +}); + +$("#cleanup-vnc-task-button").click(function(){ + const vncCleanupToken = $(this).data('vnc_cleanup_token'); +// let data = {'token': vncCleanupToken}; + + console.log(vncCleanupToken); + + var formData = new FormData(); + formData.append('token', vncCleanupToken); + fetch(`/console/cleanup`, { + method: 'post', + credentials: 'same-origin', + body: formData + }).then(res => { + console.log("Request complete! response:", res); + }); +}); + + function change_for_template(obj) { var template_element = obj; var selected = template_element.options[template_element.selectedIndex].value; @@ -653,7 +678,6 @@ $("#console-vm").click(function(){ return response.json() }).then((vnc_params) => { // TODO (willnilges): encrypt=true - // TODO (willnilges): set host and port to an env variable window.open(`/static/noVNC/vnc.html?autoconnect=true&password=${vnc_params.password}&host=${vnc_params.host}&port=${vnc_params.port}&path=path?token=${vnc_params.token}`, '_blank'); }).catch(err => { if (err) { diff --git a/proxstar/templates/settings.html b/proxstar/templates/settings.html index 1df687f..34bd502 100644 --- a/proxstar/templates/settings.html +++ b/proxstar/templates/settings.html @@ -113,6 +113,13 @@ +
+ + + + + +
From cd6bdba409130a1635d3e6971419784cac8d8e9c Mon Sep 17 00:00:00 2001 From: Will Nilges Date: Sat, 10 Sep 2022 10:16:57 -0400 Subject: [PATCH 2/3] SweetAlert on "Cleanup VNC Sessions" --- proxstar/static/js/script.js | 50 +++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/proxstar/static/js/script.js b/proxstar/static/js/script.js index c30a761..e2c9bab 100644 --- a/proxstar/static/js/script.js +++ b/proxstar/static/js/script.js @@ -636,18 +636,44 @@ $("#process-expiring-vms-task-button").click(function(){ $("#cleanup-vnc-task-button").click(function(){ const vncCleanupToken = $(this).data('vnc_cleanup_token'); -// let data = {'token': vncCleanupToken}; - - console.log(vncCleanupToken); - - var formData = new FormData(); - formData.append('token', vncCleanupToken); - fetch(`/console/cleanup`, { - method: 'post', - credentials: 'same-origin', - body: formData - }).then(res => { - console.log("Request complete! response:", res); + + swal({ + title: "Are you sure you want to clear VNC tokens?", + text: "This will clear the websockify targets file, and remove all entries from Redis. Ongoing VNC sessions may be disrupted.", + icon: "warning", + buttons: { + cancel: true, + action: { + text: "Cleanup VNC Sessions", + closeModal: false, + className: "swal-button--danger", + } + }, + dangerMode: true, + }) + .then((willComplete) => { + if (willComplete) { + var formData = new FormData(); + formData.append('token', vncCleanupToken); + fetch(`/console/cleanup`, { + method: 'post', + credentials: 'same-origin', + body: formData + }).then((response) => { + return swal("VNC Sessions have been cleared", { + icon: "success", + }); + }).then(() => { + window.location = location; + }).catch(err => { + if (err) { + swal("Uh oh...", "Unable to clear VNC sessions", "error"); + } else { + swal.stopLoading(); + swal.close(); + } + }); + } }); }); From 7c4bcb24975dbe148a3c7bbbcbfe2ef2f892d5ee Mon Sep 17 00:00:00 2001 From: Will Nilges Date: Sat, 10 Sep 2022 10:32:21 -0400 Subject: [PATCH 3/3] Disable other task buttons These tasks are not currently reachable through the API. Given that I don't yet fully grasp what they do, that might not be a bad thing. --- proxstar/static/js/script.js | 4 +++- proxstar/templates/settings.html | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/proxstar/static/js/script.js b/proxstar/static/js/script.js index e2c9bab..2234fe1 100644 --- a/proxstar/static/js/script.js +++ b/proxstar/static/js/script.js @@ -627,12 +627,14 @@ $(".add-ignored-pool").click(function(){ }); }); +// TODO: Move these tasks so they're callable via JS? +/* $("#generate-pool-cache-task-button").click(function(){ - }); $("#process-expiring-vms-task-button").click(function(){ }); +*/ $("#cleanup-vnc-task-button").click(function(){ const vncCleanupToken = $(this).data('vnc_cleanup_token'); diff --git a/proxstar/templates/settings.html b/proxstar/templates/settings.html index 34bd502..cef6537 100644 --- a/proxstar/templates/settings.html +++ b/proxstar/templates/settings.html @@ -114,10 +114,11 @@
- - - - + +