Mercurial > prosody-modules
comparison mod_manifesto/mod_manifesto.lua @ 1325:b21236b6b8d8
Backed out changeset 853a382c9bd6
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 28 Feb 2014 15:37:55 +0100 |
parents | 853a382c9bd6 |
children | 65082d91950e |
comparison
equal
deleted
inserted
replaced
1324:853a382c9bd6 | 1325:b21236b6b8d8 |
---|---|
55 | 55 |
56 local notified; | 56 local notified; |
57 | 57 |
58 module:hook("resource-bind", function (event) | 58 module:hook("resource-bind", function (event) |
59 local session = event.session; | 59 local session = event.session; |
60 module:log("debug", "mod_%s sees that %s logged in", module.name, session.username); | |
61 | 60 |
62 local now = time(); | 61 local now = time(); |
63 local last_notify = notified[session.username] or 0; | 62 local last_notify = notified[session.username] or 0; |
64 if last_notify > ( now - 86400 * 7 ) then | 63 if last_notify > ( now - 86400 * 7 ) then |
65 module:log("debug", "Already notified %s", session.username); | |
66 return | 64 return |
67 end | 65 end |
68 | 66 |
69 module:log("debug", "Waiting 15 seconds"); | |
70 timer.add_task(15, function () | 67 timer.add_task(15, function () |
71 module:log("debug", "15 seconds later... session.type is %q", session.type); | |
72 if session.type ~= "c2s" then return end -- user quit already | 68 if session.type ~= "c2s" then return end -- user quit already |
73 local bad_contacts, bad_hosts = {}, {}; | 69 local bad_contacts, bad_hosts = {}, {}; |
74 for contact_jid, item in pairs(session.roster or {}) do | 70 for contact_jid, item in pairs(session.roster or {}) do |
75 local _, contact_host = jid_split(contact_jid); | 71 local _, contact_host = jid_split(contact_jid); |
76 local bad = false; | 72 local bad = false; |
98 bad_hosts[contact_host] = true; | 94 bad_hosts[contact_host] = true; |
99 table.insert(bad_hosts, contact_host); | 95 table.insert(bad_hosts, contact_host); |
100 end | 96 end |
101 end | 97 end |
102 end | 98 end |
103 module:log("debug", "%s has %d bad contacts", session.username, #bad_contacts); | |
104 if #bad_contacts > 0 then | 99 if #bad_contacts > 0 then |
105 local vars = { | 100 local vars = { |
106 HOST = host; | 101 HOST = host; |
107 CONTACTS = " "..table.concat(bad_contacts, "\n "); | 102 CONTACTS = " "..table.concat(bad_contacts, "\n "); |
108 SERVICES = " "..table.concat(bad_hosts, "\n "); | 103 SERVICES = " "..table.concat(bad_hosts, "\n "); |
109 CONTACTVIA = contact_method, CONTACT = contact; | 104 CONTACTVIA = contact_method, CONTACT = contact; |
110 }; | 105 }; |
111 module:log("debug", "Sending notification to %s", session.username); | |
112 session.send(st.message({ type = "headline", from = host }):tag("body"):text(message:gsub("$(%w+)", vars))); | 106 session.send(st.message({ type = "headline", from = host }):tag("body"):text(message:gsub("$(%w+)", vars))); |
113 notified[session.username] = now; | 107 notified[session.username] = now; |
114 end | 108 end |
115 end); | 109 end); |
116 end); | 110 end); |
163 if fields.state == "enabled" then | 157 if fields.state == "enabled" then |
164 config_set(host, "c2s_require_encryption", true); | 158 config_set(host, "c2s_require_encryption", true); |
165 config_set(host, "s2s_require_encryption", true); | 159 config_set(host, "s2s_require_encryption", true); |
166 | 160 |
167 for _, session in pairs(s2s_sessions) do | 161 for _, session in pairs(s2s_sessions) do |
168 if session.type == "s2sin" or session.type == "s2sout" and not session.secure then | 162 if not session.secure then |
169 (session.close or s2s_destroy_session)(session); | 163 (session.close or s2s_destroy_session)(session); |
170 end | 164 end |
171 end | 165 end |
172 | 166 |
173 info = "Manifesto mode enabled"; | 167 info = "Manifesto mode enabled"; |