diff --git a/index.js b/index.js index 1e7a190..91f055d 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,8 @@ var session = require('express-session')({ resave: true, saveUninitialized: false }) -var termCols, termRows, myError +var colors = require('colors/safe') +var termCols, termRows // var LogPrefix // var dataBuffer = '' @@ -72,7 +73,7 @@ app.get('/ssh/host/:host?', function (req, res, next) { config.header.background = req.query.headerBackground || config.header.background console.log('webssh2 Login: user=' + req.session.username + ' from=' + req.ip + ' host=' + config.ssh.host + ' port=' + config.ssh.port + ' sessionID=' + req.sessionID + ' allowreplay=' + req.headers.allowreplay) // LogPrefix = req.session.username + '@' + req.ip + ' ssh://' + config.ssh.host + ':' + config.ssh.port + '/' + req.sessionID - // console.log('Headers: ' + JSON.stringify(req.headers)) + debugWebSSH2('Headers: ' + colors.yellow(JSON.stringify(req.headers))) config.options.allowreplay = req.headers.allowreplay }) @@ -158,13 +159,13 @@ io.on('connection', function (socket) { console.log('controlData: ' + controlData) } }) - + socket.on('disconnecting', function (reason) { debugWebSSH2('SOCKET DISCONNECTING: ' + reason) }) socket.on('disconnect', function (reason) { debugWebSSH2('SOCKET DISCONNECT: ' + reason) err = { message: reason } - socketutil.SSHerror ('CLIENT SOCKET DISCONNECT', err) + socketutil.SSHerror('CLIENT SOCKET DISCONNECT', err) conn.end() }) @@ -173,7 +174,7 @@ io.on('connection', function (socket) { stream.on('data', function (d) { socket.emit('data', d.toString('binary')) }) stream.on('close', function (code, signal) { - err = { message: ((code||signal) ? (((code)? 'CODE: ' + code: '') + ((code&&signal)? ' ':'') + ((signal)? 'SIGNAL: ' + signal : '')) : undefined) } + err = { message: ((code || signal) ? (((code) ? 'CODE: ' + code : '') + ((code && signal) ? ' ' : '') + ((signal) ? 'SIGNAL: ' + signal : '')) : undefined) } socketutil.SSHerror('STREAM CLOSE', err) conn.end() }) @@ -186,7 +187,7 @@ io.on('connection', function (socket) { conn.on('end', function (err) { socketutil.SSHerror('CONN END BY HOST', err) }) conn.on('close', function (err) { socketutil.SSHerror('CONN CLOSE', err) }) - conn.on('error', function (err) { socketutil.SSHerror('CONN ERROR', err ) }) + conn.on('error', function (err) { socketutil.SSHerror('CONN ERROR', err) }) conn.on('keyboard-interactive', function (name, instructions, instructionsLang, prompts, finish) { debugWebSSH2('Connection :: keyboard-interactive') diff --git a/socket/index.js b/socket/index.js index 8769cbc..52d0366 100644 --- a/socket/index.js +++ b/socket/index.js @@ -1,11 +1,12 @@ -var myError = myError +var debug = require('debug')('WebSSH2') +var myError module.exports = function (socket, io) { this.SSHerror = function (myFunc, err) { - myError = (myError) ? myError : ((err) ? err.message:undefined) + myError = (myError) || ((err) ? err.message : undefined) thisError = (myError) ? ': ' + myError : '' - console.error('SSH ' + myFunc + thisError) - socket.emit('ssherror', 'SSH ' + myFunc + thisError) - socket.disconnect(true) + debug('SSH ' + myFunc + thisError) + socket.emit('ssherror', 'SSH ' + myFunc + thisError) + socket.disconnect(true) } } diff --git a/util/index.js b/util/index.js index 5c3d4a7..c7bb162 100644 --- a/util/index.js +++ b/util/index.js @@ -1,3 +1,4 @@ +var debug = require('debug')('WebSSH2') var colors = require('colors') var Auth = require('basic-auth') @@ -18,9 +19,11 @@ exports.basicAuth = function (req, res, next) { if (myAuth) { req.session.username = myAuth.name req.session.userpassword = myAuth.pass + debug('myAuth.name: ' + myAuth.name + ' and password ' + ((myAuth.pass) ? 'exists' : 'is blank'.underline.red)) next() } else { res.statusCode = 401 + debug('basicAuth credential request (401)') res.setHeader('WWW-Authenticate', 'Basic realm="WebSSH"') res.end('Username and password required for web SSH service.') }