本文整理汇总了PHP中IP::isInRange方法的典型用法代码示例。如果您正苦于以下问题:PHP IP::isInRange方法的具体用法?PHP IP::isInRange怎么用?PHP IP::isInRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IP
的用法示例。
在下文中一共展示了IP::isInRange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkIP
/**
* Test an IP address
* @param string $ip
* @return bool
*/
public function checkIP($ip)
{
foreach ($this->ipAddresses as $range) {
if (\IP::isInRange($ip, $range)) {
return true;
}
}
return false;
}
示例2: isWhitelistedFromAutoblocks
/**
* Checks whether a given IP is on the autoblock whitelist.
* TODO: this probably belongs somewhere else, but not sure where...
*
* @param string $ip The IP to check
* @return bool
*/
public static function isWhitelistedFromAutoblocks($ip)
{
// Try to get the autoblock_whitelist from the cache, as it's faster
// than getting the msg raw and explode()'ing it.
$cache = ObjectCache::getMainWANInstance();
$lines = $cache->getWithSetCallback(wfMemcKey('ipb', 'autoblock', 'whitelist'), $cache::TTL_DAY, function () {
return explode("\n", wfMessage('autoblock_whitelist')->inContentLanguage()->plain());
});
wfDebug("Checking the autoblock whitelist..\n");
foreach ($lines as $line) {
# List items only
if (substr($line, 0, 1) !== '*') {
continue;
}
$wlEntry = substr($line, 1);
$wlEntry = trim($wlEntry);
wfDebug("Checking {$ip} against {$wlEntry}...");
# Is the IP in this range?
if (IP::isInRange($ip, $wlEntry)) {
wfDebug(" IP {$ip} matches {$wlEntry}, not autoblocking\n");
return true;
} else {
wfDebug(" No match\n");
}
}
return false;
}
示例3: checkAccess
function checkAccess() {
foreach ( $this->accessRanges as $range ) {
if ( IP::isInRange( $_SERVER['REMOTE_ADDR'], $range ) ) {
return true;
}
}
return false;
}
示例4: wfIsConfiguredProxy
/**
* Checks if an IP matches a proxy we've configured.
*
* @param string $ip
* @return bool
* @since 1.23 Supports CIDR ranges in $wgSquidServersNoPurge
*/
function wfIsConfiguredProxy($ip)
{
global $wgSquidServers, $wgSquidServersNoPurge;
// quick check of known proxy servers
$trusted = in_array($ip, $wgSquidServers) || in_array($ip, $wgSquidServersNoPurge);
if (!$trusted) {
// slightly slower check to see if the ip is listed directly or in a CIDR
// block in $wgSquidServersNoPurge
foreach ($wgSquidServersNoPurge as $block) {
if (strpos($block, '/') !== false && IP::isInRange($ip, $block)) {
$trusted = true;
break;
}
}
}
return $trusted;
}
示例5: checkCondition
/**
* As recCheckCondition, but *not* recursive. The only valid conditions
* are those whose first element is APCOND_EMAILCONFIRMED/APCOND_EDITCOUNT/
* APCOND_AGE. Other types will throw an exception if no extension evalu-
* ates them.
*
* @param $cond Array: A condition, which must not contain other conditions
* @param $user User The user to check the condition against
* @return bool Whether the condition is true for the user
*/
private static function checkCondition($cond, User $user)
{
global $wgEmailAuthentication, $wgEnableEditCountLocal;
if (count($cond) < 1) {
return false;
}
switch ($cond[0]) {
case APCOND_EMAILCONFIRMED:
if (Sanitizer::validateEmail($user->getEmail())) {
if ($wgEmailAuthentication) {
return (bool) $user->getEmailAuthenticationTimestamp();
} else {
return true;
}
}
return false;
case APCOND_EDITCOUNT:
if (!empty($wgEnableEditCountLocal)) {
return $user->getEditCountLocal() >= $cond[1];
} else {
return $user->getEditCount() >= $cond[1];
}
case APCOND_AGE:
$age = time() - wfTimestampOrNull(TS_UNIX, $user->getRegistration());
return $age >= $cond[1];
case APCOND_AGE_FROM_EDIT:
$age = time() - wfTimestampOrNull(TS_UNIX, $user->getFirstEditTimestamp());
return $age >= $cond[1];
case APCOND_INGROUPS:
$groups = array_slice($cond, 1);
return count(array_intersect($groups, $user->getGroups())) == count($groups);
case APCOND_ISIP:
return $cond[1] == $user->getRequest()->getIP();
case APCOND_IPINRANGE:
return IP::isInRange($user->getRequest()->getIP(), $cond[1]);
case APCOND_BLOCKED:
return $user->isBlocked();
case APCOND_ISBOT:
return in_array('bot', User::getGroupPermissions($user->getGroups()));
default:
$result = null;
wfRunHooks('AutopromoteCondition', array($cond[0], array_slice($cond, 1), $user, &$result));
if ($result === null) {
throw new MWException("Unrecognized condition {$cond[0]} for autopromotion!");
}
return (bool) $result;
}
}
示例6: isIPWhitelisted
/**
* Check if the IP is allowed to skip captchas
*/
function isIPWhitelisted()
{
if ($this->IPWhitelist) {
$ip = wfGetIp();
foreach ($this->IPWhitelist as $range) {
if (IP::isInRange($ip, $range)) {
return true;
}
}
}
return false;
}
示例7: doAutoblock
/**
* Autoblocks the given IP, referring to this Block.
* @param string $autoblockip The IP to autoblock.
* @param bool $justInserted The main block was just inserted
* @return bool Whether or not an autoblock was inserted.
*/
function doAutoblock($autoblockip, $justInserted = false)
{
# If autoblocks are disabled, go away.
if (!$this->mEnableAutoblock) {
return;
}
# Check for presence on the autoblock whitelist
# TODO cache this?
$lines = explode("\n", wfMsgForContentNoTrans('autoblock_whitelist'));
$ip = $autoblockip;
wfDebug("Checking the autoblock whitelist..\n");
foreach ($lines as $line) {
# List items only
if (substr($line, 0, 1) !== '*') {
continue;
}
$wlEntry = substr($line, 1);
$wlEntry = trim($wlEntry);
wfDebug("Checking {$ip} against {$wlEntry}...");
# Is the IP in this range?
if (IP::isInRange($ip, $wlEntry)) {
wfDebug(" IP {$ip} matches {$wlEntry}, not autoblocking\n");
#$autoblockip = null; # Don't autoblock a whitelisted IP.
return;
#This /SHOULD/ introduce a dummy block - but
# I don't know a safe way to do so. -werdna
} else {
wfDebug(" No match\n");
}
}
# It's okay to autoblock. Go ahead and create/insert the block.
$ipblock = Block::newFromDB($autoblockip);
if ($ipblock) {
# If the user is already blocked. Then check if the autoblock would
# exceed the user block. If it would exceed, then do nothing, else
# prolong block time
if ($this->mExpiry && $this->mExpiry < Block::getAutoblockExpiry($ipblock->mTimestamp)) {
return;
}
# Just update the timestamp
if (!$justInserted) {
$ipblock->updateTimestamp();
}
return;
} else {
$ipblock = new Block();
}
# Make a new block object with the desired properties
wfDebug("Autoblocking {$this->mAddress}@" . $autoblockip . "\n");
$ipblock->mAddress = $autoblockip;
$ipblock->mUser = 0;
$ipblock->mBy = $this->mBy;
$ipblock->mReason = wfMsgForContent('autoblocker', $this->mAddress, $this->mReason);
$ipblock->mTimestamp = wfTimestampNow();
$ipblock->mAuto = 1;
$ipblock->mCreateAccount = $this->mCreateAccount;
# Continue suppressing the name if needed
$ipblock->mHideName = $this->mHideName;
# If the user is already blocked with an expiry date, we don't
# want to pile on top of that!
if ($this->mExpiry) {
$ipblock->mExpiry = min($this->mExpiry, Block::getAutoblockExpiry($this->mTimestamp));
} else {
$ipblock->mExpiry = Block::getAutoblockExpiry($this->mTimestamp);
}
# Insert it
return $ipblock->insert();
}
示例8: isWhitelistedFromAutoblocks
/**
* Checks whether a given IP is on the autoblock whitelist.
* TODO: this probably belongs somewhere else, but not sure where...
*
* @param string $ip The IP to check
* @return bool
*/
public static function isWhitelistedFromAutoblocks($ip)
{
global $wgMemc;
// Try to get the autoblock_whitelist from the cache, as it's faster
// than getting the msg raw and explode()'ing it.
$key = wfMemcKey('ipb', 'autoblock', 'whitelist');
$lines = $wgMemc->get($key);
if (!$lines) {
$lines = explode("\n", wfMessage('autoblock_whitelist')->inContentLanguage()->plain());
$wgMemc->set($key, $lines, 3600 * 24);
}
wfDebug("Checking the autoblock whitelist..\n");
foreach ($lines as $line) {
# List items only
if (substr($line, 0, 1) !== '*') {
continue;
}
$wlEntry = substr($line, 1);
$wlEntry = trim($wlEntry);
wfDebug("Checking {$ip} against {$wlEntry}...");
# Is the IP in this range?
if (IP::isInRange($ip, $wlEntry)) {
wfDebug(" IP {$ip} matches {$wlEntry}, not autoblocking\n");
return true;
} else {
wfDebug(" No match\n");
}
}
return false;
}
示例9: isIPWhitelisted
/**
* Check if the IP is allowed to skip captchas
*/
public function isIPWhitelisted()
{
if ($this->wg->CaptchaWhitelistIP) {
$ip = $this->wg->Request->getIP();
foreach ($this->wg->CaptchaWhitelistIP as $range) {
if (\IP::isInRange($ip, $range)) {
return true;
}
}
}
return false;
}
示例10: checkWhitelist
public static function checkWhitelist( $ip ) {
global $wgMemc;
$whitelist = self::loadWhitelist();
$memcKey = wfMemcKey( 'whitelisted', $ip );
$data = $wgMemc->get( $memcKey );
if( $data != '' ) {
return ( $data === 'ok' ) ? true : false;
}
if( is_array( $whitelist ) ) {
foreach( $whitelist as $entry ) {
if( IP::isInRange( $ip, $entry ) ) {
$wgMemc->set( $memcKey, 'ok', 86400 );
return true;
}
}
}
$wgMemc->set( $memcKey, 'not', 86400 );
return false;
}
示例11: ScanNetwork
function ScanNetwork($RuleID, $RuleName, $network, $basePath, $QuotaSizeBytes, $FileAcls)
{
events("[INFO]: Scanning {$network}", __LINE__);
$acls_content = array();
$NOTIF_TEXT = array();
$basePath = $basePath . "/IPADDR";
$unix = new unix();
$dirs = $unix->dirdir($basePath);
$FileAclsMD5_start = md5_file($FileAcls);
$IP = new IP();
$f = array();
while (list($fullpath, $none) = each($dirs)) {
$addr = basename($fullpath);
if (!$IP->isInRange($addr, $network)) {
continue;
}
if (!Scan_IpAddr($RuleID, $RuleName, $addr, $basePath, $QuotaSizeBytes, $FileAcls)) {
continue;
}
$f[] = $addr;
}
@file_put_contents($FileAcls, @implode("\n", $f));
$FileAclsMD5_end = md5_file($FileAcls);
if ($FileAclsMD5_end != $FileAclsMD5_start) {
squid_admin_mysql(1, "{$RuleName}: Quota changed", @implode("\n", $GLOBALS["NOTIF_TEXT"]), __FILE__, __LINE__);
$GLOBALS["MUST_RELOAD_SQUID"] = true;
}
}
示例12: checkCondition
/**
* As recCheckCondition, but *not* recursive. The only valid conditions
* are those whose first element is APCOND_EMAILCONFIRMED/APCOND_EDITCOUNT/
* APCOND_AGE. Other types will throw an exception if no extension evalu-
* ates them.
*
* @param $cond Array: A condition, which must not contain other conditions
* @param $user The user to check the condition against
* @return bool Whether the condition is true for the user
*/
private static function checkCondition($cond, User $user)
{
if (count($cond) < 1) {
return false;
}
switch ($cond[0]) {
case APCOND_EMAILCONFIRMED:
if (User::isValidEmailAddr($user->getEmail())) {
global $wgEmailAuthentication;
if ($wgEmailAuthentication) {
return (bool) $user->getEmailAuthenticationTimestamp();
} else {
return true;
}
}
return false;
case APCOND_EDITCOUNT:
return $user->getEditCount() >= $cond[1];
case APCOND_AGE:
$age = time() - wfTimestampOrNull(TS_UNIX, $user->getRegistration());
return $age >= $cond[1];
case APCOND_AGE_FROM_EDIT:
$age = time() - wfTimestampOrNull(TS_UNIX, $user->getFirstEditTimestamp());
return $age >= $cond[1];
case APCOND_INGROUPS:
$groups = array_slice($cond, 1);
return count(array_intersect($groups, $user->getGroups())) == count($groups);
case APCOND_ISIP:
return $cond[1] == wfGetIP();
case APCOND_IPINRANGE:
return IP::isInRange(wfGetIP(), $cond[1]);
default:
$result = null;
wfRunHooks('AutopromoteCondition', array($cond[0], array_slice($cond, 1), $user, &$result));
if ($result === null) {
throw new MWException("Unrecognized condition {$cond[0]} for autopromotion!");
}
return $result ? true : false;
}
}
示例13: isWhiteListedIP
/**
* Check if an IP address is in a whitelisted range.
*
* @param string $ipAddress IP address to whitelist
* @return boolean
*/
public function isWhiteListedIP($ipAddress)
{
$ipAddress = \IP::sanitizeIP($ipAddress);
$whitelistRanges = $this->getWhitelistRanges();
$isWhitelisted = false;
foreach ($whitelistRanges as $range) {
if (\IP::isInRange($ipAddress, $range)) {
$isWhitelisted = true;
break;
}
}
return $isWhitelisted;
}
示例14: isIPWhitelisted
/**
* Check if the IP is allowed to skip captchas
*/
function isIPWhitelisted()
{
global $wgCaptchaWhitelistIP;
if ($wgCaptchaWhitelistIP) {
global $wgRequest;
// Compat: WebRequest::getIP is only available since MW 1.19.
$ip = method_exists($wgRequest, 'getIP') ? $wgRequest->getIP() : wfGetIP();
foreach ($wgCaptchaWhitelistIP as $range) {
if (IP::isInRange($ip, $range)) {
return true;
}
}
}
return false;
}
示例15: isWhitelistedFromAutoblocks
/**
* Checks whether a given IP is on the autoblock whitelist.
* TODO: this probably belongs somewhere else, but not sure where...
*
* @param $ip String: The IP to check
* @return Boolean
*/
public static function isWhitelistedFromAutoblocks($ip)
{
global $wgMemc;
// Try to get the autoblock_whitelist from the cache, as it's faster
// than getting the msg raw and explode()'ing it.
$key = wfMemcKey('ipb', 'autoblock', 'whitelist');
$lines = $wgMemc->get($key);
if (!$lines) {
$lines = explode("\n", wfMsgForContentNoTrans('autoblock_whitelist'));
$wgMemc->set($key, $lines, 3600 * 24);
}
/** Wikia Change start **/
global $wgGlobalWhitelistedFromAutoblocks;
if (!empty($wgGlobalWhitelistedFromAutoblocks) && is_array($wgGlobalWhitelistedFromAutoblocks)) {
if (empty($lines)) {
$lines = array();
}
foreach ($wgGlobalWhitelistedFromAutoblocks as $val) {
$lines[] = '*' . $val;
}
}
/** Wikia Change end **/
wfDebug("Checking the autoblock whitelist..\n");
foreach ($lines as $line) {
# List items only
if (substr($line, 0, 1) !== '*') {
continue;
}
$wlEntry = substr($line, 1);
$wlEntry = trim($wlEntry);
wfDebug("Checking {$ip} against {$wlEntry}...");
# Is the IP in this range?
if (IP::isInRange($ip, $wlEntry)) {
wfDebug(" IP {$ip} matches {$wlEntry}, not autoblocking\n");
return true;
} else {
wfDebug(" No match\n");
}
}
return false;
}