From 589265028523993b0da60ca80553e4d7360a89fd Mon Sep 17 00:00:00 2001 From: Jiri Kalvoda <jirikalvoda@kam.mff.cuni.cz> Date: Mon, 25 Sep 2023 09:59:43 +0200 Subject: [PATCH] vnc default configuration --- vm.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/vm.py b/vm.py index d569aed..6e127bf 100755 --- a/vm.py +++ b/vm.py @@ -459,20 +459,25 @@ def sshfs_clean(): def escape_sh(*arg): return " ".join("'" + s.replace("'", "'\"'\"'") + "'" for s in arg) + +def get_vnc_client_env(vm): + vnc_client_env = os.environ.copy() + vnc_client_env["VNC_PASSWORD"] = open(vm_dir(vm)+"vnc_passwd", "r").read().strip() + return vnc_client_env + +vncviewer_args = ["-FullscreenSystemKeys=0", "-AcceptClipboard=0", "-SendClipboard=0"] + @cmd def vncapp(vm: str, cmd: str, user: str = "u"): import random import psutil unit_id = random.randint(100000, 999999) vm, user = extended_name(vm, user=user) - vm = name_to_id(vm) display_id=random.randint(10, 50) vnc_server = subprocess.Popen(ssh_args(vm, f"systemd-run --unit vncapp-vnc-{display_id}-{unit_id} --user -P bash -c '(cat /vnc_passwd;echo; cat /vnc_passwd; echo;echo n) | vncpasswd; vncserver :{display_id}'", user=user)) time.sleep(1) - vnc_client_env = os.environ.copy() - vnc_client_env["VNC_PASSWORD"] = open(vm_dir(vm)+"vnc_passwd", "r").read().strip() app = subprocess.Popen(ssh_args(vm, f"systemd-run --unit vncapp-app-{display_id}-{unit_id} --user -P -E DISPLAY=:{display_id} bash -c {escape_sh(cmd)}", user=user)); - vnc_client = subprocess.Popen(["vncviewer", get_ip(vm)+f":{display_id}"], env=vnc_client_env) + vnc_client = subprocess.Popen(["vncviewer", get_ip(vm)+f":{display_id}", *vncviewer_args], env=get_vnc_client_env(vm)) def on_terminate(proc): if verbose: print(f"KILLING ALL APPS because {proc} terminated") @@ -489,12 +494,9 @@ def vncsession(vm: str, display_id: int =0, user: str = "u"): import psutil unit_id = random.randint(100000, 999999) vm, user = extended_name(vm, user=user) - vm = name_to_id(vm) vnc_server = subprocess.Popen(ssh_args(vm, f"systemd-run --unit vncsession-{display_id}-{unit_id} --user -P bash -c '(cat /vnc_passwd;echo; cat /vnc_passwd; echo;echo n) | vncpasswd; vncserver :{display_id}'", user=user)) - vnc_client_env = os.environ.copy() - vnc_client_env["VNC_PASSWORD"] = open(vm_dir(vm)+"vnc_passwd", "r").read().strip() time.sleep(1) - vnc_client = subprocess.Popen(["vncviewer", get_ip(vm)+f":{display_id}"], env=vnc_client_env) + vnc_client = subprocess.Popen(["vncviewer", get_ip(vm)+f":{display_id}", *vncviewer_args], env=get_vnc_client_env(vm)) def on_terminate(proc): if verbose: print("KILLING ALL APPS") -- GitLab