checker.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. -- Default proxy and vpn checker websites
  2. -- The best checker should be the first registered!
  3. -- Iphub.info
  4. local iphub_key = minetest.settings:get("iphub_key")
  5. if iphub_key then
  6. local check = {}
  7. function check.getreq(ip)
  8. local req = {
  9. ["url"] = "http://v2.api.iphub.info/ip/"..ip,
  10. ["extra_headers"] = {"X-Key: "..iphub_key}
  11. }
  12. local callback = function(result)
  13. if result.code == 429 then -- Iphub request limit reached!
  14. check.active = false
  15. return nil, "IPhub Limit reached!"
  16. end
  17. local data = minetest.parse_json(result.data)
  18. if result.completed and result.succeeded and data and data.block then -- Correct request
  19. if data.block == 1 then
  20. return false
  21. else return true
  22. end
  23. else return nil, "Incorrect iphub request!"
  24. end
  25. end
  26. return req, callback
  27. end
  28. vps_blocker.register_checker(check)
  29. end
  30. -- Getipintel.net
  31. local contact = minetest.settings:get("getipintel_contact")
  32. if contact then
  33. local check = {}
  34. function check.getreq(ip)
  35. local req = {
  36. ["url"] = "https://check.getipintel.net/check.php?contact="..contact.."&ip="..ip
  37. }
  38. local callback = function(result)
  39. if result.code == 429 then -- Iphub request limit reached!
  40. check.active = false
  41. return nil, "Getipintel Limit reached!"
  42. end
  43. local data = tonumber(result.data)
  44. if result.completed and result.succeeded and result.code == 200 and data then -- Correct request
  45. if data > 0.99 then
  46. return false
  47. else return true
  48. end
  49. else return nil, "Incorrect getipintel request!"
  50. end
  51. end
  52. return req, callback
  53. end
  54. vps_blocker.register_checker(check)
  55. end
  56. -- Proxycheck.io
  57. do
  58. local proxycheck_key = minetest.settings:get("proxycheck_key")
  59. local check = {}
  60. function check.getreq(ip)
  61. local req = {
  62. ["url"] = "http://proxycheck.io/v2/"..ip.."?vpn=1"
  63. }
  64. if proxycheck_key then
  65. req.url = req.url.."&key="..proxycheck_key
  66. end
  67. local callback = function(result)
  68. local data = minetest.parse_json(result.data)
  69. if result.completed and result.succeeded and data then -- Correct request
  70. if data.status == "ok" or data.status == "warning" and data[ip] and data[ip].proxy then
  71. if data[ip].proxy == "yes" then
  72. return false
  73. else return true
  74. end
  75. elseif data.status == "denied" and string.find(data.message, "exhausted") then
  76. check.active = false
  77. return nil, "Proxycheck Limit reached!"
  78. else return nil, (data.status or "error") .. ": "..(data.message or "Bad request-result!")
  79. end
  80. else return nil, "Incorrect iphub request!"
  81. end
  82. end
  83. return req, callback
  84. end
  85. vps_blocker.register_checker(check)
  86. end