vnc_auto.html 9.3 KB

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