mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
Joe figured it out
This commit is contained in:
parent
c1a14cd90e
commit
586536c708
6 changed files with 19 additions and 7 deletions
|
@ -9,5 +9,5 @@ COPY *.py .
|
|||
COPY proxstar ./proxstar
|
||||
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
|
||||
COPY HACKING/ssh_key proxmox_ssh_key
|
||||
ENTRYPOINT ddtrace-run python3 wsgi.py
|
||||
|
|
|
@ -64,6 +64,7 @@ REDIS_PORT = int(environ.get('PROXSTAR_REDIS_PORT', '6379'))
|
|||
# VNC
|
||||
WEBSOCKIFY_PATH = environ.get('PROXSTAR_WEBSOCKIFY_PATH', '/usr/local/bin/websockify')
|
||||
WEBSOCKIFY_TARGET_FILE = environ.get('PROXSTAR_WEBSOCKIFY_TARGET_FILE', '/opt/proxstar/targets')
|
||||
VNC_HOST = environ.get('PROXSTAR_VNC_HOST', 'proxmox-vnc.csh.rit.edu')
|
||||
|
||||
# SENTRY
|
||||
# If you set the sentry dsn locally, make sure you use the local-dev or some
|
||||
|
|
|
@ -16,6 +16,7 @@ timeout = app.config['TIMEOUT']
|
|||
def start_websockify(websockify_path, target_file):
|
||||
result = subprocess.run(['pgrep', 'websockify'], stdout=subprocess.PIPE)
|
||||
if not result.stdout:
|
||||
print("Websockify is stopped. Starting websockify.")
|
||||
subprocess.call(
|
||||
[
|
||||
websockify_path,
|
||||
|
@ -28,7 +29,10 @@ def start_websockify(websockify_path, target_file):
|
|||
],
|
||||
stdout=subprocess.PIPE,
|
||||
)
|
||||
else:
|
||||
print("Websockify started.")
|
||||
|
||||
|
||||
def on_starting(server):
|
||||
print("Starting Websockify...")
|
||||
start_websockify(app.config['WEBSOCKIFY_PATH'], app.config['WEBSOCKIFY_TARGET_FILE'])
|
||||
|
|
|
@ -6,6 +6,7 @@ import logging
|
|||
import subprocess
|
||||
import psutil
|
||||
import psycopg2
|
||||
from gunicorn_conf import start_websockify
|
||||
import rq_dashboard
|
||||
from rq import Queue
|
||||
from redis import Redis
|
||||
|
@ -60,6 +61,11 @@ app.config['GIT_REVISION'] = (
|
|||
subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8').rstrip()
|
||||
)
|
||||
|
||||
# Probably cursed.
|
||||
if 'localhost' in app.config['SERVER_NAME']:
|
||||
print("Server name is localhost. Starting websockify...")
|
||||
start_websockify(app.config['WEBSOCKIFY_PATH'], app.config['WEBSOCKIFY_TARGET_FILE'])
|
||||
|
||||
# Sentry setup
|
||||
sentry_sdk.init(
|
||||
dsn=app.config['SENTRY_DSN'],
|
||||
|
@ -289,7 +295,8 @@ def vm_console(vmid):
|
|||
vm.configure_vnc_in_vm_config(app.config['PROXMOX_SSH_USER'], app.config['PROXMOX_SSH_KEY_PASS'])
|
||||
ssh_tunnels.append(tunnel)
|
||||
# vm.start_vnc(port) # Broken :(
|
||||
return token, 200
|
||||
# return json.dumps([app.config['VNC_HOST'], token]), 200
|
||||
return {'host' : app.config['VNC_HOST'], 'token' : token}, 200
|
||||
else:
|
||||
return '', 403
|
||||
|
||||
|
|
|
@ -650,12 +650,11 @@ $("#console-vm").click(function(){
|
|||
credentials: 'same-origin',
|
||||
method: 'post'
|
||||
}).then((response) => {
|
||||
return response.text()
|
||||
}).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');
|
||||
return response.json()
|
||||
}).then((vnc_params) => {
|
||||
// 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');
|
||||
window.open(`/static/noVNC/vnc.html?autoconnect=true&password=${vmid}&host=${vnc_params.host}&port=8081&path=path?token=${vnc_params.token}`, '_blank');
|
||||
}).catch(err => {
|
||||
if (err) {
|
||||
swal("Uh oh...", `Unable to start console for ${vmname}. Please try again later.`, "error");
|
||||
|
|
|
@ -279,11 +279,12 @@ class VM:
|
|||
TODO (willnilges): Current password is "chomchom1", but should be changed lol
|
||||
"""
|
||||
# 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={self.id} -vnc 127.0.0.1:{int(self.id)+5900},password-secret=secvnc{self.id}'
|
||||
path = f'/etc/pve/local/qemu-server/{self.id}.conf'
|
||||
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.exec_command(f"if grep -- '{config}' {path}; then echo identical config found; else sed -i /dev/null '/-vnc/d' {path}") #YOLO
|
||||
ssh.exec_command(f"if grep -- '-vnc' {path}; then echo found config; else echo {config} >> {path}; fi")
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue