-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: lint ./app/server/util.js #242
- Loading branch information
1 parent
ec2fcfb
commit bd0760e
Showing
1 changed file
with
29 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,43 @@ | ||
'use strict' | ||
/* jshint esversion: 6, asi: true, node: true */ | ||
// util.js | ||
|
||
// private | ||
require('colors') // allow for color property extensions in log messages | ||
var debug = require('debug')('WebSSH2') | ||
var Auth = require('basic-auth') | ||
require('colors'); // allow for color property extensions in log messages | ||
const debug = require('debug')('WebSSH2'); | ||
const Auth = require('basic-auth'); | ||
|
||
const defaultCredentials = { username: null, password: null, privatekey: null } | ||
const defaultCredentials = { username: null, password: null, privatekey: null }; | ||
|
||
exports.setDefaultCredentials = function (username, password, privatekey) { | ||
defaultCredentials.username = username | ||
defaultCredentials.password = password | ||
defaultCredentials.privatekey = privatekey | ||
} | ||
exports.setDefaultCredentials = function setDefaultCredentials(username, password, privatekey) { | ||
defaultCredentials.username = username; | ||
defaultCredentials.password = password; | ||
defaultCredentials.privatekey = privatekey; | ||
}; | ||
|
||
exports.basicAuth = function basicAuth (req, res, next) { | ||
var myAuth = Auth(req) | ||
exports.basicAuth = function basicAuth(req, res, next) { | ||
const myAuth = Auth(req); | ||
if (myAuth && myAuth.pass !== '') { | ||
req.session.username = myAuth.name | ||
req.session.userpassword = myAuth.pass | ||
debug('myAuth.name: ' + myAuth.name.yellow.bold.underline + | ||
' and password ' + ((myAuth.pass) ? 'exists'.yellow.bold.underline | ||
: 'is blank'.underline.red.bold)) | ||
req.session.username = myAuth.name; | ||
req.session.userpassword = myAuth.pass; | ||
debug(`myAuth.name: ${myAuth.name.yellow.bold.underline | ||
} and password ${(myAuth.pass) ? 'exists'.yellow.bold.underline | ||
: 'is blank'.underline.red.bold}`); | ||
} else { | ||
req.session.username = defaultCredentials.username | ||
req.session.userpassword = defaultCredentials.password | ||
req.session.privatekey = defaultCredentials.privatekey | ||
req.session.username = defaultCredentials.username; | ||
req.session.userpassword = defaultCredentials.password; | ||
req.session.privatekey = defaultCredentials.privatekey; | ||
} | ||
if ((!req.session.userpassword) && (!req.session.privatekey)) { | ||
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.') | ||
return | ||
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.'); | ||
return; | ||
} | ||
next() | ||
} | ||
next(); | ||
}; | ||
|
||
// takes a string, makes it boolean (true if the string is true, false otherwise) | ||
exports.parseBool = function parseBool (str) { | ||
return (str.toLowerCase() === 'true') | ||
} | ||
exports.parseBool = function parseBool(str) { | ||
return (str.toLowerCase() === 'true'); | ||
}; |