4 <link rel="stylesheet" href="styles.css" type="text/css">
5 <style type="text/css">
16 vertical-align: middle;
22 <script type="text/javascript"><!--
24 // We would like to hide overflowing lines as this can lead to
25 // visually jarring results if the browser substitutes oversized
26 // Unicode characters from different fonts. Unfortunately, a bug
27 // in Firefox prevents it from allowing multi-line text
28 // selections whenever we change the "overflow" style. So, only
29 // do so for non-Netscape browsers.
30 if (typeof navigator.appName == 'undefined' ||
31 navigator.appName != 'Netscape') {
32 document.write('<style type="text/css">' +
33 '#vt100 #console div, #vt100 #alt_console div {' +
34 ' overflow: hidden;' +
40 var urlParams = new URLSearchParams(window.location.search);
41 var token = urlParams.get('token');
42 var user = urlParams.get('login');
43 var host = urlParams.get('host');
44 var timeout = urlParams.get('timeout');
47 var idleTimeoutMs = timeout * 1000;
49 function updateIdleTimer() {
50 var currentTime = Date.now();
51 var lastTime = localStorage.getItem('lastActiveTimestamp');
52 if (currentTime - lastTime > 1000) {
53 localStorage.setItem('lastActiveTimestamp', currentTime);
57 function checkIdleTimer() {
58 var currentTime = Date.now();
59 var lastTime = localStorage.getItem('lastActiveTimestamp');
60 if (currentTime - lastTime > idleTimeoutMs) {
64 document.body.onmousemove = undefined;
65 document.body.onkeydown = undefined;
67 setTimeout(checkIdleTimer, 1000);
72 sh = new ShellInABox(host);
74 var findText = function(txt) {
75 var a = document.querySelectorAll("span.ansi0");
76 for (var i = 0; i < a.length; i++) {
77 if (a[i].textContent.indexOf(txt) > -1) {
84 var trySendToken = function() {
85 // change this text when PAM is reconfigured to present a
86 // password prompt that we can wait for.
87 if (findText("assword:")) {
88 sh.keysPressed(token + "\n");
89 sh.vt100('(sent authentication token)\n');
92 document.body.onmousemove = updateIdleTimer;
93 document.body.onkeydown = updateIdleTimer;
94 setTimeout(checkIdleTimer, 1000);
96 setTimeout(trySendToken, 200);
100 var trySendLogin = function() {
101 if (findText("login:")) {
102 sh.keysPressed(user + "\n");
103 // Make this wait shorter when PAM is reconfigured to
104 // present a password prompt that we can wait for.
105 setTimeout(trySendToken, 200);
107 setTimeout(trySendLogin, 200);
116 history.replaceState(null, "", `/webshell/?host=${encodeURIComponent(host)}&timeout=${timeout}&login=${encodeURIComponent(user)}`);
117 } else if (localStorage.getItem('apiToken')) {
118 token = localStorage.getItem('apiToken');
120 document.getElementById("notoken").style.display = "block";
127 <script type="text/javascript" src="shell_in_a_box.js"></script>
129 <!-- Load ShellInABox from a timer as Konqueror sometimes fails to
130 correctly deal with the enclosing frameset (if any), if we do not
133 <body onload="setTimeout(init, 1000)"
134 scroll="no"><noscript>JavaScript must be enabled for ShellInABox</noscript>
135 <div id="notoken" style="display: none;">
136 Error: No token found. Please return to <a href="/virtual-machines-user">Virtual Machines</a> and try again.