X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/32dad59b5b3b8d6bf20cce316967603aa8cf55b8..199b80d7913ae588b098aa653ff0c24181a0a31a:/public/webshell/index.html diff --git a/public/webshell/index.html b/public/webshell/index.html index 4044f994..aae70a97 100644 --- a/public/webshell/index.html +++ b/public/webshell/index.html @@ -41,8 +41,33 @@ var token = urlParams.get('token'); var user = urlParams.get('login'); var host = urlParams.get('host'); + var timeout = urlParams.get('timeout'); urlParams = null; + var idleTimeoutMs = timeout * 1000; + + function updateIdleTimer() { + var currentTime = Date.now(); + var lastTime = localStorage.getItem('lastActiveTimestamp'); + if (currentTime - lastTime > 1000) { + localStorage.setItem('lastActiveTimestamp', currentTime); + } + } + + function checkIdleTimer() { + var currentTime = Date.now(); + var lastTime = localStorage.getItem('lastActiveTimestamp'); + if (currentTime - lastTime > idleTimeoutMs) { + //logout + sh.reset(); + sh.sessionClosed("Session timed out after " + timeout + " seconds."); + document.body.onmousemove = undefined; + document.body.onkeydown = undefined; + } else { + setTimeout(checkIdleTimer, 1000); + } + } + function login() { sh = new ShellInABox(host); @@ -63,6 +88,12 @@ sh.keysPressed(token + "\n"); sh.vt100('(sent authentication token)\n'); token = null; + if (timeout > 0) { + updateIdleTimer(); + document.body.onmousemove = updateIdleTimer; + document.body.onkeydown = updateIdleTimer; + setTimeout(checkIdleTimer, 1000); + } } else { setTimeout(trySendToken, 200); } @@ -84,7 +115,7 @@ function init() { if (token) { - history.replaceState(null, "", `/webshell/?host=${encodeURIComponent(host)}&login=${encodeURIComponent(login)}`); + history.replaceState(null, "", `/webshell/?host=${encodeURIComponent(host)}&timeout=${timeout}&login=${encodeURIComponent(user)}`); } else if (localStorage.getItem('apiToken')) { token = localStorage.getItem('apiToken'); } else {