Software /
code /
prosody-modules
Comparison
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 |
comparison
equal
deleted
inserted
replaced
1306:63e7e20a0074 | 1307:71dd991c94e7 |
---|---|
2 | 2 |
3 local timer = require "util.timer"; | 3 local timer = require "util.timer"; |
4 local jid_split = require "util.jid".split; | 4 local jid_split = require "util.jid".split; |
5 local st = require "util.stanza"; | 5 local st = require "util.stanza"; |
6 local dm = require "util.datamanager"; | 6 local dm = require "util.datamanager"; |
7 local dataforms_new = require "util.dataforms".new; | |
8 local adhoc_initial = require "util.adhoc".new_initial_data_form; | |
9 local mm_reload = require "modulemanager".reload; | |
10 local config = require "core.configmanager"; | |
11 local config_get = config.get; | |
12 local config_set = config.set; | |
13 local t_concat = table.concat; | |
14 local adhoc_new = module:require "adhoc".new; | |
7 local time = os.time; | 15 local time = os.time; |
8 | 16 |
9 local hosts = prosody.hosts; | 17 local hosts = prosody.hosts; |
10 local host = module.host; | 18 local host = module.host; |
11 local host_session = hosts[host]; | 19 local host_session = hosts[host]; |
117 end | 125 end |
118 | 126 |
119 function module.uninstall() | 127 function module.uninstall() |
120 dm.store(nil, host, module.name, nil); | 128 dm.store(nil, host, module.name, nil); |
121 end | 129 end |
130 | |
131 -- Ad-hoc command for switching to/from "manifesto mode" | |
132 local layout = dataforms_new { | |
133 title = "Configure manifesto mode"; | |
134 | |
135 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/manifesto" }; | |
136 { name = "state", type = "list-single", required = true, label = "Manifesto mode:"}; | |
137 }; | |
138 | |
139 local adhoc_handler = adhoc_initial(layout, function() | |
140 local enabled = config_get(host, "c2s_require_encryption") and config_get(host, "s2s_require_encryption"); | |
141 return { state = { | |
142 { label = "Enabled", value = "enabled", default = enabled }, | |
143 { label = "Configuration settings", value = "config", default = not enabled }, | |
144 }}; | |
145 end, function(fields, err) | |
146 if err then | |
147 local errmsg = {}; | |
148 for name, err in pairs(errors) do | |
149 errmsg[#errmsg + 1] = name .. ": " .. err; | |
150 end | |
151 return { status = "completed", error = { message = t_concat(errmsg, "\n") } }; | |
152 end | |
153 | |
154 local info; | |
155 if fields.state == "enabled" then | |
156 config_set(host, "c2s_require_encryption", true); | |
157 config_set(host, "s2s_require_encryption", true); | |
158 info = "Manifesto mode enabled"; | |
159 else | |
160 local ok, err = prosody.reload_config(); | |
161 if not ok then | |
162 return { status = "completed", error = { message = "Failed to reload config: " .. tostring(err) } }; | |
163 end | |
164 info = "Reset to configuration settings"; | |
165 end | |
166 | |
167 local ok, err = mm_reload(host, "tls"); | |
168 if not ok then return { status = "completed", error = { message = "Failed to reload mod_tls: " .. tostring(err) } }; end | |
169 ok, err = mm_reload(host, "s2s"); | |
170 if not ok then return { status = "completed", error = { message = "Failed to reload mod_s2s: " .. tostring(err) } }; end | |
171 ok, err = mm_reload(host, "saslauth"); | |
172 if not ok then return { status = "completed", error = { message = "Failed to reload mod_saslauth: " .. tostring(err) } }; end | |
173 | |
174 return { status = "completed", info = info }; | |
175 end); | |
176 module:provides("adhoc", adhoc_new("Configure manifesto mode", "http://prosody.im/protocol/manifesto", adhoc_handler, "admin")); |