file_path ); } return (false !== @file_put_contents($this->file_path, $this->get_contents(), FILE_APPEND)); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- ignore this } /** * Checks whether the file's contents are valid * * @param string $contents * @return boolean */ protected function is_content_valid($contents) { $regex = '/php_value auto_prepend_file \'(.*)\'/isU'; $bootstrap_path = AIOWPSecurity_Utility_Firewall::get_bootstrap_path(); $matches = array(); if (preg_match_all($regex, $contents, $matches)) { $match = ''; foreach ($matches[1] as $match) { if ($bootstrap_path !== $match) { return false; } } } else { return false; } return true; } /** * The regex pattern that demarcates our contents * * @return string */ protected function get_regex_pattern() { return '/\r?\n?# Begin AIOWPSEC Firewall(.*?)# End AIOWPSEC Firewall/is'; } /** * Our contents; the required apache directives for auto prepending a file * * @return string */ public function get_contents() { $bootstrap_path = AIOWPSecurity_Utility_Firewall::get_bootstrap_path(); $directives = "\n# Begin AIOWPSEC Firewall\n"; $directives .= "\t\n"; $directives .= "\t\tphp_value auto_prepend_file '{$bootstrap_path}'\n"; $directives .= "\t\n"; $directives .= "\t\n"; $directives .= "\t\tphp_value auto_prepend_file '{$bootstrap_path}'\n"; $directives .= "\t\n"; $directives .= "\t\n"; $directives .= "\t\tphp_value auto_prepend_file '{$bootstrap_path}'\n"; $directives .= "\t\n"; $directives .= "# End AIOWPSEC Firewall"; return $directives; } } //end of class