Skip to content
Snippets Groups Projects
Commit 58926502 authored by Jiří Kalvoda's avatar Jiří Kalvoda
Browse files

vnc default configuration

parent 2091ae7d
Branches
No related tags found
No related merge requests found
...@@ -459,20 +459,25 @@ def sshfs_clean(): ...@@ -459,20 +459,25 @@ def sshfs_clean():
def escape_sh(*arg): def escape_sh(*arg):
return " ".join("'" + s.replace("'", "'\"'\"'") + "'" for s in 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 @cmd
def vncapp(vm: str, cmd: str, user: str = "u"): def vncapp(vm: str, cmd: str, user: str = "u"):
import random import random
import psutil import psutil
unit_id = random.randint(100000, 999999) unit_id = random.randint(100000, 999999)
vm, user = extended_name(vm, user=user) vm, user = extended_name(vm, user=user)
vm = name_to_id(vm)
display_id=random.randint(10, 50) 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)) 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) 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)); 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): def on_terminate(proc):
if verbose: print(f"KILLING ALL APPS because {proc} terminated") 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"): ...@@ -489,12 +494,9 @@ def vncsession(vm: str, display_id: int =0, user: str = "u"):
import psutil import psutil
unit_id = random.randint(100000, 999999) unit_id = random.randint(100000, 999999)
vm, user = extended_name(vm, user=user) 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_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) 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): def on_terminate(proc):
if verbose: print("KILLING ALL APPS") if verbose: print("KILLING ALL APPS")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment