| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace JFB_Modules\Security; |
| 5 |
|
| 6 |
use JFB_Modules\Logger; |
| 7 |
use JFB_Components\Module\Base_Module_After_Install_It; |
| 8 |
use JFB_Components\Module\Base_Module_Dir_It; |
| 9 |
use JFB_Components\Module\Base_Module_Dir_Trait; |
| 10 |
use JFB_Components\Module\Base_Module_Handle_It; |
| 11 |
use JFB_Components\Module\Base_Module_Handle_Trait; |
| 12 |
use JFB_Components\Module\Base_Module_It; |
| 13 |
use JFB_Components\Module\Base_Module_Url_It; |
| 14 |
use JFB_Components\Module\Base_Module_Url_Trait; |
| 15 |
use JFB_Modules\Security\Exceptions\Spam_Exception; |
| 16 |
use JFB_Modules\Security\Csrf; |
| 17 |
use JFB_Modules\Security\Honeypot; |
| 18 |
use JFB_Modules\Security\Wp_Nonce; |
| 19 |
|
| 20 |
// If this file is called directly, abort. |
| 21 |
if ( ! defined( 'WPINC' ) ) { |
| 22 |
die; |
| 23 |
} |
| 24 |
|
| 25 |
class Module implements |
| 26 |
Base_Module_It, |
| 27 |
Base_Module_Url_It, |
| 28 |
Base_Module_Dir_It, |
| 29 |
Base_Module_After_Install_It, |
| 30 |
Base_Module_Handle_It { |
| 31 |
|
| 32 |
use Base_Module_Handle_Trait; |
| 33 |
use Base_Module_Url_Trait; |
| 34 |
use Base_Module_Dir_Trait; |
| 35 |
|
| 36 |
private $spam_statuses = array(); |
| 37 |
|
| 38 |
/** |
| 39 |
* @var Restricted_Preset_Notice |
| 40 |
*/ |
| 41 |
private $restricted_preset_notice; |
| 42 |
|
| 43 |
public function rep_item_id() { |
| 44 |
return 'security'; |
| 45 |
} |
| 46 |
|
| 47 |
public function on_install() { |
| 48 |
jet_form_builder()->get_modules()->install( new Csrf\Module() ); |
| 49 |
jet_form_builder()->get_modules()->install( new Honeypot\Module() ); |
| 50 |
jet_form_builder()->get_modules()->install( new Wp_Nonce\Module() ); |
| 51 |
|
| 52 |
$this->spam_statuses = apply_filters( |
| 53 |
'jet-form-builder/security/spam-statuses', |
| 54 |
array() |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
public function on_uninstall() { |
| 59 |
jet_form_builder()->get_modules()->uninstall( new Csrf\Module() ); |
| 60 |
jet_form_builder()->get_modules()->uninstall( new Honeypot\Module() ); |
| 61 |
jet_form_builder()->get_modules()->uninstall( new Wp_Nonce\Module() ); |
| 62 |
|
| 63 |
$this->spam_statuses = array(); |
| 64 |
} |
| 65 |
|
| 66 |
public function condition(): bool { |
| 67 |
return true; |
| 68 |
} |
| 69 |
|
| 70 |
public function init_hooks() { |
| 71 |
$this->restricted_preset_notice = new Restricted_Preset_Notice(); |
| 72 |
$this->restricted_preset_notice->init_hooks(); |
| 73 |
} |
| 74 |
|
| 75 |
public function remove_hooks() { |
| 76 |
if ( $this->restricted_preset_notice ) { |
| 77 |
$this->restricted_preset_notice->remove_hooks(); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
public function has_spam(): bool { |
| 82 |
$status = jet_fb_handler()->response_args['status'] ?? ''; |
| 83 |
|
| 84 |
return ( |
| 85 |
in_array( $status, $this->spam_statuses, true ) || |
| 86 |
Logger\Module::instance()->has_log( Spam_Exception::class ) |
| 87 |
); |
| 88 |
} |
| 89 |
|
| 90 |
public static function get_hasher(): \PasswordHash { |
| 91 |
global $wp_hasher; |
| 92 |
|
| 93 |
if ( ! empty( $wp_hasher ) ) { |
| 94 |
return $wp_hasher; |
| 95 |
} |
| 96 |
|
| 97 |
require_once ABSPATH . WPINC . '/class-phpass.php'; |
| 98 |
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 99 |
$wp_hasher = new \PasswordHash( 8, true ); |
| 100 |
|
| 101 |
return $wp_hasher; |
| 102 |
} |
| 103 |
|
| 104 |
} |
| 105 |
|