mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Working login + connection list UI stub.
This commit is contained in:
@@ -0,0 +1,88 @@
|
|||||||
|
package net.sourceforge.guacamole.net.basic;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Guacamole - Clientless Remote Desktop
|
||||||
|
* Copyright (C) 2010 Michael Jumper
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
|
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
||||||
|
import net.sourceforge.guacamole.properties.GuacamoleProperties;
|
||||||
|
import net.sourceforge.guacamole.net.basic.properties.BasicGuacamoleProperties;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class BasicLogin extends HttpServlet {
|
||||||
|
|
||||||
|
private Logger logger = LoggerFactory.getLogger(BasicLogin.class);
|
||||||
|
|
||||||
|
private AuthenticationProvider authProvider;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() throws ServletException {
|
||||||
|
|
||||||
|
// Get auth provider instance
|
||||||
|
try {
|
||||||
|
authProvider = GuacamoleProperties.getProperty(BasicGuacamoleProperties.AUTH_PROVIDER);
|
||||||
|
}
|
||||||
|
catch (GuacamoleException e) {
|
||||||
|
logger.error("Error getting authentication provider from properties.", e);
|
||||||
|
throw new ServletException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void service(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws IOException {
|
||||||
|
|
||||||
|
HttpSession httpSession = request.getSession(true);
|
||||||
|
|
||||||
|
// Retrieve username and password from parms
|
||||||
|
String username = request.getParameter("username");
|
||||||
|
String password = request.getParameter("password");
|
||||||
|
|
||||||
|
// Get authorized config
|
||||||
|
GuacamoleConfiguration config;
|
||||||
|
try {
|
||||||
|
config = authProvider.getAuthorizedConfiguration(username, password);
|
||||||
|
}
|
||||||
|
catch (GuacamoleException e) {
|
||||||
|
logger.error("Error retrieving authorized configuration for user {}.", username);
|
||||||
|
response.sendError(HttpServletResponse.SC_FORBIDDEN);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config == null) {
|
||||||
|
logger.warn("Failed login from {} for user \"{}\".", request.getRemoteAddr(), username);
|
||||||
|
response.sendError(HttpServletResponse.SC_FORBIDDEN);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Successful login from {} for user \"{}\".", request.getRemoteAddr(), username);
|
||||||
|
|
||||||
|
httpSession.setAttribute("GUAC_AUTH_CONFIGS", new Integer(0));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@@ -28,6 +28,17 @@
|
|||||||
</session-timeout>
|
</session-timeout>
|
||||||
</session-config>
|
</session-config>
|
||||||
|
|
||||||
|
<!-- Basic Login Servlet -->
|
||||||
|
<servlet>
|
||||||
|
<description>Login servlet.</description>
|
||||||
|
<servlet-name>Login</servlet-name>
|
||||||
|
<servlet-class>net.sourceforge.guacamole.net.basic.BasicLogin</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>Login</servlet-name>
|
||||||
|
<url-pattern>/login</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
<!-- Guacamole Tunnel Servlet -->
|
<!-- Guacamole Tunnel Servlet -->
|
||||||
<servlet>
|
<servlet>
|
||||||
<description>Tunnel servlet.</description>
|
<description>Tunnel servlet.</description>
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div id="login-ui">
|
<div id="login-ui" style="display: none">
|
||||||
<div id="login-dialog-middle">
|
<div id="login-dialog-middle">
|
||||||
|
|
||||||
<div id="login-dialog">
|
<div id="login-dialog">
|
||||||
@@ -60,25 +60,51 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="version-dialog">
|
|
||||||
Guacamole ${project.version}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Main UI - hidden until login succeeds -->
|
<!-- Connection list UI -->
|
||||||
<div id="connection-list-ui" style="display: none">
|
<div id="connection-list-ui" style="display: none">
|
||||||
<!-- STUB -->
|
|
||||||
|
<h1>
|
||||||
|
<img class="logo" src="images/guacamole-logo-64.png" alt=""/>
|
||||||
|
Available Connections
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<table class="connections">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Protocol</th>
|
||||||
|
<th>Description</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>zhz@localhost</td>
|
||||||
|
<td>vnc</td>
|
||||||
|
<td class="description">Connect to test.guac-dev.org via vnc.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>zhz@localhost</td>
|
||||||
|
<td>ssh</td>
|
||||||
|
<td class="description">Connect to test.guac-dev.org via ssh.</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="version-dialog">
|
||||||
|
Guacamole ${project.version}
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Init -->
|
<!-- Init -->
|
||||||
<script type="text/javascript"> /* <![CDATA[ */
|
<script type="text/javascript"> /* <![CDATA[ */
|
||||||
|
|
||||||
var loginForm = document.getElementById("login-form");
|
var loginForm = document.getElementById("login-form");
|
||||||
var loginUI = document.getElementById("login-ui");
|
var loginUI = document.getElementById("login-ui");
|
||||||
var display = document.getElementById("display");
|
var connectionListUI = document.getElementById("connection-list-ui");
|
||||||
|
|
||||||
// TODO: Get connection list
|
// TODO: Get connection list
|
||||||
// On no-auth fail, show login UI
|
// On no-auth fail, show login UI
|
||||||
@@ -93,7 +119,21 @@
|
|||||||
+ "&password=" + encodeURIComponent(password.value)
|
+ "&password=" + encodeURIComponent(password.value)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// STUB
|
|
||||||
|
// Log in
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("POST", "login", false);
|
||||||
|
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||||
|
xhr.send(data);
|
||||||
|
|
||||||
|
// Handle failures
|
||||||
|
if (xhr.status != 200)
|
||||||
|
throw new Error("Invalid login");
|
||||||
|
|
||||||
|
// Hide login UI, display connections
|
||||||
|
loginUI.style.display = "none";
|
||||||
|
connectionListUI.style.display = "";
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
|
||||||
@@ -113,6 +153,8 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loginUI.style.display = "";
|
||||||
|
|
||||||
/* ]]> */ </script>
|
/* ]]> */ </script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
body {
|
body {
|
||||||
background: black;
|
background: gray;
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
@@ -114,7 +114,7 @@ div#login-dialog #login-fields img.logo {
|
|||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
div#login-ui #version-dialog {
|
div#version-dialog {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
right: 0;
|
right: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
@@ -136,3 +136,57 @@ img#license {
|
|||||||
float: right;
|
float: right;
|
||||||
margin: 2px;
|
margin: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div#connection-list-ui {
|
||||||
|
background: #BCA;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#connection-list-ui table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#connection-list-ui table thead {
|
||||||
|
background: #9A8;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#connection-list-ui table thead tr {
|
||||||
|
border-top: 1px solid #676;
|
||||||
|
border-bottom: 1px solid gray;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#connection-list-ui table tbody {
|
||||||
|
background: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#connection-list-ui table tbody tr {
|
||||||
|
border-top: 1px solid gray;
|
||||||
|
border-bottom: 1px solid gray;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#connection-list-ui table td {
|
||||||
|
padding: 0.25em;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#connection-list-ui table tbody tr:nth-child(even) { background: #CCC; }
|
||||||
|
div#connection-list-ui table tbody tr:nth-child(odd) { background: #EEE; }
|
||||||
|
|
||||||
|
div#connection-list-ui table td.description {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#connection-list-ui h1 {
|
||||||
|
|
||||||
|
margin: 0;
|
||||||
|
padding: 0.5em;
|
||||||
|
|
||||||
|
font-size: 2em;
|
||||||
|
vertical-align: middle;
|
||||||
|
text-align: center;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
div#connection-list-ui img {
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
Reference in New Issue
Block a user