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