comparison mod_audit/mod_audit.lua @ 5757:08a635862201

mod_audit: Update command to handle storing JIDs instead of only usernames
author Kim Alvefur <zash@zash.se>
date Sat, 02 Dec 2023 11:48:19 +0100
parents 1bdc6b5979ee
children 754f8eaad34c
comparison
equal deleted inserted replaced
5756:e199f33f7a2e 5757:08a635862201
170 local arg = require "util.argparse".parse(arg_, { 170 local arg = require "util.argparse".parse(arg_, {
171 value_params = { "limit" }; 171 value_params = { "limit" };
172 }); 172 });
173 173
174 module:log("debug", "arg = %q", arg); 174 module:log("debug", "arg = %q", arg);
175 local query_user, host = jid.prepped_split(arg[1]); 175 local query_jid = jid.prep(arg[1]);
176 local host = jid.host(query_jid);
176 177
177 if arg.prune then 178 if arg.prune then
178 local sm = require "core.storagemanager"; 179 local sm = require "core.storagemanager";
179 if host then 180 if host then
180 sm.initialize_host(host); 181 sm.initialize_host(host);
199 require "core.storagemanager".initialize_host(host); 200 require "core.storagemanager".initialize_host(host);
200 local store = stores[host]; 201 local store = stores[host];
201 local c = 0; 202 local c = 0;
202 203
203 if arg.global then 204 if arg.global then
204 if query_user then 205 if jid.node(query_jid) then
205 print("WW: Specifying a user account is incompatible with --global. Showing only global events."); 206 print("WW: Specifying a user account is incompatible with --global. Showing only global events.");
206 end 207 end
207 query_user = "@"; 208 query_jid = "@";
209 elseif host == query_jid then
210 query_jid = "@";
208 end 211 end
209 212
210 local results, err = store:find(nil, { 213 local results, err = store:find(nil, {
211 with = query_user; 214 with = query_jid;
212 limit = arg.limit and tonumber(arg.limit) or nil; 215 limit = arg.limit and tonumber(arg.limit) or nil;
213 reverse = true; 216 reverse = true;
214 }) 217 })
215 if not results then 218 if not results then
216 print("EE: Failed to query audit log: "..tostring(err)); 219 print("EE: Failed to query audit log: "..tostring(err));
221 { title = "Date", key = "when", width = 19, mapper = function (when) return os.date("%Y-%m-%d %R:%S", when); end }; 224 { title = "Date", key = "when", width = 19, mapper = function (when) return os.date("%Y-%m-%d %R:%S", when); end };
222 { title = "Source", key = "source", width = "2p" }; 225 { title = "Source", key = "source", width = "2p" };
223 { title = "Event", key = "event_type", width = "2p" }; 226 { title = "Event", key = "event_type", width = "2p" };
224 }; 227 };
225 228
226 if arg.show_user ~= false and (not arg.global and not query_user) or arg.show_user then 229 if arg.show_user ~= false and (not arg.global and not query_jid) or arg.show_user then
227 table.insert(colspec, { 230 table.insert(colspec, {
228 title = "User", key = "username", width = "2p", 231 title = "User", key = "username", width = "2p",
229 mapper = function (user) 232 mapper = function (user)
230 if user == "@" then return ""; end 233 if user == "@" then return ""; end
231 if user:sub(-#host-1, -1) == ("@"..host) then 234 if user:sub(-#host-1, -1) == ("@"..host) then