Software / code / prosody
Comparison
plugins/mod_register.lua @ 691:406b070b5d3e
Add option to in-band registration to allow only whitelisted IPs to register
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 11 Jan 2009 07:15:42 +0000 |
| parent | 690:e901a0709005 |
| child | 758:b1885732e979 |
comparison
equal
deleted
inserted
replaced
| 690:e901a0709005 | 691:406b070b5d3e |
|---|---|
| 94 end; | 94 end; |
| 95 end); | 95 end); |
| 96 | 96 |
| 97 local recent_ips = {}; | 97 local recent_ips = {}; |
| 98 local min_seconds_between_registrations = config.get(module.host, "core", "min_seconds_between_registrations"); | 98 local min_seconds_between_registrations = config.get(module.host, "core", "min_seconds_between_registrations"); |
| 99 local whitelist_only = config.get(module.host, "core", "whitelist_registration_only"); | |
| 99 local whitelisted_ips = config.get(module.host, "core", "registration_whitelist") or { "127.0.0.1" }; | 100 local whitelisted_ips = config.get(module.host, "core", "registration_whitelist") or { "127.0.0.1" }; |
| 100 local blacklisted_ips = config.get(module.host, "core", "registration_blacklist") or {}; | 101 local blacklisted_ips = config.get(module.host, "core", "registration_blacklist") or {}; |
| 101 | 102 |
| 102 for _, ip in ipairs(whitelisted_ips) do whitelisted_ips[ip] = true; end | 103 for _, ip in ipairs(whitelisted_ips) do whitelisted_ips[ip] = true; end |
| 103 for _, ip in ipairs(blacklisted_ips) do blacklisted_ips[ip] = true; end | 104 for _, ip in ipairs(blacklisted_ips) do blacklisted_ips[ip] = true; end |
| 120 else | 121 else |
| 121 local username = query:child_with_name("username"); | 122 local username = query:child_with_name("username"); |
| 122 local password = query:child_with_name("password"); | 123 local password = query:child_with_name("password"); |
| 123 if username and password then | 124 if username and password then |
| 124 -- Check that the user is not blacklisted or registering too often | 125 -- Check that the user is not blacklisted or registering too often |
| 125 if blacklisted_ips[session.ip] then | 126 if blacklisted_ips[session.ip] or (whitelist_only and not whitelisted_ips[session.ip]) then |
| 126 session.send(st.error_reply(stanza, "cancel", "not-acceptable")); | 127 session.send(st.error_reply(stanza, "cancel", "not-acceptable")); |
| 127 return; | 128 return; |
| 128 elseif min_seconds_between_registrations and not whitelisted_ips[session.ip] then | 129 elseif min_seconds_between_registrations and not whitelisted_ips[session.ip] then |
| 129 if not recent_ips[session.ip] then | 130 if not recent_ips[session.ip] then |
| 130 recent_ips[session.ip] = { time = os_time(), count = 1 }; | 131 recent_ips[session.ip] = { time = os_time(), count = 1 }; |