annotate mod_log_auth/mod_log_auth.lua @ 2695:8b21f13b08c5

mod_log_auth: Split some long lines
author Kim Alvefur <zash@zash.se>
date Wed, 19 Apr 2017 06:36:52 +0200
parents 9d43095d915f
children 404d47d2e833
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1427
322a076f53e8 mod_log_auth: Add ability to log IPs of successful authentications too
Matthew Wild <mwild1@gmail.com>
parents: 1097
diff changeset
1 local mode = module:get_option_string("log_auth_ips", "failure");
2695
8b21f13b08c5 mod_log_auth: Split some long lines
Kim Alvefur <zash@zash.se>
parents: 2084
diff changeset
2 assert(({ all = true, failure = true, success = true })[mode],
8b21f13b08c5 mod_log_auth: Split some long lines
Kim Alvefur <zash@zash.se>
parents: 2084
diff changeset
3 "Unknown log mode: "..tostring(mode).." - valid modes are 'all', 'failure', 'success'");
407
41feaf7fd8ac mod_auth_log: New module (currently) to log failed auth attempts and their IP address, requires trunk
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
1427
322a076f53e8 mod_log_auth: Add ability to log IPs of successful authentications too
Matthew Wild <mwild1@gmail.com>
parents: 1097
diff changeset
5 if mode == "failure" or mode == "all" then
322a076f53e8 mod_log_auth: Add ability to log IPs of successful authentications too
Matthew Wild <mwild1@gmail.com>
parents: 1097
diff changeset
6 module:hook("authentication-failure", function (event)
2695
8b21f13b08c5 mod_log_auth: Split some long lines
Kim Alvefur <zash@zash.se>
parents: 2084
diff changeset
7 local session = event.session;
8b21f13b08c5 mod_log_auth: Split some long lines
Kim Alvefur <zash@zash.se>
parents: 2084
diff changeset
8 module:log("info", "Failed authentication attempt (%s) for user %s from IP: %s",
8b21f13b08c5 mod_log_auth: Split some long lines
Kim Alvefur <zash@zash.se>
parents: 2084
diff changeset
9 event.condition or "unknown-condition", session.username or "?", session.ip or "?");
1427
322a076f53e8 mod_log_auth: Add ability to log IPs of successful authentications too
Matthew Wild <mwild1@gmail.com>
parents: 1097
diff changeset
10 end);
322a076f53e8 mod_log_auth: Add ability to log IPs of successful authentications too
Matthew Wild <mwild1@gmail.com>
parents: 1097
diff changeset
11 end
322a076f53e8 mod_log_auth: Add ability to log IPs of successful authentications too
Matthew Wild <mwild1@gmail.com>
parents: 1097
diff changeset
12
322a076f53e8 mod_log_auth: Add ability to log IPs of successful authentications too
Matthew Wild <mwild1@gmail.com>
parents: 1097
diff changeset
13 if mode == "success" or mode == "all" then
322a076f53e8 mod_log_auth: Add ability to log IPs of successful authentications too
Matthew Wild <mwild1@gmail.com>
parents: 1097
diff changeset
14 module:hook("authentication-success", function (event)
322a076f53e8 mod_log_auth: Add ability to log IPs of successful authentications too
Matthew Wild <mwild1@gmail.com>
parents: 1097
diff changeset
15 local session = event.session;
322a076f53e8 mod_log_auth: Add ability to log IPs of successful authentications too
Matthew Wild <mwild1@gmail.com>
parents: 1097
diff changeset
16 module:log("info", "Successful authentication as %s from IP: %s", session.username, session.ip or "?");
322a076f53e8 mod_log_auth: Add ability to log IPs of successful authentications too
Matthew Wild <mwild1@gmail.com>
parents: 1097
diff changeset
17 end);
322a076f53e8 mod_log_auth: Add ability to log IPs of successful authentications too
Matthew Wild <mwild1@gmail.com>
parents: 1097
diff changeset
18 end