mirror of
https://github.com/hack-chat/main.git
synced 2024-03-22 13:20:33 +08:00
Added unban by hash
This commit is contained in:
parent
39ec02d3c4
commit
aa33c86af0
|
@ -38,7 +38,8 @@ exports.run = async (core, server, socket, data) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO unban by hash
|
// TODO unban by hash
|
||||||
server._police.arrest(badClient.remoteAddress);
|
let clientHash = server.getSocketHash(badClient);
|
||||||
|
server._police.arrest(badClient.remoteAddress, clientHash);
|
||||||
|
|
||||||
console.log(`${socket.nick} [${socket.trip}] banned ${targetNick} in ${socket.channel}`);
|
console.log(`${socket.nick} [${socket.trip}] banned ${targetNick} in ${socket.channel}`);
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ exports.run = async (core, server, socket, data) => {
|
||||||
|
|
||||||
server.broadcast({
|
server.broadcast({
|
||||||
cmd: 'info',
|
cmd: 'info',
|
||||||
text: `${socket.nick} banned ${targetNick} in ${socket.channel}, userhash: ${server.getSocketHash(badClient)}`
|
text: `${socket.nick} banned ${targetNick} in ${socket.channel}, userhash: ${clientHash}`
|
||||||
}, { uType: 'mod' });
|
}, { uType: 'mod' });
|
||||||
|
|
||||||
badClient.close();
|
badClient.close();
|
||||||
|
|
|
@ -10,44 +10,48 @@ exports.run = async (core, server, socket, data) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof data.ip !== 'string') {
|
if (typeof data.ip !== 'string' && typeof data.hash !== 'string') {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let ip = data.ip;
|
|
||||||
let hash = data.hash; // TODO unban by hash
|
|
||||||
|
|
||||||
// TODO unban by hash
|
|
||||||
let recordFound = server._police.pardon(data.ip);
|
|
||||||
|
|
||||||
if (!recordFound) {
|
|
||||||
server.reply({
|
server.reply({
|
||||||
cmd: 'warn',
|
cmd: 'warn',
|
||||||
text: 'Could not find target in records'
|
text: "hash:'targethash' or ip:'1.2.3.4' is required"
|
||||||
}, socket);
|
}, socket);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`${socket.nick} [${socket.trip}] unbanned ${/*hash || */ip} in ${socket.channel}`);
|
let mode, target;
|
||||||
|
|
||||||
|
if (typeof data.ip === 'string') {
|
||||||
|
mode = 'ip';
|
||||||
|
target = data.ip;
|
||||||
|
} else {
|
||||||
|
mode = 'hash';
|
||||||
|
target = data.hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
server._police.pardon(target);
|
||||||
|
|
||||||
|
if (mode === 'ip') {
|
||||||
|
target = server.getSocketHash(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`${socket.nick} [${socket.trip}] unbanned ${target} in ${socket.channel}`);
|
||||||
|
|
||||||
server.reply({
|
server.reply({
|
||||||
cmd: 'info',
|
cmd: 'info',
|
||||||
text: `${socket.nick} unbanned a userhash: ${server.getSocketHash(ip)}`
|
text: `Unbanned ${target}`
|
||||||
}, socket);
|
}, socket);
|
||||||
|
|
||||||
server.broadcast({
|
server.broadcast({
|
||||||
cmd: 'info',
|
cmd: 'info',
|
||||||
text: `${socket.nick} unbanned a userhash: ${server.getSocketHash(ip)}`
|
text: `${socket.nick} unbanned: ${target}`
|
||||||
}, { uType: 'mod' });
|
}, { uType: 'mod' });
|
||||||
|
|
||||||
core.managers.stats.decrement('users-banned');
|
core.managers.stats.decrement('users-banned');
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.requiredData = ['ip'];
|
|
||||||
|
|
||||||
exports.info = {
|
exports.info = {
|
||||||
name: 'unban',
|
name: 'unban',
|
||||||
usage: 'unban {ip}',
|
usage: 'unban {[ip || hash]}',
|
||||||
description: 'Removes target ip from the ratelimiter'
|
description: 'Removes target ip from the ratelimiter'
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,6 +18,7 @@ class Police {
|
||||||
this._records = {};
|
this._records = {};
|
||||||
this._halflife = 30000; // ms
|
this._halflife = 30000; // ms
|
||||||
this._threshold = 25;
|
this._threshold = 25;
|
||||||
|
this._hashes = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,12 +77,11 @@ class Police {
|
||||||
*
|
*
|
||||||
* @memberof Police
|
* @memberof Police
|
||||||
*/
|
*/
|
||||||
arrest (id) {
|
arrest (id, hash) {
|
||||||
var record = this.search(id);
|
let record = this.search(id);
|
||||||
|
|
||||||
if (record) {
|
record.arrested = true;
|
||||||
record.arrested = true;
|
this._hashes[hash] = id;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,14 +93,12 @@ class Police {
|
||||||
* @memberof Police
|
* @memberof Police
|
||||||
*/
|
*/
|
||||||
pardon (id) {
|
pardon (id) {
|
||||||
var record = this.search(id);
|
if (typeof this._hashes[id] !== 'undefined') {
|
||||||
|
id = this._hashes[id];
|
||||||
if (record) {
|
|
||||||
record.arrested = false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
let record = this.search(id);
|
||||||
|
record.arrested = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user