Mercurial > prosody-modules
comparison mod_component_guard/mod_component_guard.lua @ 460:9bb9343f3c7a
mod_component_guard: made module global, refactored init.
| author | Marco Cirillo <maranda@lightwitch.org> |
|---|---|
| date | Mon, 24 Oct 2011 00:20:51 +0000 |
| parents | 3117d7e207c5 |
| children |
comparison
equal
deleted
inserted
replaced
| 459:3117d7e207c5 | 460:9bb9343f3c7a |
|---|---|
| 1 -- Block or restrict by blacklist remote access to local components. | 1 -- Block or restrict by blacklist remote access to local components. |
| 2 | |
| 3 module:set_global() | |
| 2 | 4 |
| 3 local guard_blockall = module:get_option_set("component_guard_blockall", {}) | 5 local guard_blockall = module:get_option_set("component_guard_blockall", {}) |
| 4 local guard_protect = module:get_option_set("component_guard_components", {}) | 6 local guard_protect = module:get_option_set("component_guard_components", {}) |
| 5 local guard_block_bl = module:get_option_set("component_guard_blacklist", {}) | 7 local guard_block_bl = module:get_option_set("component_guard_blacklist", {}) |
| 6 | 8 |
| 79 guard_protect = module:get_option_set("component_guard_components"); | 81 guard_protect = module:get_option_set("component_guard_components"); |
| 80 guard_block_bl = module:get_option_set("component_guard_blacklist"); | 82 guard_block_bl = module:get_option_set("component_guard_blacklist"); |
| 81 end | 83 end |
| 82 | 84 |
| 83 local function setup() | 85 local function setup() |
| 84 module:log ("debug", "initializing component guard module..."); | 86 module:log ("debug", "initializing component guard module..."); |
| 85 | 87 |
| 86 prosody.events.remove_handler("component-activated", handle_activation); | 88 module:hook ("component-activated", handle_activation); |
| 87 prosody.events.add_handler("component-activated", handle_activation); | 89 module:hook ("component-deactivated", handle_deactivation); |
| 88 prosody.events.remove_handler("component-deactivated", handle_deactivation); | 90 module:hook ("config-reloaded", reload); |
| 89 prosody.events.add_handler("component-deactivated", handle_deactivation); | |
| 90 prosody.events.remove_handler("config-reloaded", reload); | |
| 91 prosody.events.add_handler("config-reloaded", reload); | |
| 92 | 91 |
| 93 for n,table in pairs(hosts) do | 92 for n,table in pairs(hosts) do |
| 94 if table.type == "component" then | 93 if table.type == "component" then |
| 95 if guard_blockall:contains(n) or guard_protect:contains(n) then | 94 if guard_blockall:contains(n) or guard_protect:contains(n) then |
| 96 hosts[n].events.remove_handler("stanza/jabber:server:dialback:result", sdr_hook); | 95 hosts[n].events.remove_handler("stanza/jabber:server:dialback:result", sdr_hook); |
| 97 handle_activation(n); | 96 handle_activation(n); |
| 98 end | 97 end |
| 99 end | 98 end |
| 100 end | 99 end |
| 101 end | 100 end |
| 102 | 101 |
| 103 if prosody.start_time then | 102 if prosody.start_time then |
| 104 setup(); | 103 setup(); |
| 105 else | 104 else |
