We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | <?php |
||
16 | class Ip extends AbstractRule |
||
17 | { |
||
18 | public $ipOptions; |
||
19 | |||
20 | public $networkRange; |
||
21 | |||
22 | 40 | public function __construct($ipOptions = null) |
|
32 | |||
33 | 39 | protected function parseRange($input) |
|
34 | { |
||
35 | 39 | if ($input === null || $input == '*' || $input == '*.*.*.*' |
|
36 | 39 | || $input == '0.0.0.0-255.255.255.255') { |
|
37 | 9 | return; |
|
38 | } |
||
39 | |||
40 | 30 | $range = ['min' => null, 'max' => null, 'mask' => null]; |
|
41 | |||
42 | 30 | if (mb_strpos($input, '-') !== false) { |
|
43 | 8 | list($range['min'], $range['max']) = explode('-', $input); |
|
44 | 22 | } elseif (mb_strpos($input, '*') !== false) { |
|
45 | 11 | $this->parseRangeUsingWildcards($input, $range); |
|
46 | 11 | } elseif (mb_strpos($input, '/') !== false) { |
|
47 | 9 | $this->parseRangeUsingCidr($input, $range); |
|
48 | } else { |
||
49 | 2 | throw new ComponentException('Invalid network range'); |
|
50 | } |
||
51 | |||
52 | 25 | if (!$this->verifyAddress($range['min'])) { |
|
53 | throw new ComponentException('Invalid network range'); |
||
54 | } |
||
55 | |||
56 | 25 | if (isset($range['max']) && !$this->verifyAddress($range['max'])) { |
|
57 | 2 | throw new ComponentException('Invalid network range'); |
|
58 | } |
||
59 | |||
60 | 23 | return $range; |
|
61 | } |
||
62 | |||
63 | 20 | protected function fillAddress(&$input, $char = '*') |
|
64 | { |
||
65 | 20 | while (mb_substr_count($input, '.') < 3) { |
|
66 | 5 | $input .= '.'.$char; |
|
67 | } |
||
68 | 20 | } |
|
69 | |||
70 | 11 | protected function parseRangeUsingWildcards($input, &$range) |
|
77 | |||
78 | 9 | protected function parseRangeUsingCidr($input, &$range) |
|
98 | |||
99 | 33 | public function validate($input) |
|
103 | |||
104 | 37 | protected function verifyAddress($address) |
|
105 | { |
||
106 | 37 | return (bool) filter_var( |
|
107 | 37 | $address, |
|
108 | 37 | FILTER_VALIDATE_IP, |
|
109 | [ |
||
110 | 37 | 'flags' => $this->ipOptions, |
|
111 | ] |
||
112 | ); |
||
113 | } |
||
114 | |||
115 | 27 | protected function verifyNetwork($input) |
|
130 | |||
131 | 6 | protected function belongsToSubnet($input) |
|
139 | } |
||
140 |