| @@ -41,13 +41,17 @@ | ||
| 41 | 41 | use WP_Defender\Model\Setting\Main_Setting as Model_Main_Setting; |
| 42 | 42 | use WP_Defender\Model\Setting\Audit_Logging as Model_Audit_Logging; |
| 43 | 43 | use WP_Defender\Model\Setting\Login_Lockout as Model_Login_Lockout; |
| 44 | 44 | use WP_Defender\Model\Setting\User_Agent_Lockout as Model_Ua_Lockout; |
| 45 | +use WP_Defender\Model\Setting\Strong_Password as Strong_Password_Model; | |
| 45 | 46 | use WP_Defender\Model\Setting\Security_Tweaks as Model_Security_Tweaks; |
| 47 | +use WP_Defender\Controller\Strong_Password as Strong_Password_Controller; | |
| 46 | 48 | use WP_Defender\Controller\Security_Tweaks as Controller_Security_Tweaks; |
| 47 | 49 | use WP_Defender\Model\Setting\Notfound_Lockout as Model_Notfound_Lockout; |
| 48 | 50 | use WP_Defender\Model\Setting\Security_Headers as Model_Security_Headers; |
| 49 | 51 | use WP_Defender\Model\Setting\Blacklist_Lockout as Model_Blacklist_Lockout; |
| 52 | +use WP_Defender\Model\Setting\Session_Protection as Session_Protection_Model; | |
| 53 | +use WP_Defender\Controller\Session_Protection as Session_Protection_Controller; | |
| 50 | 54 | use WP_Defender\Model\Setting\Password_Protection as Model_Password_Protection; |
| 51 | 55 | use WP_Defender\Controller\Password_Protection as Controller_Password_Protection; |
| 52 | 56 | |
| 53 | 57 | /** |
| @@ -59,13 +63,13 @@ | ||
| 59 | 63 | |
| 60 | 64 | public const KEY = 'defender_last_settings', INDEXER = 'defender_config_indexer'; |
| 61 | 65 | |
| 62 | 66 | /** |
| 63 | - * Indicates whether the current installation is a pro version. | |
| 67 | + * Indicates whether the site has a HUB API key (true for both free and pro with Hub connected). | |
| 64 | 68 | * |
| 65 | 69 | * @var bool |
| 66 | 70 | */ |
| 67 | - private $is_pro; | |
| 71 | + private $has_hub_api_key; | |
| 68 | 72 | |
| 69 | 73 | /** |
| 70 | 74 | * Constructor for the Backup_Settings class. |
| 71 | 75 | * It initializes the class and sets whether the current installation is a pro version. |
| @@ -70,9 +74,10 @@ | ||
| 70 | 74 | * Constructor for the Backup_Settings class. |
| 71 | 75 | * It initializes the class and sets whether the current installation is a pro version. |
| 72 | 76 | */ |
| 73 | 77 | public function __construct() { |
| 74 | - $this->is_pro = ( new WPMUDEV() )->is_pro(); | |
| 78 | + $wpmudev = wd_di()->get( WPMUDEV::class ); | |
| 79 | + $this->has_hub_api_key = $wpmudev->is_apikey_available(); | |
| 75 | 80 | } |
| 76 | 81 | |
| 77 | 82 | /** |
| 78 | 83 | * Changes the format of subscribers in a notification object to an array format. |
| @@ -88,17 +93,17 @@ | ||
| 88 | 93 | && ! is_array( $notification_object->out_house_recipients ) |
| 89 | 94 | ) { |
| 90 | 95 | return array(); |
| 91 | 96 | } |
| 92 | - if ( empty( $notification_object->in_house_recipients ) && empty( $notification_object->out_house_recipients ) ) { | |
| 97 | + if ( array() === $notification_object->in_house_recipients && array() === $notification_object->out_house_recipients ) { | |
| 93 | 98 | return array(); |
| 94 | 99 | } |
| 95 | 100 | |
| 96 | 101 | $subscribers = array(); |
| 97 | - if ( ! empty( $notification_object->in_house_recipients ) ) { | |
| 102 | + if ( array() !== $notification_object->in_house_recipients ) { | |
| 98 | 103 | $subscribers['in_house_recipients'] = $notification_object->in_house_recipients; |
| 99 | 104 | } |
| 100 | - if ( ! empty( $notification_object->out_house_recipients ) ) { | |
| 105 | + if ( array() !== $notification_object->out_house_recipients ) { | |
| 101 | 106 | $subscribers['out_house_recipients'] = $notification_object->out_house_recipients; |
| 102 | 107 | } |
| 103 | 108 | |
| 104 | 109 | return $subscribers; |
| @@ -115,10 +120,8 @@ | ||
| 115 | 120 | $tweak_class->refresh_tweaks_status(); |
| 116 | 121 | $settings = new Model_Security_Tweaks(); |
| 117 | 122 | $tweak_notification = new Tweak_Reminder(); |
| 118 | 123 | $security_tweaks = array( |
| 119 | - 'notification_repeat' => $tweak_notification->configs['reminder'], | |
| 120 | - 'subscribers' => $this->change_subscriber_format( $tweak_notification ), | |
| 121 | 124 | 'notification' => $tweak_notification->status, |
| 122 | 125 | 'data' => $settings->data, |
| 123 | 126 | 'fixed' => $settings->fixed, |
| 124 | 127 | 'issues' => $settings->issues, |
| @@ -136,8 +139,9 @@ | ||
| 136 | 139 | 'check_plugins' => $settings->check_plugins, |
| 137 | 140 | 'check_known_vuln' => $settings->check_known_vuln, |
| 138 | 141 | 'scan_malware' => $settings->scan_malware, |
| 139 | 142 | 'filesize' => $settings->filesize, |
| 143 | + 'check_abandoned_plugin' => $settings->check_abandoned_plugin, | |
| 140 | 144 | // @since 2.7.0 changes for Scheduled options. |
| 141 | 145 | 'scheduled_scanning' => $settings->scheduled_scanning, |
| 142 | 146 | 'day' => $settings->day, |
| 143 | 147 | 'day_n' => $settings->day_n, |
| @@ -163,9 +167,9 @@ | ||
| 163 | 167 | $settings = new Model_Audit_Logging(); |
| 164 | 168 | $audit_report = new Audit_Report(); |
| 165 | 169 | $audit = array( |
| 166 | 170 | 'enabled' => $settings->is_active(), |
| 167 | - 'report' => $audit_report->status, | |
| 171 | + 'report' => 'disabled', | |
| 168 | 172 | 'subscribers' => $this->change_subscriber_format( $audit_report ), |
| 169 | 173 | 'frequency' => $audit_report->frequency, |
| 170 | 174 | 'day' => $audit_report->day, |
| 171 | 175 | 'day_n' => $audit_report->day_n, |
| @@ -173,14 +177,12 @@ | ||
| 173 | 177 | // @since 2.7.0 We can remove it in the next version. |
| 174 | 178 | 'dry_run' => false, |
| 175 | 179 | 'storage_days' => $settings->storage_days, |
| 176 | 180 | ); |
| 177 | - if ( ! $this->is_pro ) { | |
| 178 | - $audit['enabled'] = false; | |
| 179 | - } | |
| 180 | 181 | } else { |
| 181 | 182 | $audit['enabled'] = false; |
| 182 | 183 | } |
| 184 | + | |
| 183 | 185 | $settings_firewall = new Model_Firewall(); |
| 184 | 186 | $settings_ll = new Model_Login_Lockout(); |
| 185 | 187 | $settings_nl = new Model_Notfound_Lockout(); |
| 186 | 188 | $settings_bl = new Model_Blacklist_Lockout(); |
| @@ -261,10 +263,9 @@ | ||
| 261 | 263 | ); |
| 262 | 264 | if ( isset( $audit ) ) { |
| 263 | 265 | $ret['audit'] = $audit; |
| 264 | 266 | } |
| 265 | - // For Blocklist_Monitor. | |
| 266 | - if ( $this->is_pro ) { | |
| 267 | + if ( $this->has_hub_api_key ) { | |
| 267 | 268 | $blocklist_monitor_class = wd_di()->get( Blocklist_Monitor::class ); |
| 268 | 269 | $status = (string) $blocklist_monitor_class->get_status(); |
| 269 | 270 | $ret['blocklist_monitor']['enabled'] = '1' === $status; |
| 270 | 271 | $ret['blocklist_monitor']['status'] = $status; |
| @@ -269,8 +270,9 @@ | ||
| 269 | 270 | $ret['blocklist_monitor']['enabled'] = '1' === $status; |
| 270 | 271 | $ret['blocklist_monitor']['status'] = $status; |
| 271 | 272 | } else { |
| 272 | 273 | $ret['blocklist_monitor']['enabled'] = false; |
| 274 | + $ret['blocklist_monitor']['status'] = '-1'; | |
| 273 | 275 | } |
| 274 | 276 | // For Pwned passwords. |
| 275 | 277 | $pwned_password_model = wd_di()->get( Model_Password_Protection::class ); |
| 276 | 278 | $ret['pwned_passwords']['enabled'] = $pwned_password_model->is_active(); |
| @@ -275,8 +277,20 @@ | ||
| 275 | 277 | $pwned_password_model = wd_di()->get( Model_Password_Protection::class ); |
| 276 | 278 | $ret['pwned_passwords']['enabled'] = $pwned_password_model->is_active(); |
| 277 | 279 | $ret['pwned_passwords']['user_roles'] = $pwned_password_model->user_roles; |
| 278 | 280 | $ret['pwned_passwords']['custom_message'] = $pwned_password_model->pwned_actions['force_change_message']; |
| 281 | + // For Strong Passwords. | |
| 282 | + $strong_password_model = wd_di()->get( Strong_Password_Model::class ); | |
| 283 | + $ret['force_strong_password']['enabled'] = $strong_password_model->is_active(); | |
| 284 | + $ret['force_strong_password']['user_roles'] = $strong_password_model->user_roles; | |
| 285 | + $ret['force_strong_password']['message'] = $strong_password_model->get_message(); | |
| 286 | + // For Session Protection. | |
| 287 | + $session_protection_model = wd_di()->get( Session_Protection_Model::class ); | |
| 288 | + $ret['session_protection']['enabled'] = $session_protection_model->enabled; | |
| 289 | + $ret['session_protection']['user_roles'] = $session_protection_model->user_roles; | |
| 290 | + $ret['session_protection']['lock_properties'] = $session_protection_model->lock_properties; | |
| 291 | + $ret['session_protection']['idle_timeout'] = $session_protection_model->idle_timeout; | |
| 292 | + $ret['session_protection']['login_duration'] = $session_protection_model->login_duration; | |
| 279 | 293 | // It's better to add Tweaks as the last key to eliminate unexpected behavior with possible user logout. |
| 280 | 294 | $ret['security_tweaks'] = $security_tweaks; |
| 281 | 295 | |
| 282 | 296 | return $ret; |
| @@ -289,9 +303,9 @@ | ||
| 289 | 303 | */ |
| 290 | 304 | public function get_configs(): array { |
| 291 | 305 | $keys = get_site_option( self::INDEXER, false ); |
| 292 | 306 | $results = array(); |
| 293 | - if ( empty( $keys ) ) { | |
| 307 | + if ( ! is_array( $keys ) || array() === $keys ) { | |
| 294 | 308 | return $results; |
| 295 | 309 | } |
| 296 | 310 | |
| 297 | 311 | foreach ( $keys as $key ) { |
| @@ -330,9 +344,9 @@ | ||
| 330 | 344 | * @return void |
| 331 | 345 | */ |
| 332 | 346 | public function clear_keys(): void { |
| 333 | 347 | $keys = get_site_option( self::INDEXER, array() ); |
| 334 | - if ( empty( $keys ) ) { | |
| 348 | + if ( array() === $keys ) { | |
| 335 | 349 | delete_site_option( self::INDEXER ); |
| 336 | 350 | delete_site_option( self::KEY ); |
| 337 | 351 | } |
| 338 | 352 | } |
| @@ -341,9 +355,9 @@ | ||
| 341 | 355 | * Clears all configurations from the options table. |
| 342 | 356 | */ |
| 343 | 357 | public function clear_configs(): void { |
| 344 | 358 | $keys = get_site_option( self::INDEXER, false ); |
| 345 | - if ( is_array( $keys ) && ! empty( $keys ) ) { | |
| 359 | + if ( is_array( $keys ) && array() !== $keys ) { | |
| 346 | 360 | foreach ( $keys as $key ) { |
| 347 | 361 | delete_site_option( $key ); |
| 348 | 362 | } |
| 349 | 363 | } |
| @@ -364,9 +378,9 @@ | ||
| 364 | 378 | '%wp_defender_config_%' |
| 365 | 379 | ), |
| 366 | 380 | ARRAY_A |
| 367 | 381 | ); |
| 368 | - if ( ! empty( $result ) ) { | |
| 382 | + if ( array() !== $result ) { | |
| 369 | 383 | foreach ( $result as $arr ) { |
| 370 | 384 | delete_site_option( $arr['option_name'] ); |
| 371 | 385 | } |
| 372 | 386 | } |
| @@ -378,12 +392,13 @@ | ||
| 378 | 392 | * @return void |
| 379 | 393 | */ |
| 380 | 394 | public function maybe_create_default_config(): void { |
| 381 | 395 | $keys = get_site_option( self::INDEXER, array() ); |
| 382 | - if ( empty( $keys ) ) { | |
| 396 | + if ( array() === $keys ) { | |
| 383 | 397 | $this->remove_unindexed_configs(); |
| 384 | - $key = 'wp_defender_config_default' . time(); | |
| 385 | - if ( ! get_site_option( $key ) ) { | |
| 398 | + $key = 'wp_defender_config_default' . time(); | |
| 399 | + $config = get_site_option( $key ); | |
| 400 | + if ( ! is_array( $config ) || array() === $config ) { | |
| 386 | 401 | $this->create_basic_config( $key ); |
| 387 | 402 | } |
| 388 | 403 | } |
| 389 | 404 | } |
| @@ -412,22 +427,25 @@ | ||
| 412 | 427 | $default_ip_lockout_values = ( new Model_Blacklist_Lockout() )->get_default_values(); |
| 413 | 428 | $default_ua_lockout_values = ( new Model_Ua_Lockout() )->get_default_values(); |
| 414 | 429 | $default_password_protection_values = ( new Model_Password_Protection() )->get_default_values(); |
| 415 | 430 | $default_2fa_values = ( new Model_Two_Fa() )->get_default_values(); |
| 431 | + $default_scan_settings = wd_di()->get( Model_Scan::class ); | |
| 432 | + | |
| 416 | 433 | // Total data. |
| 417 | - $data = array( | |
| 418 | - 'scan' => array( | |
| 434 | + $data = array( | |
| 435 | + 'scan' => array( | |
| 419 | 436 | 'integrity_check' => true, |
| 420 | 437 | 'check_core' => true, |
| 421 | 438 | 'check_plugins' => true, |
| 422 | - 'check_known_vuln' => true, | |
| 423 | - 'scan_malware' => true, | |
| 439 | + 'check_known_vuln' => $default_scan_settings->check_known_vuln, | |
| 440 | + 'scan_malware' => $default_scan_settings->scan_malware, | |
| 441 | + 'check_abandoned_plugin' => true, | |
| 424 | 442 | 'filesize' => 3, |
| 425 | 443 | 'report' => 'enabled', |
| 426 | 444 | 'always_send' => false, |
| 427 | 445 | 'report_subscribers' => $default_recipients, |
| 428 | 446 | 'day' => 'sunday', |
| 429 | - 'day_n' => '1', | |
| 447 | + 'day_n' => 1, | |
| 430 | 448 | 'time' => '4:00', |
| 431 | 449 | 'frequency' => 'weekly', |
| 432 | 450 | // @since 2.7.0 We can remove it in the next version. |
| 433 | 451 | 'dry_run' => false, |
| @@ -440,13 +458,12 @@ | ||
| 440 | 458 | 'email_subject_error' => $default_scan_notification_values['subject_error'], |
| 441 | 459 | 'email_content_issue_found' => $default_scan_notification_values['content_issue_found'], |
| 442 | 460 | 'email_content_issue_not_found' => $default_scan_notification_values['content_issue_not_found'], |
| 443 | 461 | 'email_content_error' => $default_scan_notification_values['content_error'], |
| 444 | - // @since 2.7.0 move Scheduled options from Malware Scanning - Reporting to Malware settings. | |
| 445 | 462 | // Values for frequency, day and time are above. |
| 446 | 463 | 'scheduled_scanning' => true, |
| 447 | 464 | ), |
| 448 | - 'iplockout' => array( | |
| 465 | + 'iplockout' => array( | |
| 449 | 466 | 'login_protection' => true, |
| 450 | 467 | 'login_protection_login_attempt' => '5', |
| 451 | 468 | 'login_protection_lockout_timeframe' => '300', |
| 452 | 469 | 'login_protection_lockout_ban' => 'timeframe', |
| @@ -482,9 +499,9 @@ | ||
| 482 | 499 | 'report' => 'enabled', |
| 483 | 500 | 'report_subscribers' => $default_recipients, |
| 484 | 501 | 'report_frequency' => 'weekly', |
| 485 | 502 | 'day' => 'sunday', |
| 486 | - 'day_n' => '1', | |
| 503 | + 'day_n' => 1, | |
| 487 | 504 | 'report_time' => '4:00', |
| 488 | 505 | // @since 2.7.0 We can remove it in the next version. |
| 489 | 506 | 'dry_run' => false, |
| 490 | 507 | 'storage_days' => '180', |
| @@ -500,9 +517,9 @@ | ||
| 500 | 517 | // @since 3.4.0 New Global IP list. |
| 501 | 518 | 'global_ip_list' => false, |
| 502 | 519 | 'global_ip_list_blocklist_autosync' => false, |
| 503 | 520 | ), |
| 504 | - 'two_factor' => array( | |
| 521 | + 'two_factor' => array( | |
| 505 | 522 | // @since 2.6.5 Disabled module. |
| 506 | 523 | 'enabled' => false, |
| 507 | 524 | 'lost_phone' => true, |
| 508 | 525 | 'force_auth' => false, |
| @@ -517,9 +534,9 @@ | ||
| 517 | 534 | 'email_sender' => $default_2fa_values['email_sender'], |
| 518 | 535 | 'email_body' => $default_2fa_values['email_body'], |
| 519 | 536 | 'app_title' => $default_2fa_values['app_title'], |
| 520 | 537 | ), |
| 521 | - 'mask_login' => array( | |
| 538 | + 'mask_login' => array( | |
| 522 | 539 | 'enabled' => false, |
| 523 | 540 | 'mask_url' => '', |
| 524 | 541 | 'redirect_traffic' => 'off', |
| 525 | 542 | 'redirect_traffic_url' => '', |
| @@ -524,9 +541,9 @@ | ||
| 524 | 541 | 'redirect_traffic' => 'off', |
| 525 | 542 | 'redirect_traffic_url' => '', |
| 526 | 543 | 'redirect_traffic_page_id' => 0, |
| 527 | 544 | ), |
| 528 | - 'security_headers' => array( | |
| 545 | + 'security_headers' => array( | |
| 529 | 546 | 'sh_xframe' => true, |
| 530 | 547 | 'sh_xframe_mode' => 'sameorigin', |
| 531 | 548 | 'sh_xframe_urls' => '', |
| 532 | 549 | 'sh_xss_protection' => true, |
| @@ -542,9 +559,9 @@ | ||
| 542 | 559 | 'sh_feature_policy' => true, |
| 543 | 560 | 'sh_feature_policy_mode' => 'self', |
| 544 | 561 | 'sh_feature_policy_urls' => '', |
| 545 | 562 | ), |
| 546 | - 'settings' => array( | |
| 563 | + 'settings' => array( | |
| 547 | 564 | 'uninstall_data' => 'keep', |
| 548 | 565 | 'uninstall_settings' => 'preserve', |
| 549 | 566 | // @since 2.7.0 Empty. |
| 550 | 567 | 'translate' => '', |
| @@ -550,28 +567,39 @@ | ||
| 550 | 567 | 'translate' => '', |
| 551 | 568 | 'usage_tracking' => false, |
| 552 | 569 | 'high_contrast_mode' => false, |
| 553 | 570 | ), |
| 554 | - 'pwned_passwords' => array( | |
| 571 | + 'pwned_passwords' => array( | |
| 555 | 572 | 'enabled' => false, |
| 556 | 573 | 'user_roles' => $user_roles, |
| 557 | 574 | 'custom_message' => $default_password_protection_values['message'], |
| 558 | 575 | ), |
| 576 | + 'force_strong_password' => array( | |
| 577 | + 'enabled' => false, | |
| 578 | + 'user_roles' => $user_roles, | |
| 579 | + 'message' => ( new Strong_Password_Model() )->get_message(), | |
| 580 | + ), | |
| 581 | + 'session_protection' => array( | |
| 582 | + 'enabled' => false, | |
| 583 | + 'idle_timeout' => 1, | |
| 584 | + 'login_duration' => ( new Session_Protection_Model() )->get_default_duration(), | |
| 585 | + 'user_roles' => $user_roles, | |
| 586 | + 'lock_properties' => array(), | |
| 587 | + ), | |
| 559 | 588 | ); |
| 560 | - // Pro properties. | |
| 561 | - if ( $this->is_pro ) { | |
| 562 | - $data['audit'] = array( | |
| 563 | - 'enabled' => true, | |
| 564 | - 'report' => 'enabled', | |
| 565 | - 'subscribers' => $default_recipients, | |
| 566 | - 'frequency' => 'weekly', | |
| 567 | - 'day' => 'sunday', | |
| 568 | - 'day_n' => '1', | |
| 569 | - 'time' => '4:00', | |
| 570 | - // @since 2.7.0 We can remove it in the next version. | |
| 571 | - 'dry_run' => false, | |
| 572 | - 'storage_days' => '6 months', | |
| 573 | - ); | |
| 589 | + $data['audit'] = array( | |
| 590 | + 'enabled' => true, | |
| 591 | + 'report' => 'disabled', | |
| 592 | + 'subscribers' => $default_recipients, | |
| 593 | + 'frequency' => 'weekly', | |
| 594 | + 'day' => 'sunday', | |
| 595 | + 'day_n' => 1, | |
| 596 | + 'time' => '4:00', | |
| 597 | + // @since 2.7.0 We can remove it in the next version. | |
| 598 | + 'dry_run' => false, | |
| 599 | + 'storage_days' => '6 months', | |
| 600 | + ); | |
| 601 | + if ( $this->has_hub_api_key ) { | |
| 574 | 602 | $data['blocklist_monitor'] = array( |
| 575 | 603 | // @since 2.7.0 Enable. |
| 576 | 604 | 'enabled' => true, |
| 577 | 605 | 'status' => '1', |
| @@ -576,26 +604,25 @@ | ||
| 576 | 604 | 'enabled' => true, |
| 577 | 605 | 'status' => '1', |
| 578 | 606 | ); |
| 579 | 607 | } else { |
| 580 | - $data['audit']['enabled'] = false; | |
| 581 | - $data['blocklist_monitor']['enabled'] = false; | |
| 608 | + $data['blocklist_monitor'] = array( | |
| 609 | + 'enabled' => false, | |
| 610 | + 'status' => '-1', | |
| 611 | + ); | |
| 582 | 612 | } |
| 583 | 613 | // It's better to add Tweaks as the last key to eliminate unexpected behavior with possible user logout. |
| 584 | 614 | $data['security_tweaks'] = array( |
| 585 | - 'notification_repeat' => 'weekly', | |
| 586 | - 'subscribers' => $default_recipients, | |
| 587 | - 'notification' => 'enabled', | |
| 588 | - 'automate' => true, | |
| 589 | - 'data' => array(), | |
| 615 | + 'notification' => 'disabled', | |
| 616 | + 'data' => array(), | |
| 590 | 617 | // @since 2.7.0 Specific values for 4 fixed, 0 ignored and 8 actioned tweaks. 12 tweaks in total. |
| 591 | - 'fixed' => array( | |
| 618 | + 'fixed' => array( | |
| 592 | 619 | 'disable-xml-rpc', |
| 593 | 620 | 'login-duration', |
| 594 | 621 | 'disable-trackback', |
| 595 | 622 | 'prevent-enum-users', |
| 596 | 623 | ), |
| 597 | - 'issues' => array( | |
| 624 | + 'issues' => array( | |
| 598 | 625 | 'php-version', |
| 599 | 626 | 'wp-version', |
| 600 | 627 | 'prevent-php-executed', |
| 601 | 628 | 'protect-information', |
| @@ -603,17 +630,18 @@ | ||
| 603 | 630 | 'security-key', |
| 604 | 631 | 'disable-file-editor', |
| 605 | 632 | 'hide-error', |
| 606 | 633 | ), |
| 607 | - 'ignore' => array(), | |
| 634 | + 'ignore' => array(), | |
| 608 | 635 | ); |
| 609 | 636 | |
| 610 | 637 | $configs['configs'] = $data; |
| 611 | - $configs['strings'] = $this->create_default_module_strings( $data, $this->is_pro ); | |
| 638 | + $configs['strings'] = $this->create_default_module_strings( $data ); | |
| 612 | 639 | $configs['name'] = esc_html__( 'Basic Config', 'defender-security' ); |
| 613 | 640 | $configs['description'] = esc_html__( 'Recommended default protection for every site', 'defender-security' ); |
| 614 | 641 | $configs['immortal'] = true; |
| 615 | 642 | $configs['is_removable'] = true; |
| 643 | + $configs['version'] = 2; | |
| 616 | 644 | update_site_option( $key, $configs ); |
| 617 | 645 | $this->index_key( $key ); |
| 618 | 646 | } |
| 619 | 647 | |
| @@ -628,9 +656,9 @@ | ||
| 628 | 656 | if ( is_array( $keys ) ) { |
| 629 | 657 | $keys[ $key ] = $key; |
| 630 | 658 | $keys = array_unique( $keys ); |
| 631 | 659 | update_site_option( self::INDEXER, $keys ); |
| 632 | - } elseif ( empty( $keys ) ) { | |
| 660 | + } elseif ( '' === $keys ) { | |
| 633 | 661 | // The first config. |
| 634 | 662 | update_site_option( self::INDEXER, array( $key => $key ) ); |
| 635 | 663 | } |
| 636 | 664 | } |
| @@ -686,9 +714,9 @@ | ||
| 686 | 714 | $controller = $this->module_to_controller( $module, true ); |
| 687 | 715 | // Return array of objects if the module is IP Lockout. |
| 688 | 716 | if ( is_object( $controller ) || is_array( $controller ) ) { |
| 689 | 717 | foreach ( $module_data as &$value ) { |
| 690 | - if ( ! is_array( $value ) && ! filter_var( $value, FILTER_VALIDATE_BOOLEAN ) ) { | |
| 718 | + if ( isset( $value ) && ! is_array( $value ) && ! filter_var( $value, FILTER_VALIDATE_BOOLEAN ) ) { | |
| 691 | 719 | $value = str_replace( '{nl}', PHP_EOL, $value ); |
| 692 | 720 | } |
| 693 | 721 | } |
| 694 | 722 | |
| @@ -702,9 +730,9 @@ | ||
| 702 | 730 | $controller->import_data( $module_data ); |
| 703 | 731 | |
| 704 | 732 | $scan_notification = new Malware_Notification(); |
| 705 | 733 | $scan_report = new Malware_Report(); |
| 706 | - if ( ! empty( $module_data ) ) { | |
| 734 | + if ( array() !== $module_data ) { | |
| 707 | 735 | $scan_settings = new Model_Scan(); |
| 708 | 736 | // For Scan notification. |
| 709 | 737 | if ( isset( $module_data['notification'] ) ) { |
| 710 | 738 | if ( $scan_notification->status !== $module_data['notification'] ) { |
| @@ -715,60 +743,59 @@ | ||
| 715 | 743 | } |
| 716 | 744 | if ( isset( $module_data['error_send'] ) ) { |
| 717 | 745 | $scan_notification->configs['error_send'] = $module_data['error_send']; |
| 718 | 746 | } |
| 719 | - if ( ! empty( $module_data['email_subject_issue_found'] ) ) { | |
| 747 | + if ( isset( $module_data['email_subject_issue_found'] ) && '' !== $module_data['email_subject_issue_found'] ) { | |
| 720 | 748 | $scan_notification->configs['template']['found']['subject'] = $module_data['email_subject_issue_found']; |
| 721 | 749 | } |
| 722 | - if ( ! empty( $module_data['email_subject_issue_not_found'] ) ) { | |
| 750 | + if ( isset( $module_data['email_subject_issue_not_found'] ) && '' !== $module_data['email_subject_issue_not_found'] ) { | |
| 723 | 751 | $scan_notification->configs['template']['not_found']['subject'] = $module_data['email_subject_issue_not_found']; |
| 724 | 752 | } |
| 725 | - if ( ! empty( $module_data['email_subject_error'] ) ) { | |
| 753 | + if ( isset( $module_data['email_subject_error'] ) && '' !== $module_data['email_subject_error'] ) { | |
| 726 | 754 | $scan_notification->configs['template']['error']['subject'] = $module_data['email_subject_error']; |
| 727 | 755 | } |
| 728 | - if ( ! empty( $module_data['email_content_issue_found'] ) ) { | |
| 756 | + if ( isset( $module_data['email_content_issue_found'] ) && '' !== $module_data['email_content_issue_found'] ) { | |
| 729 | 757 | $scan_notification->configs['template']['found']['body'] = $module_data['email_content_issue_found']; |
| 730 | 758 | } |
| 731 | - if ( ! empty( $module_data['email_content_issue_not_found'] ) ) { | |
| 759 | + if ( isset( $module_data['email_content_issue_not_found'] ) && '' !== $module_data['email_content_issue_not_found'] ) { | |
| 732 | 760 | $scan_notification->configs['template']['not_found']['body'] = $module_data['email_content_issue_not_found']; |
| 733 | 761 | } |
| 734 | - if ( ! empty( $module_data['email_content_error'] ) ) { | |
| 762 | + if ( isset( $module_data['email_content_error'] ) && '' !== $module_data['email_content_error'] ) { | |
| 735 | 763 | $scan_notification->configs['template']['error']['body'] = $module_data['email_content_error']; |
| 736 | 764 | } |
| 737 | - if ( ! empty( $module_data['notification_subscribers'] ) ) { | |
| 765 | + if ( | |
| 766 | + isset( $module_data['notification_subscribers'] ) | |
| 767 | + && is_array( $module_data['notification_subscribers'] ) | |
| 768 | + && array() !== $module_data['notification_subscribers'] | |
| 769 | + ) { | |
| 738 | 770 | // Reset all recipients before. |
| 739 | 771 | $scan_notification->in_house_recipients = array(); |
| 740 | 772 | $scan_notification->out_house_recipients = array(); |
| 741 | 773 | foreach ( $module_data['notification_subscribers'] as $key => $subscribers ) { |
| 742 | - $scan_notification->$key = $subscribers; | |
| 774 | + if ( 'in_house_recipients' === $key ) { | |
| 775 | + $scan_notification->in_house_recipients = $subscribers; | |
| 776 | + } elseif ( 'out_house_recipients' === $key ) { | |
| 777 | + $scan_notification->out_house_recipients = $subscribers; | |
| 778 | + } | |
| 743 | 779 | } |
| 744 | 780 | } |
| 745 | 781 | $scan_notification->save(); |
| 746 | 782 | } |
| 747 | - // For Scan report. | |
| 748 | - if ( | |
| 749 | - $this->is_pro | |
| 750 | - && isset( $module_data['report'] ) | |
| 751 | - && $scan_report->status !== $module_data['report'] | |
| 752 | - ) { | |
| 753 | - $scan_report->status = $module_data['report']; | |
| 754 | - } | |
| 755 | 783 | if ( isset( $module_data['always_send'] ) ) { |
| 756 | 784 | $scan_report->configs['always_send'] = $module_data['always_send']; |
| 757 | 785 | } |
| 758 | - if ( ! empty( $module_data['report_subscribers'] ) ) { | |
| 786 | + if ( isset( $module_data['report_subscribers'] ) && is_array( $module_data['report_subscribers'] ) && array() !== $module_data['report_subscribers'] ) { | |
| 759 | 787 | // Reset all recipients before. |
| 760 | 788 | $scan_report->in_house_recipients = array(); |
| 761 | 789 | $scan_report->out_house_recipients = array(); |
| 762 | 790 | foreach ( $module_data['report_subscribers'] as $key => $subscribers ) { |
| 763 | - $scan_report->$key = $subscribers; | |
| 791 | + if ( 'in_house_recipients' === $key ) { | |
| 792 | + $scan_report->in_house_recipients = $subscribers; | |
| 793 | + } elseif ( 'out_house_recipients' === $key ) { | |
| 794 | + $scan_report->out_house_recipients = $subscribers; | |
| 795 | + } | |
| 764 | 796 | } |
| 765 | 797 | } |
| 766 | - // @since 2.7.0 Remove 'dry_run'-restoring. | |
| 767 | - // @since 2.7.0 scheduled values. Step#1 if 'report'-key exists. | |
| 768 | - if ( $this->is_pro && isset( $module_data['report'] ) ) { | |
| 769 | - $scan_settings->scheduled_scanning = 'enabled' === $module_data['report']; | |
| 770 | - } | |
| 771 | 798 | // Step#2 if 'scheduled_scanning'-key exists. |
| 772 | 799 | if ( isset( $module_data['scheduled_scanning'] ) ) { |
| 773 | 800 | $scan_settings->scheduled_scanning = $module_data['scheduled_scanning']; |
| 774 | 801 | } |
| @@ -781,10 +808,10 @@ | ||
| 781 | 808 | $scan_settings->day = $module_data['day']; |
| 782 | 809 | $scan_report->day = $module_data['day']; |
| 783 | 810 | } |
| 784 | 811 | if ( isset( $module_data['day_n'] ) ) { |
| 785 | - $scan_settings->day_n = $module_data['day_n']; | |
| 786 | - $scan_report->day_n = $module_data['day_n']; | |
| 812 | + $scan_settings->day_n = (int) $module_data['day_n']; | |
| 813 | + $scan_report->day_n = (int) $module_data['day_n']; | |
| 787 | 814 | } |
| 788 | 815 | if ( isset( $module_data['time'] ) ) { |
| 789 | 816 | $scan_settings->time = $module_data['time']; |
| 790 | 817 | $scan_report->time = $module_data['time']; |
| @@ -808,9 +835,9 @@ | ||
| 808 | 835 | foreach ( $controller as $lockout_controller ) { |
| 809 | 836 | $lockout_controller->import_data( $module_data ); |
| 810 | 837 | } |
| 811 | 838 | // For Notification and Report. |
| 812 | - if ( ! empty( $module_data ) ) { | |
| 839 | + if ( is_array( $module_data ) && array() !== $module_data ) { | |
| 813 | 840 | // Get string values for notification & report. |
| 814 | 841 | if ( isset( $module_data['notification'] ) ) { |
| 815 | 842 | $lockout_notification = new Firewall_Notification(); |
| 816 | 843 | if ( $lockout_notification->status !== $module_data['notification'] ) { |
| @@ -830,50 +857,23 @@ | ||
| 830 | 857 | } |
| 831 | 858 | if ( isset( $module_data['cooldown_period'] ) ) { |
| 832 | 859 | $lockout_notification->configs['cool_off'] = $module_data['cooldown_period']; |
| 833 | 860 | } |
| 834 | - if ( ! empty( $module_data['notification_subscribers'] ) ) { | |
| 861 | + if ( isset( $module_data['notification_subscribers'] ) && is_array( $module_data['notification_subscribers'] ) && array() !== $module_data['notification_subscribers'] ) { | |
| 835 | 862 | // Reset all recipients before. |
| 836 | 863 | $lockout_notification->in_house_recipients = array(); |
| 837 | 864 | $lockout_notification->out_house_recipients = array(); |
| 838 | 865 | foreach ( $module_data['notification_subscribers'] as $key => $subscribers ) { |
| 839 | - $lockout_notification->$key = $subscribers; | |
| 866 | + if ( 'in_house_recipients' === $key ) { | |
| 867 | + $lockout_notification->in_house_recipients = $subscribers; | |
| 868 | + } elseif ( 'out_house_recipients' === $key ) { | |
| 869 | + $lockout_notification->out_house_recipients = $subscribers; | |
| 870 | + } | |
| 840 | 871 | } |
| 841 | 872 | } |
| 842 | 873 | |
| 843 | 874 | $lockout_notification->save(); |
| 844 | 875 | } |
| 845 | - if ( $this->is_pro && isset( $module_data['report'] ) ) { | |
| 846 | - $lockout_report = new Firewall_Report(); | |
| 847 | - if ( $lockout_report->status !== $module_data['report'] ) { | |
| 848 | - $lockout_report->status = $module_data['report']; | |
| 849 | - } | |
| 850 | - if ( isset( $module_data['day'] ) ) { | |
| 851 | - $lockout_report->day = $module_data['day']; | |
| 852 | - } | |
| 853 | - if ( isset( $module_data['report_frequency'] ) ) { | |
| 854 | - $lockout_report->frequency = $module_data['report_frequency']; | |
| 855 | - } | |
| 856 | - if ( isset( $module_data['day_n'] ) ) { | |
| 857 | - $lockout_report->day_n = $module_data['day_n']; | |
| 858 | - } | |
| 859 | - if ( isset( $module_data['report_time'] ) ) { | |
| 860 | - $lockout_report->time = $module_data['report_time']; | |
| 861 | - } | |
| 862 | - if ( ! empty( $module_data['report_subscribers'] ) ) { | |
| 863 | - // Reset all recipients before. | |
| 864 | - $lockout_report->in_house_recipients = array(); | |
| 865 | - $lockout_report->out_house_recipients = array(); | |
| 866 | - foreach ( $module_data['report_subscribers'] as $key => $subscribers ) { | |
| 867 | - $lockout_report->$key = $subscribers; | |
| 868 | - } | |
| 869 | - } | |
| 870 | - if ( isset( $module_data['last_sent'] ) ) { | |
| 871 | - $lockout_report->last_sent = $module_data['last_sent']; | |
| 872 | - } | |
| 873 | - // @since 2.7.0 Remove 'dry_run'-restoring. | |
| 874 | - $lockout_report->save(); | |
| 875 | - } | |
| 876 | 876 | } else { |
| 877 | 877 | // Default data for lockout notification. |
| 878 | 878 | $lockout_notification = new Firewall_Notification(); |
| 879 | 879 | $lockout_notification->status = 'disabled'; |
| @@ -892,9 +892,9 @@ | ||
| 892 | 892 | $lockout_report->status = 'disabled'; |
| 893 | 893 | // @since 2.7.0 We can remove it in the next version. |
| 894 | 894 | $lockout_report->dry_run = false; |
| 895 | 895 | $lockout_report->frequency = 'weekly'; |
| 896 | - $lockout_report->day_n = '1'; | |
| 896 | + $lockout_report->day_n = 1; | |
| 897 | 897 | $lockout_report->day = 'sunday'; |
| 898 | 898 | $lockout_report->time = '4:00'; |
| 899 | 899 | $lockout_report->save(); |
| 900 | 900 | } |
| @@ -902,21 +902,14 @@ | ||
| 902 | 902 | // Import. |
| 903 | 903 | $controller->import_data( $module_data ); |
| 904 | 904 | // Report. |
| 905 | 905 | $audit_report = new Audit_Report(); |
| 906 | - if ( ! empty( $module_data ) ) { | |
| 907 | - if ( | |
| 908 | - $this->is_pro | |
| 909 | - && isset( $module_data['report'] ) | |
| 910 | - && $audit_report->status !== $module_data['report'] | |
| 911 | - ) { | |
| 912 | - $audit_report->status = $module_data['report']; | |
| 913 | - } | |
| 906 | + if ( is_array( $module_data ) && array() !== $module_data ) { | |
| 914 | 907 | if ( isset( $module_data['frequency'] ) ) { |
| 915 | 908 | $audit_report->frequency = $module_data['frequency']; |
| 916 | 909 | } |
| 917 | 910 | if ( isset( $module_data['day_n'] ) ) { |
| 918 | - $audit_report->day_n = $module_data['day_n']; | |
| 911 | + $audit_report->day_n = (int) $module_data['day_n']; | |
| 919 | 912 | } |
| 920 | 913 | if ( isset( $module_data['day'] ) ) { |
| 921 | 914 | $audit_report->day = $module_data['day']; |
| 922 | 915 | } |
| @@ -922,14 +915,18 @@ | ||
| 922 | 915 | } |
| 923 | 916 | if ( isset( $module_data['time'] ) ) { |
| 924 | 917 | $audit_report->time = $module_data['time']; |
| 925 | 918 | } |
| 926 | - if ( ! empty( $module_data['subscribers'] ) ) { | |
| 919 | + if ( isset( $module_data['subscribers'] ) && is_array( $module_data['subscribers'] ) && array() !== $module_data['subscribers'] ) { | |
| 927 | 920 | // Reset all recipients before. |
| 928 | 921 | $audit_report->in_house_recipients = array(); |
| 929 | 922 | $audit_report->out_house_recipients = array(); |
| 930 | 923 | foreach ( $module_data['subscribers'] as $key => $subscribers ) { |
| 931 | - $audit_report->$key = $subscribers; | |
| 924 | + if ( 'in_house_recipients' === $key ) { | |
| 925 | + $audit_report->in_house_recipients = $subscribers; | |
| 926 | + } elseif ( 'out_house_recipients' === $key ) { | |
| 927 | + $audit_report->out_house_recipients = $subscribers; | |
| 928 | + } | |
| 932 | 929 | } |
| 933 | 930 | } |
| 934 | 931 | if ( isset( $module_data['last_sent'] ) ) { |
| 935 | 932 | $audit_report->last_sent = $module_data['last_sent']; |
| @@ -940,9 +937,9 @@ | ||
| 940 | 937 | $audit_report->status = 'disabled'; |
| 941 | 938 | // @since 2.7.0 We can remove it in the next version. |
| 942 | 939 | $audit_report->dry_run = false; |
| 943 | 940 | $audit_report->frequency = 'weekly'; |
| 944 | - $audit_report->day_n = '1'; | |
| 941 | + $audit_report->day_n = 1; | |
| 945 | 942 | $audit_report->day = 'sunday'; |
| 946 | 943 | $audit_report->time = '4:00'; |
| 947 | 944 | } |
| 948 | 945 | |
| @@ -951,18 +948,22 @@ | ||
| 951 | 948 | * If 'blocklist_monitor' module is activated, 'enabled' set as true. |
| 952 | 949 | */ |
| 953 | 950 | } elseif ( |
| 954 | 951 | 'blocklist_monitor' === $module |
| 955 | - && $this->is_pro | |
| 956 | - && isset( $module_data['status'] ) | |
| 952 | + && $this->has_hub_api_key | |
| 957 | 953 | ) { |
| 958 | 954 | // No need to import data. Just change status. |
| 959 | - ( new Blocklist_Monitor() )->change_status( $module_data['status'] ); | |
| 955 | + $blocklist_status = $module_data['status'] ?? '-1'; | |
| 956 | + ( new Blocklist_Monitor() )->change_status( $blocklist_status ); | |
| 960 | 957 | } elseif ( |
| 961 | 958 | 'pwned_passwords' === $module |
| 962 | 959 | && isset( $module_data['custom_message'] ) |
| 963 | 960 | ) { |
| 964 | 961 | $controller->import_data( $module_data ); |
| 962 | + } elseif ( 'force_strong_password' === $module ) { | |
| 963 | + $controller->import_data( $module_data ); | |
| 964 | + } elseif ( 'session_protection' === $module ) { | |
| 965 | + $controller->import_data( $module_data ); | |
| 965 | 966 | } elseif ( 'two_factor' === $module ) { |
| 966 | 967 | $controller->import_data( $module_data ); |
| 967 | 968 | } elseif ( 'mask_login' === $module ) { |
| 968 | 969 | $controller->import_data( $module_data ); |
| @@ -981,50 +982,13 @@ | ||
| 981 | 982 | $tweak_class = wd_di()->get( Controller_Security_Tweaks::class ); |
| 982 | 983 | $need_reauth = $tweak_class->automate( $module_data, $request_reason ); |
| 983 | 984 | } |
| 984 | 985 | // For Tweak notification. |
| 985 | - if ( ! empty( $module_data ) && isset( $module_data['notification'] ) ) { | |
| 986 | + if ( is_array( $module_data ) && array() !== $module_data && isset( $module_data['notification'] ) ) { | |
| 986 | 987 | $tweak_notification = new Tweak_Reminder(); |
| 987 | 988 | if ( $tweak_notification->status !== $module_data['notification'] ) { |
| 988 | - $tweak_notification->status = $module_data['notification']; | |
| 989 | + $tweak_notification->status = 'disabled'; | |
| 989 | 990 | } |
| 990 | - | |
| 991 | - if ( isset( $module_data['notification_repeat'] ) ) { | |
| 992 | - // Temporary check for older versions. | |
| 993 | - if ( is_bool( $module_data['notification_repeat'] ) ) { | |
| 994 | - $tweak_notification->configs['reminder'] = $module_data['notification_repeat'] | |
| 995 | - ? 'daily' | |
| 996 | - : 'weekly'; | |
| 997 | - } elseif ( | |
| 998 | - is_string( $module_data['notification_repeat'] ) | |
| 999 | - && in_array( | |
| 1000 | - $module_data['notification_repeat'], | |
| 1001 | - array( | |
| 1002 | - 'daily', | |
| 1003 | - 'weekly', | |
| 1004 | - 'monthly', | |
| 1005 | - ), | |
| 1006 | - true | |
| 1007 | - ) | |
| 1008 | - ) { | |
| 1009 | - $tweak_notification->configs['reminder'] = $module_data['notification_repeat']; | |
| 1010 | - } else { | |
| 1011 | - $tweak_notification->configs['reminder'] = 'weekly'; | |
| 1012 | - } | |
| 1013 | - } else { | |
| 1014 | - $tweak_notification->configs['reminder'] = 'weekly'; | |
| 1015 | - } | |
| 1016 | - if ( ! empty( $module_data['subscribers'] ) ) { | |
| 1017 | - // Reset all recipients before. | |
| 1018 | - $tweak_notification->in_house_recipients = array(); | |
| 1019 | - $tweak_notification->out_house_recipients = array(); | |
| 1020 | - foreach ( $module_data['subscribers'] as $key => $subscribers ) { | |
| 1021 | - $tweak_notification->$key = $subscribers; | |
| 1022 | - } | |
| 1023 | - } | |
| 1024 | - if ( isset( $module_data['last_sent'] ) ) { | |
| 1025 | - $tweak_notification->last_sent = $module_data['last_sent']; | |
| 1026 | - } | |
| 1027 | 991 | $tweak_notification->save(); |
| 1028 | 992 | } |
| 1029 | 993 | } |
| 1030 | 994 | } |
| @@ -1042,9 +1006,9 @@ | ||
| 1042 | 1006 | * |
| 1043 | 1007 | * @return array Returns an array containing parsed data for import. |
| 1044 | 1008 | */ |
| 1045 | 1009 | public function parse_data_for_import( $configs = null ): array { |
| 1046 | - if ( empty( $configs ) ) { | |
| 1010 | + if ( ! is_array( $configs ) || array() === $configs ) { | |
| 1047 | 1011 | $configs = $this->gather_data(); |
| 1048 | 1012 | } |
| 1049 | 1013 | $strings = array(); |
| 1050 | 1014 | foreach ( $configs as $module => $module_data ) { |
| @@ -1109,8 +1073,12 @@ | ||
| 1109 | 1073 | case 'blocklist_monitor': |
| 1110 | 1074 | return new Blocklist_Monitor(); |
| 1111 | 1075 | case 'pwned_passwords': |
| 1112 | 1076 | return new Controller_Password_Protection(); |
| 1077 | + case 'force_strong_password': | |
| 1078 | + return new Strong_Password_Controller(); | |
| 1079 | + case 'session_protection': | |
| 1080 | + return new Session_Protection_Controller(); | |
| 1113 | 1081 | default: |
| 1114 | 1082 | return ''; |
| 1115 | 1083 | } |
| 1116 | 1084 | } |
| @@ -1122,9 +1090,10 @@ | ||
| 1122 | 1090 | * |
| 1123 | 1091 | * @return bool Returns true if the new structure is used, otherwise false. |
| 1124 | 1092 | */ |
| 1125 | 1093 | public function check_for_new_structure( array $configs ): bool { |
| 1126 | - return array_key_exists( 'subscribers', $configs['security_tweaks'] ); | |
| 1094 | + return isset( $configs['version'] ) || | |
| 1095 | + ( isset( $configs['security_tweaks'] ) && array_key_exists( 'enabled_user_enums', $configs['security_tweaks'] ) ); | |
| 1127 | 1096 | } |
| 1128 | 1097 | |
| 1129 | 1098 | /** |
| 1130 | 1099 | * Verifies the integrity of configuration data. |
| @@ -1133,10 +1102,11 @@ | ||
| 1133 | 1102 | * |
| 1134 | 1103 | * @return bool Returns true if the data is valid, otherwise false. |
| 1135 | 1104 | */ |
| 1136 | 1105 | public function verify_config_data( $data ): bool { |
| 1137 | - if ( ! isset( $data['name'], $data['configs'], $data['strings'] ) | |
| 1138 | - || empty( $data['name'] ) || empty( $data['strings'] ) | |
| 1106 | + if ( | |
| 1107 | + ! isset( $data['name'], $data['configs'], $data['strings'] ) | |
| 1108 | + || '' === $data['name'] || ! is_array( $data['strings'] ) || array() === $data['strings'] | |
| 1139 | 1109 | ) { |
| 1140 | 1110 | return false; |
| 1141 | 1111 | } |
| 1142 | 1112 | |
| @@ -1150,50 +1120,41 @@ | ||
| 1150 | 1120 | * |
| 1151 | 1121 | * @return array Returns an array of imported module strings. |
| 1152 | 1122 | */ |
| 1153 | 1123 | public function import_module_strings( array $data ): array { |
| 1154 | - if ( empty( $data['strings'] ) ) { | |
| 1124 | + if ( ! isset( $data['strings'] ) || ! is_array( $data['strings'] ) || array() === $data['strings'] ) { | |
| 1155 | 1125 | return array(); |
| 1156 | 1126 | } |
| 1157 | 1127 | |
| 1158 | 1128 | foreach ( $data['configs'] as $key => $config ) { |
| 1159 | - if ( | |
| 1160 | - 'security_tweaks' === $key | |
| 1161 | - && 'enabled' === $config['notification'] | |
| 1162 | - && 1 === ( is_array( $data['strings']['security_tweaks'] ) | |
| 1163 | - || $data['strings']['security_tweaks'] instanceof Countable ? count( $data['strings']['security_tweaks'] ) : 0 ) | |
| 1164 | - ) { | |
| 1165 | - $data['strings']['security_tweaks'][] = esc_html__( 'Email notifications active', 'defender-security' ); | |
| 1129 | + if ( 'security_tweaks' === $key ) { | |
| 1130 | + $data['strings']['security_tweaks'] = wd_di()->get( Controller_Security_Tweaks::class )->config_strings( $config ); | |
| 1166 | 1131 | } elseif ( 'scan' === $key ) { |
| 1167 | - $data['strings']['scan'] = wd_di()->get( Controller_Scan::class )->config_strings( | |
| 1168 | - $config, | |
| 1169 | - $this->is_pro | |
| 1170 | - ); | |
| 1132 | + $data['strings']['scan'] = wd_di()->get( Controller_Scan::class )->config_strings( $config ); | |
| 1171 | 1133 | } elseif ( 'iplockout' === $key ) { |
| 1172 | - $data['strings']['iplockout'] = wd_di()->get( Controller_Firewall::class )->config_strings( | |
| 1173 | - $config, | |
| 1174 | - $this->is_pro | |
| 1175 | - ); | |
| 1134 | + $data['strings']['iplockout'] = wd_di()->get( Controller_Firewall::class )->config_strings( $config ); | |
| 1176 | 1135 | } elseif ( 'audit' === $key ) { |
| 1177 | 1136 | // Additional check for Free version. |
| 1178 | 1137 | $config = is_array( $config ) ? $config : array(); |
| 1179 | - $data['strings']['audit'] = wd_di()->get( Audit_Logging::class )->config_strings( | |
| 1180 | - $config, | |
| 1181 | - $this->is_pro | |
| 1182 | - ); | |
| 1138 | + $data['strings']['audit'] = wd_di()->get( Audit_Logging::class )->config_strings( $config ); | |
| 1183 | 1139 | } elseif ( 'blocklist_monitor' === $key ) { |
| 1184 | 1140 | // Additional check for Free version. |
| 1185 | 1141 | $config = is_array( $config ) ? $config : array(); |
| 1186 | - $data['strings']['blocklist_monitor'] = $this->format_blocklist_monitor_strings( | |
| 1187 | - $config, | |
| 1188 | - $this->is_pro | |
| 1189 | - ); | |
| 1142 | + $data['strings']['blocklist_monitor'] = $this->format_blocklist_monitor_strings( $config ); | |
| 1190 | 1143 | } elseif ( 'pwned_passwords' === $key ) { |
| 1191 | - $data['strings']['pwned_passwords'] = wd_di()->get( Controller_Password_Protection::class )->config_strings( | |
| 1192 | - $config, | |
| 1193 | - $this->is_pro | |
| 1194 | - ); | |
| 1144 | + $data['strings']['pwned_passwords'] = wd_di()->get( Controller_Password_Protection::class )->config_strings( $config ); | |
| 1145 | + } elseif ( 'mask_login' === $key ) { | |
| 1146 | + $data['strings']['mask_login'] = wd_di()->get( Controller_Mask_Login::class )->config_strings( $config ); | |
| 1147 | + } elseif ( 'security_headers' === $key ) { | |
| 1148 | + $config = is_array( $config ) ? $config : array(); | |
| 1149 | + $data['strings']['security_headers'] = wd_di()->get( Security_Headers::class )->config_strings( $config ); | |
| 1150 | + } elseif ( 'two_factor' === $key ) { | |
| 1151 | + // Two-Factor is available on both Free and Pro. | |
| 1152 | + $data['strings']['two_factor'] = wd_di()->get( Two_Factor::class )->config_strings( $config ); | |
| 1153 | + } elseif ( 'force_strong_password' === $key ) { | |
| 1154 | + $data['strings']['force_strong_password'] = wd_di()->get( Strong_Password_Controller::class )->config_strings( $config ); | |
| 1195 | 1155 | } |
| 1156 | + // todo: display session_protection strings. | |
| 1196 | 1157 | } |
| 1197 | 1158 | |
| 1198 | 1159 | return $data['strings']; |
| 1199 | 1160 | } |
| @@ -1200,41 +1161,38 @@ | ||
| 1200 | 1161 | |
| 1201 | 1162 | /** |
| 1202 | 1163 | * Creates default module strings for the Basic configuration. |
| 1203 | 1164 | * |
| 1204 | - * @param array $configs The configuration data. | |
| 1205 | - * @param bool $is_pro Whether the current installation is a pro version. | |
| 1165 | + * @param array $configs The configuration data. | |
| 1206 | 1166 | * |
| 1207 | 1167 | * @return array Returns an array of default module strings. |
| 1208 | 1168 | */ |
| 1209 | - public function create_default_module_strings( array $configs, bool $is_pro ): array { | |
| 1169 | + public function create_default_module_strings( array $configs ): array { | |
| 1210 | 1170 | $strings = array(); |
| 1171 | + | |
| 1211 | 1172 | foreach ( $configs as $key => $config ) { |
| 1212 | 1173 | if ( 'security_tweaks' === $key ) { |
| 1213 | - $strings['security_tweaks'] = wd_di()->get( Controller_Security_Tweaks::class )->config_strings( | |
| 1214 | - $config, | |
| 1215 | - $is_pro | |
| 1216 | - ); | |
| 1174 | + $strings['security_tweaks'] = wd_di()->get( Controller_Security_Tweaks::class )->config_strings( $config ); | |
| 1217 | 1175 | } elseif ( 'scan' === $key ) { |
| 1218 | - $strings['scan'] = wd_di()->get( Controller_Scan::class )->config_strings( $config, $is_pro ); | |
| 1176 | + $strings['scan'] = wd_di()->get( Controller_Scan::class )->config_strings( $config ); | |
| 1219 | 1177 | } elseif ( 'iplockout' === $key ) { |
| 1220 | - $strings['iplockout'] = wd_di()->get( Controller_Firewall::class )->config_strings( $config, $is_pro ); | |
| 1178 | + $strings['iplockout'] = wd_di()->get( Controller_Firewall::class )->config_strings( $config ); | |
| 1221 | 1179 | } elseif ( 'audit' === $key ) { |
| 1222 | - $strings['audit'] = wd_di()->get( Audit_Logging::class )->config_strings( $config, $is_pro ); | |
| 1180 | + $strings['audit'] = wd_di()->get( Audit_Logging::class )->config_strings( $config ); | |
| 1223 | 1181 | } elseif ( 'two_factor' === $key ) { |
| 1224 | 1182 | $strings['two_factor'][] = esc_html__( 'Inactive', 'defender-security' ); |
| 1225 | 1183 | } elseif ( 'mask_login' === $key ) { |
| 1226 | - $strings['mask_login'][] = esc_html__( 'Inactive', 'defender-security' ); | |
| 1184 | + $strings['mask_login'] = wd_di()->get( Controller_Mask_Login::class )->config_strings( $config ); | |
| 1227 | 1185 | } elseif ( 'security_headers' === $key ) { |
| 1228 | - $strings['security_headers'][] = esc_html__( 'Active', 'defender-security' ); | |
| 1186 | + $strings['security_headers'] = wd_di()->get( Security_Headers::class )->config_strings( $config ); | |
| 1229 | 1187 | } elseif ( 'blocklist_monitor' === $key ) { |
| 1230 | - $strings['blocklist_monitor'] = wd_di()->get( Blocklist_Monitor::class )->config_strings( | |
| 1231 | - $config, | |
| 1232 | - $is_pro | |
| 1233 | - ); | |
| 1188 | + $strings['blocklist_monitor'] = wd_di()->get( Blocklist_Monitor::class )->config_strings( $config ); | |
| 1234 | 1189 | } elseif ( 'pwned_passwords' === $key ) { |
| 1235 | 1190 | $strings['pwned_passwords'][] = esc_html__( 'Inactive', 'defender-security' ); |
| 1191 | + } elseif ( 'force_strong_password' === $key ) { | |
| 1192 | + $strings['force_strong_password'][] = esc_html__( 'Inactive', 'defender-security' ); | |
| 1236 | 1193 | } |
| 1194 | + // todo: display session_protection strings. | |
| 1237 | 1195 | } |
| 1238 | 1196 | |
| 1239 | 1197 | return $strings; |
| 1240 | 1198 | } |
| @@ -1247,9 +1205,9 @@ | ||
| 1247 | 1205 | * @return array Returns the decoded settings array. |
| 1248 | 1206 | */ |
| 1249 | 1207 | private function get_decoded_settings( string $key ): array { |
| 1250 | 1208 | $data = get_site_option( $key ); |
| 1251 | - if ( $data && is_string( $data ) ) { | |
| 1209 | + if ( is_string( $data ) && '' !== trim( $data ) ) { | |
| 1252 | 1210 | $decoded_data = json_decode( $data, true ); |
| 1253 | 1211 | if ( is_array( $decoded_data ) ) { |
| 1254 | 1212 | return $decoded_data; |
| 1255 | 1213 | } |
| @@ -1264,9 +1222,9 @@ | ||
| 1264 | 1222 | * @return array |
| 1265 | 1223 | */ |
| 1266 | 1224 | private function get_prev_settings(): array { |
| 1267 | 1225 | $arr = array(); |
| 1268 | - if ( $this->is_pro ) { | |
| 1226 | + if ( $this->has_hub_api_key ) { | |
| 1269 | 1227 | $status = (string) wd_di()->get( Blocklist_Monitor::class )->get_status(); |
| 1270 | 1228 | $arr['enabled'] = '1' === $status; |
| 1271 | 1229 | $arr['status'] = $status; |
| 1272 | 1230 | } else { |
| @@ -1297,11 +1255,11 @@ | ||
| 1297 | 1255 | */ |
| 1298 | 1256 | private function module_to_name( string $module ): string { |
| 1299 | 1257 | switch ( $module ) { |
| 1300 | 1258 | case 'security_tweaks': |
| 1301 | - return esc_html__( 'Security Recommendations', 'defender-security' ); | |
| 1259 | + return esc_html__( 'Hardening', 'defender-security' ); | |
| 1302 | 1260 | case 'scan': |
| 1303 | - return esc_html__( 'Malware Scanning', 'defender-security' ); | |
| 1261 | + return esc_html__( 'Issue', 'defender-security' ); | |
| 1304 | 1262 | case 'audit': |
| 1305 | 1263 | return Model_Audit_Logging::get_module_name(); |
| 1306 | 1264 | case 'iplockout': |
| 1307 | 1265 | return esc_html__( 'Firewall', 'defender-security' ); |
| @@ -1427,39 +1385,21 @@ | ||
| 1427 | 1385 | ); |
| 1428 | 1386 | } |
| 1429 | 1387 | |
| 1430 | 1388 | /** |
| 1431 | - * Format strings of Block list Monitor config. | |
| 1389 | + * Format strings of Blocklist Monitor config. | |
| 1432 | 1390 | * |
| 1433 | 1391 | * @param array $config Saved config. |
| 1434 | - * @param bool $is_pro User membership status. | |
| 1435 | 1392 | * |
| 1436 | 1393 | * @return array |
| 1437 | 1394 | */ |
| 1438 | - private function format_blocklist_monitor_strings( array $config, bool $is_pro ): array { | |
| 1439 | - // If Block list Monitor is enable. | |
| 1440 | - if ( isset( $config['status'] ) && '1' === (string) $config['status'] ) { | |
| 1441 | - if ( $is_pro ) { | |
| 1442 | - $monitor = array( esc_html__( 'Active', 'defender-security' ) ); | |
| 1443 | - } else { | |
| 1444 | - $monitor = array( | |
| 1445 | - sprintf( | |
| 1446 | - /* translators: %s: Html for Pro-tag. */ | |
| 1447 | - esc_html__( 'Active %s', 'defender-security' ), | |
| 1448 | - '<span class="sui-tag sui-tag-pro">Pro</span>' | |
| 1449 | - ), | |
| 1450 | - ); | |
| 1451 | - } | |
| 1452 | - } elseif ( $is_pro ) { | |
| 1453 | - $monitor = array( esc_html__( 'Inactive', 'defender-security' ) ); | |
| 1395 | + private function format_blocklist_monitor_strings( array $config ): array { | |
| 1396 | + if ( $this->has_hub_api_key ) { | |
| 1397 | + $monitor = isset( $config['status'] ) && '1' === (string) $config['status'] | |
| 1398 | + ? array( esc_html__( 'Blocklist Monitor active', 'defender-security' ) ) | |
| 1399 | + : array( esc_html__( 'Blocklist Monitor inactive', 'defender-security' ) ); | |
| 1454 | 1400 | } else { |
| 1455 | - $monitor = array( | |
| 1456 | - sprintf( | |
| 1457 | - /* translators: %s: Html for Pro-tag. */ | |
| 1458 | - esc_html__( 'Inactive %s', 'defender-security' ), | |
| 1459 | - '<span class="sui-tag sui-tag-pro">Pro</span>' | |
| 1460 | - ), | |
| 1461 | - ); | |
| 1401 | + $monitor = array( esc_html__( 'Blocklist Monitor inactive', 'defender-security' ) ); | |
| 1462 | 1402 | } |
| 1463 | 1403 | |
| 1464 | 1404 | return $monitor; |
| 1465 | 1405 | } |