当前位置: 首页>>代码示例>>PHP>>正文


PHP wordfence::getWAFBootstrapContent方法代码示例

本文整理汇总了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)));
//.........这里部分代码省略.........
开发者ID:ashenkar,项目名称:sanga,代码行数:101,代码来源:wordfenceClass.php


注:本文中的wordfence::getWAFBootstrapContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。