telize

High performance JSON IP and GeoIP REST API (IP Geolocation)
Log | Files | Refs | README | LICENSE

commit 29d093f5c783dc95caadf96072b04ff4aa46c188
parent 932806b72827a1804f54af29c5a10f5c895605ff
Author: Frederic Cambus <fcambus@users.sourceforge.net>
Date:   Thu,  3 Oct 2013 15:22:35 +0200

Support for GeoIP ASN database (and adding ASN and ISP fields to the JSON output)

Diffstat:
Mtelize | 15+++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/telize b/telize @@ -4,7 +4,7 @@ # http://www.telize.com # # # # Created: 2013/08/15 # -# Last Updated: 2013/08/21 # +# Last Updated: 2013/10/03 # # # # Telize is released under the BSD 3-Clause license. # # See LICENSE file for details. # @@ -45,15 +45,20 @@ server { location /localize { set_real_ip_from 127.0.0.1; - echo_exec /jsonify ip=$remote_addr&country_code=$geoip_city_country_code&country_code3=$geoip_city_country_code3&country=$geoip_city_country_name&region_code=$geoip_region&region=$geoip_region_name&city=$geoip_city&postal_code=$geoip_postal_code&continent_code=$geoip_city_continent_code&latitude=$geoip_latitude&longitude=$geoip_longitude&dma_code=$geoip_dma_code&area_code=$geoip_area_code&callback=$arg_callback; + echo_exec /jsonify ip=$remote_addr&country_code=$geoip_city_country_code&country_code3=$geoip_city_country_code3&country=$geoip_city_country_name&region_code=$geoip_region&region=$geoip_region_name&city=$geoip_city&postal_code=$geoip_postal_code&continent_code=$geoip_city_continent_code&latitude=$geoip_latitude&longitude=$geoip_longitude&dma_code=$geoip_dma_code&area_code=$geoip_area_code&org=$geoip_org&callback=$arg_callback; } location /jsonify { access_log off; - + charset iso-8859-1; default_type application/json; + if ($geoip_org ~* "^(AS[0-9]+) (.+)") { + set $asn $1; + set $isp $2; + } + content_by_lua ' local cjson = require("cjson") @@ -70,6 +75,8 @@ server { local longitude = ngx.var.arg_longitude ~= "" and tonumber(ngx.var.arg_longitude) or nil local dma_code = ngx.var.arg_dma_code ~= "" and ngx.var.arg_dma_code or nil local area_code = ngx.var.arg_area_code ~= "" and ngx.var.arg_area_code or nil + local asn = ngx.var.asn ~= "" and ngx.var.asn or nil + local isp = ngx.var.isp ~= "" and ngx.var.isp or nil local callback = ngx.var.arg_callback if ip == "127.0.0.1" then @@ -78,7 +85,7 @@ server { ngx.exit(ngx.HTTP_OK) end - json = cjson.encode({ip = ip, country_code = country_code, country_code3 = country_code3, country = country, region_code = region_code, region = region, city = city, postal_code = postal_code, continent_code = continent_code, latitude = latitude, longitude = longitude, dma_code = dma_code, area_code = area_code}) + json = cjson.encode({ip = ip, country_code = country_code, country_code3 = country_code3, country = country, region_code = region_code, region = region, city = city, postal_code = postal_code, continent_code = continent_code, latitude = latitude, longitude = longitude, dma_code = dma_code, area_code = area_code, asn = asn, isp = isp}) if callback ~= "" then ngx.say(callback, "(", json, ");")