ray { $settings = new Mask_Login(); return [ 'active' => $settings->is_active(), 'masked_url' => $settings->mask_url, ]; } /** * @return array */ public function build_recaptcha_hub_data(): array { $settings = new \WP_Defender\Model\Setting\Recaptcha(); return [ 'active' => $settings->is_active(), ]; } /** * @return array */ public function build_password_protection_hub_data(): array { $settings = new \WP_Defender\Model\Setting\Password_Protection(); return [ 'active' => $settings->is_active(), ]; } /** * @param object $module_report * * @return string */ private function get_notification_day( $module_report ): string { if ( ! is_object( $module_report ) ) { return ''; } if ( 'daily' === $module_report->frequency ) { $day = '1'; } elseif ( 'weekly' === $module_report->frequency ) { $day = $module_report->day; } else { // For 'monthly'. $day = $module_report->day_n; } return $day; } /** * Frequency format: * if frequency is day, e.g.: 'frequency' => 1, 'day' => '1', 'time' => '20:30' * if frequency is week, e.g.: 'frequency' => 7, 'day' => 'wednesday', 'time' => '14:00' * if frequency is month, e.g.: 'frequency' => 30, 'day' => '4', 'time' => '4:30' * * @return array */ public function build_notification_hub_data(): array { $audit_settings = new Audit_Logging(); $audit_report = new Audit_Report(); $firewall_report = new Firewall_Report(); $malware_report = new Malware_Report(); $scan_settings = new Scan_Settings(); return [ 'file_scanning' => [ 'active' => true, // @since 2.7.0 move scheduled options to Scan settings, but we get status of Malware Scanning - Reporting here. 'enabled' => Notification::STATUS_ACTIVE === $malware_report->status, // Report enabled bool value. 'frequency' => [ 'frequency' => $this->backward_frequency_compatibility( $scan_settings->frequency ), 'day' => $this->get_notification_day( $scan_settings ), 'time' => $scan_settings->time, ], ], 'audit_logging' => [ 'active' => $audit_settings->is_active(), 'enabled' => Notification::STATUS_ACTIVE === $audit_report->status, 'frequency' => [ 'frequency' => $this->backward_frequency_compatibility( $audit_report->frequency ), 'day' => $this->get_notification_day( $audit_report ), 'time' => $audit_report->time, ], ], 'ip_lockouts' => [ // Always true as we have blacklist listening. 'active' => true, 'enabled' => Notification::STATUS_ACTIVE === $firewall_report->status, // Report enabled bool value. 'frequency' => [ 'frequency' => $this->backward_frequency_compatibility( $firewall_report->frequency ), 'day' => $this->get_notification_day( $firewall_report ), 'time' => $firewall_report->time, ], ], ]; } /** * @return array */ public function build_firewall_notification_hub_data(): array { $firewall_notification = new Firewall_Notification(); if ( 'enabled' === $firewall_notification->status ) { $login_lockout = $firewall_notification->configs['login_lockout']; $nf_lockout = $firewall_notification->configs['nf_lockout']; $ua_lockout = $firewall_notification->configs['ua_lockout'] ?? false; } else { $login_lockout = false; $nf_lockout = false; $ua_lockout = false; } return [ 'firewall' => [ 'login_lockout' => $login_lockout, '404_lockout' => $nf_lockout, 'ua_lockout' => $ua_lockout, ], ]; } /** * @return array */ public function build_security_headers_hub_data(): array { $security_headers = wd_di()->get( Security_Headers::class )->get_type_headers(); return [ 'active' => $security_headers['active'], 'inactive' => $security_headers['inactive'], ]; } /** * @return array */ public function build_stats_to_hub(): array { $scan_data = $this->build_scan_hub_data(); $tweaks_data = $this->build_security_tweaks_hub_data(); $audit_data = $this->build_audit_hub_data(); $firewall_data = $this->build_lockout_hub_data(); $two_fa = $this->build_2fa_hub_data(); $mask_login = $this->build_mask_login_hub_data(); $sec_headers = $this->build_security_headers_hub_data(); $recaptcha = $this->build_recaptcha_hub_data(); $pwned_password = $this->build_password_protection_hub_data(); $quarantined_files = $this->build_quarantined_files_hub_data(); return [ // Domain name. 'domain' => network_home_url(), // Last scan date. 'timestamp' => $scan_data['timestamp'], // Scan issue count. 'warnings' => $scan_data['warning'], // Security tweaks issue count. 'cautions' => $tweaks_data['cautions'], 'data_version' => gmdate( 'Ymd' ), 'scan_data' => json_encode( [ 'scan_result' => $scan_data['scan_result'], 'hardener_result' => [ 'issues' => $tweaks_data[ Security_Tweaks::STATUS_ISSUES ], 'ignored' => $tweaks_data[ Security_Tweaks::STATUS_IGNORE ], 'resolved' => $tweaks_data[ Security_Tweaks::STATUS_RESOLVE ], ], 'scan_schedule' => $scan_data['scan_schedule'], 'audit_status' => [ 'events_in_month' => $audit_data['month'], 'audit_enabled' => $audit_data['enabled'], 'last_event_date' => $audit_data['last_event'], ], 'audit_page_url' => network_admin_url( 'admin.php?page=wdf-logging' ), 'labels' => [ // Todo: maybe should it remove because Scan Settings model has label() method for that? 'parent_integrity' => esc_html__( 'File change detection', 'wpdef' ), 'core_integrity' => esc_html__( 'Scan core files', 'wpdef' ), 'plugin_integrity' => esc_html__( 'Scan plugin files', 'wpdef' ), 'vulnerability_db' => esc_html__( 'Known vulnerabilities', 'wpdef' ), 'file_suspicious' => esc_html__( 'Suspicious code', 'wpdef' ), ], 'scan_page_url' => network_admin_url( 'admin.php?page=wdf-scan' ), 'hardener_page_url' => network_admin_url( 'admin.php?page=wdf-hardener' ), 'new_scan_url' => network_admin_url( 'admin.php?page=wdf-scan&wdf-action=new_scan' ), 'schedule_scans_url' => network_admin_url( 'admin.php?page=wdf-schedule-scan' ), 'settings_page_url' => network_admin_url( 'admin.php?page=wdf-settings' ), 'ip_lockout_page_url' => network_admin_url( 'admin.php?page=wdf-ip-lockout' ), 'last_lockout' => $firewall_data['last_lockout'], 'login_lockout_enabled' => $firewall_data['lp'], 'login_lockout' => $firewall_data['lp_week'], 'lockout_404_enabled' => $firewall_data['nf'], 'lockout_404' => $firewall_data['nf_week'], 'lockout_ua_enabled' => $firewall_data['ua'], 'lockout_ua' => $firewall_data['ua_week'], 'total_lockout' => (int) $firewall_data['lp_week'] + (int) $firewall_data['nf_week'] + (int) $firewall_data['ua_week'], 'global_ip_list_enabled' => $firewall_data['global_ip_list_enabled'], 'advanced' => [ // This is moved but still keep here for backward compatibility. 'multi_factors_auth' => [ 'active' => $two_fa['active'], 'enabled' => $two_fa['enabled'], 'active_users' => $two_fa['active_users'], ], 'mask_login' => [ 'activate' => $mask_login['active'], 'masked_url' => $mask_login['masked_url'], ], 'security_headers' => [ 'active' => $sec_headers['active'], 'inactive' => $sec_headers['inactive'], ], 'google_recaptcha' => [ 'active' => $recaptcha['active'], ], 'password_protection' => [ 'active' => $pwned_password['active'], ], ], 'reports' => $this->build_notification_hub_data(), 'notifications' => $this->build_firewall_notification_hub_data(), 'quarantined_files' => $quarantined_files, ] ), ]; } /** * Checks whether we're on WPMU DEV Hosting. * * @return bool */ public function is_wpmu_hosting(): bool { return isset( $_SERVER['WPMUDEV_HOSTED'] ) && ! empty( $_SERVER['WPMUDEV_HOSTED'] ); } /** * @return bool */ protected function is_tfh_account(): bool { return class_exists( 'WPMUDEV_Dashboard' ) && is_object( WPMUDEV_Dashboard::$api ) && method_exists( WPMUDEV_Dashboard::$api, 'get_membership_status' ) && 'free' === WPMUDEV_Dashboard::$api->get_membership_status(); } /** * Check if WPMUDEV Hosted site is connected to The Free HUB. * * @since 3.3.0 * @return bool */ public function is_hosted_site_connected_to_tfh(): bool { return $this->is_tfh_account() && $this->is_wpmu_hosting(); } /** * Check if a site from 3rd party hosting is connected to The Free HUB. * * @since 3.6.0 * @return bool */ public function is_another_hosted_site_connected_to_tfh(): bool { return $this->is_tfh_account() && ! $this->is_wpmu_hosting(); } /** * @return array */ protected function build_quarantined_files_hub_data(): array { if ( ! class_exists( 'WP_Defender\Component\Quarantine' ) ) { return []; } return wd_di()->get( Quarantine::class )->hub_list(); } /** * Schedule Hub Synchronization event. */ public function schedule_hub_sync(): void { if ( ! wp_next_scheduled( 'defender_hub_sync' ) ) { wp_schedule_single_event( time(), 'defender_hub_sync' ); } } }