]> git.proxmox.com Git - mirror_novnc.git/blobdiff - vnc_auto.html
Clean up Util
[mirror_novnc.git] / vnc_auto.html
index 9fd2272a38610ce8a0ba438610244a5c19fc5057..2bb9013be81c142d37e32e7fdd306350e7872adb 100644 (file)
@@ -11,6 +11,8 @@
 
     Connect parameters are provided in query string:
         http://example.com/?host=HOST&port=PORT&encrypt=1&true_color=1
+    or the fragment:
+        http://example.com/#host=HOST&port=PORT&encrypt=1&true_color=1
     -->
     <title>noVNC</title>
 
     <meta name="apple-mobile-web-app-capable" content="yes" />
     <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
     <!-- App Start Icon  -->
-    <link rel="apple-touch-startup-image" href="images/screen_320x460.png" />
+    <link rel="apple-touch-startup-image" href="app/images/screen_320x460.png" />
     <!-- For iOS devices set the icon to use if user bookmarks app on their homescreen -->
-    <link rel="apple-touch-icon" href="images/screen_57x57.png">
+    <link rel="apple-touch-icon" href="app/images/screen_57x57.png">
     <!--
-    <link rel="apple-touch-icon-precomposed" href="images/screen_57x57.png" />
+    <link rel="apple-touch-icon-precomposed" href="app/images/screen_57x57.png" />
     -->
 
 
     <!-- Stylesheets -->
-    <link rel="stylesheet" href="include/base.css" title="plain">
+    <link rel="stylesheet" href="app/styles/base.css" title="plain">
 
      <!--
     <script type='text/javascript'
         src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
     -->
-        <script src="include/util.js"></script>
+        <script src="core/util.js"></script>
+        <script src="app/webutil.js"></script>
 </head>
 
 <body style="margin: 0px;">
-    <div id="noVNC_screen">
+    <div id="noVNC_container">
             <div id="noVNC_status_bar" class="noVNC_status_bar" style="margin-top: 0px;">
                 <table border=0 width="100%"><tr>
                     <td><div id="noVNC_status" style="position: relative; height: auto;">
         "use strict";
 
         // Load supporting scripts
