Changeset 17758 for extensions/EStat/lib/statDB.class.inc.php
- Timestamp:
- Sep 5, 2012, 4:15:54 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/EStat/lib/statDB.class.inc.php
r17737 r17758 193 193 * 194 194 * @param String $file 195 * @param Boolean $force: if true, $force the filename affectation even if file doesn't exist 195 196 * @return String: file name set 196 197 */ 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)) 200 201 $this->ipCountryFile=$file; 201 202 return($this->ipCountryFile); … … 728 729 break; 729 730 case 'between': 731 case 'not between': 730 732 if($field=='IPadress') 731 733 { … … 737 739 $num++; 738 740 } 739 $where[]=' '.$field. " BETWEEN ".$param['minValue']." AND ".$param['maxValue']." ";741 $where[]=' '.$field.' '.strtoupper($param['operator']).' '.$param['minValue']." AND ".$param['maxValue']." "; 740 742 break; 741 743 } … … 824 826 } 825 827 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 826 865 827 866 … … 856 895 case '<=': 857 896 case '!=': 897 case 'like': 898 case 'not like': 858 899 if(isset($value['value'])) 859 900 { … … 866 907 break; 867 908 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); 869 911 if($value['value']==null) return(null); 870 912 break; … … 893 935 break; 894 936 case 'IP': 895 $val=$this->checkValueIP($val );937 $val=$this->checkValueIP($val, 0); 896 938 if($val!=null) $returned[]=$val; 897 939 break; … … 910 952 break; 911 953 case 'between': 954 case 'not between': 912 955 if(isset($value['minValue']) and isset($value['maxValue'])) 913 956 { … … 921 964 break; 922 965 case 'IP': 923 $value['minValue']=$this->checkValueIP($value['minValue'] );966 $value['minValue']=$this->checkValueIP($value['minValue'], 0); 924 967 if($value['minValue']==null) return(null); 925 $value['maxValue']=$this->checkValueIP($value['maxValue'] );968 $value['maxValue']=$this->checkValueIP($value['maxValue'], 255); 926 969 if($value['maxValue']==null) return(null); 927 970 break; … … 981 1024 * 982 1025 * @param String $value 1026 * @param Integer $completeCode 983 1027 * @return String 984 1028 */ 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); 988 1032 if($returned=="\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") return(null); 989 1033 return($returned); … … 1000 1044 * 1001 1045 * @param String $IP: text IP string 1046 * @param Integer $completeCode 1002 1047 * @return String: a binary string 1003 1048 */ 1004 static public function IPBinaryEncode($IP )1049 static public function IPBinaryEncode($IP, $completeCode=0) 1005 1050 { 1006 1051 $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) 1008 1053 { 1009 1054 //IPv4 1010 1055 $tmp=explode('.',$value); 1056 while(count($tmp)<4) $tmp[]=$completeCode; 1057 1011 1058 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)); 1012 1059 } … … 1088 1135 1089 1136 1090 1091 1092 1137 /* 1138 used to display binary values when debug is necessary... 1139 1140 function 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 */ 1093 1154 1094 1155
Note: See TracChangeset
for help on using the changeset viewer.