Software / code / prosody
Comparison
plugins/mod_dialback.lua @ 1077:d6a885cacd8c
mod_dialback: Miscellaneous logging improvements, changing levels, improving messages and using session loggers where possible
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 30 Apr 2009 02:45:33 +0100 |
| parent | 1070:3b066968063b |
| child | 1337:16c5aa4696ca |
comparison
equal
deleted
inserted
replaced
| 1076:ba3639692493 | 1077:d6a885cacd8c |
|---|---|
| 22 local dialback_requests = setmetatable({}, { __mode = 'v' }); | 22 local dialback_requests = setmetatable({}, { __mode = 'v' }); |
| 23 | 23 |
| 24 module:add_handler({"s2sin_unauthed", "s2sin"}, "verify", xmlns_dialback, | 24 module:add_handler({"s2sin_unauthed", "s2sin"}, "verify", xmlns_dialback, |
| 25 function (origin, stanza) | 25 function (origin, stanza) |
| 26 -- We are being asked to verify the key, to ensure it was generated by us | 26 -- We are being asked to verify the key, to ensure it was generated by us |
| 27 log("debug", "verifying dialback key..."); | 27 origin.log("debug", "verifying that dialback key is ours..."); |
| 28 local attr = stanza.attr; | 28 local attr = stanza.attr; |
| 29 -- FIXME: Grr, ejabberd breaks this one too?? it is black and white in XEP-220 example 34 | 29 -- FIXME: Grr, ejabberd breaks this one too?? it is black and white in XEP-220 example 34 |
| 30 --if attr.from ~= origin.to_host then error("invalid-from"); end | 30 --if attr.from ~= origin.to_host then error("invalid-from"); end |
| 31 local type; | 31 local type; |
| 32 if s2s_verify_dialback(attr.id, attr.from, attr.to, stanza[1]) then | 32 if s2s_verify_dialback(attr.id, attr.from, attr.to, stanza[1]) then |
| 33 type = "valid" | 33 type = "valid" |
| 34 else | 34 else |
| 35 type = "invalid" | 35 type = "invalid" |
| 36 log("warn", "Asked to verify a dialback key that was incorrect. An imposter is claiming to be %s?", attr.to); | 36 origin.log("warn", "Asked to verify a dialback key that was incorrect. An imposter is claiming to be %s?", attr.to); |
| 37 end | 37 end |
| 38 log("debug", "verified dialback key... it is %s", type); | 38 origin.log("debug", "verified dialback key... it is %s", type); |
| 39 origin.sends2s(st.stanza("db:verify", { from = attr.to, to = attr.from, id = attr.id, type = type }):text(stanza[1])); | 39 origin.sends2s(st.stanza("db:verify", { from = attr.to, to = attr.from, id = attr.id, type = type }):text(stanza[1])); |
| 40 end); | 40 end); |
| 41 | 41 |
| 42 module:add_handler({ "s2sin_unauthed", "s2sin" }, "result", xmlns_dialback, | 42 module:add_handler({ "s2sin_unauthed", "s2sin" }, "result", xmlns_dialback, |
| 43 function (origin, stanza) | 43 function (origin, stanza) |
| 46 local attr = stanza.attr; | 46 local attr = stanza.attr; |
| 47 origin.hosts[attr.from] = { dialback_key = stanza[1] }; | 47 origin.hosts[attr.from] = { dialback_key = stanza[1] }; |
| 48 | 48 |
| 49 if not hosts[attr.to] then | 49 if not hosts[attr.to] then |
| 50 -- Not a host that we serve | 50 -- Not a host that we serve |
| 51 log("info", "%s tried to connect to %s, which we don't serve", attr.from, attr.to); | 51 origin.log("info", "%s tried to connect to %s, which we don't serve", attr.from, attr.to); |
| 52 origin:close("host-unknown"); | 52 origin:close("host-unknown"); |
| 53 return; | 53 return; |
| 54 end | 54 end |
| 55 | 55 |
| 56 dialback_requests[attr.from] = origin; | 56 dialback_requests[attr.from] = origin; |
| 62 if not origin.to_host then | 62 if not origin.to_host then |
| 63 -- Just used for friendlier logging | 63 -- Just used for friendlier logging |
| 64 origin.to_host = attr.to; | 64 origin.to_host = attr.to; |
| 65 end | 65 end |
| 66 | 66 |
| 67 log("debug", "asking %s if key %s belongs to them", attr.from, stanza[1]); | 67 origin.log("debug", "asking %s if key %s belongs to them", attr.from, stanza[1]); |
| 68 send_s2s(attr.to, attr.from, | 68 send_s2s(attr.to, attr.from, |
| 69 st.stanza("db:verify", { from = attr.to, to = attr.from, id = origin.streamid }):text(stanza[1])); | 69 st.stanza("db:verify", { from = attr.to, to = attr.from, id = origin.streamid }):text(stanza[1])); |
| 70 end); | 70 end); |
| 71 | 71 |
| 72 module:add_handler({ "s2sout_unauthed", "s2sout" }, "verify", xmlns_dialback, | 72 module:add_handler({ "s2sout_unauthed", "s2sout" }, "verify", xmlns_dialback, |