Passed
Push — master ( 3d7e39...d44cfc )
by Patrick
02:50
created
application/controllers/HelperController.php 1 patch
Braces   +16 added lines, -32 removed lines patch added patch discarded remove patch
@@ -65,8 +65,7 @@  discard block
 block discarded – undo
65 65
 		if (isset($postData['host']))
66 66
 		{
67 67
 			$host=$postData['host'];
68
-		}
69
-		else
68
+		} else
70 69
 		{
71 70
 			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1));
72 71
 			return;
@@ -77,8 +76,7 @@  discard block
 block discarded – undo
77 76
 		{	
78 77
 			$this->_helper->json(array('status'=>'More than one host matches','hostid' => -1));
79 78
 			return;
80
-		}
81
-		else if (count($hostArray) == 0)
79
+		} else if (count($hostArray) == 0)
82 80
 		{
83 81
 			$this->_helper->json(array('status'=>'No host matches','hostid' => -1));
84 82
 			return;
@@ -114,8 +112,7 @@  discard block
 block discarded – undo
114 112
 		{	
115 113
 			$this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1));
116 114
 			return;
117
-		}
118
-		else if (count($hostArray) == 0)
115
+		} else if (count($hostArray) == 0)
119 116
 		{
120 117
 			$this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1));
121 118
 			return;
@@ -146,8 +143,7 @@  discard block
 block discarded – undo
146 143
 		{
147 144
 			$traplist=$this->getMIB()->getTrapList($mib);
148 145
 			$retTraps=array('status'=>'OK','traps' => $traplist);
149
-		} 
150
-		catch (Exception $e) 
146
+		} catch (Exception $e) 
151 147
 		{ 
152 148
 			$retTraps=array('status' => 'Error getting mibs');
153 149
 		}
@@ -169,8 +165,7 @@  discard block
 block discarded – undo
169 165
 		{
170 166
 			$objectlist=$this->getMIB()->getObjectList($trap);
171 167
 			$retObjects=array('status'=>'OK','objects' => $objectlist);
172
-		} 
173
-		catch (Exception $e) 
168
+		} catch (Exception $e) 
174 169
 		{ 
175 170
 			$retObjects=array('status' => 'not found');
176 171
 		}
@@ -185,8 +180,7 @@  discard block
 block discarded – undo
185 180
 		try
186 181
 		{
187 182
 			$miblist=$this->getMIB()->getMIBList();
188
-		} 
189
-		catch (Exception $e) 
183
+		} catch (Exception $e) 
190 184
 		{ 
191 185
 			$miblist=array('Error getting mibs');
192 186
 		}
@@ -209,8 +203,7 @@  discard block
 block discarded – undo
209 203
 		{
210 204
 			$this->_helper->json(array('status'=>'Not found'));
211 205
 			return;
212
-		}
213
-		else
206
+		} else
214 207
 		{
215 208
 			$this->_helper->json(
216 209
 				array('status'=>'OK',
@@ -244,8 +237,7 @@  discard block
 block discarded – undo
244 237
 			try
245 238
 			{
246 239
 			    $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days);
247
-			}
248
-			catch (Exception $e)
240
+			} catch (Exception $e)
249 241
 			{
250 242
 				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
251 243
 				return;
@@ -263,8 +255,7 @@  discard block
 block discarded – undo
263 255
 				$trap = new Trap($icingaweb2_etc);
264 256
 				$trap->setLogging($debug_level,'syslog');
265 257
 				$trap->eraseOldTraps($days);
266
-			}
267
-			catch (Exception $e)
258
+			} catch (Exception $e)
268 259
 			{
269 260
 				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage() ));
270 261
 				return;
@@ -301,14 +292,12 @@  discard block
 block discarded – undo
301 292
 			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
302 293
 			    return;
303 294
 			}
304
-		}
305
-		else
295
+		} else
306 296
 		{
307 297
 			if ($destination != 'file')
308 298
 			{
309 299
 				$file=null;
310
-			}
311
-			else
300
+			} else
312 301
 			{
313 302
 				$this->_helper->json(array('status'=>'No file'));
314 303
 				return;
@@ -322,8 +311,7 @@  discard block
 block discarded – undo
322 311
 		    $this->getUIDatabase()->setDBConfigValue('log_destination',$destination);
323 312
 		    $this->getUIDatabase()->setDBConfigValue('log_file',$file);
324 313
 		    $this->getUIDatabase()->setDBConfigValue('log_level',$level);
325
-		}
326
-		catch (Exception $e)
314
+		} catch (Exception $e)
327 315
 		{
328 316
 			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
329 317
 			return;
@@ -359,8 +347,7 @@  discard block
 block discarded – undo
359 347
 	            // Eval
360 348
 	            $item=0;
361 349
 	            $rule=$trap->ruleClass->evaluation($rule,$item);
362
-	        }
363
-	        catch (Exception $e)
350
+	        } catch (Exception $e)
364 351
 	        {
365 352
 	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
366 353
 	            return;
@@ -393,8 +380,7 @@  discard block
 block discarded – undo
393 380
             $action=($action == 'enable') ? true : false;
394 381
             $retVal=$trap->pluginClass->enablePlugin($pluginName, $action);
395 382
             
396
-        }
397
-        catch (Exception $e)
383
+        } catch (Exception $e)
398 384
         {
399 385
             $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
400 386
             return;
@@ -402,8 +388,7 @@  discard block
 block discarded – undo
402 388
         if ($retVal === true)
403 389
         {
404 390
             $this->_helper->json(array('status'=>'OK'));
405
-        }
406
-        else
391
+        } else
407 392
         {
408 393
             $this->_helper->json(array('status'=>'Error, see logs'));
409 394
         }
@@ -434,8 +419,7 @@  discard block
 block discarded – undo
434 419
 	        $functionString = $trap->ruleClass->eval_cleanup($functionString);
435 420
 	        // Eval functions
436 421
 	        $result = $trap->pluginClass->evaluateFunctionString($functionString);	        
437
-	    }
438
-	    catch (Exception $e)
422
+	    } catch (Exception $e)
439 423
 	    {
440 424
 	        $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
441 425
 	        return;
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->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->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->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.
application/controllers/StatusController.php 1 patch
Braces   +13 added lines, -21 removed lines patch added patch discarded remove patch
@@ -22,7 +22,9 @@  discard block
 block discarded – undo
22 22
 		try
23 23
 		{
24 24
 		    $dbConn = $this->getUIDatabase()->getDbConn();
25
-		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
25
+		    if ($dbConn === null) {
26
+		    	throw new \ErrorException('uncatched db error');
27
+		    }
26 28
 			$query = $dbConn->select()->from(
27 29
 				$this->getModuleConfig()->getTrapTableName(),
28 30
 				array('COUNT(*)')
@@ -41,8 +43,7 @@  discard block
 block discarded – undo
41 43
  			
42 44
 			$this->view->trap_days_delete=$this->getUIDatabase()->getDBConfigValue('db_remove_days');
43 45
 			
44
-		}
45
-		catch (Exception $e)
46
+		} catch (Exception $e)
46 47
 		{
47 48
 			$this->displayExitError('status',$e->getMessage());
48 49
 		}
@@ -56,8 +57,7 @@  discard block
 block discarded – undo
56 57
 			$this->view->currentLogFile=$this->getUIDatabase()->getDBConfigValue('log_file');
57 58
 			$this->view->logLevels=$this->getModuleConfig()->getlogLevels();
58 59
 			$this->view->currentLogLevel=$this->getUIDatabase()->getDBConfigValue('log_level');
59
-		}
60
-		catch (Exception $e)
60
+		} catch (Exception $e)
61 61
 		{
62 62
 			$this->displayExitError('status',$e->getMessage());
63 63
 		}		
@@ -107,8 +107,7 @@  discard block
 block discarded – undo
107 107
 					if ($retVal == 0)
108 108
 					{ // process is alive
109 109
 						$this->_helper->json(array('status'=>'Alive and kicking'));
110
-					}
111
-					else
110
+					} else
112 111
 					{ // process is dead
113 112
 					    $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid));
114 113
 					}
@@ -124,22 +123,19 @@  discard block
 block discarded – undo
124 123
 				if (!is_dir($destDir))
125 124
 				{
126 125
 				    $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration";
127
-				}
128
-				else
126
+				} else
129 127
 				{
130 128
 				    if (!is_writable($destDir))
131 129
 				    {
132 130
 				        $this->view->uploadStatus="ERROR : $destDir directory is not writable";
133
-				    }
134
-				    else
131
+				    } else
135 132
 				    {
136 133
 				        $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name";
137 134
 				        $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING);
138 135
 				        if (move_uploaded_file($sourceTmpNam,$destination)===false)
139 136
     				    {
140 137
     				        $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations";
141
-    				    }
142
-    				    else
138
+    				    } else
143 139
     				    {
144 140
     				        $this->view->uploadStatus="File $name uploaded in $destDir";
145 141
     				    }
@@ -161,13 +157,11 @@  discard block
 block discarded – undo
161 157
 			{
162 158
 				$this->view->snmptranslate='works fine';
163 159
 				$this->view->snmptranslate_state='ok';
164
-			}
165
-			else
160
+			} else
166 161
 			{
167 162
 				$this->view->snmptranslate='can execute but no resolution';
168 163
 			}
169
-		}
170
-		else
164
+		} else
171 165
 		{
172 166
 			$this->view->snmptranslate='cannot execute';
173 167
 		}
@@ -188,15 +182,13 @@  discard block
 block discarded – undo
188 182
 		if ($retVal==0)
189 183
 		{
190 184
 			$dirArray=array_merge($dirArray,explode(':',$sysDirs));
191
-		}
192
-		else
185
+		} else
193 186
 		{
194 187
 			$translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS');
195 188
 			if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches))
196 189
 			{
197 190
 				$dirArray=array_merge($dirArray,explode(':',$matches[1]));
198
-			}
199
-			else
191
+			} else
200 192
 			{
201 193
 				array_push($dirArray,'Install net-snmp-config to see system directories');
202 194
 			}
Please login to merge, or discard this patch.
library/Trapdirector/TrapsController.php 1 patch
Braces   +31 added lines, -12 removed lines patch added patch discarded remove patch
@@ -180,7 +180,9 @@  discard block
 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'),
@@ -201,7 +203,9 @@  discard block
 block discarded – undo
