Commit c5d5ef64 by Daniel Ruf Committed by Scott

support IPv6 in qa_block_ip_match

parent 0c163460
...@@ -179,19 +179,27 @@ ...@@ -179,19 +179,27 @@
Returns whether the ip address $ip is matched by the clause $blockipclause, which can contain a hyphen or asterisk Returns whether the ip address $ip is matched by the clause $blockipclause, which can contain a hyphen or asterisk
*/ */
{ {
if (long2ip(ip2long($ip))==$ip) { if (filter_var($ip, FILTER_VALIDATE_IP)) {
if (preg_match('/^(.*)\-(.*)$/', $blockipclause, $matches)) { if (preg_match('/^(.*)\-(.*)$/', $blockipclause, $matches)) {
if ( (long2ip(ip2long($matches[1]))==$matches[1]) && (long2ip(ip2long($matches[2]))==$matches[2]) ) { if ( filter_var($matches[1], FILTER_VALIDATE_IP) && filter_var($matches[2], FILTER_VALIDATE_IP) ) {
$iplong=sprintf('%u', ip2long($ip)); if(filter_var($ip, FILTER_VALIDATE_IP,FILTER_FLAG_IPV6)){
$end1long=sprintf('%u', ip2long($matches[1])); $ip=ipv6_expand($ip);
$end2long=sprintf('%u', ip2long($matches[2])); $matches[1]=ipv6_expand($matches[1],true);
$matches[2]=ipv6_expand($matches[2],true);
}
$iplong=ipv6_numeric($ip);
$end1long=ipv6_numeric($matches[1]);
$end2long=ipv6_numeric($matches[2]);
return (($iplong>=$end1long) && ($iplong<=$end2long)) || (($iplong>=$end2long) && ($iplong<=$end1long)); return (($iplong>=$end1long) && ($iplong<=$end2long)) || (($iplong>=$end2long) && ($iplong<=$end1long));
} }
} elseif (strlen($blockipclause)){
} elseif (strlen($blockipclause)) if(filter_var($ip, FILTER_VALIDATE_IP,FILTER_FLAG_IPV6)){
return preg_match('/^'.str_replace('\\*', '[0-9]+', preg_quote($blockipclause, '/')).'$/', $ip) > 0; $ip=ipv6_expand($ip,true);
$blockipclause=ipv6_expand($blockipclause,true);
}
return preg_match('/^'.str_replace('\\*', '[0-9a-fA-F]+', preg_quote($blockipclause, '/')).'$/', $ip) > 0;
// preg_quote misses hyphens but that is OK here // preg_quote misses hyphens but that is OK here
}
} }
return false; return false;
...@@ -226,4 +234,4 @@ ...@@ -226,4 +234,4 @@
/* /*
Omit PHP closing tag to help avoid accidental output Omit PHP closing tag to help avoid accidental output
*/ */
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment