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
17 <meta charset=
"utf-8">
19 <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
20 Remove this if you use the .htaccess -->
21 <meta http-equiv=
"X-UA-Compatible" content=
"IE=edge,chrome=1">
23 <!-- Apple iOS Safari settings -->
24 <meta name=
"viewport" content=
"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
25 <meta name=
"apple-mobile-web-app-capable" content=
"yes" />
26 <meta name=
"apple-mobile-web-app-status-bar-style" content=
"black-translucent" />
27 <!-- App Start Icon -->
28 <link rel=
"apple-touch-startup-image" href=
"images/screen_320x460.png" />
29 <!-- For iOS devices set the icon to use if user bookmarks app on their homescreen -->
30 <link rel=
"apple-touch-icon" href=
"images/screen_57x57.png">
32 <link rel="apple-touch-icon-precomposed" href="images/screen_57x57.png" />
37 <link rel=
"stylesheet" href=
"include/base.css" title=
"plain">
40 <script type='text/javascript'
41 src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
43 <script src=
"include/util.js"></script>
46 <body style=
"margin: 0px;">
47 <div id=
"noVNC_screen">
48 <div id=
"noVNC_status_bar" class=
"noVNC_status_bar" style=
"margin-top: 0px;">
49 <table border=
0 width=
"100%"><tr>
50 <td><div id=
"noVNC_status" style=
"position: relative; height: auto;">
53 <td width=
"1%"><div id=
"noVNC_buttons">
54 <input type=button
value=
"Send CtrlAltDel"
55 id=
"sendCtrlAltDelButton">
56 <span id=
"noVNC_xvp_buttons">
57 <input type=button
value=
"Shutdown"
58 id=
"xvpShutdownButton">
59 <input type=button
value=
"Reboot"
61 <input type=button
value=
"Reset"
67 <canvas id=
"noVNC_canvas" width=
"640px" height=
"20px">
73 /*jslint white: false */
74 /*global window, $, Util, RFB, */
77 // Load supporting scripts
78 Util.load_scripts([
"webutil.js",
"base64.js",
"websock.js",
"des.js",
79 "keysymdef.js",
"keyboard.js",
"input.js",
"display.js",
80 "jsunzip.js",
"rfb.js",
"keysym.js"]);
87 if (WebUtil.getQueryVar('resize', false)) {
88 var innerW = window.innerWidth;
89 var innerH = window.innerHeight;
90 var controlbarH = $D('noVNC_status_bar').offsetHeight;
92 if (innerW !== undefined && innerH !== undefined)
93 rfb.setDesktopSize(innerW, innerH - controlbarH - padding);
96 function FBUComplete(rfb, fbu) {
98 rfb.set_onFBUComplete(function() { });
100 function passwordRequired(rfb) {
102 msg = '
<form onsubmit=
"return setPassword();"';
103 msg += '
style=
"margin-bottom: 0px">';
104 msg += 'Password Required: ';
105 msg += '
<input type=password size=
10 id=
"password_input" class=
"noVNC_status">';
107 $D('noVNC_status_bar').setAttribute(
"class",
"noVNC_status_warn");
108 $D('noVNC_status').innerHTML = msg;
110 function setPassword() {
111 rfb.sendPassword($D('password_input').value);
114 function sendCtrlAltDel() {
115 rfb.sendCtrlAltDel();
118 function xvpShutdown() {
122 function xvpReboot() {
126 function xvpReset() {
130 function updateState(rfb, state, oldstate, msg) {
131 var s, sb, cad, level;
132 s = $D('noVNC_status');
133 sb = $D('noVNC_status_bar');
134 cad = $D('sendCtrlAltDelButton');
136 case 'failed': level =
"error"; break;
137 case 'fatal': level =
"error"; break;
138 case 'normal': level =
"normal"; break;
139 case 'disconnected': level =
"normal"; break;
140 case 'loaded': level =
"normal"; break;
141 default: level =
"warn"; break;
144 if (state ===
"normal") {
145 cad.disabled = false;
151 if (typeof(msg) !== 'undefined') {
152 sb.setAttribute(
"class",
"noVNC_status_" + level);
157 window.onresize = function () {
158 // When the window has been resized, wait until the size remains
159 // the same for
0.5 seconds before sending the request for changing
160 // the resolution of the session
161 clearTimeout(resizeTimeout);
162 resizeTimeout = setTimeout(function(){
167 function xvpInit(ver) {
169 xvpbuttons = $D('noVNC_xvp_buttons');
171 xvpbuttons.style.display = 'inline';
173 xvpbuttons.style.display = 'none';
177 window.onscriptsload = function () {
178 var host, port, password, path, token;
180 $D('sendCtrlAltDelButton').style.display =
"inline";
181 $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
182 $D('xvpShutdownButton').onclick = xvpShutdown;
183 $D('xvpRebootButton').onclick = xvpReboot;
184 $D('xvpResetButton').onclick = xvpReset;
186 WebUtil.init_logging(WebUtil.getQueryVar('logging', 'warn'));
187 document.title = unescape(WebUtil.getQueryVar('title', 'noVNC'));
188 // By default, use the host and port of server that served this file
189 host = WebUtil.getQueryVar('host', window.location.hostname);
190 port = WebUtil.getQueryVar('port', window.location.port);
192 // if port ==
80 (or
443) then it won't be present and should be
195 if (window.location.protocol.substring(
0,
5) == 'https') {
198 else if (window.location.protocol.substring(
0,
4) == 'http') {
203 // If a token variable is passed in, set the parameter in a cookie.
204 // This is used by nova-novncproxy.
205 token = WebUtil.getQueryVar('token', null);
207 WebUtil.createCookie('token', token,
1)
210 password = WebUtil.getQueryVar('password', '');
211 path = WebUtil.getQueryVar('path', 'websockify');
213 if ((!host) || (!port)) {
214 updateState('failed',
215 "Must specify host and port in URL");
219 rfb = new RFB({'target': $D('noVNC_canvas'),
220 'encrypt': WebUtil.getQueryVar('encrypt',
221 (window.location.protocol ===
"https:")),
222 'repeaterID': WebUtil.getQueryVar('repeaterID', ''),
223 'true_color': WebUtil.getQueryVar('true_color', true),
224 'local_cursor': WebUtil.getQueryVar('cursor', true),
225 'shared': WebUtil.getQueryVar('shared', true),
226 'view_only': WebUtil.getQueryVar('view_only', false),
227 'onUpdateState': updateState,
228 'onXvpInit': xvpInit,
229 'onPasswordRequired': passwordRequired,
230 'onFBUComplete': FBUComplete});
231 rfb.connect(host, port, password, path);