Mercurial > prosody-hg
comparison plugins/mod_proxy65.lua @ 11560:3bbb1af92514
Merge 0.11->trunk
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 13 May 2021 11:17:13 +0100 |
| parents | 027af78d8125 65dcc175ef5b |
| children | 74b9e05af71e f34ad235cf3b |
comparison
equal
deleted
inserted
replaced
| 11538:30feeb4d9d0b | 11560:3bbb1af92514 |
|---|---|
| 91 function module.add_host(module) | 91 function module.add_host(module) |
| 92 local host, name = module:get_host(), module:get_option_string("name", "SOCKS5 Bytestreams Service"); | 92 local host, name = module:get_host(), module:get_option_string("name", "SOCKS5 Bytestreams Service"); |
| 93 | 93 |
| 94 local proxy_address = module:get_option_string("proxy65_address", host); | 94 local proxy_address = module:get_option_string("proxy65_address", host); |
| 95 local proxy_acl = module:get_option_array("proxy65_acl"); | 95 local proxy_acl = module:get_option_array("proxy65_acl"); |
| 96 local proxy_open_access = module:get_option_boolean("proxy65_open_access", false); | |
| 96 | 97 |
| 97 -- COMPAT w/pre-0.9 where proxy65_port was specified in the components section of the config | 98 -- COMPAT w/pre-0.9 where proxy65_port was specified in the components section of the config |
| 98 local legacy_config = module:get_option_number("proxy65_port"); | 99 local legacy_config = module:get_option_number("proxy65_port"); |
| 99 if legacy_config then | 100 if legacy_config then |
| 100 module:log("warn", "proxy65_port is deprecated, please put proxy65_ports = { %d } into the global section instead", legacy_config); | 101 module:log("warn", "proxy65_port is deprecated, please put proxy65_ports = { %d } into the global section instead", legacy_config); |
| 107 module:hook("iq-get/host/http://jabber.org/protocol/bytestreams:query", function(event) | 108 module:hook("iq-get/host/http://jabber.org/protocol/bytestreams:query", function(event) |
| 108 local origin, stanza = event.origin, event.stanza; | 109 local origin, stanza = event.origin, event.stanza; |
| 109 | 110 |
| 110 -- check ACL | 111 -- check ACL |
| 111 -- using 'while' instead of 'if' so we can break out of it | 112 -- using 'while' instead of 'if' so we can break out of it |
| 112 while proxy_acl and #proxy_acl > 0 do --luacheck: ignore 512 | 113 local allow; |
| 114 if proxy_acl and #proxy_acl > 0 then | |
| 113 local jid = stanza.attr.from; | 115 local jid = stanza.attr.from; |
| 114 local allow; | |
| 115 for _, acl in ipairs(proxy_acl) do | 116 for _, acl in ipairs(proxy_acl) do |
| 116 if jid_compare(jid, acl) then allow = true; break; end | 117 if jid_compare(jid, acl) then |
| 118 allow = true; | |
| 119 break; | |
| 120 end | |
| 117 end | 121 end |
| 118 if allow then break; end | 122 elseif proxy_open_access or origin.type == "c2s" then |
| 123 allow = true; | |
| 124 end | |
| 125 | |
| 126 if not allow then | |
| 119 module:log("warn", "Denying use of proxy for %s", stanza.attr.from); | 127 module:log("warn", "Denying use of proxy for %s", stanza.attr.from); |
| 120 origin.send(st.error_reply(stanza, "auth", "forbidden")); | 128 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
| 121 return true; | 129 return true; |
| 122 end | 130 end |
| 123 | 131 |
