From c54ffcbca5ef1735609252f7b00beeb270aee363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Thu, 7 Oct 2021 20:41:00 +0300 Subject: [PATCH 1/8] Polishing SpamChecker --- src/bb-modules/Spamchecker/Service.php | 30 +- .../html_admin/mod_spamchecker_settings.phtml | 33 +-- .../mod_spamchecker_recaptcha.phtml | 11 - src/bb-modules/Spamchecker/manifest.json | 12 +- src/bb-modules/Spamchecker/recaptchalib.php | 277 ------------------ 5 files changed, 26 insertions(+), 337 deletions(-) delete mode 100644 src/bb-modules/Spamchecker/recaptchalib.php diff --git a/src/bb-modules/Spamchecker/Service.php b/src/bb-modules/Spamchecker/Service.php index c732021d2..ffd4f50a3 100644 --- a/src/bb-modules/Spamchecker/Service.php +++ b/src/bb-modules/Spamchecker/Service.php @@ -164,31 +164,15 @@ class Service implements InjectionAwareInterface $options = [ 'form_params' => $postData ]; - $response = $di['guzzle_client']->request('POST', 'https://www.google.com/recaptcha/api/siteverify', $options); + $response = $di['guzzle_client']->request('POST', 'https://google.com/recaptcha/api/siteverify', $options); $body = $response->getBody()->getContents(); $content = json_decode($body, true); if (!$content['success']) { - throw new \Box_Exception('Captcha verification failed.'); + throw new \Box_Exception('reCAPTCHA verification failed.'); } - } else { - - $privatekey = $config['captcha_recaptcha_privatekey']; - - if ($privatekey == null || $privatekey == '') { - throw new \Box_Exception("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create"); - } - - require_once BB_PATH_MODS . '/Spamchecker/recaptchalib.php'; - $resp = recaptcha_check_answer($privatekey, - $data['ip'], - $data["recaptcha_challenge_field"], - $data["recaptcha_response_field"]); - if (!$resp->is_valid) { - error_log($resp->error); - throw new \Box_Exception('Captcha verification failed.'); - } + throw new \Box_Exception('reCAPTCHA verification failed.'); } } @@ -211,7 +195,7 @@ class Service implements InjectionAwareInterface public function isInStopForumSpamDatabase(array $data) { $data['f'] = 'json'; - $url = 'http://www.stopforumspam.com/api?'.http_build_query($data); + $url = 'https://www.stopforumspam.com/api?'.http_build_query($data); $file_contents = $this->di['tools']->file_get_contents($url); $json = json_decode($file_contents); @@ -220,13 +204,13 @@ class Service implements InjectionAwareInterface } if(isset($json->username->appears) && $json->username->appears) { - throw new \Box_Exception('Your Username is blacklisted in global database'); + throw new \Box_Exception('Your username is blacklisted in the Stop Forum Spam database'); } if(isset($json->email->appears) && $json->email->appears) { - throw new \Box_Exception('Your Email is blacklisted in global database'); + throw new \Box_Exception('Your e-mail is blacklisted in the Stop Forum Spam database'); } if(isset($json->ip->appears) && $json->ip->appears) { - throw new \Box_Exception('Your IP is blacklisted in global database'); + throw new \Box_Exception('Your IP address is blacklisted in the Stop Forum Spam database'); } return false; diff --git a/src/bb-modules/Spamchecker/html_admin/mod_spamchecker_settings.phtml b/src/bb-modules/Spamchecker/html_admin/mod_spamchecker_settings.phtml index 2056847f6..21c8875c4 100644 --- a/src/bb-modules/Spamchecker/html_admin/mod_spamchecker_settings.phtml +++ b/src/bb-modules/Spamchecker/html_admin/mod_spamchecker_settings.phtml @@ -42,14 +42,14 @@
-

{% trans 'Recaptcha settings' %}

-

{% trans 'Enable captcha for client registration and contact us forms' %}

-

{% trans 'Sign up for Recaptcha key for your domain at' %} http://www.google.com/recaptcha

+

{% trans 'reCAPTCHA settings' %}

+

