Annotate

mod_manifesto/mod_manifesto.lua @ 1307:71dd991c94e7

mod_manifesto: Add ad-hoc command to enable "manifesto mode"
author Florian Zeitz <florob@babelmonkeys.de>
date Mon, 17 Feb 2014 20:39:48 +0100
parent 1306:63e7e20a0074
child 1308:9ddfff2acddc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1282
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 -- mod_manifesto
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local timer = require "util.timer";
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local jid_split = require "util.jid".split;
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local st = require "util.stanza";
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 local dm = require "util.datamanager";
1307
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
7 local dataforms_new = require "util.dataforms".new;
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
8 local adhoc_initial = require "util.adhoc".new_initial_data_form;
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
9 local mm_reload = require "modulemanager".reload;
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
10 local config = require "core.configmanager";
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
11 local config_get = config.get;
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
12 local config_set = config.set;
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
13 local t_concat = table.concat;
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
14 local adhoc_new = module:require "adhoc".new;
1282
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 local time = os.time;
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 local hosts = prosody.hosts;
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 local host = module.host;
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 local host_session = hosts[host];
1283
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
20 local incoming_s2s = prosody.incoming_s2s;
1282
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 local default_tpl = [[
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 Hello there.
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 This is a brief system message to let you know about some upcoming changes to the $HOST service.
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 Some of your contacts are on other Jabber/XMPP services that do not support encryption. As part of an initiative to increase the security of the Jabber/XMPP network, this service ($HOST) will be participating in a series of tests to discover the impact of our planned changes, and you may lose the ability to communicate with some of your contacts.
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28
1305
b0971d8815bf mod_manifesto: Fix typo
Kim Alvefur <zash@zash.se>
parents: 1300
diff changeset
29 The test days will be on the following dates: January 4, February 22, March 22 and April 19. On these days we will require that all client and server connections are encrypted. Unless they enable encryption before that, you will be unable to communicate with your contacts that use these services:
1282
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 $SERVICES
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 Your affected contacts are:
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 $CONTACTS
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 What can you do? You may tell your contacts to inform their service administrator about their lack of encryption. Your contacts may also switch to a more secure service. A list of public services can be found at https://xmpp.net/directory.php
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 For more information about the Jabber/XMPP security initiative that we are participating in, please read the announcement at https://stpeter.im/journal/1496.html
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 If you have any questions or concerns, you may contact us via $CONTACTVIA at $CONTACT
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 ]];
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 local message = module:get_option_string("manifesto_contact_encryption_warning", default_tpl);
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 local contact = module:get_option_string("admin_contact_address", module:get_option_array("admins", {})[1]);
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 if not contact then
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 error("mod_manifesto needs you to set 'admin_contact_address' in your config file.", 0);
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 end
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 local contact_method = "Jabber/XMPP";
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 if select(2, contact:gsub("^mailto:", "")) > 0 then
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 contact_method = "email";
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 end
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 local notified;
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 module:hook("resource-bind", function (event)
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 local session = event.session;
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 local now = time();
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 local last_notify = notified[session.username] or 0;
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 if last_notify > ( now - 86400 * 7 ) then
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 return
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 end
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 timer.add_task(15, function ()
1300
99748c89edd4 mod_manifesto: Fix traceback when user disconnects before the timer (fixes #48)
Kim Alvefur <zash@zash.se>
parents: 1286
diff changeset
66 if session.type ~= "c2s" then return end -- user quit already
1282
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 local bad_contacts, bad_hosts = {}, {};
1286
9700c89f7bf6 mod_manifesto: Fix traceback when user doesn't have a roster (?)
Matthew Wild <mwild1@gmail.com>
parents: 1284
diff changeset
68 for contact_jid, item in pairs(session.roster or {}) do
1283
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
69 local _, contact_host = jid_split(contact_jid);
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
70 local bad = false;
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
71 local remote_host_session = host_session.s2sout[contact_host];
1282
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 if remote_host_session and remote_host_session.type == "s2sout" then -- Only check remote hosts we have completed s2s connections to
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 if not remote_host_session.secure then
1283
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
74 bad = true;
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
75 end
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
76 end
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
77 for session in pairs(incoming_s2s) do
1284
e36f82d7baae mod_manifesto: Only check fully established incoming sessions
Florian Zeitz <florob@babelmonkeys.de>
parents: 1283
diff changeset
78 if session.to_host == host and session.from_host == contact_host and session.type == "s2sin" then
1283
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
79 if not session.secure then
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
80 bad = true;
1282
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
81 end
1283
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
82 end
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
83 end
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
84 if bad then
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
85 local contact_name = item.name;
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
86 if contact_name then
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
87 table.insert(bad_contacts, contact_name.." <"..contact_jid..">");
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
88 else
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
89 table.insert(bad_contacts, contact_jid);
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
90 end
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
91 if not bad_hosts[contact_host] then
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
92 bad_hosts[contact_host] = true;
3e96889c0c36 mod_manifesto: Check state of incoming connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 1282
diff changeset
93 table.insert(bad_hosts, contact_host);
1282
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
94 end
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
95 end
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
96 end
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
97 if #bad_contacts > 0 then
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
98 local vars = {
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
99 HOST = host;
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
100 CONTACTS = " "..table.concat(bad_contacts, "\n ");
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
101 SERVICES = " "..table.concat(bad_hosts, "\n ");
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
102 CONTACTVIA = contact_method, CONTACT = contact;
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
103 };
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
104 session.send(st.message({ type = "headline", from = host }):tag("body"):text(message:gsub("$(%w+)", vars)));
1306
63e7e20a0074 mod_manifesto: Only keep track of who we sent notifications to
Kim Alvefur <zash@zash.se>
parents: 1305
diff changeset
105 notified[session.username] = now;
1282
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
106 end
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
107 end);
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
108 end);
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
109
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
110 function module.load()
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
111 notified = dm.load(nil, host, module.name) or {};
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
112 end
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
113
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
114 function module.save()
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
115 dm.store(nil, host, module.name, notified);
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
116 return { notified = notified };
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
117 end
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
118
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
119 function module.restore(data)
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
120 notified = data.notified;
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
121 end
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
122
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
123 function module.unload()
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
124 dm.store(nil, host, module.name, notified);
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
125 end
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
126
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
127 function module.uninstall()
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
128 dm.store(nil, host, module.name, nil);
17cb51496469 mod_manifesto: Module that informs users about the Security Test Days and which contacts it will affect (Thanks to MattJ, who wrote most of it)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
129 end
1307
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
130
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
131 -- Ad-hoc command for switching to/from "manifesto mode"
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
132 local layout = dataforms_new {
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
133 title = "Configure manifesto mode";
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
134
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
135 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/manifesto" };
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
136 { name = "state", type = "list-single", required = true, label = "Manifesto mode:"};
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
137 };
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
138
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
139 local adhoc_handler = adhoc_initial(layout, function()
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
140 local enabled = config_get(host, "c2s_require_encryption") and config_get(host, "s2s_require_encryption");
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
141 return { state = {
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
142 { label = "Enabled", value = "enabled", default = enabled },
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
143 { label = "Configuration settings", value = "config", default = not enabled },
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
144 }};
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
145 end, function(fields, err)
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
146 if err then
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
147 local errmsg = {};
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
148 for name, err in pairs(errors) do
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
149 errmsg[#errmsg + 1] = name .. ": " .. err;
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
150 end
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
151 return { status = "completed", error = { message = t_concat(errmsg, "\n") } };
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
152 end
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
153
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
154 local info;
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
155 if fields.state == "enabled" then
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
156 config_set(host, "c2s_require_encryption", true);
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
157 config_set(host, "s2s_require_encryption", true);
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
158 info = "Manifesto mode enabled";
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
159 else
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
160 local ok, err = prosody.reload_config();
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
161 if not ok then
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
162 return { status = "completed", error = { message = "Failed to reload config: " .. tostring(err) } };
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
163 end
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
164 info = "Reset to configuration settings";
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
165 end
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
166
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
167 local ok, err = mm_reload(host, "tls");
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
168 if not ok then return { status = "completed", error = { message = "Failed to reload mod_tls: " .. tostring(err) } }; end
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
169 ok, err = mm_reload(host, "s2s");
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
170 if not ok then return { status = "completed", error = { message = "Failed to reload mod_s2s: " .. tostring(err) } }; end
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
171 ok, err = mm_reload(host, "saslauth");
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
172 if not ok then return { status = "completed", error = { message = "Failed to reload mod_saslauth: " .. tostring(err) } }; end
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
173
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
174 return { status = "completed", info = info };
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
175 end);
71dd991c94e7 mod_manifesto: Add ad-hoc command to enable "manifesto mode"
Florian Zeitz <florob@babelmonkeys.de>
parents: 1306
diff changeset
176 module:provides("adhoc", adhoc_new("Configure manifesto mode", "http://prosody.im/protocol/manifesto", adhoc_handler, "admin"));