vadimpronin / guacamole-lite

Node.js library for creating Guacamole-compatible servers. Guacamole is a RDP/VNC/SSH/Telnet client for HTML5 browsers.
Apache License 2.0
250 stars 78 forks source link

Not able to connect to VNC | Closing connection with error: Error: not opened #46

Closed pawansingh00 closed 2 years ago

pawansingh00 commented 2 years ago

I am having above error when connecting to gucamole .I am trying to connect using vnc protcol and flowing is my setup

#!/usr/bin/env node

const GuacamoleLite = require('guacamole-lite');

const websocketOptions = {
    port: 8080 // we will accept connections to this port
};

const guacdOptions = {
    port: 4822 // port of guacd
};

const clientOptions = {
    log: {
        verbose: true
    },
    crypt: {
        cypher: 'AES-256-CBC',
        key: 'MySuperSecretKeyForParamsToken12'
    }
};

const guacServer = new GuacamoleLite(websocketOptions, guacdOptions, clientOptions);

To generate the Token I am using a script -

const crypto = require('crypto');

const clientOptions = {
    cypher: 'AES-256-CBC',
    key: 'MySuperSecretKeyForParamsToken12'
}

const encrypt = (value) => {
    const iv = crypto.randomBytes(16);
    const cipher = crypto.createCipheriv(clientOptions.cypher, clientOptions.key, iv);

    let crypted = cipher.update(JSON.stringify(value), 'utf8', 'base64');
    crypted += cipher.final('base64');

    const data = {
        iv: iv.toString('base64'),
        value: crypted
    };

    return new Buffer(JSON.stringify(data)).toString('base64');
};

console.log("Token : " + encrypt({
    "connection": {
        "type": "vnc",
        "settings": {
            "hostname": "192.168.43.158",
            "port": "5900",
            "username": "pawan",
            "password": "pawan"           
        }
    }
}));

And my client side app looks like this --


<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Page Title</title>
        <meta name="viewport" content="width=device-width,initial-scale=1">
        <link rel="stylesheet" href="">
        <style></style>

        <!-- Guacamole -->
        <script type="text/javascript"
            src="https://unpkg.com/browse/guacamole-common-js@1.3.0/dist/guacamole-common.js"></script>

        <script type="text/javascript"
        src="/index.js"></script>

    </head>

    <body>

        <!-- 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.WebSocketTunnel("ws://192.168.43.158:8080?token=eyJpdiI6IjRXamp4VXl1ZTZMZ1BpUHVydjhzM1E9PSIsInZhbHVlIjoiV2QyQVVTbnF1Zk01eW1ERWlQYnNZUnFNK3FrNERFS05XNjkyZC9yM0c1MndxZXZBb3NGNVNqdUVFSUZkR0xOYXVoS2dJVkV6UHlUaXlvZWdoSG90dy9NQ0tFVWtJYWxEanEzRmlCQVFUaHZWRUpVTXhlVjZDRktwV3Q2WVVIeXIrME1kL3lXN2RFN2FwTHMweENjM2pIMU5xTWh1c3crRFNzNTh4Z0xNalJVPSJ9")
            );

            // Add client to display div
            display.appendChild(guac.getDisplay().getElement());

            // Error handler
            guac.onerror = function(error) {
                console.log("Error :: ", error);
                alert(error);
            };

            // Connect
            guac.connect('');

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

        /* ]]> */ </script>

    </body>

</html>

I have attached the logs from Server side --

