Skip to main content
Topic: [ADDON] GeoIP Location (Read 2091 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

[ADDON] GeoIP Location

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
Squish squish. squish, squish, squish.
Find a bug,
Make a wish.

Re: [ADDON] GeoIP Location

Reply #1
Cool stuff! :D

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.

 emanuele 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
Bugs creator.
Features destroyer.
Template killer.

Re: [ADDON] GeoIP Location

Reply #2
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.
Squish squish. squish, squish, squish.
Find a bug,
Make a wish.

Re: [ADDON] GeoIP Location

Reply #3
Updated package to support ElkArte 1.1
Squish squish. squish, squish, squish.
Find a bug,
Make a wish.

Re: [ADDON] GeoIP Location

Reply #4
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?

Re: [ADDON] GeoIP Location

Reply #5
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

Re: [ADDON] GeoIP Location

Reply #6
Tell me please, can I put CMS on the server with version 5.1
Or what is the minimum requirement?

Re: [ADDON] GeoIP Location

Reply #7
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?


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.
Bugs creator.
Features destroyer.
Template killer.

Re: [ADDON] GeoIP Location

Reply #8
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.

Re: [ADDON] GeoIP Location

Reply #9
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.

Re: [ADDON] GeoIP Location

Reply #10
hmm...
No error in the javascript console?
Or in the error log?
Bugs creator.
Features destroyer.
Template killer.


Re: [ADDON] GeoIP Location

Reply #12
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.

Re: [ADDON] GeoIP Location

Reply #13
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.  ;)

Re: [ADDON] GeoIP Location

Reply #14
I think I have to install the mod to understand what is going on... Today is finished, I'll see if I can tomorrow. :-\
Bugs creator.
Features destroyer.
Template killer.