@@ -23,16 +23,16 @@ discard block |
||
| 23 | 23 | $this->checkReadPermission(); |
| 24 | 24 | $this->prepareTabs()->activate('status'); |
| 25 | 25 | |
| 26 | - $dbConn = $this->getUIDatabase()->getDb(); |
|
| 26 | + $dbConn=$this->getUIDatabase()->getDb(); |
|
| 27 | 27 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 28 | 28 | |
| 29 | 29 | $this->getHandlerListTable()->setConnection($dbConn); |
| 30 | 30 | $this->getHandlerListTable()->setMibloader($this->getMIB()); |
| 31 | 31 | // Apply pagination limits |
| 32 | - $this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(),$this->getModuleConfig()->itemListDisplay()); |
|
| 32 | + $this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(), $this->getModuleConfig()->itemListDisplay()); |
|
| 33 | 33 | |
| 34 | 34 | // Set Filter |
| 35 | - $this->view->filterEditor = $this->getHandlerListTable()->getFilterEditor($this->getRequest()); |
|
| 35 | + $this->view->filterEditor=$this->getHandlerListTable()->getFilterEditor($this->getRequest()); |
|
| 36 | 36 | |
| 37 | 37 | //$this->displayExitError('Handler/indexAction','Not implemented'); |
| 38 | 38 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | public function testruleAction() |
| 43 | 43 | { |
| 44 | 44 | $this->checkReadPermission(); |
| 45 | - $this->getTabs()->add('get',array( |
|
| 45 | + $this->getTabs()->add('get', array( |
|
| 46 | 46 | 'active' => true, |
| 47 | 47 | 'label' => $this->translate('Test Rule'), |
| 48 | 48 | 'url' => Url::fromRequest() |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | if ($this->params->get('rule') !== null) |
| 53 | 53 | { |
| 54 | - $this->view->rule= $this->params->get('rule'); |
|
| 54 | + $this->view->rule=$this->params->get('rule'); |
|
| 55 | 55 | } |
| 56 | 56 | else |
| 57 | 57 | { |
@@ -110,12 +110,12 @@ discard block |
||
| 110 | 110 | } |
| 111 | 111 | catch (Exception $e) |
| 112 | 112 | { |
| 113 | - $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
|
| 113 | + $this->displayExitError('Add handler : get host by IP/Name ', $e->getMessage()); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | |
| 117 | 117 | // if one unique host found -> put id text input |
| 118 | - if (count($hosts)==1) { |
|
| 118 | + if (count($hosts) == 1) { |
|
| 119 | 119 | $this->view->hostname=$hosts[0]->name; |
| 120 | 120 | //$hostid=$hosts[0]->id; |
| 121 | 121 | // Tell JS to get services when page is loaded |
@@ -124,9 +124,9 @@ discard block |
||
| 124 | 124 | } |
| 125 | 125 | else |
| 126 | 126 | { |
| 127 | - foreach($hosts as $key=>$val) |
|
| 127 | + foreach ($hosts as $key=>$val) |
|
| 128 | 128 | { |
| 129 | - array_push($this->view->hostlist,$hosts[$key]->name); |
|
| 129 | + array_push($this->view->hostlist, $hosts[$key]->name); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
@@ -165,18 +165,18 @@ discard block |
||
| 165 | 165 | $currentObjectTypeEnum |
| 166 | 166 | ); |
| 167 | 167 | $oid_index++; |
| 168 | - array_push($this->view->objectList,$currentObject); |
|
| 168 | + array_push($this->view->objectList, $currentObject); |
|
| 169 | 169 | // set currrent object to null in allObjects |
| 170 | 170 | if (isset($allObjects[$val->oid])) |
| 171 | 171 | { |
| 172 | 172 | $allObjects[$val->oid]=null; |
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | - if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
| 175 | + if ($allObjects != null) // in case trap doesn't have objects or is not resolved |
|
| 176 | 176 | { |
| 177 | 177 | foreach ($allObjects as $key => $val) |
| 178 | 178 | { |
| 179 | - if ($val==null) { continue; } |
|
| 179 | + if ($val == null) { continue; } |
|
| 180 | 180 | array_push($this->view->objectList, array( |
| 181 | 181 | $oid_index, |
| 182 | 182 | $key, |
@@ -204,9 +204,9 @@ discard block |
||
| 204 | 204 | // Check if hostname still exists |
| 205 | 205 | $host_get=$this->getHostByName($this->view->hostname); |
| 206 | 206 | |
| 207 | - if (count($host_get)==0) |
|
| 207 | + if (count($host_get) == 0) |
|
| 208 | 208 | { |
| 209 | - $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
|
| 209 | + $this->view->warning_message='Host '.$this->view->hostname.' doesn\'t exists anymore'; |
|
| 210 | 210 | $this->view->serviceGet=false; |
| 211 | 211 | } |
| 212 | 212 | else |
@@ -214,10 +214,10 @@ discard block |
||
| 214 | 214 | // Tell JS to get services when page is loaded |
| 215 | 215 | $this->view->serviceGet=true; |
| 216 | 216 | // get service id for form to set : |
| 217 | - $serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name); |
|
| 218 | - if (count($serviceID) ==0) |
|
| 217 | + $serviceID=$this->getServiceIDByName($this->view->hostname, $ruleDetail->service_name); |
|
| 218 | + if (count($serviceID) == 0) |
|
| 219 | 219 | { |
| 220 | - $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 220 | + $this->view->warning_message=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore'; |
|
| 221 | 221 | } |
| 222 | 222 | else |
| 223 | 223 | { |
@@ -234,9 +234,9 @@ discard block |
||
| 234 | 234 | { |
| 235 | 235 | // Check if groupe exists |
| 236 | 236 | $group_get=$this->getHostGroupByName($this->view->hostgroupname); |
| 237 | - if (count($group_get)==0) |
|
| 237 | + if (count($group_get) == 0) |
|
| 238 | 238 | { |
| 239 | - $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
|
| 239 | + $this->view->warning_message='HostGroup '.$this->view->hostgroupname.' doesn\'t exists anymore'; |
|
| 240 | 240 | $this->view->serviceGroupGet=false; |
| 241 | 241 | } |
| 242 | 242 | else |
@@ -254,9 +254,9 @@ discard block |
||
| 254 | 254 | |
| 255 | 255 | // Tell JS to get services when page is loaded |
| 256 | 256 | $this->view->serviceGroupGet=true; |
| 257 | - if ($foundGrpService==0) |
|
| 257 | + if ($foundGrpService == 0) |
|
| 258 | 258 | { |
| 259 | - $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 259 | + $this->view->warning_message.=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore'; |
|
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | 262 | } |
@@ -274,12 +274,12 @@ discard block |
||
| 274 | 274 | $index=1; |
| 275 | 275 | // check in display & rule for : OID(<oid>) |
| 276 | 276 | $matches=array(); |
| 277 | - while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) || |
|
| 278 | - preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches)) |
|
| 277 | + while (preg_match('/_OID\(([\.0-9\*]+)\)/', $display, $matches) || |
|
| 278 | + preg_match('/_OID\(([\.0-9\*]+)\)/', $rule, $matches)) |
|
| 279 | 279 | { |
| 280 | 280 | $curOid=$matches[1]; |
| 281 | 281 | |
| 282 | - if ( (preg_match('/\*/',$curOid) == 0 ) |
|
| 282 | + if ((preg_match('/\*/', $curOid) == 0) |
|
| 283 | 283 | && ($object=$this->getMIB()->translateOID($curOid)) != null) |
| 284 | 284 | { |
| 285 | 285 | array_push($curObjectList, array( |
@@ -304,9 +304,9 @@ discard block |
||
| 304 | 304 | 'not found' |
| 305 | 305 | )); |
| 306 | 306 | } |
| 307 | - $curOid = preg_replace('/\*/','\*',$curOid); |
|
| 308 | - $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display); |
|
| 309 | - $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule); |
|
| 307 | + $curOid=preg_replace('/\*/', '\*', $curOid); |
|
| 308 | + $display=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $display); |
|
| 309 | + $rule=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $rule); |
|
| 310 | 310 | $index++; |
| 311 | 311 | } |
| 312 | 312 | return $curObjectList; |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | { |
| 321 | 321 | $this->checkConfigPermission(); |
| 322 | 322 | // set up tab |
| 323 | - $this->getTabs()->add('get',array( |
|
| 323 | + $this->getTabs()->add('get', array( |
|
| 324 | 324 | 'active' => true, |
| 325 | 325 | 'label' => $this->translate('Add handler'), |
| 326 | 326 | 'url' => Url::fromRequest() |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | |
| 334 | 334 | //$this->view->trapvalues=false; // Set to true to display 'value' colum in objects |
| 335 | 335 | |
| 336 | - if (($trapid = $this->params->get('fromid')) !== null) { |
|
| 336 | + if (($trapid=$this->params->get('fromid')) !== null) { |
|
| 337 | 337 | /********** Setup from existing trap ***************/ |
| 338 | 338 | $this->add_from_existing($trapid); |
| 339 | 339 | return; |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | $this->view->setRuleMatch=$ruleDetail->action_match; |
| 354 | 354 | $this->view->setRuleNoMatch=$ruleDetail->action_nomatch; |
| 355 | 355 | $this->view->hostgroupname=$ruleDetail->host_group_name; |
| 356 | - $this->view->modified=gmdate("Y-m-d\TH:i:s\Z",$ruleDetail->modified); |
|
| 356 | + $this->view->modified=gmdate("Y-m-d\TH:i:s\Z", $ruleDetail->modified); |
|
| 357 | 357 | $this->view->modifier=$ruleDetail->modifier; |
| 358 | 358 | |
| 359 | 359 | // Warning message if host/service don't exists anymore |
@@ -405,26 +405,26 @@ discard block |
||
| 405 | 405 | |
| 406 | 406 | $params=array( |
| 407 | 407 | // id (also db) => array('post' => post id, 'val' => default val, 'db' => send to table) |
| 408 | - 'hostgroup' => array('post' => 'hostgroup','db'=>false), |
|
| 409 | - 'db_rule' => array('post' => 'db_rule','db'=>false), |
|
| 410 | - 'hostid' => array('post' => 'hostid','db'=>false), |
|
| 411 | - 'host_name' => array('post' => 'hostname','val' => null,'db'=>true), |
|
| 412 | - 'host_group_name'=> array('post' => null,'val' => null,'db'=>true), |
|
| 413 | - 'serviceid' => array('post' => 'serviceid','db'=>false), |
|
| 414 | - 'service_name' => array('post' => 'serviceName','db'=>true), |
|
| 415 | - 'trap_oid' => array('post' => 'oid','db'=>true), |
|
| 416 | - 'revert_ok' => array('post' => 'revertOK','val' => 0,'db'=>true), |
|
| 417 | - 'display' => array('post' => 'display','val' => '','db'=>true), |
|
| 418 | - 'rule' => array('post' => 'rule','val' => '','db'=>true), |
|
| 419 | - 'action_match' => array('post' => 'ruleMatch','val' => -1,'db'=>true), |
|
| 420 | - 'action_nomatch'=> array('post' => 'ruleNoMatch','val' => -1,'db'=>true), |
|
| 421 | - 'ip4' => array('post' => null,'val' => null,'db'=>true), |
|
| 422 | - 'ip6' => array('post' => null,'val' => null,'db'=>true), |
|
| 423 | - 'action_form' => array('post' => 'action_form','db'=>false) |
|
| 408 | + 'hostgroup' => array('post' => 'hostgroup', 'db'=>false), |
|
| 409 | + 'db_rule' => array('post' => 'db_rule', 'db'=>false), |
|
| 410 | + 'hostid' => array('post' => 'hostid', 'db'=>false), |
|
| 411 | + 'host_name' => array('post' => 'hostname', 'val' => null, 'db'=>true), |
|
| 412 | + 'host_group_name'=> array('post' => null, 'val' => null, 'db'=>true), |
|
| 413 | + 'serviceid' => array('post' => 'serviceid', 'db'=>false), |
|
| 414 | + 'service_name' => array('post' => 'serviceName', 'db'=>true), |
|
| 415 | + 'trap_oid' => array('post' => 'oid', 'db'=>true), |
|
| 416 | + 'revert_ok' => array('post' => 'revertOK', 'val' => 0, 'db'=>true), |
|
| 417 | + 'display' => array('post' => 'display', 'val' => '', 'db'=>true), |
|
| 418 | + 'rule' => array('post' => 'rule', 'val' => '', 'db'=>true), |
|
| 419 | + 'action_match' => array('post' => 'ruleMatch', 'val' => -1, 'db'=>true), |
|
| 420 | + 'action_nomatch'=> array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true), |
|
| 421 | + 'ip4' => array('post' => null, 'val' => null, 'db'=>true), |
|
| 422 | + 'ip6' => array('post' => null, 'val' => null, 'db'=>true), |
|
| 423 | + 'action_form' => array('post' => 'action_form', 'db'=>false) |
|
| 424 | 424 | ); |
| 425 | 425 | |
| 426 | 426 | if (isset($postData[$params['action_form']['post']]) |
| 427 | - && $postData[$params['action_form']['post']] == 'delete' ) |
|
| 427 | + && $postData[$params['action_form']['post']] == 'delete') |
|
| 428 | 428 | { |
| 429 | 429 | try |
| 430 | 430 | { |
@@ -444,16 +444,16 @@ discard block |
||
| 444 | 444 | } |
| 445 | 445 | foreach (array_keys($params) as $key) |
| 446 | 446 | { |
| 447 | - if ($params[$key]['post']==null) continue; // data not sent in post vars |
|
| 448 | - if (! isset($postData[$params[$key]['post']])) |
|
| 447 | + if ($params[$key]['post'] == null) continue; // data not sent in post vars |
|
| 448 | + if (!isset($postData[$params[$key]['post']])) |
|
| 449 | 449 | { |
| 450 | 450 | // should not happen as the js checks data |
| 451 | - $this->_helper->json(array('status'=>'No ' . $key)); |
|
| 451 | + $this->_helper->json(array('status'=>'No '.$key)); |
|
| 452 | 452 | } |
| 453 | 453 | else |
| 454 | 454 | { |
| 455 | 455 | $data=$postData[$params[$key]['post']]; |
| 456 | - if ($data!=null && $data !="") |
|
| 456 | + if ($data != null && $data != "") |
|
| 457 | 457 | { |
| 458 | 458 | $params[$key]['val']=$postData[$params[$key]['post']]; |
| 459 | 459 | } |
@@ -462,8 +462,8 @@ discard block |
||
| 462 | 462 | |
| 463 | 463 | try |
| 464 | 464 | { |
| 465 | - $isHostGroup=($params['hostgroup']['val'] == 1)?true:false; |
|
| 466 | - if (! $isHostGroup ) |
|
| 465 | + $isHostGroup=($params['hostgroup']['val'] == 1) ?true:false; |
|
| 466 | + if (!$isHostGroup) |
|
| 467 | 467 | { // checks if selection by host |
| 468 | 468 | $hostAddr=$this->getHostInfoByID($params['hostid']['val']); |
| 469 | 469 | $params['ip4']['val']=$hostAddr->ip4; |
@@ -490,25 +490,25 @@ discard block |
||
| 490 | 490 | return; |
| 491 | 491 | } |
| 492 | 492 | // Put param in correct column (group_name) |
| 493 | - $params['host_group_name']['val'] = $params['host_name']['val']; |
|
| 493 | + $params['host_group_name']['val']=$params['host_name']['val']; |
|
| 494 | 494 | $params['host_name']['val']=null; |
| 495 | 495 | } |
| 496 | 496 | $dbparams=array(); |
| 497 | 497 | foreach ($params as $key=>$val) |
| 498 | 498 | { |
| 499 | - if ($val['db']==true ) |
|
| 499 | + if ($val['db'] == true) |
|
| 500 | 500 | { |
| 501 | - $dbparams[$key] = $val['val']; |
|
| 501 | + $dbparams[$key]=$val['val']; |
|
| 502 | 502 | } |
| 503 | 503 | } |
| 504 | 504 | // echo '<br>'; print_r($dbparams);echo '<br>'; |
| 505 | - if ($params['db_rule']['val'] == -1 ) |
|
| 505 | + if ($params['db_rule']['val'] == -1) |
|
| 506 | 506 | { |
| 507 | 507 | $ruleID=$this->addHandlerRule($dbparams); |
| 508 | 508 | } |
| 509 | 509 | else |
| 510 | 510 | { |
| 511 | - $this->updateHandlerRule($dbparams,$params['db_rule']['val']); |
|
| 511 | + $this->updateHandlerRule($dbparams, $params['db_rule']['val']); |
|
| 512 | 512 | $ruleID=$params['db_rule']['val']; |
| 513 | 513 | } |
| 514 | 514 | } |
@@ -527,10 +527,10 @@ discard block |
||
| 527 | 527 | */ |
| 528 | 528 | protected function getTrapDetail($trapid) |
| 529 | 529 | { |
| 530 | - if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
|
| 530 | + if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); } |
|
| 531 | 531 | $queryArray=$this->getModuleConfig()->trapDetailQuery(); |
| 532 | 532 | |
| 533 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 533 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
| 534 | 534 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 535 | 535 | // *************** Get main data |
| 536 | 536 | // extract columns and titles; |
@@ -540,19 +540,19 @@ discard block |
||
| 540 | 540 | } |
| 541 | 541 | try |
| 542 | 542 | { |
| 543 | - $query = $dbConn->select() |
|
| 544 | - ->from($this->getModuleConfig()->getTrapTableName(),$elmts) |
|
| 545 | - ->where('id=?',$trapid); |
|
| 543 | + $query=$dbConn->select() |
|
| 544 | + ->from($this->getModuleConfig()->getTrapTableName(), $elmts) |
|
| 545 | + ->where('id=?', $trapid); |
|
| 546 | 546 | $trapDetail=$dbConn->fetchRow($query); |
| 547 | - if ( $trapDetail == null ) |
|
| 547 | + if ($trapDetail == null) |
|
| 548 | 548 | { |
| 549 | - $trapDetail = 'NULL'; |
|
| 549 | + $trapDetail='NULL'; |
|
| 550 | 550 | throw new Exception('No traps was found with id = '.$trapid); |
| 551 | 551 | } |
| 552 | 552 | } |
| 553 | 553 | catch (Exception $e) |
| 554 | 554 | { |
| 555 | - $this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage()); |
|
| 555 | + $this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail, true), $e->getMessage()); |
|
| 556 | 556 | return; |
| 557 | 557 | } |
| 558 | 558 | |
@@ -566,10 +566,10 @@ discard block |
||
| 566 | 566 | */ |
| 567 | 567 | protected function getTrapobjects($trapid) |
| 568 | 568 | { |
| 569 | - if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
|
| 569 | + if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); } |
|
| 570 | 570 | $queryArrayData=$this->getModuleConfig()->trapDataDetailQuery(); |
| 571 | 571 | |
| 572 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 572 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
| 573 | 573 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 574 | 574 | // *************** Get object data |
| 575 | 575 | // extract columns and titles; |
@@ -579,15 +579,15 @@ discard block |
||
| 579 | 579 | } |
| 580 | 580 | try |
| 581 | 581 | { |
| 582 | - $query = $dbConn->select() |
|
| 583 | - ->from($this->moduleConfig->getTrapDataTableName(),$data_elmts) |
|
| 584 | - ->where('trap_id=?',$trapid); |
|
| 582 | + $query=$dbConn->select() |
|
| 583 | + ->from($this->moduleConfig->getTrapDataTableName(), $data_elmts) |
|
| 584 | + ->where('trap_id=?', $trapid); |
|
| 585 | 585 | $trapDetail=$dbConn->fetchAll($query); |
| 586 | 586 | // if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid); |
| 587 | 587 | } |
| 588 | 588 | catch (Exception $e) |
| 589 | 589 | { |
| 590 | - $this->displayExitError('Add handler : get trap data detail : ',$e->getMessage()); |
|
| 590 | + $this->displayExitError('Add handler : get trap data detail : ', $e->getMessage()); |
|
| 591 | 591 | return array(); |
| 592 | 592 | } |
| 593 | 593 | |
@@ -601,24 +601,24 @@ discard block |
||
| 601 | 601 | */ |
| 602 | 602 | protected function getRuleDetail($ruleid) |
| 603 | 603 | { |
| 604 | - if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id'); } |
|
| 604 | + if (!preg_match('/^[0-9]+$/', $ruleid)) { throw new Exception('Invalid id'); } |
|
| 605 | 605 | $queryArray=$this->getModuleConfig()->ruleDetailQuery(); |
| 606 | 606 | |
| 607 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 607 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
| 608 | 608 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 609 | 609 | // *************** Get main data |
| 610 | 610 | try |
| 611 | 611 | { |
| 612 | - $query = $dbConn->select() |
|
| 613 | - ->from($this->getModuleConfig()->getTrapRuleName(),$queryArray) |
|
| 614 | - ->where('id=?',$ruleid); |
|
| 612 | + $query=$dbConn->select() |
|
| 613 | + ->from($this->getModuleConfig()->getTrapRuleName(), $queryArray) |
|
| 614 | + ->where('id=?', $ruleid); |
|
| 615 | 615 | $ruleDetail=$dbConn->fetchRow($query); |
| 616 | - if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid); |
|
| 616 | + if ($ruleDetail == null) throw new Exception('No rule was found with id = '.$ruleid); |
|
| 617 | 617 | } |
| 618 | 618 | catch (Exception $e) |
| 619 | 619 | { |
| 620 | - $this->displayExitError('Update handler : get rule detail',$e->getMessage()); |
|
| 621 | - throw new Exception('Error : ',$e->getMessage()); |
|
| 620 | + $this->displayExitError('Update handler : get rule detail', $e->getMessage()); |
|
| 621 | + throw new Exception('Error : ', $e->getMessage()); |
|
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | return $ruleDetail; |
@@ -631,7 +631,7 @@ discard block |
||
| 631 | 631 | { |
| 632 | 632 | return $this->getTabs()->add('status', array( |
| 633 | 633 | 'label' => $this->translate('Traps'), |
| 634 | - 'url' => $this->getModuleConfig()->urlPath() . '/handler') |
|
| 634 | + 'url' => $this->getModuleConfig()->urlPath().'/handler') |
|
| 635 | 635 | ); |
| 636 | 636 | } |
| 637 | 637 | |
@@ -29,10 +29,10 @@ discard block |
||
| 29 | 29 | * @param int $code |
| 30 | 30 | * @param Exception $previous |
| 31 | 31 | */ |
| 32 | - public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null) |
|
| 32 | + public function __construct(array $retarray, string $message=null, int $code=0, Exception $previous=null) |
|
| 33 | 33 | { |
| 34 | - parent::__construct($message,$code,$previous); |
|
| 35 | - $this->returnArray = $retarray; |
|
| 34 | + parent::__construct($message, $code, $previous); |
|
| 35 | + $this->returnArray=$retarray; |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -88,19 +88,19 @@ discard block |
||
| 88 | 88 | * @return bool true if OK, false if version < min version |
| 89 | 89 | * @throws Exception if error and test = true |
| 90 | 90 | */ |
| 91 | - protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname) |
|
| 91 | + protected function testDbVersion($dbAdapter, int $min, bool $test, string $DBname) |
|
| 92 | 92 | { |
| 93 | 93 | try |
| 94 | 94 | { |
| 95 | - $query = $dbAdapter->select() |
|
| 96 | - ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value') |
|
| 95 | + $query=$dbAdapter->select() |
|
| 96 | + ->from($this->trapController->getModuleConfig()->getDbConfigTableName(), 'value') |
|
| 97 | 97 | ->where('name=\'db_version\''); |
| 98 | 98 | $version=$dbAdapter->fetchRow($query); |
| 99 | - if ( ($version == null) || ! property_exists($version,'value') ) |
|
| 99 | + if (($version == null) || !property_exists($version, 'value')) |
|
| 100 | 100 | { |
| 101 | 101 | if ($test === true) |
| 102 | 102 | { |
| 103 | - $this->testResult = array(4,$DBname); |
|
| 103 | + $this->testResult=array(4, $DBname); |
|
| 104 | 104 | return false; |
| 105 | 105 | } |
| 106 | 106 | $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | { |
| 111 | 111 | if ($test === true) |
| 112 | 112 | { |
| 113 | - $this->testResult = array(5,$version->value,$min); |
|
| 113 | + $this->testResult=array(5, $version->value, $min); |
|
| 114 | 114 | return false; |
| 115 | 115 | } |
| 116 | 116 | $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | { |
| 122 | 122 | if ($test === true) |
| 123 | 123 | { |
| 124 | - $this->testResult = array(3,$DBname,$e->getMessage()); |
|
| 124 | + $this->testResult=array(3, $DBname, $e->getMessage()); |
|
| 125 | 125 | return false; |
| 126 | 126 | } |
| 127 | 127 | $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
@@ -137,17 +137,17 @@ discard block |
||
| 137 | 137 | * @throws DBException if test = true and error |
| 138 | 138 | * @return Selectable|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
| 139 | 139 | */ |
| 140 | - protected function getDbByName($DBname , $test = false , $test_version = true) |
|
| 140 | + protected function getDbByName($DBname, $test=false, $test_version=true) |
|
| 141 | 141 | { |
| 142 | 142 | try |
| 143 | 143 | { |
| 144 | - $dbconn = IcingaDbConnection::fromResourceName($DBname); |
|
| 144 | + $dbconn=IcingaDbConnection::fromResourceName($DBname); |
|
| 145 | 145 | } |
| 146 | 146 | catch (Exception $e) |
| 147 | 147 | { |
| 148 | 148 | if ($test === true) |
| 149 | 149 | { |
| 150 | - throw new DBException(array(2,$DBname)); |
|
| 150 | + throw new DBException(array(2, $DBname)); |
|
| 151 | 151 | } |
| 152 | 152 | $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
| 153 | 153 | return null; |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | { |
| 163 | 163 | if ($test === true) |
| 164 | 164 | { |
| 165 | - throw new DBException(array(3,$DBname,$e->getMessage())); |
|
| 165 | + throw new DBException(array(3, $DBname, $e->getMessage())); |
|
| 166 | 166 | } |
| 167 | 167 | $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
| 168 | 168 | return null; |
@@ -185,19 +185,19 @@ discard block |
||
| 185 | 185 | */ |
| 186 | 186 | public function getDb() |
| 187 | 187 | { |
| 188 | - if ( $this->trapDB != null ) return $this->trapDB; |
|
| 188 | + if ($this->trapDB != null) return $this->trapDB; |
|
| 189 | 189 | |
| 190 | 190 | |
| 191 | 191 | $dbresource=$this->trapController->Config()->get('config', 'database'); |
| 192 | 192 | |
| 193 | - if ( ! $dbresource ) |
|
| 193 | + if (!$dbresource) |
|
| 194 | 194 | { |
| 195 | 195 | $this->trapController->redirectNow('trapdirector/settings?dberror=1'); |
| 196 | 196 | return null; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | try { |
| 200 | - $this->trapDB = $this->getDbByName($dbresource,false,true); |
|
| 200 | + $this->trapDB=$this->getDbByName($dbresource, false, true); |
|
| 201 | 201 | } catch (DBException $e) { |
| 202 | 202 | return null; // Should not happen as test = false |
| 203 | 203 | } |
@@ -227,12 +227,12 @@ discard block |
||
| 227 | 227 | { |
| 228 | 228 | $dbresource=$this->trapController->Config()->get('config', 'database'); |
| 229 | 229 | |
| 230 | - if ( ! $dbresource ) |
|
| 230 | + if (!$dbresource) |
|
| 231 | 231 | { |
| 232 | - throw new DBException(array(1,'')); |
|
| 232 | + throw new DBException(array(1, '')); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - $this->trapDB = $this->getDbByName($dbresource,true,true); |
|
| 235 | + $this->trapDB=$this->getDbByName($dbresource, true, true); |
|
| 236 | 236 | return; |
| 237 | 237 | } |
| 238 | 238 | |
@@ -243,11 +243,11 @@ discard block |
||
| 243 | 243 | */ |
| 244 | 244 | public function getIdoDb() |
| 245 | 245 | { |
| 246 | - if ( $this->idoDB != null ) return $this->idoDB; |
|
| 246 | + if ($this->idoDB != null) return $this->idoDB; |
|
| 247 | 247 | // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
| 248 | - $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
| 248 | + $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase'); ; |
|
| 249 | 249 | |
| 250 | - if ( ! $dbresource ) |
|
| 250 | + if (!$dbresource) |
|
| 251 | 251 | { |
| 252 | 252 | $this->trapController->redirectNow('trapdirector/settings?idodberror=1'); |
| 253 | 253 | return null; |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | |
| 256 | 256 | try |
| 257 | 257 | { |
| 258 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
| 258 | + $dbconn=IcingaDbConnection::fromResourceName($dbresource); |
|
| 259 | 259 | } |
| 260 | 260 | catch (Exception $e) |
| 261 | 261 | { |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | return null; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - $this->idoDB = $dbconn; |
|
| 266 | + $this->idoDB=$dbconn; |
|
| 267 | 267 | return $this->idoDB; |
| 268 | 268 | } |
| 269 | 269 | |
@@ -286,35 +286,35 @@ discard block |
||
| 286 | 286 | public function testGetIdoDb() |
| 287 | 287 | { |
| 288 | 288 | // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
| 289 | - $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
| 289 | + $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase'); ; |
|
| 290 | 290 | |
| 291 | - if ( ! $dbresource ) |
|
| 291 | + if (!$dbresource) |
|
| 292 | 292 | { |
| 293 | - throw new DBException(array(1,'No database in config.ini')); |
|
| 293 | + throw new DBException(array(1, 'No database in config.ini')); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | try |
| 297 | 297 | { |
| 298 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
| 298 | + $dbconn=IcingaDbConnection::fromResourceName($dbresource); |
|
| 299 | 299 | } |
| 300 | 300 | catch (Exception $e) |
| 301 | 301 | { |
| 302 | - throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") ); |
|
| 302 | + throw new DBException(array(2, "Database $dbresource does not exists in IcingaWeb2")); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | try |
| 306 | 306 | { |
| 307 | - $query = $dbconn->select() |
|
| 308 | - ->from('icinga_dbversion',array('version')); |
|
| 307 | + $query=$dbconn->select() |
|
| 308 | + ->from('icinga_dbversion', array('version')); |
|
| 309 | 309 | $version=$dbconn->fetchRow($query); |
| 310 | - if ( ($version == null) || ! property_exists($version,'version') ) |
|
| 310 | + if (($version == null) || !property_exists($version, 'version')) |
|
| 311 | 311 | { |
| 312 | - throw new DBException( array(4,"$dbresource does not look like an IDO database")); |
|
| 312 | + throw new DBException(array(4, "$dbresource does not look like an IDO database")); |
|
| 313 | 313 | } |
| 314 | 314 | } |
| 315 | 315 | catch (Exception $e) |
| 316 | 316 | { |
| 317 | - throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage())); |
|
| 317 | + throw new DBException(array(3, "Error connecting to $dbresource : ".$e->getMessage())); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | return; |