Passed
Push — master ( 9f9a4d...75cf8d )
by Patrick
02:29
created
application/clicommands/StatusCommand.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,8 +40,7 @@
 block discarded – undo
40 40
 			$query = $dataBase->select()->from($Config->getTrapRuleName(),array('COUNT(*)'));			
41 41
 			printf("Number of rules : %s\n", $dataBase->fetchOne($query) );
42 42
 			
43
-		}
44
-		catch (Exception $e)
43
+		} catch (Exception $e)
45 44
 		{
46 45
 			printf('Error in DB : %s\n', $e->getMessage());
47 46
 		}	   
Please login to merge, or discard this patch.
application/clicommands/TrapsCommand.php 1 patch
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -42,14 +42,12 @@  discard block
 block discarded – undo
42 42
 			if ($days=='<default>')
43 43
 			{
44 44
 				$trap->eraseOldTraps();
45
-			}
46
-			else
45
+			} else
47 46
 			{
48 47
 				$trap->eraseOldTraps($days);
49 48
 			}
50 49
 			
51
-		}
52
-		catch (Exception $e)
50
+		} catch (Exception $e)
53 51
 		{
54 52
 			echo 'Error in updating : ' . $e->getMessage();
55 53
 		}	   
@@ -74,8 +72,7 @@  discard block
 block discarded – undo
74 72
 		try 
75 73
 		{
76 74
 			$trap->reset_services();
77
-		} 
78
-		catch (Exception $e) 
75
+		} catch (Exception $e) 
79 76
 		{
80 77
 			echo 'ERROR : '. $e->getMessage();
81 78
 		}
Please login to merge, or discard this patch.
application/clicommands/MibCommand.php 1 patch
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -62,8 +62,7 @@  discard block
 block discarded – undo
62 62
 		if ($pid == 1)
63 63
 		{
64 64
 		    $trap->setLogging($logLevel,'display');
65
-		}
66
-		else
65
+		} else
67 66
 		{  // use default display TODO : if default is 'display' son process will be killed at first output....
68 67
 		    if ($pid != 0)
69 68
 		    {
@@ -72,8 +71,7 @@  discard block
 block discarded – undo
72 71
 		        fclose($file);
73 72
 		        echo "OK : process $pid in bckground";
74 73
 		        return 0;
75
-		    }
76
-		    else
74
+		    } else
77 75
 		    {  // son process : close all file descriptors and go to a new session
78 76
 		        fclose($file);		        
79 77
 // 		        $sid = posix_setsid();
@@ -83,8 +81,7 @@  discard block
 block discarded – undo
83 81
                 try
84 82
                 {
85 83
                     $trap->update_mib_database(false,$forceCheck);
86
-                }
87
-                catch (Exception $e)
84
+                } catch (Exception $e)
88 85
                 {
89 86
                     $trap->trapLog('Error in updating : ' . $e->getMessage(),2);
90 87
                 }
@@ -101,8 +98,7 @@  discard block
 block discarded – undo
101 98
 			$trap->update_mib_database(true,$forceCheck);
102 99
 			echo "Done\n";
103 100
 			
104
-		}
105
-		catch (Exception $e)
101
+		} catch (Exception $e)
106 102
 		{
107 103
 			echo 'Error in updating : ' . $e->getMessage();
108 104
 		}
@@ -144,8 +140,7 @@  discard block
 block discarded – undo
144 140
 			$query = $db->select()->from($Config->getTrapRuleName(),array('COUNT(*)'));			
145 141
 			echo "Number of rules : " . $db->fetchOne($query) ."\n";		
146 142
 			
147
-		}
148
-		catch (Exception $e)
143
+		} catch (Exception $e)
149 144
 		{
150 145
 			echo 'Error in DB : ' . $e->getMessage();
151 146
 		}	   
Please login to merge, or discard this patch.
application/controllers/ReceivedController.php 1 patch
Braces   +7 added lines, -9 removed lines patch added patch discarded remove patch
@@ -76,9 +76,10 @@  discard block
 block discarded – undo
76 76
 				->from($this->moduleConfig->getTrapTableName(),$elmts)
77 77
 				->where('id=?',$trapid);
78 78
 			$trapDetail=$db->fetchRow($query);
79
-			if ( $trapDetail == null) throw new Exception('No traps was found with id = '.$trapid);
80
-		}
81
-		catch (Exception $e)
79
+			if ( $trapDetail == null) {
80
+				throw new Exception('No traps was found with id = '.$trapid);
81
+			}
82
+		} catch (Exception $e)
82 83
 		{
83 84
 			$this->displayExitError('Trap detail',$e->getMessage());
84 85
 		}
@@ -108,8 +109,7 @@  discard block
 block discarded – undo
108 109
 				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
