10 log("debug", "Loading geoip database"); |
10 log("debug", "Loading geoip database"); |
11 local city_db = assert(require "geoip.city".open(city_db_path)); |
11 local city_db = assert(require "geoip.city".open(city_db_path)); |
12 log("debug", "Loaded geoip database successfully"); |
12 log("debug", "Loaded geoip database successfully"); |
13 |
13 |
14 events.add_handler("new-client", function (info) |
14 events.add_handler("new-client", function (info) |
15 local ip = info.conn:ip(); |
15 local ip = info.request.headers.x_forwarded_for or info.conn:ip(); |
16 local location = city_db:query_by_addr(ip); |
|
17 log("debug", "GeoIP query for %s", tostring(ip)); |
16 log("debug", "GeoIP query for %s", tostring(ip)); |
18 local location, err = city_db:query_by_addr(ip); |
17 local location, err = city_db:query_by_addr(ip); |
19 if location then |
18 if location then |
20 local l = {}; |
19 local l = {}; |
21 if location.city_name then |
20 if location.city_name then |