guacamole-brite

Based on guacamole-lite by Vadim Pronin.

Usage no npm install needed!

<script type="module">
  import guacamoleBrite from 'https://cdn.skypack.dev/guacamole-brite';
</script>

README

Based on guacamole-lite by Vadim Pronin.

Functionality remains largely the same and I highly recommend reading through the guacamole-lite README for a detailed explanation.

Description

Guacamole-brite is a Typescript port of guacamole-lite, with updated dependencies and minor usage changes.

It acts as a NodeJS replacement for guacamole-client (server-side Java servlet). Guacamole is a RDP/VNC client for HTML5 browsers.

Major changes

  • Typescript

  • Crypto replaced by CryptoJS.

  • Callbacks do not return flattened connection settings.

Installation

npm install --save guacamole-brite

Code example

Simple example which accepts connections to port 8080 and forwards all traffic to guacd on port 4822:

import { Server, LogLevel } from 'guacamole-brite';

const clientOptions = {
  secretKey: 'MySuperSecretKeyForParamsToken',
  log: {
    level: LogLevel.DBG,
  },
};

const server = new Server({}, {}, clientOptions);

Log levels:

NON = 0,
ERR = 10,
INF = 20,
DBG = 30,

Example with callback and events:

import { Server, LogLevel, IClientConfiguration, IGuacdConfiguration, IWebSocketConfiguration, ICallback } from 'guacamole-brite';

const guacdConfig: IGuacdConfiguration = {
  port: 4822,
  host: '127.0.0.1',
};

const webSocketConfig: IWebSocketConfiguration = {
  port: 8080,
};

const clientConfig: IClientConfiguration = {
  secretKey: 'MySuperSecretKeyForParamsToken',
  log: {
    level: LogLevel.INF,
    stdLog: (...args) => {
      console.log('[MyLog]', ...args);
    },
    errorLog: (...args) => {
      console.error('[MyLog]', ...args);
    },
  },
};

const callback: ICallback = {
  processConnectionSettings: (callback, connectionSettings) => {
    // do something

    // callback must be called at the end
    // passing an error into the callback will close the connection
    // passing connectionSettings will overwrite existing settings
    callback(new Error('Whoops'), connectionSettings);
  },
};

const server = new Server(webSocketConfig, guacdConfig, clientConfig, callback);

server.on('open', (clientConnection) => {
  // do something
});

server.on('close', (clientConnection) => {
  // do something
});

server.on('error', (clientConnection, error) => {
  // do something
});

Now to connect to guacamole-brite from the browser you need to add guacamole-common-js into your page. Please refer to Chapter 17 of Guacamole documentation for instructions on how to do it.

Do NOT add token/username/password or any confidential information to client side js.

Angular example:

import { AfterViewInit, Component } from '@angular/core';
import Guacamole from 'guacamole-common-js';
import * as CryptoJS from 'crypto-js';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent implements AfterViewInit {
  private config = {
    connection: {
      type: 'ssh',
      settings: {
        hostname: '127.0.0.1',
        username: 'myUser',
        password: 'myPassword',
        security: 'any',
        'ignore-cert': true,
      },
    },
  };

  private token = encodeURIComponent(
    CryptoJS.AES.encrypt(JSON.stringify(this.config), 'MySuperSecretKeyForParamsToken').toString()
  );

  constructor() {}

  ngAfterViewInit(): void {
    const tunnel = new Guacamole.WebSocketTunnel('ws://localhost:8080');
    const client = new Guacamole.Client(tunnel);
    const display = document.getElementById('display');
    const dis = client.getDisplay().getElement();
    display?.appendChild(dis);

    client.connect('token=' + this.token);
  }
}