109 110
 				->where('trap_id=?',$trapid);
110 111
 			$trapDetail=$db->fetchAll($query);
111
-		}
112
-		catch (Exception $e)
112
+		} catch (Exception $e)
113 113
 		{
114 114
 			$this->displayExitError('Trap detail',$e->getMessage());
115 115
 		}
@@ -117,8 +117,7 @@  discard block
 block discarded – undo
117 117
 		if ($trapDetail == null ) 
118 118
 		{
119 119
 			$this->view->data=false;
120
-		}
121
-		else
120
+		} else
122 121
 		{
123 122
 			$this->view->data=true;
124 123
 			// Store result in array.
@@ -204,8 +203,7 @@  discard block
 block discarded – undo
204 203
 			$ip=$postData['IP'];
205 204
 			$oid=$postData['OID'];
206 205
 			$action=$postData['action'];
207
-		}
208
-		else
206
+		} else
209 207
 		{
210 208
 			$this->_helper->json(array('status'=>'Missing variables'));
211 209
 		}
Please login to merge, or discard this patch.
application/controllers/SettingsController.php 1 patch
Braces   +18 added lines, -16 removed lines patch added patch discarded remove patch
@@ -28,11 +28,13 @@  discard block
 block discarded – undo
28 28
 	$this->checkReadPermission();
29 29
 	// Get message : sent on configuration problems detected by controllers
30 30
 	$dberrorMsg=$this->params->get('dberror');
31
-	if ($dberrorMsg != '')
32
-	    $this->view->errorDetected=$dberrorMsg;
31
+	if ($dberrorMsg != '') {
32
+		    $this->view->errorDetected=$dberrorMsg;
33
+	}
33 34
     $dberrorMsg=$this->params->get('idodberror');
34
-    if ($dberrorMsg != '')
35
-        $this->view->errorDetected=$dberrorMsg;
35
+    if ($dberrorMsg != '') {
36
+            $this->view->errorDetected=$dberrorMsg;
37
+    }
36 38
     
37 39
     $this->view->configErrorDetected == NULL; // Displayed error on various conifugration errors.
38 40
     
@@ -46,8 +48,7 @@  discard block
 block discarded – undo
46 48
             $this->Config()->saveIni();
47 49
             $this->view->configErrorDetected='Configuration is empty : you can run install script with parameters (see Automatic installation below)';
48 50
 			$emptyConfig=1;
49
-        }
50
-        catch (Exception $e)
51
+        } catch (Exception $e)
51 52
         {
52 53
             $this->view->configErrorDetected=$e->getMessage();
53 54
         }
@@ -106,8 +107,7 @@  discard block
 block discarded – undo
106 107
     	    $this->view->apimessage='API config : ' . $e->getMessage();
107 108
     	    $this->view->apimessageError=true;
108 109
     	} 
109
-	}
110
-	else
110
+	} else
111 111
 	{
112 112
 	    $this->view->apimessage='API parameters not configured';
113 113
 	    $this->view->apimessageError=true;
@@ -184,8 +184,7 @@  discard block
 block discarded – undo
184 184
 	if ($dberror[0] == 0)
185 185
 	{
186 186
 		printf('Schema already exists');
187
-	}
188
-	else
187
+	} else
189 188
 	{
190 189
 		printf('Creating schema : <br>');
191 190
 
@@ -308,12 +307,15 @@  discard block
 block discarded – undo
308 307
       }
309 308
       // Assume there is only one line... TODO : see if there is a better way to do this
310 309
       $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]);
311
-      if (!preg_match('/-n/',$line))
312
-          return array(1,'snmptrapd has no -n option : '.$line);
313
-      if (!preg_match('/-O[^ ]*n/',$line))
314
-          return array(1,'snmptrapd has no -On option : '.$line);
315
-      if (!preg_match('/-O[^ ]*e/',$line))
316
-          return array(1,'snmptrapd has no -Oe option : '.$line);
310
+      if (!preg_match('/-n/',$line)) {
311
+                return array(1,'snmptrapd has no -n option : '.$line);
312
+      }
313
+      if (!preg_match('/-O[^ ]*n/',$line)) {
314
+                return array(1,'snmptrapd has no -On option : '.$line);
315
+      }
316
+      if (!preg_match('/-O[^ ]*e/',$line)) {
317
+                return array(1,'snmptrapd has no -Oe option : '.$line);
318
+      }
317 319
       
318 320
       return array(0,'snmptrapd listening to UDP/162, options : '.$line);
319 321
   }
Please login to merge, or discard this patch.
application/controllers/HandlerController.php 1 patch
Braces   +35 added lines, -39 removed lines patch added patch discarded remove patch
@@ -51,8 +51,7 @@  discard block
 block discarded – undo
