Passed
Pull Request — master (#78)
by
unknown
03:51
created
application/controllers/StatusController.php 1 patch
Braces   +19 added lines, -29 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
 		}
@@ -69,8 +69,7 @@  discard block
 block discarded – undo
69 69
 		    $this->view->SnmpTrapAddressOID=$this->getUIDatabase()->getDBConfigValue('SnmpTrapAddess_oid');
70 70
 		    $this->view->SnmpTrapAddressOIDDefault = ($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid'] ) ? TRUE : FALSE;
71 71
 		    
72
-		}
73
-		catch (Exception $e)
72
+		} catch (Exception $e)
74 73
 		{
75 74
 		    $this->displayExitError('status',$e->getMessage());
76 75
 		}		
@@ -120,8 +119,7 @@  discard block
 block discarded – undo
120 119
 					if ($retVal == 0)
121 120
 					{ // process is alive
122 121
 						$this->_helper->json(array('status'=>'Alive and kicking'));
123
-					}
124
-					else
122
+					} else
125 123
 					{ // process is dead
126 124
 					    $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid));
127 125
 					}
@@ -137,22 +135,19 @@  discard block
 block discarded – undo
137 135
 				if (!is_dir($destDir))
138 136
 				{
139 137
 				    $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration";
140
-				}
141
-				else
138
+				} else
142 139
 				{
143 140
 				    if (!is_writable($destDir))
144 141
 				    {
145 142
 				        $this->view->uploadStatus="ERROR : $destDir directory is not writable";
146
-				    }
147
-				    else
143
+				    } else
148 144
 				    {
149 145
 				        $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name";
150 146
 				        $sourceTmpNam=htmlspecialchars($_FILES['mibfile']['tmp_name']);
151 147
 				        if (move_uploaded_file($sourceTmpNam,$destination)===false)
152 148
     				    {
153 149
     				        $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations";
154
-    				    }
155
-    				    else
150
+    				    } else
156 151
     				    {
157 152
     				        $this->view->uploadStatus="File $name uploaded in $destDir";
158 153
     				    }
@@ -177,18 +172,15 @@  discard block
 block discarded – undo
177 172
 			    {		    
178 173
     				$this->view->snmptranslate='works fine';
179 174
     				$this->view->snmptranslate_state='ok';
180
-			    }
181
-			    else
175
+			    } else
182 176
 			    {
183 177
 			        $this->view->snmptranslate='works fine but missing basic MIBs';
184 178
 			    }
185
-			}
186
-			else
179
+			} else
187 180
 			{
188 181
 				$this->view->snmptranslate='Can execute but no OID to name resolution';
189 182
 			}
190
-		}
191
-		else
183
+		} else
192 184
 		{
193 185
 			$this->view->snmptranslate='Cannot execute';
194 186
 		}
@@ -209,15 +201,13 @@  discard block
 block discarded – undo
209 201
 		if ($retVal==0)
210 202
 		{
211 203
 			$dirArray=array_merge($dirArray,explode(':',$sysDirs));
212
-		}
213
-		else
204
+		} else
214 205
 		{
215 206
 			$translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS');
216 207
 			if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches))
217 208
 			{
218 209
 				$dirArray=array_merge($dirArray,explode(':',$matches[1]));
219
-			}
220
-			else
210
+			} else
221 211
 			{
222 212
 				array_push($dirArray,'Install net-snmp-config to see system directories');
223 213
 			}
@@ -256,8 +246,7 @@  discard block
 block discarded – undo
256 246
 	        if (!preg_match('/^[0-9]+$/', $maxRows) || $maxRows < 1)
