From bc7b52e5649d4ed064b18fdffa8d60f2aead9826 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Fri, 29 Mar 2024 23:59:13 +0100 Subject: [PATCH 1/4] refactor: adjust variable name for readability --- jupyter_remote_desktop_proxy/setup_websockify.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jupyter_remote_desktop_proxy/setup_websockify.py b/jupyter_remote_desktop_proxy/setup_websockify.py index 051110ce..f0e7df0e 100644 --- a/jupyter_remote_desktop_proxy/setup_websockify.py +++ b/jupyter_remote_desktop_proxy/setup_websockify.py @@ -34,11 +34,11 @@ def setup_websockify(): is_tigervnc = "tigervnc" in vncserver_file.read().casefold() if is_tigervnc: + websockify_args = ['--unix-target', sockets_path] vnc_args = [vncserver, '-rfbunixpath', sockets_path] - socket_args = ['--unix-target', sockets_path] else: + websockify_args = [] vnc_args = [vncserver, '-rfbport', '{port}'] - socket_args = [] if not os.path.exists(os.path.expanduser('~/.vnc/xstartup')): vnc_args.extend(['-xstartup', os.path.join(HERE, 'share/xstartup')]) @@ -63,7 +63,7 @@ def setup_websockify(): '30', '{port}', ] - + socket_args + + websockify_args + ['--', '/bin/sh', '-c', f'cd {os.getcwd()} && {vnc_command}'], 'timeout': 30, 'new_browser_window': True, From a27fde42d644f0efaa5ba2f98729b2e30443c317 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Sat, 30 Mar 2024 00:01:14 +0100 Subject: [PATCH 2/4] refactor: use long flag names --- jupyter_remote_desktop_proxy/setup_websockify.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/jupyter_remote_desktop_proxy/setup_websockify.py b/jupyter_remote_desktop_proxy/setup_websockify.py index f0e7df0e..fa6079d9 100644 --- a/jupyter_remote_desktop_proxy/setup_websockify.py +++ b/jupyter_remote_desktop_proxy/setup_websockify.py @@ -47,20 +47,19 @@ def setup_websockify(): vnc_args + [ '-verbose', + '-fg', '-geometry', '1680x1050', '-SecurityTypes', 'None', - '-fg', ] ) return { 'command': [ 'websockify', - '-v', - '--heartbeat', - '30', + '--verbose', + '--heartbeat=30', '{port}', ] + websockify_args From 4219727208f885e8cc3fd2443a9a0034c15b769c Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Sat, 30 Mar 2024 00:02:03 +0100 Subject: [PATCH 3/4] refactor: let turbovnc listen to localhost TigerVNC listens to localhost by default, and TurboVNC doesn't. Let's make them do the same. When websockify starts either TigerVNC or TurboVNC, it will listen only to localhost anyhow - so this doesn't change anything really but could reduce the complexity a bit when debugging these things, as I've done at length now. --- jupyter_remote_desktop_proxy/setup_websockify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyter_remote_desktop_proxy/setup_websockify.py b/jupyter_remote_desktop_proxy/setup_websockify.py index fa6079d9..51a77370 100644 --- a/jupyter_remote_desktop_proxy/setup_websockify.py +++ b/jupyter_remote_desktop_proxy/setup_websockify.py @@ -38,7 +38,7 @@ def setup_websockify(): vnc_args = [vncserver, '-rfbunixpath', sockets_path] else: websockify_args = [] - vnc_args = [vncserver, '-rfbport', '{port}'] + vnc_args = [vncserver, '-localhost', '-rfbport', '{port}'] if not os.path.exists(os.path.expanduser('~/.vnc/xstartup')): vnc_args.extend(['-xstartup', os.path.join(HERE, 'share/xstartup')]) From 7797912cc0d9728b5a24c3000eb7f5d8ccd20a7c Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Sat, 30 Mar 2024 07:02:56 +0100 Subject: [PATCH 4/4] refactor: co-locate code for tiger's unix socket initialization No change, just relocates code. --- jupyter_remote_desktop_proxy/setup_websockify.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/jupyter_remote_desktop_proxy/setup_websockify.py b/jupyter_remote_desktop_proxy/setup_websockify.py index 51a77370..7cdbd07b 100644 --- a/jupyter_remote_desktop_proxy/setup_websockify.py +++ b/jupyter_remote_desktop_proxy/setup_websockify.py @@ -7,18 +7,12 @@ def setup_websockify(): - # make a secure temporary directory for sockets - # This is only readable, writeable & searchable by our uid - sockets_dir = tempfile.mkdtemp() - sockets_path = os.path.join(sockets_dir, 'vnc-socket') vncserver = which('vncserver') - if not vncserver: raise RuntimeError( "vncserver executable not found, please install a VNC server" ) - # TigerVNC provides the option to connect a Unix socket. TurboVNC does not. # TurboVNC and TigerVNC share the same origin and both use a Perl script # as the executable vncserver. We can determine if vncserver is TigerVNC # by searching tigervnc string in the Perl script. @@ -34,6 +28,12 @@ def setup_websockify(): is_tigervnc = "tigervnc" in vncserver_file.read().casefold() if is_tigervnc: + # Make a secure temporary directory for sockets that is only readable, + # writeable, and searchable by our uid - TigerVNC can listen to a Unix + # socket! + sockets_dir = tempfile.mkdtemp() + sockets_path = os.path.join(sockets_dir, 'vnc-socket') + websockify_args = ['--unix-target', sockets_path] vnc_args = [vncserver, '-rfbunixpath', sockets_path] else: