var path=require("path"), basicAuth=require("basic-auth"); var cwd=process.cwd(); var globalAccounts=require(cwd+"/globalAccounts.json"); var statusbotObject={ // calls cb with http status code "send":function statusbotSend(sender,text,cb){ if(statusbotObject._handler==null){ console.log("[common.statusbot] No statusbot yet"); cb(500); return; } statusbotObject._handler(sender,text,cb); }, "_handler":null, // to be set from the statusbot module }; module.exports={ "serverdir":cwd, "webfilesdir":cwd+"/web_files", "persistdir":cwd+"/persist", "simpleHTMLescape":function simpleHTMLescape(str){ return str.replace(/&/g,'&').replace(//g,'>'); }, "authgen":function authgen(accounts){ //omit `accounts` to use the globalAccounts list if(!accounts)accounts=globalAccounts; return function (req,res,next){ function unauth(res){ res.set("WWW-Authenticate","Basic realm=Authorization required"); return res.sendStatus(401); }; var user=basicAuth(req); if(!user||!user.name||!user.pass){ return unauth(res); } var i; for(i=0;i