@@ -18,14 +18,14 @@ discard block |
||
| 18 | 18 | { |
| 19 | 19 | $postData=$this->getRequest()->getPost(); |
| 20 | 20 | |
| 21 | - $hostFilter = $this->checkPostVar($postData, 'hostFilter', '.*'); |
|
| 21 | + $hostFilter=$this->checkPostVar($postData, 'hostFilter', '.*'); |
|
| 22 | 22 | |
| 23 | - $retHosts=array('status'=>'OK','hosts' => array()); |
|
| 23 | + $retHosts=array('status'=>'OK', 'hosts' => array()); |
|
| 24 | 24 | |
| 25 | 25 | $hosts=$this->getHostByIP($hostFilter); |
| 26 | 26 | foreach ($hosts as $val) |
| 27 | 27 | { |
| 28 | - array_push($retHosts['hosts'],$val->name); |
|
| 28 | + array_push($retHosts['hosts'], $val->name); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | $this->_helper->json($retHosts); |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | { |
| 39 | 39 | $postData=$this->getRequest()->getPost(); |
| 40 | 40 | |
| 41 | - $hostFilter = $this->checkPostVar($postData, 'hostfilter', '.*'); |
|
| 41 | + $hostFilter=$this->checkPostVar($postData, 'hostfilter', '.*'); |
|
| 42 | 42 | |
| 43 | - $retHosts=array('status'=>'OK','hosts' => array()); |
|
| 43 | + $retHosts=array('status'=>'OK', 'hosts' => array()); |
|
| 44 | 44 | |
| 45 | 45 | $hosts=$this->getHostGroupByName($hostFilter); |
| 46 | 46 | foreach ($hosts as $val) |
| 47 | 47 | { |
| 48 | - array_push($retHosts['hosts'],$val->name); |
|
| 48 | + array_push($retHosts['hosts'], $val->name); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | $this->_helper->json($retHosts); |
@@ -68,31 +68,31 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | else |
| 70 | 70 | { |
| 71 | - $this->_helper->json(array('status'=>'No Hosts','hostid' => -1)); |
|
| 71 | + $this->_helper->json(array('status'=>'No Hosts', 'hostid' => -1)); |
|
| 72 | 72 | return; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | $hostArray=$this->getHostByName($host); |
| 76 | 76 | if (count($hostArray) > 1) |
| 77 | 77 | { |
| 78 | - $this->_helper->json(array('status'=>'More than one host matches','hostid' => -1)); |
|
| 78 | + $this->_helper->json(array('status'=>'More than one host matches', 'hostid' => -1)); |
|
| 79 | 79 | return; |
| 80 | 80 | } |
| 81 | 81 | else if (count($hostArray) == 0) |
| 82 | 82 | { |
| 83 | - $this->_helper->json(array('status'=>'No host matches','hostid' => -1)); |
|
| 83 | + $this->_helper->json(array('status'=>'No host matches', 'hostid' => -1)); |
|
| 84 | 84 | return; |
| 85 | 85 | } |
| 86 | 86 | $services=$this->getServicesByHostid($hostArray[0]->id); |
| 87 | 87 | if (count($services) < 1) |
| 88 | 88 | { |
| 89 | - $this->_helper->json(array('status'=>'No services found for host','hostid' => $hostArray[0]->id)); |
|
| 89 | + $this->_helper->json(array('status'=>'No services found for host', 'hostid' => $hostArray[0]->id)); |
|
| 90 | 90 | return; |
| 91 | 91 | } |
| 92 | - $retServices=array('status'=>'OK','services' => array(),'hostid' => $hostArray[0]->id); |
|
| 92 | + $retServices=array('status'=>'OK', 'services' => array(), 'hostid' => $hostArray[0]->id); |
|
| 93 | 93 | foreach ($services as $val) |
| 94 | 94 | { |
| 95 | - array_push($retServices['services'],array($val->id , $val->name)); |
|
| 95 | + array_push($retServices['services'], array($val->id, $val->name)); |
|
| 96 | 96 | } |
| 97 | 97 | $this->_helper->json($retServices); |
| 98 | 98 | } |
@@ -107,26 +107,26 @@ discard block |
||
| 107 | 107 | { |
| 108 | 108 | $postData=$this->getRequest()->getPost(); |
| 109 | 109 | |
| 110 | - $host = $this->checkPostVar($postData, 'host', '.*'); |
|
| 110 | + $host=$this->checkPostVar($postData, 'host', '.*'); |
|
| 111 | 111 | |
| 112 | 112 | $hostArray=$this->getHostGroupByName($host); |
| 113 | 113 | if (count($hostArray) > 1) |
| 114 | 114 | { |
| 115 | - $this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1)); |
|
| 115 | + $this->_helper->json(array('status'=>'More than one hostgroup matches', 'hostid' => -1)); |
|
| 116 | 116 | return; |
| 117 | 117 | } |
| 118 | 118 | else if (count($hostArray) == 0) |
| 119 | 119 | { |
| 120 | - $this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1)); |
|
| 120 | + $this->_helper->json(array('status'=>'No hostgroup matches', 'hostid' => -1)); |
|
| 121 | 121 | return; |
| 122 | 122 | } |
| 123 | 123 | $services=$this->getServicesByHostGroupid($hostArray[0]->id); |
| 124 | 124 | if (count($services) < 1) |
| 125 | 125 | { |
| 126 | - $this->_helper->json(array('status'=>'No services found for hostgroup','hostid' => $hostArray[0]->id)); |
|
| 126 | + $this->_helper->json(array('status'=>'No services found for hostgroup', 'hostid' => $hostArray[0]->id)); |
|
| 127 | 127 | return; |
| 128 | 128 | } |
| 129 | - $retServices=array('status'=>'OK','services' => $services,'hostid' => $hostArray[0]->id); |
|
| 129 | + $retServices=array('status'=>'OK', 'services' => $services, 'hostid' => $hostArray[0]->id); |
|
| 130 | 130 | |
| 131 | 131 | $this->_helper->json($retServices); |
| 132 | 132 | } |
@@ -140,12 +140,12 @@ discard block |
||
| 140 | 140 | { |
| 141 | 141 | $postData=$this->getRequest()->getPost(); |
| 142 | 142 | |
| 143 | - $mib = $this->checkPostVar($postData, 'mib', '.*'); |
|
| 143 | + $mib=$this->checkPostVar($postData, 'mib', '.*'); |
|
| 144 | 144 | |
| 145 | 145 | try |
| 146 | 146 | { |
| 147 | 147 | $traplist=$this->getMIB()->getTrapList($mib); |
| 148 | - $retTraps=array('status'=>'OK','traps' => $traplist); |
|
| 148 | + $retTraps=array('status'=>'OK', 'traps' => $traplist); |
|
| 149 | 149 | } |
| 150 | 150 | catch (Exception $e) |
| 151 | 151 | { |
@@ -163,12 +163,12 @@ discard block |
||
| 163 | 163 | { |
| 164 | 164 | $postData=$this->getRequest()->getPost(); |
| 165 | 165 | |
| 166 | - $trap = $this->checkPostVar($postData, 'trap', '.*'); |
|
| 166 | + $trap=$this->checkPostVar($postData, 'trap', '.*'); |
|
| 167 | 167 | |
| 168 | 168 | try |
| 169 | 169 | { |
| 170 | 170 | $objectlist=$this->getMIB()->getObjectList($trap); |
| 171 | - $retObjects=array('status'=>'OK','objects' => $objectlist); |
|
| 171 | + $retObjects=array('status'=>'OK', 'objects' => $objectlist); |
|
| 172 | 172 | } |
| 173 | 173 | catch (Exception $e) |
| 174 | 174 | { |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | { |
| 203 | 203 | $postData=$this->getRequest()->getPost(); |
| 204 | 204 | |
| 205 | - $oid = $this->checkPostVar($postData, 'oid', '.*'); |
|
| 205 | + $oid=$this->checkPostVar($postData, 'oid', '.*'); |
|
| 206 | 206 | |
| 207 | 207 | // Try to get oid name from snmptranslate |
| 208 | 208 | if (($object=$this->getMIB()->translateOID($oid)) == null) |
@@ -235,19 +235,19 @@ discard block |
||
| 235 | 235 | |
| 236 | 236 | $postData=$this->getRequest()->getPost(); |
| 237 | 237 | |
| 238 | - $days = $this->checkPostVar($postData, 'days', '^[0-9]+$'); |
|
| 238 | + $days=$this->checkPostVar($postData, 'days', '^[0-9]+$'); |
|
| 239 | 239 | |
| 240 | - $action = $this->checkPostVar($postData, 'action', 'save|execute'); |
|
| 240 | + $action=$this->checkPostVar($postData, 'action', 'save|execute'); |
|
| 241 | 241 | |
| 242 | 242 | if ($action == 'save') |
| 243 | 243 | { |
| 244 | 244 | try |
| 245 | 245 | { |
| 246 | - $this->setDBConfigValue('db_remove_days',$days); |
|
| 246 | + $this->setDBConfigValue('db_remove_days', $days); |
|
| 247 | 247 | } |
| 248 | 248 | catch (Exception $e) |
| 249 | 249 | { |
| 250 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
| 250 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
| 251 | 251 | return; |
| 252 | 252 | } |
| 253 | 253 | $this->_helper->json(array('status'=>'OK')); |
@@ -257,16 +257,16 @@ discard block |
||
| 257 | 257 | { |
| 258 | 258 | try |
| 259 | 259 | { |
| 260 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 260 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 261 | 261 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 262 | 262 | $debug_level=4; |
| 263 | - $trap = new Trap($icingaweb2_etc); |
|
| 264 | - $trap->setLogging($debug_level,'syslog'); |
|
| 263 | + $trap=new Trap($icingaweb2_etc); |
|
| 264 | + $trap->setLogging($debug_level, 'syslog'); |
|
| 265 | 265 | $trap->eraseOldTraps($days); |
| 266 | 266 | } |
| 267 | 267 | catch (Exception $e) |
| 268 | 268 | { |
| 269 | - $this->_helper->json(array('status'=>'execute error : '.$e->getMessage() )); |
|
| 269 | + $this->_helper->json(array('status'=>'execute error : '.$e->getMessage())); |
|
| 270 | 270 | return; |
| 271 | 271 | } |
| 272 | 272 | $this->_helper->json(array('status'=>'OK')); |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | { |
| 285 | 285 | $postData=$this->getRequest()->getPost(); |
| 286 | 286 | |
| 287 | - $destination = $this->checkPostVar($postData, 'destination', '.*'); |
|
| 287 | + $destination=$this->checkPostVar($postData, 'destination', '.*'); |
|
| 288 | 288 | $logDest=$this->getModuleConfig()->getLogDestinations(); |
| 289 | 289 | if (!isset($logDest[$destination])) |
| 290 | 290 | { |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | if (isset($postData['file'])) |
| 296 | 296 | { |
| 297 | 297 | $file=$postData['file']; |
| 298 | - $fileHandler=@fopen($file,'w'); |
|
| 298 | + $fileHandler=@fopen($file, 'w'); |
|
| 299 | 299 | if ($fileHandler == false) |
| 300 | 300 | { // File os note writabe / cannot create |
| 301 | 301 | $this->_helper->json(array('status'=>'File not writable : '.$file)); |
@@ -315,17 +315,17 @@ discard block |
||
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - $level = $this->checkPostVar($postData, 'level', '[0-9]'); |
|
| 318 | + $level=$this->checkPostVar($postData, 'level', '[0-9]'); |
|
| 319 | 319 | |
| 320 | 320 | try |
| 321 | 321 | { |
| 322 | - $this->setDBConfigValue('log_destination',$destination); |
|
| 323 | - $this->setDBConfigValue('log_file',$file); |
|
| 324 | - $this->setDBConfigValue('log_level',$level); |
|
| 322 | + $this->setDBConfigValue('log_destination', $destination); |
|
| 323 | + $this->setDBConfigValue('log_file', $file); |
|
| 324 | + $this->setDBConfigValue('log_level', $level); |
|
| 325 | 325 | } |
| 326 | 326 | catch (Exception $e) |
| 327 | 327 | { |
| 328 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
| 328 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
| 329 | 329 | return; |
| 330 | 330 | } |
| 331 | 331 | $this->_helper->json(array('status'=>'OK')); |
@@ -343,29 +343,29 @@ discard block |
||
| 343 | 343 | |
| 344 | 344 | $postData=$this->getRequest()->getPost(); |
| 345 | 345 | |
| 346 | - $rule = $this->checkPostVar($postData, 'rule', '.*'); |
|
| 346 | + $rule=$this->checkPostVar($postData, 'rule', '.*'); |
|
| 347 | 347 | |
| 348 | - $action = $this->checkPostVar($postData, 'action', 'evaluate'); |
|
| 348 | + $action=$this->checkPostVar($postData, 'action', 'evaluate'); |
|
| 349 | 349 | |
| 350 | 350 | if ($action == 'evaluate') |
| 351 | 351 | { |
| 352 | 352 | try |
| 353 | 353 | { |
| 354 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 354 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 355 | 355 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 356 | - $trap = new Trap($icingaweb2_etc); |
|
| 356 | + $trap=new Trap($icingaweb2_etc); |
|
| 357 | 357 | // Cleanup spaces before eval |
| 358 | 358 | $rule=$trap->ruleClass->eval_cleanup($rule); |
| 359 | 359 | // Eval |
| 360 | 360 | $item=0; |
| 361 | - $rule=$trap->ruleClass->evaluation($rule,$item); |
|
| 361 | + $rule=$trap->ruleClass->evaluation($rule, $item); |
|
| 362 | 362 | } |
| 363 | 363 | catch (Exception $e) |
| 364 | 364 | { |
| 365 | - $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
| 365 | + $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage())); |
|
| 366 | 366 | return; |
| 367 | 367 | } |
| 368 | - $return=($rule==true)?'true':'false'; |
|
| 368 | + $return=($rule == true) ? 'true' : 'false'; |
|
| 369 | 369 | $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
| 370 | 370 | } |
| 371 | 371 | |
@@ -380,15 +380,15 @@ discard block |
||
| 380 | 380 | { |
| 381 | 381 | $postData=$this->getRequest()->getPost(); |
| 382 | 382 | |
| 383 | - $pluginName = $this->checkPostVar($postData, 'name', '.*'); |
|
| 383 | + $pluginName=$this->checkPostVar($postData, 'name', '.*'); |
|
| 384 | 384 | |
| 385 | - $action = $this->checkPostVar($postData, 'action', 'enable|disable'); |
|
| 385 | + $action=$this->checkPostVar($postData, 'action', 'enable|disable'); |
|
| 386 | 386 | |
| 387 | 387 | try |
| 388 | 388 | { |
| 389 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 389 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 390 | 390 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 391 | - $trap = new Trap($icingaweb2_etc); |
|
| 391 | + $trap=new Trap($icingaweb2_etc); |
|
| 392 | 392 | // Enable plugin. |
| 393 | 393 | $action=($action == 'enable') ? true : false; |
| 394 | 394 | $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | } |
| 397 | 397 | catch (Exception $e) |
| 398 | 398 | { |
| 399 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
| 399 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage())); |
|
| 400 | 400 | return; |
| 401 | 401 | } |
| 402 | 402 | if ($retVal === true) |
@@ -418,45 +418,45 @@ discard block |
||
| 418 | 418 | { |
| 419 | 419 | $postData=$this->getRequest()->getPost(); |
| 420 | 420 | |
| 421 | - $functionString = $this->checkPostVar($postData, 'function', '.*'); |
|
| 421 | + $functionString=$this->checkPostVar($postData, 'function', '.*'); |
|
| 422 | 422 | |
| 423 | 423 | $this->checkPostVar($postData, 'action', 'evaluate'); |
| 424 | 424 | |
| 425 | 425 | // Only one action possible for now, no tests on action. |
| 426 | 426 | try |
| 427 | 427 | { |
| 428 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 428 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 429 | 429 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 430 | - $trap = new Trap($icingaweb2_etc); |
|
| 430 | + $trap=new Trap($icingaweb2_etc); |
|
| 431 | 431 | // load all plugins in case tested function is not enabled. |
| 432 | 432 | $trap->pluginClass->registerAllPlugins(false); |
| 433 | 433 | // Clean all spaces |
| 434 | - $functionString = $trap->ruleClass->eval_cleanup($functionString); |
|
| 434 | + $functionString=$trap->ruleClass->eval_cleanup($functionString); |
|
| 435 | 435 | // Eval functions |
| 436 | - $result = $trap->pluginClass->evaluateFunctionString($functionString); |
|
| 436 | + $result=$trap->pluginClass->evaluateFunctionString($functionString); |
|
| 437 | 437 | } |
| 438 | 438 | catch (Exception $e) |
| 439 | 439 | { |
| 440 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
| 440 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage())); |
|
| 441 | 441 | return; |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | - $result = ($result === true)?'True':'False'; |
|
| 445 | - $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
| 444 | + $result=($result === true) ? 'True' : 'False'; |
|
| 445 | + $this->_helper->json(array('status'=>'OK', 'message' => $result)); |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | /************** Utilities **********************/ |
| 449 | 449 | |
| 450 | - private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string |
|
| 450 | + private function checkPostVar(array $postData, string $postVar, string $validRegexp) : string |
|
| 451 | 451 | { |
| 452 | 452 | if (!isset ($postData[$postVar])) |
| 453 | 453 | { |
| 454 | - $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
| 454 | + $this->_helper->json(array('status'=>'No '.$postVar)); |
|
| 455 | 455 | return ''; |
| 456 | 456 | } |
| 457 | 457 | if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
| 458 | 458 | { |
| 459 | - $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
| 459 | + $this->_helper->json(array('status'=>'Unknown '.$postVar.' value '.$postData[$postVar])); |
|
| 460 | 460 | return ''; |
| 461 | 461 | } |
| 462 | 462 | return $postData[$postVar]; |