Compare commits
5 Commits
96f9dbb148
...
e296f4568d
Author | SHA1 | Date |
---|---|---|
|
e296f4568d | |
|
3f36207279 | |
|
fea69b3d94 | |
|
4a7833f700 | |
|
3233c74c53 |
10
api.lua
10
api.lua
|
@ -1,8 +1,8 @@
|
|||
local api_base = {}
|
||||
local http_api = ...
|
||||
local cache_time = tonumber(core.settings:get("block_vps_cache_time")) or 30000 -- ~8 hours
|
||||
local max_try_count = tonumber(core.settings:get("block_vps_max_try")) or 3 -- how many API do we try to use before aborting
|
||||
local enabled_sources = string.split(core.settings:get("block_vps_datasources")
|
||||
local cache_time = tonumber(block_vps.get_setting("block_vps_cache_time")) or 30000 -- ~8 hours
|
||||
local max_try_count = tonumber(block_vps.get_setting("block_vps_max_try")) or 3 -- how many API do we try to use before aborting
|
||||
local enabled_sources = string.split(block_vps.get_setting("block_vps_datasources")
|
||||
or "iphub, iphub_legacy, nastyhosts", ",")
|
||||
|
||||
local function gen_stub(name)
|
||||
|
@ -213,7 +213,7 @@ local function get_info_async(ip, callback, try_count, ignored_datasources, ...)
|
|||
table.insert(ignored_datasources, name)
|
||||
get_info_async(ip, callback, try_count, ignored_datasources, ...)
|
||||
else
|
||||
-- might be better to return stale information if aviable?
|
||||
-- might be better to return stale information if available?
|
||||
ip_info_cache[ip] = ip_info
|
||||
callback(ip, ip_info, ...)
|
||||
end
|
||||
|
@ -225,7 +225,7 @@ function block_vps.get_ip_info(ip, callback, ...)
|
|||
-- Check if we already looked up that IP recently and return from cache
|
||||
local info = ip_info_cache[ip]
|
||||
if info then
|
||||
source = datasources[info.api]
|
||||
local source = datasources[info.api]
|
||||
if not source:is_data_stale(info) then
|
||||
callback(ip, info, ...)
|
||||
return
|
||||
|
|
39
init.lua
39
init.lua
|
@ -3,8 +3,23 @@ local http_api = minetest.request_http_api()
|
|||
assert(http_api ~= nil, "Add 'block_vps' to secure.http_mods and restart server")
|
||||
|
||||
local mod_path = core.get_modpath(core.get_current_modname())
|
||||
local mod_storage = minetest.get_mod_storage()
|
||||
local block_type = core.settings:get("block_vps_type") or "activation"
|
||||
local mod_storage
|
||||
|
||||
-- support older minetest versions
|
||||
if minetest.get_mod_storage then
|
||||
mod_storage = minetest.get_mod_storage()
|
||||
end
|
||||
|
||||
-- support older minetest versions
|
||||
function block_vps.get_setting(name)
|
||||
if core.settings then
|
||||
return core.settings:get(name)
|
||||
else
|
||||
return core.setting_get(name)
|
||||
end
|
||||
end
|
||||
|
||||
local block_type = block_vps.get_setting("block_vps_type") or "activation"
|
||||
|
||||
assert(loadfile(mod_path .. "/api.lua"))(http_api)
|
||||
dofile(mod_path .. "/iphub.lua")
|
||||
|
@ -46,6 +61,12 @@ if block_type == "creation" then
|
|||
end
|
||||
end)
|
||||
elseif block_type == "activation" then
|
||||
-- support older minetest versions
|
||||
assert(mod_storage ~= nil, "Your minetest version doesn't support mod storage, " ..
|
||||
"it is required if 'block_vps_type' is set to 'activation' please change it to any other support setting ('none', 'kick', 'creation')")
|
||||
|
||||
local default_privs = core.string_to_privs(core.settings:get("default_privs"))
|
||||
|
||||
core.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
-- Check if the account has yet to connect from a valid IP
|
||||
|
@ -56,7 +77,9 @@ elseif block_type == "activation" then
|
|||
log_block(name, ip, info.isp, info.api, true)
|
||||
minetest.kick_player(name, create_reject_message(ip, info.isp))
|
||||
else
|
||||
mod_storage:set_int(name, 0) -- there doesn't seem to be a function to erase a key?
|
||||
-- give the player back the default privs we took
|
||||
core.set_player_privs(name, default_privs)
|
||||
mod_storage:set_string(name, "") -- only way to erase a mod storage key
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
@ -64,6 +87,8 @@ elseif block_type == "activation" then
|
|||
|
||||
core.register_on_newplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
-- revoke all of the players privs so they don't try to exploit the small delay between connection and IP lookup end.
|
||||
core.set_player_privs(name, {})
|
||||
block_vps.get_ip_info(core.get_player_ip(name), function(ip, info)
|
||||
if info and info.is_blocked then
|
||||
--[[
|
||||
|
@ -73,12 +98,18 @@ elseif block_type == "activation" then
|
|||
mod_storage:set_int(name, 1)
|
||||
log_block(name, ip, info.isp, info.api, true)
|
||||
minetest.kick_player(name, create_reject_message(ip, info.isp, true))
|
||||
else
|
||||
-- give the player back the default privs we took
|
||||
core.set_player_privs(name, default_privs)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
elseif block_type == "kick" then
|
||||
core.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
if core.check_player_privs(name, {bypass_ip_check=true}) then
|
||||
return
|
||||
end
|
||||
block_vps.get_ip_info(core.get_player_ip(name), function(ip, info)
|
||||
if info and info.is_blocked then
|
||||
log_block(name, ip, info.isp, info.api, true)
|
||||
|
@ -88,6 +119,8 @@ elseif block_type == "kick" then
|
|||
end)
|
||||
end
|
||||
|
||||
core.register_privilege("bypass_ip_check", "Stops the users IP from being check on join by block_vps")
|
||||
|
||||
core.register_chatcommand("get_ip_info", {
|
||||
params = "<ip_address>",
|
||||
description = "Display IP address information",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
local ip_hub_api = {}
|
||||
local API_KEY = core.settings:get("iphub_api_key") or 'YOUR_API_KEY_HERE'
|
||||
local API_KEY = block_vps.get_setting("iphub_api_key") or 'YOUR_API_KEY_HERE'
|
||||
|
||||
local function is_base_64(string)
|
||||
if type(string) == "string" and string ~= "" then
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local ip_hub_api = {}
|
||||
|
||||
local email = core.settings:get("block_vps_email") or "YOUR_EMAIL@example.com"
|
||||
local email = block_vps.get_setting("block_vps_email") or "YOUR_EMAIL@example.com"
|
||||
|
||||
function ip_hub_api:generate_request(ip)
|
||||
return { url = "http://legacy.iphub.info/api.php?showtype=4&ip=" .. ip .. "&email=" ..email }
|
||||
|
|
Loading…
Reference in New Issue