From ad399a95dded2a0378eb410569dcac65c3c9c44a Mon Sep 17 00:00:00 2001 From: alecpl <alec@alec.pl> Date: Thu, 09 Dec 2010 04:26:54 -0500 Subject: [PATCH] - Add username and IP address to log message on unsuccessful login (#1487626) --- program/include/main.inc | 42 +++++++++++++++++++++++++++--------------- 1 files changed, 27 insertions(+), 15 deletions(-) diff --git a/program/include/main.inc b/program/include/main.inc index 160c835..a9a96a0 100644 --- a/program/include/main.inc +++ b/program/include/main.inc @@ -1193,21 +1193,33 @@ if (!$RCMAIL->config->get('log_logins') || !$RCMAIL->user) return; - $address = $_SERVER['REMOTE_ADDR']; - // append the NGINX X-Real-IP header, if set - if (!empty($_SERVER['HTTP_X_REAL_IP'])) { - $remote_ip[] = 'X-Real-IP: ' . $_SERVER['HTTP_X_REAL_IP']; - } - // append the X-Forwarded-For header, if set - if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { - $remote_ip[] = 'X-Forwarded-For: ' . $_SERVER['HTTP_X_FORWARDED_FOR']; - } - - if (!empty($remote_ip)) - $address .= '(' . implode(',', $remote_ip) . ')'; - write_log('userlogins', sprintf('Successful login for %s (ID: %d) from %s', - $RCMAIL->user->get_username(), $RCMAIL->user->ID, $address)); + $RCMAIL->user->get_username(), $RCMAIL->user->ID, rcmail_remote_ip())); +} + + +/** + * Returns remote IP address and forwarded addresses if found + * + * @return string Remote IP address(es) + */ +function rcmail_remote_ip() +{ + $address = $_SERVER['REMOTE_ADDR']; + + // append the NGINX X-Real-IP header, if set + if (!empty($_SERVER['HTTP_X_REAL_IP'])) { + $remote_ip[] = 'X-Real-IP: ' . $_SERVER['HTTP_X_REAL_IP']; + } + // append the X-Forwarded-For header, if set + if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { + $remote_ip[] = 'X-Forwarded-For: ' . $_SERVER['HTTP_X_FORWARDED_FOR']; + } + + if (!empty($remote_ip)) + $address .= '(' . implode(',', $remote_ip) . ')'; + + return $address; } @@ -1219,7 +1231,7 @@ { return microtime(true); } - + /** * @access private -- Gitblit v1.9.1