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


PHP wfUtils::countryCode2Name方法代码示例

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


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

示例1: displayIP

 public function displayIP($binaryIP)
 {
     $readableIP = wfUtils::inet_ntop($binaryIP);
     $country = wfUtils::countryCode2Name(wfUtils::IP2Country($readableIP));
     return "{$readableIP} (" . ($country ? $country : 'Unknown') . ")";
 }
开发者ID:GafaMX,项目名称:operaciondespierta.org,代码行数:6,代码来源:wfActivityReport.php

示例2: processAttackData

    /**
     *
     */
    public static function processAttackData()
    {
        global $wpdb;
        $waf = wfWAF::getInstance();
        if ($waf->getStorageEngine()->getConfig('attackDataKey', false) === false) {
            $waf->getStorageEngine()->setConfig('attackDataKey', mt_rand(0, 0xfff));
        }
        //Send alert email if needed
        if (wfConfig::get('wafAlertOnAttacks')) {
            $alertInterval = wfConfig::get('wafAlertInterval', 0);
            $cutoffTime = max(time() - $alertInterval, wfConfig::get('wafAlertLastSendTime'));
            $wafAlertWhitelist = wfConfig::get('wafAlertWhitelist', '');
            $wafAlertWhitelist = preg_split("/[,\r\n]+/", $wafAlertWhitelist);
            foreach ($wafAlertWhitelist as $index => &$entry) {
                $entry = trim($entry);
                if (!preg_match('/^(?:\\d{1,3}(?:\\.|$)){4}/', $entry) && !preg_match('/^((?:[\\da-f]{1,4}(?::|)){0,8})(::)?((?:[\\da-f]{1,4}(?::|)){0,8})$/i', $entry)) {
                    unset($wafAlertWhitelist[$index]);
                    continue;
                }
                $packed = @wfUtils::inet_pton($entry);
                if ($packed === false) {
                    unset($wafAlertWhitelist[$index]);
                    continue;
                }
                $entry = bin2hex($packed);
            }
            $wafAlertWhitelist = array_filter($wafAlertWhitelist);
            $attackData = $wpdb->get_results($wpdb->prepare("SELECT SQL_CALC_FOUND_ROWS * FROM {$wpdb->base_prefix}wfHits\n\tWHERE action = 'blocked:waf' " . (count($wafAlertWhitelist) ? "AND HEX(IP) NOT IN (" . implode(", ", array_fill(0, count($wafAlertWhitelist), '%s')) . ")" : "") . "AND attackLogTime > %.6f\n\tORDER BY attackLogTime DESC\n\tLIMIT 10", array_merge($wafAlertWhitelist, array($cutoffTime))));
            $attackCount = $wpdb->get_var('SELECT FOUND_ROWS()');
            if ($attackCount >= wfConfig::get('wafAlertThreshold')) {
                $durationMessage = wfUtils::makeDuration($alertInterval);
                $message = <<<ALERTMSG
The Wordfence Web Application Firewall has blocked {$attackCount} attacks over the last {$durationMessage}. Below is a sample of these recent attacks:


ALERTMSG;
                $attackTable = array();
                $dateMax = $ipMax = $countryMax = 0;
                foreach ($attackData as $row) {
                    $row->longDescription = "Blocked for " . $row->actionDescription;
                    $actionData = json_decode($row->actionData, true);
                    if (!is_array($actionData) || !isset($actionData['paramKey']) || !isset($actionData['paramValue'])) {
                        continue;
                    }
                    $paramKey = base64_decode($actionData['paramKey']);
                    $paramValue = base64_decode($actionData['paramValue']);
                    if (strlen($paramValue) > 100) {
                        $paramValue = substr($paramValue, 0, 100) . chr(2026);
                    }
                    if (preg_match('/([a-z0-9_]+\\.[a-z0-9_]+)(?:\\[(.+?)\\](.*))?/i', $paramKey, $matches)) {
                        switch ($matches[1]) {
                            case 'request.queryString':
                                $row->longDescription = "Blocked for " . $row->actionDescription . ' in query string: ' . $matches[2] . '=' . $paramValue;
                                break;
                            case 'request.body':
                                $row->longDescription = "Blocked for " . $row->actionDescription . ' in POST body: ' . $matches[2] . '=' . $paramValue;
                                break;
                            case 'request.cookie':
                                $row->longDescription = "Blocked for " . $row->actionDescription . ' in cookie: ' . $matches[2] . '=' . $paramValue;
                                break;
                            case 'request.fileNames':
                                $row->longDescription = "Blocked for a " . $row->actionDescription . ' in file: ' . $matches[2] . '=' . $paramValue;
                                break;
                        }
                    }
                    $date = date_i18n('F j, Y g:ia', floor($row->attackLogTime));
                    $dateMax = max(strlen($date), $dateMax);
                    $ip = wfUtils::inet_ntop($row->IP);
                    $ipMax = max(strlen($ip), $ipMax);
                    $country = wfUtils::countryCode2Name(wfUtils::IP2Country($ip));
                    $country = empty($country) ? 'Unknown' : $country;
                    $countryMax = max(strlen($country), $countryMax);
                    $attackTable[] = array('date' => $date, 'IP' => $ip, 'country' => $country, 'message' => $row->longDescription);
                }
                foreach ($attackTable as $row) {
                    $date = str_pad($row['date'], $dateMax + 2);
                    $ip = str_pad($row['IP'] . " ({$row['country']})", $ipMax + $countryMax + 8);
                    $attackMessage = $row['message'];
                    $message .= $date . $ip . $attackMessage . "\n";
                }
                self::alert('Increased Attack Rate', $message, false);
                wfConfig::set('wafAlertLastSendTime', time());
            }
        }
        //Send attack data
        $limit = 500;
        $lastSendTime = wfConfig::get('lastAttackDataSendTime');
        $attackData = $wpdb->get_results($wpdb->prepare("SELECT SQL_CALC_FOUND_ROWS * FROM {$wpdb->base_prefix}wfHits\nWHERE action in ('blocked:waf', 'learned:waf', 'logged:waf', 'blocked:waf-always')\nAND attackLogTime > %.6f\nLIMIT %d", $lastSendTime, $limit));
        $totalRows = $wpdb->get_var('SELECT FOUND_ROWS()');
        if ($attackData && wfConfig::get('other_WFNet', true)) {
            $response = wp_remote_get(sprintf(WFWAF_API_URL_SEC . "waf-rules/%d.txt", $waf->getStorageEngine()->getConfig('attackDataKey')));
            if (!is_wp_error($response)) {
                $okToSendBody = wp_remote_retrieve_body($response);
                if ($okToSendBody === 'ok') {
                    // Build JSON to send
                    $dataToSend = array();
                    $attackDataToUpdate = array();
//.........这里部分代码省略.........
开发者ID:Jerram-Marketing,项目名称:Gummer-Co,代码行数:101,代码来源:wordfenceClass.php


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