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/component/class-scan.php +75 -26 5.8.1 → 6.3.0 View file →
@@ -17,10 +17,8 @@
17 17 use WP_Defender\Behavior\Scan\Gather_Fact;
18 18 use WP_Defender\Behavior\Scan\Malware_Scan;
19 19 use WP_Defender\Behavior\Scan\Core_Integrity;
20 20 use WP_Defender\Behavior\Scan\Plugin_Integrity;
21 -use WP_Defender\Behavior\Scan\Malware_Deep_Scan;
22 -use WP_Defender\Behavior\Scan\Malware_Quick_Scan;
23 21 use WP_Defender\Behavior\Scan\Known_Vulnerability;
24 22 use WP_Defender\Behavior\Scan\Abandoned_Plugin;
25 23 use WP_Defender\Model\Setting\Scan as Scan_Settings;
26 24 use WP_Defender\Helper\Analytics\Scan as Scan_Analytics;
@@ -61,9 +59,8 @@
61 59 *
62 60 * @var Known_Vulnerability
63 61 */
64 62 private $known_vulnerability;
65 -
66 63 /**
67 64 * Instance of Malware_Scan to handle malware scanning.
68 65 *
69 66 * @var Malware_Scan
@@ -91,13 +88,13 @@
91 88 */
92 89 protected string $lock_filename = 'scan.lock';
93 90
94 91 /**
95 - * Indicate whether the current installation is a pro version.
92 + * Is the Hub API key available?
96 93 *
97 94 * @var bool
98 95 */
99 - private $is_pro;
96 + private $is_apikey;
100 97
101 98 /**
102 99 * Constructs the Scan object and initializes behaviors.
103 100 */
@@ -104,10 +101,11 @@
104 101 public function __construct() {
105 102 $this->attach_behavior( WPMUDEV::class, WPMUDEV::class );
106 103 $this->attach_behavior( Core_Integrity::class, Core_Integrity::class );
107 104 $this->attach_behavior( Plugin_Integrity::class, Plugin_Integrity::class );
108 - $this->is_pro = wd_di()->get( WPMUDEV::class )->is_pro();
109 - $this->settings = wd_di()->get( Scan_Settings::class );
105 +
106 + $this->is_apikey = wd_di()->get( WPMUDEV::class )->is_apikey_available();
107 + $this->settings = wd_di()->get( Scan_Settings::class );
110 108 }
111 109
112 110 /**
113 111 * Performs additional actions after an advanced scan.
@@ -141,11 +139,13 @@
141 139 if ( Scan_Model::STATUS_INIT === $scan->status ) {
142 140 // Get the first.
143 141 $this->log( 'Prepare facts for a scan', Scan_Controller::SCAN_LOG );
144 142 $task = Scan_Model::STEP_GATHER_INFO;
143 + $this->scan->status = $task;
145 144 $this->scan->percent = 0;
146 145 $this->scan->total_tasks = $runner->count();
147 146 $this->scan->save();
147 + $this->scan->enqueue_status_message( $this->scan->get_status_text() );
148 148 }
149 149 if (
150 150 in_array(
151 151 $this->scan->status,
@@ -181,8 +181,9 @@
181 181 $this->scan->status = $runner->key();
182 182 $this->scan->task_checkpoint = '';
183 183 $this->scan->date_end = gmdate( 'Y-m-d H:i:s' );
184 184 $this->scan->save();
185 + $this->scan->enqueue_status_message( $this->scan->get_status_text() );
185 186 // Queue for next run.
186 187 return false;
187 188 }
188 189 $this->log( 'All done!', Scan_Controller::SCAN_LOG );
@@ -239,9 +240,10 @@
239 240
240 241 if ( $this->settings->check_abandoned_plugin ) {
241 242 $tasks[ Scan_Model::STEP_ABANDONED_PLUGIN_CHECK ] = 'abandoned_plugin_check';
242 243 }
243 - if ( $this->is_pro ) {
244 + // Check if this is HC feature.
245 + if ( $this->is_apikey ) {
244 246 if ( $this->settings->check_known_vuln && $this->has_method( Scan_Model::STEP_VULN_CHECK ) ) {
245 247 $tasks[ Scan_Model::STEP_VULN_CHECK ] = 'vuln_check';
246 248 }
247 249 // The division between PHP and JS files occurs when collecting files.
@@ -294,10 +296,14 @@
294 296 );
295 297 }
296 298
297 299 return $this->abandoned_plugin_check( $this->abandoned_plugin );
300 + case 'core_integrity_check':
301 + return $this->core_integrity_check();
302 + case 'plugin_integrity_check':
303 + return $this->plugin_integrity_check();
298 304 default:
299 - return $this->$task();
305 + return false;
300 306 }
301 307 }
302 308
303 309 /**
@@ -334,10 +340,10 @@
334 340 * @return bool True if method Malware_Scan::suspicious_check not exists else bool value returned by that method.
335 341 */
336 342 private function suspicious_check( Malware_Scan $malware_scan ): bool {
337 343 if ( method_exists( $malware_scan, 'suspicious_check' ) ) {
338 - $quick_scan = wd_di()->get( Malware_Quick_Scan::class );
339 - $deep_scan = wd_di()->get( Malware_Deep_Scan::class );
344 + $quick_scan = wd_di()->get( \WP_Defender\Behavior\Scan\Malware_Quick_Scan::class );
345 + $deep_scan = wd_di()->get( \WP_Defender\Behavior\Scan\Malware_Deep_Scan::class );
340 346
341 347 return $malware_scan->suspicious_check( $quick_scan, $deep_scan );
342 348 }
343 349
@@ -456,8 +462,30 @@
456 462 return $count;
457 463 }
458 464
459 465 /**
466 + * Checks if any scan type is active.
467 + *
468 + * @return bool True if any scan type is active, false otherwise.
469 + */
470 + public function is_any_scan_type_active(): bool {
471 + $settings = $this->settings;
472 + $file_change_check = $settings->is_checked_any_file_change_types();
473 + // Check#1 the 'File change detection' type because only it's available with nested types.
474 + // Check#2 the Abandoned plugin type.
475 + $check_free_settings = $file_change_check || $settings->check_abandoned_plugin;
476 + // Indicates if the API key is available for HC features.
477 + if ( $this->is_apikey ) {
478 + // HC version. Check all parent types.
479 + return $check_free_settings || $settings->check_known_vuln || $settings->scan_malware;
480 + } else {
481 + // Without HC access.
482 + return $check_free_settings;
483 + }
484 + }
485 +
486 +
487 + /**
460 488 * Checks if any scan type is active based on the scan settings and the user's membership status.
461 489 *
462 490 * @param array $scan_settings The scan settings.
463 491 *
@@ -462,9 +490,9 @@
462 490 * @param array $scan_settings The scan settings.
463 491 *
464 492 * @return bool Returns true if any scan type is active, false otherwise.
465 493 */
466 - public function is_any_scan_active( $scan_settings ): bool {
494 + public function check_scan_active_by( $scan_settings ): bool {
467 495 if ( ! isset( $scan_settings['integrity_check'] ) || ! $scan_settings['integrity_check'] ) {
468 496 // Check the parent type.
469 497 $file_change_check = false;
470 498 } elseif (
@@ -476,17 +504,19 @@
476 504 $file_change_check = false;
477 505 } else {
478 506 $file_change_check = true;
479 507 }
480 - // Similar to is_any_active(...) method from the controller.
481 - if ( $this->is_pro ) {
482 - // Pro version. Check all parent types.
483 - return $file_change_check || ( isset( $scan_settings['check_known_vuln'] ) && $scan_settings['check_known_vuln'] )
508 +
509 + $check_free_settings = $file_change_check
510 + || ( isset( $scan_settings['check_abandoned_plugin'] ) && $scan_settings['check_abandoned_plugin'] );
511 + // For HC features.
512 + if ( $this->is_apikey ) {
513 + // Similar to is_any_scan_type_active() method.Check all parent types including HC features.
514 + return $check_free_settings || ( isset( $scan_settings['check_known_vuln'] ) && $scan_settings['check_known_vuln'] )
484 515 || ( isset( $scan_settings['scan_malware'] ) && $scan_settings['scan_malware'] );
485 - } else {
486 - // Free version.
487 - return $file_change_check || ( isset( $scan_settings['check_abandoned_plugin'] ) && $scan_settings['check_abandoned_plugin'] );
488 516 }
517 +
518 + return $check_free_settings;
489 519 }
490 520
491 521 /**
492 522 * Update the idle scan status due the time limit.
@@ -502,9 +532,11 @@
502 532 $ready_to_send = true;
503 533 }
504 534 $this->delete_interim_data();
505 535
506 - as_unschedule_all_actions( 'defender/async_scan' );
536 + if ( function_exists( 'as_unschedule_all_actions' ) ) {
537 + as_unschedule_all_actions( 'defender/async_scan' );
538 + }
507 539
508 540 $idle_scan->status = Scan_Model::STATUS_IDLE;
509 541 $idle_scan->task_checkpoint = 'time_limit';
510 542 $idle_scan->save();
@@ -529,9 +561,11 @@
529 561 $ready_to_send = true;
530 562 }
531 563 $this->delete_interim_data();
532 564
533 - as_unschedule_all_actions( 'defender/async_scan' );
565 + if ( function_exists( 'as_unschedule_all_actions' ) ) {
566 + as_unschedule_all_actions( 'defender/async_scan' );
567 + }
534 568
535 569 $scan->status = Scan_Model::STATUS_IDLE;
536 570 $scan->task_checkpoint = 'checksum_issue';
537 571 $scan->save();
@@ -552,8 +586,9 @@
552 586 delete_site_option( Gather_Fact::CACHE_CONTENT );
553 587 delete_site_option( Malware_Scan::YARA_RULES );
554 588 delete_site_option( Core_Integrity::CACHE_CHECKSUMS );
555 589 delete_site_option( Plugin_Integrity::PLUGIN_SLUGS );
590 + delete_site_option( Plugin_Integrity::PLUGIN_SLUGS_CHECKPOINT );
556 591 delete_site_option( Plugin_Integrity::PLUGIN_PREMIUM_SLUGS );
557 592 delete_site_option( self::PLUGINS_ACTIONED );
558 593 $this->maybe_track_failed_checksum();
559 594 }
@@ -633,9 +668,9 @@
633 668 'notice-error'
634 669 );
635 670
636 671 $notice = sprintf(
637 - /* translators: %s - Plugin name. */
672 + /* translators: %s: Plugin name. */
638 673 esc_html__(
639 674 '%s has detected a vulnerability in this plugin that may cause harm to your site.',
640 675 'defender-security'
641 676 ),
@@ -650,9 +685,9 @@
650 685 $notice .= implode( '<br/>', $lines );
651 686 $notice .= '<hr/><span class="vulnerability-indent"></span>';
652 687 if ( '0' !== $last_fixed_in ) {
653 688 $notice .= sprintf(
654 - /* translators: %s - Version number. */
689 + /* translators: %s: Version number. */
655 690 esc_html__(
656 691 'The vulnerability has been fixed in version %s. We recommend that you update this plugin accordingly.',
657 692 'defender-security'
658 693 ),
@@ -671,9 +706,9 @@
671 706 'We recommend that you deactivate this plugin until the vulnerability has been fixed.',
672 707 'defender-security'
673 708 )
674 709 : sprintf(
675 - /* translators: 1: Version number. */
710 + /* translators: %s: Version number. */
676 711 esc_html__(
677 712 'The vulnerability has been fixed in version %s. We recommend that you update this plugin accordingly.',
678 713 'defender-security'
679 714 ),
@@ -824,9 +859,9 @@
824 859 return true;
825 860 }
826 861
827 862 /**
828 - * Gey intentions.
863 + * Get intentions.
829 864 *
830 865 * @since 4.11.0
831 866 * @return array
832 867 */
@@ -856,9 +891,9 @@
856 891 if ( $this->settings->integrity_check && $this->settings->check_plugins ) {
857 892 $is_plugin_used = true;
858 893 } elseif ( $this->settings->check_abandoned_plugin ) {
859 894 $is_plugin_used = true;
860 - } elseif ( $this->is_pro && ( $this->settings->check_known_vuln || $this->settings->scan_malware ) ) {
895 + } elseif ( $this->is_apikey && ( $this->settings->check_known_vuln || $this->settings->scan_malware ) ) {
861 896 $is_plugin_used = true;
862 897 }
863 898
864 899 if ( $is_plugin_used ) {
@@ -912,6 +947,20 @@
912 947 * @return string
913 948 */
914 949 public function get_lock_filename(): string {
915 950 return $this->lock_filename;
951 + }
952 +
953 + /**
954 + * Get the text for the emergency scan stop case.
955 + *
956 + * @return string
957 + */
958 + public static function get_emergency_scan_stop_text(): string {
959 + $text = __( 'Scan aborted. No scan types are enabled. Enable at least one scan type under Defender > Settings > Tools before running a scan.', 'defender-security' );
960 + if ( defender_is_wp_cli() ) {
961 + return $text;
962 + }
963 +
964 + return esc_html( $text );
916 965 }
917 966 }