diff --git a/proxstar/__init__.py b/proxstar/__init__.py index 7e19c75..94fb7b8 100644 --- a/proxstar/__init__.py +++ b/proxstar/__init__.py @@ -389,7 +389,7 @@ def boot_order(vmid): def create(): user = User(session['userinfo']['preferred_username']) proxmox = connect_proxmox() - if user.active: + if user.active or user.rtp: if request.method == 'GET': isos = get_isos(proxmox, app.config['PROXMOX_ISO_STORAGE']) pools = get_pools(proxmox, db) diff --git a/proxstar/db.py b/proxstar/db.py index 55dc274..f09fef5 100644 --- a/proxstar/db.py +++ b/proxstar/db.py @@ -192,8 +192,8 @@ def delete_allowed_user(db, user): def set_template_info(db, template_id, name, disk): if db.query(exists().where(Template.id == template_id, )).scalar(): - template = db.query(Template).filter(Template.id == template_id, - ).one() + template = db.query(Template).filter( + Template.id == template_id, ).one() template.name = name template.disk = disk db.commit() diff --git a/proxstar/static/js/script.js b/proxstar/static/js/script.js index 5bf3dc3..fd60b38 100644 --- a/proxstar/static/js/script.js +++ b/proxstar/static/js/script.js @@ -4,36 +4,34 @@ $(document).ready(function(){ $('[data-toggle="tooltip"]').tooltip(); }); -$("#delete-vm").click(function(){ - const vmname = $(this).data('vmname'); +function confirmDialog(url, confirm, confirmButton, complete, error, location) { swal({ - title: `Are you sure you want to delete ${vmname}?`, + title: confirm, icon: "warning", buttons: { cancel: true, - delete: { - text: "Delete", + action: { + text: confirmButton, closeModal: false, className: "swal-button--danger", } }, dangerMode: true, }) - .then((willDelete) => { - if (willDelete) { - const vmid = $(this).data('vmid'); - fetch(`/vm/${vmid}/delete`, { + .then((willComplete) => { + if (willComplete) { + fetch(url, { credentials: 'same-origin', method: 'post' }).then((response) => { - return swal(`${vmname} is now being deleted.`, { + return swal(complete, { icon: "success", }); }).then(() => { - window.location = "/"; + window.location = location; }).catch(err => { if (err) { - swal("Uh oh...", `Unable to delete ${vmname}. Please try again later.`, "error"); + swal("Uh oh...", error, "error"); } else { swal.stopLoading(); swal.close(); @@ -41,162 +39,36 @@ $("#delete-vm").click(function(){ }); } }); +} + +$("#delete-vm").click(function(){ + const vmname = $(this).data('vmname'); + const vmid = $(this).data('vmid') + confirmDialog(`/vm/${vmid}/delete`, `Are you sure you want to delete ${vmname}?`, "Delete", `${vmname} is now being deleted.`, `Unable to delete ${vmname}. Please try again later.`, '/') }); $("#stop-vm").click(function(){ const vmname = $(this).data('vmname'); - swal({ - title: `Are you sure you want to stop ${vmname}?`, - icon: "warning", - buttons: { - cancel: true, - delete: { - text: "Stop", - closeModal: false, - className: "swal-button--danger", - } - }, - dangerMode: true, - }) - .then((willStop) => { - if (willStop) { - const vmid = $(this).data('vmid') - fetch(`/vm/${vmid}/power/stop`, { - credentials: 'same-origin', - method: 'post' - }).then((response) => { - return swal(`${vmname} is now stopping!`, { - icon: "success", - }); - }).then(() => { - window.location = `/vm/${vmid}`; - }).catch(err => { - if (err) { - swal("Uh oh...", `Unable to stop ${vmname}. Please try again later.`, "error"); - } else { - swal.stopLoading(); - swal.close(); - } - }); - } - }); + const vmid = $(this).data('vmid') + confirmDialog(`/vm/${vmid}/power/stop`, `Are you sure you want to stop ${vmname}?`, "Stop", `${vmname} is now stopping!`, `Unable to stop ${vmname}. Please try again later.`, `/vm/${vmid}`) }); $("#reset-vm").click(function(){ const vmname = $(this).data('vmname'); - swal({ - title: `Are you sure you want to reset ${vmname}?`, - icon: "warning", - buttons: { - cancel: true, - delete: { - text: "Reset", - closeModal: false, - className: "swal-button--danger", - } - }, - dangerMode: true, - }) - .then((willReset) => { - if (willReset) { - const vmid = $(this).data('vmid'); - fetch(`/vm/${vmid}/power/reset`, { - credentials: 'same-origin', - method: 'post' - }).then((response) => { - return swal(`${vmname} is now resetting!`, { - icon: "success", - }); - }).then(() => { - window.location = `/vm/${vmid}`; - }).catch(err => { - if (err) { - swal("Uh oh...", `Unable to reset ${vmname}. Please try again later.`, "error"); - } else { - swal.stopLoading(); - swal.close(); - } - }); - } - }); + const vmid = $(this).data('vmid') + confirmDialog(`/vm/${vmid}/power/reset`, `Are you sure you want to reset ${vmname}?`, "Reset", `${vmname} is now resetting!`, `Unable to reset ${vmname}. Please try again later.`, `/vm/${vmid}`) }); $("#shutdown-vm").click(function(){ const vmname = $(this).data('vmname'); - swal({ - title: `Are you sure you want to shutdown ${vmname}?`, - icon: "warning", - buttons: { - cancel: true, - delete: { - text: "Shutdown", - closeModal: false, - className: "swal-button--danger", - } - }, - dangerMode: true, - }) - .then((willShutdown) => { - if (willShutdown) { - const vmid = $(this).data('vmid'); - fetch(`/vm/${vmid}/power/shutdown`, { - credentials: 'same-origin', - method: 'post' - }).then((response) => { - return swal(`${vmname} is now shutting down!`, { - icon: "success", - }); - }).then(() => { - window.location = `/vm/${vmid}`; - }).catch(err => { - if (err) { - swal("Uh oh...", `Unable to shutdown ${vmname}. Please try again later.`, "error"); - } else { - swal.stopLoading(); - swal.close(); - } - }); - } - }); + const vmid = $(this).data('vmid') + confirmDialog(`/vm/${vmid}/power/shutdown`, `Are you sure you want to shutdown ${vmname}?`, "Shutdown", `${vmname} is now shutting down!`, `Unable to shutdown ${vmname}. Please try again later.`, `/vm/${vmid}`) }); $("#suspend-vm").click(function(){ const vmname = $(this).data('vmname'); - swal({ - title: `Are you sure you want to suspend ${vmname}?`, - icon: "warning", - buttons: { - cancel: true, - delete: { - text: "Suspend", - closeModal: false, - className: "swal-button--danger", - } - }, - dangerMode: true, - }) - .then((willSuspend) => { - if (willSuspend) { - const vmid = $(this).data('vmid'); - fetch(`/vm/${vmid}/power/suspend`, { - credentials: 'same-origin', - method: 'post' - }).then((response) => { - return swal(`${vmname} is now suspending!`, { - icon: "success", - }); - }).then(() => { - window.location = `/vm/${vmid}`; - }).catch(err => { - if (err) { - swal("Uh oh...", `Unable to suspend ${vmname}. Please try again later.`, "error"); - } else { - swal.stopLoading(); - swal.close(); - } - }); - } - }); + const vmid = $(this).data('vmid') + confirmDialog(`/vm/${vmid}/power/suspend`, `Are you sure you want to suspend ${vmname}?`, "Suspend", `${vmname} is now suspending!`, `Unable to suspend ${vmname}. Please try again later.`, `/vm/${vmid}`) }); $("#start-vm").click(function(){ diff --git a/proxstar/tasks.py b/proxstar/tasks.py index f9f090e..5098d3d 100644 --- a/proxstar/tasks.py +++ b/proxstar/tasks.py @@ -93,11 +93,10 @@ def process_expiring_vms_task(): expiring_vms.append([vm.id, vm.name, days]) if days <= 0: expired_vms.append([vm.id, vm.name, days]) - if days <= 0: vm.stop() - elif days == -7: + elif days <= -7: print( - "Deleting {} ({}) as it has been a week since expiration.". + "Deleting {} ({}) as it has been at least a week since expiration.". format(vm.name, vm.id)) send_stop_ssh_tunnel(vm.id) delete_vm_task(vm.id) diff --git a/proxstar/templates/base.html b/proxstar/templates/base.html index 6795820..bc59090 100644 --- a/proxstar/templates/base.html +++ b/proxstar/templates/base.html @@ -21,7 +21,7 @@