微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

制作自定义鳄梨酱 Web 应用程序所需的配置

如何解决制作自定义鳄梨酱 Web 应用程序所需的配置

我正在制作我自己的定制 Web 应用程序,它将取代 guacamole Web 应用程序前端。我正在关注 guacamole 手册,根据我们需要一个 index.html,另一个是 servlet,它是一个扩展 GuacamoleHTTPTunnelServlet 的类。 index.html 页面获取虚拟机的凭据以对用户进行身份验证,并在后台进入 guacamole 服务器并进行身份验证并在建立连接时提供相应的虚拟机。

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:doConnect() 函数返回一个 GuacamoleTunnel,它为 GuacamoleHTTPTunnelServlet 提供了一个持久的通信通道,用于在与 guacd 交谈并使用一些任意远程桌面协议启动与某个任意远程桌面的连接时使用。在我们的简单隧道中,此配置将被硬编码,并且不会尝试任何身份验证。

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

    }

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。