Mercurial > prosody-modules
comparison mod_lastlog/mod_lastlog.lua @ 1049:59f031d1cd38
mod_last_offline: Merge into an option of mod_lastlog
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 03 Jun 2013 20:54:06 +0200 |
| parents | 50bed746aa16 |
| children | 59657e03c25c |
comparison
equal
deleted
inserted
replaced
| 1048:50bed746aa16 | 1049:59f031d1cd38 |
|---|---|
| 1 local datamanager = require "util.datamanager"; | 1 local datamanager = require "util.datamanager"; |
| 2 local jid = require "util.jid"; | |
| 2 local time = os.time; | 3 local time = os.time; |
| 3 local log_ip = module:get_option_boolean("lastlog_ip_address", false); | 4 local log_ip = module:get_option_boolean("lastlog_ip_address", false); |
| 4 local host = module.host; | 5 local host = module.host; |
| 5 | 6 |
| 6 module:hook("authentication-success", function(event) | 7 module:hook("authentication-success", function(event) |
| 23 ip = log_ip and session.ip or nil, | 24 ip = log_ip and session.ip or nil, |
| 24 }); | 25 }); |
| 25 end | 26 end |
| 26 end); | 27 end); |
| 27 | 28 |
| 29 if module:get_option_boolean("lastlog_stamp_offline") then | |
| 30 local function offline_stamp(event) | |
| 31 local stanza = event.stanza; | |
| 32 local node, to_host = jid.split(stanza.attr.from); | |
| 33 if to_host == host and event.origin == hosts[host] and stanza.attr.type == "unavailable" then | |
| 34 local data = datamanager.load(node, host, "lastlog"); | |
| 35 local timestamp = data and data.timestamp; | |
| 36 if timestamp then | |
| 37 stanza:tag("delay", { | |
| 38 xmlns = "urn:xmpp:delay", | |
| 39 from = host, | |
| 40 stamp = datetime.datetime(timestamp), | |
| 41 }):up(); | |
| 42 end | |
| 43 end | |
| 44 end | |
| 45 | |
| 46 module:hook("pre-presence/bare", offline_stamp); | |
| 47 module:hook("pre-presence/full", offline_stamp); | |
| 48 end | |
| 49 | |
| 28 function module.command(arg) | 50 function module.command(arg) |
| 29 local user, host = require "util.jid".prepped_split(table.remove(arg, 1)); | 51 local user, host = jid.prepped_split(table.remove(arg, 1)); |
| 30 require"core.storagemanager".initialize_host(host); | 52 require"core.storagemanager".initialize_host(host); |
| 31 local lastlog = assert(datamanager.load(user, host, "lastlog")); | 53 local lastlog = assert(datamanager.load(user, host, "lastlog")); |
| 32 if lastlog then | 54 if lastlog then |
| 33 print(("Last %s: %s"):format(lastlog.event or "login", | 55 print(("Last %s: %s"):format(lastlog.event or "login", |
| 34 lastlog.timestamp and os.date("%Y-%m-%d %H:%M:%S", lastlog.timestamp) or "<unknown>")); | 56 lastlog.timestamp and os.date("%Y-%m-%d %H:%M:%S", lastlog.timestamp) or "<unknown>")); |
