comparison mod_onions/mod_onions.lua @ 1780:b3e3ad35391a

mod_onions: Small fixes making bounce_sendq match mod_s2s again.
author Thijs Alkemade <me@thijsalkema.de>
date Thu, 13 Aug 2015 18:20:33 +0200
parents e0d8caffa209
children 12ac88940fe3
comparison
equal deleted inserted replaced
1779:bdf1de953fd9 1780:b3e3ad35391a
1 local prosody = prosody;
2 local core_process_stanza = prosody.core_process_stanza;
3
1 local wrapclient = require "net.server".wrapclient; 4 local wrapclient = require "net.server".wrapclient;
2 local s2s_new_outgoing = require "core.s2smanager".new_outgoing; 5 local s2s_new_outgoing = require "core.s2smanager".new_outgoing;
3 local initialize_filters = require "util.filters".initialize; 6 local initialize_filters = require "util.filters".initialize;
4 local st = require "util.stanza"; 7 local st = require "util.stanza";
5 8
195 socks5listener.register_outgoing(conn, host_session); 198 socks5listener.register_outgoing(conn, host_session);
196 199
197 host_session.conn = conn; 200 host_session.conn = conn;
198 end 201 end
199 202
203 local bouncy_stanzas = { message = true, presence = true, iq = true };
200 local function bounce_sendq(session, reason) 204 local function bounce_sendq(session, reason)
201 local sendq = session.sendq; 205 local sendq = session.sendq;
202 if not sendq then return; end 206 if not sendq then return; end
203 session.log("info", "sending error replies for "..#sendq.." queued stanzas because of failed outgoing connection to "..tostring(session.to_host)); 207 session.log("info", "Sending error replies for "..#sendq.." queued stanzas because of failed outgoing connection to "..tostring(session.to_host));
204 local dummy = { 208 local dummy = {
205 type = "s2sin"; 209 type = "s2sin";
206 send = function(s) 210 send = function(s)
207 (session.log or log)("error", "Replying to to an s2s error reply, please report this! Traceback: %s", traceback()); 211 (session.log or log)("error", "Replying to to an s2s error reply, please report this! Traceback: %s", traceback());
208 end; 212 end;
209 dummy = true; 213 dummy = true;
210 }; 214 };
211 for i, data in ipairs(sendq) do 215 for i, data in ipairs(sendq) do
212 local reply = data[2]; 216 local reply = data[2];
213 if reply and not(reply.attr.xmlns) then 217 if reply and not(reply.attr.xmlns) and bouncy_stanzas[reply.name] then
214 reply.attr.type = "error"; 218 reply.attr.type = "error";
215 reply:tag("error", {type = "cancel"}) 219 reply:tag("error", {type = "cancel"})
216 :tag("remote-server-not-found", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}):up(); 220 :tag("remote-server-not-found", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}):up();
217 if reason then 221 if reason then
218 reply:tag("text", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}) 222 reply:tag("text", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"})
219 :text("Server-to-server connection failed: "..reason):up(); 223 :text("Server-to-server connection failed: "..reason):up();
220 end 224 end
221 core_process_stanza(dummy, reply); 225 core_process_stanza(dummy, reply);
222 end 226 end
223 sendq[i] = nil; 227 sendq[i] = nil;
224 end 228 end
225 session.sendq = nil; 229 session.sendq = nil;
226 end 230 end
227
228 -- Try to intercept anything to *.onion 231 -- Try to intercept anything to *.onion
229 local function route_to_onion(event) 232 local function route_to_onion(event)
230 local stanza = event.stanza; 233 local stanza = event.stanza;
231 234
232 if not event.to_host:find(".onion(.?)$") then 235 if not event.to_host:find(".onion(.?)$") then
233 if forbid_else then 236 if forbid_else then
234 module:log("debug", event.to_host .. " is not an onion. Blocking it."); 237 module:log("debug", event.to_host .. " is not an onion. Blocking it.");
235 return false; 238 return false;
236 elseif not torify_all then 239 elseif not torify_all then
237 return; 240 return;
238 end 241 end
239 end 242 end