mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-17 03:01:08 +01:00
closes #6816
This commit is contained in:
@@ -36,6 +36,8 @@ events.types = [
|
|||||||
'password-change',
|
'password-change',
|
||||||
'email-change',
|
'email-change',
|
||||||
'username-change',
|
'username-change',
|
||||||
|
'ip-blacklist-save',
|
||||||
|
'ip-blacklist-addRule',
|
||||||
'registration-approved',
|
'registration-approved',
|
||||||
'registration-rejected',
|
'registration-rejected',
|
||||||
'accept-membership',
|
'accept-membership',
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ var async = require('async');
|
|||||||
|
|
||||||
var user = require('../user');
|
var user = require('../user');
|
||||||
var meta = require('../meta');
|
var meta = require('../meta');
|
||||||
|
var events = require('../events');
|
||||||
|
|
||||||
var SocketBlacklist = module.exports;
|
var SocketBlacklist = module.exports;
|
||||||
|
|
||||||
@@ -13,21 +14,14 @@ SocketBlacklist.validate = function (socket, data, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SocketBlacklist.save = function (socket, rules, callback) {
|
SocketBlacklist.save = function (socket, rules, callback) {
|
||||||
async.waterfall([
|
blacklist(socket, 'save', rules, callback);
|
||||||
function (next) {
|
|
||||||
user.isAdminOrGlobalMod(socket.uid, next);
|
|
||||||
},
|
|
||||||
function (isAdminOrGlobalMod, next) {
|
|
||||||
if (!isAdminOrGlobalMod) {
|
|
||||||
return callback(new Error('[[error:no-privileges]]'));
|
|
||||||
}
|
|
||||||
|
|
||||||
meta.blacklist.save(rules, next);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketBlacklist.addRule = function (socket, rule, callback) {
|
SocketBlacklist.addRule = function (socket, rule, callback) {
|
||||||
|
blacklist(socket, 'addRule', rule, callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
function blacklist(socket, method, rule, callback) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
user.isAdminOrGlobalMod(socket.uid, next);
|
user.isAdminOrGlobalMod(socket.uid, next);
|
||||||
@@ -37,7 +31,15 @@ SocketBlacklist.addRule = function (socket, rule, callback) {
|
|||||||
return callback(new Error('[[error:no-privileges]]'));
|
return callback(new Error('[[error:no-privileges]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
meta.blacklist.addRule(rule, next);
|
meta.blacklist[method](rule, next);
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
events.log({
|
||||||
|
type: 'ip-blacklist-' + method,
|
||||||
|
uid: socket.uid,
|
||||||
|
ip: socket.ip,
|
||||||
|
rule: rule,
|
||||||
|
}, next);
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
};
|
}
|
||||||
Reference in New Issue
Block a user