| @@ -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; |
| @@ -29,9 +27,13 @@ | ||
| 29 | 27 | /** |
| 30 | 28 | * The Scan class handles the scanning process, managing tasks, and coordinating different types of scans. |
| 31 | 29 | */ |
| 32 | 30 | class Scan extends Component { |
| 31 | + use \WP_Defender\Traits\Plugin; | |
| 33 | 32 | |
| 33 | + // For all Scan types where plugins are used. | |
| 34 | + public const PLUGINS_ACTIONED = 'wp-defender-actioned-plugins'; | |
| 35 | + | |
| 34 | 36 | /** |
| 35 | 37 | * The current scan model. |
| 36 | 38 | * |
| 37 | 39 | * @var Scan_Model |
| @@ -57,9 +59,8 @@ | ||
| 57 | 59 | * |
| 58 | 60 | * @var Known_Vulnerability |
| 59 | 61 | */ |
| 60 | 62 | private $known_vulnerability; |
| 61 | - | |
| 62 | 63 | /** |
| 63 | 64 | * Instance of Malware_Scan to handle malware scanning. |
| 64 | 65 | * |
| 65 | 66 | * @var Malware_Scan |
| @@ -70,9 +71,9 @@ | ||
| 70 | 71 | * Instance of Gather_Fact to gather necessary information before scanning. |
| 71 | 72 | * |
| 72 | 73 | * @var Gather_Fact|null |
| 73 | 74 | */ |
| 74 | - private ?Gather_Fact $gather_fact; | |
| 75 | + private ?Gather_Fact $gather_fact = null; | |
| 75 | 76 | |
| 76 | 77 | /** |
| 77 | 78 | * Instance of Abandoned_Plugin to handle abandoned plugin checks. |
| 78 | 79 | * |
| @@ -87,8 +88,15 @@ | ||
| 87 | 88 | */ |
| 88 | 89 | protected string $lock_filename = 'scan.lock'; |
| 89 | 90 | |
| 90 | 91 | /** |
| 92 | + * Is the Hub API key available? | |
| 93 | + * | |
| 94 | + * @var bool | |
| 95 | + */ | |
| 96 | + private $is_apikey; | |
| 97 | + | |
| 98 | + /** | |
| 91 | 99 | * Constructs the Scan object and initializes behaviors. |
| 92 | 100 | */ |
| 93 | 101 | public function __construct() { |
| 94 | 102 | $this->attach_behavior( WPMUDEV::class, WPMUDEV::class ); |
| @@ -93,14 +101,17 @@ | ||
| 93 | 101 | public function __construct() { |
| 94 | 102 | $this->attach_behavior( WPMUDEV::class, WPMUDEV::class ); |
| 95 | 103 | $this->attach_behavior( Core_Integrity::class, Core_Integrity::class ); |
| 96 | 104 | $this->attach_behavior( Plugin_Integrity::class, Plugin_Integrity::class ); |
| 105 | + | |
| 106 | + $this->is_apikey = wd_di()->get( WPMUDEV::class )->is_apikey_available(); | |
| 107 | + $this->settings = wd_di()->get( Scan_Settings::class ); | |
| 97 | 108 | } |
| 98 | 109 | |
| 99 | 110 | /** |
| 100 | 111 | * Performs additional actions after an advanced scan. |
| 101 | 112 | * |
| 102 | - * @param object $model The scan model. | |
| 113 | + * @param Scan_Model $model The scan model. | |
| 103 | 114 | */ |
| 104 | 115 | public function advanced_scan_actions( $model ) { |
| 105 | 116 | $this->reindex_ignored_issues( $model ); |
| 106 | 117 | $this->clean_up(); |
| @@ -128,11 +139,13 @@ | ||
| 128 | 139 | if ( Scan_Model::STATUS_INIT === $scan->status ) { |
| 129 | 140 | // Get the first. |
| 130 | 141 | $this->log( 'Prepare facts for a scan', Scan_Controller::SCAN_LOG ); |
| 131 | 142 | $task = Scan_Model::STEP_GATHER_INFO; |
| 143 | + $this->scan->status = $task; | |
| 132 | 144 | $this->scan->percent = 0; |
| 133 | 145 | $this->scan->total_tasks = $runner->count(); |
| 134 | 146 | $this->scan->save(); |
| 147 | + $this->scan->enqueue_status_message( $this->scan->get_status_text() ); | |
| 135 | 148 | } |
| 136 | 149 | if ( |
| 137 | 150 | in_array( |
| 138 | 151 | $this->scan->status, |
| @@ -168,8 +181,9 @@ | ||
| 168 | 181 | $this->scan->status = $runner->key(); |
| 169 | 182 | $this->scan->task_checkpoint = ''; |
| 170 | 183 | $this->scan->date_end = gmdate( 'Y-m-d H:i:s' ); |
| 171 | 184 | $this->scan->save(); |
| 185 | + $this->scan->enqueue_status_message( $this->scan->get_status_text() ); | |
| 172 | 186 | // Queue for next run. |
| 173 | 187 | return false; |
| 174 | 188 | } |
| 175 | 189 | $this->log( 'All done!', Scan_Controller::SCAN_LOG ); |
| @@ -212,10 +226,9 @@ | ||
| 212 | 226 | * |
| 213 | 227 | * @return array |
| 214 | 228 | */ |
| 215 | 229 | public function get_tasks(): array { |
| 216 | - $this->settings = new Scan_Settings(); | |
| 217 | - $tasks = array( Scan_Model::STEP_GATHER_INFO => 'gather_info' ); | |
| 230 | + $tasks = array( Scan_Model::STEP_GATHER_INFO => 'gather_info' ); | |
| 218 | 231 | if ( $this->settings->integrity_check ) { |
| 219 | 232 | // Nested options. |
| 220 | 233 | if ( $this->settings->check_core ) { |
| 221 | 234 | $tasks[ Scan_Model::STEP_CHECK_CORE ] = 'core_integrity_check'; |
| @@ -227,18 +240,17 @@ | ||
| 227 | 240 | |
| 228 | 241 | if ( $this->settings->check_abandoned_plugin ) { |
| 229 | 242 | $tasks[ Scan_Model::STEP_ABANDONED_PLUGIN_CHECK ] = 'abandoned_plugin_check'; |
| 230 | 243 | } |
| 231 | - if ( $this->is_pro() ) { | |
| 232 | - if ( $this->settings->check_known_vuln ) { | |
| 233 | - if ( $this->has_method( Scan_Model::STEP_VULN_CHECK ) ) { | |
| 234 | - $tasks[ Scan_Model::STEP_VULN_CHECK ] = 'vuln_check'; | |
| 235 | - } | |
| 244 | + // Check if this is HC feature. | |
| 245 | + if ( $this->is_apikey ) { | |
| 246 | + if ( $this->settings->check_known_vuln && $this->has_method( Scan_Model::STEP_VULN_CHECK ) ) { | |
| 247 | + $tasks[ Scan_Model::STEP_VULN_CHECK ] = 'vuln_check'; | |
| 236 | 248 | } |
| 237 | - if ( $this->settings->scan_malware ) { | |
| 238 | - if ( $this->has_method( Scan_Model::STEP_SUSPICIOUS_CHECK ) ) { | |
| 239 | - $tasks[ Scan_Model::STEP_SUSPICIOUS_CHECK ] = 'suspicious_check'; | |
| 240 | - } | |
| 249 | + // The division between PHP and JS files occurs when collecting files. | |
| 250 | + if ( $this->settings->scan_malware && $this->has_method( Scan_Model::STEP_SUSPICIOUS_CHECK ) | |
| 251 | + ) { | |
| 252 | + $tasks[ Scan_Model::STEP_SUSPICIOUS_CHECK ] = 'suspicious_check'; | |
| 241 | 253 | } |
| 242 | 254 | } |
| 243 | 255 | |
| 244 | 256 | return $tasks; |
| @@ -253,9 +265,9 @@ | ||
| 253 | 265 | */ |
| 254 | 266 | private function task_handler( $task ) { |
| 255 | 267 | switch ( $task ) { |
| 256 | 268 | case 'gather_info': |
| 257 | - if ( empty( $this->gather_fact ) && class_exists( Gather_Fact::class ) ) { | |
| 269 | + if ( ! ( $this->gather_fact instanceof Gather_Fact ) && class_exists( Gather_Fact::class ) ) { | |
| 258 | 270 | $this->set_gather_fact( |
| 259 | 271 | wd_di()->make( Gather_Fact::class, array( 'scan' => $this->scan ) ) |
| 260 | 272 | ); |
| 261 | 273 | } |
| @@ -261,9 +273,9 @@ | ||
| 261 | 273 | } |
| 262 | 274 | |
| 263 | 275 | return $this->gather_info( $this->gather_fact ); |
| 264 | 276 | case 'vuln_check': |
| 265 | - if ( empty( $this->known_vulnerability ) && class_exists( Known_Vulnerability::class ) ) { | |
| 277 | + if ( ! ( $this->known_vulnerability instanceof Known_Vulnerability ) && class_exists( Known_Vulnerability::class ) ) { | |
| 266 | 278 | $this->set_known_vulnerability( |
| 267 | 279 | wd_di()->make( Known_Vulnerability::class, array( 'scan' => $this->scan ) ) |
| 268 | 280 | ); |
| 269 | 281 | } |
| @@ -277,9 +289,9 @@ | ||
| 277 | 289 | } |
| 278 | 290 | |
| 279 | 291 | return $this->suspicious_check( $this->malware_scan ); |
| 280 | 292 | case 'abandoned_plugin_check': |
| 281 | - if ( empty( $this->abandoned_plugin ) && class_exists( Abandoned_Plugin::class ) ) { | |
| 293 | + if ( ! ( $this->abandoned_plugin instanceof Abandoned_Plugin ) && class_exists( Abandoned_Plugin::class ) ) { | |
| 282 | 294 | $this->set_abandoned_plugin( |
| 283 | 295 | wd_di()->make( Abandoned_Plugin::class, array( 'scan' => $this->scan ) ) |
| 284 | 296 | ); |
| 285 | 297 | } |
| @@ -284,10 +296,14 @@ | ||
| 284 | 296 | ); |
| 285 | 297 | } |
| 286 | 298 | |
| 287 | 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(); | |
| 288 | 304 | default: |
| 289 | - return $this->$task(); | |
| 305 | + return false; | |
| 290 | 306 | } |
| 291 | 307 | } |
| 292 | 308 | |
| 293 | 309 | /** |
| @@ -316,9 +332,9 @@ | ||
| 316 | 332 | } |
| 317 | 333 | } |
| 318 | 334 | |
| 319 | 335 | /** |
| 320 | - * A wrapper method for Malware_Scan class method vuln_check. | |
| 336 | + * A wrapper method for Malware_Scan class method suspicious_check. | |
| 321 | 337 | * |
| 322 | 338 | * @param Malware_Scan $malware_scan An instance of Malware_Scan. |
| 323 | 339 | * |
| 324 | 340 | * @return bool True if method Malware_Scan::suspicious_check not exists else bool value returned by that method. |
| @@ -324,10 +340,10 @@ | ||
| 324 | 340 | * @return bool True if method Malware_Scan::suspicious_check not exists else bool value returned by that method. |
| 325 | 341 | */ |
| 326 | 342 | private function suspicious_check( Malware_Scan $malware_scan ): bool { |
| 327 | 343 | if ( method_exists( $malware_scan, 'suspicious_check' ) ) { |
| 328 | - $quick_scan = wd_di()->get( Malware_Quick_Scan::class ); | |
| 329 | - $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 ); | |
| 330 | 346 | |
| 331 | 347 | return $malware_scan->suspicious_check( $quick_scan, $deep_scan ); |
| 332 | 348 | } |
| 333 | 349 | |
| @@ -379,9 +395,9 @@ | ||
| 379 | 395 | if ( is_object( $scan ) ) { |
| 380 | 396 | $scan->delete(); |
| 381 | 397 | } |
| 382 | 398 | $this->clean_up(); |
| 383 | - $this->remove_lock(); | |
| 399 | + $this->remove_lock( $this->lock_filename ); | |
| 384 | 400 | |
| 385 | 401 | $scan_analytics = wd_di()->get( Scan_Analytics::class ); |
| 386 | 402 | |
| 387 | 403 | $scan_analytics->track_feature( |
| @@ -420,9 +436,9 @@ | ||
| 420 | 436 | public function clean_up() { |
| 421 | 437 | $this->delete_interim_data(); |
| 422 | 438 | |
| 423 | 439 | $models = Scan_Model::get_last_all(); |
| 424 | - if ( ! empty( $models ) ) { | |
| 440 | + if ( is_array( $models ) && array() !== $models ) { | |
| 425 | 441 | // Remove the latest. Don't remove code to find the first value. |
| 426 | 442 | $current = array_shift( $models ); |
| 427 | 443 | foreach ( $models as $model ) { |
| 428 | 444 | $model->delete(); |
| @@ -446,23 +462,44 @@ | ||
| 446 | 462 | return $count; |
| 447 | 463 | } |
| 448 | 464 | |
| 449 | 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 | + /** | |
| 450 | 488 | * Checks if any scan type is active based on the scan settings and the user's membership status. |
| 451 | 489 | * |
| 452 | 490 | * @param array $scan_settings The scan settings. |
| 453 | - * @param bool $is_pro Whether the user has a pro membership. | |
| 454 | 491 | * |
| 455 | 492 | * @return bool Returns true if any scan type is active, false otherwise. |
| 456 | 493 | */ |
| 457 | - public function is_any_scan_active( $scan_settings, $is_pro ): bool { | |
| 458 | - if ( empty( $scan_settings['integrity_check'] ) ) { | |
| 494 | + public function check_scan_active_by( $scan_settings ): bool { | |
| 495 | + if ( ! isset( $scan_settings['integrity_check'] ) || ! $scan_settings['integrity_check'] ) { | |
| 459 | 496 | // Check the parent type. |
| 460 | 497 | $file_change_check = false; |
| 461 | 498 | } elseif ( |
| 462 | - ! empty( $scan_settings['integrity_check'] ) | |
| 463 | - && empty( $scan_settings['check_core'] ) | |
| 464 | - && empty( $scan_settings['check_plugins'] ) | |
| 499 | + $scan_settings['integrity_check'] | |
| 500 | + && ( ! isset( $scan_settings['check_core'] ) || ! $scan_settings['check_core'] ) | |
| 501 | + && ( ! isset( $scan_settings['check_plugins'] ) || ! $scan_settings['check_plugins'] ) | |
| 465 | 502 | ) { |
| 466 | 503 | // Check the parent and child types. |
| 467 | 504 | $file_change_check = false; |
| 468 | 505 | } else { |
| @@ -467,17 +504,19 @@ | ||
| 467 | 504 | $file_change_check = false; |
| 468 | 505 | } else { |
| 469 | 506 | $file_change_check = true; |
| 470 | 507 | } |
| 471 | - // Similar to is_any_active(...) method from the controller. | |
| 472 | - if ( $is_pro ) { | |
| 473 | - // Pro version. Check all parent types. | |
| 474 | - return $file_change_check || ! empty( $scan_settings['check_known_vuln'] ) | |
| 475 | - || ! empty( $scan_settings['scan_malware'] ); | |
| 476 | - } else { | |
| 477 | - // Free version. | |
| 478 | - return $file_change_check || ! empty( $scan_settings['check_abandoned_plugin'] ); | |
| 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'] ) | |
| 515 | + || ( isset( $scan_settings['scan_malware'] ) && $scan_settings['scan_malware'] ); | |
| 479 | 516 | } |
| 517 | + | |
| 518 | + return $check_free_settings; | |
| 480 | 519 | } |
| 481 | 520 | |
| 482 | 521 | /** |
| 483 | 522 | * Update the idle scan status due the time limit. |
| @@ -493,15 +532,17 @@ | ||
| 493 | 532 | $ready_to_send = true; |
| 494 | 533 | } |
| 495 | 534 | $this->delete_interim_data(); |
| 496 | 535 | |
| 497 | - as_unschedule_all_actions( 'defender/async_scan' ); | |
| 536 | + if ( function_exists( 'as_unschedule_all_actions' ) ) { | |
| 537 | + as_unschedule_all_actions( 'defender/async_scan' ); | |
| 538 | + } | |
| 498 | 539 | |
| 499 | 540 | $idle_scan->status = Scan_Model::STATUS_IDLE; |
| 500 | 541 | $idle_scan->task_checkpoint = 'time_limit'; |
| 501 | 542 | $idle_scan->save(); |
| 502 | 543 | |
| 503 | - $this->remove_lock(); | |
| 544 | + $this->remove_lock( $this->lock_filename ); | |
| 504 | 545 | if ( $ready_to_send ) { |
| 505 | 546 | do_action( 'defender_notify', 'malware-notification', $idle_scan ); |
| 506 | 547 | } |
| 507 | 548 | } |
| @@ -520,15 +561,17 @@ | ||
| 520 | 561 | $ready_to_send = true; |
| 521 | 562 | } |
| 522 | 563 | $this->delete_interim_data(); |
| 523 | 564 | |
| 524 | - as_unschedule_all_actions( 'defender/async_scan' ); | |
| 565 | + if ( function_exists( 'as_unschedule_all_actions' ) ) { | |
| 566 | + as_unschedule_all_actions( 'defender/async_scan' ); | |
| 567 | + } | |
| 525 | 568 | |
| 526 | 569 | $scan->status = Scan_Model::STATUS_IDLE; |
| 527 | 570 | $scan->task_checkpoint = 'checksum_issue'; |
| 528 | 571 | $scan->save(); |
| 529 | 572 | |
| 530 | - $this->remove_lock(); | |
| 573 | + $this->remove_lock( $this->lock_filename ); | |
| 531 | 574 | if ( $ready_to_send ) { |
| 532 | 575 | do_action( 'defender_notify', 'malware-notification', $scan ); |
| 533 | 576 | } |
| 534 | 577 | } |
| @@ -543,9 +586,11 @@ | ||
| 543 | 586 | delete_site_option( Gather_Fact::CACHE_CONTENT ); |
| 544 | 587 | delete_site_option( Malware_Scan::YARA_RULES ); |
| 545 | 588 | delete_site_option( Core_Integrity::CACHE_CHECKSUMS ); |
| 546 | 589 | delete_site_option( Plugin_Integrity::PLUGIN_SLUGS ); |
| 590 | + delete_site_option( Plugin_Integrity::PLUGIN_SLUGS_CHECKPOINT ); | |
| 547 | 591 | delete_site_option( Plugin_Integrity::PLUGIN_PREMIUM_SLUGS ); |
| 592 | + delete_site_option( self::PLUGINS_ACTIONED ); | |
| 548 | 593 | $this->maybe_track_failed_checksum(); |
| 549 | 594 | } |
| 550 | 595 | |
| 551 | 596 | /** |
| @@ -576,20 +621,20 @@ | ||
| 576 | 621 | 'WP_Plugins_List_Table', |
| 577 | 622 | array( 'screen' => get_current_screen() ) |
| 578 | 623 | ); |
| 579 | 624 | $bugs = $this->vulnerability_details[ $file ]['bugs']; |
| 580 | - if ( empty( $bugs ) ) { | |
| 625 | + if ( ! is_array( $bugs ) || array() === $bugs ) { | |
| 581 | 626 | return; |
| 582 | 627 | } |
| 583 | 628 | $last_fixed_in = '0'; |
| 584 | 629 | // Check if there have been updates since the last scan. |
| 585 | 630 | $exist_update = true; |
| 586 | - if ( isset( $plugin_data['Version'] ) && ! empty( $plugin_data['Version'] ) ) { | |
| 631 | + if ( isset( $plugin_data['Version'] ) && '' !== $plugin_data['Version'] ) { | |
| 587 | 632 | // The current plugin version. |
| 588 | 633 | $current_version = $plugin_data['Version']; |
| 589 | 634 | foreach ( $bugs as $bug_details ) { |
| 590 | 635 | // If the fixed version is existed then get the latest one. |
| 591 | - if ( isset( $bug_details['fixed_in'] ) && ! empty( $bug_details['fixed_in'] ) | |
| 636 | + if ( isset( $bug_details['fixed_in'] ) && '' !== $bug_details['fixed_in'] | |
| 592 | 637 | && version_compare( $bug_details['fixed_in'], $last_fixed_in, '>' ) |
| 593 | 638 | ) { |
| 594 | 639 | $last_fixed_in = $bug_details['fixed_in']; |
| 595 | 640 | } |
| @@ -601,9 +646,9 @@ | ||
| 601 | 646 | // If there were updates, do not display notice. |
| 602 | 647 | if ( $exist_update ) { |
| 603 | 648 | return; |
| 604 | 649 | } |
| 605 | - if ( empty( $plugin_data['slug'] ) && isset( $this->vulnerability_details[ $file ]['base_slug'] ) ) { | |
| 650 | + if ( ( ! isset( $plugin_data['slug'] ) || '' === $plugin_data['slug'] ) && isset( $this->vulnerability_details[ $file ]['base_slug'] ) ) { | |
| 606 | 651 | $plugin_data['slug'] = $this->vulnerability_details[ $file ]['base_slug']; |
| 607 | 652 | } |
| 608 | 653 | |
| 609 | 654 | if ( is_network_admin() || ! is_multisite() ) { |
| @@ -623,9 +668,9 @@ | ||
| 623 | 668 | 'notice-error' |
| 624 | 669 | ); |
| 625 | 670 | |
| 626 | 671 | $notice = sprintf( |
| 627 | - /* translators: %s - Plugin name. */ | |
| 672 | + /* translators: %s: Plugin name. */ | |
| 628 | 673 | esc_html__( |
| 629 | 674 | '%s has detected a vulnerability in this plugin that may cause harm to your site.', |
| 630 | 675 | 'defender-security' |
| 631 | 676 | ), |
| @@ -640,9 +685,9 @@ | ||
| 640 | 685 | $notice .= implode( '<br/>', $lines ); |
| 641 | 686 | $notice .= '<hr/><span class="vulnerability-indent"></span>'; |
| 642 | 687 | if ( '0' !== $last_fixed_in ) { |
| 643 | 688 | $notice .= sprintf( |
| 644 | - /* translators: %s - Version number. */ | |
| 689 | + /* translators: %s: Version number. */ | |
| 645 | 690 | esc_html__( |
| 646 | 691 | 'The vulnerability has been fixed in version %s. We recommend that you update this plugin accordingly.', |
| 647 | 692 | 'defender-security' |
| 648 | 693 | ), |
| @@ -655,15 +700,15 @@ | ||
| 655 | 700 | ); |
| 656 | 701 | } |
| 657 | 702 | } else { |
| 658 | 703 | $notice .= '<br/><span class="vulnerability-indent"></span>' . $bugs[0]['title'] . '<br/><span class="vulnerability-indent"></span>'; |
| 659 | - $notice .= empty( $last_fixed_in ) | |
| 704 | + $notice .= '0' === $last_fixed_in | |
| 660 | 705 | ? esc_html__( |
| 661 | 706 | 'We recommend that you deactivate this plugin until the vulnerability has been fixed.', |
| 662 | 707 | 'defender-security' |
| 663 | 708 | ) |
| 664 | 709 | : sprintf( |
| 665 | - /* translators: 1: Version number. */ | |
| 710 | + /* translators: %s: Version number. */ | |
| 666 | 711 | esc_html__( |
| 667 | 712 | 'The vulnerability has been fixed in version %s. We recommend that you update this plugin accordingly.', |
| 668 | 713 | 'defender-security' |
| 669 | 714 | ), |
| @@ -687,9 +732,9 @@ | ||
| 687 | 732 | |
| 688 | 733 | $last = Scan_Model::get_last(); |
| 689 | 734 | if ( is_object( $last ) && ! is_wp_error( $last ) ) { |
| 690 | 735 | $vulnerability_issues = $last->get_issues( Scan_Item::TYPE_VULNERABILITY ); |
| 691 | - if ( empty( $vulnerability_issues ) ) { | |
| 736 | + if ( ! is_array( $vulnerability_issues ) || array() === $vulnerability_issues ) { | |
| 692 | 737 | return; |
| 693 | 738 | } |
| 694 | 739 | |
| 695 | 740 | add_action( 'admin_print_styles-plugins.php', array( $this, 'show_plugin_admin_styles' ) ); |
| @@ -718,12 +763,12 @@ | ||
| 718 | 763 | */ |
| 719 | 764 | public static function clear_logs() { |
| 720 | 765 | global $wpdb; |
| 721 | 766 | |
| 722 | - $table_actions = ! empty( $wpdb->actionscheduler_actions ) ? | |
| 767 | + $table_actions = isset( $wpdb->actionscheduler_actions ) && '' !== $wpdb->actionscheduler_actions ? | |
| 723 | 768 | $wpdb->actionscheduler_actions : |
| 724 | 769 | $wpdb->prefix . 'actionscheduler_actions'; |
| 725 | - $table_logs = ! empty( $wpdb->actionscheduler_logs ) ? | |
| 770 | + $table_logs = isset( $wpdb->actionscheduler_logs ) && '' !== $wpdb->actionscheduler_logs ? | |
| 726 | 771 | $wpdb->actionscheduler_logs : |
| 727 | 772 | $wpdb->prefix . 'actionscheduler_logs'; |
| 728 | 773 | |
| 729 | 774 | $table_count = (int) $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery |
| @@ -752,9 +797,9 @@ | ||
| 752 | 797 | $limit |
| 753 | 798 | ) |
| 754 | 799 | ); |
| 755 | 800 | while ( $action_ids ) { |
| 756 | - if ( empty( $action_ids ) ) { | |
| 801 | + if ( ! is_array( $action_ids ) || array() === $action_ids ) { | |
| 757 | 802 | break; |
| 758 | 803 | } |
| 759 | 804 | |
| 760 | 805 | $query = "DELETE as_actions, as_logs FROM {$table_actions} as_actions LEFT JOIN {$table_logs} as_logs ON as_actions.action_id = as_logs.action_id WHERE as_actions.action_id IN ( " . implode( |
| @@ -814,9 +859,9 @@ | ||
| 814 | 859 | return true; |
| 815 | 860 | } |
| 816 | 861 | |
| 817 | 862 | /** |
| 818 | - * Gey intentions. | |
| 863 | + * Get intentions. | |
| 819 | 864 | * |
| 820 | 865 | * @since 4.11.0 |
| 821 | 866 | * @return array |
| 822 | 867 | */ |
| @@ -827,6 +872,95 @@ | ||
| 827 | 872 | 'delete', |
| 828 | 873 | 'unignore', |
| 829 | 874 | 'quarantine', |
| 830 | 875 | ); |
| 876 | + } | |
| 877 | + | |
| 878 | + /** | |
| 879 | + * Get the list of actioned plugins taking into account the Ignored and Excluded. | |
| 880 | + * | |
| 881 | + * @return array | |
| 882 | + */ | |
| 883 | + public function gather_actioned_plugin_details(): array { | |
| 884 | + $cache = get_site_option( self::PLUGINS_ACTIONED ); | |
| 885 | + if ( self::are_actioned_plugins( $cache ) ) { | |
| 886 | + return $cache; | |
| 887 | + } | |
| 888 | + | |
| 889 | + $items = array(); | |
| 890 | + $is_plugin_used = false; | |
| 891 | + if ( $this->settings->integrity_check && $this->settings->check_plugins ) { | |
| 892 | + $is_plugin_used = true; | |
| 893 | + } elseif ( $this->settings->check_abandoned_plugin ) { | |
| 894 | + $is_plugin_used = true; | |
| 895 | + } elseif ( $this->is_apikey && ( $this->settings->check_known_vuln || $this->settings->scan_malware ) ) { | |
| 896 | + $is_plugin_used = true; | |
| 897 | + } | |
| 898 | + | |
| 899 | + if ( $is_plugin_used ) { | |
| 900 | + $model = Scan_Model::get_last(); | |
| 901 | + /** | |
| 902 | + * Exclude plugin slugs. | |
| 903 | + * | |
| 904 | + * @param array $slugs Slugs of excluded plugins. | |
| 905 | + * | |
| 906 | + * @since 3.1.0 | |
| 907 | + */ | |
| 908 | + $excluded_slugs = apply_filters( 'wd_scan_excluded_plugin_slugs', array() ); | |
| 909 | + $excluded_slugs = ! is_array( $excluded_slugs ) ? (array) $excluded_slugs : $excluded_slugs; | |
| 910 | + | |
| 911 | + foreach ( $this->get_plugins() as $slug => $item ) { | |
| 912 | + if ( is_object( $model ) && $model->is_issue_ignored( $slug ) ) { | |
| 913 | + continue; | |
| 914 | + } | |
| 915 | + $base_slug = $this->get_plugin_slug_by( $slug ); | |
| 916 | + if ( in_array( $base_slug, $excluded_slugs, true ) ) { | |
| 917 | + continue; | |
| 918 | + } | |
| 919 | + // Use keys with the first capital letter to match default plugin header keys. | |
| 920 | + $items[ $base_slug ] = array( | |
| 921 | + 'Name' => $item['Name'], | |
| 922 | + 'Version' => $item['Version'], | |
| 923 | + 'Slug' => $slug, | |
| 924 | + ); | |
| 925 | + } | |
| 926 | + | |
| 927 | + update_site_option( self::PLUGINS_ACTIONED, $items ); | |
| 928 | + } | |
| 929 | + | |
| 930 | + return $items; | |
| 931 | + } | |
| 932 | + | |
| 933 | + /** | |
| 934 | + * Does the list of actioned plugins exist and no empty? | |
| 935 | + * | |
| 936 | + * @param array|false $actioned_plugins The actioned plugins. | |
| 937 | + * | |
| 938 | + * @return bool | |
| 939 | + */ | |
| 940 | + public static function are_actioned_plugins( $actioned_plugins ): bool { | |
| 941 | + return is_array( $actioned_plugins ) && array() !== $actioned_plugins; | |
| 942 | + } | |
| 943 | + | |
| 944 | + /** | |
| 945 | + * Get the lock filename. | |
| 946 | + * | |
| 947 | + * @return string | |
| 948 | + */ | |
| 949 | + public function get_lock_filename(): string { | |
| 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 ); | |
| 831 | 965 | } |
| 832 | 966 | } |