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_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;">
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",
"keyboard.js",
"input.js",
"display.js",
82 "inflator.js",
"rfb.js",
"keysym.js"]);
89 if (WebUtil.getConfigVar('resize', false)) {
90 var innerW = window.innerWidth;
91 var innerH = window.innerHeight;
92 var controlbarH = $D('noVNC_status_bar').offsetHeight;
94 if (innerW !== undefined && innerH !== undefined)
95 rfb.requestDesktopSize(innerW, innerH - controlbarH - padding);
98 function FBUComplete(rfb, fbu) {
100 rfb.set_onFBUComplete(function() { });
102 function passwordRequired(rfb) {
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">';
109 $D('noVNC_status_bar').setAttribute(
"class",
"noVNC_status_warn");
110 $D('noVNC_status').innerHTML = msg;
112 function setPassword() {
113 rfb.sendPassword($D('password_input').value);
116 function sendCtrlAltDel() {
117 rfb.sendCtrlAltDel();
120 function xvpShutdown() {
124 function xvpReboot() {
128 function xvpReset() {
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');
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;
146 if (state ===
"normal") {
147 cad.disabled = false;
153 if (typeof(msg) !== 'undefined') {
154 sb.setAttribute(
"class",
"noVNC_status_" + level);
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(){
169 function xvpInit(ver) {
171 xvpbuttons = $D('noVNC_xvp_buttons');
173 xvpbuttons.style.display = 'inline';
175 xvpbuttons.style.display = 'none';
179 window.onscriptsload = function () {
180 var host, port, password, path, token;
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;
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);
194 // if port ==
80 (or
443) then it won't be present and should be
197 if (window.location.protocol.substring(
0,
5) == 'https') {
200 else if (window.location.protocol.substring(
0,
4) == 'http') {
205 password = WebUtil.getConfigVar('password', '');
206 path = WebUtil.getConfigVar('path', 'websockify');
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);
213 // if token is already present in the path we should use it
214 path = WebUtil.injectParamIfMissing(path,
"token", token);
216 WebUtil.createCookie('token', token,
1)
219 if ((!host) || (!port)) {
220 updateState(null, 'fatal', null, 'Must specify host and port in URL');
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});
238 updateState(null, 'fatal', null, 'Unable to create RFB client -- ' + exc);
239 return; // don't continue trying to connect
242 rfb.connect(host, port, password, path);