Version Notes
stable release
Download this release
Release Info
| Developer | Jurij |
| Extension | ET_IpSecurity |
| Version | 2.3.0 |
| Comparing to | |
| See all releases | |
Code changes from version 2.2.0 to 2.3.0
app/code/community/ET/IpSecurity/Model/IpVariable.php
CHANGED
|
@@ -20,13 +20,16 @@
|
|
| 20 |
/**
|
| 21 |
* Class ET_IpSecurity_Model_IpVariable
|
| 22 |
*/
|
| 23 |
-
class ET_IpSecurity_Model_IpVariable
|
| 24 |
{
|
|
|
|
|
|
|
|
|
|
| 25 |
/**
|
| 26 |
* Option getter
|
| 27 |
* @return array
|
| 28 |
*/
|
| 29 |
-
public function
|
| 30 |
{
|
| 31 |
if (is_null($this->_options)) {
|
| 32 |
$this->_options = array(
|
|
@@ -56,22 +59,28 @@ class ET_IpSecurity_Model_IpVariable extends Mage_Eav_Model_Entity_Attribute_Sou
|
|
| 56 |
}
|
| 57 |
|
| 58 |
/**
|
|
|
|
|
|
|
| 59 |
* @return array
|
| 60 |
*/
|
| 61 |
public function getOptionArray()
|
| 62 |
{
|
| 63 |
$_options = array();
|
| 64 |
-
foreach ($this->
|
| 65 |
$_options[$option['value']] = $option['label'];
|
| 66 |
}
|
| 67 |
return $_options;
|
| 68 |
}
|
| 69 |
|
|
|
|
| 70 |
/**
|
|
|
|
|
|
|
| 71 |
* @return array
|
| 72 |
*/
|
| 73 |
-
public function
|
| 74 |
{
|
| 75 |
return $this->getOptionArray();
|
| 76 |
}
|
|
|
|
| 77 |
}
|
| 20 |
/**
|
| 21 |
* Class ET_IpSecurity_Model_IpVariable
|
| 22 |
*/
|
| 23 |
+
class ET_IpSecurity_Model_IpVariable
|
| 24 |
{
|
| 25 |
+
|
| 26 |
+
protected $_options;
|
| 27 |
+
|
| 28 |
/**
|
| 29 |
* Option getter
|
| 30 |
* @return array
|
| 31 |
*/
|
| 32 |
+
public function toOptionArray()
|
| 33 |
{
|
| 34 |
if (is_null($this->_options)) {
|
| 35 |
$this->_options = array(
|
| 59 |
}
|
| 60 |
|
| 61 |
/**
|
| 62 |
+
* Get options in "key-value" format
|
| 63 |
+
*
|
| 64 |
* @return array
|
| 65 |
*/
|
| 66 |
public function getOptionArray()
|
| 67 |
{
|
| 68 |
$_options = array();
|
| 69 |
+
foreach ($this->toOptionArray() as $option) {
|
| 70 |
$_options[$option['value']] = $option['label'];
|
| 71 |
}
|
| 72 |
return $_options;
|
| 73 |
}
|
| 74 |
|
| 75 |
+
|
| 76 |
/**
|
| 77 |
+
* Options getter
|
| 78 |
+
*
|
| 79 |
* @return array
|
| 80 |
*/
|
| 81 |
+
public function toArray()
|
| 82 |
{
|
| 83 |
return $this->getOptionArray();
|
| 84 |
}
|
| 85 |
+
|
| 86 |
}
|
app/code/community/ET/IpSecurity/Model/Observer.php
CHANGED
|
@@ -24,6 +24,16 @@ class ET_IpSecurity_Model_Observer
|
|
| 24 |
{
|
| 25 |
const TOKEN_COOKIE_NAME = 'ipsecurity_token';
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
protected $_redirectPage = null;
|
| 28 |
protected $_redirectBlank = null;
|
| 29 |
protected $_rawAllowIpData = null;
|
|
@@ -59,6 +69,30 @@ class ET_IpSecurity_Model_Observer
|
|
| 59 |
$this->_processIpCheck($observer);
|
| 60 |
}
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
/**
|
| 63 |
* If loading Admin
|
| 64 |
*
|
|
@@ -200,14 +234,16 @@ class ET_IpSecurity_Model_Observer
|
|
| 200 |
protected function _processIpCheck($observer)
|
| 201 |
{
|
| 202 |
$currentIp = $this->getCurrentIp();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
$allowIps = $this->_ipTextToArray($this->_rawAllowIpData);
|
| 204 |
$blockIps = $this->_ipTextToArray($this->_rawBlockIpData);
|
| 205 |
|
| 206 |
$allow = $this->isIpAllowed($currentIp, $allowIps, $blockIps);
|
| 207 |
|
| 208 |
-
//FOR DEBUG TESTING Token Access !!!! REMOVE AFTER TEST
|
| 209 |
-
//$allow = false;
|
| 210 |
-
|
| 211 |
if (!$allow) {
|
| 212 |
$allow = $this->_checkSecurityTokenAccess($observer);
|
| 213 |
}
|
|
@@ -404,9 +440,9 @@ class ET_IpSecurity_Model_Observer
|
|
| 404 |
);
|
| 405 |
|
| 406 |
$ipTokenLogModel->setData('create_time', now());
|
| 407 |
-
|
| 408 |
$helper->log('_addTokenLog():');
|
| 409 |
-
$helper->log('url: '
|
| 410 |
|
| 411 |
$ipTokenLogModel->setData('blocked_from', $fullUrl);
|
| 412 |
|
|
@@ -496,14 +532,16 @@ class ET_IpSecurity_Model_Observer
|
|
| 496 |
*/
|
| 497 |
protected function _processAllowDeny($allow, $currentIp)
|
| 498 |
{
|
| 499 |
-
//TODO: Refactoring?
|
| 500 |
$currentPage = $this->trimTrailingSlashes(Mage::helper('core/url')->getCurrentUrl());
|
| 501 |
// searching for CMS page storeId
|
| 502 |
-
// if we don't do it - we have loop in redirect with setting Add Store Code to Urls = Yes
|
| 503 |
// (block access to admin redirects to admin)
|
| 504 |
$pageStoreId = $this->getPageStoreId();
|
| 505 |
-
|
| 506 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 507 |
$scope = $this->_getScopeName();
|
| 508 |
|
| 509 |
if (!strlen($this->_redirectPage) && !$this->_isDownloader) {
|
|
@@ -568,42 +606,42 @@ class ET_IpSecurity_Model_Observer
|
|
| 568 |
/**
|
| 569 |
* Get store id of target redirect cms page
|
| 570 |
*
|
| 571 |
-
* @return int
|
| 572 |
*/
|
|
|
|
| 573 |
public function getPageStoreId()
|
| 574 |
{
|
| 575 |
-
$
|
| 576 |
-
$
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
foreach ($pageStoreIds as $pageStoreId) {
|
| 597 |
-
if ($pageStoreId > 0) {
|
| 598 |
-
break;
|
| 599 |
}
|
| 600 |
}
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
|
|
|
| 605 |
}
|
| 606 |
-
|
|
|
|
| 607 |
}
|
| 608 |
|
| 609 |
|
|
@@ -826,6 +864,21 @@ class ET_IpSecurity_Model_Observer
|
|
| 826 |
default:
|
| 827 |
$result = $currentIp;
|
| 828 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 829 |
return $result;
|
| 830 |
}
|
| 831 |
|
| 24 |
{
|
| 25 |
const TOKEN_COOKIE_NAME = 'ipsecurity_token';
|
| 26 |
|
| 27 |
+
/**
|
| 28 |
+
* Rss with admin authentication
|
| 29 |
+
* @var array
|
| 30 |
+
*/
|
| 31 |
+
protected $_requestPathList = array(
|
| 32 |
+
'/rss/order/new',
|
| 33 |
+
'/rss/catalog/notifystock',
|
| 34 |
+
'/rss/catalog/review'
|
| 35 |
+
);
|
| 36 |
+
|
| 37 |
protected $_redirectPage = null;
|
| 38 |
protected $_redirectBlank = null;
|
| 39 |
protected $_rawAllowIpData = null;
|
| 69 |
$this->_processIpCheck($observer);
|
| 70 |
}
|
| 71 |
|
| 72 |
+
/**
|
| 73 |
+
* If loading Frontend and router is "rss"
|
| 74 |
+
*
|
| 75 |
+
* Event: controller_front_init_routers
|
| 76 |
+
* @param Varien_Event_Observer $observer
|
| 77 |
+
*/
|
| 78 |
+
public function onLoadingRss($observer)
|
| 79 |
+
{
|
| 80 |
+
foreach ($this->_requestPathList as $pattern) {
|
| 81 |
+
if (strpos(Mage::app()->getRequest()->getPathInfo(), $pattern) !== false) {
|
| 82 |
+
/** @var ET_IpSecurity_Helper_Data $helper */
|
| 83 |
+
$helper = Mage::helper('etipsecurity');
|
| 84 |
+
$helper->log('onLoadingRss()');
|
| 85 |
+
|
| 86 |
+
$eventName = (string)$observer->getEvent()->getName();
|
| 87 |
+
$helper->log('event Name: ' . $eventName);
|
| 88 |
+
|
| 89 |
+
$this->_readAdminConfig();
|
| 90 |
+
$this->_readTokenConfig();
|
| 91 |
+
$this->_processIpCheck($observer);
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
/**
|
| 97 |
* If loading Admin
|
| 98 |
*
|
| 234 |
protected function _processIpCheck($observer)
|
| 235 |
{
|
| 236 |
$currentIp = $this->getCurrentIp();
|
| 237 |
+
//error or IPv6 or localhost
|
| 238 |
+
if (is_null($currentIp) || $currentIp === "127.0.0.1") {
|
| 239 |
+
return $this;
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
$allowIps = $this->_ipTextToArray($this->_rawAllowIpData);
|
| 243 |
$blockIps = $this->_ipTextToArray($this->_rawBlockIpData);
|
| 244 |
|
| 245 |
$allow = $this->isIpAllowed($currentIp, $allowIps, $blockIps);
|
| 246 |
|
|
|
|
|
|
|
|
|
|
| 247 |
if (!$allow) {
|
| 248 |
$allow = $this->_checkSecurityTokenAccess($observer);
|
| 249 |
}
|
| 440 |
);
|
| 441 |
|
| 442 |
$ipTokenLogModel->setData('create_time', now());
|
| 443 |
+
|
| 444 |
$helper->log('_addTokenLog():');
|
| 445 |
+
$helper->log('url: ' . $fullUrl);
|
| 446 |
|
| 447 |
$ipTokenLogModel->setData('blocked_from', $fullUrl);
|
| 448 |
|
| 532 |
*/
|
| 533 |
protected function _processAllowDeny($allow, $currentIp)
|
| 534 |
{
|
|
|
|
| 535 |
$currentPage = $this->trimTrailingSlashes(Mage::helper('core/url')->getCurrentUrl());
|
| 536 |
// searching for CMS page storeId
|
|
|
|
| 537 |
// (block access to admin redirects to admin)
|
| 538 |
$pageStoreId = $this->getPageStoreId();
|
| 539 |
+
if ($pageStoreId !== false) {
|
| 540 |
+
$this->_redirectPage = Mage::getUrl(null, array('_direct' => $this->_redirectPage, "_store" => $pageStoreId));
|
| 541 |
+
} else {
|
| 542 |
+
//no active page to redirect - redirecting to no-route
|
| 543 |
+
$this->_redirectPage = Mage::getUrl('no-route', array("_store" => $pageStoreId));
|
| 544 |
+
}
|
| 545 |
$scope = $this->_getScopeName();
|
| 546 |
|
| 547 |
if (!strlen($this->_redirectPage) && !$this->_isDownloader) {
|
| 606 |
/**
|
| 607 |
* Get store id of target redirect cms page
|
| 608 |
*
|
| 609 |
+
* @return int|
|
| 610 |
*/
|
| 611 |
+
|
| 612 |
public function getPageStoreId()
|
| 613 |
{
|
| 614 |
+
/* @var $cmsPage Mage_Cms_Model_Page */
|
| 615 |
+
$cmsPage = Mage::getModel('cms/page');
|
| 616 |
+
$storeId = Mage::app()->getStore()->getId();
|
| 617 |
+
|
| 618 |
+
//if current store is Admin
|
| 619 |
+
if ($storeId == 0) {
|
| 620 |
+
if (isset($_SERVER["SERVER_NAME"])) {
|
| 621 |
+
/** @var Mage_Core_Model_Store $store */
|
| 622 |
+
foreach (Mage::app()->getStores() as $store) {
|
| 623 |
+
$url = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, false);
|
| 624 |
+
//domain check
|
| 625 |
+
if (strpos($url, $_SERVER["SERVER_NAME"]) !== false) {
|
| 626 |
+
$redirectPage = $this->trimTrailingSlashes(
|
| 627 |
+
Mage::getStoreConfig('etipsecurity/ipsecurityadmin/redirect_page', $store->getId()));
|
| 628 |
+
//store have that page
|
| 629 |
+
if ($cmsPage->checkIdentifier($redirectPage, $store->getId())) {
|
| 630 |
+
$this->_redirectPage = $redirectPage;
|
| 631 |
+
return $store->getId();
|
| 632 |
+
}
|
| 633 |
+
}
|
| 634 |
+
}
|
|
|
|
|
|
|
|
|
|
| 635 |
}
|
| 636 |
}
|
| 637 |
+
//check identifier check page on active and specified store
|
| 638 |
+
$pageId = $cmsPage->checkIdentifier($this->_redirectPage, $storeId);
|
| 639 |
+
if ($pageId > 0) {
|
| 640 |
+
//current store id
|
| 641 |
+
return $storeId;
|
| 642 |
}
|
| 643 |
+
//no active redirect page for current store
|
| 644 |
+
return false;
|
| 645 |
}
|
| 646 |
|
| 647 |
|
| 864 |
default:
|
| 865 |
$result = $currentIp;
|
| 866 |
}
|
| 867 |
+
//IPv6 127.0.0.1
|
| 868 |
+
if ($result == "::1") {
|
| 869 |
+
$result = "127.0.0.1";
|
| 870 |
+
} elseif (substr_count($result, ':') > 0) {
|
| 871 |
+
//finding ipv4 part
|
| 872 |
+
$ipVFourArray = explode(".", $result);
|
| 873 |
+
//IPv4-compatible IPv6
|
| 874 |
+
if (count($ipVFourArray) == 4) {
|
| 875 |
+
$ipVFourArray[0] = array_pop(explode(":", $ipVFourArray[0]));
|
| 876 |
+
return implode(".", $ipVFourArray);
|
| 877 |
+
}
|
| 878 |
+
//no real ip4 address
|
| 879 |
+
return null;
|
| 880 |
+
}
|
| 881 |
+
|
| 882 |
return $result;
|
| 883 |
}
|
| 884 |
|
app/code/community/ET/IpSecurity/etc/config.xml
CHANGED
|
@@ -23,7 +23,7 @@
|
|
| 23 |
<modules>
|
| 24 |
<ET_IpSecurity>
|
| 25 |
<name>ET Ip Security</name>
|
| 26 |
-
<version>2.
|
| 27 |
<descr>
|
| 28 |
<ru_RU><