connectcore-demo-example: dashboard: remove console access
Console is not going to be supported at this moment. https://onedigi.atlassian.net/browse/DEL-7742 Signed-off-by: Tatiana Leon <Tatiana.Leon@digi.com>
This commit is contained in:
parent
b359ef3d43
commit
0e6d64b499
|
|
@ -11,7 +11,6 @@ Digi Demo - Dashboard
|
|||
|
||||
<link rel="stylesheet" href="./static/css/general.css">
|
||||
<link rel="stylesheet" href="./static/css/toastr.css">
|
||||
<link rel="stylesheet" href="./static/css/xterm.css">
|
||||
|
||||
<!-- JS, Popper.js, and jQuery -->
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
|
||||
|
|
@ -234,33 +233,6 @@ Digi Demo - Dashboard
|
|||
<div class="help-panel-button" onclick="setHelpPopupVisible(false)">Got it!</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="console_panel_area" class="panel-area panel-tooltip" onclick="openConsole()">
|
||||
<span class="panel-tooltip-text">Open console</span>
|
||||
<span id="console_panel_icon" class="fas fa-terminal panel-area-icon"></span>
|
||||
</div>
|
||||
<div id="console_panel" class="console-panel">
|
||||
<div class="console-background"></div>
|
||||
<div id="console_container" class="console-container">
|
||||
<div id="console_header" class="device-card-header">
|
||||
<span class="fas fa-terminal fa-lg mr-2"></span>
|
||||
<span>Remote console</span>
|
||||
<div class="fas fa-window-close fa-lg device-card-header-button" onclick="closeConsole()"></div>
|
||||
</div>
|
||||
<div id="console" class="terminal"></div>
|
||||
<div id="console_hover_background" class="console-hover-background"></div>
|
||||
<div id="console_loading" class="popup shadow" style="top: 33%">
|
||||
<img class="popup-item" src="./static/images/loading.gif" alt="Connecting..." />
|
||||
<div class="popup-text">Connecting...</div>
|
||||
</div>
|
||||
<div id="console_error_reconnect" class="popup popup-error-reconnect shadow">
|
||||
<div id="console_error_text" class="console-error-text">Error</div>
|
||||
<div class="console-error-buttons-container">
|
||||
<div id="console_reconnect_button" class="device-card-button" onclick="initCLISession()">Reconnect</div>
|
||||
<div id="console_close_button" class="device-card-button" style="margin-left: 10px;" onclick="closeConsole()">Close</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="cpu_panel_area" class="panel-area panel-tooltip" onclick="toggleInfoPanelVisibility('cpu')">
|
||||
<span class="panel-tooltip-text">CPU stats</span>
|
||||
<span id="cpu_panel_icon" class="fas fa-microchip panel-area-icon"></span>
|
||||
|
|
@ -792,9 +764,6 @@ Digi Demo - Dashboard
|
|||
<script type="text/javascript" src="./static/js/dashboard.js"></script>
|
||||
<script type="text/javascript" src="./static/js/management.js"></script>
|
||||
<script type="text/javascript" src="./static/js/history.js"></script>
|
||||
<script type="text/javascript" src="./static/js/xterm.js"></script>
|
||||
<script type="text/javascript" src="./static/js/xterm-addon-fit.js"></script>
|
||||
<script type="text/javascript" src="./static/js/console.js"></script>
|
||||
<script type="text/javascript" src="./static/js/file-system.js"></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
|
|
|
|||
|
|
@ -1,187 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2014 The xterm.js authors. All rights reserved.
|
||||
* Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
|
||||
* https://github.com/chjj/term.js
|
||||
* @license MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* Originally forked from (with the author's permission):
|
||||
* Fabrice Bellard's javascript vt100 for jslinux:
|
||||
* http://bellard.org/jslinux/
|
||||
* Copyright (c) 2011 Fabrice Bellard
|
||||
* The original design remains. The terminal itself
|
||||
* has been extended to include xterm CSI codes, among
|
||||
* other features.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Default styles for xterm.js
|
||||
*/
|
||||
|
||||
.xterm {
|
||||
position: relative;
|
||||
user-select: none;
|
||||
-ms-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
}
|
||||
|
||||
.xterm.focus,
|
||||
.xterm:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.xterm .xterm-helpers {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
/**
|
||||
* The z-index of the helpers must be higher than the canvases in order for
|
||||
* IMEs to appear on top.
|
||||
*/
|
||||
z-index: 5;
|
||||
}
|
||||
|
||||
.xterm .xterm-helper-textarea {
|
||||
padding: 0;
|
||||
border: 0;
|
||||
margin: 0;
|
||||
/* Move textarea out of the screen to the far left, so that the cursor is not visible */
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
left: -9999em;
|
||||
top: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
z-index: -5;
|
||||
/** Prevent wrapping so the IME appears against the textarea at the correct position */
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
resize: none;
|
||||
}
|
||||
|
||||
.xterm .composition-view {
|
||||
/* TODO: Composition position got messed up somewhere */
|
||||
background: #000;
|
||||
color: #FFF;
|
||||
display: none;
|
||||
position: absolute;
|
||||
white-space: nowrap;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.xterm .composition-view.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.xterm .xterm-viewport {
|
||||
/* On OS X this is required in order for the scroll bar to appear fully opaque */
|
||||
background-color: #000;
|
||||
overflow-y: scroll;
|
||||
cursor: default;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.xterm .xterm-screen {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.xterm .xterm-screen canvas {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.xterm .xterm-scroll-area {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.xterm-char-measure-element {
|
||||
display: inline-block;
|
||||
visibility: hidden;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: -9999em;
|
||||
line-height: normal;
|
||||
}
|
||||
|
||||
.xterm {
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.xterm.enable-mouse-events {
|
||||
/* When mouse events are enabled (eg. tmux), revert to the standard pointer cursor */
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.xterm.xterm-cursor-pointer,
|
||||
.xterm .xterm-cursor-pointer {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.xterm.column-select.focus {
|
||||
/* Column selection mode */
|
||||
cursor: crosshair;
|
||||
}
|
||||
|
||||
.xterm .xterm-accessibility,
|
||||
.xterm .xterm-message {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
z-index: 10;
|
||||
color: transparent;
|
||||
}
|
||||
|
||||
.xterm .live-region {
|
||||
position: absolute;
|
||||
left: -9999px;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.xterm-dim {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.xterm-underline {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.xterm-strikethrough {
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
.xterm-screen .xterm-decoration-container .xterm-decoration {
|
||||
z-index: 6;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.xterm-decoration-overview-ruler {
|
||||
z-index: 7;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
}
|
||||
|
|
@ -1,387 +0,0 @@
|
|||
/*
|
||||
* Copyright 2022, Digi International Inc.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
// Constants.
|
||||
const CONSOLE_CURSOR_BLINK = true;
|
||||
const CONSOLE_NUM_ROWS = 30;
|
||||
const CONSOLE_SCROLLBACK = 1000;
|
||||
const CONSOLE_TAB_STOP_WIDTH = 8;
|
||||
const CONSOLE_MAX_SEND_COMMANDS = 5;
|
||||
const CONSOLE_SEND_COMMANDS_DELAY = 150;
|
||||
|
||||
const ID_CONSOLE_CLOSE_BUTTON = "console_close_button";
|
||||
const ID_CONSOLE_CONTAINER = "console_container";
|
||||
const ID_CONSOLE_ERROR_RECONNECT = "console_error_reconnect";
|
||||
const ID_CONSOLE_ERROR_TEXT = "console_error_text";
|
||||
const ID_CONSOLE_HEADER = "console_header";
|
||||
const ID_CONSOLE_HOVER_BACKGROUND = "console_hover_background";
|
||||
const ID_CONSOLE_LOADING = "console_loading";
|
||||
const ID_CONSOLE_PANEL = "console_panel";
|
||||
const ID_CONSOLE_RECONNECT_BUTTON = "console_reconnect_button";
|
||||
const ID_CONSOLE_VIEWPORT = "xterm-viewport";
|
||||
|
||||
const CLI_MESSAGE_TYPE_DATA = "data";
|
||||
const CLI_MESSAGE_TYPE_ERROR = "error";
|
||||
const CLI_MESSAGE_TYPE_START = "start";
|
||||
const CLI_MESSAGE_TYPE_TERMINATE = "terminate";
|
||||
|
||||
const ERROR_SESSION_CLOSED_REMOTELY = "Session closed from the remote end";
|
||||
const ERROR_SESSION_CLOSING = "Previous console session is closing, please wait a moment...";
|
||||
|
||||
// Variables.
|
||||
var term;
|
||||
var cliSessionID;
|
||||
var cliSocket;
|
||||
var cliSessionTerminating = false;
|
||||
var fitAddon;
|
||||
var commandsToSend = [];
|
||||
var cliTerminateFlagTimer = null;
|
||||
var consoleResizeObserver = null;
|
||||
|
||||
// Opens the console.
|
||||
function openConsole() {
|
||||
// Check if console is showing.
|
||||
if (isConsoleShowing())
|
||||
return;
|
||||
// Check if previous session is terminating.
|
||||
if (cliSessionTerminating) {
|
||||
toastr.info(ERROR_SESSION_CLOSING);
|
||||
return;
|
||||
}
|
||||
// Initialize variables.
|
||||
var consoleDiv = document.getElementById(ID_CONSOLE);
|
||||
// Remove any residual terminals.
|
||||
while (consoleDiv.firstChild)
|
||||
consoleDiv.removeChild(consoleDiv.lastChild);
|
||||
// Create the terminal instance.
|
||||
term = new Terminal({
|
||||
cursorBlink: CONSOLE_CURSOR_BLINK,
|
||||
scrollback: CONSOLE_SCROLLBACK,
|
||||
tabStopWidth: CONSOLE_TAB_STOP_WIDTH,
|
||||
rows: CONSOLE_NUM_ROWS
|
||||
});
|
||||
// Configure terminal input data event.
|
||||
term.onData( (data) => {
|
||||
sendCLIData(data);
|
||||
});
|
||||
// Load Fit addon.
|
||||
fitAddon = new FitAddon.FitAddon();
|
||||
term.loadAddon(fitAddon);
|
||||
// Attach the terminal to the div.
|
||||
term.open(consoleDiv);
|
||||
// Setup resize observer.
|
||||
if (consoleResizeObserver == null || consoleResizeObserver == "undefined") {
|
||||
consoleResizeObserver = new ResizeObserver((entries) => {
|
||||
adjustConsoleSize();
|
||||
})
|
||||
consoleResizeObserver.observe(document.getElementById(ID_CONSOLE_CONTAINER));
|
||||
}
|
||||
// Show the console.
|
||||
var consolePanel = document.getElementById(ID_CONSOLE_PANEL);
|
||||
consolePanel.style.visibility = "visible";
|
||||
consolePanel.style.display = "flex";
|
||||
// Adjust console size after some time to give time to the terminal to load.
|
||||
window.setTimeout(function () {
|
||||
adjustConsoleSize();
|
||||
}, 100);
|
||||
adjustConsoleSize();
|
||||
// Initialize the CLI session.
|
||||
initCLISession();
|
||||
}
|
||||
|
||||
// Adjusts the console size.
|
||||
function adjustConsoleSize() {
|
||||
// Sanity checks.
|
||||
if (!isConsoleShowing())
|
||||
return;
|
||||
// Initialize variables.
|
||||
var consoleContainer = document.getElementById(ID_CONSOLE_CONTAINER);
|
||||
var consoleViewPort = document.getElementsByClassName(ID_CONSOLE_VIEWPORT)[0];
|
||||
var consoleHeader = document.getElementById(ID_CONSOLE_HEADER);
|
||||
var consoleHoverBackground = document.getElementById(ID_CONSOLE_HOVER_BACKGROUND);
|
||||
// Adjust terminal size.
|
||||
if (fitAddon != null && fitAddon != "undefined")
|
||||
fitAddon.fit();
|
||||
// Obtain dimensions.
|
||||
var consoleHeight = consoleViewPort.clientHeight;
|
||||
var headerHeight = consoleHeader.clientHeight;
|
||||
// Set size values.
|
||||
consoleContainer.style.height = (consoleHeight + headerHeight).toString() + "px";
|
||||
consoleHoverBackground.style.height = (consoleContainer.clientHeight - headerHeight).toString() + "px";
|
||||
consoleViewPort.style.width = "initial";
|
||||
}
|
||||
|
||||
// Returns whether the console window is open or not.
|
||||
function isConsoleShowing() {
|
||||
// Sanity checks.
|
||||
if (!isDashboardShowing())
|
||||
return false;
|
||||
// Initialize variables.
|
||||
var consolePanel = document.getElementById(ID_CONSOLE_PANEL);
|
||||
// Return whether the console is showing or not.
|
||||
return consolePanel.style.visibility == "visible";
|
||||
}
|
||||
|
||||
// Shows/hides the console loading panel.
|
||||
function showConsoleLoading(visible) {
|
||||
// Initialize variables.
|
||||
var consoleHoverBackground = document.getElementById(ID_CONSOLE_HOVER_BACKGROUND);
|
||||
var consoleLoading = document.getElementById(ID_CONSOLE_LOADING);
|
||||
// Show/hide the loading panel.
|
||||
if (visible && isConsoleShowing()) {
|
||||
consoleHoverBackground.style.visibility = "visible";
|
||||
consoleLoading.style.visibility = "visible";
|
||||
} else {
|
||||
consoleHoverBackground.style.visibility = "hidden";
|
||||
consoleLoading.style.visibility = "hidden";
|
||||
}
|
||||
}
|
||||
|
||||
// Shows/hides the console error with reconnect panel.
|
||||
function showConsoleErrorReconnect(visible, error) {
|
||||
// Initialize variables.
|
||||
var consoleHoverBackground = document.getElementById(ID_CONSOLE_HOVER_BACKGROUND);
|
||||
var consoleErrorReconnect = document.getElementById(ID_CONSOLE_ERROR_RECONNECT);
|
||||
var consoleErrorText = document.getElementById(ID_CONSOLE_ERROR_TEXT);
|
||||
var reconnectButton = document.getElementById(ID_CONSOLE_RECONNECT_BUTTON);
|
||||
var closeButton = document.getElementById(ID_CONSOLE_CLOSE_BUTTON);
|
||||
// Show/hide the error panel.
|
||||
if (visible && isConsoleShowing()) {
|
||||
consoleHoverBackground.style.visibility = "visible";
|
||||
consoleErrorReconnect.style.visibility = "visible";
|
||||
reconnectButton.style.visibility = "visible";
|
||||
closeButton.style.visibility = "visible";
|
||||
if (error == null)
|
||||
error = ERROR_UNKNOWN_ERROR;
|
||||
consoleErrorText.innerText = error;
|
||||
} else {
|
||||
consoleHoverBackground.style.visibility = "hidden";
|
||||
consoleErrorReconnect.style.visibility = "hidden";
|
||||
reconnectButton.style.visibility = "hidden";
|
||||
closeButton.style.visibility = "hidden";
|
||||
}
|
||||
}
|
||||
|
||||
// Initializes a CLI session.
|
||||
function initCLISession() {
|
||||
// Hide error with reconnect panel.
|
||||
showConsoleErrorReconnect(false);
|
||||
// Clear the terminal.
|
||||
term.clear();
|
||||
// Show loading panel.
|
||||
showConsoleLoading(true);
|
||||
$.post(
|
||||
"../ajax/cli_init_session",
|
||||
function(data) {
|
||||
// Process only if the console is showing.
|
||||
if (!isConsoleShowing())
|
||||
return;
|
||||
// Process answer.
|
||||
processInitCLISessionResponse(data);
|
||||
}
|
||||
).fail(function(response) {
|
||||
// Process only if the console is showing.
|
||||
if (!isConsoleShowing())
|
||||
return;
|
||||
// Process error.
|
||||
var error = processAjaxErrorResponse(response);
|
||||
// Hide the loading status.
|
||||
showConsoleLoading(false);
|
||||
// Show error with reconnect panel.
|
||||
showConsoleErrorReconnect(true, error);
|
||||
});
|
||||
}
|
||||
|
||||
// Processes the init CLI session response.
|
||||
function processInitCLISessionResponse(response) {
|
||||
// Check if there was any error in the request.
|
||||
if (checkErrorResponse(response, false)) {
|
||||
// Hide the loading status.
|
||||
showConsoleLoading(false);
|
||||
// Show error with reconnect panel.
|
||||
showConsoleErrorReconnect(true, error);
|
||||
} else {
|
||||
// Store session ID.
|
||||
cliSessionID = response[ID_SESSION_ID];
|
||||
// Register the TCP monitor.
|
||||
subscribeCLISession(cliSessionID);
|
||||
}
|
||||
}
|
||||
|
||||
// Sends the given CLI data.
|
||||
function sendCLIData(data) {
|
||||
// Check if CLI session exists.
|
||||
if (cliSessionID == null)
|
||||
return;
|
||||
// Add the command to the buffer.
|
||||
commandsToSend.push(data);
|
||||
// If the send timer is scheduled and there is enough data to send,
|
||||
// return to let the timer to complete.
|
||||
if (sendTimerScheduled && commandsToSend.length > CONSOLE_MAX_SEND_COMMANDS)
|
||||
return;
|
||||
if (sendTimer != null && sendTimer != "undefined") {
|
||||
clearTimeout(sendTimer);
|
||||
sendTimer = null;
|
||||
}
|
||||
// Schedule the timer.
|
||||
sendTimer = setTimeout(function() {
|
||||
// Clear timer flag.
|
||||
sendTimerScheduled = false;
|
||||
// Build data.
|
||||
var dataToSend = btoa(commandsToSend.join(""));
|
||||
commandsToSend = [];
|
||||
$.post(
|
||||
"../ajax/cli_data",
|
||||
JSON.stringify({
|
||||
"session_id": cliSessionID,
|
||||
"data": dataToSend
|
||||
}),
|
||||
function(data) {
|
||||
// Process only if the console is showing.
|
||||
if (!isConsoleShowing())
|
||||
return;
|
||||
// Process answer.
|
||||
processCLISendDataResponse(data);
|
||||
}
|
||||
).fail(function(response) {
|
||||
// Process only if the console is showing.
|
||||
if (!isConsoleShowing())
|
||||
return;
|
||||
// Process error.
|
||||
processAjaxErrorResponse(response);
|
||||
});
|
||||
}, CONSOLE_SEND_COMMANDS_DELAY);
|
||||
// Set timer flag.
|
||||
sendTimerScheduled = true;
|
||||
}
|
||||
|
||||
// Processes the send CLI data response.
|
||||
function processCLISendDataResponse(response) {
|
||||
// Check if there was any error in the request.
|
||||
checkErrorResponse(response, false);
|
||||
}
|
||||
|
||||
// Closes the console.
|
||||
function closeConsole() {
|
||||
// Check if console is showing.
|
||||
if (!isConsoleShowing())
|
||||
return;
|
||||
// Hide the loading panel.
|
||||
showConsoleLoading(false);
|
||||
// Hide the error reconnect panel.
|
||||
showConsoleErrorReconnect(false);
|
||||
// Terminate the CLI session.
|
||||
terminateCLIsession();
|
||||
// Hide the console.
|
||||
var consolePanel = document.getElementById(ID_CONSOLE_PANEL);
|
||||
consolePanel.style.visibility = "collapse";
|
||||
consolePanel.style.display = "none";
|
||||
}
|
||||
|
||||
// Terminates the CLI session.
|
||||
function terminateCLIsession() {
|
||||
// Check if CLI session exists.
|
||||
if (cliSessionID == null)
|
||||
return;
|
||||
// Flag session terminating.
|
||||
cliSessionTerminating = true;
|
||||
cliTerminateFlagTimer = window.setTimeout(function () {
|
||||
cliSessionTerminating = false;
|
||||
}, 30000); // In the case the terminate request hangs, set a timeout to manually remove the flag.
|
||||
// Send request to terminate CLI session.
|
||||
$.post(
|
||||
"../ajax/cli_terminate_session",
|
||||
JSON.stringify({
|
||||
"session_id": cliSessionID
|
||||
}),
|
||||
function(data) {
|
||||
// Process only if the console is showing.
|
||||
if (!isConsoleShowing())
|
||||
return;
|
||||
// Process answer.
|
||||
processTerminateCLISessionResponse(data);
|
||||
}
|
||||
).fail(function(response) {
|
||||
// Un-flag session terminating.
|
||||
cliSessionTerminating = false;
|
||||
window.clearTimeout(cliTerminateFlagTimer);
|
||||
// Process only if the console is showing.
|
||||
if (!isConsoleShowing())
|
||||
return;
|
||||
// Process error.
|
||||
processAjaxErrorResponse(response);
|
||||
});
|
||||
// Clear CLI session ID.
|
||||
cliSessionID = null;
|
||||
}
|
||||
|
||||
// Processes the terminate CLI session response.
|
||||
function processTerminateCLISessionResponse(response) {
|
||||
// Check if there was any error in the request.
|
||||
if (checkErrorResponse(response, false)) {
|
||||
// Un-flag session terminating.
|
||||
cliSessionTerminating = false;
|
||||
window.clearTimeout(cliTerminateFlagTimer);
|
||||
}
|
||||
}
|
||||
|
||||
// Subscribes to any CLI session change.
|
||||
function subscribeCLISession(sessionID) {
|
||||
// Create the web socket.
|
||||
//var socketPrefix = window.location.protocol == "https:" ? "wss" : "ws";
|
||||
//cliSocket = new WebSocket(socketPrefix + "://" + window.location.host + "/ws/cli/" + device.getDeviceID() + "/" + sessionID);
|
||||
// Define the callback to be notified when data is received in the web socket.
|
||||
cliSocket.onmessage = function(e) {
|
||||
if (isDashboardShowing() && term != null && term != "undefined") {
|
||||
var event = JSON.parse(e.data);
|
||||
var type = event[ID_TYPE];
|
||||
switch (type) {
|
||||
case CLI_MESSAGE_TYPE_DATA:
|
||||
var data = event[ID_DATA];
|
||||
var decodedData = atob(data);
|
||||
if (isConsoleShowing())
|
||||
term.write(decodedData);
|
||||
break;
|
||||
case CLI_MESSAGE_TYPE_TERMINATE:
|
||||
case CLI_MESSAGE_TYPE_ERROR:
|
||||
cliSessionID = null;
|
||||
if (cliSocket != null && cliSocket != "undefined")
|
||||
cliSocket.close();
|
||||
// Hide the loading status.
|
||||
showConsoleLoading(false);
|
||||
// Check specific type.
|
||||
var error = null;
|
||||
if (type == CLI_MESSAGE_TYPE_TERMINATE && isConsoleShowing())
|
||||
error = ERROR_SESSION_CLOSED_REMOTELY;
|
||||
else if (type == CLI_MESSAGE_TYPE_ERROR)
|
||||
error = event[ID_ERROR];
|
||||
if (isConsoleShowing())
|
||||
showConsoleErrorReconnect(true, error);
|
||||
if (error != null && (type == CLI_MESSAGE_TYPE_ERROR ||
|
||||
(type == CLI_MESSAGE_TYPE_TERMINATE && isConsoleShowing())))
|
||||
toastr.error(error);
|
||||
// Un-flag session terminating.
|
||||
cliSessionTerminating = false;
|
||||
window.clearTimeout(cliTerminateFlagTimer);
|
||||
break;
|
||||
case CLI_MESSAGE_TYPE_START:
|
||||
// Hide the loading status.
|
||||
showConsoleLoading(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -22,8 +22,6 @@ const ID_AUDIO_PANEL_ICON = "audio_panel_icon";
|
|||
const ID_AUDIO_SLIDER_CONTAINER = "audio_volume";
|
||||
const ID_BOARD_IMAGE = "board_image";
|
||||
const ID_BOARD_IMAGE_CONTAINER = "board_image_container";
|
||||
const ID_CONSOLE_PANEL_AREA = "console_panel_area";
|
||||
const ID_CONSOLE_PANEL_ICON = "console_panel_icon";
|
||||
const ID_CPU_PANEL = "cpu_panel";
|
||||
const ID_CPU_PANEL_AREA = "cpu_panel_area";
|
||||
const ID_CPU_PANEL_ARROW = "cpu_panel_arrow";
|
||||
|
|
@ -381,11 +379,6 @@ function initializeComponents() {
|
|||
var ethernetPanelIcon = document.getElementById(ID_ETHERNET_PANEL_ICON);
|
||||
var ethernetInfo = {"panel": ethernetPanel, "arrow": ethernetPanelArrow, "area": ethernetPanelArea, "icon": ethernetPanelIcon, "data": device.getEthernetComponentData()};
|
||||
components[ID_ETHERNET] = ethernetInfo;
|
||||
// Console component.
|
||||
var consolePanelArea = document.getElementById(ID_CONSOLE_PANEL_AREA);
|
||||
var consolePanelIcon = document.getElementById(ID_CONSOLE_PANEL_ICON);
|
||||
var consoleInfo = {"area": consolePanelArea, "icon": consolePanelIcon, "data": device.getConsoleComponentData()};
|
||||
components[ID_CONSOLE] = consoleInfo;
|
||||
// Video component.
|
||||
var videoPanel = document.getElementById(ID_VIDEO_PANEL);
|
||||
var videoPanelArrow = document.getElementById(ID_VIDEO_PANEL_ARROW);
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.FitAddon=t():e.FitAddon=t()}(self,(function(){return(()=>{"use strict";var e={775:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FitAddon=void 0;var r=function(){function e(){}return e.prototype.activate=function(e){this._terminal=e},e.prototype.dispose=function(){},e.prototype.fit=function(){var e=this.proposeDimensions();if(e&&this._terminal){var t=this._terminal._core;this._terminal.rows===e.rows&&this._terminal.cols===e.cols||(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}},e.prototype.proposeDimensions=function(){if(this._terminal&&this._terminal.element&&this._terminal.element.parentElement){var e=this._terminal._core;if(0!==e._renderService.dimensions.actualCellWidth&&0!==e._renderService.dimensions.actualCellHeight){var t=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(t.getPropertyValue("height")),i=Math.max(0,parseInt(t.getPropertyValue("width"))),n=window.getComputedStyle(this._terminal.element),o=r-(parseInt(n.getPropertyValue("padding-top"))+parseInt(n.getPropertyValue("padding-bottom"))),a=i-(parseInt(n.getPropertyValue("padding-right"))+parseInt(n.getPropertyValue("padding-left")))-e.viewport.scrollBarWidth;return{cols:Math.max(2,Math.floor(a/e._renderService.dimensions.actualCellWidth)),rows:Math.max(1,Math.floor(o/e._renderService.dimensions.actualCellHeight))}}}},e}();t.FitAddon=r}},t={};return function r(i){if(t[i])return t[i].exports;var n=t[i]={exports:{}};return e[i](n,n.exports,r),n.exports}(775)})()}));
|
||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue