summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorspiderr <spiderr@bitweaver.org>2025-04-05 23:49:35 -0400
committerspiderr <spiderr@bitweaver.org>2025-04-05 23:49:35 -0400
commite441c2464df951c756d46d8252d14077519f68f0 (patch)
treea72e82d115bac09c19e43ac4d67a3615e253ec78 /includes
parent26851a0d171c1d30c01330df9670e2b0949c9499 (diff)
downloadusers-e441c2464df951c756d46d8252d14077519f68f0.tar.gz
users-e441c2464df951c756d46d8252d14077519f68f0.tar.bz2
users-e441c2464df951c756d46d8252d14077519f68f0.zip
remove Solve Media smcaptcha (not defunct) and implement Cloudflare Turnstile groundwork
Diffstat (limited to 'includes')
-rw-r--r--includes/classes/CloudflareTurnstile.php73
-rw-r--r--includes/classes/RoleUser.php6
2 files changed, 76 insertions, 3 deletions
diff --git a/includes/classes/CloudflareTurnstile.php b/includes/classes/CloudflareTurnstile.php
new file mode 100644
index 0000000..06f4e1a
--- /dev/null
+++ b/includes/classes/CloudflareTurnstile.php
@@ -0,0 +1,73 @@
+<?php
+
+class CloudflareTurnstileValidator {
+ private $secretKey;
+ private $verifyUrl = 'https://challenges.cloudflare.com/turnstile/v0/siteverify';
+
+ public function __construct($secretKey) {
+ $this->secretKey = $secretKey;
+ }
+
+ public function validate($responseToken, $remoteIp = null) {
+ // Prepare POST data
+ $data = [
+ 'secret' => $this->secretKey,
+ 'response' => $responseToken
+ ];
+
+ if ($remoteIp) {
+ $data['remoteip'] = $remoteIp;
+ }
+
+ // Initialize cURL
+ $ch = curl_init($this->verifyUrl);
+ curl_setopt($ch, CURLOPT_POST, true);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_TIMEOUT, 10);
+
+ // Execute request
+ $response = curl_exec($ch);
+ $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+
+ curl_close($ch);
+
+ // Check if request was successful
+ if ($httpCode !== 200) {
+ return [
+ 'success' => false,
+ 'error' => 'Failed to connect to verification server'
+ ];
+ }
+
+ // Decode JSON response
+ $result = json_decode($response, true);
+
+ if (!$result) {
+ return [
+ 'success' => false,
+ 'error' => 'Invalid response from verification server'
+ ];
+ }
+
+ // Return validation result
+ return [
+ 'success' => $result['success'],
+ 'timestamp' => $result['challenge_ts'] ?? null,
+ 'hostname' => $result['hostname'] ?? null,
+ 'error_codes' => $result['error-codes'] ?? []
+ ];
+ }
+}
+
+// Example usage:
+/*
+$validator = new TurnstileValidator('YOUR_SECRET_KEY_HERE');
+$result = $validator->validate($_POST['cf-turnstile-response'], $_SERVER['REMOTE_ADDR']);
+
+if ($result['success']) {
+ echo "Verification successful!";
+} else {
+ echo "Verification failed: " . implode(', ', $result['error_codes']);
+}
+*/
diff --git a/includes/classes/RoleUser.php b/includes/classes/RoleUser.php
index 7e9c496..d4efc66 100644
--- a/includes/classes/RoleUser.php
+++ b/includes/classes/RoleUser.php
@@ -414,15 +414,15 @@ class BitUser extends LibertyMime {
}
}
- if( $gBitSystem->isFeatureActive( 'users_register_smcaptcha' ) && (empty( $pParamHash['novalidation'] ) || $pParamHash['novalidation'] != 'yes') ) {
+ if( $gBitSystem->isFeatureActive( 'users_register_cfcaptcha' ) && (empty( $pParamHash['novalidation'] ) || $pParamHash['novalidation'] != 'yes') ) {
require_once( USERS_PKG_INCLUDE_PATH.'solvemedialib.php' );
if( !empty( $pParamHash['adcopy_challenge'] ) && !empty( $pParamHash['adcopy_response'] ) ) {
$solvemediaResponse = solvemedia_check_answer($gBitSystem->getConfig( 'users_register_smcaptcha_v_key' ), $_SERVER["REMOTE_ADDR"], $pParamHash["adcopy_challenge"], $pParamHash["adcopy_response"], $gBitSystem->getConfig( 'users_register_smcaptcha_h_key' ) );
if( !$solvemediaResponse->is_valid ) {
- $this->mErrors['smcaptcha'] = $solvemediaResponse->error;
+ $this->mErrors['cfcaptcha'] = $solvemediaResponse->error;
}
} else {
- $this->mErrors['smcaptcha'] = 'Wrong Answer';
+ $this->mErrors['cfcaptcha'] = 'Wrong Answer';
}
}