Mercurial > prosody-hg
comparison plugins/mod_proxy65.lua @ 6054:7a5ddbaf758d
Merge 0.9->0.10
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 02 Apr 2014 17:41:38 +0100 |
| parents | f8c17af769d9 |
| children | e6968e47826d |
comparison
equal
deleted
inserted
replaced
| 6053:2f93a04564b2 | 6054:7a5ddbaf758d |
|---|---|
| 1 -- Prosody IM | 1 -- Prosody IM |
| 2 -- Copyright (C) 2008-2011 Matthew Wild | 2 -- Copyright (C) 2008-2011 Matthew Wild |
| 3 -- Copyright (C) 2008-2011 Waqas Hussain | 3 -- Copyright (C) 2008-2011 Waqas Hussain |
| 4 -- Copyright (C) 2009 Thilo Cestonaro | 4 -- Copyright (C) 2009 Thilo Cestonaro |
| 5 -- | 5 -- |
| 6 -- This project is MIT/X11 licensed. Please see the | 6 -- This project is MIT/X11 licensed. Please see the |
| 7 -- COPYING file in the source package for more information. | 7 -- COPYING file in the source package for more information. |
| 8 -- | 8 -- |
| 9 | 9 |
| 10 module:set_global(); | 10 module:set_global(); |
| 28 if transfer and transfer.activated then -- copy data between initiator and target | 28 if transfer and transfer.activated then -- copy data between initiator and target |
| 29 local initiator, target = transfer.initiator, transfer.target; | 29 local initiator, target = transfer.initiator, transfer.target; |
| 30 (conn == initiator and target or initiator):write(data); | 30 (conn == initiator and target or initiator):write(data); |
| 31 return; | 31 return; |
| 32 end -- FIXME server.link should be doing this? | 32 end -- FIXME server.link should be doing this? |
| 33 | 33 |
| 34 if not session.greeting_done then | 34 if not session.greeting_done then |
| 35 local nmethods = data:byte(2) or 0; | 35 local nmethods = data:byte(2) or 0; |
| 36 if data:byte(1) == 0x05 and nmethods > 0 and #data == 2 + nmethods then -- check if we have all the data | 36 if data:byte(1) == 0x05 and nmethods > 0 and #data == 2 + nmethods then -- check if we have all the data |
| 37 if data:find("%z") then -- 0x00 = 'No authentication' is supported | 37 if data:find("%z") then -- 0x00 = 'No authentication' is supported |
| 38 session.greeting_done = true; | 38 session.greeting_done = true; |
| 88 end | 88 end |
| 89 end | 89 end |
| 90 | 90 |
| 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("proxy65_address", host); | 94 local proxy_address = module:get_option("proxy65_address", host); |
| 95 local proxy_port = next(portmanager.get_active_services():search("proxy65", nil)[1] or {}); | 95 local proxy_port = next(portmanager.get_active_services():search("proxy65", nil)[1] or {}); |
| 96 local proxy_acl = module:get_option("proxy65_acl"); | 96 local proxy_acl = module:get_option("proxy65_acl"); |
| 97 | 97 |
| 98 -- 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 |
| 99 local legacy_config = module:get_option_number("proxy65_port"); | 99 local legacy_config = module:get_option_number("proxy65_port"); |
| 100 if legacy_config then | 100 if legacy_config then |
| 101 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); |
| 102 end | 102 end |
| 103 | 103 |
| 104 module:depends("disco"); | |
| 104 module:add_identity("proxy", "bytestreams", name); | 105 module:add_identity("proxy", "bytestreams", name); |
| 105 module:add_feature("http://jabber.org/protocol/bytestreams"); | 106 module:add_feature("http://jabber.org/protocol/bytestreams"); |
| 106 | 107 |
| 107 module:hook("iq-get/host/http://jabber.org/protocol/disco#info:query", function(event) | |
| 108 local origin, stanza = event.origin, event.stanza; | |
| 109 if not stanza.tags[1].attr.node then | |
| 110 origin.send(st.reply(stanza):query("http://jabber.org/protocol/disco#info") | |
| 111 :tag("identity", {category='proxy', type='bytestreams', name=name}):up() | |
| 112 :tag("feature", {var="http://jabber.org/protocol/bytestreams"}) ); | |
| 113 return true; | |
| 114 end | |
| 115 end, -1); | |
| 116 | |
| 117 module:hook("iq-get/host/http://jabber.org/protocol/disco#items:query", function(event) | |
| 118 local origin, stanza = event.origin, event.stanza; | |
| 119 if not stanza.tags[1].attr.node then | |
| 120 origin.send(st.reply(stanza):query("http://jabber.org/protocol/disco#items")); | |
| 121 return true; | |
| 122 end | |
| 123 end, -1); | |
| 124 | |
| 125 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) |
| 126 local origin, stanza = event.origin, event.stanza; | 109 local origin, stanza = event.origin, event.stanza; |
| 127 | 110 |
| 128 -- check ACL | 111 -- check ACL |
| 129 while proxy_acl and #proxy_acl > 0 do -- using 'while' instead of 'if' so we can break out of it | 112 while proxy_acl and #proxy_acl > 0 do -- using 'while' instead of 'if' so we can break out of it |
| 130 local jid = stanza.attr.from; | 113 local jid = stanza.attr.from; |
| 131 local allow; | 114 local allow; |
| 132 for _, acl in ipairs(proxy_acl) do | 115 for _, acl in ipairs(proxy_acl) do |
| 135 if allow then break; end | 118 if allow then break; end |
| 136 module:log("warn", "Denying use of proxy for %s", tostring(stanza.attr.from)); | 119 module:log("warn", "Denying use of proxy for %s", tostring(stanza.attr.from)); |
| 137 origin.send(st.error_reply(stanza, "auth", "forbidden")); | 120 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
| 138 return true; | 121 return true; |
| 139 end | 122 end |
| 140 | 123 |
| 141 local sid = stanza.tags[1].attr.sid; | 124 local sid = stanza.tags[1].attr.sid; |
| 142 origin.send(st.reply(stanza):tag("query", {xmlns="http://jabber.org/protocol/bytestreams", sid=sid}) | 125 origin.send(st.reply(stanza):tag("query", {xmlns="http://jabber.org/protocol/bytestreams", sid=sid}) |
| 143 :tag("streamhost", {jid=host, host=proxy_address, port=proxy_port})); | 126 :tag("streamhost", {jid=host, host=proxy_address, port=proxy_port})); |
| 144 return true; | 127 return true; |
| 145 end); | 128 end); |
| 146 | 129 |
| 147 module:hook("iq-set/host/http://jabber.org/protocol/bytestreams:query", function(event) | 130 module:hook("iq-set/host/http://jabber.org/protocol/bytestreams:query", function(event) |
| 148 local origin, stanza = event.origin, event.stanza; | 131 local origin, stanza = event.origin, event.stanza; |
| 149 | 132 |
| 150 local query = stanza.tags[1]; | 133 local query = stanza.tags[1]; |
| 151 local sid = query.attr.sid; | 134 local sid = query.attr.sid; |
| 152 local from = stanza.attr.from; | 135 local from = stanza.attr.from; |
| 153 local to = query:get_child_text("activate"); | 136 local to = query:get_child_text("activate"); |
| 154 local prepped_to = jid_prep(to); | 137 local prepped_to = jid_prep(to); |
| 155 | 138 |
| 156 local info = "sid: "..tostring(sid)..", initiator: "..tostring(from)..", target: "..tostring(prepped_to or to); | 139 local info = "sid: "..tostring(sid)..", initiator: "..tostring(from)..", target: "..tostring(prepped_to or to); |
| 157 if prepped_to and sid then | 140 if prepped_to and sid then |
| 158 local sha = sha1(sid .. from .. prepped_to, true); | 141 local sha = sha1(sid .. from .. prepped_to, true); |
| 159 if not transfers[sha] then | 142 if not transfers[sha] then |
| 160 module:log("debug", "Activation request has unknown session id; activation failed (%s)", info); | 143 module:log("debug", "Activation request has unknown session id; activation failed (%s)", info); |
