diff --git a/src/fireedge/config.yml b/src/fireedge/fireedge-server.conf similarity index 91% rename from src/fireedge/config.yml rename to src/fireedge/fireedge-server.conf index a499f4f78a..fc34d38e8d 100644 --- a/src/fireedge/config.yml +++ b/src/fireedge/fireedge-server.conf @@ -26,3 +26,8 @@ LIMIT_TOKEN: VMRC: TARGET: 'http://opennebula.io' TOKENS_PATH: '/var/lib/one/sunstone_vnc_tokens/vmrc' + +# Guacamole +# GUACD: +# PORT: 4822 +# HOST: '127.0.0.1' diff --git a/src/fireedge/package.json b/src/fireedge/package.json index d0f0888827..8a1ccbf9b9 100644 --- a/src/fireedge/package.json +++ b/src/fireedge/package.json @@ -44,6 +44,7 @@ "express": "^4.17.1", "fs-extra": "^9.0.1", "fuse.js": "^6.4.1", + "guacamole-lite": "^0.6.3", "helmet": "^3.23.3", "http": "0.0.1-security", "http-proxy-middleware": "^1.0.5", diff --git a/src/fireedge/src/index.js b/src/fireedge/src/index.js index c8b4b52f56..02567aca6a 100644 --- a/src/fireedge/src/index.js +++ b/src/fireedge/src/index.js @@ -43,6 +43,7 @@ const { } = require('./routes/entrypoints'); const { oneHooks } = require('./routes/websockets/zeromq'); const { vmrcUpgrade } = require('./routes/websockets/vmrc'); +const { guacamole } = require('./routes/websockets/guacamole'); const { messageTerminal, getConfig } = require('./utils'); const app = express(); @@ -115,3 +116,4 @@ appServer.listen(port, () => { messageTerminal(config); }); vmrcUpgrade(appServer); +guacamole(appServer); diff --git a/src/fireedge/src/routes/websockets/guacamole/index.js b/src/fireedge/src/routes/websockets/guacamole/index.js new file mode 100644 index 0000000000..b321cd5f1f --- /dev/null +++ b/src/fireedge/src/routes/websockets/guacamole/index.js @@ -0,0 +1,47 @@ +const { console } = require('window-or-global'); +/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +const GuacamoleLite = require('guacamole-lite'); +const { getConfig } = require('../../../utils/yml'); +const { clientOptions, clientCallbacks } = require('./options'); + +const appConfig = getConfig(); +const guacd = appConfig.GUACD || {}; +const guacdPort = guacd.PORT || 4822; +const guacdHost = guacd.HOST || '127.0.0.1'; + +const endpoint = '/guacamole'; +const guacamole = appServer => { + if ( + appServer && + appServer.constructor && + appServer.constructor.name && + appServer.constructor.name === 'Server' + ) { + // eslint-disable-next-line no-new + new GuacamoleLite( + { server: appServer, path: endpoint }, // server fireedge + { host: guacdHost, port: guacdPort }, // guacD + clientOptions, + clientCallbacks + ); + } +}; + +module.exports = { + endpoint, + guacamole +}; diff --git a/src/fireedge/src/routes/websockets/guacamole/options.js b/src/fireedge/src/routes/websockets/guacamole/options.js new file mode 100644 index 0000000000..744a5647c4 --- /dev/null +++ b/src/fireedge/src/routes/websockets/guacamole/options.js @@ -0,0 +1,27 @@ +const clientOptions = { + crypt: { + cypher: 'AES-256-CBC', + key: 'LSIOGCKYLSIOGCKYLSIOGCKYLSIOGCKY' + }, + allowedUnencryptedConnectionSettings: { + rdp: ['width', 'height', 'dpi'], + vnc: ['width', 'height', 'dpi'], + ssh: ['color-scheme', 'font-name', 'font-size', 'width', 'height', 'dpi'], + telnet: ['color-scheme', 'font-name', 'font-size', 'width', 'height', 'dpi'] + }, + log: { verbose: false } +}; + +const callbacks = { + processConnectionSettings: (settings, callback) => { + if (settings.expiration && settings.expiration < Date.now()) { + return callback(new Error('Token expired')); + } + return callback(null, settings); + } +}; + +module.exports = { + clientOptions, + callbacks +}; diff --git a/src/fireedge/src/routes/websockets/vmrc/index.js b/src/fireedge/src/routes/websockets/vmrc/index.js index c336c928af..6b39861b59 100644 --- a/src/fireedge/src/routes/websockets/vmrc/index.js +++ b/src/fireedge/src/routes/websockets/vmrc/index.js @@ -16,13 +16,15 @@ const { createProxyMiddleware } = require('http-proxy-middleware'); const { readFileSync } = require('fs-extra'); const { getConfig } = require('../../../utils/yml'); const { messageTerminal } = require('../../../utils/general'); -const { console } = require('window-or-global'); const appConfig = getConfig(); const vmrcData = appConfig.VMRC || {}; const endpoint = '/vmrc'; const url = vmrcData.TARGET || ''; +const config = { + color: 'red' +}; const vmrcProxy = createProxyMiddleware(endpoint, { target: url, changeOrigin: false, @@ -30,20 +32,23 @@ const vmrcProxy = createProxyMiddleware(endpoint, { secure: /^(https):\/\/[^ "]+$/.test(url), logLevel: 'debug', pathRewrite: path => path.replace(endpoint, '/ticket'), + onError: err => { + config.type = err.message; + config.message = 'Error connection : %s'; + messageTerminal(config); + }, + // eslint-disable-next-line consistent-return router: req => { if (req && req.url) { - const ticket = req.url.split('/')[2]; + const ticket = req.url.split('/')[2] || ''; try { const esxi = readFileSync( `${vmrcData.TOKENS_PATH || ''}/${ticket}` ).toString(); return esxi; } catch (error) { - const config = { - color: 'red', - type: error.message, - message: 'Error read vmrc token: %s' - }; + config.type = error.message; + config.message = 'Error read vmrc token: %s'; messageTerminal(config); } } diff --git a/src/fireedge/src/utils/constants/defaults.js b/src/fireedge/src/utils/constants/defaults.js index f7ae577a92..e927c0fde3 100644 --- a/src/fireedge/src/utils/constants/defaults.js +++ b/src/fireedge/src/utils/constants/defaults.js @@ -41,7 +41,7 @@ const defaults = { HOST: defaultIp, PORT: 2474 }, - defaultConfigFile: `${__dirname}/../config.yml`, + defaultConfigFile: `${__dirname}/../fireedge-server.conf`, defaultTypeLog: 'prod', defaultWebpackMode: 'development', defaultWebpackDevTool: 'inline-source-map',