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 <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
17 Remove this if you use the .htaccess -->
18 <meta http-equiv=
"X-UA-Compatible" content=
"chrome=1">
22 <link rel=
"stylesheet" href=
"include/base.css" title=
"plain">
25 <script type='text/javascript'
26 src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
28 <script src=
"include/util.js"></script>
31 <body style=
"margin: 0px;">
32 <div id=
"noVNC_screen">
33 <div id=
"noVNC_status_bar" class=
"noVNC_status_bar" style=
"margin-top: 0px;">
34 <table border=
0 width=
"100%"><tr>
35 <td><div id=
"noVNC_status">Loading
</div></td>
36 <td width=
"1%"><div id=
"noVNC_buttons">
37 <input type=button
value=
"Send CtrlAltDel"
38 id=
"sendCtrlAltDelButton">
42 <canvas id=
"noVNC_canvas" width=
"640px" height=
"20px">
48 /*jslint white: false */
49 /*global window, $, Util, RFB, */
52 // Load supporting scripts
53 Util.load_scripts([
"webutil.js",
"base64.js",
"websock.js",
"des.js",
54 "input.js",
"display.js",
"jsunzip.js",
"rfb.js"]);
58 function passwordRequired(rfb) {
60 msg = '
<form onsubmit=
"return setPassword();"';
61 msg += '
style=
"margin-bottom: 0px">';
62 msg += 'Password Required: ';
63 msg += '
<input type=password size=
10 id=
"password_input" class=
"noVNC_status">';
65 $D('noVNC_status_bar').setAttribute(
"class",
"noVNC_status_warn");
66 $D('noVNC_status').innerHTML = msg;
68 function setPassword() {
69 rfb.sendPassword($D('password_input').value);
72 function sendCtrlAltDel() {
76 function updateState(rfb, state, oldstate, msg) {
77 var s, sb, cad, level;
78 s = $D('noVNC_status');
79 sb = $D('noVNC_status_bar');
80 cad = $D('sendCtrlAltDelButton');
82 case 'failed': level =
"error"; break;
83 case 'fatal': level =
"error"; break;
84 case 'normal': level =
"normal"; break;
85 case 'disconnected': level =
"normal"; break;
86 case 'loaded': level =
"normal"; break;
87 default: level =
"warn"; break;
90 if (state ===
"normal") { cad.disabled = false; }
91 else { cad.disabled = true; }
93 if (typeof(msg) !== 'undefined') {
94 sb.setAttribute(
"class",
"noVNC_status_" + level);
99 window.onscriptsload = function () {
100 var host, port, password, path, token;
102 $D('sendCtrlAltDelButton').style.display =
"inline";
103 $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
105 WebUtil.init_logging(WebUtil.getQueryVar('logging', 'warn'));
106 document.title = unescape(WebUtil.getQueryVar('title', 'noVNC'));
107 // By default, use the host and port of server that served this file
108 host = WebUtil.getQueryVar('host', window.location.hostname);
109 port = WebUtil.getQueryVar('port', window.location.port);
111 // If a token variable is passed in, set the parameter in a cookie.
112 // This is used by nova-novncproxy.
113 token = WebUtil.getQueryVar('token', null);
115 WebUtil.createCookie('token', token,
1)
118 password = WebUtil.getQueryVar('password', '');
119 path = WebUtil.getQueryVar('path', 'websockify');
121 if ((!host) || (!port)) {
122 updateState('failed',
123 "Must specify host and port in URL");
127 rfb = new RFB({'target': $D('noVNC_canvas'),
128 'encrypt': WebUtil.getQueryVar('encrypt',
129 (window.location.protocol ===
"https:")),
130 'repeaterID': WebUtil.getQueryVar('repeaterID', ''),
131 'true_color': WebUtil.getQueryVar('true_color', true),
132 'local_cursor': WebUtil.getQueryVar('cursor', true),
133 'shared': WebUtil.getQueryVar('shared', true),
134 'view_only': WebUtil.getQueryVar('view_only', false),
135 'updateState': updateState,
136 'onPasswordRequired': passwordRequired});
137 rfb.connect(host, port, password, path);