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


PHP wfUtils::patternToRegex方法代码示例

本文整理汇总了PHP中wfUtils::patternToRegex方法的典型用法代码示例。如果您正苦于以下问题:PHP wfUtils::patternToRegex方法的具体用法?PHP wfUtils::patternToRegex怎么用?PHP wfUtils::patternToRegex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wfUtils的用法示例。


在下文中一共展示了wfUtils::patternToRegex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: veryFirstAction


//.........这里部分代码省略.........
                         header('Location: ' . wp_login_url());
                         exit;
                     } else {
                         echo "Invalid function specified. Please check the link we emailed you and make sure it was not cut-off by your email reader.";
                         exit;
                     }
                 }
             }
         }
     }
     // Sync the WAF data with the database.
     if (!WFWAF_SUBDIRECTORY_INSTALL && ($waf = wfWAF::getInstance())) {
         try {
             $configDefaults = array('apiKey' => wfConfig::get('apiKey'), 'isPaid' => wfConfig::get('isPaid'), 'siteURL' => site_url(), 'homeURL' => home_url(), 'whitelistedIPs' => (string) wfConfig::get('whitelisted'), 'howGetIPs' => (string) wfConfig::get('howGetIPs'));
             foreach ($configDefaults as $key => $value) {
                 $waf->getStorageEngine()->setConfig($key, $value);
             }
             if (empty($_GET['wordfence_syncAttackData'])) {
                 $lastAttackMicroseconds = $wpdb->get_var("SELECT MAX(attackLogTime) FROM {$wpdb->base_prefix}wfHits");
                 if ($waf->getStorageEngine()->hasNewerAttackData($lastAttackMicroseconds)) {
                     if (get_site_option('wordfence_syncingAttackData') <= time() - 60) {
                         // Could be the request to itself is not completing, add ajax to the head as a workaround
                         $attempts = get_site_option('wordfence_syncAttackDataAttempts', 0);
                         if ($attempts > 10) {
                             add_action('wp_head', 'wordfence::addSyncAttackDataAjax');
                             add_action('login_head', 'wordfence::addSyncAttackDataAjax');
                             add_action('admin_head', 'wordfence::addSyncAttackDataAjax');
                         } else {
                             update_site_option('wordfence_syncAttackDataAttempts', ++$attempts);
                             wp_remote_post(add_query_arg('wordfence_syncAttackData', microtime(true), home_url('/')), array('timeout' => 0.01, 'blocking' => false, 'sslverify' => apply_filters('https_local_ssl_verify', false)));
                         }
                     }
                 }
             }
             if ($waf instanceof wfWAFWordPress && ($learningModeAttackException = $waf->getLearningModeAttackException())) {
                 $log = self::getLog();
                 $log->initLogRequest();
                 $request = $log->getCurrentRequest();
                 $request->action = 'learned:waf';
                 $request->attackLogTime = microtime(true);
                 $ruleIDs = array();
                 /** @var wfWAFRule $failedRule */
                 foreach ($learningModeAttackException->getFailedRules() as $failedRule) {
                     $ruleIDs[] = $failedRule->getRuleID();
                 }
                 $actionData = array('learningMode' => 1, 'failedRules' => $ruleIDs, 'paramKey' => $learningModeAttackException->getParamKey(), 'paramValue' => $learningModeAttackException->getParamValue());
                 if ($ruleIDs && $ruleIDs[0]) {
                     $rule = $waf->getRule($ruleIDs[0]);
                     if ($rule) {
                         $request->actionDescription = $rule->getDescription();
                         $actionData['category'] = $rule->getCategory();
                         $actionData['ssl'] = $waf->getRequest()->getProtocol() === 'https';
                         $actionData['fullRequest'] = base64_encode($waf->getRequest());
                     }
                 }
                 $request->actionData = wfRequestModel::serializeActionData($actionData);
                 register_shutdown_function(array($request, 'save'));
                 self::scheduleSendAttackData();
             }
         } catch (wfWAFStorageFileException $e) {
             // We don't have anywhere to write files in this scenario.
         }
     }
     if (wfConfig::get('firewallEnabled')) {
         $wfLog = self::getLog();
         $wfLog->firewallBadIPs();
         $IP = wfUtils::getIP();
         if ($wfLog->isWhitelisted($IP)) {
             return;
         }
         if (wfConfig::get('neverBlockBG') == 'neverBlockUA' && wfCrawl::isGoogleCrawler()) {
             return;
         }
         if (wfConfig::get('neverBlockBG') == 'neverBlockVerified' && wfCrawl::isVerifiedGoogleCrawler()) {
             return;
         }
         if (wfConfig::get('blockFakeBots')) {
             if (wfCrawl::isGooglebot() && !wfCrawl::isVerifiedGoogleCrawler()) {
                 $wfLog->blockIP($IP, "Fake Google crawler automatically blocked");
                 wordfence::status(2, 'info', "Blocking fake Googlebot at IP {$IP}");
                 $wfLog->do503(3600, "Fake Google crawler automatically blocked.");
             }
         }
         if (wfConfig::get('bannedURLs', false)) {
             $URLs = explode(',', wfConfig::get('bannedURLs'));
             foreach ($URLs as $URL) {
                 if (preg_match(wfUtils::patternToRegex($URL, ''), $_SERVER['REQUEST_URI'])) {
                     $wfLog->blockIP($IP, "Accessed a banned URL.");
                     $wfLog->do503(3600, "Accessed a banned URL.");
                     //exits
                 }
             }
         }
         if (wfConfig::get('other_blockBadPOST') == '1' && $_SERVER['REQUEST_METHOD'] == 'POST' && empty($_SERVER['HTTP_USER_AGENT']) && empty($_SERVER['HTTP_REFERER'])) {
             $wfLog->blockIP($IP, "POST received with blank user-agent and referer");
             $wfLog->do503(3600, "POST received with blank user-agent and referer");
             //exits
         }
     }
 }
