]> git.proxmox.com Git - mirror_novnc.git/blob - vnc_auto.html
Refactor dynamic script loading. Add util.js:load_scripts()
[mirror_novnc.git] / vnc_auto.html
1 <!DOCTYPE html>
2 <html>
3 <!--
4 noVNC example: simple example using default UI
5 Copyright (C) 2012 Joel Martin
6 noVNC is licensed under the MPL 2.0 (see LICENSE.txt)
7 This file is licensed under the 2-Clause BSD license (see LICENSE.txt).
8
9 Connect parameters are provided in query string:
10 http://example.com/?host=HOST&port=PORT&encrypt=1&true_color=1
11 -->
12 <head>
13 <title>noVNC</title>
14 <meta http-equiv="X-UA-Compatible" content="chrome=1">
15 <link rel="stylesheet" href="include/base.css" title="plain">
16 <!--
17 <script type='text/javascript'
18 src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
19 -->
20 <script src="include/util.js"></script>
21 </head>
22
23 <body style="margin: 0px;">
24 <div id="noVNC_screen">
25 <div id="noVNC_status_bar" class="noVNC_status_bar" style="margin-top: 0px;">
26 <table border=0 width="100%"><tr>
27 <td><div id="noVNC_status">Loading</div></td>
28 <td width="1%"><div id="noVNC_buttons">
29 <input type=button value="Send CtrlAltDel"
30 id="sendCtrlAltDelButton">
31 </div></td>
32 </tr></table>
33 </div>
34 <canvas id="noVNC_canvas" width="640px" height="20px">
35 Canvas not supported.
36 </canvas>
37 </div>
38
39 <script>
40 /*jslint white: false */
41 /*global window, $, Util, RFB, */
42 "use strict";
43
44 // Load supporting scripts
45 Util.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js",
46 "input.js", "display.js", "jsunzip.js", "rfb.js"]);
47
48 var rfb;
49
50 function passwordRequired(rfb) {
51 var msg;
52 msg = '<form onsubmit="return setPassword();"';
53 msg += ' style="margin-bottom: 0px">';
54 msg += 'Password Required: ';
55 msg += '<input type=password size=10 id="password_input" class="noVNC_status">';
56 msg += '<\/form>';
57 $D('noVNC_status_bar').setAttribute("class", "noVNC_status_warn");
58 $D('noVNC_status').innerHTML = msg;
59 }
60 function setPassword() {
61 rfb.sendPassword($D('password_input').value);
62 return false;
63 }
64 function sendCtrlAltDel() {
65 rfb.sendCtrlAltDel();
66 return false;
67 }
68 function updateState(rfb, state, oldstate, msg) {
69 var s, sb, cad, level;
70 s = $D('noVNC_status');
71 sb = $D('noVNC_status_bar');
72 cad = $D('sendCtrlAltDelButton');
73 switch (state) {
74 case 'failed': level = "error"; break;
75 case 'fatal': level = "error"; break;
76 case 'normal': level = "normal"; break;
77 case 'disconnected': level = "normal"; break;
78 case 'loaded': level = "normal"; break;
79 default: level = "warn"; break;
80 }
81
82 if (state === "normal") { cad.disabled = false; }
83 else { cad.disabled = true; }
84
85 if (typeof(msg) !== 'undefined') {
86 sb.setAttribute("class", "noVNC_status_" + level);
87 s.innerHTML = msg;
88 }
89 }
90
91 window.onscriptsload = function () {
92 var host, port, password, path, token;
93
94 $D('sendCtrlAltDelButton').style.display = "inline";
95 $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
96
97 WebUtil.init_logging(WebUtil.getQueryVar('logging', 'warn'));
98 document.title = unescape(WebUtil.getQueryVar('title', 'noVNC'));
99 // By default, use the host and port of server that served this file
100 host = WebUtil.getQueryVar('host', window.location.hostname);
101 port = WebUtil.getQueryVar('port', window.location.port);
102
103 // If a token variable is passed in, set the parameter in a cookie.
104 // This is used by nova-novncproxy.
105 token = WebUtil.getQueryVar('token', null);
106 if (token) {
107 WebUtil.createCookie('token', token, 1)
108 }
109
110 password = WebUtil.getQueryVar('password', '');
111 path = WebUtil.getQueryVar('path', 'websockify');
112
113 if ((!host) || (!port)) {
114 updateState('failed',
115 "Must specify host and port in URL");
116 return;
117 }
118
119 rfb = new RFB({'target': $D('noVNC_canvas'),
120 'encrypt': WebUtil.getQueryVar('encrypt',
121 (window.location.protocol === "https:")),
122 'repeaterID': WebUtil.getQueryVar('repeaterID', ''),
123 'true_color': WebUtil.getQueryVar('true_color', true),
124 'local_cursor': WebUtil.getQueryVar('cursor', true),
125 'shared': WebUtil.getQueryVar('shared', true),
126 'view_only': WebUtil.getQueryVar('view_only', false),
127 'updateState': updateState,
128 'onPasswordRequired': passwordRequired});
129 rfb.connect(host, port, password, path);
130 };
131 </script>
132
133 </body>
134 </html>
135