0

I am making my own customized web application which is going to replace guacamole web application front end. I am following guacamole manual, according to that we required one index.html and another one is servlet which a class that extends GuacamoleHTTPTunnelServlet. index.html page takes credential for virtual machine to authenticate user and on the background it goes to guacamole server and do authentication and provide respective virtual machine if there is connection establish.

index.html

<!DOCTYPE HTML>
<html>

    <head>
        <title>Guacamole Tutorial</title>
    </head>

    <body>
<!-- Guacamole -->
        <script type="text/javascript"
            src="guacamole-common-js/all.min.js"></script>

        <!-- Display -->
        <div id="display"></div>

        <!-- Init -->
        <script type="text/javascript"> /* <![CDATA[ */

            // 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);
            };

            // Connect
            guac.connect();

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

        /* ]]> */ </script>

        <p>Hello World</p>
    </body>
 <!-- Init -->
        <script type="text/javascript"> /* <![CDATA[ */

            ...

            // Mouse
            var mouse = new Guacamole.Mouse(guac.getDisplay().getElement());

            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);
            };

        /* ]]> */ </script>

</html>

Servlet:The doConnect() function returns a GuacamoleTunnel, which provides a persistent communication channel for GuacamoleHTTPTunnelServlet to use when talking with guacd and initiating a connection with some arbitrary remote desktop using some arbitrary remote desktop protocol. In our simple tunnel, this configuration will be hard-coded, and no authentication will be attempted.

package org.apache.guacamole.net.example;

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

public class TutorialGuacamoleTunnelServlet
    extends GuacamoleHTTPTunnelServlet {

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

        // Create our configuration
        GuacamoleConfiguration config = new GuacamoleConfiguration();
        config.setProtocol("vnc");
        config.setParameter("hostname", "localhost");
        config.setParameter("port", "5901");
        config.setParameter("password", "potato");

        // 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);;

    }

}
jyotsna
  • 51
  • 9
  • What is the question? – mnikolic Feb 16 '21 at 20:29
  • What is your question? Do you want to setting the Socket without hard coded code? – Han Feb 17 '21 at 05:18
  • My question is that this part of code is enough do I need to add more files to this project – jyotsna Feb 17 '21 at 06:00
  • If I am replacing guacamole web application to my web page what credential need to be authenticate guacamole server or virtual machine in hard coded part – jyotsna Feb 17 '21 at 06:06
  • I am new to this guacamole need some ideas and guidance. Thanks in advance – jyotsna Feb 17 '21 at 06:08
  • If you have some authentication information, how about use properties, XML or JSON? you need to write your authentication information in the file(properties, XML, or JSON) by the rule. after that, you read and use your read information when you call doConnect() method – Han Feb 17 '21 at 13:46
  • I am using XML.Do I need to create any environment before building this application – jyotsna Feb 17 '21 at 14:19
  • @Han where we are using doConnect() in index page – jyotsna Feb 27 '21 at 12:00

0 Answers0