Mercurial > prosody-modules
changeset 1427:322a076f53e8
mod_log_auth: Add ability to log IPs of successful authentications too
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 31 May 2014 13:38:35 +0100 (2014-05-31) |
parents | 249c5447fed1 |
children | 091ee76745e8 |
files | mod_log_auth/mod_log_auth.lua |
diffstat | 1 files changed, 14 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_log_auth/mod_log_auth.lua Fri May 30 19:07:18 2014 -0400 +++ b/mod_log_auth/mod_log_auth.lua Sat May 31 13:38:35 2014 +0100 @@ -1,4 +1,15 @@ +local mode = module:get_option_string("log_auth_ips", "failure"); +assert(({ all = true, failure = true, success = true })[mode], "Unknown log mode: "..tostring(mode).." - valid modes are 'all', 'failure', 'success'"); -module:hook("authentication-failure", function (event) - module:log("info", "Failed authentication attempt (%s) from IP: %s", event.condition or "unknown-condition", event.session.ip or "?"); -end); +if mode == "failure" or mode == "all" then + module:hook("authentication-failure", function (event) + module:log("info", "Failed authentication attempt (%s) from IP: %s", event.condition or "unknown-condition", event.session.ip or "?"); + end); +end + +if mode == "success" or mode == "all" then + module:hook("authentication-success", function (event) + local session = event.session; + module:log("info", "Successful authentication as %s from IP: %s", session.username, session.ip or "?"); + end); +end