Skip to content

Commit

Permalink
auth.js: added updateUsers and call to process.on('SIGHUP', function(…
Browse files Browse the repository at this point in the history
…){})

Allows it to reread the htpasswd file whenever a SIGHUP is sent
  • Loading branch information
Phoebe Simon committed May 30, 2012
1 parent 718d61a commit b1eefc3
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions lib/web/auth.js
Expand Up @@ -60,6 +60,9 @@ AuthDB.prototype._validateMD5 = function(password, hash) {
};


AuthDB.prototype.updateUsers = function(users) {
this.users = users;
}

function sha1crypt(password) {
return '{SHA}' + crypto.createHash('sha1').update(password).digest('base64');
Expand Down Expand Up @@ -136,20 +139,31 @@ function md5crypt(password, salt, magic) {


exports.loadDBFromFile = function(filePath) {
var contents = fs.readFileSync(filePath, 'utf8'),

var getUsers = function(filePath) {
var contents = fs.readFileSync(filePath, 'utf8'),
users = {},
lines, both, i;

lines = contents.split('\n').map(function(line) {
return line.trim();
});
lines = contents.split('\n').map(function(line) {
return line.trim();
});

for (i = 0; i < lines.length; i++) {
if (lines[i] && lines[i].indexOf('#') !== 0) {
both = lines[i].split(':');
users[both[0]] = both[1];
for (i = 0; i < lines.length; i++) {
if (lines[i] && lines[i].indexOf('#') !== 0) {
both = lines[i].split(':');
users[both[0]] = both[1];
}
}
}
return users;
};

users = getUsers(filePath);
myAuthDB = new AuthDB(users);
process.on('SIGHUP', function(){
users = getUsers(filePath);
myAuthDB.updateUsers(users);
});

return new AuthDB(users);
return myAuthDB;
};

0 comments on commit b1eefc3

Please sign in to comment.