tools/ejabberd2prosody: Disable generating a config, as the format it generates is...
[prosody.git] / plugins / mod_proxy65.lua
index 896780fbe081ca2db875db994e3a90acfb866101..1fa42bd86b88e299eddde68c12f4a364a17227a5 100644 (file)
@@ -14,6 +14,7 @@ local st = require "util.stanza";
 local sha1 = require "util.hashes".sha1;
 local b64 = require "util.encodings".base64.encode;
 local server = require "net.server";
+local portmanager = require "core.portmanager";
 
 local sessions, transfers = module:shared("sessions", "transfers");
 local max_buffer_size = 4096;
@@ -94,7 +95,7 @@ function module.add_host(module)
        local proxy_port = next(portmanager.get_active_services():search("proxy65", nil)[1] or {});
        local proxy_acl = module:get_option("proxy65_acl");
 
-       -- COMPAT w/pre-0.9 where proxy65_port was specified the components section of the config
+       -- COMPAT w/pre-0.9 where proxy65_port was specified in the components section of the config
        local legacy_config = module:get_option_number("proxy65_port");
        if legacy_config then
                module:log("warn", "proxy65_port is deprecated, please put proxy65_ports = { %d } into the global section instead", legacy_config);
@@ -105,16 +106,20 @@ function module.add_host(module)
        
        module:hook("iq-get/host/http://jabber.org/protocol/disco#info:query", function(event)
                local origin, stanza = event.origin, event.stanza;
-               origin.send(st.reply(stanza):query("http://jabber.org/protocol/disco#info")
-                       :tag("identity", {category='proxy', type='bytestreams', name=name}):up()
-                       :tag("feature", {var="http://jabber.org/protocol/bytestreams"}) );
-               return true;
+               if not stanza.tags[1].attr.node then
+                       origin.send(st.reply(stanza):query("http://jabber.org/protocol/disco#info")
+                               :tag("identity", {category='proxy', type='bytestreams', name=name}):up()
+                               :tag("feature", {var="http://jabber.org/protocol/bytestreams"}) );
+                       return true;
+               end
        end, -1);
        
        module:hook("iq-get/host/http://jabber.org/protocol/disco#items:query", function(event)
                local origin, stanza = event.origin, event.stanza;
-               origin.send(st.reply(stanza):query("http://jabber.org/protocol/disco#items"));
-               return true;
+               if not stanza.tags[1].attr.node then
+                       origin.send(st.reply(stanza):query("http://jabber.org/protocol/disco#items"));
+                       return true;
+               end
        end, -1);
        
        module:hook("iq-get/host/http://jabber.org/protocol/bytestreams:query", function(event)
@@ -123,9 +128,11 @@ function module.add_host(module)
                -- check ACL
                while proxy_acl and #proxy_acl > 0 do -- using 'while' instead of 'if' so we can break out of it
                        local jid = stanza.attr.from;
+                       local allow;
                        for _, acl in ipairs(proxy_acl) do
-                               if jid_compare(jid, acl) then break; end
+                               if jid_compare(jid, acl) then allow = true; break; end
                        end
+                       if allow then break; end
                        module:log("warn", "Denying use of proxy for %s", tostring(stanza.attr.from));
                        origin.send(st.error_reply(stanza, "auth", "forbidden"));
                        return true;