Passed
Push — master ( 101619...42d7f2 )
by Patrick
01:57
created
library/Trapdirector/TrapsController.php 1 patch
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.