summaryrefslogtreecommitdiff
path: root/xban2/importers
diff options
context:
space:
mode:
Diffstat (limited to 'xban2/importers')
-rw-r--r--xban2/importers/minetest.lua29
-rw-r--r--xban2/importers/v1.lua33
-rw-r--r--xban2/importers/v2.lua35
3 files changed, 97 insertions, 0 deletions
diff --git a/xban2/importers/minetest.lua b/xban2/importers/minetest.lua
new file mode 100644
index 0000000..e19c3c6
--- /dev/null
+++ b/xban2/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/xban2/importers/v1.lua b/xban2/importers/v1.lua
new file mode 100644
index 0000000..a3722c7
--- /dev/null
+++ b/xban2/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
diff --git a/xban2/importers/v2.lua b/xban2/importers/v2.lua
new file mode 100644
index 0000000..fd29966
--- /dev/null
+++ b/xban2/importers/v2.lua
@@ -0,0 +1,35 @@
+
+function xban.importers.v2()
+ return pcall(function()
+ local f, e = io.open(minetest.get_worldpath().."/players.iplist.v2")
+ if not f then
+ error("Unable to open `players.iplist.v2': "..e)
+ end
+ local text = f:read("*a")
+ f:close()
+ local db = minetest.deserialize(text)
+ for _, e in ipairs(db) do
+ for name in pairs(e.names) do
+ local entry = xban.find_entry(name, true)
+ if entry.source ~= "xban:importer_v2" then
+ for nm in pairs(e.names) do
+ entry.names[nm] = true
+ end
+ if e.banned then
+ entry.banned = true
+ entry.reason = e.banned
+ entry.source = "xban:importer_v2"
+ entry.time = e.time
+ entry.expires = e.expires
+ table.insert(entry.record, {
+ source = entry.source,
+ reason = entry.reason,
+ time = entry.time,
+ expires = entry.expires,
+ })
+ end
+ end
+ end
+ end
+ end)
+end