csrf
2 years ago
exceptions
2 years ago
honeypot
2 years ago
wp-nonce
2 years ago
module.php
2 years ago
module.php
95 lines
| 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 | public function rep_item_id() { |
| 39 | return 'security'; |
| 40 | } |
| 41 | |
| 42 | public function on_install() { |
| 43 | $this->spam_statuses = apply_filters( |
| 44 | 'jet-form-builder/security/spam-statuses', |
| 45 | array() |
| 46 | ); |
| 47 | |
| 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 | |
| 53 | public function on_uninstall() { |
| 54 | $this->spam_statuses = array(); |
| 55 | |
| 56 | jet_form_builder()->get_modules()->uninstall( new Csrf\Module() ); |
| 57 | jet_form_builder()->get_modules()->uninstall( new Honeypot\Module() ); |
| 58 | jet_form_builder()->get_modules()->uninstall( new Wp_Nonce\Module() ); |
| 59 | } |
| 60 | |
| 61 | public function condition(): bool { |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | public function init_hooks() { |
| 66 | } |
| 67 | |
| 68 | public function remove_hooks() { |
| 69 | } |
| 70 | |
| 71 | public function has_spam(): bool { |
| 72 | $status = jet_fb_handler()->response_args['status'] ?? ''; |
| 73 | |
| 74 | return ( |
| 75 | in_array( $status, $this->spam_statuses, true ) || |
| 76 | Logger\Module::instance()->has_log( Spam_Exception::class ) |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | public static function get_hasher(): \PasswordHash { |
| 81 | global $wp_hasher; |
| 82 | |
| 83 | if ( ! empty( $wp_hasher ) ) { |
| 84 | return $wp_hasher; |
| 85 | } |
| 86 | |
| 87 | require_once ABSPATH . WPINC . '/class-phpass.php'; |
| 88 | // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 89 | $wp_hasher = new \PasswordHash( 8, true ); |
| 90 | |
| 91 | return $wp_hasher; |
| 92 | } |
| 93 | |
| 94 | } |
| 95 |