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 +69 -25 5.9.0 → 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,11 +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 - // @phpstan-ignore-next-line
300 - return is_callable( array( $this, $task ) ) ? $this->$task() : false;
305 + return false;
301 306 }
302 307 }
303 308
304 309 /**
@@ -335,10 +340,10 @@
335 340 * @return bool True if method Malware_Scan::suspicious_check not exists else bool value returned by that method.
336 341 */
337 342 private function suspicious_check( Malware_Scan $malware_scan ): bool {
338 343 if ( method_exists( $malware_scan, 'suspicious_check' ) ) {
339 - $quick_scan = wd_di()->get( Malware_Quick_Scan::class );
340 - $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 );
341 346
342 347 return $malware_scan->suspicious_check( $quick_scan, $deep_scan );
343 348 }
344 349
@@ -457,8 +462,30 @@
457 462 return $count;
458 463 }
459 464
460 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 + /**
461 488 * Checks if any scan type is active based on the scan settings and the user's membership status.
462 489 *
463 490 * @param array $scan_settings The scan settings.
464 491 *
@@ -463,9 +490,9 @@
463 490 * @param array $scan_settings The scan settings.
464 491 *
465 492 * @return bool Returns true if any scan type is active, false otherwise.
466 493 */
467 - public function is_any_scan_active( $scan_settings ): bool {
494 + public function check_scan_active_by( $scan_settings ): bool {
468 495 if ( ! isset( $scan_settings['integrity_check'] ) || ! $scan_settings['integrity_check'] ) {
469 496 // Check the parent type.
470 497 $file_change_check = false;
471 498 } elseif (
@@ -477,17 +504,19 @@
477 504 $file_change_check = false;
478 505 } else {
479 506 $file_change_check = true;
480 507 }
481 - // Similar to is_any_active(...) method from the controller.
482 - if ( $this->is_pro ) {
483 - // Pro version. Check all parent types.
484 - 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'] )
485 515 || ( isset( $scan_settings['scan_malware'] ) && $scan_settings['scan_malware'] );
486 - } else {
487 - // Free version.
488 - return $file_change_check || ( isset( $scan_settings['check_abandoned_plugin'] ) && $scan_settings['check_abandoned_plugin'] );
489 516 }
517 +
518 + return $check_free_settings;
490 519 }
491 520
492 521 /**
493 522 * Update the idle scan status due the time limit.
@@ -557,8 +586,9 @@
557 586 delete_site_option( Gather_Fact::CACHE_CONTENT );
558 587 delete_site_option( Malware_Scan::YARA_RULES );
559 588 delete_site_option( Core_Integrity::CACHE_CHECKSUMS );
560 589 delete_site_option( Plugin_Integrity::PLUGIN_SLUGS );
590 + delete_site_option( Plugin_Integrity::PLUGIN_SLUGS_CHECKPOINT );
561 591 delete_site_option( Plugin_Integrity::PLUGIN_PREMIUM_SLUGS );
562 592 delete_site_option( self::PLUGINS_ACTIONED );
563 593 $this->maybe_track_failed_checksum();
564 594 }
@@ -638,9 +668,9 @@
638 668 'notice-error'
639 669 );
640 670
641 671 $notice = sprintf(
642 - /* translators: %s - Plugin name. */
672 + /* translators: %s: Plugin name. */
643 673 esc_html__(
644 674 '%s has detected a vulnerability in this plugin that may cause harm to your site.',
645 675 'defender-security'
646 676 ),
@@ -655,9 +685,9 @@
655 685 $notice .= implode( '<br/>', $lines );
656 686 $notice .= '<hr/><span class="vulnerability-indent"></span>';
657 687 if ( '0' !== $last_fixed_in ) {
658 688 $notice .= sprintf(
659 - /* translators: %s - Version number. */
689 + /* translators: %s: Version number. */
660 690 esc_html__(
661 691 'The vulnerability has been fixed in version %s. We recommend that you update this plugin accordingly.',
662 692 'defender-security'
663 693 ),
@@ -676,9 +706,9 @@
676 706 'We recommend that you deactivate this plugin until the vulnerability has been fixed.',
677 707 'defender-security'
678 708 )
679 709 : sprintf(
680 - /* translators: 1: Version number. */
710 + /* translators: %s: Version number. */
681 711 esc_html__(
682 712 'The vulnerability has been fixed in version %s. We recommend that you update this plugin accordingly.',
683 713 'defender-security'
684 714 ),
@@ -829,9 +859,9 @@
829 859 return true;
830 860 }
831 861
832 862 /**
833 - * Gey intentions.
863 + * Get intentions.
834 864 *
835 865 * @since 4.11.0
836 866 * @return array
837 867 */
@@ -861,9 +891,9 @@
861 891 if ( $this->settings->integrity_check && $this->settings->check_plugins ) {
862 892 $is_plugin_used = true;
863 893 } elseif ( $this->settings->check_abandoned_plugin ) {
864 894 $is_plugin_used = true;
865 - } 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 ) ) {
866 896 $is_plugin_used = true;
867 897 }
868 898
869 899 if ( $is_plugin_used ) {
@@ -917,6 +947,20 @@
917 947 * @return string
918 948 */
919 949 public function get_lock_filename(): string {
920 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 );
921 965 }
922 966 }