diff options
author | Diego Martinez <kaeza@users.sf.net> | 2014-05-21 07:07:37 -0300 |
---|---|---|
committer | Diego Martinez <kaeza@users.sf.net> | 2014-05-21 07:07:37 -0300 |
commit | d47e87e390b018ac5510bb2143eb0e66f6bc2eeb (patch) | |
tree | 268699a2fcd923116452bf33bdf833893cc6f72f /importers | |
parent | 51097eee6bb6179773e7df4c958c1dd80136ed42 (diff) |
Allow importing old databases.
Currently:
- Minetest (`ipban.txt')
- xban v1 (`players.iplist')
Diffstat (limited to 'importers')
-rw-r--r-- | importers/minetest.lua | 29 | ||||
-rw-r--r-- | importers/v1.lua | 33 |
2 files changed, 62 insertions, 0 deletions
diff --git a/importers/minetest.lua b/importers/minetest.lua new file mode 100644 index 0000000..e19c3c6 --- /dev/null +++ b/importers/minetest.lua @@ -0,0 +1,29 @@ + +function xban.importers.minetest() + local f, e = io.open(minetest.get_worldpath().."/ipban.txt") + if not f then + return false, "Unable to open `ipban.txt': "..e + end + for line in f:lines() do + local ip, name = line:match("([^|]+)%|(.+)") + if ip and name then + local entry + entry = xban.find_entry(ip, true) + entry.banned = true + entry.reason = "Banned in `ipban.txt'" + entry.names[name] = true + entry.names[ip] = true + entry.time = os.time() + entry.expires = nil + entry.source = "xban:importer_minetest" + table.insert(entry.record, { + source = entry.source, + reason = entry.reason, + time = entry.time, + expires = nil, + }) + end + end + f:close() + return true +end diff --git a/importers/v1.lua b/importers/v1.lua new file mode 100644 index 0000000..a3722c7 --- /dev/null +++ b/importers/v1.lua @@ -0,0 +1,33 @@ + +function xban.importers.v1() + local f, e = io.open(minetest.get_worldpath().."/players.iplist") + if not f then + return false, "Unable to open `players.iplist': "..e + end + for line in f:lines() do + local list = line:split("|") + if #list >= 2 then + local banned = (list[1]:sub(1, 1) == "!") + local entry + entry = xban.find_entry(list[1], true) + entry.banned = banned + for _, name in ipairs(list) do + entry.names[name] = true + end + if banned then + entry.reason = "Banned in `players.iplist'" + entry.time = os.time() + entry.expires = nil + entry.source = "xban:importer_v1" + table.insert(entry.record, { + source = entry.source, + reason = entry.reason, + time = entry.time, + expires = nil, + }) + end + end + end + f:close() + return true +end |