![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-backend/Model/Validator/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Backend\Model\Validator; /** * Class to validate list of IPs for maintenance commands */ class IpValidator { /** * @var string[] */ private $none; /** * @var string[] */ private $validIps; /** * @var string[] */ private $invalidIps; /** * Validates list of ips * * @param string[] $ips * @param bool $noneAllowed * @return string[] * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function validateIps(array $ips, $noneAllowed) { $this->none = []; $this->validIps = []; $this->invalidIps = []; $messages = []; $this->filterIps($ips); if (count($this->none) > 0 && !$noneAllowed) { $messages[] = "'none' is not allowed"; } elseif ($noneAllowed && count($this->none) > 1) { $messages[] = "'none' can be only used once"; } elseif ($noneAllowed && count($this->none) > 0 && (count($this->validIps) > 0 || count($this->invalidIps) > 0) ) { $messages[] = "Multiple values are not allowed when 'none' is used"; } else { foreach ($this->invalidIps as $invalidIp) { $messages[] = "Invalid IP $invalidIp"; } } return $messages; } /** * Filter ips into 'none', valid and invalid ips * * @param string[] $ips * @return void */ private function filterIps(array $ips) { foreach ($ips as $ip) { if (filter_var($ip, FILTER_VALIDATE_IP)) { $this->validIps[] = $ip; } elseif ($ip == 'none') { $this->none[] = $ip; } else { $this->invalidIps[] = $ip; } } } }