feat: Update connectionHandler.js and routes.js to propmpt for basic credentials when accessing /ssh/host/<address>
and pre-populate credentials and host info AND auto-connect to server.
This commit is contained in:
parent
e39fb885fd
commit
fe7248e056
4 changed files with 40 additions and 15 deletions
|
@ -23,8 +23,11 @@ function handleConnection(req, res, urlParams) {
|
||||||
},
|
},
|
||||||
ssh: {
|
ssh: {
|
||||||
host: connectionParams.host || '',
|
host: connectionParams.host || '',
|
||||||
port: connectionParams.port || 22
|
port: connectionParams.port || 22,
|
||||||
}
|
username: connectionParams.username || '',
|
||||||
|
password: connectionParams.password || ''
|
||||||
|
},
|
||||||
|
autoConnect: !!(connectionParams.host && connectionParams.username && connectionParams.password)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Read the client.htm file
|
// Read the client.htm file
|
||||||
|
|
|
@ -1,18 +1,32 @@
|
||||||
// server
|
// server
|
||||||
// /app/routes.js
|
// /app/routes.js
|
||||||
const express = require('express');
|
var express = require('express');
|
||||||
const path = require('path');
|
var router = express.Router();
|
||||||
const router = express.Router();
|
var handleConnection = require('./connectionHandler');
|
||||||
const handleConnection = require('./connectionHandler');
|
var basicAuth = require('basic-auth');
|
||||||
|
|
||||||
// Route for host in URL
|
function auth(req, res, next) {
|
||||||
router.get('/host/:host', (req, res) => {
|
var credentials = basicAuth(req);
|
||||||
handleConnection(req, res, { host: req.params.host });
|
if (!credentials) {
|
||||||
});
|
res.setHeader('WWW-Authenticate', 'Basic realm="WebSSH2"');
|
||||||
|
return res.status(401).send('Authentication required.');
|
||||||
|
}
|
||||||
|
req.sshCredentials = credentials;
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
|
||||||
// Default route
|
// Scenario 1: No auth required
|
||||||
router.get('/', (req, res) => {
|
router.get('/', function(req, res) {
|
||||||
handleConnection(req, res);
|
handleConnection(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Scenario 2: Auth required
|
||||||
|
router.get('/host/:host', auth, function(req, res) {
|
||||||
|
handleConnection(req, res, {
|
||||||
|
host: req.params.host,
|
||||||
|
username: req.sshCredentials.name,
|
||||||
|
password: req.sshCredentials.pass
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
13
package-lock.json
generated
13
package-lock.json
generated
|
@ -330,6 +330,14 @@
|
||||||
"resolved": "https://registry.npmjs.org/base64id/-/base64id-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/base64id/-/base64id-1.0.0.tgz",
|
||||||
"integrity": "sha512-rz8L+d/xByiB/vLVftPkyY215fqNrmasrcJsYkVcm4TgJNz+YXKrFaFAWibSaHkiKoSgMDCb+lipOIRQNGYesw=="
|
"integrity": "sha512-rz8L+d/xByiB/vLVftPkyY215fqNrmasrcJsYkVcm4TgJNz+YXKrFaFAWibSaHkiKoSgMDCb+lipOIRQNGYesw=="
|
||||||
},
|
},
|
||||||
|
"basic-auth": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==",
|
||||||
|
"requires": {
|
||||||
|
"safe-buffer": "5.1.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"bcrypt-pbkdf": {
|
"bcrypt-pbkdf": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
|
||||||
|
@ -3675,8 +3683,7 @@
|
||||||
"safe-buffer": {
|
"safe-buffer": {
|
||||||
"version": "5.1.2",
|
"version": "5.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
|
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"safe-regex": {
|
"safe-regex": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
|
@ -4722,7 +4729,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#86a1131e7ce3a31803c9e6c1c416f88d68e53a01",
|
"version": "git+ssh://git@github.com/billchurch/webssh2_client.git#ef2d4753306ec3c43247fc76484b5a5b9d928e50",
|
||||||
"from": "git+ssh://git@github.com/billchurch/webssh2_client.git"
|
"from": "git+ssh://git@github.com/billchurch/webssh2_client.git"
|
||||||
},
|
},
|
||||||
"which": {
|
"which": {
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ajv": "^4.11.8",
|
"ajv": "^4.11.8",
|
||||||
|
"basic-auth": "^2.0.1",
|
||||||
"body-parser": "^1.15.2",
|
"body-parser": "^1.15.2",
|
||||||
"debug": "~4.1.0",
|
"debug": "~4.1.0",
|
||||||
"express": "^4.14.1",
|
"express": "^4.14.1",
|
||||||
|
|
Loading…
Reference in a new issue