Skip to content

Instantly share code, notes, and snippets.

@Cdaprod
Created June 30, 2024 21:12
Show Gist options
  • Save Cdaprod/553c70c0e4e9f2b1a96c3c189bd70fb8 to your computer and use it in GitHub Desktop.
Save Cdaprod/553c70c0e4e9f2b1a96c3c189bd70fb8 to your computer and use it in GitHub Desktop.
This gist provides an approximate guide to extending Apache Guacamole to support the HTTP protocol by creating a custom protocol extension.

Here are the approximate steps to extend Apache Guacamole to support the HTTP protocol. This involves creating a custom protocol extension that integrates with Guacamole's existing framework. Below are the key steps and a brief overview of the process:

Step 1: Understand the Guacamole Extension Mechanism

Guacamole allows the creation of extensions that can add or modify its functionality. These extensions can be written in Java and packaged as .jar files.

Step 2: Create the Extension Structure

Create a new directory structure for your extension. For instance:

my-guacamole-extension/
|-- src/
|   |-- main/
|   |   |-- java/
|   |   |   |-- org/
|   |   |   |   |-- mycompany/
|   |   |   |   |   |-- guacamole/
|   |   |   |   |   |   |-- protocol/
|   |   |   |   |   |   |   |-- http/
|   |   |   |   |   |   |   |   |-- HTTPGuacamoleTunnel.java
|   |   |   |   |   |   |   |   |-- HTTPGuacamoleClient.java
|   |   |-- resources/
|-- pom.xml

Step 3: Implement HTTP Protocol Handling

Implement the necessary classes to handle the HTTP protocol.

HTTPGuacamoleTunnel.java:

package org.mycompany.guacamole.protocol.http;

import org.apache.guacamole.protocol.GuacamoleTunnel;
import org.apache.guacamole.net.GuacamoleSocket;
import org.apache.guacamole.net.InetGuacamoleSocket;
import java.io.IOException;
import java.net.Socket;

public class HTTPGuacamoleTunnel implements GuacamoleTunnel {

    private final GuacamoleSocket socket;

    public HTTPGuacamoleTunnel(String hostname, int port) throws IOException {
        Socket tcpSocket = new Socket(hostname, port);
        this.socket = new InetGuacamoleSocket(tcpSocket);
    }

    @Override
    public GuacamoleSocket getSocket() {
        return socket;
    }
}

HTTPGuacamoleClient.java:

package org.mycompany.guacamole.protocol.http;

import org.apache.guacamole.protocol.GuacamoleClientInformation;
import org.apache.guacamole.protocol.GuacamoleInstruction;
import org.apache.guacamole.protocol.GuacamoleStatus;

import java.io.IOException;

public class HTTPGuacamoleClient {

    private final String hostname;
    private final int port;

    public HTTPGuacamoleClient(String hostname, int port) {
        this.hostname = hostname;
        this.port = port;
    }

    public void connect(GuacamoleClientInformation clientInformation) throws IOException {
        // Implement the connection logic to the HTTP server here
    }

    public GuacamoleInstruction readInstruction() throws IOException {
        // Implement reading instructions from the HTTP server
        return null;
    }

    public void sendInstruction(GuacamoleInstruction instruction) throws IOException {
        // Implement sending instructions to the HTTP server
    }
}

Step 4: Configure Maven

Ensure your pom.xml is correctly configured to build your extension.

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.mycompany</groupId>
    <artifactId>my-guacamole-extension</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>org.apache.guacamole</groupId>
            <artifactId>guacamole-ext</artifactId>
            <version>1.3.0</version>
        </dependency>
    </dependencies>
</project>

Step 5: Build and Deploy Your Extension

Use Maven to build your extension:

mvn clean package

This will generate a .jar file in the target directory. Copy this .jar file to the extensions directory of your Guacamole server.

Step 6: Configure Guacamole

Edit your guacamole.properties to include the new protocol.

lib-directory: /path/to/guacamole/extensions

Step 7: Restart Guacamole Server

Restart your Guacamole server to load the new extension.

Additional Resources

By following these steps, you can extend Guacamole to support the HTTP protocol, allowing you to monitor and interact with your HTTP servers through the Guacamole interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment