Mercurial > prosody-hg
comparison plugins/mod_proxy65.lua @ 5776:bd0ff8ae98a8
Remove all trailing whitespace
| author | Florian Zeitz <florob@babelmonkeys.de> |
|---|---|
| date | Fri, 09 Aug 2013 17:48:21 +0200 |
| parents | b31ab26f9997 |
| children | f8c17af769d9 |
comparison
equal
deleted
inserted
replaced
| 5775:a6c2b8933507 | 5776:bd0ff8ae98a8 |
|---|---|
| 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 |
| 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:add_identity("proxy", "bytestreams", name); | 104 module:add_identity("proxy", "bytestreams", name); |
| 105 module:add_feature("http://jabber.org/protocol/bytestreams"); | 105 module:add_feature("http://jabber.org/protocol/bytestreams"); |
| 106 | 106 |
| 107 module:hook("iq-get/host/http://jabber.org/protocol/disco#info:query", function(event) | 107 module:hook("iq-get/host/http://jabber.org/protocol/disco#info:query", function(event) |
| 108 local origin, stanza = event.origin, event.stanza; | 108 local origin, stanza = event.origin, event.stanza; |
| 109 if not stanza.tags[1].attr.node then | 109 if not stanza.tags[1].attr.node then |
| 110 origin.send(st.reply(stanza):query("http://jabber.org/protocol/disco#info") | 110 origin.send(st.reply(stanza):query("http://jabber.org/protocol/disco#info") |
| 111 :tag("identity", {category='proxy', type='bytestreams', name=name}):up() | 111 :tag("identity", {category='proxy', type='bytestreams', name=name}):up() |
| 112 :tag("feature", {var="http://jabber.org/protocol/bytestreams"}) ); | 112 :tag("feature", {var="http://jabber.org/protocol/bytestreams"}) ); |
| 113 return true; | 113 return true; |
| 114 end | 114 end |
| 115 end, -1); | 115 end, -1); |
| 116 | 116 |
| 117 module:hook("iq-get/host/http://jabber.org/protocol/disco#items:query", function(event) | 117 module:hook("iq-get/host/http://jabber.org/protocol/disco#items:query", function(event) |
| 118 local origin, stanza = event.origin, event.stanza; | 118 local origin, stanza = event.origin, event.stanza; |
| 119 if not stanza.tags[1].attr.node then | 119 if not stanza.tags[1].attr.node then |
| 120 origin.send(st.reply(stanza):query("http://jabber.org/protocol/disco#items")); | 120 origin.send(st.reply(stanza):query("http://jabber.org/protocol/disco#items")); |
| 121 return true; | 121 return true; |
| 122 end | 122 end |
| 123 end, -1); | 123 end, -1); |
| 124 | 124 |
| 125 module:hook("iq-get/host/http://jabber.org/protocol/bytestreams:query", function(event) | 125 module:hook("iq-get/host/http://jabber.org/protocol/bytestreams:query", function(event) |
| 126 local origin, stanza = event.origin, event.stanza; | 126 local origin, stanza = event.origin, event.stanza; |
| 127 | 127 |
| 128 -- check ACL | 128 -- check ACL |
| 129 while proxy_acl and #proxy_acl > 0 do -- using 'while' instead of 'if' so we can break out of it | 129 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; | 130 local jid = stanza.attr.from; |
| 131 local allow; | 131 local allow; |
| 132 for _, acl in ipairs(proxy_acl) do | 132 for _, acl in ipairs(proxy_acl) do |
| 135 if allow then break; end | 135 if allow then break; end |
| 136 module:log("warn", "Denying use of proxy for %s", tostring(stanza.attr.from)); | 136 module:log("warn", "Denying use of proxy for %s", tostring(stanza.attr.from)); |
| 137 origin.send(st.error_reply(stanza, "auth", "forbidden")); | 137 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
| 138 return true; | 138 return true; |
| 139 end | 139 end |
| 140 | 140 |
| 141 local sid = stanza.tags[1].attr.sid; | 141 local sid = stanza.tags[1].attr.sid; |
| 142 origin.send(st.reply(stanza):tag("query", {xmlns="http://jabber.org/protocol/bytestreams", sid=sid}) | 142 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})); | 143 :tag("streamhost", {jid=host, host=proxy_address, port=proxy_port})); |
| 144 return true; | 144 return true; |
| 145 end); | 145 end); |
| 146 | 146 |
| 147 module:hook("iq-set/host/http://jabber.org/protocol/bytestreams:query", function(event) | 147 module:hook("iq-set/host/http://jabber.org/protocol/bytestreams:query", function(event) |
| 148 local origin, stanza = event.origin, event.stanza; | 148 local origin, stanza = event.origin, event.stanza; |
| 149 | 149 |
| 150 local query = stanza.tags[1]; | 150 local query = stanza.tags[1]; |
| 151 local sid = query.attr.sid; | 151 local sid = query.attr.sid; |
| 152 local from = stanza.attr.from; | 152 local from = stanza.attr.from; |
| 153 local to = query:get_child_text("activate"); | 153 local to = query:get_child_text("activate"); |
| 154 local prepped_to = jid_prep(to); | 154 local prepped_to = jid_prep(to); |
| 155 | 155 |
| 156 local info = "sid: "..tostring(sid)..", initiator: "..tostring(from)..", target: "..tostring(prepped_to or to); | 156 local info = "sid: "..tostring(sid)..", initiator: "..tostring(from)..", target: "..tostring(prepped_to or to); |
| 157 if prepped_to and sid then | 157 if prepped_to and sid then |
| 158 local sha = sha1(sid .. from .. prepped_to, true); | 158 local sha = sha1(sid .. from .. prepped_to, true); |
| 159 if not transfers[sha] then | 159 if not transfers[sha] then |
| 160 module:log("debug", "Activation request has unknown session id; activation failed (%s)", info); | 160 module:log("debug", "Activation request has unknown session id; activation failed (%s)", info); |