51 51
 	    if ($this->params->get('rule') !== null) 
52 52
 	    {
53 53
 	        $this->view->rule= $this->params->get('rule');
54
-	    }
55
-	    else
54
+	    } else
56 55
 	    {
57 56
 	        $this->view->rule='';
58 57
 	    }
@@ -113,8 +112,7 @@  discard block
 block discarded – undo
113 112
 			try
114 113
 			{
115 114
 				$hosts=$this->getHostByIP($hostfilter);
116
-			}
117
-			catch (Exception $e)
115
+			} catch (Exception $e)
118 116
 			{
119 117
 				$this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
120 118
 			}
@@ -127,8 +125,7 @@  discard block
 block discarded – undo
127 125
 				// Tell JS to get services when page is loaded
128 126
 				$this->view->serviceGet=true;
129 127
 				
130
-			}
131
-			else
128
+			} else
132 129
 			{
133 130
 				foreach($hosts as $key=>$val)
134 131
 				{
@@ -178,11 +175,14 @@  discard block
 block discarded – undo
178 175
 					$allObjects[$val->oid]=null;
179 176
 				}
180 177
 			}
181
-			if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
178
+			if ($allObjects!=null) {
179
+				// in case trap doesn't have objects or is not resolved
182 180
 			{
183 181
 				foreach ($allObjects as $key => $val)
184 182
 				{
185
-					if ($val==null) { continue; }
183
+					if ($val==null) { continue;
184
+			}
185
+			}
186 186
 					array_push($this->view->objectList, array(
187 187
 					    $oid_index,
188 188
 						$key,
@@ -231,8 +231,7 @@  discard block
 block discarded – undo
231 231
 			    {
232 232
 			        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
233 233
 			        $this->view->serviceGet=false;
234
-			    }
235
-			    else
234
+			    } else
236 235
 			    {
237 236
     				// Tell JS to get services when page is loaded
238 237
     				$this->view->serviceGet=true;
@@ -241,14 +240,12 @@  discard block
 block discarded – undo
241 240
     				if (count($serviceID) ==0)
242 241
     				{
243 242
     				    $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
244
-    				} 
245
-    				else
243
+    				} else
246 244
     				{
247 245
     				    $this->view->serviceSet=$serviceID[0]->id;
248 246
     				}
249 247
 			    }
250
-			}
251
-			else
248
+			} else
252 249
 			{
253 250
 			    $this->view->selectGroup=true;
254 251
 			    // Check if groupe exists
@@ -257,8 +254,7 @@  discard block
 block discarded – undo
257 254
 			    {
258 255
 			        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
259 256
 			        $this->view->serviceGroupGet=false;
260
-			    }
261
-			    else
257
+			    } else
262 258
 			    {
263 259
 			        $grpServices=$this->getServicesByHostGroupid($group_get[0]->id);
264 260
 			        $foundGrpService=0;
@@ -281,9 +277,11 @@  discard block
 block discarded – undo
281 277
 			}
282 278
 			$this->view->mainoid=$ruleDetail->trap_oid;
283 279
 			$oidName=$this->getMIB()->translateOID($ruleDetail->trap_oid);
284
-			if ($oidName != null)  // oid is found in mibs
280
+			if ($oidName != null) {
281
+				// oid is found in mibs
285 282
 			{
286
-				$this->view->mib=$oidName['mib']; 
283
+				$this->view->mib=$oidName['mib'];
284
+			}
287 285
 				$this->view->name=$oidName['name'];
288 286
 				$this->view->trapListForMIB=$this->getMIB()
289 287
 					->getTrapList($oidName['mib']);				
@@ -310,8 +308,7 @@  discard block
 block discarded – undo
310 308
 						$object['type'],
311 309
 						$object['type_enum']
312 310
 					));
