Skip to content

Commit 1849c15

Browse files
Merge pull request #28 from nexcess/devel
Devel
2 parents d643065 + c34a60f commit 1849c15

File tree

12 files changed

+593
-13
lines changed

12 files changed

+593
-13
lines changed

CHANGELOG.md

Whitespace-only changes.

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
SHELL := /bin/bash
2+
.PHONY: connect-desc connect-pkg all clean
3+
4+
connect-desc:
5+
grep -v 'Build Status' README.md | markdown_py -o html5 -f "build/magento-connect-desc-$(shell ./util/get-version.sh).html"
6+
7+
connect-changelog:
8+
markdown_py -o html5 -f "build/magento-connect-changelog-$(shell ./util/get-version.sh).html" CHANGELOG.md
9+
10+
connect-pkg:
11+
./build/build_package.py -d build/mage-package.xml
12+
13+
all: connect-desc connect-changelog connect-pkg
14+
15+
clean:
16+
rm -f ./build/*.tgz ./build/*.html ./package.xml

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ to the **devel** branch. The *master* branch is only for stable releases. Please
4040
make sure the new code follows the same style and conventions as already written
4141
code.
4242

43-
### Referanced work
43+
### Referenced work
4444

4545
Some code based on previous work by Jonathan Day [email protected]
4646
- https://github.com/magento-hackathon/Magento-Two-factor-Authentication
@@ -51,7 +51,7 @@ Some code based on previous work by Michael Kliewe/PHPGangsta
5151

5252
----
5353
### Notes -
54-
1. Installing this module will update the AdminUser table in the Magento database to add a twofactor_google_secret
54+
1. Installing this module will update the admin_user table in the Magento database to add a twofactor_google_secret
5555
field for storing the local GA key. It is safe to remove this field once the module is removed.
5656
1. If you get locked out of admin because of a settings issue, loss of your provider account or other software related issue, you can *temporarily disable* the second factor authentication -
5757
- Place a file named __tfaoff.flag__ in the root directory of your Magento installation.

app/code/community/HE/TwoFactorAuth/Helper/Data.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function __construct()
1818
$this->_provider = Mage::getStoreConfig('he2faconfig/control/provider');
1919
$this->_logging = Mage::getStoreConfig('he2faconfig/control/logging');
2020
$this->_logAccess = Mage::getStoreConfig('he2faconfig/control/logaccess');
21+
$this->_ipWhitelist = $this->getIPWhitelist();
2122
}
2223

2324
public function isDisabled()
@@ -66,4 +67,33 @@ public function disable2FA()
6667
Mage::getModel('core/config')->saveConfig('he2faconfig/control/provider', 'disabled');
6768
Mage::app()->getStore()->resetConfig();
6869
}
70+
71+
private function getIPWhitelist()
72+
{
73+
$return = [];
74+
$ips = preg_split("/\r\n|\n|\r/", trim(Mage::getStoreConfig('he2faconfig/control/ipwhitelist')));
75+
foreach ($ips as $ip) {
76+
if (filter_var($ip, FILTER_VALIDATE_IP)) {
77+
$return[] = trim($ip);
78+
}
79+
}
80+
return $return;
81+
}
82+
83+
84+
public function inWhitelist($ip)
85+
{
86+
if (count($this->_ipWhitelist) == 0) { return false; }
87+
88+
if (in_array( $ip, $this->_ipWhitelist )) {
89+
if ( $this->shouldLogAccess() ) {
90+
Mage::log("TFA bypassed for IP $ip - whitelisted", 0, "two_factor_auth.log");
91+
}
92+
return true;
93+
}
94+
else {
95+
return false;
96+
}
97+
}
98+
6999
}

app/code/community/HE/TwoFactorAuth/Model/Observer.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class HE_TwoFactorAuth_Model_Observer
1717
{
18-
protected $_allowedActions = array('login', 'forgotpassword');
18+
protected $_allowedActions = array('login', 'forgotpassword', 'resetpassword', 'resetpasswordpost');
1919

2020
public function __construct()
2121
{
@@ -28,6 +28,11 @@ public function admin_user_authenticate_after($observer)
2828
return;
2929
}
3030

31+
// check ip-whitelist
32+
if (Mage::helper('he_twofactorauth')->inWhitelist( Mage::helper('core/http')->getRemoteAddr() )) {
33+
Mage::getSingleton('admin/session')->set2faState(HE_TwoFactorAuth_Model_Validate::TFA_STATE_ACTIVE);
34+
}
35+
3136
if (Mage::getSingleton('admin/session')->get2faState() != HE_TwoFactorAuth_Model_Validate::TFA_STATE_ACTIVE) {
3237

3338
if ($this->_shouldLog) {
@@ -211,9 +216,7 @@ public function googleSaveClear(Varien_Event_Observer $observer)
211216
// check that a user record has been saved
212217

213218
// if google is turned and 2fa active...
214-
if ((Mage::helper('he_twofactorauth')->getProvider() == 'google')
215-
&& (!Mage::helper('he_twofactorauth')->isDisabled())
216-
) {
219+
if (Mage::helper('he_twofactorauth')->getProvider() == 'google') {
217220
$params = Mage::app()->getRequest()->getParams();
218221
if (isset($params['clear_google_secret'])) {
219222
if ($params['clear_google_secret'] == 1) {
@@ -228,4 +231,4 @@ public function googleSaveClear(Varien_Event_Observer $observer)
228231
}
229232
}
230233
}
231-
}
234+
}

app/code/community/HE/TwoFactorAuth/controllers/Adminhtml/TwofactorController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ public function _construct()
2727
parent::_construct();
2828
}
2929

30+
/**
31+
* Allow all admin users to access the 2fa forms
32+
*/
33+
protected function _isAllowed()
34+
{
35+
return true;
36+
}
37+
3038
//need an action per provider so that we can load the correct 2fa form
3139

3240
public function duoAction()

app/code/community/HE/TwoFactorAuth/etc/config.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
</helpers>
2828

2929
<events>
30-
<controller_action_postdispatch_adminhtml>
30+
<controller_action_predispatch_adminhtml>
3131
<observers>
3232
<he_twofactorauth_observer_check>
3333
<type>singleton</type>
3434
<class>he_twofactorauth/observer</class>
3535
<method>check_twofactor_active</method>
3636
</he_twofactorauth_observer_check>
3737
</observers>
38-
</controller_action_postdispatch_adminhtml>
38+
</controller_action_predispatch_adminhtml>
3939
</events>
4040

4141
<resources>
@@ -132,8 +132,8 @@
132132
<he2falinks>
133133
<human-element-link>http://www.human-element.com</human-element-link>
134134
<nexcess-link>https://www.nexcess.net</nexcess-link>
135-
<docs-link>http://www.human-element.com/sentry-two-factor-authentication-documentation</docs-link>
136-
<submit-bug-link>http://www.human-element.com/sentry-two-factor-authentication-documentation#bugs</submit-bug-link>
135+
<docs-link>https://github.com/nexcess/magento-sentry-two-factor-authentication/wiki</docs-link>
136+
<submit-bug-link>https://github.com/nexcess/magento-sentry-two-factor-authentication/issues</submit-bug-link>
137137
<multi-auth-link>http://en.wikipedia.org/wiki/Multi-factor_authentication</multi-auth-link>
138138
<mage-support-link>http://www.human-element.com/magento-support-page</mage-support-link>
139139
<contact-link>http://www.human-element.com/contact/#contact-form</contact-link>
@@ -160,4 +160,4 @@
160160
</control>
161161
</he2faconfig>
162162
</default>
163-
</config>
163+
</config>

app/code/community/HE/TwoFactorAuth/etc/system.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@
4747
</comment>
4848
</provider>
4949

50+
<ipwhitelist>
51+
<label>Whitelisted IP Addresses</label>
52+
<frontend_type>textarea</frontend_type>
53+
<sort_order>15</sort_order>
54+
<show_in_default>1</show_in_default>
55+
<show_in_website>1</show_in_website>
56+
<comment>
57+
<![CDATA[
58+
You may whitelist IP addresses here (one per line). Anyone logging in from a whitelisted IP will not be required to perform two-factor authentication.
59+
]]>
60+
</comment>
61+
</ipwhitelist>
62+
5063
<logaccess>
5164
<label>Enable access logging</label>
5265
<frontend_type>select</frontend_type>

app/design/adminhtml/default/default/template/he_twofactor/google/auth.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<link rel="icon" href="<?php echo $this->getSkinUrl('favicon.ico'); ?>" type="image/x-icon" />
5656
<link rel="shortcut icon" href="<?php echo $this->getSkinUrl('favicon.ico'); ?>" type="image/x-icon" />
5757

58-
<script type="text/javascript" src="<?php echo $this->getJsUrl(); ?>index.php/x.js?f=prototype/prototype.js,prototype/validation.js,mage/adminhtml/events.js,mage/adminhtml/form.js,scriptaculous/effects.js"></script>
58+
<script type="text/javascript" src="<?php echo $this->getJsUrl(); ?>index.php/x.js?c=auto&f=prototype/prototype.js,prototype/validation.js,mage/adminhtml/events.js,mage/adminhtml/form.js,scriptaculous/effects.js"></script>
5959
<script type="text/javascript" src="<?php echo $this->getJsUrl('mage/captcha.js') ?>"></script>
6060

6161
<!--[if IE]> <link rel="stylesheet" href="<?php echo $this->getSkinUrl('iestyles.css'); ?>" type="text/css" media="all" /> <![endif]-->

0 commit comments

Comments
 (0)