1
0
Fork 0

return early if rule is * and remove one level of nesting

pull/2017/head
radnan 2013-06-20 13:38:08 -05:00
parent a92ceaf4fe
commit 7e584de9e8
1 changed files with 28 additions and 28 deletions

View File

@ -54,40 +54,40 @@ class NoProxyPattern
} }
foreach ($this->rules as $rule) { foreach ($this->rules as $rule) {
if ($rule == '*') {
return true;
}
$match = false; $match = false;
if ($rule == '*') { list($ruleHost) = explode(':', $rule);
$match = true; list($base) = explode('/', $ruleHost);
} else {
list($ruleHost) = explode(':', $rule);
list($base) = explode('/', $ruleHost);
if (filter_var($base, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { if (filter_var($base, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
// ip or cidr match // ip or cidr match
if (!isset($ip)) { if (!isset($ip)) {
$ip = gethostbyname($host); $ip = gethostbyname($host);
}
if (strpos($ruleHost, '/') === false) {
$match = $ip === $ruleHost;
} else {
$match = self::inCIDRBlock($ruleHost, $ip);
}
} else {
// match end of domain
$haystack = '.' . trim($host, '.') . '.';
$needle = '.'. trim($ruleHost, '.') .'.';
$match = stripos(strrev($haystack), strrev($needle)) === 0;
} }
// final port check if (strpos($ruleHost, '/') === false) {
if ($match && strpos($rule, ':') !== false) { $match = $ip === $ruleHost;
list(, $rulePort) = explode(':', $rule); } else {
if (!empty($rulePort) && $port != $rulePort) { $match = self::inCIDRBlock($ruleHost, $ip);
$match = false; }
} } else {
// match end of domain
$haystack = '.' . trim($host, '.') . '.';
$needle = '.'. trim($ruleHost, '.') .'.';
$match = stripos(strrev($haystack), strrev($needle)) === 0;
}
// final port check
if ($match && strpos($rule, ':') !== false) {
list(, $rulePort) = explode(':', $rule);
if (!empty($rulePort) && $port != $rulePort) {
$match = false;
} }
} }