PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.5.4
JetFormBuilder — Dynamic Blocks Form Builder v3.5.4
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / captcha / turnstile / verify-token-action.php
jetformbuilder / modules / captcha / turnstile Last commit date
turnstile.php 1 year ago verify-token-action.php 1 year ago
verify-token-action.php
104 lines
1 <?php
2
3
4 namespace JFB_Modules\Captcha\Turnstile;
5
6 // If this file is called directly, abort.
7 if ( ! defined( 'WPINC' ) ) {
8 die;
9 }
10
11 use Jet_Form_Builder\Classes\Http\Http_Tools;
12 use Jet_Form_Builder\Exceptions\Gateway_Exception;
13 use JFB_Modules\Gateways\Actions_Abstract\Action_Application_Raw_Body_It;
14 use JFB_Modules\Gateways\Base_Gateway_Action;
15 use JFB_Modules\Captcha\Module;
16
17 class Verify_Token_Action extends Base_Gateway_Action implements
18 Action_Application_Raw_Body_It {
19
20 private $secret;
21 private $challenge;
22 private $ip;
23 private $action;
24
25 public function action_endpoint() {
26 return 'siteverify';
27 }
28
29 public function base_url(): string {
30 return 'https://challenges.cloudflare.com/turnstile/v0/';
31 }
32
33 public function send_request() {
34 $response = parent::send_request();
35
36 $action = $response['action'] ?? '';
37
38 if ( $this->action === $action && ! empty( $response['success'] ) ) {
39 return $response;
40 }
41
42 // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
43 throw new Gateway_Exception( Module::SPAM_EXCEPTION, $response, $this->get_request_args() );
44 }
45
46 /**
47 * @throws Gateway_Exception
48 */
49 public function before_make_request() {
50 if ( ! $this->ip ) {
51 $this->set_ip( Http_Tools::get_ip_address() );
52 }
53
54 if ( ! $this->action ) {
55 $this->set_action( jet_fb_live()->form_id );
56 }
57
58 if ( $this->ip && $this->secret && $this->challenge ) {
59 return;
60 }
61
62 // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
63 throw new Gateway_Exception( Module::SPAM_EXCEPTION, 'Empty solution. Spammer detected' );
64 }
65
66 public function set_secret( string $secret ): Verify_Token_Action {
67 $this->secret = $secret;
68
69 return $this;
70 }
71
72 public function set_challenge( string $challenge ): Verify_Token_Action {
73 $this->challenge = $challenge;
74
75 return $this;
76 }
77
78 public function set_ip( string $ip ): Verify_Token_Action {
79 $this->ip = $ip;
80
81 return $this;
82 }
83
84 /**
85 * @param string|int $action
86 *
87 * @return Verify_Token_Action
88 */
89 public function set_action( $action ): Verify_Token_Action {
90 $this->action = is_numeric( $action ) ? Module::PREFIX . $action : $action;
91
92 return $this;
93 }
94
95 public function action_body() {
96 return array(
97 'secret' => $this->secret,
98 'response' => $this->challenge,
99 'remoteip' => $this->ip,
100 );
101 }
102
103 }
104