/** * Returns the hostname given the IP address string * * @param string $ipStr IP Address * @return string hostname (or human-readable IP address) */ private function getHost($ipStr) { $ip = IP::fromStringIP($ipStr); $host = $ip->getHostname(); $host = $host === null ? $ipStr : $host; return trim(strtolower($host)); }
/** * {@inheritdoc} */ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) { if ($this->enabled) { $ip = IP::fromStringIP($request->getClientIp()); $valid = F\some($this->whiteList, function ($range) use($ip) { return $ip->isInRange($range); }); if (!$valid) { return new Response('Forbidden', 403); } } return $this->app->handle($request, $type, $catch); }
/** * {@inheritDoc} */ public function geocode($address) { if (!filter_var($address, FILTER_VALIDATE_IP)) { throw new UnsupportedOperation('The IpRangeGeoIp provider does not support street addresses, only IP addresses.'); } if ('127.0.0.1' === $address) { return $this->returnResults([$this->getLocalhostDefaults()]); } $ip = Network\IP::fromStringIP($address); $result = []; foreach ($this->getData() as $row) { if (isset($row['networks']) && $ip->isInRanges($row['networks']) === true) { if (isset($row['address']) && is_array($row['address'])) { $result = $row['address']; } // match -> stop break; } } if (count($result) === 0) { throw new NoResult(sprintf('No results found for IP address "%s".', $address)); } return $this->returnResults([$this->fixEncoding(array_merge($this->getDefaults(), ['latitude' => isset($result['latitude']) ? $result['latitude'] : null, 'longitude' => isset($result['longitude']) ? $result['longitude'] : null, 'bounds' => ['south' => isset($result['bounds']['south']) ? $result['bounds']['south'] : null, 'west' => isset($result['bounds']['west']) ? $result['bounds']['west'] : null, 'north' => isset($result['bounds']['north']) ? $result['bounds']['north'] : null, 'east' => isset($result['bounds']['east']) ? $result['bounds']['east'] : null], 'streetNumber' => isset($result['streetNumber']) ? $result['streetNumber'] : null, 'streetName' => isset($result['streetName']) ? $result['streetName'] : null, 'locality' => isset($result['locality']) ? $result['locality'] : null, 'postalCode' => isset($result['postalCode']) ? $result['postalCode'] : null, 'subLocality' => isset($result['subLocality']) ? $result['subLocality'] : null, 'adminLevels' => [], 'country' => isset($result['country']) ? $result['country'] : null, 'countryCode' => isset($result['countryCode']) ? $result['countryCode'] : null, 'timezone' => isset($result['timezone']) ? $result['timezone'] : null]))]); }
/** * Returns an IP address from an array that was passed into getLocation. This * will return an IPv4 address or IPv6 address. * * @param array $info Must have 'ip' key. * @return string|null */ protected function getIpFromInfo($info) { $ip = \Piwik\Network\IP::fromStringIP($info['ip']); if ($ip instanceof \Piwik\Network\IPv6 && $ip->isMappedIPv4()) { return $ip->toIPv4String(); } else { return $ip->toString(); } }
/** * Returns the last IP address in a comma separated list, subject to an optional exclusion list. * * @param string $csv Comma separated list of elements. * @param array $excludedIps Optional list of excluded IP addresses (or IP address ranges). * @return string Last (non-excluded) IP address in the list or an empty string if all given IPs are excluded. */ public static function getLastIpFromList($csv, $excludedIps = null) { $p = strrpos($csv, ','); if ($p !== false) { $elements = explode(',', $csv); for ($i = count($elements); $i--;) { $element = trim(Common::sanitizeInputValue($elements[$i])); $ip = \Piwik\Network\IP::fromStringIP(IPUtils::sanitizeIp($element)); if (empty($excludedIps) || !in_array($element, $excludedIps) && !$ip->isInRanges($excludedIps)) { return $element; } } return ''; } return trim(Common::sanitizeInputValue($csv)); }
} } $f = fopen($clickheatConf['logPath'] . $final . '/' . date('Y-m-d') . '.log', 'a'); } if (is_resource($f)) { $logMe = true; if (isset($_COOKIE['clickheat-admin'])) { echo 'OK, but click not logged as you selected it in the admin panel ("Log my clicks/Enregistrer mes clics")'; $logMe = false; } elseif (IS_PIWIK_MODULE === true) { $site = (string) (int) $site; // prevents path injection if (file_exists(PIWIK_INCLUDE_PATH . '/tmp/cache/tracker/' . $site . '.php')) { require_once PIWIK_INCLUDE_PATH . '/tmp/cache/tracker/' . $site . '.php'; if (isset($content['excluded_ips'])) { $ip = IPUtils::stringToBinaryIP(\Piwik\Network\IP::fromStringIP(IP::getIpFromHeader())); if (isIpInRange($ip, $content['excluded_ips']) === true) { echo 'OK, but click not logged as you prevent this IP to be tracked in Piwik\'s configuration'; $logMe = false; } } } } if ($logMe === true) { echo 'OK'; fputs($f, (int) $_GET['x'] . '|' . (int) $_GET['y'] . '|' . (int) $_GET['w'] . '|' . $browser . '|' . (int) $_GET['c'] . "\n"); } fclose($f); } else { echo 'KO, file not writable'; }