view mod_lastlog/mod_lastlog.lua @ 1039:3f91f17ddaca

mod_lastlog: Add prosodyctl command (prosodyctl mod_lastlog JID) to show last login time and IP of user (if available)
author Matthew Wild <>
date Sat, 01 Jun 2013 23:29:21 +0100
parents 884ae37d76bf
children 38781835c911
line wrap: on
line source

local datamanager = require "util.datamanager";	
local time = os.time;
local log_ip = module:get_option_boolean("lastlog_ip_address", false);

module:hook("authentication-success", function(event)
	local session = event.session;
	if session.username then,, "lastlog", {
			timestamp = time(),
			ip = log_ip and session.ip or nil,

function module.command(arg)
	local user, host = require "util.jid".prepped_split(table.remove(arg, 1));
	local lastlog = datamanager.load(user, host, "lastlog") or {};
	print("Last login: "..(lastlog and"%Y-%m-%d %H:%m:%s", datamanager.load(user, host, "lastlog").time) or "<unknown>"));
	if lastlog.ip then
		print("IP address: "..lastlog.ip);
	return 0;