Plugin-Datei, Name, Ordner, auf den der Inhalt verweisen muss. * * @var array */ const FILES = array( 'wordfence-waf.php' => array( 'plugin' => 'wordfence/wordfence.php', 'name' => 'Wordfence', 'folder' => 'plugins/wordfence/', ), ); /** Groesser ist keine der bekannten Dateien; alles darueber wird nicht gelesen. */ const MAX_BYTES = 20000; /** * Passt der Inhalt zu der bekannten Datei? Reine Logik. * * @param string $name Dateiname im Wurzelverzeichnis. * @param string $content Inhalt der Datei. * @return array{plugin:string,name:string,folder:string}|null */ public static function match( $name, $content ) { if ( ! isset( self::FILES[ $name ] ) || strlen( (string) $content ) > self::MAX_BYTES ) { return null; } $known = self::FILES[ $name ]; if ( false === stripos( (string) $content, $known['folder'] ) ) { return null; } if ( preg_match( '/\b(?:eval|assert|gzinflate|gzuncompress|str_rot13|base64_decode|create_function)\s*\(|\$_(?:GET|POST|REQUEST|COOKIE)\b/i', (string) $content ) ) { return null; } return $known; } /** * Bekannte Datei im Wurzelverzeichnis der Website? * * @param string $path Pfad relativ zum Wurzelverzeichnis. * @param string $base Wurzelverzeichnis mit Schraegstrich am Ende. * @return array{plugin:string,name:string,folder:string,active:bool}|null */ public static function identify( $path, $base ) { $path = (string) $path; if ( false !== strpos( $path, '/' ) || ! isset( self::FILES[ $path ] ) || ! is_readable( $base . $path ) ) { return null; } $content = file_get_contents( $base . $path, false, null, 0, self::MAX_BYTES + 1 ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- kleine lokale Datei. $known = self::match( $path, is_string( $content ) ? $content : '' ); if ( ! $known ) { return null; } if ( ! function_exists( 'is_plugin_active' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $known['active'] = is_plugin_active( $known['plugin'] ) || is_plugin_active_for_network( $known['plugin'] ); return $known; } /** * Hinweis fuer die Anzeige. * * @param array $known Ergebnis aus {@see self::identify()}. */ public static function note( array $known ) { if ( ! empty( $known['active'] ) ) { /* translators: %s: plugin name */ return sprintf( __( 'Firewall file of %s. The plugin is active, so this is in order.', '360-orbit-security-digest' ), $known['name'] ); } /* translators: %s: plugin name */ return sprintf( __( 'Leftover of %s, which is no longer active. Remove its firewall setup in the plugin (or the line with auto_prepend_file in .user.ini or php.ini) before you delete this file, otherwise every page shows an error.', '360-orbit-security-digest' ), $known['name'] ); } }