vnc_auto.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <!--
  5. noVNC example: simple example using default UI
  6. Copyright (C) 2012 Joel Martin
  7. Copyright (C) 2013 Samuel Mannehed for Cendio AB
  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).
  10. Connect parameters are provided in query string:
  11. http://example.com/?host=HOST&port=PORT&encrypt=1&true_color=1
  12. or the fragment:
  13. http://example.com/#host=HOST&port=PORT&encrypt=1&true_color=1
  14. -->
  15. <title>noVNC</title>
  16. <meta charset="utf-8">
  17. <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
  18. Remove this if you use the .htaccess -->
  19. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  20. <!-- Apple iOS Safari settings -->
  21. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  22. <meta name="apple-mobile-web-app-capable" content="yes" />
  23. <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
  24. <!-- App Start Icon -->
  25. <link rel="apple-touch-startup-image" href="images/screen_320x460.png" />
  26. <!-- For iOS devices set the icon to use if user bookmarks app on their homescreen -->
  27. <link rel="apple-touch-icon" href="images/screen_57x57.png">
  28. <!--
  29. <link rel="apple-touch-icon-precomposed" href="images/screen_57x57.png" />
  30. -->
  31. <!-- Stylesheets -->
  32. <link rel="stylesheet" href="include/base.css" title="plain">
  33. <!--
  34. <script type='text/javascript'
  35. src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
  36. -->
  37. <script src="include/util.js"></script>
  38. </head>
  39. <body style="margin: 0px;">
  40. <div id="noVNC_container">
  41. <div id="noVNC_status_bar" class="noVNC_status_bar" style="margin-top: 0px;">
  42. <table border=0 width="100%"><tr>
  43. <td><div id="noVNC_status" style="position: relative; height: auto;">
  44. Loading
  45. </div></td>
  46. <td width="1%"><div id="noVNC_buttons">
  47. <input type=button value="Send CtrlAltDel"
  48. id="sendCtrlAltDelButton">
  49. <span id="noVNC_xvp_buttons">
  50. <input type=button value="Shutdown"
  51. id="xvpShutdownButton">
  52. <input type=button value="Reboot"
  53. id="xvpRebootButton">
  54. <input type=button value="Reset"
  55. id="xvpResetButton">
  56. </span>
  57. </div></td>
  58. </tr></table>
  59. </div>
  60. <canvas id="noVNC_canvas" width="640px" height="20px">
  61. Canvas not supported.
  62. </canvas>
  63. </div>
  64. <script>
  65. /*jslint white: false */
  66. /*global window, $, Util, RFB, */
  67. "use strict";
  68. // Load supporting scripts
  69. Util.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js",
  70. "keysymdef.js", "keyboard.js", "input.js", "display.js",
  71. "inflator.js", "rfb.js", "keysym.js"]);
  72. var rfb;
  73. var resizeTimeout;
  74. function UIresize() {
  75. if (WebUtil.getConfigVar('resize', false)) {
  76. var innerW = window.innerWidth;
  77. var innerH = window.innerHeight;
  78. var controlbarH = $D('noVNC_status_bar').offsetHeight;
  79. var padding = 5;
  80. if (innerW !== undefined && innerH !== undefined)
  81. rfb.requestDesktopSize(innerW, innerH - controlbarH - padding);
  82. }
  83. }
  84. function FBUComplete(rfb, fbu) {
  85. UIresize();
  86. rfb.set_onFBUComplete(function() { });
  87. }
  88. function passwordRequired(rfb) {
  89. var msg;
  90. msg = '<form onsubmit="return setPassword();"';
  91. msg += ' style="margin-bottom: 0px">';
  92. msg += 'Password Required: ';
  93. msg += '<input type=password size=10 id="password_input" class="noVNC_status">';
  94. msg += '<\/form>';
  95. $D('noVNC_status_bar').setAttribute("class", "noVNC_status_warn");
  96. $D('noVNC_status').innerHTML = msg;
  97. }
  98. function setPassword() {
  99. rfb.sendPassword($D('password_input').value);
  100. return false;
  101. }
  102. function sendCtrlAltDel() {
  103. rfb.sendCtrlAltDel();
  104. return false;
  105. }
  106. function xvpShutdown() {
  107. rfb.xvpShutdown();
  108. return false;
  109. }
  110. function xvpReboot() {
  111. rfb.xvpReboot();
  112. return false;
  113. }
  114. function xvpReset() {
  115. rfb.xvpReset();
  116. return false;
  117. }
  118. function updateState(rfb, state, oldstate, msg) {
  119. var s, sb, cad, level;
  120. s = $D('noVNC_status');
  121. sb = $D('noVNC_status_bar');
  122. cad = $D('sendCtrlAltDelButton');
  123. switch (state) {
  124. case 'failed': level = "error"; break;
  125. case 'fatal': level = "error"; break;
  126. case 'normal': level = "normal"; break;
  127. case 'disconnected': level = "normal"; break;
  128. case 'loaded': level = "normal"; break;
  129. default: level = "warn"; break;
  130. }
  131. if (state === "normal") {
  132. cad.disabled = false;
  133. } else {
  134. cad.disabled = true;
  135. xvpInit(0);
  136. }
  137. if (typeof(msg) !== 'undefined') {
  138. sb.setAttribute("class", "noVNC_status_" + level);
  139. s.textContent = msg;
  140. }
  141. }
  142. window.onresize = function () {
  143. // When the window has been resized, wait until the size remains
  144. // the same for 0.5 seconds before sending the request for changing
  145. // the resolution of the session
  146. clearTimeout(resizeTimeout);
  147. resizeTimeout = setTimeout(function(){
  148. UIresize();
  149. }, 500);
  150. };
  151. function xvpInit(ver) {
  152. var xvpbuttons;
  153. xvpbuttons = $D('noVNC_xvp_buttons');
  154. if (ver >= 1) {
  155. xvpbuttons.style.display = 'inline';
  156. } else {
  157. xvpbuttons.style.display = 'none';
  158. }
  159. }
  160. window.onscriptsload = function () {
  161. var host, port, password, path, token;
  162. $D('sendCtrlAltDelButton').style.display = "inline";
  163. $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
  164. $D('xvpShutdownButton').onclick = xvpShutdown;
  165. $D('xvpRebootButton').onclick = xvpReboot;
  166. $D('xvpResetButton').onclick = xvpReset;
  167. WebUtil.init_logging(WebUtil.getConfigVar('logging', 'warn'));
  168. document.title = unescape(WebUtil.getConfigVar('title', 'noVNC'));
  169. // By default, use the host and port of server that served this file
  170. host = WebUtil.getConfigVar('host', window.location.hostname);
  171. port = WebUtil.getConfigVar('port', window.location.port);
  172. // if port == 80 (or 443) then it won't be present and should be
  173. // set manually
  174. if (!port) {
  175. if (window.location.protocol.substring(0,5) == 'https') {
  176. port = 443;
  177. }
  178. else if (window.location.protocol.substring(0,4) == 'http') {
  179. port = 80;
  180. }
  181. }
  182. password = WebUtil.getConfigVar('password', '');
  183. path = WebUtil.getConfigVar('path', 'websockify');
  184. // If a token variable is passed in, set the parameter in a cookie.
  185. // This is used by nova-novncproxy.
  186. token = WebUtil.getConfigVar('token', null);
  187. if (token) {
  188. // if token is already present in the path we should use it
  189. path = WebUtil.injectParamIfMissing(path, "token", token);
  190. WebUtil.createCookie('token', token, 1)
  191. }
  192. if ((!host) || (!port)) {
  193. updateState(null, 'fatal', null, 'Must specify host and port in URL');
  194. return;
  195. }
  196. try {
  197. rfb = new RFB({'target': $D('noVNC_canvas'),
  198. 'encrypt': WebUtil.getConfigVar('encrypt',
  199. (window.location.protocol === "https:")),
  200. 'repeaterID': WebUtil.getConfigVar('repeaterID', ''),
  201. 'true_color': WebUtil.getConfigVar('true_color', true),
  202. 'local_cursor': WebUtil.getConfigVar('cursor', true),
  203. 'shared': WebUtil.getConfigVar('shared', true),
  204. 'view_only': WebUtil.getConfigVar('view_only', false),
  205. 'onUpdateState': updateState,
  206. 'onXvpInit': xvpInit,
  207. 'onPasswordRequired': passwordRequired,
  208. 'onFBUComplete': FBUComplete});
  209. } catch (exc) {
  210. updateState(null, 'fatal', null, 'Unable to create RFB client -- ' + exc);
  211. return; // don't continue trying to connect
  212. }
  213. rfb.connect(host, port, password, path);
  214. };
  215. </script>
  216. </body>
  217. </html>