BaseValidator.php
1 year ago
CharacterLength.php
2 years ago
DateTime.php
2 years ago
Email.php
2 years ago
Exception.php
2 years ago
IdSite.php
2 years ago
IpRanges.php
2 years ago
NotEmpty.php
2 years ago
NumberRange.php
2 years ago
Regex.php
1 year ago
UrlLike.php
2 years ago
WhitelistedValue.php
1 year ago
IpRanges.php
31 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Matomo free/libre analytics platform |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 8 | */ |
| 9 | namespace Piwik\Validators; |
| 10 | |
| 11 | use Matomo\Network\IPUtils; |
| 12 | use Piwik\Piwik; |
| 13 | class IpRanges extends \Piwik\Validators\BaseValidator |
| 14 | { |
| 15 | public function validate($value) |
| 16 | { |
| 17 | if (!empty($value)) { |
| 18 | if (!is_array($value)) { |
| 19 | throw new \Piwik\Validators\Exception('The IP ranges need to be an array'); |
| 20 | } |
| 21 | $ips = array_map('trim', $value); |
| 22 | $ips = array_filter($ips, 'strlen'); |
| 23 | foreach ($ips as $ip) { |
| 24 | if (IPUtils::getIPRangeBounds($ip) === null) { |
| 25 | throw new \Piwik\Validators\Exception(Piwik::translate('SitesManager_ExceptionInvalidIPFormat', array($ip, "1.2.3.4, 1.2.3.*, or 1.2.3.4/5"))); |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 |