17229: Webshell show message when toke is missing
[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       #notoken {
10         position: absolute;
11         top: 0;
12         left: 0;
13         right: 0;
14         bottom: 0;
15         text-align: center;
16         vertical-align: middle;
17         line-height: 100vh;
18         z-index: 100;
19         font-family: sans;
20       }
21     </style>
22     <script type="text/javascript"><!--
23       (function() {
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;' +
35                          '}' +
36                          '</style>');
37         }
38       })();
39       var sh;
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       urlParams = null;
45
46       function login() {
47         sh = new ShellInABox(host);
48
49         var findText = function(txt) {
50           var a = document.querySelectorAll("span.ansi0");
51           for (var i = 0; i < a.length; i++) {
52             if (a[i].textContent.indexOf(txt) > -1) {
53               return true;
54             }
55           }
56           return false;
57         }
58
59         var trySendToken = function() {
60           // change this text when PAM is reconfigured to present a
61           // password prompt that we can wait for.
62           if (findText("assword:")) {
63              sh.keysPressed(token + "\n");
64              sh.vt100('(sent authentication token)\n');
65              token = null;
66           } else {
67             setTimeout(trySendToken, 200);
68           }
69         };
70
71         var trySendLogin = function() {
72           if (findText("login:")) {
73             sh.keysPressed(user + "\n");
74             // Make this wait shorter when PAM is reconfigured to
75             // present a password prompt that we can wait for.
76             setTimeout(trySendToken, 200);
77           } else {
78             setTimeout(trySendLogin, 200);
79           }
80         };
81
82         trySendLogin();
83       }
84
85       function init() {
86         if (token) {
87           history.replaceState(null, "", `/webshell/?host=${encodeURIComponent(host)}&login=${encodeURIComponent(login)}`);
88         } else if (localStorage.getItem('apiToken')) {
89           token = localStorage.getItem('apiToken');
90         } else {
91           document.getElementById("notoken").style.display = "block";
92           return;
93         }
94         login();
95       }
96     // -->
97 </script>
98     <script type="text/javascript" src="shell_in_a_box.js"></script>
99   </head>
100   <!-- Load ShellInABox from a timer as Konqueror sometimes fails to
101        correctly deal with the enclosing frameset (if any), if we do not
102        do this
103    -->
104 <body onload="setTimeout(init, 1000)"
105     scroll="no"><noscript>JavaScript must be enabled for ShellInABox</noscript>
106     <div id="notoken" style="display: none;">
107       Error: No token found. Please return to <a href="/virtual-machines-user">Virtual Machines</a> and try again.
108     </div>
109 </body>
110 </html>