ElkArte Community

Extending Elk => Addons => Topic started by: Spuds on August 03, 2014, 02:06:16 pm

Title: [ADDON] GeoIP Location
Post by: Spuds on August 03, 2014, 02:06:16 pm
This is a simplified version of my GeoIP modification.  The simplification is that it now depends on the web server (Nginx or Apache) providing the GeoIP data.   This means that your web server must having this capability enabled and that it also provides the environment data to PHP.   My original modification created a mysql database from the maxmind files, this proved to be a support issue.  Now it depends on the server, so if your web  server does not have this, don't install this addon.    Also note I've only tested this with Nginx since thats what I use,

geoIP Location

Introduction
This modification adds the ability to use the latitude & longitude of a member given their IP address. This is commonly referred to as geolocation. The mod makes use of the geoip capabilities in Nginx or Apache web servers.  You must have this capability enabled in your web server and they must make the following enviroment variables available to PHP ('GEOIP_LATITUDE', 'GEOIP_LONGITUDE' 'GEOIP_CITY_COUNTRY_NAME', 'GEOIP_CITY', 'GEOIP_CITY_COUNTRY_CODE')

License
o This modification is released under a MPL V1.1 license, a copy of it with its provisions is included with the package.

A note on accuracy:
Maxmind shows that this database (which is updated on a monthly basis) is over 99.5% accurate on a country level making it a viable source for registration blocking.

When it comes to the city level accuracy this number is and 79% for the US (within a 25 mile radius).  That is the best accuracy, and other countries city/region location accuracy tapper off from that.  Even with that level of accuracy, it still makes for an entertaining online member map.

In some instances the IP address will not be found, or will have incomplete data.  In this case the mod will make use of secondary sources to gather information.

Features
o Adds an on-line member map which will show a map pin for each IP currently on your forum
o Adds the ability to block or allow member registrations on a per country basis
o Adds in the geoIP information under the track IP sections, allows you to see city / region (state) / country of the IP address
o No source edits
o @todo add country flag to online member list

There are admin settings available with this mod, go to admin - configuration - addon settings - geoIP.

Installation
IMPORTANT NOTES:
o The package will install on all systems, however you must have geoip capabilities enabled in the web server and the environment variables made available to PHP.  If you are on shared hosting, check with your host, or if you are on a VPS you can read how to do it, for example with Nginx : http://www.howtoforge.com/using-geoip-with-nginx-on-ubuntu-12.04

Repo
https://bitbucket.org/spuds_/elk_geoip
Source
https://bitbucket.org/spuds_/elk_geoip/src
Download
http://addons.elkarte.net/feature/geoIP-Location.html
Title: Re: [ADDON] GeoIP Location
Post by: emanuele on August 03, 2014, 06:18:00 pm
Cool stuff! :D

Quote from: Spuds – so if your web  server does not have this, don't install this addon.
And that makes me think that a very cool feature for our beloved PacMan could be a dependencies check of sort... well, in the end it would just be a "during-install-checks-run-this-function" kind of thing.

/me loves how easy things look like when you write them compared to how difficult the darn b**stards are when you have to actually code them. xD
Title: Re: [ADDON] GeoIP Location
Post by: Spuds on August 04, 2014, 08:42:22 am
Not a bad idea ... we do have <requires> in pacman , but thats a package dependency check.  Could add a server based one, like min level of php, mysql, or some extension installed.    I think this could be done if I add in a <code> section and do the checks as well.
Title: Re: [ADDON] GeoIP Location
Post by: Spuds on November 26, 2017, 05:55:51 pm
Updated package to support ElkArte 1.1
Title: Re: [ADDON] GeoIP Location
Post by: badmonkey on January 02, 2018, 09:32:03 pm
Fantastic addon!  Many thanks for your work on this @Spuds‍   8)   One question: would it be possible for the popups on the Online Member map to show the corresponding IP?
Title: Re: [ADDON] GeoIP Location
Post by: b4pjoe on January 14, 2018, 05:50:39 pm
I have checked with my host and they have enabled GeoIP in my shared hosting plan. I installed this add-on in a clean install of ElkArte 1.1.1. I got my Google API key and put it in the admin settings for GeoIP. My host told me to add

GeoIPEnable On

to my .htaccess file.

I'm using PHP 7.1.

But when I try to go to the map I see a map flash in the box and then it immediately goes gray with the message:

Oops! Something went wrong.
This page didn't load Google Maps correctly. See the JavaScript console for technical details.

Looking at the Javascript Console it says:

Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error

ElkArte error log shows this error (see atttached)

Is this addon compatible with ElkArte 1.1.1? If so any idea what could be going on
Title: Re: [ADDON] GeoIP Location
Post by: Yokohama on January 18, 2018, 02:33:51 pm
Tell me please, can I put CMS on the server with version 5.1
Or what is the minimum requirement?
Title: Re: [ADDON] GeoIP Location
Post by: emanuele on January 18, 2018, 06:34:59 pm
Quote from: b4pjoe – But when I try to go to the map I see a map flash in the box and then it immediately goes gray with the message:

Oops! Something went wrong.
This page didn't load Google Maps correctly. See the JavaScript console for technical details.

Looking at the Javascript Console it says:

Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error
hmm... I'm not expert on this one, but it may be a little mistake in the template, can you try changing:
Code: [Select]
$key = !empty($modSettings['googleMap_Key']) ? $modSettings['googleMap_Key'] : '';
to:
Code: [Select]
$key = !empty($modSettings['geoIP_Key']) ? $modSettings['geoIP_Key'] : '';
in the file geoIP.template.php?


Quote from: b4pjoe – ElkArte error log shows this error (see atttached)

Is this addon compatible with ElkArte 1.1.1? If so any idea what could be going on
This seems unrelated, it may be some functionality removed?
You can just change:
Code: [Select]
if ($modSettings['googleMap_Sidebar'] !== 'none')
to:
Code: [Select]
if (!empty($modSettings['googleMap_Sidebar']) && $modSettings['googleMap_Sidebar'] !== 'none')
in GeoIP.controller.php.
Title: Re: [ADDON] GeoIP Location
Post by: b4pjoe on January 19, 2018, 11:11:50 am
Thanks for the replies Emanuele. I am using the default ElkArte template. I will try these two things this weekend and see if I can get it working.
Title: Re: [ADDON] GeoIP Location
Post by: b4pjoe on January 20, 2018, 11:12:13 am
Changing those settings in geoIP.template.php does give me a map now but there are no locations shown and the sidebar doesn't show any users online even though there are users logged in and online.

Changing the setting in GeoIP.controller.php does get rid of the error messages but the map is no longer visible when you make that change.
Title: Re: [ADDON] GeoIP Location
Post by: emanuele on January 20, 2018, 02:14:10 pm
hmm...
No error in the javascript console?
Or in the error log?
Title: Re: [ADDON] GeoIP Location
Post by: b4pjoe on January 20, 2018, 11:51:03 pm
With the edits to geoIP.template.php I still get this error in the error log. (see attachment #1)

And in the javascript console I get this. (see attachment #2)
Title: Re: [ADDON] GeoIP Location
Post by: b4pjoe on January 21, 2018, 09:54:42 am
I reverted back to the original files geoIP.template.php and GeoIP.controller.php and made the edits again. I do get the map now but still no users listed in the sidebar and no locations shown on the map and I am no longer getting the errors in the error log and I am not seeing any errors in the javascript console. So no errors, I get the map but no users and no locations on the map.
Title: Re: [ADDON] GeoIP Location
Post by: badmonkey on January 21, 2018, 03:29:21 pm
Are you using nginx? I ran into some issues between the latest nginx 1.13.8 and the maxminds geoip database. For some reason it was super slow with lookups, like 10 seconds for each reference  I reverted back to 1.13.7, problem solved. Or so I thought. After updating the geoip database files, things were sluggish with some unexpected behaviors. One of which the map took a while to populate after restarting nginx. So reverting the geoip files was in order as well. Didn't try the two latest versions together. Thought it wise to let them settle out the bugs first. Anyway, just throwing that out there.  ;)
Title: Re: [ADDON] GeoIP Location
Post by: emanuele on January 21, 2018, 06:00:20 pm
I think I have to install the mod to understand what is going on... Today is finished, I'll see if I can tomorrow. :-\
Title: Re: [ADDON] GeoIP Location
Post by: b4pjoe on January 22, 2018, 09:14:51 am
Quote from: badmonkey – Are you using nginx? I ran into some issues between the latest nginx 1.13.8 and the maxminds geoip database. For some reason it was super slow with lookups, like 10 seconds for each reference  I reverted back to 1.13.7, problem solved. Or so I thought. After updating the geoip database files, things were sluggish with some unexpected behaviors. One of which the map took a while to populate after restarting nginx. So reverting the geoip files was in order as well. Didn't try the two latest versions together. Thought it wise to let them settle out the bugs first. Anyway, just throwing that out there.  ;)

I am on shared hosting. Not sure what OS they use.
Title: Re: [ADDON] GeoIP Location
Post by: ahrasis on January 22, 2018, 10:09:39 am
You can check php info in server config to check the OS. Mine is something like this:
$_SERVER['SERVER_SOFTWARE']   nginx/1.13.8
Title: Re: [ADDON] GeoIP Location
Post by: b4pjoe on January 24, 2018, 09:52:54 pm
Mine shows this:

$_SERVER['SERVER_SOFTWARE']   LiteSpeed
Title: Re: [ADDON] GeoIP Location
Post by: badmonkey on March 29, 2019, 11:00:24 am
I'm having issues getting this to work with geoip2 on nginx. How should the fastcgi_param be passed? It's probably just a variable naming issue.... ::)
Title: Re: [ADDON] GeoIP Location
Post by: Spuds on April 01, 2019, 04:29:12 pm
here is what I use.  This is on nginx version: nginx/1.14.1 with ngx_geoip2_module-3.2 ... this is for the GeoLite2 databases.

Code: [Select]
# GEOIP Variables
fastcgi_param  GEOIP_COUNTRY_CODE $geoip2_country_code;
fastcgi_param  GEOIP_COUNTRY_NAME $geoip2_country;
fastcgi_param  GEOIP_CITY_COUNTRY_CODE $geoip2_country_code;
fastcgi_param  GEOIP_CITY_COUNTRY_NAME $geoip2_country;
fastcgi_param  GEOIP_REGION $geoip2_region_code;
fastcgi_param  GEOIP_REGION_NAME $geoip2_region;
fastcgi_param  GEOIP_CITY $geoip2_city;
fastcgi_param  GEOIP_POSTAL_CODE $geoip2_postal_code;
fastcgi_param  GEOIP_CITY_CONTINENT_CODE $geoip2_continent_code;
fastcgi_param  GEOIP_LATITUDE $geoip2_latitude;
fastcgi_param  GEOIP_LONGITUDE $geoip2_longitude;