diff options
author | Matthieu Napoli <matthieu@mnapoli.fr> | 2015-03-10 07:01:14 +0300 |
---|---|---|
committer | Matthieu Napoli <matthieu@mnapoli.fr> | 2015-03-10 07:01:14 +0300 |
commit | 090f9a418db83677431a5f6a5b26dea83789eb13 (patch) | |
tree | df7686583460b2bdb21d057f9cab86ad4c684e33 /core | |
parent | a1fe093ab4cd5243ef3ff22ebd5f6814a6e1c4a7 (diff) |
Removed all deprecated methods of the Piwik\IP class
This should fix the unit tests.
Diffstat (limited to 'core')
-rw-r--r-- | core/Common.php | 20 | ||||
-rw-r--r-- | core/IP.php | 237 | ||||
-rw-r--r-- | core/Tracker/VisitExcluded.php | 9 |
3 files changed, 5 insertions, 261 deletions
diff --git a/core/Common.php b/core/Common.php index 7e3bcbc7af..1ed8d48935 100644 --- a/core/Common.php +++ b/core/Common.php @@ -638,26 +638,6 @@ class Common } /** - * Convert IP address (in network address format) to presentation format. - * This is a backward compatibility function for code that only expects - * IPv4 addresses (i.e., doesn't support IPv6). - * - * @see IP::N2P() - * - * This function does not support the long (or its string representation) - * returned by the built-in ip2long() function, from Piwik 1.3 and earlier. - * - * @deprecated 1.4 - * - * @param string $ip IP address in network address format - * @return string - */ - public static function long2ip($ip) - { - return IP::long2ip($ip); - } - - /** * JSON encode wrapper * - missing or broken in some php 5.x versions * diff --git a/core/IP.php b/core/IP.php index e952ddbe27..b6ec2c2d22 100644 --- a/core/IP.php +++ b/core/IP.php @@ -10,8 +10,6 @@ namespace Piwik; use Piwik\Network\IPUtils; -use Piwik\Network\IPv4; -use Piwik\Network\IPv6; /** * Contains IP address helper functions (for both IPv4 and IPv6). @@ -40,223 +38,6 @@ use Piwik\Network\IPv6; class IP { /** - * Removes the port and the last portion of a CIDR IP address. - * - * @param string $ipString The IP address to sanitize. - * @return string - * - * @deprecated Use IPUtils::sanitizeIp() instead - * @see \Piwik\Network\IPUtils - */ - public static function sanitizeIp($ipString) - { - return IPUtils::sanitizeIp($ipString); - } - - /** - * Sanitize human-readable (user-supplied) IP address range. - * - * Accepts the following formats for $ipRange: - * - single IPv4 address, e.g., 127.0.0.1 - * - single IPv6 address, e.g., ::1/128 - * - IPv4 block using CIDR notation, e.g., 192.168.0.0/22 represents the IPv4 addresses from 192.168.0.0 to 192.168.3.255 - * - IPv6 block using CIDR notation, e.g., 2001:DB8::/48 represents the IPv6 addresses from 2001:DB8:0:0:0:0:0:0 to 2001:DB8:0:FFFF:FFFF:FFFF:FFFF:FFFF - * - wildcards, e.g., 192.168.0.* - * - * @param string $ipRangeString IP address range - * @return string|bool IP address range in CIDR notation OR false - * - * @deprecated Use IPUtils::sanitizeIpRange() instead - * @see \Piwik\Network\IPUtils - */ - public static function sanitizeIpRange($ipRangeString) - { - $result = IPUtils::sanitizeIpRange($ipRangeString); - - return $result === null ? false : $result; - } - - /** - * Converts an IP address in presentation format to network address format. - * - * @param string $ipString IP address, either IPv4 or IPv6, e.g., `"127.0.0.1"`. - * @return string Binary-safe string, e.g., `"\x7F\x00\x00\x01"`. - * - * @deprecated Use IPUtils::stringToBinaryIP() instead - * @see \Piwik\Network\IPUtils - */ - public static function P2N($ipString) - { - return IPUtils::stringToBinaryIP($ipString); - } - - /** - * Convert network address format to presentation format. - * - * See also {@link prettyPrint()}. - * - * @param string $ip IP address in network address format. - * @return string IP address in presentation format. - * - * @deprecated Use IPUtils::binaryToStringIP() instead - */ - public static function N2P($ip) - { - return IPUtils::binaryToStringIP($ip); - } - - /** - * Alias for {@link N2P()}. - * - * @param string $ip IP address in network address format. - * @return string IP address in presentation format. - * - * @deprecated Will be removed - */ - public static function prettyPrint($ip) - { - return IPUtils::binaryToStringIP($ip); - } - - /** - * Returns true if `$ip` is an IPv4, IPv4-compat, or IPv4-mapped address, false - * if otherwise. - * - * @param string $ip IP address in network address format. - * @return bool True if IPv4, else false. - * - * @deprecated Will be removed - * @see \Piwik\Network\IP - */ - public static function isIPv4($ip) - { - $ip = Network\IP::fromBinaryIP($ip); - - return $ip instanceof IPv4; - } - - /** - * Converts an IP address (in network address format) to presentation format. - * This is a backward compatibility function for code that only expects - * IPv4 addresses (i.e., doesn't support IPv6). - * - * This function does not support the long (or its string representation) - * returned by the built-in ip2long() function, from Piwik 1.3 and earlier. - * - * @param string $ip IPv4 address in network address format. - * @return string IP address in presentation format. - * - * @deprecated This method was kept for backward compatibility and doesn't seem used - */ - public static function long2ip($ip) - { - // IPv4 - if (strlen($ip) == 4) { - return IPUtils::binaryToStringIP($ip); - } - - // IPv6 - transitional address? - if (strlen($ip) == 16) { - if (substr_compare($ip, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff", 0, 12) === 0 - || substr_compare($ip, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0, 12) === 0 - ) { - // remap 128-bit IPv4-mapped and IPv4-compat addresses - return IPUtils::binaryToStringIP(substr($ip, 12)); - } - } - - return '0.0.0.0'; - } - - /** - * Returns true if $ip is an IPv6 address, false if otherwise. This function does - * a naive check. It assumes that whatever format $ip is in, it is well-formed. - * - * @param string $ip - * @return bool - * - * @deprecated Will be removed - * @see \Piwik\Network\IP - */ - public static function isIPv6($ip) - { - $ip = Network\IP::fromBinaryIP($ip); - - return $ip instanceof IPv6; - } - - /** - * Returns true if $ip is a IPv4 mapped address, false if otherwise. - * - * @param string $ip - * @return bool - * - * @deprecated Will be removed - * @see \Piwik\Network\IP - */ - public static function isMappedIPv4($ip) - { - $ip = Network\IP::fromStringIP($ip); - - if (! $ip instanceof IPv6) { - return false; - } - - return $ip->isMappedIPv4(); - } - - /** - * Returns an IPv4 address from a 'mapped' IPv6 address. - * - * @param string $ip eg, `'::ffff:192.0.2.128'` - * @return string eg, `'192.0.2.128'` - * - * @deprecated Use Piwik\Network\IP::toIPv4String() instead - * @see \Piwik\Network\IP - */ - public static function getIPv4FromMappedIPv6($ip) - { - $ip = Network\IP::fromStringIP($ip); - - return $ip->toIPv4String(); - } - - /** - * Get low and high IP addresses for a specified range. - * - * @param array $ipRange An IP address range in presentation format. - * @return array|bool Array `array($lowIp, $highIp)` in network address format, or false on failure. - * - * @deprecated Use Piwik\Network\IPUtils::getIPRangeBounds() instead - * @see \Piwik\Network\IPUtils - */ - public static function getIpsForRange($ipRange) - { - $result = IPUtils::getIPRangeBounds($ipRange); - - return $result === null ? false : $result; - } - - /** - * Determines if an IP address is in a specified IP address range. - * - * An IPv4-mapped address should be range checked with an IPv4-mapped address range. - * - * @param string $ip IP address in network address format - * @param array $ipRanges List of IP address ranges - * @return bool True if in any of the specified IP address ranges; else false. - * - * @deprecated Use Piwik\Network\IP::isInRanges() instead - * @see \Piwik\Network\IP - */ - public static function isIpInRange($ip, $ipRanges) - { - $ip = Network\IP::fromBinaryIP($ip); - - return $ip->isInRanges($ipRanges); - } - - /** * Returns the most accurate IP address availble for the current user, in * IPv4 format. This could be the proxy client's IP address. * @@ -333,22 +114,4 @@ class IP } return trim(Common::sanitizeInputValue($csv)); } - - /** - * Returns the hostname for a given IP address. - * - * @param string $ipStr Human-readable IP address. - * @return string The hostname or unmodified $ipStr on failure. - * - * @deprecated Use Piwik\Network\IP::getHostname() instead - * @see \Piwik\Network\IP - */ - public static function getHostByAddr($ipStr) - { - $ip = Network\IP::fromStringIP($ipStr); - - $host = $ip->getHostname(); - - return $host === null ? $ipStr : $host; - } } diff --git a/core/Tracker/VisitExcluded.php b/core/Tracker/VisitExcluded.php index f3d8d0cab2..ae380cac42 100644 --- a/core/Tracker/VisitExcluded.php +++ b/core/Tracker/VisitExcluded.php @@ -11,7 +11,7 @@ namespace Piwik\Tracker; use Piwik\Common; use Piwik\Config; use Piwik\DeviceDetectorFactory; -use Piwik\IP; +use Piwik\Network\IP; use Piwik\Piwik; /** @@ -158,9 +158,10 @@ class VisitExcluded $deviceDetector = DeviceDetectorFactory::getInstance($this->userAgent); + $ip = IP::fromBinaryIP($this->ip); + return !$allowBots - && ($deviceDetector->isBot() - || IP::isIpInRange($this->ip, $this->getBotIpRanges())); + && ($deviceDetector->isBot() || $ip->isInRanges($this->getBotIpRanges())); } protected function getBotIpRanges() @@ -223,7 +224,7 @@ class VisitExcluded $websiteAttributes = Cache::getCacheWebsiteAttributes($this->idSite); if (!empty($websiteAttributes['excluded_ips'])) { - $ip = \Piwik\Network\IP::fromBinaryIP($this->ip); + $ip = IP::fromBinaryIP($this->ip); if ($ip->isInRanges($websiteAttributes['excluded_ips'])) { Common::printDebug('Visitor IP ' . $ip->toString() . ' is excluded from being tracked'); return true; |