257 247
 	        {
258 248
 	            $this->view->setError='Max rows must be a number';
259
-	        }
260
-	        else
249
+	        } else
261 250
 	        {
262 251
 	            $this->setitemListDisplay($maxRows);
263 252
 	            $this->view->setOKMsg='Set max rows to ' . $maxRows;
@@ -276,8 +265,9 @@  discard block
 block discarded – undo
276 265
 	        $index = $this->getRequest()->getPost('index',NULL);
277 266
 	        $newname = $this->getRequest()->getPost('newname',NULL);
278 267
 
279
-	        if (!preg_match('/^[0-9]+$/', $index) || $index < 1)
280
-	            $this->_helper->json(array('status'=>'Bad index'));
268
+	        if (!preg_match('/^[0-9]+$/', $index) || $index < 1) {
269
+	        	            $this->_helper->json(array('status'=>'Bad index'));
270
+	        }
281 271
 	        
282 272
 	        switch ($type)
283 273
 	        {
Please login to merge, or discard this patch.
library/Trapdirector/TrapsActions/UIDatabase.php 1 patch
Braces   +18 added lines, -16 removed lines patch added patch discarded remove patch
@@ -126,8 +126,7 @@  discard block
 block discarded – undo
126 126
                 $this->trapController->redirectNow('trapdirector/settings?dberror=5');
127 127
                 return false;
128 128
             }
129
-        }
130
-        catch (Exception $e)
129
+        } catch (Exception $e)
131 130
         {
132 131
             if ($test === true) 
133 132
             {
@@ -152,8 +151,7 @@  discard block
 block discarded – undo
152 151
         try
153 152
         {
154 153
             $dbconn = IcingaDbConnection::fromResourceName($DBname);
155
-        }
156
-        catch (Exception $e)
154
+        } catch (Exception $e)
157 155
         {
158 156
             if ($test === true) 
159 157
             {
@@ -167,8 +165,7 @@  discard block
 block discarded – undo
167 165
         {
168 166
             $dbAdapter=$dbconn->getDbAdapter();
169 167
             
170
-        }
171
-        catch (Exception $e)
168
+        } catch (Exception $e)
172 169
         {
173 170
             if ($test === true)
174 171
             {
@@ -195,7 +192,9 @@  discard block
 block discarded – undo
195 192
      */
196 193
     public function getDb()
197 194
     {
198
-        if ( $this->trapDB != null ) return $this->trapDB;
195
+        if ( $this->trapDB != null ) {
196
+        	return $this->trapDB;
197
+        }
199 198
         
200 199
         
201 200
         $dbresource=$this->trapController->Config()->get('config', 'database');
@@ -223,7 +222,9 @@  discard block
 block discarded – undo
223 222
      */
224 223
     public function getDbConn()
225 224
     {
226
-        if ($this->getDb() == null) return null;
225
+        if ($this->getDb() == null) {
226
+        	return null;
227
+        }
227 228
         return $this->getDb()->getDbAdapter();
228 229
 //        return $this->getDb()->getConnection();
229 230
     }
@@ -254,7 +255,9 @@  discard block
 block discarded – undo
254 255
      */
255 256
     public function getIdoDb()
256 257
     {
257
-        if ( $this->idoDB != null ) return $this->idoDB;
258
+        if ( $this->idoDB != null ) {
259
+        	return $this->idoDB;
260
+        }
258 261
         // TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
259 262
         $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');;
260 263
         
@@ -267,8 +270,7 @@  discard block
 block discarded – undo
267 270
         try
268 271
         {
269 272
             $dbconn = IcingaDbConnection::fromResourceName($dbresource);
270
-        }
271
-        catch (Exception $e)
273
+        } catch (Exception $e)
272 274
         {
273 275
             $this->trapController->redirectNow('trapdirector/settings?idodberror=2');
274 276
             return null;
@@ -285,7 +287,9 @@  discard block
 block discarded – undo
285 287
      */
286 288
     public function getIdoDbConn()
287 289
     {
288
-        if ($this->getIdoDb() == null) return null;
290
+        if ($this->getIdoDb() == null) {
291
+        	return null;
292
+        }
289 293
         return $this->getIdoDb()->getConnection();
290 294
     }
291 295
     
@@ -307,8 +311,7 @@  discard block
 block discarded – undo
307 311
         try
308 312
         {
309 313
             $dbconn = IcingaDbConnection::fromResourceName($dbresource);
310
-        }
311
-        catch (Exception $e)
314
+        } catch (Exception $e)
312 315
         {
313 316
             throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") );
314 317
         }
@@ -322,8 +325,7 @@  discard block
 block discarded – undo
322 325
             {
323 326
                 throw new DBException( array(4,"$dbresource does not look like an IDO database"));
324 327
             }
325
-        }
326
-        catch (Exception $e)
328
+        } catch (Exception $e)
327 329
         {
328 330
             throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage()));
329 331
         }
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/TrapConfig.php 1 patch
Braces   +15 added lines, -8 removed lines patch added patch discarded remove patch
@@ -46,8 +46,7 @@  discard block
 block discarded – undo
46 46
             }
47 47
             $this->getLogging()->log($message,$log_level);
48 48
             return false;
49
-        }
50
-        else
49
+        } else
51 50
         {
52 51
             $option_var=$option_array[$option_category][$option_name];
53 52
             return true;
@@ -60,16 +59,20 @@  discard block
 block discarded – undo
60 59
     protected function getDatabaseOptions()
61 60
     {
62 61
         // Database options
63
-        if ($this->logSetup === false) // Only if logging was no setup in constructor
62
+        if ($this->logSetup === false) {
63
+        	// Only if logging was no setup in constructor
64 64
         {
65 65
             $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel);
66
+        }
66 67
             $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode);
67 68
             $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile);
68 69
         }
69 70
         
70 71
         $tmpVal = -1; // Get boolean coded in database as 1/0
71 72
         $this->getDBConfigIfSet('use_SnmpTrapAddess', $tmpVal);
72
-        if ($tmpVal != -1) $this->useSnmpTrapAddess = ($tmpVal == 1) ? TRUE : FALSE;
73
+        if ($tmpVal != -1) {
74
+        	$this->useSnmpTrapAddess = ($tmpVal == 1) ? TRUE : FALSE;
75
+        }
73 76
         
74 77
         $this->getDBConfigIfSet('SnmpTrapAddess_oid', $this->snmpTrapAddressOID); // Get oid then replace '.' with '\.' to use in regexp whrn reading traps
75 78
         $this->snmpTrapAddressOID = preg_replace('/\./', '\\.', $this->snmpTrapAddressOID);
@@ -82,7 +85,9 @@  discard block
 block discarded – undo
82 85
     protected function getDBConfigIfSet($element,&$variable)
83 86
     {
84 87
         $value=$this->getDBConfig($element);
85
-        if ($value != null) $variable=$value;
88
+        if ($value != null) {
89
+        	$variable=$value;
90
+        }
86 91
     }
87 92
     
88 93
     /**
@@ -119,8 +124,7 @@  discard block
 block discarded – undo
119 124
         {
120 125
             $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN);
121 126
             $this->getTrapApi()->setStatusMaster();
122
-        }
123
-        else 
127
+        } else 
124 128
         {
125 129
             if ($this->getTrapApi()->getStatus() != TrapApi::MASTER)
126 130
             {
@@ -189,7 +193,10 @@  discard block
 block discarded – undo
189 193
         $this->logging->log("API Use : ".print_r($this->apiUse,true),DEBUG );
190 194
         
191 195
         //TODO enable this again when API queries are all done :
192
-        if ($this->apiUse === true) return; // In case of API use, no IDO is necessary
196
+        if ($this->apiUse === true) {
197
+        	return;
198
+        }
199
+        // In case of API use, no IDO is necessary
193 200
         
194 201
         // IDO Database
195 202
         if (!array_key_exists('IDOdatabase',$trapConfig['config']))
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/Trap.php 1 patch
Braces   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -98,8 +98,7 @@  discard block
 block discarded – undo
98 98
         {
99 99
             $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile);
100 100
             $this->logSetup=true;
101
-        }
102
-        else
101
+        } else
103 102
         {
104 103
             $this->logSetup=false;
105 104
         }
@@ -129,7 +128,10 @@  discard block
 block discarded – undo
129 128
         $this->getDatabaseOptions(); // Get options in database
130 129
         
131 130
         // Setup API
132
-        if ($this->apiUse === true) $this->getAPI(); // Setup API
131
+        if ($this->apiUse === true) {
132
+        	$this->getAPI();
133
+        }
134
+        // Setup API
133 135
         
134 136
         // Setup MIB
135 137
         $this->mibClass = new Mib($this->logging,$this->trapsDB,$this->snmptranslate,$this->snmptranslate_dirs); // Create Mib class
@@ -238,8 +240,7 @@  discard block
 block discarded – undo
238 240
         {
239 241
             $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
240 242
             $this->logging->log('Error parsing IP : '.$IP,ERROR,'');
241
-        }
242
-        else
243
+        } else
243 244
         {
244 245
             $this->trapData['source_ip']=$matches[1];
245 246
             $this->trapData['destination_ip']=$matches[3];
@@ -322,10 +323,10 @@  discard block
 block discarded – undo
322 323
         $this->logging->log('SQL query : '.$sql,DEBUG );
323 324
         if (($ret_code=$db_conn->query($sql)) === false) {
324 325
             $this->logging->log('No result in query : ' . $sql,ERROR,'');
325
-        }
326
-        else {
327
-            if (($name=$ret_code->fetch()) !== false)
328
-                return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
326
+        } else {
327
+            if (($name=$ret_code->fetch()) !== false) {
328
+                            return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
329
+            }
329 330
         }
330 331
         
331 332
         // Also check if it is an instance of OID
@@ -335,10 +336,10 @@  discard block
 block discarded – undo
335 336
         $this->logging->log('SQL query : '.$sql,DEBUG );
336 337
         if (($ret_code=$db_conn->query($sql)) === false) {
337 338
             $this->logging->log('No result in query : ' . $sql,ERROR,'');
338
-        }
339
-        else {
340
-            if (($name=$ret_code->fetch()) !== false)
341
-                return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
339
+        } else {
340
+            if (($name=$ret_code->fetch()) !== false) {
341
+                            return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
342
+            }
342 343
         }
343 344
         
344 345
         // Try to get oid name from snmptranslate
@@ -437,7 +438,9 @@  discard block
 block discarded – undo
437 438
                 }
438 439
                 
439 440
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
440
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
441
+                if ($inserted_id==false) {
442
+                	throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
443
+                }
441 444
                 $this->trapId=$inserted_id;
442 445
                 break;
443 446
             default:
@@ -453,7 +456,9 @@  discard block
 block discarded – undo
453 456
     {
454 457
         
455 458
         // If action is ignore -> don't send t DB
456
-        if ($this->trapToDb === false) return;
459
+        if ($this->trapToDb === false) {
460
+        	return;
461
+        }
457 462
         
458 463
         
459 464
         $db_conn=$this->trapsDB->db_connect_trap();
@@ -510,7 +515,9 @@  discard block
 block discarded – undo
510 515
                 }
511 516
                 
512 517
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
513
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
518
+                if ($inserted_id==false) {
519
+                	throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
520
+                }
514 521
                 $this->trapId=$inserted_id;
515 522
                 break;
516 523
             default:
@@ -591,7 +598,7 @@  discard block
 block discarded – undo
591 598
                         continue;
592 599
                     }
593 600
                     $grouphosts=$ret_code2->fetchAll();
594
-                }else{
601
+                } else{
595 602
                     $api = $this->getAPI();
596 603
                     $api->setCredentials($this->apiUsername, $this->apiPassword);
597 604
                     $grouphosts=$api->getHostsIPByHostGroup($rule['host_group_name']);
@@ -599,7 +606,9 @@  discard block
 block discarded – undo
599 606
                 //echo "rule grp :\n";print_r($grouphosts);echo "\n";
600 607
                 foreach ( $grouphosts as $host)
601 608
                 {
602
-                    if( is_object( $host ) ) $host=(array)$host;
609
+                    if( is_object( $host ) ) {
610
+                    	$host=(array)$host;
611
+                    }
603 612
                     //echo $host['address']."\n";
604 613
                     if ($host['address']==$ip || $host['address6']==$ip)
605 614
                     {
@@ -648,8 +657,7 @@  discard block
 block discarded – undo
648 657
                 // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
649 658
                 exec('echo "'.$send.'" > ' .$this->icinga2cmd);
650 659
                 return true;
651
-        }
652
-        else
660
+        } else
653 661
         {
654 662
             // Get perfdata if found
655 663
             $matches=array();
@@ -657,8 +665,7 @@  discard block
 block discarded – undo
657 665
             {
658 666
                 $display=$matches[1];
659 667
                 $perfdata=$matches[2];
660
-            }
661
-            else
668
+            } else
662 669
             {
663 670
                 $perfdata='';
664 671
             }
@@ -670,8 +677,7 @@  discard block
 block discarded – undo
670 677
             {
671 678
                 $this->logging->log( "Error sending result : " .$retmessage,WARN,'');
672 679
                 return false;
673
-            }
674
-            else
680
+            } else
675 681
             {
676 682
                 $this->logging->log( "Sent result : " .$retmessage,INFO );
677 683
                 return true;
@@ -770,20 +776,17 @@  discard block
 block discarded – undo
770 776
                         if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
771 777
                         {
772 778
                             $this->trapAction.='Error sending status : check cmd/API';
773
-                        }
774
-                        else
779
+                        } else
775 780
                         {
776 781
                             $this->add_rule_match($rule['id'],$rule['num_match']+1);
777 782
                             $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name;
778 783
                         }
779
-                    }
780
-                    else
784
+                    } else
781 785
                     {
782 786
                         $this->add_rule_match($rule['id'],$rule['num_match']+1);
783 787
                     }
784 788
                     $this->trapToDb=($action==-2)?false:true;
785
-                }
786
-                else
789
+                } else
787 790
                 {
788 791
                     //$this->logging->log('rules KOO : '.print_r($rule),INFO );
789 792
                     
@@ -794,14 +797,12 @@  discard block
 block discarded – undo
794 797
                         if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
795 798
                         {
796 799
                             $this->trapAction.='Error sending status : check cmd/API';
797
-                        }
798
-                        else
800
+                        } else
799 801
                         {
800 802
                             $this->add_rule_match($rule['id'],$rule['num_match']+1);
801 803
                             $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name;
802 804
                         }
803
-                    }
804
-                    else
805
+                    } else
805 806
                     {
806 807
                         $this->add_rule_match($rule['id'],$rule['num_match']+1);
807 808
                     }
@@ -811,16 +812,14 @@  discard block
 block discarded – undo
811 812
                 if (!isset($this->trapData['source_name']))
812 813
                 {
813 814
                     $this->trapData['source_name']=$rule['host_name'];
814
-                }
815
-                else
815
+                } else
816 816
                 {
817 817
                     if (!preg_match('/'.$rule['host_name'].'/',$this->trapData['source_name']))
818 818
                     { // only add if not present
819 819
                         $this->trapData['source_name'].=','.$rule['host_name'];
820 820
                     }
821 821
                 }
822
-            }
823
-            catch (Exception $e)
822
+            } catch (Exception $e)
824 823
             {
825 824
                 $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
826 825
                 $this->trapAction.=' ERR : '.$e->getMessage();
@@ -831,8 +830,7 @@  discard block
 block discarded – undo
831 830
         if ($this->trapData['status']=='error')
832 831
         {
833 832
             $this->trapToDb=true; // Always put errors in DB for the use can see
834
-        }
835
-        else
833
+        } else
836 834
         {
837 835
             $this->trapData['status']='done';
838 836
         }
@@ -879,7 +877,7 @@  discard block
 block discarded – undo
879 877
                 return 0;
880 878
             }
881 879
             $services=$services_db->fetchAll();
882
-        }else{
880
+        } else{
883 881
             $api = $this->getAPI();
884 882
             $api->setCredentials($this->apiUsername, $this->apiPassword);
885 883
             $services=$api->getNOKservice();
@@ -899,7 +897,9 @@  discard block
 block discarded – undo
899 897
         $numreset=0;
900 898
         foreach ($rules as $rule)
901 899
         {
902
-            if( is_object( $services ) ) $services=(array)$services;
900
+            if( is_object( $services ) ) {
901
+            	$services=(array)$services;
902
+            }
903 903
             foreach ($services as $service)
904 904
             {
905 905
                 if ($service['name'] == $rule['service_name'] &&
Please login to merge, or discard this patch.