function setUp() { $this->server = $_SERVER; $_SERVER['HTTP_HOST'] = 'test'; $this->stats_counter = new StatsCounter(); $this->stats_ip = new StatsIpTestVersion($this); $this->stats_ip->__construct(); $this->stats_ip->setReturnValue('getClientIp', Ip::encodeIp('127.0.0.1')); $this->stats_counter = new StatsCounterTestVersion2($this); $this->stats_counter->__construct(); $this->stats_referer = new StatsRefererTestVersion($this); $this->stats_referer->__construct(); $this->stats_referer->setReturnValue('getRefererPageId', 10); $this->stats_search_phrase = new StatsSearchPhraseTestVersion($this); $this->stats_search_phrase->__construct(); $this->stats_search_phrase->setReturnValue('register', true); $this->stats_register = new StatsRegisterTestVersion($this); $this->stats_register->__construct(); $this->stats_register->setReturnValue('_getIpRegister', $this->stats_ip); $this->stats_register->setReturnValue('_getCounterRegister', $this->stats_counter); $this->stats_register->setReturnValue('_getRefererRegister', $this->stats_referer); $this->stats_register->setReturnValue('_getSearchPhraseRegister', $this->stats_search_phrase); Limb::toolkit()->getUser()->set('id', 10); $this->_cleanUp(); }
function testSameHostWrongDay() { $date1 = new Date(); $ip = Ip::encodeIp('192.168.0.5'); $this->stats_ip->setReturnValue('getClientIp', $ip); $this->stats_ip->isNewHost($date1); $date2 = new Date(); $date2->setByDays($date1->dateToDays() - 2); $this->stats_ip->setReturnValueAt(1, 'getClientIp', $ip); $this->assertFalse($this->stats_ip->isNewHost($date2)); $this->_checkStatsIpRecord($total_records = 1, $ip, $date1); }
public function setIpFilter($ip_string) { $ip_positive_hex_list = array(); $ip_negative_hex_list = array(); $ip_string_list = $this->_parseInputString($ip_string); foreach ($ip_string_list as $ip_piece) { if (substr($ip_piece, 0, 1) == '!') { $ip_piece = substr($ip_piece, 1); $ip_hex_list =& $ip_negative_hex_list; } else { $ip_hex_list =& $ip_positive_hex_list; } if (Ip::isValid($ip_piece)) { if (strpos($ip_piece, '*') !== false) { $ip_hex_list[] = Ip::encodeIp(str_replace('*', '255', $ip_piece)); } else { $ip_hex_list[] = Ip::encodeIp($ip_piece); } } elseif (preg_match('/^([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})[ ]*\\-[ ]*([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})$/', $ip_piece, $ip_match)) { foreach (Ip::encodeIpRange($ip_match[1], $ip_match[2]) as $ip_range_hex_item) { $ip_hex_list[] = $ip_range_hex_item; } } } $positive_conditions = array(); foreach ($ip_positive_hex_list as $hex_ip) { if (preg_match('/(ff\\.)|(\\.ff)/is', chunk_split($hex_ip, 2, '.'))) { $value = str_replace('.', '', preg_replace('/(ff\\.)|(\\.ff)/is', '%', chunk_split($hex_ip, 2, "."))) . "'"; } else { $value = $hex_ip; } $positive_conditions[] = $this->_buildPositiveCondition('sslog.ip', $value); } $negative_conditions = array(); foreach ($ip_negative_hex_list as $hex_ip) { if (preg_match('/(ff\\.)|(\\.ff)/is', chunk_split($hex_ip, 2, '.'))) { $value = str_replace('.', '', preg_replace('/(ff\\.)|(\\.ff)/is', '%', chunk_split($hex_ip, 2, "."))) . "'"; } else { $value = $hex_ip; } $negative_conditions[] = $this->_buildNegativeCondition('sslog.ip', $value); } $condition = $this->_combinePositiveNegativeConditions($positive_conditions, $negative_conditions); if ($condition) { $this->filter_conditions[] = ' AND ( ' . $condition . ' ) '; } }
public function getClientIp() { return Ip::encodeIp(Sys::clientIp()); }