From 0bb7cecf8fe8ef9ae0587a64c87068cba3515ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez?= Date: Wed, 3 Apr 2013 00:54:24 +0000 Subject: [PATCH] Updated so properties can contain a reference to an external file as url container --- .../org/openuds/guacamole/TunnelServlet.java | 43 ++++++++++++++++--- .../src/main/webapp/WEB-INF/tunnel.properties | 6 ++- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/guacamole-tunnel/src/main/java/org/openuds/guacamole/TunnelServlet.java b/guacamole-tunnel/src/main/java/org/openuds/guacamole/TunnelServlet.java index ca44b42f..91559420 100644 --- a/guacamole-tunnel/src/main/java/org/openuds/guacamole/TunnelServlet.java +++ b/guacamole-tunnel/src/main/java/org/openuds/guacamole/TunnelServlet.java @@ -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 params = Util.readParameters( getConfigValue("uds") + UDS_PATH + data); + Hashtable 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 keys = params.keys(); while( keys.hasMoreElements() ) { @@ -78,19 +97,33 @@ 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), - config, info - ); + 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; diff --git a/guacamole-tunnel/src/main/webapp/WEB-INF/tunnel.properties b/guacamole-tunnel/src/main/webapp/WEB-INF/tunnel.properties index c6faa463..309505c4 100644 --- a/guacamole-tunnel/src/main/webapp/WEB-INF/tunnel.properties +++ b/guacamole-tunnel/src/main/webapp/WEB-INF/tunnel.properties @@ -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