mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
fix all rtp/perms checks, add db parameter to necessary functions
This commit is contained in:
parent
9405d5b6cc
commit
59836baf74
1 changed files with 18 additions and 19 deletions
|
@ -110,8 +110,7 @@ def vm_details(vmid):
|
||||||
rtp = 'rtp' in session['userinfo']['groups']
|
rtp = 'rtp' in session['userinfo']['groups']
|
||||||
active = 'active' in session['userinfo']['groups']
|
active = 'active' in session['userinfo']['groups']
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if 'rtp' in session['userinfo']['groups'] or int(
|
if rtp or int(vmid) in get_user_allowed_vms(proxmox, user):
|
||||||
vmid) in get_user_allowed_vms(proxmox, user):
|
|
||||||
vm = get_vm(proxmox, vmid)
|
vm = get_vm(proxmox, vmid)
|
||||||
vm['vmid'] = vmid
|
vm['vmid'] = vmid
|
||||||
vm['config'] = get_vm_config(proxmox, vmid)
|
vm['config'] = get_vm_config(proxmox, vmid)
|
||||||
|
@ -147,9 +146,9 @@ def vm_details(vmid):
|
||||||
@auth.oidc_auth
|
@auth.oidc_auth
|
||||||
def vm_power(vmid, action):
|
def vm_power(vmid, action):
|
||||||
user = session['userinfo']['preferred_username']
|
user = session['userinfo']['preferred_username']
|
||||||
|
rtp = 'rtp' in session['userinfo']['groups']
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if int(vmid) in get_user_allowed_vms(
|
if rtp or int(vmid) in get_user_allowed_vms(proxmox, user):
|
||||||
proxmox, user) or 'rtp' in session['userinfo']['groups']:
|
|
||||||
if action == 'start':
|
if action == 'start':
|
||||||
config = get_vm_config(proxmox, vmid)
|
config = get_vm_config(proxmox, vmid)
|
||||||
usage_check = check_user_usage(proxmox, db, user, config['cores'],
|
usage_check = check_user_usage(proxmox, db, user, config['cores'],
|
||||||
|
@ -166,17 +165,17 @@ def vm_power(vmid, action):
|
||||||
@auth.oidc_auth
|
@auth.oidc_auth
|
||||||
def vm_cpu(vmid, cores):
|
def vm_cpu(vmid, cores):
|
||||||
user = session['userinfo']['preferred_username']
|
user = session['userinfo']['preferred_username']
|
||||||
|
rtp = 'rtp' in session['userinfo']['groups']
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if int(vmid) in get_user_allowed_vms(
|
if rtp or int(vmid) in get_user_allowed_vms(proxmox, user):
|
||||||
proxmox, user) or 'rtp' in session['userinfo']['groups']:
|
|
||||||
cur_cores = get_vm_config(proxmox, vmid)['cores']
|
cur_cores = get_vm_config(proxmox, vmid)['cores']
|
||||||
if cores >= cur_cores:
|
if cores >= cur_cores:
|
||||||
status = get_vm(proxmox, vmid)['qmpstatus']
|
status = get_vm(proxmox, vmid)['qmpstatus']
|
||||||
if status == 'running' or status == 'paused':
|
if status == 'running' or status == 'paused':
|
||||||
usage_check = check_user_usage(proxmox, user,
|
usage_check = check_user_usage(proxmox, db, user,
|
||||||
cores - cur_cores, 0, 0)
|
cores - cur_cores, 0, 0)
|
||||||
else:
|
else:
|
||||||
usage_check = check_user_usage(proxmox, user, cores, 0, 0)
|
usage_check = check_user_usage(proxmox, db, user, cores, 0, 0)
|
||||||
if usage_check:
|
if usage_check:
|
||||||
return usage_check
|
return usage_check
|
||||||
change_vm_cpu(proxmox, vmid, cores)
|
change_vm_cpu(proxmox, vmid, cores)
|
||||||
|
@ -189,17 +188,17 @@ def vm_cpu(vmid, cores):
|
||||||
@auth.oidc_auth
|
@auth.oidc_auth
|
||||||
def vm_mem(vmid, mem):
|
def vm_mem(vmid, mem):
|
||||||
user = session['userinfo']['preferred_username']
|
user = session['userinfo']['preferred_username']
|
||||||
|
rtp = 'rtp' in session['userinfo']['groups']
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if 'rtp' in session['userinfo']['groups'] or int(
|
if rtp or int(vmid) in get_user_allowed_vms(proxmox, user):
|
||||||
vmid) in get_user_allowed_vms(proxmox, user):
|
|
||||||
cur_mem = get_vm_config(proxmox, vmid)['memory'] // 1024
|
cur_mem = get_vm_config(proxmox, vmid)['memory'] // 1024
|
||||||
if mem >= cur_mem:
|
if mem >= cur_mem:
|
||||||
status = get_vm(proxmox, vmid)['qmpstatus']
|
status = get_vm(proxmox, vmid)['qmpstatus']
|
||||||
if status == 'running' or status == 'paused':
|
if status == 'running' or status == 'paused':
|
||||||
usage_check = check_user_usage(proxmox, user, 0, mem - cur_mem,
|
usage_check = check_user_usage(proxmox, db, user, 0,
|
||||||
0)
|
mem - cur_mem, 0)
|
||||||
else:
|
else:
|
||||||
usage_check = check_user_usage(proxmox, user, 0, mem, 0)
|
usage_check = check_user_usage(proxmox, db, user, 0, mem, 0)
|
||||||
if usage_check:
|
if usage_check:
|
||||||
return usage_check
|
return usage_check
|
||||||
change_vm_mem(proxmox, vmid, mem * 1024)
|
change_vm_mem(proxmox, vmid, mem * 1024)
|
||||||
|
@ -212,9 +211,9 @@ def vm_mem(vmid, mem):
|
||||||
@auth.oidc_auth
|
@auth.oidc_auth
|
||||||
def vm_renew(vmid):
|
def vm_renew(vmid):
|
||||||
user = session['userinfo']['preferred_username']
|
user = session['userinfo']['preferred_username']
|
||||||
|
rtp = 'rtp' in session['userinfo']['groups']
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if 'rtp' in session['userinfo']['groups'] or int(
|
if rtp or int(vmid) in get_user_allowed_vms(proxmox, user):
|
||||||
vmid) in get_user_allowed_vms(proxmox, user):
|
|
||||||
renew_vm_expire(db, vmid, app.config['VM_EXPIRE_MONTHS'])
|
renew_vm_expire(db, vmid, app.config['VM_EXPIRE_MONTHS'])
|
||||||
for interface in get_vm_interfaces(proxmox, vmid):
|
for interface in get_vm_interfaces(proxmox, vmid):
|
||||||
renew_ip(starrs, get_ip_for_mac(starrs, interface[1]))
|
renew_ip(starrs, get_ip_for_mac(starrs, interface[1]))
|
||||||
|
@ -227,9 +226,9 @@ def vm_renew(vmid):
|
||||||
@auth.oidc_auth
|
@auth.oidc_auth
|
||||||
def iso_eject(vmid):
|
def iso_eject(vmid):
|
||||||
user = session['userinfo']['preferred_username']
|
user = session['userinfo']['preferred_username']
|
||||||
|
rtp = 'rtp' in session['userinfo']['groups']
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if int(vmid) in get_user_allowed_vms(
|
if rtp or int(vmid) in get_user_allowed_vms(proxmox, user):
|
||||||
proxmox, user) or 'rtp' in session['userinfo']['groups']:
|
|
||||||
eject_vm_iso(proxmox, vmid)
|
eject_vm_iso(proxmox, vmid)
|
||||||
return '', 200
|
return '', 200
|
||||||
else:
|
else:
|
||||||
|
@ -240,9 +239,9 @@ def iso_eject(vmid):
|
||||||
@auth.oidc_auth
|
@auth.oidc_auth
|
||||||
def iso_mount(vmid, iso):
|
def iso_mount(vmid, iso):
|
||||||
user = session['userinfo']['preferred_username']
|
user = session['userinfo']['preferred_username']
|
||||||
|
rtp = 'rtp' in session['userinfo']['groups']
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
if int(vmid) in get_user_allowed_vms(
|
if rtp or int(vmid) in get_user_allowed_vms(proxmox, user):
|
||||||
proxmox, user) or 'rtp' in session['userinfo']['groups']:
|
|
||||||
iso = "{}:iso/{}".format(app.config['PROXMOX_ISO_STORAGE'], iso)
|
iso = "{}:iso/{}".format(app.config['PROXMOX_ISO_STORAGE'], iso)
|
||||||
mount_vm_iso(proxmox, vmid, iso)
|
mount_vm_iso(proxmox, vmid, iso)
|
||||||
return '', 200
|
return '', 200
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue