mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-05 06:37:10 -04:00
pulled configure and basic_auth into global scope
This commit is contained in:
parent
b0d23cb952
commit
772925f285
1 changed files with 36 additions and 30 deletions
|
@ -392,6 +392,40 @@ function logOkPostCombinator(prefix, consoleFn, field){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function configureCombinator(app, settings, basic_auth, log4js, httpLogger){
|
||||||
|
return function configBack()
|
||||||
|
{
|
||||||
|
// Activate http basic auth if it has been defined in settings.json
|
||||||
|
if(settings.httpAuth != null) app.use(basic_auth);
|
||||||
|
|
||||||
|
// If the log level specified in the config file is WARN or ERROR the application server never starts listening to requests as reported in issue #158.
|
||||||
|
// Not installing the log4js connect logger when the log level has a higher severity than INFO since it would not log at that level anyway.
|
||||||
|
if (!(settings.loglevel === "WARN" || settings.loglevel == "ERROR"))
|
||||||
|
app.use(log4js.connectLogger(httpLogger, { level: log4js.levels.INFO, format: ':status, :method :url'}));
|
||||||
|
app.use(express.cookieParser());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
//checks for basic http auth
|
||||||
|
function basic_auth (req, res, next) {
|
||||||
|
if (req.headers.authorization && req.headers.authorization.search('Basic ') === 0) {
|
||||||
|
// fetch login and password
|
||||||
|
if (new Buffer(req.headers.authorization.split(' ')[1], 'base64').toString() == settings.httpAuth) {
|
||||||
|
next();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res.header('WWW-Authenticate', 'Basic realm="Protected Area"');
|
||||||
|
if (req.headers.authorization) {
|
||||||
|
setTimeout(function () {
|
||||||
|
res.send('Authentication required', 401);
|
||||||
|
}, 1000);
|
||||||
|
} else {
|
||||||
|
res.send('Authentication required', 401);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
//initalize the database
|
//initalize the database
|
||||||
setupDb,
|
setupDb,
|
||||||
|
@ -413,17 +447,7 @@ async.waterfall([
|
||||||
|
|
||||||
//install logging
|
//install logging
|
||||||
var httpLogger = log4js.getLogger("http");
|
var httpLogger = log4js.getLogger("http");
|
||||||
app.configure(function()
|
app.configure(configureCombinator(app, settings, basic_auth, log4js, httpLogger));
|
||||||
{
|
|
||||||
// Activate http basic auth if it has been defined in settings.json
|
|
||||||
if(settings.httpAuth != null) app.use(basic_auth);
|
|
||||||
|
|
||||||
// If the log level specified in the config file is WARN or ERROR the application server never starts listening to requests as reported in issue #158.
|
|
||||||
// Not installing the log4js connect logger when the log level has a higher severity than INFO since it would not log at that level anyway.
|
|
||||||
if (!(settings.loglevel === "WARN" || settings.loglevel == "ERROR"))
|
|
||||||
app.use(log4js.connectLogger(httpLogger, { level: log4js.levels.INFO, format: ':status, :method :url'}));
|
|
||||||
app.use(express.cookieParser());
|
|
||||||
});
|
|
||||||
|
|
||||||
app.error(function(err, req, res, next){
|
app.error(function(err, req, res, next){
|
||||||
res.send(500);
|
res.send(500);
|
||||||
|
@ -449,25 +473,7 @@ async.waterfall([
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//checks for basic http auth
|
|
||||||
function basic_auth (req, res, next) {
|
|
||||||
if (req.headers.authorization && req.headers.authorization.search('Basic ') === 0) {
|
|
||||||
// fetch login and password
|
|
||||||
if (new Buffer(req.headers.authorization.split(' ')[1], 'base64').toString() == settings.httpAuth) {
|
|
||||||
next();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
res.header('WWW-Authenticate', 'Basic realm="Protected Area"');
|
|
||||||
if (req.headers.authorization) {
|
|
||||||
setTimeout(function () {
|
|
||||||
res.send('Authentication required', 401);
|
|
||||||
}, 1000);
|
|
||||||
} else {
|
|
||||||
res.send('Authentication required', 401);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//serve read only pad
|
//serve read only pad
|
||||||
app.get('/ro/:id', getRoCombinator(serverName, {ro: readOnlyManager}, hasPadAccess, ERR, exporthtml));
|
app.get('/ro/:id', getRoCombinator(serverName, {ro: readOnlyManager}, hasPadAccess, ERR, exporthtml));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue