1 <!DOCTYPE html> 2 <html> 3 <!-- 4 noVNC Example: Automatically connect on page load. 5 Copyright (C) 2011 Joel Martin 6 Licensed under LGPL-3 (see LICENSE.txt) 7 8 Connect parameters are provided in query string: 9 http://example.com/?host=HOST&port=PORT&encrypt=1&true_color=1 10 --> 11 <head> 12 <title>noVNC</title> 13 <meta http-equiv="X-UA-Compatible" content="chrome=1"> 14 <link rel="stylesheet" href="include/base.css" title="plain"> 15 <!-- 16 <script type='text/javascript' 17 src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script> 18 --> 19 <script src="include/vnc.js"></script> 20 </head> 21 22 <body style="margin: 0px;"> 23 <div id="noVNC_screen"> 24 <div id="noVNC_status_bar" class="noVNC_status_bar" style="margin-top: 0px;"> 25 <table border=0 width="100%"><tr> 26 <td><div id="noVNC_status">Loading</div></td> 27 <td width="1%"><div id="noVNC_buttons"> 28 <input type=button value="Send CtrlAltDel" 29 id="sendCtrlAltDelButton"> 30 </div></td> 31 </tr></table> 32 </div> 33 <canvas id="noVNC_canvas" width="640px" height="20px"> 34 Canvas not supported. 35 </canvas> 36 </div> 37 38 <script> 39 /*jslint white: false */ 40 /*global window, $, Util, RFB, */ 41 "use strict"; 42 43 var rfb; 44 45 function passwordRequired(rfb) { 46 var msg; 47 msg = '<form onsubmit="return setPassword();"'; 48 msg += ' style="margin-bottom: 0px">'; 49 msg += 'Password Required: '; 50 msg += '<input type=password size=10 id="password_input" class="noVNC_status">'; 51 msg += '<\/form>'; 52 $D('noVNC_status_bar').setAttribute("class", "noVNC_status_warn"); 53 $D('noVNC_status').innerHTML = msg; 54 } 55 function setPassword() { 56 rfb.sendPassword($D('password_input').value); 57 return false; 58 } 59 function sendCtrlAltDel() { 60 rfb.sendCtrlAltDel(); 61 return false; 62 } 63 function updateState(rfb, state, oldstate, msg) { 64 var s, sb, cad, level; 65 s = $D('noVNC_status'); 66 sb = $D('noVNC_status_bar'); 67 cad = $D('sendCtrlAltDelButton'); 68 switch (state) { 69 case 'failed': level = "error"; break; 70 case 'fatal': level = "error"; break; 71 case 'normal': level = "normal"; break; 72 case 'disconnected': level = "normal"; break; 73 case 'loaded': level = "normal"; break; 74 default: level = "warn"; break; 75 } 76 77 if (state === "normal") { cad.disabled = false; } 78 else { cad.disabled = true; } 79 80 if (typeof(msg) !== 'undefined') { 81 sb.setAttribute("class", "noVNC_status_" + level); 82 s.innerHTML = msg; 83 } 84 } 85 86 window.onload = function () { 87 var host, port, password, path, token; 88 89 $D('sendCtrlAltDelButton').style.display = "inline"; 90 $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel; 91 92 document.title = unescape(WebUtil.getQueryVar('title', 'noVNC')); 93 // By default, use the host and port of server that served this file 94 host = WebUtil.getQueryVar('host', window.location.hostname); 95 port = WebUtil.getQueryVar('port', window.location.port); 96 97 // If a token variable is passed in, set the parameter in a cookie. 98 // This is used by nova-novncproxy. 99 token = WebUtil.getQueryVar('token', null); 100 if (token) { 101 WebUtil.createCookie('token', token, 1) 102 } 103 104 password = WebUtil.getQueryVar('password', ''); 105 path = WebUtil.getQueryVar('path', 'websockify'); 106 if ((!host) || (!port)) { 107 updateState('failed', 108 "Must specify host and port in URL"); 109 return; 110 } 111 112 rfb = new RFB({'target': $D('noVNC_canvas'), 113 'encrypt': WebUtil.getQueryVar('encrypt', 114 (window.location.protocol === "https:")), 115 'true_color': WebUtil.getQueryVar('true_color', true), 116 'local_cursor': WebUtil.getQueryVar('cursor', true), 117 'shared': WebUtil.getQueryVar('shared', true), 118 'view_only': WebUtil.getQueryVar('view_only', false), 119 'updateState': updateState, 120 'onPasswordRequired': passwordRequired}); 121 rfb.connect(host, port, password, path); 122 }; 123 </script> 124 125 </body> 126 </html> 127 128