Version Notes
Release notes:
v. 0.2.0
- Grid with custom cells rendering
- Used the Event Observer Methods for custom actions
v. 0.1.0
- initial public release of Login Notifier
Download this release
Release Info
Developer | Webmu |
Extension | Webmu_LoginNotifier |
Version | 0.2.0 |
Comparing to | |
See all releases |
Code changes from version 0.1.0 to 0.2.0
- app/code/community/Webmu/LoginNotifier/Block/Adminhtml/Report/Grid.php +27 -7
- app/code/community/Webmu/LoginNotifier/Block/Adminhtml/Report/Renderer/Created.php +26 -0
- app/code/community/Webmu/LoginNotifier/Block/Adminhtml/Report/Renderer/Info.php +28 -0
- app/code/community/Webmu/LoginNotifier/Block/Adminhtml/Report/Renderer/Result.php +30 -0
- app/code/community/Webmu/LoginNotifier/Model/Admin/Session.php +0 -221
- app/code/community/Webmu/LoginNotifier/Model/Observer.php +159 -0
- app/code/community/Webmu/LoginNotifier/etc/config.xml +21 -6
- app/design/adminhtml/default/default/layout/loginnotifier.xml +8 -0
- app/etc/modules/Webmu_LoginNotifier.xml +0 -1
- app/locale/en_US/template/email/loginnotifier_notificationemail_failed.html +3 -0
- app/locale/en_US/template/email/loginnotifier_notificationemail_success.html +3 -0
- package.xml +16 -9
app/code/community/Webmu/LoginNotifier/Block/Adminhtml/Report/Grid.php
CHANGED
@@ -39,9 +39,10 @@ class Webmu_LoginNotifier_Block_Adminhtml_Report_Grid extends Mage_Adminhtml_Blo
|
|
39 |
$this->addColumn("created", array(
|
40 |
"header" => Mage::helper("loginnotifier")->__("Created on"),
|
41 |
"align" =>"left",
|
42 |
-
"width" => "
|
43 |
"type" => "datetime",
|
44 |
"index" => "created",
|
|
|
45 |
));
|
46 |
|
47 |
$this->addColumn("ip", array(
|
@@ -56,22 +57,25 @@ class Webmu_LoginNotifier_Block_Adminhtml_Report_Grid extends Mage_Adminhtml_Blo
|
|
56 |
));
|
57 |
|
58 |
$this->addColumn("user_agent", array(
|
59 |
-
"header" => Mage::helper("loginnotifier")->__("User
|
60 |
"index" => "user_agent",
|
|
|
|
|
61 |
));
|
62 |
|
63 |
-
|
64 |
"header" => Mage::helper("loginnotifier")->__("Referer"),
|
65 |
"width" => "200px",
|
66 |
"index" => "http_referer",
|
67 |
-
))
|
68 |
|
69 |
$this->addColumn('result', array(
|
70 |
'header' => Mage::helper('loginnotifier')->__('Result'),
|
71 |
"align" =>"right",
|
72 |
'index' => 'result',
|
73 |
'type' => 'options',
|
74 |
-
'options'=> Mage::getModel('loginnotifier/resultOption')->toOptionArray()
|
|
|
75 |
));
|
76 |
|
77 |
$this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV'));
|
@@ -80,8 +84,24 @@ class Webmu_LoginNotifier_Block_Adminhtml_Report_Grid extends Mage_Adminhtml_Blo
|
|
80 |
return parent::_prepareColumns();
|
81 |
}
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
public function getRowUrl($row)
|
84 |
{
|
85 |
-
|
86 |
-
}
|
|
|
87 |
}
|
39 |
$this->addColumn("created", array(
|
40 |
"header" => Mage::helper("loginnotifier")->__("Created on"),
|
41 |
"align" =>"left",
|
42 |
+
"width" => "130px",
|
43 |
"type" => "datetime",
|
44 |
"index" => "created",
|
45 |
+
"renderer" => "Webmu_LoginNotifier_Block_Adminhtml_Report_Renderer_Created",
|
46 |
));
|
47 |
|
48 |
$this->addColumn("ip", array(
|
57 |
));
|
58 |
|
59 |
$this->addColumn("user_agent", array(
|
60 |
+
"header" => Mage::helper("loginnotifier")->__("User information"),
|
61 |
"index" => "user_agent",
|
62 |
+
"renderer" => "Webmu_LoginNotifier_Block_Adminhtml_Report_Renderer_Info",
|
63 |
+
'filter_condition_callback' => array($this, '_userInformationFilter'),
|
64 |
));
|
65 |
|
66 |
+
/*$this->addColumn("http_referer", array(
|
67 |
"header" => Mage::helper("loginnotifier")->__("Referer"),
|
68 |
"width" => "200px",
|
69 |
"index" => "http_referer",
|
70 |
+
));*/
|
71 |
|
72 |
$this->addColumn('result', array(
|
73 |
'header' => Mage::helper('loginnotifier')->__('Result'),
|
74 |
"align" =>"right",
|
75 |
'index' => 'result',
|
76 |
'type' => 'options',
|
77 |
+
'options'=> Mage::getModel('loginnotifier/resultOption')->toOptionArray(),
|
78 |
+
"renderer" => "Webmu_LoginNotifier_Block_Adminhtml_Report_Renderer_Result",
|
79 |
));
|
80 |
|
81 |
$this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV'));
|
84 |
return parent::_prepareColumns();
|
85 |
}
|
86 |
|
87 |
+
protected function _userInformationFilter($collection, $column)
|
88 |
+
{
|
89 |
+
if (!$value = $column->getFilter()->getValue()) {
|
90 |
+
return $this;
|
91 |
+
}
|
92 |
+
|
93 |
+
$this->getCollection()->getSelect()->where(
|
94 |
+
"main_table.http_referer like ?
|
95 |
+
OR main_table.user_agent like ?"
|
96 |
+
, "%$value%");
|
97 |
+
|
98 |
+
|
99 |
+
return $this;
|
100 |
+
}
|
101 |
+
|
102 |
public function getRowUrl($row)
|
103 |
{
|
104 |
+
return false;
|
105 |
+
}
|
106 |
+
|
107 |
}
|
app/code/community/Webmu/LoginNotifier/Block/Adminhtml/Report/Renderer/Created.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Webmu
|
16 |
+
* @package Webmu_LoginNotifier
|
17 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
18 |
+
*/
|
19 |
+
class Webmu_LoginNotifier_Block_Adminhtml_Report_Renderer_Created extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
|
20 |
+
{
|
21 |
+
public function render(Varien_Object $row)
|
22 |
+
{
|
23 |
+
$value = $row->getData($this->getColumn()->getIndex());
|
24 |
+
return $value;
|
25 |
+
}
|
26 |
+
}
|
app/code/community/Webmu/LoginNotifier/Block/Adminhtml/Report/Renderer/Info.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Webmu
|
16 |
+
* @package Webmu_LoginNotifier
|
17 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
18 |
+
*/
|
19 |
+
class Webmu_LoginNotifier_Block_Adminhtml_Report_Renderer_Info extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
|
20 |
+
{
|
21 |
+
public function render(Varien_Object $row)
|
22 |
+
{
|
23 |
+
$value = $row->getData($this->getColumn()->getIndex());
|
24 |
+
return '<strong>' . Mage::helper("loginnotifier")->__("User agent") . ':</strong> ' .
|
25 |
+
$value . '</span><br /><strong>' . Mage::helper("loginnotifier")->__("Referer") . ':</strong> ' .
|
26 |
+
$row->getHttpReferer();
|
27 |
+
}
|
28 |
+
}
|
app/code/community/Webmu/LoginNotifier/Block/Adminhtml/Report/Renderer/Result.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Webmu
|
16 |
+
* @package Webmu_LoginNotifier
|
17 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
18 |
+
*/
|
19 |
+
class Webmu_LoginNotifier_Block_Adminhtml_Report_Renderer_Result extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
|
20 |
+
{
|
21 |
+
public function render(Varien_Object $row)
|
22 |
+
{
|
23 |
+
$value = $row->getData($this->getColumn()->getIndex());
|
24 |
+
$options = Mage::getModel('loginnotifier/resultOption')->toOptionArray();
|
25 |
+
if( $value == 1)
|
26 |
+
return '<span class="grid-severity-notice"><span>' . $options[$value] . '</span></span>';
|
27 |
+
else
|
28 |
+
return '<span class="grid-severity-critical"><span>' . $options[$value] . '</span></span>';
|
29 |
+
}
|
30 |
+
}
|
app/code/community/Webmu/LoginNotifier/Model/Admin/Session.php
DELETED
@@ -1,221 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Magento
|
4 |
-
*
|
5 |
-
* NOTICE OF LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
-
* that is bundled with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://opensource.org/licenses/osl-3.0.php
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* @category Webmu
|
16 |
-
* @package Webmu_LoginNotifier
|
17 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
18 |
-
*/
|
19 |
-
class Webmu_LoginNotifier_Model_Admin_Session extends Mage_Admin_Model_Session
|
20 |
-
{
|
21 |
-
/**
|
22 |
-
* Pull out information from session whether there is currently the first page after log in
|
23 |
-
*
|
24 |
-
* The idea is to set this value on login(), then redirect happens,
|
25 |
-
* after that on next request the value is grabbed once the session is initialized
|
26 |
-
* Since the session is used as a singleton, the value will be in $_isFirstPageAfterLogin until the end of request,
|
27 |
-
* unless it is reset intentionally from somewhere
|
28 |
-
*
|
29 |
-
* @param string $namespace
|
30 |
-
* @param string $sessionName
|
31 |
-
* @return Mage_Admin_Model_Session
|
32 |
-
* @see self::login()
|
33 |
-
*/
|
34 |
-
public function init($namespace, $sessionName = null)
|
35 |
-
{
|
36 |
-
parent::init($namespace, $sessionName);
|
37 |
-
$this->isFirstPageAfterLogin();
|
38 |
-
return $this;
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Try to login user in admin
|
43 |
-
*
|
44 |
-
* @param string $username
|
45 |
-
* @param string $password
|
46 |
-
* @param Mage_Core_Controller_Request_Http $request
|
47 |
-
* @return Mage_Admin_Model_User|null
|
48 |
-
*/
|
49 |
-
public function login($username, $password, $request = null)
|
50 |
-
{
|
51 |
-
if (empty($username) || empty($password)) {
|
52 |
-
return;
|
53 |
-
}
|
54 |
-
|
55 |
-
$result = 0;
|
56 |
-
|
57 |
-
try {
|
58 |
-
/** @var $user Mage_Admin_Model_User */
|
59 |
-
$user = $this->_factory->getModel('admin/user');
|
60 |
-
$user->login($username, $password);
|
61 |
-
if ($user->getId()) {
|
62 |
-
|
63 |
-
$this->_addLoginNotification(array(
|
64 |
-
"username" => $username,
|
65 |
-
"result" => 1
|
66 |
-
)
|
67 |
-
);
|
68 |
-
|
69 |
-
if( Mage::getStoreConfig('loginnotifier/success/general_success_login') == 'enabled'){
|
70 |
-
$this->sendSuccessNotificationEmail($username, $password);
|
71 |
-
}
|
72 |
-
|
73 |
-
$this->renewSession();
|
74 |
-
|
75 |
-
if (Mage::getSingleton('adminhtml/url')->useSecretKey()) {
|
76 |
-
Mage::getSingleton('adminhtml/url')->renewSecretUrls();
|
77 |
-
}
|
78 |
-
$this->setIsFirstPageAfterLogin(true);
|
79 |
-
$this->setUser($user);
|
80 |
-
$this->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());
|
81 |
-
|
82 |
-
$alternativeUrl = $this->_getRequestUri($request);
|
83 |
-
$redirectUrl = $this->_urlPolicy->getRedirectUrl($user, $request, $alternativeUrl);
|
84 |
-
if ($redirectUrl) {
|
85 |
-
Mage::dispatchEvent('admin_session_user_login_success', array('user' => $user));
|
86 |
-
$this->_response->clearHeaders()
|
87 |
-
->setRedirect($redirectUrl)
|
88 |
-
->sendHeadersAndExit();
|
89 |
-
}
|
90 |
-
} else {
|
91 |
-
|
92 |
-
$this->_addLoginNotification(array(
|
93 |
-
"username" => $username,
|
94 |
-
"result" => 0
|
95 |
-
)
|
96 |
-
);
|
97 |
-
|
98 |
-
if( Mage::getStoreConfig('loginnotifier/failed/general_failed_login') == 'enabled'){
|
99 |
-
$this->sendFailedNotificationEmail($username, $password);
|
100 |
-
}
|
101 |
-
Mage::throwException(Mage::helper('adminhtml')->__('Invalid User Name or Password.'));
|
102 |
-
}
|
103 |
-
} catch (Mage_Core_Exception $e) {
|
104 |
-
Mage::dispatchEvent('admin_session_user_login_failed',
|
105 |
-
array('user_name' => $username, 'exception' => $e));
|
106 |
-
if ($request && !$request->getParam('messageSent')) {
|
107 |
-
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
|
108 |
-
$request->setParam('messageSent', true);
|
109 |
-
}
|
110 |
-
}
|
111 |
-
|
112 |
-
return $user;
|
113 |
-
}
|
114 |
-
|
115 |
-
protected function _addLoginNotification( $data_params = array()){
|
116 |
-
|
117 |
-
$data = array_merge( $data_params, array(
|
118 |
-
'ip' => Mage::helper('core/http')->getRemoteAddr(),
|
119 |
-
'user_agent' => Mage::helper('core/http')->getHttpUserAgent(),
|
120 |
-
'http_referer' => Mage::helper('core/http')->getHttpReferer()
|
121 |
-
));
|
122 |
-
$model = Mage::getModel('loginnotifier/report')->setData($data);
|
123 |
-
|
124 |
-
try {
|
125 |
-
$insertId = $model->save()->getId();
|
126 |
-
} catch (Exception $error){
|
127 |
-
Mage::getSingleton('core/session')->addError($error->getMessage());
|
128 |
-
return false;
|
129 |
-
}
|
130 |
-
}
|
131 |
-
|
132 |
-
public function sendFailedNotificationEmail( $username, $password)
|
133 |
-
{
|
134 |
-
$template_id = 'loginnotifier_notificationemail_failed';
|
135 |
-
|
136 |
-
$recipients = Mage::getStoreConfig('loginnotifier/failed/general_failed_login_email');
|
137 |
-
if( strstr( $recipients, ",")){
|
138 |
-
$recipients = array_map('trim', explode(',', $recipients));
|
139 |
-
}
|
140 |
-
|
141 |
-
$senderName = Mage::getStoreConfig('trans_email/ident_general/name');
|
142 |
-
$senderEmail = Mage::getStoreConfig('trans_email/ident_general/email');
|
143 |
-
|
144 |
-
$emailTemplate = Mage::getModel('core/email_template')->loadDefault($template_id);
|
145 |
-
$emailTemplateVariables = array(
|
146 |
-
'username' => $username,
|
147 |
-
'date' => Mage::getModel('core/date')->date('Y-m-d'),
|
148 |
-
'hour' => Mage::getModel('core/date')->date('H:i'),
|
149 |
-
'ip' => Mage::helper('core/http')->getRemoteAddr()
|
150 |
-
);
|
151 |
-
|
152 |
-
//Appending the Custom Variables to Template.
|
153 |
-
$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
|
154 |
-
|
155 |
-
//Sending E-Mail to Customers.
|
156 |
-
$mail = Mage::getModel('core/email')
|
157 |
-
->setToEmail($recipients)
|
158 |
-
->setSubject($emailTemplate->getTemplateSubject())
|
159 |
-
->setBody($processedTemplate)
|
160 |
-
->setFromEmail($senderEmail)
|
161 |
-
->setFromName($senderName)
|
162 |
-
->setType('html');
|
163 |
-
|
164 |
-
try{
|
165 |
-
//Confimation E-Mail Send
|
166 |
-
$mail->send();
|
167 |
-
}
|
168 |
-
catch(Exception $error)
|
169 |
-
{
|
170 |
-
Mage::getSingleton('core/session')->addError($error->getMessage());
|
171 |
-
return false;
|
172 |
-
}
|
173 |
-
}
|
174 |
-
|
175 |
-
public function sendSuccessNotificationEmail( $username, $password)
|
176 |
-
{
|
177 |
-
$template_id = 'loginnotifier_notificationemail_success';
|
178 |
-
|
179 |
-
$recipients = Mage::getStoreConfig('loginnotifier/success/general_success_login_email');
|
180 |
-
if( strstr( $recipients, ",")){
|
181 |
-
$recipients = array_map('trim', explode(',', $recipients));
|
182 |
-
}
|
183 |
-
|
184 |
-
$senderName = Mage::getStoreConfig('trans_email/ident_general/name');
|
185 |
-
$senderEmail = Mage::getStoreConfig('trans_email/ident_general/email');
|
186 |
-
|
187 |
-
$emailTemplate = Mage::getModel('core/email_template')->loadDefault($template_id);
|
188 |
-
|
189 |
-
$senderName = Mage::getStoreConfig('trans_email/ident_general/name');
|
190 |
-
$senderEmail = Mage::getStoreConfig('trans_email/ident_general/email');
|
191 |
-
|
192 |
-
$emailTemplateVariables = array(
|
193 |
-
'username' => $username,
|
194 |
-
'date' => Mage::getModel('core/date')->date('Y-m-d'),
|
195 |
-
'hour' => Mage::getModel('core/date')->date('H:i'),
|
196 |
-
'ip' => Mage::helper('core/http')->getRemoteAddr()
|
197 |
-
);
|
198 |
-
|
199 |
-
//Appending the Custom Variables to Template.
|
200 |
-
$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
|
201 |
-
|
202 |
-
//Sending E-Mail to Customers.
|
203 |
-
$mail = Mage::getModel('core/email')
|
204 |
-
->setToEmail($recipients)
|
205 |
-
->setSubject($emailTemplate->getTemplateSubject())
|
206 |
-
->setBody($processedTemplate)
|
207 |
-
->setFromEmail($senderEmail)
|
208 |
-
->setFromName($senderName)
|
209 |
-
->setType('html');
|
210 |
-
|
211 |
-
try{
|
212 |
-
//Confimation E-Mail Send
|
213 |
-
$mail->send();
|
214 |
-
}
|
215 |
-
catch(Exception $error)
|
216 |
-
{
|
217 |
-
Mage::getSingleton('core/session')->addError($error->getMessage());
|
218 |
-
return false;
|
219 |
-
}
|
220 |
-
}
|
221 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Webmu/LoginNotifier/Model/Observer.php
ADDED
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category Webmu
|
16 |
+
* @package Webmu_LoginNotifier
|
17 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
18 |
+
*/
|
19 |
+
class Webmu_LoginNotifier_Model_Observer {
|
20 |
+
|
21 |
+
public function successLogin( $user) {
|
22 |
+
|
23 |
+
if ($user->getId()) {
|
24 |
+
$this->_addLoginNotification(array(
|
25 |
+
"username" => $user->getUsername(),
|
26 |
+
"result" => 1
|
27 |
+
)
|
28 |
+
);
|
29 |
+
|
30 |
+
if( Mage::getStoreConfig('loginnotifier/success/general_success_login') == 'enabled'){
|
31 |
+
$this->sendSuccessNotificationEmail($user->getUsername());
|
32 |
+
}
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
public function failedLogin( $observer) {
|
37 |
+
|
38 |
+
if ($observer['user_name']) {
|
39 |
+
$this->_addLoginNotification(array(
|
40 |
+
"username" => $observer['user_name'],
|
41 |
+
"result" => 0
|
42 |
+
)
|
43 |
+
);
|
44 |
+
|
45 |
+
if( Mage::getStoreConfig('loginnotifier/failed/general_failed_login') == 'enabled'){
|
46 |
+
$this->sendFailedNotificationEmail($observer['user_name']);
|
47 |
+
}
|
48 |
+
}
|
49 |
+
}
|
50 |
+
|
51 |
+
protected function _addLoginNotification( $data_params = array()){
|
52 |
+
|
53 |
+
$data = array_merge( $data_params, array(
|
54 |
+
'ip' => Mage::helper('core/http')->getRemoteAddr(),
|
55 |
+
'user_agent' => Mage::helper('core/http')->getHttpUserAgent(),
|
56 |
+
'http_referer' => Mage::helper('core/http')->getHttpReferer()
|
57 |
+
));
|
58 |
+
$model = Mage::getModel('loginnotifier/report')->setData($data);
|
59 |
+
|
60 |
+
try {
|
61 |
+
$insertId = $model->save()->getId();
|
62 |
+
} catch (Exception $error){
|
63 |
+
Mage::getSingleton('core/session')->addError($error->getMessage());
|
64 |
+
return false;
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
public function sendFailedNotificationEmail( $username)
|
69 |
+
{
|
70 |
+
$template_id = 'loginnotifier_notificationemail_failed';
|
71 |
+
|
72 |
+
$recipients = Mage::getStoreConfig('loginnotifier/failed/general_failed_login_email');
|
73 |
+
if( strstr( $recipients, ",")){
|
74 |
+
$recipients = array_map('trim', explode(',', $recipients));
|
75 |
+
}
|
76 |
+
|
77 |
+
$senderName = Mage::getStoreConfig('trans_email/ident_general/name');
|
78 |
+
$senderEmail = Mage::getStoreConfig('trans_email/ident_general/email');
|
79 |
+
|
80 |
+
$emailTemplate = Mage::getModel('core/email_template')->loadDefault($template_id);
|
81 |
+
$emailTemplateVariables = array(
|
82 |
+
'username' => $username,
|
83 |
+
'date' => Mage::getModel('core/date')->date('Y-m-d'),
|
84 |
+
'hour' => Mage::getModel('core/date')->date('H:i'),
|
85 |
+
'ip' => Mage::helper('core/http')->getRemoteAddr(),
|
86 |
+
'base_url' => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB)
|
87 |
+
);
|
88 |
+
|
89 |
+
//Appending the Custom Variables to Template.
|
90 |
+
$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
|
91 |
+
|
92 |
+
//Sending E-Mail to Customers.
|
93 |
+
$mail = Mage::getModel('core/email')
|
94 |
+
->setToEmail($recipients)
|
95 |
+
->setSubject($emailTemplate->getTemplateSubject())
|
96 |
+
->setBody($processedTemplate)
|
97 |
+
->setFromEmail($senderEmail)
|
98 |
+
->setFromName($senderName)
|
99 |
+
->setType('html');
|
100 |
+
|
101 |
+
try{
|
102 |
+
//Confimation E-Mail Send
|
103 |
+
$mail->send();
|
104 |
+
}
|
105 |
+
catch(Exception $error)
|
106 |
+
{
|
107 |
+
Mage::getSingleton('core/session')->addError($error->getMessage());
|
108 |
+
return false;
|
109 |
+
}
|
110 |
+
}
|
111 |
+
|
112 |
+
public function sendSuccessNotificationEmail( $username)
|
113 |
+
{
|
114 |
+
$template_id = 'loginnotifier_notificationemail_success';
|
115 |
+
|
116 |
+
$recipients = Mage::getStoreConfig('loginnotifier/success/general_success_login_email');
|
117 |
+
if( strstr( $recipients, ",")){
|
118 |
+
$recipients = array_map('trim', explode(',', $recipients));
|
119 |
+
}
|
120 |
+
|
121 |
+
$senderName = Mage::getStoreConfig('trans_email/ident_general/name');
|
122 |
+
$senderEmail = Mage::getStoreConfig('trans_email/ident_general/email');
|
123 |
+
|
124 |
+
$emailTemplate = Mage::getModel('core/email_template')->loadDefault($template_id);
|
125 |
+
|
126 |
+
$senderName = Mage::getStoreConfig('trans_email/ident_general/name');
|
127 |
+
$senderEmail = Mage::getStoreConfig('trans_email/ident_general/email');
|
128 |
+
|
129 |
+
$emailTemplateVariables = array(
|
130 |
+
'username' => $username,
|
131 |
+
'date' => Mage::getModel('core/date')->date('Y-m-d'),
|
132 |
+
'hour' => Mage::getModel('core/date')->date('H:i'),
|
133 |
+
'ip' => Mage::helper('core/http')->getRemoteAddr(),
|
134 |
+
'base_url' => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB)
|
135 |
+
);
|
136 |
+
|
137 |
+
//Appending the Custom Variables to Template.
|
138 |
+
$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
|
139 |
+
|
140 |
+
//Sending E-Mail to Customers.
|
141 |
+
$mail = Mage::getModel('core/email')
|
142 |
+
->setToEmail($recipients)
|
143 |
+
->setSubject($emailTemplate->getTemplateSubject())
|
144 |
+
->setBody($processedTemplate)
|
145 |
+
->setFromEmail($senderEmail)
|
146 |
+
->setFromName($senderName)
|
147 |
+
->setType('html');
|
148 |
+
|
149 |
+
try{
|
150 |
+
//Confimation E-Mail Send
|
151 |
+
$mail->send();
|
152 |
+
}
|
153 |
+
catch(Exception $error)
|
154 |
+
{
|
155 |
+
Mage::getSingleton('core/session')->addError($error->getMessage());
|
156 |
+
return false;
|
157 |
+
}
|
158 |
+
}
|
159 |
+
}
|
app/code/community/Webmu/LoginNotifier/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Webmu_LoginNotifier>
|
5 |
-
<version>0.
|
6 |
</Webmu_LoginNotifier>
|
7 |
</modules>
|
8 |
<global>
|
@@ -29,11 +29,6 @@
|
|
29 |
</report>
|
30 |
</entities>
|
31 |
</loginnotifier_mysql4>
|
32 |
-
<admin>
|
33 |
-
<rewrite>
|
34 |
-
<session>Webmu_LoginNotifier_Model_Admin_Session</session>
|
35 |
-
</rewrite>
|
36 |
-
</admin>
|
37 |
</models>
|
38 |
<resources>
|
39 |
<loginnotifier_setup>
|
@@ -82,6 +77,26 @@
|
|
82 |
</routers>
|
83 |
</admin>
|
84 |
<adminhtml>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
<menu>
|
86 |
<report>
|
87 |
<children>
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Webmu_LoginNotifier>
|
5 |
+
<version>0.2.0</version>
|
6 |
</Webmu_LoginNotifier>
|
7 |
</modules>
|
8 |
<global>
|
29 |
</report>
|
30 |
</entities>
|
31 |
</loginnotifier_mysql4>
|
|
|
|
|
|
|
|
|
|
|
32 |
</models>
|
33 |
<resources>
|
34 |
<loginnotifier_setup>
|
77 |
</routers>
|
78 |
</admin>
|
79 |
<adminhtml>
|
80 |
+
<events>
|
81 |
+
<admin_session_user_login_success>
|
82 |
+
<observers>
|
83 |
+
<loginnotifier_success>
|
84 |
+
<type>singleton</type>
|
85 |
+
<class>loginnotifier/observer</class>
|
86 |
+
<method>successLogin</method>
|
87 |
+
</loginnotifier_success>
|
88 |
+
</observers>
|
89 |
+
</admin_session_user_login_success>
|
90 |
+
<admin_session_user_login_failed>
|
91 |
+
<observers>
|
92 |
+
<loginnotifier_failed>
|
93 |
+
<type>singleton</type>
|
94 |
+
<class>loginnotifier/observer</class>
|
95 |
+
<method>failedLogin</method>
|
96 |
+
</loginnotifier_failed>
|
97 |
+
</observers>
|
98 |
+
</admin_session_user_login_failed>
|
99 |
+
</events>
|
100 |
<menu>
|
101 |
<report>
|
102 |
<children>
|
app/design/adminhtml/default/default/layout/loginnotifier.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout version="0.1.0">
|
3 |
+
<loginnotifier_adminhtml_report_index>
|
4 |
+
<reference name="content">
|
5 |
+
<block type="loginnotifier/adminhtml_report" name="report" />
|
6 |
+
</reference>
|
7 |
+
</loginnotifier_adminhtml_report_index>
|
8 |
+
</layout>
|
app/etc/modules/Webmu_LoginNotifier.xml
CHANGED
@@ -4,7 +4,6 @@
|
|
4 |
<Webmu_LoginNotifier>
|
5 |
<active>true</active>
|
6 |
<codePool>community</codePool>
|
7 |
-
<version>0.1.0</version>
|
8 |
</Webmu_LoginNotifier>
|
9 |
</modules>
|
10 |
</config>
|
4 |
<Webmu_LoginNotifier>
|
5 |
<active>true</active>
|
6 |
<codePool>community</codePool>
|
|
|
7 |
</Webmu_LoginNotifier>
|
8 |
</modules>
|
9 |
</config>
|
app/locale/en_US/template/email/loginnotifier_notificationemail_failed.html
CHANGED
@@ -21,6 +21,9 @@
|
|
21 |
<strong>Dear Administrator</strong>,<br/>
|
22 |
<br />
|
23 |
we inform you that the <strong>{{var date}}</strong> at <strong>{{var hour}}</strong> has been made an attempt to login to the username <strong>{{var username}}</strong> from IP <b>{{var ip}}</b>.
|
|
|
|
|
|
|
24 |
</p>
|
25 |
</td>
|
26 |
</tr>
|
21 |
<strong>Dear Administrator</strong>,<br/>
|
22 |
<br />
|
23 |
we inform you that the <strong>{{var date}}</strong> at <strong>{{var hour}}</strong> has been made an attempt to login to the username <strong>{{var username}}</strong> from IP <b>{{var ip}}</b>.
|
24 |
+
<br />
|
25 |
+
<br />
|
26 |
+
<strong>Magento Url</strong>: {{var base_url}}
|
27 |
</p>
|
28 |
</td>
|
29 |
</tr>
|
app/locale/en_US/template/email/loginnotifier_notificationemail_success.html
CHANGED
@@ -21,6 +21,9 @@
|
|
21 |
<strong>Dear Administrator</strong>,<br/>
|
22 |
<br />
|
23 |
we inform you that the <strong>{{var date}}</strong> at <strong>{{var hour}}</strong> was made access to the username <strong>{{var username}}</strong> from IP <b>{{var ip}}</b>.
|
|
|
|
|
|
|
24 |
</p>
|
25 |
</td>
|
26 |
</tr>
|
21 |
<strong>Dear Administrator</strong>,<br/>
|
22 |
<br />
|
23 |
we inform you that the <strong>{{var date}}</strong> at <strong>{{var hour}}</strong> was made access to the username <strong>{{var username}}</strong> from IP <b>{{var ip}}</b>.
|
24 |
+
<br />
|
25 |
+
<br />
|
26 |
+
<strong>Magento Url</strong>: {{var base_url}}
|
27 |
</p>
|
28 |
</td>
|
29 |
</tr>
|
package.xml
CHANGED
@@ -1,26 +1,33 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Webmu_LoginNotifier</name>
|
4 |
-
<version>0.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
-
<summary>Login Notifier will send a mail
|
10 |
-
<description>Sends an email with useful data to the administrator each time a user successfully logs in or fails to connect.
|
11 |

|
12 |
-
The purpose of this plugin consists in improving the security of a Magento backend.
|
13 |

|
14 |
When a user logs in successfully the extensions sends an email to the administrator with the date, user name, IP address and store all data into database.
|
15 |

|
16 |
-
A Login Report is available on Reports menu in Magento Admin Panel
|
|
|
|
|
17 |
<notes>Release notes:
|
18 |

|
19 |
-
0.
|
|
|
|
|
|
|
|
|
|
|
20 |
<authors><author><name>Webmu</name><user>webmu</user><email>info@webmu.it</email></author></authors>
|
21 |
-
<date>2016-02-
|
22 |
-
<time>
|
23 |
-
<contents><target name="magecommunity"><dir name="Webmu"><dir name="LoginNotifier"><dir name="Block"><dir name="Adminhtml"><dir name="Report"><file name="Grid.php" hash="
|
24 |
<compatible/>
|
25 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
26 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Webmu_LoginNotifier</name>
|
4 |
+
<version>0.2.0</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
+
<summary>Login Notifier will send a mail if anyone reaches or attempts to login to the Magento Backend.</summary>
|
10 |
+
<description>Sends an email with useful data to the administrator each time a user successfully logs in or fails to connect to the Magento Backend.
|
11 |

|
12 |
+
The purpose of this plugin consists in improving the security of a Magento backend. If someone attempts to login, it will also send the user name they tried logging in with, as well as their IP address, User-Agent, Timestamp, and the Referral URL.
|
13 |

|
14 |
When a user logs in successfully the extensions sends an email to the administrator with the date, user name, IP address and store all data into database.
|
15 |

|
16 |
+
A Login Report is available on Reports menu in Magento Admin Panel.
|
17 |
+

|
18 |
+
If you see multiple attempts to login at times you are not logged on to the site, this means someone is attempting to brute force their way into your site, and you should ban the offending IP address from your site. Especially if they are trying multiple names, or sending them rapidly, one after another.</description>
|
19 |
<notes>Release notes:
|
20 |

|
21 |
+
v. 0.2.0
|
22 |
+
- Grid with custom cells rendering
|
23 |
+
- Used the Event Observer Methods for custom actions
|
24 |
+

|
25 |
+
v. 0.1.0
|
26 |
+
- initial public release of Login Notifier</notes>
|
27 |
<authors><author><name>Webmu</name><user>webmu</user><email>info@webmu.it</email></author></authors>
|
28 |
+
<date>2016-02-03</date>
|
29 |
+
<time>11:14:23</time>
|
30 |
+
<contents><target name="magecommunity"><dir name="Webmu"><dir name="LoginNotifier"><dir name="Block"><dir name="Adminhtml"><dir name="Report"><file name="Grid.php" hash="1686ae5de8b408ac5af7f3b0b4d94842"/><dir name="Renderer"><file name="Created.php" hash="b3e5a03f8a0918992fd0a36c5e6b238b"/><file name="Info.php" hash="2177c4d89ea2cdd9c7d698f65d93dc13"/><file name="Result.php" hash="1b4e3bb2537621412e35c55f0982531e"/></dir></dir><file name="Report.php" hash="1447817f2ecf54a3a8edf576fb7c8dd8"/></dir></dir><dir name="Helper"><file name="Data.php" hash="8c064319279e925427261fa1e23cd9f8"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Report"><file name="Collection.php" hash="798f9f6277fe8cbe9e62138f24afce3b"/></dir><file name="Report.php" hash="a514d8ed7d920cb9dbb830864894fc91"/></dir><file name="Observer.php" hash="9a340e8675b622e2df7ec66fd3faaaa7"/><file name="Report.php" hash="bf80985e5de55e8b1796190edf4fca1b"/><file name="ResultOption.php" hash="50eb871000d878fb9c0df6ba8809ad75"/><dir name="System"><dir name="Config"><dir name="Source"><dir name="General"><file name="Option.php" hash="dbece10127ac2faf0b581b6b5a3066e9"/></dir></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="ReportController.php" hash="884f7ec59c7948e839caca36943b5429"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="3b6b78f4be94b9f63ca0405ea233e241"/><file name="config.xml" hash="4baa83137db18ebeda7ee5ba7d7dd286"/><file name="system.xml" hash="04b7c6c9e6ed6c9929f4fe46f5d1446e"/></dir><dir name="sql"><dir name="loginnotifier_setup"><file name="mysql4-install-0.1.0.php" hash="105c2a3fbf42e2ddd4a28a714336ed50"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Webmu_LoginNotifier.xml" hash="fba4a225627793ada87cc4c1a42da5f9"/></dir></target><target name="magelocale"><dir name="en_US"><dir name="template"><dir name="email"><file name="loginnotifier_notificationemail_failed.html" hash="c033f69b1171c38dff572d2416379d7b"/><file name="loginnotifier_notificationemail_success.html" hash="9f00e8d92c2f3977bed3d5897ea3f812"/></dir></dir><file name="Webmu_LoginNotifier.csv" hash="9d10578f91f7a213f21b1c1d5cec599a"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="loginnotifier.xml" hash="377b33e835ebe58438938abad96e38e1"/></dir></dir></dir></dir></target></contents>
|
31 |
<compatible/>
|
32 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
33 |
</package>
|