# HG changeset patch # User Marco Cirillo # Date 1326570984 0 # Node ID d8143f627f9f2fd22da0352bf4bbe268ddd5bfe7 # Parent fc5df35a3fe4da09ee649252bdd1c78943318711 mod_register_json: modified code to employ get_option_set for true sets, and contains meta method diff -r fc5df35a3fe4 -r d8143f627f9f mod_register_json/mod_register_json.lua --- a/mod_register_json/mod_register_json.lua Sat Jan 14 20:50:24 2012 +0100 +++ b/mod_register_json/mod_register_json.lua Sat Jan 14 19:56:24 2012 +0000 @@ -19,8 +19,8 @@ local set_realm_name = module:get_option("reg_servlet_realm") or "Restricted" local throttle_time = module:get_option("reg_servlet_ttime") or false -local whitelist = module:get_option("reg_servlet_wl") or {} -local blacklist = module:get_option("reg_servlet_bl") or {} +local whitelist = module:get_option_set("reg_servlet_wl", {}) +local blacklist = module:get_option_set("reg_servlet_bl", {}) local recent_ips = {} -- Begin @@ -71,8 +71,8 @@ return http_response(401, "I obey only to my masters... Have a nice day.") else -- Checks for both Throttling/Whitelist and Blacklist (basically copycatted from prosody's register.lua code) - if blacklist[req_body["ip"]] then module:log("warn", "Attempt of reg. submission to the JSON servlet from blacklisted address: %s", req_body["ip"]) ; return http_response(403, "The specified address is blacklisted, sorry sorry.") end - if throttle_time and not whitelist[req_body["ip"]] then + if blacklist:contains(req_body["ip"]) then module:log("warn", "Attempt of reg. submission to the JSON servlet from blacklisted address: %s", req_body["ip"]) ; return http_response(403, "The specified address is blacklisted, sorry sorry.") end + if throttle_time and not whitelist:contains(req_body["ip"]) then if not recent_ips[req_body["ip"]] then recent_ips[req_body["ip"]] = { time = os_time(), count = 1 } else