Software /
code /
prosody
Annotate
plugins/mod_flags.lua @ 13689:6049c1602c79 13.0
modulemanager: Remove autoloading of per-platform module
We only support posix these days, and we moved it to the core startup process
to make it more deterministic and reliable.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 13 Feb 2025 18:00:54 +0000 |
parent | 13583:e77ef9a4604f |
rev | line source |
---|---|
13583
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local jid_node = require "prosody.util.jid".node; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local flags = module:open_store("account_flags", "keyval+"); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 -- API |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 function add_flag(username, flag, comment) |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local flag_data = { |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 when = os.time(); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 comment = comment; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 }; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 local ok, err = flags:set_key(username, flag, flag_data); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 if not ok then |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 return nil, err; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 end |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 module:fire_event("user-flag-added/"..flag, { |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 user = username; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 flag = flag; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 data = flag_data; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 }); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 return true; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 end |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 function remove_flag(username, flag) |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 local ok, err = flags:set_key(username, flag, nil); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 if not ok then |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 return nil, err; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 end |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 module:fire_event("user-flag-removed/"..flag, { |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 user = username; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 flag = flag; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 }); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 return true; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 end |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 function has_flag(username, flag) -- luacheck: ignore 131/has_flag |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 local ok, err = flags:get_key(username, flag); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 if not ok and err then |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 error("Failed to check flags for user: "..err); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 end |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 return not not ok; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 end |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 function get_flag_info(username, flag) -- luacheck: ignore 131/get_flag_info |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 return flags:get_key(username, flag); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 end |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 -- Shell commands |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 local function get_username(jid) |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 return (assert(jid_node(jid), "please supply a valid user JID")); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 end |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 module:add_item("shell-command", { |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 section = "flags"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 section_desc = "View and manage flags on user accounts"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 name = "list"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 desc = "List flags for the given user account"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 args = { |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 { name = "jid", type = "string" }; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 }; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 host_selector = "jid"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 handler = function(self, jid) --luacheck: ignore 212/self |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 local c = 0; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 local user_flags, err = flags:get(get_username(jid)); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 if not user_flags and err then |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 return false, "Unable to list flags: "..err; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 end |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 if user_flags then |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 local print = self.session.print; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 for flag_name, flag_data in pairs(user_flags) do |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 print(flag_name, os.date("%Y-%m-%d %R", flag_data.when), flag_data.comment); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 c = c + 1; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 end |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 end |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 return true, ("%d flags listed"):format(c); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 end; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 }); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 module:add_item("shell-command", { |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 section = "flags"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 section_desc = "View and manage flags on user accounts"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 name = "add"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 desc = "Add a flag to the given user account, with optional comment"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 args = { |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 { name = "jid", type = "string" }; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 { name = "flag", type = "string" }; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 { name = "comment", type = "string" }; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 }; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 host_selector = "jid"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 handler = function(self, jid, flag, comment) --luacheck: ignore 212/self |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 local username = get_username(jid); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 local ok, err = add_flag(username, flag, comment); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 if not ok then |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 return false, "Failed to add flag: "..err; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 end |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 return true, "Flag added"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 end; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 }); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 module:add_item("shell-command", { |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 section = "flags"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 section_desc = "View and manage flags on user accounts"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 name = "remove"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 desc = "Remove a flag from the given user account"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 args = { |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 { name = "jid", type = "string" }; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 { name = "flag", type = "string" }; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 }; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 host_selector = "jid"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 handler = function(self, jid, flag) --luacheck: ignore 212/self |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 local username = get_username(jid); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 local ok, err = remove_flag(username, flag); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 if not ok then |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 return false, "Failed to remove flag: "..err; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 end |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 return true, "Flag removed"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 end; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 }); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 module:add_item("shell-command", { |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 section = "flags"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 section_desc = "View and manage flags on user accounts"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 name = "find"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 desc = "Find all user accounts with a given flag on the specified host"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 args = { |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 { name = "host", type = "string" }; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 { name = "flag", type = "string" }; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 }; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 host_selector = "host"; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 handler = function(self, host, flag) --luacheck: ignore 212/self 212/host |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 local users_with_flag = flags:get_key_from_all(flag); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 local print = self.session.print; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 local c = 0; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 for user, flag_data in pairs(users_with_flag) do |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 print(user, os.date("%Y-%m-%d %R", flag_data.when), flag_data.comment); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 c = c + 1; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 end |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 return true, ("%d accounts listed"):format(c); |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 end; |
e77ef9a4604f
mod_flags: New module to view and manage flags on user accounts via shell/API
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 }); |