nextcloud / terms_of_service

📜 Requires users to accept the terms of service before accessing data.
https://apps.nextcloud.com/apps/terms_of_service
GNU Affero General Public License v3.0
31 stars 20 forks source link

Undefined index: country at /var/www/valise.chapril.org/public_html/apps/terms_of_service/lib/CountryDetector.php#57 #690

Closed pitchum closed 2 years ago

pitchum commented 2 years ago

Maybe related to #367, it seems that some IP addresses present in the maxmind DB don't have a "country" attribute. It doesn't seem to break anything, but it writes a lot of garbage in logs.

On my instance, I solved this with the following patch:

--- apps/terms_of_service/lib/CountryDetector.php
+++ apps/terms_of_service/lib/CountryDetector.php
@@ -54,6 +54,10 @@
                        return CountryMapper::GLOBAL;
                }

+               if (!array_key_exists('country', $record)) {
+                       return CountryMapper::GLOBAL;
+               }
+
                if ($this->countryMapper->isValidCountry($record['country']['iso_code'])) {
                        return $record['country']['iso_code'];
                }

HTH

nickvergessen commented 2 years ago

Can you log the IP and the returned record and share it with me?

pitchum commented 2 years ago

I don't want to publicly share IP addresses and I couldn't find a way to send you a private message. What I can tell you is that those IPs only have "continent" information in the maxmind DB. Here is what command mmdblookup return for thoses IPs:

$ mmdblookup --file GeoLite2-Country.mmdb --ip x.x.x.x

  {
    "continent": 
      {
        "code": 
          "EU" <utf8_string>
        "geoname_id": 
          6255148 <uint32>
        "names": 
          {
            "de": 
              "Europa" <utf8_string>
            "en": 
              "Europe" <utf8_string>
            "es": 
              "Europa" <utf8_string>
            "fr": 
              "Europe" <utf8_string>
            "ja": 
              "ヨーロッパ" <utf8_string>
            "pt-BR": 
              "Europa" <utf8_string>
            "ru": 
              "Европа" <utf8_string>
            "zh-CN": 
              "欧洲" <utf8_string>
          }
      }
  }
nickvergessen commented 2 years ago

Feel free to drop me an email to <my github name>@nextcloud.com

pitchum commented 2 years ago

done!