mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +00:00
Working multiple-config login stub.
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
<groupId>net.sourceforge.guacamole</groupId>
|
<groupId>net.sourceforge.guacamole</groupId>
|
||||||
<artifactId>guacamole-default-webapp</artifactId>
|
<artifactId>guacamole-default-webapp</artifactId>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<version>0.4.0</version>
|
<version>0.5.0</version>
|
||||||
<name>guacamole-default-webapp</name>
|
<name>guacamole-default-webapp</name>
|
||||||
<url>http://guacamole.sourceforge.net/</url>
|
<url>http://guacamole.sourceforge.net/</url>
|
||||||
|
|
||||||
|
@@ -18,8 +18,10 @@ package net.sourceforge.guacamole.net.basic;
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
import net.sourceforge.guacamole.GuacamoleException;
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
import net.sourceforge.guacamole.net.InetGuacamoleSocket;
|
import net.sourceforge.guacamole.net.InetGuacamoleSocket;
|
||||||
@@ -59,26 +61,26 @@ public class BasicGuacamoleTunnelServlet extends GuacamoleTunnelServlet {
|
|||||||
|
|
||||||
HttpSession httpSession = request.getSession(true);
|
HttpSession httpSession = request.getSession(true);
|
||||||
|
|
||||||
// Retrieve username and password from parms
|
// Get ID of connection
|
||||||
String username = request.getParameter("username");
|
String id = request.getParameter("id");
|
||||||
String password = request.getParameter("password");
|
|
||||||
|
// Get authorized configs
|
||||||
|
Map<String, GuacamoleConfiguration> configs =
|
||||||
|
(Map<String, GuacamoleConfiguration>)
|
||||||
|
httpSession.getAttribute("GUAC_AUTH_CONFIGS");
|
||||||
|
|
||||||
|
// If no configs in session, not authorized
|
||||||
|
if (configs == null)
|
||||||
|
throw new GuacamoleException("No authorized configurations.");
|
||||||
|
|
||||||
// Get authorized config
|
// Get authorized config
|
||||||
GuacamoleConfiguration config;
|
GuacamoleConfiguration config = configs.get(id);
|
||||||
try {
|
if (config == null) {
|
||||||
config = authProvider.getAuthorizedConfiguration(username, password);
|
logger.error("Error retrieving authorized configuration id={}.", id);
|
||||||
}
|
throw new GuacamoleException("Unknown configuration ID.");
|
||||||
catch (GuacamoleException e) {
|
|
||||||
logger.error("Error retrieving authorized configuration for user {}.", username);
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config == null) {
|
logger.info("Successful connection from {} to \"{}\".", request.getRemoteAddr(), id);
|
||||||
logger.warn("Failed login from {} for user \"{}\".", request.getRemoteAddr(), username);
|
|
||||||
throw new GuacamoleException("Invalid login");
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Successful login from {} for user \"{}\".", request.getRemoteAddr(), username);
|
|
||||||
|
|
||||||
// Configure and connect socket
|
// Configure and connect socket
|
||||||
String hostname = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_HOSTNAME);
|
String hostname = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_HOSTNAME);
|
||||||
|
@@ -19,6 +19,8 @@ package net.sourceforge.guacamole.net.basic;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -80,7 +82,11 @@ public class BasicLogin extends HttpServlet {
|
|||||||
|
|
||||||
logger.info("Successful login from {} for user \"{}\".", request.getRemoteAddr(), username);
|
logger.info("Successful login from {} for user \"{}\".", request.getRemoteAddr(), username);
|
||||||
|
|
||||||
httpSession.setAttribute("GUAC_AUTH_CONFIGS", new Integer(0));
|
// Build map of authorized configs
|
||||||
|
Map<String, GuacamoleConfiguration> configs = new HashMap<String, GuacamoleConfiguration>();
|
||||||
|
configs.put("TEST-UID", config);
|
||||||
|
|
||||||
|
httpSession.setAttribute("GUAC_AUTH_CONFIGS", configs);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,77 @@
|
|||||||
|
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 java.io.PrintWriter;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class ConfigurationList extends HttpServlet {
|
||||||
|
|
||||||
|
private Logger logger = LoggerFactory.getLogger(ConfigurationList.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void service(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws IOException {
|
||||||
|
|
||||||
|
HttpSession httpSession = request.getSession(true);
|
||||||
|
|
||||||
|
// Get authorized configs
|
||||||
|
Map<String, GuacamoleConfiguration> configs =
|
||||||
|
(Map<String, GuacamoleConfiguration>)
|
||||||
|
httpSession.getAttribute("GUAC_AUTH_CONFIGS");
|
||||||
|
|
||||||
|
// If no configs in session, not authorized
|
||||||
|
if (configs == null) {
|
||||||
|
response.sendError(HttpServletResponse.SC_FORBIDDEN);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write XML
|
||||||
|
response.setHeader("Content-Type", "text/xml");
|
||||||
|
PrintWriter out = response.getWriter();
|
||||||
|
out.println("<configs>");
|
||||||
|
|
||||||
|
for (Entry<String, GuacamoleConfiguration> entry : configs.entrySet()) {
|
||||||
|
|
||||||
|
GuacamoleConfiguration config = entry.getValue();
|
||||||
|
|
||||||
|
// Write config
|
||||||
|
out.print("<config id=\"");
|
||||||
|
out.print(entry.getKey());
|
||||||
|
out.print("\" protocol=\"");
|
||||||
|
out.print(config.getProtocol());
|
||||||
|
out.println("\"/>");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
out.println("</configs>");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@@ -39,6 +39,17 @@
|
|||||||
<url-pattern>/login</url-pattern>
|
<url-pattern>/login</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<!-- Configuration List Servlet -->
|
||||||
|
<servlet>
|
||||||
|
<description>Configuration list servlet.</description>
|
||||||
|
<servlet-name>Configs</servlet-name>
|
||||||
|
<servlet-class>net.sourceforge.guacamole.net.basic.ConfigurationList</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>Configs</servlet-name>
|
||||||
|
<url-pattern>/configs</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
<!-- Guacamole Tunnel Servlet -->
|
<!-- Guacamole Tunnel Servlet -->
|
||||||
<servlet>
|
<servlet>
|
||||||
<description>Tunnel servlet.</description>
|
<description>Tunnel servlet.</description>
|
||||||
|
@@ -91,16 +91,6 @@
|
|||||||
new Guacamole.HTTPTunnel("tunnel")
|
new Guacamole.HTTPTunnel("tunnel")
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
// Connect client
|
|
||||||
guac.connect(data);
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
// TODO: Handle exception ...
|
|
||||||
}
|
|
||||||
|
|
||||||
var menu = document.getElementById("menu");
|
var menu = document.getElementById("menu");
|
||||||
var logo = document.getElementById("status-logo");
|
var logo = document.getElementById("status-logo");
|
||||||
|
|
||||||
@@ -325,6 +315,23 @@
|
|||||||
guac.sendKeyEvent(0, KEYSYM_CTRL);
|
guac.sendKeyEvent(0, KEYSYM_CTRL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Get ID
|
||||||
|
var url = window.location.href;
|
||||||
|
var query = url.indexOf("?");
|
||||||
|
var id = url.substring(query+1);
|
||||||
|
|
||||||
|
// Connect client
|
||||||
|
guac.connect("id=" + encodeURIComponent(id));
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
// TODO: Handle exception ...
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ]]> */ </script>
|
/* ]]> */ </script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
@@ -74,22 +74,11 @@
|
|||||||
<table class="connections">
|
<table class="connections">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th class="protocol">Protocol</th>
|
||||||
<th>Protocol</th>
|
<th class="name">Name</th>
|
||||||
<th>Description</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody id="connections-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>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
@@ -102,6 +91,96 @@
|
|||||||
<!-- Init -->
|
<!-- Init -->
|
||||||
<script type="text/javascript"> /* <![CDATA[ */
|
<script type="text/javascript"> /* <![CDATA[ */
|
||||||
|
|
||||||
|
function Config(protocol, id) {
|
||||||
|
this.protocol = protocol;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getConfigList() {
|
||||||
|
|
||||||
|
// Get config list
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("GET", "configs", false);
|
||||||
|
xhr.send(null);
|
||||||
|
|
||||||
|
// If fail, throw error
|
||||||
|
if (xhr.status != 200)
|
||||||
|
throw new Error(xhr.statusText);
|
||||||
|
|
||||||
|
// Otherwise, get list
|
||||||
|
var configs = new Array();
|
||||||
|
|
||||||
|
var configElements = xhr.responseXML.getElementsByTagName("config");
|
||||||
|
for (var i=0; i<configElements.length; i++) {
|
||||||
|
configs.push(new Config(
|
||||||
|
configElements[i].getAttribute("protocol"),
|
||||||
|
configElements[i].getAttribute("id")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return configs;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetUI() {
|
||||||
|
|
||||||
|
var configs;
|
||||||
|
try {
|
||||||
|
configs = getConfigList();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
|
||||||
|
console.log(e);
|
||||||
|
|
||||||
|
// Show login UI if unable to get configs
|
||||||
|
loginUI.style.display = "";
|
||||||
|
connectionListUI.style.display = "none";
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove all rows from connections list
|
||||||
|
var tbody = document.getElementById("connections-tbody");
|
||||||
|
tbody.innerHTML = "";
|
||||||
|
|
||||||
|
// Add one row per connection
|
||||||
|
for (var i=0; i<configs.length; i++) {
|
||||||
|
|
||||||
|
// Create row and cells
|
||||||
|
var tr = document.createElement("tr");
|
||||||
|
var protocol = document.createElement("td");
|
||||||
|
var id = document.createElement("td");
|
||||||
|
|
||||||
|
// Set CSS
|
||||||
|
protocol.className = "protocol";
|
||||||
|
id.className = "name";
|
||||||
|
|
||||||
|
// Create link to client
|
||||||
|
var clientLink = document.createElement("a");
|
||||||
|
clientLink.setAttribute("href",
|
||||||
|
"client.xhtml?" + encodeURIComponent(configs[i].id));
|
||||||
|
|
||||||
|
// Set cell contents
|
||||||
|
protocol.textContent = configs[i].protocol;
|
||||||
|
clientLink.textContent = configs[i].id;
|
||||||
|
id.appendChild(clientLink);
|
||||||
|
|
||||||
|
// Add cells
|
||||||
|
tr.appendChild(protocol);
|
||||||
|
tr.appendChild(id);
|
||||||
|
|
||||||
|
// Add row
|
||||||
|
tbody.appendChild(tr);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// If configs could be retrieved, display list
|
||||||
|
loginUI.style.display = "none";
|
||||||
|
connectionListUI.style.display = "";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
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 connectionListUI = document.getElementById("connection-list-ui");
|
var connectionListUI = document.getElementById("connection-list-ui");
|
||||||
@@ -130,9 +209,7 @@
|
|||||||
if (xhr.status != 200)
|
if (xhr.status != 200)
|
||||||
throw new Error("Invalid login");
|
throw new Error("Invalid login");
|
||||||
|
|
||||||
// Hide login UI, display connections
|
resetUI();
|
||||||
loginUI.style.display = "none";
|
|
||||||
connectionListUI.style.display = "";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
@@ -153,7 +230,7 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loginUI.style.display = "";
|
resetUI();
|
||||||
|
|
||||||
/* ]]> */ </script>
|
/* ]]> */ </script>
|
||||||
|
|
||||||
|
@@ -150,6 +150,16 @@ div#connection-list-ui table thead {
|
|||||||
background: #9A8;
|
background: #9A8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div#connection-list-ui table thead th.protocol {
|
||||||
|
width: 1em;
|
||||||
|
padding: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#connection-list-ui table thead th.name {
|
||||||
|
text-align: left;
|
||||||
|
padding: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
div#connection-list-ui table thead tr {
|
div#connection-list-ui table thead tr {
|
||||||
border-top: 1px solid #676;
|
border-top: 1px solid #676;
|
||||||
border-bottom: 1px solid gray;
|
border-bottom: 1px solid gray;
|
||||||
@@ -169,6 +179,10 @@ div#connection-list-ui table td {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div#connection-list-ui table td.name {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
div#connection-list-ui table tbody tr:nth-child(even) { background: #CCC; }
|
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 tbody tr:nth-child(odd) { background: #EEE; }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user