3f25aed59b4447a9817f66d1fdd5a722211f19de
[arvados-workbench2.git] / public / webshell / index.html
1 <!DOCTYPE html>
2     <head>
3     <title></title>
4     <link rel="stylesheet" href="styles.css" type="text/css">
5     <style type="text/css">
6       body {
7         margin: 0px;
8       }
9     </style>
10     <script type="text/javascript"><!--
11       (function() {
12         // We would like to hide overflowing lines as this can lead to
13         // visually jarring results if the browser substitutes oversized
14         // Unicode characters from different fonts. Unfortunately, a bug
15         // in Firefox prevents it from allowing multi-line text
16         // selections whenever we change the "overflow" style. So, only
17         // do so for non-Netscape browsers.
18         if (typeof navigator.appName == 'undefined' ||
19             navigator.appName != 'Netscape') {
20           document.write('<style type="text/css">' +
21                          '#vt100 #console div, #vt100 #alt_console div {' +
22                          '  overflow: hidden;' +
23                          '}' +
24                          '</style>');
25         }
26       })();
27
28       function login(username, token) {
29         const urlParams = new URLSearchParams(window.location.search);
30         var sh = new ShellInABox(urlParams.get('host'));
31
32         var findText = function(txt) {
33           var a = document.querySelectorAll("span.ansi0");
34           for (var i = 0; i < a.length; i++) {
35             if (a[i].textContent.indexOf(txt) > -1) {
36               return true;
37             }
38           }
39           return false;
40         }
41
42         var trySendToken = function() {
43           var token = urlParams.get('token');
44           if (token) {
45             history.replaceState(null, "", `/webshell/?host=${encodeURIComponent(urlParams.get('host'))}&login=${encodeURIComponent(urlParams.get('login'))}`)
46           } else if (localStorage.getItem('apiToken')) {
47             token = localStorage.getItem('apiToken');
48           } else {
49             // No token
50           }
51           // change this text when PAM is reconfigured to present a
52           // password prompt that we can wait for.
53           if (findText("assword:")) {
54              sh.keysPressed(token + "\n");
55              sh.vt100('(sent authentication token)\n');
56              token = null;
57           } else {
58             setTimeout(trySendToken, 200);
59           }
60         };
61
62         var trySendLogin = function() {
63           var login = urlParams.get('login');
64           if (findText("login:")) {
65             sh.keysPressed(login + "\n");
66             // Make this wait shorter when PAM is reconfigured to
67             // present a password prompt that we can wait for.
68             setTimeout(trySendToken, 200);
69           } else {
70             setTimeout(trySendLogin, 200);
71           }
72         };
73
74         trySendLogin();
75       }
76     // -->
77 </script>
78     <script type="text/javascript" src="shell_in_a_box.js"></script>
79   </head>
80   <!-- Load ShellInABox from a timer as Konqueror sometimes fails to
81        correctly deal with the enclosing frameset (if any), if we do not
82        do this
83    -->
84 <body onload="setTimeout(login, 1000)"
85     scroll="no"><noscript>JavaScript must be enabled for ShellInABox</noscript>
86 </body>
87 </html>