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=
"app/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=
"app/images/screen_57x57.png">
34 <link rel="apple-touch-icon-precomposed" href="app/images/screen_57x57.png" />
39 <link rel=
"stylesheet" href=
"app/styles/auto.css">
42 <script type='text/javascript'
43 src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
45 <script src=
"core/util.js"></script>
46 <script src=
"app/webutil.js"></script>
49 <body style=
"margin: 0px;">
50 <div id=
"noVNC_container">
51 <div id=
"noVNC_status_bar" class=
"noVNC_status_bar" style=
"margin-top: 0px;">
52 <table border=
0 width=
"100%"><tr>
53 <td><div id=
"noVNC_status" style=
"position: relative; height: auto;">
56 <td width=
"1%"><div id=
"noVNC_buttons">
57 <input type=button
value=
"Send CtrlAltDel"
58 id=
"sendCtrlAltDelButton">
59 <span id=
"noVNC_xvp_buttons">
60 <input type=button
value=
"Shutdown"
61 id=
"xvpShutdownButton">
62 <input type=button
value=
"Reboot"
64 <input type=button
value=
"Reset"
70 <canvas id=
"noVNC_canvas" width=
"640px" height=
"20px">
76 /*jslint white: false */
77 /*global window, $, Util, RFB, */
80 // Load supporting scripts
81 WebUtil.load_scripts({
82 'core': [
"base64.js",
"websock.js",
"des.js",
"input/keysymdef.js",
83 "input/xtscancodes.js",
"input/util.js",
"input/devices.js",
84 "display.js",
"inflator.js",
"rfb.js",
"input/keysym.js"],
85 'app': [WebUtil.getLanguageFileLocation(),
"webutil.js"]});
93 if (WebUtil.getConfigVar('resize', false)) {
94 var innerW = window.innerWidth;
95 var innerH = window.innerHeight;
96 var controlbarH = document.getElementById('noVNC_status_bar').offsetHeight;
97 if (innerW !== undefined && innerH !== undefined)
98 rfb.requestDesktopSize(innerW, innerH - controlbarH);
101 function FBUComplete(rfb, fbu) {
103 rfb.set_onFBUComplete(function() { });
105 function updateDesktopName(rfb, name) {
108 function passwordRequired(rfb, msg) {
109 if (typeof msg === 'undefined') {
110 msg = 'Password Required: ';
113 html = '
<form onsubmit=
"return setPassword();"';
114 html += '
style=
"margin-bottom: 0px">';
116 html += '
<input type=password size=
10 id=
"password_input" class=
"noVNC_status">';
118 status(html,
"warn");
120 function setPassword() {
121 rfb.sendPassword(document.getElementById('password_input').value);
124 function sendCtrlAltDel() {
125 rfb.sendCtrlAltDel();
128 function xvpShutdown() {
132 function xvpReboot() {
136 function xvpReset() {
140 function status(text, level) {
149 document.getElementById('noVNC_status_bar').setAttribute(
"class",
"noVNC_status_" + level);
150 document.getElementById('noVNC_status').innerHTML = text;
152 function updateState(rfb, state, oldstate) {
153 var cad = document.getElementById('sendCtrlAltDelButton');
156 status(Util.Localisation.get(
"Connecting"),
"normal");
159 if (rfb && rfb.get_encrypt()) {
160 status(Util.Localisation.
161 get(
"Connected (encrypted) to ") +
162 desktopName,
"normal");
164 status(Util.Localisation.
165 get(
"Connected (unencrypted) to ") +
166 desktopName,
"normal");
169 case 'disconnecting':
170 status(Util.Localisation.get(
"Disconnecting"),
"normal");
173 status(Util.Localisation.get(
"Disconnected"),
"normal");
176 status(state,
"warn");
180 if (state === 'connected') {
181 cad.disabled = false;
188 function disconnected(rfb, reason) {
189 if (typeof(reason) !== 'undefined') {
190 status(reason,
"error");
193 function notification(rfb, msg, level, options) {
197 window.onresize = function () {
198 // When the window has been resized, wait until the size remains
199 // the same for
0.5 seconds before sending the request for changing
200 // the resolution of the session
201 clearTimeout(resizeTimeout);
202 resizeTimeout = setTimeout(function(){
207 function xvpInit(ver) {
209 xvpbuttons = document.getElementById('noVNC_xvp_buttons');
211 xvpbuttons.style.display = 'inline';
213 xvpbuttons.style.display = 'none';
217 window.onscriptsload = function () {
218 var host, port, password, path, token;
220 document.getElementById('sendCtrlAltDelButton').style.display =
"inline";
221 document.getElementById('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
222 document.getElementById('xvpShutdownButton').onclick = xvpShutdown;
223 document.getElementById('xvpRebootButton').onclick = xvpReboot;
224 document.getElementById('xvpResetButton').onclick = xvpReset;
226 WebUtil.init_logging(WebUtil.getConfigVar('logging', 'warn'));
227 document.title = unescape(WebUtil.getConfigVar('title', 'noVNC'));
228 // By default, use the host and port of server that served this file
229 host = WebUtil.getConfigVar('host', window.location.hostname);
230 port = WebUtil.getConfigVar('port', window.location.port);
232 // if port ==
80 (or
443) then it won't be present and should be
235 if (window.location.protocol.substring(
0,
5) == 'https') {
238 else if (window.location.protocol.substring(
0,
4) == 'http') {
243 password = WebUtil.getConfigVar('password', '');
244 path = WebUtil.getConfigVar('path', 'websockify');
246 // If a token variable is passed in, set the parameter in a cookie.
247 // This is used by nova-novncproxy.
248 token = WebUtil.getConfigVar('token', null);
251 // if token is already present in the path we should use it
252 path = WebUtil.injectParamIfMissing(path,
"token", token);
254 WebUtil.createCookie('token', token,
1)
257 if ((!host) || (!port)) {
258 status('Must specify host and port in URL', 'error');
263 rfb = new RFB({'target': document.getElementById('noVNC_canvas'),
264 'encrypt': WebUtil.getConfigVar('encrypt',
265 (window.location.protocol ===
"https:")),
266 'repeaterID': WebUtil.getConfigVar('repeaterID', ''),
267 'true_color': WebUtil.getConfigVar('true_color', true),
268 'local_cursor': WebUtil.getConfigVar('cursor', true),
269 'shared': WebUtil.getConfigVar('shared', true),
270 'view_only': WebUtil.getConfigVar('view_only', false),
271 'onNotification': notification,
272 'onUpdateState': updateState,
273 'onDisconnected': disconnected,
274 'onXvpInit': xvpInit,
275 'onPasswordRequired': passwordRequired,
276 'onFBUComplete': FBUComplete,
277 'onDesktopName': updateDesktopName});
279 status('Unable to create RFB client -- ' + exc, 'error');
280 return; // don't continue trying to connect
283 rfb.connect(host, port, password, path);