are_Report::class ); $two_fa = wd_di()->get( Two_Fa::class ); $quarantined_files = array(); $antibot_service = wd_di()->get( Antibot_Global_Firewall::class ); $ret = array( 'summary' => array( 'count' => $total, 'next_scan' => $scan_report->get_next_run_for_hub(), ), 'report' => array( 'malware_scan' => $scan_report->get_next_run_as_string( true ), 'firewall' => wd_di()->get( Firewall_Report::class )->get_next_run_as_string( true ), 'audit_logging' => wd_di()->get( Audit_Report::class )->get_next_run_as_string( true ), ), 'security_tweaks' => array( 'issues' => $tweak_arr['count_issues'], 'fixed' => $tweak_arr['count_fixed'], 'notification' => wd_di()->get( Tweak_Reminder::class )->status === $status_active, 'wp_version' => $wp_version, 'php_version' => PHP_VERSION, ), 'malware_scan' => array( 'count' => $scan_total_issues, 'notification' => wd_di()->get( Malware_Notification::class )->status === $status_active, ), 'firewall' => array( 'last_lockout' => Lockout_Log::get_last_lockout_date( true ), '24_hours' => array( 'login_lockout' => Lockout_Log::count( strtotime( '-24 hours' ), time(), array( Lockout_Log::AUTH_LOCK ) ), '404_lockout' => Lockout_Log::count( strtotime( '-24 hours' ), time(), array( Lockout_Log::LOCKOUT_404 ) ), 'user_agent_lockout' => Lockout_Log::count( strtotime( '-24 hours' ), time(), array( Lockout_Log::LOCKOUT_UA ) ), ), '7_days' => array( 'login_lockout' => Lockout_Log::count_login_lockout_last_7_days(), '404_lockout' => Lockout_Log::count_404_lockout_last_7_days(), 'user_agent_lockout' => Lockout_Log::count_ua_lockout_last_7_days(), ), '30_days' => array( 'login_lockout' => Lockout_Log::count( strtotime( '-30 days' ), time(), array( Lockout_Log::AUTH_LOCK ) ), '404_lockout' => Lockout_Log::count( strtotime( '-30 days' ), time(), array( Lockout_Log::LOCKOUT_404 ) ), 'user_agent_lockout' => Lockout_Log::count( strtotime( '-30 days' ), time(), array( Lockout_Log::LOCKOUT_UA ) ), ), 'notification_status' => array( 'login_lockout' => $login_lockout, '404_lockout' => $nf_lockout, 'ua_lockout' => $ua_lockout, ), 'login_lockout_enabled' => wd_di()->get( Login_Lockout::class )->enabled, 'lockout_404_enabled' => wd_di()->get( Notfound_Lockout::class )->enabled, 'user_agent_lockout_enabled' => wd_di()->get( User_Agent_Lockout::class )->enabled, 'global_ip_list_enabled' => wd_di()->get( Global_Ip_Lockout::class )->enabled, 'antibot_enabled' => $antibot_service->frontend_is_enabled(), 'antibot_mode' => $antibot_service->frontend_mode(), ), 'audit' => array( 'last_event' => $audit['lastEvent'] ?? 'n/a', '24_hours' => $audit['dayCount'] ?? 0, '7_days' => $audit['weekCount'] ?? 0, '30_days' => $audit['monthCount'] ?? 0, 'enabled' => $audit_log->model->is_active(), ), 'advanced_tools' => array( 'security_headers' => array( 'sh_xframe' => $model_sec_headers->sh_xframe, 'sh_xss_protection' => $model_sec_headers->sh_xss_protection, 'sh_content_type_options' => $model_sec_headers->sh_content_type_options, 'sh_strict_transport' => $model_sec_headers->sh_strict_transport, 'sh_referrer_policy' => $model_sec_headers->sh_referrer_policy, 'sh_feature_policy' => $model_sec_headers->sh_feature_policy, ), 'mask_login' => wd_di()->get( \WP_Defender\Model\Setting\Mask_Login::class )->is_active(), // We'll change 'google_recaptcha'-key to 'captcha' in the future. 'google_recaptcha' => array( 'status' => wd_di()->get( \WP_Defender\Model\Setting\Captcha::class )->is_active(), ), 'password_protection' => array( 'status' => wd_di()->get( \WP_Defender\Model\Setting\Password_Protection::class )->is_active(), ), ), 'two_fa' => array( 'status' => $two_fa->enabled, 'lost_phone' => $two_fa->lost_phone, ), 'quarantined_files' => $quarantined_files, ); wp_send_json_success( array( 'stats' => $ret ) ); } /** * Synchronizes the data with the hub by making a POST request to the WPMUDEV API. * * @return void */ public function hub_sync() { $data = $this->build_stats_to_hub(); $this->make_wpmu_request( WPMUDEV::API_HUB_SYNC, $data, array( 'method' => 'POST' ) ); } /** * Removes settings for all submodules. */ public function remove_settings() { } /** * Delete all the data & the cache. */ public function remove_data() { } /** * Placeholder for frontend data. * * @return array */ public function data_frontend() { return array(); } /** * Converts the current object state to an array. * * @return array The array representation of the object. */ public function to_array(): array { return array(); } /** * Placeholder for importing data. * * @param array $data Data to import. */ public function import_data( array $data ) { } /** * Exports strings. * * @return array An array of strings. */ public function export_strings(): array { return array(); } /** * Display Onboard if the bool value 'true' and vice versa. * * @param bool $is_show Settings to display. */ public function set_onboarding_status( $is_show ) { $this->view_onboard = $is_show; } /** * Retrieve the Onboard status. * * @return bool */ public function get_onboarding_status(): bool { return $this->view_onboard; } /** * Activate/deactivate Captcha from HUB. */ public function manage_recaptcha() { $response = null; if ( class_exists( \WP_Defender\Model\Setting\Captcha::class ) ) { $settings = new \WP_Defender\Model\Setting\Captcha(); $response = array(); if ( true === $settings->enabled ) { $settings->enabled = false; $response['enabled'] = false; } else { $settings->enabled = true; $response['enabled'] = true; } $settings->save(); // Track. if ( $this->is_tracking_active() ) { $this->track_feature_from_hub( ! $settings->enabled, 'Google reCAPTCHA' ); } } wp_send_json_success( $response ); } /** * Activate/deactivate 2FA from HUB. * * @param array $params Request parameters. */ public function manage_2fa( array $params ) { $response = null; if ( class_exists( Two_Fa::class ) ) { $settings = wd_di()->get( Two_Fa::class ); $response = array(); if ( true === $settings->enabled ) { $settings->enabled = false; $response['enabled'] = false; } else { $settings->enabled = true; $response['enabled'] = true; } $settings->save(); // Track. if ( $this->is_tracking_active() ) { // Only deactivation from the Hub. $this->track_feature_from_hub( false, 'Two-Factor Authentication' ); } } wp_send_json_success( $response ); } /** * Activate/deactivate Global IP list from HUB. * * @param object $params Request parameters. * * @return void * @since 3.4.0 */ public function manage_global_ip_list( object $params ): void { if ( ! isset( $params->enable ) ) { wp_send_json_error( array( 'message' => esc_html__( 'Missing parameter(s)', 'defender-security' ) ) ); } $response = null; if ( class_exists( Global_Ip_Lockout::class ) ) { $settings = wd_di()->get( Global_Ip_Lockout::class ); $response = array(); if ( true === $params->enable ) { $settings->enabled = true; $response['enabled'] = true; } else { $settings->enabled = false; $response['enabled'] = false; } $settings->save(); } wp_send_json_success( $response ); } /** * Set Global IP list. * * @param object $params Request parameters. * * @return void * @since 3.4.0 */ public function set_global_ips( object $params ): void { $global_ip_component = wd_di()->get( Global_IP::class ); $result = $global_ip_component->set_global_ip_list( (array) $params ); if ( is_wp_error( $result ) ) { wp_send_json_error( array( 'message' => implode( ' ', $result->get_error_messages() ), ) ); } wp_send_json_success( array( 'enabled' => $global_ip_component->is_global_ip_enabled() ) ); } /** * Handle plugin deactivation. * * @param string $plugin Path to the plugin file relative to the plugins directory. * * @return void */ public function intercept_deactivate( $plugin ) { if ( ! $this->is_tracking_active() ) { return; } // Only if Defender. if ( DEFENDER_PLUGIN_BASENAME !== $plugin ) { return; } $action = defender_get_data_from_request( 'action', 'r' ); // Todo: this is a default value. Need to update it in the future. $triggered_from = 'Unknown'; // Deactivated from WPMUDEV Dashboard. if ( 'wdp-project-deactivate' === $action ) { $triggered_from = 'Plugin deactivation - dashboard'; } elseif ( 'deactivate' === $action ) { // Deactivated from WP plugins page. $triggered_from = 'Plugin deactivation - wpadmin'; } elseif ( $this->is_hub_request() ) { $triggered_from = 'Plugin deactivation - hub'; } // Send plugin deactivation event. $this->track_opt_toggle( false, $triggered_from ); } /** * Enable/Disable Antibot Functionality. Only for third party site. * * @param object $params Request parameters. * * @return void * @since 4.11.0 */ public function set_antibot_status( object $params ): void { if ( ! isset( $params->enable ) && ! isset( $params->mode ) ) { wp_send_json_error( array( 'message' => esc_html__( 'Missing parameter(s)', 'defender-security' ) ) ); } if ( ! class_exists( Antibot_Global_Firewall_Setting::class ) ) { wp_send_json_error( array( 'message' => esc_html__( 'Missing class', 'defender-security' ) ) ); } $is_updated = false; $antibot_settings = wd_di()->get( Antibot_Global_Firewall_Setting::class ); if ( isset( $params->mode ) ) { if ( ! in_array( $params->mode, Antibot_Global_Firewall_Setting::get_valid_modes(), true ) ) { wp_send_json_error( array( 'message' => esc_html__( 'Invalid mode', 'defender-security' ) ) ); } $old_mode = $antibot_settings->mode; $new_mode = $params->mode; if ( $old_mode !== $new_mode ) { $is_updated = true; $antibot_settings->mode = $new_mode; } } if ( isset( $params->enable ) ) { $old_enabled = $antibot_settings->enabled; $new_enabled = (bool) $params->enable; if ( $old_enabled !== $new_enabled ) { $is_updated = true; $antibot_settings->enabled = $new_enabled; // Track. if ( $this->is_tracking_active() ) { wd_di()->get( \WP_Defender\Helper\Analytics\Antibot::class ) ->track_antibot( $old_enabled, 'Hub' ); } } } if ( $is_updated ) { $antibot_settings->save(); /** * Download and store the blocklist. * * @var Antibot_Global_Firewall $antibot_service */ $antibot_service = wd_di()->get( Antibot_Global_Firewall::class ); if ( 'plugin' === $antibot_service->get_managed_by() && $antibot_service->is_enabled() ) { $antibot_service->download_and_store_blocklist(); } } wp_send_json_success( array( 'enabled' => $antibot_settings->enabled, 'mode' => $antibot_settings->mode, ) ); } }