From 74ea1573b298be5a935caaca0b3cc57cb1e9264a Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Sun, 9 Mar 2025 00:12:48 +0700 Subject: [PATCH] feat(captcha): Added `Text Captcha` provider (#1839) * feat(captcha): Added `Text Captcha` provider * Create TextCaptcha.php * Updated * Update composer.lock * Updated * Update config.php * Update functions.php * Update TextCaptcha.php * Update TextCaptcha.php * Update TextCaptcha.php * Update TextCaptcha.php * Update TextCaptcha.php * Update TextCaptcha.php * Update TextCaptcha.php --- composer.json | 1 + composer.lock | 114 +++++++++++++++++++++++-------- library/config.php | 2 +- library/includes/functions.php | 3 +- library/language/source/main.php | 1 + src/Captcha/GoogleCaptchaV3.php | 4 +- src/Captcha/TextCaptcha.php | 71 +++++++++++++++++++ 7 files changed, 165 insertions(+), 31 deletions(-) create mode 100644 src/Captcha/TextCaptcha.php diff --git a/composer.json b/composer.json index 2a4d1d02b..81a45bc44 100644 --- a/composer.json +++ b/composer.json @@ -53,6 +53,7 @@ "arokettu/torrent-file": "^5.2.1", "bugsnag/bugsnag": "^v3.29.1", "claviska/simpleimage": "^4.0", + "gregwar/captcha": "1.*", "egulias/email-validator": "^4.0.1", "filp/whoops": "^2.15", "z4kn4fein/php-semver": "^v3.0.0", diff --git a/composer.lock b/composer.lock index ef6589450..78f1f5dae 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9024100c87e72c5ee811638607aa15f5", + "content-hash": "3cdb46350e69ff19cc07455ac9791423", "packages": [ { "name": "arokettu/bencode", @@ -813,21 +813,21 @@ "source": { "type": "git", "url": "https://github.com/Gemorroj/M3uParser.git", - "reference": "fcb37acd137a6e1d6aa2ef3745e1bc7a6e0b46e6" + "reference": "6e6a35df8d5410d8884c7dadcde611607aae3b12" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Gemorroj/M3uParser/zipball/fcb37acd137a6e1d6aa2ef3745e1bc7a6e0b46e6", - "reference": "fcb37acd137a6e1d6aa2ef3745e1bc7a6e0b46e6", + "url": "https://api.github.com/repos/Gemorroj/M3uParser/zipball/6e6a35df8d5410d8884c7dadcde611607aae3b12", + "reference": "6e6a35df8d5410d8884c7dadcde611607aae3b12", "shasum": "" }, "require": { "php": ">=8.0.2" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.46", - "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^9.6" + "friendsofphp/php-cs-fixer": "^3.68.5", + "phpstan/phpstan": "^2", + "phpunit/phpunit": "^9.6.22" }, "default-branch": true, "type": "library", @@ -855,7 +855,7 @@ "issues": "https://github.com/Gemorroj/M3uParser/issues", "source": "https://github.com/Gemorroj/M3uParser/tree/master" }, - "time": "2024-07-27T11:53:30+00:00" + "time": "2025-03-03T18:16:38+00:00" }, { "name": "gigablah/sphinxphp", @@ -1026,6 +1026,63 @@ ], "time": "2024-07-20T21:45:45+00:00" }, + { + "name": "gregwar/captcha", + "version": "v1.2.1", + "source": { + "type": "git", + "url": "https://github.com/Gregwar/Captcha.git", + "reference": "229d3cdfe33d6f1349e0aec94a26e9205a6db08e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Gregwar/Captcha/zipball/229d3cdfe33d6f1349e0aec94a26e9205a6db08e", + "reference": "229d3cdfe33d6f1349e0aec94a26e9205a6db08e", + "shasum": "" + }, + "require": { + "ext-gd": "*", + "ext-mbstring": "*", + "php": ">=5.3.0", + "symfony/finder": "*" + }, + "require-dev": { + "phpunit/phpunit": "^6.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "Gregwar\\": "src/Gregwar" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Grégoire Passault", + "email": "g.passault@gmail.com", + "homepage": "http://www.gregwar.com/" + }, + { + "name": "Jeremy Livingston", + "email": "jeremy.j.livingston@gmail.com" + } + ], + "description": "Captcha generator", + "homepage": "https://github.com/Gregwar/Captcha", + "keywords": [ + "bot", + "captcha", + "spam" + ], + "support": { + "issues": "https://github.com/Gregwar/Captcha/issues", + "source": "https://github.com/Gregwar/Captcha/tree/v1.2.1" + }, + "time": "2023-09-26T13:45:37+00:00" + }, { "name": "guzzlehttp/guzzle", "version": "7.9.2", @@ -2026,6 +2083,7 @@ "issues": "https://github.com/nemorize/php-indexnow/issues", "source": "https://github.com/nemorize/php-indexnow/tree/0.0.1" }, + "abandoned": true, "time": "2023-07-31T17:08:12+00:00" }, { @@ -3186,16 +3244,16 @@ }, { "name": "symfony/mailer", - "version": "v6.4.13", + "version": "v6.4.18", "source": { "type": "git", "url": "https://github.com/symfony/mailer.git", - "reference": "c2f7e0d8d7ac8fe25faccf5d8cac462805db2663" + "reference": "e93a6ae2767d7f7578c2b7961d9d8e27580b2b11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/mailer/zipball/c2f7e0d8d7ac8fe25faccf5d8cac462805db2663", - "reference": "c2f7e0d8d7ac8fe25faccf5d8cac462805db2663", + "url": "https://api.github.com/repos/symfony/mailer/zipball/e93a6ae2767d7f7578c2b7961d9d8e27580b2b11", + "reference": "e93a6ae2767d7f7578c2b7961d9d8e27580b2b11", "shasum": "" }, "require": { @@ -3246,7 +3304,7 @@ "description": "Helps sending emails", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/mailer/tree/v6.4.13" + "source": "https://github.com/symfony/mailer/tree/v6.4.18" }, "funding": [ { @@ -3262,20 +3320,20 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:18:03+00:00" + "time": "2025-01-24T15:27:15+00:00" }, { "name": "symfony/mime", - "version": "v6.4.17", + "version": "v6.4.19", "source": { "type": "git", "url": "https://github.com/symfony/mime.git", - "reference": "ea87c8850a54ff039d3e0ab4ae5586dd4e6c0232" + "reference": "ac537b6c55ccc2c749f3c979edfa9ec14aaed4f3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/mime/zipball/ea87c8850a54ff039d3e0ab4ae5586dd4e6c0232", - "reference": "ea87c8850a54ff039d3e0ab4ae5586dd4e6c0232", + "url": "https://api.github.com/repos/symfony/mime/zipball/ac537b6c55ccc2c749f3c979edfa9ec14aaed4f3", + "reference": "ac537b6c55ccc2c749f3c979edfa9ec14aaed4f3", "shasum": "" }, "require": { @@ -3331,7 +3389,7 @@ "mime-type" ], "support": { - "source": "https://github.com/symfony/mime/tree/v6.4.17" + "source": "https://github.com/symfony/mime/tree/v6.4.19" }, "funding": [ { @@ -3347,7 +3405,7 @@ "type": "tidelift" } ], - "time": "2024-12-02T11:09:41+00:00" + "time": "2025-02-17T21:23:52+00:00" }, { "name": "symfony/polyfill", @@ -3689,16 +3747,16 @@ "packages-dev": [ { "name": "symfony/var-dumper", - "version": "v6.4.15", + "version": "v6.4.18", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "38254d5a5ac2e61f2b52f9caf54e7aa3c9d36b80" + "reference": "4ad10cf8b020e77ba665305bb7804389884b4837" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/38254d5a5ac2e61f2b52f9caf54e7aa3c9d36b80", - "reference": "38254d5a5ac2e61f2b52f9caf54e7aa3c9d36b80", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/4ad10cf8b020e77ba665305bb7804389884b4837", + "reference": "4ad10cf8b020e77ba665305bb7804389884b4837", "shasum": "" }, "require": { @@ -3754,7 +3812,7 @@ "dump" ], "support": { - "source": "https://github.com/symfony/var-dumper/tree/v6.4.15" + "source": "https://github.com/symfony/var-dumper/tree/v6.4.18" }, "funding": [ { @@ -3770,7 +3828,7 @@ "type": "tidelift" } ], - "time": "2024-11-08T15:28:48+00:00" + "time": "2025-01-17T11:26:11+00:00" } ], "aliases": [], @@ -3784,6 +3842,6 @@ "platform": { "php": "^8.1 | ^8.2 | ^8.3 | ^8.4" }, - "platform-dev": [], - "plugin-api-version": "2.3.0" + "platform-dev": {}, + "plugin-api-version": "2.6.0" } diff --git a/library/config.php b/library/config.php index 900b02e4c..418c1331d 100644 --- a/library/config.php +++ b/library/config.php @@ -675,7 +675,7 @@ $bb_cfg['group_avatars'] = [ // Captcha $bb_cfg['captcha'] = [ 'disabled' => true, - 'service' => 'googleV3', // Available services: googleV2, googleV3, hCaptcha, yandex, cloudflare + 'service' => 'googleV3', // Available services: text, googleV2, googleV3, hCaptcha, yandex, cloudflare 'public_key' => '', 'secret_key' => '', 'theme' => 'light', // theming (available: light, dark) (working only if supported by captcha service) diff --git a/library/includes/functions.php b/library/includes/functions.php index edb43d26f..5ed6e33cc 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -2057,7 +2057,7 @@ function bb_captcha(string $mode): bool|string $settings['language'] = $bb_cfg['default_lang']; // Checking captcha settings - if (!$settings['disabled']) { + if (!$settings['disabled'] && $settings['service'] !== 'text') { if (empty($settings['public_key']) || empty($settings['secret_key'])) { bb_die($lang['CAPTCHA_SETTINGS']); } @@ -2070,6 +2070,7 @@ function bb_captcha(string $mode): bool|string 'hCaptcha' => \TorrentPier\Captcha\HCaptcha::class, 'yandex' => \TorrentPier\Captcha\YandexSmartCaptcha::class, 'cloudflare' => \TorrentPier\Captcha\CloudflareTurnstileCaptcha::class, + 'text' => \TorrentPier\Captcha\TextCaptcha::class ]; if (!isset($captchaClasses[$settings['service']])) { bb_die(sprintf('Captcha service (%s) not supported', $settings['service'])); diff --git a/library/language/source/main.php b/library/language/source/main.php index ee7de900b..65fd05fd1 100644 --- a/library/language/source/main.php +++ b/library/language/source/main.php @@ -3073,6 +3073,7 @@ $lang['UPLOAD_ERRORS'] = [ $lang['CAPTCHA'] = 'Check that you are not a robot'; $lang['CAPTCHA_WRONG'] = 'You could not confirm that you are not a robot'; $lang['CAPTCHA_SETTINGS'] = '

Captcha is not fully configured

Generate the keys using the dashboard of your captcha service, after you need to put them at the file library/config.php.

'; +$lang['CAPTCHA_OCCURS_BACKGROUND'] = 'The CAPTCHA verification occurs in the background'; // Sending email $lang['REPLY_TO'] = 'Reply to'; diff --git a/src/Captcha/GoogleCaptchaV3.php b/src/Captcha/GoogleCaptchaV3.php index 4a8aed893..855066861 100644 --- a/src/Captcha/GoogleCaptchaV3.php +++ b/src/Captcha/GoogleCaptchaV3.php @@ -41,7 +41,9 @@ class GoogleCaptchaV3 implements CaptchaInterface */ public function get(): string { - return " + global $lang; + + return "{$lang['CAPTCHA_OCCURS_BACKGROUND']}