debug_logger->log_debug($exception->getMessage(), 4); return ''; } catch (Error $error) { // phpcs:ignore PHPCompatibility.Classes.NewClasses.errorFound -- this won't run on PHP 5.6 so we still want to catch it on other versions $aio_wp_security->debug_logger->log_debug($error->getMessage(), 4); return ''; } } } else { $directive = ini_get('auto_prepend_file'); if (false !== $directive) { return $directive; } } return ''; } /** * Returns the file that's necessary to load our firewall * * @return AIOWPSecurity_Block_File|null file needed to load the firewall */ public static function get_server_file() { $server_type = AIOWPSecurity_Utility::get_server_type(); $is_cgi = false; $sapi = PHP_SAPI; if (false !== stripos($sapi, 'cgi')) { $is_cgi = true; } if (AIOWPSecurity_Utility::UNSUPPORTED_SERVER_TYPE === $server_type) { return self::MANUAL_SETUP; } elseif (false === $is_cgi && 'apache' === $server_type) { $htpath = path_join(AIOWPSecurity_Utility_File::get_home_path(), '.htaccess'); return new AIOWPSecurity_Block_Htaccess($htpath); } elseif ('litespeed' === $server_type || 'litespeed' === $sapi) { $htpath = path_join(AIOWPSecurity_Utility_File::get_home_path(), '.htaccess'); return new AIOWPSecurity_Block_Litespeed($htpath); } else { $userini = path_join(AIOWPSecurity_Utility_File::get_home_path(), '.user.ini'); return new AIOWPSecurity_Block_Userini($userini); } } /** * Checks whether the firewall has been setup * * @return boolean */ public static function is_firewall_setup() { $is_in_bootstrap = (true === self::get_bootstrap_file()->contains_contents()); $files = array( self::get_server_file(), self::get_wpconfig_file(), self::get_muplugin_file(), ); foreach ($files as $file) { if (AIOWPSecurity_Utility_Firewall::MANUAL_SETUP === $file) continue; if ($is_in_bootstrap && (true === $file->contains_contents())) return true; } return false; } /** * Attempts to remove our firewall. * * @return void */ public static function remove_firewall() { global $aio_wp_security; $firewall_files = array( 'server' => AIOWPSecurity_Utility_Firewall::get_server_file(), 'bootstrap' => AIOWPSecurity_Utility_Firewall::get_bootstrap_file(), 'wpconfig' => AIOWPSecurity_Utility_Firewall::get_wpconfig_file(), 'muplugin' => AIOWPSecurity_Utility_Firewall::get_muplugin_file(), ); foreach ($firewall_files as $file) { if (AIOWPSecurity_Utility_Firewall::MANUAL_SETUP === $file) { continue; } if (true === $file->contains_contents()) { $removed = $file->remove_contents(); if (is_wp_error($removed)) { $error_message = $removed->get_error_message(); $error_message .= ' - '; $error_message .= $removed->get_error_data(); $aio_wp_security->debug_logger->log_debug($error_message, 4); } } } //Delete our mu-plugin, if it's created clearstatcache(); $muplugin_path = $firewall_files['muplugin']; if (file_exists($muplugin_path)) { @wp_delete_file($muplugin_path); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- ignore this } $aio_wp_security->configs->set_value('aios_firewall_dismiss', false, true); } }