You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
863 B
JavaScript
37 lines
863 B
JavaScript
|
|
'use strict';
|
|
|
|
const user = require('../user');
|
|
const meta = require('../meta');
|
|
const events = require('../events');
|
|
|
|
const SocketBlacklist = module.exports;
|
|
|
|
SocketBlacklist.validate = async function (socket, data) {
|
|
return meta.blacklist.validate(data.rules);
|
|
};
|
|
|
|
SocketBlacklist.save = async function (socket, rules) {
|
|
await blacklist(socket, 'save', rules);
|
|
};
|
|
|
|
SocketBlacklist.addRule = async function (socket, rule) {
|
|
await blacklist(socket, 'addRule', rule);
|
|
};
|
|
|
|
async function blacklist(socket, method, rule) {
|
|
const isAdminOrGlobalMod = await user.isAdminOrGlobalMod(socket.uid);
|
|
if (!isAdminOrGlobalMod) {
|
|
throw new Error('[[error:no-privileges]]');
|
|
}
|
|
await meta.blacklist[method](rule);
|
|
await events.log({
|
|
type: `ip-blacklist-${method}`,
|
|
uid: socket.uid,
|
|
ip: socket.ip,
|
|
rule: rule,
|
|
});
|
|
}
|
|
|
|
require('../promisify')(SocketBlacklist);
|