开发者ID:ashenkar,项目名称:sanga,代码行数:101,代码来源:wordfenceClass.php

示例2: firewallBadIPs

 public function firewallBadIPs()
 {
     $IP = wfUtils::getIP();
     if ($this->isWhitelisted($IP)) {
         return;
     }
     $IPnum = wfUtils::inet_pton($IP);
     $hostname = null;
     //New range and UA pattern blocking:
     $r1 = $this->getDB()->querySelect("select id, blockType, blockString from " . $this->ipRangesTable);
     foreach ($r1 as $blockRec) {
         if ($blockRec['blockType'] == 'IU') {
             $ipRangeBlocked = false;
             $uaPatternBlocked = false;
             $refBlocked = false;
             $bDat = explode('|', $blockRec['blockString']);
             $ipRange = $bDat[0];
             $uaPattern = $bDat[1];
             $refPattern = isset($bDat[2]) ? $bDat[2] : '';
             if ($ipRange) {
                 list($start_range, $end_range) = explode('-', $ipRange);
                 if (preg_match('/[\\.:]/', $start_range)) {
                     $start_range = wfUtils::inet_pton($start_range);
                     $end_range = wfUtils::inet_pton($end_range);
                 } else {
                     $start_range = wfUtils::inet_pton(long2ip($start_range));
                     $end_range = wfUtils::inet_pton(long2ip($end_range));
                 }
                 if (strcmp($IPnum, $start_range) >= 0 && strcmp($IPnum, $end_range) <= 0) {
                     $ipRangeBlocked = true;
                 }
             }
             if (!empty($bDat[3])) {
                 $ipRange = true;
                 /* We reuse the ipRangeBlocked variable */
                 if ($hostname === null) {
                     $hostname = wfUtils::reverseLookup($IP);
                 }
                 if (preg_match(wfUtils::patternToRegex($bDat[3]), $hostname)) {
                     $ipRangeBlocked = true;
                 }
             }
             if ($uaPattern) {
                 if (wfUtils::isUABlocked($uaPattern)) {
                     $uaPatternBlocked = true;
                 }
             }
             if ($refPattern) {
                 if (wfUtils::isRefererBlocked($refPattern)) {
                     $refBlocked = true;
                 }
             }
             $doBlock = false;
             if ($uaPattern && $ipRange && $refPattern) {
                 if ($uaPatternBlocked && $ipRangeBlocked && $refBlocked) {
                     $doBlock = true;
                 }
             }
             if ($uaPattern && $ipRange) {
                 if ($uaPatternBlocked && $ipRangeBlocked) {
                     $doBlock = true;
                 }
             }
             if ($uaPattern && $refPattern) {
                 if ($uaPatternBlocked && $refBlocked) {
                     $doBlock = true;
                 }
             }
             if ($ipRange && $refPattern) {
                 if ($ipRangeBlocked && $refBlocked) {
                     $doBlock = true;
                 }
             } else {
                 if ($uaPattern) {
                     if ($uaPatternBlocked) {
                         $doBlock = true;
                     }
                 } else {
                     if ($ipRange) {
                         if ($ipRangeBlocked) {
                             $doBlock = true;
                         }
                     } else {
                         if ($refPattern) {
                             if ($refBlocked) {
                                 $doBlock = true;
                             }
                         }
                     }
                 }
             }
             if ($doBlock) {
                 $this->getDB()->queryWrite("update " . $this->ipRangesTable . " set totalBlocked = totalBlocked + 1, lastBlocked = unix_timestamp() where id=%d", $blockRec['id']);
                 wfActivityReport::logBlockedIP($IP);
                 $this->currentRequest->actionDescription = 'UA/Referrer/IP Range not allowed';
                 $this->do503(3600, "Advanced blocking in effect.");
             }
         }
     }
     //End range/UA blocking
//.........这里部分代码省略.........
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:101,代码来源:wfLog.php

示例3: firewallBadIPs

 public function firewallBadIPs()
 {
     $IP = wfUtils::getIP();
     if ($this->isWhitelisted($IP)) {
         return;
     }
     $IPnum = wfUtils::inet_pton($IP);
     $hostname = null;
     //New range and UA pattern blocking:
     $r1 = $this->getDB()->querySelect("select id, blockType, blockString from " . $this->ipRangesTable);
     foreach ($r1 as $blockRec) {
         if ($blockRec['blockType'] == 'IU') {
             $ipRangeBlocked = false;
             $uaPatternBlocked = false;
             $refBlocked = false;
             $bDat = explode('|', $blockRec['blockString']);
             $ipRange = $bDat[0];
             $uaPattern = $bDat[1];
             $refPattern = isset($bDat[2]) ? $bDat[2] : '';
             if ($ipRange) {
                 list($start_range, $end_range) = explode('-', $ipRange);
                 if (preg_match('/[\\.:]/', $start_range)) {
                     $start_range = wfUtils::inet_pton($start_range);
                     $end_range = wfUtils::inet_pton($end_range);
                 } else {
                     $start_range = wfUtils::inet_pton(long2ip($start_range));
                     $end_range = wfUtils::inet_pton(long2ip($end_range));
                 }
                 if (strcmp($IPnum, $start_range) >= 0 && strcmp($IPnum, $end_range) <= 0) {
                     $ipRangeBlocked = true;
                 }
             }
             if (!empty($bDat[3])) {
                 $ipRange = true;
                 /* We reuse the ipRangeBlocked variable */
                 if ($hostname === null) {
                     $hostname = wfUtils::reverseLookup($IP);
                 }
                 if (preg_match(wfUtils::patternToRegex($bDat[3]), $hostname)) {
                     $ipRangeBlocked = true;
                 }
             }
             if ($uaPattern) {
                 if (wfUtils::isUABlocked($uaPattern)) {
                     $uaPatternBlocked = true;
                 }
             }
             if ($refPattern) {
                 if (wfUtils::isRefererBlocked($refPattern)) {
                     $refBlocked = true;
                 }
             }
             $doBlock = false;
             if ($uaPattern && $ipRange && $refPattern) {
                 if ($uaPatternBlocked && $ipRangeBlocked && $refBlocked) {
                     $doBlock = true;
                 }
             }
             if ($uaPattern && $ipRange) {
                 if ($uaPatternBlocked && $ipRangeBlocked) {
                     $doBlock = true;
                 }
             }
             if ($uaPattern && $refPattern) {
                 if ($uaPatternBlocked && $refBlocked) {
                     $doBlock = true;
                 }
             }
             if ($ipRange && $refPattern) {
                 if ($ipRangeBlocked && $refBlocked) {
                     $doBlock = true;
                 }
             } else {
                 if ($uaPattern) {
                     if ($uaPatternBlocked) {
                         $doBlock = true;
                     }
                 } else {
                     if ($ipRange) {
                         if ($ipRangeBlocked) {
                             $doBlock = true;
                         }
                     } else {
                         if ($refPattern) {
                             if ($refBlocked) {
                                 $doBlock = true;
                             }
                         }
                     }
                 }
             }
             if ($doBlock) {
                 $this->getDB()->queryWrite("update " . $this->ipRangesTable . " set totalBlocked = totalBlocked + 1, lastBlocked = unix_timestamp() where id=%d", $blockRec['id']);
                 wfActivityReport::logBlockedIP($IP);
                 $this->currentRequest->actionDescription = 'UA/Referrer/IP Range not allowed';
                 $this->do503(3600, "Advanced blocking in effect.");
             }
         }
     }
     //End range/UA blocking
//.........这里部分代码省略.........
开发者ID:ashenkar,项目名称:sanga,代码行数:101,代码来源:wfLog.php

示例4: getHtaccessCode

    public static function getHtaccessCode()
    {
        $siteURL = site_url();
        $homeURL = home_url();
        $pathPrefix = "";
        if (preg_match('/^https?:\\/\\/[^\\/]+\\/(.+)$/i', $siteURL, $matches)) {
            $path = $matches[1];
            $path = preg_replace('/^\\//', '', $path);
            $path = preg_replace('/\\/$/', '', $path);
            $pathPrefix = '/' . $path;
            // Which is: /my/path
        }
        $matchCaps = '$1/$2~$3~$4~$5~$6';
        if (preg_match('/^https?:\\/\\/[^\\/]+\\/(.+)$/i', $homeURL, $matches)) {
            $path = $matches[1];
            $path = preg_replace('/^\\//', '', $path);
            $path = preg_replace('/\\/$/', '', $path);
            $pieces = explode('/', $path);
            if (count($pieces) == 1) {
                # No path:       "/wp-content/wfcache/%{HTTP_HOST}_$1/$2~$3~$4~$5~$6_wfcache%{ENV:WRDFNC_HTTPS}.html%{ENV:WRDFNC_ENC}" [L]
                # One path:  "/mdm/wp-content/wfcache/%{HTTP_HOST}_mdm/$1~$2~$3~$4~$5_wfcache%{ENV:WRDFNC_HTTPS}.html%{ENV:WRDFNC_ENC}" [L]
                $matchCaps = $pieces[0] . '/$1~$2~$3~$4~$5';
            } else {
                if (count($pieces) == 2) {
                    $matchCaps = $pieces[0] . '/' . $pieces[1] . '/$1~$2~$3~$4';
                } else {
                    $matchCaps = '$1/$2~$3~$4~$5~$6';
                    #defaults to the regular setting but this won't work. However user should already have gotten a warning that we don't support sites more than 2 dirs deep with falcon.
                }
            }
        }
        $sslString = "RewriteCond %{HTTPS} off";
        if (wfConfig::get('allowHTTPSCaching')) {
            $sslString = "";
        }
        $otherRewriteConds = "";
        $ex = wfConfig::get('cacheExclusions', false);
        if ($ex) {
            $ex = unserialize($ex);
            foreach ($ex as $v) {
                if ($v['pt'] == 'uac') {
                    $otherRewriteConds .= "\n\tRewriteCond %{HTTP_USER_AGENT} !" . self::regexSpaceFix(preg_quote($v['p'])) . " [NC]";
                }
                if ($v['pt'] == 'uaeq') {
                    $otherRewriteConds .= "\n\tRewriteCond %{HTTP_USER_AGENT} !^" . self::regexSpaceFix(preg_quote($v['p'])) . "\$ [NC]";
                }
                if ($v['pt'] == 'cc') {
                    $otherRewriteConds .= "\n\tRewriteCond %{HTTP_COOKIE} !" . self::regexSpaceFix(preg_quote($v['p'])) . " [NC]";
                }
            }
        }
        //We exclude URLs that are banned so that Wordfence PHP code can catch the IP address, then ban that IP and the ban is added to .htaccess.
        $excludedURLs = "";
        if (wfConfig::get('bannedURLs', false)) {
            foreach (explode(',', wfConfig::get('bannedURLs', false)) as $URL) {
                $excludedURLs .= "RewriteCond %{REQUEST_URI} !" . wfUtils::patternToRegex($URL, '', '') . "\n\t";
            }
        }
        $code = <<<EOT
#WFCACHECODE - Do not remove this line. Disable Web Caching in Wordfence to remove this data.
<IfModule mod_deflate.c>
\tAddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json
\t<IfModule mod_headers.c>
\t\tHeader append Vary User-Agent env=!dont-vary
\t</IfModule>
\t<IfModule mod_mime.c>
\t\tAddOutputFilter DEFLATE js css htm html xml
\t</IfModule>
</IfModule>
<IfModule mod_mime.c>
\tAddType text/html .html_gzip
\tAddEncoding gzip .html_gzip
\tAddType text/xml .xml_gzip
\tAddEncoding gzip .xml_gzip
</IfModule>
<IfModule mod_setenvif.c>
\tSetEnvIfNoCase Request_URI \\.html_gzip\$ no-gzip
\tSetEnvIfNoCase Request_URI \\.xml_gzip\$ no-gzip
</IfModule>
<IfModule mod_headers.c>
\tHeader set Vary "Accept-Encoding, Cookie"
</IfModule>
<IfModule mod_rewrite.c>
\t#Prevents garbled chars in cached files if there is no default charset.
\tAddDefaultCharset utf-8

\t#Cache rules:
\tRewriteEngine On
\tRewriteBase /
\tRewriteCond %{HTTPS} on
\tRewriteRule .* - [E=WRDFNC_HTTPS:_https]
\tRewriteCond %{HTTP:Accept-Encoding} gzip
\tRewriteRule .* - [E=WRDFNC_ENC:_gzip]
\tRewriteCond %{REQUEST_METHOD} !=POST
\t{$sslString}
\tRewriteCond %{QUERY_STRING} ^(?:\\d+=\\d+)?\$
\tRewriteCond %{REQUEST_URI} (?:\\/|\\.html)\$ [NC]
\t{$excludedURLs}
\tRewriteCond %{HTTP_COOKIE} !(comment_author|wp\\-postpass|wf_logout|wordpress_logged_in|wptouch_switch_toggle|wpmp_switcher) [NC]
\t{$otherRewriteConds}
//.........这里部分代码省略.........
开发者ID:ashenkar,项目名称:sanga,代码行数:101,代码来源:wfCache.php


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