Webmu_LoginNotifier - Version 0.1.0

Version Notes

Release notes:

0.1.0 - initial public release of Login Notifier

Download this release

Release Info

Developer Webmu
Extension Webmu_LoginNotifier
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/community/Webmu/LoginNotifier/Block/Adminhtml/Report.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 extends Mage_Adminhtml_Block_Widget_Grid_Container{
20
+
21
+ public function __construct()
22
+ {
23
+ $this->_controller = "adminhtml_report";
24
+ $this->_blockGroup = "loginnotifier";
25
+ $this->_headerText = Mage::helper("loginnotifier")->__("Report Backend Login");
26
+ $this->_addButtonLabel = Mage::helper("loginnotifier")->__("Add New Item");
27
+
28
+ parent::__construct();
29
+ $this->_removeButton('add');
30
+ }
31
+
32
+ }
app/code/community/Webmu/LoginNotifier/Block/Adminhtml/Report/Grid.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Grid extends Mage_Adminhtml_Block_Widget_Grid
20
+ {
21
+ public function __construct()
22
+ {
23
+ parent::__construct();
24
+ $this->setId("reportGrid");
25
+ $this->setDefaultSort("created");
26
+ $this->setDefaultDir("DESC");
27
+ $this->setSaveParametersInSession(true);
28
+ }
29
+
30
+ protected function _prepareCollection()
31
+ {
32
+ $collection = Mage::getModel("loginnotifier/report")->getCollection();
33
+ $this->setCollection($collection);
34
+ return parent::_prepareCollection();
35
+ }
36
+
37
+ protected function _prepareColumns()
38
+ {
39
+ $this->addColumn("created", array(
40
+ "header" => Mage::helper("loginnotifier")->__("Created on"),
41
+ "align" =>"left",
42
+ "width" => "150px",
43
+ "type" => "datetime",
44
+ "index" => "created",
45
+ ));
46
+
47
+ $this->addColumn("ip", array(
48
+ "header" => Mage::helper("loginnotifier")->__("IP address"),
49
+ "align" =>"right",
50
+ "index" => "ip",
51
+ ));
52
+
53
+ $this->addColumn("username", array(
54
+ "header" => Mage::helper("loginnotifier")->__("Username"),
55
+ "index" => "username",
56
+ ));
57
+
58
+ $this->addColumn("user_agent", array(
59
+ "header" => Mage::helper("loginnotifier")->__("User agent"),
60
+ "index" => "user_agent",
61
+ ));
62
+
63
+ $this->addColumn("http_referer", array(
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'));
78
+ $this->addExportType('*/*/exportExcel', Mage::helper('sales')->__('Excel'));
79
+
80
+ return parent::_prepareColumns();
81
+ }
82
+
83
+ public function getRowUrl($row)
84
+ {
85
+ return false;
86
+ }
87
+ }
app/code/community/Webmu/LoginNotifier/Helper/Data.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Helper_Data extends Mage_Core_Helper_Abstract
20
+ {
21
+ }
22
+
app/code/community/Webmu/LoginNotifier/Model/Admin/Session.php ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/Mysql4/Report.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Mysql4_Report extends Mage_Core_Model_Mysql4_Abstract
20
+ {
21
+ protected function _construct()
22
+ {
23
+ $this->_init("loginnotifier/report", "id");
24
+ }
25
+ }
app/code/community/Webmu/LoginNotifier/Model/Mysql4/Report/Collection.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Mysql4_Report_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
20
+ {
21
+
22
+ public function _construct(){
23
+ $this->_init("loginnotifier/report");
24
+ }
25
+ }
app/code/community/Webmu/LoginNotifier/Model/Report.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_Model_Report extends Mage_Core_Model_Abstract
20
+ {
21
+ protected function _construct(){
22
+
23
+ $this->_init("loginnotifier/report");
24
+
25
+ }
26
+
27
+ }
28
+
app/code/community/Webmu/LoginNotifier/Model/ResultOption.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_ResultOption extends Varien_Object
20
+ {
21
+ public function toOptionArray(){
22
+
23
+ $options = array(
24
+ 0 => Mage::helper('loginnotifier')->__('Failed'),
25
+ 1 => Mage::helper('loginnotifier')->__('Success'),
26
+ );
27
+ return $options;
28
+ }
29
+ }
app/code/community/Webmu/LoginNotifier/Model/System/Config/Source/General/Option.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_System_Config_Source_General_Option extends Varien_Object
20
+ {
21
+ public function toOptionArray()
22
+ {
23
+ $options = array(
24
+ "disabled" => Mage::helper('loginnotifier')->__('Disabled'),
25
+ "enabled" => Mage::helper('loginnotifier')->__('Enabled'),
26
+ );
27
+ return $options;
28
+ }
29
+ }
app/code/community/Webmu/LoginNotifier/controllers/Adminhtml/ReportController.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Adminhtml_ReportController extends Mage_Adminhtml_Controller_Action
20
+ {
21
+ protected function _initAction()
22
+ {
23
+ $this->loadLayout()->_setActiveMenu("loginnotifier/report")->_addBreadcrumb(Mage::helper("adminhtml")->__("Report Backend Login"), Mage::helper("adminhtml")->__("Report Backend Login"));
24
+ return $this;
25
+ }
26
+
27
+ public function indexAction()
28
+ {
29
+ $this->_title($this->__("LoginNotifier"));
30
+ $this->_title($this->__("Report Backend Login"));
31
+
32
+ $this->_initAction();
33
+ $this->renderLayout();
34
+ }
35
+
36
+ /**
37
+ * Export order grid to CSV format
38
+ */
39
+ public function exportCsvAction()
40
+ {
41
+ $fileName = 'report.csv';
42
+ $grid = $this->getLayout()->createBlock('loginnotifier/adminhtml_report_grid');
43
+ $this->_prepareDownloadResponse($fileName, $grid->getCsvFile());
44
+ }
45
+ /**
46
+ * Export order grid to Excel XML format
47
+ */
48
+ public function exportExcelAction()
49
+ {
50
+ $fileName = 'report.xml';
51
+ $grid = $this->getLayout()->createBlock('loginnotifier/adminhtml_report_grid');
52
+ $this->_prepareDownloadResponse($fileName, $grid->getExcelFile($fileName));
53
+ }
54
+ }
app/code/community/Webmu/LoginNotifier/etc/adminhtml.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <admin>
6
+ <children>
7
+ <system>
8
+ <children>
9
+ <config>
10
+ <children>
11
+ <loginnotifier translate="title" module="loginnotifier">
12
+ <title>Login Notifier Section</title>
13
+ <sort_order>0</sort_order>
14
+ </loginnotifier>
15
+ </children>
16
+ </config>
17
+ </children>
18
+ </system>
19
+ </children>
20
+ </admin>
21
+ </resources>
22
+ </acl>
23
+ </config>
app/code/community/Webmu/LoginNotifier/etc/config.xml ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Webmu_LoginNotifier>
5
+ <version>0.1.0</version>
6
+ </Webmu_LoginNotifier>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <loginnotifier>
11
+ <class>Webmu_LoginNotifier_Helper</class>
12
+ </loginnotifier>
13
+ </helpers>
14
+ <blocks>
15
+ <loginnotifier>
16
+ <class>Webmu_LoginNotifier_Block</class>
17
+ </loginnotifier>
18
+ </blocks>
19
+ <models>
20
+ <loginnotifier>
21
+ <class>Webmu_LoginNotifier_Model</class>
22
+ <resourceModel>loginnotifier_mysql4</resourceModel>
23
+ </loginnotifier>
24
+ <loginnotifier_mysql4>
25
+ <class>Webmu_LoginNotifier_Model_Mysql4</class>
26
+ <entities>
27
+ <report>
28
+ <table>webmu_loginnotifier</table>
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>
40
+ <setup>
41
+ <module>Webmu_LoginNotifier</module>
42
+ </setup>
43
+ <connection>
44
+ <use>core_setup</use>
45
+ </connection>
46
+ </loginnotifier_setup>
47
+ <loginnotifier_write>
48
+ <connection>
49
+ <use>core_write</use>
50
+ </connection>
51
+ </loginnotifier_write>
52
+ <loginnotifier_read>
53
+ <connection>
54
+ <use>core_read</use>
55
+ </connection>
56
+ </loginnotifier_read>
57
+ </resources>
58
+ <template>
59
+ <email>
60
+ <loginnotifier_notificationemail_success>
61
+ <label>LoginNotifier success login email</label>
62
+ <file>loginnotifier_notificationemail_success.html</file>
63
+ <type>html</type>
64
+ </loginnotifier_notificationemail_success>
65
+ <loginnotifier_notificationemail_failed>
66
+ <label>LoginNotifier failed login email</label>
67
+ <file>loginnotifier_notificationemail_failed.html</file>
68
+ <type>html</type>
69
+ </loginnotifier_notificationemail_failed>
70
+ </email>
71
+ </template>
72
+ </global>
73
+ <admin>
74
+ <routers>
75
+ <loginnotifier>
76
+ <use>admin</use>
77
+ <args>
78
+ <module>Webmu_LoginNotifier</module>
79
+ <frontName>admin_loginnotifier</frontName>
80
+ </args>
81
+ </loginnotifier>
82
+ </routers>
83
+ </admin>
84
+ <adminhtml>
85
+ <menu>
86
+ <report>
87
+ <children>
88
+ <loginnotifier translate="title" module="loginnotifier">
89
+ <title>Backend Login</title>
90
+ <sort_order>0</sort_order>
91
+ <action>admin_loginnotifier/adminhtml_report</action>
92
+ </loginnotifier>
93
+ </children>
94
+ </report>
95
+ </menu>
96
+ <acl>
97
+ <resources>
98
+ <all>
99
+ <title>Allow Everything</title>
100
+ </all>
101
+ <admin>
102
+ <children>
103
+ <loginnotifier translate="title" module="loginnotifier">
104
+ <title>LoginNotifier</title>
105
+ <sort_order>1000</sort_order>
106
+ <children>
107
+ <report translate="title">
108
+ <title>Backend Login</title>
109
+ <sort_order>0</sort_order>
110
+ </report>
111
+ </children>
112
+ </loginnotifier>
113
+ </children>
114
+ </admin>
115
+ </resources>
116
+ </acl>
117
+ <translate>
118
+ <modules>
119
+ <Webmu_LoginNotifier>
120
+ <files>
121
+ <default>Webmu_LoginNotifier.csv</default>
122
+ </files>
123
+ </Webmu_LoginNotifier>
124
+ </modules>
125
+ </translate>
126
+ <layout>
127
+ <updates>
128
+ <loginnotifier>
129
+ <file>loginnotifier.xml</file>
130
+ </loginnotifier>
131
+ </updates>
132
+ </layout>
133
+ </adminhtml>
134
+ </config>
app/code/community/Webmu/LoginNotifier/etc/system.xml ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <webmu translate="label" module="loginnotifier">
5
+ <label>WEBMU EXTENSIONS</label>
6
+ <sort_order>1600</sort_order>
7
+ </webmu>
8
+ </tabs>
9
+ <sections>
10
+ <loginnotifier module="loginnotifier" translate="label">
11
+ <class>separator-top</class>
12
+ <label>Login Notifier</label>
13
+ <tab>webmu</tab>
14
+ <frontend_type>text</frontend_type>
15
+ <sort_order>1110</sort_order>
16
+ <show_in_default>1</show_in_default>
17
+ <show_in_website>0</show_in_website>
18
+ <show_in_store>0</show_in_store>
19
+ <groups>
20
+ <success module="loginnotifier" translate="label">
21
+ <label>Success Notification Settings</label>
22
+ <frontend_type>text</frontend_type>
23
+ <sort_order>10</sort_order>
24
+ <expanded>1</expanded>
25
+ <show_in_default>1</show_in_default>
26
+ <show_in_website>1</show_in_website>
27
+ <show_in_store>1</show_in_store>
28
+ <fields>
29
+ <general_success_login translate="label">
30
+ <label>Notify Success Login</label>
31
+ <frontend_type>select</frontend_type>
32
+ <source_model>loginnotifier/system_config_source_general_option</source_model>
33
+ <sort_order>1</sort_order>
34
+ <show_in_default>1</show_in_default>
35
+ <show_in_website>0</show_in_website>
36
+ <show_in_store>0</show_in_store>
37
+ </general_success_login>
38
+ <general_success_login_email translate="label">
39
+ <label>Send Notification Email To</label>
40
+ <comment>Comma-separated.</comment>
41
+ <frontend_type>text</frontend_type>
42
+ <sort_order>5</sort_order>
43
+ <show_in_default>1</show_in_default>
44
+ <show_in_website>0</show_in_website>
45
+ <show_in_store>0</show_in_store>
46
+ <depends>
47
+ <general_success_login>enabled</general_success_login>
48
+ </depends>
49
+ <validate>required-entry</validate>
50
+ </general_success_login_email>
51
+ </fields>
52
+ </success>
53
+ <failed module="loginnotifier" translate="label">
54
+ <label>Failed Notification Settings</label>
55
+ <frontend_type>text</frontend_type>
56
+ <sort_order>20</sort_order>
57
+ <expanded>1</expanded>
58
+ <show_in_default>1</show_in_default>
59
+ <show_in_website>1</show_in_website>
60
+ <show_in_store>1</show_in_store>
61
+ <fields>
62
+ <general_failed_login translate="label">
63
+ <label>Notify Failed Login</label>
64
+ <frontend_type>select</frontend_type>
65
+ <source_model>loginnotifier/system_config_source_general_option</source_model>
66
+ <sort_order>1</sort_order>
67
+ <show_in_default>1</show_in_default>
68
+ <show_in_website>0</show_in_website>
69
+ <show_in_store>0</show_in_store>
70
+ </general_failed_login>
71
+ <general_failed_login_email translate="label">
72
+ <label>Send Notification Email To</label>
73
+ <comment>Comma-separated.</comment>
74
+ <frontend_type>text</frontend_type>
75
+ <sort_order>5</sort_order>
76
+ <show_in_default>1</show_in_default>
77
+ <show_in_website>0</show_in_website>
78
+ <show_in_store>0</show_in_store>
79
+ <depends>
80
+ <general_failed_login>enabled</general_failed_login>
81
+ </depends>
82
+ <validate>required-entry</validate>
83
+ </general_failed_login_email>
84
+ </fields>
85
+ </failed>
86
+ </groups>
87
+ </loginnotifier>
88
+ </sections>
89
+ </config>
app/code/community/Webmu/LoginNotifier/sql/loginnotifier_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
20
+ $installer = $this;
21
+ $installer->startSetup();
22
+ $sql=<<<SQLTEXT
23
+ CREATE TABLE IF NOT EXISTS `webmu_loginnotifier` (
24
+ `id` int(11) NOT NULL,
25
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
26
+ `username` varchar(100) NOT NULL,
27
+ `ip` varchar(20) NOT NULL,
28
+ `user_agent` varchar(255) NOT NULL,
29
+ `http_referer` varchar(255) NOT NULL,
30
+ `result` int(1) NOT NULL
31
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
32
+
33
+ --
34
+ -- Indexes for dumped tables
35
+ --
36
+
37
+ --
38
+ -- Indexes for table `webmu_loginnotifier`
39
+ --
40
+ ALTER TABLE `webmu_loginnotifier`
41
+ ADD PRIMARY KEY (`id`), ADD KEY `result` (`result`);
42
+
43
+ --
44
+ -- AUTO_INCREMENT for dumped tables
45
+ --
46
+
47
+ --
48
+ -- AUTO_INCREMENT for table `webmu_loginnotifier`
49
+ --
50
+ ALTER TABLE `webmu_loginnotifier`
51
+ MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
52
+
53
+ SQLTEXT;
54
+
55
+ $installer->run($sql);
56
+ $installer->endSetup();
57
+
app/etc/modules/Webmu_LoginNotifier.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Webmu_LoginNotifier>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <version>0.1.0</version>
8
+ </Webmu_LoginNotifier>
9
+ </modules>
10
+ </config>
app/locale/en_US/Webmu_LoginNotifier.csv ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Backend Login","Backend Login"
2
+ "Report Backend Login","Report Backend Login"
3
+ "Created on","Created on"
4
+ "IP Address","IP Address",
5
+ "Username","Username"
6
+ "User agent","User agent"
7
+ "Referer","Referer"
8
+ "Result","Result"
9
+ "Failed","Failed"
10
+ "Success","Success"
11
+ "Disabled","Disabled"
12
+ "Enabled","Enabled"
app/locale/en_US/template/email/loginnotifier_notificationemail_failed.html ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--@subject ALERT: Failed login Notification Magento @-->
2
+ <div style="font:11px/1.35em Verdana, Arial, Helvetica, sans-serif;">
3
+ <table cellspacing="0" cellpadding="0" border="0" width="98%" style="margin-top:10px; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; margin-bottom:10px;">
4
+ <tr>
5
+ <td align="center" valign="top">
6
+ <!-- [ header starts here] -->
7
+ <table cellspacing="0" cellpadding="0" border="0" width="650">
8
+ <tr>
9
+ <td valign="top">
10
+ <p>
11
+ <a href="{{store url=""}}" style="color:#1E7EC8;"><img src="{{skin url="images/logo_email.gif" _area='frontend'}}" alt="Magento" border="0"/></a>
12
+ </p>
13
+ </td>
14
+ </tr>
15
+ </table>
16
+ <!-- [ middle starts here] -->
17
+ <table cellspacing="0" cellpadding="0" border="0" width="650">
18
+ <tr>
19
+ <td valign="top">
20
+ <p>
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>
27
+ </table>
28
+ </td>
29
+ </tr>
30
+ </table>
31
+ </div>
app/locale/en_US/template/email/loginnotifier_notificationemail_success.html ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--@subject NOTICE: Success login Notification Magento @-->
2
+ <div style="font:11px/1.35em Verdana, Arial, Helvetica, sans-serif;">
3
+ <table cellspacing="0" cellpadding="0" border="0" width="98%" style="margin-top:10px; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; margin-bottom:10px;">
4
+ <tr>
5
+ <td align="center" valign="top">
6
+ <!-- [ header starts here] -->
7
+ <table cellspacing="0" cellpadding="0" border="0" width="650">
8
+ <tr>
9
+ <td valign="top">
10
+ <p>
11
+ <a href="{{store url=""}}" style="color:#1E7EC8;"><img src="{{skin url="images/logo_email.gif" _area='frontend'}}" alt="Magento" border="0"/></a>
12
+ </p>
13
+ </td>
14
+ </tr>
15
+ </table>
16
+ <!-- [ middle starts here] -->
17
+ <table cellspacing="0" cellpadding="0" border="0" width="650">
18
+ <tr>
19
+ <td valign="top">
20
+ <p>
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>
27
+ </table>
28
+ </td>
29
+ </tr>
30
+ </table>
31
+ </div>
package.xml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Webmu_LoginNotifier</name>
4
+ <version>0.1.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 whenever someone logs in 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.&#xD;
11
+ &#xD;
12
+ The purpose of this plugin consists in improving the security of a Magento backend.&#xD;
13
+ &#xD;
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.&#xD;
15
+ &#xD;
16
+ A Login Report is available on Reports menu in Magento Admin Panel.</description>
17
+ <notes>Release notes:&#xD;
18
+ &#xD;
19
+ 0.1.0 - initial public release of Login Notifier</notes>
20
+ <authors><author><name>Webmu</name><user>webmu</user><email>info@webmu.it</email></author></authors>
21
+ <date>2016-02-01</date>
22
+ <time>09:37:51</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="025dff85a672824af43ec58124aba5ab"/></dir><file name="Report.php" hash="1447817f2ecf54a3a8edf576fb7c8dd8"/></dir></dir><dir name="Helper"><file name="Data.php" hash="8c064319279e925427261fa1e23cd9f8"/></dir><dir name="Model"><dir name="Admin"><file name="Session.php" hash="06efeddb8fc0a1a3e0bcc7c725a0061e"/></dir><dir name="Mysql4"><dir name="Report"><file name="Collection.php" hash="798f9f6277fe8cbe9e62138f24afce3b"/></dir><file name="Report.php" hash="a514d8ed7d920cb9dbb830864894fc91"/></dir><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="b727541719f958d9c847b77205928068"/><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="60f9b8fda882b07a373e068dbda6b6e8"/></dir></target><target name="magelocale"><dir name="en_US"><dir name="template"><dir name="email"><file name="loginnotifier_notificationemail_failed.html" hash="5ba49621b2b51205affd85696da01521"/><file name="loginnotifier_notificationemail_success.html" hash="870e9f04ce48a5f2e2a4b7aabaf929fc"/></dir></dir><file name="Webmu_LoginNotifier.csv" hash="9d10578f91f7a213f21b1c1d5cec599a"/></dir></target></contents>
24
+ <compatible/>
25
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
26
+ </package>