diff --git a/app/app.js b/app/app.js index 6d13b67..46637e2 100644 --- a/app/app.js +++ b/app/app.js @@ -16,22 +16,22 @@ const sshRoutes = require('./routes') * @returns {express.Application} The Express application instance */ function createApp() { - const app = express() + var app = express(); // Resolve the correct path to the webssh2_client module - const clientPath = path.resolve(__dirname, '..', 'node_modules', 'webssh2_client', 'client', 'public') + var clientPath = path.resolve(__dirname, '..', 'node_modules', 'webssh2_client', 'client', 'public'); // Handle POST and GET parameters - app.use(bodyParser.urlencoded({ extended: true })) - app.use(bodyParser.json()) + app.use(bodyParser.urlencoded({ extended: true })); + app.use(bodyParser.json()); - // Serve static files from the webssh2_client module - app.use('/ssh', express.static(clientPath)) + // Serve static files from the webssh2_client module with a custom prefix + app.use('/ssh/assets', express.static(clientPath)); // Use the SSH routes - app.use('/ssh', sshRoutes) + app.use('/ssh', sshRoutes); - return app + return app; } /** diff --git a/app/connectionHandler.js b/app/connectionHandler.js index 23c4eb5..fd41f8f 100644 --- a/app/connectionHandler.js +++ b/app/connectionHandler.js @@ -1,6 +1,7 @@ // server // app/connectionHandler.js var path = require('path'); +var fs = require('fs'); var extend = require('util')._extend; function handleConnection(req, res, urlParams) { @@ -22,10 +23,18 @@ function handleConnection(req, res, urlParams) { } }; - // You can process connectionParams here or pass them to the client - - // Serve the client HTML - res.sendFile(path.join(clientPath, 'client.htm')); + // Read the client.htm file + fs.readFile(path.join(clientPath, 'client.htm'), 'utf8', function(err, data) { + if (err) { + return res.status(500).send('Error loading client file'); + } + + // Replace relative paths with the correct path + var modifiedHtml = data.replace(/(src|href)="(?!http|\/\/)/g, '$1="/ssh/assets/'); + + // Send the modified HTML + res.send(modifiedHtml); + }); } module.exports = handleConnection; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 2466f8c..82902ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1842,6 +1842,11 @@ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.3.0.tgz", "integrity": "sha512-akx5WBKAwMSg36qoHTuMMVncHWctlaDGslJASDYAhoLrzDUDCjZlOngNa/iC6lPm9aA0qk8pN5KnpmbJHSIIQQ==" }, + "fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", diff --git a/package.json b/package.json index 95a6294..7e9ef06 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "body-parser": "^1.15.2", "debug": "~4.1.0", "express": "^4.14.1", + "fs": "0.0.1-security", "read-config-ng": "~3.0.7", "socket.io": "~2.2.0", "ssh2": "~0.8.9",