From 0ccf1750b4143223e729fc3212b5e4b0a447b420 Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Mon, 20 Sep 2021 17:31:31 -0400 Subject: [PATCH] 17229: Patch shellinabox to cleanly close instead of sending cancel+eof Arvados-DCO-1.1-Signed-off-by: Stephen Smith --- public/webshell/index.html | 4 ++-- public/webshell/shell_in_a_box.js | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/public/webshell/index.html b/public/webshell/index.html index 42ef9a44..028664c4 100644 --- a/public/webshell/index.html +++ b/public/webshell/index.html @@ -59,8 +59,8 @@ var lastTime = localStorage.getItem('lastActiveTimestamp'); if (currentTime - lastTime > idleTimeoutMs) { //logout - sh.sendKeys('03'); // Ctrl + c - sh.sendKeys('04'); // Ctrl + d + sh.reset(); + sh.sessionClosed(); document.body.onmousemove = undefined; document.body.onkeydown = undefined; } else { diff --git a/public/webshell/shell_in_a_box.js b/public/webshell/shell_in_a_box.js index 1002f7a9..c258b5d7 100644 --- a/public/webshell/shell_in_a_box.js +++ b/public/webshell/shell_in_a_box.js @@ -122,7 +122,7 @@ function ShellInABox(url, container) { // Chrome never realizes that the page has loaded. setTimeout(function(shellInABox) { return function() { - shellInABox.sendRequest(); + shellInABox.sendRequest(true); }; }(this), 1); }; @@ -137,6 +137,7 @@ ShellInABox.prototype.sessionClosed = function() { this.vt100('\r\n'); } this.vt100('Session closed.'); + this.currentRequest.abort(); } // Revealing the "reconnect" button is commented out until we hook // up the username+token auto-login mechanism to the new session: @@ -161,14 +162,14 @@ ShellInABox.prototype.reconnect = function() { this.pendingKeys = ''; this.keysInFlight = false; this.reset(true); - this.sendRequest(); + this.sendRequest(true); } } } return false; }; -ShellInABox.prototype.sendRequest = function(request) { +ShellInABox.prototype.sendRequest = function(init = false, request) { if (request == undefined) { request = new XMLHttpRequest(); } @@ -185,7 +186,7 @@ ShellInABox.prototype.sendRequest = function(request) { request.onreadystatechange = function(shellInABox) { return function() { try { - return shellInABox.onReadyStateChange(request); + return shellInABox.onReadyStateChange(request, init); } catch (e) { shellInABox.sessionClosed(); } @@ -193,10 +194,11 @@ ShellInABox.prototype.sendRequest = function(request) { }(this); ShellInABox.lastRequestSent = Date.now(); request.send(content); + this.currentRequest = request; }; -ShellInABox.prototype.onReadyStateChange = function(request) { - if (request.readyState == 4 /* XHR_LOADED */) { +ShellInABox.prototype.onReadyStateChange = function(request, init) { + if (request.readyState == 4 /* XHR_LOADED */ && (this.connected || init)) { if (request.status == 200) { this.connected = true; var response = eval('(' + request.responseText + ')'); @@ -209,12 +211,12 @@ ShellInABox.prototype.onReadyStateChange = function(request) { this.sessionClosed(); } else { this.session = response.session; - this.sendRequest(request); + this.sendRequest(false, request); } } else if (request.status == 0) { if (ShellInABox.lastRequestSent + 2000 < Date.now()) { // Timeout, try again - this.sendRequest(request); + this.sendRequest(false, request); } else { this.vt100('\r\n\r\nRequest failed.'); this.sessionClosed(); -- 2.30.2