Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button to manually run the Cleanup VNC sessions task #172

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions proxstar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
54 changes: 53 additions & 1 deletion proxstar/static/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,59 @@ $(".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');

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


function change_for_template(obj) {
var template_element = obj;
var selected = template_element.options[template_element.selectedIndex].value;
Expand All @@ -653,7 +706,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) {
Expand Down
8 changes: 8 additions & 0 deletions proxstar/templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ <h3 class="panel-title">Allowed Users</h3>
</div>
</div>
</div>
<div class="panel-body">
<!--TODO: Expose these functions through Flask so that they can be called with the API-->
<!--
<button class="btn btn-secondary" id="generate-pool-cache-task-button" name="generate-pool-cache-task-button" >GENERATE POOL CACHE</button>
<button class="btn btn-secondary" id="process-expiring-vms-task-button" name="process-expiring-vms-task-button">PROCESS EXPIRING VMS</button>
-->
<button class="btn btn-secondary" id="cleanup-vnc-task-button" name="cleanup-vnc-task-button" data-vnc_cleanup_token="{{ vnc_cleanup_token }}" data-server_name="{{ server_name }}">CLEANUP VNC SESSIONS</button>
</div>
</div>
</div>

Expand Down