comparison mod_register_json/mod_register_json.lua @ 550:d8143f627f9f

mod_register_json: modified code to employ get_option_set for true sets, and contains meta method
author Marco Cirillo <maranda@lightwitch.org>
date Sat, 14 Jan 2012 19:56:24 +0000
parents 4691e72a055c
children 859bf77b9fbf
comparison
equal deleted inserted replaced
549:fc5df35a3fe4 550:d8143f627f9f
17 17
18 -- Pick up configuration. 18 -- Pick up configuration.
19 19
20 local set_realm_name = module:get_option("reg_servlet_realm") or "Restricted" 20 local set_realm_name = module:get_option("reg_servlet_realm") or "Restricted"
21 local throttle_time = module:get_option("reg_servlet_ttime") or false 21 local throttle_time = module:get_option("reg_servlet_ttime") or false
22 local whitelist = module:get_option("reg_servlet_wl") or {} 22 local whitelist = module:get_option_set("reg_servlet_wl", {})
23 local blacklist = module:get_option("reg_servlet_bl") or {} 23 local blacklist = module:get_option_set("reg_servlet_bl", {})
24 local recent_ips = {} 24 local recent_ips = {}
25 25
26 -- Begin 26 -- Begin
27 27
28 local function http_response(code, message, extra_headers) 28 local function http_response(code, message, extra_headers)
69 if not usermanager.is_admin(user, req_body["host"]) then 69 if not usermanager.is_admin(user, req_body["host"]) then
70 module:log("warn", "%s tried to submit registration data for %s but he's not an admin", user, req_body["host"]) 70 module:log("warn", "%s tried to submit registration data for %s but he's not an admin", user, req_body["host"])
71 return http_response(401, "I obey only to my masters... Have a nice day.") 71 return http_response(401, "I obey only to my masters... Have a nice day.")
72 else 72 else
73 -- Checks for both Throttling/Whitelist and Blacklist (basically copycatted from prosody's register.lua code) 73 -- Checks for both Throttling/Whitelist and Blacklist (basically copycatted from prosody's register.lua code)
74 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 74 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
75 if throttle_time and not whitelist[req_body["ip"]] then 75 if throttle_time and not whitelist:contains(req_body["ip"]) then
76 if not recent_ips[req_body["ip"]] then 76 if not recent_ips[req_body["ip"]] then
77 recent_ips[req_body["ip"]] = { time = os_time(), count = 1 } 77 recent_ips[req_body["ip"]] = { time = os_time(), count = 1 }
78 else 78 else
79 local ip = recent_ips[req_body["ip"]] 79 local ip = recent_ips[req_body["ip"]]
80 ip.count = ip.count + 1 80 ip.count = ip.count + 1