4 noVNC example: simple example using default UI
5 Copyright (C) 2012 Joel Martin
6 noVNC is licensed under the MPL 2.0 (see LICENSE.txt)
7 This file is licensed under the 2-Clause BSD license (see LICENSE.txt).
9 Connect parameters are provided in query string:
10 http://example.com/?host=HOST&port=PORT&encrypt=1&true_color=1
14 <meta http-equiv=
"X-UA-Compatible" content=
"chrome=1">
15 <link rel=
"stylesheet" href=
"include/base.css" title=
"plain">
17 <script type='text/javascript'
18 src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
20 <script src=
"include/vnc.js"></script>
23 <body style=
"margin: 0px;">
24 <div id=
"noVNC_screen">
25 <div id=
"noVNC_status_bar" class=
"noVNC_status_bar" style=
"margin-top: 0px;">
26 <table border=
0 width=
"100%"><tr>
27 <td><div id=
"noVNC_status">Loading
</div></td>
28 <td width=
"1%"><div id=
"noVNC_buttons">
29 <input type=button
value=
"Send CtrlAltDel"
30 id=
"sendCtrlAltDelButton">
34 <canvas id=
"noVNC_canvas" width=
"640px" height=
"20px">
40 /*jslint white: false */
41 /*global window, $, Util, RFB, */
46 function passwordRequired(rfb) {
48 msg = '
<form onsubmit=
"return setPassword();"';
49 msg += '
style=
"margin-bottom: 0px">';
50 msg += 'Password Required: ';
51 msg += '
<input type=password size=
10 id=
"password_input" class=
"noVNC_status">';
53 $D('noVNC_status_bar').setAttribute(
"class",
"noVNC_status_warn");
54 $D('noVNC_status').innerHTML = msg;
56 function setPassword() {
57 rfb.sendPassword($D('password_input').value);
60 function sendCtrlAltDel() {
64 function updateState(rfb, state, oldstate, msg) {
65 var s, sb, cad, level;
66 s = $D('noVNC_status');
67 sb = $D('noVNC_status_bar');
68 cad = $D('sendCtrlAltDelButton');
70 case 'failed': level =
"error"; break;
71 case 'fatal': level =
"error"; break;
72 case 'normal': level =
"normal"; break;
73 case 'disconnected': level =
"normal"; break;
74 case 'loaded': level =
"normal"; break;
75 default: level =
"warn"; break;
78 if (state ===
"normal") { cad.disabled = false; }
79 else { cad.disabled = true; }
81 if (typeof(msg) !== 'undefined') {
82 sb.setAttribute(
"class",
"noVNC_status_" + level);
87 window.onload = function () {
88 var host, port, password, path, token;
90 $D('sendCtrlAltDelButton').style.display =
"inline";
91 $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
93 WebUtil.init_logging(WebUtil.getQueryVar('logging', 'warn'));
94 document.title = unescape(WebUtil.getQueryVar('title', 'noVNC'));
95 // By default, use the host and port of server that served this file
96 host = WebUtil.getQueryVar('host', window.location.hostname);
97 port = WebUtil.getQueryVar('port', window.location.port);
99 // If a token variable is passed in, set the parameter in a cookie.
100 // This is used by nova-novncproxy.
101 token = WebUtil.getQueryVar('token', null);
103 WebUtil.createCookie('token', token,
1)
106 password = WebUtil.getQueryVar('password', '');
107 path = WebUtil.getQueryVar('path', 'websockify');
109 if ((!host) || (!port)) {
110 updateState('failed',
111 "Must specify host and port in URL");
115 rfb = new RFB({'target': $D('noVNC_canvas'),
116 'encrypt': WebUtil.getQueryVar('encrypt',
117 (window.location.protocol ===
"https:")),
118 'repeaterID': WebUtil.getQueryVar('repeaterID', ''),
119 'true_color': WebUtil.getQueryVar('true_color', true),
120 'local_cursor': WebUtil.getQueryVar('cursor', true),
121 'shared': WebUtil.getQueryVar('shared', true),
122 'view_only': WebUtil.getQueryVar('view_only', false),
123 'updateState': updateState,
124 'onPasswordRequired': passwordRequired});
125 rfb.connect(host, port, password, path);