Oh my god I'm so close. I'm so close.

This commit is contained in:
Will Nilges 2022-07-07 00:23:35 -04:00
parent cb73b9ff40
commit c1a14cd90e
6 changed files with 17 additions and 20 deletions

View file

@ -8,4 +8,6 @@ COPY .git ./.git
COPY *.py . COPY *.py .
COPY proxstar ./proxstar COPY proxstar ./proxstar
RUN touch proxmox_ssh_key targets && chmod a+w proxmox_ssh_key targets # This is some OKD shit. RUN touch proxmox_ssh_key targets && chmod a+w proxmox_ssh_key targets # This is some OKD shit.
# This is so cringe, but it's for development. Comment this before pushing.
#COPY HACKING/ssh_key proxmox_ssh_key
ENTRYPOINT ddtrace-run python3 wsgi.py ENTRYPOINT ddtrace-run python3 wsgi.py

View file

@ -62,8 +62,8 @@ RQ_DASHBOARD_REDIS_HOST = environ.get('PROXSTAR_REDIS_HOST', 'localhost')
REDIS_PORT = int(environ.get('PROXSTAR_REDIS_PORT', '6379')) REDIS_PORT = int(environ.get('PROXSTAR_REDIS_PORT', '6379'))
# VNC # VNC
WEBSOCKIFY_PATH = environ.get('PROXSTAR_WEBSOCKIFY_PATH', '/opt/app-root/bin/websockify') WEBSOCKIFY_PATH = environ.get('PROXSTAR_WEBSOCKIFY_PATH', '/usr/local/bin/websockify')
WEBSOCKIFY_TARGET_FILE = environ.get('PROXSTAR_WEBSOCKIFY_TARGET_FILE', '/opt/app-root/src/targets') WEBSOCKIFY_TARGET_FILE = environ.get('PROXSTAR_WEBSOCKIFY_TARGET_FILE', '/opt/proxstar/targets')
# SENTRY # SENTRY
# If you set the sentry dsn locally, make sure you use the local-dev or some # If you set the sentry dsn locally, make sure you use the local-dev or some

View file

@ -67,8 +67,9 @@ sentry_sdk.init(
environment=app.config['SENTRY_ENV'], environment=app.config['SENTRY_ENV'],
) )
with open('proxmox_ssh_key', 'w') as ssh_key_file: if not os.path.exists('proxmox_ssh_key'):
ssh_key_file.write(app.config['PROXMOX_SSH_KEY']) with open('proxmox_ssh_key', 'w') as ssh_key_file:
ssh_key_file.write(app.config['PROXMOX_SSH_KEY'])
ssh_tunnels = [] ssh_tunnels = []
@ -277,6 +278,7 @@ def vm_console(vmid):
user = User(session['userinfo']['preferred_username']) user = User(session['userinfo']['preferred_username'])
connect_proxmox() connect_proxmox()
if user.rtp or int(vmid) in user.allowed_vms: if user.rtp or int(vmid) in user.allowed_vms:
# import pdb; pdb.set_trace()
vm = VM(vmid) vm = VM(vmid)
stop_ssh_tunnel(vm.id, ssh_tunnels) stop_ssh_tunnel(vm.id, ssh_tunnels)
port = str(5900 + int(vmid)) port = str(5900 + int(vmid))
@ -291,19 +293,6 @@ def vm_console(vmid):
else: else:
return '', 403 return '', 403
@app.route('/novnc')
def get_resource(): # pragma: no cover
mimetypes = {
".css": "text/css",
".html": "text/html",
".js": "application/javascript",
}
complete_path = os.path.join('/opt/proxstar/proxstar/', 'static/noVNC/vnc.html')
# ext = os.path.splitext(path)[1]
# mimetype = mimetypes.get(ext, "text/html")
content = open(complete_path).read()
return Response(content)
@app.route('/vm/<string:vmid>/cpu/<int:cores>', methods=['POST']) @app.route('/vm/<string:vmid>/cpu/<int:cores>', methods=['POST'])
@auth.oidc_auth @auth.oidc_auth
def vm_cpu(vmid, cores): def vm_cpu(vmid, cores):

View file

@ -652,7 +652,10 @@ $("#console-vm").click(function(){
}).then((response) => { }).then((response) => {
return response.text() return response.text()
}).then((token) => { }).then((token) => {
window.open(`/static/noVNC/vnc.html?autoconnect=true&encrypt=true&host=proxstar-vnc.csh.rit.edu&port=443&path=path?token=${token}`, '_blank'); // window.open(`/static/noVNC/vnc.html?autoconnect=true&encrypt=true&host=proxstar-vnc.csh.rit.edu&port=443&path=path?token=${token}`, '_blank');
// TODO (willnilges): encrypt=true
// TODO (willnilges): set host and port to an env variable
window.open(`/static/noVNC/vnc.html?autoconnect=true&host=freedom.csh.rit.edu&port=8081&path=path?token=${token}`, '_blank');
}).catch(err => { }).catch(err => {
if (err) { if (err) {
swal("Uh oh...", `Unable to start console for ${vmname}. Please try again later.`, "error"); swal("Uh oh...", `Unable to start console for ${vmname}. Please try again later.`, "error");

View file

@ -4,7 +4,7 @@ import urllib
from flask import current_app as app from flask import current_app as app
from tenacity import retry, stop_after_attempt, wait_fixed from tenacity import retry, stop_after_attempt, wait_fixed
from paramiko import SSHClient import paramiko
from proxstar import db, starrs from proxstar import db, starrs
from proxstar.db import delete_vm_expire, get_vm_expire from proxstar.db import delete_vm_expire, get_vm_expire
@ -281,7 +281,8 @@ class VM:
# proxmox = connect_proxmox() # proxmox = connect_proxmox()
config = f'args: -object secret,id=secvnc{self.id},data=chomchom1 -vnc 127.0.0.1:{int(self.id)+5900},password-secret=secvnc{self.id}' config = f'args: -object secret,id=secvnc{self.id},data=chomchom1 -vnc 127.0.0.1:{int(self.id)+5900},password-secret=secvnc{self.id}'
path = f'/etc/pve/local/qemu-server/{self.id}.conf' path = f'/etc/pve/local/qemu-server/{self.id}.conf'
with SSHClient() as ssh: with paramiko.SSHClient() as ssh:
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(self.node, port=22, username=ssh_user, key_filename='proxmox_ssh_key', passphrase=ssh_pass) ssh.connect(self.node, port=22, username=ssh_user, key_filename='proxmox_ssh_key', passphrase=ssh_pass)
ssh.exec_command(f"if grep -- '-vnc' {path}; then echo found config; else echo {config} >> {path}; fi") ssh.exec_command(f"if grep -- '-vnc' {path}; then echo found config; else echo {config} >> {path}; fi")

View file

@ -38,6 +38,7 @@ def get_vnc_targets():
def add_vnc_target(port): def add_vnc_target(port):
# TODO (willnilges): This doesn't throw an error if the target file is wrong.
targets = get_vnc_targets() targets = get_vnc_targets()
target = next((target for target in targets if target['port'] == port), None) target = next((target for target in targets if target['port'] == port), None)
if target: if target:
@ -66,6 +67,7 @@ def start_ssh_tunnel(node, port):
to the proxstar container to the proxstar container
""" """
port = int(port) port = int(port)
server = SSHTunnelForwarder( server = SSHTunnelForwarder(
node, node,
ssh_username=app.config['PROXMOX_SSH_USER'], ssh_username=app.config['PROXMOX_SSH_USER'],