Comparison

mod_register_json/mod_register_json.lua @ 597:1004d7176be2

mod_register_json: cleanup unused stuff
author Marco Cirillo <maranda@lightwitch.org>
date Thu, 09 Feb 2012 00:24:31 +0000
parent 566:39a612eb4431
child 598:36b3ecebdc7e
comparison
equal deleted inserted replaced
584:1c2fc3b845f2 597:1004d7176be2
73 else 73 else
74 -- Checks for both Throttling/Whitelist and Blacklist (basically copycatted from prosody's register.lua code) 74 -- Checks for both Throttling/Whitelist and Blacklist (basically copycatted from prosody's register.lua code)
75 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 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
76 if throttle_time and not whitelist:contains(req_body["ip"]) then 76 if throttle_time and not whitelist:contains(req_body["ip"]) then
77 if not recent_ips[req_body["ip"]] then 77 if not recent_ips[req_body["ip"]] then
78 recent_ips[req_body["ip"]] = { time = os_time(), count = 1 } 78 recent_ips[req_body["ip"]] = os_time()
79 else 79 else
80 local ip = recent_ips[req_body["ip"]] 80 if os_time() - recent_ips[req_body["ip"]] < throttle_time then
81 ip.count = ip.count + 1 81 recent_ips[req_body["ip"]] = os_time()
82
83 if os_time() - ip.time < throttle_time then
84 ip.time = os_time()
85 module:log("warn", "JSON Registration request from %s has been throttled.", req_body["ip"]) 82 module:log("warn", "JSON Registration request from %s has been throttled.", req_body["ip"])
86 return http_response(503, "Woah... How many users you want to register..? Request throttled, wait a bit and try again.") 83 return http_response(503, "Woah... How many users you want to register..? Request throttled, wait a bit and try again.")
87 end 84 end
88 ip.time = os_time() 85 recent_ips[req_body["ip"]] = os_time()
89 end 86 end
90 end 87 end
91 88
92 -- We first check if the supplied username for registration is already there. 89 -- We first check if the supplied username for registration is already there.
93 -- And nodeprep the username 90 -- And nodeprep the username