@@ -20,8 +20,7 @@ discard block |
||
| 20 | 20 | if (isset($postData['hostFilter'])) |
| 21 | 21 | { |
| 22 | 22 | $hostFilter=$postData['hostFilter']; |
| 23 | - } |
|
| 24 | - else |
|
| 23 | + } else |
|
| 25 | 24 | { |
| 26 | 25 | $this->_helper->json(array('status'=>'KO')); |
| 27 | 26 | return; |
@@ -48,8 +47,7 @@ discard block |
||
| 48 | 47 | if (isset($postData['hostFilter'])) |
| 49 | 48 | { |
| 50 | 49 | $hostFilter=$postData['hostFilter']; |
| 51 | - } |
|
| 52 | - else |
|
| 50 | + } else |
|
| 53 | 51 | { |
| 54 | 52 | $this->_helper->json(array('status'=>'Error : no filter')); |
| 55 | 53 | return; |
@@ -79,8 +77,7 @@ discard block |
||
| 79 | 77 | if (isset($postData['host'])) |
| 80 | 78 | { |
| 81 | 79 | $host=$postData['host']; |
| 82 | - } |
|
| 83 | - else |
|
| 80 | + } else |
|
| 84 | 81 | { |
| 85 | 82 | $this->_helper->json(array('status'=>'No Hosts','hostid' => -1)); |
| 86 | 83 | return; |
@@ -91,8 +88,7 @@ discard block |
||
| 91 | 88 | { |
| 92 | 89 | $this->_helper->json(array('status'=>'More than one host matches','hostid' => -1)); |
| 93 | 90 | return; |
| 94 | - } |
|
| 95 | - else if (count($hostArray) == 0) |
|
| 91 | + } else if (count($hostArray) == 0) |
|
| 96 | 92 | { |
| 97 | 93 | $this->_helper->json(array('status'=>'No host matches','hostid' => -1)); |
| 98 | 94 | return; |
@@ -123,8 +119,7 @@ discard block |
||
| 123 | 119 | if (isset($postData['host'])) |
| 124 | 120 | { |
| 125 | 121 | $host=$postData['host']; |
| 126 | - } |
|
| 127 | - else |
|
| 122 | + } else |
|
| 128 | 123 | { |
| 129 | 124 | $this->_helper->json(array('status'=>'No Hosts','hostid' => -1)); |
| 130 | 125 | return; |
@@ -135,8 +130,7 @@ discard block |
||
| 135 | 130 | { |
| 136 | 131 | $this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1)); |
| 137 | 132 | return; |
| 138 | - } |
|
| 139 | - else if (count($hostArray) == 0) |
|
| 133 | + } else if (count($hostArray) == 0) |
|
| 140 | 134 | { |
| 141 | 135 | $this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1)); |
| 142 | 136 | return; |
@@ -163,8 +157,7 @@ discard block |
||
| 163 | 157 | if (isset($postData['mib'])) |
| 164 | 158 | { |
| 165 | 159 | $mib=$postData['mib']; |
| 166 | - } |
|
| 167 | - else |
|
| 160 | + } else |
|
| 168 | 161 | { |
| 169 | 162 | $this->_helper->json(array('status'=>'No mib')); |
| 170 | 163 | return; |
@@ -173,8 +166,7 @@ discard block |
||
| 173 | 166 | { |
| 174 | 167 | $traplist=$this->getMIB()->getTrapList($mib); |
| 175 | 168 | $retTraps=array('status'=>'OK','traps' => $traplist); |
| 176 | - } |
|
| 177 | - catch (Exception $e) |
|
| 169 | + } catch (Exception $e) |
|
| 178 | 170 | { |
| 179 | 171 | $retTraps=array('status' => 'Error getting mibs'); |
| 180 | 172 | } |
@@ -192,8 +184,7 @@ discard block |
||
| 192 | 184 | if (isset($postData['trap'])) |
| 193 | 185 | { |
| 194 | 186 | $trap=$postData['trap']; |
| 195 | - } |
|
| 196 | - else |
|
| 187 | + } else |
|
| 197 | 188 | { |
| 198 | 189 | $this->_helper->json(array('status'=>'No trap')); |
| 199 | 190 | return; |
@@ -202,8 +193,7 @@ discard block |
||
| 202 | 193 | { |
| 203 | 194 | $objectlist=$this->getMIB()->getObjectList($trap); |
| 204 | 195 | $retObjects=array('status'=>'OK','objects' => $objectlist); |
| 205 | - } |
|
| 206 | - catch (Exception $e) |
|
| 196 | + } catch (Exception $e) |
|
| 207 | 197 | { |
| 208 | 198 | $retObjects=array('status' => 'not found'); |
| 209 | 199 | } |
@@ -218,8 +208,7 @@ discard block |
||
| 218 | 208 | try |
| 219 | 209 | { |
| 220 | 210 | $miblist=$this->getMIB()->getMIBList(); |
| 221 | - } |
|
| 222 | - catch (Exception $e) |
|
| 211 | + } catch (Exception $e) |
|
| 223 | 212 | { |
| 224 | 213 | $miblist=array('Error getting mibs'); |
| 225 | 214 | } |
@@ -237,8 +226,7 @@ discard block |
||
| 237 | 226 | if (isset($postData['oid'])) |
| 238 | 227 | { |
| 239 | 228 | $oid=$postData['oid']; |
| 240 | - } |
|
| 241 | - else |
|
| 229 | + } else |
|
| 242 | 230 | { |
| 243 | 231 | $this->_helper->json(array('status'=>'No oid')); |
| 244 | 232 | return; |
@@ -249,8 +237,7 @@ discard block |
||
| 249 | 237 | { |
| 250 | 238 | $this->_helper->json(array('status'=>'Not found')); |
| 251 | 239 | return; |
| 252 | - } |
|
| 253 | - else |
|
| 240 | + } else |
|
| 254 | 241 | { |
| 255 | 242 | $this->_helper->json( |
| 256 | 243 | array('status'=>'OK', |
@@ -283,8 +270,7 @@ discard block |
||
| 283 | 270 | $this->_helper->json(array('status'=>'invalid days : '.$days)); |
| 284 | 271 | return; |
| 285 | 272 | } |
| 286 | - } |
|
| 287 | - else |
|
| 273 | + } else |
|
| 288 | 274 | { |
| 289 | 275 | $this->_helper->json(array('status'=>'No days')); |
| 290 | 276 | return; |
@@ -297,8 +283,7 @@ discard block |
||
| 297 | 283 | $this->_helper->json(array('status'=>'unknown action '.$action)); |
| 298 | 284 | return; |
| 299 | 285 | } |
| 300 | - } |
|
| 301 | - else |
|
| 286 | + } else |
|
| 302 | 287 | { |
| 303 | 288 | $this->_helper->json(array('status'=>'No action')); |
| 304 | 289 | return; |
@@ -308,8 +293,7 @@ discard block |
||
| 308 | 293 | try |
| 309 | 294 | { |
| 310 | 295 | $this->setDBConfigValue('db_remove_days',$days); |
| 311 | - } |
|
| 312 | - catch (Exception $e) |
|
| 296 | + } catch (Exception $e) |
|
| 313 | 297 | { |
| 314 | 298 | $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
| 315 | 299 | return; |
@@ -327,8 +311,7 @@ discard block |
||
| 327 | 311 | $Trap = new Trap($icingaweb2_etc); |
| 328 | 312 | $Trap->setLogging($debug_level,'syslog'); |
| 329 | 313 | $Trap->eraseOldTraps($days); |
| 330 | - } |
|
| 331 | - catch (Exception $e) |
|
| 314 | + } catch (Exception $e) |
|
| 332 | 315 | { |
| 333 | 316 | $this->_helper->json(array('status'=>'execute error : '.$e->getMessage() )); |
| 334 | 317 | return; |
@@ -356,8 +339,7 @@ discard block |
||
| 356 | 339 | $this->_helper->json(array('status'=>'invalid destination : '.$destination)); |
| 357 | 340 | return; |
| 358 | 341 | } |
| 359 | - } |
|
| 360 | - else |
|
| 342 | + } else |
|
| 361 | 343 | { |
| 362 | 344 | $this->_helper->json(array('status'=>'No destination')); |
| 363 | 345 | } |
@@ -370,14 +352,12 @@ discard block |
||
| 370 | 352 | $this->_helper->json(array('status'=>'File not writable : '.$file)); |
| 371 | 353 | return; |
| 372 | 354 | } |
| 373 | - } |
|
| 374 | - else |
|
| 355 | + } else |
|
| 375 | 356 | { |
| 376 | 357 | if ($destination != 'file') |
| 377 | 358 | { |
| 378 | 359 | $file=null; |
| 379 | - } |
|
| 380 | - else |
|
| 360 | + } else |
|
| 381 | 361 | { |
| 382 | 362 | $this->_helper->json(array('status'=>'No file')); |
| 383 | 363 | return; |
@@ -387,8 +367,7 @@ discard block |
||
| 387 | 367 | if (isset($postData['level'])) |
| 388 | 368 | { |
| 389 | 369 | $level=$postData['level']; |
| 390 | - } |
|
| 391 | - else |
|
| 370 | + } else |
|
| 392 | 371 | { |
| 393 | 372 | $this->_helper->json(array('status'=>'No level')); |
| 394 | 373 | return; |
@@ -399,8 +378,7 @@ discard block |
||
| 399 | 378 | $this->setDBConfigValue('log_destination',$destination); |
| 400 | 379 | $this->setDBConfigValue('log_file',$file); |
| 401 | 380 | $this->setDBConfigValue('log_level',$level); |
| 402 | - } |
|
| 403 | - catch (Exception $e) |
|
| 381 | + } catch (Exception $e) |
|
| 404 | 382 | { |
| 405 | 383 | $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
| 406 | 384 | return; |
@@ -422,8 +400,7 @@ discard block |
||
| 422 | 400 | if (isset($postData['rule'])) |
| 423 | 401 | { |
| 424 | 402 | $rule=$postData['rule']; |
| 425 | - } |
|
| 426 | - else |
|
| 403 | + } else |
|
| 427 | 404 | { |
| 428 | 405 | $this->_helper->json(array('status'=>'No Rule')); |
| 429 | 406 | } |
@@ -435,8 +412,7 @@ discard block |
||
| 435 | 412 | $this->_helper->json(array('status'=>'unknown action '.$action)); |
| 436 | 413 | return; |
| 437 | 414 | } |
| 438 | - } |
|
| 439 | - else |
|
| 415 | + } else |
|
| 440 | 416 | { |
| 441 | 417 | $this->_helper->json(array('status'=>'No action')); |
| 442 | 418 | return; |
@@ -453,8 +429,7 @@ discard block |
||
| 453 | 429 | // Eval |
| 454 | 430 | $item=0; |
| 455 | 431 | $rule=$Trap->ruleClass->evaluation($rule,$item); |
| 456 | - } |
|
| 457 | - catch (Exception $e) |
|
| 432 | + } catch (Exception $e) |
|
| 458 | 433 | { |
| 459 | 434 | $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
| 460 | 435 | return; |
@@ -476,8 +451,7 @@ discard block |
||
| 476 | 451 | if (isset($postData['name'])) |
| 477 | 452 | { |
| 478 | 453 | $pluginName=$postData['name']; |
| 479 | - } |
|
| 480 | - else |
|
| 454 | + } else |
|
| 481 | 455 | { |
| 482 | 456 | $this->_helper->json(array('status'=>'No plugin name')); |
| 483 | 457 | } |
@@ -489,8 +463,7 @@ discard block |
||
| 489 | 463 | $this->_helper->json(array('status'=>'unknown action '.$action)); |
| 490 | 464 | return; |
| 491 | 465 | } |
| 492 | - } |
|
| 493 | - else |
|
| 466 | + } else |
|
| 494 | 467 | { |
| 495 | 468 | $this->_helper->json(array('status'=>'No action')); |
| 496 | 469 | return; |
@@ -505,8 +478,7 @@ discard block |
||
| 505 | 478 | $action=($action == 'enable') ? true : false; |
| 506 | 479 | $retVal=$Trap->pluginClass->enablePlugin($pluginName, $action); |
| 507 | 480 | |
| 508 | - } |
|
| 509 | - catch (Exception $e) |
|
| 481 | + } catch (Exception $e) |
|
| 510 | 482 | { |
| 511 | 483 | $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
| 512 | 484 | return; |
@@ -514,8 +486,7 @@ discard block |
||
| 514 | 486 | if ($retVal === true) |
| 515 | 487 | { |
| 516 | 488 | $this->_helper->json(array('status'=>'OK')); |
| 517 | - } |
|
| 518 | - else |
|
| 489 | + } else |
|
| 519 | 490 | { |
| 520 | 491 | $this->_helper->json(array('status'=>'Error, see logs')); |
| 521 | 492 | } |
@@ -532,8 +503,7 @@ discard block |
||
| 532 | 503 | if (isset($postData['function'])) |
| 533 | 504 | { |
| 534 | 505 | $functionString=$postData['function']; |
| 535 | - } |
|
| 536 | - else |
|
| 506 | + } else |
|
| 537 | 507 | { |
| 538 | 508 | $this->_helper->json(array('status'=>'No function name')); |
| 539 | 509 | } |
@@ -545,8 +515,7 @@ discard block |
||
| 545 | 515 | $this->_helper->json(array('status'=>'unknown action '.$action)); |
| 546 | 516 | return; |
| 547 | 517 | } |
| 548 | - } |
|
| 549 | - else |
|
| 518 | + } else |
|
| 550 | 519 | { |
| 551 | 520 | $this->_helper->json(array('status'=>'No action')); |
| 552 | 521 | return; |
@@ -560,8 +529,7 @@ discard block |
||
| 560 | 529 | // load plugins. |
| 561 | 530 | $Trap->pluginClass->registerAllPlugins(false); |
| 562 | 531 | $result = $Trap->pluginClass->evaluateFunctionString($functionString); |
| 563 | - } |
|
| 564 | - catch (Exception $e) |
|
| 532 | + } catch (Exception $e) |
|
| 565 | 533 | { |
| 566 | 534 | $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
| 567 | 535 | return; |
@@ -69,8 +69,7 @@ discard block |
||
| 69 | 69 | { |
| 70 | 70 | $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile); |
| 71 | 71 | $this->logSetup=true; |
| 72 | - } |
|
| 73 | - else |
|
| 72 | + } else |
|
| 74 | 73 | { |
| 75 | 74 | $this->logSetup=false; |
| 76 | 75 | } |
@@ -95,7 +94,10 @@ discard block |
||
| 95 | 94 | $this->getDatabaseOptions(); // Get options in database |
| 96 | 95 | |
| 97 | 96 | //*************** Setup API |
| 98 | - if ($this->api_use === true) $this->getAPI(); // Setup API |
|
| 97 | + if ($this->api_use === true) { |
|
| 98 | + $this->getAPI(); |
|
| 99 | + } |
|
| 100 | + // Setup API |
|
| 99 | 101 | |
| 100 | 102 | //*************** Setup MIB |
| 101 | 103 | $this->mibClass = new Mib($this->logging,$this->trapsDB,$this->snmptranslate,$this->snmptranslate_dirs); // Create Mib class |
@@ -138,8 +140,7 @@ discard block |
||
| 138 | 140 | } |
| 139 | 141 | $this->logging->log($message,$log_level); |
| 140 | 142 | return false; |
| 141 | - } |
|
| 142 | - else |
|
| 143 | + } else |
|
| 143 | 144 | { |
| 144 | 145 | $option_var=$option_array[$option_category][$option_name]; |
| 145 | 146 | return true; |
@@ -203,7 +204,10 @@ discard block |
||
| 203 | 204 | |
| 204 | 205 | $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->db_prefix); |
| 205 | 206 | |
| 206 | - if ($this->api_use === true) return; // In case of API use, no IDO is necessary |
|
| 207 | + if ($this->api_use === true) { |
|
| 208 | + return; |
|
| 209 | + } |
|
| 210 | + // In case of API use, no IDO is necessary |
|
| 207 | 211 | |
| 208 | 212 | // IDO Database |
| 209 | 213 | if (!array_key_exists('IDOdatabase',$trapConfig['config'])) |
@@ -228,9 +232,11 @@ discard block |
||
| 228 | 232 | protected function getDatabaseOptions() |
| 229 | 233 | { |
| 230 | 234 | // Database options |
| 231 | - if ($this->logSetup === false) // Only if logging was no setup in constructor |
|
| 235 | + if ($this->logSetup === false) { |
|
| 236 | + // Only if logging was no setup in constructor |
|
| 232 | 237 | { |
| 233 | 238 | $this->getDBConfigIfSet('log_level',$this->logging->debugLevel); |
| 239 | + } |
|
| 234 | 240 | $this->getDBConfigIfSet('log_destination',$this->logging->outputMode); |
| 235 | 241 | $this->getDBConfigIfSet('log_file',$this->logging->outputFile); |
| 236 | 242 | } |
@@ -243,7 +249,9 @@ discard block |
||
| 243 | 249 | protected function getDBConfigIfSet($element,&$variable) |
| 244 | 250 | { |
| 245 | 251 | $value=$this->getDBConfig($element); |
| 246 | - if ($value != null) $variable=$value; |
|
| 252 | + if ($value != null) { |
|
| 253 | + $variable=$value; |
|
| 254 | + } |
|
| 247 | 255 | } |
| 248 | 256 | |
| 249 | 257 | /** |
@@ -335,8 +343,7 @@ discard block |
||
| 335 | 343 | { |
| 336 | 344 | $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)"); |
| 337 | 345 | $this->logging->log('Error parsing IP : '.$IP,ERROR,''); |
| 338 | - } |
|
| 339 | - else |
|
| 346 | + } else |
|
| 340 | 347 | { |
| 341 | 348 | $this->trap_data['source_ip']=$matches[1]; |
| 342 | 349 | $this->trap_data['destination_ip']=$matches[3]; |
@@ -351,14 +358,12 @@ discard block |
||
| 351 | 358 | if ($ret_code===0 || $ret_code===false) |
| 352 | 359 | { |
| 353 | 360 | $this->logging->log('No match on trap data : '.$vars,WARN,''); |
| 354 | - } |
|
| 355 | - else |
|
| 361 | + } else |
|
| 356 | 362 | { |
| 357 | 363 | 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')) |
| 358 | 364 | { |
| 359 | 365 | $this->trap_data['trap_oid']=$matches[2]; |
| 360 | - } |
|
| 361 | - else |
|
| 366 | + } else |
|
| 362 | 367 | { |
| 363 | 368 | $object= new stdClass; |
| 364 | 369 | $object->oid =$matches[1]; |
@@ -529,7 +534,9 @@ discard block |
||
| 529 | 534 | } |
| 530 | 535 | |
| 531 | 536 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
| 532 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 537 | + if ($inserted_id==false) { |
|
| 538 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 539 | + } |
|
| 533 | 540 | $this->trap_id=$inserted_id; |
| 534 | 541 | break; |
| 535 | 542 | default: |
@@ -545,7 +552,9 @@ discard block |
||
| 545 | 552 | { |
| 546 | 553 | |
| 547 | 554 | // If action is ignore -> don't send t DB |
| 548 | - if ($this->trap_to_db === false) return; |
|
| 555 | + if ($this->trap_to_db === false) { |
|
| 556 | + return; |
|
| 557 | + } |
|
| 549 | 558 | |
| 550 | 559 | |
| 551 | 560 | $db_conn=$this->trapsDB->db_connect_trap(); |
@@ -602,7 +611,9 @@ discard block |
||
| 602 | 611 | } |
| 603 | 612 | |
| 604 | 613 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
| 605 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 614 | + if ($inserted_id==false) { |
|
| 615 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 616 | + } |
|
| 606 | 617 | $this->trap_id=$inserted_id; |
| 607 | 618 | break; |
| 608 | 619 | default: |
@@ -731,8 +742,7 @@ discard block |
||
| 731 | 742 | // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default.... |
| 732 | 743 | exec('echo "'.$send.'" > ' .$this->icinga2cmd); |
| 733 | 744 | return true; |
| 734 | - } |
|
| 735 | - else |
|
| 745 | + } else |
|
| 736 | 746 | { |
| 737 | 747 | // Get perfdata if found |
| 738 | 748 | $matches=array(); |
@@ -740,8 +750,7 @@ discard block |
||
| 740 | 750 | { |
| 741 | 751 | $display=$matches[1]; |
| 742 | 752 | $perfdata=$matches[2]; |
| 743 | - } |
|
| 744 | - else |
|
| 753 | + } else |
|
| 745 | 754 | { |
| 746 | 755 | $perfdata=''; |
| 747 | 756 | } |
@@ -753,8 +762,7 @@ discard block |
||
| 753 | 762 | { |
| 754 | 763 | $this->logging->log( "Error sending result : " .$retmessage,WARN,''); |
| 755 | 764 | return false; |
| 756 | - } |
|
| 757 | - else |
|
| 765 | + } else |
|
| 758 | 766 | { |
| 759 | 767 | $this->logging->log( "Sent result : " .$retmessage,INFO ); |
| 760 | 768 | return true; |
@@ -850,20 +858,17 @@ discard block |
||
| 850 | 858 | if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false) |
| 851 | 859 | { |
| 852 | 860 | $this->trap_action.='Error sending status : check cmd/API'; |
| 853 | - } |
|
| 854 | - else |
|
| 861 | + } else |
|
| 855 | 862 | { |
| 856 | 863 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 857 | 864 | $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name; |
| 858 | 865 | } |
| 859 | - } |
|
| 860 | - else |
|
| 866 | + } else |
|
| 861 | 867 | { |
| 862 | 868 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 863 | 869 | } |
| 864 | 870 | $this->trap_to_db=($action==-2)?false:true; |
| 865 | - } |
|
| 866 | - else |
|
| 871 | + } else |
|
| 867 | 872 | { |
| 868 | 873 | //$this->logging->log('rules KOO : '.print_r($rule),INFO ); |
| 869 | 874 | |
@@ -874,14 +879,12 @@ discard block |
||
| 874 | 879 | if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false) |
| 875 | 880 | { |
| 876 | 881 | $this->trap_action.='Error sending status : check cmd/API'; |
| 877 | - } |
|
| 878 | - else |
|
| 882 | + } else |
|
| 879 | 883 | { |
| 880 | 884 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 881 | 885 | $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name; |
| 882 | 886 | } |
| 883 | - } |
|
| 884 | - else |
|
| 887 | + } else |
|
| 885 | 888 | { |
| 886 | 889 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 887 | 890 | } |
@@ -891,16 +894,14 @@ discard block |
||
| 891 | 894 | if (!isset($this->trap_data['source_name'])) |
| 892 | 895 | { |
| 893 | 896 | $this->trap_data['source_name']=$rule['host_name']; |
| 894 | - } |
|
| 895 | - else |
|
| 897 | + } else |
|
| 896 | 898 | { |
| 897 | 899 | if (!preg_match('/'.$rule['host_name'].'/',$this->trap_data['source_name'])) |
| 898 | 900 | { // only add if not present |
| 899 | 901 | $this->trap_data['source_name'].=','.$rule['host_name']; |
| 900 | 902 | } |
| 901 | 903 | } |
| 902 | - } |
|
| 903 | - catch (Exception $e) |
|
| 904 | + } catch (Exception $e) |
|
| 904 | 905 | { |
| 905 | 906 | $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,''); |
| 906 | 907 | $this->trap_action.=' ERR : '.$e->getMessage(); |
@@ -911,8 +912,7 @@ discard block |
||
| 911 | 912 | if ($this->trap_data['status']=='error') |
| 912 | 913 | { |
| 913 | 914 | $this->trap_to_db=true; // Always put errors in DB for the use can see |
| 914 | - } |
|
| 915 | - else |
|
| 915 | + } else |
|
| 916 | 916 | { |
| 917 | 917 | $this->trap_data['status']='done'; |
| 918 | 918 | } |
@@ -56,8 +56,7 @@ discard block |
||
| 56 | 56 | if ($pluginDir == '') |
| 57 | 57 | { |
| 58 | 58 | $this->pluginDir=dirname(__DIR__).'/Plugins'; |
| 59 | - } |
|
| 60 | - else |
|
| 59 | + } else |
|
| 61 | 60 | { |
| 62 | 61 | $this->pluginDir=$pluginDir; |
| 63 | 62 | } |
@@ -94,8 +93,7 @@ discard block |
||
| 94 | 93 | { |
| 95 | 94 | $this->logClass->log('No enabled plugins',DEBUG); |
| 96 | 95 | return; |
| 97 | - } |
|
| 98 | - else |
|
| 96 | + } else |
|
| 99 | 97 | { // Saved config : <plugin name>;<Catch all OID ? 1|0>;<Trap target ? 1|0>;<func 1 name>|<func 2 name>... ,<plugin2 name>.... |
| 100 | 98 | $this->logClass->log('Enabled plugins = '.$PluginList,DEBUG); |
| 101 | 99 | |
@@ -233,9 +231,11 @@ discard block |
||
| 233 | 231 | */ |
| 234 | 232 | public function registerPlugin(string $pluginName) |
| 235 | 233 | { |
| 236 | - if ( ! isset($this->pluginsList[$pluginName]) ) // Plugin isn't enable, create entry |
|
| 234 | + if ( ! isset($this->pluginsList[$pluginName]) ) { |
|
| 235 | + // Plugin isn't enable, create entry |
|
| 237 | 236 | { |
| 238 | 237 | $pluginListElmt = array(); |
| 238 | + } |
|
| 239 | 239 | $pluginListElmt['object'] = null; // class not loaded |
| 240 | 240 | $pluginListElmt['enabled'] = false; |
| 241 | 241 | $this->pluginsList[$pluginName] = $pluginListElmt; |
@@ -282,8 +282,7 @@ discard block |
||
| 282 | 282 | . $pluginName . ' and ' . $this->functionList[$fname]['plugin']); |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - } |
|
| 286 | - else |
|
| 285 | + } else |
|
| 287 | 286 | { |
| 288 | 287 | $this->functionList[$fname]=array(); |
| 289 | 288 | $this->functionList[$fname]['plugin'] = $pluginName; |
@@ -326,11 +325,13 @@ discard block |
||
| 326 | 325 | $retDisplay .= $e->getMessage() . ' / '; |
| 327 | 326 | } |
| 328 | 327 | } |
| 329 | - if ($checkEnabled === false) // Load all php files in plugin dir |
|
| 328 | + if ($checkEnabled === false) { |
|
| 329 | + // Load all php files in plugin dir |
|
| 330 | 330 | { |
| 331 | 331 | foreach (glob($this->pluginDir."/*.php") as $filename) |
| 332 | 332 | { |
| 333 | 333 | $pluginName=basename($filename,'.php'); |
| 334 | + } |
|
| 334 | 335 | if (!preg_match('/^[a-zA-Z0-9]+$/',$pluginName)) |
| 335 | 336 | { |
| 336 | 337 | $this->logClass->log("Invalid plugin name : ".$pluginName, WARN); |
@@ -348,8 +349,7 @@ discard block |
||
| 348 | 349 | if ($retDisplay == '') |
| 349 | 350 | { |
| 350 | 351 | return 'All plugins loaded OK'; |
| 351 | - } |
|
| 352 | - else |
|
| 352 | + } else |
|
| 353 | 353 | { |
| 354 | 354 | return $retDisplay; |
| 355 | 355 | } |
@@ -153,8 +153,7 @@ discard block |
||
| 153 | 153 | if ($value != null && isset($value['id'])) |
| 154 | 154 | { // Entry exists -> update |
| 155 | 155 | $sql='UPDATE '.$this->dbPrefix.'db_config SET value = \''.$element.'\' WHERE (id = '.$value['id'].')'; |
| 156 | - } |
|
| 157 | - else |
|
| 156 | + } else |
|
| 158 | 157 | { // Entry does no exists -> create |
| 159 | 158 | $sql='INSERT INTO '.$this->dbPrefix.'db_config (name,value) VALUES (\''.$name.'\' , \''.$element.'\' )'; |
| 160 | 159 | } |
@@ -222,8 +221,7 @@ discard block |
||
| 222 | 221 | if (preg_match('/^ *CREATE TABLE ([^ ]+)/',$newline,$cur_table_array)) |
| 223 | 222 | { |
| 224 | 223 | $cur_table='table '.$cur_table_array[1]; |
| 225 | - } |
|
| 226 | - else |
|
| 224 | + } else |
|
| 227 | 225 | { |
| 228 | 226 | $cur_table='secret SQL stuff :-)'; |
| 229 | 227 | } |
@@ -267,8 +265,7 @@ discard block |
||
| 267 | 265 | if ($this->trapDBType == 'pgsql') |
| 268 | 266 | { |
| 269 | 267 | $prefix .= 'update_pgsql/schema_'; |
| 270 | - } |
|
| 271 | - else |
|
| 268 | + } else |
|
| 272 | 269 | { |
| 273 | 270 | $prefix .= 'update_sql/schema_'; |
| 274 | 271 | } |
@@ -312,7 +309,10 @@ discard block |
||
| 312 | 309 | $db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 313 | 310 | while (($line=fgets($input_stream)) !== false) |
| 314 | 311 | { |
| 315 | - if (preg_match('/^#/', $line)) continue; // ignore comment lines |
|
| 312 | + if (preg_match('/^#/', $line)) { |
|
| 313 | + continue; |
|
| 314 | + } |
|
| 315 | + // ignore comment lines |
|
| 316 | 316 | $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line)); |
| 317 | 317 | if (preg_match('/; *$/', $newline)) |
| 318 | 318 | { |
@@ -325,8 +325,7 @@ discard block |
||
| 325 | 325 | if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/',$newline,$cur_table_array)) |
| 326 | 326 | { |
| 327 | 327 | $cur_table=$cur_table_array[1] . ' SQL table '.$cur_table_array[2]; |
| 328 | - } |
|
| 329 | - else |
|
| 328 | + } else |
|
| 330 | 329 | { |
| 331 | 330 | $cur_table='secret SQL stuff :-)'; |
| 332 | 331 | //$cur_table=$newline; |