mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-03 01:17:56 +03:00
A few commits with structural fixes :(
* Html5 client based rcp/vnc client based on Guacamole Api. The idea behind this is to use an URL as transport provider for Guacamole Transport inside UDS (not done already, but thinking about it...). Using the provided code (this code is under AGPLv3), we can: 1.- Broker will connect to a servlet here, passing in the needed credentials for connection. 2.- Broker will redirect user to index.xhtml, with credentials identification within URL 3.- Client will get this credentials & params, and make the connection 4.- On exit, it will return to broker
This commit is contained in:
parent
51f9a7992c
commit
ec0e3c6dee
@ -1,5 +1,8 @@
|
||||
package org.openuds.guacamole;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
@ -7,6 +10,7 @@ import net.sourceforge.guacamole.net.GuacamoleSocket;
|
||||
import net.sourceforge.guacamole.net.GuacamoleTunnel;
|
||||
import net.sourceforge.guacamole.net.InetGuacamoleSocket;
|
||||
import net.sourceforge.guacamole.protocol.ConfiguredGuacamoleSocket;
|
||||
import net.sourceforge.guacamole.protocol.GuacamoleClientInformation;
|
||||
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
||||
import net.sourceforge.guacamole.servlet.GuacamoleHTTPTunnelServlet;
|
||||
import net.sourceforge.guacamole.servlet.GuacamoleSession;
|
||||
@ -14,27 +18,67 @@ import net.sourceforge.guacamole.servlet.GuacamoleSession;
|
||||
public class TunnelServlet
|
||||
extends GuacamoleHTTPTunnelServlet {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2010742981126080080L;
|
||||
|
||||
@Override
|
||||
protected GuacamoleTunnel doConnect(HttpServletRequest request)
|
||||
throws GuacamoleException {
|
||||
|
||||
String data = request.getParameter("data");
|
||||
if( data == null )
|
||||
return null;
|
||||
String width = request.getParameter("width");
|
||||
String height = request.getParameter("height");
|
||||
|
||||
System.out.println("Valor: " + data);
|
||||
if( data == null || width == null || height == null)
|
||||
throw new GuacamoleException("Can't read required parameters");
|
||||
|
||||
HttpSession rSession = request.getSession();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Hashtable<String,String> params = (Hashtable<String,String>)rSession.getAttribute(data);
|
||||
|
||||
|
||||
// Parameters not owned by user session, get them from remote server
|
||||
// (one time shot at other side, so they can't be retrieved again)
|
||||
if( params == null ) {
|
||||
try {
|
||||
params = Util.readParameters(data);
|
||||
rSession.setAttribute(data, params);
|
||||
} catch(Exception e) {
|
||||
throw new GuacamoleException("Getting broker data", e);
|
||||
}
|
||||
}
|
||||
else
|
||||
System.out.println("Params got from session");
|
||||
|
||||
GuacamoleClientInformation info = new GuacamoleClientInformation();
|
||||
info.setOptimalScreenWidth(Integer.parseInt(width));
|
||||
info.setOptimalScreenHeight(Integer.parseInt(height));
|
||||
|
||||
// Create our configuration
|
||||
GuacamoleConfiguration config = new GuacamoleConfiguration();
|
||||
config.setProtocol("rdp");
|
||||
config.setParameter("hostname", "w7adolfo");
|
||||
config.setParameter("username", "admin");
|
||||
config.setParameter("password", "temporal");
|
||||
config.setProtocol(params.get("protocol"));
|
||||
|
||||
|
||||
Enumeration<String> keys = params.keys();
|
||||
while( keys.hasMoreElements() ) {
|
||||
String key = keys.nextElement();
|
||||
if( "protocol".equals(key) )
|
||||
continue;
|
||||
config.setParameter(key, params.get(key));
|
||||
}
|
||||
|
||||
|
||||
//config.setParameter("hostname", "w7adolfo");
|
||||
//config.setParameter("username", "admin");
|
||||
//config.setParameter("password", "temporal");
|
||||
|
||||
// Connect to guacd - everything is hard-coded here.
|
||||
GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
|
||||
new InetGuacamoleSocket("localhost", 4822),
|
||||
config
|
||||
config, info
|
||||
);
|
||||
|
||||
// Establish the tunnel using the connected socket
|
||||
|
@ -0,0 +1,67 @@
|
||||
package org.openuds.guacamole;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Hashtable;
|
||||
|
||||
public class Util {
|
||||
|
||||
public static Hashtable<String,String> readParameters(String data) {
|
||||
//String url = unscramble(data);
|
||||
//String params = getUrl(url);
|
||||
//return parseParams(params);
|
||||
return parseParams("protocol\trdp\nhostname\tw7adolfo\nusername\tadmin\npassword\ttemporal");
|
||||
}
|
||||
|
||||
public static Hashtable<String,String> parseParams(String params)
|
||||
{
|
||||
Hashtable<String,String> res = new Hashtable<String, String>();
|
||||
String[] parms = params.split("\n");
|
||||
for( int i = 0; i < parms.length; i++) {
|
||||
String[] val = parms[i].split("\t");
|
||||
if( val.length == 1 )
|
||||
res.put(val[0], "");
|
||||
else
|
||||
res.put(val[0], val[1]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static String unscramble(String in)
|
||||
{
|
||||
int len = in.length();
|
||||
StringBuilder res = new StringBuilder(len/2);
|
||||
int val = 0x32;
|
||||
for( int i = 0; i < len; i += 2) {
|
||||
String b = in.substring(i, i+2);
|
||||
int c = Integer.parseInt(b, 16)^val;
|
||||
val = (val + c) & 0xFF;
|
||||
res.append((char)c);
|
||||
}
|
||||
|
||||
return res.reverse().toString();
|
||||
}
|
||||
|
||||
|
||||
public static String getUrl(String url) {
|
||||
try {
|
||||
java.net.URL u = new java.net.URL(url);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(u.openStream()));
|
||||
StringBuilder data = new StringBuilder();
|
||||
|
||||
String inputLine;
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
data.append(inputLine);
|
||||
data.append("\n");
|
||||
}
|
||||
|
||||
in.close();
|
||||
return data.toString();
|
||||
|
||||
} catch(Exception e) {
|
||||
System.out.println("Unable to get url. Network error? " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
guacamole-tunnel/src/main/svn-commit.tmp
Normal file
11
guacamole-tunnel/src/main/svn-commit.tmp
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
--This line, and those below, will be ignored--
|
||||
|
||||
A + webapp/index.xhtml
|
||||
A webapp/styles
|
||||
A webapp/styles/client.css
|
||||
A webapp/images
|
||||
AM webapp/images/guacamole-logo-64.png
|
||||
D webapp/WEB-INF/index.html
|
||||
M webapp/WEB-INF/web.xml
|
||||
D webapp/index.html
|
129
guacamole-tunnel/src/main/webapp/index.xhtml
Normal file
129
guacamole-tunnel/src/main/webapp/index.xhtml
Normal file
@ -0,0 +1,129 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE HTML>
|
||||
|
||||
<!--
|
||||
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/>.
|
||||
-->
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi"/>
|
||||
<meta name="apple-mobile-web-app-capable" content="yes"/>
|
||||
|
||||
<title>Simple RDP Tunneling Test</title>
|
||||
|
||||
<!-- Client core scripts -->
|
||||
<link rel="icon" type="image/png" href="images/guacamole-logo-64.png"/>
|
||||
<link rel="stylesheet" type="text/css" href="styles/client.css"/>
|
||||
|
||||
<script type="text/javascript" src="guacamole-common-js/keyboard.js"></script>
|
||||
<script type="text/javascript" src="guacamole-common-js/mouse.js"></script>
|
||||
<script type="text/javascript" src="guacamole-common-js/layer.js"></script>
|
||||
<script type="text/javascript" src="guacamole-common-js/tunnel.js"></script>
|
||||
<script type="text/javascript" src="guacamole-common-js/audio.js"></script>
|
||||
<script type="text/javascript" src="guacamole-common-js/guacamole.js"></script>
|
||||
<script type="text/javascript" src="guacamole-common-js/oskeyboard.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- Display -->
|
||||
<div class="displayOuter">
|
||||
<div class="displayMiddle">
|
||||
<div id="display">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="viewportClone"/>
|
||||
|
||||
<!-- Init -->
|
||||
<script type="text/javascript"> /* <![CDATA[ */
|
||||
window.onload = function() {
|
||||
window.setTimeout(function() {
|
||||
// Get parameter information, so we can retrieve connecton data
|
||||
var data = window.location.search.substr(1);
|
||||
|
||||
// Get display div from document
|
||||
var display = document.getElementById("display");
|
||||
|
||||
// Instantiate client, using an HTTP tunnel for communications.
|
||||
var guac = new Guacamole.Client(
|
||||
new Guacamole.HTTPTunnel("tunnel")
|
||||
);
|
||||
|
||||
|
||||
// Add client to display div
|
||||
var inner = guac.getDisplay();
|
||||
inner.className = "software-cursor";
|
||||
|
||||
// Error handler
|
||||
guac.onerror = function(error) {
|
||||
alert(error);
|
||||
};
|
||||
|
||||
var optimal_width = window.innerWidth;
|
||||
var optimal_height = window.innerHeight;
|
||||
// Scale width/height to be at least 600x600
|
||||
if (optimal_width < 600 || optimal_height < 600) {
|
||||
var scale = Math.max(600 / optimal_width, 600 / optimal_height);
|
||||
optimal_width = Math.floor(optimal_width * scale);
|
||||
optimal_height = Math.floor(optimal_height * scale);
|
||||
}
|
||||
// Get entire query string, and pass to connect().
|
||||
// Normally, only the "id" parameter is required, but
|
||||
// all parameters should be preserved and passed on for
|
||||
// the sake of authentication.
|
||||
var connect_string = "data=" + data + "&width=" + optimal_width + "&height=" + optimal_height;
|
||||
|
||||
display.appendChild(inner);
|
||||
|
||||
guac.connect(connect_string);
|
||||
|
||||
// Disconnect on close
|
||||
window.onunload = function() {
|
||||
guac.disconnect();
|
||||
}
|
||||
|
||||
// Mouse
|
||||
var mouse = new Guacamole.Mouse(inner);
|
||||
|
||||
mouse.onmousedown =
|
||||
mouse.onmouseup =
|
||||
mouse.onmousemove = function(mouseState) {
|
||||
guac.sendMouseState(mouseState);
|
||||
};
|
||||
|
||||
// Keyboard
|
||||
var keyboard = new Guacamole.Keyboard(document);
|
||||
|
||||
keyboard.onkeydown = function (keysym) {
|
||||
guac.sendKeyEvent(1, keysym);
|
||||
};
|
||||
|
||||
keyboard.onkeyup = function (keysym) {
|
||||
guac.sendKeyEvent(0, keysym);
|
||||
};
|
||||
}, 0);
|
||||
};
|
||||
/* ]]> */ </script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user