répertoire => [nom, nature] */ public const KNOWN = [ 'wordfence' => ['Wordfence', 'firewall'], 'sucuri-scanner' => ['Sucuri Security', 'scanner'], 'better-wp-security' => ['Solid Security (iThemes)', 'firewall'], 'ithemes-security-pro' => ['Solid Security Pro (iThemes)', 'firewall'], 'all-in-one-wp-security-and-firewall' => ['All In One WP Security', 'firewall'], 'malcare-security' => ['MalCare', 'firewall'], 'ninjafirewall' => ['NinjaFirewall', 'firewall'], 'bulletproof-security' => ['BulletProof Security', 'firewall'], 'defender-security' => ['Defender', 'firewall'], 'wp-defender' => ['Defender Pro', 'firewall'], 'wp-simple-firewall' => ['Shield Security', 'firewall'], 'cloudflare' => ['Cloudflare (extension)', 'cdn'], ]; /** @return array */ public function detect(): array { $active = []; foreach ($this->activePlugins() as $file) { $slug = str_contains($file, '/') ? explode('/', $file, 2)[0] : basename($file, '.php'); if (isset(self::KNOWN[$slug])) { [$name, $kind] = self::KNOWN[$slug]; $active[] = ['slug' => $slug, 'name' => $name, 'kind' => $kind]; } } $prepend = trim((string) ini_get('auto_prepend_file')); $cloudflare = isset($_SERVER['HTTP_CF_RAY']) && $_SERVER['HTTP_CF_RAY'] !== ''; return [ 'protections' => $active, 'firewall_active' => $prepend !== '' || array_filter($active, static fn (array $p): bool => $p['kind'] === 'firewall') !== [], 'php_prepend_firewall' => $prepend !== '' ? basename($prepend) : null, 'cloudflare_in_front' => $cloudflare, 'note' => 'Détection par extensions actives et en-têtes observés : un pare-feu d\'hébergeur ou un WAF réseau sans en-tête reconnaissable n\'apparaît pas ici.', ]; } /** @return list */ private function activePlugins(): array { $plugins = get_option('active_plugins', []); $plugins = is_array($plugins) ? array_values(array_filter($plugins, 'is_string')) : []; if (function_exists('get_site_option') && function_exists('is_multisite') && is_multisite()) { $network = get_site_option('active_sitewide_plugins', []); if (is_array($network)) { $plugins = [...$plugins, ...array_keys($network)]; } } return array_values(array_unique($plugins)); } }