Files
NodeBB/src/socket.io/blacklist.js

41 lines
968 B
JavaScript
Raw Normal View History

2016-03-15 12:13:35 +02:00
'use strict';
2019-09-13 18:24:21 -04:00
const user = require('../user');
const meta = require('../meta');
const events = require('../events');
2017-05-26 00:02:20 -04:00
2019-09-13 18:24:21 -04:00
const SocketBlacklist = module.exports;
2016-03-15 12:13:35 +02:00
2019-09-13 18:24:21 -04:00
SocketBlacklist.validate = async function (socket, data) {
return meta.blacklist.validate(data.rules);
2016-03-15 12:13:35 +02:00
};
2019-09-13 18:24:21 -04:00
SocketBlacklist.save = async function (socket, rules) {
await blacklist(socket, 'save', rules);
2016-03-15 12:13:35 +02:00
};
2018-02-15 14:52:49 -05:00
2019-09-13 18:24:21 -04:00
SocketBlacklist.addRule = async function (socket, rule) {
await blacklist(socket, 'addRule', rule);
2018-10-04 15:09:18 -04:00
};
2019-09-13 18:24:21 -04:00
async function blacklist(socket, method, rule) {
const isAdminOrGlobalMod = await user.isAdminOrGlobalMod(socket.uid);
if (!isAdminOrGlobalMod) {
throw new Error('[[error:no-privileges]]');
}
if (socket.ip && rule.includes(socket.ip)) {
throw new Error('[[error:cant-blacklist-self-ip]]');
}
2019-09-13 18:24:21 -04:00
await meta.blacklist[method](rule);
await events.log({
2021-02-03 23:59:08 -07:00
type: `ip-blacklist-${method}`,
2019-09-13 18:24:21 -04:00
uid: socket.uid,
ip: socket.ip,
rule: rule,
});
2018-10-04 15:26:34 -04:00
}
2019-09-13 18:24:21 -04:00
require('../promisify')(SocketBlacklist);