MENU

Admin (failed) login notification

  Previous article Next article  

You want to have more control over your Admin panel? Who is entering it and when are people failing to login... With this tutorial you will get a mail notification of these two events.

  How to use

In the Admin panel go to "Extentions" >> "User Defined Tags" and create a new UDT named "AdminLoginNotification".

Note: Change your mail address in the UDT.
To avoid that notifications mails are sent when you login from your home address enter your IP address (3.129.70.138) too.

Both parameters can have multiple values separated by a comma.

// ++++++++ Update these lines ++++++++

$email_address = 'you@website.com';
$whitelabel_ip = array ("127.0.0.1","0,0,0,0");

// ++++++++ Update these lines ++++++++

// Source: https://cmscanbesimple.org/blog/admin-failed-login-notification

$current_ip = cms_utils::get_real_ip();

if (!in_array($current_ip, $whitelabel_ip))
{

$user = $params['user'];

if ($params['_eventname'] == 'LoginPost')
{
$subject  = 'Successful login: ' . $user->username . ' - ' . $current_ip;

$message_template = <<<'EOD'
There has been a successful login in your Admin panel.

User Name: %s
IP Address: %s
First Name: %s
Last Name: %s
E-mail: %s
EOD
;

$message = sprintf($message_template,
  $user->username,
  $current_ip,
  $user->firstname,
  $user->lastname,
  $user->email
);
}
elseif ($params['_eventname'] == 'LoginFailed')
{
$subject  = 'Failed login: ' . $user . ' - ' . $current_ip;

$message_template  = <<<'EOD'
There has been a failed login in your Admin panel.

User Name: %s
IP Address: %s
EOD
;

$message = sprintf($message_template,
  $user,
  $current_ip
);
}

$mailer = new \cms_mailer;
$mailer->AddAddress($email_address);
$mailer->SetSubject($subject);
$mailer->SetBody($message);
$mailer->Send();

}

Depending on your wishes you should attach the UDT to the LoginPost and/or LoginFailed events in the CMSMS Event Manager. You will find it in the "Extensions" menu.


Buy Me A Coffee


  Comment Form

ReviewManager

Click here to open the form

ReviewManager

  2 Comments

Buy Me A Coffee

CMS Made Simple - Tutorials, Tips and Tricks - CMSMS

Admin (failed) login notification

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.19
  Last updated: 20-05-2018
  Comments: 2
  http://cms.ms/MH3Q


Buy Me A Coffee




Advertisement


Ads help me to help you! Thanks!

Ads help me to help you! Buy products from these advertisers!