diff --git a/src/core/ChatProvider.js b/src/core/ChatProvider.js index ef22daa..19dfc93 100644 --- a/src/core/ChatProvider.js +++ b/src/core/ChatProvider.js @@ -380,7 +380,7 @@ export class ChatProvider { return null; } - if (!user.userlvl && await cheapDetector(user.ip)) { + if (await cheapDetector(user.ip)) { logger.info( `${name} / ${user.ip} tried to send chat message with proxy`, ); diff --git a/src/core/mail.js b/src/core/mail.js index ec61720..26e3333 100644 --- a/src/core/mail.js +++ b/src/core/mail.js @@ -193,14 +193,6 @@ class MailProvider { return reguser.name; } - static createCode() { - const part1 = Math.random().toString(36).substring(2, 15) - + Math.random().toString(36).substring(2, 15); - const part2 = Math.random().toString(36).substring(2, 15) - + Math.random().toString(36).substring(2, 15); - return `${part1}-${part2}`; - } - static createCode() { return randomUUID(); } diff --git a/src/data/redis/captcha.js b/src/data/redis/captcha.js index 9a2e62e..7933353 100644 --- a/src/data/redis/captcha.js +++ b/src/data/redis/captcha.js @@ -59,9 +59,6 @@ function evaluateResult(captchaText, userText) { return false; } } - if (Math.random() < 0.1) { - return false; - } return true; } @@ -97,6 +94,7 @@ export async function setCaptchaSolution( * @param text Solution of captcha * @param ip * @param onetime If the captcha is just one time or should be remembered + * @param wrongCallback function that gets called when captcha got solved wrong * for this ip * @return 0 if solution right * 1 if timed out @@ -107,6 +105,7 @@ export async function checkCaptchaSolution( ip, onetime = false, captchaid = null, + wrongCallback = null, ) { const ipn = getIPv6Subnet(ip); let key = `capt:${ip}`; @@ -116,6 +115,9 @@ export async function checkCaptchaSolution( const solution = await redis.get(key); if (solution) { if (evaluateResult(solution, text)) { + if (Math.random() < 0.1) { + return 2; + } if (!onetime) { const solvkey = `human:${ipn}`; await redis.set(solvkey, '', { @@ -128,6 +130,7 @@ export async function checkCaptchaSolution( logger.info( `CAPTCHA ${ip} got captcha wrong (${text} instead of ${solution})`, ); + wrongCallback(text, solution); return 2; } logger.info(`CAPTCHA ${ip}:${captchaid} timed out`); diff --git a/src/routes/api/captcha.js b/src/routes/api/captcha.js index e8c5f00..6811df6 100644 --- a/src/routes/api/captcha.js +++ b/src/routes/api/captcha.js @@ -8,6 +8,7 @@ import logger from '../../core/logger'; import { checkCaptchaSolution } from '../../data/redis/captcha'; import { getIPFromRequest } from '../../utils/ip'; +import chatProvider from '../../core/ChatProvider'; export default async (req, res) => { const ip = getIPFromRequest(req); @@ -26,7 +27,21 @@ export default async (req, res) => { return; } - const ret = await checkCaptchaSolution(text, ip, false, id); + const ret = await checkCaptchaSolution( + text, + ip, + false, + id, + (inpt, solution) => { + chatProvider.broadcastChatMessage( + 'info', + // eslint-disable-next-line max-len + `Someone got his captcha wrong and entered ${inpt} instead of ${solution}`, + chatProvider.enChannelId, + chatProvider.infoUserId, + ); + }, + ); switch (ret) { case 0: