<?php
 class vB_HumanVerify_Turnstile extends vB_HumanVerify { public function verify_token($input, $action) { if (!empty($input['cfturnstile-response'])) { $options = vB::getDatastore()->getValue('options'); $vurl = vB::getUrlLoader(); $url = 'https://challenges.cloudflare.com/turnstile/v0/siteverify'; $query = [ 'secret' => $options['hv_turnstile_secretkey'], 'remoteip' => vB::getRequest()->getIpAddress(), 'response' => $input['cfturnstile-response'], ]; $result = $vurl->post($url, $query); if ($result === false) { $this->error = 'humanverify_remoteverify_unreachable'; return false; } else { $result = json_decode($result['body'], true); if ($result['success'] !== true) { switch ($result['error-codes'][0]) { case 'missing-input-secret': case 'invalid-input-secret': $this->error = 'humanverify_remoteverify_privatekey'; break; case 'timeout-or-duplicate': $this->error = 'humanverify_remoteverify_expired'; break; case 'invalid-input-response': $this->error = 'humanverify_remoteverify_failure'; break; case 'missing-input-response': case 'bad-request': case 'internal-error': default: $this->error = 'humanverify_remoteverify_parameters'; break; } return false; } if (trim($action) != trim($result['action'])) { $this->error = 'humanverify_remoteverify_failure'; return false; } return true; } } else { $this->error = 'humanverify_remoteverify_parameters'; return false; } } } 