313
-				}
314
-				else
311
+				} else
315 312
 				{
316 313
 					array_push($curObjectList, array(
317 314
 					    $index,
@@ -369,8 +366,7 @@  discard block
 block discarded – undo
369 366
 			try
370 367
 			{
371 368
 				$this->deleteRule($postData[$params['db_rule']['post']]);
372
-			}
373
-			catch (Exception $e)
369
+			} catch (Exception $e)
374 370
 			{
375 371
 				$this->_helper->json(array('status'=>$e->getMessage()));
376 372
 				return;
@@ -384,13 +380,15 @@  discard block
 block discarded – undo
384 380
 		}		
385 381
 		foreach (array_keys($params) as $key)
386 382
 		{
387
-			if ($params[$key]['post']==null) continue; // data not sent in post vars
383
+			if ($params[$key]['post']==null) {
384
+				continue;
385
+			}
386
+			// data not sent in post vars
388 387
 			if (! isset($postData[$params[$key]['post']]))
389 388
 			{
390 389
 				// should not happen as the js checks data
391 390
 				$this->_helper->json(array('status'=>'No ' . $key));
392
-			}
393
-			else
391
+			} else
394 392
 			{
395 393
 				$data=$postData[$params[$key]['post']];
396 394
 				if ($data!=null && $data !="")
@@ -420,8 +418,7 @@  discard block
 block discarded – undo
420 418
 					$this->_helper->json(array('status'=>"Invalid service id : Please re enter service"));
421 419
 					return;
422 420
 				}
423
-			}
424
-			else
421
+			} else
425 422
 			{
426 423
 				$object=$this->getObjectNameByid($params['hostid']['val']);
427 424
 				if ($params['host_name']['val'] != $object->name1)
@@ -445,14 +442,12 @@  discard block
 block discarded – undo
445 442
 			if ($params['db_rule']['val'] == -1 ) 
446 443
 			{
447 444
 				$ruleID=$this->addHandlerRule($dbparams);
448
-			}
449
-			else
445
+			} else
450 446
 			{
451 447
 				$this->updateHandlerRule($dbparams,$params['db_rule']['val']);
452 448
 				$ruleID=$params['db_rule']['val'];
453 449
 			}
454
-		}
455
-		catch (Exception $e)
450
+		} catch (Exception $e)
456 451
 		{
457 452
 			$this->_helper->json(array('status'=>$e->getMessage()));
458 453
 			return;
@@ -483,9 +478,10 @@  discard block
 block discarded – undo
483 478
 				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
484 479
 				->where('id=?',$trapid);
485 480
 			$trapDetail=$db->fetchRow($query);
486
-			if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
487
-		}
488
-		catch (Exception $e)
481
+			if ( $trapDetail == null ) {
482
+				throw new Exception('No traps was found with id = '.$trapid);
483
+			}
484
+		} catch (Exception $e)
489 485
 		{
490 486
 			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
491 487
 		}
@@ -517,8 +513,7 @@  discard block
 block discarded – undo
517 513
 				->where('trap_id=?',$trapid);
518 514
 			$trapDetail=$db->fetchAll($query);
519 515
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
520
-		}
521
-		catch (Exception $e)
516
+		} catch (Exception $e)
522 517
 		{
523 518
 			$this->displayExitError('Add handler : get trap data detail',$e->getMessage());
524 519
 		}
@@ -543,9 +538,10 @@  discard block
 block discarded – undo
543 538
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
544 539
 				->where('id=?',$ruleid);
545 540
 			$ruleDetail=$db->fetchRow($query);
546
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
547
-		}
548
-		catch (Exception $e)
541
+			if ( $ruleDetail == null ) {
542
+				throw new Exception('No rule was found with id = '.$ruleid);
543
+			}
544
+		} catch (Exception $e)
549 545
 		{
550 546
 			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
551 547
 		}
Please login to merge, or discard this patch.
application/controllers/StatusController.php 1 patch
Braces   +8 added lines, -16 removed lines patch added patch discarded remove patch
@@ -41,8 +41,7 @@  discard block
 block discarded – undo
41 41
  			
42 42
 			$this->view->trap_days_delete=$this->getDBConfigValue('db_remove_days');
43 43
 			
44
-		}
45
-		catch (Exception $e)
44
+		} catch (Exception $e)
46 45
 		{
47 46
 			$this->displayExitError('status',$e->getMessage());
48 47
 		}
@@ -56,8 +55,7 @@  discard block
 block discarded – undo
56 55
 			$this->view->currentLogFile=$this->getDBConfigValue('log_file');
57 56
 			$this->view->logLevels=$this->getModuleConfig()->getlogLevels();
58 57
 			$this->view->currentLogLevel=$this->getDBConfigValue('log_level');
59
-		}
60
-		catch (Exception $e)
58
+		} catch (Exception $e)
61 59
 		{
62 60
 			$this->displayExitError('status',$e->getMessage());
63 61
 		}		
@@ -106,8 +104,7 @@  discard block
 block discarded – undo
106 104
 					if ($retVal == 0)
107 105
 					{ // process is alive
108 106
 						$this->_helper->json(array('status'=>'Alive and kicking'));
109
-					}
110
-					else
107
+					} else
111 108
 					{ // process is dead
112 109
 					    $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid));
113 110
 					}
@@ -123,8 +120,7 @@  discard block
 block discarded – undo
123 120
 				if (move_uploaded_file($_FILES['mibfile']['tmp_name'],$destination)==false)
124 121
 				{
125 122
 					$this->view->uploadStatus='ERROR, file not loaded. Check mibs directory permission';
126
-				}
127
-				else
123
+				} else
128 124
 				{
129 125
 					$this->view->uploadStatus="File $name uploaded";
130 126
 				}
