From 3278415b3d3c838ce852d2925f8b8870a88ac62b Mon Sep 17 00:00:00 2001 From: William Desportes Date: Mon, 27 Jan 2020 22:01:35 +0100 Subject: [PATCH] Implement $cfg['CaptchaSiteVerifyURL'] for Google re-captcha Signed-off-by: William Desportes --- doc/config.rst | 11 +++++++++++ libraries/classes/Config/Descriptions.php | 2 ++ libraries/classes/Config/Forms/Setup/FeaturesForm.php | 1 + .../classes/Plugins/Auth/AuthenticationCookie.php | 8 +++++--- libraries/config.default.php | 7 +++++++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/doc/config.rst b/doc/config.rst index 5e8592d61b..7525989d9e 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -1892,6 +1892,17 @@ Cookie authentication options reCaptcha will be then used in :ref:`cookie`. +.. config:option:: $cfg['CaptchaSiteVerifyURL'] + + :type: string + :default: ``''`` + + The URL for the reCaptcha service to do siteverify action. + + reCaptcha will be then used in :ref:`cookie`. + + .. versionadded:: 5.1.0 + Navigation panel setup ---------------------- diff --git a/libraries/classes/Config/Descriptions.php b/libraries/classes/Config/Descriptions.php index 3ed85daeba..8ba644b894 100644 --- a/libraries/classes/Config/Descriptions.php +++ b/libraries/classes/Config/Descriptions.php @@ -898,6 +898,8 @@ class Descriptions 'CaptchaLoginPublicKey_name' => __('Public key for reCaptcha'), 'CaptchaLoginPrivateKey_desc' => __('Enter your private key for your domain reCaptcha service.'), 'CaptchaLoginPrivateKey_name' => __('Private key for reCaptcha'), + 'CaptchaSiteVerifyURL_desc' => __('Enter your siteverify URL for your reCaptcha service.'), + 'CaptchaSiteVerifyURL_name' => __('URL for reCaptcha siteverify'), 'SendErrorReports_desc' => __('Choose the default action when sending error reports.'), 'SendErrorReports_name' => __('Send error reports'), diff --git a/libraries/classes/Config/Forms/Setup/FeaturesForm.php b/libraries/classes/Config/Forms/Setup/FeaturesForm.php index 75875759e4..3b529583a2 100644 --- a/libraries/classes/Config/Forms/Setup/FeaturesForm.php +++ b/libraries/classes/Config/Forms/Setup/FeaturesForm.php @@ -49,6 +49,7 @@ class FeaturesForm extends \PhpMyAdmin\Config\Forms\User\FeaturesForm 'LoginCookieDeleteAll', 'CaptchaLoginPublicKey', 'CaptchaLoginPrivateKey', + 'CaptchaSiteVerifyURL', ]; $result['Developer'] = [ 'UserprefsDeveloperTab', diff --git a/libraries/classes/Plugins/Auth/AuthenticationCookie.php b/libraries/classes/Plugins/Auth/AuthenticationCookie.php index c57c84b439..9aa5c68718 100644 --- a/libraries/classes/Plugins/Auth/AuthenticationCookie.php +++ b/libraries/classes/Plugins/Auth/AuthenticationCookie.php @@ -268,20 +268,22 @@ class AuthenticationCookie extends AuthenticationPlugin && ! empty($GLOBALS['cfg']['CaptchaLoginPublicKey']) ) { if (! empty($_POST['g-recaptcha-response'])) { + $captchaSiteVerifyURL = $GLOBALS['cfg']['CaptchaSiteVerifyURL'] ?? ''; + $captchaSiteVerifyURL = empty($captchaSiteVerifyURL) ? null : $captchaSiteVerifyURL; if (function_exists('curl_init')) { $reCaptcha = new ReCaptcha\ReCaptcha( $GLOBALS['cfg']['CaptchaLoginPrivateKey'], - new ReCaptcha\RequestMethod\CurlPost() + new ReCaptcha\RequestMethod\CurlPost(null, $captchaSiteVerifyURL) ); } elseif (ini_get('allow_url_fopen')) { $reCaptcha = new ReCaptcha\ReCaptcha( $GLOBALS['cfg']['CaptchaLoginPrivateKey'], - new ReCaptcha\RequestMethod\Post() + new ReCaptcha\RequestMethod\Post($captchaSiteVerifyURL) ); } else { $reCaptcha = new ReCaptcha\ReCaptcha( $GLOBALS['cfg']['CaptchaLoginPrivateKey'], - new ReCaptcha\RequestMethod\SocketPost() + new ReCaptcha\RequestMethod\SocketPost(null, $captchaSiteVerifyURL) ); } diff --git a/libraries/config.default.php b/libraries/config.default.php index 22891e4e72..07db8b89a8 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -848,6 +848,13 @@ $cfg['CaptchaLoginPublicKey'] = ''; */ $cfg['CaptchaLoginPrivateKey'] = ''; +/** + * if reCaptcha is enabled may need an URL for site verify + * + * @global string $cfg['CaptchaSiteVerifyURL'] + */ +$cfg['CaptchaSiteVerifyURL'] = ''; + /** * Enable drag and drop import *