Skip to content

Commit e8e4a93

Browse files
Anton EversAnton Evers
authored andcommitted
Replace darsyn/ip in favour of symfony/http-foundation
1 parent 803d0ca commit e8e4a93

File tree

5 files changed

+74
-139
lines changed

5 files changed

+74
-139
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"sjparkinson/static-review": "~4.1",
4848
"symfony/console": "~2.3, !=2.7.0",
4949
"symfony/event-dispatcher": "~2.1",
50+
"symfony/http-foundation": "^3.3",
5051
"symfony/process": "~2.1",
5152
"tedivm/jshrink": "~1.1.0",
5253
"tubalmartin/cssmin": "4.1.0",
@@ -75,8 +76,7 @@
7576
"zendframework/zend-text": "^2.6.0",
7677
"zendframework/zend-uri": "^2.5.1",
7778
"zendframework/zend-validator": "^2.6.0",
78-
"zendframework/zend-view": "^2.8.1",
79-
"darsyn/ip": "^3.3"
79+
"zendframework/zend-view": "^2.8.1"
8080
},
8181
"require-dev": {
8282
"friendsofphp/php-cs-fixer": "~2.1.1",

composer.lock

Lines changed: 55 additions & 104 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/internal/Magento/Framework/App/MaintenanceMode.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use Magento\Framework\App\Filesystem\DirectoryList;
99
use Magento\Framework\Filesystem;
10-
use Darsyn\IP\IP;
10+
use Symfony\Component\HttpFoundation\IpUtils;
1111

1212
/**
1313
* Application Maintenance Mode
@@ -62,23 +62,7 @@ public function isOn($remoteAddr = '')
6262
if (!$this->flagDir->isExist(self::FLAG_FILENAME)) {
6363
return false;
6464
}
65-
$info = $this->getAddressInfo();
66-
$testIp = new IP($remoteAddr);
67-
foreach ($info as $range) {
68-
$cidr = 32;
69-
$ip = $range;
70-
if (strpos($range, '/') !== false) {
71-
list($ip, $cidr) = explode('/', $range);
72-
}
73-
$rangeIp = new IP($ip);
74-
if ($rangeIp->isVersion4()) {
75-
$cidr += IP::CIDR4TO6;
76-
}
77-
if ($testIp->inRange($rangeIp, $cidr)) {
78-
return false;
79-
}
80-
}
81-
return true;
65+
return !IpUtils::checkIp($remoteAddr, $this->getAddressInfo());
8266
}
8367

8468
/**

lib/internal/Magento/Framework/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"monolog/monolog": "^1.17",
2929
"oyejorge/less.php": "~1.7.0",
3030
"symfony/console": "~2.3, !=2.7.0",
31+
"symfony/http-foundation": "^3.3",
3132
"symfony/process": "~2.1",
3233
"tedivm/jshrink": "~1.1.0",
3334
"zendframework/zend-code": "^3.1.0",
@@ -37,7 +38,8 @@
3738
"zendframework/zend-stdlib": "^2.7.7",
3839
"zendframework/zend-uri": "^2.5.1",
3940
"zendframework/zend-validator": "^2.6.0",
40-
"darsyn/ip": "^3.3"
41+
"zendframework/zend-stdlib": "^2.7.7",
42+
"zendframework/zend-http": "^2.6.0"
4143
},
4244
"suggest": {
4345
"ext-imagick": "Use Image Magick >=3.0.0 as an optional alternative image processing library"

setup/src/Magento/Setup/Validator/IpValidator.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
*/
66
namespace Magento\Setup\Validator;
77

8-
use Darsyn\IP\IP;
9-
use Darsyn\IP\InvalidIpAddressException;
10-
118
/**
129
* Class to validate list of IPs for maintenance commands
1310
*/
@@ -70,30 +67,31 @@ public function validateIps(array $ips, $noneAllowed)
7067
private function filterIps(array $ips)
7168
{
7269
foreach ($ips as $range) {
70+
if ($range === 'none') {
71+
$this->none[] = $range;
72+
continue;
73+
}
74+
7375
$cidr = 32;
7476
$ip = $range;
7577
if (strpos($range, '/') !== false) {
7678
list($ip, $cidr) = explode('/', $range);
7779
}
7880

79-
try {
80-
$validIp = new IP($ip);
81-
} catch (InvalidIpAddressException $e) {
82-
if ($range == 'none') {
83-
$this->none[] = $range;
84-
continue;
85-
}
81+
$ipValidator = new \Zend_Validate_Ip(['allowipv6' => true, 'allowipv4' => true]);
82+
if (!$ipValidator->isValid($ip)) {
8683
$this->invalidIps[] = $range;
8784
continue;
8885
}
8986

90-
$max = $validIp->isVersion4() ? 32 : 128;
91-
if ($cidr >= 0 && $cidr <= $max) {
92-
$this->validIps[] = $range;
87+
$ipv4Validator = new \Zend_Validate_Ip(['allowipv6' => false, 'allowipv4' => true]);
88+
$max = $ipv4Validator->isValid($ip) ? 32 : 128;
89+
if ($cidr < 0 || $cidr > $max) {
90+
$this->invalidIps[] = $range;
9391
continue;
9492
}
9593

96-
$this->invalidIps[] = $range;
94+
$this->validIps[] = $range;
9795
}
9896
}
9997
}

0 commit comments

Comments
 (0)