Remove all the {{{ and }}} folding
This commit is contained in:
@@ -14,7 +14,6 @@ class Ipaddresses
|
||||
* @param string $ip The IP Address to validate
|
||||
*/
|
||||
public function validIPAddress ($ip)
|
||||
// {{{
|
||||
{
|
||||
if (!is_string ($ip) || $ip === "")
|
||||
throw new \Exception (dgettext ("domframework", "Invalid IP address"),
|
||||
@@ -25,13 +24,11 @@ class Ipaddresses
|
||||
$rc = $this->validIPv6Address ($ip);
|
||||
return $rc;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Return true if the provided IP address is valid and is IPv4
|
||||
* @param string $ip The IP Address to validate
|
||||
*/
|
||||
public function validIPv4Address ($ip)
|
||||
// {{{
|
||||
{
|
||||
if (!is_string ($ip) || $ip === "")
|
||||
throw new \Exception (dgettext ("domframework", "Invalid IPv4 address"),
|
||||
@@ -41,13 +38,11 @@ class Ipaddresses
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Return true if the provided IP address is valid and is IPv6
|
||||
* @param string $ip The IP Address to validate
|
||||
*/
|
||||
public function validIPv6Address ($ip)
|
||||
// {{{
|
||||
{
|
||||
if (!is_string ($ip) || $ip === "")
|
||||
throw new \Exception (dgettext ("domframework", "Invalid IPv6 address"),
|
||||
@@ -57,14 +52,12 @@ class Ipaddresses
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Return true if the provided IP address is valid (IPv4 or IPv6) and the
|
||||
* provided CIDR is valid too
|
||||
* @param string $ip The IP Address to validate with a CIDR
|
||||
*/
|
||||
public function validIPAddressWithCIDR ($ip)
|
||||
// {{{
|
||||
{
|
||||
if (!is_string ($ip) || $ip === "")
|
||||
throw new \Exception (dgettext ("domframework", "Invalid IP address"),
|
||||
@@ -75,14 +68,12 @@ class Ipaddresses
|
||||
$rc = $this->validIPv6AddressWithCIDR ($ip);
|
||||
return $rc;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Return true if the provided IP address is valid and is IPv4 and the
|
||||
* provided CIDR is valid too
|
||||
* @param string $ip The IP Address to validate with a CIDR
|
||||
*/
|
||||
public function validIPv4AddressWithCIDR ($ip)
|
||||
// {{{
|
||||
{
|
||||
if (!is_string ($ip) || $ip === "")
|
||||
throw new \Exception (dgettext ("domframework", "Invalid IPv4 address"),
|
||||
@@ -97,14 +88,12 @@ class Ipaddresses
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Return true if the provided IP address is valid and is IPv6 and the
|
||||
* provided CIDR is valid too
|
||||
* @param string $ip The IP Address to validate with a CIDR
|
||||
*/
|
||||
public function validIPv6AddressWithCIDR ($ip)
|
||||
// {{{
|
||||
{
|
||||
if (!is_string ($ip) || $ip === "")
|
||||
throw new \Exception (dgettext ("domframework", "Invalid IPv6 address"),
|
||||
@@ -119,7 +108,6 @@ class Ipaddresses
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Return true if the provided CIDR is valid. The CIDR can be valid in IPv4
|
||||
* or IPv6
|
||||
@@ -127,7 +115,6 @@ class Ipaddresses
|
||||
* @return boolean The CIDR is valid
|
||||
*/
|
||||
public function validCIDR ($cidr)
|
||||
// {{{
|
||||
{
|
||||
if (! is_integer ($cidr) && ! is_integer ($cidr))
|
||||
throw new \Exception (dgettext ("domframework", "Invalid CIDR provided"),
|
||||
@@ -138,14 +125,12 @@ class Ipaddresses
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Return true if the provided CIDR is valid. The CIDR can be valid in IPv4.
|
||||
* @param integer $cidr The CIDR to test
|
||||
* @return boolean The CIDR is valid
|
||||
*/
|
||||
public function validIPv4CIDR ($cidr)
|
||||
// {{{
|
||||
{
|
||||
if (! is_integer ($cidr) && ! is_string ($cidr))
|
||||
throw new \Exception (dgettext ("domframework", "Invalid CIDR provided"),
|
||||
@@ -156,14 +141,12 @@ class Ipaddresses
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Return true if the provided CIDR is valid. The CIDR can be valid in IPv6.
|
||||
* @param integer $cidr The CIDR to test
|
||||
* @return boolean The CIDR is valid
|
||||
*/
|
||||
public function validIPv6CIDR ($cidr)
|
||||
// {{{
|
||||
{
|
||||
if (! is_integer ($cidr) && ! is_string ($cidr))
|
||||
throw new \Exception (dgettext ("domframework", "Invalid CIDR provided"),
|
||||
@@ -174,7 +157,6 @@ class Ipaddresses
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Return the IPv6 to compressed (or compact) form.
|
||||
* Remove the 0 when they are placed on the begin of the nibble.
|
||||
@@ -184,7 +166,6 @@ class Ipaddresses
|
||||
* @param string $ip The IP to compress
|
||||
*/
|
||||
public function compressIP ($ip)
|
||||
// {{{
|
||||
{
|
||||
if (strpos ($ip, ":") === false)
|
||||
return $ip;
|
||||
@@ -239,7 +220,6 @@ class Ipaddresses
|
||||
$ipHex = implode (":", $ipArr);
|
||||
return $ipHex;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Return the IPv6 uncompressed (all the fields exists). They are not filled
|
||||
* by zeros
|
||||
@@ -252,7 +232,6 @@ class Ipaddresses
|
||||
* return "0:0:0:0:0:0:ffff:7f00:1"
|
||||
*/
|
||||
public function uncompressIPv6 ($ip)
|
||||
// {{{
|
||||
{
|
||||
if (! is_string ($ip) || $ip === "" ||
|
||||
$this->validIPAddress ($ip) === false)
|
||||
@@ -299,7 +278,6 @@ class Ipaddresses
|
||||
}
|
||||
return $ip;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Get an IPv6 address with the format
|
||||
* x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x
|
||||
@@ -309,7 +287,6 @@ class Ipaddresses
|
||||
* @param string $ipv6 The IPv6 to group
|
||||
*/
|
||||
public function groupIPv6 ($ipv6)
|
||||
// {{{
|
||||
{
|
||||
if (! is_string ($ipv6) || $ipv6 === "")
|
||||
throw new \Exception (dgettext ("domframework", "Invalid IPv6 address"),
|
||||
@@ -329,7 +306,6 @@ class Ipaddresses
|
||||
}
|
||||
return $new;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Return the IP adddress with filling the fields with the missing zeros.
|
||||
* Valid only on IPv6 (but don't change anything if the provided address is
|
||||
@@ -341,7 +317,6 @@ class Ipaddresses
|
||||
* return "0000:0000:0000:0000:0000:0000:ffff:7f00:0001"
|
||||
*/
|
||||
public function completeAddressWithZero ($ip)
|
||||
// {{{
|
||||
{
|
||||
if (! is_string ($ip) || $ip === "")
|
||||
throw new \Exception (dgettext ("domframework", "Invalid IP address"),
|
||||
@@ -370,7 +345,6 @@ class Ipaddresses
|
||||
}
|
||||
throw new \Exception (dgettext ("domframework", "Invalid IP address"), 500);
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Return the provided CIDR in binary. Length must be in bytes.
|
||||
* Return FALSE if the parameters are invalid
|
||||
@@ -378,7 +352,6 @@ class Ipaddresses
|
||||
* @param integer $length The length to use
|
||||
*/
|
||||
public function cidrToBin ($cidr, $length)
|
||||
// {{{
|
||||
{
|
||||
if (! is_numeric ($cidr) || $cidr < 0 || $cidr > 128)
|
||||
throw new \Exception (dgettext ("domframework", "Invalid CIDR"), 500);
|
||||
@@ -392,7 +365,6 @@ class Ipaddresses
|
||||
}
|
||||
return pack ('H*', $this->str_base_convert ($val, 2, 16));
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Base conversion with 128 bits support for IPv6
|
||||
* Based on http://fr2.php.net/manual/en/function.base-convert.php#109660
|
||||
@@ -403,7 +375,6 @@ class Ipaddresses
|
||||
* default)
|
||||
*/
|
||||
public function str_base_convert($str, $frombase=10, $tobase=36)
|
||||
// {{{
|
||||
{
|
||||
$str = trim ($str);
|
||||
if (intval ($frombase) != 10)
|
||||
@@ -438,7 +409,6 @@ class Ipaddresses
|
||||
|
||||
return $s;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Reverse the provided IP address
|
||||
* The IPv6 are returned in format :
|
||||
@@ -446,7 +416,6 @@ class Ipaddresses
|
||||
* @param string $ipReverse The IPv6 to reverse
|
||||
*/
|
||||
function reverseIPAddress ($ipReverse)
|
||||
// {{{
|
||||
{
|
||||
if (!is_string ($ipReverse) || $ipReverse === "")
|
||||
throw new \Exception (dgettext ("domframework", "Invalid IP address"),
|
||||
@@ -477,7 +446,6 @@ class Ipaddresses
|
||||
}
|
||||
throw new \Exception (dgettext ("domframework", "Invalid IP address"), 500);
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** This function return the CIDR associated to the provided netmask
|
||||
* Ex. Return 24 for a mask 255.255.255.0 in direct
|
||||
@@ -490,7 +458,6 @@ class Ipaddresses
|
||||
* check a wildcard mask
|
||||
*/
|
||||
public function netmask2cidr ($netmask, $maskdirect = true)
|
||||
// {{{
|
||||
{
|
||||
$maskdirect = "". ($maskdirect + 0);
|
||||
$maskrevert = ($maskdirect === "0") ? "1" : "0";
|
||||
@@ -523,7 +490,6 @@ class Ipaddresses
|
||||
return 32;
|
||||
return $res;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** This function return the netmask associated to a CIDR.
|
||||
* Work only on IPv4 addresses (CIDR between 0 and 32)
|
||||
@@ -534,7 +500,6 @@ class Ipaddresses
|
||||
* @return false if the CIDR is not between 0 and 32
|
||||
*/
|
||||
public function cidr2netmask ($cidr, $maskdirect = true)
|
||||
// {{{
|
||||
{
|
||||
if ($cidr < 0 || $cidr > 32)
|
||||
return false;
|
||||
@@ -558,7 +523,6 @@ class Ipaddresses
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** This function return true if the provided address is in the provided
|
||||
* network with the associated cidr
|
||||
@@ -568,7 +532,6 @@ class Ipaddresses
|
||||
* @return boolean True if $ip is in $network/$cidr
|
||||
*/
|
||||
public function ipInNetwork ($ip, $network, $cidr)
|
||||
// {{{
|
||||
{
|
||||
if ($this->validIPAddress ($ip) === false)
|
||||
throw new \Exception (dgettext ("domframework", "Invalid IP address"),
|
||||
@@ -596,7 +559,6 @@ class Ipaddresses
|
||||
return ($this->networkFirstIP ($ip, $cidr) ===
|
||||
$this->networkFirstIP ($network, $cidr));
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Get the first IP of a network.
|
||||
* IPv4 and IPv6 compatible
|
||||
@@ -606,11 +568,9 @@ class Ipaddresses
|
||||
* Example : $ip="192.168.1.2", $cidr=24 => return "192.168.1.0"
|
||||
*/
|
||||
public function networkFirstIP ($ip, $cidr)
|
||||
// {{{
|
||||
{
|
||||
return $this->networkFirstLastIP ($ip, $cidr, "0");
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Get the last IP of a network.
|
||||
* IPv4 and IPv6 compatible
|
||||
@@ -620,11 +580,9 @@ class Ipaddresses
|
||||
* Example : $ip="192.168.1.2", $cidr=24 => return "192.168.1.255"
|
||||
*/
|
||||
public function networkLastIP ($ip, $cidr)
|
||||
// {{{
|
||||
{
|
||||
return $this->networkFirstLastIP ($ip, $cidr, "1");
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Get the network first IP.
|
||||
* IPv4 and IPv6 compatible
|
||||
@@ -636,7 +594,6 @@ class Ipaddresses
|
||||
* Example : $ip="192.168.1.2", $cidr=24 => return "192.168.1.0"
|
||||
*/
|
||||
private function networkFirstLastIP ($ip, $cidr, $map)
|
||||
// {{{
|
||||
{
|
||||
if ($this->validIPAddress ($ip) === false)
|
||||
throw new \Exception (dgettext ("domframework", "Invalid IP address"),
|
||||
@@ -714,5 +671,4 @@ class Ipaddresses
|
||||
}
|
||||
return $ipBase;
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user