/** * Added compatibility for hosts that do not have inet_pton. * * @param $ip * @return bool|string */ public static function _inet_pton($ip) { // IPv4 if (preg_match('/^(?:\\d{1,3}(?:\\.|$)){4}/', $ip)) { $octets = explode('.', $ip); $bin = chr($octets[0]) . chr($octets[1]) . chr($octets[2]) . chr($octets[3]); return $bin; } // IPv6 if (preg_match('/^((?:[\\da-f]{1,4}(?::|)){0,8})(::)?((?:[\\da-f]{1,4}(?::|)){0,8})$/i', $ip)) { if ($ip === '::') { return ""; } $colon_count = wfWAFUtils::substr_count($ip, ':'); $dbl_colon_pos = wfWAFUtils::strpos($ip, '::'); if ($dbl_colon_pos !== false) { $ip = str_replace('::', str_repeat(':0000', ($dbl_colon_pos === 0 || $dbl_colon_pos === wfWAFUtils::strlen($ip) - 2 ? 9 : 8) - $colon_count) . ':', $ip); $ip = trim($ip, ':'); } $ip_groups = explode(':', $ip); $ipv6_bin = ''; foreach ($ip_groups as $ip_group) { $ipv6_bin .= pack('H*', str_pad($ip_group, 4, '0', STR_PAD_LEFT)); } return wfWAFUtils::strlen($ipv6_bin) === 16 ? $ipv6_bin : false; } // IPv4 mapped IPv6 if (preg_match('/^((?:0{1,4}(?::|)){0,5})(::)?ffff:((?:\\d{1,3}(?:\\.|$)){4})$/i', $ip, $matches)) { $octets = explode('.', $matches[3]); return "ÿÿ" . chr($octets[0]) . chr($octets[1]) . chr($octets[2]) . chr($octets[3]); } return false; }
public function containsCount($subject) { if (is_array($this->getExpected())) { $this->multiplier = 0; foreach ($this->getExpected() as $val) { if ($val == $subject) { $this->multiplier++; } } return $this->multiplier > 0; } $this->multiplier = wfWAFUtils::substr_count($subject, $this->getExpected()); return $this->multiplier > 0; }
/** * The current line of the scanned string. * * @return int */ public function getLine() { if ($this->getPointer() + 1 > $this->getLength()) { return wfWAFUtils::substr_count($this->getString(), "\n") + 1; } return wfWAFUtils::substr_count($this->getString(), "\n", 0, $this->getPointer() + 1) + 1; }