Software /
code /
prosody-modules
Comparison
mod_lastlog/mod_lastlog.lua @ 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 |
parent | 1039:3f91f17ddaca |
child | 1048:50bed746aa16 |
comparison
equal
deleted
inserted
replaced
1046:b9d47487d550 | 1047:38781835c911 |
---|---|
1 local datamanager = require "util.datamanager"; | 1 local datamanager = require "util.datamanager"; |
2 local time = os.time; | 2 local time = os.time; |
3 local log_ip = module:get_option_boolean("lastlog_ip_address", false); | 3 local log_ip = module:get_option_boolean("lastlog_ip_address", false); |
4 local host = module.host; | |
4 | 5 |
5 module:hook("authentication-success", function(event) | 6 module:hook("authentication-success", function(event) |
6 local session = event.session; | 7 local session = event.session; |
7 if session.username then | 8 if session.username then |
8 datamanager.store(session.username, session.host, "lastlog", { | 9 datamanager.store(session.username, host, "lastlog", { |
10 event = "login"; | |
11 timestamp = time(), | |
12 ip = log_ip and session.ip or nil, | |
13 }); | |
14 end | |
15 end); | |
16 | |
17 module:hook("resource-unbind", function(event) | |
18 local session = event.session; | |
19 if session.username then | |
20 datamanager.store(session.username, host, "lastlog", { | |
21 event = "logout"; | |
9 timestamp = time(), | 22 timestamp = time(), |
10 ip = log_ip and session.ip or nil, | 23 ip = log_ip and session.ip or nil, |
11 }); | 24 }); |
12 end | 25 end |
13 end); | 26 end); |