{% trans 'Enable captcha for client registration and contact forms' %}

+

{% trans 'Sign up for reCAPTCHA key for your domain at' %} https://google.com/recaptcha/

- +
@@ -57,25 +57,18 @@
-
- -
- - -
-
-
-
- + +
+ +
+ +
-
-
-
- +
@@ -85,7 +78,7 @@

{% trans 'Akismet settings' %}

-

{% trans %} Enable forum messages checking on http://www.akismet.com database{% endtrans %}

+

{% trans %} Enable forum messages checking on the Akismet database{% endtrans %}

@@ -109,7 +102,7 @@

{% trans 'StopForumSpam.com settings' %}

-

{% trans %} If enabled, client ip will be checked on http://www.stopforumspam.com database before registration{% endtrans %}

+

{% trans %} If enabled, client IP will be checked on the Stop Forum Spam database before registration{% endtrans %}

diff --git a/src/bb-modules/Spamchecker/html_client/mod_spamchecker_recaptcha.phtml b/src/bb-modules/Spamchecker/html_client/mod_spamchecker_recaptcha.phtml index e314d2a5c..b818ead69 100644 --- a/src/bb-modules/Spamchecker/html_client/mod_spamchecker_recaptcha.phtml +++ b/src/bb-modules/Spamchecker/html_client/mod_spamchecker_recaptcha.phtml @@ -4,17 +4,6 @@ {% if rc.version == 2 %}
- {% else %} - {% set server = "https://www.google.com/recaptcha/api" %} - - {% endif %} {% endif %} {% endif %} \ No newline at end of file diff --git a/src/bb-modules/Spamchecker/manifest.json b/src/bb-modules/Spamchecker/manifest.json index 5f1fcc06b..ade8c8066 100644 --- a/src/bb-modules/Spamchecker/manifest.json +++ b/src/bb-modules/Spamchecker/manifest.json @@ -1,13 +1,13 @@ { "id": "spamchecker", "type": "mod", - "name": "Spam Checker", - "description": "Uses stopforumspam.com database and captcha verification to stop spam", + "name": "SpamChecker", + "description": "Uses stopforumspam.com and reCAPTCHA to stop spam", "icon_url": "icon.png", - "project_url": "http://www.boxbilling.com/", - "homepage_url": "http://www.boxbilling.com/", + "project_url": "https://boxbilling.com/", + "homepage_url": "https://boxbilling.com/", "author": "BoxBilling", - "author_url": "http://www.boxbilling.cz/", + "author_url": "https://boxbilling.org/", "license": "Free for commercial and non-commercial use (Apache License or GPL 2)", - "version": "1.0.0" + "version": "4.22.0" } \ No newline at end of file diff --git a/src/bb-modules/Spamchecker/recaptchalib.php b/src/bb-modules/Spamchecker/recaptchalib.php deleted file mode 100644 index a2f9df223..000000000 --- a/src/bb-modules/Spamchecker/recaptchalib.php +++ /dev/null @@ -1,277 +0,0 @@ - $value ) - $req .= $key . '=' . urlencode( stripslashes($value) ) . '&'; - - // Cut the last '&' - $req=substr($req,0,strlen($req)-1); - return $req; -} - - - -/** - * Submits an HTTP POST to a reCAPTCHA server - * @param string $host - * @param string $path - * @param array $data - * @param int port - * @return array response - */ -function _recaptcha_http_post($host, $path, $data, $port = 80) { - - $req = _recaptcha_qsencode ($data); - - $http_request = "POST $path HTTP/1.0\r\n"; - $http_request .= "Host: $host\r\n"; - $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n"; - $http_request .= "Content-Length: " . strlen($req) . "\r\n"; - $http_request .= "User-Agent: reCAPTCHA/PHP\r\n"; - $http_request .= "\r\n"; - $http_request .= $req; - - $response = ''; - if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) { - throw new Exception(__('Could not open socket')); - } - - fwrite($fs, $http_request); - - while ( !feof($fs) ) - $response .= fgets($fs, 1160); // One TCP-IP packet - fclose($fs); - $response = explode("\r\n\r\n", $response, 2); - - return $response; -} - - - -/** - * Gets the challenge HTML (javascript and non-javascript version). - * This is called from the browser, and the resulting reCAPTCHA HTML widget - * is embedded within the HTML form it was called from. - * @param string $pubkey A public key for reCAPTCHA - * @param string $error The error given by reCAPTCHA (optional, default is null) - * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false) - - * @return string - The HTML to be embedded in the user's form. - */ -function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false) -{ - if ($pubkey == null || $pubkey == '') { - die ("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create"); - } - - if ($use_ssl) { - $server = RECAPTCHA_API_SECURE_SERVER; - } else { - $server = RECAPTCHA_API_SERVER; - } - - $errorpart = ""; - if ($error) { - $errorpart = "&error=" . $error; - } - return ' - - '; -} - - - - -/** - * A ReCaptchaResponse is returned from recaptcha_check_answer() - */ -class ReCaptchaResponse { - var $is_valid; - var $error; -} - - -/** - * Calls an HTTP POST function to verify if the user's guess was correct - * @param string $privkey - * @param string $remoteip - * @param string $challenge - * @param string $response - * @param array $extra_params an array of extra variables to post to the server - * @return ReCaptchaResponse - */ -function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array()) -{ - if ($privkey == null || $privkey == '') { - throw new Exception("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create"); - } - - if ($remoteip == null || $remoteip == '') { - throw new Exception("For security reasons, you must pass the remote ip to reCAPTCHA"); - } - - - - //discard spam submissions - if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) { - $recaptcha_response = new ReCaptchaResponse(); - $recaptcha_response->is_valid = false; - $recaptcha_response->error = 'Incorrect captcha'; - return $recaptcha_response; - } - - $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify", - array ( - 'privatekey' => $privkey, - 'remoteip' => $remoteip, - 'challenge' => $challenge, - 'response' => $response - ) + $extra_params - ); - - $answers = explode ("\n", $response [1]); - $recaptcha_response = new ReCaptchaResponse(); - - if (trim ($answers [0]) == 'true') { - $recaptcha_response->is_valid = true; - } - else { - $recaptcha_response->is_valid = false; - $recaptcha_response->error = $answers [1]; - } - return $recaptcha_response; - -} - -/** - * gets a URL where the user can sign up for reCAPTCHA. If your application - * has a configuration page where you enter a key, you should provide a link - * using this function. - * @param string $domain The domain where the page is hosted - * @param string $appname The name of your application - */ -function recaptcha_get_signup_url ($domain = null, $appname = null) { - return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname)); -} - -function _recaptcha_aes_pad($val) { - $block_size = 16; - $numpad = $block_size - (strlen ($val) % $block_size); - return str_pad($val, strlen ($val) + $numpad, chr($numpad)); -} - -/* Mailhide related code */ - -function _recaptcha_aes_encrypt($val,$ky) { - if (! function_exists ("mcrypt_encrypt")) { - throw new Exception("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed."); - } - $mode=MCRYPT_MODE_CBC; - $enc=MCRYPT_RIJNDAEL_128; - $val=_recaptcha_aes_pad($val); - return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); -} - - -function _recaptcha_mailhide_urlbase64 ($x) { - return strtr(base64_encode ($x), '+/', '-_'); -} - -/* gets the reCAPTCHA Mailhide url for a given email, public key and private key */ -function recaptcha_mailhide_url($pubkey, $privkey, $email) { - if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) { - die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " . - "you can do so at http://www.google.com/recaptcha/mailhide/apikey"); - } - - - $ky = pack('H*', $privkey); - $cryptmail = _recaptcha_aes_encrypt ($email, $ky); - - return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail); -} - -/** - * gets the parts of the email to expose to the user. - * eg, given johndoe@example,com return ["john", "example.com"]. - * the email is then displayed as john...@example.com - */ -function _recaptcha_mailhide_email_parts ($email) { - $arr = preg_split("/@/", $email ); - - if (strlen ($arr[0]) <= 4) { - $arr[0] = substr ($arr[0], 0, 1); - } else if (strlen ($arr[0]) <= 6) { - $arr[0] = substr ($arr[0], 0, 3); - } else { - $arr[0] = substr ($arr[0], 0, 4); - } - return $arr; -} - -/** - * Gets html to display an email address given a public an private key. - * to get a key, go to: - * - * http://www.google.com/recaptcha/mailhide/apikey - */ -function recaptcha_mailhide_html($pubkey, $privkey, $email) { - $emailparts = _recaptcha_mailhide_email_parts ($email); - $url = recaptcha_mailhide_url ($pubkey, $privkey, $email); - - return htmlentities($emailparts[0]) . "...@" . htmlentities ($emailparts [1]); - -} - - -?> From 0d7ffbf78a4047abda22d26d07ba611b23a32b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Thu, 7 Oct 2021 20:49:26 +0300 Subject: [PATCH 2/8] Fix test --- tests/bb-modules/Spamchecker/ServiceTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/bb-modules/Spamchecker/ServiceTest.php b/tests/bb-modules/Spamchecker/ServiceTest.php index 8bbd87170..0ac6b802f 100644 --- a/tests/bb-modules/Spamchecker/ServiceTest.php +++ b/tests/bb-modules/Spamchecker/ServiceTest.php @@ -253,13 +253,13 @@ class ServiceTest extends \BBTestCase { { return array( array( - '{"success" : "true", "username" : {"appears" : "true" }}', 'Your Username is blacklisted in global database' + '{"success" : "true", "username" : {"appears" : "true" }}', 'Your username is blacklisted in the Stop Forum Spam database' ), array( - '{"success" : "true", "email" : {"appears" : "true" }}', 'Your Email is blacklisted in global database' + '{"success" : "true", "email" : {"appears" : "true" }}', 'Your e-mail is blacklisted in the Stop Forum Spam database' ), array( - '{"success" : "true", "ip" : {"appears" : "true" }}', 'Your IP is blacklisted in global database' + '{"success" : "true", "ip" : {"appears" : "true" }}', 'Your IP address is blacklisted in the Stop Forum Spam database' ), ); } From c61a97c89b7b8f7267c7e0efe1c6f97e02be4d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Thu, 7 Oct 2021 21:39:29 +0300 Subject: [PATCH 3/8] Drop reCAPTCHA v1 from theme 'boxbilling' --- .../boxbilling/html/macro_functions.phtml | 40 +++---------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/src/bb-themes/boxbilling/html/macro_functions.phtml b/src/bb-themes/boxbilling/html/macro_functions.phtml index b21926f64..274c320c0 100644 --- a/src/bb-themes/boxbilling/html/macro_functions.phtml +++ b/src/bb-themes/boxbilling/html/macro_functions.phtml @@ -47,40 +47,12 @@ {% macro recaptcha() %} {% if guest.extension_is_on({"mod":"spamchecker"}) %} -{% set rc = guest.spamchecker_recaptcha %} - {% if rc.enabled %} - {% if rc.version == 2 %} - -
- {% else %} - {% set server = "https://www.google.com/recaptcha/api" %} - - - - - - + {% set rc = guest.spamchecker_recaptcha %} + {% if rc.enabled %} + {% if rc.version == 2 %} + +
+ {% endif %} {% endif %} {% endif %} -{% endif %} {% endmacro %} From 087604a1249b204984746d1ee9164cbf2f618a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Thu, 7 Oct 2021 21:41:56 +0300 Subject: [PATCH 4/8] Drop reCAPTCHA v1 from theme 'bootstrap' --- .../bootstrap/html/macro_functions.phtml | 29 ------------------- 1 file changed, 29 deletions(-) diff --git a/src/bb-themes/bootstrap/html/macro_functions.phtml b/src/bb-themes/bootstrap/html/macro_functions.phtml index 9e00f4864..ba1a84302 100755 --- a/src/bb-themes/bootstrap/html/macro_functions.phtml +++ b/src/bb-themes/bootstrap/html/macro_functions.phtml @@ -52,35 +52,6 @@ {% if rc.version == 2 %}
- {% else %} - {% set server = "https://www.google.com/recaptcha/api" %} - - - - - - {% endif %} {% endif %} -{% endif %} {% endmacro %} From cddd0996755e86a58b54d4998860f9aa3e3507c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Thu, 7 Oct 2021 21:42:49 +0300 Subject: [PATCH 5/8] Fix syntax --- .../huraga/html/macro_functions.phtml | 35 ++----------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/src/bb-themes/huraga/html/macro_functions.phtml b/src/bb-themes/huraga/html/macro_functions.phtml index 43ee3bfd3..76ee20710 100644 --- a/src/bb-themes/huraga/html/macro_functions.phtml +++ b/src/bb-themes/huraga/html/macro_functions.phtml @@ -1,5 +1,5 @@ {% macro selectbox(name, options, selected, required, nullOption) %} - {% if nullOption %}{% endif %} {% for val,label in options %} @@ -8,7 +8,7 @@ {% endmacro %} {% macro selectboxtld(name, options, selected, required) %} - {% for data in options %} {% endfor %} @@ -52,36 +52,7 @@ {% if rc.version == 2 %}
- {% else %} - - {% set server = "https://www.google.com/recaptcha/api" %} - - - - - - {% endif %} {% endif %} {% endif %} -{% endmacro %} \ No newline at end of file +{% endmacro %} From 53502a88a0a515f1570074535908f425da7bd4d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Thu, 7 Oct 2021 21:44:49 +0300 Subject: [PATCH 6/8] Drop reCAPTCHA v1 --- src/bb-themes/huraga/html/macro_functions.phtml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bb-themes/huraga/html/macro_functions.phtml b/src/bb-themes/huraga/html/macro_functions.phtml index 76ee20710..d4339adb4 100644 --- a/src/bb-themes/huraga/html/macro_functions.phtml +++ b/src/bb-themes/huraga/html/macro_functions.phtml @@ -1,5 +1,5 @@ {% macro selectbox(name, options, selected, required, nullOption) %} - {% if nullOption %}{% endif %} {% for val,label in options %} @@ -8,7 +8,7 @@ {% endmacro %} {% macro selectboxtld(name, options, selected, required) %} - {% for data in options %} {% endfor %} From 237b84cd27e6cfc35a54601e254b068703fd84c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Thu, 7 Oct 2021 21:45:17 +0300 Subject: [PATCH 7/8] Fix syntax --- src/bb-themes/bootstrap/html/macro_functions.phtml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bb-themes/bootstrap/html/macro_functions.phtml b/src/bb-themes/bootstrap/html/macro_functions.phtml index ba1a84302..76ee20710 100755 --- a/src/bb-themes/bootstrap/html/macro_functions.phtml +++ b/src/bb-themes/bootstrap/html/macro_functions.phtml @@ -54,4 +54,5 @@
{% endif %} {% endif %} +{% endif %} {% endmacro %} From 58d07d9cbc5e2719df9aa255bd12ef5007b492d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Thu, 7 Oct 2021 22:05:16 +0300 Subject: [PATCH 8/8] Making instructions more clear --- src/bb-modules/Spamchecker/Service.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bb-modules/Spamchecker/Service.php b/src/bb-modules/Spamchecker/Service.php index ffd4f50a3..136ab0776 100644 --- a/src/bb-modules/Spamchecker/Service.php +++ b/src/bb-modules/Spamchecker/Service.php @@ -148,11 +148,11 @@ class Service implements InjectionAwareInterface if (isset($config['captcha_version']) && $config['captcha_version'] == 2) { if (!isset($config['captcha_recaptcha_privatekey']) || $config['captcha_recaptcha_privatekey'] == '') { - throw new \Box_Exception("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create"); + throw new \Box_Exception("To use reCAPTCHA you must get an API key from here"); } if (!isset($params['g-recaptcha-response']) || $params['g-recaptcha-response'] == '') { - throw new \Box_Exception("No response received"); + throw new \Box_Exception("You have to complete the CAPTCHA to continue"); } $postData = array( @@ -215,4 +215,4 @@ class Service implements InjectionAwareInterface return false; } -} \ No newline at end of file +}