PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
← All changes | src/controller/class-hub.php +87 -158 5.8.1 → 6.3.0 View file →
@@ -11,9 +11,8 @@
11 11 use WP_Defender\Traits\IO;
12 12 use WP_Defender\Traits\Formats;
13 13 use WP_Defender\Behavior\WPMUDEV;
14 14 use WP_Defender\Model\Lockout_Log;
15 -use WP_Defender\Component\Quarantine;
16 15 use WP_Defender\Model\Setting\Two_Fa;
17 16 use WP_Defender\Component\IP\Antibot_Global_Firewall;
18 17 use WP_Defender\Component\IP\Global_IP;
19 18 use WP_Defender\Component\Backup_Settings;
@@ -25,8 +24,9 @@
25 24 use WP_Defender\Component\Config\Config_Adapter;
26 25 use WP_Defender\Model\Setting\User_Agent_Lockout;
27 26 use WP_Defender\Model\Notification\Malware_Report;
28 27 use WP_Defender\Model\Notification\Tweak_Reminder;
28 +use WP_Defender\Component\Scan as Scan_Component;
29 29 use WP_Defender\Component\Config\Config_Hub_Helper;
30 30 use WP_Defender\Model\Notification\Firewall_Report;
31 31 use WP_Defender\Model\Notification\Malware_Notification;
32 32 use WP_Defender\Model\Notification\Firewall_Notification;
@@ -42,20 +42,13 @@
42 42 use IO;
43 43 use Formats;
44 44
45 45 /**
46 - * Flag indicating whether to display the onboarding view or not.
47 - *
48 - * @var bool
49 - */
50 - private $view_onboard = false;
51 -
52 - /**
53 46 * Initializes the model and service, registers routes, and sets up scheduled events if the model is active.
54 47 */
55 48 public function __construct() {
56 49 $this->attach_behavior( WPMUDEV::class, WPMUDEV::class );
57 - add_action( 'wdp_register_hub_action', array( $this, 'add_hub_endpoint' ) );
50 + add_filter( 'wdp_register_hub_action', array( $this, 'add_hub_endpoint' ) );
58 51 add_action( 'defender_hub_sync', array( $this, 'hub_sync' ) );
59 52 }
60 53
61 54 /**
@@ -65,11 +58,12 @@
65 58 *
66 59 * @return array The updated actions array with hub endpoints added.
67 60 */
68 61 public function add_hub_endpoint( $actions ) {
69 - $actions['defender_new_scan'] = array( $this, 'new_scan' );
70 - $actions['defender_schedule_scan'] = array( $this, 'schedule_scan' );
71 - $actions['defender_manage_audit_log'] = array( $this, 'manage_audit_log' );
62 + $actions['defender_new_scan'] = array( $this, 'new_scan' );
63 + $actions['defender_get_quarantined_files'] = array( $this, 'get_quarantined_files' );
64 + $actions['defender_restore_quarantined_file'] = array( $this, 'restore_quarantined_file' );
65 +
72 66 $actions['defender_manage_lockout'] = array( $this, 'manage_lockout' );
73 67 $actions['defender_whitelist_ip'] = array( $this, 'whitelist_ip' );
74 68 $actions['defender_blacklist_ip'] = array( $this, 'blacklist_ip' );
75 69 $actions['defender_get_scan_progress'] = array( $this, 'get_scan_progress' );
@@ -85,11 +79,8 @@
85 79 $actions['defender_get_stats'] = array( $this, 'get_stats' );
86 80 // Version#2.
87 81 $actions['defender_get_stats_v2'] = array( $this, 'defender_get_stats_v2' );
88 82
89 - $actions['defender_get_quarantined_files'] = array( $this, 'get_quarantined_files' );
90 - $actions['defender_restore_quarantined_file'] = array( $this, 'restore_quarantined_file' );
91 -
92 83 return $actions;
93 84 }
94 85
95 86 /**
@@ -95,8 +86,17 @@
95 86 /**
96 87 * Create new scan, triggered from HUB.
97 88 */
98 89 public function new_scan() {
90 + $scan_component = wd_di()->get( Scan_Component::class );
91 + if ( ! $scan_component->is_any_scan_type_active() ) {
92 + wp_send_json_error(
93 + array(
94 + 'message' => Scan_Component::get_emergency_scan_stop_text(),
95 + )
96 + );
97 + }
98 +
99 99 $scan = \WP_Defender\Model\Scan::create();
100 100 if ( is_wp_error( $scan ) ) {
101 101 wp_send_json_error(
102 102 array(
@@ -110,34 +110,8 @@
110 110 wp_send_json_success();
111 111 }
112 112
113 113 /**
114 - * Schedule a scan, from HUB.
115 - *
116 - * @param array $params Schedule config.
117 - */
118 - public function schedule_scan( $params ) {
119 - $frequency = $params['frequency'];
120 - $day = $params['day'];
121 - $time = $params['time'];
122 - $allowed_freq = array( 1, 7, 30 );
123 - if (
124 - ! in_array( $frequency, $allowed_freq, true )
125 - || ! in_array( $day, $this->get_days_of_week(), true )
126 - || ! in_array( $time, $this->get_times(), true )
127 - ) {
128 - wp_send_json_error();
129 - }
130 - $malware_report = new Malware_Report();
131 - $malware_report->frequency = $frequency;
132 - $malware_report->day = $day;
133 - $malware_report->time = $time;
134 - $malware_report->save();
135 -
136 - wp_send_json_success();
137 - }
138 -
139 - /**
140 114 * Track a feature activation or deactivation from the Hub.
141 115 *
142 116 * @param bool $is_active Whether the feature is being activated or deactivated.
143 117 * @param string $feature_title The title of the feature being tracked.
@@ -152,32 +126,66 @@
152 126 $this->track_feature( $event, $data );
153 127 }
154 128
155 129 /**
156 - * Manage the audit log settings by toggling the enabled status of the Audit Logging feature.
130 + * Get recent quarantined files.
131 + */
132 + public function get_quarantined_files(): void {
133 + if ( ! class_exists( 'WP_Defender\Component\Quarantine' ) ) {
134 + $result = array(
135 + 'message' => defender_quarantine_pro_only(),
136 + 'success' => false,
137 + );
138 +
139 + wp_send_json_error( $result );
140 + }
141 +
142 + $quarantine_obj = wd_di()->get( \WP_Defender\Component\Quarantine::class );
143 +
144 + $quarantined_files = $quarantine_obj->hub_list();
145 +
146 + wp_send_json_success(
147 + array( 'quarantined_files' => $quarantined_files )
148 + );
149 + }
150 +
151 + /**
152 + * Restores a quarantined file based on the provided parameters.
157 153 *
154 + * @param object $params The parameters for restoring the quarantined file.
155 + * Requires the 'id' property to be set.
156 + *
158 157 * @return void
159 158 */
160 - public function manage_audit_log() {
161 - $response = null;
162 - if ( class_exists( Model_Audit_Logging::class ) ) {
163 - $settings = new Model_Audit_Logging();
164 - $response = array();
165 - if ( true === $settings->enabled ) {
166 - $settings->enabled = false;
167 - $response['enabled'] = false;
168 - } else {
169 - $settings->enabled = true;
170 - $response['enabled'] = true;
159 + public function restore_quarantined_file( object $params ): void {
160 + if ( ! class_exists( 'WP_Defender\Component\Quarantine' ) ) {
161 + $result = array(
162 + 'message' => defender_quarantine_pro_only(),
163 + 'success' => false,
164 + );
165 +
166 + wp_send_json_error( $result );
167 + }
168 +
169 + if ( isset( $params->id ) ) {
170 + $id = (int) $params->id;
171 +
172 + $quarantine_obj = wd_di()->get( \WP_Defender\Component\Quarantine::class );
173 +
174 + $result = $quarantine_obj->restore_file( $id );
175 +
176 + if ( isset( $result['success'] ) && false === $result['success'] ) {
177 + wp_send_json_error( $result );
171 178 }
172 - $settings->save();
173 - // Track.
174 - if ( $this->is_tracking_active() ) {
175 - $this->track_feature_from_hub( ! $settings->enabled, 'Audit Logging' );
176 - }
179 +
180 + wp_send_json_success( $result );
177 181 }
178 182
179 - wp_send_json_success( $response );
183 + wp_send_json_error(
184 + array(
185 + 'message' => esc_html__( 'Missing parameter: id.', 'defender-security' ),
186 + )
187 + );
180 188 }
181 189
182 190 /**
183 191 * Manages the lockout feature based on the given parameters.
@@ -182,10 +190,9 @@
182 190 /**
183 191 * Manages the lockout feature based on the given parameters.
184 192 *
185 193 * @param array $params The parameters for managing the lockout.
186 - * - type (string): The type of lockout to manage. Possible values: 'login', '404',
187 - * 'ua-lockout'.
194 + * - type (string): The type of lockout to manage. Possible values: 'login', '404', 'ua-lockout'.
188 195 * @param string $action The action to perform on the lockout.
189 196 *
190 197 * @return void
191 198 */
@@ -435,12 +442,15 @@
435 442 $status_active = \WP_Defender\Model\Notification::STATUS_ACTIVE;
436 443 $model_sec_headers = wd_di()->get( \WP_Defender\Model\Setting\Security_Headers::class );
437 444 $scan_report = wd_di()->get( Malware_Report::class );
438 445 $two_fa = wd_di()->get( Two_Fa::class );
446 + if ( class_exists( 'WP_Defender\Component\Quarantine' ) ) {
447 + $quarantined_files = wd_di()->get( \WP_Defender\Component\Quarantine::class )->hub_list();
448 + } else {
449 + $quarantined_files = array();
450 + }
439 451
440 - $quarantined_files = class_exists( 'WP_Defender\Component\Quarantine' ) ?
441 - wd_di()->get( Quarantine::class )->hub_list() : array();
442 - $antibot_service = wd_di()->get( Antibot_Global_Firewall::class );
452 + $antibot_service = wd_di()->get( Antibot_Global_Firewall::class );
443 453
444 454 $ret = array(
445 455 'summary' => array(
446 456 'count' => $total,
@@ -446,11 +456,12 @@
446 456 'count' => $total,
447 457 'next_scan' => $scan_report->get_next_run_for_hub(),
448 458 ),
449 459 'report' => array(
450 - 'malware_scan' => $scan_report->get_next_run_as_string( true ),
451 - 'firewall' => wd_di()->get( Firewall_Report::class )->get_next_run_as_string( true ),
452 - 'audit_logging' => wd_di()->get( Audit_Report::class )->get_next_run_as_string( true ),
460 + 'malware_scan' => $scan_report->get_next_run_as_string( true ),
461 + 'firewall' => wd_di()->get( Firewall_Report::class )->get_next_run_as_string( true ),
462 + 'audit_logging' => wd_di()->get( Audit_Report::class )->get_next_run_as_string( true ),
463 + 'tweak_reminder' => wd_di()->get( Tweak_Reminder::class )->get_next_run_as_string( true ),
453 464 ),
454 465 'security_tweaks' => array(
455 466 'issues' => $tweak_arr['count_issues'],
456 467 'fixed' => $tweak_arr['count_fixed'],
@@ -472,15 +483,11 @@
472 483 ),
473 484 '404_lockout' => Lockout_Log::count(
474 485 strtotime( '-24 hours' ),
475 486 time(),
476 - array( Lockout_Log::LOCKOUT_404 )
487 + Lockout_Log::get_404_lockout_types()
477 488 ),
478 - 'user_agent_lockout' => Lockout_Log::count(
479 - strtotime( '-24 hours' ),
480 - time(),
481 - array( Lockout_Log::LOCKOUT_UA )
482 - ),
489 + 'user_agent_lockout' => Lockout_Log::count_ua_lockouts_in_24_hours(),
483 490 ),
484 491 '7_days' => array(
485 492 'login_lockout' => Lockout_Log::count_login_lockout_last_7_days(),
486 493 '404_lockout' => Lockout_Log::count_404_lockout_last_7_days(),
@@ -499,9 +506,9 @@
499 506 ),
500 507 'user_agent_lockout' => Lockout_Log::count(
501 508 strtotime( '-30 days' ),
502 509 time(),
503 - array( Lockout_Log::LOCKOUT_UA )
510 + Lockout_Log::get_ua_lockout_types()
504 511 ),
505 512 ),
506 513 'notification_status' => array(
507 514 'login_lockout' => $login_lockout,
@@ -515,12 +522,12 @@
515 522 'antibot_enabled' => $antibot_service->frontend_is_enabled(),
516 523 'antibot_mode' => $antibot_service->frontend_mode(),
517 524 ),
518 525 'audit' => array(
519 - 'last_event' => $audit['lastEvent'],
520 - '24_hours' => $audit['dayCount'],
521 - '7_days' => $audit['weekCount'],
522 - '30_days' => $audit['monthCount'],
526 + 'last_event' => $audit['lastEvent'] ?? 'n/a',
527 + '24_hours' => $audit['dayCount'] ?? 0,
528 + '7_days' => $audit['weekCount'] ?? 0,
529 + '30_days' => $audit['monthCount'] ?? 0,
523 530 'enabled' => $audit_log->model->is_active(),
524 531 ),
525 532 'advanced_tools' => array(
526 533 'security_headers' => array(
@@ -580,11 +587,12 @@
580 587
581 588 /**
582 589 * Placeholder for frontend data.
583 590 *
584 - * @return void
591 + * @return array
585 592 */
586 593 public function data_frontend() {
594 + return array();
587 595 }
588 596
589 597 /**
590 598 * Converts the current object state to an array.
@@ -612,26 +620,8 @@
612 620 return array();
613 621 }
614 622
615 623 /**
616 - * Display Onboard if the bool value 'true' and vice versa.
617 - *
618 - * @param bool $is_show Settings to display.
619 - */
620 - public function set_onboarding_status( $is_show ) {
621 - $this->view_onboard = $is_show;
622 - }
623 -
624 - /**
625 - * Retrieve the Onboard status.
626 - *
627 - * @return bool
628 - */
629 - public function get_onboarding_status(): bool {
630 - return $this->view_onboard;
631 - }
632 -
633 - /**
634 624 * Activate/deactivate Captcha from HUB.
635 625 */
636 626 public function manage_recaptcha() {
637 627 $response = null;
@@ -735,69 +725,8 @@
735 725 }
736 726
737 727 wp_send_json_success(
738 728 array( 'enabled' => $global_ip_component->is_global_ip_enabled() )
739 - );
740 - }
741 -
742 - /**
743 - * Get recent quarantined files.
744 - */
745 - public function get_quarantined_files(): void {
746 - if ( ! class_exists( 'WP_Defender\Component\Quarantine' ) ) {
747 - $result = array(
748 - 'message' => defender_quarantine_pro_only(),
749 - 'success' => false,
750 - );
751 -
752 - wp_send_json_error( $result );
753 - }
754 -
755 - $quarantine_obj = wd_di()->get( Quarantine::class );
756 -
757 - $quarantined_files = $quarantine_obj->hub_list();
758 -
759 - wp_send_json_success(
760 - array( 'quarantined_files' => $quarantined_files )
761 - );
762 - }
763 -
764 - /**
765 - * Restores a quarantined file based on the provided parameters.
766 - *
767 - * @param object $params The parameters for restoring the quarantined file.
768 - * Requires the 'id' property to be set.
769 - *
770 - * @return void
771 - */
772 - public function restore_quarantined_file( object $params ): void {
773 - if ( ! class_exists( 'WP_Defender\Component\Quarantine' ) ) {
774 - $result = array(
775 - 'message' => defender_quarantine_pro_only(),
776 - 'success' => false,
777 - );
778 -
779 - wp_send_json_error( $result );
780 - }
781 -
782 - if ( isset( $params->id ) ) {
783 - $id = (int) $params->id;
784 -
785 - $quarantine_obj = wd_di()->get( Quarantine::class );
786 -
787 - $result = $quarantine_obj->restore_file( $id );
788 -
789 - if ( isset( $result['success'] ) && false === $result['success'] ) {
790 - wp_send_json_error( $result );
791 - }
792 -
793 - wp_send_json_success( $result );
794 - }
795 -
796 - wp_send_json_error(
797 - array(
798 - 'message' => esc_html__( 'Missing parameter: id.', 'defender-security' ),
799 - )
800 729 );
801 730 }
802 731
803 732 /**