Merge branch 'master' into apikey

This commit is contained in:
Joe Abbate 2022-10-20 00:24:42 -04:00 committed by GitHub
commit a11b7eefc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 22 deletions

View file

@ -331,17 +331,11 @@ def vm_power(vmid, action):
@auth.oidc_auth
def vm_console(vmid):
user = User(session['userinfo']['preferred_username'])
connect_proxmox()
proxmox = connect_proxmox()
if user.rtp or int(vmid) in user.allowed_vms:
# import pdb; pdb.set_trace()
vm = VM(vmid)
vnc_ticket, vnc_port = open_vnc_session(
vmid,
vm.node,
app.config['PROXMOX_USER'],
app.config['PROXMOX_TOKEN_NAME'],
app.config['PROXMOX_TOKEN_VALUE'],
)
vnc_ticket, vnc_port = open_vnc_session(vmid, vm.node, proxmox)
node = f'{vm.node}.csh.rit.edu'
token = add_vnc_target(node, vnc_port)
redis_conn.set(f'vnc_token|{vmid}', str(token)) # Store the VNC token in Redis.

View file

@ -3,7 +3,6 @@ import subprocess
import time
import urllib.parse
import requests
from flask import current_app as app
from proxstar import logging
@ -74,25 +73,15 @@ def delete_vnc_target(node=None, port=None, token=None):
raise LookupError('Target does not exist')
def open_vnc_session(vmid, node, proxmox_user, proxmox_token_name, proxmox_token_value):
def open_vnc_session(vmid, node, proxmox):
"""Pings the Proxmox API to request a VNC Proxy connection. Authenticates
against the API using a Uname/Token, gets a few tokens back, then uses those
tokens to open the VNC Proxy. Use these to connect to the VM's host with
websockify proxy.
Returns: Ticket to use as the noVNC password, and a port.
"""
# Get Proxmox API ticket and CSRF_Prevention_Token
# TODO (willnilges): Use Proxmoxer to get this information
# TODO (willnilges): Report errors
proxy_params = {'node': node, 'vmid': str(vmid), 'websocket': '1', 'generate-password': '0'}
vncproxy_response_data = requests.post(
f'https://{node}.csh.rit.edu:8006/api2/json/nodes/{node}/qemu/{vmid}/vncproxy',
verify=False,
timeout=5,
params=proxy_params,
headers={
'Authorization': f'PVEAPIToken={proxmox_user}!{proxmox_token_name}={proxmox_token_value}'
},
).json()['data']
params = {'websocket': '1', 'generate-password': '0'}
vncproxy_response_data = proxmox.nodes(node).qemu(str(vmid)).vncproxy.post(**params)
return urllib.parse.quote_plus(vncproxy_response_data['ticket']), vncproxy_response_data['port']