@@ -16,515 +16,515 @@ |
||
16 | 16 | class EE_Encryption |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * key used for saving the encryption key to the wp_options table |
|
21 | - */ |
|
22 | - const ENCRYPTION_OPTION_KEY = 'ee_encryption_key'; |
|
23 | - |
|
24 | - /** |
|
25 | - * the OPENSSL cipher method used |
|
26 | - */ |
|
27 | - const OPENSSL_CIPHER_METHOD = 'aes-256-ctr'; |
|
28 | - |
|
29 | - /** |
|
30 | - * the OPENSSL digest method used |
|
31 | - */ |
|
32 | - const OPENSSL_DIGEST_METHOD = 'sha512'; |
|
33 | - |
|
34 | - /** |
|
35 | - * separates the encrypted text from the initialization vector |
|
36 | - */ |
|
37 | - const OPENSSL_IV_DELIMITER = ':iv:'; |
|
38 | - |
|
39 | - /** |
|
40 | - * appended to text encrypted using the acme encryption |
|
41 | - */ |
|
42 | - const ACME_ENCRYPTION_FLAG = '::ae'; |
|
43 | - |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * instance of the EE_Encryption object |
|
48 | - */ |
|
49 | - protected static $_instance; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var string $_encryption_key |
|
53 | - */ |
|
54 | - protected $_encryption_key; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var boolean $_use_openssl_encrypt |
|
58 | - */ |
|
59 | - protected $_use_openssl_encrypt = false; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var boolean $_use_mcrypt |
|
63 | - */ |
|
64 | - protected $_use_mcrypt = false; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var boolean $_use_base64_encode |
|
68 | - */ |
|
69 | - protected $_use_base64_encode = false; |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * protected constructor to prevent direct creation |
|
75 | - */ |
|
76 | - protected function __construct() |
|
77 | - { |
|
78 | - if (! defined('ESPRESSO_ENCRYPT')) { |
|
79 | - define('ESPRESSO_ENCRYPT', true); |
|
80 | - } |
|
81 | - if (extension_loaded('openssl')) { |
|
82 | - $this->_use_openssl_encrypt = true; |
|
83 | - } else if (extension_loaded('mcrypt')) { |
|
84 | - $this->_use_mcrypt = true; |
|
85 | - } |
|
86 | - if (function_exists('base64_encode')) { |
|
87 | - $this->_use_base64_encode = true; |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * singleton method used to instantiate class object |
|
95 | - * |
|
96 | - * @return EE_Encryption |
|
97 | - */ |
|
98 | - public static function instance() |
|
99 | - { |
|
100 | - // check if class object is instantiated |
|
101 | - if (! self::$_instance instanceof EE_Encryption) { |
|
102 | - self::$_instance = new self(); |
|
103 | - } |
|
104 | - return self::$_instance; |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * get encryption key |
|
111 | - * |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public function get_encryption_key() |
|
115 | - { |
|
116 | - // if encryption key has not been set |
|
117 | - if (empty($this->_encryption_key)) { |
|
118 | - // retrieve encryption_key from db |
|
119 | - $this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, ''); |
|
120 | - // WHAT?? No encryption_key in the db ?? |
|
121 | - if ($this->_encryption_key === '') { |
|
122 | - // let's make one. And md5 it to make it just the right size for a key |
|
123 | - $new_key = md5($this->generate_random_string()); |
|
124 | - // now save it to the db for later |
|
125 | - add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key); |
|
126 | - // here's the key - FINALLY ! |
|
127 | - $this->_encryption_key = $new_key; |
|
128 | - } |
|
129 | - } |
|
130 | - return $this->_encryption_key; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * encrypts data |
|
137 | - * |
|
138 | - * @param string $text_string - the text to be encrypted |
|
139 | - * @return string |
|
140 | - * @throws RuntimeException |
|
141 | - */ |
|
142 | - public function encrypt($text_string = '') |
|
143 | - { |
|
144 | - // you give me nothing??? GET OUT ! |
|
145 | - if (empty($text_string)) { |
|
146 | - return $text_string; |
|
147 | - } |
|
148 | - if ($this->_use_openssl_encrypt) { |
|
149 | - $encrypted_text = $this->openssl_encrypt($text_string); |
|
150 | - } else { |
|
151 | - $encrypted_text = $this->acme_encrypt($text_string); |
|
152 | - } |
|
153 | - return $encrypted_text; |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * decrypts data |
|
160 | - * |
|
161 | - * @param string $encrypted_text - the text to be decrypted |
|
162 | - * @return string |
|
163 | - * @throws RuntimeException |
|
164 | - */ |
|
165 | - public function decrypt($encrypted_text = '') |
|
166 | - { |
|
167 | - // you give me nothing??? GET OUT ! |
|
168 | - if (empty($encrypted_text)) { |
|
169 | - return $encrypted_text; |
|
170 | - } |
|
171 | - // if PHP's mcrypt functions are installed then we'll use them |
|
172 | - if ($this->_use_openssl_encrypt) { |
|
173 | - $decrypted_text = $this->openssl_decrypt($encrypted_text); |
|
174 | - } else { |
|
175 | - $decrypted_text = $this->acme_decrypt($encrypted_text); |
|
176 | - } |
|
177 | - return $decrypted_text; |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * encodes string with PHP's base64 encoding |
|
184 | - * |
|
185 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
186 | - * @param string $text_string the text to be encoded |
|
187 | - * @return string |
|
188 | - */ |
|
189 | - public function base64_string_encode($text_string = '') |
|
190 | - { |
|
191 | - // you give me nothing??? GET OUT ! |
|
192 | - if (empty($text_string) || ! $this->_use_base64_encode) { |
|
193 | - return $text_string; |
|
194 | - } |
|
195 | - // encode |
|
196 | - return base64_encode($text_string); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * decodes string that has been encoded with PHP's base64 encoding |
|
203 | - * |
|
204 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
205 | - * @param string $encoded_string the text to be decoded |
|
206 | - * @return string |
|
207 | - */ |
|
208 | - public function base64_string_decode($encoded_string = '') |
|
209 | - { |
|
210 | - // you give me nothing??? GET OUT ! |
|
211 | - if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
212 | - return $encoded_string; |
|
213 | - } |
|
214 | - // decode |
|
215 | - return base64_decode($encoded_string); |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * encodes url string with PHP's base64 encoding |
|
222 | - * |
|
223 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
224 | - * @param string $text_string the text to be encoded |
|
225 | - * @return string |
|
226 | - */ |
|
227 | - public function base64_url_encode($text_string = '') |
|
228 | - { |
|
229 | - // you give me nothing??? GET OUT ! |
|
230 | - if (empty($text_string) || ! $this->_use_base64_encode) { |
|
231 | - return $text_string; |
|
232 | - } |
|
233 | - // encode |
|
234 | - $encoded_string = base64_encode($text_string); |
|
235 | - // remove chars to make encoding more URL friendly |
|
236 | - return strtr($encoded_string, '+/=', '-_,'); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * decodes url string that has been encoded with PHP's base64 encoding |
|
243 | - * |
|
244 | - * @see http://php.net/manual/en/function.base64-encode.php |
|
245 | - * @param string $encoded_string the text to be decoded |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - public function base64_url_decode($encoded_string = '') |
|
249 | - { |
|
250 | - // you give me nothing??? GET OUT ! |
|
251 | - if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
252 | - return $encoded_string; |
|
253 | - } |
|
254 | - // replace previously removed characters |
|
255 | - $encoded_string = strtr($encoded_string, '-_,', '+/='); |
|
256 | - // decode |
|
257 | - return base64_decode($encoded_string); |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * encrypts data using PHP's openssl functions |
|
264 | - * |
|
265 | - * @param string $text_string the text to be encrypted |
|
266 | - * @return string |
|
267 | - * @throws RuntimeException |
|
268 | - */ |
|
269 | - protected function openssl_encrypt($text_string = '') |
|
270 | - { |
|
271 | - // you give me nothing??? GET OUT ! |
|
272 | - if (empty($text_string)) { |
|
273 | - return $text_string; |
|
274 | - } |
|
275 | - // get initialization vector size |
|
276 | - $iv_size = openssl_cipher_iv_length(EE_Encryption::OPENSSL_CIPHER_METHOD); |
|
277 | - // generate initialization vector |
|
278 | - $iv = openssl_random_pseudo_bytes($iv_size, $is_strong); |
|
279 | - if ($iv === false || $is_strong === false) { |
|
280 | - throw new RuntimeException( |
|
281 | - esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso') |
|
282 | - ); |
|
283 | - } |
|
284 | - // encrypt it |
|
285 | - $encrypted_text = openssl_encrypt( |
|
286 | - $text_string, |
|
287 | - EE_Encryption::OPENSSL_CIPHER_METHOD, |
|
288 | - openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD), |
|
289 | - 0, |
|
290 | - $iv |
|
291 | - ); |
|
292 | - // append the initialization vector |
|
293 | - $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv; |
|
294 | - // trim and maybe encode |
|
295 | - return $this->_use_base64_encode |
|
296 | - ? trim(base64_encode($encrypted_text)) |
|
297 | - : trim($encrypted_text); |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * decrypts data that has been encrypted with PHP's openssl functions |
|
304 | - * |
|
305 | - * @param string $encrypted_text the text to be decrypted |
|
306 | - * @return string |
|
307 | - * @throws RuntimeException |
|
308 | - */ |
|
309 | - protected function openssl_decrypt($encrypted_text = '') |
|
310 | - { |
|
311 | - // you give me nothing??? GET OUT ! |
|
312 | - if (empty($encrypted_text)) { |
|
313 | - return $encrypted_text; |
|
314 | - } |
|
315 | - // decode |
|
316 | - $encrypted_text = $this->valid_base_64($encrypted_text) |
|
317 | - ? base64_decode($encrypted_text) |
|
318 | - : $encrypted_text; |
|
319 | - $encrypted_components = explode( |
|
320 | - EE_Encryption::OPENSSL_IV_DELIMITER, |
|
321 | - $encrypted_text, |
|
322 | - 2 |
|
323 | - ); |
|
324 | - // check that iv exists, and if not, maybe text was encoded using mcrypt? |
|
325 | - if (! isset($encrypted_components[1]) && $this->_use_mcrypt) { |
|
326 | - return $this->m_decrypt($encrypted_text); |
|
327 | - } |
|
328 | - // decrypt it |
|
329 | - $decrypted_text = openssl_decrypt( |
|
330 | - $encrypted_components[0], |
|
331 | - EE_Encryption::OPENSSL_CIPHER_METHOD, |
|
332 | - openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD), |
|
333 | - 0, |
|
334 | - $encrypted_components[1] |
|
335 | - ); |
|
336 | - $decrypted_text = trim($decrypted_text); |
|
337 | - return $decrypted_text; |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * encrypts data for acme servers that didn't bother to install PHP mcrypt |
|
344 | - * |
|
345 | - * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
346 | - * @param string $text_string the text to be decrypted |
|
347 | - * @return string |
|
348 | - */ |
|
349 | - protected function acme_encrypt($text_string = '') |
|
350 | - { |
|
351 | - // you give me nothing??? GET OUT ! |
|
352 | - if (empty($text_string)) { |
|
353 | - return $text_string; |
|
354 | - } |
|
355 | - $key_bits = str_split( |
|
356 | - str_pad('', strlen($text_string), $this->get_encryption_key(), STR_PAD_RIGHT) |
|
357 | - ); |
|
358 | - $string_bits = str_split($text_string); |
|
359 | - foreach ($string_bits as $k => $v) { |
|
360 | - $temp = ord($v) + ord($key_bits[$k]); |
|
361 | - $string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp); |
|
362 | - } |
|
363 | - $encrypted_text = implode('', $string_bits); |
|
364 | - $encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG; |
|
365 | - return $this->_use_base64_encode |
|
366 | - ? base64_encode($encrypted_text) |
|
367 | - : $encrypted_text; |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * decrypts data for acme servers that didn't bother to install PHP mcrypt |
|
374 | - * |
|
375 | - * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
376 | - * @param string $encrypted_text the text to be decrypted |
|
377 | - * @return string |
|
378 | - */ |
|
379 | - protected function acme_decrypt($encrypted_text = '') |
|
380 | - { |
|
381 | - // you give me nothing??? GET OUT ! |
|
382 | - if (empty($encrypted_text)) { |
|
383 | - return $encrypted_text; |
|
384 | - } |
|
385 | - // decode the data ? |
|
386 | - $encrypted_text = $this->valid_base_64($encrypted_text) |
|
387 | - ? base64_decode($encrypted_text) |
|
388 | - : $encrypted_text; |
|
389 | - if (strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false && $this->_use_mcrypt) { |
|
390 | - return $this->m_decrypt($encrypted_text); |
|
391 | - } |
|
392 | - $key_bits = str_split( |
|
393 | - str_pad('', strlen($encrypted_text), $this->get_encryption_key(), STR_PAD_RIGHT) |
|
394 | - ); |
|
395 | - $string_bits = str_split($encrypted_text); |
|
396 | - foreach ($string_bits as $k => $v) { |
|
397 | - $temp = ord($v) - ord($key_bits[$k]); |
|
398 | - $string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp); |
|
399 | - } |
|
400 | - return implode('', $string_bits); |
|
401 | - } |
|
402 | - |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906 |
|
407 | - * @param $string |
|
408 | - * @return bool |
|
409 | - */ |
|
410 | - protected function valid_base_64($string) |
|
411 | - { |
|
412 | - // ensure data is a string |
|
413 | - if (! is_string($string) || ! $this->_use_base64_encode) { |
|
414 | - return false; |
|
415 | - } |
|
416 | - $decoded = base64_decode($string, true); |
|
417 | - // Check if there is no invalid character in string |
|
418 | - if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
419 | - return false; |
|
420 | - } |
|
421 | - // Decode the string in strict mode and send the response |
|
422 | - if (! base64_decode($string, true)) { |
|
423 | - return false; |
|
424 | - } |
|
425 | - // Encode and compare it to original one |
|
426 | - return base64_encode($decoded) === $string; |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * generate random string |
|
433 | - * |
|
434 | - * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php |
|
435 | - * @param int $length number of characters for random string |
|
436 | - * @return string |
|
437 | - */ |
|
438 | - public function generate_random_string($length = 40) |
|
439 | - { |
|
440 | - $iterations = ceil($length / 40); |
|
441 | - $random_string = ''; |
|
442 | - for ($i = 0; $i < $iterations; $i++) { |
|
443 | - $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
444 | - } |
|
445 | - $random_string = substr($random_string, 0, $length); |
|
446 | - return $random_string; |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * encrypts data using PHP's mcrypt functions |
|
453 | - * |
|
454 | - * @deprecated 4.9.39 |
|
455 | - * @param string $text_string |
|
456 | - * @internal param $string - the text to be encrypted |
|
457 | - * @return string |
|
458 | - * @throws RuntimeException |
|
459 | - */ |
|
460 | - protected function m_encrypt($text_string = '') |
|
461 | - { |
|
462 | - // you give me nothing??? GET OUT ! |
|
463 | - if (empty($text_string)) { |
|
464 | - return $text_string; |
|
465 | - } |
|
466 | - // get the initialization vector size |
|
467 | - $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
468 | - // initialization vector |
|
469 | - $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
470 | - if ($iv === false) { |
|
471 | - throw new RuntimeException( |
|
472 | - esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso') |
|
473 | - ); |
|
474 | - } |
|
475 | - // encrypt it |
|
476 | - $encrypted_text = mcrypt_encrypt( |
|
477 | - MCRYPT_RIJNDAEL_256, |
|
478 | - $this->get_encryption_key(), |
|
479 | - $text_string, |
|
480 | - MCRYPT_MODE_ECB, |
|
481 | - $iv |
|
482 | - ); |
|
483 | - // trim and maybe encode |
|
484 | - return $this->_use_base64_encode |
|
485 | - ? trim(base64_encode($encrypted_text)) |
|
486 | - : trim($encrypted_text); |
|
487 | - } |
|
488 | - |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * decrypts data that has been encrypted with PHP's mcrypt functions |
|
493 | - * |
|
494 | - * @deprecated 4.9.39 |
|
495 | - * @param string $encrypted_text the text to be decrypted |
|
496 | - * @return string |
|
497 | - * @throws RuntimeException |
|
498 | - */ |
|
499 | - protected function m_decrypt($encrypted_text = '') |
|
500 | - { |
|
501 | - // you give me nothing??? GET OUT ! |
|
502 | - if (empty($encrypted_text)) { |
|
503 | - return $encrypted_text; |
|
504 | - } |
|
505 | - // decode |
|
506 | - $encrypted_text = $this->valid_base_64($encrypted_text) |
|
507 | - ? base64_decode($encrypted_text) |
|
508 | - : $encrypted_text; |
|
509 | - // get the initialization vector size |
|
510 | - $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
511 | - $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
512 | - if ($iv === false) { |
|
513 | - throw new RuntimeException( |
|
514 | - esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso') |
|
515 | - ); |
|
516 | - } |
|
517 | - // decrypt it |
|
518 | - $decrypted_text = mcrypt_decrypt( |
|
519 | - MCRYPT_RIJNDAEL_256, |
|
520 | - $this->get_encryption_key(), |
|
521 | - $encrypted_text, |
|
522 | - MCRYPT_MODE_ECB, |
|
523 | - $iv |
|
524 | - ); |
|
525 | - $decrypted_text = trim($decrypted_text); |
|
526 | - return $decrypted_text; |
|
527 | - } |
|
19 | + /** |
|
20 | + * key used for saving the encryption key to the wp_options table |
|
21 | + */ |
|
22 | + const ENCRYPTION_OPTION_KEY = 'ee_encryption_key'; |
|
23 | + |
|
24 | + /** |
|
25 | + * the OPENSSL cipher method used |
|
26 | + */ |
|
27 | + const OPENSSL_CIPHER_METHOD = 'aes-256-ctr'; |
|
28 | + |
|
29 | + /** |
|
30 | + * the OPENSSL digest method used |
|
31 | + */ |
|
32 | + const OPENSSL_DIGEST_METHOD = 'sha512'; |
|
33 | + |
|
34 | + /** |
|
35 | + * separates the encrypted text from the initialization vector |
|
36 | + */ |
|
37 | + const OPENSSL_IV_DELIMITER = ':iv:'; |
|
38 | + |
|
39 | + /** |
|
40 | + * appended to text encrypted using the acme encryption |
|
41 | + */ |
|
42 | + const ACME_ENCRYPTION_FLAG = '::ae'; |
|
43 | + |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * instance of the EE_Encryption object |
|
48 | + */ |
|
49 | + protected static $_instance; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var string $_encryption_key |
|
53 | + */ |
|
54 | + protected $_encryption_key; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var boolean $_use_openssl_encrypt |
|
58 | + */ |
|
59 | + protected $_use_openssl_encrypt = false; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var boolean $_use_mcrypt |
|
63 | + */ |
|
64 | + protected $_use_mcrypt = false; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var boolean $_use_base64_encode |
|
68 | + */ |
|
69 | + protected $_use_base64_encode = false; |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * protected constructor to prevent direct creation |
|
75 | + */ |
|
76 | + protected function __construct() |
|
77 | + { |
|
78 | + if (! defined('ESPRESSO_ENCRYPT')) { |
|
79 | + define('ESPRESSO_ENCRYPT', true); |
|
80 | + } |
|
81 | + if (extension_loaded('openssl')) { |
|
82 | + $this->_use_openssl_encrypt = true; |
|
83 | + } else if (extension_loaded('mcrypt')) { |
|
84 | + $this->_use_mcrypt = true; |
|
85 | + } |
|
86 | + if (function_exists('base64_encode')) { |
|
87 | + $this->_use_base64_encode = true; |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * singleton method used to instantiate class object |
|
95 | + * |
|
96 | + * @return EE_Encryption |
|
97 | + */ |
|
98 | + public static function instance() |
|
99 | + { |
|
100 | + // check if class object is instantiated |
|
101 | + if (! self::$_instance instanceof EE_Encryption) { |
|
102 | + self::$_instance = new self(); |
|
103 | + } |
|
104 | + return self::$_instance; |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * get encryption key |
|
111 | + * |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public function get_encryption_key() |
|
115 | + { |
|
116 | + // if encryption key has not been set |
|
117 | + if (empty($this->_encryption_key)) { |
|
118 | + // retrieve encryption_key from db |
|
119 | + $this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, ''); |
|
120 | + // WHAT?? No encryption_key in the db ?? |
|
121 | + if ($this->_encryption_key === '') { |
|
122 | + // let's make one. And md5 it to make it just the right size for a key |
|
123 | + $new_key = md5($this->generate_random_string()); |
|
124 | + // now save it to the db for later |
|
125 | + add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key); |
|
126 | + // here's the key - FINALLY ! |
|
127 | + $this->_encryption_key = $new_key; |
|
128 | + } |
|
129 | + } |
|
130 | + return $this->_encryption_key; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * encrypts data |
|
137 | + * |
|
138 | + * @param string $text_string - the text to be encrypted |
|
139 | + * @return string |
|
140 | + * @throws RuntimeException |
|
141 | + */ |
|
142 | + public function encrypt($text_string = '') |
|
143 | + { |
|
144 | + // you give me nothing??? GET OUT ! |
|
145 | + if (empty($text_string)) { |
|
146 | + return $text_string; |
|
147 | + } |
|
148 | + if ($this->_use_openssl_encrypt) { |
|
149 | + $encrypted_text = $this->openssl_encrypt($text_string); |
|
150 | + } else { |
|
151 | + $encrypted_text = $this->acme_encrypt($text_string); |
|
152 | + } |
|
153 | + return $encrypted_text; |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * decrypts data |
|
160 | + * |
|
161 | + * @param string $encrypted_text - the text to be decrypted |
|
162 | + * @return string |
|
163 | + * @throws RuntimeException |
|
164 | + */ |
|
165 | + public function decrypt($encrypted_text = '') |
|
166 | + { |
|
167 | + // you give me nothing??? GET OUT ! |
|
168 | + if (empty($encrypted_text)) { |
|
169 | + return $encrypted_text; |
|
170 | + } |
|
171 | + // if PHP's mcrypt functions are installed then we'll use them |
|
172 | + if ($this->_use_openssl_encrypt) { |
|
173 | + $decrypted_text = $this->openssl_decrypt($encrypted_text); |
|
174 | + } else { |
|
175 | + $decrypted_text = $this->acme_decrypt($encrypted_text); |
|
176 | + } |
|
177 | + return $decrypted_text; |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * encodes string with PHP's base64 encoding |
|
184 | + * |
|
185 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
186 | + * @param string $text_string the text to be encoded |
|
187 | + * @return string |
|
188 | + */ |
|
189 | + public function base64_string_encode($text_string = '') |
|
190 | + { |
|
191 | + // you give me nothing??? GET OUT ! |
|
192 | + if (empty($text_string) || ! $this->_use_base64_encode) { |
|
193 | + return $text_string; |
|
194 | + } |
|
195 | + // encode |
|
196 | + return base64_encode($text_string); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * decodes string that has been encoded with PHP's base64 encoding |
|
203 | + * |
|
204 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
205 | + * @param string $encoded_string the text to be decoded |
|
206 | + * @return string |
|
207 | + */ |
|
208 | + public function base64_string_decode($encoded_string = '') |
|
209 | + { |
|
210 | + // you give me nothing??? GET OUT ! |
|
211 | + if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
212 | + return $encoded_string; |
|
213 | + } |
|
214 | + // decode |
|
215 | + return base64_decode($encoded_string); |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * encodes url string with PHP's base64 encoding |
|
222 | + * |
|
223 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
224 | + * @param string $text_string the text to be encoded |
|
225 | + * @return string |
|
226 | + */ |
|
227 | + public function base64_url_encode($text_string = '') |
|
228 | + { |
|
229 | + // you give me nothing??? GET OUT ! |
|
230 | + if (empty($text_string) || ! $this->_use_base64_encode) { |
|
231 | + return $text_string; |
|
232 | + } |
|
233 | + // encode |
|
234 | + $encoded_string = base64_encode($text_string); |
|
235 | + // remove chars to make encoding more URL friendly |
|
236 | + return strtr($encoded_string, '+/=', '-_,'); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * decodes url string that has been encoded with PHP's base64 encoding |
|
243 | + * |
|
244 | + * @see http://php.net/manual/en/function.base64-encode.php |
|
245 | + * @param string $encoded_string the text to be decoded |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + public function base64_url_decode($encoded_string = '') |
|
249 | + { |
|
250 | + // you give me nothing??? GET OUT ! |
|
251 | + if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) { |
|
252 | + return $encoded_string; |
|
253 | + } |
|
254 | + // replace previously removed characters |
|
255 | + $encoded_string = strtr($encoded_string, '-_,', '+/='); |
|
256 | + // decode |
|
257 | + return base64_decode($encoded_string); |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * encrypts data using PHP's openssl functions |
|
264 | + * |
|
265 | + * @param string $text_string the text to be encrypted |
|
266 | + * @return string |
|
267 | + * @throws RuntimeException |
|
268 | + */ |
|
269 | + protected function openssl_encrypt($text_string = '') |
|
270 | + { |
|
271 | + // you give me nothing??? GET OUT ! |
|
272 | + if (empty($text_string)) { |
|
273 | + return $text_string; |
|
274 | + } |
|
275 | + // get initialization vector size |
|
276 | + $iv_size = openssl_cipher_iv_length(EE_Encryption::OPENSSL_CIPHER_METHOD); |
|
277 | + // generate initialization vector |
|
278 | + $iv = openssl_random_pseudo_bytes($iv_size, $is_strong); |
|
279 | + if ($iv === false || $is_strong === false) { |
|
280 | + throw new RuntimeException( |
|
281 | + esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso') |
|
282 | + ); |
|
283 | + } |
|
284 | + // encrypt it |
|
285 | + $encrypted_text = openssl_encrypt( |
|
286 | + $text_string, |
|
287 | + EE_Encryption::OPENSSL_CIPHER_METHOD, |
|
288 | + openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD), |
|
289 | + 0, |
|
290 | + $iv |
|
291 | + ); |
|
292 | + // append the initialization vector |
|
293 | + $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv; |
|
294 | + // trim and maybe encode |
|
295 | + return $this->_use_base64_encode |
|
296 | + ? trim(base64_encode($encrypted_text)) |
|
297 | + : trim($encrypted_text); |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * decrypts data that has been encrypted with PHP's openssl functions |
|
304 | + * |
|
305 | + * @param string $encrypted_text the text to be decrypted |
|
306 | + * @return string |
|
307 | + * @throws RuntimeException |
|
308 | + */ |
|
309 | + protected function openssl_decrypt($encrypted_text = '') |
|
310 | + { |
|
311 | + // you give me nothing??? GET OUT ! |
|
312 | + if (empty($encrypted_text)) { |
|
313 | + return $encrypted_text; |
|
314 | + } |
|
315 | + // decode |
|
316 | + $encrypted_text = $this->valid_base_64($encrypted_text) |
|
317 | + ? base64_decode($encrypted_text) |
|
318 | + : $encrypted_text; |
|
319 | + $encrypted_components = explode( |
|
320 | + EE_Encryption::OPENSSL_IV_DELIMITER, |
|
321 | + $encrypted_text, |
|
322 | + 2 |
|
323 | + ); |
|
324 | + // check that iv exists, and if not, maybe text was encoded using mcrypt? |
|
325 | + if (! isset($encrypted_components[1]) && $this->_use_mcrypt) { |
|
326 | + return $this->m_decrypt($encrypted_text); |
|
327 | + } |
|
328 | + // decrypt it |
|
329 | + $decrypted_text = openssl_decrypt( |
|
330 | + $encrypted_components[0], |
|
331 | + EE_Encryption::OPENSSL_CIPHER_METHOD, |
|
332 | + openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD), |
|
333 | + 0, |
|
334 | + $encrypted_components[1] |
|
335 | + ); |
|
336 | + $decrypted_text = trim($decrypted_text); |
|
337 | + return $decrypted_text; |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * encrypts data for acme servers that didn't bother to install PHP mcrypt |
|
344 | + * |
|
345 | + * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
346 | + * @param string $text_string the text to be decrypted |
|
347 | + * @return string |
|
348 | + */ |
|
349 | + protected function acme_encrypt($text_string = '') |
|
350 | + { |
|
351 | + // you give me nothing??? GET OUT ! |
|
352 | + if (empty($text_string)) { |
|
353 | + return $text_string; |
|
354 | + } |
|
355 | + $key_bits = str_split( |
|
356 | + str_pad('', strlen($text_string), $this->get_encryption_key(), STR_PAD_RIGHT) |
|
357 | + ); |
|
358 | + $string_bits = str_split($text_string); |
|
359 | + foreach ($string_bits as $k => $v) { |
|
360 | + $temp = ord($v) + ord($key_bits[$k]); |
|
361 | + $string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp); |
|
362 | + } |
|
363 | + $encrypted_text = implode('', $string_bits); |
|
364 | + $encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG; |
|
365 | + return $this->_use_base64_encode |
|
366 | + ? base64_encode($encrypted_text) |
|
367 | + : $encrypted_text; |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * decrypts data for acme servers that didn't bother to install PHP mcrypt |
|
374 | + * |
|
375 | + * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php |
|
376 | + * @param string $encrypted_text the text to be decrypted |
|
377 | + * @return string |
|
378 | + */ |
|
379 | + protected function acme_decrypt($encrypted_text = '') |
|
380 | + { |
|
381 | + // you give me nothing??? GET OUT ! |
|
382 | + if (empty($encrypted_text)) { |
|
383 | + return $encrypted_text; |
|
384 | + } |
|
385 | + // decode the data ? |
|
386 | + $encrypted_text = $this->valid_base_64($encrypted_text) |
|
387 | + ? base64_decode($encrypted_text) |
|
388 | + : $encrypted_text; |
|
389 | + if (strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false && $this->_use_mcrypt) { |
|
390 | + return $this->m_decrypt($encrypted_text); |
|
391 | + } |
|
392 | + $key_bits = str_split( |
|
393 | + str_pad('', strlen($encrypted_text), $this->get_encryption_key(), STR_PAD_RIGHT) |
|
394 | + ); |
|
395 | + $string_bits = str_split($encrypted_text); |
|
396 | + foreach ($string_bits as $k => $v) { |
|
397 | + $temp = ord($v) - ord($key_bits[$k]); |
|
398 | + $string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp); |
|
399 | + } |
|
400 | + return implode('', $string_bits); |
|
401 | + } |
|
402 | + |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906 |
|
407 | + * @param $string |
|
408 | + * @return bool |
|
409 | + */ |
|
410 | + protected function valid_base_64($string) |
|
411 | + { |
|
412 | + // ensure data is a string |
|
413 | + if (! is_string($string) || ! $this->_use_base64_encode) { |
|
414 | + return false; |
|
415 | + } |
|
416 | + $decoded = base64_decode($string, true); |
|
417 | + // Check if there is no invalid character in string |
|
418 | + if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) { |
|
419 | + return false; |
|
420 | + } |
|
421 | + // Decode the string in strict mode and send the response |
|
422 | + if (! base64_decode($string, true)) { |
|
423 | + return false; |
|
424 | + } |
|
425 | + // Encode and compare it to original one |
|
426 | + return base64_encode($decoded) === $string; |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * generate random string |
|
433 | + * |
|
434 | + * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php |
|
435 | + * @param int $length number of characters for random string |
|
436 | + * @return string |
|
437 | + */ |
|
438 | + public function generate_random_string($length = 40) |
|
439 | + { |
|
440 | + $iterations = ceil($length / 40); |
|
441 | + $random_string = ''; |
|
442 | + for ($i = 0; $i < $iterations; $i++) { |
|
443 | + $random_string .= sha1(microtime(true) . mt_rand(10000, 90000)); |
|
444 | + } |
|
445 | + $random_string = substr($random_string, 0, $length); |
|
446 | + return $random_string; |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * encrypts data using PHP's mcrypt functions |
|
453 | + * |
|
454 | + * @deprecated 4.9.39 |
|
455 | + * @param string $text_string |
|
456 | + * @internal param $string - the text to be encrypted |
|
457 | + * @return string |
|
458 | + * @throws RuntimeException |
|
459 | + */ |
|
460 | + protected function m_encrypt($text_string = '') |
|
461 | + { |
|
462 | + // you give me nothing??? GET OUT ! |
|
463 | + if (empty($text_string)) { |
|
464 | + return $text_string; |
|
465 | + } |
|
466 | + // get the initialization vector size |
|
467 | + $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
468 | + // initialization vector |
|
469 | + $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
470 | + if ($iv === false) { |
|
471 | + throw new RuntimeException( |
|
472 | + esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso') |
|
473 | + ); |
|
474 | + } |
|
475 | + // encrypt it |
|
476 | + $encrypted_text = mcrypt_encrypt( |
|
477 | + MCRYPT_RIJNDAEL_256, |
|
478 | + $this->get_encryption_key(), |
|
479 | + $text_string, |
|
480 | + MCRYPT_MODE_ECB, |
|
481 | + $iv |
|
482 | + ); |
|
483 | + // trim and maybe encode |
|
484 | + return $this->_use_base64_encode |
|
485 | + ? trim(base64_encode($encrypted_text)) |
|
486 | + : trim($encrypted_text); |
|
487 | + } |
|
488 | + |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * decrypts data that has been encrypted with PHP's mcrypt functions |
|
493 | + * |
|
494 | + * @deprecated 4.9.39 |
|
495 | + * @param string $encrypted_text the text to be decrypted |
|
496 | + * @return string |
|
497 | + * @throws RuntimeException |
|
498 | + */ |
|
499 | + protected function m_decrypt($encrypted_text = '') |
|
500 | + { |
|
501 | + // you give me nothing??? GET OUT ! |
|
502 | + if (empty($encrypted_text)) { |
|
503 | + return $encrypted_text; |
|
504 | + } |
|
505 | + // decode |
|
506 | + $encrypted_text = $this->valid_base_64($encrypted_text) |
|
507 | + ? base64_decode($encrypted_text) |
|
508 | + : $encrypted_text; |
|
509 | + // get the initialization vector size |
|
510 | + $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
|
511 | + $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); |
|
512 | + if ($iv === false) { |
|
513 | + throw new RuntimeException( |
|
514 | + esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso') |
|
515 | + ); |
|
516 | + } |
|
517 | + // decrypt it |
|
518 | + $decrypted_text = mcrypt_decrypt( |
|
519 | + MCRYPT_RIJNDAEL_256, |
|
520 | + $this->get_encryption_key(), |
|
521 | + $encrypted_text, |
|
522 | + MCRYPT_MODE_ECB, |
|
523 | + $iv |
|
524 | + ); |
|
525 | + $decrypted_text = trim($decrypted_text); |
|
526 | + return $decrypted_text; |
|
527 | + } |
|
528 | 528 | |
529 | 529 | } |
530 | 530 | /* End of file EE_Encryption.class.php */ |
@@ -17,323 +17,323 @@ |
||
17 | 17 | { |
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * @return EED_Bot_Trap|EED_Module |
|
22 | - */ |
|
23 | - public static function instance() |
|
24 | - { |
|
25 | - return parent::get_instance(__CLASS__); |
|
26 | - } |
|
20 | + /** |
|
21 | + * @return EED_Bot_Trap|EED_Module |
|
22 | + */ |
|
23 | + public static function instance() |
|
24 | + { |
|
25 | + return parent::get_instance(__CLASS__); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
31 | - * |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public static function set_hooks() |
|
35 | - { |
|
36 | - if ( |
|
37 | - apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) && |
|
38 | - \EE_Registry::instance()->CFG->registration->use_bot_trap |
|
39 | - ) { |
|
40 | - \EED_Bot_Trap::set_trap(); |
|
41 | - // redirect bots to bogus success page |
|
42 | - \EE_Config::register_route('ticket_selection_received', 'EED_Bot_Trap', 'display_bot_trap_success'); |
|
43 | - } |
|
44 | - } |
|
29 | + /** |
|
30 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
31 | + * |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public static function set_hooks() |
|
35 | + { |
|
36 | + if ( |
|
37 | + apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) && |
|
38 | + \EE_Registry::instance()->CFG->registration->use_bot_trap |
|
39 | + ) { |
|
40 | + \EED_Bot_Trap::set_trap(); |
|
41 | + // redirect bots to bogus success page |
|
42 | + \EE_Config::register_route('ticket_selection_received', 'EED_Bot_Trap', 'display_bot_trap_success'); |
|
43 | + } |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
49 | - * |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - public static function set_trap() |
|
53 | - { |
|
54 | - define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__) . DS); |
|
55 | - add_action( |
|
56 | - 'AHEE__ticket_selector_chart__template__after_ticket_selector', |
|
57 | - array('EED_Bot_Trap', 'generate_bot_trap'), |
|
58 | - 10, 2 |
|
59 | - ); |
|
60 | - add_action( |
|
61 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
62 | - array('EED_Bot_Trap', 'process_bot_trap'), |
|
63 | - 1, 2 |
|
64 | - ); |
|
65 | - } |
|
47 | + /** |
|
48 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
49 | + * |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + public static function set_trap() |
|
53 | + { |
|
54 | + define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__) . DS); |
|
55 | + add_action( |
|
56 | + 'AHEE__ticket_selector_chart__template__after_ticket_selector', |
|
57 | + array('EED_Bot_Trap', 'generate_bot_trap'), |
|
58 | + 10, 2 |
|
59 | + ); |
|
60 | + add_action( |
|
61 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
62 | + array('EED_Bot_Trap', 'process_bot_trap'), |
|
63 | + 1, 2 |
|
64 | + ); |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
70 | - * |
|
71 | - * @return void |
|
72 | - */ |
|
73 | - public static function set_hooks_admin() |
|
74 | - { |
|
75 | - if ( |
|
76 | - defined('DOING_AJAX') |
|
77 | - && DOING_AJAX |
|
78 | - && apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) |
|
79 | - && \EE_Registry::instance()->CFG->registration->use_bot_trap |
|
80 | - ) { |
|
81 | - \EED_Bot_Trap::set_trap(); |
|
82 | - } |
|
83 | - add_action( |
|
84 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
85 | - array('EED_Bot_Trap', 'bot_trap_settings_form'), |
|
86 | - 5 |
|
87 | - ); |
|
88 | - add_filter( |
|
89 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
90 | - array('EED_Bot_Trap', 'update_bot_trap_settings_form'), |
|
91 | - 10, 1 |
|
92 | - ); |
|
93 | - } |
|
68 | + /** |
|
69 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
70 | + * |
|
71 | + * @return void |
|
72 | + */ |
|
73 | + public static function set_hooks_admin() |
|
74 | + { |
|
75 | + if ( |
|
76 | + defined('DOING_AJAX') |
|
77 | + && DOING_AJAX |
|
78 | + && apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) |
|
79 | + && \EE_Registry::instance()->CFG->registration->use_bot_trap |
|
80 | + ) { |
|
81 | + \EED_Bot_Trap::set_trap(); |
|
82 | + } |
|
83 | + add_action( |
|
84 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
85 | + array('EED_Bot_Trap', 'bot_trap_settings_form'), |
|
86 | + 5 |
|
87 | + ); |
|
88 | + add_filter( |
|
89 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
90 | + array('EED_Bot_Trap', 'update_bot_trap_settings_form'), |
|
91 | + 10, 1 |
|
92 | + ); |
|
93 | + } |
|
94 | 94 | |
95 | 95 | |
96 | - /** |
|
97 | - * run - initial module setup |
|
98 | - * |
|
99 | - * @param WP $WP |
|
100 | - * @return void |
|
101 | - */ |
|
102 | - public function run($WP) |
|
103 | - { |
|
104 | - } |
|
96 | + /** |
|
97 | + * run - initial module setup |
|
98 | + * |
|
99 | + * @param WP $WP |
|
100 | + * @return void |
|
101 | + */ |
|
102 | + public function run($WP) |
|
103 | + { |
|
104 | + } |
|
105 | 105 | |
106 | 106 | |
107 | - /** |
|
108 | - * generate_bot_trap |
|
109 | - * |
|
110 | - * @return void |
|
111 | - * @throws RuntimeException |
|
112 | - */ |
|
113 | - public static function generate_bot_trap() |
|
114 | - { |
|
115 | - $do_not_enter = esc_html__('please do not enter anything in this input', 'event_espresso'); |
|
116 | - $time = microtime(true); |
|
117 | - $html = '<div class="tkt-slctr-request-processor-dv" style="float:left; margin:0 0 0 -999em; height: 0;">'; |
|
118 | - $html .= '<label for="tkt-slctr-request-processor-email-' . $time . '">' . $do_not_enter . '</label>'; |
|
119 | - $html .= '<input type="email" id="tkt-slctr-request-processor-email-'; |
|
120 | - $html .= $time . '" name="tkt-slctr-request-processor-email" value=""/>'; |
|
121 | - $html .= '<input type="hidden" name="tkt-slctr-request-processor-token" value="'; |
|
122 | - if (EE_Registry::instance()->CFG->registration->use_encryption) { |
|
123 | - EE_Registry::instance()->load_core('EE_Encryption'); |
|
124 | - $html .= EE_Encryption::instance()->encrypt($time); |
|
125 | - } else { |
|
126 | - $html .= $time; |
|
127 | - } |
|
128 | - $html .= '"/>'; |
|
129 | - $html .= '</div><!-- .tkt-slctr-request-processor-dv -->'; |
|
130 | - echo $html; |
|
131 | - } |
|
107 | + /** |
|
108 | + * generate_bot_trap |
|
109 | + * |
|
110 | + * @return void |
|
111 | + * @throws RuntimeException |
|
112 | + */ |
|
113 | + public static function generate_bot_trap() |
|
114 | + { |
|
115 | + $do_not_enter = esc_html__('please do not enter anything in this input', 'event_espresso'); |
|
116 | + $time = microtime(true); |
|
117 | + $html = '<div class="tkt-slctr-request-processor-dv" style="float:left; margin:0 0 0 -999em; height: 0;">'; |
|
118 | + $html .= '<label for="tkt-slctr-request-processor-email-' . $time . '">' . $do_not_enter . '</label>'; |
|
119 | + $html .= '<input type="email" id="tkt-slctr-request-processor-email-'; |
|
120 | + $html .= $time . '" name="tkt-slctr-request-processor-email" value=""/>'; |
|
121 | + $html .= '<input type="hidden" name="tkt-slctr-request-processor-token" value="'; |
|
122 | + if (EE_Registry::instance()->CFG->registration->use_encryption) { |
|
123 | + EE_Registry::instance()->load_core('EE_Encryption'); |
|
124 | + $html .= EE_Encryption::instance()->encrypt($time); |
|
125 | + } else { |
|
126 | + $html .= $time; |
|
127 | + } |
|
128 | + $html .= '"/>'; |
|
129 | + $html .= '</div><!-- .tkt-slctr-request-processor-dv -->'; |
|
130 | + echo $html; |
|
131 | + } |
|
132 | 132 | |
133 | 133 | |
134 | - /** |
|
135 | - * process_bot_trap |
|
136 | - * |
|
137 | - * @param array|string $triggered_trap_callback Callback that will be executed for handling the |
|
138 | - * response if the bot trap is triggered. |
|
139 | - * It should receive one argument: a boolean indicating |
|
140 | - * whether the trap was triggered by suspicious timing or not. |
|
141 | - * @throws RuntimeException |
|
142 | - */ |
|
143 | - public static function process_bot_trap($triggered_trap_callback = array()) |
|
144 | - { |
|
145 | - // what's your email address Mr. Bot ? |
|
146 | - $empty_trap = isset($_REQUEST['tkt-slctr-request-processor-email']) |
|
147 | - && $_REQUEST['tkt-slctr-request-processor-email'] === ''; |
|
148 | - // get encrypted timestamp for when the form was originally displayed |
|
149 | - $bot_trap_timestamp = isset($_REQUEST['tkt-slctr-request-processor-token']) |
|
150 | - ? sanitize_text_field($_REQUEST['tkt-slctr-request-processor-token']) |
|
151 | - : ''; |
|
152 | - // decrypt and convert to absolute integer |
|
153 | - if (EE_Registry::instance()->CFG->registration->use_encryption) { |
|
154 | - EE_Registry::instance()->load_core('EE_Encryption'); |
|
155 | - $bot_trap_timestamp = absint(EE_Encryption::instance()->decrypt($bot_trap_timestamp)); |
|
156 | - } else { |
|
157 | - $bot_trap_timestamp = absint($bot_trap_timestamp); |
|
158 | - } |
|
159 | - // ticket form submitted too impossibly fast ( after now ) or more than an hour later ??? |
|
160 | - $suspicious_timing = $bot_trap_timestamp > time() || $bot_trap_timestamp < (time() - HOUR_IN_SECONDS); |
|
161 | - // are we human ? |
|
162 | - if ($empty_trap && !$suspicious_timing) { |
|
163 | - do_action('AHEE__EED_Bot_Trap__process_bot_trap__trap_not_triggered'); |
|
164 | - return; |
|
165 | - } |
|
166 | - // check the given callback is valid first before executing |
|
167 | - if (!is_callable($triggered_trap_callback)) { |
|
168 | - // invalid callback so lets just sub in our default. |
|
169 | - $triggered_trap_callback = array('EED_Bot_Trap', 'triggered_trap_response'); |
|
170 | - } |
|
171 | - call_user_func($triggered_trap_callback, $suspicious_timing); |
|
172 | - } |
|
134 | + /** |
|
135 | + * process_bot_trap |
|
136 | + * |
|
137 | + * @param array|string $triggered_trap_callback Callback that will be executed for handling the |
|
138 | + * response if the bot trap is triggered. |
|
139 | + * It should receive one argument: a boolean indicating |
|
140 | + * whether the trap was triggered by suspicious timing or not. |
|
141 | + * @throws RuntimeException |
|
142 | + */ |
|
143 | + public static function process_bot_trap($triggered_trap_callback = array()) |
|
144 | + { |
|
145 | + // what's your email address Mr. Bot ? |
|
146 | + $empty_trap = isset($_REQUEST['tkt-slctr-request-processor-email']) |
|
147 | + && $_REQUEST['tkt-slctr-request-processor-email'] === ''; |
|
148 | + // get encrypted timestamp for when the form was originally displayed |
|
149 | + $bot_trap_timestamp = isset($_REQUEST['tkt-slctr-request-processor-token']) |
|
150 | + ? sanitize_text_field($_REQUEST['tkt-slctr-request-processor-token']) |
|
151 | + : ''; |
|
152 | + // decrypt and convert to absolute integer |
|
153 | + if (EE_Registry::instance()->CFG->registration->use_encryption) { |
|
154 | + EE_Registry::instance()->load_core('EE_Encryption'); |
|
155 | + $bot_trap_timestamp = absint(EE_Encryption::instance()->decrypt($bot_trap_timestamp)); |
|
156 | + } else { |
|
157 | + $bot_trap_timestamp = absint($bot_trap_timestamp); |
|
158 | + } |
|
159 | + // ticket form submitted too impossibly fast ( after now ) or more than an hour later ??? |
|
160 | + $suspicious_timing = $bot_trap_timestamp > time() || $bot_trap_timestamp < (time() - HOUR_IN_SECONDS); |
|
161 | + // are we human ? |
|
162 | + if ($empty_trap && !$suspicious_timing) { |
|
163 | + do_action('AHEE__EED_Bot_Trap__process_bot_trap__trap_not_triggered'); |
|
164 | + return; |
|
165 | + } |
|
166 | + // check the given callback is valid first before executing |
|
167 | + if (!is_callable($triggered_trap_callback)) { |
|
168 | + // invalid callback so lets just sub in our default. |
|
169 | + $triggered_trap_callback = array('EED_Bot_Trap', 'triggered_trap_response'); |
|
170 | + } |
|
171 | + call_user_func($triggered_trap_callback, $suspicious_timing); |
|
172 | + } |
|
173 | 173 | |
174 | 174 | |
175 | - /** |
|
176 | - * This is the default callback executed by EED_Bot_Trap::process_bot_trap that handles the response. |
|
177 | - * |
|
178 | - * @param bool $suspicious_timing If true, then the bot trap was triggered due to the suspicious timing test. |
|
179 | - */ |
|
180 | - public static function triggered_trap_response($suspicious_timing) |
|
181 | - { |
|
182 | - // UH OH... |
|
183 | - $redirect_url = add_query_arg( |
|
184 | - array('ee' => 'ticket_selection_received'), |
|
185 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
186 | - ); |
|
187 | - if ($suspicious_timing) { |
|
188 | - $redirect_url = add_query_arg( |
|
189 | - array( |
|
190 | - 'ee-notice' => urlencode( |
|
191 | - esc_html__( |
|
192 | - 'We\'re sorry, but your ticket selections could not be processed due to a server timing error. Please hit the back button on your browser and try again.', |
|
193 | - 'event_espresso' |
|
194 | - ) |
|
195 | - ) |
|
196 | - ), |
|
197 | - $redirect_url |
|
198 | - ); |
|
199 | - } |
|
200 | - $redirect_url = apply_filters('FHEE__EED_Bot_Trap__process_bot_trap__redirect_url', $redirect_url); |
|
201 | - // if AJAX, return the redirect URL |
|
202 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
203 | - echo wp_json_encode( |
|
204 | - array_merge( |
|
205 | - EE_Error::get_notices(false), |
|
206 | - array( |
|
207 | - 'redirect_url' => $redirect_url |
|
208 | - ) |
|
209 | - ) |
|
210 | - ); |
|
211 | - exit(); |
|
212 | - } |
|
213 | - wp_safe_redirect($redirect_url); |
|
214 | - exit(); |
|
215 | - } |
|
175 | + /** |
|
176 | + * This is the default callback executed by EED_Bot_Trap::process_bot_trap that handles the response. |
|
177 | + * |
|
178 | + * @param bool $suspicious_timing If true, then the bot trap was triggered due to the suspicious timing test. |
|
179 | + */ |
|
180 | + public static function triggered_trap_response($suspicious_timing) |
|
181 | + { |
|
182 | + // UH OH... |
|
183 | + $redirect_url = add_query_arg( |
|
184 | + array('ee' => 'ticket_selection_received'), |
|
185 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
186 | + ); |
|
187 | + if ($suspicious_timing) { |
|
188 | + $redirect_url = add_query_arg( |
|
189 | + array( |
|
190 | + 'ee-notice' => urlencode( |
|
191 | + esc_html__( |
|
192 | + 'We\'re sorry, but your ticket selections could not be processed due to a server timing error. Please hit the back button on your browser and try again.', |
|
193 | + 'event_espresso' |
|
194 | + ) |
|
195 | + ) |
|
196 | + ), |
|
197 | + $redirect_url |
|
198 | + ); |
|
199 | + } |
|
200 | + $redirect_url = apply_filters('FHEE__EED_Bot_Trap__process_bot_trap__redirect_url', $redirect_url); |
|
201 | + // if AJAX, return the redirect URL |
|
202 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
203 | + echo wp_json_encode( |
|
204 | + array_merge( |
|
205 | + EE_Error::get_notices(false), |
|
206 | + array( |
|
207 | + 'redirect_url' => $redirect_url |
|
208 | + ) |
|
209 | + ) |
|
210 | + ); |
|
211 | + exit(); |
|
212 | + } |
|
213 | + wp_safe_redirect($redirect_url); |
|
214 | + exit(); |
|
215 | + } |
|
216 | 216 | |
217 | 217 | |
218 | - /** |
|
219 | - * display_bot_trap_success |
|
220 | - * shows a "success" screen to bots so that they (ie: the ppl managing them) |
|
221 | - * think the form was submitted successfully |
|
222 | - * |
|
223 | - * @return void |
|
224 | - */ |
|
225 | - public static function display_bot_trap_success() |
|
226 | - { |
|
227 | - add_filter('FHEE__EED_Single_Page_Checkout__run', '__return_false'); |
|
228 | - $bot_notice = esc_html__( |
|
229 | - 'Thank you so much. Your ticket selections have been received for consideration.', |
|
230 | - 'event_espresso' |
|
231 | - ); |
|
232 | - $bot_notice = isset($_REQUEST['ee-notice']) && $_REQUEST['ee-notice'] !== '' |
|
233 | - ? sanitize_text_field(stripslashes($_REQUEST['ee-notice'])) |
|
234 | - : $bot_notice; |
|
235 | - EE_Registry::instance()->REQ->add_output(EEH_HTML::div($bot_notice, '', 'ee-attention')); |
|
236 | - } |
|
218 | + /** |
|
219 | + * display_bot_trap_success |
|
220 | + * shows a "success" screen to bots so that they (ie: the ppl managing them) |
|
221 | + * think the form was submitted successfully |
|
222 | + * |
|
223 | + * @return void |
|
224 | + */ |
|
225 | + public static function display_bot_trap_success() |
|
226 | + { |
|
227 | + add_filter('FHEE__EED_Single_Page_Checkout__run', '__return_false'); |
|
228 | + $bot_notice = esc_html__( |
|
229 | + 'Thank you so much. Your ticket selections have been received for consideration.', |
|
230 | + 'event_espresso' |
|
231 | + ); |
|
232 | + $bot_notice = isset($_REQUEST['ee-notice']) && $_REQUEST['ee-notice'] !== '' |
|
233 | + ? sanitize_text_field(stripslashes($_REQUEST['ee-notice'])) |
|
234 | + : $bot_notice; |
|
235 | + EE_Registry::instance()->REQ->add_output(EEH_HTML::div($bot_notice, '', 'ee-attention')); |
|
236 | + } |
|
237 | 237 | |
238 | 238 | |
239 | 239 | |
240 | - /*********************************** ADMIN **********************************/ |
|
240 | + /*********************************** ADMIN **********************************/ |
|
241 | 241 | |
242 | 242 | |
243 | - /** |
|
244 | - * bot_trap_settings_form |
|
245 | - * |
|
246 | - * @return void |
|
247 | - * @throws EE_Error |
|
248 | - */ |
|
249 | - public static function bot_trap_settings_form() |
|
250 | - { |
|
251 | - EED_Bot_Trap::_bot_trap_settings_form()->enqueue_js(); |
|
252 | - echo EED_Bot_Trap::_bot_trap_settings_form()->get_html(); |
|
253 | - } |
|
243 | + /** |
|
244 | + * bot_trap_settings_form |
|
245 | + * |
|
246 | + * @return void |
|
247 | + * @throws EE_Error |
|
248 | + */ |
|
249 | + public static function bot_trap_settings_form() |
|
250 | + { |
|
251 | + EED_Bot_Trap::_bot_trap_settings_form()->enqueue_js(); |
|
252 | + echo EED_Bot_Trap::_bot_trap_settings_form()->get_html(); |
|
253 | + } |
|
254 | 254 | |
255 | 255 | |
256 | - /** |
|
257 | - * _bot_trap_settings_form |
|
258 | - * |
|
259 | - * @return EE_Form_Section_Proper |
|
260 | - * @throws EE_Error |
|
261 | - */ |
|
262 | - protected static function _bot_trap_settings_form() |
|
263 | - { |
|
264 | - return new EE_Form_Section_Proper( |
|
265 | - array( |
|
266 | - 'name' => 'bot_trap_settings', |
|
267 | - 'html_id' => 'bot_trap_settings', |
|
268 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
269 | - 'subsections' => array( |
|
270 | - 'bot_trap_hdr' => new EE_Form_Section_HTML(EEH_HTML::h2(esc_html__('Bot Trap Settings', 'event_espresso'))), |
|
271 | - 'use_bot_trap' => new EE_Yes_No_Input( |
|
272 | - array( |
|
273 | - 'html_label_text' => esc_html__('Enable Bot Trap', 'event_espresso'), |
|
274 | - 'html_help_text' => esc_html__('The Event Espresso Bot Trap will insert a fake input into your Ticket Selector forms that is hidden from regular site visitors, but visible to spam bots. Because the input asks for an email address, it is irresistible to spam bots who will of course enter text into it. Since regular site visitors can not see this input, any value detected during form submission means a bot has been detected, which will then be blocked from submitting the form.', 'event_espresso'), |
|
275 | - 'default' => EE_Registry::instance()->CFG->registration->use_bot_trap !== null |
|
276 | - ? EE_Registry::instance()->CFG->registration->use_bot_trap |
|
277 | - : true, |
|
278 | - 'required' => false |
|
279 | - ) |
|
280 | - ), |
|
281 | - 'use_encryption' => new EE_Yes_No_Input( |
|
282 | - array( |
|
283 | - 'html_label_text' => esc_html__('Encrypt Bot Trap Data', 'event_espresso'), |
|
284 | - 'html_help_text' => esc_html__( |
|
285 | - 'One way to detect spam bots is by looking at how long it takes them to submit a form. They are often inhumanly fast, or will submit forms hours, days, or even weeks after the form was first scraped off the web. The Event Espresso Bot Trap will send a timestamp with the Ticket Selector form when it is submitted. By default, this timestamp is encrypted so that the spam bots can not change it, but encryption may cause issues on some servers due to configuration "conflicts". If you continuously get caught in the bot trap, then try setting this option to "No". This may increase the number of spam submissions you receive, but increases server compatibility.', |
|
286 | - 'event_espresso' |
|
287 | - ), |
|
288 | - 'default' => EE_Registry::instance()->CFG->registration->use_encryption !== null |
|
289 | - ? EE_Registry::instance()->CFG->registration->use_encryption |
|
290 | - : true, |
|
291 | - 'required' => false |
|
292 | - ) |
|
293 | - ), |
|
294 | - ) |
|
295 | - ) |
|
296 | - ); |
|
297 | - } |
|
256 | + /** |
|
257 | + * _bot_trap_settings_form |
|
258 | + * |
|
259 | + * @return EE_Form_Section_Proper |
|
260 | + * @throws EE_Error |
|
261 | + */ |
|
262 | + protected static function _bot_trap_settings_form() |
|
263 | + { |
|
264 | + return new EE_Form_Section_Proper( |
|
265 | + array( |
|
266 | + 'name' => 'bot_trap_settings', |
|
267 | + 'html_id' => 'bot_trap_settings', |
|
268 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
269 | + 'subsections' => array( |
|
270 | + 'bot_trap_hdr' => new EE_Form_Section_HTML(EEH_HTML::h2(esc_html__('Bot Trap Settings', 'event_espresso'))), |
|
271 | + 'use_bot_trap' => new EE_Yes_No_Input( |
|
272 | + array( |
|
273 | + 'html_label_text' => esc_html__('Enable Bot Trap', 'event_espresso'), |
|
274 | + 'html_help_text' => esc_html__('The Event Espresso Bot Trap will insert a fake input into your Ticket Selector forms that is hidden from regular site visitors, but visible to spam bots. Because the input asks for an email address, it is irresistible to spam bots who will of course enter text into it. Since regular site visitors can not see this input, any value detected during form submission means a bot has been detected, which will then be blocked from submitting the form.', 'event_espresso'), |
|
275 | + 'default' => EE_Registry::instance()->CFG->registration->use_bot_trap !== null |
|
276 | + ? EE_Registry::instance()->CFG->registration->use_bot_trap |
|
277 | + : true, |
|
278 | + 'required' => false |
|
279 | + ) |
|
280 | + ), |
|
281 | + 'use_encryption' => new EE_Yes_No_Input( |
|
282 | + array( |
|
283 | + 'html_label_text' => esc_html__('Encrypt Bot Trap Data', 'event_espresso'), |
|
284 | + 'html_help_text' => esc_html__( |
|
285 | + 'One way to detect spam bots is by looking at how long it takes them to submit a form. They are often inhumanly fast, or will submit forms hours, days, or even weeks after the form was first scraped off the web. The Event Espresso Bot Trap will send a timestamp with the Ticket Selector form when it is submitted. By default, this timestamp is encrypted so that the spam bots can not change it, but encryption may cause issues on some servers due to configuration "conflicts". If you continuously get caught in the bot trap, then try setting this option to "No". This may increase the number of spam submissions you receive, but increases server compatibility.', |
|
286 | + 'event_espresso' |
|
287 | + ), |
|
288 | + 'default' => EE_Registry::instance()->CFG->registration->use_encryption !== null |
|
289 | + ? EE_Registry::instance()->CFG->registration->use_encryption |
|
290 | + : true, |
|
291 | + 'required' => false |
|
292 | + ) |
|
293 | + ), |
|
294 | + ) |
|
295 | + ) |
|
296 | + ); |
|
297 | + } |
|
298 | 298 | |
299 | 299 | |
300 | - /** |
|
301 | - * update_bot_trap_settings_form |
|
302 | - * |
|
303 | - * @param EE_Registration_Config $EE_Registration_Config |
|
304 | - * @return EE_Registration_Config |
|
305 | - * @throws ReflectionException |
|
306 | - * @throws EE_Error |
|
307 | - */ |
|
308 | - public static function update_bot_trap_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
309 | - { |
|
310 | - try { |
|
311 | - $bot_trap_settings_form = EED_Bot_Trap::_bot_trap_settings_form(); |
|
312 | - // if not displaying a form, then check for form submission |
|
313 | - if ($bot_trap_settings_form->was_submitted()) { |
|
314 | - // capture form data |
|
315 | - $bot_trap_settings_form->receive_form_submission(); |
|
316 | - // validate form data |
|
317 | - if ($bot_trap_settings_form->is_valid()) { |
|
318 | - // grab validated data from form |
|
319 | - $valid_data = $bot_trap_settings_form->valid_data(); |
|
320 | - if (isset($valid_data['use_bot_trap'], $valid_data['use_encryption'])) { |
|
321 | - $EE_Registration_Config->use_bot_trap = $valid_data['use_bot_trap']; |
|
322 | - $EE_Registration_Config->use_encryption = $valid_data['use_encryption']; |
|
323 | - } else { |
|
324 | - EE_Error::add_error(esc_html__('Invalid or missing Bot Trap settings. Please refresh the form and try again.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
325 | - } |
|
326 | - } else { |
|
327 | - if ($bot_trap_settings_form->submission_error_message() !== '') { |
|
328 | - EE_Error::add_error($bot_trap_settings_form->submission_error_message(), __FILE__, __FUNCTION__, __LINE__); |
|
329 | - } |
|
330 | - } |
|
331 | - } |
|
332 | - } catch (EE_Error $e) { |
|
333 | - $e->get_error(); |
|
334 | - } |
|
335 | - return $EE_Registration_Config; |
|
336 | - } |
|
300 | + /** |
|
301 | + * update_bot_trap_settings_form |
|
302 | + * |
|
303 | + * @param EE_Registration_Config $EE_Registration_Config |
|
304 | + * @return EE_Registration_Config |
|
305 | + * @throws ReflectionException |
|
306 | + * @throws EE_Error |
|
307 | + */ |
|
308 | + public static function update_bot_trap_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
309 | + { |
|
310 | + try { |
|
311 | + $bot_trap_settings_form = EED_Bot_Trap::_bot_trap_settings_form(); |
|
312 | + // if not displaying a form, then check for form submission |
|
313 | + if ($bot_trap_settings_form->was_submitted()) { |
|
314 | + // capture form data |
|
315 | + $bot_trap_settings_form->receive_form_submission(); |
|
316 | + // validate form data |
|
317 | + if ($bot_trap_settings_form->is_valid()) { |
|
318 | + // grab validated data from form |
|
319 | + $valid_data = $bot_trap_settings_form->valid_data(); |
|
320 | + if (isset($valid_data['use_bot_trap'], $valid_data['use_encryption'])) { |
|
321 | + $EE_Registration_Config->use_bot_trap = $valid_data['use_bot_trap']; |
|
322 | + $EE_Registration_Config->use_encryption = $valid_data['use_encryption']; |
|
323 | + } else { |
|
324 | + EE_Error::add_error(esc_html__('Invalid or missing Bot Trap settings. Please refresh the form and try again.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
325 | + } |
|
326 | + } else { |
|
327 | + if ($bot_trap_settings_form->submission_error_message() !== '') { |
|
328 | + EE_Error::add_error($bot_trap_settings_form->submission_error_message(), __FILE__, __FUNCTION__, __LINE__); |
|
329 | + } |
|
330 | + } |
|
331 | + } |
|
332 | + } catch (EE_Error $e) { |
|
333 | + $e->get_error(); |
|
334 | + } |
|
335 | + return $EE_Registration_Config; |
|
336 | + } |
|
337 | 337 | |
338 | 338 | |
339 | 339 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public static function set_trap() |
53 | 53 | { |
54 | - define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__) . DS); |
|
54 | + define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__).DS); |
|
55 | 55 | add_action( |
56 | 56 | 'AHEE__ticket_selector_chart__template__after_ticket_selector', |
57 | 57 | array('EED_Bot_Trap', 'generate_bot_trap'), |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | $do_not_enter = esc_html__('please do not enter anything in this input', 'event_espresso'); |
116 | 116 | $time = microtime(true); |
117 | 117 | $html = '<div class="tkt-slctr-request-processor-dv" style="float:left; margin:0 0 0 -999em; height: 0;">'; |
118 | - $html .= '<label for="tkt-slctr-request-processor-email-' . $time . '">' . $do_not_enter . '</label>'; |
|
118 | + $html .= '<label for="tkt-slctr-request-processor-email-'.$time.'">'.$do_not_enter.'</label>'; |
|
119 | 119 | $html .= '<input type="email" id="tkt-slctr-request-processor-email-'; |
120 | - $html .= $time . '" name="tkt-slctr-request-processor-email" value=""/>'; |
|
120 | + $html .= $time.'" name="tkt-slctr-request-processor-email" value=""/>'; |
|
121 | 121 | $html .= '<input type="hidden" name="tkt-slctr-request-processor-token" value="'; |
122 | 122 | if (EE_Registry::instance()->CFG->registration->use_encryption) { |
123 | 123 | EE_Registry::instance()->load_core('EE_Encryption'); |
@@ -159,12 +159,12 @@ discard block |
||
159 | 159 | // ticket form submitted too impossibly fast ( after now ) or more than an hour later ??? |
160 | 160 | $suspicious_timing = $bot_trap_timestamp > time() || $bot_trap_timestamp < (time() - HOUR_IN_SECONDS); |
161 | 161 | // are we human ? |
162 | - if ($empty_trap && !$suspicious_timing) { |
|
162 | + if ($empty_trap && ! $suspicious_timing) { |
|
163 | 163 | do_action('AHEE__EED_Bot_Trap__process_bot_trap__trap_not_triggered'); |
164 | 164 | return; |
165 | 165 | } |
166 | 166 | // check the given callback is valid first before executing |
167 | - if (!is_callable($triggered_trap_callback)) { |
|
167 | + if ( ! is_callable($triggered_trap_callback)) { |
|
168 | 168 | // invalid callback so lets just sub in our default. |
169 | 169 | $triggered_trap_callback = array('EED_Bot_Trap', 'triggered_trap_response'); |
170 | 170 | } |