function test_process_simple_ips_list() { $ip_list = $this->ip->process_ip_range('192.168.0.1, 192.168.0.2, 192.168.0.3'); $this->assertEqual($ip_list[0], ip::encode_ip('192.168.0.1')); $this->assertEqual($ip_list[1], ip::encode_ip('192.168.0.2')); $this->assertEqual($ip_list[2], ip::encode_ip('192.168.0.3')); }
function test_same_host_wrong_day() { $date1 = new date(); $ip = ip::encode_ip('192.168.0.5'); $this->stats_ip->setReturnValue('get_client_ip', $ip); $this->stats_ip->is_new_host($date1); $date2 = new date(); $date2->set_by_days($date1->date_to_days() - 2); $this->stats_ip->setReturnValueAt(1, 'get_client_ip', $ip); $this->assertFalse($this->stats_ip->is_new_host($date2)); $this->_check_stats_ip_record($total_records = 1, $ip, $date1); }
function process_ip_range($ip_range) { $ip_list = array(); $ip_list_temp = explode(',', $ip_range); for ($i = 0; $i < count($ip_list_temp); $i++) { if (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})$/', trim($ip_list_temp[$i]), $ip_range_explode)) { $ip_1_counter = $ip_range_explode[1]; $ip_1_end = $ip_range_explode[5]; while ($ip_1_counter <= $ip_1_end) { $ip_2_counter = $ip_1_counter == $ip_range_explode[1] ? $ip_range_explode[2] : 0; $ip_2_end = $ip_1_counter < $ip_1_end ? 254 : $ip_range_explode[6]; if ($ip_2_counter == 0 && $ip_2_end == 254) { $ip_2_counter = 255; $ip_2_fragment = 255; $ip_list[] = ip::encode_ip("{$ip_1_counter}.255.255.255"); } while ($ip_2_counter <= $ip_2_end) { $ip_3_counter = $ip_2_counter == $ip_range_explode[2] && $ip_1_counter == $ip_range_explode[1] ? $ip_range_explode[3] : 0; $ip_3_end = $ip_2_counter < $ip_2_end || $ip_1_counter < $ip_1_end ? 254 : $ip_range_explode[7]; if ($ip_3_counter == 0 && $ip_3_end == 254) { $ip_3_counter = 255; $ip_3_fragment = 255; $ip_list[] = ip::encode_ip("{$ip_1_counter}.{$ip_2_counter}.255.255"); } while ($ip_3_counter <= $ip_3_end) { $ip_4_counter = $ip_3_counter == $ip_range_explode[3] && $ip_2_counter == $ip_range_explode[2] && $ip_1_counter == $ip_range_explode[1] ? $ip_range_explode[4] : 0; $ip_4_end = $ip_3_counter < $ip_3_end || $ip_2_counter < $ip_2_end ? 254 : $ip_range_explode[8]; if ($ip_4_counter == 0 && $ip_4_end == 254) { $ip_4_counter = 255; $ip_4_fragment = 255; $ip_list[] = ip::encode_ip("{$ip_1_counter}.{$ip_2_counter}.{$ip_3_counter}.255"); } while ($ip_4_counter <= $ip_4_end) { $ip_list[] = ip::encode_ip("{$ip_1_counter}.{$ip_2_counter}.{$ip_3_counter}.{$ip_4_counter}"); $ip_4_counter++; } $ip_3_counter++; } $ip_2_counter++; } $ip_1_counter++; } } elseif (preg_match('/^([0-9\\*]{1,3})\\.([0-9\\*]{1,3})\\.([0-9\\*]{1,3})\\.([0-9\\*]{1,3})$/', trim($ip_list_temp[$i]))) { $ip_list[] = ip::encode_ip(str_replace('*', '255', trim($ip_list_temp[$i]))); } } return $ip_list; }
function login($login, $password) { $this->_delete_cookie(); $user_ip = ip::encode_ip(sys::client_ip()); $sid = md5(uniqid($user_ip)); session::set('phpbb_sid', $sid); $phpbb_user_data = array(); $phpbb_user_data['session_user_id'] = user::get_id(); $phpbb_user_data['session_id'] = $sid; $phpbb_user_data['session_ip'] = $user_ip; $phpbb_user_data['session_logged_in'] = 1; $phpbb_user_data['session_start'] = time(); $phpbb_user_data['session_time'] = time(); $db_table =& db_table_factory::create('phpbb_sessions'); return $db_table->insert($phpbb_user_data); }
function set_ip_filter($ip_string) { $ip_positive_hex_list = array(); $ip_negative_hex_list = array(); $ip_string_list = $this->_parse_input_string($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::is_valid($ip_piece)) { if (strpos($ip_piece, '*') !== false) { $ip_hex_list[] = ip::encode_ip(str_replace('*', '255', $ip_piece)); } else { $ip_hex_list[] = ip::encode_ip($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::encode_ip_range($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->_build_positive_condition('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->_build_negative_condition('sslog.ip', $value); } $condition = $this->_combine_positive_negative_conditions($positive_conditions, $negative_conditions); if ($condition) { $this->filter_conditions[] = ' AND ( ' . $condition . ' ) '; } }
function encode_ip_range($ip_begin, $ip_end) { $ip_regex = '/^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})$/'; if (!preg_match($ip_regex, $ip_begin, $ip_begin_range_explode) || !preg_match($ip_regex, $ip_end, $ip_end_range_explode)) { return array(); } $ip_list = array(); $ip_1_counter = $ip_begin_range_explode[1]; $ip_1_end = $ip_end_range_explode[1]; while ($ip_1_counter <= $ip_1_end) { $ip_2_counter = $ip_1_counter == $ip_begin_range_explode[1] ? $ip_begin_range_explode[2] : 0; $ip_2_end = $ip_1_counter < $ip_1_end ? 254 : $ip_end_range_explode[2]; if ($ip_2_counter == 0 && $ip_2_end == 254) { $ip_2_counter = 255; $ip_2_fragment = 255; $ip_list[] = ip::encode_ip("{$ip_1_counter}.255.255.255"); } while ($ip_2_counter <= $ip_2_end) { $ip_3_counter = $ip_2_counter == $ip_begin_range_explode[2] && $ip_1_counter == $ip_begin_range_explode[1] ? $ip_begin_range_explode[3] : 0; $ip_3_end = $ip_2_counter < $ip_2_end || $ip_1_counter < $ip_1_end ? 254 : $ip_end_range_explode[3]; if ($ip_3_counter == 0 && $ip_3_end == 254) { $ip_3_counter = 255; $ip_3_fragment = 255; $ip_list[] = ip::encode_ip("{$ip_1_counter}.{$ip_2_counter}.255.255"); } while ($ip_3_counter <= $ip_3_end) { $ip_4_counter = $ip_3_counter == $ip_begin_range_explode[3] && $ip_2_counter == $ip_begin_range_explode[2] && $ip_1_counter == $ip_begin_range_explode[1] ? $ip_begin_range_explode[4] : 0; $ip_4_end = $ip_3_counter < $ip_3_end || $ip_2_counter < $ip_2_end ? 254 : $ip_end_range_explode[4]; if ($ip_4_counter == 0 && $ip_4_end == 254) { $ip_4_counter = 255; $ip_4_fragment = 255; $ip_list[] = ip::encode_ip("{$ip_1_counter}.{$ip_2_counter}.{$ip_3_counter}.255"); } while ($ip_4_counter <= $ip_4_end) { $ip_list[] = ip::encode_ip("{$ip_1_counter}.{$ip_2_counter}.{$ip_3_counter}.{$ip_4_counter}"); $ip_4_counter++; } $ip_3_counter++; } $ip_2_counter++; } $ip_1_counter++; } return $ip_list; }
function set_ip_filter($ip_string) { $ip_positive_hex_list = array(); $ip_negative_hex_list = array(); if (!($ip_string_list = $this->_parse_input_string($ip_string))) { return; } foreach ($ip_string_list as $ip_piece) { //we make a temp link with $ip_hex_list 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; } $ip_piece = str_replace('*', '255', $ip_piece); if (ip::is_valid($ip_piece)) { $ip_hex_list[] = ip::encode_ip($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::encode_ip_range($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) { $hex_ip = $this->_process_ip_255_segments($hex_ip); $positive_conditions[] = $this->_build_positive_condition('sslog.ip', $hex_ip); } $negative_conditions = array(); foreach ($ip_negative_hex_list as $hex_ip) { $hex_ip = $this->_process_ip_255_segments($hex_ip); $negative_conditions[] = $this->_build_negative_condition('sslog.ip', $hex_ip); } $condition = $this->_combine_positive_and_negative_conditions($positive_conditions, $negative_conditions); if ($condition) { $this->filter_conditions[] = ' AND ( ' . $condition . ' ) '; } }
function setUp() { $this->stats_counter = new stats_counter(); $this->stats_ip = new stats_ip_test_version($this); $this->stats_ip->stats_ip(); $this->stats_ip->setReturnValue('get_client_ip', ip::encode_ip('127.0.0.1')); $this->stats_counter = new stats_counter_test_version($this); $this->stats_counter->stats_counter(); $this->stats_referer = new stats_referer_test_version($this); $this->stats_referer->stats_referer(); $this->stats_referer->setReturnValue('get_referer_page_id', 10); $this->stats_search_phrase = new stats_search_phrase_test_version($this); $this->stats_search_phrase->stats_search_phrase(); $this->stats_search_phrase->setReturnValue('register', true); $this->stats_register = new stats_register_test_version($this); $this->stats_register->stats_register(); $this->stats_register->setReturnReference('_get_ip_register', $this->stats_ip); $this->stats_register->setReturnReference('_get_counter_register', $this->stats_counter); $this->stats_register->setReturnReference('_get_referer_register', $this->stats_referer); $this->stats_register->setReturnReference('_get_search_phrase_register', $this->stats_search_phrase); $this->_login_user(10, array()); $this->_clean_up(); }
function test_login() { $this->_login_user(5, array()); $this->assertTrue($this->object->login('', '')); $db_table =& db_table_factory :: instance('phpbb_sessions'); $conditions['session_user_id'] = 5; $rows = $db_table->get_list($conditions, '', null); $record = current($rows); $this->assertEqual($record['session_ip'], ip :: encode_ip(sys :: client_ip())); $this->assertEqual($record['session_logged_in'], 1); }
function get_client_ip() { return ip::encode_ip(sys::client_ip()); }