Notifications module - V2 alternatives? Sends email on event

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Location: Maidenhead, UK
Contact:

Notifications module - V2 alternatives? Sends email on event

Post by paulbaker »

I use the notifications module on every V1 site. It's great, it notifies me by email every time an admin logs in to the backend. So I can easily see which clients are updating their sites - and which are not. It also emails me on every unsuccessful backend login (e.g. wrong password) so I can tell if someone, or something, is trying to hack in.

I would like to continue using it in V2 but it hasn't been updated in a while and it is unlikely to be updated because it was created by a couple of guys who have left the CMSMS world:
http://dev.cmsmadesimple.org/projects/notifications

I tried installing in to a V 2.1.3 site - it seemed to install without error but unsurprisingly it did not work, giving a white unstyled page when accessing the admin page.

Is there an alternative method of getting the functionality described without using this module?

Thanks
To copy System Information to the forum:
https://docs.cmsmadesimple.org/troubles ... nformation

CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: Notifications module - V2 alternatives? Sends email on e

Post by Rolf »

- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Location: Maidenhead, UK
Contact:

Re: Notifications module - V2 alternatives? Sends email on e

Post by paulbaker »

Thanks for the swift reply Rolf!

I tried the Mail UDT. It worked great. So I am now notified on a failed login.

I made a similar UDT and linked it to the LoginPost event, hoping to be told every time someone successfully logs in. The UDT fires OK but the $_POST["username"] field is blank. It would be great if anyone had some ideas on that.
To copy System Information to the forum:
https://docs.cmsmadesimple.org/troubles ... nformation

CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: Notifications module - V2 alternatives? Sends email on e

Post by Rolf »

Code: Select all

$_SESSION['login_user_username']
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Notifications module - V2 alternatives? Sends email on e

Post by velden »

LoginPost

Description: Sent after a user logs into the Admin panel
Parameters

'user' - Reference to the affected user object.

Event Handlers

None
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Notifications module - V2 alternatives? Sends email on e

Post by velden »

Generic (for both failed en success):

Code: Select all

$to = 'YOUREMAIL@YOURDOMAIN.COM';
$headers = 'From: CMS Made Simple website.com <noreply@website.com>';

$user = $params['user'];
if ($params['_eventname'] == 'LoginPost') {

$subject  = 'Successful login: ' . $user->username . ' - ' . cms_utils::get_real_ip();

$message_template  =<<<'EOD'
There has been a successful login in your admin panel.
Username: %s
IP Address: %s
First Name: %s
Last Name: %s
Email %s
EOD;

$message = sprintf($message_template,
  $user->username,
  cms_utils::get_real_ip(),
  $user->firstname,
  $user->lastname,
  $user->email
);
} elseif($params['_eventname'] == 'LoginFailed') {

$subject  = 'Failed login: ' . $user . ' - ' . cms_utils::get_real_ip();

$message_template  =<<<'EOD'
There has been a failed login in your admin panel.
Username: %s
IP Address: %s
EOD;

$message = sprintf($message_template,
  $user,
  cms_utils::get_real_ip()
);

}
@mail($to, $subject, $message, $headers);
Personally I'd rather use the CMSMS api to send the email out (instead of 'mail') but don't have time now to find out how.
Last edited by velden on Thu May 19, 2016 10:20 am, edited 1 time in total.
Reason: Removed 'Is Admin' from code
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Notifications module - V2 alternatives? Sends email on e

Post by calguy1000 »

in 2.x:

$mailer = new cms_mailer();
$mailer->SetSubject($subject);
$mailer->SetBody($body);
$mailer->AddAddress($email_address);
$mailer->Send();
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: Notifications module - V2 alternatives? Sends email on e

Post by Rolf »

- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
Post Reply

Return to “Modules/Add-Ons”