getGeneralConfig(); return !empty($general['login_whitelist_apply_to_reporting_api_requests']); } public function shouldCheckWhitelist() { if (Common::isPhpCliMode()) { return false; } // ignore whitelist checks for opt out iframe if (!SettingsServer::isTrackerApiRequest() && 'CoreAdminHome' === Piwik::getModule() && 'optOut' === Piwik::getAction()) { return false; } $ips = $this->getWhitelistedLoginIps(); return !empty($ips); } public function checkIsWhitelisted($ipString) { if (!$this->isIpWhitelisted($ipString)) { throw new NoAccessException(Piwik::translate('CoreHome_ExceptionNotWhitelistedIP', $ipString)); } } public function isIpWhitelisted($userIpString) { $userIp = NetworkIp::fromStringIP($userIpString); $ipsWhitelisted = $this->getWhitelistedLoginIps(); if (empty($ipsWhitelisted)) { return false; } return $userIp->isInRanges($ipsWhitelisted); } /** * @return array */ protected function getWhitelistedLoginIps() { $ips = StaticContainer::get('login.whitelist.ips'); if (!empty($ips) && is_array($ips)) { $ips = array_map(function ($ip) { return trim($ip); }, $ips); $ips = array_filter($ips, function ($ip) { return !empty($ip); }); return array_unique(array_values($ips)); } return array(); } private function getGeneralConfig() { $config = Config::getInstance(); $general = $config->General; return $general; } }