@iprok opened this Issue on July 1st 2018

Hello!

I make IP->geo resolving on nginx reverse proxy. So geoip headers come to matomo with HTTP_ prefix. Can you add support of such situation to matomo please? For now I manually patched the code. Path attached.
geoip-proxy.patch.gz

@Findus23 commented on July 1st 2018 Member

In case someone doesn't want to download and extract the patch file:

--- plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php.old  2018-07-01 18:49:31.401744139 +0300
+++ plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php  2018-07-01 18:42:21.977012029 +0300
@@ -26,25 +26,25 @@
 {
     const ID = 'geoip_serverbased';
     const TITLE = 'GeoIP Legacy (%s)';
-    const TEST_SERVER_VAR = 'GEOIP_ADDR';
-    const TEST_SERVER_VAR_ALT = 'GEOIP_COUNTRY_CODE';
-    const TEST_SERVER_VAR_ALT_IPV6 = 'GEOIP_COUNTRY_CODE_V6';
+    const TEST_SERVER_VAR = 'HTTP_GEOIP_ADDR';
+    const TEST_SERVER_VAR_ALT = 'HTTP_GEOIP_COUNTRY_CODE';
+    const TEST_SERVER_VAR_ALT_IPV6 = 'HTTP_GEOIP_COUNTRY_CODE_V6';

     private static $geoIpServerVars = array(
-        parent::COUNTRY_CODE_KEY => 'GEOIP_COUNTRY_CODE',
-        parent::COUNTRY_NAME_KEY => 'GEOIP_COUNTRY_NAME',
-        parent::REGION_CODE_KEY  => 'GEOIP_REGION',
-        parent::REGION_NAME_KEY  => 'GEOIP_REGION_NAME',
-        parent::AREA_CODE_KEY    => 'GEOIP_AREA_CODE',
-        parent::LATITUDE_KEY     => 'GEOIP_LATITUDE',
-        parent::LONGITUDE_KEY    => 'GEOIP_LONGITUDE',
-        parent::POSTAL_CODE_KEY  => 'GEOIP_POSTAL_CODE',
+        parent::COUNTRY_CODE_KEY => 'HTTP_GEOIP_COUNTRY_CODE',
+        parent::COUNTRY_NAME_KEY => 'HTTP_GEOIP_COUNTRY_NAME',
+        parent::REGION_CODE_KEY  => 'HTTP_GEOIP_REGION',
+        parent::REGION_NAME_KEY  => 'HTTP_GEOIP_REGION_NAME',
+        parent::AREA_CODE_KEY    => 'HTTP_GEOIP_AREA_CODE',
+        parent::LATITUDE_KEY     => 'HTTP_GEOIP_LATITUDE',
+        parent::LONGITUDE_KEY    => 'HTTP_GEOIP_LONGITUDE',
+        parent::POSTAL_CODE_KEY  => 'HTTP_GEOIP_POSTAL_CODE',
     );

     private static $geoIpUtfServerVars = array(
-        parent::CITY_NAME_KEY => 'GEOIP_CITY',
-        parent::ISP_KEY       => 'GEOIP_ISP',
-        parent::ORG_KEY       => 'GEOIP_ORGANIZATION',
+        parent::CITY_NAME_KEY => 'HTTP_GEOIP_CITY',
+        parent::ISP_KEY       => 'HTTP_GEOIP_ISP',
+        parent::ORG_KEY       => 'HTTP_GEOIP_ORGANIZATION',
     );

     /**
@@ -232,7 +232,7 @@

         $geoipServerVars = array();
         foreach ($_SERVER as $key => $value) {
-            if (strpos($key, 'GEOIP') === 0) {
+            if (strpos($key, 'HTTP_GEOIP') === 0) {
                 $geoipServerVars[] = $key;
             }
         }
@sgiehl commented on July 1st 2018 Member

@iprok GeoIP (Legacy) has been deprecated, so I guess we won't change the behavior for this anymore.
For GeoIP2 it is already possible to configure the server variable names for all variables.

@iprok commented on July 1st 2018

@iprok GeoIP (Legacy) has been deprecated, so I guess we won't change the behavior for this anymore.
For GeoIP2 it is already possible to configure the server variable names for all variables.

I use geoip2 on my proxy and I just fake variable names because I thought matomo doesn't support geoip2 variable names. Where can I find information about it? I have latest matomo installed.

@sgiehl commented on July 1st 2018 Member

you need to enable the geoip2 plugin, but this will trigger an update on the log tables, so for bigger databases this might take a bit longer...

This Issue was closed on July 2nd 2018
Powered by GitHub Issue Mirror