-- mod governor by mckaygerhard, geoip specific code -- Copyright 2023 ---------------------------------------------------------------------------- -- this program can be used free but cannot be used commertially or -- modified for, licenced CC-BY-SA-NC 4.0 unless explicit permission -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ---------------------------------------------------------------------------- function format_result_geoip(result) local txt = " Place: " if result then if result.status == "success" and result.data and result.data.geo then 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 else return false end end function format_result_checkip(result) local txt = " Place: " local flg = "" if result then if result.message then return result.message .. ".. <_< . if no key, use /geoip command" end if result.security then if result.security.vpn then if result.security.vpn ~= "true" then flg = flg .. "+VPN" end end if result.security.proxy then if result.security.proxy ~= "true" then flg = flg .. "+PRX" end end if result.security.tor then if result.security.tor ~= "true" then flg = flg .. "+TOR" end end if result.security.relay then if result.security.tor ~= "true" then flg = flg .. "+REL" end end end if result.location then if result.location then if result.location.continent ~= "" then txt = txt .. result.location.continent_name .."," end end if result.location.country then if result.location.country ~= "" then txt = txt .. result.location.country .."," end end if result.location.region then if result.location.region ~= "" then txt = txt .. result.location.region .. "," end end if result.location.city then if result.location.city ~= "" then txt = txt .. result.location.city .." " end end if result.location.time_zone then if result.location.time_zone ~= "" then txt = txt .. "Timezone: " .. result.location.time_zone end end end if result.network then if result.network.autonomous_system_number then if result.network.autonomous_system_number ~= "" then txt = txt .. " ASN: " .. result.network.autonomous_system_number end end if result.network.autonomous_system_organization then if result.network.autonomous_system_organization ~= "" then txt = txt .. " ISP: " .. result.network.autonomous_system_organization end end end if result.ip then if result.ip ~= "" then txt = txt .. " IP: " .. result.ip end end return flg .. txt else return false end 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 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 -- do log ip check: if not apikey then geoip from mod; if not mod then our own geoip if governing.checkapikey ~= "" then governing.checkip(ip, function(data) -- log, but TODO: record in storage log file local txt = format_result_checkip(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) else if not governing.modgeoip then governing.lookup(ip, function(data) -- log, but TODO: record in storage log file local txt = format_result_checkip(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 end)