web-common-resource/terminal/smartxKs/terminal.html

264 lines
10 KiB
HTML
Raw Permalink Normal View History

2024-08-20 12:11:35 +00:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Terminal</title>
</head>
<body>
<link rel="stylesheet" href="base.css" title="plain">
<link rel="shortcut icon" href="assets/favicon/favicon.ico">
<script type="text/javascript" src="smartxksJq.js"></script>
<script type="text/javascript" src="smartxksUtil.js"></script>
<div id="noVNC_screen">
<div id="noVNC_status_bar" class="noVNC_status_bar">
<div id="noVNC_buttons">
<input type="button" value="Send CtrlAltDel" id="sendCtrlAltDelButton">
<span id="noVNC_xvp_buttons">
<input type="button" value="Shutdown" id="xvpShutdownButton">
<input type="button" value="Reboot" id="xvpRebootButton">
<input type="button" value="Reset" id="xvpResetButton">
</span> </div>
<div class="send-buttons" style="display:none">
<div class="dropdown">
<input class="dropdown-toggle" type="text" />
<div class="dropdown-text">按键操作...</div>
<div class="dropdown-content"><a class="btn" id="sendCtrlAltDelButton">Ctrl-Alt-Del</a><a class="btn" id="sendCtrlAltBackspaceButton">Ctrl-Alt-Backspace</a>
<div class="pipe"></div>
<a class="btn sendCtrlAltFunctionButton" data-n="1">Ctrl-Alt-F1</a><a class="btn sendCtrlAltFunctionButton" data-n="2">Ctrl-Alt-F2</a><a class="btn sendCtrlAltFunctionButton" data-n="3">Ctrl-Alt-F3</a><a class="btn sendCtrlAltFunctionButton"
data-n="4">Ctrl-Alt-F4</a><a class="btn sendCtrlAltFunctionButton" data-n="5">Ctrl-Alt-F5</a><a class="btn sendCtrlAltFunctionButton" data-n="6">Ctrl-Alt-F6</a><a class="btn sendCtrlAltFunctionButton" data-n="7">Ctrl-Alt-F7</a>
<a class="btn sendCtrlAltFunctionButton" data-n="8">Ctrl-Alt-F8</a><a class="btn sendCtrlAltFunctionButton" data-n="9">Ctrl-Alt-F9</a><a class="btn sendCtrlAltFunctionButton" data-n="10">Ctrl-Alt-F10</a><a class="btn sendCtrlAltFunctionButton"
data-n="11">Ctrl-Alt-F11</a></div>
</div>
</div>
<div id="noVNC_status"> Loading </div>
</div>
<canvas id="noVNC_canvas" width="640" height="20"> Canvas not supported. </canvas>
</div>
<script type="text/javascript">
/*jslint white: false */
/*global window, $, Util, RFB, */
"use strict";
var INCLUDE_URI = ''
// Load supporting scripts
Util.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js",
"keysymdef.js", "keyboard.js", "input.js", "display.js",
"rfb.js", "keysym.js", "inflator.js"
]);
var rfb;
const consoleData = JSON.parse(localStorage.getItem("console"))
function passwordRequired(rfb) {
var msg;
msg = '<form onsubmit="return setPassword();"';
msg += ' style="margin-bottom: 0px">';
msg += 'Password Required: ';
msg += '<input type=password size=10 id="password_input" class="noVNC_status">';
msg += '<\/form>';
$D('noVNC_status_bar').setAttribute("class", "noVNC_status_warn");
$D('noVNC_status').innerHTML = msg;
};
function setPassword() {
rfb.sendPassword($D('password_input').value);
return false;
};
function sendCtrlAltDel() {
rfb.sendCtrlAltDel();
return false;
};
function xvpShutdown() {
rfb.xvpShutdown();
return false;
};
function xvpReboot() {
rfb.xvpReboot();
return false;
};
function xvpReset() {
rfb.xvpReset();
return false;
};
function updateState(rfb, state, oldstate, msg) {
var s, sb, cad, level;
s = $D('noVNC_status');
sb = $D('noVNC_status_bar');
cad = $D('sendCtrlAltDelButton');
switch (state) {
case 'failed':
level = "error";
break;
case 'fatal':
level = "error";
break;
case 'normal':
level = "normal";
window.resizeTo(810, 700);
break;
case 'disconnected':
level = "normal";
break;
case 'loaded':
level = "normal";
break;
default:
level = "warn";
break;
}
if (state === "normal") {
cad.className = '';
cad.disabled = false;
} else {
cad.className = 'disabled';
cad.disabled = true;
xvpInit(0);
}
if (typeof(msg) !== 'undefined') {
sb.setAttribute("class", "noVNC_status_" + level);
s.innerHTML = msg;
}
};
function xvpInit(ver) {
var xvpbuttons;
xvpbuttons = $D('noVNC_xvp_buttons');
if (ver >= 1) {
xvpbuttons.style.display = 'inline';
} else {
xvpbuttons.style.display = 'none';
}
};
function getNodeKey(key) {
var url = consoleData.origin;
console.log(url)
// var url = url ? url: location.href;
var v = '';
var o = url.indexOf(key + "=");
if (o != -1) {
o += key.length + 1;
var e = url.indexOf("&", o);
if (e == -1) {
e = url.length;
}
//v = decodeURIComponent(url.substring(o, e));
v = url.substring(o, e);
}
return v;
};
function screenSize() {
var screen = $D('noVNC_screen');
// Hide the scrollbars until the size is calculated
screen.style.overflow = "hidden";
var pos = Util.getPosition(screen);
var w = pos.width;
var h = pos.height;
screen.style.overflow = "visible";
if (isNaN(w) || isNaN(h)) {
return false;
} else {
return {
w: w,
h: h - 50
};
}
}
function initialResize() {
var screen = screenSize();
if (screen && rfb.get_display()) {
var scaleRatio = rfb.get_display().autoscale(screen.w, screen.h, true);
rfb.get_mouse().set_scale(scaleRatio);
}
}
window.onscriptsload = function() {
var host, port, password, path, token;
$D('sendCtrlAltDelButton').style.display = "inline";
$D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
$D('xvpShutdownButton').onclick = xvpShutdown;
$D('xvpRebootButton').onclick = xvpReboot;
$D('xvpResetButton').onclick = xvpReset;
$("#sendCtrlAltBackspaceButton").on('click', function(e) {
rfb.sendCtrlAltBackspace();
});
$(".sendCtrlAltFunctionButton").on('click', function(e) {
var n = $(this).attr('data-n');
rfb.sendCtrlAltFunction(n);
});
WebUtil.init_logging(WebUtil.getQueryVar('logging', 'warn'));
document.title = decodeURIComponent(WebUtil.getQueryVar('title', "Terminal - " + getNodeKey('vmname')));
//document.title = unescape(WebUtil.getQueryVar('title', l10n.showhost+' '+getNodeKey('vmname')+' '+l10.terminalInterface));
// By default, use the host and port of server that served this file
// host = WebUtil.getQueryVar('host', window.location.hostname);
port = WebUtil.getQueryVar('port', window.location.port);
//host = '127.0.0.1';
// 开发调试时可以在 localStorage 中配置 dev-host 字段连接指定的 ws 服务器
host = location.hostname;
// if port == 80 (or 443) then it won't be present and should be
// set manually
if (!port) {
if (window.location.protocol.substring(0, 5) == 'https') {
port = 443;
} else if (window.location.protocol.substring(0, 4) == 'http') {
port = 80;
}
};
// If a token variable is passed in, set the parameter in a cookie.
// This is used by nova-novncproxy.
token = WebUtil.getQueryVar('token', null);
if (token) {
WebUtil.createCookie('token', token, 1)
};
password = WebUtil.getQueryVar('password', '');
path = WebUtil.getQueryVar('path', 'websockify');
path = 'api/terminal/websockify/?uuid=' + getNodeKey('uuid') + '&token=' + localStorage.getItem("access-token") + '&host=' + getNodeKey('host') + '&real_host=' + consoleData.ip + ':' + consoleData.port;;
var clusterId = sessionStorage.getItem('managed-cluster-id');
if (clusterId) {
path = 'api/v3/clusters/' + clusterId + '/' + path;
}
if ((!host) || (!port)) {
updateState('failed', "Must specify host and port in URL");
return;
};
window.rfb = new RFB({
'target': $D('noVNC_canvas'),
'encrypt': WebUtil.getQueryVar('encrypt', (consoleData.origin.substring(0, 5) === "https")),
'repeaterID': WebUtil.getQueryVar('repeaterID', ''),
'true_color': WebUtil.getQueryVar('true_color', true),
'local_cursor': WebUtil.getQueryVar('cursor', true),
'shared': WebUtil.getQueryVar('shared', true),
'view_only': WebUtil.getQueryVar('view_only', false),
'onUpdateState': updateState,
'onXvpInit': xvpInit,
'onFBUComplete': initialResize,
'onPasswordRequired': passwordRequired
});
rfb.connect(host, port, password, path);
Util.addEvent(window, 'resize', function() {
initialResize()
});
};
</script>
</body>
</html>