forked from shaba/openuds
Updated so properties can contain a reference to an external file as url container
This commit is contained in:
parent
72702db87d
commit
0bb7cecf8f
@ -1,5 +1,8 @@
|
|||||||
package org.openuds.guacamole;
|
package org.openuds.guacamole;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
@ -24,6 +27,8 @@ public class TunnelServlet
|
|||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 2010742981126080080L;
|
private static final long serialVersionUID = 2010742981126080080L;
|
||||||
private static final String UDS_PATH = "/guacamole/";
|
private static final String UDS_PATH = "/guacamole/";
|
||||||
|
private static final String UDSFILE = "udsfile";
|
||||||
|
private static final String UDS = "uds";
|
||||||
|
|
||||||
|
|
||||||
private static Properties config = null;
|
private static Properties config = null;
|
||||||
@ -33,10 +38,21 @@ public class TunnelServlet
|
|||||||
try {
|
try {
|
||||||
config = new Properties();
|
config = new Properties();
|
||||||
config.load(getServletContext().getResourceAsStream("/WEB-INF/tunnel.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 ) {
|
} catch( Exception e ) {
|
||||||
throw new GuacamoleException(e.getMessage(), e);
|
throw new GuacamoleException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
System.out.println("Getting value of " + value + ": " + config.getProperty(value));
|
||||||
|
|
||||||
return config.getProperty(value);
|
return config.getProperty(value);
|
||||||
|
|
||||||
@ -54,13 +70,15 @@ public class TunnelServlet
|
|||||||
throw new GuacamoleException("Can't read required parameters");
|
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 ) {
|
if( params == null ) {
|
||||||
System.out.println("Invalid credentials");
|
System.out.println("Invalid credentials");
|
||||||
throw new GuacamoleException("Can't access required user credentials");
|
throw new GuacamoleException("Can't access required user credentials");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("Got parameters from remote server");
|
||||||
|
|
||||||
GuacamoleClientInformation info = new GuacamoleClientInformation();
|
GuacamoleClientInformation info = new GuacamoleClientInformation();
|
||||||
info.setOptimalScreenWidth(Integer.parseInt(width));
|
info.setOptimalScreenWidth(Integer.parseInt(width));
|
||||||
info.setOptimalScreenHeight(Integer.parseInt(height));
|
info.setOptimalScreenHeight(Integer.parseInt(height));
|
||||||
@ -69,6 +87,7 @@ public class TunnelServlet
|
|||||||
GuacamoleConfiguration config = new GuacamoleConfiguration();
|
GuacamoleConfiguration config = new GuacamoleConfiguration();
|
||||||
config.setProtocol(params.get("protocol"));
|
config.setProtocol(params.get("protocol"));
|
||||||
|
|
||||||
|
System.out.println("PArsing parameters");
|
||||||
|
|
||||||
Enumeration<String> keys = params.keys();
|
Enumeration<String> keys = params.keys();
|
||||||
while( keys.hasMoreElements() ) {
|
while( keys.hasMoreElements() ) {
|
||||||
@ -78,19 +97,33 @@ public class TunnelServlet
|
|||||||
config.setParameter(key, params.get(key));
|
config.setParameter(key, params.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("Opening soket");
|
||||||
|
|
||||||
// Connect to guacd - everything is hard-coded here.
|
// Connect to guacd - everything is hard-coded here.
|
||||||
GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
|
GuacamoleSocket socket = null;
|
||||||
new InetGuacamoleSocket("localhost", 4822),
|
try {
|
||||||
config, info
|
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
|
// Establish the tunnel using the connected socket
|
||||||
GuacamoleTunnel tunnel = new GuacamoleTunnel(socket);
|
GuacamoleTunnel tunnel = new GuacamoleTunnel(socket);
|
||||||
|
|
||||||
|
System.out.println("Initializing tunnel " + tunnel.toString());
|
||||||
|
|
||||||
// Attach tunnel to session
|
// Attach tunnel to session
|
||||||
HttpSession httpSession = request.getSession(true);
|
HttpSession httpSession = request.getSession(true);
|
||||||
GuacamoleSession session = new GuacamoleSession(httpSession);
|
GuacamoleSession session = new GuacamoleSession(httpSession);
|
||||||
session.attachTunnel(tunnel);
|
session.attachTunnel(tunnel);
|
||||||
|
|
||||||
|
System.out.println("Returning tunnel");
|
||||||
|
|
||||||
// Return pre-attached tunnel
|
// Return pre-attached tunnel
|
||||||
return tunnel;
|
return tunnel;
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user