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.sendKeys('03'); // Ctrl + c
+ sh.sendKeys('04'); // Ctrl + d
+ } else {
+ setTimeout(checkIdleTimer, 1000);
+ }
+ }
+
function login() {
sh = new ShellInABox(host);
sh.keysPressed(token + "\n");
sh.vt100('(sent authentication token)\n');
token = null;
+ updateIdleTimer();
+ document.body.onmousemove = updateIdleTimer;
+ document.body.onkeydown = updateIdleTimer;
+ setTimeout(checkIdleTimer, 1000);
} else {
setTimeout(trySendToken, 200);
}
function init() {
if (token) {
- history.replaceState(null, "", `/webshell/?host=${encodeURIComponent(host)}&login=${encodeURIComponent(user)}`);
+ history.replaceState(null, "", `/webshell/?host=${encodeURIComponent(host)}&timeout=${timeout}&login=${encodeURIComponent(user)}`);
} else if (localStorage.getItem('apiToken')) {
token = localStorage.getItem('apiToken');
} else {
import { HelpIcon } from 'components/icon/icon';
import { SESSION_STORAGE } from "services/auth-service/auth-service";
// import * as CopyToClipboard from 'react-copy-to-clipboard';
+import parse from "parse-duration";
type CssRules = 'button' | 'codeSnippet' | 'link' | 'linkIcon' | 'rightAlign' | 'cardWithoutMachines' | 'icon';
token: state.auth.extraApiToken || state.auth.apiToken || '',
tokenLocation: state.auth.extraApiToken ? EXTRA_TOKEN : (state.auth.apiTokenLocation || ''),
webshellUrl: state.auth.config.clusterConfig.Services.WebShell.ExternalURL,
+ idleTimeout: parse(state.auth.config.clusterConfig.Workbench.IdleTimeout, 's') || 0,
...state.virtualMachines
};
};
helpText: string;
hostSuffix: string;
token: string;
- tokenLocation: string,
+ tokenLocation: string;
webshellUrl: string;
+ idleTimeout: number;
}
interface VirtualMachinesPanelActionProps {
{command}
</TableCell>
<TableCell>
- <a href={`/webshell/?host=${encodeURIComponent(props.webshellUrl + '/' + it.hostname)}&login=${encodeURIComponent(username)}${tokenParam}`} target="_blank" rel="noopener noreferrer" className={props.classes.link}>
+ <a href={`/webshell/?host=${encodeURIComponent(props.webshellUrl + '/' + it.hostname)}&timeout=${props.idleTimeout}&login=${encodeURIComponent(username)}${tokenParam}`} target="_blank" rel="noopener noreferrer" className={props.classes.link}>
Log in as {username}
</a>
</TableCell>