mod_lastlog: Keep track of last logout time
authorKim Alvefur <zash@zash.se>
Mon, 03 Jun 2013 19:03:42 +0200
changeset 1047 38781835c911
parent 1046 b9d47487d550
child 1048 50bed746aa16
mod_lastlog: Keep track of last logout time
mod_lastlog/mod_lastlog.lua
--- a/mod_lastlog/mod_lastlog.lua	Mon Jun 03 11:09:50 2013 -0400
+++ b/mod_lastlog/mod_lastlog.lua	Mon Jun 03 19:03:42 2013 +0200
@@ -1,11 +1,24 @@
 local datamanager = require "util.datamanager";	
 local time = os.time;
 local log_ip = module:get_option_boolean("lastlog_ip_address", false);
+local host = module.host;
 
 module:hook("authentication-success", function(event)
 	local session = event.session;
 	if session.username then
-		datamanager.store(session.username, session.host, "lastlog", {
+		datamanager.store(session.username, host, "lastlog", {
+			event = "login";
+			timestamp = time(),
+			ip = log_ip and session.ip or nil,
+		});
+	end
+end);
+
+module:hook("resource-unbind", function(event)
+	local session = event.session;
+	if session.username then
+		datamanager.store(session.username, host, "lastlog", {
+			event = "logout";
 			timestamp = time(),
 			ip = log_ip and session.ip or nil,
 		});