forked from jupyterhub/jupyter-remote-desktop-proxy
/
__init__.py
65 lines (56 loc) · 1.85 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import shlex
import tempfile
from shutil import which
HERE = os.path.dirname(os.path.abspath(__file__))
def setup_desktop():
# 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.
with open(vncserver) as vncserver_file:
is_tigervnc = "TigerVNC" in vncserver_file.read()
if is_tigervnc:
vnc_args = [vncserver, '-rfbunixpath', sockets_path]
socket_args = ['--unix-target', sockets_path]
else:
vnc_args = [vncserver]
socket_args = []
if not os.path.exists(os.path.expanduser('~/.vnc/xstartup')):
vnc_args.extend(['-xstartup', os.path.join(HERE, 'share/xstartup')])
vnc_command = shlex.join(
vnc_args
+ [
'-verbose',
'-geometry',
'1680x1050',
'-SecurityTypes',
'None',
'-fg',
]
)
return {
'command': [
'websockify',
'-v',
'--web',
os.path.join(HERE, 'static'),
'--heartbeat',
'30',
'{port}',
]
+ socket_args
+ ['--', '/bin/sh', '-c', f'cd {os.getcwd()} && {vnc_command}'],
'timeout': 30,
'mappath': {'/': '/index.html'},
'new_browser_window': True,
}