本文整理汇总了PHP中IP::isValidBlock方法的典型用法代码示例。如果您正苦于以下问题:PHP IP::isValidBlock方法的具体用法?PHP IP::isValidBlock怎么用?PHP IP::isValidBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IP
的用法示例。
在下文中一共展示了IP::isValidBlock方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Construct an IP address representation.
* @param string $address The textual representation of an IP address or CIDR range.
*/
public function __construct($address)
{
// analyze address format
$this->is_valid = IP::isIPAddress($address);
if (!$this->is_valid) {
return;
}
$this->is_ipv4 = IP::isIPv4($address);
$this->is_ipv6 = !$this->is_ipv4 && IP::isIPv6($address);
// analyze address range
$this->is_range = IP::isValidBlock($address);
$this->encoded_range = IP::parseRange($address);
$this->range = array(IP::prettifyIP(IP::formatHex($this->encoded_range[self::START])), IP::prettifyIP(IP::formatHex($this->encoded_range[self::END])));
}
示例2: network_add
function network_add()
{
$tpc = new IP();
if (!$tpc->isValidBlock($_POST["network-add"])) {
echo "{$_POST["network-add"]} invalid";
return;
}
$q = new mysql_squid_builder();
$q->QUERY_SQL("INSERT IGNORE INTO webauth_rules_nets (pattern,ruleid) VALUES ('{$_POST["network-add"]}','{$_POST["ruleid"]}')");
if (!$q->ok) {
echo $q->mysql_error;
return;
}
$sock = new sockets();
$sock->getFrameWork("hotspot.php?remove-cache=yes");
}
示例3: testInvalidBlocks
/**
* @covers IP::isValidBlock
*/
public function testInvalidBlocks()
{
$invalid = array('116.17.184.5/33', '0.17.184.5/130', '16.17.184.1/-1', '10.232.52.13/*', '7.232.52.13/ab', '11.232.52.13/', '::e:f:2001/129', '::c:f:2001/228', '::10:f:2001/-1', '::6d:f:2001/*', '::86:f:2001/ab', '::23:f:2001/');
foreach ($invalid as $i) {
$this->assertFalse(IP::isValidBlock($i), "{$i} is not a valid IP block");
}
}
示例4: parseTarget
/**
* From an existing Block, get the target and the type of target.
* Note that, except for null, it is always safe to treat the target
* as a string; for User objects this will return User::__toString()
* which in turn gives User::getName().
*
* @param string|int|User|null $target
* @return array( User|String|null, Block::TYPE_ constant|null )
*/
public static function parseTarget($target)
{
# We may have been through this before
if ($target instanceof User) {
if (IP::isValid($target->getName())) {
return array($target, self::TYPE_IP);
} else {
return array($target, self::TYPE_USER);
}
} elseif ($target === null) {
return array(null, null);
}
$target = trim($target);
if (IP::isValid($target)) {
# We can still create a User if it's an IP address, but we need to turn
# off validation checking (which would exclude IP addresses)
return array(User::newFromName(IP::sanitizeIP($target), false), Block::TYPE_IP);
} elseif (IP::isValidBlock($target)) {
# Can't create a User from an IP range
return array(IP::sanitizeRange($target), Block::TYPE_RANGE);
}
# Consider the possibility that this is not a username at all
# but actually an old subpage (bug #29797)
if (strpos($target, '/') !== false) {
# An old subpage, drill down to the user behind it
$parts = explode('/', $target);
$target = $parts[0];
}
$userObj = User::newFromName($target);
if ($userObj instanceof User) {
# Note that since numbers are valid usernames, a $target of "12345" will be
# considered a User. If you want to pass a block ID, prepend a hash "#12345",
# since hash characters are not valid in usernames or titles generally.
return array($userObj, Block::TYPE_USER);
} elseif (preg_match('/^#\\d+$/', $target)) {
# Autoblock reference in the form "#12345"
return array(substr($target, 1), Block::TYPE_AUTO);
} else {
# WTF?
return array(null, null);
}
}
示例5: testInvalidBlocks
/**
* @covers IP::isValidBlock
* @dataProvider provideInvalidBlocks
*/
public function testInvalidBlocks($invalid)
{
$this->assertFalse(IP::isValidBlock($invalid), "{$invalid} is not a valid IP block");
}
示例6: routes_main_network
function routes_main_network($ligne)
{
$NetBuilder = new system_nic();
$NetBuilder->LoadTools();
$ipClass = new IP();
$pattern = $ligne["pattern"];
$gateway = $ligne["gateway"];
if ($gateway == "0.0.0.0") {
$gateway = null;
}
if (!isset($GLOBALS["PROC_NET_DEV"][$ligne["nic"]])) {
$GLOBALS["SCRIPTS_ROUTES"][] = "# [{$ligne["nic"]}/" . __LINE__ . "] INTERFACE MATERIAL ERROR";
return;
}
$eth = $NetBuilder->NicToOther($ligne["nic"]);
$metric = $ligne["metric"];
if (!$ipClass->isValidBlock($pattern)) {
$GLOBALS["SCRIPTS_ROUTES"][] = "# [{$eth}/" . __LINE__ . "] {$pattern} is not a valid block";
return;
}
if ($ligne["SourceBasedRouting"] == 1) {
$table = alphaToNum($ligne["nic"]);
$f[] = "{$GLOBALS["ipbin"]} add {$pattern}";
if ($gateway != null) {
$f[] = "via {$gateway}";
}
$f[] = "table {$table}";
if ($metric > 0) {
$f[] = "metric {$metric}";
}
return @implode(" ", $f);
}
if ($gateway == null) {
$GLOBALS["SCRIPTS_ROUTES"][] = "# [{$ligne["nic"]}/" . __LINE__ . "] No gateway set, add just the net {$pattern} on interface {$eth}";
$f[] = "{$GLOBALS["ipbin"]} route add {$pattern} dev {$eth}";
if ($metric > 0) {
$f[] = "metric {$metric}";
}
return @implode(" ", $f);
}
$GLOBALS["SCRIPTS_ROUTES"][] = "# [{$ligne["nic"]}/" . __LINE__ . "] {$pattern} via {$gateway} on interface {$eth}";
$f[] = "{$GLOBALS["routebin"]} add -net {$pattern}";
$f[] = "gw {$gateway}";
$f[] = "dev {$eth}";
if ($metric > 0) {
$f[] = "metric {$metric}";
}
return @implode(" ", $f);
}