plugin = $plugin_instance; } /** * Realiza un escaneo completo del entorno local. * @return array Resultados del escaneo. */ public function run_local_scan() { return [ 'php' => $this->check_php_version(), 'wordpress' => $this->check_wp_version(), 'database' => $this->check_db_version(), 'debug_mode' => $this->check_debug_mode(), 'updates' => $this->check_pending_updates(), 'ssl' => $this->check_ssl(), 'themes_list' => $this->get_themes_status_list(), // New: Detailed theme list ]; } /** * Get detailed status list of all installed themes. * @return array */ private function get_themes_status_list() { $all_themes = wp_get_themes(); $update_data = get_site_transient('update_themes'); $active_theme = wp_get_theme(); $parent_theme = $active_theme->parent(); $themes_list = []; foreach ($all_themes as $slug => $theme) { $is_active = ($active_theme->get_stylesheet() === $slug); $is_parent = ($parent_theme && $parent_theme->get_stylesheet() === $slug); $has_update = false; $update_version = ''; if (isset($update_data->response[$slug])) { $has_update = true; $update_version = $update_data->response[$slug]['new_version']; } $themes_list[$slug] = [ 'name' => $theme->get('Name'), 'version' => $theme->get('Version'), 'is_active' => $is_active, 'is_parent' => $is_parent, 'has_update' => $has_update, 'new_version' => $update_version, 'author' => $theme->get('Author'), 'screenshot' => $theme->get_screenshot(), ]; } return $themes_list; } private function check_php_version() { $version = phpversion(); // Definición de versiones seguras (EOL Schedule) // Fuente: https://www.php.net/supported-versions.php $status = 'critical'; // Por defecto $message = __('Your PHP version is obsolete and insecure. Update immediately.', 'advanced-ip-blocker'); if (version_compare($version, '8.2', '>=')) { $status = 'good'; $message = __('Up to date and secure.', 'advanced-ip-blocker'); } elseif (version_compare($version, '8.1', '>=')) { $status = 'warning'; $message = __('Security updates only. Consider upgrading soon.', 'advanced-ip-blocker'); } elseif (version_compare($version, '8.0', '>=')) { $status = 'critical'; // EOL desde Nov 2023 $message = __('End of Life. No security updates. Upgrade needed.', 'advanced-ip-blocker'); } return ['current' => $version, 'status' => $status, 'message' => $message]; } private function check_wp_version() { global $wp_version; $core_updates = get_site_transient('update_core'); $status = 'good'; $message = __('You are running the latest version.', 'advanced-ip-blocker'); if (isset($core_updates->updates) && !empty($core_updates->updates)) { foreach ($core_updates->updates as $update) { if ($update->response === 'upgrade') { $status = 'critical'; /* translators: %s: The new WordPress version available. */ $message = sprintf(__('Outdated. New version %s is available.', 'advanced-ip-blocker'), $update->current); break; } } } return ['current' => $wp_version, 'status' => $status, 'message' => $message]; } private function check_db_version() { global $wpdb; // Obtenemos la versión directamente con una consulta SQL estándar a través de WPDB $version = $wpdb->get_var("SELECT VERSION()"); return ['current' => $version, 'status' => 'info', 'message' => __('Database engine version.', 'advanced-ip-blocker')]; } private function check_debug_mode() { if (defined('WP_DEBUG') && WP_DEBUG) { if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG && defined('WP_DEBUG_DISPLAY') && !WP_DEBUG_DISPLAY) { return ['status' => 'warning', 'message' => __('Enabled (Log Only). Good for dev, risky for prod.', 'advanced-ip-blocker')]; } return ['status' => 'critical', 'message' => __('Enabled and displaying errors. Security risk!', 'advanced-ip-blocker')]; } return ['status' => 'good', 'message' => __('Disabled. (Secure)', 'advanced-ip-blocker')]; } private function check_pending_updates() { $plugin_updates = get_site_transient('update_plugins'); $theme_updates = get_site_transient('update_themes'); $p_count = isset($plugin_updates->response) ? count($plugin_updates->response) : 0; $t_count = isset($theme_updates->response) ? count($theme_updates->response) : 0; $status = ($p_count + $t_count === 0) ? 'good' : 'warning'; if ($p_count + $t_count > 5) $status = 'critical'; // Acumulación peligrosa return [ 'plugins' => $p_count, 'themes' => $t_count, 'status' => $status, 'details' => $plugin_updates->response ?? [] // Lista de plugins para mostrar nombres ]; } private function check_ssl() { return is_ssl() ? ['status' => 'good', 'message' => __('Active.', 'advanced-ip-blocker')] : ['status' => 'critical', 'message' => __('Inactive. Your site is not using HTTPS.', 'advanced-ip-blocker')]; } /** * Escanea plugins instalados contra la API remota de AIB. * @return array */ public function check_vulnerabilities_via_api() { if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $payload = []; $all_plugins = get_plugins(); foreach ( $all_plugins as $path => $data ) { $slug = dirname( $path ); if ( $slug === '.' ) $slug = basename( $path, '.php' ); $payload[$slug] = $data['Version']; } $all_themes = wp_get_themes(); foreach ( $all_themes as $slug => $theme ) { $payload[$slug] = $theme->get('Version'); } $api_url = 'https://advaipbl.com/wp-json/aib-scanner/v1/check'; $response = wp_remote_post( $api_url, [ 'body' => wp_json_encode( $payload ), 'headers' => [ 'Content-Type' => 'application/json' ], 'timeout' => 15 // Subimos un poco el timeout por si la lista es larga ]); if ( is_wp_error( $response ) ) { return ['status' => 'error', 'message' => 'API Error']; } $body = wp_remote_retrieve_body( $response ); $vulnerabilities = json_decode( $body, true ); if ( empty( $vulnerabilities ) ) { return ['status' => 'clean', 'count' => 0, 'details' => []]; } return [ 'status' => 'vulnerable', 'count' => count( $vulnerabilities ), 'details' => $vulnerabilities ]; } /** * Comprueba la reputación de la IP del servidor en las listas de bloqueo configuradas. * @return array Resultados del chequeo. */ public function check_server_reputation() { $server_ip = $this->plugin->get_server_ip(); if ( ! $server_ip ) { return [ 'status' => 'error', 'message' => __('Could not determine server IP address.', 'advanced-ip-blocker') ]; } $results = [ 'ip' => $server_ip, 'status' => 'clean', // Asumimos limpio hasta demostrar lo contrario 'checks' => [] ]; $aib_status = 'clean'; if ( isset($this->plugin->community_manager) && $this->plugin->community_manager->is_ip_blocked($server_ip) ) { $aib_status = 'listed'; $results['status'] = 'blacklisted'; } $results['checks']['aib'] = [ 'label' => __('AIB Community Network', 'advanced-ip-blocker'), 'status' => $aib_status ]; $spamhaus_status = 'skipped'; if ( ! empty($this->plugin->options['enable_spamhaus_asn']) && isset($this->plugin->asn_manager) ) { // Necesitamos geolocalizar la IP del servidor primero $location = $this->plugin->geolocation_manager->fetch_location($server_ip); $asn = $this->plugin->asn_manager->extract_asn_from_data($location); if ( $asn ) { $spamhaus_list = get_option('advaipbl_spamhaus_asn_list', []); if ( in_array($asn, $spamhaus_list, true) ) { $spamhaus_status = 'listed'; $results['status'] = 'blacklisted'; } else { $spamhaus_status = 'clean'; } } else { $spamhaus_status = 'unknown'; // No se pudo obtener ASN } } $results['checks']['spamhaus'] = [ 'label' => __('Spamhaus ASN DROP', 'advanced-ip-blocker'), 'status' => $spamhaus_status ]; $abuse_status = 'skipped'; if ( ! empty($this->plugin->options['enable_abuseipdb']) && ! empty($this->plugin->options['abuseipdb_api_key']) ) { $check = $this->plugin->abuseipdb_manager->check_ip($server_ip); if ( $check && isset($check['score']) ) { if ( $check['score'] > 0 ) { $abuse_status = ($check['score'] > 20) ? 'listed' : 'warning'; // Umbral arbitrario if ($check['score'] > 20) $results['status'] = 'blacklisted'; } else { $abuse_status = 'clean'; } $results['checks']['abuseipdb'] = [ 'label' => __('AbuseIPDB', 'advanced-ip-blocker'), 'status' => $abuse_status, /* translators: %d%%: Score, e.g. 100/100 */ 'detail' => sprintf(__('Score: %d%%', 'advanced-ip-blocker'), $check['score']) ]; } } else { $results['checks']['abuseipdb'] = [ 'label' => __('AbuseIPDB', 'advanced-ip-blocker'), 'status' => 'skipped', 'detail' => __('API Key not configured', 'advanced-ip-blocker') ]; } return $results; } }