コード例 #1
0
 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 . ' ) ';
     }
 }