6 noVNC example: lightweight example using minimal UI and features
7 Copyright (C) 2012 Joel Martin
8 Copyright (C) 2017 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
15 http://example.com/#host=HOST&port=PORT&encrypt=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 <!-- Icons (see Makefile for what the sizes are for) -->
26 <link rel=
"icon" sizes=
"16x16" type=
"image/png" href=
"app/images/icons/novnc-16x16.png">
27 <link rel=
"icon" sizes=
"24x24" type=
"image/png" href=
"app/images/icons/novnc-24x24.png">
28 <link rel=
"icon" sizes=
"32x32" type=
"image/png" href=
"app/images/icons/novnc-32x32.png">
29 <link rel=
"icon" sizes=
"48x48" type=
"image/png" href=
"app/images/icons/novnc-48x48.png">
30 <link rel=
"icon" sizes=
"60x60" type=
"image/png" href=
"app/images/icons/novnc-60x60.png">
31 <link rel=
"icon" sizes=
"64x64" type=
"image/png" href=
"app/images/icons/novnc-64x64.png">
32 <link rel=
"icon" sizes=
"72x72" type=
"image/png" href=
"app/images/icons/novnc-72x72.png">
33 <link rel=
"icon" sizes=
"76x76" type=
"image/png" href=
"app/images/icons/novnc-76x76.png">
34 <link rel=
"icon" sizes=
"96x96" type=
"image/png" href=
"app/images/icons/novnc-96x96.png">
35 <link rel=
"icon" sizes=
"120x120" type=
"image/png" href=
"app/images/icons/novnc-120x120.png">
36 <link rel=
"icon" sizes=
"144x144" type=
"image/png" href=
"app/images/icons/novnc-144x144.png">
37 <link rel=
"icon" sizes=
"152x152" type=
"image/png" href=
"app/images/icons/novnc-152x152.png">
38 <link rel=
"icon" sizes=
"192x192" type=
"image/png" href=
"app/images/icons/novnc-192x192.png">
39 <!-- Firefox currently mishandles SVG, see #1419039
40 <link rel="icon" sizes="any" type="image/svg+xml" href="app/images/icons/novnc-icon.svg">
42 <!-- Repeated last so that legacy handling will pick this -->
43 <link rel=
"icon" sizes=
"16x16" type=
"image/png" href=
"app/images/icons/novnc-16x16.png">
45 <!-- Apple iOS Safari settings -->
46 <meta name=
"viewport" content=
"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
47 <meta name=
"apple-mobile-web-app-capable" content=
"yes" />
48 <meta name=
"apple-mobile-web-app-status-bar-style" content=
"black-translucent" />
49 <!-- Home Screen Icons (favourites and bookmarks use the normal icons) -->
50 <link rel=
"apple-touch-icon" sizes=
"60x60" type=
"image/png" href=
"app/images/icons/novnc-60x60.png">
51 <link rel=
"apple-touch-icon" sizes=
"76x76" type=
"image/png" href=
"app/images/icons/novnc-76x76.png">
52 <link rel=
"apple-touch-icon" sizes=
"120x120" type=
"image/png" href=
"app/images/icons/novnc-120x120.png">
53 <link rel=
"apple-touch-icon" sizes=
"152x152" type=
"image/png" href=
"app/images/icons/novnc-152x152.png">
56 <link rel=
"stylesheet" href=
"app/styles/lite.css">
59 <script type='text/javascript'
60 src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
63 <!-- promise polyfills promises for IE11 -->
64 <script src=
"vendor/promise.js"></script>
65 <!-- ES2015/ES6 modules polyfill -->
66 <script type=
"module">
67 window._noVNC_has_module_support = true;
70 window.addEventListener(
"load", function() {
71 if (window._noVNC_has_module_support) return;
72 var loader = document.createElement(
"script");
73 loader.src =
"vendor/browser-es-module-loader/dist/browser-es-module-loader.js";
74 document.head.appendChild(loader);
78 <!-- actual script modules -->
79 <script type=
"module" crossorigin=
"anonymous">
80 // Load supporting scripts
81 import * as WebUtil from './app/webutil.js';
82 import RFB from './core/rfb.js';
87 function updateDesktopName(e) {
88 desktopName = e.detail.name;
90 function credentials(e) {
93 var form = document.createElement('form');
94 form.innerHTML = '
<label></label>';
95 form.innerHTML += '
<input type=password size=
10 id=
"password_input">';
96 form.onsubmit = setPassword;
98 // bypass status() because it sets text content
99 document.getElementById('noVNC_status_bar').setAttribute(
"class",
"noVNC_status_warn");
100 document.getElementById('noVNC_status').innerHTML = '';
101 document.getElementById('noVNC_status').appendChild(form);
102 document.getElementById('noVNC_status').querySelector('label').textContent = 'Password Required: ';
104 function setPassword() {
105 rfb.sendCredentials({ password: document.getElementById('password_input').value });
108 function sendCtrlAltDel() {
109 rfb.sendCtrlAltDel();
112 function machineShutdown() {
113 rfb.machineShutdown();
116 function machineReboot() {
120 function machineReset() {
124 function status(text, level) {
133 document.getElementById('noVNC_status_bar').className =
"noVNC_status_" + level;
134 document.getElementById('noVNC_status').textContent = text;
137 function connected(e) {
138 document.getElementById('sendCtrlAltDelButton').disabled = false;
139 if (WebUtil.getConfigVar('encrypt',
140 (window.location.protocol ===
"https:"))) {
141 status(
"Connected (encrypted) to " + desktopName,
"normal");
143 status(
"Connected (unencrypted) to " + desktopName,
"normal");
147 function disconnected(e) {
148 document.getElementById('sendCtrlAltDelButton').disabled = true;
149 updatePowerButtons();
150 if (e.detail.clean) {
151 status(
"Disconnected",
"normal");
153 status(
"Something went wrong, connection is closed",
"error");
157 function updatePowerButtons() {
159 powerbuttons = document.getElementById('noVNC_power_buttons');
160 if (rfb.capabilities.power) {
161 powerbuttons.className=
"noVNC_shown";
163 powerbuttons.className =
"noVNC_hidden";
167 document.getElementById('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
168 document.getElementById('machineShutdownButton').onclick = machineShutdown;
169 document.getElementById('machineRebootButton').onclick = machineReboot;
170 document.getElementById('machineResetButton').onclick = machineReset;
172 WebUtil.init_logging(WebUtil.getConfigVar('logging', 'warn'));
173 document.title = WebUtil.getConfigVar('title', 'noVNC');
174 // By default, use the host and port of server that served this file
175 var host = WebUtil.getConfigVar('host', window.location.hostname);
176 var port = WebUtil.getConfigVar('port', window.location.port);
178 // if port ==
80 (or
443) then it won't be present and should be
181 if (window.location.protocol.substring(
0,
5) == 'https') {
184 else if (window.location.protocol.substring(
0,
4) == 'http') {
189 var password = WebUtil.getConfigVar('password', '');
190 var path = WebUtil.getConfigVar('path', 'websockify');
192 // If a token variable is passed in, set the parameter in a cookie.
193 // This is used by nova-novncproxy.
194 var token = WebUtil.getConfigVar('token', null);
196 // if token is already present in the path we should use it
197 path = WebUtil.injectParamIfMissing(path,
"token", token);
199 WebUtil.createCookie('token', token,
1)
204 status(
"Connecting",
"normal");
206 if ((!host) || (!port)) {
207 status('Must specify host and port in URL', 'error');
212 if (WebUtil.getConfigVar('encrypt',
213 (window.location.protocol ===
"https:"))) {
225 rfb = new RFB(document.body, url,
226 { repeaterID: WebUtil.getConfigVar('repeaterID', ''),
227 shared: WebUtil.getConfigVar('shared', true),
228 credentials: { password: password } });
229 rfb.viewOnly = WebUtil.getConfigVar('view_only', false);
230 rfb.addEventListener(
"connect", connected);
231 rfb.addEventListener(
"disconnect", disconnected);
232 rfb.addEventListener(
"capabilities", function () { updatePowerButtons(); });
233 rfb.addEventListener(
"credentialsrequired", credentials);
234 rfb.addEventListener(
"desktopname", updateDesktopName);
235 rfb.scaleViewport = WebUtil.getConfigVar('scale', false);
236 rfb.resizeSession = WebUtil.getConfigVar('resize', false);
242 <div id=
"noVNC_status_bar">
243 <div id=
"noVNC_left_dummy_elem"></div>
244 <div id=
"noVNC_status">Loading
</div>
245 <div id=
"noVNC_buttons">
246 <input type=button
value=
"Send CtrlAltDel"
247 id=
"sendCtrlAltDelButton" class=
"noVNC_shown">
248 <span id=
"noVNC_power_buttons" class=
"noVNC_hidden">
249 <input type=button
value=
"Shutdown"
250 id=
"machineShutdownButton">
251 <input type=button
value=
"Reboot"
252 id=
"machineRebootButton">
253 <input type=button
value=
"Reset"
254 id=
"machineResetButton">