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).
12 Connect parameters are provided in query string:
13 http://example.com/?host=HOST&port=PORT&encrypt=1&true_color=1
15 http://example.com/#host=HOST&port=PORT&encrypt=1&true_color=1
19 <meta charset=
"utf-8">
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">
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">
34 <link rel="apple-touch-icon-precomposed" href="images/screen_57x57.png" />
39 <link rel=
"stylesheet" href=
"include/base.css" title=
"plain">
42 <script type='text/javascript'
43 src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
45 <script src=
"include/util.js"></script>
48 <body style=
"margin: 0px;">
49 <div id=
"noVNC_container">
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;">
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"
63 <input type=button
value=
"Reset"
69 <canvas id=
"noVNC_canvas" width=
"640px" height=
"20px">
75 /*jslint white: false */
76 /*global window, $, Util, RFB, */
79 // Load supporting scripts
80 Util.load_scripts([
"webutil.js",
"base64.js",
"websock.js",
"des.js",
81 "keysymdef.js",
"xtscancodes.js",
"keyboard.js",
82 "input.js",
"display.js",
"inflator.js",
"rfb.js",
90 if (WebUtil.getConfigVar('resize', false)) {
91 var innerW = window.innerWidth;
92 var innerH = window.innerHeight;
93 var controlbarH = $D('noVNC_status_bar').offsetHeight;
95 if (innerW !== undefined && innerH !== undefined)
96 rfb.requestDesktopSize(innerW, innerH - controlbarH - padding);
99 function FBUComplete(rfb, fbu) {
101 rfb.set_onFBUComplete(function() { });
103 function passwordRequired(rfb) {
105 msg = '
<form onsubmit=
"return setPassword();"';
106 msg += '
style=
"margin-bottom: 0px">';
107 msg += 'Password Required: ';
108 msg += '
<input type=password size=
10 id=
"password_input" class=
"noVNC_status">';
110 $D('noVNC_status_bar').setAttribute(
"class",
"noVNC_status_warn");
111 $D('noVNC_status').innerHTML = msg;
113 function setPassword() {
114 rfb.sendPassword($D('password_input').value);
117 function sendCtrlAltDel() {
118 rfb.sendCtrlAltDel();
121 function xvpShutdown() {
125 function xvpReboot() {
129 function xvpReset() {
133 function updateState(rfb, state, oldstate, msg) {
134 var s, sb, cad, level;
135 s = $D('noVNC_status');
136 sb = $D('noVNC_status_bar');
137 cad = $D('sendCtrlAltDelButton');
139 case 'failed': level =
"error"; break;
140 case 'fatal': level =
"error"; break;
141 case 'normal': level =
"normal"; break;
142 case 'disconnected': level =
"normal"; break;
143 case 'loaded': level =
"normal"; break;
144 default: level =
"warn"; break;
147 if (state ===
"normal") {
148 cad.disabled = false;
154 if (typeof(msg) !== 'undefined') {
155 sb.setAttribute(
"class",
"noVNC_status_" + level);
160 window.onresize = function () {
161 // When the window has been resized, wait until the size remains
162 // the same for
0.5 seconds before sending the request for changing
163 // the resolution of the session
164 clearTimeout(resizeTimeout);
165 resizeTimeout = setTimeout(function(){
170 function xvpInit(ver) {
172 xvpbuttons = $D('noVNC_xvp_buttons');
174 xvpbuttons.style.display = 'inline';
176 xvpbuttons.style.display = 'none';
180 window.onscriptsload = function () {
181 var host, port, password, path, token;
183 $D('sendCtrlAltDelButton').style.display =
"inline";
184 $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
185 $D('xvpShutdownButton').onclick = xvpShutdown;
186 $D('xvpRebootButton').onclick = xvpReboot;
187 $D('xvpResetButton').onclick = xvpReset;
189 WebUtil.init_logging(WebUtil.getConfigVar('logging', 'warn'));
190 document.title = unescape(WebUtil.getConfigVar('title', 'noVNC'));
191 // By default, use the host and port of server that served this file
192 host = WebUtil.getConfigVar('host', window.location.hostname);
193 port = WebUtil.getConfigVar('port', window.location.port);
195 // if port ==
80 (or
443) then it won't be present and should be
198 if (window.location.protocol.substring(
0,
5) == 'https') {
201 else if (window.location.protocol.substring(
0,
4) == 'http') {
206 password = WebUtil.getConfigVar('password', '');
207 path = WebUtil.getConfigVar('path', 'websockify');
209 // If a token variable is passed in, set the parameter in a cookie.
210 // This is used by nova-novncproxy.
211 token = WebUtil.getConfigVar('token', null);
214 // if token is already present in the path we should use it
215 path = WebUtil.injectParamIfMissing(path,
"token", token);
217 WebUtil.createCookie('token', token,
1)
220 if ((!host) || (!port)) {
221 updateState(null, 'fatal', null, 'Must specify host and port in URL');
226 rfb = new RFB({'target': $D('noVNC_canvas'),
227 'encrypt': WebUtil.getConfigVar('encrypt',
228 (window.location.protocol ===
"https:")),
229 'repeaterID': WebUtil.getConfigVar('repeaterID', ''),
230 'true_color': WebUtil.getConfigVar('true_color', true),
231 'local_cursor': WebUtil.getConfigVar('cursor', true),
232 'shared': WebUtil.getConfigVar('shared', true),
233 'view_only': WebUtil.getConfigVar('view_only', false),
234 'onUpdateState': updateState,
235 'onXvpInit': xvpInit,
236 'onPasswordRequired': passwordRequired,
237 'onFBUComplete': FBUComplete});
239 updateState(null, 'fatal', null, 'Unable to create RFB client -- ' + exc);
240 return; // don't continue trying to connect
243 rfb.connect(host, port, password, path);