Skip to content

Commit

Permalink
reauth feature
Browse files Browse the repository at this point in the history
fixes billchurch#75 and potentially billchurch#51 thanks to both @vbeskrovny and @vvalchev
  • Loading branch information
billchurch committed Jul 30, 2018
1 parent 45cbceb commit 820ce57
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion client/public/webssh2.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/public/webssh2.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions client/src/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,10 @@ html, body {
#menu:hover .dropup-content {
display: block;
}
#logBtn {
color: #000;
}
#credentialsBtn {
#logBtn, #credentialsBtn, #reauthBtn {
color: #000;
}

.dropup {
position: relative;
display: inline-block;
Expand Down
22 changes: 21 additions & 1 deletion client/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ require('../css/style.css')

Terminal.applyAddon(fit)

/* global Blob, logBtn, credentialsBtn, downloadLogBtn */
/* global Blob, logBtn, credentialsBtn, reauthBtn, downloadLogBtn */
var sessionLogEnable = false
var loggedData = false
var allowreplay = false
var allowreauth = false
var sessionLog, sessionFooter, logDate, currentDate, myFile, errorExists
var socket, termid // eslint-disable-line
var term = new Terminal()
Expand Down Expand Up @@ -128,6 +129,17 @@ socket.on('allowreplay', function (data) {
}
})

socket.on('allowreauth', function (data) {
if (data === true) {
console.log('allowreauth: ' + data)
allowreauth = true
drawMenu(dropupContent.innerHTML + '<a id="reauthBtn"><i class="fas fa-key fa-fw"></i> Switch User</a>')
} else {
allowreauth = false
console.log('allowreauth: ' + data)
}
})

socket.on('disconnect', function (err) {
if (!errorExists) {
status.style.backgroundColor = 'red'
Expand All @@ -153,10 +165,18 @@ term.on('title', function (title) {
function drawMenu (data) {
dropupContent.innerHTML = data
logBtn.addEventListener('click', toggleLog)
allowreauth && reauthBtn.addEventListener('click', reauthSession)
allowreplay && credentialsBtn.addEventListener('click', replayCredentials)
loggedData && downloadLogBtn.addEventListener('click', downloadLog)
}

// reauthenticate
function reauthSession () { // eslint-disable-line
console.log('re-authenticating')
window.location.href = '/reauth'
return false
}

// replay password to server, requires
function replayCredentials () { // eslint-disable-line
socket.emit('control', 'replayCredentials')
Expand Down
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"secret": "mysecret"
},
"options": {
"challengeButton": true
"challengeButton": true,
"allowreauth": true
},
"algorithms": {
"kex": [
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"builddev": "webpack --progress --colors --config scripts/webpack.dev.js",
"test": "snyk test",
"watch": "nodemon index.js",
"standard": "standard --verbose | snazzy",
"standard": "standard --verbose --fix | snazzy",
"cleanmac": "find . -name '.DS_Store' -type f -delete"
},
"devDependencies": {
Expand Down Expand Up @@ -78,7 +78,8 @@
"bigip/*",
"screenshots/*",
"bin/*",
"build/*"
"build/*",
"workspace/*"
]
}
}
15 changes: 4 additions & 11 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,8 @@ app.disable('x-powered-by')
app.use(express.static(publicPath, expressOptions))

app.get('/reauth', function (req, res, next) {
var r = req.headers.referer || '/';
res.status(401).send(
'<html>' +
' <head>' +
' <meta http-equiv="refresh" content="1; url=' + r + '" />' +
' </head>' +
' <body>' +
' <a href="' + r + '">Go Back</a>' +
' </body>' +
'</html>');
var r = req.headers.referer || '/'
res.status(401).send('<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=' + r + '"></head><body bgcolor="#000"></body></html>');
})

app.get('/ssh/host/:host?', function (req, res, next) {
Expand Down Expand Up @@ -73,7 +65,8 @@ app.get('/ssh/host/:host?', function (req, res, next) {
tabStopWidth: (validator.isInt(req.query.tabStopWidth + '', {min: 1, max: 100}) && req.query.tabStopWidth) ? req.query.tabStopWidth : config.terminal.tabStopWidth,
bellStyle: ((req.query.bellStyle) && (['sound', 'none'].indexOf(req.query.bellStyle) > -1)) ? req.query.bellStyle : config.terminal.bellStyle
},
allowreplay: (validator.isBoolean(req.headers.allowreplay + '') ? myutil.parseBool(req.headers.allowreplay) : false),
allowreplay: config.options.challengeButton || (validator.isBoolean(req.headers.allowreplay + '') ? myutil.parseBool(req.headers.allowreplay) : false),
allowreauth: config.options.allowreauth || false,
mrhsession: ((validator.isAlphanumeric(req.headers.mrhsession + '') && req.headers.mrhsession) ? req.headers.mrhsession : 'none'),
serverlog: {
client: config.serverlog.client || false,
Expand Down
4 changes: 2 additions & 2 deletions server/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ var SSH = require('ssh2').Client
// var hostkeys = JSON.parse(fs.readFileSync('./hostkeyhashes.json', 'utf8'))
var termCols, termRows
var menuData = '<a id="logBtn"><i class="fas fa-clipboard fa-fw"></i> Start Log</a>' +
'<a id="downloadLogBtn"><i class="fas fa-download fa-fw"></i> Download Log</a>' +
'<a style="color:black" href="/reauth"><i class="fas fa-key fa-fw"></i> Switch User</a>';
'<a id="downloadLogBtn"><i class="fas fa-download fa-fw"></i> Download Log</a>'

// public
module.exports = function socket (socket) {
Expand Down Expand Up @@ -42,6 +41,7 @@ module.exports = function socket (socket) {
socket.emit('status', 'SSH CONNECTION ESTABLISHED')
socket.emit('statusBackground', 'green')
socket.emit('allowreplay', socket.request.session.ssh.allowreplay)
socket.emit('allowreauth', socket.request.session.ssh.allowreauth)
conn.shell({
term: socket.request.session.ssh.term,
cols: termCols,
Expand Down

0 comments on commit 820ce57

Please sign in to comment.