Changeset 207
- Timestamp:
- 10/03/2009 02:39:59 PM (2 years ago)
- Location:
- branches/awmn
- Files:
-
- 4 edited
-
globals/functions.php (modified) (1 diff)
-
includes/pages/hostmaster/hostmaster_ranges.php (modified) (1 diff)
-
includes/pages/ranges/ranges_search.php (modified) (2 diffs)
-
includes/pages/search/search_suggest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/awmn/globals/functions.php
r203 r207 237 237 } 238 238 239 function correct_ip($ip, $ret_null=TRUE) {240 if ($ip == '' && $ret_null === TRUE) return '';239 function ip_to_ranges($ip, $ret_null=TRUE) { 240 if ($ip == '' && $ret_null === TRUE) return array(); 241 241 $t = explode(".", $ip, 4); 242 for ($i=0;$i<4;$i++) { 243 $t[$i] = (integer)($t[$i]); 244 } 245 return implode(".", $t); 246 } 247 248 function correct_ip_min($ip, $ret_null=TRUE, $pad=3) { 249 if ($ip == '' && $ret_null === TRUE) return ''; 250 $t = explode(".", $ip, 4); 251 for ($i=0;$i<4;$i++) { 252 if(!isset($t[$i+1]) && $t[$i] != null) { 253 switch (substr($t[$i], 0, 1)) { 254 case '0': 255 break; 256 case '1': 257 case '2': 258 $t[$i] = intval(str_pad($t[$i], (substr($t[$i], 1, 1) >= 6?2:$pad), "0")); 259 break; 260 default: 261 $t[$i] = intval(str_pad($t[$i], ($pad==3?2:$pad), "0")); 262 } 263 }elseif($t[$i] == null) { 264 $t[$i] = 0; 265 }else{ 266 $t[$i] = (integer)($t[$i]); 267 } 268 } 269 return implode(".", $t); 270 } 271 272 function correct_ip_max($ip, $ret_null=TRUE, $pad=3) { 273 if ($ip == '' && $ret_null === TRUE) return ''; 274 $t = explode(".", $ip, 4); 275 for ($i=0;$i<4;$i++) { 276 if(!isset($t[$i+1]) && $t[$i] != null) { 277 switch (substr($t[$i], 0, 1)) { 278 case '0': 279 break; 280 case '1': 281 case '2': 282 $t[$i] = intval(str_pad($t[$i], (substr($t[$i], 1, 1) >= 6?2:$pad), "9")); 283 break; 284 default: 285 $t[$i] = intval(str_pad($t[$i], ($pad==3?2:$pad), "9")); 286 } 287 if ($t[$i] > 255) $t[$i] = 255; 288 }elseif($t[$i] == null) { 289 $t[$i] = 255; 290 }else{ 291 $t[$i] = (integer)($t[$i]); 292 } 293 } 294 return implode(".", $t); 242 for ($i=0;$i<=3;$i++) { 243 if (isset($t[$i]) && $t[$i] != '' && $i != 3) $t[$i] = $t1[$i] = $t2[$i] = (integer)($t[$i]); 244 else { 245 $t1[$i] = 0; 246 $t2[$i] = 255; 247 } 248 } 249 $ret[] = array("min" => implode(".", $t1), "max" => implode(".", $t2)); 250 $p = count($t) - 1; 251 if ($p <= 2 && $t[$p] != 0) { 252 $d = 2 - intval(log10($t[$p])); 253 for ($i=1;$i<=$d;$i++) { 254 $t1[$p] = $t[$p] * pow(10,$i); 255 $t2[$p] = $t1[$p] + pow(10,$i) - 1; 256 if ($t2[$p] > 255) $t2[$p] = 255; 257 $ret[] = array("min" => implode(".", $t1), "max" => implode(".", $t2)); 258 } 259 } 260 return $ret; 295 261 } 296 262 -
branches/awmn/includes/pages/hostmaster/hostmaster_ranges.php
r206 r207 43 43 $where = $form_search_ranges->db_data_where(array('ip' => 'exclude', 'nodes__name' => 'starts_with')); 44 44 $table_ip_ranges = new table(array('TABLE_NAME' => 'table_ip_ranges', 'FORM_NAME' => 'table_ip_ranges')); 45 $s_ip = correct_ip($form_search_ranges->data[0]['value']); 46 $where = ($where !=''?"(".$where.") AND ":""). 47 ($s_ip !=''?"ip_ranges.ip_start <= ".ip2long($s_ip)." AND ip_ranges.ip_end >= ".ip2long($s_ip)." AND ":""); 45 $where = ($where !=''?"(".$where.") AND ":""); 46 if ($form_search_ranges->data[0]['value'] != '') { 47 $where .= "("; 48 $s_ranges = ip_to_ranges($form_search_ranges->data[0]['value']); 49 foreach ($s_ranges as $s_range) { 50 $where .= "(ip_ranges.ip_start BETWEEN ".ip2long($s_range['min'])." AND ".ip2long($s_range['max']).") OR "; 51 } 52 $where = substr($where, 0, -4).") AND "; 53 } 48 54 if ($where!='') $where = substr($where, 0, -5); 49 55 $table_ip_ranges->db_data( -
branches/awmn/includes/pages/ranges/ranges_search.php
r201 r207 43 43 $where = $form_search_ranges->db_data_where(array('ip' => 'exclude')); 44 44 $table_ip_ranges = new table(array('TABLE_NAME' => 'table_ip_ranges', 'FORM_NAME' => 'table_ip_ranges')); 45 $s_ip = $form_search_ranges->data[0]['value'];46 45 $where = ($where !=''?"(".$where.") AND ":""); 47 if ($s_ip !='') $where .= '(ip_ranges.ip_start >= '.ip2long(correct_ip_min($s_ip, TRUE, 1)).' AND ip_ranges.ip_start <= '.ip2long(correct_ip_max($s_ip, TRUE, 1)).") OR ". 48 '(ip_ranges.ip_start >= '.ip2long(correct_ip_min($s_ip, TRUE, 2)).' AND ip_ranges.ip_start <= '.ip2long(correct_ip_max($s_ip, TRUE, 2)).") OR ". 49 '(ip_ranges.ip_start >= '.ip2long(correct_ip_min($s_ip, TRUE, 3)).' AND ip_ranges.ip_start <= '.ip2long(correct_ip_max($s_ip, TRUE, 3)).") AND "; 50 //$where = 51 // ($s_ip !=''?"ip_ranges.ip_start <= ".ip2long($s_ip)." AND ip_ranges.ip_end >= ".ip2long($s_ip)." AND ":""); 46 if ($form_search_ranges->data[0]['value'] != '') { 47 $where .= "("; 48 $s_ranges = ip_to_ranges($form_search_ranges->data[0]['value']); 49 foreach ($s_ranges as $s_range) { 50 $where .= "(ip_ranges.ip_start BETWEEN ".ip2long($s_range['min'])." AND ".ip2long($s_range['max']).") OR "; 51 } 52 $where = substr($where, 0, -4).") AND "; 53 } 52 54 if ($where!='') $where = substr($where, 0, -5); 53 55 $table_ip_ranges->db_data( … … 79 81 $this->tpl['link_ranges_search'] = makelink(array("page" => "ranges", "subpage" => "search")); 80 82 $this->tpl['link_ranges_allocation'] = makelink(array("page" => "ranges", "subpage" => "allocation")); 81 $form_search_ranges = $this->form_search_ranges(); 82 //if ($form_search_ranges->data[0]['value'] != '') $form_search_ranges->data[0]['value'] = correct_ip($form_search_ranges->data[0]['value']); 83 $this->tpl['form_search_ranges'] = $construct->form($form_search_ranges, __FILE__); 83 $this->tpl['form_search_ranges'] = $construct->form($this->form_search_ranges(), __FILE__); 84 84 $this->tpl['table_ranges'] = $construct->table($this->table_ip_ranges(), __FILE__); 85 85 return template($this->tpl, __FILE__); -
branches/awmn/includes/pages/search/search_suggest.php
r198 r207 4 4 * 5 5 * Copyright (C) 2006 John Kolovos <cirrus@awmn.net> 6 * Copyright (C) 2009 Vasilis Tsiligiannis <b_tsiligiannis@silverton.gr> 6 7 * 7 8 * This program is free software; you can redistribute it and/or modify … … 56 57 } 57 58 } elseif (is_ip($q, FALSE)) { 58 $where = '(ip_ranges.ip_start >= '.ip2long(correct_ip_min($q, TRUE, 1)).' AND ip_ranges.ip_start <= '.ip2long(correct_ip_max($q, TRUE, 1)).") OR ". 59 '(ip_ranges.ip_start >= '.ip2long(correct_ip_min($q, TRUE, 2)).' AND ip_ranges.ip_start <= '.ip2long(correct_ip_max($q, TRUE, 2)).") OR ". 60 '(ip_ranges.ip_start >= '.ip2long(correct_ip_min($q, TRUE, 3)).' AND ip_ranges.ip_start <= '.ip2long(correct_ip_max($q, TRUE, 3)).")"; 59 $where = "("; 60 $s_ranges = ip_to_ranges($q,FALSE); 61 foreach ($s_ranges as $s_range) { 62 $where .= "(ip_ranges.ip_start BETWEEN ".ip2long($s_range['min'])." AND ".ip2long($s_range['max']).") OR "; 63 } 64 $where = substr($where, 0, -4).")"; 61 65 $this->tpl['ip_search'] = $db->get( 62 66 'ip_ranges.ip_start, nodes.id',
Note: See TracChangeset
for help on using the changeset viewer.