@@ -143,13 +139,11 @@  discard block
 block discarded – undo
143 139
 			{
144 140
 				$this->view->snmptranslate='works fine';
145 141
 				$this->view->snmptranslate_state='ok';
146
-			}
147
-			else
142
+			} else
148 143
 			{
149 144
 				$this->view->snmptranslate='can execute but no resolution';
150 145
 			}
151
-		}
152
-		else
146
+		} else
153 147
 		{
154 148
 			$this->view->snmptranslate='cannot execute';
155 149
 		}
@@ -171,15 +165,13 @@  discard block
 block discarded – undo
171 165
 		if ($retVal==0)
172 166
 		{
173 167
 			$dirArray=array_merge($dirArray,explode(':',$sysDirs));
174
-		}
175
-		else
168
+		} else
176 169
 		{
177 170
 			$translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS');
178 171
 			if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches))
179 172
 			{
180 173
 				$dirArray=array_merge($dirArray,explode(':',$matches[1]));
181
-			}
182
-			else
174
+			} else
183 175
 			{
184 176
 				array_push($dirArray,'Install net-snmp-config to see system directories');
185 177
 			}
Please login to merge, or discard this patch.
application/controllers/HelperController.php 1 patch
Braces   +26 added lines, -52 removed lines patch added patch discarded remove patch
@@ -20,8 +20,7 @@  discard block
 block discarded – undo
20 20
 		if (isset($postData['hostFilter']))
21 21
 		{
22 22
 			$hostFilter=$postData['hostFilter'];
23
-		}
24
-		else
23
+		} else
25 24
 		{
26 25
 			$this->_helper->json(array('status'=>'KO'));
27 26
 		}
@@ -47,8 +46,7 @@  discard block
 block discarded – undo
47 46
 		if (isset($postData['hostFilter']))
48 47
 		{
49 48
 			$hostFilter=$postData['hostFilter'];
50
-		}
51
-		else
49
+		} else
52 50
 		{
53 51
 			$this->_helper->json(array('status'=>'Error : no filter'));
54 52
 		}
@@ -77,8 +75,7 @@  discard block
 block discarded – undo
77 75
 		if (isset($postData['host']))
78 76
 		{
79 77
 			$host=$postData['host'];
80
-		}
81
-		else
78
+		} else
82 79
 		{
83 80
 			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1));
84 81
 		}
@@ -87,8 +84,7 @@  discard block
 block discarded – undo
87 84
 		if (count($hostArray) > 1)
88 85
 		{	
89 86
 			$this->_helper->json(array('status'=>'More than one host matches','hostid' => -1));
90
-		}
91
-		else if (count($hostArray) == 0)
87
+		} else if (count($hostArray) == 0)
92 88
 		{
93 89
 			$this->_helper->json(array('status'=>'No host matches','hostid' => -1));
94 90
 		}
@@ -117,8 +113,7 @@  discard block
 block discarded – undo
117 113
 		if (isset($postData['host']))
118 114
 		{
119 115
 			$host=$postData['host'];
120
-		}
121
-		else
116
+		} else
122 117
 		{
123 118
 			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1));
124 119
 		}
@@ -127,8 +122,7 @@  discard block
 block discarded – undo
127 122
 		if (count($hostArray) > 1)
128 123
 		{	
129 124
 			$this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1));
130
-		}
131
-		else if (count($hostArray) == 0)
125
+		} else if (count($hostArray) == 0)
132 126
 		{
133 127
 			$this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1));
134 128
 		}
@@ -153,8 +147,7 @@  discard block
 block discarded – undo
153 147
 		if (isset($postData['mib']))
154 148
 		{
155 149
 			$mib=$postData['mib'];
156
-		}
157
-		else
150
+		} else
158 151
 		{
159 152
 			$this->_helper->json(array('status'=>'No mib'));
160 153
 		}
@@ -162,8 +155,7 @@  discard block
 block discarded – undo
162 155
 		{
163 156
 			$traplist=$this->getMIB()->getTrapList($mib);
164 157
 			$retTraps=array('status'=>'OK','traps' => $traplist);
165
-		} 
166
-		catch (Exception $e) 
158
+		} catch (Exception $e) 
167 159
 		{ 
168 160
 			$retTraps=array('status' => 'Error getting mibs');
169 161
 		}
@@ -181,8 +173,7 @@  discard block
 block discarded – undo
181 173
 		if (isset($postData['trap']))
182 174
 		{
183 175
 			$trap=$postData['trap'];
184
-		}
185
-		else
176
+		} else
186 177
 		{
187 178
 			$this->_helper->json(array('status'=>'No trap'));
188 179
 		}
@@ -190,8 +181,7 @@  discard block
 block discarded – undo
