feat: Inject SSH host and port into webssh2 configuration

This commit is contained in:
Bill Church 2024-07-18 15:35:41 +00:00
parent 8fcf4b7b75
commit e39fb885fd
No known key found for this signature in database
2 changed files with 9 additions and 2 deletions

View file

@ -16,10 +16,14 @@ function handleConnection(req, res, urlParams) {
extend(connectionParams, req.body || {}); extend(connectionParams, req.body || {});
// Inject configuration // Inject configuration
res.locals.webssh2Config = { var config = {
socket: { socket: {
url: req.protocol + '://' + req.get('host'), url: req.protocol + '://' + req.get('host'),
path: '/ssh/socket.io' path: '/ssh/socket.io'
},
ssh: {
host: connectionParams.host || '',
port: connectionParams.port || 22
} }
}; };
@ -32,6 +36,9 @@ function handleConnection(req, res, urlParams) {
// Replace relative paths with the correct path // Replace relative paths with the correct path
var modifiedHtml = data.replace(/(src|href)="(?!http|\/\/)/g, '$1="/ssh/assets/'); var modifiedHtml = data.replace(/(src|href)="(?!http|\/\/)/g, '$1="/ssh/assets/');
// Inject the configuration into the HTML
modifiedHtml = modifiedHtml.replace('window.webssh2Config = null;', 'window.webssh2Config = ' + JSON.stringify(config) + ';');
// Send the modified HTML // Send the modified HTML
res.send(modifiedHtml); res.send(modifiedHtml);
}); });

2
package-lock.json generated
View file

@ -4722,7 +4722,7 @@
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==" "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg=="
}, },
"webssh2_client": { "webssh2_client": {
"version": "git+ssh://git@github.com/billchurch/webssh2_client.git#6a1d9d7732c4a7404e8f276f531e66a6e4d17c56", "version": "git+ssh://git@github.com/billchurch/webssh2_client.git#86a1131e7ce3a31803c9e6c1c416f88d68e53a01",
"from": "git+ssh://git@github.com/billchurch/webssh2_client.git" "from": "git+ssh://git@github.com/billchurch/webssh2_client.git"
}, },
"which": { "which": {