@@ -96,8 +96,7 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | $this->trapLog($message,$log_level,'syslog'); |
| 98 | 98 | return false; |
| 99 | - } |
|
| 100 | - else |
|
| 99 | + } else |
|
| 101 | 100 | { |
| 102 | 101 | $option_var=$option_array[$option_category][$option_name]; |
| 103 | 102 | return true; |
@@ -144,7 +143,9 @@ discard block |
||
| 144 | 143 | protected function getDBConfigIfSet($element,&$variable) |
| 145 | 144 | { |
| 146 | 145 | $value=$this->getDBConfig($element); |
| 147 | - if ($value != 'null') $variable=$value; |
|
| 146 | + if ($value != 'null') { |
|
| 147 | + $variable=$value; |
|
| 148 | + } |
|
| 148 | 149 | } |
| 149 | 150 | |
| 150 | 151 | /** Get data from db_config |
@@ -180,8 +181,11 @@ discard block |
||
| 180 | 181 | $message = '['. date("Y/m/d H:i:s") . '] ' . |
| 181 | 182 | '['. basename(__FILE__) . '] ['.$this->debug_text[$level].']: ' .$message . "\n"; |
| 182 | 183 | |
| 183 | - if ( $destination != '' ) $output=$destination; |
|
| 184 | - else $output=$this->alert_output; |
|
| 184 | + if ( $destination != '' ) { |
|
| 185 | + $output=$destination; |
|
| 186 | + } else { |
|
| 187 | + $output=$this->alert_output; |
|
| 188 | + } |
|
| 185 | 189 | switch ($output) |
| 186 | 190 | { |
| 187 | 191 | case 'file': |
@@ -216,7 +220,9 @@ discard block |
||
| 216 | 220 | switch ($output_type) |
| 217 | 221 | { |
| 218 | 222 | case 'file': |
| 219 | - if ($output_option == null) throw new Exception("File logging without file !"); |
|
| 223 | + if ($output_option == null) { |
|
| 224 | + throw new Exception("File logging without file !"); |
|
| 225 | + } |
|
| 220 | 226 | $this->debug_file=$output_option; |
| 221 | 227 | $this->alert_output='file'; |
| 222 | 228 | break; |
@@ -311,16 +317,14 @@ discard block |
||
| 311 | 317 | $this->trapLog("No Config/database in config file: ".$this->trap_module_config,ERROR,''); |
| 312 | 318 | } |
| 313 | 319 | $db_name=$trap_config['config']['database']; |
| 314 | - } |
|
| 315 | - else if ($database == 'ido') |
|
| 320 | + } else if ($database == 'ido') |
|
| 316 | 321 | { |
| 317 | 322 | if (!isset($trap_config['config']['IDOdatabase'])) |
| 318 | 323 | { |
| 319 | 324 | $this->trapLog("No Config/IDOdatabase in config file: ".$this->trap_module_config,ERROR,''); |
| 320 | 325 | } |
| 321 | 326 | $db_name=$trap_config['config']['IDOdatabase']; |
| 322 | - } |
|
| 323 | - else |
|
| 327 | + } else |
|
| 324 | 328 | { |
| 325 | 329 | $this->trapLog("Unknown database type : ".$database,ERROR,''); |
| 326 | 330 | } |
@@ -339,8 +343,12 @@ discard block |
||
| 339 | 343 | $db_sql_name=$db_config[$db_name]['dbname']; |
| 340 | 344 | $db_user=$db_config[$db_name]['username']; |
| 341 | 345 | $db_pass=$db_config[$db_name]['password']; |
| 342 | - if ($database == 'traps') $this->trapDBType = $db_type; |
|
| 343 | - if ($database == 'ido') $this->idoDBType = $db_type; |
|
| 346 | + if ($database == 'traps') { |
|
| 347 | + $this->trapDBType = $db_type; |
|
| 348 | + } |
|
| 349 | + if ($database == 'ido') { |
|
| 350 | + $this->idoDBType = $db_type; |
|
| 351 | + } |
|
| 344 | 352 | |
| 345 | 353 | $this->trapLog( "DB selected : $db_type $db_host $db_sql_name $db_user",3,''); |
| 346 | 354 | return array($db_type,$db_host,$db_sql_name,$db_user,$db_pass); |
@@ -381,8 +389,7 @@ discard block |
||
| 381 | 389 | { |
| 382 | 390 | $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)"); |
| 383 | 391 | $this->trapLog('Error parsing IP : '.$IP,ERROR,''); |
| 384 | - } |
|
| 385 | - else |
|
| 392 | + } else |
|
| 386 | 393 | { |
| 387 | 394 | $this->trap_data['source_ip']=$matches[1]; |
| 388 | 395 | $this->trap_data['destination_ip']=$matches[3]; |
@@ -396,14 +403,12 @@ discard block |
||
| 396 | 403 | if ($ret_code===0 || $ret_code===false) |
| 397 | 404 | { |
| 398 | 405 | $this->trapLog('No match on trap data : '.$vars,WARN,''); |
| 399 | - } |
|
| 400 | - else |
|
| 406 | + } else |
|
| 401 | 407 | { |
| 402 | 408 | if (($matches[1]=='.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1]=='.1.3.6.1.6.3.1.1.4.1')) |
| 403 | 409 | { |
| 404 | 410 | $this->trap_data['trap_oid']=$matches[2]; |
| 405 | - } |
|
| 406 | - else |
|
| 411 | + } else |
|
| 407 | 412 | { |
| 408 | 413 | $object= new stdClass; |
| 409 | 414 | $object->oid =$matches[1]; |
@@ -574,7 +579,9 @@ discard block |
||
| 574 | 579 | } |
| 575 | 580 | |
| 576 | 581 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
| 577 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 582 | + if ($inserted_id==false) { |
|
| 583 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 584 | + } |
|
| 578 | 585 | $this->trap_id=$inserted_id; |
| 579 | 586 | break; |
| 580 | 587 | default: |
@@ -590,7 +597,9 @@ discard block |
||
| 590 | 597 | { |
| 591 | 598 | |
| 592 | 599 | // If action is ignore -> don't send t DB |
| 593 | - if ($this->trap_to_db == false) return; |
|
| 600 | + if ($this->trap_to_db == false) { |
|
| 601 | + return; |
|
| 602 | + } |
|
| 594 | 603 | |
| 595 | 604 | |
| 596 | 605 | $db_conn=$this->db_connect_trap(); |
@@ -647,7 +656,9 @@ discard block |
||
| 647 | 656 | } |
| 648 | 657 | |
| 649 | 658 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
| 650 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 659 | + if ($inserted_id==false) { |
|
| 660 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 661 | + } |
|
| 651 | 662 | $this->trap_id=$inserted_id; |
| 652 | 663 | break; |
| 653 | 664 | default: |
@@ -776,8 +787,7 @@ discard block |
||
| 776 | 787 | // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default.... |
| 777 | 788 | exec('echo "'.$send.'" > ' .$this->icinga2cmd); |
| 778 | 789 | return true; |
| 779 | - } |
|
| 780 | - else |
|
| 790 | + } else |
|
| 781 | 791 | { |
| 782 | 792 | $api = $this->getAPI(); |
| 783 | 793 | $api->setCredentials($this->api_username, $this->api_password); |
@@ -786,8 +796,7 @@ discard block |
||
| 786 | 796 | { |
| 787 | 797 | $this->trapLog( "Error sending result : " .$retmessage,WARN,''); |
| 788 | 798 | return false; |
| 789 | - } |
|
| 790 | - else |
|
| 799 | + } else |
|
| 791 | 800 | { |
| 792 | 801 | $this->trapLog( "Sent result : " .$retmessage,3,''); |
| 793 | 802 | return true; |
@@ -847,7 +856,9 @@ discard block |
||
| 847 | 856 | /***************** Eval & tokenizer functions ****************/ |
| 848 | 857 | protected function eval_getElement($rule,&$item) |
| 849 | 858 | { |
| 850 | - while ($rule[$item]==' ') $item++; |
|
| 859 | + while ($rule[$item]==' ') { |
|
| 860 | + $item++; |
|
| 861 | + } |
|
| 851 | 862 | if (preg_match('/[0-9\.]/',$rule[$item])) |
| 852 | 863 | { // number |
| 853 | 864 | |
@@ -874,14 +885,15 @@ discard block |
||
| 874 | 885 | $start=$item; |
| 875 | 886 | $parenthesis_count=0; |
| 876 | 887 | while (($item < strlen($rule)) // Not end of string AND |
| 877 | - && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded () |
|
| 888 | + && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) { |
|
| 889 | + // Closing ')' or embeded () |
|
| 878 | 890 | { |
| 879 | 891 | if ($rule[$item] == '"' ) |
| 880 | 892 | { // pass through string |
| 881 | 893 | $item++; |
| 894 | + } |
|
| 882 | 895 | $item=$this->eval_getNext($rule,$item,'"'); |
| 883 | - } |
|
| 884 | - else{ |
|
| 896 | + } else{ |
|
| 885 | 897 | if ($rule[$item] == '(') |
| 886 | 898 | { |
| 887 | 899 | $parenthesis_count++; |
@@ -909,13 +921,17 @@ discard block |
||
| 909 | 921 | protected function eval_getNext($rule,$item,$tok) |
| 910 | 922 | { |
| 911 | 923 | while (($rule[$item] != $tok ) && ($item < strlen($rule))) { $item++;} |
| 912 | - if ($item==strlen($rule)) throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item); |
|
| 924 | + if ($item==strlen($rule)) { |
|
| 925 | + throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item); |
|
| 926 | + } |
|
| 913 | 927 | return $item+1; |
| 914 | 928 | } |
| 915 | 929 | |
| 916 | 930 | protected function eval_getOper($rule,&$item) |
| 917 | 931 | { |
| 918 | - while ($rule[$item]==' ') $item++; |
|
| 932 | + while ($rule[$item]==' ') { |
|
| 933 | + $item++; |
|
| 934 | + } |
|
| 919 | 935 | switch ($rule[$item]) |
| 920 | 936 | { |
| 921 | 937 | case '<': |
@@ -951,12 +967,13 @@ discard block |
||
| 951 | 967 | public function evaluation($rule,&$item) |
| 952 | 968 | { |
| 953 | 969 | //echo "Evaluation of ".substr($rule,$item)."\n"; |
| 954 | - if ( $rule[$item] == '!') // If '!' found, negate next expression. |
|
| 970 | + if ( $rule[$item] == '!') { |
|
| 971 | + // If '!' found, negate next expression. |
|
| 955 | 972 | { |
| 956 | 973 | $negate=true; |
| 957 | - $item++; |
|
| 958 | 974 | } |
| 959 | - else |
|
| 975 | + $item++; |
|
| 976 | + } else |
|
| 960 | 977 | { |
| 961 | 978 | $negate=false; |
| 962 | 979 | } |
@@ -964,10 +981,14 @@ discard block |
||
| 964 | 981 | list($type1,$val1) = $this->eval_getElement($rule,$item); |
| 965 | 982 | //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n"; |
| 966 | 983 | |
| 967 | - if ($item==strlen($rule)) // If only element, return value, but only boolean |
|
| 984 | + if ($item==strlen($rule)) { |
|
| 985 | + // If only element, return value, but only boolean |
|
| 968 | 986 | { |
| 969 | 987 | if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule); |
| 970 | - if ($negate == true) $val1= ! $val1; |
|
| 988 | + } |
|
| 989 | + if ($negate == true) { |
|
| 990 | + $val1= ! $val1; |
|
| 991 | + } |
|
| 971 | 992 | return $val1; |
| 972 | 993 | } |
| 973 | 994 | |
@@ -976,27 +997,34 @@ discard block |
||
| 976 | 997 | //echo "Comp : ".$comp." : ".substr($rule,$item)."\n"; |
| 977 | 998 | |
| 978 | 999 | // Third element : number, string or () |
| 979 | - if ( $rule[$item] == '!') // starts with a ! so evaluate whats next |
|
| 1000 | + if ( $rule[$item] == '!') { |
|
| 1001 | + // starts with a ! so evaluate whats next |
|
| 980 | 1002 | { |
| 981 | 1003 | $item++; |
| 982 | - if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 1004 | + } |
|
| 1005 | + if ($typec != 1) { |
|
| 1006 | + throw new Exception("Mixing boolean and comparison : ".$rule); |
|
| 1007 | + } |
|
| 983 | 1008 | $val2= ! $this->evaluation($rule,$item); |
| 984 | 1009 | $type2=2; // result is a boolean |
| 985 | - } |
|
| 986 | - else |
|
| 1010 | + } else |
|
| 987 | 1011 | { |
| 988 | 1012 | list($type2,$val2) = $this->eval_getElement($rule,$item); |
| 989 | 1013 | } |
| 990 | 1014 | //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n"; |
| 991 | 1015 | |
| 992 | - if ($type1!=$type2) // cannot compare different types |
|
| 1016 | + if ($type1!=$type2) { |
|
| 1017 | + // cannot compare different types |
|
| 993 | 1018 | { |
| 994 | 1019 | throw new Exception("Cannot compare string & number : ".$rule); |
| 995 | 1020 | } |
| 996 | - if ($typec==1 && $type1 !=2) // cannot use & or | with string/number |
|
| 1021 | + } |
|
| 1022 | + if ($typec==1 && $type1 !=2) { |
|
| 1023 | + // cannot use & or | with string/number |
|
| 997 | 1024 | { |
| 998 | 1025 | throw new Exception("Cannot use boolean operators with string & number : ".$rule); |
| 999 | 1026 | } |
| 1027 | + } |
|
| 1000 | 1028 | |
| 1001 | 1029 | switch ($comp){ |
| 1002 | 1030 | case '<': $retVal= ($val1 < $val2); break; |
@@ -1010,9 +1038,15 @@ discard block |
||
| 1010 | 1038 | case '&': $retVal= ($val1 && $val2); break; |
| 1011 | 1039 | default: throw new Exception("Error in expression - unknown comp : ".$comp); |
| 1012 | 1040 | } |
| 1013 | - if ($negate == true) $retVal = ! $retVal; // Inverse result if negate before expression |
|
| 1041 | + if ($negate == true) { |
|
| 1042 | + $retVal = ! $retVal; |
|
| 1043 | + } |
|
| 1044 | + // Inverse result if negate before expression |
|
| 1014 | 1045 | |
| 1015 | - if ($item==strlen($rule)) return $retVal; // End of string : return evaluation |
|
| 1046 | + if ($item==strlen($rule)) { |
|
| 1047 | + return $retVal; |
|
| 1048 | + } |
|
| 1049 | + // End of string : return evaluation |
|
| 1016 | 1050 | // check for logical operator : |
| 1017 | 1051 | switch ($rule[$item]) |
| 1018 | 1052 | { |
@@ -1039,7 +1073,9 @@ discard block |
||
| 1039 | 1073 | $rule2.=$rule[$item]; |
| 1040 | 1074 | $item++; |
| 1041 | 1075 | } |
| 1042 | - if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 1076 | + if ($item == strlen ($rule)) { |
|
| 1077 | + throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 1078 | + } |
|
| 1043 | 1079 | $rule2.=$rule[$item]; |
| 1044 | 1080 | $item++; |
| 1045 | 1081 | continue; |
@@ -1059,10 +1095,12 @@ discard block |
||
| 1059 | 1095 | |
| 1060 | 1096 | protected function eval_rule($rule) |
| 1061 | 1097 | { |
| 1062 | - if ($rule==null || $rule == '') // Empty rule is always true |
|
| 1098 | + if ($rule==null || $rule == '') { |
|
| 1099 | + // Empty rule is always true |
|
| 1063 | 1100 | { |
| 1064 | 1101 | return true; |
| 1065 | 1102 | } |
| 1103 | + } |
|
| 1066 | 1104 | $matches=array(); |
| 1067 | 1105 | while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1) |
| 1068 | 1106 | { |
@@ -1149,20 +1187,17 @@ discard block |
||
| 1149 | 1187 | if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false) |
| 1150 | 1188 | { |
| 1151 | 1189 | $this->trap_action.='Error sending status : check cmd/API'; |
| 1152 | - } |
|
| 1153 | - else |
|
| 1190 | + } else |
|
| 1154 | 1191 | { |
| 1155 | 1192 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 1156 | 1193 | $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name; |
| 1157 | 1194 | } |
| 1158 | - } |
|
| 1159 | - else |
|
| 1195 | + } else |
|
| 1160 | 1196 | { |
| 1161 | 1197 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 1162 | 1198 | } |
| 1163 | 1199 | $this->trap_to_db=($action==-2)?false:true; |
| 1164 | - } |
|
| 1165 | - else |
|
| 1200 | + } else |
|
| 1166 | 1201 | { |
| 1167 | 1202 | //$this->trapLog('rules KOO : '.print_r($rule),3,''); |
| 1168 | 1203 | |
@@ -1173,14 +1208,12 @@ discard block |
||
| 1173 | 1208 | if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false) |
| 1174 | 1209 | { |
| 1175 | 1210 | $this->trap_action.='Error sending status : check cmd/API'; |
| 1176 | - } |
|
| 1177 | - else |
|
| 1211 | + } else |
|
| 1178 | 1212 | { |
| 1179 | 1213 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 1180 | 1214 | $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name; |
| 1181 | 1215 | } |
| 1182 | - } |
|
| 1183 | - else |
|
| 1216 | + } else |
|
| 1184 | 1217 | { |
| 1185 | 1218 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 1186 | 1219 | } |
@@ -1190,16 +1223,14 @@ discard block |
||
| 1190 | 1223 | if (!isset($this->trap_data['source_name'])) |
| 1191 | 1224 | { |
| 1192 | 1225 | $this->trap_data['source_name']=$rule['host_name']; |
| 1193 | - } |
|
| 1194 | - else |
|
| 1226 | + } else |
|
| 1195 | 1227 | { |
| 1196 | 1228 | if (!preg_match('/'.$rule['host_name'].'/',$this->trap_data['source_name'])) |
| 1197 | 1229 | { // only add if not present |
| 1198 | 1230 | $this->trap_data['source_name'].=','.$rule['host_name']; |
| 1199 | 1231 | } |
| 1200 | 1232 | } |
| 1201 | - } |
|
| 1202 | - catch (Exception $e) |
|
| 1233 | + } catch (Exception $e) |
|
| 1203 | 1234 | { |
| 1204 | 1235 | $this->trapLog('Error in rule eval : '.$e->getMessage(),WARN,''); |
| 1205 | 1236 | $this->trap_action.=' ERR : '.$e->getMessage(); |
@@ -1210,8 +1241,7 @@ discard block |
||
| 1210 | 1241 | if ($this->trap_data['status']=='error') |
| 1211 | 1242 | { |
| 1212 | 1243 | $this->trap_to_db=true; // Always put errors in DB for the use can see |
| 1213 | - } |
|
| 1214 | - else |
|
| 1244 | + } else |
|
| 1215 | 1245 | { |
| 1216 | 1246 | $this->trap_data['status']='done'; |
| 1217 | 1247 | } |
@@ -1265,8 +1295,7 @@ discard block |
||
| 1265 | 1295 | if (preg_match('/^ *CREATE TABLE ([^ ]+)/',$newline,$cur_table_array)) |
| 1266 | 1296 | { |
| 1267 | 1297 | $cur_table='table '.$cur_table_array[1]; |
| 1268 | - } |
|
| 1269 | - else |
|
| 1298 | + } else |
|
| 1270 | 1299 | { |
| 1271 | 1300 | $cur_table='secret SQL stuff :-)'; |
| 1272 | 1301 | } |
@@ -1310,8 +1339,7 @@ discard block |
||
| 1310 | 1339 | if ($this->trapDBType == 'pgsql') |
| 1311 | 1340 | { |
| 1312 | 1341 | $prefix .= 'update_pgsql/schema_'; |
| 1313 | - } |
|
| 1314 | - else |
|
| 1342 | + } else |
|
| 1315 | 1343 | { |
| 1316 | 1344 | $prefix .= 'update_sql/schema_'; |
| 1317 | 1345 | } |
@@ -1357,7 +1385,10 @@ discard block |
||
| 1357 | 1385 | $db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 1358 | 1386 | while (($line=fgets($input_stream)) != FALSE) |
| 1359 | 1387 | { |
| 1360 | - if (preg_match('/^#/', $line)) continue; // ignore comment lines |
|
| 1388 | + if (preg_match('/^#/', $line)) { |
|
| 1389 | + continue; |
|
| 1390 | + } |
|
| 1391 | + // ignore comment lines |
|
| 1361 | 1392 | $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line)); |
| 1362 | 1393 | if (preg_match('/; *$/', $newline)) |
| 1363 | 1394 | { |
@@ -1369,8 +1400,7 @@ discard block |
||
| 1369 | 1400 | if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/',$newline,$cur_table_array)) |
| 1370 | 1401 | { |
| 1371 | 1402 | $cur_table=$cur_table_array[1] . ' SQL table '.$cur_table_array[2]; |
| 1372 | - } |
|
| 1373 | - else |
|
| 1403 | + } else |
|
| 1374 | 1404 | { |
| 1375 | 1405 | $cur_table='secret SQL stuff :-)'; |
| 1376 | 1406 | $cur_table=$newline; |
@@ -1508,8 +1538,7 @@ discard block |
||
| 1508 | 1538 | } |
| 1509 | 1539 | $this->trapLog('Trap updated : '.$name . ' / OID : '.$oid,4,''); |
| 1510 | 1540 | return 1; |
| 1511 | - } |
|
| 1512 | - else |
|
| 1541 | + } else |
|
| 1513 | 1542 | { |
| 1514 | 1543 | $this->trapLog('Trap unchanged : '.$name . ' / OID : '.$oid,4,''); |
| 1515 | 1544 | return 0; |
@@ -1525,7 +1554,9 @@ discard block |
||
| 1525 | 1554 | 'values (:oid, :name , :type ,:mib ,:tc , :display_hint'. |
| 1526 | 1555 | ', :syntax, :type_enum, :description )'; |
| 1527 | 1556 | |
| 1528 | - if ($this->trapDBType == 'pgsql') $sql .= 'RETURNING id'; |
|
| 1557 | + if ($this->trapDBType == 'pgsql') { |
|
| 1558 | + $sql .= 'RETURNING id'; |
|
| 1559 | + } |
|
| 1529 | 1560 | |
| 1530 | 1561 | $sqlQuery=$db_conn->prepare($sql); |
| 1531 | 1562 | |
@@ -1565,7 +1596,9 @@ discard block |
||
| 1565 | 1596 | } |
| 1566 | 1597 | |
| 1567 | 1598 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
| 1568 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 1599 | + if ($inserted_id==false) { |
|
| 1600 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 1601 | + } |
|
| 1569 | 1602 | $this->dbOidIndex[$oid]['id']=$inserted_id; |
| 1570 | 1603 | break; |
| 1571 | 1604 | default: |
@@ -1818,12 +1851,14 @@ discard block |
||
| 1818 | 1851 | $name=$match[1]; // Name |
| 1819 | 1852 | $type=$match[2]; // type (21=trap, 0: may be trap, else : not trap |
| 1820 | 1853 | |
| 1821 | - if ($type==0) // object type=0 : check if v1 trap |
|
| 1854 | + if ($type==0) { |
|
| 1855 | + // object type=0 : check if v1 trap |
|
| 1822 | 1856 | { |
| 1823 | 1857 | // Check if next is suboid -> in that case is cannot be a trap |
| 1824 | 1858 | if (preg_match("/^$oid/",$this->objectsAll[$curElement+1])) |
| 1825 | 1859 | { |
| 1826 | 1860 | $time_check2 += microtime(true) - $time_1; |
| 1861 | + } |
|
| 1827 | 1862 | $time_check2N++; |
| 1828 | 1863 | continue; |
| 1829 | 1864 | } |
@@ -1840,9 +1875,11 @@ discard block |
||
| 1840 | 1875 | // Force as trap. |
| 1841 | 1876 | $type=21; |
| 1842 | 1877 | } |
| 1843 | - if ($onlyTraps==true && $type!=21) // if only traps and not a trap, continue |
|
| 1878 | + if ($onlyTraps==true && $type!=21) { |
|
| 1879 | + // if only traps and not a trap, continue |
|
| 1844 | 1880 | { |
| 1845 | 1881 | $time_check3 += microtime(true) - $time_1; |
| 1882 | + } |
|
| 1846 | 1883 | $time_check3N++; |
| 1847 | 1884 | continue; |
| 1848 | 1885 | } |
@@ -1850,7 +1887,10 @@ discard block |
||
| 1850 | 1887 | $time_num_traps++; |
| 1851 | 1888 | |
| 1852 | 1889 | $this->trapLog('Found trap : '.$match[1] . ' / OID : '.$oid,3,''); |
| 1853 | - if ($display_progress) echo '#'; // echo a # when trap found |
|
| 1890 | + if ($display_progress) { |
|
| 1891 | + echo '#'; |
|
| 1892 | + } |
|
| 1893 | + // echo a # when trap found |
|
| 1854 | 1894 | |
| 1855 | 1895 | // get trap objects & source MIB |
| 1856 | 1896 | unset($snmptrans); |
@@ -1868,7 +1908,9 @@ discard block |
||
| 1868 | 1908 | $trapMib=$match[1]; |
| 1869 | 1909 | |
| 1870 | 1910 | $numLine=1;$trapDesc=''; |
| 1871 | - while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++; |
|
| 1911 | + while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) { |
|
| 1912 | + $numLine++; |
|
| 1913 | + } |
|
| 1872 | 1914 | if (isset($snmptrans[$numLine])) |
| 1873 | 1915 | { |
| 1874 | 1916 | $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]); |
@@ -1890,7 +1932,9 @@ discard block |
||
| 1890 | 1932 | if (($update==0) && ($check_change==false)) |
| 1891 | 1933 | { // Trapd didn't change & force check disabled |
| 1892 | 1934 | $time_objects += microtime(true) - $time_1; |
| 1893 | - if ($display_progress) echo "C"; |
|
| 1935 | + if ($display_progress) { |
|
| 1936 | + echo "C"; |
|
| 1937 | + } |
|
| 1894 | 1938 | continue; |
| 1895 | 1939 | } |
| 1896 | 1940 | |