Updated so properties can contain a reference to an external file as url container

This commit is contained in:
Adolfo Gómez 2013-04-03 00:54:24 +00:00
parent 72702db87d
commit 0bb7cecf8f
2 changed files with 43 additions and 6 deletions

View File

@ -1,5 +1,8 @@
package org.openuds.guacamole;
import java.io.BufferedReader;
import java.io.FileReader;
import java.net.URL;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
@ -24,6 +27,8 @@ public class TunnelServlet
*/
private static final long serialVersionUID = 2010742981126080080L;
private static final String UDS_PATH = "/guacamole/";
private static final String UDSFILE = "udsfile";
private static final String UDS = "uds";
private static Properties config = null;
@ -33,10 +38,21 @@ public class TunnelServlet
try {
config = new Properties();
config.load(getServletContext().getResourceAsStream("/WEB-INF/tunnel.properties"));
if( null != config.getProperty(UDSFILE)) {
BufferedReader bufferedReader = new BufferedReader(new FileReader(config.getProperty(UDSFILE)));
URL u = new URL(bufferedReader.readLine());
String uds = u.getProtocol() + "://" + u.getAuthority();
bufferedReader.close();
config.put(UDS, uds);
}
} catch( Exception e ) {
throw new GuacamoleException(e.getMessage(), e);
}
}
System.out.println("Getting value of " + value + ": " + config.getProperty(value));
return config.getProperty(value);
@ -54,13 +70,15 @@ public class TunnelServlet
throw new GuacamoleException("Can't read required parameters");
Hashtable<String,String> params = Util.readParameters( getConfigValue("uds") + UDS_PATH + data);
Hashtable<String,String> params = Util.readParameters( getConfigValue(UDS) + UDS_PATH + data);
if( params == null ) {
System.out.println("Invalid credentials");
throw new GuacamoleException("Can't access required user credentials");
}
System.out.println("Got parameters from remote server");
GuacamoleClientInformation info = new GuacamoleClientInformation();
info.setOptimalScreenWidth(Integer.parseInt(width));
info.setOptimalScreenHeight(Integer.parseInt(height));
@ -69,6 +87,7 @@ public class TunnelServlet
GuacamoleConfiguration config = new GuacamoleConfiguration();
config.setProtocol(params.get("protocol"));
System.out.println("PArsing parameters");
Enumeration<String> keys = params.keys();
while( keys.hasMoreElements() ) {
@ -78,20 +97,34 @@ public class TunnelServlet
config.setParameter(key, params.get(key));
}
System.out.println("Opening soket");
// Connect to guacd - everything is hard-coded here.
GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
new InetGuacamoleSocket("localhost", 4822),
GuacamoleSocket socket = null;
try {
socket = new ConfiguredGuacamoleSocket(
new InetGuacamoleSocket("127.0.0.1", 4822),
config, info
);
} catch( Exception e ) {
System.out.print(e.getMessage());
System.out.print(e);
}
System.out.println("Initializing socket " + socket.toString());
// Establish the tunnel using the connected socket
GuacamoleTunnel tunnel = new GuacamoleTunnel(socket);
System.out.println("Initializing tunnel " + tunnel.toString());
// Attach tunnel to session
HttpSession httpSession = request.getSession(true);
GuacamoleSession session = new GuacamoleSession(httpSession);
session.attachTunnel(tunnel);
System.out.println("Returning tunnel");
// Return pre-attached tunnel
return tunnel;

View File

@ -1 +1,5 @@
uds=http://172.27.0.1:8000
# We can specify the uds server here as:
# uds=http://172.27.0.1:8000
# Or we can get the server from an external file. The path part of the URL inside the file will be removed,
# so, if we put "https://example.com/other", the value of uds configuration will be "https://example.com"
udsfile=/var/ssh_443/etc/uds.conf