Mercurial > prosody-modules
comparison mod_manifesto/mod_manifesto.lua @ 1283:3e96889c0c36
mod_manifesto: Check state of incoming connections
| author | Florian Zeitz <florob@babelmonkeys.de> |
|---|---|
| date | Thu, 23 Jan 2014 19:15:47 +0100 |
| parents | 17cb51496469 |
| children | e36f82d7baae |
comparison
equal
deleted
inserted
replaced
| 1282:17cb51496469 | 1283:3e96889c0c36 |
|---|---|
| 7 local time = os.time; | 7 local time = os.time; |
| 8 | 8 |
| 9 local hosts = prosody.hosts; | 9 local hosts = prosody.hosts; |
| 10 local host = module.host; | 10 local host = module.host; |
| 11 local host_session = hosts[host]; | 11 local host_session = hosts[host]; |
| 12 local incoming_s2s = prosody.incoming_s2s; | |
| 12 | 13 |
| 13 local default_tpl = [[ | 14 local default_tpl = [[ |
| 14 Hello there. | 15 Hello there. |
| 15 | 16 |
| 16 This is a brief system message to let you know about some upcoming changes to the $HOST service. | 17 This is a brief system message to let you know about some upcoming changes to the $HOST service. |
| 51 local last_notify = notified[session.username] or 0; | 52 local last_notify = notified[session.username] or 0; |
| 52 if last_notify > ( now - 86400 * 7 ) then | 53 if last_notify > ( now - 86400 * 7 ) then |
| 53 return | 54 return |
| 54 end | 55 end |
| 55 | 56 |
| 56 notified[session.username] = now; | |
| 57 timer.add_task(15, function () | 57 timer.add_task(15, function () |
| 58 local bad_contacts, bad_hosts = {}, {}; | 58 local bad_contacts, bad_hosts = {}, {}; |
| 59 for contact_jid, item in pairs(session.roster) do | 59 for contact_jid, item in pairs(session.roster) do |
| 60 local _, host = jid_split(contact_jid); | 60 local _, contact_host = jid_split(contact_jid); |
| 61 local remote_host_session = host_session.s2sout[host]; | 61 local bad = false; |
| 62 local remote_host_session = host_session.s2sout[contact_host]; | |
| 62 if remote_host_session and remote_host_session.type == "s2sout" then -- Only check remote hosts we have completed s2s connections to | 63 if remote_host_session and remote_host_session.type == "s2sout" then -- Only check remote hosts we have completed s2s connections to |
| 63 if not remote_host_session.secure then | 64 if not remote_host_session.secure then |
| 64 local contact_name = item.name; | 65 bad = true; |
| 65 if contact_name then | 66 end |
| 66 table.insert(bad_contacts, contact_name.." <"..contact_jid..">"); | 67 end |
| 67 else | 68 for session in pairs(incoming_s2s) do |
| 68 table.insert(bad_contacts, contact_jid); | 69 if session.to_host == host and session.from_host == contact_host then |
| 70 if not session.secure then | |
| 71 bad = true; | |
| 69 end | 72 end |
| 70 if not bad_hosts[host] then | 73 end |
| 71 bad_hosts[host] = true; | 74 end |
| 72 table.insert(bad_hosts, host); | 75 if bad then |
| 73 end | 76 local contact_name = item.name; |
| 77 if contact_name then | |
| 78 table.insert(bad_contacts, contact_name.." <"..contact_jid..">"); | |
| 79 else | |
| 80 table.insert(bad_contacts, contact_jid); | |
| 81 end | |
| 82 if not bad_hosts[contact_host] then | |
| 83 bad_hosts[contact_host] = true; | |
| 84 table.insert(bad_hosts, contact_host); | |
| 74 end | 85 end |
| 75 end | 86 end |
| 76 end | 87 end |
| 77 if #bad_contacts > 0 then | 88 if #bad_contacts > 0 then |
| 78 local vars = { | 89 local vars = { |
| 81 SERVICES = " "..table.concat(bad_hosts, "\n "); | 92 SERVICES = " "..table.concat(bad_hosts, "\n "); |
| 82 CONTACTVIA = contact_method, CONTACT = contact; | 93 CONTACTVIA = contact_method, CONTACT = contact; |
| 83 }; | 94 }; |
| 84 session.send(st.message({ type = "headline", from = host }):tag("body"):text(message:gsub("$(%w+)", vars))); | 95 session.send(st.message({ type = "headline", from = host }):tag("body"):text(message:gsub("$(%w+)", vars))); |
| 85 end | 96 end |
| 97 notified[session.username] = now; | |
| 86 end); | 98 end); |
| 87 end); | 99 end); |
| 88 | 100 |
| 89 function module.load() | 101 function module.load() |
| 90 notified = dm.load(nil, host, module.name) or {}; | 102 notified = dm.load(nil, host, module.name) or {}; |
