Skip to content

Commit

Permalink
move to cloud geoip resolver
Browse files Browse the repository at this point in the history
fixes #2
  • Loading branch information
BuckarooBanzay committed Mar 19, 2020
1 parent f039d02 commit 0f14465
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 30 deletions.
20 changes: 9 additions & 11 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
geoip = {
url = minetest.settings:get("geoip.url")
}

local http = minetest.request_http_api()

if not http then
Expand All @@ -21,7 +17,7 @@ minetest.register_privilege("geoip_verbose", {

local function lookup(ip, callback)
http.fetch({
url = geoip.url .. "/" .. ip,
url = "https://tools.keycdn.com/geo.json?host=" .. ip,
timeout = 1,
}, function(res)
if res.code == 200 and callback then
Expand Down Expand Up @@ -59,19 +55,21 @@ minetest.register_chatcommand("geoip", {
return true, "no ip available!"
end

lookup(ip, function(data)
lookup(ip, function(result)
local txt = "Geoip result: "

if data.Data then
if data.Data.Country and data.Data.Country.Names and data.Data.Country.Names.en then
txt = txt .. " Country: " .. data.Data.Country.Names.en
if result and result.status == "success" then
if result.country_name then
txt = txt .. " Country: " .. result.country_name
end
if data.Data.City and data.Data.City.Names and data.Data.City.Names.en then
txt = txt .. " City: " .. data.Data.City.Names.en
if result.city_name then
txt = txt .. " City: " .. result.city_name
end
if is_verbose then
txt = txt .. " IP: " .. ip
end
else
minetest.chat_send_player(name, "Geoip error: " .. (result.description or "unknown error"))
end

minetest.log("action", "[geoip] result for player " .. param .. ": " .. txt)
Expand Down
29 changes: 10 additions & 19 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@

geoip mod for minetest

![luacheck](https://github.com/pandorabox-io/geoip/workflows/luacheck/badge.svg)

# Overview

Lets you resolve geoip requests on a player

powered by [IP Location Finder by KeyCDN](https://tools.keycdn.com/geo)

### minetest.conf
```
# enable curl/http on that mod
secure.http_mods = geoip
# the url to the geoip server
geoip.url = http://127.0.0.1:5000
```

### Commands
```
/geoip <playername>
```


### privs

* `geoip` geoip query with basic responses (country, city)
* `geoip_verbose` geoip query with additional ip-address

### docker compose

```yml
version: "2"

services:
geoip:
image: klauspost/geoip-service
restart: always
ports:
- "5000:5000"
volumes:
- "./GeoLite2-City.mmdb:/data/geodb.mmdb"
```

0 comments on commit 0f14465

Please sign in to comment.