3

I tried to build a demo guacamole app for ssh from the below tutorial.

http://guac-dev.org/doc/gug/writing-you-own-guacamole-app.html

The app worked just fine as long as the values were hardcoded. But I need to get the hostname/IP from the user. To achieve that I tried using request.getParameter() in the below code :

package org.glyptodon.guacamole.net.example;

import javax.servlet.http.HttpServletRequest;
import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.net.GuacamoleSocket;
import org.glyptodon.guacamole.net.GuacamoleTunnel;
import org.glyptodon.guacamole.net.InetGuacamoleSocket;
import org.glyptodon.guacamole.net.SimpleGuacamoleTunnel;
import org.glyptodon.guacamole.protocol.ConfiguredGuacamoleSocket;
import org.glyptodon.guacamole.protocol.GuacamoleConfiguration;
import org.glyptodon.guacamole.servlet.GuacamoleHTTPTunnelServlet;

public class TutorialGuacamoleTunnelServlet
    extends GuacamoleHTTPTunnelServlet {

    @Override
    protected GuacamoleTunnel doConnect(HttpServletRequest request)
        throws GuacamoleException {

        // Create our configuration
        String hostname = request.getParameter("hostname");
        GuacamoleConfiguration config = new GuacamoleConfiguration();
        config.setProtocol("ssh");
        config.setParameter("hostname", hostname);
        config.setParameter("port", "22");

        // Connect to guacd - everything is hard-coded here.
        GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
            new InetGuacamoleSocket("localhost", 4822),
            config
        );


        // Return a new tunnel which uses the connected socket
        return new SimpleGuacamoleTunnel(socket);

    }

}

But when I try to use it like localhost:8080/guacamole-tutorial-0.9.9?hostname=localhost, it doesn't work. Whereas it works just fine if I hardcode the same values. Please help me out.

1 Answers1

3

you'll need to use JavaScript to pass those parameters to the connect() function of Guacamole.Client. got from here

  <script type="text/javascript">

     // 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
     display.appendChild(guac.getDisplay().getElement());

    // Error handler
     guac.onerror = function(error) {
         alert(error);
         console.log(error);
     };
     // Connect
     guac.connect('ip=192.168.99.100&user=root');** set parameters here**

     // Disconnect on close
     window.onunload = function() {
         guac.disconnect();
     }

   </script>

and In your TutorialGuacamoleTunnelServlet access these as

config.setProtocol("ssh");
config.setParameter("hostname", request.getParameter("ip"));
config.setParameter("username", request.getParameter("user"));
vinay
  • 1,121
  • 2
  • 12
  • 17