本文整理匯總了PHP中wordfence::getWAFBootstrapContent方法的典型用法代碼示例。如果您正苦於以下問題:PHP wordfence::getWAFBootstrapContent方法的具體用法?PHP wordfence::getWAFBootstrapContent怎麽用?PHP wordfence::getWAFBootstrapContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wordfence
的用法示例。
在下文中一共展示了wordfence::getWAFBootstrapContent方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: performInstallation
/**
* @param WP_Filesystem_Base $wp_filesystem
* @throws wfWAFAutoPrependHelperException
*/
public function performInstallation($wp_filesystem)
{
$bootstrapPath = wordfence::getWAFBootstrapPath();
if (!$wp_filesystem->put_contents($bootstrapPath, wordfence::getWAFBootstrapContent($this->currentAutoPrependedFile))) {
throw new wfWAFAutoPrependHelperException('We were unable to create the <code>wordfence-waf.php</code> file
in the root of the WordPress installation. It\'s possible WordPress cannot write to the <code>wordfence-waf.php</code>
file because of file permissions. Please verify the permissions are correct and retry the installation.');
}
$serverConfig = $this->getServerConfig();
$htaccessPath = $this->getHtaccessPath();
$homePath = dirname($htaccessPath);
$userIniPath = $this->getUserIniPath();
$userIni = ini_get('user_ini.filename');
$userIniHtaccessDirectives = '';
if ($userIni) {
$userIniHtaccessDirectives = sprintf('<Files "%s">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</Files>
', addcslashes($userIni, '"'));
}
// .htaccess configuration
switch ($serverConfig) {
case 'apache-mod_php':
$autoPrependDirective = sprintf("# Wordfence WAF\n<IfModule mod_php%d.c>\n\tphp_value auto_prepend_file '%s'\n</IfModule>\n{$userIniHtaccessDirectives}\n# END Wordfence WAF\n", PHP_MAJOR_VERSION, addcslashes($bootstrapPath, "'"));
break;
case 'litespeed':
$autoPrependDirective = sprintf("# Wordfence WAF\n<IfModule LiteSpeed>\nphp_value auto_prepend_file '%s'\n</IfModule>\n{$userIniHtaccessDirectives}\n# END Wordfence WAF\n", addcslashes($bootstrapPath, "'"));
break;
case 'apache-suphp':
$autoPrependDirective = sprintf("# Wordfence WAF\n<IfModule mod_suphp.c>\n\tsuPHP_ConfigPath '%s'\n</IfModule>\n{$userIniHtaccessDirectives}\n# END Wordfence WAF\n", addcslashes($homePath, "'"));
break;
case 'cgi':
if ($userIniHtaccessDirectives) {
$autoPrependDirective = sprintf("# Wordfence WAF\n{$userIniHtaccessDirectives}\n# END Wordfence WAF\n", addcslashes($homePath, "'"));
}
break;
}
if (!empty($autoPrependDirective)) {
// Modify .htaccess
$htaccessContent = $wp_filesystem->get_contents($htaccessPath);
if ($htaccessContent) {
$regex = '/# Wordfence WAF.*?# END Wordfence WAF/is';
if (preg_match($regex, $htaccessContent, $matches)) {
$htaccessContent = preg_replace($regex, $autoPrependDirective, $htaccessContent);
} else {
$htaccessContent .= "\n\n" . $autoPrependDirective;
}
} else {
$htaccessContent = $autoPrependDirective;
}
if (!$wp_filesystem->put_contents($htaccessPath, $htaccessContent)) {
throw new wfWAFAutoPrependHelperException('We were unable to make changes to the .htaccess file. It\'s
possible WordPress cannot write to the .htaccess file because of file permissions, which may have been
set by another security plugin, or you may have set them manually. Please verify the permissions allow
the web server to write to the file, and retry the installation.');
}
if ($serverConfig == 'litespeed') {
// sleep(2);
$wp_filesystem->touch($htaccessPath);
}
}
if ($userIni) {
// .user.ini configuration
switch ($serverConfig) {
case 'cgi':
case 'nginx':
case 'apache-suphp':
case 'litespeed':
case 'iis':
$autoPrependIni = sprintf("; Wordfence WAF\nauto_prepend_file = '%s'\n; END Wordfence WAF\n", addcslashes($bootstrapPath, "'"));
break;
}
if (!empty($autoPrependIni)) {
// Modify .user.ini
$userIniContent = $wp_filesystem->get_contents($userIniPath);
if (is_string($userIniContent)) {
$userIniContent = str_replace('auto_prepend_file', ';auto_prepend_file', $userIniContent);
$regex = '/; Wordfence WAF.*?; END Wordfence WAF/is';
if (preg_match($regex, $userIniContent, $matches)) {
$userIniContent = preg_replace($regex, $autoPrependIni, $userIniContent);
} else {
$userIniContent .= "\n\n" . $autoPrependIni;
}
} else {
$userIniContent = $autoPrependIni;
}
if (!$wp_filesystem->put_contents($userIniPath, $userIniContent)) {
throw new wfWAFAutoPrependHelperException(sprintf('We were unable to make changes to the %1$s file.
It\'s possible WordPress cannot write to the %1$s file because of file permissions.
Please verify the permissions are correct and retry the installation.', basename($userIniPath)));
//.........這裏部分代碼省略.........