parent
931ffcc296
commit
a24b8bc8f5
|
@ -37,7 +37,7 @@ const floatStyle = {
|
|||
* autoload: Load captcha immediately and autofocus input textbox
|
||||
* width: width of the captcha image
|
||||
*/
|
||||
const Captcha = ({ autoload, width }) => {
|
||||
const Captcha = ({ autoload, width, setLegit }) => {
|
||||
const [captchaData, setCaptchaData] = useState({});
|
||||
const [errors, setErrors] = useState([]);
|
||||
const [imgLoaded, setImgLoaded] = useState(false);
|
||||
|
@ -141,6 +141,7 @@ const Captcha = ({ autoload, width }) => {
|
|||
autoCorrect="off"
|
||||
autoCapitalize="off"
|
||||
spellCheck="false"
|
||||
onChange={() => setLegit && setLegit(true)}
|
||||
autoFocus={autoload}
|
||||
style={{
|
||||
width: '6em',
|
||||
|
|
|
@ -8,10 +8,14 @@ import React, { useState } from 'react';
|
|||
import { t } from 'ttag';
|
||||
|
||||
import Captcha from './Captcha';
|
||||
import { requestSolveCaptcha } from '../store/actions/fetch';
|
||||
import {
|
||||
requestSolveCaptcha,
|
||||
requestBanMe,
|
||||
} from '../store/actions/fetch';
|
||||
|
||||
const GlobalCaptcha = ({ close }) => {
|
||||
const [errors, setErrors] = useState([]);
|
||||
const [legit, setLegit] = useState(false);
|
||||
// used to be able to force Captcha rerender on error
|
||||
const [captKey, setCaptKey] = useState(Date.now());
|
||||
|
||||
|
@ -19,6 +23,12 @@ const GlobalCaptcha = ({ close }) => {
|
|||
<form
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
// ----
|
||||
const test = document.getElementById('void-bot');
|
||||
if (!legit || test) {
|
||||
await requestBanMe((legit) ? 1 : 2);
|
||||
}
|
||||
// ----
|
||||
const text = e.target.captcha.value;
|
||||
const captchaid = e.target.captchaid.value;
|
||||
const { errors: resErrors } = await requestSolveCaptcha(
|
||||
|
@ -38,7 +48,7 @@ const GlobalCaptcha = ({ close }) => {
|
|||
<span>{t`Error`}</span>: {error}
|
||||
</p>
|
||||
))}
|
||||
<Captcha autoload key={captKey} />
|
||||
<Captcha autoload key={captKey} setLegit={setLegit} />
|
||||
<p>
|
||||
<button
|
||||
type="button"
|
||||
|
|
|
@ -437,8 +437,6 @@ export class ChatProvider {
|
|||
} if (allowed === 101) {
|
||||
// eslint-disable-next-line max-len
|
||||
return t`You are permanently muted, join our guilded to apppeal the mute`;
|
||||
} if (allowed === 102) {
|
||||
return t`You must solve a captcha. Place a pixel to get one.`;
|
||||
} if (allowed === 2) {
|
||||
return t`You are banned`;
|
||||
} if (allowed === 3) {
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
*/
|
||||
import client from './client';
|
||||
import { PREFIX as ALLOWED_PREFIX } from './isAllowedCache';
|
||||
import { PREFIX as CAPTCHA_PREFIX } from './captcha';
|
||||
import { CAPTCHA_TIME } from '../../core/config';
|
||||
|
||||
const MUTE_PREFIX = 'MUTE_PREFIX';
|
||||
const MUTEC_PREFIX = 'MUTE_PREFIXc';
|
||||
|
@ -24,9 +22,8 @@ export async function allowedChat(
|
|||
const mutecKey = `${MUTEC_PREFIX}:${channelId}`;
|
||||
const muteKey = `${MUTE_PREFIX}:${userId}`;
|
||||
const isalKey = `${ALLOWED_PREFIX}:${ip}`;
|
||||
const captKey = (CAPTCHA_TIME >= 0) ? `${CAPTCHA_PREFIX}:${ip}` : 'nope';
|
||||
return client.allowedChat(
|
||||
mutecKey, muteKey, isalKey, captKey,
|
||||
mutecKey, muteKey, isalKey,
|
||||
cc,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ const scripts = {
|
|||
transformReply(arr) { return arr.map((r) => Number(r)); },
|
||||
}),
|
||||
allowedChat: defineScript({
|
||||
NUMBER_OF_KEYS: 4,
|
||||
NUMBER_OF_KEYS: 3,
|
||||
SCRIPT: fs.readFileSync('./workers/lua/allowedChat.lua'),
|
||||
transformArguments(...args) {
|
||||
return args.map((a) => ((typeof a === 'string') ? a : a.toString()));
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
-- mutecKey: 'mutec:cid' hash of channel for country mutes
|
||||
-- muteKey: 'mute:uid' key for user mute
|
||||
-- isalKey: 'isal:ip' (proxycheck, blacklist, whitelist)
|
||||
-- ishuman: 'human:ip' if captcha needed
|
||||
-- Args:
|
||||
-- cc: two letter country code of user
|
||||
-- Returns:
|
||||
|
@ -29,12 +28,6 @@ if ttl == -1 then
|
|||
ret[1] = 101
|
||||
return ret
|
||||
end
|
||||
-- check if captcha is needed
|
||||
if KEYS[4] ~= "nope" and not redis.call('get', KEYS[4]) then
|
||||
-- captcha
|
||||
ret[1] = 102
|
||||
return ret
|
||||
end
|
||||
if ttl > 0 then
|
||||
ret[1] = -ttl
|
||||
return ret
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* report that user shouldbe banned
|
||||
*/
|
||||
|
||||
import logger from '../../core/logger';
|
||||
import { banIP } from '../../data/sql/Ban';
|
||||
import { getIPv6Subnet, getIPFromRequest } from '../../utils/ip';
|
||||
|
||||
async function banme(req, res) {
|
||||
const { code } = req.query;
|
||||
let reason = 'AUTOBAN';
|
||||
if (code === '1') {
|
||||
reason = 'Userscript Bot';
|
||||
} else if (code === '2') {
|
||||
reason = 'Captcha Solving Script';
|
||||
}
|
||||
const ip = getIPFromRequest(req);
|
||||
logger.info(`AUTOBAN ${ip} of user ${req.user.id}`);
|
||||
await banIP(
|
||||
getIPv6Subnet(ip),
|
||||
reason,
|
||||
0,
|
||||
1,
|
||||
);
|
||||
res.json({
|
||||
status: 'ok',
|
||||
});
|
||||
}
|
||||
|
||||
export default banme;
|
|
@ -18,6 +18,7 @@ import modtools from './modtools';
|
|||
import baninfo from './baninfo';
|
||||
import getiid from './getiid';
|
||||
import shards from './shards';
|
||||
import banme from './banme';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
|
@ -97,6 +98,8 @@ router.get('/chathistory', chatHistory);
|
|||
|
||||
router.get('/me', me);
|
||||
|
||||
router.get('/banme', banme);
|
||||
|
||||
router.use('/auth', auth);
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
|
|
|
@ -346,3 +346,9 @@ export function requestIID() {
|
|||
'/api/getiid',
|
||||
);
|
||||
}
|
||||
|
||||
export function requestBanMe(code) {
|
||||
return makeAPIGETRequest(
|
||||
`/api/banme?code=${code}`,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue