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(), ]; } 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 = []; // 1. Plugins $all_plugins = get_plugins(); foreach ( $all_plugins as $path => $data ) { $slug = dirname( $path ); if ( $slug === '.' ) $slug = basename( $path, '.php' ); $payload[$slug] = $data['Version']; } // 2. Themes (NUEVO) $all_themes = wp_get_themes(); foreach ( $all_themes as $slug => $theme ) { $payload[$slug] = $theme->get('Version'); } // Llamada a la API $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 ]; } }