Removed obviously completed TODO comment.
[guacamole.git] / src / main / webapp / index.xhtml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE html>
3
4 <!--
5     Guacamole - Clientless Remote Desktop
6     Copyright (C) 2010  Michael Jumper
7
8     This program is free software: you can redistribute it and/or modify
9     it under the terms of the GNU Affero General Public License as published by
10     the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU Affero General Public License for more details.
17
18     You should have received a copy of the GNU Affero General Public License
19     along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 -->
21
22 <html xmlns="http://www.w3.org/1999/xhtml">
23
24     <head>
25         <link rel="icon" type="image/png" href="images/guacamole-logo-64.png"/>
26         <link rel="stylesheet" type="text/css" href="styles/login.css"/>
27         <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi"/>
28         <title>Guacamole ${project.version}</title>
29     </head>
30
31     <body>
32
33         <div id="login-ui" style="display: none">
34             <div id="login-dialog-middle">
35
36                 <div id="login-dialog">
37
38                     <p id="login-error"></p>
39
40                     <form id="login-form" action="#" method="post">
41
42                         <div id="login-fields">
43                             <table>
44                                 <tr>
45                                     <th>Username</th>
46                                     <td><input type="text" name="username" id="username" autofocus="autofocus"/></td>
47                                 </tr>
48                                 <tr>
49                                     <th>Password</th>
50                                     <td><input type="password" name="password" id="password"/></td>
51                                 </tr>
52                             </table>
53
54                             <img class="logo" src="images/guacamole-logo-64.png" alt=""/>
55                         </div>
56
57                         <div id="buttons">
58                             <input type="submit" name="login" id="login" value="Login"/>
59                         </div>
60
61                     </form>
62                 </div>
63
64             </div>
65         </div>
66
67         <!-- Connection list UI -->
68         <div id="connection-list-ui" style="display: none">
69
70             <div id="logout-panel">
71                 <button id="logout">Logout</button>
72             </div>
73             
74             <h1>
75                 <img class="logo" src="images/guacamole-logo-64.png" alt=""/>
76                 Available Connections
77             </h1>
78             
79             <table class="connections">
80                 <thead>
81                     <tr>
82                         <th class="protocol"> </th>
83                         <th class="name">Name</th>
84                     </tr>
85                 </thead>
86                 <tbody id="connections-tbody">
87                 </tbody>
88             </table>
89
90         </div>
91
92         <div id="version-dialog">
93             Guacamole ${project.version}
94         </div>
95
96         <script type="text/javascript" src="scripts/connections.js"></script>
97
98         <!-- Init -->
99         <script type="text/javascript"> /* <![CDATA[ */
100
101             function resetUI() {
102
103                 var configs;
104                 try {
105                     configs = getConfigList();
106                 }
107                 catch (e) {
108
109                     // Show login UI if unable to get configs
110                     loginUI.style.display = "";
111                     connectionListUI.style.display = "none";
112
113                     return;
114
115                 }
116
117                 // If only one connection, redirect to that.
118                 if (configs.length == 1) {
119                     window.location.href = "client.xhtml?" + encodeURIComponent(configs[0].id);
120                     return;
121                 }
122
123                 // Remove all rows from connections list
124                 var tbody = document.getElementById("connections-tbody");
125                 tbody.innerHTML = "";
126                 
127                 // Add one row per connection
128                 for (var i=0; i<configs.length; i++) {
129
130                     // Create row and cells
131                     var tr = document.createElement("tr");
132                     var protocol = document.createElement("td");
133                     var id = document.createElement("td");
134
135                     var protocolIcon = document.createElement("div");
136                     protocolIcon.className = "protocol icon " + configs[i].protocol;
137
138                     // Set CSS
139                     protocol.className = "protocol";
140                     id.className = "name";
141
142                     // Create link to client
143                     var clientLink = document.createElement("a");
144                     clientLink.setAttribute("href",
145                         "client.xhtml?" + encodeURIComponent(configs[i].id));
146
147                     // Set cell contents
148                     protocol.appendChild(protocolIcon);
149                     //protocol.textContent   = configs[i].protocol;
150                     clientLink.textContent = configs[i].id;
151                     id.appendChild(clientLink);
152
153                     // Add cells
154                     tr.appendChild(protocol);
155                     tr.appendChild(id);
156
157                     // Add row
158                     tbody.appendChild(tr);
159
160                 }
161
162                 // If configs could be retrieved, display list
163                 loginUI.style.display = "none";
164                 connectionListUI.style.display = "";
165
166             }
167
168             var loginForm = document.getElementById("login-form");
169             var loginUI = document.getElementById("login-ui");
170             var connectionListUI = document.getElementById("connection-list-ui");
171             var logout = document.getElementById("logout");
172
173             logout.onclick = function() {
174                 window.location.href = "logout";
175             };
176
177             loginForm.onsubmit = function() {
178
179                 var username = document.getElementById("username");
180                 var password = document.getElementById("password");
181
182                 var data =
183                        "username=" + encodeURIComponent(username.value)
184                     + "&password=" + encodeURIComponent(password.value)
185
186                 try {
187
188                     // Log in
189                     var xhr = new XMLHttpRequest();
190                     xhr.open("POST", "login", false);
191                     xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
192                     xhr.send(data);
193
194                     // Handle failures
195                     if (xhr.status != 200)
196                         throw new Error("Invalid login");
197
198                     resetUI();
199
200                 }
201                 catch (e) {
202
203                     var loginError = document.getElementById("login-error");
204
205                     // Display error, reset and refocus password field
206                     loginError.textContent = e.message;
207                     password.value = "";
208                     password.focus();
209
210                     return false;
211
212                 }
213
214                 // On success, hide loginUI, get and show connection list.
215                 return false;
216
217             }
218
219             resetUI();
220
221             /* ]]> */ </script>
222
223     </body>
224
225 </html>