Ignore:
Timestamp:
Sep 5, 2012, 4:15:54 PM (12 years ago)
Author:
grum
Message:

version 0.1.0b

. Fix install bugs
. Manage anonymous directories
. Manage CSV export options settings
. Fix IPadress<=>country association bug & improve join performances
. Fix bug on IP filter
. Improve performances for history consult

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/EStat/lib/statDB.class.inc.php

    r17737 r17758  
    193193   *
    194194   * @param String $file
     195   * @param Boolean $force: if true, $force the filename affectation even if file doesn't exist
    195196   * @return String: file name set
    196197   */
    197   public function setIpCountryFile($file)
    198   {
    199     if(file_exists($file))
     198  public function setIpCountryFile($file, $force=false)
     199  {
     200    if($force or file_exists($file))
    200201      $this->ipCountryFile=$file;
    201202    return($this->ipCountryFile);
     
    728729            break;
    729730          case 'between':
     731          case 'not between':
    730732            if($field=='IPadress')
    731733            {
     
    737739              $num++;
    738740            }
    739             $where[]=' '.$field." BETWEEN ".$param['minValue']." AND ".$param['maxValue']." ";
     741            $where[]=' '.$field.' '.strtoupper($param['operator']).' '.$param['minValue']." AND ".$param['maxValue']." ";
    740742            break;
    741743        }
     
    824826  }
    825827
     828
     829  /**
     830   * to be used with IP filter: replace the given operator with 'between' or 'not between'
     831   *
     832   * @param Array $value
     833   * @return Array
     834   */
     835  protected function checkIPFilter($value)
     836  {
     837    if(is_array($value))
     838    {
     839      if(isset($value['operator']))
     840      {
     841        if($value['operator']=='=' or
     842           $value['operator']=='>' or
     843           $value['operator']=='>=' or
     844           $value['operator']=='<' or
     845           $value['operator']=='<=' or
     846           $value['operator']=='like')
     847        {
     848          $value['operator']='between';
     849          $value['minValue']=$value['value'];
     850          $value['maxValue']=$value['value'];
     851          $value['value']=null;
     852        }
     853        elseif($value['operator']=='!=' or
     854               $value['operator']=='not like')
     855        {
     856          $value['operator']='not between';
     857          $value['minValue']=$value['value'];
     858          $value['maxValue']=$value['value'];
     859          $value['value']=null;
     860        }
     861      }
     862    }
     863    return($value);
     864  } // checkIPFilter
    826865
    827866
     
    856895          case '<=':
    857896          case '!=':
     897          case 'like':
     898          case 'not like':
    858899            if(isset($value['value']))
    859900            {
     
    866907                  break;
    867908                case 'IP':
    868                   $value['value']=$this->checkValueIP($value['value']);
     909                  // for IP, replace internaly the operator with a 'between'
     910                  $value['value']=$this->checkValueIP($value['value'], 0);
    869911                  if($value['value']==null) return(null);
    870912                  break;
     
    893935                    break;
    894936                  case 'IP':
    895                     $val=$this->checkValueIP($val);
     937                    $val=$this->checkValueIP($val, 0);
    896938                    if($val!=null) $returned[]=$val;
    897939                    break;
     
    910952            break;
    911953          case 'between':
     954          case 'not between':
    912955            if(isset($value['minValue']) and  isset($value['maxValue']))
    913956            {
     
    921964                  break;
    922965                case 'IP':
    923                   $value['minValue']=$this->checkValueIP($value['minValue']);
     966                  $value['minValue']=$this->checkValueIP($value['minValue'], 0);
    924967                  if($value['minValue']==null) return(null);
    925                   $value['maxValue']=$this->checkValueIP($value['maxValue']);
     968                  $value['maxValue']=$this->checkValueIP($value['maxValue'], 255);
    926969                  if($value['maxValue']==null) return(null);
    927970                  break;
     
    9811024   *
    9821025   * @param String $value
     1026   * @param Integer $completeCode
    9831027   * @return String
    9841028   */
    985   protected function checkValueIP($value)
    986   {
    987     $returned=self::IPBinaryEncode($value);
     1029  protected function checkValueIP($value, $completeCode=0)
     1030  {
     1031    $returned=self::IPBinaryEncode($value, $completeCode);
    9881032    if($returned=="\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") return(null);
    9891033    return($returned);
     
    10001044   *
    10011045   * @param String $IP: text IP string
     1046   * @param Integer $completeCode
    10021047   * @return String: a binary string
    10031048   */
    1004   static public function IPBinaryEncode($IP)
     1049  static public function IPBinaryEncode($IP, $completeCode=0)
    10051050  {
    10061051    $value=trim($IP);
    1007     if(preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/i',$value)>0)
     1052    if(preg_match('/\d{1,3}(\.\d{1,3}(\.\d{1,3}(\.\d{1,3})?)?)?/i',$value)>0)
    10081053    {
    10091054      //IPv4
    10101055      $tmp=explode('.',$value);
     1056      while(count($tmp)<4) $tmp[]=$completeCode;
     1057
    10111058      return("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".chr($tmp[0]+0).chr($tmp[1]+0).chr($tmp[2]+0).chr($tmp[3]+0));
    10121059    }
     
    10881135
    10891136
    1090 
    1091 
    1092 
     1137/*
     1138 used to display binary values when debug is necessary...
     1139
     1140function toHexDump($data)
     1141  {
     1142    $returned="";
     1143    $maxItems=strlen($data);
     1144
     1145    $tmp=array();
     1146    for($i=0;$i<$maxItems;$i++)
     1147    {
     1148      $tmp[]=sprintf("%02x", ord($data{$i}));
     1149    }
     1150    $returned.=implode(" ", $tmp);
     1151    return($returned);
     1152  }
     1153*/
    10931154
    10941155
Note: See TracChangeset for help on using the changeset viewer.