changeset 1047:38781835c911

mod_lastlog: Keep track of last logout time
author Kim Alvefur <zash@zash.se>
date Mon, 03 Jun 2013 19:03:42 +0200
parents b9d47487d550
children 50bed746aa16
files mod_lastlog/mod_lastlog.lua
diffstat 1 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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,
 		});