6 noVNC example: lightweight example using minimal UI and features
7 Copyright (C) 2012 Joel Martin
8 Copyright (C) 2018 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 app/images/icons/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">
46 <link rel=
"stylesheet" href=
"app/styles/lite.css">
48 <!-- promise polyfills promises for IE11 -->
49 <script src=
"vendor/promise.js"></script>
50 <!-- ES2015/ES6 modules polyfill -->
51 <script type=
"module">
52 window._noVNC_has_module_support = true;
55 window.addEventListener(
"load", function() {
56 if (window._noVNC_has_module_support) return;
57 var loader = document.createElement(
"script");
58 loader.src =
"vendor/browser-es-module-loader/dist/browser-es-module-loader.js";
59 document.head.appendChild(loader);
63 <!-- actual script modules -->
64 <script type=
"module" crossorigin=
"anonymous">
65 // Load supporting scripts
66 import * as WebUtil from './app/webutil.js';
67 import RFB from './core/rfb.js';
72 function updateDesktopName(e) {
73 desktopName = e.detail.name;
75 function credentials(e) {
78 var form = document.createElement('form');
79 form.innerHTML = '
<label></label>';
80 form.innerHTML += '
<input type=password size=
10 id=
"password_input">';
81 form.onsubmit = setPassword;
83 // bypass status() because it sets text content
84 document.getElementById('noVNC_status_bar').setAttribute(
"class",
"noVNC_status_warn");
85 document.getElementById('noVNC_status').innerHTML = '';
86 document.getElementById('noVNC_status').appendChild(form);
87 document.getElementById('noVNC_status').querySelector('label').textContent = 'Password Required: ';
89 function setPassword() {
90 rfb.sendCredentials({ password: document.getElementById('password_input').value });
93 function sendCtrlAltDel() {
97 function status(text, level) {
106 document.getElementById('noVNC_status_bar').className =
"noVNC_status_" + level;
107 document.getElementById('noVNC_status').textContent = text;
110 function connected(e) {
111 document.getElementById('sendCtrlAltDelButton').disabled = false;
112 if (WebUtil.getConfigVar('encrypt',
113 (window.location.protocol ===
"https:"))) {
114 status(
"Connected (encrypted) to " + desktopName,
"normal");
116 status(
"Connected (unencrypted) to " + desktopName,
"normal");
120 function disconnected(e) {
121 document.getElementById('sendCtrlAltDelButton').disabled = true;
122 if (e.detail.clean) {
123 status(
"Disconnected",
"normal");
125 status(
"Something went wrong, connection is closed",
"error");
129 document.getElementById('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
131 WebUtil.init_logging(WebUtil.getConfigVar('logging', 'warn'));
132 document.title = WebUtil.getConfigVar('title', 'noVNC');
133 // By default, use the host and port of server that served this file
134 var host = WebUtil.getConfigVar('host', window.location.hostname);
135 var port = WebUtil.getConfigVar('port', window.location.port);
137 // if port ==
80 (or
443) then it won't be present and should be
140 if (window.location.protocol.substring(
0,
5) == 'https') {
143 else if (window.location.protocol.substring(
0,
4) == 'http') {
148 var password = WebUtil.getConfigVar('password', '');
149 var path = WebUtil.getConfigVar('path', 'websockify');
151 // If a token variable is passed in, set the parameter in a cookie.
152 // This is used by nova-novncproxy.
153 var token = WebUtil.getConfigVar('token', null);
155 // if token is already present in the path we should use it
156 path = WebUtil.injectParamIfMissing(path,
"token", token);
158 WebUtil.createCookie('token', token,
1)
163 status(
"Connecting",
"normal");
165 if ((!host) || (!port)) {
166 status('Must specify host and port in URL', 'error');
171 if (WebUtil.getConfigVar('encrypt',
172 (window.location.protocol ===
"https:"))) {
184 rfb = new RFB(document.body, url,
185 { repeaterID: WebUtil.getConfigVar('repeaterID', ''),
186 shared: WebUtil.getConfigVar('shared', true),
187 credentials: { password: password } });
188 rfb.viewOnly = WebUtil.getConfigVar('view_only', false);
189 rfb.addEventListener(
"connect", connected);
190 rfb.addEventListener(
"disconnect", disconnected);
191 rfb.addEventListener(
"credentialsrequired", credentials);
192 rfb.addEventListener(
"desktopname", updateDesktopName);
193 rfb.scaleViewport = WebUtil.getConfigVar('scale', false);
194 rfb.resizeSession = WebUtil.getConfigVar('resize', false);
200 <div id=
"noVNC_status_bar">
201 <div id=
"noVNC_left_dummy_elem"></div>
202 <div id=
"noVNC_status">Loading
</div>
203 <div id=
"noVNC_buttons">
204 <input type=button
value=
"Send CtrlAltDel"
205 id=
"sendCtrlAltDelButton" class=
"noVNC_shown">