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


PHP wfUtils::inet_ntoa方法代码示例

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


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

示例1: getHits

 public function getHits($hitType, $type, $afterTime, $limit = 50, $IP = false)
 {
     $serverTime = $this->getDB()->querySingle("select unix_timestamp()");
     $IPSQL = "";
     if ($IP) {
         $IPSQL = " and IP=INET_ATON(%s) ";
         $sqlArgs = array($afterTime, $IP, $limit);
     } else {
         $sqlArgs = array($afterTime, $limit);
     }
     if ($hitType == 'hits') {
         if ($type == 'hit') {
             $typeSQL = " ";
         } else {
             if ($type == 'crawler') {
                 $now = time();
                 $typeSQL = " and jsRun = 0 and {$now} - ctime > 30 ";
             } else {
                 if ($type == 'gCrawler') {
                     $typeSQL = " and isGoogle = 1 ";
                 } else {
                     if ($type == '404') {
                         $typeSQL = " and is404 = 1 ";
                     } else {
                         if ($type == 'human') {
                             $typeSQL = " and jsRun = 1 ";
                         } else {
                             if ($type == 'ruser') {
                                 $typeSQL = " and userID > 0 ";
                             } else {
                                 wordfence::status(1, 'error', "Invalid log type to wfLog: {$type}");
                                 return false;
                             }
                         }
                     }
                 }
             }
         }
         array_unshift($sqlArgs, "select * from " . $this->hitsTable . " where ctime > %f {$IPSQL} {$typeSQL} order by ctime desc limit %d");
         $results = call_user_func_array(array($this->getDB(), 'querySelect'), $sqlArgs);
     } else {
         if ($hitType == 'logins') {
             array_unshift($sqlArgs, "select * from " . $this->loginsTable . " where ctime > %f {$IPSQL} order by ctime desc limit %d");
             $results = call_user_func_array(array($this->getDB(), 'querySelect'), $sqlArgs);
         } else {
             wordfence::status(1, 'error', "getHits got invalid hitType: {$hitType}");
             return false;
         }
     }
     $this->resolveIPs($results);
     $ourURL = parse_url(site_url());
     $ourHost = strtolower($ourURL['host']);
     $ourHost = preg_replace('/^www\\./i', '', $ourHost);
     $browscap = new wfBrowscap();
     foreach ($results as &$res) {
         $res['type'] = $type;
         $res['timeAgo'] = wfUtils::makeTimeAgo($serverTime - $res['ctime']);
         $res['blocked'] = $this->getDB()->querySingle("select blockedTime from " . $this->blocksTable . " where IP=%s and (permanent = 1 OR (blockedTime + %s > unix_timestamp()))", $res['IP'], wfConfig::get('blockedTime'));
         $res['IP'] = wfUtils::inet_ntoa($res['IP']);
         $res['extReferer'] = false;
         if (isset($res['referer']) && $res['referer']) {
             $refURL = parse_url($res['referer']);
             if (is_array($refURL) && $refURL['host']) {
                 $refHost = strtolower(preg_replace('/^www\\./i', '', $refURL['host']));
                 if ($refHost != $ourHost) {
                     $res['extReferer'] = true;
                     //now extract search terms
                     $q = false;
                     if (preg_match('/(?:google|bing|alltheweb|aol|ask)\\./i', $refURL['host'])) {
                         $q = 'q';
                     } else {
                         if (stristr($refURL['host'], 'yahoo.')) {
                             $q = 'p';
                         } else {
                             if (stristr($refURL['host'], 'baidu.')) {
                                 $q = 'wd';
                             }
                         }
                     }
                     if ($q) {
                         $queryVars = array();
                         if (isset($refURL['query'])) {
                             parse_str($refURL['query'], $queryVars);
                             if (isset($queryVars[$q])) {
                                 $res['searchTerms'] = $queryVars[$q];
                             }
                         }
                     }
                 }
             }
             if ($res['extReferer']) {
                 if (isset($referringPage) && stristr($referringPage['host'], 'google.')) {
                     parse_str($referringPage['query'], $queryVars);
                     echo $queryVars['q'];
                     // This is the search term used
                 }
             }
         }
         $res['browser'] = false;
         if ($res['UA']) {
//.........这里部分代码省略.........
开发者ID:roycocup,项目名称:enclothed,代码行数:101,代码来源:wfLog.php

示例2: updateBlockedIPs

 public static function updateBlockedIPs($action)
 {
     //'add' or 'remove'
     if (wfConfig::get('cacheType') != 'falcon') {
         return;
     }
     $htaccessPath = ABSPATH . '/.htaccess';
     if ($action == 'remove') {
         $fh = fopen($htaccessPath, 'r+');
         if (!$fh) {
             $err = error_get_last();
             return $err['message'];
         }
         flock($fh, LOCK_EX);
         fseek($fh, 0, SEEK_SET);
         //start of file
         $contents = fread($fh, filesize($htaccessPath));
         if (!$contents) {
             fclose($fh);
             return "Could not read from {$htaccessPath}";
         }
         $contents = preg_replace('/#WFIPBLOCKS.*WFIPBLOCKS[r\\s\\n\\t]*/s', '', $contents);
         ftruncate($fh, 0);
         fseek($fh, 0, SEEK_SET);
         fwrite($fh, $contents);
         flock($fh, LOCK_UN);
         fclose($fh);
         return false;
     } else {
         if ($action == 'add') {
             $lines = array();
             $wfLog = new wfLog(wfConfig::get('apiKey'), wfUtils::getWPVersion());
             $IPs = $wfLog->getBlockedIPsAddrOnly();
             if (sizeof($IPs) > 0) {
                 foreach ($IPs as $IP) {
                     $lines[] = "Deny from {$IP}\n";
                 }
             }
             $ranges = $wfLog->getRangesBasic();
             $browserAdded = false;
             $browserLines = array();
             if ($ranges) {
                 foreach ($ranges as $r) {
                     $arr = explode('|', $r);
                     $range = isset($arr[0]) ? $arr[0] : false;
                     $browser = isset($arr[1]) ? $arr[1] : false;
                     if ($range && $browser) {
                         continue;
                         //Don't process browser and range combos
                     } else {
                         if ($range) {
                             $ips = explode('-', $range);
                             $cidrs = wfUtils::rangeToCIDRs($ips[0], $ips[1]);
                             $hIPs = wfUtils::inet_ntoa($ips[0]) . ' - ' . wfUtils::inet_ntoa($ips[1]);
                             if (sizeof($cidrs) > 0) {
                                 $lines[] = '#Start of blocking code for IP range: ' . $hIPs . "\n";
                                 foreach ($cidrs as $c) {
                                     $lines[] = "Deny from {$c}\n";
                                 }
                                 $lines[] = '#End of blocking code for IP range: ' . $hIPs . "\n";
                             }
                         } else {
                             if ($browser) {
                                 $browserLines[] = "\t#Blocking code for browser pattern: {$browser}\n";
                                 $browser = preg_replace('/([\\-\\_\\.\\+\\!\\@\\#\\$\\%\\^\\&\\(\\)\\[\\]\\{\\}\\/])/', "\\\\\$1", $browser);
                                 $browser = preg_replace('/\\*/', '.*', $browser);
                                 $browserLines[] = "\tSetEnvIf User-Agent " . $browser . " WordfenceBadBrowser=1\n";
                                 $browserAdded = true;
                             }
                         }
                     }
                 }
             }
             if ($browserAdded) {
                 $lines[] = "<IfModule mod_setenvif.c>\n";
                 foreach ($browserLines as $l) {
                     $lines[] = $l;
                 }
                 $lines[] = "\tDeny from env=WordfenceBadBrowser\n";
                 $lines[] = "</IfModule>\n";
             }
         }
     }
     $blockCode = "#WFIPBLOCKS - Do not remove this line. Disable Web Caching in Wordfence to remove this data.\nOrder Deny,Allow\n";
     $blockCode .= implode('', $lines);
     $blockCode .= "#Do not remove this line. Disable Web Caching in Wordfence to remove this data - WFIPBLOCKS\n";
     $fh = fopen($htaccessPath, 'r+');
     if (!$fh) {
         $err = error_get_last();
         return $err['message'];
     }
     //Minimize time between lock/unlock
     flock($fh, LOCK_EX);
     fseek($fh, 0, SEEK_SET);
     //start of file
     $contents = fread($fh, filesize($htaccessPath));
     if (!$contents) {
         fclose($fh);
         return "Could not read from {$htaccessPath}";
     }
//.........这里部分代码省略.........
开发者ID:roycocup,项目名称:enclothed,代码行数:101,代码来源:wfCache.php

示例3: updateBlockedIPs

	public static function updateBlockedIPs($action){ //'add' or 'remove'
		if(wfConfig::get('cacheType') != 'falcon'){ return; }

		$htaccessPath = self::getHtaccessPath();
		if(! $htaccessPath){
			return "Wordfence could not find your .htaccess file.";
		}
		if($action == 'remove'){
			$fh = @fopen($htaccessPath, 'r+');
			if(! $fh){
				$err = error_get_last();
				return $err['message'];
			}
			flock($fh, LOCK_EX);
			fseek($fh, 0, SEEK_SET); //start of file
			clearstatcache();
			$contents = @fread($fh, filesize($htaccessPath));
			if(! $contents){
				fclose($fh);
				return "Could not read from $htaccessPath";
			}

			$contents = preg_replace('/#WFIPBLOCKS.*WFIPBLOCKS[r\s\n\t]*/s', '', $contents);

			ftruncate($fh, 0);
			fseek($fh, 0, SEEK_SET);
			@fwrite($fh, $contents);
			flock($fh, LOCK_UN);
			fclose($fh);
			return false;
		} else if($action == 'add'){
			$fh = @fopen($htaccessPath, 'r+');
			if(! $fh){
				$err = error_get_last();
				return $err['message'];
			}

			$lines = array();
			$wfLog = new wfLog(wfConfig::get('apiKey'), wfUtils::getWPVersion());
			$IPs = $wfLog->getBlockedIPsAddrOnly();
			if(sizeof($IPs) > 0){
				foreach($IPs as $IP){
					$lines[] = "Deny from $IP\n";
				}
			}
			$ranges = $wfLog->getRangesBasic();
			$browserAdded = false;
			$browserLines = array();
			if($ranges){
				foreach($ranges as $r){
					$arr = explode('|', $r);
					$range = isset($arr[0]) ? $arr[0] : false;
					$browser = isset($arr[1]) ? $arr[1] : false;
					$referer = isset($arr[2]) ? $arr[2] : false;

					if($range){
						if($browser || $referer){ continue; } //We don't allow combos in falcon
						$ips = explode('-', $range);
						$cidrs = wfUtils::rangeToCIDRs($ips[0], $ips[1]);
						$hIPs = wfUtils::inet_ntoa($ips[0]) . ' - ' . wfUtils::inet_ntoa($ips[1]);
						if(sizeof($cidrs) > 0){
							$lines[] = '#Start of blocking code for IP range: ' . $hIPs . "\n";
							foreach($cidrs as $c){
								$lines[] = "Deny from $c\n";
							}
							$lines[] = '#End of blocking code for IP range: ' . $hIPs . "\n";
						}
					} else if($browser){
						if($range || $referer){ continue; }
						$browserLines[] = "\t#Blocking code for browser pattern: $browser\n";
						$browser = preg_replace('/([\-\_\.\+\!\@\#\$\%\^\&\(\)\[\]\{\}\/])/', "\\\\$1", $browser);
						$browser = preg_replace('/\*/', '.*', $browser);
						$browserLines[] = "\tSetEnvIf User-Agent " . $browser . " WordfenceBadBrowser=1\n";
						$browserAdded = true;
					} else if($referer){
						if($browser || $range){ continue; }
						$browserLines[] = "\t#Blocking code for referer pattern: $referer\n";
						$referer = preg_replace('/([\-\_\.\+\!\@\#\$\%\^\&\(\)\[\]\{\}\/])/', "\\\\$1", $referer);
						$referer = preg_replace('/\*/', '.*', $referer);
						$browserLines[] = "\tSetEnvIf Referer " . $referer . " WordfenceBadBrowser=1\n";
						$browserAdded = true;
					}
				}
			}
			if($browserAdded){
				$lines[] = "<IfModule mod_setenvif.c>\n";
				foreach($browserLines as $l){
					$lines[] = $l;
				}
				$lines[] = "\tDeny from env=WordfenceBadBrowser\n";
				$lines[] = "</IfModule>\n";
			}
		}
		$blockCode = "#WFIPBLOCKS - Do not remove this line. Disable Web Caching in Wordfence to remove this data.\nOrder Deny,Allow\n";
		$blockCode .= implode('', $lines);
		$blockCode .= "#Do not remove this line. Disable Web Caching in Wordfence to remove this data - WFIPBLOCKS\n";


		//Minimize time between lock/unlock
		flock($fh, LOCK_EX);
//.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:101,代码来源:wfCache.php


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