Software /
code /
prosody-modules
Annotate
mod_list_inactive/mod_list_inactive.lua @ 1360:6ee395396333
mod_s2s_auth_dnssec_srv: Do something useful for incoming connection
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 19 Mar 2014 19:19:46 +0100 |
parent | 1267:589991b148e8 |
child | 1496:cccb151a4cc5 |
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; |
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
|
6 |
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 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
|
8 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
|
9 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
|
10 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
|
11 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
|
12 } |
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 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
|
15 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
|
16 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
|
17 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
|
18 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
|
19 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
|
20 |
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 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
|
22 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
|
23 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
|
24 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
|
25 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
|
26 local bare = user.."@"..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
|
27 if last_active < max_age then |
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
|
28 print(("user:delete%q"):format(bare)); |
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 |