190 181
 		{
191 182
 			$objectlist=$this->getMIB()->getObjectList($trap);
192 183
 			$retObjects=array('status'=>'OK','objects' => $objectlist);
193
-		} 
194
-		catch (Exception $e) 
184
+		} catch (Exception $e) 
195 185
 		{ 
196 186
 			$retObjects=array('status' => 'not found');
197 187
 		}
@@ -206,8 +196,7 @@  discard block
 block discarded – undo
206 196
 		try
207 197
 		{
208 198
 			$miblist=$this->getMIB()->getMIBList();
209
-		} 
210
-		catch (Exception $e) 
199
+		} catch (Exception $e) 
211 200
 		{ 
212 201
 			$miblist=array('Error getting mibs');
213 202
 		}
@@ -225,8 +214,7 @@  discard block
 block discarded – undo
225 214
 		if (isset($postData['oid']))
226 215
 		{
227 216
 			$oid=$postData['oid'];
228
-		}
229
-		else
217
+		} else
230 218
 		{
231 219
 			$this->_helper->json(array('status'=>'No oid'));
232 220
 		}
@@ -235,8 +223,7 @@  discard block
 block discarded – undo
235 223
 		if (($object=$this->getMIB()->translateOID($oid)) == null)
236 224
 		{
237 225
 			$this->_helper->json(array('status'=>'Not found'));
238
-		}
239
-		else
226
+		} else
240 227
 		{
241 228
 			$this->_helper->json(
242 229
 				array('status'=>'OK',
@@ -268,8 +255,7 @@  discard block
 block discarded – undo
268 255
 			{
269 256
 				$this->_helper->json(array('status'=>'invalid days : '.$days));
270 257
 			}
271
-		}
272
-		else
258
+		} else
273 259
 		{
274 260
 			$this->_helper->json(array('status'=>'No days'));
275 261
 		}
@@ -281,8 +267,7 @@  discard block
 block discarded – undo
281 267
 				$this->_helper->json(array('status'=>'unknown action '.$action));
282 268
 				return;
283 269
 			}
284
-		}
285
-		else
270
+		} else
286 271
 		{
287 272
 			$this->_helper->json(array('status'=>'No action'));
288 273
 			return;
@@ -292,8 +277,7 @@  discard block
 block discarded – undo
292 277
 			try
293 278
 			{
294 279
 				$this->setDBConfigValue('db_remove_days',$days);
295
-			}
296
-			catch (Exception $e)
280
+			} catch (Exception $e)
297 281
 			{
298 282
 				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
299 283
 				return;
@@ -311,8 +295,7 @@  discard block
 block discarded – undo
311 295
 				$Trap = new Trap($icingaweb2_etc);
312 296
 				$Trap->setLogging($debug_level,'syslog');
313 297
 				$Trap->eraseOldTraps($days);
314
-			}
315
-			catch (Exception $e)
298
+			} catch (Exception $e)
316 299
 			{
317 300
 				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage() ));
318 301
 				return;
@@ -339,8 +322,7 @@  discard block
 block discarded – undo
339 322
 			{
340 323
 				$this->_helper->json(array('status'=>'invalid destination : '.$destination));
341 324
 			}
342
-		}
343
-		else
325
+		} else
344 326
 		{
345 327
 			$this->_helper->json(array('status'=>'No destination'));
346 328
 		}
@@ -352,14 +334,12 @@  discard block
 block discarded – undo
352 334
 			{   // File os note writabe / cannot create
353 335
 			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
354 336
 			}
355
-		}
356
-		else
337
+		} else
357 338
 		{
358 339
 			if ($destination != 'file')
359 340
 			{
360 341
 				$file=null;
361
-			}
362
-			else
342
+			} else
363 343
 			{
364 344
 				$this->_helper->json(array('status'=>'No file'));
365 345
 			}
@@ -368,14 +348,12 @@  discard block
 block discarded – undo
368 348
 		if (isset($postData['level']))
369 349
 		{ 
370 350
 			$level=$postData['level'];
371
-		}
372
-		else
351
+		} else
373 352
 		{
374 353
 			if ($destination != 'level')
375 354
 			{
376 355
 				$level=null;
377
-			}
378
-			else
356
+			} else
379 357
 			{
380 358
 				$this->_helper->json(array('status'=>'No level'));
381 359
 			}
@@ -387,8 +365,7 @@  discard block
 block discarded – undo
387 365
 			$this->setDBConfigValue('log_destination',$destination);
388 366
 			$this->setDBConfigValue('log_file',$file);
389 367
 			$this->setDBConfigValue('log_level',$level);
390
-		}
391
-		catch (Exception $e)
368
+		} catch (Exception $e)
392 369
 		{
393 370
 			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
394 371
 			return;
@@ -410,8 +387,7 @@  discard block
 block discarded – undo
410 387
 	    if (isset($postData['rule']))
411 388
 	    {
412 389
 	        $rule=$postData['rule'];
413
-	    }
414
-	    else
390
+	    } else
415 391
 	    {
416 392
 	        $this->_helper->json(array('status'=>'No Rule'));
417 393
 	    }
@@ -423,8 +399,7 @@  discard block
 block discarded – undo
423 399
 	            $this->_helper->json(array('status'=>'unknown action '.$action));
424 400
 	            return;
425 401
 	        }
426
-	    }
427
-	    else
402
+	    } else
428 403
 	    {
429 404
 	        $this->_helper->json(array('status'=>'No action'));
430 405
 	        return;
@@ -441,8 +416,7 @@  discard block
 block discarded – undo
441 416
 	            // Eval
442 417
 	            $item=0;
443 418
 	            $rule=$Trap->evaluation($rule,$item);
444
-	        }
445
-	        catch (Exception $e)
419
+	        } catch (Exception $e)
446 420
 	        {
447 421
 	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
448 422
 	            return;
Please login to merge, or discard this patch.
library/Trapdirector/TrapsController.php 1 patch
Braces   +62 added lines, -30 removed lines patch added patch discarded remove patch
@@ -82,10 +82,11 @@  discard block
 block discarded – undo
82 82
 		try 
83 83
 		{
84 84
 			$dbconn = IcingaDbConnection::fromResourceName($DBname);
85
-		} 
86
-		catch (Exception $e)
85
+		} catch (Exception $e)
87 86
 		{
88
-			if ($test) return array(2,$DBname);
87
+			if ($test) {
88
+				return array(2,$DBname);
89
+			}
89 90
 			$this->redirectNow('trapdirector/settings?dberror=2');
90 91
 			return null;
91 92
 		}
@@ -93,10 +94,11 @@  discard block
 block discarded – undo
93 94
 			try 
94 95
 			{
95 96
 				$db=$dbconn->getConnection();
96
-			}
97
-			catch (Exception $e) 
97
+			} catch (Exception $e) 
98 98
 			{
99
-				if ($test) return array(3,$DBname,$e->getMessage());
99
+				if ($test) {
100
+					return array(3,$DBname,$e->getMessage());
101
+				}
100 102
 				$this->redirectNow('trapdirector/settings?dberror=3');
101 103
 				return null;
102 104
 			}
@@ -108,55 +110,72 @@  discard block
 block discarded – undo
108 110
 				$version=$db->fetchRow($query);
109 111
 				if ( ($version == null) || ! property_exists($version,'value') )
110 112
 				{
111
-					if ($test) return array(4,$DBname);
113
+					if ($test) {
114
+						return array(4,$DBname);
115
+					}
112 116
 					$this->redirectNow('trapdirector/settings?dberror=4');
113 117
 					return null;
114 118
 				}
115 119
 				if ($version->value < $this->getModuleConfig()->getDbMinVersion()) 
116 120
 				{
117
-					if ($test) return array(5,$version->value,$this->getModuleConfig()->getDbMinVersion());
121
+					if ($test) {
122
+						return array(5,$version->value,$this->getModuleConfig()->getDbMinVersion());
123
+					}
118 124
 					$this->redirectNow('trapdirector/settings?dberror=5');
119 125
 					return null;
120 126
 				}
121
-			}
122
-			catch (Exception $e) 
127
+			} catch (Exception $e) 
123 128
 			{
124
-				if ($test) return array(3,$DBname,$e->getMessage());
129
+				if ($test) {
130
+					return array(3,$DBname,$e->getMessage());
131
+				}
125 132
 				$this->redirectNow('trapdirector/settings?dberror=4');
126 133
 				return null;
127 134
 			}
128 135
 		}
129
-		if ($test) return array(0,'');
136
+		if ($test) {
137
+			return array(0,'');
138
+		}
130 139
 		return $dbconn;
131 140
 	}
132 141
 
133 142
 	public function getDb($test=false)
134 143
 	{
135
-		if ($this->trapDB != null && $test = false) return $this->trapDB;
144
+		if ($this->trapDB != null && $test = false) {
145
+			return $this->trapDB;
146
+		}
136 147
 		
137 148
 		$dbresource=$this->Config()->get('config', 'database');
138 149
 		
139 150
 		if ( ! $dbresource )
140 151
 		{	
141
-			if ($test) return array(1,'');
152
+			if ($test) {
153
+				return array(1,'');
154
+			}
142 155
 			$this->redirectNow('trapdirector/settings?dberror=1');
143 156
 			return null;
144 157
 		}
145 158
 		$retDB=$this->getDbByName($dbresource,$test,true);
146
-		if ($test == true) return $retDB;
159
+		if ($test == true) {
160
+			return $retDB;
161
+		}
147 162
 		$this->trapDB=$retDB;
148 163
 		return $this->trapDB;
149 164
 	}
150 165
 	
151 166
 	public function getIdoDb($test=false)
152 167
 	{
153
-		if ($this->icingaDB != null && $test = false) return $this->icingaDB;
168
+		if ($this->icingaDB != null && $test = false) {
169
+			return $this->icingaDB;
170
+		}
154 171
 		// TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
155 172
 		$dbresource=$this->Config()->get('config', 'IDOdatabase');;
156 173
 
157 174
 		if ( ! $dbresource )
158 175
 		{
159
-		    if ($test) return array(1,'No database in config.ini');
176
+		    if ($test) {
177
+		    	return array(1,'No database in config.ini');
178
+		    }
160 179
 		    $this->redirectNow('trapdirector/settings?idodberror=1');
161 180
 		    return null;
162 181
 		}
@@ -164,10 +183,11 @@  discard block
 block discarded – undo
164 183
 		try
165 184
 		{
166 185
 		    $dbconn = IcingaDbConnection::fromResourceName($dbresource);
167
-		}
168
-		catch (Exception $e)
186
+		} catch (Exception $e)
169 187
 		{
170
-		    if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2");
188
+		    if ($test) {
189
+		    	return array(2,"Database $dbresource does not exists in IcingaWeb2");
190
+		    }
171 191
 		    $this->redirectNow('trapdirector/settings?idodberror=2');
172 192
 		    return null;
173 193
 		}
@@ -183,8 +203,7 @@  discard block
 block discarded – undo
183 203
 		    {
184 204
 		        return array(4,"$dbresource does not look like an IDO database");
185 205
 		    }
186
-		}
187
-		catch (Exception $e)
206
+		} catch (Exception $e)
188 207
 		{
189 208
 		    return array(3,"Error connecting to $dbresource : " . $e->getMessage());
190 209
 		    $this->redirectNow('trapdirector/settings?dberror=4');
@@ -437,8 +456,7 @@  discard block
 block discarded – undo
437 456
 				if (isset($common_services[$service->name2]['num']))
438 457
 				{
439 458
 					$common_services[$service->name2]['num'] +=1;
440
-				}
441
-				else
459
+				} else
442 460
 				{
443 461
 					$common_services[$service->name2]['num']=1;
444 462
 					$common_services[$service->name2]['name']=$service->name;
@@ -579,7 +597,9 @@  discard block
 block discarded – undo
579 597
 			$condition=($condition==null)?'':$condition.' AND ';
580 598
 			$condition.="trap_oid='$oid'";
581 599
 		}
582
-		if($condition ==null) return null;
600
+		if($condition ==null) {
601
+			return null;
602
+		}
583 603
 		$query=$db->delete(
584 604
 			$this->getModuleConfig()->getTrapTableName(),
585 605
 			$condition
@@ -607,7 +627,9 @@  discard block
 block discarded – undo
607 627
 			$condition=($condition==null)?'':$condition.' AND ';
608 628
 			$condition.="trap_oid='$oid'";
609 629
 		}
610
-		if($condition ==null) return 0;
630
+		if($condition ==null) {
631
+			return 0;
632
+		}
611 633
 		$query=$db->select()
612 634
 			->from(
613 635
 				$this->getModuleConfig()->getTrapTableName(),
@@ -631,18 +653,28 @@  discard block
 block discarded – undo
631 653
 				array('value'=>'value'))
632 654
 			->where('name=?',$element);
633 655
 		$return_row=$db->fetchRow($query);
634
-		if ($return_row==null)  // value does not exists
656
+		if ($return_row==null) {
657
+			// value does not exists
635 658
 		{
636 659
 			$default=$this->getModuleConfig()->getDBConfigDefaults();
637
-			if ( ! isset($default[$element])) return null; // no default and not value
660
+		}
661
+			if ( ! isset($default[$element])) {
662
+				return null;
663
+			}
664
+			// no default and not value
638 665
 			
639 666
 			$this->addDBConfigValue($element,$default[$element]);
640 667
 			return $default[$element];
641 668
 		}
642
-		if ($return_row->value == null) // value id empty
669
+		if ($return_row->value == null) {
670
+			// value id empty
643 671
 		{
644 672
 			$default=$this->getModuleConfig()->getDBConfigDefaults();
645
-			if ( ! isset($default[$element])) return null; // no default and not value
673
+		}
674
+			if ( ! isset($default[$element])) {
675
+				return null;
676
+			}
677
+			// no default and not value
646 678
 			$this->setDBConfigValue($element,$default[$element]);
647 679
 			return $default[$element];			
648 680
 		}
Please login to merge, or discard this patch.