From 828b669f84c7bd8a74ea6cd4b859b438eb54877e Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 15 Mar 2007 14:35:52 +0000 Subject: [PATCH] *Add some IPv6 ranges (64,80,96,112) --- includes/SpecialContributions.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/includes/SpecialContributions.php b/includes/SpecialContributions.php index d59eb78c76..d61860bd5a 100644 --- a/includes/SpecialContributions.php +++ b/includes/SpecialContributions.php @@ -71,12 +71,32 @@ class ContribsFinder { if ( $this->username == 'newbies' ) { $max = $this->dbr->selectField( 'user', 'max(user_id)', false, 'make_sql' ); $condition = 'rev_user >' . (int)($max - $max / 100); - } else if ( preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/(24|16)/", $this->username) ) { + } else if ( IP::isIPv4( $this->username ) && preg_match("/\/(24|16)$/", $this->username, $matches) ) { $abcd = explode( ".", $this->username ); - if( substr( $this->username, -2 ) == 24 ) $ipmask = $abcd[0] . '.' . $abcd[1] . '.' . $abcd[2] . '.%'; + if( $matches[1] == 24 ) $ipmask = $abcd[0] . '.' . $abcd[1] . '.' . $abcd[2] . '.%'; else $ipmask=$abcd[0] . '.' . $abcd[1] . '.%'; $condition = 'rev_user_text LIKE ' . $this->dbr->addQuotes($ipmask); - } else if ( IP::isIPv6( $this->username ) ) { + } else if ( IP::isIPv6( $this->username ) && preg_match("/^(64|80|96|112)$/", $this->username) ) { + $abcdefgh = explode( ":", IP::sanitizeIP($this->username) ); + $abcd = implode( ":", array_slice($abcdefgh, 0, 4) ); + switch( $matches[1] ) { + case '112': + $ipmask = $abcd . ':' . $abcd[4] . ':' . $abcd[5] . ':' . $abcd[6] . ':%'; + break; + case '96': + $ipmask = $abcd . ':' . $abcd[4] . ':' . $abcd[5] . ':%'; + break; + case '80': + $ipmask = $abcd . ':' . $abcd[4] . ':%'; + break; + case '64': + $ipmask = $abcd . ':%'; + break; + } + $condition = 'rev_user_text LIKE ' . $this->dbr->addQuotes($ipmask); + } + + else if ( IP::isIPv6( $this->username ) ) { # All stored IPs should be sanitized from now on, check for exact matches for reverse compatibility $condition = '(rev_user_text=' . $this->dbr->addQuotes(IP::sanitizeIP($this->username)) . ' OR rev_user_text=' . $this->dbr->addQuotes($this->username) . ')'; } -- 2.20.1