diff options
Diffstat (limited to 'plugins/UserCountry')
-rw-r--r-- | plugins/UserCountry/Controller.php | 2 | ||||
-rwxr-xr-x | plugins/UserCountry/LocationProvider.php | 46 | ||||
-rwxr-xr-x | plugins/UserCountry/LocationProvider/GeoIp/Pecl.php | 45 | ||||
-rwxr-xr-x | plugins/UserCountry/LocationProvider/GeoIp/Php.php | 30 | ||||
-rwxr-xr-x | plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php | 59 | ||||
-rwxr-xr-x | plugins/UserCountry/templates/adminIndex.tpl | 12 |
6 files changed, 176 insertions, 18 deletions
diff --git a/plugins/UserCountry/Controller.php b/plugins/UserCountry/Controller.php index 8d477d7f01..e7ed5c458a 100644 --- a/plugins/UserCountry/Controller.php +++ b/plugins/UserCountry/Controller.php @@ -229,6 +229,8 @@ class Piwik_UserCountry_Controller extends Piwik_Controller $footerMessage = Piwik_Translate('UserCountry_NoDataForGeoIPReport', array( '<a target="_blank" href="'.Piwik_Url::getCurrentQueryStringWithParametersModified($params).'">', '</a>', + '<a target="_blank" href="http://dev.maxmind.com/geoip/geolite?rId=piwik">', + '</a>', '<a target="_blank" href="http://piwik.org/faq/how-to/#faq_167">', '</a>' )); diff --git a/plugins/UserCountry/LocationProvider.php b/plugins/UserCountry/LocationProvider.php index 744bc24fe1..f2cc40cd2d 100755 --- a/plugins/UserCountry/LocationProvider.php +++ b/plugins/UserCountry/LocationProvider.php @@ -213,9 +213,14 @@ abstract class Piwik_UserCountry_LocationProvider $location = false; $statusMessage = false; - if (!$provider->isAvailable()) + $availableOrMessage = $provider->isAvailable(); + if ($availableOrMessage !== true) { $status = self::NOT_INSTALLED; + if (is_string($availableOrMessage)) + { + $statusMessage = $availableOrMessage; + } } else { @@ -446,18 +451,41 @@ abstract class Piwik_UserCountry_LocationProvider { $lines[] = ''; - if (!empty($locationInfo[self::ORG_KEY])) - { - $lines[] = "Org: ".$locationInfo[self::ORG_KEY]; - } + $unknown = Piwik_Translate('General_Unknown'); - if (!empty($locationInfo[self::ISP_KEY])) - { - $lines[] = "ISP: ".$locationInfo[self::ISP_KEY]; - } + $org = !empty($locationInfo[self::ORG_KEY]) ? $locationInfo[self::ORG_KEY] : $unknown; + $lines[] = "Org: $org"; + + $isp = !empty($locationInfo[self::ISP_KEY]) ? $locationInfo[self::ISP_KEY] : $unknown; + $lines[] = "ISP: $isp"; } return implode($newline, $lines); } + + /** + * Returns an IP address from an array that was passed into getLocation. This + * will return an IPv4 address or false if the address is IPv6 (IPv6 is not + * supported yet). + * + * @param array $ip Must have 'ip' key. + * @return string|bool + */ + protected function getIpFromInfo( $info ) + { + $ip = $info['ip']; + if (Piwik_IP::isMappedIPv4($ip)) + { + return Piwik_IP::getIPv4FromMappedIPv6($ip); + } + else if (Piwik_IP::isIPv6($ip)) // IPv6 is not supported (yet) + { + return false; + } + else + { + return $ip; + } + } } diff --git a/plugins/UserCountry/LocationProvider/GeoIp/Pecl.php b/plugins/UserCountry/LocationProvider/GeoIp/Pecl.php index 06789ce8f1..0ddf8e2c1d 100755 --- a/plugins/UserCountry/LocationProvider/GeoIp/Pecl.php +++ b/plugins/UserCountry/LocationProvider/GeoIp/Pecl.php @@ -47,7 +47,7 @@ class Piwik_UserCountry_LocationProvider_GeoIp_Pecl extends Piwik_UserCountry_Lo */ public function getLocation( $info ) { - $ip = $info['ip']; + $ip = $this->getIpFromInfo($info); $result = array(); @@ -237,10 +237,53 @@ class Piwik_UserCountry_LocationProvider_GeoIp_Pecl extends Piwik_UserCountry_Lo . Piwik_Translate('UserCountry_HowToInstallGeoIpPecl') . '</a>' . '</em>'; + + $extraMessage = false; + if ($this->isAvailable()) + { + $peclDir = ini_get('geoip.custom_directory'); + if ($peclDir === false) + { + $extraMessage = Piwik_Translate('UserCountry_GeoIPPeclCustomDirNotSet', "'geoip.custom_directory'"); + } + else + { + $extraMessage = 'The \'geoip.custom_directory\' PHP ini option is set to \''.$peclDir.'\'.'; + } + + $availableDatabaseTypes = array(); + if (self::isCityDatabaseAvailable()) + { + $availableDatabaseTypes[] = Piwik_Translate('UserCountry_City'); + } + if (self::isRegionDatabaseAvailable()) + { + $availableDatabaseTypes[] = Piwik_Translate('UserCountry_Region'); + } + if (self::isCountryDatabaseAvailable()) + { + $availableDatabaseTypes[] = Piwik_Translate('UserCountry_Country'); + } + if (self::isISPDatabaseAvailable()) + { + $availableDatabaseTypes[] = 'ISP'; + } + if (self::isOrgDatabaseAvailable()) + { + $availableDatabaseTypes[] = Piwik_Translate('UserCountry_Organization'); + } + + $extraMessage .= '<br/><br/>'.Piwik_Translate('UserCountry_GeoIPImplHasAccessTo').': <strong><em>' + . implode(', ', $availableDatabaseTypes).'</em></strong>.'; + + $extraMessage = '<strong><em>'.Piwik_Translate('General_Note').': </em></strong>'.$extraMessage; + } + return array('id' => self::ID, 'title' => self::TITLE, 'description' => $desc, 'install_docs' => $installDocs, + 'extra_message' => $extraMessage, 'order' => 3); } diff --git a/plugins/UserCountry/LocationProvider/GeoIp/Php.php b/plugins/UserCountry/LocationProvider/GeoIp/Php.php index 5696029ad4..63c9e1eb1a 100755 --- a/plugins/UserCountry/LocationProvider/GeoIp/Php.php +++ b/plugins/UserCountry/LocationProvider/GeoIp/Php.php @@ -57,7 +57,7 @@ class Piwik_UserCountry_LocationProvider_GeoIp_Php extends Piwik_UserCountry_Loc */ public function getLocation( $info ) { - $ip = $info['ip']; + $ip = $this->getIpFromInfo($info); $result = array(); @@ -253,10 +253,38 @@ class Piwik_UserCountry_LocationProvider_GeoIp_Php extends Piwik_UserCountry_Loc $installDocs = '<em><a target="_blank" href="http://piwik.org/faq/how-to/#faq_163">' . Piwik_Translate('UserCountry_HowToInstallGeoIPDatabases') . '</em></a>'; + + $availableDatabaseTypes = array(); + if (self::getPathToGeoIpDatabase(array('GeoIPCity.dat', 'GeoLiteCity.dat')) !== false) + { + $availableDatabaseTypes[] = Piwik_Translate('UserCountry_City'); + } + if (self::getPathToGeoIpDatabase(array('GeoIPRegion.dat')) !== false) + { + $availableDatabaseTypes[] = Piwik_Translate('UserCountry_Region'); + } + if (self::getPathToGeoIpDatabase(array('GeoIPCountry.dat')) !== false) + { + $availableDatabaseTypes[] = Piwik_Translate('UserCountry_Country'); + } + if (self::getPathToGeoIpDatabase(array('GeoIPISP.dat')) !== false) + { + $availableDatabaseTypes[] = 'ISP'; + } + if (self::getPathToGeoIpDatabase(array('GeoIPOrg.dat')) !== false) + { + $availableDatabaseTypes[] = Piwik_Translate('UserCountry_Organization'); + } + + $extraMessage = '<strong><em>'.Piwik_Translate('General_Note').'</em></strong>: ' + . Piwik_Translate('UserCountry_GeoIPImplHasAccessTo').': <strong><em>' + . implode(', ', $availableDatabaseTypes).'</em></strong>.'; + return array('id' => self::ID, 'title' => self::TITLE, 'description' => $desc, 'install_docs' => $installDocs, + 'extra_message' => $extraMessage, 'order' => 2); } diff --git a/plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php b/plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php index b5c92ce110..a5f580530c 100755 --- a/plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php +++ b/plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php @@ -61,10 +61,12 @@ class Piwik_UserCountry_LocationProvider_GeoIp_ServerBased extends Piwik_UserCou */ public function getLocation( $info ) { + $ip = $this->getIpFromInfo($info); + // geoip modules that are built into servers can't use a forced IP. in this case we try // to fallback to another version. $myIP = Piwik_IP::getIpFromHeader(); - if (!self::isSameOrAnonymizedIp($info['ip'], $myIP) + if (!self::isSameOrAnonymizedIp($ip, $myIP) && (!isset($info['disable_fallbacks']) || !$info['disable_fallbacks'])) { @@ -136,7 +138,7 @@ class Piwik_UserCountry_LocationProvider_GeoIp_ServerBased extends Piwik_UserCou * There's a special check for the Apache module, but we can't check specifically * for anything else. * - * @return bool + * @return bool|string */ public function isAvailable() { @@ -152,8 +154,30 @@ class Piwik_UserCountry_LocationProvider_GeoIp_ServerBased extends Piwik_UserCou } } - return !empty($_SERVER[self::TEST_SERVER_VAR]) - || !empty($_SERVER[self::TEST_SERVER_VAR_ALT]); + $available = !empty($_SERVER[self::TEST_SERVER_VAR]) + || !empty($_SERVER[self::TEST_SERVER_VAR_ALT]); + + if ($available) + { + return true; + } + else // if not available return message w/ extra info + { + if (!function_exists('apache_get_modules')) + { + return Piwik_Translate('General_Note').': '.Piwik_Translate('UserCountry_AssumingNonApache'); + } + + $message = "<strong><em>".Piwik_Translate('General_Note').': ' + . Piwik_Translate('UserCountry_FoundApacheModules') + . "</em></strong>:<br/><br/>\n<ul style=\"list-style:disc;margin-left:24px\">\n"; + foreach (apache_get_modules() as $name) + { + $message .= "<li>$name</li>\n"; + } + $message .= "</ul>"; + return $message; + } } /** @@ -209,11 +233,36 @@ class Piwik_UserCountry_LocationProvider_GeoIp_ServerBased extends Piwik_UserCou . Piwik_Translate('UserCountry_HowToInstallNginxModule') . '</a></em>'; + $geoipServerVars = array(); + foreach ($_SERVER as $key => $value) + { + if (strpos($key, 'GEOIP') === 0) + { + $geoipServerVars[] = $key; + } + } + + if (empty($geoipServerVars)) + { + $extraMessage = '<strong><em>'.Piwik_Translate('UserCountry_GeoIPNoServerVars', '$_SERVER').'</em></strong>'; + } + else + { + $extraMessage = '<strong><em>'.Piwik_Translate('UserCountry_GeoIPServerVarsFound', '$_SERVER') + .":</em></strong><br/><br/>\n<ul style=\"list-style:disc;margin-left:24px\">\n"; + foreach ($geoipServerVars as $key) + { + $extraMessage .= '<li>'.$key."</li>\n"; + } + $extraMessage .= '</ul>'; + } + return array('id' => self::ID, 'title' => $title, 'description' => $desc, 'order' => 4, - 'install_docs' => $installDocs); + 'install_docs' => $installDocs, + 'extra_message' => $extraMessage); } /** diff --git a/plugins/UserCountry/templates/adminIndex.tpl b/plugins/UserCountry/templates/adminIndex.tpl index 4362dae5c7..a4ddcfa9bc 100755 --- a/plugins/UserCountry/templates/adminIndex.tpl +++ b/plugins/UserCountry/templates/adminIndex.tpl @@ -73,12 +73,20 @@ {/if} {/capture} {$currentLocation|inlineHelp} - {elseif $provider.status eq 2} + {/if} + {if isset($provider.statusMessage) && $provider.statusMessage} {capture assign=brokenReason} - <strong><em>{'General_Error'|translate}:</strong></em> {$provider.statusMessage} + {if $provider.status eq 2}<strong><em>{'General_Error'|translate}:</strong></em> {/if}{$provider.statusMessage} {/capture} {$brokenReason|inlineHelp} {/if} + {if isset($provider.extra_message) && $provider.extra_message} + {capture assign=extraMessage} + {$provider.extra_message} + {/capture} + <br/> + {$extraMessage|inlineHelp} + {/if} </td> {/foreach} </table> |