-        Util.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js",
-                           "keysymdef.js", "keyboard.js", "input.js", "display.js",
-                           "jsunzip.js", "rfb.js", "keysym.js"]);
+        WebUtil.load_scripts({
+            'core': ["base64.js", "websock.js", "des.js", "keysymdef.js",
+                     "xtscancodes.js", "keyboard.js", "input.js", "display.js",
+                     "inflator.js", "rfb.js", "keysym.js"],
+            'app': ["webutil.js"]});
 
         var rfb;
         var resizeTimeout;
 
 
         function UIresize() {
-            if (WebUtil.getQueryVar('resize', false)) {
+            if (WebUtil.getConfigVar('resize', false)) {
                 var innerW = window.innerWidth;
                 var innerH = window.innerHeight;
-                var controlbarH = $D('noVNC_status_bar').offsetHeight;
+                var controlbarH = document.getElementById('noVNC_status_bar').offsetHeight;
                 var padding = 5;
                 if (innerW !== undefined && innerH !== undefined)
-                    rfb.setDesktopSize(innerW, innerH - controlbarH - padding);
+                    rfb.requestDesktopSize(innerW, innerH - controlbarH - padding);
             }
         }
         function FBUComplete(rfb, fbu) {
             msg += 'Password Required: ';
             msg += '<input type=password size=10 id="password_input" class="noVNC_status">';
             msg += '<\/form>';
-            $D('noVNC_status_bar').setAttribute("class", "noVNC_status_warn");
-            $D('noVNC_status').innerHTML = msg;
+            document.getElementById('noVNC_status_bar').setAttribute("class", "noVNC_status_warn");
+            document.getElementById('noVNC_status').innerHTML = msg;
         }
         function setPassword() {
-            rfb.sendPassword($D('password_input').value);
+            rfb.sendPassword(document.getElementById('password_input').value);
             return false;
         }
         function sendCtrlAltDel() {
         }
         function updateState(rfb, state, oldstate, msg) {
             var s, sb, cad, level;
-            s = $D('noVNC_status');
-            sb = $D('noVNC_status_bar');
-            cad = $D('sendCtrlAltDelButton');
+            s = document.getElementById('noVNC_status');
+            sb = document.getElementById('noVNC_status_bar');
+            cad = document.getElementById('sendCtrlAltDelButton');
             switch (state) {
                 case 'failed':       level = "error";  break;
                 case 'fatal':        level = "error";  break;
 
         function xvpInit(ver) {
             var xvpbuttons;
-            xvpbuttons = $D('noVNC_xvp_buttons');
+            xvpbuttons = document.getElementById('noVNC_xvp_buttons');
             if (ver >= 1) {
                 xvpbuttons.style.display = 'inline';
             } else {
         window.onscriptsload = function () {
             var host, port, password, path, token;
 
-            $D('sendCtrlAltDelButton').style.display = "inline";
-            $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
-            $D('xvpShutdownButton').onclick = xvpShutdown;
-            $D('xvpRebootButton').onclick = xvpReboot;
-            $D('xvpResetButton').onclick = xvpReset;
+            document.getElementById('sendCtrlAltDelButton').style.display = "inline";
+            document.getElementById('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
+            document.getElementById('xvpShutdownButton').onclick = xvpShutdown;
+            document.getElementById('xvpRebootButton').onclick = xvpReboot;
+            document.getElementById('xvpResetButton').onclick = xvpReset;
 
-            WebUtil.init_logging(WebUtil.getQueryVar('logging', 'warn'));
-            document.title = unescape(WebUtil.getQueryVar('title', 'noVNC'));
+            WebUtil.init_logging(WebUtil.getConfigVar('logging', 'warn'));
+            document.title = unescape(WebUtil.getConfigVar('title', 'noVNC'));
             // By default, use the host and port of server that served this file
-            host = WebUtil.getQueryVar('host', window.location.hostname);
-            port = WebUtil.getQueryVar('port', window.location.port);
+            host = WebUtil.getConfigVar('host', window.location.hostname);
+            port = WebUtil.getConfigVar('port', window.location.port);
 
             // if port == 80 (or 443) then it won't be present and should be
             // set manually
                 }
             }
 
+            password = WebUtil.getConfigVar('password', '');
+            path = WebUtil.getConfigVar('path', 'websockify');
+
             // If a token variable is passed in, set the parameter in a cookie.
             // This is used by nova-novncproxy.
-            token = WebUtil.getQueryVar('token', null);
+            token = WebUtil.getConfigVar('token', null);
             if (token) {
+
+                // if token is already present in the path we should use it
+                path = WebUtil.injectParamIfMissing(path, "token", token);
+
                 WebUtil.createCookie('token', token, 1)
             }
 
-            password = WebUtil.getQueryVar('password', '');
-            path = WebUtil.getQueryVar('path', 'websockify');
-
             if ((!host) || (!port)) {
-                updateState('failed',
-                    "Must specify host and port in URL");
+                updateState(null, 'fatal', null, 'Must specify host and port in URL');
                 return;
             }
 
-            rfb = new RFB({'target':       $D('noVNC_canvas'),
-                           'encrypt':      WebUtil.getQueryVar('encrypt',
-                                    (window.location.protocol === "https:")),
-                           'repeaterID':   WebUtil.getQueryVar('repeaterID', ''),
-                           'true_color':   WebUtil.getQueryVar('true_color', true),
-                           'local_cursor': WebUtil.getQueryVar('cursor', true),
-                           'shared':       WebUtil.getQueryVar('shared', true),
-                           'view_only':    WebUtil.getQueryVar('view_only', false),
-                           'onUpdateState':  updateState,
-                           'onXvpInit':    xvpInit,
-                           'onPasswordRequired':  passwordRequired,
-                           'onFBUComplete': FBUComplete});
+            try {
+                rfb = new RFB({'target':       document.getElementById('noVNC_canvas'),
+                               'encrypt':      WebUtil.getConfigVar('encrypt',
+                                        (window.location.protocol === "https:")),
+                               'repeaterID':   WebUtil.getConfigVar('repeaterID', ''),
+                               'true_color':   WebUtil.getConfigVar('true_color', true),
+                               'local_cursor': WebUtil.getConfigVar('cursor', true),
+                               'shared':       WebUtil.getConfigVar('shared', true),
+                               'view_only':    WebUtil.getConfigVar('view_only', false),
+                               'onUpdateState':  updateState,
+                               'onXvpInit':    xvpInit,
+                               'onPasswordRequired':  passwordRequired,
+                               'onFBUComplete': FBUComplete});
+            } catch (exc) {
+                updateState(null, 'fatal', null, 'Unable to create RFB client -- ' + exc);
+                return; // don't continue trying to connect
+            }
+
             rfb.connect(host, port, password, path);
         };
         </script>