Admin (failed) login notification

  Previous article Next article  

Admin (failed) login notification

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.3.1
  Last updated: 05-07-2017
  Comments: 2

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 (54.157.81.13) 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://www.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 "Extentions" menu.



A2 Webhosting CMS Made Simple

A2 Webhosting CMS Made Simple

  Comments

  Click here to leave a comment






This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)
  « Enter the CAPTCHA code (lower case)

Your IP address will be stored on submit. I reserve the right to change or delete your response without notice!
In case of abuse your IP address will be blocked!


Can I have your attention for a moment?

Did this tutorial help you solving a problem at your (clients) website and it saved you many hours of work? Great!!
Consider buying Rolf a cup of coffee in return! [ Click here ]


  2 Comments

CMS Made Simple 2.2.3.1 - Tutorials, tips and tricks - CMSMS 2.2.3.1

Admin (failed) login notification

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.3.1
  Last updated: 05-07-2017
  Comments: 2

A2 Webhosting CMS Made Simple