make cd based on subnet if not logged in

This commit is contained in:
HF 2022-09-22 10:36:45 +02:00
parent a08ba00940
commit 279819eac0
2 changed files with 15 additions and 2 deletions

View File

@ -38,7 +38,15 @@ export default function allowPlace(
const isalKey = `${ALLOWED_PREFIX}:${ip}`;
const captKey = (CAPTCHA_TIME >= 0) ? `${CAPTCHA_PREFIX}:${ip}` : 'nope';
const ipCdKey = `${PREFIX}:${canvasId}:ip:${ip}`;
const idCdKey = (id) ? `${PREFIX}:${canvasId}:id:${id}` : 'nope';
let idCdKey;
if (id) {
idCdKey = `${PREFIX}:${canvasId}:id:${id}`;
} else if (ip.includes('.')) {
const ips = ip.slice(0, ip.lastIndexOf('.'));
idCdKey = `${PREFIX}:${canvasId}:ips:${ips}`;
} else {
idCdKey = 'nope';
}
const chunkKey = `ch:${canvasId}:${i}:${j}`;
const cc = country || 'xx';
const rankset = (ranked) ? RANKED_KEY : 'nope';
@ -67,6 +75,10 @@ export async function getCoolDown(
if (id) {
const ttlid = await client.pTTL(`${PREFIX}:${canvasId}:id:${id}`);
ttl = Math.max(ttl, ttlid);
} else if (ip.includes('.')) {
const ips = ip.slice(0, ip.lastIndexOf('.'));
const ttlid = await client.pTTL(`${PREFIX}:${canvasId}:ips:${ips}`);
ttl = Math.max(ttl, ttlid);
}
const cooldown = ttl < 0 ? 0 : ttl;
return cooldown;

View File

@ -22,7 +22,8 @@ async function banme(req, res) {
reason = 'Captcha Solving Script';
}
const ip = getIPFromRequest(req);
logger.info(`AUTOBAN ${ip} of user ${req.user.id}`);
// eslint-disable-next-line max-len
logger.info(`AUTOBAN ${code}${ip} of user ${req.user.id} with ua "${req.headers['user-agent']}"`);
await banIP(
getIPv6Subnet(ip),
reason,