Mercurial > prosody-modules
annotate mod_list_inactive/mod_list_inactive.lua @ 1496:cccb151a4cc5
mod_list_inactive: Delay joining JIDs until they are used
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 26 Aug 2014 16:15:23 +0200 |
parents | 589991b148e8 |
children | d1836dfa4ae4 |
rev | line source |
---|---|
1267
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 -- Copyright (C) 2012-2013 Kim Alvefur |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local um = require "core.usermanager"; |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local sm = require "core.storagemanager"; |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 local dm_load = require "util.datamanager".load; |
1496
cccb151a4cc5
mod_list_inactive: Delay joining JIDs until they are used
Kim Alvefur <zash@zash.se>
parents:
1267
diff
changeset
|
6 local jid_join = require"util.jid".join; |
1267
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 local multipliers = { |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 d = 86400, -- day |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 w = 604800, -- week |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 m = 2629746, -- month |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 y = 31556952, -- year |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 } |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 function module.command(arg) |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 local items = {}; |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 local host = arg[1]; |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 assert(hosts[host], "Host "..tostring(host).." does not exist"); |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 sm.initialize_host(host); |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 um.initialize_host(host); |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 local max_age, unit = assert(arg[2], "No time range given"):match("^(%d*)%s*([dwmy]?)"); |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 max_age = os.time() - ( tonumber(max_age) or 1 ) * ( multipliers[unit] or 1 ); |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 for user in um.users(host) do |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 local last_active = dm_load(user, host, "lastlog"); |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 last_active = last_active and last_active.timestamp or 0; |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 if last_active < max_age then |
1496
cccb151a4cc5
mod_list_inactive: Delay joining JIDs until they are used
Kim Alvefur <zash@zash.se>
parents:
1267
diff
changeset
|
28 print(("user:delete%q"):format(jid_join(user, host))); |
1267
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 end |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 end |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 end |
589991b148e8
mod_list_inactive: Parse data collected by mod_lastlog and print users who have not logged in for some time
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 |