Skip to content

Commit

Permalink
added input valadation
Browse files Browse the repository at this point in the history
  • Loading branch information
nogoodidea committed Feb 27, 2024
1 parent 2b9d327 commit d814663
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 8 additions & 1 deletion proxstar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ def vm_renew(vmid):
@app.route('/vm/<string:vmid>/disk/create/<int:size>', methods=['POST'])
@auth.oidc_auth
def create_disk(vmid, size):
if(size =< 0):## are they trying to disk with zero size
return '', 400
user = User(session['userinfo']['preferred_username'])
connect_proxmox()
if user.rtp or int(vmid) in user.allowed_vms:
Expand Down Expand Up @@ -589,8 +591,13 @@ def create():
name = request.form['name'].lower()
cores = request.form['cores']
memory = request.form['mem']
template = request.form['template']
disk = request.form['disk']
## CHECK STUFF DEAR GOD
if(int(cores) <= 0 or int(memory) <= 0 or int(disk) <= 0){
return 'VM creation with cores and/or mem and/or disk values that are less than 0' 400
}

template = request.form['template']
iso = request.form['iso']
ssh_key = request.form['ssh_key']
if iso != 'none':
Expand Down
11 changes: 10 additions & 1 deletion proxstar/static/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,21 @@ $("#create-vm").click(function(){
if (name && disk) {
if (template != 'none' && !ssh_regex.test(ssh_key)) {
swal("Uh oh...", "Invalid SSH key!", "error");
// MAXIMUM BOUNDS CHECK
} else if (disk > max_disk) {
swal("Uh oh...", `You do not have enough disk resources available! Please lower the VM disk size to ${max_disk}GB or lower.`, "error");
} else if (template != 'none' && cores > max_cpu) {
swal("Uh oh...", `You do not have enough CPU resources available! Please lower the VM cores to ${max_cpu} or lower.`, "error");
} else if (template != 'none' && mem/1024 > max_mem) {
swal("Uh oh...", `You do not have enough memory resources available! Please lower the VM memory to ${max_mem}GB or lower.`, "error");
// MINIMUM BOUNDS CHECK
else if(0 <= disk){
swal("Uh oh...", `Selected disk size is less than 0.`,"error");
}else if(0 <= cores){
swal("Uh oh...", `Selected cores amount is less than 0.`,"error");
}else if(0 <= mem){
swal("Uh oh...", `Selected memory size is less than 0.`,"error");
}
} else {
fetch(`/hostname/${name}`, {
credentials: 'same-origin',
Expand Down Expand Up @@ -1155,4 +1164,4 @@ $(".delete-disk").click(function(){
const vmid = $(this).data('vmid')
const disk = $(this).data('disk')
confirmDialog(`/vm/${vmid}/disk/${disk}/delete`, `Are you sure you want to delete ${disk}?`, "Delete", `Deleting ${disk}!`, `Unable to delete disk. Please try again later.`, `/vm/${vmid}`, true)
});
});

0 comments on commit d814663

Please sign in to comment.