# HG changeset patch # User Matthew Wild # Date 1451924820 0 # Node ID d35376a536441ecc27e3f7a2b4e0921129e1c0d0 # Parent 67858d7315180271835e9a324b783e8815a551b2 main, geoip: Add GeoIP lookup support for watcher info diff -r 67858d731518 -r d35376a53644 geoip.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geoip.lua Mon Jan 04 16:27:00 2016 +0000 @@ -0,0 +1,24 @@ +pcall(function () + local city_db_path = os.getenv("GEOIP_CITY_DB"); + if not city_db_path then return; end + + local city_db = assert(require "geoip.city".open(city_db_path)); + + events.add_handler("new-client", function (info) + local ip = info.conn:ip(); + local location = city_db:query_by_addr(ip); + if location then + local l = {}; + if location.city_name then + table.insert(l, location.city_name); + end + if location.region then + table.insert(l, location.region); + end + if location.country_name then + table.insert(l, location.country_name); + end + conn.location = table.concat(l, ", "); + end + end); +end) diff -r 67858d731518 -r d35376a53644 main.lua --- a/main.lua Mon Jan 04 16:23:57 2016 +0000 +++ b/main.lua Mon Jan 04 16:27:00 2016 +0000 @@ -9,6 +9,7 @@ events = require "util.events".new(); require "clients"; +require "geoip"; local function printf(source, level, fmt, ...) return print(source, level, fmt:format(...)); end for _, level in ipairs{"debug", "info", "warn", "error"} do