This commit is contained in:
Willard Nilges 2024-11-26 01:32:47 +00:00 committed by GitHub
commit 6a12159dd6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 63 additions and 1 deletions

View file

@ -679,6 +679,8 @@ def settings():
templates=templates, templates=templates,
ignored_pools=db_ignored_pools, ignored_pools=db_ignored_pools,
allowed_users=db_allowed_users, allowed_users=db_allowed_users,
vnc_cleanup_token=app.config['VNC_CLEANUP_TOKEN'],
server_name=app.config['SERVER_NAME']
) )
else: else:
return abort(403) return abort(403)

View file

@ -730,6 +730,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) { function change_for_template(obj) {
var template_element = obj; var template_element = obj;
var selected = template_element.options[template_element.selectedIndex].value; var selected = template_element.options[template_element.selectedIndex].value;
@ -756,7 +809,6 @@ $("#console-vm").click(function(){
return response.json() return response.json()
}).then((vnc_params) => { }).then((vnc_params) => {
// TODO (willnilges): encrypt=true // 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'); 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 => { }).catch(err => {
if (err) { if (err) {

View file

@ -113,6 +113,14 @@
</div> </div>
</div> </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>
</div> </div>