mckaygerhard 31542d73da geoip part - the format for geopip now with unique name
* this cos we will also implement a new cdn api tool
  to detect vpn access and real ip clients
2023-06-21 22:00:15 -04:00

66 lines
2.4 KiB
Lua

function format_result_geoip(result)
if result and result.status == "success" and result.data and result.data.geo then
local txt = " Place: "
if result.data.geo.ip then
if result.data.geo.ip == "127.0.0.1" then return txt .. " seems localhost " ..".. <_< ." end
end
if result.data.geo.continent_name then
if result.data.geo.continent_name ~= "" then txt = txt .. result.data.geo.continent_name .."," end
end
if result.data.geo.country_name then
if result.data.geo.country_name ~= "" then txt = txt .. result.data.geo.country_name .."," end
end
if result.data.geo.region_name then
if result.data.geo.region_name ~= "" then txt = txt .. result.data.geo.region_name .. "," end
end
if result.data.geo.city then
if result.data.geo.city ~= "" then txt = txt .. result.data.geo.city .."" end
end
if result.data.geo.timezone then
if result.data.geo.timezone ~= "" then txt = txt .. " Timezone: " .. result.data.geo.timezone end
end
if result.data.geo.asn then
if result.data.geo.asn ~= "" then txt = txt .. " ASN: " .. result.data.geo.asn end
end
if result.data.geo.isp then
if result.data.geo.isp ~= "" then txt = txt .. " ISP: " .. result.data.geo.isp end
end
if result.data.geo.ip then
if result.data.geo.ip ~= "" then txt = txt .. " IP: " .. result.data.geo.ip end
end
return txt
else
return false
end
end
if not governing.modgeoip then
minetest.register_privilege("geoip", {
description = "can do geoip lookups on players for governing",
give_to_singleplayer = false
})
end
governing.joinplayer_callback = function() end -- function(name, result)
minetest.register_on_joinplayer(function(player) -- query ip on join, record in logs and execute callback
if not governing.modgeoip then
if not player then return end
if not player:is_player() then return end
if not minetest.get_player_ip then return end
local name = player:get_player_name()
local ip = minetest.get_player_ip(name)
if not ip then return end
governing.lookup(ip, function(data) -- log, but TODO: record in storage log file
local txt = format_result_geoip(data)
if txt then minetest.log("warning", "[goberning/geoip] joined player, " .. name .. ":" .. ip .. "," .. txt)
else minetest.log("error", "[goberning/geoip] joined player, " .. name .. ":" .. ip .. ", seems fails")
end
governing.joinplayer_callback(name, data) -- execute callback
end)
end
end)