Changeset 207


Ignore:
Timestamp:
10/03/2009 02:39:59 PM (2 years ago)
Author:
Acinonyx
Message:

[awmn] Fix undefined offset errors, replace correct_ip* functions with ip_to_ranges

Location:
branches/awmn
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/awmn/globals/functions.php

    r203 r207  
    237237} 
    238238 
    239 function correct_ip($ip, $ret_null=TRUE) { 
    240         if ($ip == '' && $ret_null === TRUE) return ''; 
     239function ip_to_ranges($ip, $ret_null=TRUE) { 
     240        if ($ip == '' && $ret_null === TRUE) return array(); 
    241241        $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; 
    295261} 
    296262 
  • branches/awmn/includes/pages/hostmaster/hostmaster_ranges.php

    r206 r207  
    4343                $where = $form_search_ranges->db_data_where(array('ip' => 'exclude', 'nodes__name' => 'starts_with')); 
    4444                $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                } 
    4854                if ($where!='') $where = substr($where, 0, -5); 
    4955                $table_ip_ranges->db_data( 
  • branches/awmn/includes/pages/ranges/ranges_search.php

    r201 r207  
    4343                $where = $form_search_ranges->db_data_where(array('ip' => 'exclude')); 
    4444                $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']; 
    4645                $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                } 
    5254                if ($where!='') $where = substr($where, 0, -5); 
    5355                $table_ip_ranges->db_data( 
     
    7981                $this->tpl['link_ranges_search'] = makelink(array("page" => "ranges", "subpage" => "search")); 
    8082                $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__); 
    8484                $this->tpl['table_ranges'] = $construct->table($this->table_ip_ranges(), __FILE__); 
    8585                return template($this->tpl, __FILE__); 
  • branches/awmn/includes/pages/search/search_suggest.php

    r198 r207  
    44* 
    55* Copyright (C) 2006 John Kolovos <cirrus@awmn.net> 
     6* Copyright (C) 2009 Vasilis Tsiligiannis <b_tsiligiannis@silverton.gr> 
    67* 
    78* This program is free software; you can redistribute it and/or modify 
     
    5657                        } 
    5758                } 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).")"; 
    6165                        $this->tpl['ip_search'] = $db->get( 
    6266                                                                                'ip_ranges.ip_start, nodes.id', 
Note: See TracChangeset for help on using the changeset viewer.