Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"Timestamp": "2019-08-09T07:59:05+02:00"
}
}));
} else {
console.log("404 Not Found");
response.writeHead(404, {
"Content-Type": "text/plain"
});
response.write("404 Not Found\n");
response.end();
return;
}
}
if (useDigestAuth) {
var digest = auth.digest({
realm: realm
}, function (username, callback) { // Expecting md5(username:realm:password) in callback.
if (username === "admin") {
var hash = crypto.createHash('md5');
hash.update("admin:" + realm + ":admin");
callback(hash.digest('hex'));
} else {
callback();
}
});
http.createServer(digest, requestListener).listen(parseInt(port, 10));
} else {
http.createServer(requestListener).listen(parseInt(port, 10));
}
console.log("Server running at\n => http://localhost:" + parseInt(port, 10) + "/\nCTRL + C to shutdown");
ReplHttpServer.prototype.start = function(port) {
var self = this;
if (this.username !== undefined && this.password !== undefined) {
// Set up server that requires http digest authentication
var configuredUsername = this.username;
var configuredPassword = this.password;
var auth = require('http-auth');
var crypto = require('crypto');
var digest = auth.digest({ realm: "webrepl" },
function (username, callback) { // Expecting md5(username:realm:password) in callback.
if (username === configuredUsername) {
var md5hash = crypto.createHash('md5');
callback(md5hash.update(configuredUsername + ":webrepl:" + configuredPassword).digest("hex"));
} else {
callback();
}
}
);
self.server = http.createServer(digest, function(req, res) {
self.route(req, res);
});
self.server.listen(port, this.hostname);
} else {
// No auth required
const url = `http://${host}:${port}/`
const username = 'user'
const password = 'pass'
const realmBasic = 'basic'
const realmDigest = 'digest'
const basic = auth.basic(
{
realm: realmBasic,
},
(usr, pass, callback) => {
callback(usr === username && pass === password)
},
)
const digest = auth.digest(
{
realm: realmDigest,
},
(usr, callback) => {
const hash = crypto.createHash('md5')
if (usr === username) {
hash.update([username, realmDigest, password].join(':'))
const hashDigest = hash.digest('hex')
callback(hashDigest)
} else {
callback()
}
},
)