6 noVNC example: simple example using default UI
7 Copyright (C) 2012 Joel Martin
8 noVNC is licensed under the MPL 2.0 (see LICENSE.txt)
9 This file is licensed under the 2-Clause BSD license (see LICENSE.txt).
11 Connect parameters are provided in query string:
12 http://example.com/?host=HOST&port=PORT&encrypt=1&true_color=1
16 <meta charset=
"utf-8">
18 <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
19 Remove this if you use the .htaccess -->
20 <meta http-equiv=
"X-UA-Compatible" content=
"IE=edge,chrome=1">
22 <!-- Apple iOS Safari settings -->
23 <meta name=
"viewport" content=
"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
24 <meta name=
"apple-mobile-web-app-capable" content=
"yes" />
25 <meta name=
"apple-mobile-web-app-status-bar-style" content=
"black-translucent" />
26 <!-- App Start Icon -->
27 <link rel=
"apple-touch-startup-image" href=
"images/screen_320x460.png" />
28 <!-- For iOS devices set the icon to use if user bookmarks app on their homescreen -->
29 <link rel=
"apple-touch-icon" href=
"images/screen_57x57.png">
31 <link rel="apple-touch-icon-precomposed" href="images/screen_57x57.png" />
36 <link rel=
"stylesheet" href=
"include/base.css" title=
"plain">
39 <script type='text/javascript'
40 src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
42 <script src=
"include/util.js"></script>
45 <body style=
"margin: 0px;">
46 <div id=
"noVNC_screen">
47 <div id=
"noVNC_status_bar" class=
"noVNC_status_bar" style=
"margin-top: 0px;">
48 <table border=
0 width=
"100%"><tr>
49 <td><div id=
"noVNC_status">Loading
</div></td>
50 <td width=
"1%"><div id=
"noVNC_buttons">
51 <input type=button
value=
"Send CtrlAltDel"
52 id=
"sendCtrlAltDelButton">
56 <canvas id=
"noVNC_canvas" width=
"640px" height=
"20px">
62 /*jslint white: false */
63 /*global window, $, Util, RFB, */
66 // Load supporting scripts
67 Util.load_scripts([
"webutil.js",
"base64.js",
"websock.js",
"des.js",
68 "input.js",
"display.js",
"jsunzip.js",
"rfb.js"]);
72 function passwordRequired(rfb) {
74 msg = '
<form onsubmit=
"return setPassword();"';
75 msg += '
style=
"margin-bottom: 0px">';
76 msg += 'Password Required: ';
77 msg += '
<input type=password size=
10 id=
"password_input" class=
"noVNC_status">';
79 $D('noVNC_status_bar').setAttribute(
"class",
"noVNC_status_warn");
80 $D('noVNC_status').innerHTML = msg;
82 function setPassword() {
83 rfb.sendPassword($D('password_input').value);
86 function sendCtrlAltDel() {
90 function updateState(rfb, state, oldstate, msg) {
91 var s, sb, cad, level;
92 s = $D('noVNC_status');
93 sb = $D('noVNC_status_bar');
94 cad = $D('sendCtrlAltDelButton');
96 case 'failed': level =
"error"; break;
97 case 'fatal': level =
"error"; break;
98 case 'normal': level =
"normal"; break;
99 case 'disconnected': level =
"normal"; break;
100 case 'loaded': level =
"normal"; break;
101 default: level =
"warn"; break;
104 if (state ===
"normal") { cad.disabled = false; }
105 else { cad.disabled = true; }
107 if (typeof(msg) !== 'undefined') {
108 sb.setAttribute(
"class",
"noVNC_status_" + level);
113 window.onscriptsload = function () {
114 var host, port, password, path, token;
116 $D('sendCtrlAltDelButton').style.display =
"inline";
117 $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
119 WebUtil.init_logging(WebUtil.getQueryVar('logging', 'warn'));
120 document.title = unescape(WebUtil.getQueryVar('title', 'noVNC'));
121 // By default, use the host and port of server that served this file
122 host = WebUtil.getQueryVar('host', window.location.hostname);
123 port = WebUtil.getQueryVar('port', window.location.port);
125 // If a token variable is passed in, set the parameter in a cookie.
126 // This is used by nova-novncproxy.
127 token = WebUtil.getQueryVar('token', null);
129 WebUtil.createCookie('token', token,
1)
132 password = WebUtil.getQueryVar('password', '');
133 path = WebUtil.getQueryVar('path', 'websockify');
135 if ((!host) || (!port)) {
136 updateState('failed',
137 "Must specify host and port in URL");
141 rfb = new RFB({'target': $D('noVNC_canvas'),
142 'encrypt': WebUtil.getQueryVar('encrypt',
143 (window.location.protocol ===
"https:")),
144 'repeaterID': WebUtil.getQueryVar('repeaterID', ''),
145 'true_color': WebUtil.getQueryVar('true_color', true),
146 'local_cursor': WebUtil.getQueryVar('cursor', true),
147 'shared': WebUtil.getQueryVar('shared', true),
148 'view_only': WebUtil.getQueryVar('view_only', false),
149 'updateState': updateState,
150 'onPasswordRequired': passwordRequired});
151 rfb.connect(host, port, password, path);