comparison mod_manifesto/mod_manifesto.lua @ 1324:853a382c9bd6

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