Passed
Push — master ( b0b632...393299 )
by Patrick
02:12
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,37 +101,37 @@  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
 
@@ -142,17 +142,17 @@  discard block
 block discarded – undo
142 142
 	 */
143 143
 	public function getDb($test=false)
144 144
 	{
145
-		if ($this->trapDB != null && $test = false) return $this->trapDB;
145
+		if ($this->trapDB != null && $test=false) return $this->trapDB;
146 146
 		
147 147
 		$dbresource=$this->Config()->get('config', 'database');
148 148
 		
149
-		if ( ! $dbresource )
149
+		if (!$dbresource)
150 150
 		{	
151
-			if ($test) return array(1,'');
151
+			if ($test) return array(1, '');
152 152
 			$this->redirectNow('trapdirector/settings?dberror=1');
153 153
 			return null;
154 154
 		}
155
-		$retDB=$this->getDbByName($dbresource,$test,true);
155
+		$retDB=$this->getDbByName($dbresource, $test, true);
156 156
 		if ($test === true) return $retDB;
157 157
 		$this->trapDB=$retDB;
158 158
 		return $this->trapDB;
@@ -160,78 +160,78 @@  discard block
 block discarded – undo
160 160
 	
161 161
 	public function getIdoDb($test=false)
162 162
 	{
163
-		if ($this->icingaDB != null && $test = false) return $this->icingaDB;
163
+		if ($this->icingaDB != null && $test=false) return $this->icingaDB;
164 164
 		// TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
165
-		$dbresource=$this->Config()->get('config', 'IDOdatabase');;
165
+		$dbresource=$this->Config()->get('config', 'IDOdatabase'); ;
166 166
 
167
-		if ( ! $dbresource )
167
+		if (!$dbresource)
168 168
 		{
169
-		    if ($test) return array(1,'No database in config.ini');
169
+		    if ($test) return array(1, 'No database in config.ini');
170 170
 		    $this->redirectNow('trapdirector/settings?idodberror=1');
171 171
 		    return null;
172 172
 		}
173 173
 		
174 174
 		try
175 175
 		{
176
-		    $dbconn = IcingaDbConnection::fromResourceName($dbresource);
176
+		    $dbconn=IcingaDbConnection::fromResourceName($dbresource);
177 177
 		}
178 178
 		catch (Exception $e)
179 179
 		{
180
-		    if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2");
180
+		    if ($test) return array(2, "Database $dbresource does not exists in IcingaWeb2");
181 181
 		    $this->redirectNow('trapdirector/settings?idodberror=2');
182 182
 		    return null;
183 183
 		}
184 184
 		
185 185
 		if ($test == false) 
186 186
 		{ 
187
-			$this->icingaDB = $dbconn; 
187
+			$this->icingaDB=$dbconn; 
188 188
 			return $this->icingaDB;
189 189
 		}
190 190
 		
191 191
 		try
192 192
 		{
193
-		    $query = $dbconn->select()
194
-		    ->from('icinga_dbversion',array('version'));
193
+		    $query=$dbconn->select()
194
+		    ->from('icinga_dbversion', array('version'));
195 195
 		    $version=$dbconn->fetchRow($query);
196
-		    if ( ($version == null) || ! property_exists($version,'version') )
196
+		    if (($version == null) || !property_exists($version, 'version'))
197 197
 		    {
198
-		        return array(4,"$dbresource does not look like an IDO database");
198
+		        return array(4, "$dbresource does not look like an IDO database");
199 199
 		    }
200 200
 		}
201 201
 		catch (Exception $e)
202 202
 		{
203
-			return array(3,"Error connecting to $dbresource : " . $e->getMessage());
203
+			return array(3, "Error connecting to $dbresource : ".$e->getMessage());
204 204
 		}
205 205
 		
206
-		return array(0,'');
206
+		return array(0, '');
207 207
 	}
208 208
 	
209
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
209
+    protected function applyPaginationLimits(Paginatable $paginatable, $limit=25, $offset=null)
210 210
     {
211
-        $limit = $this->params->get('limit', $limit);
212
-        $page = $this->params->get('page', $offset);
211
+        $limit=$this->params->get('limit', $limit);
212
+        $page=$this->params->get('page', $offset);
213 213
 
214 214
         $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
215 215
 
216 216
         return $paginatable;
217 217
     }	
218 218
 	
219
-	public function displayExitError($source,$message)
219
+	public function displayExitError($source, $message)
220 220
 	{	// TODO : check better ways to transmit data (with POST ?)
221 221
 		$this->redirectNow('trapdirector/error?source='.$source.'&message='.$message);
222 222
 	}
223 223
 	
224 224
 	protected function checkReadPermission()
225 225
 	{
226
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
227
-            $this->displayExitError('Permissions','No permission fo view content');
226
+        if (!$this->Auth()->hasPermission('trapdirector/view')) {
227
+            $this->displayExitError('Permissions', 'No permission fo view content');
228 228
         }		
229 229
 	}
230 230
 
231 231
 	protected function checkConfigPermission()
232 232
 	{
233
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
234
-            $this->displayExitError('Permissions','No permission fo configure');
233
+        if (!$this->Auth()->hasPermission('trapdirector/config')) {
234
+            $this->displayExitError('Permissions', 'No permission fo configure');
235 235
         }		
236 236
 	}
237 237
 	
@@ -242,10 +242,10 @@  discard block
 block discarded – undo
242 242
      */
243 243
 	protected function checkModuleConfigPermission($check=0)
244 244
 	{
245
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
245
+        if (!$this->Auth()->hasPermission('trapdirector/module_config')) {
246 246
             if ($check == 0)
247 247
             {
248
-                $this->displayExitError('Permissions','No permission fo configure module');
248
+                $this->displayExitError('Permissions', 'No permission fo configure module');
249 249
             }
250 250
             return false;
251 251
         }
@@ -257,10 +257,10 @@  discard block
 block discarded – undo
257 257
 	{ // TODO : try/catch here ? or within caller
258 258
 		if ($this->trapClass == null)
259 259
 		{
260
-			require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
260
+			require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
261 261
 			$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
262 262
 			//$debug_level=4;
263
-			$this->trapClass = new Trap($icingaweb2_etc);
263
+			$this->trapClass=new Trap($icingaweb2_etc);
264 264
 			//$Trap->setLogging($debug_level,'syslog');
265 265
 		}
266 266
 		return $this->trapClass;
@@ -294,12 +294,12 @@  discard block
 block discarded – undo
294 294
 	protected function getHostByIP($ip) 
295 295
 	{
296 296
 		// 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
297
-		$db = $this->getIdoDb()->getConnection();
297
+		$db=$this->getIdoDb()->getConnection();
298 298
 		// TODO : check for SQL injections
299 299
 		$query=$db->select()
300 300
 				->from(
301 301
 					array('a' => 'icinga_objects'),
302
-					array('name' => 'a.name1','id' => 'object_id'))
302
+					array('name' => 'a.name1', 'id' => 'object_id'))
303 303
 				->join(
304 304
 					array('b' => 'icinga_hosts'),
305 305
 					'b.host_object_id=a.object_id',
@@ -315,12 +315,12 @@  discard block
 block discarded – undo
315 315
 	protected function getHostByName($name) 
316 316
 	{
317 317
 		// 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
318
-		$db = $this->getIdoDb()->getConnection();
318
+		$db=$this->getIdoDb()->getConnection();
319 319
 		// TODO : check for SQL injections
320 320
 		$query=$db->select()
321 321
 				->from(
322 322
 					array('a' => 'icinga_objects'),
323
-					array('name' => 'a.name1','id' => 'object_id'))
323
+					array('name' => 'a.name1', 'id' => 'object_id'))
324 324
 				->join(
325 325
 					array('b' => 'icinga_hosts'),
326 326
 					'b.host_object_id=a.object_id',
@@ -336,12 +336,12 @@  discard block
 block discarded – undo
336 336
 	protected function getHostGroupByName($ip) 
337 337
 	{
338 338
 		// 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
339
-		$db = $this->getIdoDb()->getConnection();
339
+		$db=$this->getIdoDb()->getConnection();
340 340
 		// TODO : check for SQL injections
341 341
 		$query=$db->select()
342 342
 				->from(
343 343
 					array('a' => 'icinga_objects'),
344
-					array('name' => 'a.name1','id' => 'object_id'))
344
+					array('name' => 'a.name1', 'id' => 'object_id'))
345 345
 				->join(
346 346
 					array('b' => 'icinga_hostgroups'),
347 347
 					'b.hostgroup_object_id=a.object_id',
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
 	*/
358 358
 	protected function getHostInfoByID($id) 
359 359
 	{
360
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
361
-		$db = $this->getIdoDb()->getConnection();
360
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
361
+		$db=$this->getIdoDb()->getConnection();
362 362
 		$query=$db->select()
363 363
 				->from(
364 364
 					array('a' => 'icinga_objects'),
@@ -378,17 +378,17 @@  discard block
 block discarded – undo
378 378
 	*/
379 379
 	protected function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above
380 380
 	{
381
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
382
-		$db = $this->getIdoDb()->getConnection();
381
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
382
+		$db=$this->getIdoDb()->getConnection();
383 383
 		$query=$db->select()
384 384
 				->from(
385 385
 					array('a' => 'icinga_objects'),
386
-					array('name' => 'a.name1','id' => 'a.object_id'))
386
+					array('name' => 'a.name1', 'id' => 'a.object_id'))
387 387
 				->join(
388 388
 					array('b' => 'icinga_hosts'),
389 389
 					'b.host_object_id=a.object_id',
390
-					array('display_name' => 'b.display_name' , 'ip' => 'b.address', 'ip6' => 'b.address6'))
391
-				->where('a.object_id = ?',$id);
390
+					array('display_name' => 'b.display_name', 'ip' => 'b.address', 'ip6' => 'b.address6'))
391
+				->where('a.object_id = ?', $id);
392 392
 		return $db->fetchRow($query);
393 393
 	}	
394 394
 	
@@ -400,16 +400,16 @@  discard block
 block discarded – undo
400 400
 	protected function getServicesByHostid($id) 
401 401
 	{
402 402
 		// 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
403
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
404
-		$db = $this->getIdoDb()->getConnection();
403
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
404
+		$db=$this->getIdoDb()->getConnection();
405 405
 		$query=$db->select()
406 406
 				->from(
407 407
 					array('s' => 'icinga_services'),
408
-					array('name' => 's.display_name','id' => 's.service_object_id'))
408
+					array('name' => 's.display_name', 'id' => 's.service_object_id'))
409 409
 				->join(
410 410
 					array('a' => 'icinga_objects'),
411 411
 					's.service_object_id=a.object_id',
412
-					array('is_active'=>'a.is_active','name2'=>'a.name2'))
412
+					array('is_active'=>'a.is_active', 'name2'=>'a.name2'))
413 413
 				->where('s.host_object_id='.$id.' AND a.is_active = 1');
414 414
 
415 415
 		return $db->fetchAll($query);
@@ -423,8 +423,8 @@  discard block
 block discarded – undo
423 423
 	*/
424 424
 	protected function getServicesByHostGroupid($id) 
425 425
 	{		
426
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
427
-		$db = $this->getIdoDb()->getConnection();
426
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
427
+		$db=$this->getIdoDb()->getConnection();
428 428
 		$query=$db->select()
429 429
 				->from(
430 430
 					array('s' => 'icinga_hostgroup_members'),
@@ -441,11 +441,11 @@  discard block
 block discarded – undo
441 441
 		foreach ($hosts as $key => $host)
442 442
 		{ // For each host, get all services and add in common_services if not found or add counter
443 443
 			$host_services=$this->getServicesByHostid($host->host_object_id);
444
-			foreach($host_services as $service)
444
+			foreach ($host_services as $service)
445 445
 			{
446 446
 				if (isset($common_services[$service->name2]['num']))
447 447
 				{
448
-					$common_services[$service->name2]['num'] +=1;
448
+					$common_services[$service->name2]['num']+=1;
449 449
 				}
450 450
 				else
451 451
 				{
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 		{
462 462
 		    if ($common_services[$key]['num'] == $num_hosts)
463 463
 			{
464
-				array_push($result,array($key,$common_services[$key]['name']));
464
+				array_push($result, array($key, $common_services[$key]['name']));
465 465
 			}
466 466
 		}
467 467
 		
@@ -474,9 +474,9 @@  discard block
 block discarded – undo
474 474
 	*	@param $name string service name
475 475
 	*	@return array  service id
476 476
 	*/
477
-	protected function getServiceIDByName($hostname,$name) 
477
+	protected function getServiceIDByName($hostname, $name) 
478 478
 	{
479
-		$db = $this->getIdoDb()->getConnection();
479
+		$db=$this->getIdoDb()->getConnection();
480 480
 		if ($name == null)
481 481
 		{
482 482
 			return array();
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 		$query=$db->select()
486 486
 				->from(
487 487
 					array('s' => 'icinga_services'),
488
-					array('name' => 's.display_name','id' => 's.service_object_id'))
488
+					array('name' => 's.display_name', 'id' => 's.service_object_id'))
489 489
 				->join(
490 490
 					array('a' => 'icinga_objects'),
491 491
 					's.service_object_id=a.object_id',
@@ -503,12 +503,12 @@  discard block
 block discarded – undo
503 503
 	protected function getObjectNameByid($id) 
504 504
 	{
505 505
 		// 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
506
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
507
-		$db = $this->getIdoDb()->getConnection();
506
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
507
+		$db=$this->getIdoDb()->getConnection();
508 508
 		$query=$db->select()
509 509
 				->from(
510 510
 					array('a' => 'icinga_objects'),
511
-					array('name1' => 'a.name1','name2' => 'a.name2'))
511
+					array('name1' => 'a.name1', 'name2' => 'a.name2'))
512 512
 				->where('a.object_id='.$id.' AND a.is_active = 1');
513 513
 
514 514
 		return $db->fetchRow($query);
@@ -521,17 +521,17 @@  discard block
 block discarded – undo
521 521
 	protected function addHandlerRule($params)
522 522
 	{
523 523
 		// TODO Check for rule consistency
524
-		$db = $this->getDb()->getConnection();
524
+		$db=$this->getDb()->getConnection();
525 525
 		// Add last modified date = creation date and username
526
-		$params['created'] = new Zend_Db_Expr('NOW()');
527
-		$params['modified'] = new 	Zend_Db_Expr('NOW()');
528
-		$params['modifier'] = $this->Auth()->getUser()->getUsername();
526
+		$params['created']=new Zend_Db_Expr('NOW()');
527
+		$params['modified']=new 	Zend_Db_Expr('NOW()');
528
+		$params['modifier']=$this->Auth()->getUser()->getUsername();
529 529
 		
530 530
 		$query=$db->insert(
531 531
 			$this->getModuleConfig()->getTrapRuleName(),
532 532
 			$params
533 533
 		);
534
-		if($query==false)
534
+		if ($query == false)
535 535
 		{
536 536
 		  return null;
537 537
 		}
@@ -543,13 +543,13 @@  discard block
 block discarded – undo
543 543
 	*   @param integer $ruleID : rule id in db
544 544
 	*	@return array affected rows
545 545
 	*/
546
-	protected function updateHandlerRule($params,$ruleID)
546
+	protected function updateHandlerRule($params, $ruleID)
547 547
 	{
548 548
 		// TODO Check for rule consistency
549
-		$db = $this->getDb()->getConnection();
549
+		$db=$this->getDb()->getConnection();
550 550
 		// Add last modified date = creation date and username
551
-		$params['modified'] = new 	Zend_Db_Expr('NOW()');
552
-		$params['modifier'] = $this->Auth()->getUser()->getUsername();
551
+		$params['modified']=new 	Zend_Db_Expr('NOW()');
552
+		$params['modifier']=$this->Auth()->getUser()->getUsername();
553 553
 		
554 554
 		$numRows=$db->update(
555 555
 			$this->getModuleConfig()->getTrapRuleName(),
@@ -564,8 +564,8 @@  discard block
 block discarded – undo
564 564
 	*/
565 565
 	protected function deleteRule($ruleID)
566 566
 	{
567
-		if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
568
-		$db = $this->getDb()->getConnection();
567
+		if (!preg_match('/^[0-9]+$/', $ruleID)) { throw new Exception('Invalid id'); }
568
+		$db=$this->getDb()->getConnection();
569 569
 		
570 570
 		$query=$db->delete(
571 571
 			$this->getModuleConfig()->getTrapRuleName(),
@@ -578,10 +578,10 @@  discard block
 block discarded – undo
578 578
 	*	@param $ip string source IP (v4 or v6)
579 579
 	*	@param $oid string oid
580 580
 	*/
581
-	protected function deleteTrap($ip,$oid)
581
+	protected function deleteTrap($ip, $oid)
582 582
 	{
583 583
 		
584
-		$db = $this->getDb()->getConnection();
584
+		$db=$this->getDb()->getConnection();
585 585
 		$condition=null;
586 586
 		if ($ip != null)
587 587
 		{
@@ -589,10 +589,10 @@  discard block
 block discarded – undo
589 589
 		}
590 590
 		if ($oid != null)
591 591
 		{
592
-			$condition=($condition===null)?'':$condition.' AND ';
592
+			$condition=($condition === null) ? '' : $condition.' AND ';
593 593
 			$condition.="trap_oid='$oid'";
594 594
 		}
595
-		if($condition === null) return null;
595
+		if ($condition === null) return null;
596 596
 		$query=$db->delete(
597 597
 			$this->getModuleConfig()->getTrapTableName(),
598 598
 			$condition
@@ -606,10 +606,10 @@  discard block
 block discarded – undo
606 606
 	*	@param $ip string source IP (v4 or v6)
607 607
 	*	@param $oid string oid
608 608
 	*/
609
-	protected function countTrap($ip,$oid)
609
+	protected function countTrap($ip, $oid)
610 610
 	{
611 611
 		
612
-		$db = $this->getDb()->getConnection();
612
+		$db=$this->getDb()->getConnection();
613 613
 		$condition=null;
614 614
 		if ($ip != null)
615 615
 		{
@@ -617,10 +617,10 @@  discard block
 block discarded – undo
617 617
 		}
618 618
 		if ($oid != null)
619 619
 		{
620
-			$condition=($condition===null)?'':$condition.' AND ';
620
+			$condition=($condition === null) ? '' : $condition.' AND ';
621 621
 			$condition.="trap_oid='$oid'";
622 622
 		}
623
-		if($condition === null) return 0;
623
+		if ($condition === null) return 0;
624 624
 		$query=$db->select()
625 625
 			->from(
626 626
 				$this->getModuleConfig()->getTrapTableName(),
@@ -636,27 +636,27 @@  discard block
 block discarded – undo
636 636
 	protected function getDBConfigValue($element)
637 637
 	{
638 638
 	
639
-		$db = $this->getDb()->getConnection();
639
+		$db=$this->getDb()->getConnection();
640 640
 		
641 641
 		$query=$db->select()
642 642
 			->from(
643 643
 				$this->getModuleConfig()->getDbConfigTableName(),
644 644
 				array('value'=>'value'))
645
-			->where('name=?',$element);
645
+			->where('name=?', $element);
646 646
 		$return_row=$db->fetchRow($query);
647
-		if ($return_row==null)  // value does not exists
647
+		if ($return_row == null)  // value does not exists
648 648
 		{
649 649
 			$default=$this->getModuleConfig()->getDBConfigDefaults();
650
-			if ( ! isset($default[$element])) return null; // no default and not value
650
+			if (!isset($default[$element])) return null; // no default and not value
651 651
 			
652
-			$this->addDBConfigValue($element,$default[$element]);
652
+			$this->addDBConfigValue($element, $default[$element]);
653 653
 			return $default[$element];
654 654
 		}
655 655
 		if ($return_row->value == null) // value id empty
656 656
 		{
657 657
 			$default=$this->getModuleConfig()->getDBConfigDefaults();
658
-			if ( ! isset($default[$element])) return null; // no default and not value
659
-			$this->setDBConfigValue($element,$default[$element]);
658
+			if (!isset($default[$element])) return null; // no default and not value
659
+			$this->setDBConfigValue($element, $default[$element]);
660 660
 			return $default[$element];			
661 661
 		}
662 662
 		return $return_row->value;		
@@ -667,10 +667,10 @@  discard block
 block discarded – undo
667 667
 	*   @param string $value : value
668 668
 	*/
669 669
 		
670
-	protected function addDBConfigValue($element,$value)
670
+	protected function addDBConfigValue($element, $value)
671 671
 	{
672 672
 	
673
-		$db = $this->getDb()->getConnection();
673
+		$db=$this->getDb()->getConnection();
674 674
 		
675 675
 		$query=$db->insert(
676 676
 				$this->getModuleConfig()->getDbConfigTableName(),
@@ -686,10 +686,10 @@  discard block
 block discarded – undo
686 686
 	*	@param string $element : name of config element
687 687
 	*   @param string $value : value
688 688
 	*/
689
-	protected function setDBConfigValue($element,$value)
689
+	protected function setDBConfigValue($element, $value)
690 690
 	{
691 691
 	
692
-		$db = $this->getDb()->getConnection();
692
+		$db=$this->getDb()->getConnection();
693 693
 		$query=$db->update(
694 694
 				$this->getModuleConfig()->getDbConfigTableName(),
695 695
 				array('value'=>$value),
@@ -704,10 +704,10 @@  discard block
 block discarded – undo
704 704
 	protected function isDirectorInstalled()
705 705
 	{
706 706
 	    $output=array();
707
-	    exec('icingacli module list',$output);
707
+	    exec('icingacli module list', $output);
708 708
 	    foreach ($output as $line)
709 709
 		{
710
-			if (preg_match('/^director .*enabled/',$line))
710
+			if (preg_match('/^director .*enabled/', $line))
711 711
 			{
712 712
 				return true;
713 713
 			}
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/Trap.php 1 patch
Spacing   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
49 49
     
50 50
     // Logs
51 51
     /** @var Logging Logging class. */
52
-    public $logging;    //< Logging class.
52
+    public $logging; //< Logging class.
53 53
     /** @var bool true if log was setup in constructor */
54
-    protected $logSetup;   //< bool true if log was setup in constructor
54
+    protected $logSetup; //< bool true if log was setup in constructor
55 55
     
56 56
     // Databases
57 57
     /** @var Database $trapsDB  Database class*/
58
-    public $trapsDB = null;
58
+    public $trapsDB=null;
59 59
     
60 60
     // Trap received data
61 61
     protected $receivingHost;
@@ -67,15 +67,15 @@  discard block
 block discarded – undo
67 67
     protected $trap_to_db=true; //< log trap to DB
68 68
     
69 69
     /** @var Mib mib class */
70
-    public $mibClass = null;
70
+    public $mibClass=null;
71 71
     
72 72
     /** @var Rule rule class */
73
-    public $ruleClass = null;
73
+    public $ruleClass=null;
74 74
     
75 75
     /** @var Plugins plugins manager **/
76
-    public $pluginClass = null;
76
+    public $pluginClass=null;
77 77
     
78
-    function __construct($etc_dir='/etc/icingaweb2',$baseLogLevel=null,$baseLogMode='syslog',$baseLogFile='')
78
+    function __construct($etc_dir='/etc/icingaweb2', $baseLogLevel=null, $baseLogMode='syslog', $baseLogFile='')
79 79
     {
80 80
         // Paths of ini files
81 81
         $this->icingaweb2ETC=$etc_dir;
@@ -83,10 +83,10 @@  discard block
 block discarded – undo
83 83
         $this->icingaweb2Ressources=$this->icingaweb2ETC."/resources.ini";
84 84
         
85 85
         //************* Setup logging
86
-        $this->logging = new Logging();
86
+        $this->logging=new Logging();
87 87
         if ($baseLogLevel != null)
88 88
         {
89
-            $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile);
89
+            $this->logging->setLogging($baseLogLevel, $baseLogMode, $baseLogFile);
90 90
             $this->logSetup=true;
91 91
         }
92 92
         else
@@ -96,14 +96,14 @@  discard block
 block discarded – undo
96 96
         $this->logging->log('Loggin started', INFO);
97 97
         
98 98
         //*************** Get options from ini files
99
-        if (! is_file($this->trapModuleConfig))
99
+        if (!is_file($this->trapModuleConfig))
100 100
         {
101 101
             throw new Exception("Ini file ".$this->trapModuleConfig." does not exists");
102 102
         }
103
-        $trapConfig=parse_ini_file($this->trapModuleConfig,true);
103
+        $trapConfig=parse_ini_file($this->trapModuleConfig, true);
104 104
         if ($trapConfig == false)
105 105
         {
106
-            $this->logging->log("Error reading ini file : ".$this->trapModuleConfig,ERROR,'syslog');
106
+            $this->logging->log("Error reading ini file : ".$this->trapModuleConfig, ERROR, 'syslog');
107 107
             throw new Exception("Error reading ini file : ".$this->trapModuleConfig);
108 108
         }
109 109
         $this->getMainOptions($trapConfig); // Get main options from ini file
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
         if ($this->apiUse === true) $this->getAPI(); // Setup API
118 118
         
119 119
         //*************** Setup MIB
120
-        $this->mibClass = new Mib($this->logging,$this->trapsDB,$this->snmptranslate,$this->snmptranslate_dirs); // Create Mib class
120
+        $this->mibClass=new Mib($this->logging, $this->trapsDB, $this->snmptranslate, $this->snmptranslate_dirs); // Create Mib class
121 121
         
122 122
         //*************** Setup Rule
123
-        $this->ruleClass = new Rule($this->logging); //< Create Rule class
123
+        $this->ruleClass=new Rule($this->logging); //< Create Rule class
124 124
         
125 125
         $this->trap_data=array(  // TODO : put this in a reset function (DAEMON_MODE)
126 126
             'source_ip'	=> 'unknown',
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
         
133 133
         //*************** Setup Plugins
134 134
         //Create plugin class. Plugins are not loaded here, but by calling registerAllPlugins
135
-        $this->pluginClass = new Plugins($this);
135
+        $this->pluginClass=new Plugins($this);
136 136
             
137 137
             
138 138
     }
@@ -147,15 +147,15 @@  discard block
 block discarded – undo
147 147
      * @param string $message warning message if not found
148 148
      * @return boolean true if found, or false
149 149
      */
150
-    protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = 2, $message = null)
150
+    protected function getOptionIfSet($option_array, $option_category, $option_name, &$option_var, $log_level=2, $message=null)
151 151
     {
152 152
         if (!isset($option_array[$option_category][$option_name]))
153 153
         {
154 154
             if ($message === null)
155 155
             {
156
-                $message='No ' . $option_name . ' in config file: '. $this->trapModuleConfig;
156
+                $message='No '.$option_name.' in config file: '.$this->trapModuleConfig;
157 157
             }
158
-            $this->logging->log($message,$log_level);
158
+            $this->logging->log($message, $log_level);
159 159
             return false;
160 160
         }
161 161
         else
@@ -173,24 +173,24 @@  discard block
 block discarded – undo
173 173
     {
174 174
         
175 175
         // Snmptranslate binary path
176
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate);
176
+        $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate', $this->snmptranslate);
177 177
         
178 178
         // mibs path
179
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs);
179
+        $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate_dirs', $this->snmptranslate_dirs);
180 180
         
181 181
         // icinga2cmd path
182
-        $this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd);
182
+        $this->getOptionIfSet($trapConfig, 'config', 'icingacmd', $this->icinga2cmd);
183 183
         
184 184
         // table prefix
185
-        $this->getOptionIfSet($trapConfig,'config','database_prefix', $this->dbPrefix);
185
+        $this->getOptionIfSet($trapConfig, 'config', 'database_prefix', $this->dbPrefix);
186 186
         
187 187
         // API options
188
-        if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->apiHostname))
188
+        if ($this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_host', $this->apiHostname))
189 189
         {
190 190
             $this->apiUse=true;
191
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->apiPort);
192
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->apiUsername);
193
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->apiPassword);
191
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_port', $this->apiPort);
192
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_user', $this->apiUsername);
193
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_password', $this->apiPassword);
194 194
         }
195 195
     }
196 196
     
@@ -201,40 +201,40 @@  discard block
 block discarded – undo
201 201
     protected function setupDatabase($trapConfig)
202 202
     {
203 203
         // Trap database
204
-        if (!array_key_exists('database',$trapConfig['config']))
204
+        if (!array_key_exists('database', $trapConfig['config']))
205 205
         {
206
-            $this->logging->log("No database in config file: ".$this->trapModuleConfig,ERROR,'');
206
+            $this->logging->log("No database in config file: ".$this->trapModuleConfig, ERROR, '');
207 207
             return;
208 208
         }
209 209
         $dbTrapName=$trapConfig['config']['database'];
210
-        $this->logging->log("Found database in config file: ".$dbTrapName,INFO );
210
+        $this->logging->log("Found database in config file: ".$dbTrapName, INFO);
211 211
         
212
-        if ( ($dbConfig=parse_ini_file($this->icingaweb2Ressources,true)) === false)
212
+        if (($dbConfig=parse_ini_file($this->icingaweb2Ressources, true)) === false)
213 213
         {
214
-            $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources,ERROR,'');
214
+            $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources, ERROR, '');
215 215
             return;
216 216
         }
217
-        if (!array_key_exists($dbTrapName,$dbConfig))
217
+        if (!array_key_exists($dbTrapName, $dbConfig))
218 218
         {
219
-            $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
219
+            $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources, ERROR, '');
220 220
             return;
221 221
         }
222 222
         
223
-        $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix);
223
+        $this->trapsDB=new Database($this->logging, $dbConfig[$dbTrapName], $this->dbPrefix);
224 224
         
225 225
         if ($this->apiUse === true) return; // In case of API use, no IDO is necessary
226 226
         
227 227
         // IDO Database
228
-        if (!array_key_exists('IDOdatabase',$trapConfig['config']))
228
+        if (!array_key_exists('IDOdatabase', $trapConfig['config']))
229 229
         {
230
-            $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,'');
230
+            $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig, ERROR, '');
231 231
         }
232 232
         $dbIdoName=$trapConfig['config']['IDOdatabase'];
233 233
         
234
-        $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
235
-        if (!array_key_exists($dbIdoName,$dbConfig))
234
+        $this->logging->log("Found IDO database in config file: ".$dbIdoName, INFO);
235
+        if (!array_key_exists($dbIdoName, $dbConfig))
236 236
         {
237
-            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
237
+            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources, ERROR, '');
238 238
             return;
239 239
         }
240 240
         
@@ -249,9 +249,9 @@  discard block
 block discarded – undo
249 249
         // Database options
250 250
         if ($this->logSetup === false) // Only if logging was no setup in constructor
251 251
         {
252
-            $this->getDBConfigIfSet('log_level',$this->logging->debugLevel);
253
-            $this->getDBConfigIfSet('log_destination',$this->logging->outputMode);
254
-            $this->getDBConfigIfSet('log_file',$this->logging->outputFile);
252
+            $this->getDBConfigIfSet('log_level', $this->logging->debugLevel);
253
+            $this->getDBConfigIfSet('log_destination', $this->logging->outputMode);
254
+            $this->getDBConfigIfSet('log_file', $this->logging->outputFile);
255 255
         }
256 256
     }
257 257
     
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
      * @param string $element
260 260
      * @param string $variable
261 261
      */
262
-    protected function getDBConfigIfSet($element,&$variable)
262
+    protected function getDBConfigIfSet($element, &$variable)
263 263
     {
264 264
         $value=$this->getDBConfig($element);
265 265
         if ($value != null) $variable=$value;
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
         $db_conn=$this->trapsDB->db_connect_trap();
276 276
         $sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )';
277 277
         if (($ret_code=$db_conn->query($sql)) === false) {
278
-            $this->logging->log('No result in query : ' . $sql,WARN,'');
278
+            $this->logging->log('No result in query : '.$sql, WARN, '');
279 279
             return null;
280 280
         }
281 281
         $value=$ret_code->fetch();
@@ -292,15 +292,15 @@  discard block
 block discarded – undo
292 292
      *	@param  string $destination file/syslog/display
293 293
      *	@return void
294 294
      **/
295
-    public function trapLog( $message, $level, $destination ='') // OBSOLETE
295
+    public function trapLog($message, $level, $destination='') // OBSOLETE
296 296
     {
297 297
         // TODO : replace ref with $this->logging->log
298 298
         $this->logging->log($message, $level, $destination);
299 299
     }
300 300
     
301
-    public function setLogging($debugLvl,$outputType,$outputOption=null)  // OBSOLETE
301
+    public function setLogging($debugLvl, $outputType, $outputOption=null)  // OBSOLETE
302 302
     {
303
-        $this->logging->setLogging($debugLvl, $outputType,$outputOption);
303
+        $this->logging->setLogging($debugLvl, $outputType, $outputOption);
304 304
     }
305 305
     
306 306
     /**
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
     {
312 312
         if ($this->icinga2api == null)
313 313
         {
314
-            $this->icinga2api = new Icinga2API($this->apiHostname,$this->apiPort);
314
+            $this->icinga2api=new Icinga2API($this->apiHostname, $this->apiPort);
315 315
         }
316 316
         return $this->icinga2api;
317 317
     }
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
         if ($input_stream === false)
331 331
         {
332 332
             $this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)");
333
-            $this->logging->log("Error reading stdin !",ERROR,'');
333
+            $this->logging->log("Error reading stdin !", ERROR, '');
334 334
             return null; // note : exception thrown by logging
335 335
         }
336 336
         
@@ -339,21 +339,21 @@  discard block
 block discarded – undo
339 339
         if ($this->receivingHost === false)
340 340
         {
341 341
             $this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)");
342
-            $this->logging->log("Error reading Host !",ERROR,'');
342
+            $this->logging->log("Error reading Host !", ERROR, '');
343 343
         }
344 344
         // line 2 IP:port=>IP:port
345 345
         $IP=chop(fgets($input_stream));
346 346
         if ($IP === false)
347 347
         {
348 348
             $this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)");
349
-            $this->logging->log("Error reading IP !",ERROR,'');
349
+            $this->logging->log("Error reading IP !", ERROR, '');
350 350
         }
351 351
         $matches=array();
352
-        $ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/',$IP,$matches);
353
-        if ($ret_code===0 || $ret_code===false)
352
+        $ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/', $IP, $matches);
353
+        if ($ret_code === 0 || $ret_code === false)
354 354
         {
355 355
             $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
356
-            $this->logging->log('Error parsing IP : '.$IP,ERROR,'');
356
+            $this->logging->log('Error parsing IP : '.$IP, ERROR, '');
357 357
         }
358 358
         else
359 359
         {
@@ -363,34 +363,34 @@  discard block
 block discarded – undo
363 363
             $this->trap_data['destination_port']=$matches[4];
364 364
         }
365 365
         
366
-        while (($vars=fgets($input_stream)) !==false)
366
+        while (($vars=fgets($input_stream)) !== false)
367 367
         {
368 368
             $vars=chop($vars);
369
-            $ret_code=preg_match('/^([^ ]+) (.*)$/',$vars,$matches);
370
-            if ($ret_code===0 || $ret_code===false)
369
+            $ret_code=preg_match('/^([^ ]+) (.*)$/', $vars, $matches);
370
+            if ($ret_code === 0 || $ret_code === false)
371 371
             {
372
-                $this->logging->log('No match on trap data : '.$vars,WARN,'');
372
+                $this->logging->log('No match on trap data : '.$vars, WARN, '');
373 373
             }
374 374
             else
375 375
             {
376
-                if (($matches[1]=='.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1]=='.1.3.6.1.6.3.1.1.4.1'))
376
+                if (($matches[1] == '.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1] == '.1.3.6.1.6.3.1.1.4.1'))
377 377
                 {
378 378
                     $this->trap_data['trap_oid']=$matches[2];
379 379
                 }
380 380
                 else
381 381
                 {
382
-                    $object= new stdClass;
383
-                    $object->oid =$matches[1];
384
-                    $object->value = $matches[2];
385
-                    array_push($this->trap_data_ext,$object);
382
+                    $object=new stdClass;
383
+                    $object->oid=$matches[1];
384
+                    $object->value=$matches[2];
385
+                    array_push($this->trap_data_ext, $object);
386 386
                 }
387 387
             }
388 388
         }
389 389
         
390
-        if ($this->trap_data['trap_oid']=='unknown')
390
+        if ($this->trap_data['trap_oid'] == 'unknown')
391 391
         {
392
-            $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trap_data['source_ip']);
393
-            $this->logging->log('no trap oid found',ERROR,'');
392
+            $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)", $this->trap_data['source_ip']);
393
+            $this->logging->log('no trap oid found', ERROR, '');
394 394
         }
395 395
         
396 396
         // Translate oids.
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
         }
413 413
         
414 414
         
415
-        $this->trap_data['status']= 'waiting';
415
+        $this->trap_data['status']='waiting';
416 416
         
417 417
         return $this->trap_data;
418 418
     }
@@ -428,40 +428,40 @@  discard block
 block discarded – undo
428 428
         $db_conn=$this->trapsDB->db_connect_trap();
429 429
         
430 430
         $sql='SELECT mib,name from '.$this->dbPrefix.'mib_cache WHERE oid=\''.$oid.'\';';
431
-        $this->logging->log('SQL query : '.$sql,DEBUG );
431
+        $this->logging->log('SQL query : '.$sql, DEBUG);
432 432
         if (($ret_code=$db_conn->query($sql)) === false) {
433
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
433
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
434 434
         }
435 435
         $name=$ret_code->fetch();
436 436
         if ($name['name'] != null)
437 437
         {
438
-            return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
438
+            return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
439 439
         }
440 440
         
441 441
         // Also check if it is an instance of OID
442
-        $oid_instance=preg_replace('/\.[0-9]+$/','',$oid);
442
+        $oid_instance=preg_replace('/\.[0-9]+$/', '', $oid);
443 443
         
444 444
         $sql='SELECT mib,name from '.$this->dbPrefix.'mib_cache WHERE oid=\''.$oid_instance.'\';';
445
-        $this->logging->log('SQL query : '.$sql,DEBUG );
445
+        $this->logging->log('SQL query : '.$sql, DEBUG);
446 446
         if (($ret_code=$db_conn->query($sql)) === false) {
447
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
447
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
448 448
         }
449 449
         $name=$ret_code->fetch();
450 450
         if ($name['name'] != null)
451 451
         {
452
-            return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
452
+            return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
453 453
         }
454 454
         
455 455
         // Try to get oid name from snmptranslate
456
-        $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
456
+        $translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
457 457
             ' '.$oid);
458 458
         $matches=array();
459
-        $ret_code=preg_match('/(.*)::(.*)/',$translate,$matches);
460
-        if ($ret_code===0 || $ret_code === false) {
459
+        $ret_code=preg_match('/(.*)::(.*)/', $translate, $matches);
460
+        if ($ret_code === 0 || $ret_code === false) {
461 461
             return NULL;
462 462
         } else {
463
-            $this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid,INFO);
464
-            return array('trap_name_mib'=>$matches[1],'trap_name'=>$matches[2]);
463
+            $this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid, INFO);
464
+            return array('trap_name_mib'=>$matches[1], 'trap_name'=>$matches[2]);
465 465
         }
466 466
     }
467 467
     
@@ -472,90 +472,90 @@  discard block
 block discarded – undo
472 472
      **/
473 473
     public function eraseOldTraps($days=0)
474 474
     {
475
-        if ($days==0)
475
+        if ($days == 0)
476 476
         {
477 477
             if (($days=$this->getDBConfig('db_remove_days')) == null)
478 478
             {
479
-                $this->logging->log('No days specified & no db value : no tap erase' ,WARN,'');
479
+                $this->logging->log('No days specified & no db value : no tap erase', WARN, '');
480 480
                 return;
481 481
             }
482 482
         }
483 483
         $db_conn=$this->trapsDB->db_connect_trap();
484
-        $daysago = strtotime("-".$days." day");
485
-        $sql= 'delete from '.$this->dbPrefix.'received where date_received < \''.date("Y-m-d H:i:s",$daysago).'\';';
484
+        $daysago=strtotime("-".$days." day");
485
+        $sql='delete from '.$this->dbPrefix.'received where date_received < \''.date("Y-m-d H:i:s", $daysago).'\';';
486 486
         if ($db_conn->query($sql) === false) {
487
-            $this->logging->log('Error erasing traps : '.$sql,ERROR,'');
487
+            $this->logging->log('Error erasing traps : '.$sql, ERROR, '');
488 488
         }
489
-        $this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql,INFO);
489
+        $this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql, INFO);
490 490
     }
491 491
     
492 492
     /** Write error to received trap database
493 493
      */
494
-    public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null)
494
+    public function writeTrapErrorToDB($message, $sourceIP=null, $trapoid=null)
495 495
     {
496 496
         
497 497
         $db_conn=$this->trapsDB->db_connect_trap();
498 498
         
499 499
         // add date time
500
-        $insert_col ='date_received,status';
501
-        $insert_val = "'" . date("Y-m-d H:i:s")."','error'";
500
+        $insert_col='date_received,status';
501
+        $insert_val="'".date("Y-m-d H:i:s")."','error'";
502 502
         
503
-        if ($sourceIP !=null)
503
+        if ($sourceIP != null)
504 504
         {
505
-            $insert_col .=',source_ip';
506
-            $insert_val .=",'". $sourceIP ."'";
505
+            $insert_col.=',source_ip';
506
+            $insert_val.=",'".$sourceIP."'";
507 507
         }
508
-        if ($trapoid !=null)
508
+        if ($trapoid != null)
509 509
         {
510
-            $insert_col .=',trap_oid';
511
-            $insert_val .=",'". $trapoid ."'";
510
+            $insert_col.=',trap_oid';
511
+            $insert_val.=",'".$trapoid."'";
512 512
         }
513
-        $insert_col .=',status_detail';
514
-        $insert_val .=",'". $message ."'";
513
+        $insert_col.=',status_detail';
514
+        $insert_val.=",'".$message."'";
515 515
         
516
-        $sql= 'INSERT INTO '.$this->dbPrefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
516
+        $sql='INSERT INTO '.$this->dbPrefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
517 517
         
518 518
         switch ($this->trapsDB->trapDBType)
519 519
         {
520 520
             case 'pgsql':
521
-                $sql .= ' RETURNING id;';
522
-                $this->logging->log('sql : '.$sql,INFO);
521
+                $sql.=' RETURNING id;';
522
+                $this->logging->log('sql : '.$sql, INFO);
523 523
                 if (($ret_code=$db_conn->query($sql)) === false) {
524
-                    $this->logging->log('Error SQL insert : '.$sql,1,'');
524
+                    $this->logging->log('Error SQL insert : '.$sql, 1, '');
525 525
                 }
526
-                $this->logging->log('SQL insertion OK',INFO );
526
+                $this->logging->log('SQL insertion OK', INFO);
527 527
                 // Get last id to insert oid/values in secondary table
528 528
                 if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
529 529
                     
530
-                    $this->logging->log('Erreur recuperation id',1,'');
530
+                    $this->logging->log('Erreur recuperation id', 1, '');
531 531
                 }
532
-                if (! isset($inserted_id_ret['id'])) {
533
-                    $this->logging->log('Error getting id',1,'');
532
+                if (!isset($inserted_id_ret['id'])) {
533
+                    $this->logging->log('Error getting id', 1, '');
534 534
                 }
535 535
                 $this->trap_id=$inserted_id_ret['id'];
536 536
                 break;
537 537
             case 'mysql':
538
-                $sql .= ';';
539
-                $this->logging->log('sql : '.$sql,INFO );
538
+                $sql.=';';
539
+                $this->logging->log('sql : '.$sql, INFO);
540 540
                 if ($db_conn->query($sql) === false) {
541
-                    $this->logging->log('Error SQL insert : '.$sql,1,'');
541
+                    $this->logging->log('Error SQL insert : '.$sql, 1, '');
542 542
                 }
543
-                $this->logging->log('SQL insertion OK',INFO );
543
+                $this->logging->log('SQL insertion OK', INFO);
544 544
                 // Get last id to insert oid/values in secondary table
545 545
                 $sql='SELECT LAST_INSERT_ID();';
546 546
                 if (($ret_code=$db_conn->query($sql)) === false) {
547
-                    $this->logging->log('Erreur recuperation id',1,'');
547
+                    $this->logging->log('Erreur recuperation id', 1, '');
548 548
                 }
549 549
                 
550 550
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
551
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
551
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
552 552
                 $this->trap_id=$inserted_id;
553 553
                 break;
554 554
             default:
555
-                $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType,1,'');
555
+                $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType, 1, '');
556 556
         }
557 557
         
558
-        $this->logging->log('id found: '. $this->trap_id,INFO );
558
+        $this->logging->log('id found: '.$this->trap_id, INFO);
559 559
     }
560 560
     
561 561
     /** Write trap data to trap database
@@ -572,86 +572,86 @@  discard block
 block discarded – undo
572 572
         $insert_col='';
573 573
         $insert_val='';
574 574
         // add date time
575
-        $this->trap_data['date_received'] = date("Y-m-d H:i:s");
575
+        $this->trap_data['date_received']=date("Y-m-d H:i:s");
576 576
         
577 577
         $firstcol=1;
578 578
         foreach ($this->trap_data as $col => $val)
579 579
         {
580
-            if ($firstcol==0)
580
+            if ($firstcol == 0)
581 581
             {
582
-                $insert_col .=',';
583
-                $insert_val .=',';
582
+                $insert_col.=',';
583
+                $insert_val.=',';
584 584
             }
585
-            $insert_col .= $col ;
586
-            $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
585
+            $insert_col.=$col;
586
+            $insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
587 587
             $firstcol=0;
588 588
         }
589 589
         
590
-        $sql= 'INSERT INTO '.$this->dbPrefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
590
+        $sql='INSERT INTO '.$this->dbPrefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
591 591
         switch ($this->trapsDB->trapDBType)
592 592
         {
593 593
             case 'pgsql':
594
-                $sql .= ' RETURNING id;';
595
-                $this->logging->log('sql : '.$sql,INFO );
594
+                $sql.=' RETURNING id;';
595
+                $this->logging->log('sql : '.$sql, INFO);
596 596
                 if (($ret_code=$db_conn->query($sql)) === false) {
597
-                    $this->logging->log('Error SQL insert : '.$sql,ERROR,'');
597
+                    $this->logging->log('Error SQL insert : '.$sql, ERROR, '');
598 598
                 }
599
-                $this->logging->log('SQL insertion OK',INFO );
599
+                $this->logging->log('SQL insertion OK', INFO);
600 600
                 // Get last id to insert oid/values in secondary table
601 601
                 if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
602 602
                     
603
-                    $this->logging->log('Erreur recuperation id',ERROR,'');
603
+                    $this->logging->log('Erreur recuperation id', ERROR, '');
604 604
                 }
605
-                if (! isset($inserted_id_ret['id'])) {
606
-                    $this->logging->log('Error getting id',ERROR,'');
605
+                if (!isset($inserted_id_ret['id'])) {
606
+                    $this->logging->log('Error getting id', ERROR, '');
607 607
                 }
608 608
                 $this->trap_id=$inserted_id_ret['id'];
609 609
                 break;
610 610
             case 'mysql':
611
-                $sql .= ';';
612
-                $this->logging->log('sql : '.$sql,INFO );
611
+                $sql.=';';
612
+                $this->logging->log('sql : '.$sql, INFO);
613 613
                 if ($db_conn->query($sql) === false) {
614
-                    $this->logging->log('Error SQL insert : '.$sql,ERROR,'');
614
+                    $this->logging->log('Error SQL insert : '.$sql, ERROR, '');
615 615
                 }
616
-                $this->logging->log('SQL insertion OK',INFO );
616
+                $this->logging->log('SQL insertion OK', INFO);
617 617
                 // Get last id to insert oid/values in secondary table
618 618
                 $sql='SELECT LAST_INSERT_ID();';
619 619
                 if (($ret_code=$db_conn->query($sql)) === false) {
620
-                    $this->logging->log('Erreur recuperation id',ERROR,'');
620
+                    $this->logging->log('Erreur recuperation id', ERROR, '');
621 621
                 }
622 622
                 
623 623
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
624
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
624
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
625 625
                 $this->trap_id=$inserted_id;
626 626
                 break;
627 627
             default:
628
-                $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType,ERROR,'');
628
+                $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType, ERROR, '');
629 629
         }
630
-        $this->logging->log('id found: '.$this->trap_id,INFO );
630
+        $this->logging->log('id found: '.$this->trap_id, INFO);
631 631
         
632 632
         // Fill trap extended data table
633 633
         foreach ($this->trap_data_ext as $value) {
634 634
             // TODO : detect if trap value is encoded and decode it to UTF-8 for database
635 635
             $firstcol=1;
636
-            $value->trap_id = $this->trap_id;
636
+            $value->trap_id=$this->trap_id;
637 637
             $insert_col='';
638 638
             $insert_val='';
639 639
             foreach ($value as $col => $val)
640 640
             {
641
-                if ($firstcol==0)
641
+                if ($firstcol == 0)
642 642
                 {
643
-                    $insert_col .=',';
644
-                    $insert_val .=',';
643
+                    $insert_col.=',';
644
+                    $insert_val.=',';
645 645
                 }
646
-                $insert_col .= $col;
647
-                $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
646
+                $insert_col.=$col;
647
+                $insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
648 648
                 $firstcol=0;
649 649
             }
650 650
             
651
-            $sql= 'INSERT INTO '.$this->dbPrefix.'received_data (' . $insert_col . ') VALUES ('.$insert_val.');';
651
+            $sql='INSERT INTO '.$this->dbPrefix.'received_data ('.$insert_col.') VALUES ('.$insert_val.');';
652 652
             
653 653
             if ($db_conn->query($sql) === false) {
654
-                $this->logging->log('Erreur insertion data : ' . $sql,WARN,'');
654
+                $this->logging->log('Erreur insertion data : '.$sql, WARN, '');
655 655
             }
656 656
         }
657 657
     }
@@ -661,14 +661,14 @@  discard block
 block discarded – undo
661 661
      *	@param $oid string oid in numeric
662 662
      *	@return mixed|boolean : PDO object or false
663 663
      */
664
-    protected function getRules($ip,$oid)
664
+    protected function getRules($ip, $oid)
665 665
     {
666 666
         $db_conn=$this->trapsDB->db_connect_trap();
667 667
         // fetch rules based on IP in rule and OID
668 668
         $sql='SELECT * from '.$this->dbPrefix.'rules WHERE trap_oid=\''.$oid.'\' ';
669
-        $this->logging->log('SQL query : '.$sql,DEBUG );
669
+        $this->logging->log('SQL query : '.$sql, DEBUG);
670 670
         if (($ret_code=$db_conn->query($sql)) === false) {
671
-            $this->logging->log('No result in query : ' . $sql,WARN,'');
671
+            $this->logging->log('No result in query : '.$sql, WARN, '');
672 672
             return false;
673 673
         }
674 674
         $rules_all=$ret_code->fetchAll();
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
         $rule_ret_key=0;
678 678
         foreach ($rules_all as $key => $rule)
679 679
         {
680
-            if ($rule['ip4']==$ip || $rule['ip6']==$ip)
680
+            if ($rule['ip4'] == $ip || $rule['ip6'] == $ip)
681 681
             {
682 682
                 $rules_ret[$rule_ret_key]=$rules_all[$key];
683 683
                 //TODO : get host name by API (and check if correct in rule).
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
                 continue;
686 686
             }
687 687
             // TODO : get hosts IP by API
688
-            if (isset($rule['host_group_name']) && $rule['host_group_name']!=null)
688
+            if (isset($rule['host_group_name']) && $rule['host_group_name'] != null)
689 689
             { // get ips of group members by oid
690 690
                 $db_conn2=$this->trapsDB->db_connect_ido();
691 691
                 $sql="SELECT m.host_object_id, a.address as ip4, a.address6 as ip6, b.name1 as host_name
@@ -696,15 +696,15 @@  discard block
 block discarded – undo
696 696
 						LEFT JOIN icinga_objects as b ON b.object_id = a.host_object_id
697 697
 						WHERE o.name1='".$rule['host_group_name']."';";
698 698
                 if (($ret_code2=$db_conn2->query($sql)) === false) {
699
-                    $this->logging->log('No result in query : ' . $sql,WARN,'');
699
+                    $this->logging->log('No result in query : '.$sql, WARN, '');
700 700
                     continue;
701 701
                 }
702 702
                 $grouphosts=$ret_code2->fetchAll();
703 703
                 //echo "rule grp :\n";print_r($grouphosts);echo "\n";
704
-                foreach ( $grouphosts as $host)
704
+                foreach ($grouphosts as $host)
705 705
                 {
706 706
                     //echo $host['ip4']."\n";
707
-                    if ($host['ip4']==$ip || $host['ip6']==$ip)
707
+                    if ($host['ip4'] == $ip || $host['ip6'] == $ip)
708 708
                     {
709 709
                         //echo "Rule added \n";
710 710
                         $rules_ret[$rule_ret_key]=$rules_all[$key];
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
         $db_conn=$this->trapsDB->db_connect_trap();
728 728
         $sql="UPDATE ".$this->dbPrefix."rules SET num_match = '".$set."' WHERE (id = '".$id."');";
729 729
         if ($db_conn->query($sql) === false) {
730
-            $this->logging->log('Error in update query : ' . $sql,WARN,'');
730
+            $this->logging->log('Error in update query : '.$sql, WARN, '');
731 731
         }
732 732
     }
733 733
     
@@ -739,23 +739,23 @@  discard block
 block discarded – undo
739 739
      * @param string $display
740 740
      * @returnn bool true is service check was sent without error
741 741
      */
742
-    public function serviceCheckResult($host,$service,$state,$display)
742
+    public function serviceCheckResult($host, $service, $state, $display)
743 743
     {
744 744
         if ($this->apiUse === false)
745 745
         {
746
-            $send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' .
747
-                $host.';' .$service .';' . $state . ';'.$display;
748
-                $this->logging->log( $send." : to : " .$this->icinga2cmd,INFO );
746
+            $send='['.date('U').'] PROCESS_SERVICE_CHECK_RESULT;'.
747
+                $host.';'.$service.';'.$state.';'.$display;
748
+                $this->logging->log($send." : to : ".$this->icinga2cmd, INFO);
749 749
                 
750 750
                 // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
751
-                exec('echo "'.$send.'" > ' .$this->icinga2cmd);
751
+                exec('echo "'.$send.'" > '.$this->icinga2cmd);
752 752
                 return true;
753 753
         }
754 754
         else
755 755
         {
756 756
             // Get perfdata if found
757 757
             $matches=array();
758
-            if (preg_match('/(.*)\|(.*)/',$display,$matches) == 1)
758
+            if (preg_match('/(.*)\|(.*)/', $display, $matches) == 1)
759 759
             {
760 760
                 $display=$matches[1];
761 761
                 $perfdata=$matches[2];
@@ -765,17 +765,17 @@  discard block
 block discarded – undo
765 765
                 $perfdata='';
766 766
             }
767 767
             
768
-            $api = $this->getAPI();
768
+            $api=$this->getAPI();
769 769
             $api->setCredentials($this->apiUsername, $this->apiPassword);
770
-            list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display,$perfdata);
770
+            list($retcode, $retmessage)=$api->serviceCheckResult($host, $service, $state, $display, $perfdata);
771 771
             if ($retcode == false)
772 772
             {
773
-                $this->logging->log( "Error sending result : " .$retmessage,WARN,'');
773
+                $this->logging->log("Error sending result : ".$retmessage, WARN, '');
774 774
                 return false;
775 775
             }
776 776
             else
777 777
             {
778
-                $this->logging->log( "Sent result : " .$retmessage,INFO );
778
+                $this->logging->log("Sent result : ".$retmessage, INFO);
779 779
                 return true;
780 780
             }
781 781
         }
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
     
784 784
     public function getHostByIP($ip)
785 785
     {
786
-        $api = $this->getAPI();
786
+        $api=$this->getAPI();
787 787
         $api->setCredentials($this->apiUsername, $this->apiPassword);
788 788
         return $api->getHostByIP($ip);
789 789
     }
@@ -796,32 +796,32 @@  discard block
 block discarded – undo
796 796
     protected function applyDisplay($display)
797 797
     {
798 798
         $matches=array();
799
-        while (preg_match('/_OID\(([0-9\.]+)\)/',$display,$matches) == 1)
799
+        while (preg_match('/_OID\(([0-9\.]+)\)/', $display, $matches) == 1)
800 800
         {
801 801
             $oid=$matches[1];
802 802
             $found=0;
803
-            foreach($this->trap_data_ext as $val)
803
+            foreach ($this->trap_data_ext as $val)
804 804
             {
805 805
                 if ($oid == $val->oid)
806 806
                 {
807
-                    $val->value=preg_replace('/"/','',$val->value);
807
+                    $val->value=preg_replace('/"/', '', $val->value);
808 808
                     $rep=0;
809
-                    $display=preg_replace('/_OID\('.$oid.'\)/',$val->value,$display,-1,$rep);
810
-                    if ($rep==0)
809
+                    $display=preg_replace('/_OID\('.$oid.'\)/', $val->value, $display, -1, $rep);
810
+                    if ($rep == 0)
811 811
                     {
812
-                        $this->logging->log("Error in display",WARN,'');
812
+                        $this->logging->log("Error in display", WARN, '');
813 813
                         return $display;
814 814
                     }
815 815
                     $found=1;
816 816
                     break;
817 817
                 }
818 818
             }
819
-            if ($found==0)
819
+            if ($found == 0)
820 820
             {
821
-                $display=preg_replace('/_OID\('.$oid.'\)/','<not in trap>',$display,-1,$rep);
822
-                if ($rep==0)
821
+                $display=preg_replace('/_OID\('.$oid.'\)/', '<not in trap>', $display, -1, $rep);
822
+                if ($rep == 0)
823 823
                 {
824
-                    $this->logging->log("Error in display",WARN,'');
824
+                    $this->logging->log("Error in display", WARN, '');
825 825
                     return $display;
826 826
                 }
827 827
             }
@@ -833,11 +833,11 @@  discard block
 block discarded – undo
833 833
      */
834 834
     public function applyRules()
835 835
     {
836
-        $rules = $this->getRules($this->trap_data['source_ip'],$this->trap_data['trap_oid']);
836
+        $rules=$this->getRules($this->trap_data['source_ip'], $this->trap_data['trap_oid']);
837 837
         
838
-        if ($rules===false || count($rules)==0)
838
+        if ($rules === false || count($rules) == 0)
839 839
         {
840
-            $this->logging->log('No rules found for this trap',INFO );
840
+            $this->logging->log('No rules found for this trap', INFO);
841 841
             $this->trap_data['status']='unknown';
842 842
             $this->trap_to_db=true;
843 843
             return;
@@ -852,59 +852,59 @@  discard block
 block discarded – undo
852 852
             $service_name=$rule['service_name'];
853 853
             
854 854
             $display=$this->applyDisplay($rule['display']);
855
-            $this->trap_action = ($this->trap_action==null)? '' : $this->trap_action . ', ';
855
+            $this->trap_action=($this->trap_action == null) ? '' : $this->trap_action.', ';
856 856
             try
857 857
             {
858
-                $this->logging->log('Rule to eval : '.$rule['rule'],INFO );
859
-                $evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trap_data_ext) ;
858
+                $this->logging->log('Rule to eval : '.$rule['rule'], INFO);
859
+                $evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trap_data_ext);
860 860
                 //->eval_rule($rule['rule']);
861 861
                 
862 862
                 if ($evalr == true)
863 863
                 {
864 864
                     //$this->logging->log('rules OOK: '.print_r($rule),INFO );
865 865
                     $action=$rule['action_match'];
866
-                    $this->logging->log('action OK : '.$action,INFO );
866
+                    $this->logging->log('action OK : '.$action, INFO);
867 867
                     if ($action >= 0)
868 868
                     {
869
-                        if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
869
+                        if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
870 870
                         {
871 871
                             $this->trap_action.='Error sending status : check cmd/API';
872 872
                         }
873 873
                         else
874 874
                         {
875
-                            $this->add_rule_match($rule['id'],$rule['num_match']+1);
875
+                            $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
876 876
                             $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
877 877
                         }
878 878
                     }
879 879
                     else
880 880
                     {
881
-                        $this->add_rule_match($rule['id'],$rule['num_match']+1);
881
+                        $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
882 882
                     }
883
-                    $this->trap_to_db=($action==-2)?false:true;
883
+                    $this->trap_to_db=($action == -2) ?false:true;
884 884
                 }
885 885
                 else
886 886
                 {
887 887
                     //$this->logging->log('rules KOO : '.print_r($rule),INFO );
888 888
                     
889 889
                     $action=$rule['action_nomatch'];
890
-                    $this->logging->log('action NOK : '.$action,INFO );
890
+                    $this->logging->log('action NOK : '.$action, INFO);
891 891
                     if ($action >= 0)
892 892
                     {
893
-                        if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
893
+                        if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
894 894
                         {
895 895
                             $this->trap_action.='Error sending status : check cmd/API';
896 896
                         }
897 897
                         else
898 898
                         {
899
-                            $this->add_rule_match($rule['id'],$rule['num_match']+1);
899
+                            $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
900 900
                             $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
901 901
                         }
902 902
                     }
903 903
                     else
904 904
                     {
905
-                        $this->add_rule_match($rule['id'],$rule['num_match']+1);
905
+                        $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
906 906
                     }
907
-                    $this->trap_to_db=($action==-2)?false:true;
907
+                    $this->trap_to_db=($action == -2) ?false:true;
908 908
                 }
909 909
                 // Put name in source_name
910 910
                 if (!isset($this->trap_data['source_name']))
@@ -913,7 +913,7 @@  discard block
 block discarded – undo
913 913
                 }
914 914
                 else
915 915
                 {
916
-                    if (!preg_match('/'.$rule['host_name'].'/',$this->trap_data['source_name']))
916
+                    if (!preg_match('/'.$rule['host_name'].'/', $this->trap_data['source_name']))
917 917
                     { // only add if not present
918 918
                         $this->trap_data['source_name'].=','.$rule['host_name'];
919 919
                     }
@@ -921,13 +921,13 @@  discard block
 block discarded – undo
921 921
             }
922 922
             catch (Exception $e)
923 923
             {
924
-                $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
924
+                $this->logging->log('Error in rule eval : '.$e->getMessage(), WARN, '');
925 925
                 $this->trap_action.=' ERR : '.$e->getMessage();
926 926
                 $this->trap_data['status']='error';
927 927
             }
928 928
             
929 929
         }
930
-        if ($this->trap_data['status']=='error')
930
+        if ($this->trap_data['status'] == 'error')
931 931
         {
932 932
             $this->trap_to_db=true; // Always put errors in DB for the use can see
933 933
         }
@@ -943,13 +943,13 @@  discard block
 block discarded – undo
943 943
     public function add_rule_final($time)
944 944
     {
945 945
         $db_conn=$this->trapsDB->db_connect_trap();
946
-        if ($this->trap_action==null)
946
+        if ($this->trap_action == null)
947 947
         {
948 948
             $this->trap_action='No action';
949 949
         }
950 950
         $sql="UPDATE ".$this->dbPrefix."received SET process_time = '".$time."' , status_detail='".$this->trap_action."'  WHERE (id = '".$this->trap_id."');";
951 951
         if ($db_conn->query($sql) === false) {
952
-            $this->logging->log('Error in update query : ' . $sql,WARN,'');
952
+            $this->logging->log('Error in update query : '.$sql, WARN, '');
953 953
         }
954 954
     }
955 955
     
@@ -972,7 +972,7 @@  discard block
 block discarded – undo
972 972
     WHERE s.current_state != 0;";
973 973
         $db_conn=$this->trapsDB->db_connect_ido();
974 974
         if (($services_db=$db_conn->query($sql_query)) === false) { // set err to 1 to throw exception.
975
-            $this->logging->log('No result in query : ' . $sql_query,ERROR,'');
975
+            $this->logging->log('No result in query : '.$sql_query, ERROR, '');
976 976
             return 0;
977 977
         }
978 978
         $services=$services_db->fetchAll();
@@ -981,7 +981,7 @@  discard block
 block discarded – undo
981 981
         $sql_query="SELECT host_name, service_name, revert_ok FROM ".$this->dbPrefix."rules where revert_ok != 0;";
982 982
         $db_conn2=$this->trapsDB->db_connect_trap();
983 983
         if (($rules_db=$db_conn2->query($sql_query)) === false) {
984
-            $this->logging->log('No result in query : ' . $sql_query,ERROR,'');
984
+            $this->logging->log('No result in query : '.$sql_query, ERROR, '');
985 985
             return 0;
986 986
         }
987 987
         $rules=$rules_db->fetchAll();
@@ -997,13 +997,13 @@  discard block
 block discarded – undo
997 997
                     $service['host_name'] == $rule['host_name'] &&
998 998
                     ($service['last_check'] + $rule['revert_ok']) < $now)
999 999
                 {
1000
-                    $this->serviceCheckResult($service['host_name'],$service['service_name'],0,'Reset service to OK after '.$rule['revert_ok'].' seconds');
1000
+                    $this->serviceCheckResult($service['host_name'], $service['service_name'], 0, 'Reset service to OK after '.$rule['revert_ok'].' seconds');
1001 1001
                     $numreset++;
1002 1002
                 }
1003 1003
             }
1004 1004
         }
1005 1005
         echo "\n";
1006
-        echo $numreset . " service(s) reset to OK\n";
1006
+        echo $numreset." service(s) reset to OK\n";
1007 1007
         return 0;
1008 1008
         
1009 1009
     }
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/Plugins.php 1 patch
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      * $pluginsList[plugin name]['target']  : bool true if plugin can be trap processing target
25 25
      * $pluginsList[plugin name]['enabled'] : bool true if plugin is in enabled list 
26 26
      **/
27
-    protected $pluginsList = array();
27
+    protected $pluginsList=array();
28 28
 
29 29
     /** Array of functions names
30 30
      * @var array $functionList 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      * @param string $plugin_dir optional plugin directory
52 52
      * @throws \Exception
53 53
      */
54
-    function __construct(Trap $trapClass,string $pluginDir='')
54
+    function __construct(Trap $trapClass, string $pluginDir='')
55 55
     {
56 56
         if ($pluginDir == '')
57 57
         {
@@ -88,42 +88,42 @@  discard block
 block discarded – undo
88 88
      */
89 89
     private function loadEnabledPlugins()
90 90
     {
91
-        $PluginList = $this->trapClass->trapsDB->getDBConfig('enabled_plugins');
91
+        $PluginList=$this->trapClass->trapsDB->getDBConfig('enabled_plugins');
92 92
                
93 93
         if ($PluginList === null || $PluginList == '')
94 94
         {
95
-            $this->logClass->log('No enabled plugins',DEBUG);
95
+            $this->logClass->log('No enabled plugins', DEBUG);
96 96
             return;
97 97
         }
98 98
         else
99 99
         {   // Saved config : <plugin name>;<Catch all OID ? 1|0>;<Trap target ? 1|0>;<func 1 name>|<func 2 name>... ,<plugin2 name>....
100
-            $this->logClass->log('Enabled plugins = '.$PluginList,DEBUG);
100
+            $this->logClass->log('Enabled plugins = '.$PluginList, DEBUG);
101 101
             
102
-            $pluginArray = explode(',', $PluginList);
102
+            $pluginArray=explode(',', $PluginList);
103 103
             foreach ($pluginArray as $pluginElmt)
104 104
             {
105
-                $pluginElmt = explode(';',$pluginElmt);
105
+                $pluginElmt=explode(';', $pluginElmt);
106 106
                 if ($pluginElmt === false || count($pluginElmt) != 4)
107 107
                 {
108
-                    throw new \Exception('Invalid plugin configuration : '. $PluginList );
108
+                    throw new \Exception('Invalid plugin configuration : '.$PluginList);
109 109
                 }
110 110
                 $pluginName=$pluginElmt[0];
111 111
                 
112
-                $pluginListElmt = array();
113
-                $pluginListElmt['object'] = null; // class not loaded
114
-                $pluginListElmt['allOID'] = ($pluginElmt[1]=='1') ? true : false;
115
-                $pluginListElmt['target'] = ($pluginElmt[2]=='1') ? true : false;
116
-                $pluginListElmt['enabled'] = true;
112
+                $pluginListElmt=array();
113
+                $pluginListElmt['object']=null; // class not loaded
114
+                $pluginListElmt['allOID']=($pluginElmt[1] == '1') ? true : false;
115
+                $pluginListElmt['target']=($pluginElmt[2] == '1') ? true : false;
116
+                $pluginListElmt['enabled']=true;
117 117
                 
118
-                $this->pluginsList[$pluginName] = $pluginListElmt;
118
+                $this->pluginsList[$pluginName]=$pluginListElmt;
119 119
                 
120 120
                 // deal with plugin functions
121
-                $pluginFunctions = explode('|',$pluginElmt[3]);
121
+                $pluginFunctions=explode('|', $pluginElmt[3]);
122 122
                 if ($pluginFunctions !== false)
123 123
                 {
124 124
                     foreach ($pluginFunctions as $function)
125 125
                     {
126
-                        $this->functionList[$function] = array(
126
+                        $this->functionList[$function]=array(
127 127
                             'plugin'    =>   $pluginName,
128 128
                             'function'  =>  null
129 129
                         );
@@ -155,16 +155,16 @@  discard block
 block discarded – undo
155 155
                 {
156 156
                     continue;
157 157
                 }
158
-                $functionString .= ($functionString == '') ? '' : '|'; // add separator if not empty
159
-                $functionString .= $fName;
158
+                $functionString.=($functionString == '') ? '' : '|'; // add separator if not empty
159
+                $functionString.=$fName;
160 160
             }
161
-            $saveString .= ($saveString == '')?'':',' ;
161
+            $saveString.=($saveString == '') ? '' : ',';
162 162
             
163
-            $allOID = ($value['allOID'] === true) ? 1 : 0;
164
-            $target = ($value['target'] === true) ? 1 : 0;
165
-            $saveString .= $name . ';' . $allOID . ';' . $target . ';' . $functionString ;
163
+            $allOID=($value['allOID'] === true) ? 1 : 0;
164
+            $target=($value['target'] === true) ? 1 : 0;
165
+            $saveString.=$name.';'.$allOID.';'.$target.';'.$functionString;
166 166
         }
167
-        $this->logClass->log('Saving : ' . $saveString,DEBUG);
167
+        $this->logClass->log('Saving : '.$saveString, DEBUG);
168 168
         return $this->trapClass->trapsDB->setDBConfig('enabled_plugins', $saveString);
169 169
     }
170 170
     
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
         {
179 179
             if ($value['enabled'] == true)
180 180
             {
181
-                array_push($retArray,$name);
181
+                array_push($retArray, $name);
182 182
             }
183 183
         }
184 184
         return $retArray;
@@ -190,29 +190,29 @@  discard block
 block discarded – undo
190 190
      * @param bool $enabled true to enable, false to disable
191 191
      * @return bool true if OK, or false (error logged)
192 192
      */
193
-    public function enablePlugin(string $pluginName,bool $enabled)
193
+    public function enablePlugin(string $pluginName, bool $enabled)
194 194
     {
195 195
         if ($enabled === false)
196 196
         {
197 197
             // If plugin is defined set to disable
198
-            if ( isset($this->pluginsList[$pluginName]))
198
+            if (isset($this->pluginsList[$pluginName]))
199 199
             {
200
-                $this->pluginsList[$pluginName]['enabled'] = false;
200
+                $this->pluginsList[$pluginName]['enabled']=false;
201 201
             }            
202 202
             return $this->saveEnabledPlugins();
203 203
         }
204 204
         // Check if plugin is loaded / exists
205
-        if ( ! isset($this->pluginsList[$pluginName]) || 
205
+        if (!isset($this->pluginsList[$pluginName]) || 
206 206
                 $this->pluginsList[$pluginName]['object'] === null)
207 207
         {
208 208
             try {
209 209
                 $this->registerPlugin($pluginName);
210 210
             } catch (Exception $e) {
211
-                $this->logClass->log('Cannot enable plugin : ' . $e->getMessage(),WARN);
211
+                $this->logClass->log('Cannot enable plugin : '.$e->getMessage(), WARN);
212 212
                 return false;
213 213
             }
214 214
         }
215
-        $this->pluginsList[$pluginName]['enabled'] = true;
215
+        $this->pluginsList[$pluginName]['enabled']=true;
216 216
         // save in DB and return 
217 217
         return $this->saveEnabledPlugins();
218 218
     }
@@ -233,12 +233,12 @@  discard block
 block discarded – undo
233 233
      */
234 234
     public function registerPlugin(string $pluginName)
235 235
     {
236
-        if ( ! isset($this->pluginsList[$pluginName]) ) // Plugin isn't enable, create entry
236
+        if (!isset($this->pluginsList[$pluginName])) // Plugin isn't enable, create entry
237 237
         {
238
-            $pluginListElmt = array();
239
-            $pluginListElmt['object'] = null; // class not loaded
240
-            $pluginListElmt['enabled'] = false;
241
-            $this->pluginsList[$pluginName] = $pluginListElmt;
238
+            $pluginListElmt=array();
239
+            $pluginListElmt['object']=null; // class not loaded
240
+            $pluginListElmt['enabled']=false;
241
+            $this->pluginsList[$pluginName]=$pluginListElmt;
242 242
         }
243 243
         
244 244
         if ($this->pluginsList[$pluginName]['object'] !== null)
@@ -247,13 +247,13 @@  discard block
 block discarded – undo
247 247
         }
248 248
         try {
249 249
             // Include plugin file
250
-            include_once($this->pluginDir.'/' . $pluginName . '.php');
250
+            include_once($this->pluginDir.'/'.$pluginName.'.php');
251 251
             
252 252
             // Create full class name with namespace
253
-            $pluginClassName = __NAMESPACE__ . '\\Plugins\\' . $pluginName;
253
+            $pluginClassName=__NAMESPACE__.'\\Plugins\\'.$pluginName;
254 254
             
255 255
             // Create class
256
-            $newClass = new $pluginClassName();
256
+            $newClass=new $pluginClassName();
257 257
             
258 258
             // Set logging
259 259
             $newClass->setLoggingClass($this->logClass);
@@ -276,33 +276,33 @@  discard block
 block discarded – undo
276 276
             {
277 277
                 if (isset($this->functionList[$fname]))
278 278
                 {
279
-                    if ($this->functionList[$fname]['plugin'] != $pluginName )
279
+                    if ($this->functionList[$fname]['plugin'] != $pluginName)
280 280
                     {
281
-                        throw new Exception('Duplicate function name '.$fname . ' in ' 
282
-                            . $pluginName . ' and ' . $this->functionList[$fname]['plugin']);
281
+                        throw new Exception('Duplicate function name '.$fname.' in ' 
282
+                            . $pluginName.' and '.$this->functionList[$fname]['plugin']);
283 283
                     }
284 284
                     
285 285
                 }
286 286
                 else
287 287
                 {
288 288
                     $this->functionList[$fname]=array();
289
-                    $this->functionList[$fname]['plugin'] = $pluginName;
289
+                    $this->functionList[$fname]['plugin']=$pluginName;
290 290
                 }
291 291
                 $this->functionList[$fname]['function']=$function['function'];
292 292
             }
293
-            $this->logClass->log('Registered plugin '.$pluginName,DEBUG);
293
+            $this->logClass->log('Registered plugin '.$pluginName, DEBUG);
294 294
             
295 295
         } catch (Exception $e) {
296 296
             unset($this->pluginsList[$pluginName]);
297
-            $errorMessage = "Error registering plugin $pluginName : ".$e->getMessage();
298
-            $this->logClass->log($errorMessage,WARN);
297
+            $errorMessage="Error registering plugin $pluginName : ".$e->getMessage();
298
+            $this->logClass->log($errorMessage, WARN);
299 299
             // Disable the plugin
300 300
             $this->enablePlugin($pluginName, false);
301 301
             throw new \Exception($errorMessage);
302 302
         } catch (Throwable $t) {
303 303
             unset($this->pluginsList[$pluginName]);
304
-            $errorMessage = $t->getMessage() . ' in file ' . $t->getFile() . ' line ' . $t->getLine();
305
-            $this->logClass->log($errorMessage,WARN);
304
+            $errorMessage=$t->getMessage().' in file '.$t->getFile().' line '.$t->getLine();
305
+            $this->logClass->log($errorMessage, WARN);
306 306
             // Disable the plugin
307 307
             $this->enablePlugin($pluginName, false);
308 308
             throw new \Exception($errorMessage);
@@ -323,24 +323,24 @@  discard block
 block discarded – undo
323 323
             try {
324 324
                 $this->registerPlugin($pluginName);
325 325
             } catch (Exception $e) {
326
-                $retDisplay .= $e->getMessage() . ' / ';
326
+                $retDisplay.=$e->getMessage().' / ';
327 327
             }
328 328
         }
329 329
         if ($checkEnabled === false) // Load all php files in plugin dir
330 330
         {
331 331
             foreach (glob($this->pluginDir."/*.php") as $filename)
332 332
             {             
333
-                $pluginName=basename($filename,'.php');
334
-                if (!preg_match('/^[a-zA-Z0-9]+$/',$pluginName))
333
+                $pluginName=basename($filename, '.php');
334
+                if (!preg_match('/^[a-zA-Z0-9]+$/', $pluginName))
335 335
                 {
336 336
                     $this->logClass->log("Invalid plugin name : ".$pluginName, WARN);
337
-                    $retDisplay .= "Invalid plugin name : ".$pluginName . " / ";
337
+                    $retDisplay.="Invalid plugin name : ".$pluginName." / ";
338 338
                     break;
339 339
                 }
340 340
                 try { // Already registerd plugin will simply return false
341 341
                     $this->registerPlugin($pluginName);               
342 342
                 } catch (Exception $e) {
343
-                    $retDisplay .= $e->getMessage() . ' / ';
343
+                    $retDisplay.=$e->getMessage().' / ';
344 344
                 }
345 345
             }
346 346
         }
@@ -380,17 +380,17 @@  discard block
 block discarded – undo
380 380
         {
381 381
             $this->registerPlugin($name); // can throw exception handled by caller
382 382
         }
383
-        $retObj = new stdClass();
384
-        $retObj->name           = $name;
385
-        $retObj->catchAllTraps  = $this->pluginsList[$name]['allOID'];
386
-        $retObj->processTraps   = $this->pluginsList[$name]['target'];
387
-        $retObj->description    = $this->pluginsList[$name]['object']->description;
383
+        $retObj=new stdClass();
384
+        $retObj->name=$name;
385
+        $retObj->catchAllTraps=$this->pluginsList[$name]['allOID'];
386
+        $retObj->processTraps=$this->pluginsList[$name]['target'];
387
+        $retObj->description=$this->pluginsList[$name]['object']->description;
388 388
         $functions=array();
389 389
         foreach ($this->functionList as $fName => $func)
390 390
         {
391 391
             if ($func['plugin'] == $name)
392 392
             {
393
-                array_push($functions,$fName);
393
+                array_push($functions, $fName);
394 394
             }
395 395
         }
396 396
         $retObj->funcArray=$functions;
@@ -403,13 +403,13 @@  discard block
 block discarded – undo
403 403
      * @param string $pluginName
404 404
      * @return boolean returns plugin object of false;
405 405
      */
406
-    public function getFunction($funcName,&$pluginName)
406
+    public function getFunction($funcName, &$pluginName)
407 407
     {
408
-        if (! isset($this->functionList[$funcName]) )
408
+        if (!isset($this->functionList[$funcName]))
409 409
         {
410 410
             return false;
411 411
         }
412
-        $pluginName = $this->functionList[$funcName]['plugin'];
412
+        $pluginName=$this->functionList[$funcName]['plugin'];
413 413
         return true;
414 414
     }
415 415
     
@@ -421,21 +421,21 @@  discard block
 block discarded – undo
421 421
      */
422 422
     public function getFunctionDetails($funcName)
423 423
     {
424
-        if (! isset($this->functionList[$funcName]) )
424
+        if (!isset($this->functionList[$funcName]))
425 425
         {
426 426
             return false;
427 427
         }
428
-        $pluginName = $this->functionList[$funcName]['plugin']; // plugin name
429
-        $plugin = $this->pluginsList[$pluginName]['object']; // plugin object
428
+        $pluginName=$this->functionList[$funcName]['plugin']; // plugin name
429
+        $plugin=$this->pluginsList[$pluginName]['object']; // plugin object
430 430
         if ($plugin === null)
431 431
         {
432 432
             $this->registerPlugin($pluginName); // can throw exception handled by caller
433 433
         }
434
-        $retObj = new stdClass();
435
-        $retObj->name           = $funcName;
436
-        $retObj->plugin         = $pluginName;
437
-        $retObj->params         = $plugin->functions[$funcName]['params'];
438
-        $retObj->description    = $plugin->functions[$funcName]['description'];
434
+        $retObj=new stdClass();
435
+        $retObj->name=$funcName;
436
+        $retObj->plugin=$pluginName;
437
+        $retObj->params=$plugin->functions[$funcName]['params'];
438
+        $retObj->description=$plugin->functions[$funcName]['description'];
439 439
         return $retObj;
440 440
     }
441 441
     
@@ -446,23 +446,23 @@  discard block
 block discarded – undo
446 446
      * @throws Exception
447 447
      * @return bool
448 448
      */
449
-    public function getFunctionEval(string $funcName,$params) : bool
449
+    public function getFunctionEval(string $funcName, $params) : bool
450 450
     {
451
-        if (! isset($this->functionList[$funcName]) )
451
+        if (!isset($this->functionList[$funcName]))
452 452
         {
453
-            throw new Exception($funcName . ' not found.');
453
+            throw new Exception($funcName.' not found.');
454 454
         }
455
-        $pluginName = $this->functionList[$funcName]['plugin']; // plugin name
456
-        $plugin = $this->pluginsList[$pluginName]['object']; // plugin object
455
+        $pluginName=$this->functionList[$funcName]['plugin']; // plugin name
456
+        $plugin=$this->pluginsList[$pluginName]['object']; // plugin object
457 457
 
458 458
         if ($plugin === null)
459 459
         {
460 460
             $this->registerPlugin($pluginName); // can throw exception handled by caller
461
-            $plugin = $this->pluginsList[$pluginName]['object'];
461
+            $plugin=$this->pluginsList[$pluginName]['object'];
462 462
         }
463 463
         
464
-        $propertyName = $this->functionList[$funcName]['function'];
465
-        $this->logClass->log('Using property '. $propertyName . ' of class : '.$pluginName,DEBUG);
464
+        $propertyName=$this->functionList[$funcName]['function'];
465
+        $this->logClass->log('Using property '.$propertyName.' of class : '.$pluginName, DEBUG);
466 466
         
467 467
         return $plugin->{$propertyName}($params);        
468 468
     }
@@ -471,21 +471,21 @@  discard block
 block discarded – undo
471 471
     {
472 472
         $matches=array();
473 473
         // Cleanup spaces
474
-        $functionString = $this->trapClass->ruleClass->eval_cleanup($functionString);
475
-        $this->logClass->log('eval cleanup : '.$functionString,DEBUG);
474
+        $functionString=$this->trapClass->ruleClass->eval_cleanup($functionString);
475
+        $this->logClass->log('eval cleanup : '.$functionString, DEBUG);
476 476
         
477 477
         // Match function call
478
-        $num=preg_match('/^__([a-zA-Z0-9]+)\((.+)\)$/', $functionString , $matches);
479
-        if ($num !=1)
478
+        $num=preg_match('/^__([a-zA-Z0-9]+)\((.+)\)$/', $functionString, $matches);
479
+        if ($num != 1)
480 480
         {
481
-            throw new \ErrorException('Function syntax error : ' . $functionString );
481
+            throw new \ErrorException('Function syntax error : '.$functionString);
482 482
         }
483
-        $this->logClass->log('Got function : '. $matches[1] . ', params : '.$matches[2],DEBUG);
483
+        $this->logClass->log('Got function : '.$matches[1].', params : '.$matches[2], DEBUG);
484 484
         $funcName=$matches[1];
485 485
         
486 486
         // Get parameters comma separated
487
-        $funcParams=str_getcsv($matches[2],',','"',"\\");
488
-        $this->logClass->log('Function params : ' . print_r($funcParams,true),DEBUG);
487
+        $funcParams=str_getcsv($matches[2], ',', '"', "\\");
488
+        $this->logClass->log('Function params : '.print_r($funcParams, true), DEBUG);
489 489
         
490 490
         // return evaluation
491 491
         return $this->getFunctionEval($funcName, $funcParams);        
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
      */
521 521
     public function setLoggingClass($loggingClass)
522 522
     {
523
-        $this->loggingClass = $loggingClass;
523
+        $this->loggingClass=$loggingClass;
524 524
     }
525 525
     
526 526
     /**
@@ -528,8 +528,8 @@  discard block
 block discarded – undo
528 528
      * @param string $message
529 529
      * @param int $level DEBUG/INFO/WARN/CRIT
530 530
      */
531
-    public function log($message,$level)
531
+    public function log($message, $level)
532 532
     {
533
-        $this->loggingClass->log('[ '.get_class($this).'] '. $message, $level);
533
+        $this->loggingClass->log('[ '.get_class($this).'] '.$message, $level);
534 534
     }
535 535
 }
536 536
\ No newline at end of file
Please login to merge, or discard this patch.
library/Trapdirector/Plugins/NetworkRule.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      */
45 45
     function __construct()
46 46
     {
47
-        $this->name=basename(__FILE__,'.php');
47
+        $this->name=basename(__FILE__, '.php');
48 48
         return $this;
49 49
     }
50 50
     
@@ -56,41 +56,41 @@  discard block
 block discarded – undo
56 56
      */
57 57
     public function isInNetwork(array $params) : bool
58 58
     {
59
-        $this->log('Function params : ' . print_r($params,true),DEBUG);
60
-        if (count($params)!=3)
59
+        $this->log('Function params : '.print_r($params, true), DEBUG);
60
+        if (count($params) != 3)
61 61
         {
62
-            throw new Exception('Invalid number of parameters : ' . count($params));
62
+            throw new Exception('Invalid number of parameters : '.count($params));
63 63
         }
64 64
         
65
-        $ip = $params[0];
66
-        $net = $params[1];
67
-        $masq = $params[2];
65
+        $ip=$params[0];
66
+        $net=$params[1];
67
+        $masq=$params[2];
68 68
         
69
-        $this->log('#'. $ip . '# / #' . $net . '# / #' . $masq,DEBUG);
69
+        $this->log('#'.$ip.'# / #'.$net.'# / #'.$masq, DEBUG);
70 70
         
71
-        $ip2 = ip2long($ip);
72
-        $net2 = ip2long($net);
71
+        $ip2=ip2long($ip);
72
+        $net2=ip2long($net);
73 73
         
74
-        if ($ip2 === false )
74
+        if ($ip2 === false)
75 75
         {
76
-            $this->log('Invalid IP : #' . $ip.'#',WARN);
76
+            $this->log('Invalid IP : #'.$ip.'#', WARN);
77 77
             throw new Exception('Invalid IP');
78 78
         }
79 79
         if ($net2 === false)
80 80
         {
81
-            $this->log('Invalid network',WARN);
81
+            $this->log('Invalid network', WARN);
82 82
             throw new Exception('Invalid net');
83 83
         }
84
-        if ($masq<1 || $masq > 32)
84
+        if ($masq < 1 || $masq > 32)
85 85
         {
86
-            $this->log('Invalid masq',WARN);
86
+            $this->log('Invalid masq', WARN);
87 87
             throw new Exception('Invalid net masq');
88 88
         }
89 89
         // $range is in IP/CIDR format eg 127.0.0.1/24
90 90
 
91
-        $masq = pow( 2, ( 32 - $masq ) ) - 1;
92
-        $masq = ~ $masq;
93
-        return ( ( $ip2 & $masq ) == ( $net2 & $masq ) );
91
+        $masq=pow(2, (32 - $masq)) - 1;
92
+        $masq=~ $masq;
93
+        return (($ip2 & $masq) == ($net2 & $masq));
94 94
         
95 95
     }
96 96
 }
Please login to merge, or discard this patch.
application/controllers/HandlerController.php 1 patch
Spacing   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
 		$this->checkReadPermission();
24 24
 		$this->prepareTabs()->activate('status');
25 25
 
26
-		$db = $this->getDb();
26
+		$db=$this->getDb();
27 27
 		$this->getHandlerListTable()->setConnection($db);
28 28
 		$this->getHandlerListTable()->setMibloader($this->getMIB());
29 29
 		// Apply pagination limits 
30
-		$this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(),$this->getModuleConfig()->itemListDisplay());		
30
+		$this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(), $this->getModuleConfig()->itemListDisplay());		
31 31
 		
32 32
 		// Set Filter
33
-		$this->view->filterEditor = $this->getHandlerListTable()->getFilterEditor($this->getRequest());		
33
+		$this->view->filterEditor=$this->getHandlerListTable()->getFilterEditor($this->getRequest());		
34 34
 	
35 35
 		//$this->displayExitError('Handler/indexAction','Not implemented');
36 36
 	}
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	public function testruleAction()
41 41
 	{
42 42
 	    $this->checkReadPermission();
43
-	    $this->getTabs()->add('get',array(
43
+	    $this->getTabs()->add('get', array(
44 44
 	        'active'	=> true,
45 45
 	        'label'		=> $this->translate('Test Rule'),
46 46
 	        'url'		=> Url::fromRequest()
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 
51 51
 	    if ($this->params->get('rule') !== null) 
52 52
 	    {
53
-	        $this->view->rule= $this->params->get('rule');
53
+	        $this->view->rule=$this->params->get('rule');
54 54
 	    }
55 55
 	    else
56 56
 	    {
@@ -109,12 +109,12 @@  discard block
 block discarded – undo
109 109
 	    }
110 110
 	    catch (Exception $e)
111 111
 	    {
112
-	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
112
+	        $this->displayExitError('Add handler : get host by IP/Name ', $e->getMessage());
113 113
 	    }
114 114
 	    
115 115
 	    
116 116
 	    // if one unique host found -> put id text input
117
-	    if (count($hosts)==1) {
117
+	    if (count($hosts) == 1) {
118 118
 	        $this->view->hostname=$hosts[0]->name;
119 119
 	        //$hostid=$hosts[0]->id;
120 120
 	        // Tell JS to get services when page is loaded
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
 	    }
124 124
 	    else
125 125
 	    {
126
-	        foreach($hosts as $key=>$val)
126
+	        foreach ($hosts as $key=>$val)
127 127
 	        {
128
-	            array_push($this->view->hostlist,$hosts[$key]->name);
128
+	            array_push($this->view->hostlist, $hosts[$key]->name);
129 129
 	        }
130 130
 	    }
131 131
 	    
@@ -164,18 +164,18 @@  discard block
 block discarded – undo
164 164
 	            $currentObjectTypeEnum
165 165
 	        );
166 166
 	        $oid_index++;
167
-	        array_push($this->view->objectList,$currentObject);
167
+	        array_push($this->view->objectList, $currentObject);
168 168
 	        // set currrent object to null in allObjects
169 169
 	        if (isset($allObjects[$val->oid]))
170 170
 	        {
171 171
 	            $allObjects[$val->oid]=null;
172 172
 	        }
173 173
 	    }
174
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
174
+	    if ($allObjects != null) // in case trap doesn't have objects or is not resolved
175 175
 	    {
176 176
 	        foreach ($allObjects as $key => $val)
177 177
 	        {
178
-	            if ($val==null) { continue; }
178
+	            if ($val == null) { continue; }
179 179
 	            array_push($this->view->objectList, array(
180 180
 	                $oid_index,
181 181
 	                $key,
@@ -203,9 +203,9 @@  discard block
 block discarded – undo
203 203
 	    // Check if hostname still exists
204 204
 	    $host_get=$this->getHostByName($this->view->hostname);
205 205
 	    
206
-	    if (count($host_get)==0)
206
+	    if (count($host_get) == 0)
207 207
 	    {
208
-	        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
208
+	        $this->view->warning_message='Host '.$this->view->hostname.' doesn\'t exists anymore';
209 209
 	        $this->view->serviceGet=false;
210 210
 	    }
211 211
 	    else
@@ -213,10 +213,10 @@  discard block
 block discarded – undo
213 213
 	        // Tell JS to get services when page is loaded
214 214
 	        $this->view->serviceGet=true;
215 215
 	        // get service id for form to set :
216
-	        $serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
217
-	        if (count($serviceID) ==0)
216
+	        $serviceID=$this->getServiceIDByName($this->view->hostname, $ruleDetail->service_name);
217
+	        if (count($serviceID) == 0)
218 218
 	        {
219
-	            $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
219
+	            $this->view->warning_message=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore';
220 220
 	        }
221 221
 	        else
222 222
 	        {
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
 	{
234 234
 	    // Check if groupe exists
235 235
 	    $group_get=$this->getHostGroupByName($this->view->hostgroupname);
236
-	    if (count($group_get)==0)
236
+	    if (count($group_get) == 0)
237 237
 	    {
238
-	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
238
+	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname.' doesn\'t exists anymore';
239 239
 	        $this->view->serviceGroupGet=false;
240 240
 	    }
241 241
 	    else
@@ -253,9 +253,9 @@  discard block
 block discarded – undo
253 253
 	        
254 254
 	        // Tell JS to get services when page is loaded
255 255
 	        $this->view->serviceGroupGet=true;
256
-	        if ($foundGrpService==0)
256
+	        if ($foundGrpService == 0)
257 257
 	        {
258
-	            $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
258
+	            $this->view->warning_message.=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore';
259 259
 	        }
260 260
 	    }
261 261
 	}
@@ -273,8 +273,8 @@  discard block
 block discarded – undo
273 273
 	    $index=1;
274 274
 	    // check in display & rule for : OID(<oid>)
275 275
 	    $matches=array();
276
-	    while ( preg_match('/_OID\(([\.0-9]+)\)/',$display,$matches) ||
277
-	        preg_match('/_OID\(([\.0-9]+)\)/',$rule,$matches))
276
+	    while (preg_match('/_OID\(([\.0-9]+)\)/', $display, $matches) ||
277
+	        preg_match('/_OID\(([\.0-9]+)\)/', $rule, $matches))
278 278
 	    {
279 279
 	        $curOid=$matches[1];
280 280
 	        if (($object=$this->getMIB()->translateOID($curOid)) != null)
@@ -300,8 +300,8 @@  discard block
 block discarded – undo
300 300
 	                'not found'
301 301
 	            ));
302 302
 	        }
303
-	        $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
304
-	        $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
303
+	        $display=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $display);
304
+	        $rule=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $rule);
305 305
 	        $index++;
306 306
 	    }
307 307
 	    return $curObjectList;
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 	{
316 316
 		$this->checkConfigPermission();
317 317
 		// set up tab
318
-		$this->getTabs()->add('get',array(
318
+		$this->getTabs()->add('get', array(
319 319
 			'active'	=> true,
320 320
 			'label'		=> $this->translate('Add handler'),
321 321
 			'url'		=> Url::fromRequest()
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 		
329 329
 		//$this->view->trapvalues=false; // Set to true to display 'value' colum in objects
330 330
 		
331
-		if (($trapid = $this->params->get('fromid')) !== null) {
331
+		if (($trapid=$this->params->get('fromid')) !== null) {
332 332
 		    /********** Setup from existing trap ***************/
333 333
             $this->add_from_existing($trapid);
334 334
 			return;
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 			$this->view->setRuleMatch=$ruleDetail->action_match;
349 349
 			$this->view->setRuleNoMatch=$ruleDetail->action_nomatch;
350 350
 			$this->view->hostgroupname=$ruleDetail->host_group_name;
351
-			$this->view->modified=gmdate("Y-m-d\TH:i:s\Z",$ruleDetail->modified);
351
+			$this->view->modified=gmdate("Y-m-d\TH:i:s\Z", $ruleDetail->modified);
352 352
 			$this->view->modifier=$ruleDetail->modifier;
353 353
 			
354 354
 			// Warning message if host/service don't exists anymore
@@ -400,26 +400,26 @@  discard block
 block discarded – undo
400 400
 	
401 401
 		$params=array(
402 402
 			// id (also db) => 	array('post' => post id, 'val' => default val, 'db' => send to table)
403
-			'hostgroup'		=>	array('post' => 'hostgroup','db'=>false),
404
-			'db_rule'		=>	array('post' => 'db_rule','db'=>false),
405
-			'hostid'		=>	array('post' => 'hostid','db'=>false),
406
-			'host_name'		=>	array('post' => 'hostname','val' => null,'db'=>true),
407
-			'host_group_name'=>	array('post' => null,'val' => null,'db'=>true),
408
-			'serviceid'		=>	array('post' => 'serviceid','db'=>false),
409
-			'service_name'	=>	array('post' => 'serviceName','db'=>true),
410
-			'trap_oid'		=>	array('post' => 'oid','db'=>true),
411
-			'revert_ok'		=>	array('post' => 'revertOK','val' => 0,'db'=>true),
412
-			'display'		=>	array('post' => 'display','val' => '','db'=>true),
413
-			'rule'			=>	array('post' => 'rule','val' => '','db'=>true),			
414
-			'action_match'	=>	array('post' => 'ruleMatch','val' => -1,'db'=>true),
415
-			'action_nomatch'=>	array('post' => 'ruleNoMatch','val' => -1,'db'=>true),					
416
-			'ip4'			=>	array('post' => null,'val' => null,'db'=>true),
417
-			'ip6'			=>	array('post' => null,'val' => null,'db'=>true),
418
-			'action_form'	=>	array('post' => 'action_form','db'=>false)
403
+			'hostgroup'		=>	array('post' => 'hostgroup', 'db'=>false),
404
+			'db_rule'		=>	array('post' => 'db_rule', 'db'=>false),
405
+			'hostid'		=>	array('post' => 'hostid', 'db'=>false),
406
+			'host_name'		=>	array('post' => 'hostname', 'val' => null, 'db'=>true),
407
+			'host_group_name'=>	array('post' => null, 'val' => null, 'db'=>true),
408
+			'serviceid'		=>	array('post' => 'serviceid', 'db'=>false),
409
+			'service_name'	=>	array('post' => 'serviceName', 'db'=>true),
410
+			'trap_oid'		=>	array('post' => 'oid', 'db'=>true),
411
+			'revert_ok'		=>	array('post' => 'revertOK', 'val' => 0, 'db'=>true),
412
+			'display'		=>	array('post' => 'display', 'val' => '', 'db'=>true),
413
+			'rule'			=>	array('post' => 'rule', 'val' => '', 'db'=>true),			
414
+			'action_match'	=>	array('post' => 'ruleMatch', 'val' => -1, 'db'=>true),
415
+			'action_nomatch'=>	array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true),					
416
+			'ip4'			=>	array('post' => null, 'val' => null, 'db'=>true),
417
+			'ip6'			=>	array('post' => null, 'val' => null, 'db'=>true),
418
+			'action_form'	=>	array('post' => 'action_form', 'db'=>false)
419 419
 		);
420 420
 		
421 421
 		if (isset($postData[$params['action_form']['post']]) 
422
-			&& $postData[$params['action_form']['post']] == 'delete' )
422
+			&& $postData[$params['action_form']['post']] == 'delete')
423 423
 		{
424 424
 			try
425 425
 			{
@@ -439,16 +439,16 @@  discard block
 block discarded – undo
439 439
 		}		
440 440
 		foreach (array_keys($params) as $key)
441 441
 		{
442
-			if ($params[$key]['post']==null) continue; // data not sent in post vars
443
-			if (! isset($postData[$params[$key]['post']]))
442
+			if ($params[$key]['post'] == null) continue; // data not sent in post vars
443
+			if (!isset($postData[$params[$key]['post']]))
444 444
 			{
445 445
 				// should not happen as the js checks data
446
-				$this->_helper->json(array('status'=>'No ' . $key));
446
+				$this->_helper->json(array('status'=>'No '.$key));
447 447
 			}
448 448
 			else
449 449
 			{
450 450
 				$data=$postData[$params[$key]['post']];
451
-				if ($data!=null && $data !="")
451
+				if ($data != null && $data != "")
452 452
 				{
453 453
 					$params[$key]['val']=$postData[$params[$key]['post']];
454 454
 				}
@@ -457,8 +457,8 @@  discard block
 block discarded – undo
457 457
 
458 458
 		try 
459 459
 		{
460
-			$isHostGroup=($params['hostgroup']['val'] == 1)?true:false;
461
-			if (! $isHostGroup ) 
460
+			$isHostGroup=($params['hostgroup']['val'] == 1) ?true:false;
461
+			if (!$isHostGroup) 
462 462
 			{  // checks if selection by host 
463 463
 				$hostAddr=$this->getHostInfoByID($params['hostid']['val']);
464 464
 				$params['ip4']['val']=$hostAddr->ip4;
@@ -485,25 +485,25 @@  discard block
 block discarded – undo
485 485
 					return;					
486 486
 				}
487 487
 				// Put param in correct column (group_name)
488
-				$params['host_group_name']['val'] = $params['host_name']['val'];
488
+				$params['host_group_name']['val']=$params['host_name']['val'];
489 489
 				$params['host_name']['val']=null;
490 490
 			}
491 491
 			$dbparams=array();
492 492
 			foreach ($params as $key=>$val)
493 493
 			{
494
-				if ($val['db']==true )
494
+				if ($val['db'] == true)
495 495
 				{
496
-					$dbparams[$key] = $val['val'];
496
+					$dbparams[$key]=$val['val'];
497 497
 				}
498 498
 			}
499 499
 			// echo '<br>';	print_r($dbparams);echo '<br>';
500
-			if ($params['db_rule']['val'] == -1 ) 
500
+			if ($params['db_rule']['val'] == -1) 
501 501
 			{
502 502
 				$ruleID=$this->addHandlerRule($dbparams);
503 503
 			}
504 504
 			else
505 505
 			{
506
-				$this->updateHandlerRule($dbparams,$params['db_rule']['val']);
506
+				$this->updateHandlerRule($dbparams, $params['db_rule']['val']);
507 507
 				$ruleID=$params['db_rule']['val'];
508 508
 			}
509 509
 		}
@@ -522,10 +522,10 @@  discard block
 block discarded – undo
522 522
 	*/
523 523
 	protected function getTrapDetail($trapid) 
524 524
 	{
525
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
525
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
526 526
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
527 527
 		
528
-		$db = $this->getDb()->getConnection();
528
+		$db=$this->getDb()->getConnection();
529 529
 		// ***************  Get main data
530 530
 		// extract columns and titles;
531 531
 		$elmts=NULL;
@@ -534,19 +534,19 @@  discard block
 block discarded – undo
534 534
 		}
535 535
 		try
536 536
 		{		
537
-			$query = $db->select()
538
-				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
539
-				->where('id=?',$trapid);
537
+			$query=$db->select()
538
+				->from($this->getModuleConfig()->getTrapTableName(), $elmts)
539
+				->where('id=?', $trapid);
540 540
 			$trapDetail=$db->fetchRow($query);
541
-			if ( $trapDetail == null ) 
541
+			if ($trapDetail == null) 
542 542
 			{
543
-			    $trapDetail = 'NULL';
543
+			    $trapDetail='NULL';
544 544
 			    throw new Exception('No traps was found with id = '.$trapid);
545 545
 			}
546 546
 		}
547 547
 		catch (Exception $e)
548 548
 		{
549
-			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
549
+			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail, true), $e->getMessage());
550 550
 			return;
551 551
 		}
552 552
 
@@ -560,10 +560,10 @@  discard block
 block discarded – undo
560 560
 	*/
561 561
 	protected function getTrapobjects($trapid)
562 562
 	{	
563
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
563
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
564 564
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
565 565
 		
566
-		$db = $this->getDb()->getConnection();
566
+		$db=$this->getDb()->getConnection();
567 567
 		// ***************  Get object data
568 568
 		// extract columns and titles;
569 569
 		$data_elmts=NULL;
@@ -572,15 +572,15 @@  discard block
 block discarded – undo
572 572
 		}
573 573
 		try
574 574
 		{		
575
-			$query = $db->select()
576
-				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
577
-				->where('trap_id=?',$trapid);
575
+			$query=$db->select()
576
+				->from($this->moduleConfig->getTrapDataTableName(), $data_elmts)
577
+				->where('trap_id=?', $trapid);
578 578
 			$trapDetail=$db->fetchAll($query);
579 579
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
580 580
 		}
581 581
 		catch (Exception $e)
582 582
 		{
583
-			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
583
+			$this->displayExitError('Add handler : get trap data detail : ', $e->getMessage());
584 584
 			return array();
585 585
 		}
586 586
 
@@ -593,22 +593,22 @@  discard block
 block discarded – undo
593 593
 	*/
594 594
 	protected function getRuleDetail($ruleid) 
595 595
 	{
596
-		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
596
+		if (!preg_match('/^[0-9]+$/', $ruleid)) { throw new Exception('Invalid id'); }
597 597
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
598 598
 		
599
-		$db = $this->getDb()->getConnection();
599
+		$db=$this->getDb()->getConnection();
600 600
 		// ***************  Get main data
601 601
 		try
602 602
 		{		
603
-			$query = $db->select()
604
-				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
605
-				->where('id=?',$ruleid);
603
+			$query=$db->select()
604
+				->from($this->getModuleConfig()->getTrapRuleName(), $queryArray)
605
+				->where('id=?', $ruleid);
606 606
 			$ruleDetail=$db->fetchRow($query);
607
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
607
+			if ($ruleDetail == null) throw new Exception('No rule was found with id = '.$ruleid);
608 608
 		}
609 609
 		catch (Exception $e)
610 610
 		{
611
-			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
611
+			$this->displayExitError('Update handler : get rule detail', $e->getMessage());
612 612
 			return array();
613 613
 		}
614 614
 
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
 	{
623 623
 		return $this->getTabs()->add('status', array(
624 624
 			'label' => $this->translate('Traps'),
625
-			'url'   => $this->getModuleConfig()->urlPath() . '/handler')
625
+			'url'   => $this->getModuleConfig()->urlPath().'/handler')
626 626
 		);
627 627
 	} 
628 628
 	
Please login to merge, or discard this patch.