Mercurial > prosody-modules
annotate mod_adhoc_cmd_modules/mod_adhoc_cmd_modules.lua @ 203:4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Fri, 09 Jul 2010 01:36:32 +0200 |
parents | |
children | a6361a1fda5e |
rev | line source |
---|---|
203
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
1 -- Copyright (C) 2009-2010 Florian Zeitz |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
2 -- |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
3 -- This file is MIT/X11 licensed. Please see the |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
4 -- COPYING file in the source package for more information. |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
5 -- |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
6 |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
7 local _G = _G; |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
8 |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
9 local prosody = _G.prosody; |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
10 local hosts = prosody.hosts; |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
11 |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
12 require "util.iterators"; |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
13 local dataforms_new = require "util.dataforms".new; |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
14 local array = require "util.array"; |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
15 local adhoc_new = module:require "adhoc".new; |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
16 |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
17 function list_modules_handler(self, data, state) |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
18 local list_modules_result = dataforms_new { |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
19 title = "List of loaded modules"; |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
20 |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
21 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/modules#list" }; |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
22 { name = "modules", type = "text-multi", label = "The following modules are loaded:" }; |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
23 }; |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
24 |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
25 local modules = array.collect(keys(hosts[data.to].modules)):sort() |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
26 local modules_str = nil; |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
27 for _, name in ipairs(modules) do |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
28 modules_str = ((modules_str and modules_str .. "\n") or "") .. name; |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
29 end |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
30 |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
31 return { status = "completed", result = { layout = list_modules_result; data = { modules = modules_str } } }; |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
32 end |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
33 |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
34 local list_modules_desc = adhoc_new("List loaded modules", "http://prosody.im/protocol/modules#list", list_modules_handler, "admin"); |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
35 |
4927b9737bb7
mod_adhoc_cmd_modules: Initial version. Provides a "List loaded modules" cmd for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
36 module:add_item("adhoc", list_modules_desc); |