Drop privileges in VNC proxy if requested
[invirt/packages/invirt-web.git] / code / main.py
index 6587484..dec53d6 100755 (executable)
@@ -320,7 +320,18 @@ console will suffer artifacts.
         @cherrypy.expose
         @cherrypy.tools.mako(filename="/vnc.mako")
         def vnc(self, machine_id):
-            """VNC applet page.
+            """VNC applet page"""
+            return self._vnc(machine_id)
+
+        @cherrypy.expose
+        @cherrypy.tools.response_headers(headers=[('Content-Disposition', 'attachment; filename=vnc.jnlp')])
+        @cherrypy.tools.mako(filename="/vnc_jnlp.mako", content_type="application/x-java-jnlp-file")
+        def vnc_jnlp(self, machine_id):
+            """VNC applet exposed as a Java Web Start app (JNLP file)"""
+            return self._vnc(machine_id)
+
+        def _vnc(self, machine_id):
+            """VNC applet page functionality.
 
             Note that due to same-domain restrictions, the applet connects to
             the webserver, which needs to forward those requests to the xen
@@ -345,7 +356,7 @@ console will suffer artifacts.
             token = controls.vnctoken(machine)
             host = controls.listHost(machine)
             if host:
-                port = 10003 + [h.hostname for h in config.hosts].index(host)
+                port = config.vnc.base_port + [h.hostname for h in config.hosts].index(host)
             else:
                 port = 5900 # dummy
 
@@ -361,6 +372,31 @@ console will suffer artifacts.
             return d
 
         @cherrypy.expose
+        @cherrypy.tools.mako(filename="/novnc.mako")
+        def novnc(self, machine_id):
+            """NoVNC page functionality.
+
+            You need to set config.vnc.novnc_port and run the NoVNC proxy on
+            the web server.
+            """
+            machine = validation.Validate(cherrypy.request.login,
+                                          cherrypy.request.state,
+                                          machine_id=machine_id).machine
+            token = controls.vnctoken(machine)
+            host = controls.listHost(machine)
+
+            status = controls.statusInfo(machine)
+            has_vnc = hasVnc(status)
+
+            d = dict(on=status,
+                     has_vnc=has_vnc,
+                     machine=machine,
+                     hostname=cherrypy.request.local.name,
+                     vnc_host=host,
+                     authtoken=token)
+            return d
+
+        @cherrypy.expose
         @cherrypy.tools.mako(filename="/command.mako")
         @cherrypy.tools.require_POST()
         def command(self, command_name, machine_id, **kwargs):