]> git.proxmox.com Git - mirror_novnc.git/blob - vnc_auto.html
Pass token into the path variable
[mirror_novnc.git] / vnc_auto.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4
5 <!--
6 noVNC example: simple example using default UI
7 Copyright (C) 2012 Joel Martin
8 Copyright (C) 2013 Samuel Mannehed for Cendio AB
9 noVNC is licensed under the MPL 2.0 (see LICENSE.txt)
10 This file is licensed under the 2-Clause BSD license (see LICENSE.txt).
11
12 Connect parameters are provided in query string:
13 http://example.com/?host=HOST&port=PORT&encrypt=1&true_color=1
14 or the fragment:
15 http://example.com/#host=HOST&port=PORT&encrypt=1&true_color=1
16 -->
17 <title>noVNC</title>
18
19 <meta charset="utf-8">
20
21 <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
22 Remove this if you use the .htaccess -->
23 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
24
25 <!-- Apple iOS Safari settings -->
26 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
27 <meta name="apple-mobile-web-app-capable" content="yes" />
28 <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
29 <!-- App Start Icon -->
30 <link rel="apple-touch-startup-image" href="images/screen_320x460.png" />
31 <!-- For iOS devices set the icon to use if user bookmarks app on their homescreen -->
32 <link rel="apple-touch-icon" href="images/screen_57x57.png">
33 <!--
34 <link rel="apple-touch-icon-precomposed" href="images/screen_57x57.png" />
35 -->
36
37
38 <!-- Stylesheets -->
39 <link rel="stylesheet" href="include/base.css" title="plain">
40
41 <!--
42 <script type='text/javascript'
43 src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
44 -->
45 <script src="include/util.js"></script>
46 </head>
47
48 <body style="margin: 0px;">
49 <div id="noVNC_screen">
50 <div id="noVNC_status_bar" class="noVNC_status_bar" style="margin-top: 0px;">
51 <table border=0 width="100%"><tr>
52 <td><div id="noVNC_status" style="position: relative; height: auto;">
53 Loading
54 </div></td>
55 <td width="1%"><div id="noVNC_buttons">
56 <input type=button value="Send CtrlAltDel"
57 id="sendCtrlAltDelButton">
58 <span id="noVNC_xvp_buttons">
59 <input type=button value="Shutdown"
60 id="xvpShutdownButton">
61 <input type=button value="Reboot"
62 id="xvpRebootButton">
63 <input type=button value="Reset"
64 id="xvpResetButton">
65 </span>
66 </div></td>
67 </tr></table>
68 </div>
69 <canvas id="noVNC_canvas" width="640px" height="20px">
70 Canvas not supported.
71 </canvas>
72 </div>
73
74 <script>
75 /*jslint white: false */
76 /*global window, $, Util, RFB, */
77 "use strict";
78
79 // Load supporting scripts
80 Util.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js",
81 "keysymdef.js", "keyboard.js", "input.js", "display.js",
82 "inflator.js", "rfb.js", "keysym.js"]);
83
84 var rfb;
85 var resizeTimeout;
86
87
88 function UIresize() {
89 if (WebUtil.getConfigVar('resize', false)) {
90 var innerW = window.innerWidth;
91 var innerH = window.innerHeight;
92 var controlbarH = $D('noVNC_status_bar').offsetHeight;
93 var padding = 5;
94 if (innerW !== undefined && innerH !== undefined)
95 rfb.setDesktopSize(innerW, innerH - controlbarH - padding);
96 }
97 }
98 function FBUComplete(rfb, fbu) {
99 UIresize();
100 rfb.set_onFBUComplete(function() { });
101 }
102 function passwordRequired(rfb) {
103 var msg;
104 msg = '<form onsubmit="return setPassword();"';
105 msg += ' style="margin-bottom: 0px">';
106 msg += 'Password Required: ';
107 msg += '<input type=password size=10 id="password_input" class="noVNC_status">';
108 msg += '<\/form>';
109 $D('noVNC_status_bar').setAttribute("class", "noVNC_status_warn");
110 $D('noVNC_status').innerHTML = msg;
111 }
112 function setPassword() {
113 rfb.sendPassword($D('password_input').value);
114 return false;
115 }
116 function sendCtrlAltDel() {
117 rfb.sendCtrlAltDel();
118 return false;
119 }
120 function xvpShutdown() {
121 rfb.xvpShutdown();
122 return false;
123 }
124 function xvpReboot() {
125 rfb.xvpReboot();
126 return false;
127 }
128 function xvpReset() {
129 rfb.xvpReset();
130 return false;
131 }
132 function updateState(rfb, state, oldstate, msg) {
133 var s, sb, cad, level;
134 s = $D('noVNC_status');
135 sb = $D('noVNC_status_bar');
136 cad = $D('sendCtrlAltDelButton');
137 switch (state) {
138 case 'failed': level = "error"; break;
139 case 'fatal': level = "error"; break;
140 case 'normal': level = "normal"; break;
141 case 'disconnected': level = "normal"; break;
142 case 'loaded': level = "normal"; break;
143 default: level = "warn"; break;
144 }
145
146 if (state === "normal") {
147 cad.disabled = false;
148 } else {
149 cad.disabled = true;
150 xvpInit(0);
151 }
152
153 if (typeof(msg) !== 'undefined') {
154 sb.setAttribute("class", "noVNC_status_" + level);
155 s.innerHTML = msg;
156 }
157 }
158
159 window.onresize = function () {
160 // When the window has been resized, wait until the size remains
161 // the same for 0.5 seconds before sending the request for changing
162 // the resolution of the session
163 clearTimeout(resizeTimeout);
164 resizeTimeout = setTimeout(function(){
165 UIresize();
166 }, 500);
167 };
168
169 function xvpInit(ver) {
170 var xvpbuttons;
171 xvpbuttons = $D('noVNC_xvp_buttons');
172 if (ver >= 1) {
173 xvpbuttons.style.display = 'inline';
174 } else {
175 xvpbuttons.style.display = 'none';
176 }
177 }
178
179 window.onscriptsload = function () {
180 var host, port, password, path, token;
181
182 $D('sendCtrlAltDelButton').style.display = "inline";
183 $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
184 $D('xvpShutdownButton').onclick = xvpShutdown;
185 $D('xvpRebootButton').onclick = xvpReboot;
186 $D('xvpResetButton').onclick = xvpReset;
187
188 WebUtil.init_logging(WebUtil.getConfigVar('logging', 'warn'));
189 document.title = unescape(WebUtil.getConfigVar('title', 'noVNC'));
190 // By default, use the host and port of server that served this file
191 host = WebUtil.getConfigVar('host', window.location.hostname);
192 port = WebUtil.getConfigVar('port', window.location.port);
193
194 // if port == 80 (or 443) then it won't be present and should be
195 // set manually
196 if (!port) {
197 if (window.location.protocol.substring(0,5) == 'https') {
198 port = 443;
199 }
200 else if (window.location.protocol.substring(0,4) == 'http') {
201 port = 80;
202 }
203 }
204
205 password = WebUtil.getConfigVar('password', '');
206 path = WebUtil.getConfigVar('path', 'websockify');
207
208 // If a token variable is passed in, set the parameter in a cookie.
209 // This is used by nova-novncproxy.
210 token = WebUtil.getConfigVar('token', null);
211 if (token) {
212
213 // if token is already present in the path we should use it
214 path = WebUtil.injectParamIfMissing(path, "token", token);
215
216 WebUtil.createCookie('token', token, 1)
217 }
218
219 if ((!host) || (!port)) {
220 updateState(null, 'fatal', null, 'Must specify host and port in URL');
221 return;
222 }
223
224 try {
225 rfb = new RFB({'target': $D('noVNC_canvas'),
226 'encrypt': WebUtil.getConfigVar('encrypt',
227 (window.location.protocol === "https:")),
228 'repeaterID': WebUtil.getConfigVar('repeaterID', ''),
229 'true_color': WebUtil.getConfigVar('true_color', true),
230 'local_cursor': WebUtil.getConfigVar('cursor', true),
231 'shared': WebUtil.getConfigVar('shared', true),
232 'view_only': WebUtil.getConfigVar('view_only', false),
233 'onUpdateState': updateState,
234 'onXvpInit': xvpInit,
235 'onPasswordRequired': passwordRequired,
236 'onFBUComplete': FBUComplete});
237 } catch (exc) {
238 updateState(null, 'fatal', null, 'Unable to create RFB client -- ' + exc);
239 return; // don't continue trying to connect
240 }
241
242 rfb.connect(host, port, password, path);
243 };
244 </script>
245
246 </body>
247 </html>