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/util.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, */
44 // Load supporting scripts
45 Util.load_scripts([
"webutil.js",
"base64.js",
"websock.js",
"des.js",
46 "input.js",
"display.js",
"jsunzip.js",
"rfb.js"]);
50 function passwordRequired(rfb) {
52 msg = '
<form onsubmit=
"return setPassword();"';
53 msg += '
style=
"margin-bottom: 0px">';
54 msg += 'Password Required: ';
55 msg += '
<input type=password size=
10 id=
"password_input" class=
"noVNC_status">';
57 $D('noVNC_status_bar').setAttribute(
"class",
"noVNC_status_warn");
58 $D('noVNC_status').innerHTML = msg;
60 function setPassword() {
61 rfb.sendPassword($D('password_input').value);
64 function sendCtrlAltDel() {
68 function updateState(rfb, state, oldstate, msg) {
69 var s, sb, cad, level;
70 s = $D('noVNC_status');
71 sb = $D('noVNC_status_bar');
72 cad = $D('sendCtrlAltDelButton');
74 case 'failed': level =
"error"; break;
75 case 'fatal': level =
"error"; break;
76 case 'normal': level =
"normal"; break;
77 case 'disconnected': level =
"normal"; break;
78 case 'loaded': level =
"normal"; break;
79 default: level =
"warn"; break;
82 if (state ===
"normal") { cad.disabled = false; }
83 else { cad.disabled = true; }
85 if (typeof(msg) !== 'undefined') {
86 sb.setAttribute(
"class",
"noVNC_status_" + level);
91 window.onscriptsload = function () {
92 var host, port, password, path, token;
94 $D('sendCtrlAltDelButton').style.display =
"inline";
95 $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
97 WebUtil.init_logging(WebUtil.getQueryVar('logging', 'warn'));
98 document.title = unescape(WebUtil.getQueryVar('title', 'noVNC'));
99 // By default, use the host and port of server that served this file
100 host = WebUtil.getQueryVar('host', window.location.hostname);
101 port = WebUtil.getQueryVar('port', window.location.port);
103 // If a token variable is passed in, set the parameter in a cookie.
104 // This is used by nova-novncproxy.
105 token = WebUtil.getQueryVar('token', null);
107 WebUtil.createCookie('token', token,
1)
110 password = WebUtil.getQueryVar('password', '');
111 path = WebUtil.getQueryVar('path', 'websockify');
113 if ((!host) || (!port)) {
114 updateState('failed',
115 "Must specify host and port in URL");
119 rfb = new RFB({'target': $D('noVNC_canvas'),
120 'encrypt': WebUtil.getQueryVar('encrypt',
121 (window.location.protocol ===
"https:")),
122 'repeaterID': WebUtil.getQueryVar('repeaterID', ''),
123 'true_color': WebUtil.getQueryVar('true_color', true),
124 'local_cursor': WebUtil.getQueryVar('cursor', true),
125 'shared': WebUtil.getQueryVar('shared', true),
126 'view_only': WebUtil.getQueryVar('view_only', false),
127 'updateState': updateState,
128 'onPasswordRequired': passwordRequired});
129 rfb.connect(host, port, password, path);