Adding a new trick to an old dog

Started by Gregg, January 09, 2011, 02:29:22 AM

Previous topic - Next topic

Gregg

Surfing along the info superhighway one day looking for a way to get a remote users time zone using the GeoIP data I happened to stumble onto GeoIP Extended.

This geoip API is gutted of much over and above what comes from the CityLite database only. There is then code to make a php extension as well. It includes code to enable the API to tap into the time zone data of the City/CityLite databases.

I diffed the GeoIP Extended API against 1.4.6 from Maxmind, followed the yellow brick road modifying a Maxmind original, debuged some issues, and built as a static lib instead of dll.

I then added the functionality in mod_geoip to include GEOIP_TIME_ZONE_NAME into the environment to be picked up by a scripting language of your pleasure. It was some trial and error but to my complete surprise, It works!

Of course, mileage/kilometers will vary according to the errors of the citylite db.
Since there is only one function in the timezone.c file of the API, it looks like time zones need to be chosen by country and region, it may not be able to be retrieved from ipv6, unless a more general time zone works.

So I need to dig around and experiment some more, I see three other things  that might be worth extracting from the db


Gregg

Upon further inspection, nothing needs to be changed in the geoip api, it just needs to be built to include everything. The addition of the timezone to mod_geoip is working good, I'm now trying to get the country code3 to it but it's being a challenge. 

Sob

Quote from: Gregg on January 10, 2011, 10:40:28 PMI'm now trying to get the country code3 to it but it's being a challenge.
You mean finding lines that contain some form of "country_code", duplicating them and appending "3" to newly added ones? That doesn't sound like a big challenge. ;)

Gregg

No, I found those in the API, getting them used in mod_geoip is what my first attempt had problems with, but that was my first attempt. It compiled clean but crashed Apache. I haven't attempted it again yet but will soon.

Sob

I did exactly what I wrote before:

http://web.hisoftware.cz/sob/download/mod_geoip2_1.2.5-cc3.patch

And it works fine here (I admit that testing was very limited).

Gregg

#5
I have the first part of that which works only with the country database. I tried same in the case for the city & region DBs and it was seizing Apache, but I figured out why that was happening so all is good.

$ENV{'GEOIP_REGION_NAME'} = California
$ENV{'GEOIP_COUNTRY_CODE3'} = USA
$ENV{'GEOIP_LATITUDE'} = 32.797699
$ENV{'GEOIP_COUNTRY_CODE'} = US
$ENV{'GEOIP_COUNTRY_NAME'} = United States
$ENV{'GEOIP_CONTINENT_CODE'} = NA
$ENV{'GEOIP_DMA_CODE'} = 825
$ENV{'GEOIP_CITY'} = San Diego
$ENV{'GEOIP_AREA_CODE'} = 619
$ENV{'GEOIP_REGION'} = CA
$ENV{'GEOIP_LONGITUDE'} = -117.132202
$ENV{'GEOIP_TIME_ZONE_NAME'} = America/Los_Angeles

Monday, Jan 10, 2011 9:00 PM PST
Tuesday, Jan 11, 2011 05:00:44 UTC

Even though the Region db uses a different struct (*giregion), I'm assuming it has the same stuff since it spits out a county code as well. That was where the crashing was coming from. There's no giregion->country_code3 and the way I was trying to obtain it (like in the country db) was problematic. Duh me!

Of course, I never plan to buy a region db so I'll never be able to test it. So I guess the only question left is, does it show the right city info and if so, the right time zone?

http://www.apachehaus.net/

Is it showing the proper time for you there on the left side?

Sob

I tried only free country and city databases as I don't have access to paid ones.

QuoteIs it showing the proper time for you there on the left side?
Tried it from two locations and have the same results. It finds the correct location, but on the left under hostname there's "[an error occurred while processing this directive]" and the same is on the right under GMT Time and Server Time.

mario

From home it didn't work with the location, well the ISP is somewhere ;D  Form de mirror with lynx it shows the correct location :D

Gregg

Yeah, it's not perfect outside the US at all. So I need to rethink it some. That was a quick & dirty script, DateTime module in Perl could use to be a bit more forgiving as well which is what caused the errors you got Sob.

DnvrSysEngr

FYI -

When I went to www.apachehaus.net, it populated the following fields for me:

Hello visitor from Arvada, Colorado, United States
IP Address: 97.118.35.118
Hostname: 97-118-35-118.hlrn.qwest.net
Wednesday, Jan 12, 2011 5:58 PM MST

GMT Time:
Thursday, Jan 13, 2011 00:58:11 UTC

Server Time:
Wednesday, Jan 12, 2011 4:58 PM PST

Server Uptime:
1 day 0 hours 59 minutes 45 seconds

Apache Uptime:
1 days, 0 hrs, 50 mins, 542 secs

Is there anything specific I should be looking for?


Gregg

Hi DnvrSysEngr,

What I cared about was that it got the timezone correct.

Are you in Colorado?
If so you're in MST which is correct regardless of what city.

MST = PST+1 & GMT-7 so your time looks correct and UTC looks correct.

Thanks for checking and reporting in  :)

Looks like I could use to do some work on Apache Uptime too, 542 seconds lol ::)

DnvrSysEngr

Gregg:

545 seconds in a minute?  On another planet maybe? LOL

I should not say anything as coding is not my area of expertise.

Apache Uptime:
1 days, 5 hrs, 29 mins, 545 secs


I do like this script and would not mind having it to put on some of my customers sites.

- Scott

Gregg

Well, let me make it a little less prone to error first. I have a backup plan too, figure it out by country. Of course I can think of many countries that cover multiple time zones. I'm not worried about AU,CA & US as I know those are covered pretty well, although if you're in Adelaide, AU on optusnet.com.au you will show up as Melbourne or Brighton which is a 1/2 hour ahead of Adelaide. Thats cause of how Optus gives out IPs.

The ones that will not fair well I believe are China, Russia and the Ukraine. Each span at least 3 time zones or more. Picking one is going to be wrong in most cases but oh well.

Sob

You may try GeoIP 1.4.7 beta, unlike 1.4.6 it has more countries divided into regions in timeZone.c.

DnvrSysEngr

Update:

Today, when I went to www.apachehaus.net, it populated the following fields for me:

Hello visitor from (none), (none), United States
IP Address: 65.106.84.254
Hostname: 65.106.84.254.ptr.us.xo.net
[an error occurred while processing this directive]

GMT Time:
[an error occurred while processing this directive]
Server Time:
[an error occurred while processing this directive]Server Uptime:
2 days 17 hours 22 minutes 42 seconds

Apache Uptime:
0 days, 10 hours, 11 minutes, 48 seconds

Not as successful as last time.

- Scott