Working login + connection list UI stub.
[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         <title>Guacamole ${project.version}</title>
28     </head>
29
30     <body>
31
32         <div id="login-ui" style="display: none">
33             <div id="login-dialog-middle">
34
35                 <div id="login-dialog">
36
37                     <p id="login-error"></p>
38
39                     <form id="login-form" action="#" method="post">
40
41                         <div id="login-fields">
42                             <table>
43                                 <tr>
44                                     <th>Username</th>
45                                     <td><input type="text" name="username" id="username" autofocus="autofocus"/></td>
46                                 </tr>
47                                 <tr>
48                                     <th>Password</th>
49                                     <td><input type="password" name="password" id="password"/></td>
50                                 </tr>
51                             </table>
52
53                             <img class="logo" src="images/guacamole-logo-64.png" alt=""/>
54                         </div>
55
56                         <div id="buttons">
57                             <input type="submit" name="login" id="login" value="Login"/>
58                         </div>
59
60                     </form>
61                 </div>
62
63             </div>
64         </div>
65
66         <!-- Connection list UI -->
67         <div id="connection-list-ui" style="display: none">
68
69             <h1>
70                 <img class="logo" src="images/guacamole-logo-64.png" alt=""/>
71                 Available Connections
72             </h1>
73             
74             <table class="connections">
75                 <thead>
76                     <tr>
77                         <th>Name</th>
78                         <th>Protocol</th>
79                         <th>Description</th>
80                     </tr>
81                 </thead>
82                 <tbody>
83                     <tr>
84                         <td>zhz@localhost</td>
85                         <td>vnc</td>
86                         <td class="description">Connect to test.guac-dev.org via vnc.</td>
87                     </tr>
88                     <tr>
89                         <td>zhz@localhost</td>
90                         <td>ssh</td>
91                         <td class="description">Connect to test.guac-dev.org via ssh.</td>
92                     </tr>
93                 </tbody>
94             </table>
95
96         </div>
97
98         <div id="version-dialog">
99             Guacamole ${project.version}
100         </div>
101
102         <!-- Init -->
103         <script type="text/javascript"> /* <![CDATA[ */
104
105             var loginForm = document.getElementById("login-form");
106             var loginUI = document.getElementById("login-ui");
107             var connectionListUI = document.getElementById("connection-list-ui");
108
109             // TODO: Get connection list
110             // On no-auth fail, show login UI 
111
112             loginForm.onsubmit = function() {
113
114                 var username = document.getElementById("username");
115                 var password = document.getElementById("password");
116
117                 var data =
118                        "username=" + encodeURIComponent(username.value)
119                     + "&password=" + encodeURIComponent(password.value)
120
121                 try {
122
123                     // Log in
124                     var xhr = new XMLHttpRequest();
125                     xhr.open("POST", "login", false);
126                     xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
127                     xhr.send(data);
128
129                     // Handle failures
130                     if (xhr.status != 200)
131                         throw new Error("Invalid login");
132
133                     // Hide login UI, display connections
134                     loginUI.style.display = "none";
135                     connectionListUI.style.display = "";
136
137                 }
138                 catch (e) {
139
140                     var loginError = document.getElementById("login-error");
141
142                     // Display error, reset and refocus password field
143                     loginError.textContent = e.message;
144                     password.value = "";
145                     password.focus();
146
147                     return false;
148
149                 }
150
151                 // On success, hide loginUI, get and show connection list.
152                 return false;
153
154             }
155
156             loginUI.style.display = "";
157
158             /* ]]> */ </script>
159
160     </body>
161
162 </html>