Changeset

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 1266:51e7a4bbd70b
children 1268:854a3933cfcd
files mod_list_inactive/mod_list_inactive.lua
diffstat 1 files changed, 32 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_list_inactive/mod_list_inactive.lua	Sat Jan 04 20:34:22 2014 +0100
@@ -0,0 +1,32 @@
+-- Copyright (C) 2012-2013 Kim Alvefur
+
+local um = require "core.usermanager";
+local sm = require "core.storagemanager";
+local dm_load = require "util.datamanager".load;
+
+local multipliers = {
+	d = 86400, -- day
+	w = 604800, -- week
+	m = 2629746, -- month
+	y = 31556952, -- year
+}
+
+function module.command(arg)
+	local items = {};
+	local host = arg[1];
+	assert(hosts[host], "Host "..tostring(host).." does not exist");
+	sm.initialize_host(host);
+	um.initialize_host(host);
+
+	local max_age, unit = assert(arg[2], "No time range given"):match("^(%d*)%s*([dwmy]?)");
+	max_age = os.time() - ( tonumber(max_age) or 1 ) * ( multipliers[unit] or 1 );
+	for user in um.users(host) do
+		local last_active = dm_load(user, host, "lastlog");
+		last_active = last_active and last_active.timestamp or 0;
+		local bare = user.."@"..host;
+		if last_active < max_age then
+			print(("user:delete%q"):format(bare));
+		end
+	end
+end
+