201 203
 	{
202 204
 		// 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
203 205
 	    $dbConn = $this->getUIDatabase()->getIdoDbConn();
204
-	    if ($dbConn === null) throw new \ErrorException('uncatched db error');
206
+	    if ($dbConn === null) {
207
+	    	throw new \ErrorException('uncatched db error');
208
+	    }
205 209
 	    
206 210
 		// TODO : check for SQL injections
207 211
 		$query=$dbConn->select()
@@ -224,7 +228,9 @@  discard block
 block discarded – undo
224 228
 	{
225 229
 		// 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
226 230
 	    $dbConn = $this->getUIDatabase()->getIdoDbConn();
227
-	    if ($dbConn === null) throw new \ErrorException('uncatched db error');
231
+	    if ($dbConn === null) {
232
+	    	throw new \ErrorException('uncatched db error');
233
+	    }
228 234
 	    
229 235
 	    // TODO : check for SQL injections
230 236
 		$query=$dbConn->select()
@@ -247,7 +253,9 @@  discard block
 block discarded – undo
247 253
 	{
248 254
 		// 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
249 255
 	    $dbConn = $this->getUIDatabase()->getIdoDbConn();
250
-	    if ($dbConn === null) throw new \ErrorException('uncatched db error');
256
+	    if ($dbConn === null) {
257
+	    	throw new \ErrorException('uncatched db error');
258
+	    }
251 259
 		// TODO : check for SQL injections
252 260
 		$query=$dbConn->select()
253 261
 				->from(
@@ -270,7 +278,9 @@  discard block
 block discarded – undo
270 278
 	{
271 279
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
272 280
 		$dbConn = $this->getUIDatabase()->getIdoDbConn();
273
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
281
+		if ($dbConn === null) {
282
+			throw new \ErrorException('uncatched db error');
283
+		}
274 284
 		$query=$dbConn->select()
275 285
 				->from(
276 286
 					array('a' => 'icinga_objects'),
@@ -292,7 +302,9 @@  discard block
 block discarded – undo
292 302
 	{
293 303
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
294 304
 		$dbConn = $this->getUIDatabase()->getIdoDbConn();
295
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
305
+		if ($dbConn === null) {
306
+			throw new \ErrorException('uncatched db error');
307
+		}
296 308
 		$query=$dbConn->select()
297 309
 				->from(
298 310
 					array('a' => 'icinga_objects'),
@@ -315,7 +327,9 @@  discard block
 block discarded – undo
315 327
 		// 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
316 328
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
317 329
 		$dbConn = $this->getUIDatabase()->getIdoDbConn();
318
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
330
+		if ($dbConn === null) {
331
+			throw new \ErrorException('uncatched db error');
332
+		}
319 333
 		$query=$dbConn->select()
320 334
 				->from(
321 335
 					array('s' => 'icinga_services'),
@@ -338,7 +352,9 @@  discard block
 block discarded – undo
338 352
 	{		
339 353
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
340 354
 		$dbConn = $this->getUIDatabase()->getIdoDbConn();
341
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
355
+		if ($dbConn === null) {
356
+			throw new \ErrorException('uncatched db error');
357
+		}
342 358
 		$query=$dbConn->select()
343 359
 				->from(
344 360
 					array('s' => 'icinga_hostgroup_members'),
@@ -359,8 +375,7 @@  discard block
 block discarded – undo
359 375
 				if (isset($common_services[$service->name2]['num']))
360 376
 				{
361 377
 					$common_services[$service->name2]['num'] +=1;
362
-				}
363
-				else
378
+				} else
364 379
 				{
365 380
 					$common_services[$service->name2]['num']=1;
366 381
 					$common_services[$service->name2]['name']=$service->name;
@@ -390,7 +405,9 @@  discard block
 block discarded – undo
390 405
 	protected function getServiceIDByName($hostname,$name) 
391 406
 	{
392 407
 	    $dbConn = $this->getUIDatabase()->getIdoDbConn();
393
-	    if ($dbConn === null) throw new \ErrorException('uncatched db error');
408
+	    if ($dbConn === null) {
409
+	    	throw new \ErrorException('uncatched db error');
410
+	    }
394 411
 	    
395 412
 		if ($name == null)
396 413
 		{
@@ -420,7 +437,9 @@  discard block
 block discarded – undo
420 437
 		// 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
421 438
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
422 439
 		$dbConn = $this->getUIDatabase()->getIdoDbConn();
423
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
440
+		if ($dbConn === null) {
441
+			throw new \ErrorException('uncatched db error');
442
+		}
424 443
 		
425 444
 		$query=$dbConn->select()
426 445
 				->from(
Please login to merge, or discard this patch.
library/Trapdirector/TrapsActions/TrapDBQuery.php 1 patch
Braces   +44 added lines, -14 removed lines patch added patch discarded remove patch
@@ -30,7 +30,9 @@  discard block
 block discarded – undo
30 30
         // TODO Check for rule consistency
31 31
         
32 32
         $dbConn = $this->getDbConn();
33
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
33
+        if ($dbConn === null) {
34
+        	throw new \ErrorException('uncatched db error');
35
+        }
34 36
         // Add last modified date = creation date and username
35 37
         $params['created'] = new Zend_Db_Expr('NOW()');
36 38
         $params['modified'] = new 	Zend_Db_Expr('NOW()');
@@ -56,7 +58,9 @@  discard block
 block discarded – undo
56 58
     {
57 59
         // TODO Check for rule consistency
58 60
         $dbConn = $this->getDbConn();
59
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
61
+        if ($dbConn === null) {
62
+        	throw new \ErrorException('uncatched db error');
63
+        }
60 64
         // Add last modified date = creation date and username
61 65
         $params['modified'] = new 	Zend_Db_Expr('NOW()');
62 66
         $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
@@ -77,7 +81,9 @@  discard block
 block discarded – undo
77 81
         if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
78 82
         
79 83
         $dbConn = $this->getDbConn();
80
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
84
+        if ($dbConn === null) {
85
+        	throw new \ErrorException('uncatched db error');
86
+        }
81 87
         
82 88
         $query=$dbConn->delete(
83 89
             $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
@@ -94,7 +100,9 @@  discard block
 block discarded – undo
94 100
     {
95 101
         
96 102
         $dbConn = $this->getDbConn();
97
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
103
+        if ($dbConn === null) {
104
+        	throw new \ErrorException('uncatched db error');
105
+        }
98 106
         $condition=null;
99 107
         if ($ip != null)
100 108
         {
@@ -105,7 +113,9 @@  discard block
 block discarded – undo
105 113
             $condition=($condition===null)?'':$condition.' AND ';
106 114
             $condition.="trap_oid='$oid'";
107 115
         }
108
-        if($condition === null) return null;
116
+        if($condition === null) {
117
+        	return null;
118
+        }
109 119
         $query=$dbConn->delete(
110 120
             $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
111 121
             $condition
@@ -123,7 +133,9 @@  discard block
 block discarded – undo
123 133
     {
124 134
         
125 135
         $dbConn = $this->getDbConn();
126
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
136
+        if ($dbConn === null) {
137
+        	throw new \ErrorException('uncatched db error');
138
+        }
127 139
         
128 140
         $condition=null;
129 141
         if ($ip != null)
@@ -135,7 +147,9 @@  discard block
 block discarded – undo
135 147
             $condition=($condition===null)?'':$condition.' AND ';
136 148
             $condition.="trap_oid='$oid'";
137 149
         }
138
-        if($condition === null) return 0;
150
+        if($condition === null) {
151
+        	return 0;
152
+        }
139 153
         $query=$dbConn->select()
140 154
         ->from(
141 155
             $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
@@ -152,7 +166,9 @@  discard block
 block discarded – undo
152 166
     {
153 167
         
154 168
         $dbConn = $this->getDbConn();
155
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
169
+        if ($dbConn === null) {
170
+        	throw new \ErrorException('uncatched db error');
171
+        }
156 172
         
157 173
         $query=$dbConn->select()
158 174
         ->from(
@@ -160,18 +176,28 @@  discard block
 block discarded – undo
160 176
             array('value'=>'value'))
161 177
             ->where('name=?',$element);
162 178
             $return_row=$dbConn->fetchRow($query);
163
-            if ($return_row==null)  // value does not exists
179
+            if ($return_row==null) {
180
+            	// value does not exists
164 181
             {
165 182
                 $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
166
-                if ( ! isset($default[$element])) return null; // no default and not value
183
+            }
184
+                if ( ! isset($default[$element])) {
185
+                	return null;
186
+                }
187
+                // no default and not value
167 188
                 
168 189
                 $this->addDBConfigValue($element,$default[$element]);
169 190
                 return $default[$element];
170 191
             }
171
-            if ($return_row->value == null) // value id empty
192
+            if ($return_row->value == null) {
193
+            	// value id empty
172 194
             {
173 195
                 $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
174
-                if ( ! isset($default[$element])) return null; // no default and not value
196
+            }
197
+                if ( ! isset($default[$element])) {
198
+                	return null;
199
+                }
200
+                // no default and not value
175 201
                 $this->setDBConfigValue($element,$default[$element]);
176 202
                 return $default[$element];
177 203
             }
@@ -187,7 +213,9 @@  discard block
 block discarded – undo
187 213
     {
188 214
         
189 215
         $dbConn = $this->getDbConn();
190
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
216
+        if ($dbConn === null) {
217
+        	throw new \ErrorException('uncatched db error');
218
+        }
191 219
         
192 220
         $query=$dbConn->insert(
193 221
             $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
@@ -207,7 +235,9 @@  discard block
 block discarded – undo
207 235
     {
208 236
         
209 237
         $dbConn = $this->getDbConn();
210
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
238
+        if ($dbConn === null) {
239
+        	throw new \ErrorException('uncatched db error');
240
+        }
211 241
         
212 242
         $query=$dbConn->update(
213 243
             $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
Please login to merge, or discard this patch.