diff --git a/inc/Service/YandexCaptchaQuery.php b/inc/Service/YandexCaptchaQuery.php new file mode 100644 index 00000000..840637f2 --- /dev/null +++ b/inc/Service/YandexCaptchaQuery.php @@ -0,0 +1,44 @@ +http = $http; + $this->secret = $secret; + } + + public function responseField(): string { + return 'smart-captcha'; + } + + public function verify(string $response, ?string $remote_ip): bool { + $data = [ + 'secret' => $this->secret, + 'token' => $response + ]; + + if ($remote_ip !== null) { + $data['ip'] = $remote_ip; + } + + $ret = $this->http->requestGet('https://smartcaptcha.yandexcloud.net/validate', $data); + $resp = json_decode($ret, true, 16, JSON_THROW_ON_ERROR); + + return isset($resp['status']) && $resp['status'] === 'ok'; + } +} \ No newline at end of file diff --git a/inc/config.php b/inc/config.php index 6be2519c..463ba67e 100644 --- a/inc/config.php +++ b/inc/config.php @@ -361,7 +361,7 @@ $config['simple_spam'] = false; $config['captcha'] = [ - // Can be false, 'recaptcha', 'hcaptcha' or 'native'. + // Can be false, 'recaptcha', 'hcaptcha', 'yandexcaptcha' or 'native'. 'provider' => false, /* * If not false, the captcha is dynamically injected on the client if the web server set the `captcha-required` @@ -381,6 +381,10 @@ 'sitekey' => '10000000-ffff-ffff-ffff-000000000001', 'secret' => '0x0000000000000000000000000000000000000000', ], + 'yandexcaptcha' => [ + 'sitekey' => 'ysc1_rfl88NyaKGOwimTqVEShW23JdWHlRwXg6jyPhkW2sj1voM9Y', + 'secret' => 'ysc2_M48FXzexqG5mTESVJfS4nVWhq8lytaMGObxEVqym35Kbz0r7', + ], // To enable the native captcha you need to change a couple of settings. Read more at: /inc/captcha/readme.md 'native' => [ // Custom captcha get provider path (if not working get the absolute path aka your url). diff --git a/inc/context.php b/inc/context.php index 63557227..b0ad871a 100644 --- a/inc/context.php +++ b/inc/context.php @@ -6,6 +6,7 @@ use Vichan\Data\ReportQueries; use Vichan\Service\HCaptchaQuery; use Vichan\Service\SecureImageCaptchaQuery; use Vichan\Service\ReCaptchaQuery; +use Vichan\Service\YandexCaptchaQuery; use Vichan\Service\RemoteCaptchaQuery; defined('TINYBOARD') or exit; @@ -74,6 +75,8 @@ function build_context(array $config): Context { $config['captcha']['hcaptcha']['secret'], $config['captcha']['hcaptcha']['sitekey'] ); + case 'yandexcaptcha': + return new YandexCaptchaQuery($http, $config['captcha']['yandexcaptcha']['secret']); default: throw new \RuntimeException('No remote captcha service available'); } diff --git a/templates/header.html b/templates/header.html index fe4e7a5f..19f0bdfd 100644 --- a/templates/header.html +++ b/templates/header.html @@ -53,3 +53,6 @@ {% if config.captcha.provider == 'hcaptcha' %} {% endif %} +{% if config.captcha.provider == 'yandexcaptcha' %} + +{% endif %} \ No newline at end of file diff --git a/templates/post_form.html b/templates/post_form.html index 1095b4ae..5dd1789b 100644 --- a/templates/post_form.html +++ b/templates/post_form.html @@ -100,6 +100,16 @@ {% endif %} + {% if config.captcha.provider == 'yandexcaptcha' %} +