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