mirror of
https://github.com/retspen/webvirtcloud
synced 2025-07-31 12:41:08 +00:00
Adde novnc js
This commit is contained in:
parent
9b02c64ff4
commit
da6a2d7e29
55 changed files with 19437 additions and 0 deletions
BIN
static/js/novnc/Orbitron700.ttf
Normal file
BIN
static/js/novnc/Orbitron700.ttf
Normal file
Binary file not shown.
BIN
static/js/novnc/Orbitron700.woff
Normal file
BIN
static/js/novnc/Orbitron700.woff
Normal file
Binary file not shown.
405
static/js/novnc/base.css
Normal file
405
static/js/novnc/base.css
Normal file
|
@ -0,0 +1,405 @@
|
|||
/*
|
||||
* noVNC base CSS
|
||||
* Copyright (C) 2012 Joel Martin
|
||||
* noVNC is licensed under the MPL 2.0 (see LICENSE.txt)
|
||||
* This file is licensed under the 2-Clause BSD license (see LICENSE.txt).
|
||||
*/
|
||||
|
||||
body {
|
||||
margin:0;
|
||||
padding:0;
|
||||
font-family: Helvetica;
|
||||
/*Background image with light grey curve.*/
|
||||
background-color:#494949;
|
||||
background-repeat:no-repeat;
|
||||
background-position:right bottom;
|
||||
height:100%;
|
||||
}
|
||||
|
||||
html {
|
||||
height:100%;
|
||||
}
|
||||
|
||||
#noVNC_controls ul {
|
||||
list-style: none;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
#noVNC_controls li {
|
||||
padding-bottom:8px;
|
||||
}
|
||||
|
||||
#noVNC_host {
|
||||
width:150px;
|
||||
}
|
||||
#noVNC_port {
|
||||
width: 80px;
|
||||
}
|
||||
#noVNC_password {
|
||||
width: 150px;
|
||||
}
|
||||
#noVNC_encrypt {
|
||||
}
|
||||
#noVNC_connectTimeout {
|
||||
width: 30px;
|
||||
}
|
||||
#noVNC_path {
|
||||
width: 100px;
|
||||
}
|
||||
#noVNC_connect_button {
|
||||
width: 110px;
|
||||
float:right;
|
||||
}
|
||||
|
||||
|
||||
#noVNC_view_drag_button {
|
||||
display: none;
|
||||
}
|
||||
#sendCtrlAltDelButton {
|
||||
display: none;
|
||||
}
|
||||
#noVNC_mobile_buttons {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.noVNC-buttons-left {
|
||||
float: left;
|
||||
padding-left:10px;
|
||||
padding-top:4px;
|
||||
}
|
||||
|
||||
.noVNC-buttons-right {
|
||||
float:right;
|
||||
right: 0px;
|
||||
padding-right:10px;
|
||||
padding-top:4px;
|
||||
}
|
||||
|
||||
#noVNC_status_bar {
|
||||
margin-top: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
#noVNC_status_bar div {
|
||||
font-size: 12px;
|
||||
padding-top: 4px;
|
||||
width:100%;
|
||||
}
|
||||
|
||||
#noVNC_status {
|
||||
height:20px;
|
||||
text-align: center;
|
||||
}
|
||||
#noVNC_settings_menu {
|
||||
margin: 3px;
|
||||
text-align: left;
|
||||
}
|
||||
#noVNC_settings_menu ul {
|
||||
list-style: none;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
#noVNC_apply {
|
||||
float:right;
|
||||
}
|
||||
|
||||
.noVNC_status_normal {
|
||||
background: #eee;
|
||||
}
|
||||
.noVNC_status_error {
|
||||
background: #f44;
|
||||
}
|
||||
.noVNC_status_warn {
|
||||
background: #ff4;
|
||||
}
|
||||
|
||||
/* Do not set width/height for VNC_screen or VNC_canvas or incorrect
|
||||
* scaling will occur. Canvas resizes to remote VNC settings */
|
||||
#noVNC_screen_pad {
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
height: 44px;
|
||||
}
|
||||
#noVNC_screen {
|
||||
text-align: center;
|
||||
display: table;
|
||||
width:100%;
|
||||
height:100%;
|
||||
background-color:#313131;
|
||||
border-bottom-right-radius: 800px 600px;
|
||||
/*border-top-left-radius: 800px 600px;*/
|
||||
}
|
||||
|
||||
#noVNC_container, #noVNC_canvas {
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
#noVNC_canvas {
|
||||
left: 0px;
|
||||
}
|
||||
|
||||
#VNC_clipboard_clear_button {
|
||||
float:right;
|
||||
}
|
||||
#VNC_clipboard_text {
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
#noVNC_clipboard_clear_button {
|
||||
float:right;
|
||||
}
|
||||
|
||||
/*Bubble contents divs*/
|
||||
#noVNC_settings {
|
||||
display:none;
|
||||
margin-top:77px;
|
||||
right:20px;
|
||||
position:fixed;
|
||||
}
|
||||
|
||||
#noVNC_controls {
|
||||
display:none;
|
||||
margin-top:77px;
|
||||
right:12px;
|
||||
position:fixed;
|
||||
}
|
||||
#noVNC_controls.top:after {
|
||||
right:15px;
|
||||
}
|
||||
|
||||
#noVNC_description {
|
||||
display:none;
|
||||
position:fixed;
|
||||
|
||||
margin-top:77px;
|
||||
right:20px;
|
||||
left:20px;
|
||||
padding:15px;
|
||||
color:#000;
|
||||
background:#eee; /* default background for browsers without gradient support */
|
||||
|
||||
border:2px solid #E0E0E0;
|
||||
-webkit-border-radius:10px;
|
||||
-moz-border-radius:10px;
|
||||
border-radius:10px;
|
||||
}
|
||||
|
||||
#noVNC_clipboard {
|
||||
display:none;
|
||||
margin-top:77px;
|
||||
right:30px;
|
||||
position:fixed;
|
||||
}
|
||||
#noVNC_clipboard.top:after {
|
||||
right:85px;
|
||||
}
|
||||
|
||||
#keyboardinput {
|
||||
width:1px;
|
||||
height:1px;
|
||||
background-color:#fff;
|
||||
color:#fff;
|
||||
border:0;
|
||||
position: relative;
|
||||
left: -40px;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
.noVNC_status_warn {
|
||||
background-color:yellow;
|
||||
}
|
||||
|
||||
/*
|
||||
* Advanced Styling
|
||||
*/
|
||||
|
||||
/* Control bar */
|
||||
#noVNC-control-bar {
|
||||
position:fixed;
|
||||
background: #b2bdcd; /* Old browsers */
|
||||
background: -moz-linear-gradient(top, #b2bdcd 0%, #899cb3 49%, #7e93af 51%, #6e84a3 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b2bdcd), color-stop(49%,#899cb3), color-stop(51%,#7e93af), color-stop(100%,#6e84a3)); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* Opera11.10+ */
|
||||
background: -ms-linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* IE10+ */
|
||||
background: linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* W3C */
|
||||
|
||||
display:block;
|
||||
height:44px;
|
||||
left:0;
|
||||
top:0;
|
||||
width:100%;
|
||||
z-index:200;
|
||||
}
|
||||
|
||||
.noVNC_status_button {
|
||||
padding: 4px 4px;
|
||||
vertical-align: middle;
|
||||
border:1px solid #869dbc;
|
||||
-webkit-border-radius: 6px;
|
||||
-moz-border-radius: 6px;
|
||||
border-radius: 6px;
|
||||
background: #b2bdcd; /* Old browsers */
|
||||
background: -moz-linear-gradient(top, #b2bdcd 0%, #899cb3 49%, #7e93af 51%, #6e84a3 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b2bdcd), color-stop(49%,#899cb3), color-stop(51%,#7e93af), color-stop(100%,#6e84a3)); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* Opera11.10+ */
|
||||
background: -ms-linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* IE10+ */
|
||||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b2bdcd', endColorstr='#6e84a3',GradientType=0 ); /* IE6-9 */
|
||||
background: linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* W3C */
|
||||
/*box-shadow:inset 0.4px 0.4px 0.4px #000000;*/
|
||||
}
|
||||
|
||||
.noVNC_status_button_selected {
|
||||
padding: 4px 4px;
|
||||
vertical-align: middle;
|
||||
border:1px solid #4366a9;
|
||||
-webkit-border-radius: 6px;
|
||||
-moz-border-radius: 6px;
|
||||
background: #779ced; /* Old browsers */
|
||||
background: -moz-linear-gradient(top, #779ced 0%, #3970e0 49%, #2160dd 51%, #2463df 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#779ced), color-stop(49%,#3970e0), color-stop(51%,#2160dd), color-stop(100%,#2463df)); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(top, #779ced 0%,#3970e0 49%,#2160dd 51%,#2463df 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(top, #779ced 0%,#3970e0 49%,#2160dd 51%,#2463df 100%); /* Opera11.10+ */
|
||||
background: -ms-linear-gradient(top, #779ced 0%,#3970e0 49%,#2160dd 51%,#2463df 100%); /* IE10+ */
|
||||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#779ced', endColorstr='#2463df',GradientType=0 ); /* IE6-9 */
|
||||
background: linear-gradient(top, #779ced 0%,#3970e0 49%,#2160dd 51%,#2463df 100%); /* W3C */
|
||||
/*box-shadow:inset 0.4px 0.4px 0.4px #000000;*/
|
||||
}
|
||||
|
||||
|
||||
/*Settings Bubble*/
|
||||
.triangle-right {
|
||||
position:relative;
|
||||
padding:15px;
|
||||
margin:1em 0 3em;
|
||||
color:#fff;
|
||||
background:#fff; /* default background for browsers without gradient support */
|
||||
/* css3 */
|
||||
/*background:-webkit-gradient(linear, 0 0, 0 100%, from(#2e88c4), to(#075698));
|
||||
background:-moz-linear-gradient(#2e88c4, #075698);
|
||||
background:-o-linear-gradient(#2e88c4, #075698);
|
||||
background:linear-gradient(#2e88c4, #075698);*/
|
||||
-webkit-border-radius:10px;
|
||||
-moz-border-radius:10px;
|
||||
border-radius:10px;
|
||||
color:#000;
|
||||
border:2px solid #E0E0E0;
|
||||
}
|
||||
|
||||
.triangle-right.top:after {
|
||||
border-color: transparent #E0E0E0;
|
||||
border-width: 20px 20px 0 0;
|
||||
bottom: auto;
|
||||
left: auto;
|
||||
right: 50px;
|
||||
top: -20px;
|
||||
}
|
||||
|
||||
.triangle-right:after {
|
||||
content:"";
|
||||
position:absolute;
|
||||
bottom:-20px; /* value = - border-top-width - border-bottom-width */
|
||||
left:50px; /* controls horizontal position */
|
||||
border-width:20px 0 0 20px; /* vary these values to change the angle of the vertex */
|
||||
border-style:solid;
|
||||
border-color:#E0E0E0 transparent;
|
||||
/* reduce the damage in FF3.0 */
|
||||
display:block;
|
||||
width:0;
|
||||
}
|
||||
|
||||
.triangle-right.top:after {
|
||||
top:-40px; /* value = - border-top-width - border-bottom-width */
|
||||
right:50px; /* controls horizontal position */
|
||||
bottom:auto;
|
||||
left:auto;
|
||||
border-width:40px 40px 0 0; /* vary these values to change the angle of the vertex */
|
||||
border-color:transparent #E0E0E0;
|
||||
}
|
||||
|
||||
/*Default noVNC logo.*/
|
||||
/* From: http://fonts.googleapis.com/css?family=Orbitron:700 */
|
||||
@font-face {
|
||||
font-family: 'Orbitron';
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
src: local('?'), url('Orbitron700.woff') format('woff'),
|
||||
url('Orbitron700.ttf') format('truetype');
|
||||
}
|
||||
|
||||
#noVNC_logo {
|
||||
margin-top: 170px;
|
||||
margin-left: 10px;
|
||||
color:yellow;
|
||||
text-align:left;
|
||||
font-family: 'Orbitron', 'OrbitronTTF', sans-serif;
|
||||
line-height:90%;
|
||||
text-shadow:
|
||||
5px 5px 0 #000,
|
||||
-1px -1px 0 #000,
|
||||
1px -1px 0 #000,
|
||||
-1px 1px 0 #000,
|
||||
1px 1px 0 #000;
|
||||
}
|
||||
|
||||
|
||||
#noVNC_logo span{
|
||||
color:green;
|
||||
}
|
||||
|
||||
/* ----------------------------------------
|
||||
* Media sizing
|
||||
* ----------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
.noVNC_status_button {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
#noVNC_clipboard_text {
|
||||
width: 500px;
|
||||
}
|
||||
|
||||
#noVNC_logo {
|
||||
font-size: 180px;
|
||||
}
|
||||
|
||||
@media screen and (min-width: 481px) and (max-width: 640px) {
|
||||
.noVNC_status_button {
|
||||
font-size: 10px;
|
||||
}
|
||||
#noVNC_clipboard_text {
|
||||
width: 410px;
|
||||
}
|
||||
#noVNC_logo {
|
||||
font-size: 150px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 321px) and (max-width: 480px) {
|
||||
.noVNC_status_button {
|
||||
font-size: 10px;
|
||||
}
|
||||
#noVNC_clipboard_text {
|
||||
width: 250px;
|
||||
}
|
||||
#noVNC_logo {
|
||||
font-size: 110px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 320px) {
|
||||
.noVNC_status_button {
|
||||
font-size: 9px;
|
||||
}
|
||||
#noVNC_clipboard_text {
|
||||
width: 220px;
|
||||
}
|
||||
#noVNC_logo {
|
||||
font-size: 90px;
|
||||
}
|
||||
}
|
115
static/js/novnc/base64.js
Normal file
115
static/js/novnc/base64.js
Normal file
|
@ -0,0 +1,115 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// From: http://hg.mozilla.org/mozilla-central/raw-file/ec10630b1a54/js/src/devtools/jint/sunspider/string-base64.js
|
||||
|
||||
/*jslint white: false, bitwise: false, plusplus: false */
|
||||
/*global console */
|
||||
|
||||
var Base64 = {
|
||||
|
||||
/* Convert data (an array of integers) to a Base64 string. */
|
||||
toBase64Table : 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split(''),
|
||||
base64Pad : '=',
|
||||
|
||||
encode: function (data) {
|
||||
"use strict";
|
||||
var result = '';
|
||||
var toBase64Table = Base64.toBase64Table;
|
||||
var length = data.length
|
||||
var lengthpad = (length%3);
|
||||
var i = 0, j = 0;
|
||||
// Convert every three bytes to 4 ascii characters.
|
||||
/* BEGIN LOOP */
|
||||
for (i = 0; i < (length - 2); i += 3) {
|
||||
result += toBase64Table[data[i] >> 2];
|
||||
result += toBase64Table[((data[i] & 0x03) << 4) + (data[i+1] >> 4)];
|
||||
result += toBase64Table[((data[i+1] & 0x0f) << 2) + (data[i+2] >> 6)];
|
||||
result += toBase64Table[data[i+2] & 0x3f];
|
||||
}
|
||||
/* END LOOP */
|
||||
|
||||
// Convert the remaining 1 or 2 bytes, pad out to 4 characters.
|
||||
if (lengthpad === 2) {
|
||||
j = length - lengthpad;
|
||||
result += toBase64Table[data[j] >> 2];
|
||||
result += toBase64Table[((data[j] & 0x03) << 4) + (data[j+1] >> 4)];
|
||||
result += toBase64Table[(data[j+1] & 0x0f) << 2];
|
||||
result += toBase64Table[64];
|
||||
} else if (lengthpad === 1) {
|
||||
j = length - lengthpad;
|
||||
result += toBase64Table[data[j] >> 2];
|
||||
result += toBase64Table[(data[j] & 0x03) << 4];
|
||||
result += toBase64Table[64];
|
||||
result += toBase64Table[64];
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
/* Convert Base64 data to a string */
|
||||
toBinaryTable : [
|
||||
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
|
||||
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
|
||||
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63,
|
||||
52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1, 0,-1,-1,
|
||||
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
|
||||
15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,-1,-1,
|
||||
-1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
|
||||
41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1
|
||||
],
|
||||
|
||||
decode: function (data, offset) {
|
||||
"use strict";
|
||||
offset = typeof(offset) !== 'undefined' ? offset : 0;
|
||||
var toBinaryTable = Base64.toBinaryTable;
|
||||
var base64Pad = Base64.base64Pad;
|
||||
var result, result_length, idx, i, c, padding;
|
||||
var leftbits = 0; // number of bits decoded, but yet to be appended
|
||||
var leftdata = 0; // bits decoded, but yet to be appended
|
||||
var data_length = data.indexOf('=') - offset;
|
||||
|
||||
if (data_length < 0) { data_length = data.length - offset; }
|
||||
|
||||
/* Every four characters is 3 resulting numbers */
|
||||
result_length = (data_length >> 2) * 3 + Math.floor((data_length%4)/1.5);
|
||||
result = new Array(result_length);
|
||||
|
||||
// Convert one by one.
|
||||
/* BEGIN LOOP */
|
||||
for (idx = 0, i = offset; i < data.length; i++) {
|
||||
c = toBinaryTable[data.charCodeAt(i) & 0x7f];
|
||||
padding = (data.charAt(i) === base64Pad);
|
||||
// Skip illegal characters and whitespace
|
||||
if (c === -1) {
|
||||
console.error("Illegal character code " + data.charCodeAt(i) + " at position " + i);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Collect data into leftdata, update bitcount
|
||||
leftdata = (leftdata << 6) | c;
|
||||
leftbits += 6;
|
||||
|
||||
// If we have 8 or more bits, append 8 bits to the result
|
||||
if (leftbits >= 8) {
|
||||
leftbits -= 8;
|
||||
// Append if not padding.
|
||||
if (!padding) {
|
||||
result[idx++] = (leftdata >> leftbits) & 0xff;
|
||||
}
|
||||
leftdata &= (1 << leftbits) - 1;
|
||||
}
|
||||
}
|
||||
/* END LOOP */
|
||||
|
||||
// If there are any bits left, the base64 string was corrupted
|
||||
if (leftbits) {
|
||||
throw {name: 'Base64-Error',
|
||||
message: 'Corrupted base64 string'};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}; /* End of Base64 namespace */
|
52
static/js/novnc/black.css
Normal file
52
static/js/novnc/black.css
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* noVNC black CSS
|
||||
* Copyright (C) 2012 Joel Martin
|
||||
* noVNC is licensed under the MPL 2.0 (see LICENSE.txt)
|
||||
* This file is licensed under the 2-Clause BSD license (see LICENSE.txt).
|
||||
*/
|
||||
|
||||
#keyboardinput {
|
||||
background-color:#000;
|
||||
}
|
||||
|
||||
#noVNC-control-bar {
|
||||
background: #4c4c4c; /* Old browsers */
|
||||
background: -moz-linear-gradient(top, #4c4c4c 0%, #2c2c2c 50%, #000000 51%, #131313 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4c4c4c), color-stop(50%,#2c2c2c), color-stop(51%,#000000), color-stop(100%,#131313)); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Opera11.10+ */
|
||||
background: -ms-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* IE10+ */
|
||||
background: linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* W3C */
|
||||
}
|
||||
|
||||
.triangle-right {
|
||||
border:2px solid #fff;
|
||||
background:#000;
|
||||
color:#fff;
|
||||
}
|
||||
|
||||
.noVNC_status_button {
|
||||
font-size: 12px;
|
||||
vertical-align: middle;
|
||||
border:1px solid #4c4c4c;
|
||||
|
||||
background: #4c4c4c; /* Old browsers */
|
||||
background: -moz-linear-gradient(top, #4c4c4c 0%, #2c2c2c 50%, #000000 51%, #131313 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4c4c4c), color-stop(50%,#2c2c2c), color-stop(51%,#000000), color-stop(100%,#131313)); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Opera11.10+ */
|
||||
background: -ms-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* IE10+ */
|
||||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4c4c4c', endColorstr='#131313',GradientType=0 ); /* IE6-9 */
|
||||
background: linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* W3C */
|
||||
}
|
||||
|
||||
.noVNC_status_button_selected {
|
||||
background: #9dd53a; /* Old browsers */
|
||||
background: -moz-linear-gradient(top, #9dd53a 0%, #a1d54f 50%, #80c217 51%, #7cbc0a 100%); /* FF3.6+ */
|
||||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#9dd53a), color-stop(50%,#a1d54f), color-stop(51%,#80c217), color-stop(100%,#7cbc0a)); /* Chrome,Safari4+ */
|
||||
background: -webkit-linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* Chrome10+,Safari5.1+ */
|
||||
background: -o-linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* Opera11.10+ */
|
||||
background: -ms-linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* IE10+ */
|
||||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9dd53a', endColorstr='#7cbc0a',GradientType=0 ); /* IE6-9 */
|
||||
background: linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* W3C */
|
||||
}
|
33
static/js/novnc/blue.css
Normal file
33
static/js/novnc/blue.css
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* noVNC blue CSS
|
||||
* Copyright (C) 2012 Joel Martin
|
||||
* noVNC is licensed under the MPL 2.0 (see LICENSE.txt)
|
||||
* This file is licensed under the 2-Clause BSD license (see LICENSE.txt).
|
||||
*/
|
||||
|
||||
#noVNC-control-bar {
|
||||
background-color:#04073d;
|
||||
background-image: -webkit-gradient(
|
||||
linear,
|
||||
left bottom,
|
||||
left top,
|
||||
color-stop(0.54, rgb(10,15,79)),
|
||||
color-stop(0.5, rgb(4,7,61))
|
||||
);
|
||||
background-image: -moz-linear-gradient(
|
||||
center bottom,
|
||||
rgb(10,15,79) 54%,
|
||||
rgb(4,7,61) 50%
|
||||
);
|
||||
}
|
||||
|
||||
.triangle-right {
|
||||
border:2px solid #fff;
|
||||
background:#04073d;
|
||||
color:#fff;
|
||||
}
|
||||
|
||||
#keyboardinput {
|
||||
background-color:#04073d;
|
||||
}
|
||||
|
321
static/js/novnc/chrome-app/tcp-client.js
Normal file
321
static/js/novnc/chrome-app/tcp-client.js
Normal file
|
@ -0,0 +1,321 @@
|
|||
/*
|
||||
Copyright 2012 Google Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: Boris Smus (smus@chromium.org)
|
||||
*/
|
||||
|
||||
(function(exports) {
|
||||
|
||||
// Define some local variables here.
|
||||
var socket = chrome.socket || chrome.experimental.socket;
|
||||
var dns = chrome.experimental.dns;
|
||||
|
||||
/**
|
||||
* Creates an instance of the client
|
||||
*
|
||||
* @param {String} host The remote host to connect to
|
||||
* @param {Number} port The port to connect to at the remote host
|
||||
*/
|
||||
function TcpClient(host, port, pollInterval) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.pollInterval = pollInterval || 15;
|
||||
|
||||
// Callback functions.
|
||||
this.callbacks = {
|
||||
connect: null, // Called when socket is connected.
|
||||
disconnect: null, // Called when socket is disconnected.
|
||||
recvBuffer: null, // Called (as ArrayBuffer) when client receives data from server.
|
||||
recvString: null, // Called (as string) when client receives data from server.
|
||||
sent: null // Called when client sends data to server.
|
||||
};
|
||||
|
||||
// Socket.
|
||||
this.socketId = null;
|
||||
this.isConnected = false;
|
||||
|
||||
log('initialized tcp client');
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to the TCP socket, and creates an open socket.
|
||||
*
|
||||
* @see http://developer.chrome.com/trunk/apps/socket.html#method-create
|
||||
* @param {Function} callback The function to call on connection
|
||||
*/
|
||||
TcpClient.prototype.connect = function(callback) {
|
||||
// First resolve the hostname to an IP.
|
||||
dns.resolve(this.host, function(result) {
|
||||
this.addr = result.address;
|
||||
socket.create('tcp', {}, this._onCreate.bind(this));
|
||||
|
||||
// Register connect callback.
|
||||
this.callbacks.connect = callback;
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends an arraybuffer/view down the wire to the remote side
|
||||
*
|
||||
* @see http://developer.chrome.com/trunk/apps/socket.html#method-write
|
||||
* @param {String} msg The arraybuffer/view to send
|
||||
* @param {Function} callback The function to call when the message has sent
|
||||
*/
|
||||
TcpClient.prototype.sendBuffer = function(buf, callback) {
|
||||
if (buf.buffer) {
|
||||
buf = buf.buffer;
|
||||
}
|
||||
|
||||
/*
|
||||
// Debug
|
||||
var bytes = [], u8 = new Uint8Array(buf);
|
||||
for (var i = 0; i < u8.length; i++) {
|
||||
bytes.push(u8[i]);
|
||||
}
|
||||
log("sending bytes: " + (bytes.join(',')));
|
||||
*/
|
||||
|
||||
socket.write(this.socketId, buf, this._onWriteComplete.bind(this));
|
||||
|
||||
// Register sent callback.
|
||||
this.callbacks.sent = callback;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends a string down the wire to the remote side
|
||||
*
|
||||
* @see http://developer.chrome.com/trunk/apps/socket.html#method-write
|
||||
* @param {String} msg The string to send
|
||||
* @param {Function} callback The function to call when the message has sent
|
||||
*/
|
||||
TcpClient.prototype.sendString = function(msg, callback) {
|
||||
/*
|
||||
// Debug
|
||||
log("sending string: " + msg);
|
||||
*/
|
||||
|
||||
this._stringToArrayBuffer(msg, function(arrayBuffer) {
|
||||
socket.write(this.socketId, arrayBuffer, this._onWriteComplete.bind(this));
|
||||
}.bind(this));
|
||||
|
||||
// Register sent callback.
|
||||
this.callbacks.sent = callback;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the callback for when a message is received
|
||||
*
|
||||
* @param {Function} callback The function to call when a message has arrived
|
||||
* @param {String} type The callback argument type: "arraybuffer" or "string"
|
||||
*/
|
||||
TcpClient.prototype.addResponseListener = function(callback, type) {
|
||||
if (typeof type === "undefined") {
|
||||
type = "arraybuffer";
|
||||
}
|
||||
// Register received callback.
|
||||
if (type === "string") {
|
||||
this.callbacks.recvString = callback;
|
||||
} else {
|
||||
this.callbacks.recvBuffer = callback;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the callback for when the socket disconnects
|
||||
*
|
||||
* @param {Function} callback The function to call when the socket disconnects
|
||||
* @param {String} type The callback argument type: "arraybuffer" or "string"
|
||||
*/
|
||||
TcpClient.prototype.addDisconnectListener = function(callback) {
|
||||
// Register disconnect callback.
|
||||
this.callbacks.disconnect = callback;
|
||||
};
|
||||
|
||||
/**
|
||||
* Disconnects from the remote side
|
||||
*
|
||||
* @see http://developer.chrome.com/trunk/apps/socket.html#method-disconnect
|
||||
*/
|
||||
TcpClient.prototype.disconnect = function() {
|
||||
if (this.isConnected) {
|
||||
this.isConnected = false;
|
||||
socket.disconnect(this.socketId);
|
||||
if (this.callbacks.disconnect) {
|
||||
this.callbacks.disconnect();
|
||||
}
|
||||
log('socket disconnected');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The callback function used for when we attempt to have Chrome
|
||||
* create a socket. If the socket is successfully created
|
||||
* we go ahead and connect to the remote side.
|
||||
*
|
||||
* @private
|
||||
* @see http://developer.chrome.com/trunk/apps/socket.html#method-connect
|
||||
* @param {Object} createInfo The socket details
|
||||
*/
|
||||
TcpClient.prototype._onCreate = function(createInfo) {
|
||||
this.socketId = createInfo.socketId;
|
||||
if (this.socketId > 0) {
|
||||
socket.connect(this.socketId, this.addr, this.port, this._onConnectComplete.bind(this));
|
||||
} else {
|
||||
error('Unable to create socket');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The callback function used for when we attempt to have Chrome
|
||||
* connect to the remote side. If a successful connection is
|
||||
* made then polling starts to check for data to read
|
||||
*
|
||||
* @private
|
||||
* @param {Number} resultCode Indicates whether the connection was successful
|
||||
*/
|
||||
TcpClient.prototype._onConnectComplete = function(resultCode) {
|
||||
// Start polling for reads.
|
||||
this.isConnected = true;
|
||||
setTimeout(this._periodicallyRead.bind(this), this.pollInterval);
|
||||
|
||||
if (this.callbacks.connect) {
|
||||
log('connect complete');
|
||||
this.callbacks.connect();
|
||||
}
|
||||
log('onConnectComplete');
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks for new data to read from the socket
|
||||
*
|
||||
* @see http://developer.chrome.com/trunk/apps/socket.html#method-read
|
||||
*/
|
||||
TcpClient.prototype._periodicallyRead = function() {
|
||||
var that = this;
|
||||
socket.getInfo(this.socketId, function (info) {
|
||||
if (info.connected) {
|
||||
setTimeout(that._periodicallyRead.bind(that), that.pollInterval);
|
||||
socket.read(that.socketId, null, that._onDataRead.bind(that));
|
||||
} else if (that.isConnected) {
|
||||
log('socket disconnect detected');
|
||||
that.disconnect();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback function for when data has been read from the socket.
|
||||
* Converts the array buffer that is read in to a string
|
||||
* and sends it on for further processing by passing it to
|
||||
* the previously assigned callback function.
|
||||
*
|
||||
* @private
|
||||
* @see TcpClient.prototype.addResponseListener
|
||||
* @param {Object} readInfo The incoming message
|
||||
*/
|
||||
TcpClient.prototype._onDataRead = function(readInfo) {
|
||||
// Call received callback if there's data in the response.
|
||||
if (readInfo.resultCode > 0) {
|
||||
log('onDataRead');
|
||||
|
||||
/*
|
||||
// Debug
|
||||
var bytes = [], u8 = new Uint8Array(readInfo.data);
|
||||
for (var i = 0; i < u8.length; i++) {
|
||||
bytes.push(u8[i]);
|
||||
}
|
||||
log("received bytes: " + (bytes.join(',')));
|
||||
*/
|
||||
|
||||
if (this.callbacks.recvBuffer) {
|
||||
// Return raw ArrayBuffer directly.
|
||||
this.callbacks.recvBuffer(readInfo.data);
|
||||
}
|
||||
if (this.callbacks.recvString) {
|
||||
// Convert ArrayBuffer to string.
|
||||
this._arrayBufferToString(readInfo.data, function(str) {
|
||||
this.callbacks.recvString(str);
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
// Trigger another read right away
|
||||
setTimeout(this._periodicallyRead.bind(this), 0);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback for when data has been successfully
|
||||
* written to the socket.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} writeInfo The outgoing message
|
||||
*/
|
||||
TcpClient.prototype._onWriteComplete = function(writeInfo) {
|
||||
log('onWriteComplete');
|
||||
// Call sent callback.
|
||||
if (this.callbacks.sent) {
|
||||
this.callbacks.sent(writeInfo);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts an array buffer to a string
|
||||
*
|
||||
* @private
|
||||
* @param {ArrayBuffer} buf The buffer to convert
|
||||
* @param {Function} callback The function to call when conversion is complete
|
||||
*/
|
||||
TcpClient.prototype._arrayBufferToString = function(buf, callback) {
|
||||
var bb = new Blob([new Uint8Array(buf)]);
|
||||
var f = new FileReader();
|
||||
f.onload = function(e) {
|
||||
callback(e.target.result);
|
||||
};
|
||||
f.readAsText(bb);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a string to an array buffer
|
||||
*
|
||||
* @private
|
||||
* @param {String} str The string to convert
|
||||
* @param {Function} callback The function to call when conversion is complete
|
||||
*/
|
||||
TcpClient.prototype._stringToArrayBuffer = function(str, callback) {
|
||||
var bb = new Blob([str]);
|
||||
var f = new FileReader();
|
||||
f.onload = function(e) {
|
||||
callback(e.target.result);
|
||||
};
|
||||
f.readAsArrayBuffer(bb);
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrapper function for logging
|
||||
*/
|
||||
function log(msg) {
|
||||
console.log(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper function for error logging
|
||||
*/
|
||||
function error(msg) {
|
||||
console.error(msg);
|
||||
}
|
||||
|
||||
exports.TcpClient = TcpClient;
|
||||
|
||||
})(window);
|
273
static/js/novnc/des.js
Normal file
273
static/js/novnc/des.js
Normal file
|
@ -0,0 +1,273 @@
|
|||
/*
|
||||
* Ported from Flashlight VNC ActionScript implementation:
|
||||
* http://www.wizhelp.com/flashlight-vnc/
|
||||
*
|
||||
* Full attribution follows:
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* This DES class has been extracted from package Acme.Crypto for use in VNC.
|
||||
* The unnecessary odd parity code has been removed.
|
||||
*
|
||||
* These changes are:
|
||||
* Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
|
||||
* DesCipher - the DES encryption method
|
||||
*
|
||||
* The meat of this code is by Dave Zimmerman <dzimm@widget.com>, and is:
|
||||
*
|
||||
* Copyright (c) 1996 Widget Workshop, Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software
|
||||
* and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
|
||||
* without fee is hereby granted, provided that this copyright notice is kept
|
||||
* intact.
|
||||
*
|
||||
* WIDGET WORKSHOP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
|
||||
* OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WIDGET WORKSHOP SHALL NOT BE LIABLE
|
||||
* FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
|
||||
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
* THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
|
||||
* CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
|
||||
* PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
|
||||
* NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
|
||||
* SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
|
||||
* SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
|
||||
* PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES"). WIDGET WORKSHOP
|
||||
* SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
|
||||
* HIGH RISK ACTIVITIES.
|
||||
*
|
||||
*
|
||||
* The rest is:
|
||||
*
|
||||
* Copyright (C) 1996 by Jef Poskanzer <jef@acme.com>. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* Visit the ACME Labs Java page for up-to-date versions of this and other
|
||||
* fine Java utilities: http://www.acme.com/java/
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
/*jslint white: false, bitwise: false, plusplus: false */
|
||||
|
||||
function DES(passwd) {
|
||||
|
||||
// Tables, permutations, S-boxes, etc.
|
||||
var PC2 = [13,16,10,23, 0, 4, 2,27,14, 5,20, 9,22,18,11, 3,
|
||||
25, 7,15, 6,26,19,12, 1,40,51,30,36,46,54,29,39,
|
||||
50,44,32,47,43,48,38,55,33,52,45,41,49,35,28,31 ],
|
||||
totrot = [ 1, 2, 4, 6, 8,10,12,14,15,17,19,21,23,25,27,28],
|
||||
z = 0x0, a,b,c,d,e,f, SP1,SP2,SP3,SP4,SP5,SP6,SP7,SP8,
|
||||
keys = [];
|
||||
|
||||
a=1<<16; b=1<<24; c=a|b; d=1<<2; e=1<<10; f=d|e;
|
||||
SP1 = [c|e,z|z,a|z,c|f,c|d,a|f,z|d,a|z,z|e,c|e,c|f,z|e,b|f,c|d,b|z,z|d,
|
||||
z|f,b|e,b|e,a|e,a|e,c|z,c|z,b|f,a|d,b|d,b|d,a|d,z|z,z|f,a|f,b|z,
|
||||
a|z,c|f,z|d,c|z,c|e,b|z,b|z,z|e,c|d,a|z,a|e,b|d,z|e,z|d,b|f,a|f,
|
||||
c|f,a|d,c|z,b|f,b|d,z|f,a|f,c|e,z|f,b|e,b|e,z|z,a|d,a|e,z|z,c|d];
|
||||
a=1<<20; b=1<<31; c=a|b; d=1<<5; e=1<<15; f=d|e;
|
||||
SP2 = [c|f,b|e,z|e,a|f,a|z,z|d,c|d,b|f,b|d,c|f,c|e,b|z,b|e,a|z,z|d,c|d,
|
||||
a|e,a|d,b|f,z|z,b|z,z|e,a|f,c|z,a|d,b|d,z|z,a|e,z|f,c|e,c|z,z|f,
|
||||
z|z,a|f,c|d,a|z,b|f,c|z,c|e,z|e,c|z,b|e,z|d,c|f,a|f,z|d,z|e,b|z,
|
||||
z|f,c|e,a|z,b|d,a|d,b|f,b|d,a|d,a|e,z|z,b|e,z|f,b|z,c|d,c|f,a|e];
|
||||
a=1<<17; b=1<<27; c=a|b; d=1<<3; e=1<<9; f=d|e;
|
||||
SP3 = [z|f,c|e,z|z,c|d,b|e,z|z,a|f,b|e,a|d,b|d,b|d,a|z,c|f,a|d,c|z,z|f,
|
||||
b|z,z|d,c|e,z|e,a|e,c|z,c|d,a|f,b|f,a|e,a|z,b|f,z|d,c|f,z|e,b|z,
|
||||
c|e,b|z,a|d,z|f,a|z,c|e,b|e,z|z,z|e,a|d,c|f,b|e,b|d,z|e,z|z,c|d,
|
||||
b|f,a|z,b|z,c|f,z|d,a|f,a|e,b|d,c|z,b|f,z|f,c|z,a|f,z|d,c|d,a|e];
|
||||
a=1<<13; b=1<<23; c=a|b; d=1<<0; e=1<<7; f=d|e;
|
||||
SP4 = [c|d,a|f,a|f,z|e,c|e,b|f,b|d,a|d,z|z,c|z,c|z,c|f,z|f,z|z,b|e,b|d,
|
||||
z|d,a|z,b|z,c|d,z|e,b|z,a|d,a|e,b|f,z|d,a|e,b|e,a|z,c|e,c|f,z|f,
|
||||
b|e,b|d,c|z,c|f,z|f,z|z,z|z,c|z,a|e,b|e,b|f,z|d,c|d,a|f,a|f,z|e,
|
||||
c|f,z|f,z|d,a|z,b|d,a|d,c|e,b|f,a|d,a|e,b|z,c|d,z|e,b|z,a|z,c|e];
|
||||
a=1<<25; b=1<<30; c=a|b; d=1<<8; e=1<<19; f=d|e;
|
||||
SP5 = [z|d,a|f,a|e,c|d,z|e,z|d,b|z,a|e,b|f,z|e,a|d,b|f,c|d,c|e,z|f,b|z,
|
||||
a|z,b|e,b|e,z|z,b|d,c|f,c|f,a|d,c|e,b|d,z|z,c|z,a|f,a|z,c|z,z|f,
|
||||
z|e,c|d,z|d,a|z,b|z,a|e,c|d,b|f,a|d,b|z,c|e,a|f,b|f,z|d,a|z,c|e,
|
||||
c|f,z|f,c|z,c|f,a|e,z|z,b|e,c|z,z|f,a|d,b|d,z|e,z|z,b|e,a|f,b|d];
|
||||
a=1<<22; b=1<<29; c=a|b; d=1<<4; e=1<<14; f=d|e;
|
||||
SP6 = [b|d,c|z,z|e,c|f,c|z,z|d,c|f,a|z,b|e,a|f,a|z,b|d,a|d,b|e,b|z,z|f,
|
||||
z|z,a|d,b|f,z|e,a|e,b|f,z|d,c|d,c|d,z|z,a|f,c|e,z|f,a|e,c|e,b|z,
|
||||
b|e,z|d,c|d,a|e,c|f,a|z,z|f,b|d,a|z,b|e,b|z,z|f,b|d,c|f,a|e,c|z,
|
||||
a|f,c|e,z|z,c|d,z|d,z|e,c|z,a|f,z|e,a|d,b|f,z|z,c|e,b|z,a|d,b|f];
|
||||
a=1<<21; b=1<<26; c=a|b; d=1<<1; e=1<<11; f=d|e;
|
||||
SP7 = [a|z,c|d,b|f,z|z,z|e,b|f,a|f,c|e,c|f,a|z,z|z,b|d,z|d,b|z,c|d,z|f,
|
||||
b|e,a|f,a|d,b|e,b|d,c|z,c|e,a|d,c|z,z|e,z|f,c|f,a|e,z|d,b|z,a|e,
|
||||
b|z,a|e,a|z,b|f,b|f,c|d,c|d,z|d,a|d,b|z,b|e,a|z,c|e,z|f,a|f,c|e,
|
||||
z|f,b|d,c|f,c|z,a|e,z|z,z|d,c|f,z|z,a|f,c|z,z|e,b|d,b|e,z|e,a|d];
|
||||
a=1<<18; b=1<<28; c=a|b; d=1<<6; e=1<<12; f=d|e;
|
||||
SP8 = [b|f,z|e,a|z,c|f,b|z,b|f,z|d,b|z,a|d,c|z,c|f,a|e,c|e,a|f,z|e,z|d,
|
||||
c|z,b|d,b|e,z|f,a|e,a|d,c|d,c|e,z|f,z|z,z|z,c|d,b|d,b|e,a|f,a|z,
|
||||
a|f,a|z,c|e,z|e,z|d,c|d,z|e,a|f,b|e,z|d,b|d,c|z,c|d,b|z,a|z,b|f,
|
||||
z|z,c|f,a|d,b|d,c|z,b|e,b|f,z|z,c|f,a|e,a|e,z|f,z|f,a|d,b|z,c|e];
|
||||
|
||||
// Set the key.
|
||||
function setKeys(keyBlock) {
|
||||
var i, j, l, m, n, o, pc1m = [], pcr = [], kn = [],
|
||||
raw0, raw1, rawi, KnLi;
|
||||
|
||||
for (j = 0, l = 56; j < 56; ++j, l-=8) {
|
||||
l += l<-5 ? 65 : l<-3 ? 31 : l<-1 ? 63 : l===27 ? 35 : 0; // PC1
|
||||
m = l & 0x7;
|
||||
pc1m[j] = ((keyBlock[l >>> 3] & (1<<m)) !== 0) ? 1: 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < 16; ++i) {
|
||||
m = i << 1;
|
||||
n = m + 1;
|
||||
kn[m] = kn[n] = 0;
|
||||
for (o=28; o<59; o+=28) {
|
||||
for (j = o-28; j < o; ++j) {
|
||||
l = j + totrot[i];
|
||||
if (l < o) {
|
||||
pcr[j] = pc1m[l];
|
||||
} else {
|
||||
pcr[j] = pc1m[l - 28];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (j = 0; j < 24; ++j) {
|
||||
if (pcr[PC2[j]] !== 0) {
|
||||
kn[m] |= 1<<(23-j);
|
||||
}
|
||||
if (pcr[PC2[j + 24]] !== 0) {
|
||||
kn[n] |= 1<<(23-j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cookey
|
||||
for (i = 0, rawi = 0, KnLi = 0; i < 16; ++i) {
|
||||
raw0 = kn[rawi++];
|
||||
raw1 = kn[rawi++];
|
||||
keys[KnLi] = (raw0 & 0x00fc0000) << 6;
|
||||
keys[KnLi] |= (raw0 & 0x00000fc0) << 10;
|
||||
keys[KnLi] |= (raw1 & 0x00fc0000) >>> 10;
|
||||
keys[KnLi] |= (raw1 & 0x00000fc0) >>> 6;
|
||||
++KnLi;
|
||||
keys[KnLi] = (raw0 & 0x0003f000) << 12;
|
||||
keys[KnLi] |= (raw0 & 0x0000003f) << 16;
|
||||
keys[KnLi] |= (raw1 & 0x0003f000) >>> 4;
|
||||
keys[KnLi] |= (raw1 & 0x0000003f);
|
||||
++KnLi;
|
||||
}
|
||||
}
|
||||
|
||||
// Encrypt 8 bytes of text
|
||||
function enc8(text) {
|
||||
var i = 0, b = text.slice(), fval, keysi = 0,
|
||||
l, r, x; // left, right, accumulator
|
||||
|
||||
// Squash 8 bytes to 2 ints
|
||||
l = b[i++]<<24 | b[i++]<<16 | b[i++]<<8 | b[i++];
|
||||
r = b[i++]<<24 | b[i++]<<16 | b[i++]<<8 | b[i++];
|
||||
|
||||
x = ((l >>> 4) ^ r) & 0x0f0f0f0f;
|
||||
r ^= x;
|
||||
l ^= (x << 4);
|
||||
x = ((l >>> 16) ^ r) & 0x0000ffff;
|
||||
r ^= x;
|
||||
l ^= (x << 16);
|
||||
x = ((r >>> 2) ^ l) & 0x33333333;
|
||||
l ^= x;
|
||||
r ^= (x << 2);
|
||||
x = ((r >>> 8) ^ l) & 0x00ff00ff;
|
||||
l ^= x;
|
||||
r ^= (x << 8);
|
||||
r = (r << 1) | ((r >>> 31) & 1);
|
||||
x = (l ^ r) & 0xaaaaaaaa;
|
||||
l ^= x;
|
||||
r ^= x;
|
||||
l = (l << 1) | ((l >>> 31) & 1);
|
||||
|
||||
for (i = 0; i < 8; ++i) {
|
||||
x = (r << 28) | (r >>> 4);
|
||||
x ^= keys[keysi++];
|
||||
fval = SP7[x & 0x3f];
|
||||
fval |= SP5[(x >>> 8) & 0x3f];
|
||||
fval |= SP3[(x >>> 16) & 0x3f];
|
||||
fval |= SP1[(x >>> 24) & 0x3f];
|
||||
x = r ^ keys[keysi++];
|
||||
fval |= SP8[x & 0x3f];
|
||||
fval |= SP6[(x >>> 8) & 0x3f];
|
||||
fval |= SP4[(x >>> 16) & 0x3f];
|
||||
fval |= SP2[(x >>> 24) & 0x3f];
|
||||
l ^= fval;
|
||||
x = (l << 28) | (l >>> 4);
|
||||
x ^= keys[keysi++];
|
||||
fval = SP7[x & 0x3f];
|
||||
fval |= SP5[(x >>> 8) & 0x3f];
|
||||
fval |= SP3[(x >>> 16) & 0x3f];
|
||||
fval |= SP1[(x >>> 24) & 0x3f];
|
||||
x = l ^ keys[keysi++];
|
||||
fval |= SP8[x & 0x0000003f];
|
||||
fval |= SP6[(x >>> 8) & 0x3f];
|
||||
fval |= SP4[(x >>> 16) & 0x3f];
|
||||
fval |= SP2[(x >>> 24) & 0x3f];
|
||||
r ^= fval;
|
||||
}
|
||||
|
||||
r = (r << 31) | (r >>> 1);
|
||||
x = (l ^ r) & 0xaaaaaaaa;
|
||||
l ^= x;
|
||||
r ^= x;
|
||||
l = (l << 31) | (l >>> 1);
|
||||
x = ((l >>> 8) ^ r) & 0x00ff00ff;
|
||||
r ^= x;
|
||||
l ^= (x << 8);
|
||||
x = ((l >>> 2) ^ r) & 0x33333333;
|
||||
r ^= x;
|
||||
l ^= (x << 2);
|
||||
x = ((r >>> 16) ^ l) & 0x0000ffff;
|
||||
l ^= x;
|
||||
r ^= (x << 16);
|
||||
x = ((r >>> 4) ^ l) & 0x0f0f0f0f;
|
||||
l ^= x;
|
||||
r ^= (x << 4);
|
||||
|
||||
// Spread ints to bytes
|
||||
x = [r, l];
|
||||
for (i = 0; i < 8; i++) {
|
||||
b[i] = (x[i>>>2] >>> (8*(3 - (i%4)))) % 256;
|
||||
if (b[i] < 0) { b[i] += 256; } // unsigned
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
// Encrypt 16 bytes of text using passwd as key
|
||||
function encrypt(t) {
|
||||
return enc8(t.slice(0,8)).concat(enc8(t.slice(8,16)));
|
||||
}
|
||||
|
||||
setKeys(passwd); // Setup keys
|
||||
return {'encrypt': encrypt}; // Public interface
|
||||
|
||||
} // function DES
|
770
static/js/novnc/display.js
Normal file
770
static/js/novnc/display.js
Normal file
|
@ -0,0 +1,770 @@
|
|||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2012 Joel Martin
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*/
|
||||
|
||||
/*jslint browser: true, white: false, bitwise: false */
|
||||
/*global Util, Base64, changeCursor */
|
||||
|
||||
function Display(defaults) {
|
||||
"use strict";
|
||||
|
||||
var that = {}, // Public API methods
|
||||
conf = {}, // Configuration attributes
|
||||
|
||||
// Private Display namespace variables
|
||||
c_ctx = null,
|
||||
c_forceCanvas = false,
|
||||
|
||||
// Queued drawing actions for in-order rendering
|
||||
renderQ = [],
|
||||
|
||||
// Predefine function variables (jslint)
|
||||
imageDataGet, rgbImageData, bgrxImageData, cmapImageData,
|
||||
setFillColor, rescale, scan_renderQ,
|
||||
|
||||
// The full frame buffer (logical canvas) size
|
||||
fb_width = 0,
|
||||
fb_height = 0,
|
||||
// The visible "physical canvas" viewport
|
||||
viewport = {'x': 0, 'y': 0, 'w' : 0, 'h' : 0 },
|
||||
cleanRect = {'x1': 0, 'y1': 0, 'x2': -1, 'y2': -1},
|
||||
|
||||
c_prevStyle = "",
|
||||
tile = null,
|
||||
tile16x16 = null,
|
||||
tile_x = 0,
|
||||
tile_y = 0;
|
||||
|
||||
|
||||
// Configuration attributes
|
||||
Util.conf_defaults(conf, that, defaults, [
|
||||
['target', 'wo', 'dom', null, 'Canvas element for rendering'],
|
||||
['context', 'ro', 'raw', null, 'Canvas 2D context for rendering (read-only)'],
|
||||
['logo', 'rw', 'raw', null, 'Logo to display when cleared: {"width": width, "height": height, "data": data}'],
|
||||
['true_color', 'rw', 'bool', true, 'Use true-color pixel data'],
|
||||
['colourMap', 'rw', 'arr', [], 'Colour map array (when not true-color)'],
|
||||
['scale', 'rw', 'float', 1.0, 'Display area scale factor 0.0 - 1.0'],
|
||||
['viewport', 'rw', 'bool', false, 'Use a viewport set with viewportChange()'],
|
||||
['width', 'rw', 'int', null, 'Display area width'],
|
||||
['height', 'rw', 'int', null, 'Display area height'],
|
||||
|
||||
['render_mode', 'ro', 'str', '', 'Canvas rendering mode (read-only)'],
|
||||
|
||||
['prefer_js', 'rw', 'str', null, 'Prefer Javascript over canvas methods'],
|
||||
['cursor_uri', 'rw', 'raw', null, 'Can we render cursor using data URI']
|
||||
]);
|
||||
|
||||
// Override some specific getters/setters
|
||||
that.get_context = function () { return c_ctx; };
|
||||
|
||||
that.set_scale = function(scale) { rescale(scale); };
|
||||
|
||||
that.set_width = function (val) { that.resize(val, fb_height); };
|
||||
that.get_width = function() { return fb_width; };
|
||||
|
||||
that.set_height = function (val) { that.resize(fb_width, val); };
|
||||
that.get_height = function() { return fb_height; };
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Private functions
|
||||
//
|
||||
|
||||
// Create the public API interface
|
||||
function constructor() {
|
||||
Util.Debug(">> Display.constructor");
|
||||
|
||||
var c, func, i, curDat, curSave,
|
||||
has_imageData = false, UE = Util.Engine;
|
||||
|
||||
if (! conf.target) { throw("target must be set"); }
|
||||
|
||||
if (typeof conf.target === 'string') {
|
||||
throw("target must be a DOM element");
|
||||
}
|
||||
|
||||
c = conf.target;
|
||||
|
||||
if (! c.getContext) { throw("no getContext method"); }
|
||||
|
||||
if (! c_ctx) { c_ctx = c.getContext('2d'); }
|
||||
|
||||
Util.Debug("User Agent: " + navigator.userAgent);
|
||||
if (UE.gecko) { Util.Debug("Browser: gecko " + UE.gecko); }
|
||||
if (UE.webkit) { Util.Debug("Browser: webkit " + UE.webkit); }
|
||||
if (UE.trident) { Util.Debug("Browser: trident " + UE.trident); }
|
||||
if (UE.presto) { Util.Debug("Browser: presto " + UE.presto); }
|
||||
|
||||
that.clear();
|
||||
|
||||
// Check canvas features
|
||||
if ('createImageData' in c_ctx) {
|
||||
conf.render_mode = "canvas rendering";
|
||||
} else {
|
||||
throw("Canvas does not support createImageData");
|
||||
}
|
||||
if (conf.prefer_js === null) {
|
||||
Util.Info("Prefering javascript operations");
|
||||
conf.prefer_js = true;
|
||||
}
|
||||
|
||||
// Initialize cached tile imageData
|
||||
tile16x16 = c_ctx.createImageData(16, 16);
|
||||
|
||||
/*
|
||||
* Determine browser support for setting the cursor via data URI
|
||||
* scheme
|
||||
*/
|
||||
curDat = [];
|
||||
for (i=0; i < 8 * 8 * 4; i += 1) {
|
||||
curDat.push(255);
|
||||
}
|
||||
try {
|
||||
curSave = c.style.cursor;
|
||||
changeCursor(conf.target, curDat, curDat, 2, 2, 8, 8);
|
||||
if (c.style.cursor) {
|
||||
if (conf.cursor_uri === null) {
|
||||
conf.cursor_uri = true;
|
||||
}
|
||||
Util.Info("Data URI scheme cursor supported");
|
||||
} else {
|
||||
if (conf.cursor_uri === null) {
|
||||
conf.cursor_uri = false;
|
||||
}
|
||||
Util.Warn("Data URI scheme cursor not supported");
|
||||
}
|
||||
c.style.cursor = curSave;
|
||||
} catch (exc2) {
|
||||
Util.Error("Data URI scheme cursor test exception: " + exc2);
|
||||
conf.cursor_uri = false;
|
||||
}
|
||||
|
||||
Util.Debug("<< Display.constructor");
|
||||
return that ;
|
||||
}
|
||||
|
||||
rescale = function(factor) {
|
||||
var c, tp, x, y,
|
||||
properties = ['transform', 'WebkitTransform', 'MozTransform', null];
|
||||
c = conf.target;
|
||||
tp = properties.shift();
|
||||
while (tp) {
|
||||
if (typeof c.style[tp] !== 'undefined') {
|
||||
break;
|
||||
}
|
||||
tp = properties.shift();
|
||||
}
|
||||
|
||||
if (tp === null) {
|
||||
Util.Debug("No scaling support");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (typeof(factor) === "undefined") {
|
||||
factor = conf.scale;
|
||||
} else if (factor > 1.0) {
|
||||
factor = 1.0;
|
||||
} else if (factor < 0.1) {
|
||||
factor = 0.1;
|
||||
}
|
||||
|
||||
if (conf.scale === factor) {
|
||||
//Util.Debug("Display already scaled to '" + factor + "'");
|
||||
return;
|
||||
}
|
||||
|
||||
conf.scale = factor;
|
||||
x = c.width - c.width * factor;
|
||||
y = c.height - c.height * factor;
|
||||
c.style[tp] = "scale(" + conf.scale + ") translate(-" + x + "px, -" + y + "px)";
|
||||
};
|
||||
|
||||
setFillColor = function(color) {
|
||||
var bgr, newStyle;
|
||||
if (conf.true_color) {
|
||||
bgr = color;
|
||||
} else {
|
||||
bgr = conf.colourMap[color[0]];
|
||||
}
|
||||
newStyle = "rgb(" + bgr[2] + "," + bgr[1] + "," + bgr[0] + ")";
|
||||
if (newStyle !== c_prevStyle) {
|
||||
c_ctx.fillStyle = newStyle;
|
||||
c_prevStyle = newStyle;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Public API interface functions
|
||||
//
|
||||
|
||||
// Shift and/or resize the visible viewport
|
||||
that.viewportChange = function(deltaX, deltaY, width, height) {
|
||||
var c = conf.target, v = viewport, cr = cleanRect,
|
||||
saveImg = null, saveStyle, x1, y1, vx2, vy2, w, h;
|
||||
|
||||
if (!conf.viewport) {
|
||||
Util.Debug("Setting viewport to full display region");
|
||||
deltaX = -v.w; // Clamped later if out of bounds
|
||||
deltaY = -v.h; // Clamped later if out of bounds
|
||||
width = fb_width;
|
||||
height = fb_height;
|
||||
}
|
||||
|
||||
if (typeof(deltaX) === "undefined") { deltaX = 0; }
|
||||
if (typeof(deltaY) === "undefined") { deltaY = 0; }
|
||||
if (typeof(width) === "undefined") { width = v.w; }
|
||||
if (typeof(height) === "undefined") { height = v.h; }
|
||||
|
||||
// Size change
|
||||
|
||||
if (width > fb_width) { width = fb_width; }
|
||||
if (height > fb_height) { height = fb_height; }
|
||||
|
||||
if ((v.w !== width) || (v.h !== height)) {
|
||||
// Change width
|
||||
if ((width < v.w) && (cr.x2 > v.x + width -1)) {
|
||||
cr.x2 = v.x + width - 1;
|
||||
}
|
||||
v.w = width;
|
||||
|
||||
// Change height
|
||||
if ((height < v.h) && (cr.y2 > v.y + height -1)) {
|
||||
cr.y2 = v.y + height - 1;
|
||||
}
|
||||
v.h = height;
|
||||
|
||||
|
||||
if (v.w > 0 && v.h > 0 && c.width > 0 && c.height > 0) {
|
||||
saveImg = c_ctx.getImageData(0, 0,
|
||||
(c.width < v.w) ? c.width : v.w,
|
||||
(c.height < v.h) ? c.height : v.h);
|
||||
}
|
||||
|
||||
c.width = v.w;
|
||||
c.height = v.h;
|
||||
|
||||
if (saveImg) {
|
||||
c_ctx.putImageData(saveImg, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
vx2 = v.x + v.w - 1;
|
||||
vy2 = v.y + v.h - 1;
|
||||
|
||||
|
||||
// Position change
|
||||
|
||||
if ((deltaX < 0) && ((v.x + deltaX) < 0)) {
|
||||
deltaX = - v.x;
|
||||
}
|
||||
if ((vx2 + deltaX) >= fb_width) {
|
||||
deltaX -= ((vx2 + deltaX) - fb_width + 1);
|
||||
}
|
||||
|
||||
if ((v.y + deltaY) < 0) {
|
||||
deltaY = - v.y;
|
||||
}
|
||||
if ((vy2 + deltaY) >= fb_height) {
|
||||
deltaY -= ((vy2 + deltaY) - fb_height + 1);
|
||||
}
|
||||
|
||||
if ((deltaX === 0) && (deltaY === 0)) {
|
||||
//Util.Debug("skipping viewport change");
|
||||
return;
|
||||
}
|
||||
Util.Debug("viewportChange deltaX: " + deltaX + ", deltaY: " + deltaY);
|
||||
|
||||
v.x += deltaX;
|
||||
vx2 += deltaX;
|
||||
v.y += deltaY;
|
||||
vy2 += deltaY;
|
||||
|
||||
// Update the clean rectangle
|
||||
if (v.x > cr.x1) {
|
||||
cr.x1 = v.x;
|
||||
}
|
||||
if (vx2 < cr.x2) {
|
||||
cr.x2 = vx2;
|
||||
}
|
||||
if (v.y > cr.y1) {
|
||||
cr.y1 = v.y;
|
||||
}
|
||||
if (vy2 < cr.y2) {
|
||||
cr.y2 = vy2;
|
||||
}
|
||||
|
||||
if (deltaX < 0) {
|
||||
// Shift viewport left, redraw left section
|
||||
x1 = 0;
|
||||
w = - deltaX;
|
||||
} else {
|
||||
// Shift viewport right, redraw right section
|
||||
x1 = v.w - deltaX;
|
||||
w = deltaX;
|
||||
}
|
||||
if (deltaY < 0) {
|
||||
// Shift viewport up, redraw top section
|
||||
y1 = 0;
|
||||
h = - deltaY;
|
||||
} else {
|
||||
// Shift viewport down, redraw bottom section
|
||||
y1 = v.h - deltaY;
|
||||
h = deltaY;
|
||||
}
|
||||
|
||||
// Copy the valid part of the viewport to the shifted location
|
||||
saveStyle = c_ctx.fillStyle;
|
||||
c_ctx.fillStyle = "rgb(255,255,255)";
|
||||
if (deltaX !== 0) {
|
||||
//that.copyImage(0, 0, -deltaX, 0, v.w, v.h);
|
||||
//that.fillRect(x1, 0, w, v.h, [255,255,255]);
|
||||
c_ctx.drawImage(c, 0, 0, v.w, v.h, -deltaX, 0, v.w, v.h);
|
||||
c_ctx.fillRect(x1, 0, w, v.h);
|
||||
}
|
||||
if (deltaY !== 0) {
|
||||
//that.copyImage(0, 0, 0, -deltaY, v.w, v.h);
|
||||
//that.fillRect(0, y1, v.w, h, [255,255,255]);
|
||||
c_ctx.drawImage(c, 0, 0, v.w, v.h, 0, -deltaY, v.w, v.h);
|
||||
c_ctx.fillRect(0, y1, v.w, h);
|
||||
}
|
||||
c_ctx.fillStyle = saveStyle;
|
||||
};
|
||||
|
||||
|
||||
// Return a map of clean and dirty areas of the viewport and reset the
|
||||
// tracking of clean and dirty areas.
|
||||
//
|
||||
// Returns: {'cleanBox': {'x': x, 'y': y, 'w': w, 'h': h},
|
||||
// 'dirtyBoxes': [{'x': x, 'y': y, 'w': w, 'h': h}, ...]}
|
||||
that.getCleanDirtyReset = function() {
|
||||
var v = viewport, c = cleanRect, cleanBox, dirtyBoxes = [],
|
||||
vx2 = v.x + v.w - 1, vy2 = v.y + v.h - 1;
|
||||
|
||||
|
||||
// Copy the cleanRect
|
||||
cleanBox = {'x': c.x1, 'y': c.y1,
|
||||
'w': c.x2 - c.x1 + 1, 'h': c.y2 - c.y1 + 1};
|
||||
|
||||
if ((c.x1 >= c.x2) || (c.y1 >= c.y2)) {
|
||||
// Whole viewport is dirty
|
||||
dirtyBoxes.push({'x': v.x, 'y': v.y, 'w': v.w, 'h': v.h});
|
||||
} else {
|
||||
// Redraw dirty regions
|
||||
if (v.x < c.x1) {
|
||||
// left side dirty region
|
||||
dirtyBoxes.push({'x': v.x, 'y': v.y,
|
||||
'w': c.x1 - v.x + 1, 'h': v.h});
|
||||
}
|
||||
if (vx2 > c.x2) {
|
||||
// right side dirty region
|
||||
dirtyBoxes.push({'x': c.x2 + 1, 'y': v.y,
|
||||
'w': vx2 - c.x2, 'h': v.h});
|
||||
}
|
||||
if (v.y < c.y1) {
|
||||
// top/middle dirty region
|
||||
dirtyBoxes.push({'x': c.x1, 'y': v.y,
|
||||
'w': c.x2 - c.x1 + 1, 'h': c.y1 - v.y});
|
||||
}
|
||||
if (vy2 > c.y2) {
|
||||
// bottom/middle dirty region
|
||||
dirtyBoxes.push({'x': c.x1, 'y': c.y2 + 1,
|
||||
'w': c.x2 - c.x1 + 1, 'h': vy2 - c.y2});
|
||||
}
|
||||
}
|
||||
|
||||
// Reset the cleanRect to the whole viewport
|
||||
cleanRect = {'x1': v.x, 'y1': v.y,
|
||||
'x2': v.x + v.w - 1, 'y2': v.y + v.h - 1};
|
||||
|
||||
return {'cleanBox': cleanBox, 'dirtyBoxes': dirtyBoxes};
|
||||
};
|
||||
|
||||
// Translate viewport coordinates to absolute coordinates
|
||||
that.absX = function(x) {
|
||||
return x + viewport.x;
|
||||
};
|
||||
that.absY = function(y) {
|
||||
return y + viewport.y;
|
||||
};
|
||||
|
||||
|
||||
that.resize = function(width, height) {
|
||||
c_prevStyle = "";
|
||||
|
||||
fb_width = width;
|
||||
fb_height = height;
|
||||
|
||||
rescale(conf.scale);
|
||||
that.viewportChange();
|
||||
};
|
||||
|
||||
that.clear = function() {
|
||||
|
||||
if (conf.logo) {
|
||||
that.resize(conf.logo.width, conf.logo.height);
|
||||
that.blitStringImage(conf.logo.data, 0, 0);
|
||||
} else {
|
||||
that.resize(640, 20);
|
||||
c_ctx.clearRect(0, 0, viewport.w, viewport.h);
|
||||
}
|
||||
|
||||
renderQ = [];
|
||||
|
||||
// No benefit over default ("source-over") in Chrome and firefox
|
||||
//c_ctx.globalCompositeOperation = "copy";
|
||||
};
|
||||
|
||||
that.fillRect = function(x, y, width, height, color) {
|
||||
setFillColor(color);
|
||||
c_ctx.fillRect(x - viewport.x, y - viewport.y, width, height);
|
||||
};
|
||||
|
||||
that.copyImage = function(old_x, old_y, new_x, new_y, w, h) {
|
||||
var x1 = old_x - viewport.x, y1 = old_y - viewport.y,
|
||||
x2 = new_x - viewport.x, y2 = new_y - viewport.y;
|
||||
c_ctx.drawImage(conf.target, x1, y1, w, h, x2, y2, w, h);
|
||||
};
|
||||
|
||||
|
||||
// Start updating a tile
|
||||
that.startTile = function(x, y, width, height, color) {
|
||||
var data, bgr, red, green, blue, i;
|
||||
tile_x = x;
|
||||
tile_y = y;
|
||||
if ((width === 16) && (height === 16)) {
|
||||
tile = tile16x16;
|
||||
} else {
|
||||
tile = c_ctx.createImageData(width, height);
|
||||
}
|
||||
data = tile.data;
|
||||
if (conf.prefer_js) {
|
||||
if (conf.true_color) {
|
||||
bgr = color;
|
||||
} else {
|
||||
bgr = conf.colourMap[color[0]];
|
||||
}
|
||||
red = bgr[2];
|
||||
green = bgr[1];
|
||||
blue = bgr[0];
|
||||
for (i = 0; i < (width * height * 4); i+=4) {
|
||||
data[i ] = red;
|
||||
data[i + 1] = green;
|
||||
data[i + 2] = blue;
|
||||
data[i + 3] = 255;
|
||||
}
|
||||
} else {
|
||||
that.fillRect(x, y, width, height, color);
|
||||
}
|
||||
};
|
||||
|
||||
// Update sub-rectangle of the current tile
|
||||
that.subTile = function(x, y, w, h, color) {
|
||||
var data, p, bgr, red, green, blue, width, j, i, xend, yend;
|
||||
if (conf.prefer_js) {
|
||||
data = tile.data;
|
||||
width = tile.width;
|
||||
if (conf.true_color) {
|
||||
bgr = color;
|
||||
} else {
|
||||
bgr = conf.colourMap[color[0]];
|
||||
}
|
||||
red = bgr[2];
|
||||
green = bgr[1];
|
||||
blue = bgr[0];
|
||||
xend = x + w;
|
||||
yend = y + h;
|
||||
for (j = y; j < yend; j += 1) {
|
||||
for (i = x; i < xend; i += 1) {
|
||||
p = (i + (j * width) ) * 4;
|
||||
data[p ] = red;
|
||||
data[p + 1] = green;
|
||||
data[p + 2] = blue;
|
||||
data[p + 3] = 255;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
that.fillRect(tile_x + x, tile_y + y, w, h, color);
|
||||
}
|
||||
};
|
||||
|
||||
// Draw the current tile to the screen
|
||||
that.finishTile = function() {
|
||||
if (conf.prefer_js) {
|
||||
c_ctx.putImageData(tile, tile_x - viewport.x, tile_y - viewport.y);
|
||||
}
|
||||
// else: No-op, if not prefer_js then already done by setSubTile
|
||||
};
|
||||
|
||||
rgbImageData = function(x, y, vx, vy, width, height, arr, offset) {
|
||||
var img, i, j, data;
|
||||
/*
|
||||
if ((x - v.x >= v.w) || (y - v.y >= v.h) ||
|
||||
(x - v.x + width < 0) || (y - v.y + height < 0)) {
|
||||
// Skipping because outside of viewport
|
||||
return;
|
||||
}
|
||||
*/
|
||||
img = c_ctx.createImageData(width, height);
|
||||
data = img.data;
|
||||
for (i=0, j=offset; i < (width * height * 4); i=i+4, j=j+3) {
|
||||
data[i ] = arr[j ];
|
||||
data[i + 1] = arr[j + 1];
|
||||
data[i + 2] = arr[j + 2];
|
||||
data[i + 3] = 255; // Set Alpha
|
||||
}
|
||||
c_ctx.putImageData(img, x - vx, y - vy);
|
||||
};
|
||||
|
||||
bgrxImageData = function(x, y, vx, vy, width, height, arr, offset) {
|
||||
var img, i, j, data;
|
||||
/*
|
||||
if ((x - v.x >= v.w) || (y - v.y >= v.h) ||
|
||||
(x - v.x + width < 0) || (y - v.y + height < 0)) {
|
||||
// Skipping because outside of viewport
|
||||
return;
|
||||
}
|
||||
*/
|
||||
img = c_ctx.createImageData(width, height);
|
||||
data = img.data;
|
||||
for (i=0, j=offset; i < (width * height * 4); i=i+4, j=j+4) {
|
||||
data[i ] = arr[j + 2];
|
||||
data[i + 1] = arr[j + 1];
|
||||
data[i + 2] = arr[j ];
|
||||
data[i + 3] = 255; // Set Alpha
|
||||
}
|
||||
c_ctx.putImageData(img, x - vx, y - vy);
|
||||
};
|
||||
|
||||
cmapImageData = function(x, y, vx, vy, width, height, arr, offset) {
|
||||
var img, i, j, data, bgr, cmap;
|
||||
img = c_ctx.createImageData(width, height);
|
||||
data = img.data;
|
||||
cmap = conf.colourMap;
|
||||
for (i=0, j=offset; i < (width * height * 4); i+=4, j+=1) {
|
||||
bgr = cmap[arr[j]];
|
||||
data[i ] = bgr[2];
|
||||
data[i + 1] = bgr[1];
|
||||
data[i + 2] = bgr[0];
|
||||
data[i + 3] = 255; // Set Alpha
|
||||
}
|
||||
c_ctx.putImageData(img, x - vx, y - vy);
|
||||
};
|
||||
|
||||
that.blitImage = function(x, y, width, height, arr, offset) {
|
||||
if (conf.true_color) {
|
||||
bgrxImageData(x, y, viewport.x, viewport.y, width, height, arr, offset);
|
||||
} else {
|
||||
cmapImageData(x, y, viewport.x, viewport.y, width, height, arr, offset);
|
||||
}
|
||||
};
|
||||
|
||||
that.blitRgbImage = function(x, y, width, height, arr, offset) {
|
||||
if (conf.true_color) {
|
||||
rgbImageData(x, y, viewport.x, viewport.y, width, height, arr, offset);
|
||||
} else {
|
||||
// prolly wrong...
|
||||
cmapImageData(x, y, viewport.x, viewport.y, width, height, arr, offset);
|
||||
}
|
||||
};
|
||||
|
||||
that.blitStringImage = function(str, x, y) {
|
||||
var img = new Image();
|
||||
img.onload = function () {
|
||||
c_ctx.drawImage(img, x - viewport.x, y - viewport.y);
|
||||
};
|
||||
img.src = str;
|
||||
};
|
||||
|
||||
// Wrap ctx.drawImage but relative to viewport
|
||||
that.drawImage = function(img, x, y) {
|
||||
c_ctx.drawImage(img, x - viewport.x, y - viewport.y);
|
||||
};
|
||||
|
||||
that.renderQ_push = function(action) {
|
||||
renderQ.push(action);
|
||||
if (renderQ.length === 1) {
|
||||
// If this can be rendered immediately it will be, otherwise
|
||||
// the scanner will start polling the queue (every
|
||||
// requestAnimationFrame interval)
|
||||
scan_renderQ();
|
||||
}
|
||||
};
|
||||
|
||||
scan_renderQ = function() {
|
||||
var a, ready = true;
|
||||
while (ready && renderQ.length > 0) {
|
||||
a = renderQ[0];
|
||||
switch (a.type) {
|
||||
case 'copy':
|
||||
that.copyImage(a.old_x, a.old_y, a.x, a.y, a.width, a.height);
|
||||
break;
|
||||
case 'fill':
|
||||
that.fillRect(a.x, a.y, a.width, a.height, a.color);
|
||||
break;
|
||||
case 'blit':
|
||||
that.blitImage(a.x, a.y, a.width, a.height, a.data, 0);
|
||||
break;
|
||||
case 'blitRgb':
|
||||
that.blitRgbImage(a.x, a.y, a.width, a.height, a.data, 0);
|
||||
break;
|
||||
case 'img':
|
||||
if (a.img.complete) {
|
||||
that.drawImage(a.img, a.x, a.y);
|
||||
} else {
|
||||
// We need to wait for this image to 'load'
|
||||
// to keep things in-order
|
||||
ready = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (ready) {
|
||||
a = renderQ.shift();
|
||||
}
|
||||
}
|
||||
if (renderQ.length > 0) {
|
||||
requestAnimFrame(scan_renderQ);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
that.changeCursor = function(pixels, mask, hotx, hoty, w, h) {
|
||||
if (conf.cursor_uri === false) {
|
||||
Util.Warn("changeCursor called but no cursor data URI support");
|
||||
return;
|
||||
}
|
||||
|
||||
if (conf.true_color) {
|
||||
changeCursor(conf.target, pixels, mask, hotx, hoty, w, h);
|
||||
} else {
|
||||
changeCursor(conf.target, pixels, mask, hotx, hoty, w, h, conf.colourMap);
|
||||
}
|
||||
};
|
||||
|
||||
that.defaultCursor = function() {
|
||||
conf.target.style.cursor = "default";
|
||||
};
|
||||
|
||||
return constructor(); // Return the public API interface
|
||||
|
||||
} // End of Display()
|
||||
|
||||
|
||||
/* Set CSS cursor property using data URI encoded cursor file */
|
||||
function changeCursor(target, pixels, mask, hotx, hoty, w0, h0, cmap) {
|
||||
"use strict";
|
||||
var cur = [], rgb, IHDRsz, RGBsz, ANDsz, XORsz, url, idx, alpha, x, y;
|
||||
//Util.Debug(">> changeCursor, x: " + hotx + ", y: " + hoty + ", w0: " + w0 + ", h0: " + h0);
|
||||
|
||||
var w = w0;
|
||||
var h = h0;
|
||||
if (h < w)
|
||||
h = w; // increase h to make it square
|
||||
else
|
||||
w = h; // increace w to make it square
|
||||
|
||||
// Push multi-byte little-endian values
|
||||
cur.push16le = function (num) {
|
||||
this.push((num ) & 0xFF,
|
||||
(num >> 8) & 0xFF );
|
||||
};
|
||||
cur.push32le = function (num) {
|
||||
this.push((num ) & 0xFF,
|
||||
(num >> 8) & 0xFF,
|
||||
(num >> 16) & 0xFF,
|
||||
(num >> 24) & 0xFF );
|
||||
};
|
||||
|
||||
IHDRsz = 40;
|
||||
RGBsz = w * h * 4;
|
||||
XORsz = Math.ceil( (w * h) / 8.0 );
|
||||
ANDsz = Math.ceil( (w * h) / 8.0 );
|
||||
|
||||
// Main header
|
||||
cur.push16le(0); // 0: Reserved
|
||||
cur.push16le(2); // 2: .CUR type
|
||||
cur.push16le(1); // 4: Number of images, 1 for non-animated ico
|
||||
|
||||
// Cursor #1 header (ICONDIRENTRY)
|
||||
cur.push(w); // 6: width
|
||||
cur.push(h); // 7: height
|
||||
cur.push(0); // 8: colors, 0 -> true-color
|
||||
cur.push(0); // 9: reserved
|
||||
cur.push16le(hotx); // 10: hotspot x coordinate
|
||||
cur.push16le(hoty); // 12: hotspot y coordinate
|
||||
cur.push32le(IHDRsz + RGBsz + XORsz + ANDsz);
|
||||
// 14: cursor data byte size
|
||||
cur.push32le(22); // 18: offset of cursor data in the file
|
||||
|
||||
|
||||
// Cursor #1 InfoHeader (ICONIMAGE/BITMAPINFO)
|
||||
cur.push32le(IHDRsz); // 22: Infoheader size
|
||||
cur.push32le(w); // 26: Cursor width
|
||||
cur.push32le(h*2); // 30: XOR+AND height
|
||||
cur.push16le(1); // 34: number of planes
|
||||
cur.push16le(32); // 36: bits per pixel
|
||||
cur.push32le(0); // 38: Type of compression
|
||||
|
||||
cur.push32le(XORsz + ANDsz); // 43: Size of Image
|
||||
// Gimp leaves this as 0
|
||||
|
||||
cur.push32le(0); // 46: reserved
|
||||
cur.push32le(0); // 50: reserved
|
||||
cur.push32le(0); // 54: reserved
|
||||
cur.push32le(0); // 58: reserved
|
||||
|
||||
// 62: color data (RGBQUAD icColors[])
|
||||
for (y = h-1; y >= 0; y -= 1) {
|
||||
for (x = 0; x < w; x += 1) {
|
||||
if (x >= w0 || y >= h0) {
|
||||
cur.push(0); // blue
|
||||
cur.push(0); // green
|
||||
cur.push(0); // red
|
||||
cur.push(0); // alpha
|
||||
} else {
|
||||
idx = y * Math.ceil(w0 / 8) + Math.floor(x/8);
|
||||
alpha = (mask[idx] << (x % 8)) & 0x80 ? 255 : 0;
|
||||
if (cmap) {
|
||||
idx = (w0 * y) + x;
|
||||
rgb = cmap[pixels[idx]];
|
||||
cur.push(rgb[2]); // blue
|
||||
cur.push(rgb[1]); // green
|
||||
cur.push(rgb[0]); // red
|
||||
cur.push(alpha); // alpha
|
||||
} else {
|
||||
idx = ((w0 * y) + x) * 4;
|
||||
cur.push(pixels[idx + 2]); // blue
|
||||
cur.push(pixels[idx + 1]); // green
|
||||
cur.push(pixels[idx ]); // red
|
||||
cur.push(alpha); // alpha
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// XOR/bitmask data (BYTE icXOR[])
|
||||
// (ignored, just needs to be right size)
|
||||
for (y = 0; y < h; y += 1) {
|
||||
for (x = 0; x < Math.ceil(w / 8); x += 1) {
|
||||
cur.push(0x00);
|
||||
}
|
||||
}
|
||||
|
||||
// AND/bitmask data (BYTE icAND[])
|
||||
// (ignored, just needs to be right size)
|
||||
for (y = 0; y < h; y += 1) {
|
||||
for (x = 0; x < Math.ceil(w / 8); x += 1) {
|
||||
cur.push(0x00);
|
||||
}
|
||||
}
|
||||
|
||||
url = "data:image/x-icon;base64," + Base64.encode(cur);
|
||||
target.style.cursor = "url(" + url + ") " + hotx + " " + hoty + ", default";
|
||||
//Util.Debug("<< changeCursor, cur.length: " + cur.length);
|
||||
}
|
1946
static/js/novnc/input.js
Normal file
1946
static/js/novnc/input.js
Normal file
File diff suppressed because it is too large
Load diff
676
static/js/novnc/jsunzip.js
Executable file
676
static/js/novnc/jsunzip.js
Executable file
|
@ -0,0 +1,676 @@
|
|||
/*
|
||||
* JSUnzip
|
||||
*
|
||||
* Copyright (c) 2011 by Erik Moller
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This software is provided 'as-is', without any express
|
||||
* or implied warranty. In no event will the authors be
|
||||
* held liable for any damages arising from the use of
|
||||
* this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software
|
||||
* for any purpose, including commercial applications,
|
||||
* and to alter it and redistribute it freely, subject to
|
||||
* the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be
|
||||
* misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this
|
||||
* software in a product, an acknowledgment in
|
||||
* the product documentation would be appreciated
|
||||
* but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked
|
||||
* as such, and must not be misrepresented as
|
||||
* being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from
|
||||
* any source distribution.
|
||||
*/
|
||||
|
||||
var tinf;
|
||||
|
||||
function JSUnzip() {
|
||||
|
||||
this.getInt = function(offset, size) {
|
||||
switch (size) {
|
||||
case 4:
|
||||
return (this.data.charCodeAt(offset + 3) & 0xff) << 24 |
|
||||
(this.data.charCodeAt(offset + 2) & 0xff) << 16 |
|
||||
(this.data.charCodeAt(offset + 1) & 0xff) << 8 |
|
||||
(this.data.charCodeAt(offset + 0) & 0xff);
|
||||
break;
|
||||
case 2:
|
||||
return (this.data.charCodeAt(offset + 1) & 0xff) << 8 |
|
||||
(this.data.charCodeAt(offset + 0) & 0xff);
|
||||
break;
|
||||
default:
|
||||
return this.data.charCodeAt(offset) & 0xff;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
this.getDOSDate = function(dosdate, dostime) {
|
||||
var day = dosdate & 0x1f;
|
||||
var month = ((dosdate >> 5) & 0xf) - 1;
|
||||
var year = 1980 + ((dosdate >> 9) & 0x7f)
|
||||
var second = (dostime & 0x1f) * 2;
|
||||
var minute = (dostime >> 5) & 0x3f;
|
||||
hour = (dostime >> 11) & 0x1f;
|
||||
return new Date(year, month, day, hour, minute, second);
|
||||
}
|
||||
|
||||
this.open = function(data) {
|
||||
this.data = data;
|
||||
this.files = [];
|
||||
|
||||
if (this.data.length < 22)
|
||||
return { 'status' : false, 'error' : 'Invalid data' };
|
||||
var endOfCentralDirectory = this.data.length - 22;
|
||||
while (endOfCentralDirectory >= 0 && this.getInt(endOfCentralDirectory, 4) != 0x06054b50)
|
||||
--endOfCentralDirectory;
|
||||
if (endOfCentralDirectory < 0)
|
||||
return { 'status' : false, 'error' : 'Invalid data' };
|
||||
if (this.getInt(endOfCentralDirectory + 4, 2) != 0 || this.getInt(endOfCentralDirectory + 6, 2) != 0)
|
||||
return { 'status' : false, 'error' : 'No multidisk support' };
|
||||
|
||||
var entriesInThisDisk = this.getInt(endOfCentralDirectory + 8, 2);
|
||||
var centralDirectoryOffset = this.getInt(endOfCentralDirectory + 16, 4);
|
||||
var globalCommentLength = this.getInt(endOfCentralDirectory + 20, 2);
|
||||
this.comment = this.data.slice(endOfCentralDirectory + 22, endOfCentralDirectory + 22 + globalCommentLength);
|
||||
|
||||
var fileOffset = centralDirectoryOffset;
|
||||
|
||||
for (var i = 0; i < entriesInThisDisk; ++i) {
|
||||
if (this.getInt(fileOffset + 0, 4) != 0x02014b50)
|
||||
return { 'status' : false, 'error' : 'Invalid data' };
|
||||
if (this.getInt(fileOffset + 6, 2) > 20)
|
||||
return { 'status' : false, 'error' : 'Unsupported version' };
|
||||
if (this.getInt(fileOffset + 8, 2) & 1)
|
||||
return { 'status' : false, 'error' : 'Encryption not implemented' };
|
||||
|
||||
var compressionMethod = this.getInt(fileOffset + 10, 2);
|
||||
if (compressionMethod != 0 && compressionMethod != 8)
|
||||
return { 'status' : false, 'error' : 'Unsupported compression method' };
|
||||
|
||||
var lastModFileTime = this.getInt(fileOffset + 12, 2);
|
||||
var lastModFileDate = this.getInt(fileOffset + 14, 2);
|
||||
var lastModifiedDate = this.getDOSDate(lastModFileDate, lastModFileTime);
|
||||
|
||||
var crc = this.getInt(fileOffset + 16, 4);
|
||||
// TODO: crc
|
||||
|
||||
var compressedSize = this.getInt(fileOffset + 20, 4);
|
||||
var uncompressedSize = this.getInt(fileOffset + 24, 4);
|
||||
|
||||
var fileNameLength = this.getInt(fileOffset + 28, 2);
|
||||
var extraFieldLength = this.getInt(fileOffset + 30, 2);
|
||||
var fileCommentLength = this.getInt(fileOffset + 32, 2);
|
||||
|
||||
var relativeOffsetOfLocalHeader = this.getInt(fileOffset + 42, 4);
|
||||
|
||||
var fileName = this.data.slice(fileOffset + 46, fileOffset + 46 + fileNameLength);
|
||||
var fileComment = this.data.slice(fileOffset + 46 + fileNameLength + extraFieldLength, fileOffset + 46 + fileNameLength + extraFieldLength + fileCommentLength);
|
||||
|
||||
if (this.getInt(relativeOffsetOfLocalHeader + 0, 4) != 0x04034b50)
|
||||
return { 'status' : false, 'error' : 'Invalid data' };
|
||||
var localFileNameLength = this.getInt(relativeOffsetOfLocalHeader + 26, 2);
|
||||
var localExtraFieldLength = this.getInt(relativeOffsetOfLocalHeader + 28, 2);
|
||||
var localFileContent = relativeOffsetOfLocalHeader + 30 + localFileNameLength + localExtraFieldLength;
|
||||
|
||||
this.files[fileName] =
|
||||
{
|
||||
'fileComment' : fileComment,
|
||||
'compressionMethod' : compressionMethod,
|
||||
'compressedSize' : compressedSize,
|
||||
'uncompressedSize' : uncompressedSize,
|
||||
'localFileContent' : localFileContent,
|
||||
'lastModifiedDate' : lastModifiedDate
|
||||
};
|
||||
|
||||
fileOffset += 46 + fileNameLength + extraFieldLength + fileCommentLength;
|
||||
}
|
||||
return { 'status' : true }
|
||||
};
|
||||
|
||||
|
||||
this.read = function(fileName) {
|
||||
var fileInfo = this.files[fileName];
|
||||
if (fileInfo) {
|
||||
if (fileInfo.compressionMethod == 8) {
|
||||
if (!tinf) {
|
||||
tinf = new TINF();
|
||||
tinf.init();
|
||||
}
|
||||
var result = tinf.uncompress(this.data, fileInfo.localFileContent);
|
||||
if (result.status == tinf.OK)
|
||||
return { 'status' : true, 'data' : result.data };
|
||||
else
|
||||
return { 'status' : false, 'error' : result.error };
|
||||
} else {
|
||||
return { 'status' : true, 'data' : this.data.slice(fileInfo.localFileContent, fileInfo.localFileContent + fileInfo.uncompressedSize) };
|
||||
}
|
||||
}
|
||||
return { 'status' : false, 'error' : "File '" + fileName + "' doesn't exist in zip" };
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* tinflate - tiny inflate
|
||||
*
|
||||
* Copyright (c) 2003 by Joergen Ibsen / Jibz
|
||||
* All Rights Reserved
|
||||
*
|
||||
* http://www.ibsensoftware.com/
|
||||
*
|
||||
* This software is provided 'as-is', without any express
|
||||
* or implied warranty. In no event will the authors be
|
||||
* held liable for any damages arising from the use of
|
||||
* this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software
|
||||
* for any purpose, including commercial applications,
|
||||
* and to alter it and redistribute it freely, subject to
|
||||
* the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be
|
||||
* misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this
|
||||
* software in a product, an acknowledgment in
|
||||
* the product documentation would be appreciated
|
||||
* but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked
|
||||
* as such, and must not be misrepresented as
|
||||
* being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from
|
||||
* any source distribution.
|
||||
*/
|
||||
|
||||
/*
|
||||
* tinflate javascript port by Erik Moller in May 2011.
|
||||
* emoller@opera.com
|
||||
*
|
||||
* read_bits() patched by mike@imidio.com to allow
|
||||
* reading more then 8 bits (needed in some zlib streams)
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
function TINF() {
|
||||
|
||||
this.OK = 0;
|
||||
this.DATA_ERROR = (-3);
|
||||
this.WINDOW_SIZE = 32768;
|
||||
|
||||
/* ------------------------------ *
|
||||
* -- internal data structures -- *
|
||||
* ------------------------------ */
|
||||
|
||||
this.TREE = function() {
|
||||
this.table = new Array(16); /* table of code length counts */
|
||||
this.trans = new Array(288); /* code -> symbol translation table */
|
||||
};
|
||||
|
||||
this.DATA = function(that) {
|
||||
this.source = '';
|
||||
this.sourceIndex = 0;
|
||||
this.tag = 0;
|
||||
this.bitcount = 0;
|
||||
|
||||
this.dest = [];
|
||||
|
||||
this.history = [];
|
||||
|
||||
this.ltree = new that.TREE(); /* dynamic length/symbol tree */
|
||||
this.dtree = new that.TREE(); /* dynamic distance tree */
|
||||
};
|
||||
|
||||
/* --------------------------------------------------- *
|
||||
* -- uninitialized global data (static structures) -- *
|
||||
* --------------------------------------------------- */
|
||||
|
||||
this.sltree = new this.TREE(); /* fixed length/symbol tree */
|
||||
this.sdtree = new this.TREE(); /* fixed distance tree */
|
||||
|
||||
/* extra bits and base tables for length codes */
|
||||
this.length_bits = new Array(30);
|
||||
this.length_base = new Array(30);
|
||||
|
||||
/* extra bits and base tables for distance codes */
|
||||
this.dist_bits = new Array(30);
|
||||
this.dist_base = new Array(30);
|
||||
|
||||
/* special ordering of code length codes */
|
||||
this.clcidx = [
|
||||
16, 17, 18, 0, 8, 7, 9, 6,
|
||||
10, 5, 11, 4, 12, 3, 13, 2,
|
||||
14, 1, 15
|
||||
];
|
||||
|
||||
/* ----------------------- *
|
||||
* -- utility functions -- *
|
||||
* ----------------------- */
|
||||
|
||||
/* build extra bits and base tables */
|
||||
this.build_bits_base = function(bits, base, delta, first)
|
||||
{
|
||||
var i, sum;
|
||||
|
||||
/* build bits table */
|
||||
for (i = 0; i < delta; ++i) bits[i] = 0;
|
||||
for (i = 0; i < 30 - delta; ++i) bits[i + delta] = Math.floor(i / delta);
|
||||
|
||||
/* build base table */
|
||||
for (sum = first, i = 0; i < 30; ++i)
|
||||
{
|
||||
base[i] = sum;
|
||||
sum += 1 << bits[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* build the fixed huffman trees */
|
||||
this.build_fixed_trees = function(lt, dt)
|
||||
{
|
||||
var i;
|
||||
|
||||
/* build fixed length tree */
|
||||
for (i = 0; i < 7; ++i) lt.table[i] = 0;
|
||||
|
||||
lt.table[7] = 24;
|
||||
lt.table[8] = 152;
|
||||
lt.table[9] = 112;
|
||||
|
||||
for (i = 0; i < 24; ++i) lt.trans[i] = 256 + i;
|
||||
for (i = 0; i < 144; ++i) lt.trans[24 + i] = i;
|
||||
for (i = 0; i < 8; ++i) lt.trans[24 + 144 + i] = 280 + i;
|
||||
for (i = 0; i < 112; ++i) lt.trans[24 + 144 + 8 + i] = 144 + i;
|
||||
|
||||
/* build fixed distance tree */
|
||||
for (i = 0; i < 5; ++i) dt.table[i] = 0;
|
||||
|
||||
dt.table[5] = 32;
|
||||
|
||||
for (i = 0; i < 32; ++i) dt.trans[i] = i;
|
||||
}
|
||||
|
||||
/* given an array of code lengths, build a tree */
|
||||
this.build_tree = function(t, lengths, loffset, num)
|
||||
{
|
||||
var offs = new Array(16);
|
||||
var i, sum;
|
||||
|
||||
/* clear code length count table */
|
||||
for (i = 0; i < 16; ++i) t.table[i] = 0;
|
||||
|
||||
/* scan symbol lengths, and sum code length counts */
|
||||
for (i = 0; i < num; ++i) t.table[lengths[loffset + i]]++;
|
||||
|
||||
t.table[0] = 0;
|
||||
|
||||
/* compute offset table for distribution sort */
|
||||
for (sum = 0, i = 0; i < 16; ++i)
|
||||
{
|
||||
offs[i] = sum;
|
||||
sum += t.table[i];
|
||||
}
|
||||
|
||||
/* create code->symbol translation table (symbols sorted by code) */
|
||||
for (i = 0; i < num; ++i)
|
||||
{
|
||||
if (lengths[loffset + i]) t.trans[offs[lengths[loffset + i]]++] = i;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------- *
|
||||
* -- decode functions -- *
|
||||
* ---------------------- */
|
||||
|
||||
/* get one bit from source stream */
|
||||
this.getbit = function(d)
|
||||
{
|
||||
var bit;
|
||||
|
||||
/* check if tag is empty */
|
||||
if (!d.bitcount--)
|
||||
{
|
||||
/* load next tag */
|
||||
d.tag = d.source[d.sourceIndex++] & 0xff;
|
||||
d.bitcount = 7;
|
||||
}
|
||||
|
||||
/* shift bit out of tag */
|
||||
bit = d.tag & 0x01;
|
||||
d.tag >>= 1;
|
||||
|
||||
return bit;
|
||||
}
|
||||
|
||||
/* read a num bit value from a stream and add base */
|
||||
function read_bits_direct(source, bitcount, tag, idx, num)
|
||||
{
|
||||
var val = 0;
|
||||
while (bitcount < 24) {
|
||||
tag = tag | (source[idx++] & 0xff) << bitcount;
|
||||
bitcount += 8;
|
||||
}
|
||||
val = tag & (0xffff >> (16 - num));
|
||||
tag >>= num;
|
||||
bitcount -= num;
|
||||
return [bitcount, tag, idx, val];
|
||||
}
|
||||
this.read_bits = function(d, num, base)
|
||||
{
|
||||
if (!num)
|
||||
return base;
|
||||
|
||||
var ret = read_bits_direct(d.source, d.bitcount, d.tag, d.sourceIndex, num);
|
||||
d.bitcount = ret[0];
|
||||
d.tag = ret[1];
|
||||
d.sourceIndex = ret[2];
|
||||
return ret[3] + base;
|
||||
}
|
||||
|
||||
/* given a data stream and a tree, decode a symbol */
|
||||
this.decode_symbol = function(d, t)
|
||||
{
|
||||
while (d.bitcount < 16) {
|
||||
d.tag = d.tag | (d.source[d.sourceIndex++] & 0xff) << d.bitcount;
|
||||
d.bitcount += 8;
|
||||
}
|
||||
|
||||
var sum = 0, cur = 0, len = 0;
|
||||
do {
|
||||
cur = 2 * cur + ((d.tag & (1 << len)) >> len);
|
||||
|
||||
++len;
|
||||
|
||||
sum += t.table[len];
|
||||
cur -= t.table[len];
|
||||
|
||||
} while (cur >= 0);
|
||||
|
||||
d.tag >>= len;
|
||||
d.bitcount -= len;
|
||||
|
||||
return t.trans[sum + cur];
|
||||
}
|
||||
|
||||
/* given a data stream, decode dynamic trees from it */
|
||||
this.decode_trees = function(d, lt, dt)
|
||||
{
|
||||
var code_tree = new this.TREE();
|
||||
var lengths = new Array(288+32);
|
||||
var hlit, hdist, hclen;
|
||||
var i, num, length;
|
||||
|
||||
/* get 5 bits HLIT (257-286) */
|
||||
hlit = this.read_bits(d, 5, 257);
|
||||
|
||||
/* get 5 bits HDIST (1-32) */
|
||||
hdist = this.read_bits(d, 5, 1);
|
||||
|
||||
/* get 4 bits HCLEN (4-19) */
|
||||
hclen = this.read_bits(d, 4, 4);
|
||||
|
||||
for (i = 0; i < 19; ++i) lengths[i] = 0;
|
||||
|
||||
/* read code lengths for code length alphabet */
|
||||
for (i = 0; i < hclen; ++i)
|
||||
{
|
||||
/* get 3 bits code length (0-7) */
|
||||
var clen = this.read_bits(d, 3, 0);
|
||||
|
||||
lengths[this.clcidx[i]] = clen;
|
||||
}
|
||||
|
||||
/* build code length tree */
|
||||
this.build_tree(code_tree, lengths, 0, 19);
|
||||
|
||||
/* decode code lengths for the dynamic trees */
|
||||
for (num = 0; num < hlit + hdist; )
|
||||
{
|
||||
var sym = this.decode_symbol(d, code_tree);
|
||||
|
||||
switch (sym)
|
||||
{
|
||||
case 16:
|
||||
/* copy previous code length 3-6 times (read 2 bits) */
|
||||
{
|
||||
var prev = lengths[num - 1];
|
||||
for (length = this.read_bits(d, 2, 3); length; --length)
|
||||
{
|
||||
lengths[num++] = prev;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 17:
|
||||
/* repeat code length 0 for 3-10 times (read 3 bits) */
|
||||
for (length = this.read_bits(d, 3, 3); length; --length)
|
||||
{
|
||||
lengths[num++] = 0;
|
||||
}
|
||||
break;
|
||||
case 18:
|
||||
/* repeat code length 0 for 11-138 times (read 7 bits) */
|
||||
for (length = this.read_bits(d, 7, 11); length; --length)
|
||||
{
|
||||
lengths[num++] = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* values 0-15 represent the actual code lengths */
|
||||
lengths[num++] = sym;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* build dynamic trees */
|
||||
this.build_tree(lt, lengths, 0, hlit);
|
||||
this.build_tree(dt, lengths, hlit, hdist);
|
||||
}
|
||||
|
||||
/* ----------------------------- *
|
||||
* -- block inflate functions -- *
|
||||
* ----------------------------- */
|
||||
|
||||
/* given a stream and two trees, inflate a block of data */
|
||||
this.inflate_block_data = function(d, lt, dt)
|
||||
{
|
||||
// js optimization.
|
||||
var ddest = d.dest;
|
||||
var ddestlength = ddest.length;
|
||||
|
||||
while (1)
|
||||
{
|
||||
var sym = this.decode_symbol(d, lt);
|
||||
|
||||
/* check for end of block */
|
||||
if (sym == 256)
|
||||
{
|
||||
return this.OK;
|
||||
}
|
||||
|
||||
if (sym < 256)
|
||||
{
|
||||
ddest[ddestlength++] = sym; // ? String.fromCharCode(sym);
|
||||
d.history.push(sym);
|
||||
} else {
|
||||
|
||||
var length, dist, offs;
|
||||
var i;
|
||||
|
||||
sym -= 257;
|
||||
|
||||
/* possibly get more bits from length code */
|
||||
length = this.read_bits(d, this.length_bits[sym], this.length_base[sym]);
|
||||
|
||||
dist = this.decode_symbol(d, dt);
|
||||
|
||||
/* possibly get more bits from distance code */
|
||||
offs = d.history.length - this.read_bits(d, this.dist_bits[dist], this.dist_base[dist]);
|
||||
|
||||
if (offs < 0)
|
||||
throw ("Invalid zlib offset " + offs);
|
||||
|
||||
/* copy match */
|
||||
for (i = offs; i < offs + length; ++i) {
|
||||
//ddest[ddestlength++] = ddest[i];
|
||||
ddest[ddestlength++] = d.history[i];
|
||||
d.history.push(d.history[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* inflate an uncompressed block of data */
|
||||
this.inflate_uncompressed_block = function(d)
|
||||
{
|
||||
var length, invlength;
|
||||
var i;
|
||||
|
||||
if (d.bitcount > 7) {
|
||||
var overflow = Math.floor(d.bitcount / 8);
|
||||
d.sourceIndex -= overflow;
|
||||
d.bitcount = 0;
|
||||
d.tag = 0;
|
||||
}
|
||||
|
||||
/* get length */
|
||||
length = d.source[d.sourceIndex+1];
|
||||
length = 256*length + d.source[d.sourceIndex];
|
||||
|
||||
/* get one's complement of length */
|
||||
invlength = d.source[d.sourceIndex+3];
|
||||
invlength = 256*invlength + d.source[d.sourceIndex+2];
|
||||
|
||||
/* check length */
|
||||
if (length != (~invlength & 0x0000ffff)) return this.DATA_ERROR;
|
||||
|
||||
d.sourceIndex += 4;
|
||||
|
||||
/* copy block */
|
||||
for (i = length; i; --i) {
|
||||
d.history.push(d.source[d.sourceIndex]);
|
||||
d.dest[d.dest.length] = d.source[d.sourceIndex++];
|
||||
}
|
||||
|
||||
/* make sure we start next block on a byte boundary */
|
||||
d.bitcount = 0;
|
||||
|
||||
return this.OK;
|
||||
}
|
||||
|
||||
/* inflate a block of data compressed with fixed huffman trees */
|
||||
this.inflate_fixed_block = function(d)
|
||||
{
|
||||
/* decode block using fixed trees */
|
||||
return this.inflate_block_data(d, this.sltree, this.sdtree);
|
||||
}
|
||||
|
||||
/* inflate a block of data compressed with dynamic huffman trees */
|
||||
this.inflate_dynamic_block = function(d)
|
||||
{
|
||||
/* decode trees from stream */
|
||||
this.decode_trees(d, d.ltree, d.dtree);
|
||||
|
||||
/* decode block using decoded trees */
|
||||
return this.inflate_block_data(d, d.ltree, d.dtree);
|
||||
}
|
||||
|
||||
/* ---------------------- *
|
||||
* -- public functions -- *
|
||||
* ---------------------- */
|
||||
|
||||
/* initialize global (static) data */
|
||||
this.init = function()
|
||||
{
|
||||
/* build fixed huffman trees */
|
||||
this.build_fixed_trees(this.sltree, this.sdtree);
|
||||
|
||||
/* build extra bits and base tables */
|
||||
this.build_bits_base(this.length_bits, this.length_base, 4, 3);
|
||||
this.build_bits_base(this.dist_bits, this.dist_base, 2, 1);
|
||||
|
||||
/* fix a special case */
|
||||
this.length_bits[28] = 0;
|
||||
this.length_base[28] = 258;
|
||||
|
||||
this.reset();
|
||||
}
|
||||
|
||||
this.reset = function()
|
||||
{
|
||||
this.d = new this.DATA(this);
|
||||
delete this.header;
|
||||
}
|
||||
|
||||
/* inflate stream from source to dest */
|
||||
this.uncompress = function(source, offset)
|
||||
{
|
||||
|
||||
var d = this.d;
|
||||
var bfinal;
|
||||
|
||||
/* initialise data */
|
||||
d.source = source;
|
||||
d.sourceIndex = offset;
|
||||
d.bitcount = 0;
|
||||
|
||||
d.dest = [];
|
||||
|
||||
// Skip zlib header at start of stream
|
||||
if (typeof this.header == 'undefined') {
|
||||
this.header = this.read_bits(d, 16, 0);
|
||||
/* byte 0: 0x78, 7 = 32k window size, 8 = deflate */
|
||||
/* byte 1: check bits for header and other flags */
|
||||
}
|
||||
|
||||
var blocks = 0;
|
||||
|
||||
do {
|
||||
|
||||
var btype;
|
||||
var res;
|
||||
|
||||
/* read final block flag */
|
||||
bfinal = this.getbit(d);
|
||||
|
||||
/* read block type (2 bits) */
|
||||
btype = this.read_bits(d, 2, 0);
|
||||
|
||||
/* decompress block */
|
||||
switch (btype)
|
||||
{
|
||||
case 0:
|
||||
/* decompress uncompressed block */
|
||||
res = this.inflate_uncompressed_block(d);
|
||||
break;
|
||||
case 1:
|
||||
/* decompress block with fixed huffman trees */
|
||||
res = this.inflate_fixed_block(d);
|
||||
break;
|
||||
case 2:
|
||||
/* decompress block with dynamic huffman trees */
|
||||
res = this.inflate_dynamic_block(d);
|
||||
break;
|
||||
default:
|
||||
return { 'status' : this.DATA_ERROR };
|
||||
}
|
||||
|
||||
if (res != this.OK) return { 'status' : this.DATA_ERROR };
|
||||
blocks++;
|
||||
|
||||
} while (!bfinal && d.sourceIndex < d.source.length);
|
||||
|
||||
d.history = d.history.slice(-this.WINDOW_SIZE);
|
||||
|
||||
return { 'status' : this.OK, 'data' : d.dest };
|
||||
}
|
||||
|
||||
};
|
1
static/js/novnc/logo.js
Normal file
1
static/js/novnc/logo.js
Normal file
File diff suppressed because one or more lines are too long
102
static/js/novnc/playback.js
Normal file
102
static/js/novnc/playback.js
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2012 Joel Martin
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
/*jslint browser: true, white: false */
|
||||
/*global Util, VNC_frame_data, finish */
|
||||
|
||||
var rfb, mode, test_state, frame_idx, frame_length,
|
||||
iteration, iterations, istart_time,
|
||||
|
||||
// Pre-declarations for jslint
|
||||
send_array, next_iteration, queue_next_packet, do_packet;
|
||||
|
||||
// Override send_array
|
||||
send_array = function (arr) {
|
||||
// Stub out send_array
|
||||
};
|
||||
|
||||
next_iteration = function () {
|
||||
if (iteration === 0) {
|
||||
frame_length = VNC_frame_data.length;
|
||||
test_state = 'running';
|
||||
} else {
|
||||
rfb.disconnect();
|
||||
}
|
||||
|
||||
if (test_state !== 'running') { return; }
|
||||
|
||||
iteration += 1;
|
||||
if (iteration > iterations) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
frame_idx = 0;
|
||||
istart_time = (new Date()).getTime();
|
||||
rfb.connect('test', 0, "bogus");
|
||||
|
||||
queue_next_packet();
|
||||
|
||||
};
|
||||
|
||||
queue_next_packet = function () {
|
||||
var frame, foffset, toffset, delay;
|
||||
if (test_state !== 'running') { return; }
|
||||
|
||||
frame = VNC_frame_data[frame_idx];
|
||||
while ((frame_idx < frame_length) && (frame.charAt(0) === "}")) {
|
||||
//Util.Debug("Send frame " + frame_idx);
|
||||
frame_idx += 1;
|
||||
frame = VNC_frame_data[frame_idx];
|
||||
}
|
||||
|
||||
if (frame === 'EOF') {
|
||||
Util.Debug("Finished, found EOF");
|
||||
next_iteration();
|
||||
return;
|
||||
}
|
||||
if (frame_idx >= frame_length) {
|
||||
Util.Debug("Finished, no more frames");
|
||||
next_iteration();
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode === 'realtime') {
|
||||
foffset = frame.slice(1, frame.indexOf('{', 1));
|
||||
toffset = (new Date()).getTime() - istart_time;
|
||||
delay = foffset - toffset;
|
||||
if (delay < 1) {
|
||||
delay = 1;
|
||||
}
|
||||
|
||||
setTimeout(do_packet, delay);
|
||||
} else {
|
||||
setTimeout(do_packet, 1);
|
||||
}
|
||||
};
|
||||
|
||||
var bytes_processed = 0;
|
||||
|
||||
do_packet = function () {
|
||||
//Util.Debug("Processing frame: " + frame_idx);
|
||||
var frame = VNC_frame_data[frame_idx],
|
||||
start = frame.indexOf('{', 1) + 1;
|
||||
bytes_processed += frame.length - start;
|
||||
if (VNC_frame_encoding === 'binary') {
|
||||
var u8 = new Uint8Array(frame.length - start);
|
||||
for (var i = 0; i < frame.length - start; i++) {
|
||||
u8[i] = frame.charCodeAt(start + i);
|
||||
}
|
||||
rfb.recv_message({'data' : u8});
|
||||
} else {
|
||||
rfb.recv_message({'data' : frame.slice(start)});
|
||||
}
|
||||
frame_idx += 1;
|
||||
|
||||
queue_next_packet();
|
||||
};
|
||||
|
1866
static/js/novnc/rfb.js
Normal file
1866
static/js/novnc/rfb.js
Normal file
File diff suppressed because it is too large
Load diff
712
static/js/novnc/ui.js
Normal file
712
static/js/novnc/ui.js
Normal file
|
@ -0,0 +1,712 @@
|
|||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2012 Joel Martin
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
/*jslint white: false, browser: true */
|
||||
/*global window, $D, Util, WebUtil, RFB, Display */
|
||||
|
||||
// Load supporting scripts
|
||||
window.onscriptsload = function () { UI.load(); };
|
||||
Util.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js",
|
||||
"input.js", "display.js", "jsunzip.js", "rfb.js"]);
|
||||
|
||||
var UI = {
|
||||
|
||||
rfb_state : 'loaded',
|
||||
settingsOpen : false,
|
||||
connSettingsOpen : false,
|
||||
clipboardOpen: false,
|
||||
keyboardVisible: false,
|
||||
|
||||
// Setup rfb object, load settings from browser storage, then call
|
||||
// UI.init to setup the UI/menus
|
||||
load: function (callback) {
|
||||
WebUtil.initSettings(UI.start, callback);
|
||||
},
|
||||
|
||||
// Render default UI and initialize settings menu
|
||||
start: function(callback) {
|
||||
var html = '', i, sheet, sheets, llevels;
|
||||
|
||||
// Stylesheet selection dropdown
|
||||
sheet = WebUtil.selectStylesheet();
|
||||
sheets = WebUtil.getStylesheets();
|
||||
for (i = 0; i < sheets.length; i += 1) {
|
||||
UI.addOption($D('noVNC_stylesheet'),sheets[i].title, sheets[i].title);
|
||||
}
|
||||
|
||||
// Logging selection dropdown
|
||||
llevels = ['error', 'warn', 'info', 'debug'];
|
||||
for (i = 0; i < llevels.length; i += 1) {
|
||||
UI.addOption($D('noVNC_logging'),llevels[i], llevels[i]);
|
||||
}
|
||||
|
||||
// Settings with immediate effects
|
||||
UI.initSetting('logging', 'warn');
|
||||
WebUtil.init_logging(UI.getSetting('logging'));
|
||||
|
||||
UI.initSetting('stylesheet', 'default');
|
||||
WebUtil.selectStylesheet(null);
|
||||
// call twice to get around webkit bug
|
||||
WebUtil.selectStylesheet(UI.getSetting('stylesheet'));
|
||||
|
||||
/* Populate the controls if defaults are provided in the URL */
|
||||
UI.initSetting('host', window.location.hostname);
|
||||
UI.initSetting('port', window.location.port);
|
||||
UI.initSetting('password', '');
|
||||
UI.initSetting('encrypt', (window.location.protocol === "https:"));
|
||||
UI.initSetting('true_color', true);
|
||||
UI.initSetting('cursor', false);
|
||||
UI.initSetting('shared', true);
|
||||
UI.initSetting('view_only', false);
|
||||
UI.initSetting('connectTimeout', 2);
|
||||
UI.initSetting('path', 'websockify');
|
||||
UI.initSetting('repeaterID', '');
|
||||
|
||||
UI.rfb = RFB({'target': $D('noVNC_canvas'),
|
||||
'onUpdateState': UI.updateState,
|
||||
'onClipboard': UI.clipReceive});
|
||||
UI.updateVisualState();
|
||||
|
||||
// Unfocus clipboard when over the VNC area
|
||||
//$D('VNC_screen').onmousemove = function () {
|
||||
// var keyboard = UI.rfb.get_keyboard();
|
||||
// if ((! keyboard) || (! keyboard.get_focused())) {
|
||||
// $D('VNC_clipboard_text').blur();
|
||||
// }
|
||||
// };
|
||||
|
||||
// Show mouse selector buttons on touch screen devices
|
||||
if ('ontouchstart' in document.documentElement) {
|
||||
// Show mobile buttons
|
||||
$D('noVNC_mobile_buttons').style.display = "inline";
|
||||
UI.setMouseButton();
|
||||
// Remove the address bar
|
||||
setTimeout(function() { window.scrollTo(0, 1); }, 100);
|
||||
UI.forceSetting('clip', true);
|
||||
$D('noVNC_clip').disabled = true;
|
||||
} else {
|
||||
UI.initSetting('clip', false);
|
||||
}
|
||||
|
||||
//iOS Safari does not support CSS position:fixed.
|
||||
//This detects iOS devices and enables javascript workaround.
|
||||
if ((navigator.userAgent.match(/iPhone/i)) ||
|
||||
(navigator.userAgent.match(/iPod/i)) ||
|
||||
(navigator.userAgent.match(/iPad/i))) {
|
||||
//UI.setOnscroll();
|
||||
//UI.setResize();
|
||||
}
|
||||
UI.setBarPosition();
|
||||
|
||||
$D('noVNC_host').focus();
|
||||
|
||||
UI.setViewClip();
|
||||
Util.addEvent(window, 'resize', UI.setViewClip);
|
||||
|
||||
Util.addEvent(window, 'beforeunload', function () {
|
||||
if (UI.rfb_state === 'normal') {
|
||||
return "You are currently connected.";
|
||||
}
|
||||
} );
|
||||
|
||||
// Show description by default when hosted at for kanaka.github.com
|
||||
if (location.host === "kanaka.github.com") {
|
||||
// Open the description dialog
|
||||
$D('noVNC_description').style.display = "block";
|
||||
} else {
|
||||
// Open the connect panel on first load
|
||||
UI.toggleConnectPanel();
|
||||
}
|
||||
|
||||
// Add mouse event click/focus/blur event handlers to the UI
|
||||
UI.addMouseHandlers();
|
||||
|
||||
if (typeof callback === "function") {
|
||||
callback(UI.rfb);
|
||||
}
|
||||
},
|
||||
|
||||
addMouseHandlers: function() {
|
||||
// Setup interface handlers that can't be inline
|
||||
$D("noVNC_view_drag_button").onclick = UI.setViewDrag;
|
||||
$D("noVNC_mouse_button0").onclick = function () { UI.setMouseButton(1); };
|
||||
$D("noVNC_mouse_button1").onclick = function () { UI.setMouseButton(2); };
|
||||
$D("noVNC_mouse_button2").onclick = function () { UI.setMouseButton(4); };
|
||||
$D("noVNC_mouse_button4").onclick = function () { UI.setMouseButton(0); };
|
||||
$D("showKeyboard").onclick = UI.showKeyboard;
|
||||
//$D("keyboardinput").onkeydown = function (event) { onKeyDown(event); };
|
||||
$D("keyboardinput").onblur = UI.keyInputBlur;
|
||||
|
||||
$D("sendCtrlAltDelButton").onclick = UI.sendCtrlAltDel;
|
||||
$D("clipboardButton").onclick = UI.toggleClipboardPanel;
|
||||
$D("settingsButton").onclick = UI.toggleSettingsPanel;
|
||||
$D("connectButton").onclick = UI.toggleConnectPanel;
|
||||
$D("disconnectButton").onclick = UI.disconnect;
|
||||
$D("descriptionButton").onclick = UI.toggleConnectPanel;
|
||||
|
||||
$D("noVNC_clipboard_text").onfocus = UI.displayBlur;
|
||||
$D("noVNC_clipboard_text").onblur = UI.displayFocus;
|
||||
$D("noVNC_clipboard_text").onchange = UI.clipSend;
|
||||
$D("noVNC_clipboard_clear_button").onclick = UI.clipClear;
|
||||
|
||||
$D("noVNC_settings_menu").onmouseover = UI.displayBlur;
|
||||
$D("noVNC_settings_menu").onmouseover = UI.displayFocus;
|
||||
$D("noVNC_apply").onclick = UI.settingsApply;
|
||||
|
||||
$D("noVNC_connect_button").onclick = UI.connect;
|
||||
},
|
||||
|
||||
// Read form control compatible setting from cookie
|
||||
getSetting: function(name) {
|
||||
var val, ctrl = $D('noVNC_' + name);
|
||||
val = WebUtil.readSetting(name);
|
||||
if (val !== null && ctrl.type === 'checkbox') {
|
||||
if (val.toString().toLowerCase() in {'0':1, 'no':1, 'false':1}) {
|
||||
val = false;
|
||||
} else {
|
||||
val = true;
|
||||
}
|
||||
}
|
||||
return val;
|
||||
},
|
||||
|
||||
// Update cookie and form control setting. If value is not set, then
|
||||
// updates from control to current cookie setting.
|
||||
updateSetting: function(name, value) {
|
||||
|
||||
var i, ctrl = $D('noVNC_' + name);
|
||||
// Save the cookie for this session
|
||||
if (typeof value !== 'undefined') {
|
||||
WebUtil.writeSetting(name, value);
|
||||
}
|
||||
|
||||
// Update the settings control
|
||||
value = UI.getSetting(name);
|
||||
|
||||
if (ctrl.type === 'checkbox') {
|
||||
ctrl.checked = value;
|
||||
|
||||
} else if (typeof ctrl.options !== 'undefined') {
|
||||
for (i = 0; i < ctrl.options.length; i += 1) {
|
||||
if (ctrl.options[i].value === value) {
|
||||
ctrl.selectedIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/*Weird IE9 error leads to 'null' appearring
|
||||
in textboxes instead of ''.*/
|
||||
if (value === null) {
|
||||
value = "";
|
||||
}
|
||||
ctrl.value = value;
|
||||
}
|
||||
},
|
||||
|
||||
// Save control setting to cookie
|
||||
saveSetting: function(name) {
|
||||
var val, ctrl = $D('noVNC_' + name);
|
||||
if (ctrl.type === 'checkbox') {
|
||||
val = ctrl.checked;
|
||||
} else if (typeof ctrl.options !== 'undefined') {
|
||||
val = ctrl.options[ctrl.selectedIndex].value;
|
||||
} else {
|
||||
val = ctrl.value;
|
||||
}
|
||||
WebUtil.writeSetting(name, val);
|
||||
//Util.Debug("Setting saved '" + name + "=" + val + "'");
|
||||
return val;
|
||||
},
|
||||
|
||||
// Initial page load read/initialization of settings
|
||||
initSetting: function(name, defVal) {
|
||||
var val;
|
||||
|
||||
// Check Query string followed by cookie
|
||||
val = WebUtil.getQueryVar(name);
|
||||
if (val === null) {
|
||||
val = WebUtil.readSetting(name, defVal);
|
||||
}
|
||||
UI.updateSetting(name, val);
|
||||
//Util.Debug("Setting '" + name + "' initialized to '" + val + "'");
|
||||
return val;
|
||||
},
|
||||
|
||||
// Force a setting to be a certain value
|
||||
forceSetting: function(name, val) {
|
||||
UI.updateSetting(name, val);
|
||||
return val;
|
||||
},
|
||||
|
||||
|
||||
// Show the clipboard panel
|
||||
toggleClipboardPanel: function() {
|
||||
// Close the description panel
|
||||
$D('noVNC_description').style.display = "none";
|
||||
//Close settings if open
|
||||
if (UI.settingsOpen === true) {
|
||||
UI.settingsApply();
|
||||
UI.closeSettingsMenu();
|
||||
}
|
||||
//Close connection settings if open
|
||||
if (UI.connSettingsOpen === true) {
|
||||
UI.toggleConnectPanel();
|
||||
}
|
||||
//Toggle Clipboard Panel
|
||||
if (UI.clipboardOpen === true) {
|
||||
$D('noVNC_clipboard').style.display = "none";
|
||||
$D('clipboardButton').className = "noVNC_status_button";
|
||||
UI.clipboardOpen = false;
|
||||
} else {
|
||||
$D('noVNC_clipboard').style.display = "block";
|
||||
$D('clipboardButton').className = "noVNC_status_button_selected";
|
||||
UI.clipboardOpen = true;
|
||||
}
|
||||
},
|
||||
|
||||
// Show the connection settings panel/menu
|
||||
toggleConnectPanel: function() {
|
||||
// Close the description panel
|
||||
$D('noVNC_description').style.display = "none";
|
||||
//Close connection settings if open
|
||||
if (UI.settingsOpen === true) {
|
||||
UI.settingsApply();
|
||||
UI.closeSettingsMenu();
|
||||
$D('connectButton').className = "noVNC_status_button";
|
||||
}
|
||||
if (UI.clipboardOpen === true) {
|
||||
UI.toggleClipboardPanel();
|
||||
}
|
||||
|
||||
//Toggle Connection Panel
|
||||
if (UI.connSettingsOpen === true) {
|
||||
$D('noVNC_controls').style.display = "none";
|
||||
$D('connectButton').className = "noVNC_status_button";
|
||||
UI.connSettingsOpen = false;
|
||||
UI.saveSetting('host');
|
||||
UI.saveSetting('port');
|
||||
//UI.saveSetting('password');
|
||||
} else {
|
||||
$D('noVNC_controls').style.display = "block";
|
||||
$D('connectButton').className = "noVNC_status_button_selected";
|
||||
UI.connSettingsOpen = true;
|
||||
$D('noVNC_host').focus();
|
||||
}
|
||||
},
|
||||
|
||||
// Toggle the settings menu:
|
||||
// On open, settings are refreshed from saved cookies.
|
||||
// On close, settings are applied
|
||||
toggleSettingsPanel: function() {
|
||||
// Close the description panel
|
||||
$D('noVNC_description').style.display = "none";
|
||||
if (UI.settingsOpen) {
|
||||
UI.settingsApply();
|
||||
UI.closeSettingsMenu();
|
||||
} else {
|
||||
UI.updateSetting('encrypt');
|
||||
UI.updateSetting('true_color');
|
||||
if (UI.rfb.get_display().get_cursor_uri()) {
|
||||
UI.updateSetting('cursor');
|
||||
} else {
|
||||
UI.updateSetting('cursor', false);
|
||||
$D('noVNC_cursor').disabled = true;
|
||||
}
|
||||
UI.updateSetting('clip');
|
||||
UI.updateSetting('shared');
|
||||
UI.updateSetting('view_only');
|
||||
UI.updateSetting('connectTimeout');
|
||||
UI.updateSetting('path');
|
||||
UI.updateSetting('repeaterID');
|
||||
UI.updateSetting('stylesheet');
|
||||
UI.updateSetting('logging');
|
||||
|
||||
UI.openSettingsMenu();
|
||||
}
|
||||
},
|
||||
|
||||
// Open menu
|
||||
openSettingsMenu: function() {
|
||||
// Close the description panel
|
||||
$D('noVNC_description').style.display = "none";
|
||||
if (UI.clipboardOpen === true) {
|
||||
UI.toggleClipboardPanel();
|
||||
}
|
||||
//Close connection settings if open
|
||||
if (UI.connSettingsOpen === true) {
|
||||
UI.toggleConnectPanel();
|
||||
}
|
||||
$D('noVNC_settings').style.display = "block";
|
||||
$D('settingsButton').className = "noVNC_status_button_selected";
|
||||
UI.settingsOpen = true;
|
||||
},
|
||||
|
||||
// Close menu (without applying settings)
|
||||
closeSettingsMenu: function() {
|
||||
$D('noVNC_settings').style.display = "none";
|
||||
$D('settingsButton').className = "noVNC_status_button";
|
||||
UI.settingsOpen = false;
|
||||
},
|
||||
|
||||
// Save/apply settings when 'Apply' button is pressed
|
||||
settingsApply: function() {
|
||||
//Util.Debug(">> settingsApply");
|
||||
UI.saveSetting('encrypt');
|
||||
UI.saveSetting('true_color');
|
||||
if (UI.rfb.get_display().get_cursor_uri()) {
|
||||
UI.saveSetting('cursor');
|
||||
}
|
||||
UI.saveSetting('clip');
|
||||
UI.saveSetting('shared');
|
||||
UI.saveSetting('view_only');
|
||||
UI.saveSetting('connectTimeout');
|
||||
UI.saveSetting('path');
|
||||
UI.saveSetting('repeaterID');
|
||||
UI.saveSetting('stylesheet');
|
||||
UI.saveSetting('logging');
|
||||
|
||||
// Settings with immediate (non-connected related) effect
|
||||
WebUtil.selectStylesheet(UI.getSetting('stylesheet'));
|
||||
WebUtil.init_logging(UI.getSetting('logging'));
|
||||
UI.setViewClip();
|
||||
UI.setViewDrag(UI.rfb.get_viewportDrag());
|
||||
//Util.Debug("<< settingsApply");
|
||||
},
|
||||
|
||||
|
||||
|
||||
setPassword: function() {
|
||||
UI.rfb.sendPassword($D('noVNC_password').value);
|
||||
//Reset connect button.
|
||||
$D('noVNC_connect_button').value = "Connect";
|
||||
$D('noVNC_connect_button').onclick = UI.Connect;
|
||||
//Hide connection panel.
|
||||
UI.toggleConnectPanel();
|
||||
return false;
|
||||
},
|
||||
|
||||
sendCtrlAltDel: function() {
|
||||
UI.rfb.sendCtrlAltDel();
|
||||
},
|
||||
|
||||
setMouseButton: function(num) {
|
||||
var b, blist = [0, 1,2,4], button;
|
||||
|
||||
if (typeof num === 'undefined') {
|
||||
// Disable mouse buttons
|
||||
num = -1;
|
||||
}
|
||||
if (UI.rfb) {
|
||||
UI.rfb.get_mouse().set_touchButton(num);
|
||||
}
|
||||
|
||||
for (b = 0; b < blist.length; b++) {
|
||||
button = $D('noVNC_mouse_button' + blist[b]);
|
||||
if (blist[b] === num) {
|
||||
button.style.display = "";
|
||||
} else {
|
||||
button.style.display = "none";
|
||||
/*
|
||||
button.style.backgroundColor = "black";
|
||||
button.style.color = "lightgray";
|
||||
button.style.backgroundColor = "";
|
||||
button.style.color = "";
|
||||
*/
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
updateState: function(rfb, state, oldstate, msg) {
|
||||
var s, sb, c, d, cad, vd, klass;
|
||||
UI.rfb_state = state;
|
||||
s = $D('noVNC_status');
|
||||
sb = $D('noVNC_status_bar');
|
||||
switch (state) {
|
||||
case 'failed':
|
||||
case 'fatal':
|
||||
klass = "noVNC_status_error";
|
||||
break;
|
||||
case 'normal':
|
||||
klass = "noVNC_status_normal";
|
||||
break;
|
||||
case 'disconnected':
|
||||
$D('noVNC_logo').style.display = "block";
|
||||
// Fall through
|
||||
case 'loaded':
|
||||
klass = "noVNC_status_normal";
|
||||
break;
|
||||
case 'password':
|
||||
UI.toggleConnectPanel();
|
||||
|
||||
$D('noVNC_connect_button').value = "Send Password";
|
||||
$D('noVNC_connect_button').onclick = UI.setPassword;
|
||||
$D('noVNC_password').focus();
|
||||
|
||||
klass = "noVNC_status_warn";
|
||||
break;
|
||||
default:
|
||||
klass = "noVNC_status_warn";
|
||||
break;
|
||||
}
|
||||
|
||||
if (typeof(msg) !== 'undefined') {
|
||||
s.setAttribute("class", klass);
|
||||
sb.setAttribute("class", klass);
|
||||
s.innerHTML = msg;
|
||||
}
|
||||
|
||||
UI.updateVisualState();
|
||||
},
|
||||
|
||||
// Disable/enable controls depending on connection state
|
||||
updateVisualState: function() {
|
||||
var connected = UI.rfb_state === 'normal' ? true : false;
|
||||
|
||||
//Util.Debug(">> updateVisualState");
|
||||
$D('noVNC_encrypt').disabled = connected;
|
||||
$D('noVNC_true_color').disabled = connected;
|
||||
if (UI.rfb && UI.rfb.get_display() &&
|
||||
UI.rfb.get_display().get_cursor_uri()) {
|
||||
$D('noVNC_cursor').disabled = connected;
|
||||
} else {
|
||||
UI.updateSetting('cursor', false);
|
||||
$D('noVNC_cursor').disabled = true;
|
||||
}
|
||||
$D('noVNC_shared').disabled = connected;
|
||||
$D('noVNC_view_only').disabled = connected;
|
||||
$D('noVNC_connectTimeout').disabled = connected;
|
||||
$D('noVNC_path').disabled = connected;
|
||||
$D('noVNC_repeaterID').disabled = connected;
|
||||
|
||||
if (connected) {
|
||||
UI.setViewClip();
|
||||
UI.setMouseButton(1);
|
||||
$D('clipboardButton').style.display = "inline";
|
||||
$D('showKeyboard').style.display = "inline";
|
||||
$D('sendCtrlAltDelButton').style.display = "inline";
|
||||
} else {
|
||||
UI.setMouseButton();
|
||||
$D('clipboardButton').style.display = "none";
|
||||
$D('showKeyboard').style.display = "none";
|
||||
$D('sendCtrlAltDelButton').style.display = "none";
|
||||
}
|
||||
// State change disables viewport dragging.
|
||||
// It is enabled (toggled) by direct click on the button
|
||||
UI.setViewDrag(false);
|
||||
|
||||
switch (UI.rfb_state) {
|
||||
case 'fatal':
|
||||
case 'failed':
|
||||
case 'loaded':
|
||||
case 'disconnected':
|
||||
$D('connectButton').style.display = "";
|
||||
$D('disconnectButton').style.display = "none";
|
||||
break;
|
||||
default:
|
||||
$D('connectButton').style.display = "none";
|
||||
$D('disconnectButton').style.display = "";
|
||||
break;
|
||||
}
|
||||
|
||||
//Util.Debug("<< updateVisualState");
|
||||
},
|
||||
|
||||
|
||||
clipReceive: function(rfb, text) {
|
||||
Util.Debug(">> UI.clipReceive: " + text.substr(0,40) + "...");
|
||||
$D('noVNC_clipboard_text').value = text;
|
||||
Util.Debug("<< UI.clipReceive");
|
||||
},
|
||||
|
||||
|
||||
connect: function() {
|
||||
var host, port, password, path;
|
||||
|
||||
UI.closeSettingsMenu();
|
||||
UI.toggleConnectPanel();
|
||||
|
||||
host = $D('noVNC_host').value;
|
||||
port = $D('noVNC_port').value;
|
||||
password = $D('noVNC_password').value;
|
||||
path = $D('noVNC_path').value;
|
||||
if ((!host) || (!port)) {
|
||||
throw("Must set host and port");
|
||||
}
|
||||
|
||||
UI.rfb.set_encrypt(UI.getSetting('encrypt'));
|
||||
UI.rfb.set_true_color(UI.getSetting('true_color'));
|
||||
UI.rfb.set_local_cursor(UI.getSetting('cursor'));
|
||||
UI.rfb.set_shared(UI.getSetting('shared'));
|
||||
UI.rfb.set_view_only(UI.getSetting('view_only'));
|
||||
UI.rfb.set_connectTimeout(UI.getSetting('connectTimeout'));
|
||||
UI.rfb.set_repeaterID(UI.getSetting('repeaterID'));
|
||||
|
||||
UI.rfb.connect(host, port, password, path);
|
||||
|
||||
//Close dialog.
|
||||
setTimeout(UI.setBarPosition, 100);
|
||||
$D('noVNC_logo').style.display = "none";
|
||||
},
|
||||
|
||||
disconnect: function() {
|
||||
UI.closeSettingsMenu();
|
||||
UI.rfb.disconnect();
|
||||
|
||||
$D('noVNC_logo').style.display = "block";
|
||||
UI.connSettingsOpen = false;
|
||||
UI.toggleConnectPanel();
|
||||
},
|
||||
|
||||
displayBlur: function() {
|
||||
UI.rfb.get_keyboard().set_focused(false);
|
||||
UI.rfb.get_mouse().set_focused(false);
|
||||
},
|
||||
|
||||
displayFocus: function() {
|
||||
UI.rfb.get_keyboard().set_focused(true);
|
||||
UI.rfb.get_mouse().set_focused(true);
|
||||
},
|
||||
|
||||
clipClear: function() {
|
||||
$D('noVNC_clipboard_text').value = "";
|
||||
UI.rfb.clipboardPasteFrom("");
|
||||
},
|
||||
|
||||
clipSend: function() {
|
||||
var text = $D('noVNC_clipboard_text').value;
|
||||
Util.Debug(">> UI.clipSend: " + text.substr(0,40) + "...");
|
||||
UI.rfb.clipboardPasteFrom(text);
|
||||
Util.Debug("<< UI.clipSend");
|
||||
},
|
||||
|
||||
|
||||
// Enable/disable and configure viewport clipping
|
||||
setViewClip: function(clip) {
|
||||
var display, cur_clip, pos, new_w, new_h;
|
||||
|
||||
if (UI.rfb) {
|
||||
display = UI.rfb.get_display();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
cur_clip = display.get_viewport();
|
||||
|
||||
if (typeof(clip) !== 'boolean') {
|
||||
// Use current setting
|
||||
clip = UI.getSetting('clip');
|
||||
}
|
||||
|
||||
if (clip && !cur_clip) {
|
||||
// Turn clipping on
|
||||
UI.updateSetting('clip', true);
|
||||
} else if (!clip && cur_clip) {
|
||||
// Turn clipping off
|
||||
UI.updateSetting('clip', false);
|
||||
display.set_viewport(false);
|
||||
$D('noVNC_canvas').style.position = 'static';
|
||||
display.viewportChange();
|
||||
}
|
||||
if (UI.getSetting('clip')) {
|
||||
// If clipping, update clipping settings
|
||||
$D('noVNC_canvas').style.position = 'absolute';
|
||||
pos = Util.getPosition($D('noVNC_canvas'));
|
||||
new_w = window.innerWidth - pos.x;
|
||||
new_h = window.innerHeight - pos.y;
|
||||
display.set_viewport(true);
|
||||
display.viewportChange(0, 0, new_w, new_h);
|
||||
}
|
||||
},
|
||||
|
||||
// Toggle/set/unset the viewport drag/move button
|
||||
setViewDrag: function(drag) {
|
||||
var vmb = $D('noVNC_view_drag_button');
|
||||
if (!UI.rfb) { return; }
|
||||
|
||||
if (UI.rfb_state === 'normal' &&
|
||||
UI.rfb.get_display().get_viewport()) {
|
||||
vmb.style.display = "inline";
|
||||
} else {
|
||||
vmb.style.display = "none";
|
||||
}
|
||||
|
||||
if (typeof(drag) === "undefined" ||
|
||||
typeof(drag) === "object") {
|
||||
// If not specified, then toggle
|
||||
drag = !UI.rfb.get_viewportDrag();
|
||||
}
|
||||
if (drag) {
|
||||
vmb.className = "noVNC_status_button_selected";
|
||||
UI.rfb.set_viewportDrag(true);
|
||||
} else {
|
||||
vmb.className = "noVNC_status_button";
|
||||
UI.rfb.set_viewportDrag(false);
|
||||
}
|
||||
},
|
||||
|
||||
// On touch devices, show the OS keyboard
|
||||
showKeyboard: function() {
|
||||
if(UI.keyboardVisible === false) {
|
||||
$D('keyboardinput').focus();
|
||||
UI.keyboardVisible = true;
|
||||
$D('showKeyboard').className = "noVNC_status_button_selected";
|
||||
} else if(UI.keyboardVisible === true) {
|
||||
$D('keyboardinput').blur();
|
||||
$D('showKeyboard').className = "noVNC_status_button";
|
||||
UI.keyboardVisible = false;
|
||||
}
|
||||
},
|
||||
|
||||
keyInputBlur: function() {
|
||||
$D('showKeyboard').className = "noVNC_status_button";
|
||||
//Weird bug in iOS if you change keyboardVisible
|
||||
//here it does not actually occur so next time
|
||||
//you click keyboard icon it doesnt work.
|
||||
setTimeout(function() { UI.setKeyboard(); },100);
|
||||
},
|
||||
|
||||
setKeyboard: function() {
|
||||
UI.keyboardVisible = false;
|
||||
},
|
||||
|
||||
// iOS < Version 5 does not support position fixed. Javascript workaround:
|
||||
setOnscroll: function() {
|
||||
window.onscroll = function() {
|
||||
UI.setBarPosition();
|
||||
};
|
||||
},
|
||||
|
||||
setResize: function () {
|
||||
window.onResize = function() {
|
||||
UI.setBarPosition();
|
||||
};
|
||||
},
|
||||
|
||||
//Helper to add options to dropdown.
|
||||
addOption: function(selectbox,text,value )
|
||||
{
|
||||
var optn = document.createElement("OPTION");
|
||||
optn.text = text;
|
||||
optn.value = value;
|
||||
selectbox.options.add(optn);
|
||||
},
|
||||
|
||||
setBarPosition: function() {
|
||||
$D('noVNC-control-bar').style.top = (window.pageYOffset) + 'px';
|
||||
$D('noVNC_mobile_buttons').style.left = (window.pageXOffset) + 'px';
|
||||
|
||||
var vncwidth = $D('noVNC_screen').style.offsetWidth;
|
||||
$D('noVNC-control-bar').style.width = vncwidth + 'px';
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
381
static/js/novnc/util.js
Normal file
381
static/js/novnc/util.js
Normal file
|
@ -0,0 +1,381 @@
|
|||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2012 Joel Martin
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
/*jslint bitwise: false, white: false */
|
||||
/*global window, console, document, navigator, ActiveXObject */
|
||||
|
||||
// Globals defined here
|
||||
var Util = {};
|
||||
|
||||
|
||||
/*
|
||||
* Make arrays quack
|
||||
*/
|
||||
|
||||
Array.prototype.push8 = function (num) {
|
||||
this.push(num & 0xFF);
|
||||
};
|
||||
|
||||
Array.prototype.push16 = function (num) {
|
||||
this.push((num >> 8) & 0xFF,
|
||||
(num ) & 0xFF );
|
||||
};
|
||||
Array.prototype.push32 = function (num) {
|
||||
this.push((num >> 24) & 0xFF,
|
||||
(num >> 16) & 0xFF,
|
||||
(num >> 8) & 0xFF,
|
||||
(num ) & 0xFF );
|
||||
};
|
||||
|
||||
// IE does not support map (even in IE9)
|
||||
//This prototype is provided by the Mozilla foundation and
|
||||
//is distributed under the MIT license.
|
||||
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
|
||||
if (!Array.prototype.map)
|
||||
{
|
||||
Array.prototype.map = function(fun /*, thisp*/)
|
||||
{
|
||||
var len = this.length;
|
||||
if (typeof fun != "function")
|
||||
throw new TypeError();
|
||||
|
||||
var res = new Array(len);
|
||||
var thisp = arguments[1];
|
||||
for (var i = 0; i < len; i++)
|
||||
{
|
||||
if (i in this)
|
||||
res[i] = fun.call(thisp, this[i], i, this);
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
// requestAnimationFrame shim with setTimeout fallback
|
||||
//
|
||||
|
||||
window.requestAnimFrame = (function(){
|
||||
return window.requestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
window.mozRequestAnimationFrame ||
|
||||
window.oRequestAnimationFrame ||
|
||||
window.msRequestAnimationFrame ||
|
||||
function(callback){
|
||||
window.setTimeout(callback, 1000 / 60);
|
||||
};
|
||||
})();
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Namespaced in Util
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Logging/debug routines
|
||||
*/
|
||||
|
||||
Util._log_level = 'warn';
|
||||
Util.init_logging = function (level) {
|
||||
if (typeof level === 'undefined') {
|
||||
level = Util._log_level;
|
||||
} else {
|
||||
Util._log_level = level;
|
||||
}
|
||||
if (typeof window.console === "undefined") {
|
||||
if (typeof window.opera !== "undefined") {
|
||||
window.console = {
|
||||
'log' : window.opera.postError,
|
||||
'warn' : window.opera.postError,
|
||||
'error': window.opera.postError };
|
||||
} else {
|
||||
window.console = {
|
||||
'log' : function(m) {},
|
||||
'warn' : function(m) {},
|
||||
'error': function(m) {}};
|
||||
}
|
||||
}
|
||||
|
||||
Util.Debug = Util.Info = Util.Warn = Util.Error = function (msg) {};
|
||||
switch (level) {
|
||||
case 'debug': Util.Debug = function (msg) { console.log(msg); };
|
||||
case 'info': Util.Info = function (msg) { console.log(msg); };
|
||||
case 'warn': Util.Warn = function (msg) { console.warn(msg); };
|
||||
case 'error': Util.Error = function (msg) { console.error(msg); };
|
||||
case 'none':
|
||||
break;
|
||||
default:
|
||||
throw("invalid logging type '" + level + "'");
|
||||
}
|
||||
};
|
||||
Util.get_logging = function () {
|
||||
return Util._log_level;
|
||||
};
|
||||
// Initialize logging level
|
||||
Util.init_logging();
|
||||
|
||||
|
||||
// Set configuration default for Crockford style function namespaces
|
||||
Util.conf_default = function(cfg, api, defaults, v, mode, type, defval, desc) {
|
||||
var getter, setter;
|
||||
|
||||
// Default getter function
|
||||
getter = function (idx) {
|
||||
if ((type in {'arr':1, 'array':1}) &&
|
||||
(typeof idx !== 'undefined')) {
|
||||
return cfg[v][idx];
|
||||
} else {
|
||||
return cfg[v];
|
||||
}
|
||||
};
|
||||
|
||||
// Default setter function
|
||||
setter = function (val, idx) {
|
||||
if (type in {'boolean':1, 'bool':1}) {
|
||||
if ((!val) || (val in {'0':1, 'no':1, 'false':1})) {
|
||||
val = false;
|
||||
} else {
|
||||
val = true;
|
||||
}
|
||||
} else if (type in {'integer':1, 'int':1}) {
|
||||
val = parseInt(val, 10);
|
||||
} else if (type === 'str') {
|
||||
val = String(val);
|
||||
} else if (type === 'func') {
|
||||
if (!val) {
|
||||
val = function () {};
|
||||
}
|
||||
}
|
||||
if (typeof idx !== 'undefined') {
|
||||
cfg[v][idx] = val;
|
||||
} else {
|
||||
cfg[v] = val;
|
||||
}
|
||||
};
|
||||
|
||||
// Set the description
|
||||
api[v + '_description'] = desc;
|
||||
|
||||
// Set the getter function
|
||||
if (typeof api['get_' + v] === 'undefined') {
|
||||
api['get_' + v] = getter;
|
||||
}
|
||||
|
||||
// Set the setter function with extra sanity checks
|
||||
if (typeof api['set_' + v] === 'undefined') {
|
||||
api['set_' + v] = function (val, idx) {
|
||||
if (mode in {'RO':1, 'ro':1}) {
|
||||
throw(v + " is read-only");
|
||||
} else if ((mode in {'WO':1, 'wo':1}) &&
|
||||
(typeof cfg[v] !== 'undefined')) {
|
||||
throw(v + " can only be set once");
|
||||
}
|
||||
setter(val, idx);
|
||||
};
|
||||
}
|
||||
|
||||
// Set the default value
|
||||
if (typeof defaults[v] !== 'undefined') {
|
||||
defval = defaults[v];
|
||||
} else if ((type in {'arr':1, 'array':1}) &&
|
||||
(! (defval instanceof Array))) {
|
||||
defval = [];
|
||||
}
|
||||
// Coerce existing setting to the right type
|
||||
//Util.Debug("v: " + v + ", defval: " + defval + ", defaults[v]: " + defaults[v]);
|
||||
setter(defval);
|
||||
};
|
||||
|
||||
// Set group of configuration defaults
|
||||
Util.conf_defaults = function(cfg, api, defaults, arr) {
|
||||
var i;
|
||||
for (i = 0; i < arr.length; i++) {
|
||||
Util.conf_default(cfg, api, defaults, arr[i][0], arr[i][1],
|
||||
arr[i][2], arr[i][3], arr[i][4]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Cross-browser routines
|
||||
*/
|
||||
|
||||
|
||||
// Dynamically load scripts without using document.write()
|
||||
// Reference: http://unixpapa.com/js/dyna.html
|
||||
//
|
||||
// Handles the case where load_scripts is invoked from a script that
|
||||
// itself is loaded via load_scripts. Once all scripts are loaded the
|
||||
// window.onscriptsloaded handler is called (if set).
|
||||
Util.get_include_uri = function() {
|
||||
return (typeof INCLUDE_URI !== "undefined") ? INCLUDE_URI : "/static/js/novnc/";
|
||||
}
|
||||
Util._loading_scripts = [];
|
||||
Util._pending_scripts = [];
|
||||
Util.load_scripts = function(files) {
|
||||
var head = document.getElementsByTagName('head')[0], script,
|
||||
ls = Util._loading_scripts, ps = Util._pending_scripts;
|
||||
for (var f=0; f<files.length; f++) {
|
||||
script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.src = Util.get_include_uri() + files[f];
|
||||
//console.log("loading script: " + script.src);
|
||||
script.onload = script.onreadystatechange = function (e) {
|
||||
while (ls.length > 0 && (ls[0].readyState === 'loaded' ||
|
||||
ls[0].readyState === 'complete')) {
|
||||
// For IE, append the script to trigger execution
|
||||
var s = ls.shift();
|
||||
//console.log("loaded script: " + s.src);
|
||||
head.appendChild(s);
|
||||
}
|
||||
if (!this.readyState ||
|
||||
(Util.Engine.presto && this.readyState === 'loaded') ||
|
||||
this.readyState === 'complete') {
|
||||
if (ps.indexOf(this) >= 0) {
|
||||
this.onload = this.onreadystatechange = null;
|
||||
//console.log("completed script: " + this.src);
|
||||
ps.splice(ps.indexOf(this), 1);
|
||||
|
||||
// Call window.onscriptsload after last script loads
|
||||
if (ps.length === 0 && window.onscriptsload) {
|
||||
window.onscriptsload();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
// In-order script execution tricks
|
||||
if (Util.Engine.trident) {
|
||||
// For IE wait until readyState is 'loaded' before
|
||||
// appending it which will trigger execution
|
||||
// http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
|
||||
ls.push(script);
|
||||
} else {
|
||||
// For webkit and firefox set async=false and append now
|
||||
// https://developer.mozilla.org/en-US/docs/HTML/Element/script
|
||||
script.async = false;
|
||||
head.appendChild(script);
|
||||
}
|
||||
ps.push(script);
|
||||
}
|
||||
}
|
||||
|
||||
// Get DOM element position on page
|
||||
Util.getPosition = function (obj) {
|
||||
var x = 0, y = 0;
|
||||
if (obj.offsetParent) {
|
||||
do {
|
||||
x += obj.offsetLeft;
|
||||
y += obj.offsetTop;
|
||||
obj = obj.offsetParent;
|
||||
} while (obj);
|
||||
}
|
||||
return {'x': x, 'y': y};
|
||||
};
|
||||
|
||||
// Get mouse event position in DOM element
|
||||
Util.getEventPosition = function (e, obj, scale) {
|
||||
var evt, docX, docY, pos;
|
||||
//if (!e) evt = window.event;
|
||||
evt = (e ? e : window.event);
|
||||
evt = (evt.changedTouches ? evt.changedTouches[0] : evt.touches ? evt.touches[0] : evt);
|
||||
if (evt.pageX || evt.pageY) {
|
||||
docX = evt.pageX;
|
||||
docY = evt.pageY;
|
||||
} else if (evt.clientX || evt.clientY) {
|
||||
docX = evt.clientX + document.body.scrollLeft +
|
||||
document.documentElement.scrollLeft;
|
||||
docY = evt.clientY + document.body.scrollTop +
|
||||
document.documentElement.scrollTop;
|
||||
}
|
||||
pos = Util.getPosition(obj);
|
||||
if (typeof scale === "undefined") {
|
||||
scale = 1;
|
||||
}
|
||||
var x = Math.max(Math.min(docX - pos.x, obj.width-1), 0);
|
||||
var y = Math.max(Math.min(docY - pos.y, obj.height-1), 0);
|
||||
return {'x': x / scale, 'y': y / scale};
|
||||
};
|
||||
|
||||
|
||||
// Event registration. Based on: http://www.scottandrew.com/weblog/articles/cbs-events
|
||||
Util.addEvent = function (obj, evType, fn){
|
||||
if (obj.attachEvent){
|
||||
var r = obj.attachEvent("on"+evType, fn);
|
||||
return r;
|
||||
} else if (obj.addEventListener){
|
||||
obj.addEventListener(evType, fn, false);
|
||||
return true;
|
||||
} else {
|
||||
throw("Handler could not be attached");
|
||||
}
|
||||
};
|
||||
|
||||
Util.removeEvent = function(obj, evType, fn){
|
||||
if (obj.detachEvent){
|
||||
var r = obj.detachEvent("on"+evType, fn);
|
||||
return r;
|
||||
} else if (obj.removeEventListener){
|
||||
obj.removeEventListener(evType, fn, false);
|
||||
return true;
|
||||
} else {
|
||||
throw("Handler could not be removed");
|
||||
}
|
||||
};
|
||||
|
||||
Util.stopEvent = function(e) {
|
||||
if (e.stopPropagation) { e.stopPropagation(); }
|
||||
else { e.cancelBubble = true; }
|
||||
|
||||
if (e.preventDefault) { e.preventDefault(); }
|
||||
else { e.returnValue = false; }
|
||||
};
|
||||
|
||||
|
||||
// Set browser engine versions. Based on mootools.
|
||||
Util.Features = {xpath: !!(document.evaluate), air: !!(window.runtime), query: !!(document.querySelector)};
|
||||
|
||||
Util.Engine = {
|
||||
// Version detection break in Opera 11.60 (errors on arguments.callee.caller reference)
|
||||
//'presto': (function() {
|
||||
// return (!window.opera) ? false : ((arguments.callee.caller) ? 960 : ((document.getElementsByClassName) ? 950 : 925)); }()),
|
||||
'presto': (function() { return (!window.opera) ? false : true; }()),
|
||||
|
||||
'trident': (function() {
|
||||
return (!window.ActiveXObject) ? false : ((window.XMLHttpRequest) ? ((document.querySelectorAll) ? 6 : 5) : 4); }()),
|
||||
'webkit': (function() {
|
||||
try { return (navigator.taintEnabled) ? false : ((Util.Features.xpath) ? ((Util.Features.query) ? 525 : 420) : 419); } catch (e) { return false; } }()),
|
||||
//'webkit': (function() {
|
||||
// return ((typeof navigator.taintEnabled !== "unknown") && navigator.taintEnabled) ? false : ((Util.Features.xpath) ? ((Util.Features.query) ? 525 : 420) : 419); }()),
|
||||
'gecko': (function() {
|
||||
return (!document.getBoxObjectFor && window.mozInnerScreenX == null) ? false : ((document.getElementsByClassName) ? 19 : 18); }())
|
||||
};
|
||||
if (Util.Engine.webkit) {
|
||||
// Extract actual webkit version if available
|
||||
Util.Engine.webkit = (function(v) {
|
||||
var re = new RegExp('WebKit/([0-9\.]*) ');
|
||||
v = (navigator.userAgent.match(re) || ['', v])[1];
|
||||
return parseFloat(v, 10);
|
||||
})(Util.Engine.webkit);
|
||||
}
|
||||
|
||||
Util.Flash = (function(){
|
||||
var v, version;
|
||||
try {
|
||||
v = navigator.plugins['Shockwave Flash'].description;
|
||||
} catch(err1) {
|
||||
try {
|
||||
v = new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version');
|
||||
} catch(err2) {
|
||||
v = '0 r0';
|
||||
}
|
||||
}
|
||||
version = v.match(/\d+/g);
|
||||
return {version: parseInt(version[0] || 0 + '.' + version[1], 10) || 0, build: parseInt(version[2], 10) || 0};
|
||||
}());
|
109
static/js/novnc/web-socket-js/README.txt
Normal file
109
static/js/novnc/web-socket-js/README.txt
Normal file
|
@ -0,0 +1,109 @@
|
|||
* How to try
|
||||
|
||||
Assuming you have Web server (e.g. Apache) running at http://example.com/ .
|
||||
|
||||
- Download web_socket.rb from:
|
||||
http://github.com/gimite/web-socket-ruby/tree/master
|
||||
- Run sample Web Socket server (echo server) in example.com with: (#1)
|
||||
$ ruby web-socket-ruby/samples/echo_server.rb example.com 10081
|
||||
- If your server already provides socket policy file at port 843, modify the file to allow access to port 10081. Otherwise you can skip this step. See below for details.
|
||||
- Publish the web-socket-js directory with your Web server (e.g. put it in ~/public_html).
|
||||
- Change ws://localhost:10081 to ws://example.com:10081 in sample.html.
|
||||
- Open sample.html in your browser.
|
||||
- After "onopen" is shown, input something, click [Send] and confirm echo back.
|
||||
|
||||
#1: First argument of echo_server.rb means that it accepts Web Socket connection from HTML pages in example.com.
|
||||
|
||||
|
||||
* Troubleshooting
|
||||
|
||||
If it doesn't work, try these:
|
||||
|
||||
1. Try Chrome and Firefox 3.x.
|
||||
- It doesn't work on Chrome:
|
||||
-- It's likely an issue of your code or the server. Debug your code as usual e.g. using console.log.
|
||||
- It works on Chrome but it doesn't work on Firefox:
|
||||
-- It's likely an issue of web-socket-js specific configuration (e.g. 3 and 4 below).
|
||||
- It works on both Chrome and Firefox, but it doesn't work on your browser:
|
||||
-- Check "Supported environment" section below. Your browser may not be supported by web-socket-js.
|
||||
|
||||
2. Add this line before your code:
|
||||
WEB_SOCKET_DEBUG = true;
|
||||
and use Developer Tools (Chrome/Safari) or Firebug (Firefox) to see if console.log outputs any errors.
|
||||
|
||||
3. Make sure you do NOT open your HTML page as local file e.g. file:///.../sample.html. web-socket-js doesn't work on local file. Open it via Web server e.g. http:///.../sample.html.
|
||||
|
||||
4. If you are NOT using web-socket-ruby as your WebSocket server, you need to place Flash socket policy file on your server. See "Flash socket policy file" section below for details.
|
||||
|
||||
5. Check if sample.html bundled with web-socket-js works.
|
||||
|
||||
6. Make sure the port used for WebSocket (10081 in example above) is not blocked by your server/client's firewall.
|
||||
|
||||
7. Install debugger version of Flash Player available here to see Flash errors:
|
||||
http://www.adobe.com/support/flashplayer/downloads.html
|
||||
|
||||
|
||||
* Supported environments
|
||||
|
||||
It should work on:
|
||||
- Google Chrome 4 or later (just uses native implementation)
|
||||
- Firefox 3.x, Internet Explorer 8 + Flash Player 9 or later
|
||||
|
||||
It may or may not work on other browsers such as Safari, Opera or IE 6. Patch for these browsers are appreciated, but I will not work on fixing issues specific to these browsers by myself.
|
||||
|
||||
|
||||
* Flash socket policy file
|
||||
|
||||
This implementation uses Flash's socket, which means that your server must provide Flash socket policy file to declare the server accepts connections from Flash.
|
||||
|
||||
If you use web-socket-ruby available at
|
||||
http://github.com/gimite/web-socket-ruby/tree/master
|
||||
, you don't need anything special, because web-socket-ruby handles Flash socket policy file request. But if you already provide socket policy file at port 843, you need to modify the file to allow access to Web Socket port, because it precedes what web-socket-ruby provides.
|
||||
|
||||
If you use other Web Socket server implementation, you need to provide socket policy file yourself. See
|
||||
http://www.lightsphere.com/dev/articles/flash_socket_policy.html
|
||||
for details and sample script to run socket policy file server. node.js implementation is available here:
|
||||
http://github.com/LearnBoost/Socket.IO-node/blob/master/lib/socket.io/transports/flashsocket.js
|
||||
|
||||
Actually, it's still better to provide socket policy file at port 843 even if you use web-socket-ruby. Flash always try to connect to port 843 first, so providing the file at port 843 makes startup faster.
|
||||
|
||||
|
||||
* Cookie considerations
|
||||
|
||||
Cookie is sent if Web Socket host is the same as the origin of JavaScript. Otherwise it is not sent, because I don't know way to send right Cookie (which is Cookie of the host of Web Socket, I heard).
|
||||
|
||||
Note that it's technically possible that client sends arbitrary string as Cookie and any other headers (by modifying this library for example) once you place Flash socket policy file in your server. So don't trust Cookie and other headers if you allow connection from untrusted origin.
|
||||
|
||||
|
||||
* Proxy considerations
|
||||
|
||||
The WebSocket spec (http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol) specifies instructions for User Agents to support proxied connections by implementing the HTTP CONNECT method.
|
||||
|
||||
The AS3 Socket class doesn't implement this mechanism, which renders it useless for the scenarios where the user trying to open a socket is behind a proxy.
|
||||
|
||||
The class RFC2817Socket (by Christian Cantrell) effectively lets us implement this, as long as the proxy settings are known and provided by the interface that instantiates the WebSocket. As such, if you want to support proxied conncetions, you'll have to supply this information to the WebSocket constructor when Flash is being used. One way to go about it would be to ask the user for proxy settings information if the initial connection fails.
|
||||
|
||||
|
||||
* How to host HTML file and SWF file in different domains
|
||||
|
||||
By default, HTML file and SWF file must be in the same domain. You can follow steps below to allow hosting them in different domain.
|
||||
|
||||
WARNING: If you use the method below, HTML files in ANY domains can send arbitrary TCP data to your WebSocket server, regardless of configuration in Flash socket policy file. Arbitrary TCP data means that they can even fake request headers including Origin and Cookie.
|
||||
|
||||
- Unzip WebSocketMainInsecure.zip to extract WebSocketMainInsecure.swf.
|
||||
- Put WebSocketMainInsecure.swf on your server, instead of WebSocketMain.swf.
|
||||
- In JavaScript, set WEB_SOCKET_SWF_LOCATION to URL of your WebSocketMainInsecure.swf.
|
||||
|
||||
|
||||
* How to build WebSocketMain.swf
|
||||
|
||||
Install Flex 4 SDK:
|
||||
http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4
|
||||
|
||||
$ cd flash-src
|
||||
$ ./build.sh
|
||||
|
||||
|
||||
* License
|
||||
|
||||
New BSD License.
|
BIN
static/js/novnc/web-socket-js/WebSocketMain.swf
Normal file
BIN
static/js/novnc/web-socket-js/WebSocketMain.swf
Normal file
Binary file not shown.
4
static/js/novnc/web-socket-js/swfobject.js
Normal file
4
static/js/novnc/web-socket-js/swfobject.js
Normal file
File diff suppressed because one or more lines are too long
391
static/js/novnc/web-socket-js/web_socket.js
Normal file
391
static/js/novnc/web-socket-js/web_socket.js
Normal file
|
@ -0,0 +1,391 @@
|
|||
// Copyright: Hiroshi Ichikawa <http://gimite.net/en/>
|
||||
// License: New BSD License
|
||||
// Reference: http://dev.w3.org/html5/websockets/
|
||||
// Reference: http://tools.ietf.org/html/rfc6455
|
||||
|
||||
(function() {
|
||||
|
||||
if (window.WEB_SOCKET_FORCE_FLASH) {
|
||||
// Keeps going.
|
||||
} else if (window.WebSocket) {
|
||||
return;
|
||||
} else if (window.MozWebSocket) {
|
||||
// Firefox.
|
||||
window.WebSocket = MozWebSocket;
|
||||
return;
|
||||
}
|
||||
|
||||
var logger;
|
||||
if (window.WEB_SOCKET_LOGGER) {
|
||||
logger = WEB_SOCKET_LOGGER;
|
||||
} else if (window.console && window.console.log && window.console.error) {
|
||||
// In some environment, console is defined but console.log or console.error is missing.
|
||||
logger = window.console;
|
||||
} else {
|
||||
logger = {log: function(){ }, error: function(){ }};
|
||||
}
|
||||
|
||||
// swfobject.hasFlashPlayerVersion("10.0.0") doesn't work with Gnash.
|
||||
if (swfobject.getFlashPlayerVersion().major < 10) {
|
||||
logger.error("Flash Player >= 10.0.0 is required.");
|
||||
return;
|
||||
}
|
||||
if (location.protocol == "file:") {
|
||||
logger.error(
|
||||
"WARNING: web-socket-js doesn't work in file:///... URL " +
|
||||
"unless you set Flash Security Settings properly. " +
|
||||
"Open the page via Web server i.e. http://...");
|
||||
}
|
||||
|
||||
/**
|
||||
* Our own implementation of WebSocket class using Flash.
|
||||
* @param {string} url
|
||||
* @param {array or string} protocols
|
||||
* @param {string} proxyHost
|
||||
* @param {int} proxyPort
|
||||
* @param {string} headers
|
||||
*/
|
||||
window.WebSocket = function(url, protocols, proxyHost, proxyPort, headers) {
|
||||
var self = this;
|
||||
self.__id = WebSocket.__nextId++;
|
||||
WebSocket.__instances[self.__id] = self;
|
||||
self.readyState = WebSocket.CONNECTING;
|
||||
self.bufferedAmount = 0;
|
||||
self.__events = {};
|
||||
if (!protocols) {
|
||||
protocols = [];
|
||||
} else if (typeof protocols == "string") {
|
||||
protocols = [protocols];
|
||||
}
|
||||
// Uses setTimeout() to make sure __createFlash() runs after the caller sets ws.onopen etc.
|
||||
// Otherwise, when onopen fires immediately, onopen is called before it is set.
|
||||
self.__createTask = setTimeout(function() {
|
||||
WebSocket.__addTask(function() {
|
||||
self.__createTask = null;
|
||||
WebSocket.__flash.create(
|
||||
self.__id, url, protocols, proxyHost || null, proxyPort || 0, headers || null);
|
||||
});
|
||||
}, 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* Send data to the web socket.
|
||||
* @param {string} data The data to send to the socket.
|
||||
* @return {boolean} True for success, false for failure.
|
||||
*/
|
||||
WebSocket.prototype.send = function(data) {
|
||||
if (this.readyState == WebSocket.CONNECTING) {
|
||||
throw "INVALID_STATE_ERR: Web Socket connection has not been established";
|
||||
}
|
||||
// We use encodeURIComponent() here, because FABridge doesn't work if
|
||||
// the argument includes some characters. We don't use escape() here
|
||||
// because of this:
|
||||
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Functions#escape_and_unescape_Functions
|
||||
// But it looks decodeURIComponent(encodeURIComponent(s)) doesn't
|
||||
// preserve all Unicode characters either e.g. "\uffff" in Firefox.
|
||||
// Note by wtritch: Hopefully this will not be necessary using ExternalInterface. Will require
|
||||
// additional testing.
|
||||
var result = WebSocket.__flash.send(this.__id, encodeURIComponent(data));
|
||||
if (result < 0) { // success
|
||||
return true;
|
||||
} else {
|
||||
this.bufferedAmount += result;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Close this web socket gracefully.
|
||||
*/
|
||||
WebSocket.prototype.close = function() {
|
||||
if (this.__createTask) {
|
||||
clearTimeout(this.__createTask);
|
||||
this.__createTask = null;
|
||||
this.readyState = WebSocket.CLOSED;
|
||||
return;
|
||||
}
|
||||
if (this.readyState == WebSocket.CLOSED || this.readyState == WebSocket.CLOSING) {
|
||||
return;
|
||||
}
|
||||
this.readyState = WebSocket.CLOSING;
|
||||
WebSocket.__flash.close(this.__id);
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
||||
*
|
||||
* @param {string} type
|
||||
* @param {function} listener
|
||||
* @param {boolean} useCapture
|
||||
* @return void
|
||||
*/
|
||||
WebSocket.prototype.addEventListener = function(type, listener, useCapture) {
|
||||
if (!(type in this.__events)) {
|
||||
this.__events[type] = [];
|
||||
}
|
||||
this.__events[type].push(listener);
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
||||
*
|
||||
* @param {string} type
|
||||
* @param {function} listener
|
||||
* @param {boolean} useCapture
|
||||
* @return void
|
||||
*/
|
||||
WebSocket.prototype.removeEventListener = function(type, listener, useCapture) {
|
||||
if (!(type in this.__events)) return;
|
||||
var events = this.__events[type];
|
||||
for (var i = events.length - 1; i >= 0; --i) {
|
||||
if (events[i] === listener) {
|
||||
events.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
||||
*
|
||||
* @param {Event} event
|
||||
* @return void
|
||||
*/
|
||||
WebSocket.prototype.dispatchEvent = function(event) {
|
||||
var events = this.__events[event.type] || [];
|
||||
for (var i = 0; i < events.length; ++i) {
|
||||
events[i](event);
|
||||
}
|
||||
var handler = this["on" + event.type];
|
||||
if (handler) handler.apply(this, [event]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles an event from Flash.
|
||||
* @param {Object} flashEvent
|
||||
*/
|
||||
WebSocket.prototype.__handleEvent = function(flashEvent) {
|
||||
|
||||
if ("readyState" in flashEvent) {
|
||||
this.readyState = flashEvent.readyState;
|
||||
}
|
||||
if ("protocol" in flashEvent) {
|
||||
this.protocol = flashEvent.protocol;
|
||||
}
|
||||
|
||||
var jsEvent;
|
||||
if (flashEvent.type == "open" || flashEvent.type == "error") {
|
||||
jsEvent = this.__createSimpleEvent(flashEvent.type);
|
||||
} else if (flashEvent.type == "close") {
|
||||
jsEvent = this.__createSimpleEvent("close");
|
||||
jsEvent.wasClean = flashEvent.wasClean ? true : false;
|
||||
jsEvent.code = flashEvent.code;
|
||||
jsEvent.reason = flashEvent.reason;
|
||||
} else if (flashEvent.type == "message") {
|
||||
var data = decodeURIComponent(flashEvent.message);
|
||||
jsEvent = this.__createMessageEvent("message", data);
|
||||
} else {
|
||||
throw "unknown event type: " + flashEvent.type;
|
||||
}
|
||||
|
||||
this.dispatchEvent(jsEvent);
|
||||
|
||||
};
|
||||
|
||||
WebSocket.prototype.__createSimpleEvent = function(type) {
|
||||
if (document.createEvent && window.Event) {
|
||||
var event = document.createEvent("Event");
|
||||
event.initEvent(type, false, false);
|
||||
return event;
|
||||
} else {
|
||||
return {type: type, bubbles: false, cancelable: false};
|
||||
}
|
||||
};
|
||||
|
||||
WebSocket.prototype.__createMessageEvent = function(type, data) {
|
||||
if (document.createEvent && window.MessageEvent && !window.opera) {
|
||||
var event = document.createEvent("MessageEvent");
|
||||
event.initMessageEvent("message", false, false, data, null, null, window, null);
|
||||
return event;
|
||||
} else {
|
||||
// IE and Opera, the latter one truncates the data parameter after any 0x00 bytes.
|
||||
return {type: type, data: data, bubbles: false, cancelable: false};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Define the WebSocket readyState enumeration.
|
||||
*/
|
||||
WebSocket.CONNECTING = 0;
|
||||
WebSocket.OPEN = 1;
|
||||
WebSocket.CLOSING = 2;
|
||||
WebSocket.CLOSED = 3;
|
||||
|
||||
// Field to check implementation of WebSocket.
|
||||
WebSocket.__isFlashImplementation = true;
|
||||
WebSocket.__initialized = false;
|
||||
WebSocket.__flash = null;
|
||||
WebSocket.__instances = {};
|
||||
WebSocket.__tasks = [];
|
||||
WebSocket.__nextId = 0;
|
||||
|
||||
/**
|
||||
* Load a new flash security policy file.
|
||||
* @param {string} url
|
||||
*/
|
||||
WebSocket.loadFlashPolicyFile = function(url){
|
||||
WebSocket.__addTask(function() {
|
||||
WebSocket.__flash.loadManualPolicyFile(url);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Loads WebSocketMain.swf and creates WebSocketMain object in Flash.
|
||||
*/
|
||||
WebSocket.__initialize = function() {
|
||||
|
||||
if (WebSocket.__initialized) return;
|
||||
WebSocket.__initialized = true;
|
||||
|
||||
if (WebSocket.__swfLocation) {
|
||||
// For backword compatibility.
|
||||
window.WEB_SOCKET_SWF_LOCATION = WebSocket.__swfLocation;
|
||||
}
|
||||
if (!window.WEB_SOCKET_SWF_LOCATION) {
|
||||
logger.error("[WebSocket] set WEB_SOCKET_SWF_LOCATION to location of WebSocketMain.swf");
|
||||
return;
|
||||
}
|
||||
if (!window.WEB_SOCKET_SUPPRESS_CROSS_DOMAIN_SWF_ERROR &&
|
||||
!WEB_SOCKET_SWF_LOCATION.match(/(^|\/)WebSocketMainInsecure\.swf(\?.*)?$/) &&
|
||||
WEB_SOCKET_SWF_LOCATION.match(/^\w+:\/\/([^\/]+)/)) {
|
||||
var swfHost = RegExp.$1;
|
||||
if (location.host != swfHost) {
|
||||
logger.error(
|
||||
"[WebSocket] You must host HTML and WebSocketMain.swf in the same host " +
|
||||
"('" + location.host + "' != '" + swfHost + "'). " +
|
||||
"See also 'How to host HTML file and SWF file in different domains' section " +
|
||||
"in README.md. If you use WebSocketMainInsecure.swf, you can suppress this message " +
|
||||
"by WEB_SOCKET_SUPPRESS_CROSS_DOMAIN_SWF_ERROR = true;");
|
||||
}
|
||||
}
|
||||
var container = document.createElement("div");
|
||||
container.id = "webSocketContainer";
|
||||
// Hides Flash box. We cannot use display: none or visibility: hidden because it prevents
|
||||
// Flash from loading at least in IE. So we move it out of the screen at (-100, -100).
|
||||
// But this even doesn't work with Flash Lite (e.g. in Droid Incredible). So with Flash
|
||||
// Lite, we put it at (0, 0). This shows 1x1 box visible at left-top corner but this is
|
||||
// the best we can do as far as we know now.
|
||||
container.style.position = "absolute";
|
||||
if (WebSocket.__isFlashLite()) {
|
||||
container.style.left = "0px";
|
||||
container.style.top = "0px";
|
||||
} else {
|
||||
container.style.left = "-100px";
|
||||
container.style.top = "-100px";
|
||||
}
|
||||
var holder = document.createElement("div");
|
||||
holder.id = "webSocketFlash";
|
||||
container.appendChild(holder);
|
||||
document.body.appendChild(container);
|
||||
// See this article for hasPriority:
|
||||
// http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-7ffd.html
|
||||
swfobject.embedSWF(
|
||||
WEB_SOCKET_SWF_LOCATION,
|
||||
"webSocketFlash",
|
||||
"1" /* width */,
|
||||
"1" /* height */,
|
||||
"10.0.0" /* SWF version */,
|
||||
null,
|
||||
null,
|
||||
{hasPriority: true, swliveconnect : true, allowScriptAccess: "always"},
|
||||
null,
|
||||
function(e) {
|
||||
if (!e.success) {
|
||||
logger.error("[WebSocket] swfobject.embedSWF failed");
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Called by Flash to notify JS that it's fully loaded and ready
|
||||
* for communication.
|
||||
*/
|
||||
WebSocket.__onFlashInitialized = function() {
|
||||
// We need to set a timeout here to avoid round-trip calls
|
||||
// to flash during the initialization process.
|
||||
setTimeout(function() {
|
||||
WebSocket.__flash = document.getElementById("webSocketFlash");
|
||||
WebSocket.__flash.setCallerUrl(location.href);
|
||||
WebSocket.__flash.setDebug(!!window.WEB_SOCKET_DEBUG);
|
||||
for (var i = 0; i < WebSocket.__tasks.length; ++i) {
|
||||
WebSocket.__tasks[i]();
|
||||
}
|
||||
WebSocket.__tasks = [];
|
||||
}, 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* Called by Flash to notify WebSockets events are fired.
|
||||
*/
|
||||
WebSocket.__onFlashEvent = function() {
|
||||
setTimeout(function() {
|
||||
try {
|
||||
// Gets events using receiveEvents() instead of getting it from event object
|
||||
// of Flash event. This is to make sure to keep message order.
|
||||
// It seems sometimes Flash events don't arrive in the same order as they are sent.
|
||||
var events = WebSocket.__flash.receiveEvents();
|
||||
for (var i = 0; i < events.length; ++i) {
|
||||
WebSocket.__instances[events[i].webSocketId].__handleEvent(events[i]);
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error(e);
|
||||
}
|
||||
}, 0);
|
||||
return true;
|
||||
};
|
||||
|
||||
// Called by Flash.
|
||||
WebSocket.__log = function(message) {
|
||||
logger.log(decodeURIComponent(message));
|
||||
};
|
||||
|
||||
// Called by Flash.
|
||||
WebSocket.__error = function(message) {
|
||||
logger.error(decodeURIComponent(message));
|
||||
};
|
||||
|
||||
WebSocket.__addTask = function(task) {
|
||||
if (WebSocket.__flash) {
|
||||
task();
|
||||
} else {
|
||||
WebSocket.__tasks.push(task);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Test if the browser is running flash lite.
|
||||
* @return {boolean} True if flash lite is running, false otherwise.
|
||||
*/
|
||||
WebSocket.__isFlashLite = function() {
|
||||
if (!window.navigator || !window.navigator.mimeTypes) {
|
||||
return false;
|
||||
}
|
||||
var mimeType = window.navigator.mimeTypes["application/x-shockwave-flash"];
|
||||
if (!mimeType || !mimeType.enabledPlugin || !mimeType.enabledPlugin.filename) {
|
||||
return false;
|
||||
}
|
||||
return mimeType.enabledPlugin.filename.match(/flashlite/i) ? true : false;
|
||||
};
|
||||
|
||||
if (!window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION) {
|
||||
// NOTE:
|
||||
// This fires immediately if web_socket.js is dynamically loaded after
|
||||
// the document is loaded.
|
||||
swfobject.addDomLoadEvent(function() {
|
||||
WebSocket.__initialize();
|
||||
});
|
||||
}
|
||||
|
||||
})();
|
422
static/js/novnc/websock.js
Normal file
422
static/js/novnc/websock.js
Normal file
|
@ -0,0 +1,422 @@
|
|||
/*
|
||||
* Websock: high-performance binary WebSockets
|
||||
* Copyright (C) 2012 Joel Martin
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* Websock is similar to the standard WebSocket object but Websock
|
||||
* enables communication with raw TCP sockets (i.e. the binary stream)
|
||||
* via websockify. This is accomplished by base64 encoding the data
|
||||
* stream between Websock and websockify.
|
||||
*
|
||||
* Websock has built-in receive queue buffering; the message event
|
||||
* does not contain actual data but is simply a notification that
|
||||
* there is new data available. Several rQ* methods are available to
|
||||
* read binary data off of the receive queue.
|
||||
*/
|
||||
|
||||
/*jslint browser: true, bitwise: false, plusplus: false */
|
||||
/*global Util, Base64 */
|
||||
|
||||
|
||||
// Load Flash WebSocket emulator if needed
|
||||
|
||||
// To force WebSocket emulator even when native WebSocket available
|
||||
//window.WEB_SOCKET_FORCE_FLASH = true;
|
||||
// To enable WebSocket emulator debug:
|
||||
//window.WEB_SOCKET_DEBUG=1;
|
||||
|
||||
if (window.WebSocket && !window.WEB_SOCKET_FORCE_FLASH) {
|
||||
Websock_native = true;
|
||||
} else if (window.MozWebSocket && !window.WEB_SOCKET_FORCE_FLASH) {
|
||||
Websock_native = true;
|
||||
window.WebSocket = window.MozWebSocket;
|
||||
} else {
|
||||
/* no builtin WebSocket so load web_socket.js */
|
||||
|
||||
Websock_native = false;
|
||||
(function () {
|
||||
window.WEB_SOCKET_SWF_LOCATION = Util.get_include_uri() +
|
||||
"web-socket-js/WebSocketMain.swf";
|
||||
if (Util.Engine.trident) {
|
||||
Util.Debug("Forcing uncached load of WebSocketMain.swf");
|
||||
window.WEB_SOCKET_SWF_LOCATION += "?" + Math.random();
|
||||
}
|
||||
Util.load_scripts(["web-socket-js/swfobject.js",
|
||||
"web-socket-js/web_socket.js"]);
|
||||
}());
|
||||
}
|
||||
|
||||
|
||||
function Websock() {
|
||||
"use strict";
|
||||
|
||||
var api = {}, // Public API
|
||||
websocket = null, // WebSocket object
|
||||
mode = 'base64', // Current WebSocket mode: 'binary', 'base64'
|
||||
rQ = [], // Receive queue
|
||||
rQi = 0, // Receive queue index
|
||||
rQmax = 10000, // Max receive queue size before compacting
|
||||
sQ = [], // Send queue
|
||||
|
||||
eventHandlers = {
|
||||
'message' : function() {},
|
||||
'open' : function() {},
|
||||
'close' : function() {},
|
||||
'error' : function() {}
|
||||
},
|
||||
|
||||
test_mode = false;
|
||||
|
||||
|
||||
//
|
||||
// Queue public functions
|
||||
//
|
||||
|
||||
function get_sQ() {
|
||||
return sQ;
|
||||
}
|
||||
|
||||
function get_rQ() {
|
||||
return rQ;
|
||||
}
|
||||
function get_rQi() {
|
||||
return rQi;
|
||||
}
|
||||
function set_rQi(val) {
|
||||
rQi = val;
|
||||
}
|
||||
|
||||
function rQlen() {
|
||||
return rQ.length - rQi;
|
||||
}
|
||||
|
||||
function rQpeek8() {
|
||||
return (rQ[rQi] );
|
||||
}
|
||||
function rQshift8() {
|
||||
return (rQ[rQi++] );
|
||||
}
|
||||
function rQunshift8(num) {
|
||||
if (rQi === 0) {
|
||||
rQ.unshift(num);
|
||||
} else {
|
||||
rQi -= 1;
|
||||
rQ[rQi] = num;
|
||||
}
|
||||
|
||||
}
|
||||
function rQshift16() {
|
||||
return (rQ[rQi++] << 8) +
|
||||
(rQ[rQi++] );
|
||||
}
|
||||
function rQshift32() {
|
||||
return (rQ[rQi++] << 24) +
|
||||
(rQ[rQi++] << 16) +
|
||||
(rQ[rQi++] << 8) +
|
||||
(rQ[rQi++] );
|
||||
}
|
||||
function rQshiftStr(len) {
|
||||
if (typeof(len) === 'undefined') { len = rQlen(); }
|
||||
var arr = rQ.slice(rQi, rQi + len);
|
||||
rQi += len;
|
||||
return String.fromCharCode.apply(null, arr);
|
||||
}
|
||||
function rQshiftBytes(len) {
|
||||
if (typeof(len) === 'undefined') { len = rQlen(); }
|
||||
rQi += len;
|
||||
return rQ.slice(rQi-len, rQi);
|
||||
}
|
||||
|
||||
function rQslice(start, end) {
|
||||
if (end) {
|
||||
return rQ.slice(rQi + start, rQi + end);
|
||||
} else {
|
||||
return rQ.slice(rQi + start);
|
||||
}
|
||||
}
|
||||
|
||||
// Check to see if we must wait for 'num' bytes (default to FBU.bytes)
|
||||
// to be available in the receive queue. Return true if we need to
|
||||
// wait (and possibly print a debug message), otherwise false.
|
||||
function rQwait(msg, num, goback) {
|
||||
var rQlen = rQ.length - rQi; // Skip rQlen() function call
|
||||
if (rQlen < num) {
|
||||
if (goback) {
|
||||
if (rQi < goback) {
|
||||
throw("rQwait cannot backup " + goback + " bytes");
|
||||
}
|
||||
rQi -= goback;
|
||||
}
|
||||
//Util.Debug(" waiting for " + (num-rQlen) +
|
||||
// " " + msg + " byte(s)");
|
||||
return true; // true means need more data
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Private utility routines
|
||||
//
|
||||
|
||||
function encode_message() {
|
||||
if (mode === 'binary') {
|
||||
// Put in a binary arraybuffer
|
||||
return (new Uint8Array(sQ)).buffer;
|
||||
} else {
|
||||
// base64 encode
|
||||
return Base64.encode(sQ);
|
||||
}
|
||||
}
|
||||
|
||||
function decode_message(data) {
|
||||
//Util.Debug(">> decode_message: " + data);
|
||||
if (mode === 'binary') {
|
||||
// push arraybuffer values onto the end
|
||||
var u8 = new Uint8Array(data);
|
||||
for (var i = 0; i < u8.length; i++) {
|
||||
rQ.push(u8[i]);
|
||||
}
|
||||
} else {
|
||||
// base64 decode and concat to the end
|
||||
rQ = rQ.concat(Base64.decode(data, 0));
|
||||
}
|
||||
//Util.Debug(">> decode_message, rQ: " + rQ);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Public Send functions
|
||||
//
|
||||
|
||||
function flush() {
|
||||
if (websocket.bufferedAmount !== 0) {
|
||||
Util.Debug("bufferedAmount: " + websocket.bufferedAmount);
|
||||
}
|
||||
if (websocket.bufferedAmount < api.maxBufferedAmount) {
|
||||
//Util.Debug("arr: " + arr);
|
||||
//Util.Debug("sQ: " + sQ);
|
||||
if (sQ.length > 0) {
|
||||
websocket.send(encode_message(sQ));
|
||||
sQ = [];
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
Util.Info("Delaying send, bufferedAmount: " +
|
||||
websocket.bufferedAmount);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// overridable for testing
|
||||
function send(arr) {
|
||||
//Util.Debug(">> send_array: " + arr);
|
||||
sQ = sQ.concat(arr);
|
||||
return flush();
|
||||
}
|
||||
|
||||
function send_string(str) {
|
||||
//Util.Debug(">> send_string: " + str);
|
||||
api.send(str.split('').map(
|
||||
function (chr) { return chr.charCodeAt(0); } ) );
|
||||
}
|
||||
|
||||
//
|
||||
// Other public functions
|
||||
|
||||
function recv_message(e) {
|
||||
//Util.Debug(">> recv_message: " + e.data.length);
|
||||
|
||||
try {
|
||||
decode_message(e.data);
|
||||
if (rQlen() > 0) {
|
||||
eventHandlers.message();
|
||||
// Compact the receive queue
|
||||
if (rQ.length > rQmax) {
|
||||
//Util.Debug("Compacting receive queue");
|
||||
rQ = rQ.slice(rQi);
|
||||
rQi = 0;
|
||||
}
|
||||
} else {
|
||||
Util.Debug("Ignoring empty message");
|
||||
}
|
||||
} catch (exc) {
|
||||
if (typeof exc.stack !== 'undefined') {
|
||||
Util.Warn("recv_message, caught exception: " + exc.stack);
|
||||
} else if (typeof exc.description !== 'undefined') {
|
||||
Util.Warn("recv_message, caught exception: " + exc.description);
|
||||
} else {
|
||||
Util.Warn("recv_message, caught exception:" + exc);
|
||||
}
|
||||
if (typeof exc.name !== 'undefined') {
|
||||
eventHandlers.error(exc.name + ": " + exc.message);
|
||||
} else {
|
||||
eventHandlers.error(exc);
|
||||
}
|
||||
}
|
||||
//Util.Debug("<< recv_message");
|
||||
}
|
||||
|
||||
|
||||
// Set event handlers
|
||||
function on(evt, handler) {
|
||||
eventHandlers[evt] = handler;
|
||||
}
|
||||
|
||||
function init(protocols) {
|
||||
rQ = [];
|
||||
rQi = 0;
|
||||
sQ = [];
|
||||
websocket = null;
|
||||
|
||||
var bt = false,
|
||||
wsbt = false,
|
||||
try_binary = false;
|
||||
|
||||
// Check for full typed array support
|
||||
if (('Uint8Array' in window) &&
|
||||
('set' in Uint8Array.prototype)) {
|
||||
bt = true;
|
||||
}
|
||||
|
||||
// Check for full binary type support in WebSockets
|
||||
// TODO: this sucks, the property should exist on the prototype
|
||||
// but it does not.
|
||||
try {
|
||||
if (bt && ('binaryType' in (new WebSocket("ws://localhost:17523")))) {
|
||||
Util.Info("Detected binaryType support in WebSockets");
|
||||
wsbt = true;
|
||||
}
|
||||
} catch (exc) {
|
||||
// Just ignore failed test localhost connections
|
||||
}
|
||||
|
||||
// Default protocols if not specified
|
||||
if (typeof(protocols) === "undefined") {
|
||||
if (wsbt) {
|
||||
protocols = ['binary', 'base64'];
|
||||
} else {
|
||||
protocols = 'base64';
|
||||
}
|
||||
}
|
||||
|
||||
// If no binary support, make sure it was not requested
|
||||
if (!wsbt) {
|
||||
if (protocols === 'binary') {
|
||||
throw("WebSocket binary sub-protocol requested but not supported");
|
||||
}
|
||||
if (typeof(protocols) === "object") {
|
||||
var new_protocols = [];
|
||||
for (var i = 0; i < protocols.length; i++) {
|
||||
if (protocols[i] === 'binary') {
|
||||
Util.Error("Skipping unsupported WebSocket binary sub-protocol");
|
||||
} else {
|
||||
new_protocols.push(protocols[i]);
|
||||
}
|
||||
}
|
||||
if (new_protocols.length > 0) {
|
||||
protocols = new_protocols;
|
||||
} else {
|
||||
throw("Only WebSocket binary sub-protocol was requested and not supported.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return protocols;
|
||||
}
|
||||
|
||||
function open(uri, protocols) {
|
||||
protocols = init(protocols);
|
||||
|
||||
if (test_mode) {
|
||||
websocket = {};
|
||||
} else {
|
||||
websocket = new WebSocket(uri, protocols);
|
||||
if (protocols.indexOf('binary') >= 0) {
|
||||
websocket.binaryType = 'arraybuffer';
|
||||
}
|
||||
}
|
||||
|
||||
websocket.onmessage = recv_message;
|
||||
websocket.onopen = function() {
|
||||
Util.Debug(">> WebSock.onopen");
|
||||
if (websocket.protocol) {
|
||||
mode = websocket.protocol;
|
||||
Util.Info("Server chose sub-protocol: " + websocket.protocol);
|
||||
} else {
|
||||
mode = 'base64';
|
||||
Util.Error("Server select no sub-protocol!: " + websocket.protocol);
|
||||
}
|
||||
eventHandlers.open();
|
||||
Util.Debug("<< WebSock.onopen");
|
||||
};
|
||||
websocket.onclose = function(e) {
|
||||
Util.Debug(">> WebSock.onclose");
|
||||
eventHandlers.close(e);
|
||||
Util.Debug("<< WebSock.onclose");
|
||||
};
|
||||
websocket.onerror = function(e) {
|
||||
Util.Debug(">> WebSock.onerror: " + e);
|
||||
eventHandlers.error(e);
|
||||
Util.Debug("<< WebSock.onerror");
|
||||
};
|
||||
}
|
||||
|
||||
function close() {
|
||||
if (websocket) {
|
||||
if ((websocket.readyState === WebSocket.OPEN) ||
|
||||
(websocket.readyState === WebSocket.CONNECTING)) {
|
||||
Util.Info("Closing WebSocket connection");
|
||||
websocket.close();
|
||||
}
|
||||
websocket.onmessage = function (e) { return; };
|
||||
}
|
||||
}
|
||||
|
||||
// Override internal functions for testing
|
||||
// Takes a send function, returns reference to recv function
|
||||
function testMode(override_send, data_mode) {
|
||||
test_mode = true;
|
||||
mode = data_mode;
|
||||
api.send = override_send;
|
||||
api.close = function () {};
|
||||
return recv_message;
|
||||
}
|
||||
|
||||
function constructor() {
|
||||
// Configuration settings
|
||||
api.maxBufferedAmount = 200;
|
||||
|
||||
// Direct access to send and receive queues
|
||||
api.get_sQ = get_sQ;
|
||||
api.get_rQ = get_rQ;
|
||||
api.get_rQi = get_rQi;
|
||||
api.set_rQi = set_rQi;
|
||||
|
||||
// Routines to read from the receive queue
|
||||
api.rQlen = rQlen;
|
||||
api.rQpeek8 = rQpeek8;
|
||||
api.rQshift8 = rQshift8;
|
||||
api.rQunshift8 = rQunshift8;
|
||||
api.rQshift16 = rQshift16;
|
||||
api.rQshift32 = rQshift32;
|
||||
api.rQshiftStr = rQshiftStr;
|
||||
api.rQshiftBytes = rQshiftBytes;
|
||||
api.rQslice = rQslice;
|
||||
api.rQwait = rQwait;
|
||||
|
||||
api.flush = flush;
|
||||
api.send = send;
|
||||
api.send_string = send_string;
|
||||
|
||||
api.on = on;
|
||||
api.init = init;
|
||||
api.open = open;
|
||||
api.close = close;
|
||||
api.testMode = testMode;
|
||||
|
||||
return api;
|
||||
}
|
||||
|
||||
return constructor();
|
||||
|
||||
}
|
216
static/js/novnc/webutil.js
Normal file
216
static/js/novnc/webutil.js
Normal file
|
@ -0,0 +1,216 @@
|
|||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2012 Joel Martin
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
/*jslint bitwise: false, white: false */
|
||||
/*global Util, window, document */
|
||||
|
||||
// Globals defined here
|
||||
var WebUtil = {}, $D;
|
||||
|
||||
/*
|
||||
* Simple DOM selector by ID
|
||||
*/
|
||||
if (!window.$D) {
|
||||
window.$D = function (id) {
|
||||
if (document.getElementById) {
|
||||
return document.getElementById(id);
|
||||
} else if (document.all) {
|
||||
return document.all[id];
|
||||
} else if (document.layers) {
|
||||
return document.layers[id];
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Namespaced in WebUtil
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
|
||||
// init log level reading the logging HTTP param
|
||||
WebUtil.init_logging = function(level) {
|
||||
if (typeof level !== "undefined") {
|
||||
Util._log_level = level;
|
||||
} else {
|
||||
Util._log_level = (document.location.href.match(
|
||||
/logging=([A-Za-z0-9\._\-]*)/) ||
|
||||
['', Util._log_level])[1];
|
||||
}
|
||||
Util.init_logging();
|
||||
};
|
||||
|
||||
|
||||
WebUtil.dirObj = function (obj, depth, parent) {
|
||||
var i, msg = "", val = "";
|
||||
if (! depth) { depth=2; }
|
||||
if (! parent) { parent= ""; }
|
||||
|
||||
// Print the properties of the passed-in object
|
||||
for (i in obj) {
|
||||
if ((depth > 1) && (typeof obj[i] === "object")) {
|
||||
// Recurse attributes that are objects
|
||||
msg += WebUtil.dirObj(obj[i], depth-1, parent + "." + i);
|
||||
} else {
|
||||
//val = new String(obj[i]).replace("\n", " ");
|
||||
if (typeof(obj[i]) === "undefined") {
|
||||
val = "undefined";
|
||||
} else {
|
||||
val = obj[i].toString().replace("\n", " ");
|
||||
}
|
||||
if (val.length > 30) {
|
||||
val = val.substr(0,30) + "...";
|
||||
}
|
||||
msg += parent + "." + i + ": " + val + "\n";
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
};
|
||||
|
||||
// Read a query string variable
|
||||
WebUtil.getQueryVar = function(name, defVal) {
|
||||
var re = new RegExp('[?][^#]*' + name + '=([^&#]*)'),
|
||||
match = document.location.href.match(re);
|
||||
if (typeof defVal === 'undefined') { defVal = null; }
|
||||
if (match) {
|
||||
return decodeURIComponent(match[1]);
|
||||
} else {
|
||||
return defVal;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Cookie handling. Dervied from: http://www.quirksmode.org/js/cookies.html
|
||||
*/
|
||||
|
||||
// No days means only for this browser session
|
||||
WebUtil.createCookie = function(name,value,days) {
|
||||
var date, expires;
|
||||
if (days) {
|
||||
date = new Date();
|
||||
date.setTime(date.getTime()+(days*24*60*60*1000));
|
||||
expires = "; expires="+date.toGMTString();
|
||||
}
|
||||
else {
|
||||
expires = "";
|
||||
}
|
||||
document.cookie = name+"="+value+expires+"; path=/";
|
||||
};
|
||||
|
||||
WebUtil.readCookie = function(name, defaultValue) {
|
||||
var i, c, nameEQ = name + "=", ca = document.cookie.split(';');
|
||||
for(i=0; i < ca.length; i += 1) {
|
||||
c = ca[i];
|
||||
while (c.charAt(0) === ' ') { c = c.substring(1,c.length); }
|
||||
if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length,c.length); }
|
||||
}
|
||||
return (typeof defaultValue !== 'undefined') ? defaultValue : null;
|
||||
};
|
||||
|
||||
WebUtil.eraseCookie = function(name) {
|
||||
WebUtil.createCookie(name,"",-1);
|
||||
};
|
||||
|
||||
/*
|
||||
* Setting handling.
|
||||
*/
|
||||
|
||||
WebUtil.initSettings = function(callback) {
|
||||
var callbackArgs = Array.prototype.slice.call(arguments, 1);
|
||||
if (window.chrome && window.chrome.storage) {
|
||||
window.chrome.storage.sync.get(function (cfg) {
|
||||
WebUtil.settings = cfg;
|
||||
console.log(WebUtil.settings);
|
||||
if (callback) {
|
||||
callback.apply(this, callbackArgs);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// No-op
|
||||
if (callback) {
|
||||
callback.apply(this, callbackArgs);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// No days means only for this browser session
|
||||
WebUtil.writeSetting = function(name, value) {
|
||||
if (window.chrome && window.chrome.storage) {
|
||||
//console.log("writeSetting:", name, value);
|
||||
if (WebUtil.settings[name] !== value) {
|
||||
WebUtil.settings[name] = value;
|
||||
window.chrome.storage.sync.set(WebUtil.settings);
|
||||
}
|
||||
} else {
|
||||
localStorage.setItem(name, value);
|
||||
}
|
||||
};
|
||||
|
||||
WebUtil.readSetting = function(name, defaultValue) {
|
||||
var value;
|
||||
if (window.chrome && window.chrome.storage) {
|
||||
value = WebUtil.settings[name];
|
||||
} else {
|
||||
value = localStorage.getItem(name);
|
||||
}
|
||||
if (typeof value === "undefined") {
|
||||
value = null;
|
||||
}
|
||||
if (value === null && typeof defaultValue !== undefined) {
|
||||
return defaultValue;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
WebUtil.eraseSetting = function(name) {
|
||||
if (window.chrome && window.chrome.storage) {
|
||||
window.chrome.storage.sync.remove(name);
|
||||
delete WebUtil.settings[name];
|
||||
} else {
|
||||
localStorage.removeItem(name);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Alternate stylesheet selection
|
||||
*/
|
||||
WebUtil.getStylesheets = function() { var i, links, sheets = [];
|
||||
links = document.getElementsByTagName("link");
|
||||
for (i = 0; i < links.length; i += 1) {
|
||||
if (links[i].title &&
|
||||
links[i].rel.toUpperCase().indexOf("STYLESHEET") > -1) {
|
||||
sheets.push(links[i]);
|
||||
}
|
||||
}
|
||||
return sheets;
|
||||
};
|
||||
|
||||
// No sheet means try and use value from cookie, null sheet used to
|
||||
// clear all alternates.
|
||||
WebUtil.selectStylesheet = function(sheet) {
|
||||
var i, link, sheets = WebUtil.getStylesheets();
|
||||
if (typeof sheet === 'undefined') {
|
||||
sheet = 'default';
|
||||
}
|
||||
for (i=0; i < sheets.length; i += 1) {
|
||||
link = sheets[i];
|
||||
if (link.title === sheet) {
|
||||
Util.Debug("Using stylesheet " + sheet);
|
||||
link.disabled = false;
|
||||
} else {
|
||||
//Util.Debug("Skipping stylesheet " + link.title);
|
||||
link.disabled = true;
|
||||
}
|
||||
}
|
||||
return sheet;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue