Passed
Push — master ( 101619...42d7f2 )
by Patrick
01:57
created
library/Trapdirector/TrapsController.php 3 patches
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
 	protected $trapClass;		//< Trap class for bin/trap_class.php
33 33
 		
34 34
 	/** Get instance of TrapModuleConfig class
35
-	*	@return TrapModuleConfig
36
-	*/
35
+	 *	@return TrapModuleConfig
36
+	 */
37 37
 	public function getModuleConfig() 
38 38
 	{
39 39
 		if ($this->moduleConfig == Null) 
@@ -58,12 +58,12 @@  discard block
 block discarded – undo
58 58
 	
59 59
 	public function getTrapHostListTable()
60 60
 	{
61
-	    if ($this->trapTableHostList == Null) 
61
+		if ($this->trapTableHostList == Null) 
62 62
 		{
63
-	        $this->trapTableHostList = new TrapTableHostList();
64
-	        $this->trapTableHostList->setConfig($this->getModuleConfig());
65
-	    }
66
-	    return $this->trapTableHostList;
63
+			$this->trapTableHostList = new TrapTableHostList();
64
+			$this->trapTableHostList->setConfig($this->getModuleConfig());
65
+		}
66
+		return $this->trapTableHostList;
67 67
 	}
68 68
 	
69 69
 	public function getHandlerListTable() 
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
 	}	
78 78
 	
79 79
 	/**	Get Database connexion
80
-	*	@param $DBname string DB name in resource.ini_ge
81
-	*	@param $test bool if set to true, returns error code and not database
82
-	*	@param $test_version bool if set to flase, does not test database version of trapDB
83
-	*	@return array<integer,mixed>|mixed : if test=false, returns DB connexion, else array(error_num,message) or null on error.
84
-	*/
80
+	 *	@param $DBname string DB name in resource.ini_ge
81
+	 *	@param $test bool if set to true, returns error code and not database
82
+	 *	@param $test_version bool if set to flase, does not test database version of trapDB
83
+	 *	@return array<integer,mixed>|mixed : if test=false, returns DB connexion, else array(error_num,message) or null on error.
84
+	 */
85 85
 	public function getDbByName($DBname,$test=false,$test_version=true)
86 86
 	{
87 87
 		try 
@@ -161,20 +161,20 @@  discard block
 block discarded – undo
161 161
 
162 162
 		if ( ! $dbresource )
163 163
 		{
164
-		    if ($test) return array(1,'No database in config.ini');
165
-		    $this->redirectNow('trapdirector/settings?idodberror=1');
166
-		    return null;
164
+			if ($test) return array(1,'No database in config.ini');
165
+			$this->redirectNow('trapdirector/settings?idodberror=1');
166
+			return null;
167 167
 		}
168 168
 		
169 169
 		try
170 170
 		{
171
-		    $dbconn = IcingaDbConnection::fromResourceName($dbresource);
171
+			$dbconn = IcingaDbConnection::fromResourceName($dbresource);
172 172
 		}
173 173
 		catch (Exception $e)
174 174
 		{
175
-		    if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2");
176
-		    $this->redirectNow('trapdirector/settings?idodberror=2');
177
-		    return null;
175
+			if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2");
176
+			$this->redirectNow('trapdirector/settings?idodberror=2');
177
+			return null;
178 178
 		}
179 179
 		
180 180
 		if ($test == false) 
@@ -185,13 +185,13 @@  discard block
 block discarded – undo
185 185
 		
186 186
 		try
187 187
 		{
188
-		    $query = $dbconn->select()
189
-		    ->from('icinga_dbversion',array('version'));
190
-		    $version=$dbconn->fetchRow($query);
191
-		    if ( ($version == null) || ! property_exists($version,'version') )
192
-		    {
193
-		        return array(4,"$dbresource does not look like an IDO database");
194
-		    }
188
+			$query = $dbconn->select()
189
+			->from('icinga_dbversion',array('version'));
190
+			$version=$dbconn->fetchRow($query);
191
+			if ( ($version == null) || ! property_exists($version,'version') )
192
+			{
193
+				return array(4,"$dbresource does not look like an IDO database");
194
+			}
195 195
 		}
196 196
 		catch (Exception $e)
197 197
 		{
@@ -201,15 +201,15 @@  discard block
 block discarded – undo
201 201
 		return array(0,'');
202 202
 	}
203 203
 	
204
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
205
-    {
206
-        $limit = $this->params->get('limit', $limit);
207
-        $page = $this->params->get('page', $offset);
204
+	protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
205
+	{
206
+		$limit = $this->params->get('limit', $limit);
207
+		$page = $this->params->get('page', $offset);
208 208
 
209
-        $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
209
+		$paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
210 210
 
211
-        return $paginatable;
212
-    }	
211
+		return $paginatable;
212
+	}	
213 213
 	
214 214
 	public function displayExitError($source,$message)
215 215
 	{	// TODO : check better ways to transmit data (with POST ?)
@@ -218,33 +218,33 @@  discard block
 block discarded – undo
218 218
 	
219 219
 	protected function checkReadPermission()
220 220
 	{
221
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
222
-            $this->displayExitError('Permissions','No permission fo view content');
223
-        }		
221
+		if (! $this->Auth()->hasPermission('trapdirector/view')) {
222
+			$this->displayExitError('Permissions','No permission fo view content');
223
+		}		
224 224
 	}
225 225
 
226 226
 	protected function checkConfigPermission()
227 227
 	{
228
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
229
-            $this->displayExitError('Permissions','No permission fo configure');
230
-        }		
228
+		if (! $this->Auth()->hasPermission('trapdirector/config')) {
229
+			$this->displayExitError('Permissions','No permission fo configure');
230
+		}		
231 231
 	}
232 232
 	
233
-    /**
234
-     * Check if user has write permission
235
-     * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page
236
-     * @return boolean : user has permission
237
-     */
233
+	/**
234
+	 * Check if user has write permission
235
+	 * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page
236
+	 * @return boolean : user has permission
237
+	 */
238 238
 	protected function checkModuleConfigPermission($check=0)
239 239
 	{
240
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
241
-            if ($check == 0)
242
-            {
243
-                $this->displayExitError('Permissions','No permission fo configure module');
244
-            }
245
-            return false;
246
-        }
247
-        return true;
240
+		if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
241
+			if ($check == 0)
242
+			{
243
+				$this->displayExitError('Permissions','No permission fo configure module');
244
+			}
245
+			return false;
246
+		}
247
+		return true;
248 248
 	}
249 249
 
250 250
 	/*************************  Trap class get **********************/
@@ -264,8 +264,8 @@  discard block
 block discarded – undo
264 264
 	/************************** MIB related **************************/
265 265
 	
266 266
 	/** Get MIBLoader class
267
-	*	@return MIBLoader class
268
-	*/
267
+	 *	@return MIBLoader class
268
+	 */
269 269
 	protected function getMIB()
270 270
 	{
271 271
 		if ($this->MIBData == null)
@@ -283,9 +283,9 @@  discard block
 block discarded – undo
283 283
 	/**************************  Database queries *******************/
284 284
 	
285 285
 	/** Get host(s) by IP (v4 or v6) or by name in IDO database
286
-	*	does not catch exceptions
287
-	*	@return array of objects ( name, id (object_id), display_name)
288
-	*/
286
+	 *	does not catch exceptions
287
+	 *	@return array of objects ( name, id (object_id), display_name)
288
+	 */
289 289
 	protected function getHostByIP($ip) 
290 290
 	{
291 291
 		// 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
@@ -304,9 +304,9 @@  discard block
 block discarded – undo
304 304
 	}
305 305
 
306 306
 	/** Get host(s) by name in IDO database
307
-	*	does not catch exceptions
308
-	*	@return array of objects ( name, id (object_id), display_name)
309
-	*/
307
+	 *	does not catch exceptions
308
+	 *	@return array of objects ( name, id (object_id), display_name)
309
+	 */
310 310
 	protected function getHostByName($name) 
311 311
 	{
312 312
 		// 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
@@ -325,9 +325,9 @@  discard block
 block discarded – undo
325 325
 	}	
326 326
 	
327 327
 	/** Get host groups by  name in IDO database
328
-	*	does not catch exceptions
329
-	*	@return array of objects ( name, id (object_id), display_name)
330
-	*/
328
+	 *	does not catch exceptions
329
+	 *	@return array of objects ( name, id (object_id), display_name)
330
+	 */
331 331
 	protected function getHostGroupByName($ip) 
332 332
 	{
333 333
 		// 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
@@ -347,9 +347,9 @@  discard block
 block discarded – undo
347 347
 
348 348
 	
349 349
 	/** Get host IP (v4 and v6) by name in IDO database
350
-	*	does not catch exceptions
351
-	*	@return array ( name, display_name, ip4, ip6)
352
-	*/
350
+	 *	does not catch exceptions
351
+	 *	@return array ( name, display_name, ip4, ip6)
352
+	 */
353 353
 	protected function getHostInfoByID($id) 
354 354
 	{
355 355
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
@@ -368,9 +368,9 @@  discard block
 block discarded – undo
368 368
 
369 369
 	
370 370
 	/** Get host by objectid  in IDO database
371
-	*	does not catch exceptions
372
-	*	@return array of objects ( id, name, display_name, ip, ip6,  )
373
-	*/
371
+	 *	does not catch exceptions
372
+	 *	@return array of objects ( id, name, display_name, ip, ip6,  )
373
+	 */
374 374
 	protected function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above
375 375
 	{
376 376
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
@@ -388,10 +388,10 @@  discard block
 block discarded – undo
388 388
 	}	
389 389
 	
390 390
 	/** Get services from object ( host_object_id) in IDO database
391
-	*	does not catch exceptions
392
-	*	@param $id	int object_id
393
-	*	@return array display_name (of service), service_object_id
394
-	*/
391
+	 *	does not catch exceptions
392
+	 *	@param $id	int object_id
393
+	 *	@return array display_name (of service), service_object_id
394
+	 */
395 395
 	protected function getServicesByHostid($id) 
396 396
 	{
397 397
 		// 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
@@ -411,11 +411,11 @@  discard block
 block discarded – undo
411 411
 	}	
412 412
 	
413 413
 	/** Get services from hostgroup object id ( hostgroup_object_id) in IDO database
414
-	* 	gets all hosts in hostgroup and return common services
415
-	*	does not catch exceptions
416
-	*	@param $id	int object_id
417
-	*	@return array display_name (of service), service_object_id
418
-	*/
414
+	 * 	gets all hosts in hostgroup and return common services
415
+	 *	does not catch exceptions
416
+	 *	@param $id	int object_id
417
+	 *	@return array display_name (of service), service_object_id
418
+	 */
419 419
 	protected function getServicesByHostGroupid($id) 
420 420
 	{		
421 421
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 		//print_r($common_services);
455 455
 		foreach (array_keys($common_services) as $key)
456 456
 		{
457
-		    if ($common_services[$key]['num'] == $num_hosts)
457
+			if ($common_services[$key]['num'] == $num_hosts)
458 458
 			{
459 459
 				array_push($result,array($key,$common_services[$key]['name']));
460 460
 			}
@@ -464,11 +464,11 @@  discard block
 block discarded – undo
464 464
 	}	
465 465
 
466 466
 	/** Get services object id by host name / service name in IDO database
467
-	*	does not catch exceptions
468
-	*	@param $hostname string host name
469
-	*	@param $name string service name
470
-	*	@return int  service id
471
-	*/
467
+	 *	does not catch exceptions
468
+	 *	@param $hostname string host name
469
+	 *	@param $name string service name
470
+	 *	@return int  service id
471
+	 */
472 472
 	protected function getServiceIDByName($hostname,$name) 
473 473
 	{
474 474
 		$db = $this->getIdoDb()->getConnection();
@@ -491,10 +491,10 @@  discard block
 block discarded – undo
491 491
 	}
492 492
 	
493 493
 	/** Get object name from object_id  in IDO database
494
-	*	does not catch exceptions
495
-	*	@param int $id object_id (default to null, used first if not null)
496
-	*	@return array name1 (host) name2 (service)
497
-	*/
494
+	 *	does not catch exceptions
495
+	 *	@param int $id object_id (default to null, used first if not null)
496
+	 *	@return array name1 (host) name2 (service)
497
+	 */
498 498
 	protected function getObjectNameByid($id) 
499 499
 	{
500 500
 		// 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
@@ -510,9 +510,9 @@  discard block
 block discarded – undo
510 510
 	}		
511 511
 
512 512
 	/** Add handler rule in traps DB
513
-	*	@param array(<db item>=><value>)
514
-	*	@return int inserted id
515
-	*/
513
+	 *	@param array(<db item>=><value>)
514
+	 *	@return int inserted id
515
+	 */
516 516
 	protected function addHandlerRule($params)
517 517
 	{
518 518
 		// TODO Check for rule consistency
@@ -534,9 +534,9 @@  discard block
 block discarded – undo
534 534
 	}	
535 535
 
536 536
 	/** Update handler rule in traps DB
537
-	*	@param array(<db item>=><value>)
538
-	*	@return array affected rows
539
-	*/
537
+	 *	@param array(<db item>=><value>)
538
+	 *	@return array affected rows
539
+	 */
540 540
 	protected function updateHandlerRule($params,$ruleID)
541 541
 	{
542 542
 		// TODO Check for rule consistency
@@ -554,8 +554,8 @@  discard block
 block discarded – undo
554 554
 	}	
555 555
 	
556 556
 	/** Delete rule by id
557
-	*	@param int $ruleID rule id
558
-	*/
557
+	 *	@param int $ruleID rule id
558
+	 */
559 559
 	protected function deleteRule($ruleID)
560 560
 	{
561 561
 		if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
@@ -569,9 +569,9 @@  discard block
 block discarded – undo
569 569
 	}
570 570
 
571 571
 	/** Delete trap by ip & oid
572
-	*	@param $ip string source IP (v4 or v6)
573
-	*	@param $oid string oid
574
-	*/
572
+	 *	@param $ip string source IP (v4 or v6)
573
+	 *	@param $oid string oid
574
+	 */
575 575
 	protected function deleteTrap($ip,$oid)
576 576
 	{
577 577
 		
@@ -597,9 +597,9 @@  discard block
 block discarded – undo
597 597
    
598 598
 
599 599
 	/** count trap by ip & oid
600
-	*	@param $ip string source IP (v4 or v6)
601
-	*	@param $oid string oid
602
-	*/
600
+	 *	@param $ip string source IP (v4 or v6)
601
+	 *	@param $oid string oid
602
+	 */
603 603
 	protected function countTrap($ip,$oid)
604 604
 	{
605 605
 		
@@ -625,8 +625,8 @@  discard block
 block discarded – undo
625 625
 	}		
626 626
 	
627 627
 	/** get configuration value
628
-	*	@param configuration name in db
629
-	*/
628
+	 *	@param configuration name in db
629
+	 */
630 630
 	protected function getDBConfigValue($element)
631 631
 	{
632 632
 	
@@ -657,8 +657,8 @@  discard block
 block discarded – undo
657 657
 	}
658 658
 
659 659
 	/** add configuration value
660
-	*	@param name value
661
-	*/
660
+	 *	@param name value
661
+	 */
662 662
 	protected function addDBConfigValue($element,$value)
663 663
 	{
664 664
 	
@@ -675,8 +675,8 @@  discard block
 block discarded – undo
675 675
 	}
676 676
 
677 677
 	/** set configuration value
678
-	*	@param name value
679
-	*/
678
+	 *	@param name value
679
+	 */
680 680
 	protected function setDBConfigValue($element,$value)
681 681
 	{
682 682
 	
@@ -690,13 +690,13 @@  discard block
 block discarded – undo
690 690
 	}
691 691
 	
692 692
 	/** Check if director is installed
693
-	*	@return bool true/false
694
-	*/
693
+	 *	@return bool true/false
694
+	 */
695 695
 	protected function isDirectorInstalled()
696 696
 	{
697
-	    $output=array();
698
-	    exec('icingacli module list',$output);
699
-	    foreach ($output as $line)
697
+		$output=array();
698
+		exec('icingacli module list',$output);
699
+		foreach ($output as $line)
700 700
 		{
701 701
 			if (preg_match('/^director .*enabled/',$line))
702 702
 			{
Please login to merge, or discard this patch.
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -22,14 +22,14 @@  discard block
 block discarded – undo
22 22
 
23 23
 class TrapsController extends Controller
24 24
 {
25
-	protected $moduleConfig;  	//< TrapModuleConfig instance
26
-	protected $trapTableList; 	//< TrapTableList (by date)
27
-	protected $trapTableHostList; 	//< TrapTableList (by hosts)
28
-	protected $handlerTableList; 	//< HandlerTableList instance
29
-	protected $trapDB;			//< Trap database
30
-	protected $icingaDB;		//< Icinga IDO database;
31
-	protected $MIBData; 		//< MIBLoader class
32
-	protected $trapClass;		//< Trap class for bin/trap_class.php
25
+	protected $moduleConfig; //< TrapModuleConfig instance
26
+	protected $trapTableList; //< TrapTableList (by date)
27
+	protected $trapTableHostList; //< TrapTableList (by hosts)
28
+	protected $handlerTableList; //< HandlerTableList instance
29
+	protected $trapDB; //< Trap database
30
+	protected $icingaDB; //< Icinga IDO database;
31
+	protected $MIBData; //< MIBLoader class
32
+	protected $trapClass; //< Trap class for bin/trap_class.php
33 33
 		
34 34
 	/** Get instance of TrapModuleConfig class
35 35
 	*	@return TrapModuleConfig
@@ -43,14 +43,14 @@  discard block
 block discarded – undo
43 43
 			{
44 44
 				$this->redirectNow('trapdirector/settings?message=No database prefix');
45 45
 			}
46
-			$this->moduleConfig = new TrapModuleConfig($db_prefix);
46
+			$this->moduleConfig=new TrapModuleConfig($db_prefix);
47 47
 		}
48 48
 		return $this->moduleConfig;
49 49
 	}
50 50
 	
51 51
 	public function getTrapListTable() {
52 52
 		if ($this->trapTableList == Null) {
53
-			$this->trapTableList = new TrapTableList();
53
+			$this->trapTableList=new TrapTableList();
54 54
 			$this->trapTableList->setConfig($this->getModuleConfig());
55 55
 		}
56 56
 		return $this->trapTableList;
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	{
61 61
 	    if ($this->trapTableHostList == Null) 
62 62
 		{
63
-	        $this->trapTableHostList = new TrapTableHostList();
63
+	        $this->trapTableHostList=new TrapTableHostList();
64 64
 	        $this->trapTableHostList->setConfig($this->getModuleConfig());
65 65
 	    }
66 66
 	    return $this->trapTableHostList;
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	{
71 71
 		if ($this->handlerTableList == Null) 
72 72
 		{
73
-			$this->handlerTableList = new HandlerTableList();
73
+			$this->handlerTableList=new HandlerTableList();
74 74
 			$this->handlerTableList->setConfig($this->getModuleConfig());
75 75
 		}
76 76
 		return $this->handlerTableList;
@@ -82,15 +82,15 @@  discard block
 block discarded – undo
82 82
 	*	@param $test_version bool if set to flase, does not test database version of trapDB
83 83
 	*	@return array<integer,mixed>|mixed : if test=false, returns DB connexion, else array(error_num,message) or null on error.
84 84
 	*/
85
-	public function getDbByName($DBname,$test=false,$test_version=true)
85
+	public function getDbByName($DBname, $test=false, $test_version=true)
86 86
 	{
87 87
 		try 
88 88
 		{
89
-			$dbconn = IcingaDbConnection::fromResourceName($DBname);
89
+			$dbconn=IcingaDbConnection::fromResourceName($DBname);
90 90
 		} 
91 91
 		catch (Exception $e)
92 92
 		{
93
-			if ($test) return array(2,$DBname);
93
+			if ($test) return array(2, $DBname);
94 94
 			$this->redirectNow('trapdirector/settings?dberror=2');
95 95
 			return null;
96 96
 		}
@@ -101,53 +101,53 @@  discard block
 block discarded – undo
101 101
 			}
102 102
 			catch (Exception $e) 
103 103
 			{
104
-				if ($test) return array(3,$DBname,$e->getMessage());
104
+				if ($test) return array(3, $DBname, $e->getMessage());
105 105
 				$this->redirectNow('trapdirector/settings?dberror=3');
106 106
 				return null;
107 107
 			}
108 108
 			try
109 109
 			{
110
-				$query = $db->select()
111
-					->from($this->getModuleConfig()->getDbConfigTableName(),'value')
110
+				$query=$db->select()
111
+					->from($this->getModuleConfig()->getDbConfigTableName(), 'value')
112 112
 					->where('name=\'db_version\'');
113 113
 				$version=$db->fetchRow($query);
114
-				if ( ($version == null) || ! property_exists($version,'value') )
114
+				if (($version == null) || !property_exists($version, 'value'))
115 115
 				{
116
-					if ($test) return array(4,$DBname);
116
+					if ($test) return array(4, $DBname);
117 117
 					$this->redirectNow('trapdirector/settings?dberror=4');
118 118
 					return null;
119 119
 				}
120 120
 				if ($version->value < $this->getModuleConfig()->getDbMinVersion()) 
121 121
 				{
122
-					if ($test) return array(5,$version->value,$this->getModuleConfig()->getDbMinVersion());
122
+					if ($test) return array(5, $version->value, $this->getModuleConfig()->getDbMinVersion());
123 123
 					$this->redirectNow('trapdirector/settings?dberror=5');
124 124
 					return null;
125 125
 				}
126 126
 			}
127 127
 			catch (Exception $e) 
128 128
 			{
129
-				if ($test) return array(3,$DBname,$e->getMessage());
129
+				if ($test) return array(3, $DBname, $e->getMessage());
130 130
 				$this->redirectNow('trapdirector/settings?dberror=4');
131 131
 				return null;
132 132
 			}
133 133
 		}
134
-		if ($test) return array(0,'');
134
+		if ($test) return array(0, '');
135 135
 		return $dbconn;
136 136
 	}
137 137
 
138 138
 	public function getDb($test=false)
139 139
 	{
140
-		if ($this->trapDB != null && $test = false) return $this->trapDB;
140
+		if ($this->trapDB != null && $test=false) return $this->trapDB;
141 141
 		
142 142
 		$dbresource=$this->Config()->get('config', 'database');
143 143
 		
144
-		if ( ! $dbresource )
144
+		if (!$dbresource)
145 145
 		{	
146
-			if ($test) return array(1,'');
146
+			if ($test) return array(1, '');
147 147
 			$this->redirectNow('trapdirector/settings?dberror=1');
148 148
 			return null;
149 149
 		}
150
-		$retDB=$this->getDbByName($dbresource,$test,true);
150
+		$retDB=$this->getDbByName($dbresource, $test, true);
151 151
 		if ($test == true) return $retDB;
152 152
 		$this->trapDB=$retDB;
153 153
 		return $this->trapDB;
@@ -155,78 +155,78 @@  discard block
 block discarded – undo
155 155
 	
156 156
 	public function getIdoDb($test=false)
157 157
 	{
158
-		if ($this->icingaDB != null && $test = false) return $this->icingaDB;
158
+		if ($this->icingaDB != null && $test=false) return $this->icingaDB;
159 159
 		// TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
160
-		$dbresource=$this->Config()->get('config', 'IDOdatabase');;
160
+		$dbresource=$this->Config()->get('config', 'IDOdatabase'); ;
161 161
 
162
-		if ( ! $dbresource )
162
+		if (!$dbresource)
163 163
 		{
164
-		    if ($test) return array(1,'No database in config.ini');
164
+		    if ($test) return array(1, 'No database in config.ini');
165 165
 		    $this->redirectNow('trapdirector/settings?idodberror=1');
166 166
 		    return null;
167 167
 		}
168 168
 		
169 169
 		try
170 170
 		{
171
-		    $dbconn = IcingaDbConnection::fromResourceName($dbresource);
171
+		    $dbconn=IcingaDbConnection::fromResourceName($dbresource);
172 172
 		}
173 173
 		catch (Exception $e)
174 174
 		{
175
-		    if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2");
175
+		    if ($test) return array(2, "Database $dbresource does not exists in IcingaWeb2");
176 176
 		    $this->redirectNow('trapdirector/settings?idodberror=2');
177 177
 		    return null;
178 178
 		}
179 179
 		
180 180
 		if ($test == false) 
181 181
 		{ 
182
-			$this->icingaDB = $dbconn; 
182
+			$this->icingaDB=$dbconn; 
183 183
 			return $this->icingaDB;
184 184
 		}
185 185
 		
186 186
 		try
187 187
 		{
188
-		    $query = $dbconn->select()
189
-		    ->from('icinga_dbversion',array('version'));
188
+		    $query=$dbconn->select()
189
+		    ->from('icinga_dbversion', array('version'));
190 190
 		    $version=$dbconn->fetchRow($query);
191
-		    if ( ($version == null) || ! property_exists($version,'version') )
191
+		    if (($version == null) || !property_exists($version, 'version'))
192 192
 		    {
193
-		        return array(4,"$dbresource does not look like an IDO database");
193
+		        return array(4, "$dbresource does not look like an IDO database");
194 194
 		    }
195 195
 		}
196 196
 		catch (Exception $e)
197 197
 		{
198
-			return array(3,"Error connecting to $dbresource : " . $e->getMessage());
198
+			return array(3, "Error connecting to $dbresource : ".$e->getMessage());
199 199
 		}
200 200
 		
201
-		return array(0,'');
201
+		return array(0, '');
202 202
 	}
203 203
 	
204
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
204
+    protected function applyPaginationLimits(Paginatable $paginatable, $limit=25, $offset=null)
205 205
     {
206
-        $limit = $this->params->get('limit', $limit);
207
-        $page = $this->params->get('page', $offset);
206
+        $limit=$this->params->get('limit', $limit);
207
+        $page=$this->params->get('page', $offset);
208 208
 
209 209
         $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
210 210
 
211 211
         return $paginatable;
212 212
     }	
213 213
 	
214
-	public function displayExitError($source,$message)
214
+	public function displayExitError($source, $message)
215 215
 	{	// TODO : check better ways to transmit data (with POST ?)
216 216
 		$this->redirectNow('trapdirector/error?source='.$source.'&message='.$message);
217 217
 	}
218 218
 	
219 219
 	protected function checkReadPermission()
220 220
 	{
221
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
222
-            $this->displayExitError('Permissions','No permission fo view content');
221
+        if (!$this->Auth()->hasPermission('trapdirector/view')) {
222
+            $this->displayExitError('Permissions', 'No permission fo view content');
223 223
         }		
224 224
 	}
225 225
 
226 226
 	protected function checkConfigPermission()
227 227
 	{
228
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
229
-            $this->displayExitError('Permissions','No permission fo configure');
228
+        if (!$this->Auth()->hasPermission('trapdirector/config')) {
229
+            $this->displayExitError('Permissions', 'No permission fo configure');
230 230
         }		
231 231
 	}
232 232
 	
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
      */
238 238
 	protected function checkModuleConfigPermission($check=0)
239 239
 	{
240
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
240
+        if (!$this->Auth()->hasPermission('trapdirector/module_config')) {
241 241
             if ($check == 0)
242 242
             {
243
-                $this->displayExitError('Permissions','No permission fo configure module');
243
+                $this->displayExitError('Permissions', 'No permission fo configure module');
244 244
             }
245 245
             return false;
246 246
         }
@@ -252,10 +252,10 @@  discard block
 block discarded – undo
252 252
 	{ // TODO : try/catch here ? or within caller
253 253
 		if ($this->trapClass == null)
254 254
 		{
255
-			require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
255
+			require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
256 256
 			$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
257 257
 			//$debug_level=4;
258
-			$this->trapClass = new Trap($icingaweb2_etc);
258
+			$this->trapClass=new Trap($icingaweb2_etc);
259 259
 			//$Trap->setLogging($debug_level,'syslog');
260 260
 		}
261 261
 		return $this->trapClass;
@@ -289,12 +289,12 @@  discard block
 block discarded – undo
289 289
 	protected function getHostByIP($ip) 
290 290
 	{
291 291
 		// 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
292
-		$db = $this->getIdoDb()->getConnection();
292
+		$db=$this->getIdoDb()->getConnection();
293 293
 		// TODO : check for SQL injections
294 294
 		$query=$db->select()
295 295
 				->from(
296 296
 					array('a' => 'icinga_objects'),
297
-					array('name' => 'a.name1','id' => 'object_id'))
297
+					array('name' => 'a.name1', 'id' => 'object_id'))
298 298
 				->join(
299 299
 					array('b' => 'icinga_hosts'),
300 300
 					'b.host_object_id=a.object_id',
@@ -310,12 +310,12 @@  discard block
 block discarded – undo
310 310
 	protected function getHostByName($name) 
311 311
 	{
312 312
 		// 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
313
-		$db = $this->getIdoDb()->getConnection();
313
+		$db=$this->getIdoDb()->getConnection();
314 314
 		// TODO : check for SQL injections
315 315
 		$query=$db->select()
316 316
 				->from(
317 317
 					array('a' => 'icinga_objects'),
318
-					array('name' => 'a.name1','id' => 'object_id'))
318
+					array('name' => 'a.name1', 'id' => 'object_id'))
319 319
 				->join(
320 320
 					array('b' => 'icinga_hosts'),
321 321
 					'b.host_object_id=a.object_id',
@@ -331,12 +331,12 @@  discard block
 block discarded – undo
331 331
 	protected function getHostGroupByName($ip) 
332 332
 	{
333 333
 		// 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
334
-		$db = $this->getIdoDb()->getConnection();
334
+		$db=$this->getIdoDb()->getConnection();
335 335
 		// TODO : check for SQL injections
336 336
 		$query=$db->select()
337 337
 				->from(
338 338
 					array('a' => 'icinga_objects'),
339
-					array('name' => 'a.name1','id' => 'object_id'))
339
+					array('name' => 'a.name1', 'id' => 'object_id'))
340 340
 				->join(
341 341
 					array('b' => 'icinga_hostgroups'),
342 342
 					'b.hostgroup_object_id=a.object_id',
@@ -352,8 +352,8 @@  discard block
 block discarded – undo
352 352
 	*/
353 353
 	protected function getHostInfoByID($id) 
354 354
 	{
355
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
356
-		$db = $this->getIdoDb()->getConnection();
355
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
356
+		$db=$this->getIdoDb()->getConnection();
357 357
 		$query=$db->select()
358 358
 				->from(
359 359
 					array('a' => 'icinga_objects'),
@@ -373,17 +373,17 @@  discard block
 block discarded – undo
373 373
 	*/
374 374
 	protected function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above
375 375
 	{
376
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
377
-		$db = $this->getIdoDb()->getConnection();
376
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
377
+		$db=$this->getIdoDb()->getConnection();
378 378
 		$query=$db->select()
379 379
 				->from(
380 380
 					array('a' => 'icinga_objects'),
381
-					array('name' => 'a.name1','id' => 'a.object_id'))
381
+					array('name' => 'a.name1', 'id' => 'a.object_id'))
382 382
 				->join(
383 383
 					array('b' => 'icinga_hosts'),
384 384
 					'b.host_object_id=a.object_id',
385
-					array('display_name' => 'b.display_name' , 'ip' => 'b.address', 'ip6' => 'b.address6'))
386
-				->where('a.object_id = ?',$id);
385
+					array('display_name' => 'b.display_name', 'ip' => 'b.address', 'ip6' => 'b.address6'))
386
+				->where('a.object_id = ?', $id);
387 387
 		return $db->fetchRow($query);
388 388
 	}	
389 389
 	
@@ -395,16 +395,16 @@  discard block
 block discarded – undo
395 395
 	protected function getServicesByHostid($id) 
396 396
 	{
397 397
 		// 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
398
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
399
-		$db = $this->getIdoDb()->getConnection();
398
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
399
+		$db=$this->getIdoDb()->getConnection();
400 400
 		$query=$db->select()
401 401
 				->from(
402 402
 					array('s' => 'icinga_services'),
403
-					array('name' => 's.display_name','id' => 's.service_object_id'))
403
+					array('name' => 's.display_name', 'id' => 's.service_object_id'))
404 404
 				->join(
405 405
 					array('a' => 'icinga_objects'),
406 406
 					's.service_object_id=a.object_id',
407
-					array('is_active'=>'a.is_active','name2'=>'a.name2'))
407
+					array('is_active'=>'a.is_active', 'name2'=>'a.name2'))
408 408
 				->where('s.host_object_id='.$id.' AND a.is_active = 1');
409 409
 
410 410
 		return $db->fetchAll($query);
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
 	*/
419 419
 	protected function getServicesByHostGroupid($id) 
420 420
 	{		
421
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
422
-		$db = $this->getIdoDb()->getConnection();
421
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
422
+		$db=$this->getIdoDb()->getConnection();
423 423
 		$query=$db->select()
424 424
 				->from(
425 425
 					array('s' => 'icinga_hostgroup_members'),
@@ -436,11 +436,11 @@  discard block
 block discarded – undo
436 436
 		foreach ($hosts as $key => $host)
437 437
 		{ // For each host, get all services and add in common_services if not found or add counter
438 438
 			$host_services=$this->getServicesByHostid($host->host_object_id);
439
-			foreach($host_services as $service)
439
+			foreach ($host_services as $service)
440 440
 			{
441 441
 				if (isset($common_services[$service->name2]['num']))
442 442
 				{
443
-					$common_services[$service->name2]['num'] +=1;
443
+					$common_services[$service->name2]['num']+=1;
444 444
 				}
445 445
 				else
446 446
 				{
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
 		{
457 457
 		    if ($common_services[$key]['num'] == $num_hosts)
458 458
 			{
459
-				array_push($result,array($key,$common_services[$key]['name']));
459
+				array_push($result, array($key, $common_services[$key]['name']));
460 460
 			}
461 461
 		}
462 462
 		
@@ -469,9 +469,9 @@  discard block
 block discarded – undo
469 469
 	*	@param $name string service name
470 470
 	*	@return int  service id
471 471
 	*/
472
-	protected function getServiceIDByName($hostname,$name) 
472
+	protected function getServiceIDByName($hostname, $name) 
473 473
 	{
474
-		$db = $this->getIdoDb()->getConnection();
474
+		$db=$this->getIdoDb()->getConnection();
475 475
 		if ($name == null)
476 476
 		{
477 477
 			return 0;
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 		$query=$db->select()
481 481
 				->from(
482 482
 					array('s' => 'icinga_services'),
483
-					array('name' => 's.display_name','id' => 's.service_object_id'))
483
+					array('name' => 's.display_name', 'id' => 's.service_object_id'))
484 484
 				->join(
485 485
 					array('a' => 'icinga_objects'),
486 486
 					's.service_object_id=a.object_id',
@@ -498,12 +498,12 @@  discard block
 block discarded – undo
498 498
 	protected function getObjectNameByid($id) 
499 499
 	{
500 500
 		// 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
501
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
502
-		$db = $this->getIdoDb()->getConnection();
501
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
502
+		$db=$this->getIdoDb()->getConnection();
503 503
 		$query=$db->select()
504 504
 				->from(
505 505
 					array('a' => 'icinga_objects'),
506
-					array('name1' => 'a.name1','name2' => 'a.name2'))
506
+					array('name1' => 'a.name1', 'name2' => 'a.name2'))
507 507
 				->where('a.object_id='.$id.' AND a.is_active = 1');
508 508
 
509 509
 		return $db->fetchRow($query);
@@ -516,17 +516,17 @@  discard block
 block discarded – undo
516 516
 	protected function addHandlerRule($params)
517 517
 	{
518 518
 		// TODO Check for rule consistency
519
-		$db = $this->getDb()->getConnection();
519
+		$db=$this->getDb()->getConnection();
520 520
 		// Add last modified date = creation date and username
521
-		$params['created'] = new Zend_Db_Expr('NOW()');
522
-		$params['modified'] = new 	Zend_Db_Expr('NOW()');
523
-		$params['modifier'] = $this->Auth()->getUser()->getUsername();
521
+		$params['created']=new Zend_Db_Expr('NOW()');
522
+		$params['modified']=new 	Zend_Db_Expr('NOW()');
523
+		$params['modifier']=$this->Auth()->getUser()->getUsername();
524 524
 		
525 525
 		$query=$db->insert(
526 526
 			$this->getModuleConfig()->getTrapRuleName(),
527 527
 			$params
528 528
 		);
529
-		if($query==false)
529
+		if ($query == false)
530 530
 		{
531 531
 		  return null;
532 532
 		}
@@ -537,13 +537,13 @@  discard block
 block discarded – undo
537 537
 	*	@param array(<db item>=><value>)
538 538
 	*	@return array affected rows
539 539
 	*/
540
-	protected function updateHandlerRule($params,$ruleID)
540
+	protected function updateHandlerRule($params, $ruleID)
541 541
 	{
542 542
 		// TODO Check for rule consistency
543
-		$db = $this->getDb()->getConnection();
543
+		$db=$this->getDb()->getConnection();
544 544
 		// Add last modified date = creation date and username
545
-		$params['modified'] = new 	Zend_Db_Expr('NOW()');
546
-		$params['modifier'] = $this->Auth()->getUser()->getUsername();
545
+		$params['modified']=new 	Zend_Db_Expr('NOW()');
546
+		$params['modifier']=$this->Auth()->getUser()->getUsername();
547 547
 		
548 548
 		$numRows=$db->update(
549 549
 			$this->getModuleConfig()->getTrapRuleName(),
@@ -558,8 +558,8 @@  discard block
 block discarded – undo
558 558
 	*/
559 559
 	protected function deleteRule($ruleID)
560 560
 	{
561
-		if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
562
-		$db = $this->getDb()->getConnection();
561
+		if (!preg_match('/^[0-9]+$/', $ruleID)) { throw new Exception('Invalid id'); }
562
+		$db=$this->getDb()->getConnection();
563 563
 		
564 564
 		$query=$db->delete(
565 565
 			$this->getModuleConfig()->getTrapRuleName(),
@@ -572,10 +572,10 @@  discard block
 block discarded – undo
572 572
 	*	@param $ip string source IP (v4 or v6)
573 573
 	*	@param $oid string oid
574 574
 	*/
575
-	protected function deleteTrap($ip,$oid)
575
+	protected function deleteTrap($ip, $oid)
576 576
 	{
577 577
 		
578
-		$db = $this->getDb()->getConnection();
578
+		$db=$this->getDb()->getConnection();
579 579
 		$condition=null;
580 580
 		if ($ip != null)
581 581
 		{
@@ -583,10 +583,10 @@  discard block
 block discarded – undo
583 583
 		}
584 584
 		if ($oid != null)
585 585
 		{
586
-			$condition=($condition===null)?'':$condition.' AND ';
586
+			$condition=($condition === null) ? '' : $condition.' AND ';
587 587
 			$condition.="trap_oid='$oid'";
588 588
 		}
589
-		if($condition === null) return null;
589
+		if ($condition === null) return null;
590 590
 		$query=$db->delete(
591 591
 			$this->getModuleConfig()->getTrapTableName(),
592 592
 			$condition
@@ -600,10 +600,10 @@  discard block
 block discarded – undo
600 600
 	*	@param $ip string source IP (v4 or v6)
601 601
 	*	@param $oid string oid
602 602
 	*/
603
-	protected function countTrap($ip,$oid)
603
+	protected function countTrap($ip, $oid)
604 604
 	{
605 605
 		
606
-		$db = $this->getDb()->getConnection();
606
+		$db=$this->getDb()->getConnection();
607 607
 		$condition=null;
608 608
 		if ($ip != null)
609 609
 		{
@@ -611,10 +611,10 @@  discard block
 block discarded – undo
611 611
 		}
612 612
 		if ($oid != null)
613 613
 		{
614
-			$condition=($condition==null)?'':$condition.' AND ';
614
+			$condition=($condition == null) ? '' : $condition.' AND ';
615 615
 			$condition.="trap_oid='$oid'";
616 616
 		}
617
-		if($condition ==null) return 0;
617
+		if ($condition == null) return 0;
618 618
 		$query=$db->select()
619 619
 			->from(
620 620
 				$this->getModuleConfig()->getTrapTableName(),
@@ -630,27 +630,27 @@  discard block
 block discarded – undo
630 630
 	protected function getDBConfigValue($element)
631 631
 	{
632 632
 	
633
-		$db = $this->getDb()->getConnection();
633
+		$db=$this->getDb()->getConnection();
634 634
 		
635 635
 		$query=$db->select()
636 636
 			->from(
637 637
 				$this->getModuleConfig()->getDbConfigTableName(),
638 638
 				array('value'=>'value'))
639
-			->where('name=?',$element);
639
+			->where('name=?', $element);
640 640
 		$return_row=$db->fetchRow($query);
641
-		if ($return_row==null)  // value does not exists
641
+		if ($return_row == null)  // value does not exists
642 642
 		{
643 643
 			$default=$this->getModuleConfig()->getDBConfigDefaults();
644
-			if ( ! isset($default[$element])) return null; // no default and not value
644
+			if (!isset($default[$element])) return null; // no default and not value
645 645
 			
646
-			$this->addDBConfigValue($element,$default[$element]);
646
+			$this->addDBConfigValue($element, $default[$element]);
647 647
 			return $default[$element];
648 648
 		}
649 649
 		if ($return_row->value == null) // value id empty
650 650
 		{
651 651
 			$default=$this->getModuleConfig()->getDBConfigDefaults();
652
-			if ( ! isset($default[$element])) return null; // no default and not value
653
-			$this->setDBConfigValue($element,$default[$element]);
652
+			if (!isset($default[$element])) return null; // no default and not value
653
+			$this->setDBConfigValue($element, $default[$element]);
654 654
 			return $default[$element];			
655 655
 		}
656 656
 		return $return_row->value;		
@@ -659,10 +659,10 @@  discard block
 block discarded – undo
659 659
 	/** add configuration value
660 660
 	*	@param name value
661 661
 	*/
662
-	protected function addDBConfigValue($element,$value)
662
+	protected function addDBConfigValue($element, $value)
663 663
 	{
664 664
 	
665
-		$db = $this->getDb()->getConnection();
665
+		$db=$this->getDb()->getConnection();
666 666
 		
667 667
 		$query=$db->insert(
668 668
 				$this->getModuleConfig()->getDbConfigTableName(),
@@ -677,10 +677,10 @@  discard block
 block discarded – undo
677 677
 	/** set configuration value
678 678
 	*	@param name value
679 679
 	*/
680
-	protected function setDBConfigValue($element,$value)
680
+	protected function setDBConfigValue($element, $value)
681 681
 	{
682 682
 	
683
-		$db = $this->getDb()->getConnection();
683
+		$db=$this->getDb()->getConnection();
684 684
 		$query=$db->update(
685 685
 				$this->getModuleConfig()->getDbConfigTableName(),
686 686
 				array('value'=>$value),
@@ -695,10 +695,10 @@  discard block
 block discarded – undo
695 695
 	protected function isDirectorInstalled()
696 696
 	{
697 697
 	    $output=array();
698
-	    exec('icingacli module list',$output);
698
+	    exec('icingacli module list', $output);
699 699
 	    foreach ($output as $line)
700 700
 		{
701
-			if (preg_match('/^director .*enabled/',$line))
701
+			if (preg_match('/^director .*enabled/', $line))
702 702
 			{
703 703
 				return true;
704 704
 			}
Please login to merge, or discard this patch.
Braces   +62 added lines, -30 removed lines patch added patch discarded remove patch
@@ -87,10 +87,11 @@  discard block
 block discarded – undo
87 87
 		try 
88 88
 		{
89 89
 			$dbconn = IcingaDbConnection::fromResourceName($DBname);
90
-		} 
91
-		catch (Exception $e)
90
+		} catch (Exception $e)
92 91
 		{
93
-			if ($test) return array(2,$DBname);
92
+			if ($test) {
93
+				return array(2,$DBname);
94
+			}
94 95
 			$this->redirectNow('trapdirector/settings?dberror=2');
95 96
 			return null;
96 97
 		}
@@ -98,10 +99,11 @@  discard block
 block discarded – undo
98 99
 			try 
99 100
 			{
100 101
 				$db=$dbconn->getConnection();
101
-			}
102
-			catch (Exception $e) 
102
+			} catch (Exception $e) 
103 103
 			{
104
-				if ($test) return array(3,$DBname,$e->getMessage());
104
+				if ($test) {
105
+					return array(3,$DBname,$e->getMessage());
106
+				}
105 107
 				$this->redirectNow('trapdirector/settings?dberror=3');
106 108
 				return null;
107 109
 			}
@@ -113,55 +115,72 @@  discard block
 block discarded – undo
113 115
 				$version=$db->fetchRow($query);
114 116
 				if ( ($version == null) || ! property_exists($version,'value') )
115 117
 				{
116
-					if ($test) return array(4,$DBname);
118
+					if ($test) {
119
+						return array(4,$DBname);
120
+					}
117 121
 					$this->redirectNow('trapdirector/settings?dberror=4');
118 122
 					return null;
119 123
 				}
120 124
 				if ($version->value < $this->getModuleConfig()->getDbMinVersion()) 
121 125
 				{
122
-					if ($test) return array(5,$version->value,$this->getModuleConfig()->getDbMinVersion());
126
+					if ($test) {
127
+						return array(5,$version->value,$this->getModuleConfig()->getDbMinVersion());
128
+					}
123 129
 					$this->redirectNow('trapdirector/settings?dberror=5');
124 130
 					return null;
125 131
 				}
126
-			}
127
-			catch (Exception $e) 
132
+			} catch (Exception $e) 
128 133
 			{
129
-				if ($test) return array(3,$DBname,$e->getMessage());
134
+				if ($test) {
135
+					return array(3,$DBname,$e->getMessage());
136
+				}
130 137
 				$this->redirectNow('trapdirector/settings?dberror=4');
131 138
 				return null;
132 139
 			}
133 140
 		}
134
-		if ($test) return array(0,'');
141
+		if ($test) {
142
+			return array(0,'');
143
+		}
135 144
 		return $dbconn;
136 145
 	}
137 146
 
138 147
 	public function getDb($test=false)
139 148
 	{
140
-		if ($this->trapDB != null && $test = false) return $this->trapDB;
149
+		if ($this->trapDB != null && $test = false) {
150
+			return $this->trapDB;
151
+		}
141 152
 		
142 153
 		$dbresource=$this->Config()->get('config', 'database');
143 154
 		
144 155
 		if ( ! $dbresource )
145 156
 		{	
146
-			if ($test) return array(1,'');
157
+			if ($test) {
158
+				return array(1,'');
159
+			}
147 160
 			$this->redirectNow('trapdirector/settings?dberror=1');
148 161
 			return null;
149 162
 		}
150 163
 		$retDB=$this->getDbByName($dbresource,$test,true);
151
-		if ($test == true) return $retDB;
164
+		if ($test == true) {
165
+			return $retDB;
166
+		}
152 167
 		$this->trapDB=$retDB;
153 168
 		return $this->trapDB;
154 169
 	}
155 170
 	
156 171
 	public function getIdoDb($test=false)
157 172
 	{
158
-		if ($this->icingaDB != null && $test = false) return $this->icingaDB;
173
+		if ($this->icingaDB != null && $test = false) {
174
+			return $this->icingaDB;
175
+		}
159 176
 		// TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
160 177
 		$dbresource=$this->Config()->get('config', 'IDOdatabase');;
161 178
 
162 179
 		if ( ! $dbresource )
163 180
 		{
164
-		    if ($test) return array(1,'No database in config.ini');
181
+		    if ($test) {
182
+		    	return array(1,'No database in config.ini');
183
+		    }
165 184
 		    $this->redirectNow('trapdirector/settings?idodberror=1');
166 185
 		    return null;
167 186
 		}
@@ -169,10 +188,11 @@  discard block
 block discarded – undo
169 188
 		try
170 189
 		{
171 190
 		    $dbconn = IcingaDbConnection::fromResourceName($dbresource);
172
-		}
173
-		catch (Exception $e)
191
+		} catch (Exception $e)
174 192
 		{
175
-		    if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2");
193
+		    if ($test) {
194
+		    	return array(2,"Database $dbresource does not exists in IcingaWeb2");
195
+		    }
176 196
 		    $this->redirectNow('trapdirector/settings?idodberror=2');
177 197
 		    return null;
178 198
 		}
@@ -192,8 +212,7 @@  discard block
 block discarded – undo
192 212
 		    {
193 213
 		        return array(4,"$dbresource does not look like an IDO database");
194 214
 		    }
195
-		}
196
-		catch (Exception $e)
215
+		} catch (Exception $e)
197 216
 		{
198 217
 			return array(3,"Error connecting to $dbresource : " . $e->getMessage());
199 218
 		}
@@ -441,8 +460,7 @@  discard block
 block discarded – undo
441 460
 				if (isset($common_services[$service->name2]['num']))
442 461
 				{
443 462
 					$common_services[$service->name2]['num'] +=1;
444
-				}
445
-				else
463
+				} else
446 464
 				{
447 465
 					$common_services[$service->name2]['num']=1;
448 466
 					$common_services[$service->name2]['name']=$service->name;
@@ -586,7 +604,9 @@  discard block
 block discarded – undo
586 604
 			$condition=($condition===null)?'':$condition.' AND ';
587 605
 			$condition.="trap_oid='$oid'";
588 606
 		}
589
-		if($condition === null) return null;
607
+		if($condition === null) {
608
+			return null;
609
+		}
590 610
 		$query=$db->delete(
591 611
 			$this->getModuleConfig()->getTrapTableName(),
592 612
 			$condition
@@ -614,7 +634,9 @@  discard block
 block discarded – undo
614 634
 			$condition=($condition==null)?'':$condition.' AND ';
615 635
 			$condition.="trap_oid='$oid'";
616 636
 		}
617
-		if($condition ==null) return 0;
637
+		if($condition ==null) {
638
+			return 0;
639
+		}
618 640
 		$query=$db->select()
619 641
 			->from(
620 642
 				$this->getModuleConfig()->getTrapTableName(),
@@ -638,18 +660,28 @@  discard block
 block discarded – undo
638 660
 				array('value'=>'value'))
639 661
 			->where('name=?',$element);
640 662
 		$return_row=$db->fetchRow($query);
641
-		if ($return_row==null)  // value does not exists
663
+		if ($return_row==null) {
664
+			// value does not exists
642 665
 		{
643 666
 			$default=$this->getModuleConfig()->getDBConfigDefaults();
644
-			if ( ! isset($default[$element])) return null; // no default and not value
667
+		}
668
+			if ( ! isset($default[$element])) {
669
+				return null;
670
+			}
671
+			// no default and not value
645 672
 			
646 673
 			$this->addDBConfigValue($element,$default[$element]);
647 674
 			return $default[$element];
648 675
 		}
649
-		if ($return_row->value == null) // value id empty
676
+		if ($return_row->value == null) {
677
+			// value id empty
650 678
 		{
651 679
 			$default=$this->getModuleConfig()->getDBConfigDefaults();
652
-			if ( ! isset($default[$element])) return null; // no default and not value
680
+		}
681
+			if ( ! isset($default[$element])) {
682
+				return null;
683
+			}
684
+			// no default and not value
653 685
 			$this->setDBConfigValue($element,$default[$element]);
654 686
 			return $default[$element];			
655 687
 		}
Please login to merge, or discard this patch.