Passed
Push — master ( 57a389...e15d84 )
by Patrick
02:12
created
library/Trapdirector/TrapsController.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -180,7 +180,9 @@
 block discarded – undo
180 180
 		if ($this->MIBData == null)
181 181
 		{
182 182
 		    $dbConn = $this->getUIDatabase()->getDbConn();
183
-		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
183
+		    if ($dbConn === null) {
184
+		    	throw new \ErrorException('uncatched db error');
185
+		    }
184 186
 			$this->MIBData=new MIBLoader(
185 187
 				$this->Config()->get('config', 'snmptranslate'),
186 188
 				$this->Config()->get('config', 'snmptranslate_dirs'),
Please login to merge, or discard this patch.
library/Trapdirector/TrapsActions/IdoDBQuery.php 1 patch
Braces   +28 added lines, -11 removed lines patch added patch discarded remove patch
@@ -24,7 +24,9 @@  discard block
 block discarded – undo
24 24
     {
25 25
         // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
26 26
         $dbConn = $this->getIdoDbConn();
27
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
27
+        if ($dbConn === null) {
28
+        	throw new \ErrorException('uncatched db error');
29
+        }
28 30
         
29 31
         // TODO : check for SQL injections
30 32
         $query=$dbConn->select()
@@ -47,7 +49,9 @@  discard block
 block discarded – undo
47 49
     {
48 50
         // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
49 51
         $dbConn = $this->getIdoDbConn();
50
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
52
+        if ($dbConn === null) {
53
+        	throw new \ErrorException('uncatched db error');
54
+        }
51 55
         
52 56
         // TODO : check for SQL injections
53 57
         $query=$dbConn->select()
@@ -70,7 +74,9 @@  discard block
 block discarded – undo
70 74
     {
71 75
         // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
72 76
         $dbConn = $this->getIdoDbConn();
73
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
77
+        if ($dbConn === null) {
78
+        	throw new \ErrorException('uncatched db error');
79
+        }
74 80
         // TODO : check for SQL injections
75 81
         $query=$dbConn->select()
76 82
         ->from(
@@ -93,7 +99,9 @@  discard block
 block discarded – undo
93 99
     {
94 100
         if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
95 101
         $dbConn = $this->getIdoDbConn();
96
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
102
+        if ($dbConn === null) {
103
+        	throw new \ErrorException('uncatched db error');
104
+        }
97 105
         $query=$dbConn->select()
98 106
         ->from(
99 107
             array('a' => 'icinga_objects'),
@@ -115,7 +123,9 @@  discard block
 block discarded – undo
115 123
     {
116 124
         if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
117 125
         $dbConn = $this->getIdoDbConn();
118
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
126
+        if ($dbConn === null) {
127
+        	throw new \ErrorException('uncatched db error');
128
+        }
119 129
         $query=$dbConn->select()
120 130
         ->from(
121 131
             array('a' => 'icinga_objects'),
@@ -138,7 +148,9 @@  discard block
 block discarded – undo
138 148
         // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
139 149
         if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
140 150
         $dbConn = $this->getIdoDbConn();
141
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
151
+        if ($dbConn === null) {
152
+        	throw new \ErrorException('uncatched db error');
153
+        }
142 154
         $query=$dbConn->select()
143 155
         ->from(
144 156
             array('s' => 'icinga_services'),
@@ -161,7 +173,9 @@  discard block
 block discarded – undo
161 173
     {
162 174
         if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
163 175
         $dbConn = $this->getIdoDbConn();
164
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
176
+        if ($dbConn === null) {
177
+        	throw new \ErrorException('uncatched db error');
178
+        }
165 179
         $query=$dbConn->select()
166 180
         ->from(
167 181
             array('s' => 'icinga_hostgroup_members'),
@@ -182,8 +196,7 @@  discard block
 block discarded – undo
182 196
                         if (isset($common_services[$service->name2]['num']))
183 197
                         {
184 198
                             $common_services[$service->name2]['num'] +=1;
185
-                        }
186
-                        else
199
+                        } else
187 200
                         {
188 201
                             $common_services[$service->name2]['num']=1;
189 202
                             $common_services[$service->name2]['name']=$service->name;
@@ -213,7 +226,9 @@  discard block
 block discarded – undo
213 226
     public function getServiceIDByName($hostname,$name)
214 227
     {
215 228
         $dbConn = $this->getIdoDbConn();
216
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
229
+        if ($dbConn === null) {
230
+        	throw new \ErrorException('uncatched db error');
231
+        }
217 232
         
218 233
         if ($name == null)
219 234
         {
@@ -243,7 +258,9 @@  discard block
 block discarded – undo
243 258
         // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
244 259
         if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
245 260
         $dbConn = $this->getIdoDbConn();
246
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
261
+        if ($dbConn === null) {
262
+        	throw new \ErrorException('uncatched db error');
263
+        }
247 264
         
248 265
         $query=$dbConn->select()
249 266
         ->from(
Please login to merge, or discard this patch.
application/controllers/HandlerController.php 1 patch
Braces   +44 added lines, -42 removed lines patch added patch discarded remove patch
@@ -24,7 +24,9 @@  discard block
 block discarded – undo
24 24
 		$this->prepareTabs()->activate('status');
25 25
 
26 26
 		$dbConn = $this->getUIDatabase()->getDb();
27
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
27
+		if ($dbConn === null) {
28
+			throw new \ErrorException('uncatched db error');
29
+		}
28 30
 		
29 31
 		$this->getHandlerListTable()->setConnection($dbConn);
30 32
 		$this->getHandlerListTable()->setMibloader($this->getMIB());
@@ -52,8 +54,7 @@  discard block
 block discarded – undo
52 54
 	    if ($this->params->get('rule') !== null) 
53 55
 	    {
54 56
 	        $this->view->rule= $this->params->get('rule');
55
-	    }
56
-	    else
57
+	    } else
57 58
 	    {
58 59
 	        $this->view->rule='';
59 60
 	    }
@@ -107,8 +108,7 @@  discard block
 block discarded – undo
107 108
 	    try
108 109
 	    {
109 110
 	        $hosts=$this->getUIDatabase()->getHostByIP($hostfilter);
110
-	    }
111
-	    catch (Exception $e)
111
+	    } catch (Exception $e)
112 112
 	    {
113 113
 	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
114 114
 	    }
@@ -121,8 +121,7 @@  discard block
 block discarded – undo
121 121
 	        // Tell JS to get services when page is loaded
122 122
 	        $this->view->serviceGet=true;
123 123
 	        
124
-	    }
125
-	    else
124
+	    } else
126 125
 	    {
127 126
 	        foreach($hosts as $key=>$val)
128 127
 	        {
@@ -172,11 +171,14 @@  discard block
 block discarded – undo
172 171
 	            $allObjects[$val->oid]=null;
173 172
 	        }
174 173
 	    }
175
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
174
+	    if ($allObjects!=null) {
175
+	    	// 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
+	    }
181
+	    }
180 182
 	            array_push($this->view->objectList, array(
181 183
 	                $oid_index,
182 184
 	                $key,
@@ -208,8 +210,7 @@  discard block
 block discarded – undo
208 210
 	    {
209 211
 	        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
210 212
 	        $this->view->serviceGet=false;
211
-	    }
212
-	    else
213
+	    } else
213 214
 	    {
214 215
 	        // Tell JS to get services when page is loaded
215 216
 	        $this->view->serviceGet=true;
@@ -218,8 +219,7 @@  discard block
 block discarded – undo
218 219
 	        if (count($serviceID) ==0)
219 220
 	        {
220 221
 	            $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
221
-	        }
222
-	        else
222
+	        } else
223 223
 	        {
224 224
 	            $this->view->serviceSet=$serviceID[0]->id;
225 225
 	        }
@@ -238,8 +238,7 @@  discard block
 block discarded – undo
238 238
 	    {
239 239
 	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
240 240
 	        $this->view->serviceGroupGet=false;
241
-	    }
242
-	    else
241
+	    } else
243 242
 	    {
244 243
 	        $grpServices=$this->getUIDatabase()->getServicesByHostGroupid($group_get[0]->id);
245 244
 	        $foundGrpService=0;
@@ -291,8 +290,7 @@  discard block
 block discarded – undo
291 290
 	                $object['type'],
292 291
 	                $object['type_enum']
293 292
 	            ));
294
-	        }
295
-	        else
293
+	        } else
296 294
 	        {
297 295
 	            array_push($curObjectList, array(
298 296
 	                $index,
@@ -363,8 +361,7 @@  discard block
 block discarded – undo
363 361
 			    $this->view->selectGroup=false;
364 362
 			    // Check if hostname still exists
365 363
 			    $this->add_check_host_exists($ruleDetail);
366
-			}
367
-			else
364
+			} else
368 365
 			{
369 366
 			    $this->view->selectGroup=true;
370 367
 			    $this->add_check_hostgroup_exists($ruleDetail); //  Check if groupe exists				
@@ -372,9 +369,11 @@  discard block
 block discarded – undo
372 369
 			
373 370
 			$this->view->mainoid=$ruleDetail->trap_oid;
374 371
 			$oidName=$this->getMIB()->translateOID($ruleDetail->trap_oid);
375
-			if ($oidName != null)  // oid is found in mibs
372
+			if ($oidName != null) {
373
+				// oid is found in mibs
376 374
 			{
377
-				$this->view->mib=$oidName['mib']; 
375
+				$this->view->mib=$oidName['mib'];
376
+			}
378 377
 				$this->view->name=$oidName['name'];
379 378
 				$this->view->trapListForMIB=$this->getMIB()
380 379
 					->getTrapList($oidName['mib']);				
@@ -429,8 +428,7 @@  discard block
 block discarded – undo
429 428
 			try
430 429
 			{
431 430
 			    $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]);
432
-			}
433
-			catch (Exception $e)
431
+			} catch (Exception $e)
434 432
 			{
435 433
 				$this->_helper->json(array('status'=>$e->getMessage()));
436 434
 				return;
@@ -444,13 +442,15 @@  discard block
 block discarded – undo
444 442
 		}		
445 443
 		foreach (array_keys($params) as $key)
446 444
 		{
447
-			if ($params[$key]['post']==null) continue; // data not sent in post vars
445
+			if ($params[$key]['post']==null) {
446
+				continue;
447
+			}
448
+			// data not sent in post vars
448 449
 			if (! isset($postData[$params[$key]['post']]))
449 450
 			{
450 451
 				// should not happen as the js checks data
451 452
 				$this->_helper->json(array('status'=>'No ' . $key));
452
-			}
453
-			else
453
+			} else
454 454
 			{
455 455
 				$data=$postData[$params[$key]['post']];
456 456
 				if ($data!=null && $data !="")
@@ -480,8 +480,7 @@  discard block
 block discarded – undo
480 480
 					$this->_helper->json(array('status'=>"Invalid service id : Please re enter service"));
481 481
 					return;
482 482
 				}
483
-			}
484
-			else
483
+			} else
485 484
 			{
486 485
 			    $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']);
487 486
 				if ($params['host_name']['val'] != $object->name1)
@@ -505,14 +504,12 @@  discard block
 block discarded – undo
505 504
 			if ($params['db_rule']['val'] == -1 ) 
506 505
 			{
507 506
 			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
508
-			}
509
-			else
507
+			} else
510 508
 			{
511 509
 			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
512 510
 				$ruleID=$params['db_rule']['val'];
513 511
 			}
514
-		}
515
-		catch (Exception $e)
512
+		} catch (Exception $e)
516 513
 		{
517 514
 			$this->_helper->json(array('status'=>$e->getMessage()));
518 515
 			return;
@@ -531,7 +528,9 @@  discard block
 block discarded – undo
531 528
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
532 529
 		
533 530
 		$dbConn = $this->getUIDatabase()->getDbConn();
534
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
531
+		if ($dbConn === null) {
532
+			throw new \ErrorException('uncatched db error');
533
+		}
535 534
 		// ***************  Get main data
536 535
 		// extract columns and titles;
537 536
 		$elmts=NULL;
@@ -549,8 +548,7 @@  discard block
 block discarded – undo
549 548
 			    $trapDetail = 'NULL';
550 549
 			    throw new Exception('No traps was found with id = '.$trapid);
551 550
 			}
552
-		}
553
-		catch (Exception $e)
551
+		} catch (Exception $e)
554 552
 		{
555 553
 			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
556 554
 			return;
@@ -570,7 +568,9 @@  discard block
 block discarded – undo
570 568
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
571 569
 		
572 570
 		$dbConn = $this->getUIDatabase()->getDbConn();
573
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
571
+		if ($dbConn === null) {
572
+			throw new \ErrorException('uncatched db error');
573
+		}
574 574
 		// ***************  Get object data
575 575
 		// extract columns and titles;
576 576
 		$data_elmts=NULL;
@@ -584,8 +584,7 @@  discard block
 block discarded – undo
584 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
-		}
588
-		catch (Exception $e)
587
+		} catch (Exception $e)
589 588
 		{
590 589
 			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
591 590
 			return array();
@@ -605,7 +604,9 @@  discard block
 block discarded – undo
605 604
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
606 605
 		
607 606
 		$dbConn = $this->getUIDatabase()->getDbConn();
608
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
607
+		if ($dbConn === null) {
608
+			throw new \ErrorException('uncatched db error');
609
+		}
609 610
 		// ***************  Get main data
610 611
 		try
611 612
 		{		
@@ -613,9 +614,10 @@  discard block
 block discarded – undo
613 614
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
614 615
 				->where('id=?',$ruleid);
615 616
 			$ruleDetail=$dbConn->fetchRow($query);
616
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
617
-		}
618
-		catch (Exception $e)
617
+			if ( $ruleDetail == null ) {
618
+				throw new Exception('No rule was found with id = '.$ruleid);
619
+			}
620
+		} catch (Exception $e)
619 621
 		{
620 622
 			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
621 623
 			throw new Exception('Error : ',$e->getMessage());
Please login to merge, or discard this patch.