docker-ubuntu-vnc-desktop/noVNC/vnc_auto.html

510 lines
20 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<!--
noVNC example: simple example using default UI
Copyright (C) 2012 Joel Martin
Copyright (C) 2013 Samuel Mannehed for Cendio AB
noVNC is licensed under the MPL 2.0 (see LICENSE.txt)
This file is licensed under the 2-Clause BSD license (see LICENSE.txt).
Connect parameters are provided in query string:
http://example.com/?host=HOST&port=PORT&encrypt=1&true_color=1
-->
<title>noVNC</title>
<meta charset="utf-8">
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<!-- Apple iOS Safari settings -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<!-- App Start Icon -->
<link rel="apple-touch-startup-image" href="images/screen_320x460.png" />
<!-- For iOS devices set the icon to use if user bookmarks app on their homescreen -->
<link rel="apple-touch-icon" href="images/screen_57x57.png">
<!--
<link rel="apple-touch-icon-precomposed" href="images/screen_57x57.png" />
-->
<!-- Stylesheets -->
<link rel="stylesheet" href="include/base.css" title="plain">
<link rel="stylesheet" href="custom.css" title="plain">
<!--
<script type='text/javascript'
src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
-->
<script src="include/util.js"></script>
</head>
<body style="margin: 0px;">
<div id="noVNC_screen">
<div id="noVNC_status_bar" class="noVNC_status_bar" style="display: none;margin-top: 0px; height: 0px;">
<table border=0 width="100%"><tr>
<td><div id="noVNC_status" style="position: relative; height: auto;">
Loading
</div></td>
<td width="1%"><div id="noVNC_buttons">
<input type=button value="Send CtrlAltDel"
id="sendCtrlAltDelButton">
<span id="noVNC_xvp_buttons">
<input type=button value="Shutdown"
id="xvpShutdownButton">
<input type=button value="Reboot"
id="xvpRebootButton">
<input type=button value="Reset"
id="xvpResetButton">
</span>
</div></td>
</tr></table>
</div>
<canvas id="noVNC_canvas" width="640px" height="20px">
Canvas not supported.
</canvas>
<div id="custom_toolbar" class="custom_toolbar">
<div id="custom_toolbar_clicker" class="custom_toolbar_clicker"></div>
<div class="custom_toolbar_divider1"></div>
<div id="custom_toolbar_autoconnect_btn" class="custom_toolbar_btn"></div>
<div class="custom_toolbar_divider1"></div>
<div id="custom_toolbar_autoscale_btn" class="custom_toolbar_btn"></div>
<div class="custom_toolbar_divider1"></div>
<div id="custom_toolbar_quality_1_btn" class="custom_toolbar_btn"><div class="custom_quality_icon">L</div></div>
<div class="custom_toolbar_divider2"></div>
<div id="custom_toolbar_quality_2_btn" class="custom_toolbar_btn"><div class="custom_quality_icon">M</div></div>
<div class="custom_toolbar_divider2"></div>
<div id="custom_toolbar_quality_3_btn" class="custom_toolbar_btn"><div class="custom_quality_icon">H</div></div>
<div class="custom_toolbar_divider1"></div>
</div>
<div id="custom_mask" class="custom_mask"></div>
</div>
</body>
<script src="media/js/jquery.js"></script>
<script>
/*jslint white: false */
/*global window, $, Util, RFB, */
"use strict";
// Load supporting scripts
Util.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js",
"keysymdef.js", "keyboard.js", "input.js", "display.js",
"jsunzip.js", "rfb.js", "keysym.js"]);
var rfb;
var resizeTimeout;
// Custom noVNC share varaibles.
var Scale = {x: 1.0, y: 1.0}; // share with "./include/util.js".
var jpeg_quality = 4; // Share with "./include.rfb.js".
// Custom noVNC query parameters.
var autoconnect = 0;
var autoscale = 0;
var quality = 2;
var enablelog = 0;
// Custom toolbar click events.
$("#custom_toolbar_clicker").click(function(){
if (!$("#custom_toolbar").is(':animated')) {
if ($("#custom_toolbar" ).position().left < -10) {
$("#custom_toolbar" ).animate({ left: "+=65", }, 500, function() {
$("#custom_toolbar_clicker").css({"background-image": "url(images/pop_less.png)"});
});
}
else {
$("#custom_toolbar" ).animate({ left: "-=65", }, 500, function () {
$("#custom_toolbar_clicker").css({"background-image": "url(images/pop_more.png)"});
});
}
}
});
$("#custom_toolbar_autoconnect_btn").click(function(){
autoconnect = (autoconnect == 1) ? 0 : 1;
window.location = render_redirect_url();
});
$("#custom_toolbar_autoscale_btn").click(function(){
autoscale = (autoscale == 1) ? 0 : 1;
window.location = render_redirect_url();
});
$("#custom_toolbar_quality_1_btn").click(function(){
// low jpeg
quality = 1;
window.location = render_redirect_url();
});
$("#custom_toolbar_quality_2_btn").click(function(){
// mid jpeg
quality = 2;
window.location = render_redirect_url();
});
$("#custom_toolbar_quality_3_btn").click(function(){
// high jpeg
quality = 3;
window.location = render_redirect_url();
});
$(".custom_toolbar_btn").hover(
function() {
if (!$(this).hasClass("custom_toolbar_btn_hover_selected"))
$(this).addClass("custom_toolbar_btn_hover");
}, function() {
$(this).removeClass("custom_toolbar_btn_hover");
}
);
// Custom functions
function mask_fadein () {
var width = window.innerWidth;
var height = window.innerHeight;
$("#custom_mask").css({"width": width.toString() + "px", "height": height.toString() + "px"});
$("#custom_mask").fadeIn();
}
function mask_fadeout () {
$("#custom_mask").fadeOut();
}
function render_redirect_url() {
var new_url = (window.location.href).toString().split("?")[0] + "?";
// noVNC orign query parameter
if (WebUtil.getQueryVar('resize', false)) {
new_url += "resize=" + WebUtil.getQueryVar('resize', "") + "&";
}
if (WebUtil.getQueryVar('logging', false)) {
new_url += "logging=" + WebUtil.getQueryVar('logging', "") + "&";
}
if (WebUtil.getQueryVar('title', false)) {
new_url += "title=" + WebUtil.getQueryVar('title', "") + "&";
}
if (WebUtil.getQueryVar('host', false)) {
new_url += "host=" + WebUtil.getQueryVar('host', "") + "&";
}
if (WebUtil.getQueryVar('port', false)) {
new_url += "port=" + WebUtil.getQueryVar('port', "") + "&";
}
if (WebUtil.getQueryVar('token', false)) {
new_url += "token=" + WebUtil.getQueryVar('token', "") + "&";
}
if (WebUtil.getQueryVar('password', false)) {
new_url += "password=" + WebUtil.getQueryVar('password', "") + "&";
}
if (WebUtil.getQueryVar('path', false)) {
new_url += "path=" + WebUtil.getQueryVar('path', "") + "&";
}
if (WebUtil.getQueryVar('encrypt', false)) {
new_url += "encrypt=" + WebUtil.getQueryVar('encrypt', "") + "&";
}
if (WebUtil.getQueryVar('repeaterID', false)) {
new_url += "repeaterID=" + WebUtil.getQueryVar('repeaterID', "") + "&";
}
if (WebUtil.getQueryVar('true_color', false)) {
new_url += "true_color=" + WebUtil.getQueryVar('true_color', "") + "&";
}
if (WebUtil.getQueryVar('cursor', false)) {
new_url += "cursor=" + WebUtil.getQueryVar('cursor', "") + "&";
}
if (WebUtil.getQueryVar('shared', false)) {
new_url += "shared=" + WebUtil.getQueryVar('shared', "") + "&";
}
if (WebUtil.getQueryVar('view_only', false)) {
new_url += "view_only=" + WebUtil.getQueryVar('view_only', "") + "&";
}
// custom query parameter
new_url += "autoconnect=" + autoconnect + "&";
new_url += "autoscale=" + autoscale + "&";
new_url += "quality=" + quality + "&";
if (WebUtil.getQueryVar('enablelog', false)) {
new_url += "enablelog=" + WebUtil.getQueryVar('enablelog', "") + "&";
}
return new_url;
}
function render_custom_toolbar() {
$("#custom_toolbar_autoconnect_btn").removeClass("custom_pause_icon");
$("#custom_toolbar_autoconnect_btn").removeClass("custom_resume_icon");
if (autoconnect == 1){
$("#custom_toolbar_autoconnect_btn").addClass("custom_pause_icon");
}
else {
$("#custom_toolbar_autoconnect_btn").addClass("custom_resume_icon");
}
$("#custom_toolbar_autoscale_btn").removeClass("custom_scale_icon");
$("#custom_toolbar_autoscale_btn").removeClass("custom_not_scale_icon");
if (autoscale == 1)
$("#custom_toolbar_autoscale_btn").addClass("custom_not_scale_icon");
else
$("#custom_toolbar_autoscale_btn").addClass("custom_scale_icon");
$("#custom_toolbar_quality_1_btn").removeClass("custom_toolbar_btn_selected");
$("#custom_toolbar_quality_2_btn").removeClass("custom_toolbar_btn_selected");
$("#custom_toolbar_quality_3_btn").removeClass("custom_toolbar_btn_selected");
if (quality == 1)
$("#custom_toolbar_quality_1_btn").addClass("custom_toolbar_btn_selected");
if (quality == 2)
$("#custom_toolbar_quality_2_btn").addClass("custom_toolbar_btn_selected");
if (quality == 3)
$("#custom_toolbar_quality_3_btn").addClass("custom_toolbar_btn_selected");
if (enablelog == 1) {
console.log("------------- Custom Toolbar Settings -------------");
console.log("autoconnect: " + autoconnect);
console.log("autoscale: " + autoscale);
console.log("quality: " + quality);
console.log("enablelog: " + enablelog);
}
}
function noVNC_autoscale() {
var scaleWidth = window.innerWidth;
var scaleHeight = window.innerHeight;
var originWidth = $("#noVNC_canvas").attr("width");
var originHeight = $("#noVNC_canvas").attr("height");
$("#noVNC_canvas").css({"width": scaleWidth.toString() + "px", "height": scaleHeight.toString() + "px"})
Scale.x = scaleWidth / originWidth;
Scale.y = scaleHeight / originHeight;
if (enablelog == 1) {
console.info("-------------- Resize Canvas --------------");
console.log("Origin Width: " + originWidth);
console.log("Origin Height: " + originHeight);
console.log("Scale Width: " + scaleWidth);
console.log("Scale Height: " + scaleHeight);
console.log("Scale.x: " + Scale.x);
console.log("Scale.y: " + Scale.y);
}
}
function UIresize() {
// Enable autoscale if set 1.
if (autoscale == 1) {
noVNC_autoscale();
}
if (WebUtil.getQueryVar('resize', false)) {
var innerW = window.innerWidth;
var innerH = window.innerHeight;
var controlbarH = $D('noVNC_status_bar').offsetHeight;
var padding = 5;
if (innerW !== undefined && innerH !== undefined)
rfb.setDesktopSize(innerW, innerH - controlbarH - padding);
}
}
function FBUComplete(rfb, fbu) {
UIresize();
rfb.set_onFBUComplete(function() { });
}
function passwordRequired(rfb) {
var msg;
msg = '<form onsubmit="return setPassword();"';
msg += ' style="margin-bottom: 0px">';
msg += 'Password Required: ';
msg += '<input type=password size=10 id="password_input" class="noVNC_status">';
msg += '<\/form>';
$D('noVNC_status_bar').setAttribute("class", "noVNC_status_warn");
$D('noVNC_status').innerHTML = msg;
}
function setPassword() {
rfb.sendPassword($D('password_input').value);
return false;
}
function sendCtrlAltDel() {
rfb.sendCtrlAltDel();
return false;
}
function xvpShutdown() {
rfb.xvpShutdown();
return false;
}
function xvpReboot() {
rfb.xvpReboot();
return false;
}
function xvpReset() {
rfb.xvpReset();
return false;
}
function updateState(rfb, state, oldstate, msg) {
var s, sb, cad, level;
s = $D('noVNC_status');
sb = $D('noVNC_status_bar');
cad = $D('sendCtrlAltDelButton');
switch (state) {
case 'failed': level = "error"; break;
case 'fatal': level = "error"; break;
case 'normal': level = "normal"; break;
case 'disconnected': level = "normal"; break;
case 'loaded': level = "normal"; break;
default: level = "warn"; break;
}
if (state === "normal") {
cad.disabled = false;
} else {
cad.disabled = true;
xvpInit(0);
}
if (typeof(msg) !== 'undefined') {
sb.setAttribute("class", "noVNC_status_" + level);
s.innerHTML = msg;
}
}
function xvpInit(ver) {
var xvpbuttons;
xvpbuttons = $D('noVNC_xvp_buttons');
if (ver >= 1) {
xvpbuttons.style.display = 'inline';
} else {
xvpbuttons.style.display = 'none';
}
}
function connect_vnc() {
var host, port, password, path, token;
$D('sendCtrlAltDelButton').style.display = "inline";
$D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
$D('xvpShutdownButton').onclick = xvpShutdown;
$D('xvpRebootButton').onclick = xvpReboot;
$D('xvpResetButton').onclick = xvpReset;
WebUtil.init_logging(WebUtil.getQueryVar('logging', 'warn'));
document.title = unescape(WebUtil.getQueryVar('title', 'noVNC'));
// By default, use the host and port of server that served this file
host = WebUtil.getQueryVar('host', window.location.hostname);
port = WebUtil.getQueryVar('port', window.location.port);
// if port == 80 (or 443) then it won't be present and should be
// set manually
if (!port) {
if (window.location.protocol.substring(0,5) == 'https') {
port = 443;
}
else if (window.location.protocol.substring(0,4) == 'http') {
port = 80;
}
}
// If a token variable is passed in, set the parameter in a cookie.
// This is used by nova-novncproxy.
token = WebUtil.getQueryVar('token', null);
if (token) {
WebUtil.createCookie('token', token, 1)
}
password = WebUtil.getQueryVar('password', '');
path = WebUtil.getQueryVar('path', 'websockify');
if ((!host) || (!port)) {
updateState('failed',
"Must specify host and port in URL");
return;
}
try {
rfb = new RFB({'target': $D('noVNC_canvas'),
'encrypt': WebUtil.getQueryVar('encrypt',
(window.location.protocol === "https:")),
'repeaterID': WebUtil.getQueryVar('repeaterID', ''),
'true_color': WebUtil.getQueryVar('true_color', true),
'local_cursor': WebUtil.getQueryVar('cursor', true),
'shared': WebUtil.getQueryVar('shared', true),
'view_only': WebUtil.getQueryVar('view_only', false),
'onUpdateState': updateState,
'onXvpInit': xvpInit,
'onPasswordRequired': passwordRequired,
'onFBUComplete': FBUComplete});
} catch (exc) {
UI.updateState(null, 'fatal', null, 'Unable to create RFB client -- ' + exc);
return; // don't continue trying to connect
}
if (enablelog == 1) {
console.log('------------- noVnc Connect info -------------');
console.log('Host: ' + (host).toString());
console.log('Port: ' + (port).toString());
console.log('Password: ' + (password).toString());
console.log('Path: ' + (path).toString());
console.log('Url: ' + (window.location.href).toString());
}
// Connect
rfb.connect(host, port, password, path);
if (enablelog == 1) {
console.log('------------- noVnc RFB Stats -------------');
rfb._print_stats();
}
if (enablelog == 1) {
console.log('------------- noVnc RFB Encoding -------------');
console.log(rfb._encodings);
}
}
// Window events
window.onresize = function () {
// When the window has been resized, wait until the size remains
// the same for 0.5 seconds before sending the request for changing
// the resolution of the session
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(function(){
UIresize();
}, 100);
};
window.onload = function () {
autoconnect = WebUtil.getQueryVar('autoconnect', 0);
autoscale = WebUtil.getQueryVar('autoscale', 0);
quality = WebUtil.getQueryVar('quality', 2);
enablelog = WebUtil.getQueryVar('enablelog', 0);
// Change quality will set image level to different level (0 ~ 9)
if (quality == 1)
jpeg_quality = 0;
if (quality == 2)
jpeg_quality = 4;
if (quality == 3)
jpeg_quality = 9;
// Render the toolbar when loaded.
render_custom_toolbar();
// Connect to VNC.
if (autoconnect == 1)
connect_vnc();
}
</script>
</html>