` [2022-03-08 17:20:23] [Connection 1] Client connection open [2022-03-08 17:20:23] [Connection 1] Opening guacd connection [2022-03-08 17:20:23] [Connection 1] guacd connection open [2022-03-08 17:20:23] [Connection 1] Selecting connection type: vnc [2022-03-08 17:20:23] [Connection 1] Sending opCode: 6.select,3.vnc; [2022-03-08 17:20:23] [Connection 1] <<<W2G< 6.select,3.vnc; [2022-03-08 17:20:23] [Connection 1] Sending opCode: 4.size,4.1024,3.768,2.96; [2022-03-08 17:20:23] [Connection 1] <<<W2G< 4.size,4.1024,3.768,2.96; [2022-03-08 17:20:23] [Connection 1] Sending opCode: 5.audio; [2022-03-08 17:20:23] [Connection 1] <<<W2G< 5.audio; [2022-03-08 17:20:23] [Connection 1] Sending opCode: 5.video; [2022-03-08 17:20:23] [Connection 1] <<<W2G< 5.video; [2022-03-08 17:20:23] [Connection 1] Sending opCode: 5.image; [2022-03-08 17:20:23] [Connection 1] <<<W2G< 5.image; [2022-03-08 17:20:23] [Connection 1] Server sent handshake: 4.args,13.VERSION_1_3_0,8.hostname,4.port,9.read-only,9.encodings,8.username,8.password,13.swap-red-blue,11.color-depth,6.cursor,9.autoretry,18.clipboard-encoding,9.dest-host,9.dest-port,12.enable-audio,16.audio-servername,15.reverse-connect,14.listen-timeout,11.enable-sftp,13.sftp-hostname,13.sftp-host-key,9.sftp-port,13.sftp-username,13.sftp-password,16.sftp-private-key,15.sftp-passphrase,14.sftp-directory,19.sftp-root-directory,26.sftp-server-alive-interval,21.sftp-disable-download,19.sftp-disable-upload,14.recording-path,14.recording-name,24.recording-exclude-output,23.recording-exclude-mouse,22.recording-include-keys,21.create-recording-path,12.disable-copy,13.disable-paste,15.wol-send-packet,12.wol-mac-addr,18.wol-broadcast-addr,12.wol-udp-port,13.wol-wait-time,14.force-lossless [2022-03-08 17:20:23] [Connection 1] Sending opCode: 7.connect,0.,14.192.168.43.158,4.5900,0.,0.,6.pawan,6.pawan,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.; [2022-03-08 17:20:23] [Connection 1] <<<W2G< 7.connect,0.,14.192.168.43.158,4.5900,0.,0.,6.pawan,6.pawan,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.; [2022-03-08 17:20:23] [Connection 1] >>>G2W> 5.ready,37.$44c5724e-15d2-43ab-81b3-038379222a50;5.error,18.Aborted. See logs.,3.519;### [2022-03-08 17:20:24] [Connection 1] <<<W2G< 10.disconnect;*** [2022-03-08 17:20:24] [Connection 1] >>>G2W> 10.disconnect;### [2022-03-08 17:20:24] [Connection 1] Closing connection with error: Error: not opened at WebSocket.send (/home/pawansingh/projects/guacamole/node_modules/ws/lib/WebSocket.js:218:38) at ClientConnection.send (/home/pawansingh/projects/guacamole/node_modules/guacamole-lite/lib/ClientConnection.js:130:24) at GuacdClient.sendBufferToWebSocket (/home/pawansingh/projects/guacamole/node_modules/guacamole-lite/lib/GuacdClient.js:172:35) at GuacdClient.processReceivedData (/home/pawansingh/projects/guacamole/node_modules/guacamole-lite/lib/GuacdClient.js:163:14) at Socket.emit (node:events:390:28) at addChunk (node:internal/streams/readable:315:12) at readableAddChunk (node:internal/streams/readable:289:9) at Socket.Readable.push (node:internal/streams/readable:228:10) at TCP.onStreamRead (node:internal/stream_base_commons:199:23) [2022-03-08 17:20:24] [Connection 1] Closing guacd connection [2022-03-08 17:20:24] [Connection 1] Client connection closed

`

Can somebody please help me to understand what I am doing wrong here? Is My novnc connection param Wrong? { "connection": { "type": "vnc", "settings": { "hostname": "192.168.43.158", "port": "5900", "username": "pawan", "password": "pawan" } } }

CC: @vadimpronin / @luiso1979 Don't mean to spam you guys, just a bit desperate for a solution. Any help is much appreciated!

Thanks

pawansingh00 commented 2 years ago

Got it Working. 🎉🎉🎉🎉 Turns out that My x11vnc server was not running properly.

rashmiranjanrrs commented 2 years ago

hye @pawansingh00 I am getting the same error, I am using rdp