Passed
Branch master (9f9a4d)
by Patrick
02:33
created
application/controllers/HelperController.php 3 patches
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
 {
13 13
 	
14 14
 	/** Get host list with filter (IP or name) : host=<filter>
15
-	*	returns in JSON : status=>OK/NOK  hosts=>array of hosts
16
-	*/
15
+	 *	returns in JSON : status=>OK/NOK  hosts=>array of hosts
16
+	 */
17 17
 	public function gethostsAction()
18 18
 	{
19 19
 		$postData=$this->getRequest()->getPost();
@@ -39,8 +39,8 @@  discard block
 block discarded – undo
39 39
 
40 40
 	
41 41
 	/** Get hostgroup list with filter (name) : hostgroup=<hostFilter>
42
-	*	returns in JSON : status=>OK/NOK  hosts=>array of hosts
43
-	*/
42
+	 *	returns in JSON : status=>OK/NOK  hosts=>array of hosts
43
+	 */
44 44
 	public function gethostgroupsAction()
45 45
 	{
46 46
 		$postData=$this->getRequest()->getPost();
@@ -66,11 +66,11 @@  discard block
 block discarded – undo
66 66
 
67 67
 	
68 68
 	/** Get service list by host name ( host=<host> )
69
-	*	returns in JSON : 
70
-	*		status=>OK/No services found/More than one host matches
71
-	*		services=>array of services (name)
72
-	*		hostid = host object id or -1 if not found.
73
-	*/
69
+	 *	returns in JSON : 
70
+	 *		status=>OK/No services found/More than one host matches
71
+	 *		services=>array of services (name)
72
+	 *		hostid = host object id or -1 if not found.
73
+	 */
74 74
 	public function getservicesAction()
75 75
 	{
76 76
 		$postData=$this->getRequest()->getPost();
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
 	}
107 107
 	
108 108
 	/** Get service list by host group ( name=<host> )
109
-	*	returns in JSON : 
110
-	*		status=>OK/No services found/More than one host matches
111
-	*		services=>array of services (name)
112
-	*		groupid = group object id or -1 if not found.
113
-	*/
109
+	 *	returns in JSON : 
110
+	 *		status=>OK/No services found/More than one host matches
111
+	 *		services=>array of services (name)
112
+	 *		groupid = group object id or -1 if not found.
113
+	 */
114 114
 	public function gethostgroupservicesAction()
115 115
 	{
116 116
 		$postData=$this->getRequest()->getPost();
@@ -143,10 +143,10 @@  discard block
 block discarded – undo
143 143
 	}
144 144
 
145 145
 	/** Get traps from mib  : entry : mib=<mib>
146
-	*	returns in JSON : 
147
-	*		status=>OK/No mib/Error getting mibs
148
-	*		traps=>array of array( oid -> name)
149
-	*/
146
+	 *	returns in JSON : 
147
+	 *		status=>OK/No mib/Error getting mibs
148
+	 *		traps=>array of array( oid -> name)
149
+	 */
150 150
 	public function gettrapsAction()
151 151
 	{
152 152
 		$postData=$this->getRequest()->getPost();
@@ -171,10 +171,10 @@  discard block
 block discarded – undo
171 171
 	}	
172 172
 
173 173
 	/** Get trap objects from mib  : entry : trap=<oid>
174
-	*	returns in JSON : 
175
-	*		status=>OK/no trap/not found
176
-	*		objects=>array of array( oid -> name, oid->mib)
177
-	*/
174
+	 *	returns in JSON : 
175
+	 *		status=>OK/no trap/not found
176
+	 *		objects=>array of array( oid -> name, oid->mib)
177
+	 */
178 178
 	public function gettrapobjectsAction()
179 179
 	{
180 180
 		$postData=$this->getRequest()->getPost();
@@ -199,8 +199,8 @@  discard block
 block discarded – undo
199 199
 	}	
200 200
 	
201 201
 	/** Get list of all loaded mibs : entry : none
202
-	*	return : array of strings.
203
-	*/
202
+	 *	return : array of strings.
203
+	 */
204 204
 	public function getmiblistAction()
205 205
 	{
206 206
 		try
@@ -215,10 +215,10 @@  discard block
 block discarded – undo
215 215
 	}
216 216
 	
217 217
 	/** Get MIB::Name from OID : entry : oid
218
-	*		status=>OK/No oid/not found
219
-	*		mib=>string
220
-	*		name=>string
221
-	*/	
218
+	 *		status=>OK/No oid/not found
219
+	 *		mib=>string
220
+	 *		name=>string
221
+	 */	
222 222
 	public function translateoidAction()
223 223
 	{
224 224
 		$postData=$this->getRequest()->getPost();
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 					'name' => $object['name'],
245 245
 					'type' => $object['type'],
246 246
 					'type_enum' => $object['type_enum'],
247
-				    'description' => $object['description']
247
+					'description' => $object['description']
248 248
 				)
249 249
 			);
250 250
 		}
@@ -253,10 +253,10 @@  discard block
 block discarded – undo
253 253
 
254 254
 	
255 255
 	/** Save or execute database purge of <n> days
256
-	*	days=>int 
257
-	*	action=>save/execute
258
-	*	return : status=>OK/Message error
259
-	*/
256
+	 *	days=>int 
257
+	 *	action=>save/execute
258
+	 *	return : status=>OK/Message error
259
+	 */
260 260
 	public function dbmaintenanceAction()
261 261
 	{
262 262
 		
@@ -323,11 +323,11 @@  discard block
 block discarded – undo
323 323
 	}	
324 324
 
325 325
 	/** Save log output to db
326
-	*	destination=>log destination 
327
-	*	file=>file name
328
-	*	level => int 
329
-	*	return : status=>OK/Message error
330
-	*/
326
+	 *	destination=>log destination 
327
+	 *	file=>file name
328
+	 *	level => int 
329
+	 *	return : status=>OK/Message error
330
+	 */
331 331
 	public function logdestinationAction()
332 332
 	{
333 333
 		$postData=$this->getRequest()->getPost();
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
 			$fileHandler=@fopen($file,'w');
351 351
 			if ($fileHandler == false)
352 352
 			{   // File os note writabe / cannot create
353
-			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
353
+				$this->_helper->json(array('status'=>'File not writable :  '.$file));
354 354
 			}
355 355
 		}
356 356
 		else
@@ -406,50 +406,50 @@  discard block
 block discarded – undo
406 406
 	public function testruleAction()
407 407
 	{
408 408
 	    
409
-	    $postData=$this->getRequest()->getPost();
410
-	    if (isset($postData['rule']))
411
-	    {
412
-	        $rule=$postData['rule'];
413
-	    }
414
-	    else
415
-	    {
416
-	        $this->_helper->json(array('status'=>'No Rule'));
417
-	    }
418
-	    if (isset($postData['action']))
419
-	    {
420
-	        $action=$postData['action'];
421
-	        if ($action != 'evaluate')
422
-	        {
423
-	            $this->_helper->json(array('status'=>'unknown action '.$action));
424
-	            return;
425
-	        }
426
-	    }
427
-	    else
428
-	    {
429
-	        $this->_helper->json(array('status'=>'No action'));
430
-	        return;
431
-	    }
432
-	    if ($action == 'evaluate')
433
-	    {
434
-	        try
435
-	        {
436
-	            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
437
-	            $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
438
-	            $Trap = new Trap($icingaweb2_etc);
439
-	            // Cleanup spaces before eval
440
-	            $rule=$Trap->eval_cleanup($rule);
441
-	            // Eval
442
-	            $item=0;
443
-	            $rule=$Trap->evaluation($rule,$item);
444
-	        }
445
-	        catch (Exception $e)
446
-	        {
447
-	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
448
-	            return;
449
-	        }
450
-	        $return=($rule==true)?'true':'false';
451
-	        $this->_helper->json(array('status'=>'OK', 'message' => $return));
452
-	    }
409
+		$postData=$this->getRequest()->getPost();
410
+		if (isset($postData['rule']))
411
+		{
412
+			$rule=$postData['rule'];
413
+		}
414
+		else
415
+		{
416
+			$this->_helper->json(array('status'=>'No Rule'));
417
+		}
418
+		if (isset($postData['action']))
419
+		{
420
+			$action=$postData['action'];
421
+			if ($action != 'evaluate')
422
+			{
423
+				$this->_helper->json(array('status'=>'unknown action '.$action));
424
+				return;
425
+			}
426
+		}
427
+		else
428
+		{
429
+			$this->_helper->json(array('status'=>'No action'));
430
+			return;
431
+		}
432
+		if ($action == 'evaluate')
433
+		{
434
+			try
435
+			{
436
+				require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
437
+				$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
438
+				$Trap = new Trap($icingaweb2_etc);
439
+				// Cleanup spaces before eval
440
+				$rule=$Trap->eval_cleanup($rule);
441
+				// Eval
442
+				$item=0;
443
+				$rule=$Trap->evaluation($rule,$item);
444
+			}
445
+			catch (Exception $e)
446
+			{
447
+				$this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
448
+				return;
449
+			}
450
+			$return=($rule==true)?'true':'false';
451
+			$this->_helper->json(array('status'=>'OK', 'message' => $return));
452
+		}
453 453
 	    
454 454
 	}	
455 455
 	
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -26,12 +26,12 @@  discard block
 block discarded – undo
26 26
 			$this->_helper->json(array('status'=>'KO'));
27 27
 		}
28 28
 
29
-		$retHosts=array('status'=>'OK','hosts' => array());
29
+		$retHosts=array('status'=>'OK', 'hosts' => array());
30 30
 
31 31
 		$hosts=$this->getHostByIP($hostFilter);
32 32
 		foreach ($hosts as $val)
33 33
 		{
34
-			array_push($retHosts['hosts'],$val->name);
34
+			array_push($retHosts['hosts'], $val->name);
35 35
 		}
36 36
 		
37 37
 		$this->_helper->json($retHosts);
@@ -53,12 +53,12 @@  discard block
 block discarded – undo
53 53
 			$this->_helper->json(array('status'=>'Error : no filter'));
54 54
 		}
55 55
 
56
-		$retHosts=array('status'=>'OK','hosts' => array());
56
+		$retHosts=array('status'=>'OK', 'hosts' => array());
57 57
 
58 58
 		$hosts=$this->getHostGroupByName($hostFilter);
59 59
 		foreach ($hosts as $val)
60 60
 		{
61
-			array_push($retHosts['hosts'],$val->name);
61
+			array_push($retHosts['hosts'], $val->name);
62 62
 		}
63 63
 		
64 64
 		$this->_helper->json($retHosts);
@@ -80,27 +80,27 @@  discard block
 block discarded – undo
80 80
 		}
81 81
 		else
82 82
 		{
83
-			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1));
83
+			$this->_helper->json(array('status'=>'No Hosts', 'hostid' => -1));
84 84
 		}
85 85
 		
86 86
 		$hostArray=$this->getHostByName($host);
87 87
 		if (count($hostArray) > 1)
88 88
 		{	
89
-			$this->_helper->json(array('status'=>'More than one host matches','hostid' => -1));
89
+			$this->_helper->json(array('status'=>'More than one host matches', 'hostid' => -1));
90 90
 		}
91 91
 		else if (count($hostArray) == 0)
92 92
 		{
93
-			$this->_helper->json(array('status'=>'No host matches','hostid' => -1));
93
+			$this->_helper->json(array('status'=>'No host matches', 'hostid' => -1));
94 94
 		}
95 95
 		$services=$this->getServicesByHostid($hostArray[0]->id);
96 96
 		if (count($services) < 1)
97 97
 		{
98
-			$this->_helper->json(array('status'=>'No services found for host','hostid' => $hostArray[0]->id));
98
+			$this->_helper->json(array('status'=>'No services found for host', 'hostid' => $hostArray[0]->id));
99 99
 		}
100
-		$retServices=array('status'=>'OK','services' => array(),'hostid' => $hostArray[0]->id);
100
+		$retServices=array('status'=>'OK', 'services' => array(), 'hostid' => $hostArray[0]->id);
101 101
 		foreach ($services as $val)
102 102
 		{
103
-			array_push($retServices['services'],array($val->id , $val->name));
103
+			array_push($retServices['services'], array($val->id, $val->name));
104 104
 		}
105 105
 		$this->_helper->json($retServices);
106 106
 	}
@@ -120,24 +120,24 @@  discard block
 block discarded – undo
120 120
 		}
121 121
 		else
122 122
 		{
123
-			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1));
123
+			$this->_helper->json(array('status'=>'No Hosts', 'hostid' => -1));
124 124
 		}
125 125
 		
126 126
 		$hostArray=$this->getHostGroupByName($host);
127 127
 		if (count($hostArray) > 1)
128 128
 		{	
129
-			$this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1));
129
+			$this->_helper->json(array('status'=>'More than one hostgroup matches', 'hostid' => -1));
130 130
 		}
131 131
 		else if (count($hostArray) == 0)
132 132
 		{
133
-			$this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1));
133
+			$this->_helper->json(array('status'=>'No hostgroup matches', 'hostid' => -1));
134 134
 		}
135 135
 		$services=$this->getServicesByHostGroupid($hostArray[0]->id);
136 136
 		if (count($services) < 1)
137 137
 		{
138
-			$this->_helper->json(array('status'=>'No services found for hostgroup','hostid' => $hostArray[0]->id));
138
+			$this->_helper->json(array('status'=>'No services found for hostgroup', 'hostid' => $hostArray[0]->id));
139 139
 		}
140
-		$retServices=array('status'=>'OK','services' => $services,'hostid' => $hostArray[0]->id);
140
+		$retServices=array('status'=>'OK', 'services' => $services, 'hostid' => $hostArray[0]->id);
141 141
 		
142 142
 		$this->_helper->json($retServices);
143 143
 	}
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 		try
162 162
 		{
163 163
 			$traplist=$this->getMIB()->getTrapList($mib);
164
-			$retTraps=array('status'=>'OK','traps' => $traplist);
164
+			$retTraps=array('status'=>'OK', 'traps' => $traplist);
165 165
 		} 
166 166
 		catch (Exception $e) 
167 167
 		{ 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 		try
190 190
 		{
191 191
 			$objectlist=$this->getMIB()->getObjectList($trap);
192
-			$retObjects=array('status'=>'OK','objects' => $objectlist);
192
+			$retObjects=array('status'=>'OK', 'objects' => $objectlist);
193 193
 		} 
194 194
 		catch (Exception $e) 
195 195
 		{ 
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 		if (isset($postData['days']))
265 265
 		{
266 266
 			$days=$postData['days'];
267
-			if (!preg_match('/^[0-9]+$/',$days))
267
+			if (!preg_match('/^[0-9]+$/', $days))
268 268
 			{
269 269
 				$this->_helper->json(array('status'=>'invalid days : '.$days));
270 270
 			}
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 		if (isset($postData['action']))
277 277
 		{
278 278
 			$action=$postData['action'];
279
-			if ($action != 'save' && $action !='execute')
279
+			if ($action != 'save' && $action != 'execute')
280 280
 			{
281 281
 				$this->_helper->json(array('status'=>'unknown action '.$action));
282 282
 				return;
@@ -291,11 +291,11 @@  discard block
 block discarded – undo
291 291
 		{
292 292
 			try
293 293
 			{
294
-				$this->setDBConfigValue('db_remove_days',$days);
294
+				$this->setDBConfigValue('db_remove_days', $days);
295 295
 			}
296 296
 			catch (Exception $e)
297 297
 			{
298
-				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
298
+				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage()));
299 299
 				return;
300 300
 			}
301 301
 			$this->_helper->json(array('status'=>'OK'));
@@ -305,16 +305,16 @@  discard block
 block discarded – undo
305 305
 		{
306 306
 			try
307 307
 			{
308
-				require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
308
+				require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
309 309
 				$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
310 310
 				$debug_level=4;
311
-				$Trap = new Trap($icingaweb2_etc);
312
-				$Trap->setLogging($debug_level,'syslog');
311
+				$Trap=new Trap($icingaweb2_etc);
312
+				$Trap->setLogging($debug_level, 'syslog');
313 313
 				$Trap->eraseOldTraps($days);
314 314
 			}
315 315
 			catch (Exception $e)
316 316
 			{
317
-				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage() ));
317
+				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage()));
318 318
 				return;
319 319
 			}			
320 320
 			$this->_helper->json(array('status'=>'OK'));
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 		if (isset($postData['file']))
348 348
 		{ 
349 349
 			$file=$postData['file'];
350
-			$fileHandler=@fopen($file,'w');
350
+			$fileHandler=@fopen($file, 'w');
351 351
 			if ($fileHandler == false)
352 352
 			{   // File os note writabe / cannot create
353 353
 			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
@@ -384,13 +384,13 @@  discard block
 block discarded – undo
384 384
 		
385 385
 		try
386 386
 		{
387
-			$this->setDBConfigValue('log_destination',$destination);
388
-			$this->setDBConfigValue('log_file',$file);
389
-			$this->setDBConfigValue('log_level',$level);
387
+			$this->setDBConfigValue('log_destination', $destination);
388
+			$this->setDBConfigValue('log_file', $file);
389
+			$this->setDBConfigValue('log_level', $level);
390 390
 		}
391 391
 		catch (Exception $e)
392 392
 		{
393
-			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
393
+			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage()));
394 394
 			return;
395 395
 		}
396 396
 		$this->_helper->json(array('status'=>'OK'));
@@ -433,21 +433,21 @@  discard block
 block discarded – undo
433 433
 	    {
434 434
 	        try
435 435
 	        {
436
-	            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
436
+	            require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
437 437
 	            $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
438
-	            $Trap = new Trap($icingaweb2_etc);
438
+	            $Trap=new Trap($icingaweb2_etc);
439 439
 	            // Cleanup spaces before eval
440 440
 	            $rule=$Trap->eval_cleanup($rule);
441 441
 	            // Eval
442 442
 	            $item=0;
443
-	            $rule=$Trap->evaluation($rule,$item);
443
+	            $rule=$Trap->evaluation($rule, $item);
444 444
 	        }
445 445
 	        catch (Exception $e)
446 446
 	        {
447
-	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
447
+	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage()));
448 448
 	            return;
449 449
 	        }
450
-	        $return=($rule==true)?'true':'false';
450
+	        $return=($rule == true) ? 'true' : 'false';
451 451
 	        $this->_helper->json(array('status'=>'OK', 'message' => $return));
452 452
 	    }
453 453
 	    
Please login to merge, or discard this patch.
Braces   +26 added lines, -52 removed lines patch added patch discarded remove patch
@@ -20,8 +20,7 @@  discard block
 block discarded – undo
20 20
 		if (isset($postData['hostFilter']))
21 21
 		{
22 22
 			$hostFilter=$postData['hostFilter'];
23
-		}
24
-		else
23
+		} else
25 24
 		{
26 25
 			$this->_helper->json(array('status'=>'KO'));
27 26
 		}
@@ -47,8 +46,7 @@  discard block
 block discarded – undo
47 46
 		if (isset($postData['hostFilter']))
48 47
 		{
49 48
 			$hostFilter=$postData['hostFilter'];
50
-		}
51
-		else
49
+		} else
52 50
 		{
53 51
 			$this->_helper->json(array('status'=>'Error : no filter'));
54 52
 		}
@@ -77,8 +75,7 @@  discard block
 block discarded – undo
77 75
 		if (isset($postData['host']))
78 76
 		{
79 77
 			$host=$postData['host'];
80
-		}
81
-		else
78
+		} else
82 79
 		{
83 80
 			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1));
84 81
 		}
@@ -87,8 +84,7 @@  discard block
 block discarded – undo
87 84
 		if (count($hostArray) > 1)
88 85
 		{	
89 86
 			$this->_helper->json(array('status'=>'More than one host matches','hostid' => -1));
90
-		}
91
-		else if (count($hostArray) == 0)
87
+		} else if (count($hostArray) == 0)
92 88
 		{
93 89
 			$this->_helper->json(array('status'=>'No host matches','hostid' => -1));
94 90
 		}
@@ -117,8 +113,7 @@  discard block
 block discarded – undo
117 113
 		if (isset($postData['host']))
118 114
 		{
119 115
 			$host=$postData['host'];
120
-		}
121
-		else
116
+		} else
122 117
 		{
123 118
 			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1));
124 119
 		}
@@ -127,8 +122,7 @@  discard block
 block discarded – undo
127 122
 		if (count($hostArray) > 1)
128 123
 		{	
129 124
 			$this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1));
130
-		}
131
-		else if (count($hostArray) == 0)
125
+		} else if (count($hostArray) == 0)
132 126
 		{
133 127
 			$this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1));
134 128
 		}
@@ -153,8 +147,7 @@  discard block
 block discarded – undo
153 147
 		if (isset($postData['mib']))
154 148
 		{
155 149
 			$mib=$postData['mib'];
156
-		}
157
-		else
150
+		} else
158 151
 		{
159 152
 			$this->_helper->json(array('status'=>'No mib'));
160 153
 		}
@@ -162,8 +155,7 @@  discard block
 block discarded – undo
162 155
 		{
163 156
 			$traplist=$this->getMIB()->getTrapList($mib);
164 157
 			$retTraps=array('status'=>'OK','traps' => $traplist);
165
-		} 
166
-		catch (Exception $e) 
158
+		} catch (Exception $e) 
167 159
 		{ 
168 160
 			$retTraps=array('status' => 'Error getting mibs');
169 161
 		}
@@ -181,8 +173,7 @@  discard block
 block discarded – undo
181 173
 		if (isset($postData['trap']))
182 174
 		{
183 175
 			$trap=$postData['trap'];
184
-		}
185
-		else
176
+		} else
186 177
 		{
187 178
 			$this->_helper->json(array('status'=>'No trap'));
188 179
 		}
@@ -190,8 +181,7 @@  discard block
 block discarded – undo
190 181
 		{
191 182
 			$objectlist=$this->getMIB()->getObjectList($trap);
192 183
 			$retObjects=array('status'=>'OK','objects' => $objectlist);
193
-		} 
194
-		catch (Exception $e) 
184
+		} catch (Exception $e) 
195 185
 		{ 
196 186
 			$retObjects=array('status' => 'not found');
197 187
 		}
@@ -206,8 +196,7 @@  discard block
 block discarded – undo
206 196
 		try
207 197
 		{
208 198
 			$miblist=$this->getMIB()->getMIBList();
209
-		} 
210
-		catch (Exception $e) 
199
+		} catch (Exception $e) 
211 200
 		{ 
212 201
 			$miblist=array('Error getting mibs');
213 202
 		}
@@ -225,8 +214,7 @@  discard block
 block discarded – undo
225 214
 		if (isset($postData['oid']))
226 215
 		{
227 216
 			$oid=$postData['oid'];
228
-		}
229
-		else
217
+		} else
230 218
 		{
231 219
 			$this->_helper->json(array('status'=>'No oid'));
232 220
 		}
@@ -235,8 +223,7 @@  discard block
 block discarded – undo
235 223
 		if (($object=$this->getMIB()->translateOID($oid)) == null)
236 224
 		{
237 225
 			$this->_helper->json(array('status'=>'Not found'));
238
-		}
239
-		else
226
+		} else
240 227
 		{
241 228
 			$this->_helper->json(
242 229
 				array('status'=>'OK',
@@ -268,8 +255,7 @@  discard block
 block discarded – undo
268 255
 			{
269 256
 				$this->_helper->json(array('status'=>'invalid days : '.$days));
270 257
 			}
271
-		}
272
-		else
258
+		} else
273 259
 		{
274 260
 			$this->_helper->json(array('status'=>'No days'));
275 261
 		}
@@ -281,8 +267,7 @@  discard block
 block discarded – undo
281 267
 				$this->_helper->json(array('status'=>'unknown action '.$action));
282 268
 				return;
283 269
 			}
284
-		}
285
-		else
270
+		} else
286 271
 		{
287 272
 			$this->_helper->json(array('status'=>'No action'));
288 273
 			return;
@@ -292,8 +277,7 @@  discard block
 block discarded – undo
292 277
 			try
293 278
 			{
294 279
 				$this->setDBConfigValue('db_remove_days',$days);
295
-			}
296
-			catch (Exception $e)
280
+			} catch (Exception $e)
297 281
 			{
298 282
 				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
299 283
 				return;
@@ -311,8 +295,7 @@  discard block
 block discarded – undo
311 295
 				$Trap = new Trap($icingaweb2_etc);
312 296
 				$Trap->setLogging($debug_level,'syslog');
313 297
 				$Trap->eraseOldTraps($days);
314
-			}
315
-			catch (Exception $e)
298
+			} catch (Exception $e)
316 299
 			{
317 300
 				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage() ));
318 301
 				return;
@@ -339,8 +322,7 @@  discard block
 block discarded – undo
339 322
 			{
340 323
 				$this->_helper->json(array('status'=>'invalid destination : '.$destination));
341 324
 			}
342
-		}
343
-		else
325
+		} else
344 326
 		{
345 327
 			$this->_helper->json(array('status'=>'No destination'));
346 328
 		}
@@ -352,14 +334,12 @@  discard block
 block discarded – undo
352 334
 			{   // File os note writabe / cannot create
353 335
 			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
354 336
 			}
355
-		}
356
-		else
337
+		} else
357 338
 		{
358 339
 			if ($destination != 'file')
359 340
 			{
360 341
 				$file=null;
361
-			}
362
-			else
342
+			} else
363 343
 			{
364 344
 				$this->_helper->json(array('status'=>'No file'));
365 345
 			}
@@ -368,14 +348,12 @@  discard block
 block discarded – undo
368 348
 		if (isset($postData['level']))
369 349
 		{ 
370 350
 			$level=$postData['level'];
371
-		}
372
-		else
351
+		} else
373 352
 		{
374 353
 			if ($destination != 'level')
375 354
 			{
376 355
 				$level=null;
377
-			}
378
-			else
356
+			} else
379 357
 			{
380 358
 				$this->_helper->json(array('status'=>'No level'));
381 359
 			}
@@ -387,8 +365,7 @@  discard block
 block discarded – undo
387 365
 			$this->setDBConfigValue('log_destination',$destination);
388 366
 			$this->setDBConfigValue('log_file',$file);
389 367
 			$this->setDBConfigValue('log_level',$level);
390
-		}
391
-		catch (Exception $e)
368
+		} catch (Exception $e)
392 369
 		{
393 370
 			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
394 371
 			return;
@@ -410,8 +387,7 @@  discard block
 block discarded – undo
410 387
 	    if (isset($postData['rule']))
411 388
 	    {
412 389
 	        $rule=$postData['rule'];
413
-	    }
414
-	    else
390
+	    } else
415 391
 	    {
416 392
 	        $this->_helper->json(array('status'=>'No Rule'));
417 393
 	    }
@@ -423,8 +399,7 @@  discard block
 block discarded – undo
423 399
 	            $this->_helper->json(array('status'=>'unknown action '.$action));
424 400
 	            return;
425 401
 	        }
426
-	    }
427
-	    else
402
+	    } else
428 403
 	    {
429 404
 	        $this->_helper->json(array('status'=>'No action'));
430 405
 	        return;
@@ -441,8 +416,7 @@  discard block
 block discarded – undo
441 416
 	            // Eval
442 417
 	            $item=0;
443 418
 	            $rule=$Trap->evaluation($rule,$item);
444
-	        }
445
-	        catch (Exception $e)
419
+	        } catch (Exception $e)
446 420
 	        {
447 421
 	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
448 422
 	            return;
Please login to merge, or discard this patch.
library/Trapdirector/TrapsController.php 3 patches
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
 	protected $trapClass;		//< Trap class for bin/trap_class.php
33 33
 		
34 34
 	/** Get instance of TrapModuleConfig class
35
-	*	@return TrapModuleConfig
36
-	*/
35
+	 *	@return TrapModuleConfig
36
+	 */
37 37
 	public function getModuleConfig() {
38 38
 		if ($this->moduleConfig == Null) {
39 39
 			$db_prefix=$this->Config()->get('config', 'database_prefix');
@@ -56,11 +56,11 @@  discard block
 block discarded – undo
56 56
 	
57 57
 	public function getTrapHostListTable()
58 58
 	{
59
-	    if ($this->trapTableHostList == Null) {
60
-	        $this->trapTableHostList = new TrapTableHostList();
61
-	        $this->trapTableHostList->setConfig($this->getModuleConfig());
62
-	    }
63
-	    return $this->trapTableHostList;
59
+		if ($this->trapTableHostList == Null) {
60
+			$this->trapTableHostList = new TrapTableHostList();
61
+			$this->trapTableHostList->setConfig($this->getModuleConfig());
62
+		}
63
+		return $this->trapTableHostList;
64 64
 	}
65 65
 	
66 66
 	public function getHandlerListTable() {
@@ -72,11 +72,11 @@  discard block
 block discarded – undo
72 72
 	}	
73 73
 	
74 74
 	/**	Get Database connexion
75
-	*	@param $DBname string DB name in resource.ini_ge
76
-	*	@param $test bool if set to true, returns error code and not database
77
-	*	@param $test_version	bool if set to flase, does not test database version of trapDB
78
-	*	@return IcingaDbConnection or int
79
-	*/
75
+	 *	@param $DBname string DB name in resource.ini_ge
76
+	 *	@param $test bool if set to true, returns error code and not database
77
+	 *	@param $test_version	bool if set to flase, does not test database version of trapDB
78
+	 *	@return IcingaDbConnection or int
79
+	 */
80 80
 	public function getDbByName($DBname,$test=false,$test_version=true)
81 81
 	{
82 82
 		try 
@@ -156,53 +156,53 @@  discard block
 block discarded – undo
156 156
 
157 157
 		if ( ! $dbresource )
158 158
 		{
159
-		    if ($test) return array(1,'No database in config.ini');
160
-		    $this->redirectNow('trapdirector/settings?idodberror=1');
161
-		    return null;
159
+			if ($test) return array(1,'No database in config.ini');
160
+			$this->redirectNow('trapdirector/settings?idodberror=1');
161
+			return null;
162 162
 		}
163 163
 		
164 164
 		try
165 165
 		{
166
-		    $dbconn = IcingaDbConnection::fromResourceName($dbresource);
166
+			$dbconn = IcingaDbConnection::fromResourceName($dbresource);
167 167
 		}
168 168
 		catch (Exception $e)
169 169
 		{
170
-		    if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2");
171
-		    $this->redirectNow('trapdirector/settings?idodberror=2');
172
-		    return null;
170
+			if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2");
171
+			$this->redirectNow('trapdirector/settings?idodberror=2');
172
+			return null;
173 173
 		}
174 174
 		
175 175
 		if ($test == false) { $this->icingaDB = $dbconn; return $this->icingaDB;}
176 176
 		
177 177
 		try
178 178
 		{
179
-		    $query = $dbconn->select()
180
-		    ->from('icinga_dbversion',array('version'));
181
-		    $version=$dbconn->fetchRow($query);
182
-		    if ( ($version == null) || ! property_exists($version,'version') )
183
-		    {
184
-		        return array(4,"$dbresource does not look like an IDO database");
185
-		    }
179
+			$query = $dbconn->select()
180
+			->from('icinga_dbversion',array('version'));
181
+			$version=$dbconn->fetchRow($query);
182
+			if ( ($version == null) || ! property_exists($version,'version') )
183
+			{
184
+				return array(4,"$dbresource does not look like an IDO database");
185
+			}
186 186
 		}
187 187
 		catch (Exception $e)
188 188
 		{
189
-		    return array(3,"Error connecting to $dbresource : " . $e->getMessage());
190
-		    $this->redirectNow('trapdirector/settings?dberror=4');
191
-		    return null;
189
+			return array(3,"Error connecting to $dbresource : " . $e->getMessage());
190
+			$this->redirectNow('trapdirector/settings?dberror=4');
191
+			return null;
192 192
 		}
193 193
 		
194 194
 		return array(0,'');
195 195
 	}
196 196
 	
197
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
198
-    {
199
-        $limit = $this->params->get('limit', $limit);
200
-        $page = $this->params->get('page', $offset);
197
+	protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
198
+	{
199
+		$limit = $this->params->get('limit', $limit);
200
+		$page = $this->params->get('page', $offset);
201 201
 
202
-        $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
202
+		$paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
203 203
 
204
-        return $paginatable;
205
-    }	
204
+		return $paginatable;
205
+	}	
206 206
 	
207 207
 	public function displayExitError($source,$message)
208 208
 	{	// TODO : check better ways to transmit data (with POST ?)
@@ -211,33 +211,33 @@  discard block
 block discarded – undo
211 211
 	
212 212
 	protected function checkReadPermission()
213 213
 	{
214
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
215
-            $this->displayExitError('Permissions','No permission fo view content');
216
-        }		
214
+		if (! $this->Auth()->hasPermission('trapdirector/view')) {
215
+			$this->displayExitError('Permissions','No permission fo view content');
216
+		}		
217 217
 	}
218 218
 
219 219
 	protected function checkConfigPermission()
220 220
 	{
221
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
222
-            $this->displayExitError('Permissions','No permission fo configure');
223
-        }		
221
+		if (! $this->Auth()->hasPermission('trapdirector/config')) {
222
+			$this->displayExitError('Permissions','No permission fo configure');
223
+		}		
224 224
 	}
225 225
 	
226
-    /**
227
-     * Check if user has write permission
228
-     * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page
229
-     * @return boolean : user has permission
230
-     */
226
+	/**
227
+	 * Check if user has write permission
228
+	 * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page
229
+	 * @return boolean : user has permission
230
+	 */
231 231
 	protected function checkModuleConfigPermission($check=0)
232 232
 	{
233
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
234
-            if ($check == 0)
235
-            {
236
-                $this->displayExitError('Permissions','No permission fo configure module');
237
-            }
238
-            return false;
239
-        }
240
-        return true;
233
+		if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
234
+			if ($check == 0)
235
+			{
236
+				$this->displayExitError('Permissions','No permission fo configure module');
237
+			}
238
+			return false;
239
+		}
240
+		return true;
241 241
 	}
242 242
 
243 243
 	/*************************  Trap class get **********************/
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
 	/************************** MIB related **************************/
258 258
 	
259 259
 	/** Get MIBLoader class
260
-	*	@return MIBLoader class
261
-	*/
260
+	 *	@return MIBLoader class
261
+	 */
262 262
 	protected function getMIB()
263 263
 	{
264 264
 		if ($this->MIBData == null)
@@ -276,9 +276,9 @@  discard block
 block discarded – undo
276 276
 	/**************************  Database queries *******************/
277 277
 	
278 278
 	/** Get host(s) by IP (v4 or v6) or by name in IDO database
279
-	*	does not catch exceptions
280
-	*	@return array of objects ( name, id (object_id), display_name)
281
-	*/
279
+	 *	does not catch exceptions
280
+	 *	@return array of objects ( name, id (object_id), display_name)
281
+	 */
282 282
 	protected function getHostByIP($ip) 
283 283
 	{
284 284
 		// 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,9 +297,9 @@  discard block
 block discarded – undo
297 297
 	}
298 298
 
299 299
 	/** Get host(s) by name in IDO database
300
-	*	does not catch exceptions
301
-	*	@return array of objects ( name, id (object_id), display_name)
302
-	*/
300
+	 *	does not catch exceptions
301
+	 *	@return array of objects ( name, id (object_id), display_name)
302
+	 */
303 303
 	protected function getHostByName($name) 
304 304
 	{
305 305
 		// 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,9 +318,9 @@  discard block
 block discarded – undo
318 318
 	}	
319 319
 	
320 320
 	/** Get host groups by  name in IDO database
321
-	*	does not catch exceptions
322
-	*	@return array of objects ( name, id (object_id), display_name)
323
-	*/
321
+	 *	does not catch exceptions
322
+	 *	@return array of objects ( name, id (object_id), display_name)
323
+	 */
324 324
 	protected function getHostGroupByName($ip) 
325 325
 	{
326 326
 		// 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
@@ -340,9 +340,9 @@  discard block
 block discarded – undo
340 340
 
341 341
 	
342 342
 	/** Get host IP (v4 and v6) by name in IDO database
343
-	*	does not catch exceptions
344
-	*	@return array ( name, display_name, ip4, ip6)
345
-	*/
343
+	 *	does not catch exceptions
344
+	 *	@return array ( name, display_name, ip4, ip6)
345
+	 */
346 346
 	protected function getHostInfoByID($id) 
347 347
 	{
348 348
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
@@ -361,9 +361,9 @@  discard block
 block discarded – undo
361 361
 
362 362
 	
363 363
 	/** Get host by objectid  in IDO database
364
-	*	does not catch exceptions
365
-	*	@return array of objects ( id, name, display_name, ip, ip6,  )
366
-	*/
364
+	 *	does not catch exceptions
365
+	 *	@return array of objects ( id, name, display_name, ip, ip6,  )
366
+	 */
367 367
 	protected function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above
368 368
 	{
369 369
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
@@ -381,10 +381,10 @@  discard block
 block discarded – undo
381 381
 	}	
382 382
 	
383 383
 	/** Get services from object ( host_object_id) in IDO database
384
-	*	does not catch exceptions
385
-	*	@param $id	int object_id
386
-	*	@return array display_name (of service), service_object_id
387
-	*/
384
+	 *	does not catch exceptions
385
+	 *	@param $id	int object_id
386
+	 *	@return array display_name (of service), service_object_id
387
+	 */
388 388
 	protected function getServicesByHostid($id) 
389 389
 	{
390 390
 		// 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
@@ -407,11 +407,11 @@  discard block
 block discarded – undo
407 407
 	}	
408 408
 	
409 409
 	/** Get services from hostgroup object id ( hostgroup_object_id) in IDO database
410
-	* 	gets all hosts in hostgroup and return common services
411
-	*	does not catch exceptions
412
-	*	@param $id	int object_id
413
-	*	@return array display_name (of service), service_object_id
414
-	*/
410
+	 * 	gets all hosts in hostgroup and return common services
411
+	 *	does not catch exceptions
412
+	 *	@param $id	int object_id
413
+	 *	@return array display_name (of service), service_object_id
414
+	 */
415 415
 	protected function getServicesByHostGroupid($id) 
416 416
 	{		
417 417
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
 		//print_r($common_services);
451 451
 		foreach (array_keys($common_services) as $key)
452 452
 		{
453
-		    if ($common_services[$key]['num'] == $num_hosts)
453
+			if ($common_services[$key]['num'] == $num_hosts)
454 454
 			{
455 455
 				array_push($result,array($key,$common_services[$key]['name']));
456 456
 			}
@@ -460,11 +460,11 @@  discard block
 block discarded – undo
460 460
 	}	
461 461
 
462 462
 	/** Get services object id by host name / service name in IDO database
463
-	*	does not catch exceptions
464
-	*	@param $hostname string host name
465
-	*	@param $name string service name
466
-	*	@return int  service id
467
-	*/
463
+	 *	does not catch exceptions
464
+	 *	@param $hostname string host name
465
+	 *	@param $name string service name
466
+	 *	@return int  service id
467
+	 */
468 468
 	protected function getServiceIDByName($hostname,$name) 
469 469
 	{
470 470
 		$db = $this->getIdoDb()->getConnection();
@@ -484,10 +484,10 @@  discard block
 block discarded – undo
484 484
 	}
485 485
 	
486 486
 	/** Get object name from object_id  in IDO database
487
-	*	does not catch exceptions
488
-	*	@param $id	int object_id (default to null, used first if not null)
489
-	*	@return array name1 (host) name2 (service)
490
-	*/
487
+	 *	does not catch exceptions
488
+	 *	@param $id	int object_id (default to null, used first if not null)
489
+	 *	@return array name1 (host) name2 (service)
490
+	 */
491 491
 	protected function getObjectNameByid($id) 
492 492
 	{
493 493
 		// 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
@@ -503,9 +503,9 @@  discard block
 block discarded – undo
503 503
 	}		
504 504
 
505 505
 	/** Add handler rule in traps DB
506
-	*	@param array(<db item>=><value>)
507
-	*	@return int inserted id
508
-	*/
506
+	 *	@param array(<db item>=><value>)
507
+	 *	@return int inserted id
508
+	 */
509 509
 	protected function addHandlerRule($params)
510 510
 	{
511 511
 		// TODO Check for rule consistency
@@ -527,9 +527,9 @@  discard block
 block discarded – undo
527 527
 	}	
528 528
 
529 529
 	/** Update handler rule in traps DB
530
-	*	@param array(<db item>=><value>)
531
-	*	@return array affected rows
532
-	*/
530
+	 *	@param array(<db item>=><value>)
531
+	 *	@return array affected rows
532
+	 */
533 533
 	protected function updateHandlerRule($params,$ruleID)
534 534
 	{
535 535
 		// TODO Check for rule consistency
@@ -547,8 +547,8 @@  discard block
 block discarded – undo
547 547
 	}	
548 548
 	
549 549
 	/** Delete rule by id
550
-	*	@param int rule id
551
-	*/
550
+	 *	@param int rule id
551
+	 */
552 552
 	protected function deleteRule($ruleID)
553 553
 	{
554 554
 		if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
@@ -562,9 +562,9 @@  discard block
 block discarded – undo
562 562
 	}
563 563
 
564 564
 	/** Delete trap by ip & oid
565
-	*	@param $ip string source IP (v4 or v6)
566
-	*	@param $oid string oid
567
-	*/
565
+	 *	@param $ip string source IP (v4 or v6)
566
+	 *	@param $oid string oid
567
+	 */
568 568
 	protected function deleteTrap($ip,$oid)
569 569
 	{
570 570
 		
@@ -590,9 +590,9 @@  discard block
 block discarded – undo
590 590
    
591 591
 
592 592
 	/** count trap by ip & oid
593
-	*	@param $ip string source IP (v4 or v6)
594
-	*	@param $oid string oid
595
-	*/
593
+	 *	@param $ip string source IP (v4 or v6)
594
+	 *	@param $oid string oid
595
+	 */
596 596
 	protected function countTrap($ip,$oid)
597 597
 	{
598 598
 		
@@ -618,8 +618,8 @@  discard block
 block discarded – undo
618 618
 	}		
619 619
 	
620 620
 	/** get configuration value
621
-	*	@param configuration name in db
622
-	*/
621
+	 *	@param configuration name in db
622
+	 */
623 623
 	protected function getDBConfigValue($element)
624 624
 	{
625 625
 	
@@ -650,8 +650,8 @@  discard block
 block discarded – undo
650 650
 	}
651 651
 
652 652
 	/** add configuration value
653
-	*	@param name value
654
-	*/
653
+	 *	@param name value
654
+	 */
655 655
 	protected function addDBConfigValue($element,$value)
656 656
 	{
657 657
 	
@@ -668,8 +668,8 @@  discard block
 block discarded – undo
668 668
 	}
669 669
 
670 670
 	/** set configuration value
671
-	*	@param name value
672
-	*/
671
+	 *	@param name value
672
+	 */
673 673
 	protected function setDBConfigValue($element,$value)
674 674
 	{
675 675
 	
@@ -683,13 +683,13 @@  discard block
 block discarded – undo
683 683
 	}
684 684
 	
685 685
 	/** Check if director is installed
686
-	*	@return bool true/false
687
-	*/
686
+	 *	@return bool true/false
687
+	 */
688 688
 	protected function isDirectorInstalled()
689 689
 	{
690
-	    $output=array();
691
-	    exec('icingacli module list',$output);
692
-	    foreach ($output as $line)
690
+		$output=array();
691
+		exec('icingacli module list',$output);
692
+		foreach ($output as $line)
693 693
 		{
694 694
 			if (preg_match('/^director .*enabled/',$line))
695 695
 			{
Please login to merge, or discard this patch.
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -22,14 +22,14 @@  discard block
 block discarded – undo
22 22
 
23 23
 class TrapsController extends Controller
24 24
 {
25
-	protected $moduleConfig;  	//< TrapModuleConfig instance
26
-	protected $trapTableList; 	//< TrapTableList (by date)
27
-	protected $trapTableHostList; 	//< TrapTableList (by hosts)
28
-	protected $handlerTableList; 	//< HandlerTableList instance
29
-	protected $trapDB;			//< Trap database
30
-	protected $icingaDB;		//< Icinga IDO database;
31
-	protected $MIBData; 		//< MIBLoader class
32
-	protected $trapClass;		//< Trap class for bin/trap_class.php
25
+	protected $moduleConfig; //< TrapModuleConfig instance
26
+	protected $trapTableList; //< TrapTableList (by date)
27
+	protected $trapTableHostList; //< TrapTableList (by hosts)
28
+	protected $handlerTableList; //< HandlerTableList instance
29
+	protected $trapDB; //< Trap database
30
+	protected $icingaDB; //< Icinga IDO database;
31
+	protected $MIBData; //< MIBLoader class
32
+	protected $trapClass; //< Trap class for bin/trap_class.php
33 33
 		
34 34
 	/** Get instance of TrapModuleConfig class
35 35
 	*	@return TrapModuleConfig
@@ -41,14 +41,14 @@  discard block
 block discarded – undo
41 41
 			{
42 42
 				$this->redirectNow('trapdirector/settings?message=No database prefix');
43 43
 			}
44
-			$this->moduleConfig = new TrapModuleConfig($db_prefix);
44
+			$this->moduleConfig=new TrapModuleConfig($db_prefix);
45 45
 		}
46 46
 		return $this->moduleConfig;
47 47
 	}
48 48
 	
49 49
 	public function getTrapListTable() {
50 50
 		if ($this->trapTableList == Null) {
51
-			$this->trapTableList = new TrapTableList();
51
+			$this->trapTableList=new TrapTableList();
52 52
 			$this->trapTableList->setConfig($this->getModuleConfig());
53 53
 		}
54 54
 		return $this->trapTableList;
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	public function getTrapHostListTable()
58 58
 	{
59 59
 	    if ($this->trapTableHostList == Null) {
60
-	        $this->trapTableHostList = new TrapTableHostList();
60
+	        $this->trapTableHostList=new TrapTableHostList();
61 61
 	        $this->trapTableHostList->setConfig($this->getModuleConfig());
62 62
 	    }
63 63
 	    return $this->trapTableHostList;
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	
66 66
 	public function getHandlerListTable() {
67 67
 		if ($this->handlerTableList == Null) {
68
-			$this->handlerTableList = new HandlerTableList();
68
+			$this->handlerTableList=new HandlerTableList();
69 69
 			$this->handlerTableList->setConfig($this->getModuleConfig());
70 70
 		}
71 71
 		return $this->handlerTableList;
@@ -77,15 +77,15 @@  discard block
 block discarded – undo
77 77
 	*	@param $test_version	bool if set to flase, does not test database version of trapDB
78 78
 	*	@return IcingaDbConnection or int
79 79
 	*/
80
-	public function getDbByName($DBname,$test=false,$test_version=true)
80
+	public function getDbByName($DBname, $test=false, $test_version=true)
81 81
 	{
82 82
 		try 
83 83
 		{
84
-			$dbconn = IcingaDbConnection::fromResourceName($DBname);
84
+			$dbconn=IcingaDbConnection::fromResourceName($DBname);
85 85
 		} 
86 86
 		catch (Exception $e)
87 87
 		{
88
-			if ($test) return array(2,$DBname);
88
+			if ($test) return array(2, $DBname);
89 89
 			$this->redirectNow('trapdirector/settings?dberror=2');
90 90
 			return null;
91 91
 		}
@@ -96,53 +96,53 @@  discard block
 block discarded – undo
96 96
 			}
97 97
 			catch (Exception $e) 
98 98
 			{
99
-				if ($test) return array(3,$DBname,$e->getMessage());
99
+				if ($test) return array(3, $DBname, $e->getMessage());
100 100
 				$this->redirectNow('trapdirector/settings?dberror=3');
101 101
 				return null;
102 102
 			}
103 103
 			try
104 104
 			{
105
-				$query = $db->select()
106
-					->from($this->getModuleConfig()->getDbConfigTableName(),'value')
105
+				$query=$db->select()
106
+					->from($this->getModuleConfig()->getDbConfigTableName(), 'value')
107 107
 					->where('name=\'db_version\'');
108 108
 				$version=$db->fetchRow($query);
109
-				if ( ($version == null) || ! property_exists($version,'value') )
109
+				if (($version == null) || !property_exists($version, 'value'))
110 110
 				{
111
-					if ($test) return array(4,$DBname);
111
+					if ($test) return array(4, $DBname);
112 112
 					$this->redirectNow('trapdirector/settings?dberror=4');
113 113
 					return null;
114 114
 				}
115 115
 				if ($version->value < $this->getModuleConfig()->getDbMinVersion()) 
116 116
 				{
117
-					if ($test) return array(5,$version->value,$this->getModuleConfig()->getDbMinVersion());
117
+					if ($test) return array(5, $version->value, $this->getModuleConfig()->getDbMinVersion());
118 118
 					$this->redirectNow('trapdirector/settings?dberror=5');
119 119
 					return null;
120 120
 				}
121 121
 			}
122 122
 			catch (Exception $e) 
123 123
 			{
124
-				if ($test) return array(3,$DBname,$e->getMessage());
124
+				if ($test) return array(3, $DBname, $e->getMessage());
125 125
 				$this->redirectNow('trapdirector/settings?dberror=4');
126 126
 				return null;
127 127
 			}
128 128
 		}
129
-		if ($test) return array(0,'');
129
+		if ($test) return array(0, '');
130 130
 		return $dbconn;
131 131
 	}
132 132
 
133 133
 	public function getDb($test=false)
134 134
 	{
135
-		if ($this->trapDB != null && $test = false) return $this->trapDB;
135
+		if ($this->trapDB != null && $test=false) return $this->trapDB;
136 136
 		
137 137
 		$dbresource=$this->Config()->get('config', 'database');
138 138
 		
139
-		if ( ! $dbresource )
139
+		if (!$dbresource)
140 140
 		{	
141
-			if ($test) return array(1,'');
141
+			if ($test) return array(1, '');
142 142
 			$this->redirectNow('trapdirector/settings?dberror=1');
143 143
 			return null;
144 144
 		}
145
-		$retDB=$this->getDbByName($dbresource,$test,true);
145
+		$retDB=$this->getDbByName($dbresource, $test, true);
146 146
 		if ($test == true) return $retDB;
147 147
 		$this->trapDB=$retDB;
148 148
 		return $this->trapDB;
@@ -150,76 +150,76 @@  discard block
 block discarded – undo
150 150
 	
151 151
 	public function getIdoDb($test=false)
152 152
 	{
153
-		if ($this->icingaDB != null && $test = false) return $this->icingaDB;
153
+		if ($this->icingaDB != null && $test=false) return $this->icingaDB;
154 154
 		// TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
155
-		$dbresource=$this->Config()->get('config', 'IDOdatabase');;
155
+		$dbresource=$this->Config()->get('config', 'IDOdatabase'); ;
156 156
 
157
-		if ( ! $dbresource )
157
+		if (!$dbresource)
158 158
 		{
159
-		    if ($test) return array(1,'No database in config.ini');
159
+		    if ($test) return array(1, 'No database in config.ini');
160 160
 		    $this->redirectNow('trapdirector/settings?idodberror=1');
161 161
 		    return null;
162 162
 		}
163 163
 		
164 164
 		try
165 165
 		{
166
-		    $dbconn = IcingaDbConnection::fromResourceName($dbresource);
166
+		    $dbconn=IcingaDbConnection::fromResourceName($dbresource);
167 167
 		}
168 168
 		catch (Exception $e)
169 169
 		{
170
-		    if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2");
170
+		    if ($test) return array(2, "Database $dbresource does not exists in IcingaWeb2");
171 171
 		    $this->redirectNow('trapdirector/settings?idodberror=2');
172 172
 		    return null;
173 173
 		}
174 174
 		
175
-		if ($test == false) { $this->icingaDB = $dbconn; return $this->icingaDB;}
175
+		if ($test == false) { $this->icingaDB=$dbconn; return $this->icingaDB; }
176 176
 		
177 177
 		try
178 178
 		{
179
-		    $query = $dbconn->select()
180
-		    ->from('icinga_dbversion',array('version'));
179
+		    $query=$dbconn->select()
180
+		    ->from('icinga_dbversion', array('version'));
181 181
 		    $version=$dbconn->fetchRow($query);
182
-		    if ( ($version == null) || ! property_exists($version,'version') )
182
+		    if (($version == null) || !property_exists($version, 'version'))
183 183
 		    {
184
-		        return array(4,"$dbresource does not look like an IDO database");
184
+		        return array(4, "$dbresource does not look like an IDO database");
185 185
 		    }
186 186
 		}
187 187
 		catch (Exception $e)
188 188
 		{
189
-		    return array(3,"Error connecting to $dbresource : " . $e->getMessage());
189
+		    return array(3, "Error connecting to $dbresource : ".$e->getMessage());
190 190
 		    $this->redirectNow('trapdirector/settings?dberror=4');
191 191
 		    return null;
192 192
 		}
193 193
 		
194
-		return array(0,'');
194
+		return array(0, '');
195 195
 	}
196 196
 	
197
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
197
+    protected function applyPaginationLimits(Paginatable $paginatable, $limit=25, $offset=null)
198 198
     {
199
-        $limit = $this->params->get('limit', $limit);
200
-        $page = $this->params->get('page', $offset);
199
+        $limit=$this->params->get('limit', $limit);
200
+        $page=$this->params->get('page', $offset);
201 201
 
202 202
         $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
203 203
 
204 204
         return $paginatable;
205 205
     }	
206 206
 	
207
-	public function displayExitError($source,$message)
207
+	public function displayExitError($source, $message)
208 208
 	{	// TODO : check better ways to transmit data (with POST ?)
209 209
 		$this->redirectNow('trapdirector/error?source='.$source.'&message='.$message);
210 210
 	}
211 211
 	
212 212
 	protected function checkReadPermission()
213 213
 	{
214
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
215
-            $this->displayExitError('Permissions','No permission fo view content');
214
+        if (!$this->Auth()->hasPermission('trapdirector/view')) {
215
+            $this->displayExitError('Permissions', 'No permission fo view content');
216 216
         }		
217 217
 	}
218 218
 
219 219
 	protected function checkConfigPermission()
220 220
 	{
221
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
222
-            $this->displayExitError('Permissions','No permission fo configure');
221
+        if (!$this->Auth()->hasPermission('trapdirector/config')) {
222
+            $this->displayExitError('Permissions', 'No permission fo configure');
223 223
         }		
224 224
 	}
225 225
 	
@@ -230,10 +230,10 @@  discard block
 block discarded – undo
230 230
      */
231 231
 	protected function checkModuleConfigPermission($check=0)
232 232
 	{
233
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
233
+        if (!$this->Auth()->hasPermission('trapdirector/module_config')) {
234 234
             if ($check == 0)
235 235
             {
236
-                $this->displayExitError('Permissions','No permission fo configure module');
236
+                $this->displayExitError('Permissions', 'No permission fo configure module');
237 237
             }
238 238
             return false;
239 239
         }
@@ -245,10 +245,10 @@  discard block
 block discarded – undo
245 245
 	{ // TODO : try/catch here ? or within caller
246 246
 		if ($this->trapClass == null)
247 247
 		{
248
-			require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
248
+			require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
249 249
 			$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
250 250
 			//$debug_level=4;
251
-			$this->trapClass = new Trap($icingaweb2_etc);
251
+			$this->trapClass=new Trap($icingaweb2_etc);
252 252
 			//$Trap->setLogging($debug_level,'syslog');
253 253
 		}
254 254
 		return $this->trapClass;
@@ -282,12 +282,12 @@  discard block
 block discarded – undo
282 282
 	protected function getHostByIP($ip) 
283 283
 	{
284 284
 		// 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
285
-		$db = $this->getIdoDb()->getConnection();
285
+		$db=$this->getIdoDb()->getConnection();
286 286
 		// TODO : check for SQL injections
287 287
 		$query=$db->select()
288 288
 				->from(
289 289
 					array('a' => 'icinga_objects'),
290
-					array('name' => 'a.name1','id' => 'object_id'))
290
+					array('name' => 'a.name1', 'id' => 'object_id'))
291 291
 				->join(
292 292
 					array('b' => 'icinga_hosts'),
293 293
 					'b.host_object_id=a.object_id',
@@ -303,12 +303,12 @@  discard block
 block discarded – undo
303 303
 	protected function getHostByName($name) 
304 304
 	{
305 305
 		// 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
306
-		$db = $this->getIdoDb()->getConnection();
306
+		$db=$this->getIdoDb()->getConnection();
307 307
 		// TODO : check for SQL injections
308 308
 		$query=$db->select()
309 309
 				->from(
310 310
 					array('a' => 'icinga_objects'),
311
-					array('name' => 'a.name1','id' => 'object_id'))
311
+					array('name' => 'a.name1', 'id' => 'object_id'))
312 312
 				->join(
313 313
 					array('b' => 'icinga_hosts'),
314 314
 					'b.host_object_id=a.object_id',
@@ -324,12 +324,12 @@  discard block
 block discarded – undo
324 324
 	protected function getHostGroupByName($ip) 
325 325
 	{
326 326
 		// 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
327
-		$db = $this->getIdoDb()->getConnection();
327
+		$db=$this->getIdoDb()->getConnection();
328 328
 		// TODO : check for SQL injections
329 329
 		$query=$db->select()
330 330
 				->from(
331 331
 					array('a' => 'icinga_objects'),
332
-					array('name' => 'a.name1','id' => 'object_id'))
332
+					array('name' => 'a.name1', 'id' => 'object_id'))
333 333
 				->join(
334 334
 					array('b' => 'icinga_hostgroups'),
335 335
 					'b.hostgroup_object_id=a.object_id',
@@ -345,8 +345,8 @@  discard block
 block discarded – undo
345 345
 	*/
346 346
 	protected function getHostInfoByID($id) 
347 347
 	{
348
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
349
-		$db = $this->getIdoDb()->getConnection();
348
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
349
+		$db=$this->getIdoDb()->getConnection();
350 350
 		$query=$db->select()
351 351
 				->from(
352 352
 					array('a' => 'icinga_objects'),
@@ -366,17 +366,17 @@  discard block
 block discarded – undo
366 366
 	*/
367 367
 	protected function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above
368 368
 	{
369
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
370
-		$db = $this->getIdoDb()->getConnection();
369
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
370
+		$db=$this->getIdoDb()->getConnection();
371 371
 		$query=$db->select()
372 372
 				->from(
373 373
 					array('a' => 'icinga_objects'),
374
-					array('name' => 'a.name1','id' => 'a.object_id'))
374
+					array('name' => 'a.name1', 'id' => 'a.object_id'))
375 375
 				->join(
376 376
 					array('b' => 'icinga_hosts'),
377 377
 					'b.host_object_id=a.object_id',
378
-					array('display_name' => 'b.display_name' , 'ip' => 'b.address', 'ip6' => 'b.address6'))
379
-				->where('a.object_id = ?',$id);
378
+					array('display_name' => 'b.display_name', 'ip' => 'b.address', 'ip6' => 'b.address6'))
379
+				->where('a.object_id = ?', $id);
380 380
 		return $db->fetchRow($query);
381 381
 	}	
382 382
 	
@@ -388,18 +388,18 @@  discard block
 block discarded – undo
388 388
 	protected function getServicesByHostid($id) 
389 389
 	{
390 390
 		// 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
391
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
392
-		$db = $this->getIdoDb()->getConnection();
391
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
392
+		$db=$this->getIdoDb()->getConnection();
393 393
 		if ($id != null)
394 394
 		{
395 395
 			$query=$db->select()
396 396
 					->from(
397 397
 						array('s' => 'icinga_services'),
398
-						array('name' => 's.display_name','id' => 's.service_object_id'))
398
+						array('name' => 's.display_name', 'id' => 's.service_object_id'))
399 399
 					->join(
400 400
 						array('a' => 'icinga_objects'),
401 401
 						's.service_object_id=a.object_id',
402
-						array('is_active'=>'a.is_active','name2'=>'a.name2'))
402
+						array('is_active'=>'a.is_active', 'name2'=>'a.name2'))
403 403
 					->where('s.host_object_id='.$id.' AND a.is_active = 1');
404 404
 		}
405 405
 
@@ -414,8 +414,8 @@  discard block
 block discarded – undo
414 414
 	*/
415 415
 	protected function getServicesByHostGroupid($id) 
416 416
 	{		
417
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
418
-		$db = $this->getIdoDb()->getConnection();
417
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
418
+		$db=$this->getIdoDb()->getConnection();
419 419
 		$query=$db->select()
420 420
 				->from(
421 421
 					array('s' => 'icinga_hostgroup_members'),
@@ -432,11 +432,11 @@  discard block
 block discarded – undo
432 432
 		foreach ($hosts as $key => $host)
433 433
 		{ // For each host, get all services and add in common_services if not found or add counter
434 434
 			$host_services=$this->getServicesByHostid($host->host_object_id);
435
-			foreach($host_services as $service)
435
+			foreach ($host_services as $service)
436 436
 			{
437 437
 				if (isset($common_services[$service->name2]['num']))
438 438
 				{
439
-					$common_services[$service->name2]['num'] +=1;
439
+					$common_services[$service->name2]['num']+=1;
440 440
 				}
441 441
 				else
442 442
 				{
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 		{
453 453
 		    if ($common_services[$key]['num'] == $num_hosts)
454 454
 			{
455
-				array_push($result,array($key,$common_services[$key]['name']));
455
+				array_push($result, array($key, $common_services[$key]['name']));
456 456
 			}
457 457
 		}
458 458
 		
@@ -465,15 +465,15 @@  discard block
 block discarded – undo
465 465
 	*	@param $name string service name
466 466
 	*	@return int  service id
467 467
 	*/
468
-	protected function getServiceIDByName($hostname,$name) 
468
+	protected function getServiceIDByName($hostname, $name) 
469 469
 	{
470
-		$db = $this->getIdoDb()->getConnection();
470
+		$db=$this->getIdoDb()->getConnection();
471 471
 		if ($name != null)
472 472
 		{
473 473
 			$query=$db->select()
474 474
 					->from(
475 475
 						array('s' => 'icinga_services'),
476
-						array('name' => 's.display_name','id' => 's.service_object_id'))
476
+						array('name' => 's.display_name', 'id' => 's.service_object_id'))
477 477
 					->join(
478 478
 						array('a' => 'icinga_objects'),
479 479
 						's.service_object_id=a.object_id',
@@ -491,12 +491,12 @@  discard block
 block discarded – undo
491 491
 	protected function getObjectNameByid($id) 
492 492
 	{
493 493
 		// 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
494
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
495
-		$db = $this->getIdoDb()->getConnection();
494
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
495
+		$db=$this->getIdoDb()->getConnection();
496 496
 		$query=$db->select()
497 497
 				->from(
498 498
 					array('a' => 'icinga_objects'),
499
-					array('name1' => 'a.name1','name2' => 'a.name2'))
499
+					array('name1' => 'a.name1', 'name2' => 'a.name2'))
500 500
 				->where('a.object_id='.$id.' AND a.is_active = 1');
501 501
 
502 502
 		return $db->fetchRow($query);
@@ -509,17 +509,17 @@  discard block
 block discarded – undo
509 509
 	protected function addHandlerRule($params)
510 510
 	{
511 511
 		// TODO Check for rule consistency
512
-		$db = $this->getDb()->getConnection();
512
+		$db=$this->getDb()->getConnection();
513 513
 		// Add last modified date = creation date and username
514
-		$params['created'] = new Zend_Db_Expr('NOW()');
515
-		$params['modified'] = new 	Zend_Db_Expr('NOW()');
516
-		$params['modifier'] = $this->Auth()->getUser()->getUsername();
514
+		$params['created']=new Zend_Db_Expr('NOW()');
515
+		$params['modified']=new 	Zend_Db_Expr('NOW()');
516
+		$params['modifier']=$this->Auth()->getUser()->getUsername();
517 517
 		
518 518
 		$query=$db->insert(
519 519
 			$this->getModuleConfig()->getTrapRuleName(),
520 520
 			$params
521 521
 		);
522
-		if($query==false)
522
+		if ($query == false)
523 523
 		{
524 524
 		  return null;
525 525
 		}
@@ -530,13 +530,13 @@  discard block
 block discarded – undo
530 530
 	*	@param array(<db item>=><value>)
531 531
 	*	@return array affected rows
532 532
 	*/
533
-	protected function updateHandlerRule($params,$ruleID)
533
+	protected function updateHandlerRule($params, $ruleID)
534 534
 	{
535 535
 		// TODO Check for rule consistency
536
-		$db = $this->getDb()->getConnection();
536
+		$db=$this->getDb()->getConnection();
537 537
 		// Add last modified date = creation date and username
538
-		$params['modified'] = new 	Zend_Db_Expr('NOW()');
539
-		$params['modifier'] = $this->Auth()->getUser()->getUsername();
538
+		$params['modified']=new 	Zend_Db_Expr('NOW()');
539
+		$params['modifier']=$this->Auth()->getUser()->getUsername();
540 540
 		
541 541
 		$numRows=$db->update(
542 542
 			$this->getModuleConfig()->getTrapRuleName(),
@@ -551,8 +551,8 @@  discard block
 block discarded – undo
551 551
 	*/
552 552
 	protected function deleteRule($ruleID)
553 553
 	{
554
-		if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
555
-		$db = $this->getDb()->getConnection();
554
+		if (!preg_match('/^[0-9]+$/', $ruleID)) { throw new Exception('Invalid id'); }
555
+		$db=$this->getDb()->getConnection();
556 556
 		
557 557
 		$query=$db->delete(
558 558
 			$this->getModuleConfig()->getTrapRuleName(),
@@ -565,10 +565,10 @@  discard block
 block discarded – undo
565 565
 	*	@param $ip string source IP (v4 or v6)
566 566
 	*	@param $oid string oid
567 567
 	*/
568
-	protected function deleteTrap($ip,$oid)
568
+	protected function deleteTrap($ip, $oid)
569 569
 	{
570 570
 		
571
-		$db = $this->getDb()->getConnection();
571
+		$db=$this->getDb()->getConnection();
572 572
 		$condition=null;
573 573
 		if ($ip != null)
574 574
 		{
@@ -576,10 +576,10 @@  discard block
 block discarded – undo
576 576
 		}
577 577
 		if ($oid != null)
578 578
 		{
579
-			$condition=($condition==null)?'':$condition.' AND ';
579
+			$condition=($condition == null) ? '' : $condition.' AND ';
580 580
 			$condition.="trap_oid='$oid'";
581 581
 		}
582
-		if($condition ==null) return null;
582
+		if ($condition == null) return null;
583 583
 		$query=$db->delete(
584 584
 			$this->getModuleConfig()->getTrapTableName(),
585 585
 			$condition
@@ -593,10 +593,10 @@  discard block
 block discarded – undo
593 593
 	*	@param $ip string source IP (v4 or v6)
594 594
 	*	@param $oid string oid
595 595
 	*/
596
-	protected function countTrap($ip,$oid)
596
+	protected function countTrap($ip, $oid)
597 597
 	{
598 598
 		
599
-		$db = $this->getDb()->getConnection();
599
+		$db=$this->getDb()->getConnection();
600 600
 		$condition=null;
601 601
 		if ($ip != null)
602 602
 		{
@@ -604,10 +604,10 @@  discard block
 block discarded – undo
604 604
 		}
605 605
 		if ($oid != null)
606 606
 		{
607
-			$condition=($condition==null)?'':$condition.' AND ';
607
+			$condition=($condition == null) ? '' : $condition.' AND ';
608 608
 			$condition.="trap_oid='$oid'";
609 609
 		}
610
-		if($condition ==null) return 0;
610
+		if ($condition == null) return 0;
611 611
 		$query=$db->select()
612 612
 			->from(
613 613
 				$this->getModuleConfig()->getTrapTableName(),
@@ -623,27 +623,27 @@  discard block
 block discarded – undo
623 623
 	protected function getDBConfigValue($element)
624 624
 	{
625 625
 	
626
-		$db = $this->getDb()->getConnection();
626
+		$db=$this->getDb()->getConnection();
627 627
 		
628 628
 		$query=$db->select()
629 629
 			->from(
630 630
 				$this->getModuleConfig()->getDbConfigTableName(),
631 631
 				array('value'=>'value'))
632
-			->where('name=?',$element);
632
+			->where('name=?', $element);
633 633
 		$return_row=$db->fetchRow($query);
634
-		if ($return_row==null)  // value does not exists
634
+		if ($return_row == null)  // value does not exists
635 635
 		{
636 636
 			$default=$this->getModuleConfig()->getDBConfigDefaults();
637
-			if ( ! isset($default[$element])) return null; // no default and not value
637
+			if (!isset($default[$element])) return null; // no default and not value
638 638
 			
639
-			$this->addDBConfigValue($element,$default[$element]);
639
+			$this->addDBConfigValue($element, $default[$element]);
640 640
 			return $default[$element];
641 641
 		}
642 642
 		if ($return_row->value == null) // value id empty
643 643
 		{
644 644
 			$default=$this->getModuleConfig()->getDBConfigDefaults();
645
-			if ( ! isset($default[$element])) return null; // no default and not value
646
-			$this->setDBConfigValue($element,$default[$element]);
645
+			if (!isset($default[$element])) return null; // no default and not value
646
+			$this->setDBConfigValue($element, $default[$element]);
647 647
 			return $default[$element];			
648 648
 		}
649 649
 		return $return_row->value;		
@@ -652,10 +652,10 @@  discard block
 block discarded – undo
652 652
 	/** add configuration value
653 653
 	*	@param name value
654 654
 	*/
655
-	protected function addDBConfigValue($element,$value)
655
+	protected function addDBConfigValue($element, $value)
656 656
 	{
657 657
 	
658
-		$db = $this->getDb()->getConnection();
658
+		$db=$this->getDb()->getConnection();
659 659
 		
660 660
 		$query=$db->insert(
661 661
 				$this->getModuleConfig()->getDbConfigTableName(),
@@ -670,10 +670,10 @@  discard block
 block discarded – undo
670 670
 	/** set configuration value
671 671
 	*	@param name value
672 672
 	*/
673
-	protected function setDBConfigValue($element,$value)
673
+	protected function setDBConfigValue($element, $value)
674 674
 	{
675 675
 	
676
-		$db = $this->getDb()->getConnection();
676
+		$db=$this->getDb()->getConnection();
677 677
 		$query=$db->update(
678 678
 				$this->getModuleConfig()->getDbConfigTableName(),
679 679
 				array('value'=>$value),
@@ -688,10 +688,10 @@  discard block
 block discarded – undo
688 688
 	protected function isDirectorInstalled()
689 689
 	{
690 690
 	    $output=array();
691
-	    exec('icingacli module list',$output);
691
+	    exec('icingacli module list', $output);
692 692
 	    foreach ($output as $line)
693 693
 		{
694
-			if (preg_match('/^director .*enabled/',$line))
694
+			if (preg_match('/^director .*enabled/', $line))
695 695
 			{
696 696
 				return true;
697 697
 			}
Please login to merge, or discard this patch.
Braces   +62 added lines, -30 removed lines patch added patch discarded remove patch
@@ -82,10 +82,11 @@  discard block
 block discarded – undo
82 82
 		try 
83 83
 		{
84 84
 			$dbconn = IcingaDbConnection::fromResourceName($DBname);
85
-		} 
86
-		catch (Exception $e)
85
+		} catch (Exception $e)
87 86
 		{
88
-			if ($test) return array(2,$DBname);
87
+			if ($test) {
88
+				return array(2,$DBname);
89
+			}
89 90
 			$this->redirectNow('trapdirector/settings?dberror=2');
90 91
 			return null;
91 92
 		}
@@ -93,10 +94,11 @@  discard block
 block discarded – undo
93 94
 			try 
94 95
 			{
95 96
 				$db=$dbconn->getConnection();
96
-			}
97
-			catch (Exception $e) 
97
+			} catch (Exception $e) 
98 98
 			{
99
-				if ($test) return array(3,$DBname,$e->getMessage());
99
+				if ($test) {
100
+					return array(3,$DBname,$e->getMessage());
101
+				}
100 102
 				$this->redirectNow('trapdirector/settings?dberror=3');
101 103
 				return null;
102 104
 			}
@@ -108,55 +110,72 @@  discard block
 block discarded – undo
108 110
 				$version=$db->fetchRow($query);
109 111
 				if ( ($version == null) || ! property_exists($version,'value') )
110 112
 				{
111
-					if ($test) return array(4,$DBname);
113
+					if ($test) {
114
+						return array(4,$DBname);
115
+					}
112 116
 					$this->redirectNow('trapdirector/settings?dberror=4');
113 117
 					return null;
114 118
 				}
115 119
 				if ($version->value < $this->getModuleConfig()->getDbMinVersion()) 
116 120
 				{
117
-					if ($test) return array(5,$version->value,$this->getModuleConfig()->getDbMinVersion());
121
+					if ($test) {
122
+						return array(5,$version->value,$this->getModuleConfig()->getDbMinVersion());
123
+					}
118 124
 					$this->redirectNow('trapdirector/settings?dberror=5');
119 125
 					return null;
120 126
 				}
121
-			}
122
-			catch (Exception $e) 
127
+			} catch (Exception $e) 
123 128
 			{
124
-				if ($test) return array(3,$DBname,$e->getMessage());
129
+				if ($test) {
130
+					return array(3,$DBname,$e->getMessage());
131
+				}
125 132
 				$this->redirectNow('trapdirector/settings?dberror=4');
126 133
 				return null;
127 134
 			}
128 135
 		}
129
-		if ($test) return array(0,'');
136
+		if ($test) {
137
+			return array(0,'');
138
+		}
130 139
 		return $dbconn;
131 140
 	}
132 141
 
133 142
 	public function getDb($test=false)
134 143
 	{
135
-		if ($this->trapDB != null && $test = false) return $this->trapDB;
144
+		if ($this->trapDB != null && $test = false) {
145
+			return $this->trapDB;
146
+		}
136 147
 		
137 148
 		$dbresource=$this->Config()->get('config', 'database');
138 149
 		
139 150
 		if ( ! $dbresource )
140 151
 		{	
141
-			if ($test) return array(1,'');
152
+			if ($test) {
153
+				return array(1,'');
154
+			}
142 155
 			$this->redirectNow('trapdirector/settings?dberror=1');
143 156
 			return null;
144 157
 		}
145 158
 		$retDB=$this->getDbByName($dbresource,$test,true);
146
-		if ($test == true) return $retDB;
159
+		if ($test == true) {
160
+			return $retDB;
161
+		}
147 162
 		$this->trapDB=$retDB;
148 163
 		return $this->trapDB;
149 164
 	}
150 165
 	
151 166
 	public function getIdoDb($test=false)
152 167
 	{
153
-		if ($this->icingaDB != null && $test = false) return $this->icingaDB;
168
+		if ($this->icingaDB != null && $test = false) {
169
+			return $this->icingaDB;
170
+		}
154 171
 		// TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
155 172
 		$dbresource=$this->Config()->get('config', 'IDOdatabase');;
156 173
 
157 174
 		if ( ! $dbresource )
158 175
 		{
159
-		    if ($test) return array(1,'No database in config.ini');
176
+		    if ($test) {
177
+		    	return array(1,'No database in config.ini');
178
+		    }
160 179
 		    $this->redirectNow('trapdirector/settings?idodberror=1');
161 180
 		    return null;
162 181
 		}
@@ -164,10 +183,11 @@  discard block
 block discarded – undo
164 183
 		try
165 184
 		{
166 185
 		    $dbconn = IcingaDbConnection::fromResourceName($dbresource);
167
-		}
168
-		catch (Exception $e)
186
+		} catch (Exception $e)
169 187
 		{
170
-		    if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2");
188
+		    if ($test) {
189
+		    	return array(2,"Database $dbresource does not exists in IcingaWeb2");
190
+		    }
171 191
 		    $this->redirectNow('trapdirector/settings?idodberror=2');
172 192
 		    return null;
173 193
 		}
@@ -183,8 +203,7 @@  discard block
 block discarded – undo
183 203
 		    {
184 204
 		        return array(4,"$dbresource does not look like an IDO database");
185 205
 		    }
186
-		}
187
-		catch (Exception $e)
206
+		} catch (Exception $e)
188 207
 		{
189 208
 		    return array(3,"Error connecting to $dbresource : " . $e->getMessage());
190 209
 		    $this->redirectNow('trapdirector/settings?dberror=4');
@@ -437,8 +456,7 @@  discard block
 block discarded – undo
437 456
 				if (isset($common_services[$service->name2]['num']))
438 457
 				{
439 458
 					$common_services[$service->name2]['num'] +=1;
440
-				}
441
-				else
459
+				} else
442 460
 				{
443 461
 					$common_services[$service->name2]['num']=1;
444 462
 					$common_services[$service->name2]['name']=$service->name;
@@ -579,7 +597,9 @@  discard block
 block discarded – undo
579 597
 			$condition=($condition==null)?'':$condition.' AND ';
580 598
 			$condition.="trap_oid='$oid'";
581 599
 		}
582
-		if($condition ==null) return null;
600
+		if($condition ==null) {
601
+			return null;
602
+		}
583 603
 		$query=$db->delete(
584 604
 			$this->getModuleConfig()->getTrapTableName(),
585 605
 			$condition
@@ -607,7 +627,9 @@  discard block
 block discarded – undo
607 627
 			$condition=($condition==null)?'':$condition.' AND ';
608 628
 			$condition.="trap_oid='$oid'";
609 629
 		}
610
-		if($condition ==null) return 0;
630
+		if($condition ==null) {
631
+			return 0;
632
+		}
611 633
 		$query=$db->select()
612 634
 			->from(
613 635
 				$this->getModuleConfig()->getTrapTableName(),
@@ -631,18 +653,28 @@  discard block
 block discarded – undo
631 653
 				array('value'=>'value'))
632 654
 			->where('name=?',$element);
633 655
 		$return_row=$db->fetchRow($query);
634
-		if ($return_row==null)  // value does not exists
656
+		if ($return_row==null) {
657
+			// value does not exists
635 658
 		{
636 659
 			$default=$this->getModuleConfig()->getDBConfigDefaults();
637
-			if ( ! isset($default[$element])) return null; // no default and not value
660
+		}
661
+			if ( ! isset($default[$element])) {
662
+				return null;
663
+			}
664
+			// no default and not value
638 665
 			
639 666
 			$this->addDBConfigValue($element,$default[$element]);
640 667
 			return $default[$element];
641 668
 		}
642
-		if ($return_row->value == null) // value id empty
669
+		if ($return_row->value == null) {
670
+			// value id empty
643 671
 		{
644 672
 			$default=$this->getModuleConfig()->getDBConfigDefaults();
645
-			if ( ! isset($default[$element])) return null; // no default and not value
673
+		}
674
+			if ( ! isset($default[$element])) {
675
+				return null;
676
+			}
677
+			// no default and not value
646 678
 			$this->setDBConfigValue($element,$default[$element]);
647 679
 			return $default[$element];			
648 680
 		}
Please login to merge, or discard this patch.
library/Trapdirector/Tables/TrapTableHostList.php 3 patches
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -21,13 +21,13 @@  discard block
 block discarded – undo
21 21
 	protected $lastHost;
22 22
 	// Filters 
23 23
 	
24
-    protected $filter;
25
-    protected $enforcedFilters = array();
26
-    protected $searchColumns = array();
24
+	protected $filter;
25
+	protected $enforcedFilters = array();
26
+	protected $searchColumns = array();
27 27
 	
28 28
 	protected function getTitles() {
29 29
 		// TODO : check moduleconfig is set
30
-	    return $this->moduleConfig->getTrapHostListTitles();
30
+		return $this->moduleConfig->getTrapHostListTitles();
31 31
 	}
32 32
 		
33 33
 	// ******************  Render table in html 
@@ -35,45 +35,45 @@  discard block
 block discarded – undo
35 35
 	// Host grouping
36 36
 	protected function renderHostIfNew($IP,$hostname)
37 37
 	{
38
-	    $view = $this->getView();
38
+		$view = $this->getView();
39 39
 	    
40
-	    if ($this->lastHost === $IP) {
41
-	        return;
42
-	    }
40
+		if ($this->lastHost === $IP) {
41
+			return;
42
+		}
43 43
 	    
44
-	    if ($this->lastHost === null) 
45
-	    {
46
-	        $htm = "<thead>\n  <tr>\n";
47
-	    } else {
48
-	        $htm = "</tbody>\n<thead>\n  <tr>\n";
49
-	    }
44
+		if ($this->lastHost === null) 
45
+		{
46
+			$htm = "<thead>\n  <tr>\n";
47
+		} else {
48
+			$htm = "</tbody>\n<thead>\n  <tr>\n";
49
+		}
50 50
 	    
51
-	    if ($this->columnCount === null) 
52
-	    {
53
-	        $this->columnCount = count($this->getTitles());
54
-	    }
51
+		if ($this->columnCount === null) 
52
+		{
53
+			$this->columnCount = count($this->getTitles());
54
+		}
55 55
 	    
56
-	    $htm .= '<th colspan="' . $this->columnCount . '">' . $view->escape($IP);
57
-	    if ($hostname != null)
58
-	    {
59
-	        $htm .= ' ('.$hostname.')';
60
-	    }
61
-	    $htm .= '</th>' . "\n";
62
-	    if ($this->lastHost === null) {
63
-	        $htm .= "  </tr>\n";
64
-	    } else {
65
-	        $htm .= "  </tr>\n</thead>\n";
66
-	    }
56
+		$htm .= '<th colspan="' . $this->columnCount . '">' . $view->escape($IP);
57
+		if ($hostname != null)
58
+		{
59
+			$htm .= ' ('.$hostname.')';
60
+		}
61
+		$htm .= '</th>' . "\n";
62
+		if ($this->lastHost === null) {
63
+			$htm .= "  </tr>\n";
64
+		} else {
65
+			$htm .= "  </tr>\n</thead>\n";
66
+		}
67 67
 	    
68
-	    $this->lastHost = $IP;
68
+		$this->lastHost = $IP;
69 69
 	    
70
-	    return $htm . "<tbody>\n";
70
+		return $htm . "<tbody>\n";
71 71
 	}		
72 72
 	
73
-    public function __toString()
74
-    {
75
-        return $this->render();
76
-    }
73
+	public function __toString()
74
+	{
75
+		return $this->render();
76
+	}
77 77
 	
78 78
 	public function render()
79 79
 	{
@@ -139,9 +139,9 @@  discard block
 block discarded – undo
139 139
 
140 140
 	}
141 141
 
142
-    public function count()
143
-    {  
144
-        $db=$this->db();
142
+	public function count()
143
+	{  
144
+		$db=$this->db();
145 145
 		
146 146
 		$query = $this->getBaseQuery();
147 147
 		$this->applyFiltersToQuery($query);
@@ -149,16 +149,16 @@  discard block
 block discarded – undo
149 149
 		
150 150
 		return count($values);
151 151
 		
152
-        //return $db->fetchOne($query);
153
-    }
152
+		//return $db->fetchOne($query);
153
+	}
154 154
 	
155
-    public function getPaginator()
156
-    {
157
-        $paginator = new Paginator();
158
-        $paginator->setQuery($this);
155
+	public function getPaginator()
156
+	{
157
+		$paginator = new Paginator();
158
+		$paginator->setQuery($this);
159 159
 
160
-        return $paginator;
161
-    }
160
+		return $paginator;
161
+	}
162 162
 	
163 163
 	// ****************** DB connection and query
164 164
 	
@@ -168,24 +168,24 @@  discard block
 block discarded – undo
168 168
 		
169 169
 		$query = $this->getBaseQuery();
170 170
 		$this->applyFiltersToQuery($query);
171
-       if ($this->hasLimit() || $this->hasOffset()) {
172
-            $query->limit($this->getLimit(), $this->getOffset());
173
-        }		
171
+	   if ($this->hasLimit() || $this->hasOffset()) {
172
+			$query->limit($this->getLimit(), $this->getOffset());
173
+		}		
174 174
 		
175 175
 		return $db->fetchAll($query);
176 176
 	}
177 177
 	 
178
-    public function getBaseQuery()
179
-    {
178
+	public function getBaseQuery()
179
+	{
180 180
 		$db=$this->db();
181 181
 		$query = $db->select()->from(
182
-            $this->moduleConfig->getTrapTableName(),
183
-		    $this->moduleConfig->getTrapHostListDisplayColumns()
184
-		    )->group(array('t.source_ip','t.source_name','t.trap_oid'))
185
-		    ->order('t.source_ip');
182
+			$this->moduleConfig->getTrapTableName(),
183
+			$this->moduleConfig->getTrapHostListDisplayColumns()
184
+			)->group(array('t.source_ip','t.source_name','t.trap_oid'))
185
+			->order('t.source_ip');
186 186
 
187
-        return $query;
188
-    }	 
187
+		return $query;
188
+	}	 
189 189
 	
190 190
 	// ****************** Filters
191 191
 
@@ -215,39 +215,39 @@  discard block
 block discarded – undo
215 215
 		$this->filter_done=(isset($filter['done']))?$this->filter_done=$filter['done']:0;
216 216
 	}
217 217
 	
218
-    protected function getSearchColumns()
219
-    {
220
-        return $this->getColumns();
221
-    }
218
+	protected function getSearchColumns()
219
+	{
220
+		return $this->getColumns();
221
+	}
222 222
 	
223 223
 	public function getColumns()
224 224
 	{
225 225
 		return $this->moduleConfig->getTrapListDisplayColumns();
226 226
 	}
227 227
 
228
-    public function setFilter($filter)
229
-    {
230
-        $this->filter = $filter;
231
-        return $this;
232
-    }
228
+	public function setFilter($filter)
229
+	{
230
+		$this->filter = $filter;
231
+		return $this;
232
+	}
233 233
 	
234 234
 	public function getFilterEditor(Request $request)
235
-    {
236
-        $filterEditor = Widget::create('filterEditor')
237
-            ->setColumns(array_keys($this->getColumns()))
238
-            ->setSearchColumns(array_keys($this->getSearchColumns()))
239
-            ->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
240
-            ->ignoreParams('page')
241
-            ->handleRequest($request);
235
+	{
236
+		$filterEditor = Widget::create('filterEditor')
237
+			->setColumns(array_keys($this->getColumns()))
238
+			->setSearchColumns(array_keys($this->getSearchColumns()))
239
+			->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
240
+			->ignoreParams('page')
241
+			->handleRequest($request);
242 242
 
243
-        $filter = $filterEditor->getFilter();
244
-        $this->setFilter($filter);
243
+		$filter = $filterEditor->getFilter();
244
+		$this->setFilter($filter);
245 245
 
246
-        return $filterEditor;
247
-    }
246
+		return $filterEditor;
247
+	}
248 248
 	
249
-    protected function applyFiltersToQuery($query)
250
-    {
249
+	protected function applyFiltersToQuery($query)
250
+	{
251 251
 		
252 252
 		$sql='';
253 253
 		if ($this->filter_query != '')
@@ -268,8 +268,8 @@  discard block
 block discarded – undo
268 268
 			$sql.="(status != 'done')";
269 269
 		}
270 270
 		if ($sql != '') $query->where($sql);		
271
-        return $query;
272
-    }	
271
+		return $query;
272
+	}	
273 273
 
274 274
 }
275 275
 
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -22,8 +22,8 @@  discard block
 block discarded – undo
22 22
 	// Filters 
23 23
 	
24 24
     protected $filter;
25
-    protected $enforcedFilters = array();
26
-    protected $searchColumns = array();
25
+    protected $enforcedFilters=array();
26
+    protected $searchColumns=array();
27 27
 	
28 28
 	protected function getTitles() {
29 29
 		// TODO : check moduleconfig is set
@@ -33,9 +33,9 @@  discard block
 block discarded – undo
33 33
 	// ******************  Render table in html 
34 34
 	
35 35
 	// Host grouping
36
-	protected function renderHostIfNew($IP,$hostname)
36
+	protected function renderHostIfNew($IP, $hostname)
37 37
 	{
38
-	    $view = $this->getView();
38
+	    $view=$this->getView();
39 39
 	    
40 40
 	    if ($this->lastHost === $IP) {
41 41
 	        return;
@@ -43,31 +43,31 @@  discard block
 block discarded – undo
43 43
 	    
44 44
 	    if ($this->lastHost === null) 
45 45
 	    {
46
-	        $htm = "<thead>\n  <tr>\n";
46
+	        $htm="<thead>\n  <tr>\n";
47 47
 	    } else {
48
-	        $htm = "</tbody>\n<thead>\n  <tr>\n";
48
+	        $htm="</tbody>\n<thead>\n  <tr>\n";
49 49
 	    }
50 50
 	    
51 51
 	    if ($this->columnCount === null) 
52 52
 	    {
53
-	        $this->columnCount = count($this->getTitles());
53
+	        $this->columnCount=count($this->getTitles());
54 54
 	    }
55 55
 	    
56
-	    $htm .= '<th colspan="' . $this->columnCount . '">' . $view->escape($IP);
56
+	    $htm.='<th colspan="'.$this->columnCount.'">'.$view->escape($IP);
57 57
 	    if ($hostname != null)
58 58
 	    {
59
-	        $htm .= ' ('.$hostname.')';
59
+	        $htm.=' ('.$hostname.')';
60 60
 	    }
61
-	    $htm .= '</th>' . "\n";
61
+	    $htm.='</th>'."\n";
62 62
 	    if ($this->lastHost === null) {
63
-	        $htm .= "  </tr>\n";
63
+	        $htm.="  </tr>\n";
64 64
 	    } else {
65
-	        $htm .= "  </tr>\n</thead>\n";
65
+	        $htm.="  </tr>\n</thead>\n";
66 66
 	    }
67 67
 	    
68
-	    $this->lastHost = $IP;
68
+	    $this->lastHost=$IP;
69 69
 	    
70
-	    return $htm . "<tbody>\n";
70
+	    return $htm."<tbody>\n";
71 71
 	}		
72 72
 	
73 73
     public function __toString()
@@ -78,62 +78,62 @@  discard block
 block discarded – undo
78 78
 	public function render()
79 79
 	{
80 80
 		$data=$this->getTable();
81
-		$view = $this->getView();
82
-		$this->columnCount = count($this->getTitles());
81
+		$view=$this->getView();
82
+		$this->columnCount=count($this->getTitles());
83 83
 		$this->lastHost=null;
84 84
 		// Table start
85
-		$htm  = '<table class="simple common-table table-row-selectable">';
85
+		$htm='<table class="simple common-table table-row-selectable">';
86 86
 		
87 87
 		// Titles
88
-		$htm .= "<thead>\n  <tr>\n";
89
-		$titles = $this->getTitles();
88
+		$htm.="<thead>\n  <tr>\n";
89
+		$titles=$this->getTitles();
90 90
 		foreach ($titles as $title) 
91 91
 		{
92
-			$htm .= '    <th>' . $view->escape($view->translate($title)) . "</th>\n";
92
+			$htm.='    <th>'.$view->escape($view->translate($title))."</th>\n";
93 93
 		}
94
-		$htm .= "  </tr>\n</thead>\n";
94
+		$htm.="  </tr>\n</thead>\n";
95 95
 		
96 96
 		// Rows
97
-		$htm .= "<tbody>\n";
97
+		$htm.="<tbody>\n";
98 98
 		
99 99
 		foreach ($data as $row) 
100 100
 		{
101 101
 
102
-			$firstCol = true;
102
+			$firstCol=true;
103 103
 			// Put host header
104
-			$source_name=(property_exists($row,'source_name'))?$row->source_name:null;
105
-			$htm .= $this->renderHostIfNew($row->source_ip,$source_name);
104
+			$source_name=(property_exists($row, 'source_name')) ? $row->source_name : null;
105
+			$htm.=$this->renderHostIfNew($row->source_ip, $source_name);
106 106
 			
107 107
 			
108 108
 			// Render row
109
-			$htm .= '<tr '.' >';
110
-			foreach ( $titles as $rowkey => $title) 
109
+			$htm.='<tr '.' >';
110
+			foreach ($titles as $rowkey => $title) 
111 111
 			{
112 112
 				// Check missing value
113 113
 				if (property_exists($row, $rowkey)) 
114 114
 				{
115
-					$val = ($rowkey=='last_sent') ?  strftime('%c',$row->$rowkey) : $row->$rowkey;
115
+					$val=($rowkey == 'last_sent') ?  strftime('%c', $row->$rowkey) : $row->$rowkey;
116 116
 				} else {
117
-					$val = '-';
117
+					$val='-';
118 118
 				}
119 119
 				if ($firstCol == true) { // Put link in first column for trap detail.
120
-					$htm .= '<td>' 
120
+					$htm.='<td>' 
121 121
 							. $view->qlink(
122 122
 									$view->escape($val),  
123 123
 									Url::fromPath(
124
-										$this->moduleConfig->urlPath() . '/received', 
124
+										$this->moduleConfig->urlPath().'/received', 
125 125
 										array('q' => $row->trap_oid)
126 126
 									)
127 127
 							)
128 128
 							. '</td>';
129 129
 				} else {
130
-					$htm .= '<td>' . $view->escape($val) . '</td>';
130
+					$htm.='<td>'.$view->escape($val).'</td>';
131 131
 				}
132 132
 				$firstCol=false;
133 133
 			}
134
-			$htm .= "<tr>\n";
134
+			$htm.="<tr>\n";
135 135
 		}
136
-		$htm .= "</tbody></table>\n";
136
+		$htm.="</tbody></table>\n";
137 137
 		//$htm .= "Filter : " . $this->filter."<br>\n";
138 138
 		return $htm;
139 139
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
     {  
144 144
         $db=$this->db();
145 145
 		
146
-		$query = $this->getBaseQuery();
146
+		$query=$this->getBaseQuery();
147 147
 		$this->applyFiltersToQuery($query);
148 148
 		$values=$db->fetchAll($query);
149 149
 		
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	
155 155
     public function getPaginator()
156 156
     {
157
-        $paginator = new Paginator();
157
+        $paginator=new Paginator();
158 158
         $paginator->setQuery($this);
159 159
 
160 160
         return $paginator;
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 	{
167 167
 		$db=$this->db();
168 168
 		
169
-		$query = $this->getBaseQuery();
169
+		$query=$this->getBaseQuery();
170 170
 		$this->applyFiltersToQuery($query);
171 171
        if ($this->hasLimit() || $this->hasOffset()) {
172 172
             $query->limit($this->getLimit(), $this->getOffset());
@@ -178,10 +178,10 @@  discard block
 block discarded – undo
178 178
     public function getBaseQuery()
179 179
     {
180 180
 		$db=$this->db();
181
-		$query = $db->select()->from(
181
+		$query=$db->select()->from(
182 182
             $this->moduleConfig->getTrapTableName(),
183 183
 		    $this->moduleConfig->getTrapHostListDisplayColumns()
184
-		    )->group(array('t.source_ip','t.source_name','t.trap_oid'))
184
+		    )->group(array('t.source_ip', 't.source_name', 't.trap_oid'))
185 185
 		    ->order('t.source_ip');
186 186
 
187 187
         return $query;
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	protected $filter_Handler;
193 193
 	protected $filter_query='';
194 194
 	protected $filter_done='';
195
-	protected $filter_query_list=array('q','done');
195
+	protected $filter_query_list=array('q', 'done');
196 196
 	public function renderFilterHTML()
197 197
 	{
198 198
 		$htm=' <form id="filter" name="mainFilter" 
@@ -202,17 +202,17 @@  discard block
 block discarded – undo
202 202
 		$htm.='<input type="text" name="q" title="Search is simple! Try to combine multiple words" 
203 203
 		placeholder="Search..." class="search" value="'.$this->filter_query.'">';
204 204
 		$htm.='<input type="checkbox" id="checkbox_done" name="done" value="1" class="autosubmit" ';
205
-		if	($this->filter_done == 1) { $htm.=' checked ';}
205
+		if ($this->filter_done == 1) { $htm.=' checked '; }
206 206
 		$htm.='> <label for="checkbox_done">Hide processed traps</label>';
207 207
 		$htm.='</form>';
208 208
 		return $htm;
209 209
 	}
210 210
 	
211
-	public function updateFilter($handler,$filter)
211
+	public function updateFilter($handler, $filter)
212 212
 	{
213 213
 		$this->filter_Handler=$handler->remove($this->filter_query_list)->__toString();
214
-		$this->filter_query=(isset($filter['q']))?$this->filter_query=$filter['q']:'';
215
-		$this->filter_done=(isset($filter['done']))?$this->filter_done=$filter['done']:0;
214
+		$this->filter_query=(isset($filter['q'])) ? $this->filter_query=$filter['q'] : '';
215
+		$this->filter_done=(isset($filter['done'])) ? $this->filter_done=$filter['done'] : 0;
216 216
 	}
217 217
 	
218 218
     protected function getSearchColumns()
@@ -227,20 +227,20 @@  discard block
 block discarded – undo
227 227
 
228 228
     public function setFilter($filter)
229 229
     {
230
-        $this->filter = $filter;
230
+        $this->filter=$filter;
231 231
         return $this;
232 232
     }
233 233
 	
234 234
 	public function getFilterEditor(Request $request)
235 235
     {
236
-        $filterEditor = Widget::create('filterEditor')
236
+        $filterEditor=Widget::create('filterEditor')
237 237
             ->setColumns(array_keys($this->getColumns()))
238 238
             ->setSearchColumns(array_keys($this->getSearchColumns()))
239 239
             ->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
240 240
             ->ignoreParams('page')
241 241
             ->handleRequest($request);
242 242
 
243
-        $filter = $filterEditor->getFilter();
243
+        $filter=$filterEditor->getFilter();
244 244
         $this->setFilter($filter);
245 245
 
246 246
         return $filterEditor;
@@ -254,9 +254,9 @@  discard block
 block discarded – undo
254 254
 		{
255 255
 			$sql.='(';
256 256
 			$first=1;
257
-			foreach($this->moduleConfig->getTrapListSearchColumns() as $column)
257
+			foreach ($this->moduleConfig->getTrapListSearchColumns() as $column)
258 258
 			{
259
-				if ($first==0) $sql.=' OR ';
259
+				if ($first == 0) $sql.=' OR ';
260 260
 				$first=0;
261 261
 				$sql.=" ".$column." LIKE  '%".$this->filter_query."%' ";
262 262
 			}
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -256,7 +256,9 @@  discard block
 block discarded – undo
256 256
 			$first=1;
257 257
 			foreach($this->moduleConfig->getTrapListSearchColumns() as $column)
258 258
 			{
259
-				if ($first==0) $sql.=' OR ';
259
+				if ($first==0) {
260
+					$sql.=' OR ';
261
+				}
260 262
 				$first=0;
261 263
 				$sql.=" ".$column." LIKE  '%".$this->filter_query."%' ";
262 264
 			}
@@ -264,10 +266,14 @@  discard block
 block discarded – undo
264 266
 		}
265 267
 		if ($this->filter_done == 1)
266 268
 		{
267
-			if ($sql != '') $sql.=' AND ';
269
+			if ($sql != '') {
270
+				$sql.=' AND ';
271
+			}
268 272
 			$sql.="(status != 'done')";
269 273
 		}
270
-		if ($sql != '') $query->where($sql);		
274
+		if ($sql != '') {
275
+			$query->where($sql);
276
+		}
271 277
         return $query;
272 278
     }	
273 279
 
Please login to merge, or discard this patch.
library/Trapdirector/Tables/TrapTable.php 2 patches
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 
27 27
 	// view limits
28 28
 	protected $limit;
29
-    protected $offset;
29
+	protected $offset;
30 30
 
31 31
 	// Used for rendering days in list
32 32
 	protected $columnCount;
@@ -34,55 +34,55 @@  discard block
 block discarded – undo
34 34
 	
35 35
 	// Filters 
36 36
 	
37
-    protected $filter;
38
-    protected $enforcedFilters = array();
39
-    protected $searchColumns = array();
37
+	protected $filter;
38
+	protected $enforcedFilters = array();
39
+	protected $searchColumns = array();
40 40
 	
41 41
 	
42 42
 	// Must return titles in array ( id => display_name )
43 43
 	abstract protected function getTitles();
44 44
 	// ****************** Day header
45
-    protected function renderDayIfNew($timestamp)
46
-    {
47
-        $view = $this->getView();
45
+	protected function renderDayIfNew($timestamp)
46
+	{
47
+		$view = $this->getView();
48 48
 
49 49
 		// Check for date local format
50
-        if (in_array(setlocale(LC_ALL, 0), array('en_US.UTF-8', 'C'))) {
51
-            $day = date('l, jS F Y', (int) $timestamp);
52
-        } else {
53
-            $day = strftime('%A, %e. %B, %Y', (int) $timestamp);
54
-        }
55
-
56
-        if ($this->lastDay === $day) {
57
-            return;
58
-        }
59
-
60
-        if ($this->lastDay === null) {
61
-            $htm = "<thead>\n  <tr>\n";
62
-        } else {
63
-            $htm = "</tbody>\n<thead>\n  <tr>\n";
64
-        }
65
-
66
-        if ($this->columnCount === null) {
67
-            $this->columnCount = count($this->getTitles());
68
-        }
69
-
70
-        $htm .= '<th colspan="' . $this->columnCount . '">' . $view->escape($day) . '</th>' . "\n";
71
-        if ($this->lastDay === null) {
72
-            $htm .= "  </tr>\n";
73
-        } else {
74
-            $htm .= "  </tr>\n</thead>\n";
75
-        }
76
-
77
-        $this->lastDay = $day;
78
-
79
-        return $htm . "<tbody>\n";
80
-    }		
50
+		if (in_array(setlocale(LC_ALL, 0), array('en_US.UTF-8', 'C'))) {
51
+			$day = date('l, jS F Y', (int) $timestamp);
52
+		} else {
53
+			$day = strftime('%A, %e. %B, %Y', (int) $timestamp);
54
+		}
55
+
56
+		if ($this->lastDay === $day) {
57
+			return;
58
+		}
59
+
60
+		if ($this->lastDay === null) {
61
+			$htm = "<thead>\n  <tr>\n";
62
+		} else {
63
+			$htm = "</tbody>\n<thead>\n  <tr>\n";
64
+		}
65
+
66
+		if ($this->columnCount === null) {
67
+			$this->columnCount = count($this->getTitles());
68
+		}
69
+
70
+		$htm .= '<th colspan="' . $this->columnCount . '">' . $view->escape($day) . '</th>' . "\n";
71
+		if ($this->lastDay === null) {
72
+			$htm .= "  </tr>\n";
73
+		} else {
74
+			$htm .= "  </tr>\n</thead>\n";
75
+		}
76
+
77
+		$this->lastDay = $day;
78
+
79
+		return $htm . "<tbody>\n";
80
+	}		
81 81
 	// ******************  Render table in html  
82
-    public function __toString()
83
-    {
84
-        return $this->render();
85
-    }
82
+	public function __toString()
83
+	{
84
+		return $this->render();
85
+	}
86 86
 	
87 87
 	abstract public function render();
88 88
 	
@@ -92,76 +92,76 @@  discard block
 block discarded – undo
92 92
 		$this->moduleConfig = $conf;
93 93
 	}
94 94
 	// ******************  View get/set
95
-    protected function getView()
96
-    {
97
-        if ($this->view === null) {
98
-            $this->view = Icinga::app()->getViewRenderer()->view;
99
-        }
100
-        return $this->view;
101
-    }
95
+	protected function getView()
96
+	{
97
+		if ($this->view === null) {
98
+			$this->view = Icinga::app()->getViewRenderer()->view;
99
+		}
100
+		return $this->view;
101
+	}
102 102
 
103
-    public function setView($view)
104
-    {
105
-        $this->view = $view;
106
-    }	
103
+	public function setView($view)
104
+	{
105
+		$this->view = $view;
106
+	}	
107 107
 	
108 108
 	// Limits
109 109
 	
110
-    public function limit($count = null, $offset = null)
111
-    {
112
-        $this->limit = $count;
113
-        $this->offset = $offset;
110
+	public function limit($count = null, $offset = null)
111
+	{
112
+		$this->limit = $count;
113
+		$this->offset = $offset;
114 114
 
115
-        return $this;
116
-    }
115
+		return $this;
116
+	}
117 117
 
118
-    public function hasLimit()
119
-    {
120
-        return $this->limit !== null;
121
-    }
118
+	public function hasLimit()
119
+	{
120
+		return $this->limit !== null;
121
+	}
122 122
 
123
-    public function getLimit()
124
-    {
125
-        return $this->limit;
126
-    }
123
+	public function getLimit()
124
+	{
125
+		return $this->limit;
126
+	}
127 127
 
128
-    public function hasOffset()
129
-    {
130
-        return $this->offset !== null;
131
-    }
128
+	public function hasOffset()
129
+	{
130
+		return $this->offset !== null;
131
+	}
132 132
 
133
-    public function getOffset()
134
-    {
135
-        return $this->offset;
136
-    }
133
+	public function getOffset()
134
+	{
135
+		return $this->offset;
136
+	}
137 137
 	
138 138
 	abstract function count();
139 139
 	
140
-    public function getPaginator()
141
-    {
142
-        $paginator = new Paginator();
143
-        $paginator->setQuery($this);
140
+	public function getPaginator()
141
+	{
142
+		$paginator = new Paginator();
143
+		$paginator->setQuery($this);
144 144
 
145
-        return $paginator;
146
-    }
145
+		return $paginator;
146
+	}
147 147
 	
148 148
 	// ****************** DB connection and query
149 149
 	
150
-    public function setConnection(Selectable $connection)
151
-    {
152
-        $this->connection = $connection;
153
-        return $this;
154
-    }
150
+	public function setConnection(Selectable $connection)
151
+	{
152
+		$this->connection = $connection;
153
+		return $this;
154
+	}
155 155
 
156
-    protected function connection()
157
-    {
158
-        return $this->connection;
159
-    }
156
+	protected function connection()
157
+	{
158
+		return $this->connection;
159
+	}
160 160
 
161
-    protected function db()
162
-    {
163
-        return $this->connection()->getConnection();
164
-    }
161
+	protected function db()
162
+	{
163
+		return $this->connection()->getConnection();
164
+	}
165 165
 	
166 166
 	protected function getTable()
167 167
 	{
@@ -169,52 +169,52 @@  discard block
 block discarded – undo
169 169
 		
170 170
 		$query = $this->getBaseQuery();
171 171
 		
172
-       if ($this->hasLimit() || $this->hasOffset()) {
173
-            $query->limit($this->getLimit(), $this->getOffset());
174
-        }		
172
+	   if ($this->hasLimit() || $this->hasOffset()) {
173
+			$query->limit($this->getLimit(), $this->getOffset());
174
+		}		
175 175
 		
176 176
 		return $db->fetchAll($query);
177 177
 	}
178 178
 	 
179
-    abstract public function getBaseQuery(); 
179
+	abstract public function getBaseQuery(); 
180 180
 	
181 181
 	// ****************** Filters
182 182
 
183
-    protected function getSearchColumns()
184
-    {
185
-        return $this->getColumns();
186
-    }
183
+	protected function getSearchColumns()
184
+	{
185
+		return $this->getColumns();
186
+	}
187 187
 	
188 188
 	abstract public function getColumns();
189 189
 
190
-    public function setFilter($filter)
191
-    {
192
-        $this->filter = $filter;
193
-        return $this;
194
-    }
190
+	public function setFilter($filter)
191
+	{
192
+		$this->filter = $filter;
193
+		return $this;
194
+	}
195 195
 	
196 196
 	public function getFilterEditor(Request $request)
197
-    {
198
-        $filterEditor = Widget::create('filterEditor')
199
-            ->setColumns(array_keys($this->getColumns()))
200
-            ->setSearchColumns(array_keys($this->getSearchColumns()))
201
-            ->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
202
-            ->ignoreParams('page')
203
-            ->handleRequest($request);
197
+	{
198
+		$filterEditor = Widget::create('filterEditor')
199
+			->setColumns(array_keys($this->getColumns()))
200
+			->setSearchColumns(array_keys($this->getSearchColumns()))
201
+			->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
202
+			->ignoreParams('page')
203
+			->handleRequest($request);
204 204
 
205
-        $filter = $filterEditor->getFilter();
206
-        $this->setFilter($filter);
205
+		$filter = $filterEditor->getFilter();
206
+		$this->setFilter($filter);
207 207
 
208
-        return $filterEditor;
209
-    }
208
+		return $filterEditor;
209
+	}
210 210
 	
211 211
 	protected function renderFilter($filter)
212 212
 	{ // TODO : create a better filter wher user can choose host/oid to filter
213 213
 	}
214 214
 	
215
-    protected function applyFiltersToQuery($query)
216
-    {
217
-        /*
215
+	protected function applyFiltersToQuery($query)
216
+	{
217
+		/*
218 218
 		$filter = null;
219 219
         $enforced = $this->enforcedFilters;
220 220
         if ($this->filter && ! $this->filter->isEmpty()) {
@@ -230,8 +230,8 @@  discard block
 block discarded – undo
230 230
             $query->where($this->renderFilter($filter));
231 231
         }
232 232
 		*/
233
-        return $query;
234
-    }	
233
+		return $query;
234
+	}	
235 235
 
236 236
 }
237 237
 
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
 	// Filters 
36 36
 	
37 37
     protected $filter;
38
-    protected $enforcedFilters = array();
39
-    protected $searchColumns = array();
38
+    protected $enforcedFilters=array();
39
+    protected $searchColumns=array();
40 40
 	
41 41
 	
42 42
 	// Must return titles in array ( id => display_name )
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	// ****************** Day header
45 45
     protected function renderDayIfNew($timestamp)
46 46
     {
47
-        $view = $this->getView();
47
+        $view=$this->getView();
48 48
 
49 49
 		// Check for date local format
50 50
         if (in_array(setlocale(LC_ALL, 0), array('en_US.UTF-8', 'C'))) {
51
-            $day = date('l, jS F Y', (int) $timestamp);
51
+            $day=date('l, jS F Y', (int) $timestamp);
52 52
         } else {
53
-            $day = strftime('%A, %e. %B, %Y', (int) $timestamp);
53
+            $day=strftime('%A, %e. %B, %Y', (int) $timestamp);
54 54
         }
55 55
 
56 56
         if ($this->lastDay === $day) {
@@ -58,25 +58,25 @@  discard block
 block discarded – undo
58 58
         }
59 59
 
60 60
         if ($this->lastDay === null) {
61
-            $htm = "<thead>\n  <tr>\n";
61
+            $htm="<thead>\n  <tr>\n";
62 62
         } else {
63
-            $htm = "</tbody>\n<thead>\n  <tr>\n";
63
+            $htm="</tbody>\n<thead>\n  <tr>\n";
64 64
         }
65 65
 
66 66
         if ($this->columnCount === null) {
67
-            $this->columnCount = count($this->getTitles());
67
+            $this->columnCount=count($this->getTitles());
68 68
         }
69 69
 
70
-        $htm .= '<th colspan="' . $this->columnCount . '">' . $view->escape($day) . '</th>' . "\n";
70
+        $htm.='<th colspan="'.$this->columnCount.'">'.$view->escape($day).'</th>'."\n";
71 71
         if ($this->lastDay === null) {
72
-            $htm .= "  </tr>\n";
72
+            $htm.="  </tr>\n";
73 73
         } else {
74
-            $htm .= "  </tr>\n</thead>\n";
74
+            $htm.="  </tr>\n</thead>\n";
75 75
         }
76 76
 
77
-        $this->lastDay = $day;
77
+        $this->lastDay=$day;
78 78
 
79
-        return $htm . "<tbody>\n";
79
+        return $htm."<tbody>\n";
80 80
     }		
81 81
 	// ******************  Render table in html  
82 82
     public function __toString()
@@ -89,28 +89,28 @@  discard block
 block discarded – undo
89 89
 	// ******************  Static config set
90 90
 	public function setConfig($conf)
91 91
 	{
92
-		$this->moduleConfig = $conf;
92
+		$this->moduleConfig=$conf;
93 93
 	}
94 94
 	// ******************  View get/set
95 95
     protected function getView()
96 96
     {
97 97
         if ($this->view === null) {
98
-            $this->view = Icinga::app()->getViewRenderer()->view;
98
+            $this->view=Icinga::app()->getViewRenderer()->view;
99 99
         }
100 100
         return $this->view;
101 101
     }
102 102
 
103 103
     public function setView($view)
104 104
     {
105
-        $this->view = $view;
105
+        $this->view=$view;
106 106
     }	
107 107
 	
108 108
 	// Limits
109 109
 	
110
-    public function limit($count = null, $offset = null)
110
+    public function limit($count=null, $offset=null)
111 111
     {
112
-        $this->limit = $count;
113
-        $this->offset = $offset;
112
+        $this->limit=$count;
113
+        $this->offset=$offset;
114 114
 
115 115
         return $this;
116 116
     }
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 	
140 140
     public function getPaginator()
141 141
     {
142
-        $paginator = new Paginator();
142
+        $paginator=new Paginator();
143 143
         $paginator->setQuery($this);
144 144
 
145 145
         return $paginator;
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	
150 150
     public function setConnection(Selectable $connection)
151 151
     {
152
-        $this->connection = $connection;
152
+        $this->connection=$connection;
153 153
         return $this;
154 154
     }
155 155
 
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 	{
168 168
 		$db=$this->db();
169 169
 		
170
-		$query = $this->getBaseQuery();
170
+		$query=$this->getBaseQuery();
171 171
 		
172 172
        if ($this->hasLimit() || $this->hasOffset()) {
173 173
             $query->limit($this->getLimit(), $this->getOffset());
@@ -189,20 +189,20 @@  discard block
 block discarded – undo
189 189
 
190 190
     public function setFilter($filter)
191 191
     {
192
-        $this->filter = $filter;
192
+        $this->filter=$filter;
193 193
         return $this;
194 194
     }
195 195
 	
196 196
 	public function getFilterEditor(Request $request)
197 197
     {
198
-        $filterEditor = Widget::create('filterEditor')
198
+        $filterEditor=Widget::create('filterEditor')
199 199
             ->setColumns(array_keys($this->getColumns()))
200 200
             ->setSearchColumns(array_keys($this->getSearchColumns()))
201 201
             ->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
202 202
             ->ignoreParams('page')
203 203
             ->handleRequest($request);
204 204
 
205
-        $filter = $filterEditor->getFilter();
205
+        $filter=$filterEditor->getFilter();
206 206
         $this->setFilter($filter);
207 207
 
208 208
         return $filterEditor;
Please login to merge, or discard this patch.
library/Trapdirector/Tables/HandlerTableList.php 3 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
 	
32 32
 	// Filters 
33 33
 	
34
-    protected $filter;
35
-    protected $enforcedFilters = array();
36
-    protected $searchColumns = array();
34
+	protected $filter;
35
+	protected $enforcedFilters = array();
36
+	protected $searchColumns = array();
37 37
 	
38 38
 	protected function getTitles() {
39 39
 		return $this->moduleConfig->getHandlerListTitles();
@@ -45,10 +45,10 @@  discard block
 block discarded – undo
45 45
 		$this->doTranslate=true;
46 46
 	}
47 47
 	// ******************  Render table in html  
48
-    public function __toString()
49
-    {
50
-        return $this->render();
51
-    }
48
+	public function __toString()
49
+	{
50
+		return $this->render();
51
+	}
52 52
 	
53 53
 	public function render()
54 54
 	{
@@ -153,30 +153,30 @@  discard block
 block discarded – undo
153 153
 
154 154
 	}
155 155
 
156
-    public function count()
157
-    {
158
-        $db = $this->connection()->getConnection();
159
-        $query = clone($this->getBaseQuery());
160
-        $query->reset('order')->columns(array('COUNT(*)'));
161
-        $this->applyFiltersToQuery($query);
156
+	public function count()
157
+	{
158
+		$db = $this->connection()->getConnection();
159
+		$query = clone($this->getBaseQuery());
160
+		$query->reset('order')->columns(array('COUNT(*)'));
161
+		$this->applyFiltersToQuery($query);
162 162
 
163 163
 		$db=$this->db();
164 164
 		
165 165
 		$query = $db->select()->from(
166
-            $this->moduleConfig->getTrapRuleName(),
167
-            array('COUNT(*)')
168
-        );
166
+			$this->moduleConfig->getTrapRuleName(),
167
+			array('COUNT(*)')
168
+		);
169 169
 		
170
-        return $db->fetchOne($query);
171
-    }
170
+		return $db->fetchOne($query);
171
+	}
172 172
 	
173
-    public function getPaginator()
174
-    {
175
-        $paginator = new Paginator();
176
-        $paginator->setQuery($this);
173
+	public function getPaginator()
174
+	{
175
+		$paginator = new Paginator();
176
+		$paginator->setQuery($this);
177 177
 
178
-        return $paginator;
179
-    }
178
+		return $paginator;
179
+	}
180 180
 	
181 181
 	// ****************** DB connection and query
182 182
 	
@@ -186,63 +186,63 @@  discard block
 block discarded – undo
186 186
 		
187 187
 		$query = $this->getBaseQuery();
188 188
 		
189
-       if ($this->hasLimit() || $this->hasOffset()) {
190
-            $query->limit($this->getLimit(), $this->getOffset());
191
-        }		
189
+	   if ($this->hasLimit() || $this->hasOffset()) {
190
+			$query->limit($this->getLimit(), $this->getOffset());
191
+		}		
192 192
 		
193 193
 		return $db->fetchAll($query);
194 194
 	}
195 195
 	 
196
-    public function getBaseQuery()
197
-    {
196
+	public function getBaseQuery()
197
+	{
198 198
 		$db=$this->db();
199 199
 		
200 200
 		$query = $db->select()->from(
201
-            $this->moduleConfig->getTrapRuleName(),
202
-            $this->moduleConfig->getHandlerListDisplayColumns()
203
-        )->order('host_name DESC,trap_oid DESC');
201
+			$this->moduleConfig->getTrapRuleName(),
202
+			$this->moduleConfig->getHandlerListDisplayColumns()
203
+		)->order('host_name DESC,trap_oid DESC');
204 204
 
205
-        return $query;
206
-    }	 
205
+		return $query;
206
+	}	 
207 207
 	
208 208
 	// ****************** Filters
209 209
 
210
-    protected function getSearchColumns()
211
-    {
212
-        return $this->getColumns();
213
-    }
210
+	protected function getSearchColumns()
211
+	{
212
+		return $this->getColumns();
213
+	}
214 214
 	
215 215
 	public function getColumns()
216 216
 	{
217 217
 		return $this->moduleConfig->getHandlerListDisplayColumns();
218 218
 	}
219 219
 
220
-    public function setFilter($filter)
221
-    {
222
-        $this->filter = $filter;
223
-        return $this;
224
-    }
220
+	public function setFilter($filter)
221
+	{
222
+		$this->filter = $filter;
223
+		return $this;
224
+	}
225 225
 	
226 226
 	public function getFilterEditor(Request $request)
227
-    {
228
-        $filterEditor = Widget::create('filterEditor')
229
-            ->setColumns(array_keys($this->getColumns()))
230
-            ->setSearchColumns(array_keys($this->getSearchColumns()))
231
-            ->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
232
-            ->ignoreParams('page')
233
-            ->handleRequest($request);
227
+	{
228
+		$filterEditor = Widget::create('filterEditor')
229
+			->setColumns(array_keys($this->getColumns()))
230
+			->setSearchColumns(array_keys($this->getSearchColumns()))
231
+			->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
232
+			->ignoreParams('page')
233
+			->handleRequest($request);
234 234
 
235
-        $filter = $filterEditor->getFilter();
236
-        $this->setFilter($filter);
235
+		$filter = $filterEditor->getFilter();
236
+		$this->setFilter($filter);
237 237
 
238
-        return $filterEditor;
239
-    }
238
+		return $filterEditor;
239
+	}
240 240
 	
241
-    protected function applyFiltersToQuery($query)
242
-    {
241
+	protected function applyFiltersToQuery($query)
242
+	{
243 243
 		// TODO : implement
244 244
 		
245
-        /*$filter = null;
245
+		/*$filter = null;
246 246
         $enforced = $this->enforcedFilters;
247 247
         if ($this->filter && ! $this->filter->isEmpty()) {
248 248
             $filter = $this->filter;
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
         }
258 258
 		*/
259 259
 		
260
-        return $query;
261
-    }	
260
+		return $query;
261
+	}	
262 262
 
263 263
 }
264 264
 
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
 	// Filters 
33 33
 	
34 34
     protected $filter;
35
-    protected $enforcedFilters = array();
36
-    protected $searchColumns = array();
35
+    protected $enforcedFilters=array();
36
+    protected $searchColumns=array();
37 37
 	
38 38
 	protected function getTitles() {
39 39
 		return $this->moduleConfig->getHandlerListTitles();
@@ -53,34 +53,34 @@  discard block
 block discarded – undo
53 53
 	public function render()
54 54
 	{
55 55
 		$data=$this->getTable();
56
-		$view = $this->getView();
57
-		$this->columnCount = count($this->getTitles());
56
+		$view=$this->getView();
57
+		$this->columnCount=count($this->getTitles());
58 58
 		$this->lastDay=null;
59 59
 		// Table start
60
-		$htm  = '<table class="simple common-table table-row-selectable">';
60
+		$htm='<table class="simple common-table table-row-selectable">';
61 61
 		
62 62
 		// Titles
63
-		$htm .= "<thead>\n  <tr>\n";
64
-		$titles = $this->getTitles();
63
+		$htm.="<thead>\n  <tr>\n";
64
+		$titles=$this->getTitles();
65 65
 		foreach ($titles as $title) 
66 66
 		{
67
-			$htm .= '    <th>' . $view->escape($view->translate($title)) . "</th>\n";
67
+			$htm.='    <th>'.$view->escape($view->translate($title))."</th>\n";
68 68
 		}
69
-		$htm .= "  </tr>\n</thead>\n";
69
+		$htm.="  </tr>\n</thead>\n";
70 70
 		
71 71
 		// Rows
72
-		$htm .= "<tbody>\n";
72
+		$htm.="<tbody>\n";
73 73
 		
74 74
 		foreach ($data as $row) 
75 75
 		{
76
-			$firstCol = true;
76
+			$firstCol=true;
77 77
 			// Put date header
78 78
 			//$htm .= $this->renderDayIfNew($row->timestamp);
79 79
 			
80 80
 			
81 81
 			// Render row
82
-			$htm .= '<tr '.' >';
83
-			foreach ( $titles as $rowkey => $title) 
82
+			$htm.='<tr '.' >';
83
+			foreach ($titles as $rowkey => $title) 
84 84
 			{
85 85
 				// Check missing value
86 86
 				if (property_exists($row, $rowkey)) 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 						break;
94 94
 						case 'trap_oid': // try to traslate oids.
95 95
 						
96
-							if ($this->doTranslate==true)
96
+							if ($this->doTranslate == true)
97 97
 							{
98 98
 								$oidName=$this->MIB->translateOID($row->$rowkey);
99 99
 								if (isset($oidName['name']))
@@ -102,52 +102,52 @@  discard block
 block discarded – undo
102 102
 								}
103 103
 								else
104 104
 								{
105
-									$val = $row->$rowkey;
105
+									$val=$row->$rowkey;
106 106
 								}								
107 107
 							}
108 108
 							else
109 109
 							{
110
-								$val = $row->$rowkey;
110
+								$val=$row->$rowkey;
111 111
 							}
112 112
 						break;
113 113
 						case 'host_name': // switch to hostgroup if name is null
114 114
 							if ($row->$rowkey == null)
115 115
 							{
116
-								$val = $row->host_group_name;
116
+								$val=$row->host_group_name;
117 117
 							}
118 118
 							else
119 119
 							{
120
-								$val = $row->$rowkey;
120
+								$val=$row->$rowkey;
121 121
 							}
122 122
 						break;
123 123
 						default:
124
-							$val = $row->$rowkey;
124
+							$val=$row->$rowkey;
125 125
 					}
126
-					if ($rowkey == 'trap_oid' && $this->doTranslate==true)
126
+					if ($rowkey == 'trap_oid' && $this->doTranslate == true)
127 127
 					{					
128 128
 							
129 129
 					}
130 130
 				} else {
131
-					$val = '-';
131
+					$val='-';
132 132
 				}
133 133
 				if ($firstCol == true) { // Put link in first column for trap detail.
134
-					$htm .= '<td>' 
134
+					$htm.='<td>' 
135 135
 							. $view->qlink(
136 136
 									$view->escape($val),  
137 137
 									Url::fromPath(
138
-										$this->moduleConfig->urlPath() . '/handler/add', 
138
+										$this->moduleConfig->urlPath().'/handler/add', 
139 139
 										array('ruleid' => $row->id)
140 140
 									)
141 141
 							)
142 142
 							. '</td>';
143 143
 				} else {
144
-					$htm .= '<td>' . $view->escape($val) . '</td>';
144
+					$htm.='<td>'.$view->escape($val).'</td>';
145 145
 				}
146 146
 				$firstCol=false;
147 147
 			}
148
-			$htm .= "<tr>\n";
148
+			$htm.="<tr>\n";
149 149
 		}
150
-		$htm .= "</tbody></table>\n";
150
+		$htm.="</tbody></table>\n";
151 151
 		//$htm .= "Filter : " . $this->filter."<br>\n";
152 152
 		return $htm;
153 153
 
@@ -155,14 +155,14 @@  discard block
 block discarded – undo
155 155
 
156 156
     public function count()
157 157
     {
158
-        $db = $this->connection()->getConnection();
159
-        $query = clone($this->getBaseQuery());
158
+        $db=$this->connection()->getConnection();
159
+        $query=clone($this->getBaseQuery());
160 160
         $query->reset('order')->columns(array('COUNT(*)'));
161 161
         $this->applyFiltersToQuery($query);
162 162
 
163 163
 		$db=$this->db();
164 164
 		
165
-		$query = $db->select()->from(
165
+		$query=$db->select()->from(
166 166
             $this->moduleConfig->getTrapRuleName(),
167 167
             array('COUNT(*)')
168 168
         );
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	
173 173
     public function getPaginator()
174 174
     {
175
-        $paginator = new Paginator();
175
+        $paginator=new Paginator();
176 176
         $paginator->setQuery($this);
177 177
 
178 178
         return $paginator;
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 	{
185 185
 		$db=$this->db();
186 186
 		
187
-		$query = $this->getBaseQuery();
187
+		$query=$this->getBaseQuery();
188 188
 		
189 189
        if ($this->hasLimit() || $this->hasOffset()) {
190 190
             $query->limit($this->getLimit(), $this->getOffset());
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
     {
198 198
 		$db=$this->db();
199 199
 		
200
-		$query = $db->select()->from(
200
+		$query=$db->select()->from(
201 201
             $this->moduleConfig->getTrapRuleName(),
202 202
             $this->moduleConfig->getHandlerListDisplayColumns()
203 203
         )->order('host_name DESC,trap_oid DESC');
@@ -219,20 +219,20 @@  discard block
 block discarded – undo
219 219
 
220 220
     public function setFilter($filter)
221 221
     {
222
-        $this->filter = $filter;
222
+        $this->filter=$filter;
223 223
         return $this;
224 224
     }
225 225
 	
226 226
 	public function getFilterEditor(Request $request)
227 227
     {
228
-        $filterEditor = Widget::create('filterEditor')
228
+        $filterEditor=Widget::create('filterEditor')
229 229
             ->setColumns(array_keys($this->getColumns()))
230 230
             ->setSearchColumns(array_keys($this->getSearchColumns()))
231 231
             ->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
232 232
             ->ignoreParams('page')
233 233
             ->handleRequest($request);
234 234
 
235
-        $filter = $filterEditor->getFilter();
235
+        $filter=$filterEditor->getFilter();
236 236
         $this->setFilter($filter);
237 237
 
238 238
         return $filterEditor;
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -99,13 +99,11 @@  discard block
 block discarded – undo
99 99
 								if (isset($oidName['name']))
100 100
 								{
101 101
 									$val=$oidName['name'];
102
-								}
103
-								else
102
+								} else
104 103
 								{
105 104
 									$val = $row->$rowkey;
106 105
 								}								
107
-							}
108
-							else
106
+							} else
109 107
 							{
110 108
 								$val = $row->$rowkey;
111 109
 							}
@@ -114,8 +112,7 @@  discard block
 block discarded – undo
114 112
 							if ($row->$rowkey == null)
115 113
 							{
116 114
 								$val = $row->host_group_name;
117
-							}
118
-							else
115
+							} else
119 116
 							{
120 117
 								$val = $row->$rowkey;
121 118
 							}
Please login to merge, or discard this patch.
library/Trapdirector/Tables/TrapTableList.php 3 patches
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -20,9 +20,9 @@  discard block
 block discarded – undo
20 20
 	
21 21
 	// Filters 
22 22
 	
23
-    protected $filter;
24
-    protected $enforcedFilters = array();
25
-    protected $searchColumns = array();
23
+	protected $filter;
24
+	protected $enforcedFilters = array();
25
+	protected $searchColumns = array();
26 26
 	
27 27
 	protected function getTitles() {
28 28
 		// TODO : check moduleconfig is set
@@ -30,10 +30,10 @@  discard block
 block discarded – undo
30 30
 	}
31 31
 		
32 32
 	// ******************  Render table in html  
33
-    public function __toString()
34
-    {
35
-        return $this->render();
36
-    }
33
+	public function __toString()
34
+	{
35
+		return $this->render();
36
+	}
37 37
 	
38 38
 	public function render()
39 39
 	{
@@ -97,26 +97,26 @@  discard block
 block discarded – undo
97 97
 
98 98
 	}
99 99
 
100
-    public function count()
101
-    {
102
-        $db=$this->db();
100
+	public function count()
101
+	{
102
+		$db=$this->db();
103 103
 		
104 104
 		$query = $db->select()->from(
105
-            $this->moduleConfig->getTrapTableName(),
106
-            array('COUNT(*)')
107
-        );
105
+			$this->moduleConfig->getTrapTableName(),
106
+			array('COUNT(*)')
107
+		);
108 108
 		$this->applyFiltersToQuery($query);
109 109
 		
110
-        return $db->fetchOne($query);
111
-    }
110
+		return $db->fetchOne($query);
111
+	}
112 112
 	
113
-    public function getPaginator()
114
-    {
115
-        $paginator = new Paginator();
116
-        $paginator->setQuery($this);
113
+	public function getPaginator()
114
+	{
115
+		$paginator = new Paginator();
116
+		$paginator->setQuery($this);
117 117
 
118
-        return $paginator;
119
-    }
118
+		return $paginator;
119
+	}
120 120
 	
121 121
 	// ****************** DB connection and query
122 122
 	
@@ -126,24 +126,24 @@  discard block
 block discarded – undo
126 126
 		
127 127
 		$query = $this->getBaseQuery();
128 128
 		$this->applyFiltersToQuery($query);
129
-       if ($this->hasLimit() || $this->hasOffset()) {
130
-            $query->limit($this->getLimit(), $this->getOffset());
131
-        }		
129
+	   if ($this->hasLimit() || $this->hasOffset()) {
130
+			$query->limit($this->getLimit(), $this->getOffset());
131
+		}		
132 132
 		
133 133
 		return $db->fetchAll($query);
134 134
 	}
135 135
 	 
136
-    public function getBaseQuery()
137
-    {
136
+	public function getBaseQuery()
137
+	{
138 138
 		$db=$this->db();
139 139
 		
140 140
 		$query = $db->select()->from(
141
-            $this->moduleConfig->getTrapTableName(),
142
-            $this->moduleConfig->getTrapListDisplayColumns()
143
-        )->order('timestamp DESC');
141
+			$this->moduleConfig->getTrapTableName(),
142
+			$this->moduleConfig->getTrapListDisplayColumns()
143
+		)->order('timestamp DESC');
144 144
 
145
-        return $query;
146
-    }	 
145
+		return $query;
146
+	}	 
147 147
 	
148 148
 	// ****************** Filters
149 149
 
@@ -173,39 +173,39 @@  discard block
 block discarded – undo
173 173
 		$this->filter_done=(isset($filter['done']))?$this->filter_done=$filter['done']:0;
174 174
 	}
175 175
 	
176
-    protected function getSearchColumns()
177
-    {
178
-        return $this->getColumns();
179
-    }
176
+	protected function getSearchColumns()
177
+	{
178
+		return $this->getColumns();
179
+	}
180 180
 	
181 181
 	public function getColumns()
182 182
 	{
183 183
 		return $this->moduleConfig->getTrapListDisplayColumns();
184 184
 	}
185 185
 
186
-    public function setFilter($filter)
187
-    {
188
-        $this->filter = $filter;
189
-        return $this;
190
-    }
186
+	public function setFilter($filter)
187
+	{
188
+		$this->filter = $filter;
189
+		return $this;
190
+	}
191 191
 	
192 192
 	public function getFilterEditor(Request $request)
193
-    {
194
-        $filterEditor = Widget::create('filterEditor')
195
-            ->setColumns(array_keys($this->getColumns()))
196
-            ->setSearchColumns(array_keys($this->getSearchColumns()))
197
-            ->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
198
-            ->ignoreParams('page')
199
-            ->handleRequest($request);
200
-
201
-        $filter = $filterEditor->getFilter();
202
-        $this->setFilter($filter);
203
-
204
-        return $filterEditor;
205
-    }
193
+	{
194
+		$filterEditor = Widget::create('filterEditor')
195
+			->setColumns(array_keys($this->getColumns()))
196
+			->setSearchColumns(array_keys($this->getSearchColumns()))
197
+			->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
198
+			->ignoreParams('page')
199
+			->handleRequest($request);
200
+
201
+		$filter = $filterEditor->getFilter();
202
+		$this->setFilter($filter);
203
+
204
+		return $filterEditor;
205
+	}
206 206
 	
207
-    protected function applyFiltersToQuery($query)
208
-    {
207
+	protected function applyFiltersToQuery($query)
208
+	{
209 209
 		
210 210
 		$sql='';
211 211
 		if ($this->filter_query != '')
@@ -226,8 +226,8 @@  discard block
 block discarded – undo
226 226
 			$sql.="(status != 'done')";
227 227
 		}
228 228
 		if ($sql != '') $query->where($sql);		
229
-        return $query;
230
-    }	
229
+		return $query;
230
+	}	
231 231
 
232 232
 }
233 233
 
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
 	// Filters 
22 22
 	
23 23
     protected $filter;
24
-    protected $enforcedFilters = array();
25
-    protected $searchColumns = array();
24
+    protected $enforcedFilters=array();
25
+    protected $searchColumns=array();
26 26
 	
27 27
 	protected function getTitles() {
28 28
 		// TODO : check moduleconfig is set
@@ -38,60 +38,60 @@  discard block
 block discarded – undo
38 38
 	public function render()
39 39
 	{
40 40
 		$data=$this->getTable();
41
-		$view = $this->getView();
42
-		$this->columnCount = count($this->getTitles());
41
+		$view=$this->getView();
42
+		$this->columnCount=count($this->getTitles());
43 43
 		$this->lastDay=null;
44 44
 		// Table start
45
-		$htm  = '<table class="simple common-table table-row-selectable">';
45
+		$htm='<table class="simple common-table table-row-selectable">';
46 46
 		
47 47
 		// Titles
48
-		$htm .= "<thead>\n  <tr>\n";
49
-		$titles = $this->getTitles();
48
+		$htm.="<thead>\n  <tr>\n";
49
+		$titles=$this->getTitles();
50 50
 		foreach ($titles as $title) 
51 51
 		{
52
-			$htm .= '    <th>' . $view->escape($view->translate($title)) . "</th>\n";
52
+			$htm.='    <th>'.$view->escape($view->translate($title))."</th>\n";
53 53
 		}
54
-		$htm .= "  </tr>\n</thead>\n";
54
+		$htm.="  </tr>\n</thead>\n";
55 55
 		
56 56
 		// Rows
57
-		$htm .= "<tbody>\n";
57
+		$htm.="<tbody>\n";
58 58
 		
59 59
 		foreach ($data as $row) 
60 60
 		{
61
-			$firstCol = true;
61
+			$firstCol=true;
62 62
 			// Put date header
63
-			$htm .= $this->renderDayIfNew($row->timestamp);
63
+			$htm.=$this->renderDayIfNew($row->timestamp);
64 64
 			
65 65
 			
66 66
 			// Render row
67
-			$htm .= '<tr '.' >';
68
-			foreach ( $titles as $rowkey => $title) 
67
+			$htm.='<tr '.' >';
68
+			foreach ($titles as $rowkey => $title) 
69 69
 			{
70 70
 				// Check missing value
71 71
 				if (property_exists($row, $rowkey)) 
72 72
 				{
73
-					$val = ($rowkey=='timestamp') ?  strftime('%T',$row->$rowkey) : $row->$rowkey;
73
+					$val=($rowkey == 'timestamp') ?  strftime('%T', $row->$rowkey) : $row->$rowkey;
74 74
 				} else {
75
-					$val = '-';
75
+					$val='-';
76 76
 				}
77 77
 				if ($firstCol == true) { // Put link in first column for trap detail.
78
-					$htm .= '<td>' 
78
+					$htm.='<td>' 
79 79
 							. $view->qlink(
80 80
 									$view->escape($val),  
81 81
 									Url::fromPath(
82
-										$this->moduleConfig->urlPath() . '/received/trapdetail', 
82
+										$this->moduleConfig->urlPath().'/received/trapdetail', 
83 83
 										array('id' => $row->id)
84 84
 									)
85 85
 							)
86 86
 							. '</td>';
87 87
 				} else {
88
-					$htm .= '<td>' . $view->escape($val) . '</td>';
88
+					$htm.='<td>'.$view->escape($val).'</td>';
89 89
 				}
90 90
 				$firstCol=false;
91 91
 			}
92
-			$htm .= "<tr>\n";
92
+			$htm.="<tr>\n";
93 93
 		}
94
-		$htm .= "</tbody></table>\n";
94
+		$htm.="</tbody></table>\n";
95 95
 		//$htm .= "Filter : " . $this->filter."<br>\n";
96 96
 		return $htm;
97 97
 
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     {
102 102
         $db=$this->db();
103 103
 		
104
-		$query = $db->select()->from(
104
+		$query=$db->select()->from(
105 105
             $this->moduleConfig->getTrapTableName(),
106 106
             array('COUNT(*)')
107 107
         );
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	
113 113
     public function getPaginator()
114 114
     {
115
-        $paginator = new Paginator();
115
+        $paginator=new Paginator();
116 116
         $paginator->setQuery($this);
117 117
 
118 118
         return $paginator;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	{
125 125
 		$db=$this->db();
126 126
 		
127
-		$query = $this->getBaseQuery();
127
+		$query=$this->getBaseQuery();
128 128
 		$this->applyFiltersToQuery($query);
129 129
        if ($this->hasLimit() || $this->hasOffset()) {
130 130
             $query->limit($this->getLimit(), $this->getOffset());
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
     {
138 138
 		$db=$this->db();
139 139
 		
140
-		$query = $db->select()->from(
140
+		$query=$db->select()->from(
141 141
             $this->moduleConfig->getTrapTableName(),
142 142
             $this->moduleConfig->getTrapListDisplayColumns()
143 143
         )->order('timestamp DESC');
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	protected $filter_Handler;
151 151
 	protected $filter_query='';
152 152
 	protected $filter_done='';
153
-	protected $filter_query_list=array('q','done');
153
+	protected $filter_query_list=array('q', 'done');
154 154
 	public function renderFilterHTML()
155 155
 	{
156 156
 		$htm=' <form id="filter" name="mainFilter" 
@@ -160,17 +160,17 @@  discard block
 block discarded – undo
160 160
 		$htm.='<input type="text" name="q" title="Search is simple! Try to combine multiple words" 
161 161
 		placeholder="Search..." class="search" value="'.$this->filter_query.'">';
162 162
 		$htm.='<input type="checkbox" id="checkbox_done" name="done" value="1" class="autosubmit" ';
163
-		if	($this->filter_done == 1) { $htm.=' checked ';}
163
+		if ($this->filter_done == 1) { $htm.=' checked '; }
164 164
 		$htm.='> <label for="checkbox_done">Hide processed traps</label>';
165 165
 		$htm.='</form>';
166 166
 		return $htm;
167 167
 	}
168 168
 	
169
-	public function updateFilter($handler,$filter)
169
+	public function updateFilter($handler, $filter)
170 170
 	{
171 171
 		$this->filter_Handler=$handler->remove($this->filter_query_list)->__toString();
172
-		$this->filter_query=(isset($filter['q']))?$this->filter_query=$filter['q']:'';
173
-		$this->filter_done=(isset($filter['done']))?$this->filter_done=$filter['done']:0;
172
+		$this->filter_query=(isset($filter['q'])) ? $this->filter_query=$filter['q'] : '';
173
+		$this->filter_done=(isset($filter['done'])) ? $this->filter_done=$filter['done'] : 0;
174 174
 	}
175 175
 	
176 176
     protected function getSearchColumns()
@@ -185,20 +185,20 @@  discard block
 block discarded – undo
185 185
 
186 186
     public function setFilter($filter)
187 187
     {
188
-        $this->filter = $filter;
188
+        $this->filter=$filter;
189 189
         return $this;
190 190
     }
191 191
 	
192 192
 	public function getFilterEditor(Request $request)
193 193
     {
194
-        $filterEditor = Widget::create('filterEditor')
194
+        $filterEditor=Widget::create('filterEditor')
195 195
             ->setColumns(array_keys($this->getColumns()))
196 196
             ->setSearchColumns(array_keys($this->getSearchColumns()))
197 197
             ->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
198 198
             ->ignoreParams('page')
199 199
             ->handleRequest($request);
200 200
 
201
-        $filter = $filterEditor->getFilter();
201
+        $filter=$filterEditor->getFilter();
202 202
         $this->setFilter($filter);
203 203
 
204 204
         return $filterEditor;
@@ -212,9 +212,9 @@  discard block
 block discarded – undo
212 212
 		{
213 213
 			$sql.='(';
214 214
 			$first=1;
215
-			foreach($this->moduleConfig->getTrapListSearchColumns() as $column)
215
+			foreach ($this->moduleConfig->getTrapListSearchColumns() as $column)
216 216
 			{
217
-				if ($first==0) $sql.=' OR ';
217
+				if ($first == 0) $sql.=' OR ';
218 218
 				$first=0;
219 219
 				$sql.=" CAST(".$column." AS  char(100))  LIKE  '%".$this->filter_query."%' ";
220 220
 			}
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -214,7 +214,9 @@  discard block
 block discarded – undo
214 214
 			$first=1;
215 215
 			foreach($this->moduleConfig->getTrapListSearchColumns() as $column)
216 216
 			{
217
-				if ($first==0) $sql.=' OR ';
217
+				if ($first==0) {
218
+					$sql.=' OR ';
219
+				}
218 220
 				$first=0;
219 221
 				$sql.=" CAST(".$column." AS  char(100))  LIKE  '%".$this->filter_query."%' ";
220 222
 			}
@@ -222,10 +224,14 @@  discard block
 block discarded – undo
222 224
 		}
223 225
 		if ($this->filter_done == 1)
224 226
 		{
225
-			if ($sql != '') $sql.=' AND ';
227
+			if ($sql != '') {
228
+				$sql.=' AND ';
229
+			}
226 230
 			$sql.="(status != 'done')";
227 231
 		}
228
-		if ($sql != '') $query->where($sql);		
232
+		if ($sql != '') {
233
+			$query->where($sql);
234
+		}
229 235
         return $query;
230 236
     }	
231 237
 
Please login to merge, or discard this patch.
library/Trapdirector/Icinga2Api.php 3 patches
Indentation   +329 added lines, -329 removed lines patch added patch discarded remove patch
@@ -8,360 +8,360 @@
 block discarded – undo
8 8
 
9 9
 class Icinga2API 
10 10
 {
11
-    protected $version = 'v1';      //< icinga2 api version
11
+	protected $version = 'v1';      //< icinga2 api version
12 12
     
13
-    protected $host;                //< icinga2 host name or IP
14
-    protected $port;                //< icinga2 api port
13
+	protected $host;                //< icinga2 host name or IP
14
+	protected $port;                //< icinga2 api port
15 15
     
16
-    protected $user;                //< user name
17
-    protected $pass;                //< user password
18
-    protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
-    protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
16
+	protected $user;                //< user name
17
+	protected $pass;                //< user password
18
+	protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
+	protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
20 20
 
21
-    protected $curl;
22
-    // http://php.net/manual/de/function.json-last-error.php#119985
23
-    protected $errorReference = [
24
-        JSON_ERROR_NONE => 'No error has occurred.',
25
-        JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
26
-        JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
27
-        JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.',
28
-        JSON_ERROR_SYNTAX => 'Syntax error.',
29
-        JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.',
30
-        JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.',
31
-        JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
32
-        JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
33
-    ];
34
-    const JSON_UNKNOWN_ERROR = 'Unknown error.';
21
+	protected $curl;
22
+	// http://php.net/manual/de/function.json-last-error.php#119985
23
+	protected $errorReference = [
24
+		JSON_ERROR_NONE => 'No error has occurred.',
25
+		JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
26
+		JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
27
+		JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.',
28
+		JSON_ERROR_SYNTAX => 'Syntax error.',
29
+		JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.',
30
+		JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.',
31
+		JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
32
+		JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
33
+	];
34
+	const JSON_UNKNOWN_ERROR = 'Unknown error.';
35 35
     
36
-    /**
37
-     * Creates Icinga2API object
38
-     * 
39
-     * @param string $host host name or IP
40
-     * @param number $port API port
41
-     */
42
-    public function __construct($host, $port = 5665)
43
-    {
44
-        $this->host=$host;
45
-        $this->port=$port;
46
-    }
47
-    /**
48
-     * Set user & pass
49
-     * @param string $user
50
-     * @param string $pass
51
-     */
52
-    public function setCredentials($user,$pass)
53
-    {
54
-        $this->user=$user;
55
-        $this->pass=$pass;
56
-        $this->authmethod='pass';
57
-    }
36
+	/**
37
+	 * Creates Icinga2API object
38
+	 * 
39
+	 * @param string $host host name or IP
40
+	 * @param number $port API port
41
+	 */
42
+	public function __construct($host, $port = 5665)
43
+	{
44
+		$this->host=$host;
45
+		$this->port=$port;
46
+	}
47
+	/**
48
+	 * Set user & pass
49
+	 * @param string $user
50
+	 * @param string $pass
51
+	 */
52
+	public function setCredentials($user,$pass)
53
+	{
54
+		$this->user=$user;
55
+		$this->pass=$pass;
56
+		$this->authmethod='pass';
57
+	}
58 58
     
59
-    /**
60
-     * Set user & certificate (NOT IMPLEMENTED @throws RuntimeException)
61
-     * @param string $user
62
-     * @param string $usercert
63
-     */
64
-    public function setCredentialskey($user,$usercert)
65
-    {
66
-        $this->user=$user;
67
-        $this->usercert=$usercert;
68
-        $this->authmethod='cert';
69
-        throw new RuntimeException('Certificate auth not implemented');
70
-    }
59
+	/**
60
+	 * Set user & certificate (NOT IMPLEMENTED @throws RuntimeException)
61
+	 * @param string $user
62
+	 * @param string $usercert
63
+	 */
64
+	public function setCredentialskey($user,$usercert)
65
+	{
66
+		$this->user=$user;
67
+		$this->usercert=$usercert;
68
+		$this->authmethod='cert';
69
+		throw new RuntimeException('Certificate auth not implemented');
70
+	}
71 71
 
72
-    public function test(array $permissions)
73
-    {
74
-       try
75
-        {
76
-            $result=$this->request('GET', "", NULL, NULL);
77
-        } catch (Exception $e)
78
-        {
79
-            return array(true, 'Error with API : '.$e->getMessage());
80
-        }
81
-        //var_dump($result);
82
-        $permOk=1;
83
-        $permMissing='';
84
-        if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
85
-        {
72
+	public function test(array $permissions)
73
+	{
74
+	   try
75
+		{
76
+			$result=$this->request('GET', "", NULL, NULL);
77
+		} catch (Exception $e)
78
+		{
79
+			return array(true, 'Error with API : '.$e->getMessage());
80
+		}
81
+		//var_dump($result);
82
+		$permOk=1;
83
+		$permMissing='';
84
+		if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
85
+		{
86 86
             
87
-            foreach ( $permissions as $mustPermission)
88
-            {
89
-                $curPermOK=0;
90
-                foreach ( $result->results[0]->permissions as $curPermission)
91
-                {
92
-                    $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
93
-                    if (preg_match('#'.$curPermission.'#',$mustPermission))
94
-                    {
95
-                        $curPermOK=1;
96
-                        break;
97
-                    }
98
-                }
99
-                if ($curPermOK == 0)
100
-                {
101
-                    $permOk=0;
102
-                    $permMissing=$mustPermission;
103
-                    break;
104
-                }
105
-            }
106
-            if ($permOk == 0)
107
-            {
108
-                return array(true,'API connection OK, but missing permission : '.$permMissing);
109
-            }
110
-            return array(false,'API connection OK');
87
+			foreach ( $permissions as $mustPermission)
88
+			{
89
+				$curPermOK=0;
90
+				foreach ( $result->results[0]->permissions as $curPermission)
91
+				{
92
+					$curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
93
+					if (preg_match('#'.$curPermission.'#',$mustPermission))
94
+					{
95
+						$curPermOK=1;
96
+						break;
97
+					}
98
+				}
99
+				if ($curPermOK == 0)
100
+				{
101
+					$permOk=0;
102
+					$permMissing=$mustPermission;
103
+					break;
104
+				}
105
+			}
106
+			if ($permOk == 0)
107
+			{
108
+				return array(true,'API connection OK, but missing permission : '.$permMissing);
109
+			}
110
+			return array(false,'API connection OK');
111 111
             
112
-        }
113
-        return array(true,'API connection OK, but cannot get permissions');
114
-    }
112
+		}
113
+		return array(true,'API connection OK, but cannot get permissions');
114
+	}
115 115
     
116 116
     
117
-    protected function url($url) {
118
-        return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url);
119
-    }
117
+	protected function url($url) {
118
+		return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url);
119
+	}
120 120
     
121
-    /**
122
-     * Create or return curl ressource
123
-     * @throws Exception
124
-     * @return resource
125
-     */
126
-    protected function curl() {
127
-        if ($this->curl === null) {
128
-            $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
129
-            if (!$this->curl) {
130
-                throw new Exception('CURL INIT ERROR: ' . curl_error($this->curl));
131
-            }
132
-        }
133
-        return $this->curl;
134
-    }
121
+	/**
122
+	 * Create or return curl ressource
123
+	 * @throws Exception
124
+	 * @return resource
125
+	 */
126
+	protected function curl() {
127
+		if ($this->curl === null) {
128
+			$this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
129
+			if (!$this->curl) {
130
+				throw new Exception('CURL INIT ERROR: ' . curl_error($this->curl));
131
+			}
132
+		}
133
+		return $this->curl;
134
+	}
135 135
 
136
-    /**
137
-     * Send a passive service check
138
-     * @param string $host : host name 
139
-     * @param string $service : service name
140
-     * @param int $state : state of service
141
-     * @param string $display : service passive check output
142
-     * @return array (status = true (oK) or false (nok), string message)
143
-     */
144
-    public function serviceCheckResult($host,$service,$state,$display)
145
-    {
146
-        //Send a POST request to the URL endpoint /v1/actions/process-check-result
147
-        //actions/process-check-result?service=example.localdomain!passive-ping6
148
-        $url='actions/process-check-result';
149
-        $body=array(
150
-            "filter"        => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"',
151
-            'type'          => 'Service',
152
-            "exit_status"   => $state,
153
-            "plugin_output" => $display
154
-        );
155
-        try 
156
-        {
157
-            $result=$this->request('POST', $url, null, $body);
158
-        } catch (Exception $e) 
159
-        {
160
-            return array(false, $e->getMessage());
161
-        }
162
-        if (property_exists($result,'error') )
163
-        {
164
-            if (property_exists($result,'status'))
165
-            {
166
-                $message=$result->status;
167
-            }
168
-            else 
169
-            {
170
-                $message="Unkown status";
171
-            }
172
-            return array(false , 'Ret code ' .$result->error.' : '.$message);
173
-        }
174
-        if (property_exists($result, 'results'))
175
-        {
176
-            if (isset($result->results[0]))
177
-            {
178
-                return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
179
-            }
180
-            else
181
-            {
182
-                return array(false,'Service not found');
183
-            }
136
+	/**
137
+	 * Send a passive service check
138
+	 * @param string $host : host name 
139
+	 * @param string $service : service name
140
+	 * @param int $state : state of service
141
+	 * @param string $display : service passive check output
142
+	 * @return array (status = true (oK) or false (nok), string message)
143
+	 */
144
+	public function serviceCheckResult($host,$service,$state,$display)
145
+	{
146
+		//Send a POST request to the URL endpoint /v1/actions/process-check-result
147
+		//actions/process-check-result?service=example.localdomain!passive-ping6
148
+		$url='actions/process-check-result';
149
+		$body=array(
150
+			"filter"        => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"',
151
+			'type'          => 'Service',
152
+			"exit_status"   => $state,
153
+			"plugin_output" => $display
154
+		);
155
+		try 
156
+		{
157
+			$result=$this->request('POST', $url, null, $body);
158
+		} catch (Exception $e) 
159
+		{
160
+			return array(false, $e->getMessage());
161
+		}
162
+		if (property_exists($result,'error') )
163
+		{
164
+			if (property_exists($result,'status'))
165
+			{
166
+				$message=$result->status;
167
+			}
168
+			else 
169
+			{
170
+				$message="Unkown status";
171
+			}
172
+			return array(false , 'Ret code ' .$result->error.' : '.$message);
173
+		}
174
+		if (property_exists($result, 'results'))
175
+		{
176
+			if (isset($result->results[0]))
177
+			{
178
+				return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
179
+			}
180
+			else
181
+			{
182
+				return array(false,'Service not found');
183
+			}
184 184
             
185
-        }
186
-        return array(false,'Unkown result, open issue with this : '.print_r($result,true));
187
-    }
185
+		}
186
+		return array(false,'Unkown result, open issue with this : '.print_r($result,true));
187
+	}
188 188
  
189
-    /**
190
-     * return array of host by IP (4 or 6)
191
-     * @param string $ip
192
-     * @throws Exception
193
-     * @return array objects : array('__name','name','display_name')
194
-     */
195
-    public function getHostByIP($ip) 
196
-    {
197
-        /*
189
+	/**
190
+	 * return array of host by IP (4 or 6)
191
+	 * @param string $ip
192
+	 * @throws Exception
193
+	 * @return array objects : array('__name','name','display_name')
194
+	 */
195
+	public function getHostByIP($ip) 
196
+	{
197
+		/*
198 198
          *  curl -k -s -u  trapdirector:trapdirector -H 'X-HTTP-Method-Override: GET' -X POST 'https://localhost:5665/v1/objects/hosts' 
199 199
          *  -d '{"filter":"host.group==\"test_trap\"","attrs": ["address" ,"address6"]}'
200 200
             
201 201
             {"results":[{"attrs":{"__name":"Icinga host","address":"127.0.0.1","display_name":"Icinga host","name":"Icinga host"},"joins":{},"meta":{},"name":"Icinga host","type":"Host"}]}
202 202
          */
203 203
         
204
-        $url='objects/hosts';
205
-        $body=array(
206
-            "filter"        => 'host.address=="'.$ip.'" || host.address6=="'.$ip.'"',
207
-            "attrs"         => array('__name','name','display_name')
208
-        );
209
-        try
210
-        {
211
-            $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
212
-        } catch (Exception $e)
213
-        {
214
-            throw new Exception($e->getMessage());
215
-        }
204
+		$url='objects/hosts';
205
+		$body=array(
206
+			"filter"        => 'host.address=="'.$ip.'" || host.address6=="'.$ip.'"',
207
+			"attrs"         => array('__name','name','display_name')
208
+		);
209
+		try
210
+		{
211
+			$result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
212
+		} catch (Exception $e)
213
+		{
214
+			throw new Exception($e->getMessage());
215
+		}
216 216
         
217
-        if (property_exists($result,'error') )
218
-        {
219
-            if (property_exists($result,'status'))
220
-            {
221
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
222
-            }
223
-            else
224
-            {
225
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
226
-            }
227
-        }
228
-        if (property_exists($result, 'results'))
229
-        {
230
-            $numHost=0;
231
-            $hostArray=array();
232
-            while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
233
-            {
234
-                $hostArray[$numHost] = $result->results[$numHost]->attrs;
235
-                $numHost++;
236
-            }
237
-            return $hostArray;            
238
-        }
239
-        throw new Exception('Unkown result');
240
-    }
217
+		if (property_exists($result,'error') )
218
+		{
219
+			if (property_exists($result,'status'))
220
+			{
221
+				throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
222
+			}
223
+			else
224
+			{
225
+				throw new Exception('Ret code ' .$result->error.' : Unkown status');
226
+			}
227
+		}
228
+		if (property_exists($result, 'results'))
229
+		{
230
+			$numHost=0;
231
+			$hostArray=array();
232
+			while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
233
+			{
234
+				$hostArray[$numHost] = $result->results[$numHost]->attrs;
235
+				$numHost++;
236
+			}
237
+			return $hostArray;            
238
+		}
239
+		throw new Exception('Unkown result');
240
+	}
241 241
 
242
-    /**
243
-     * Get all host and IP from hostgroup
244
-     * @param string $hostGroup
245
-     * @throws Exception
246
-     * @return array : attributes : address, address6, name
247
-     */
248
-    public function getHostsIPByHostGroup($hostGroup)
249
-    {        
250
-        $url='objects/hosts';
251
-        $body=array(
252
-            "filter"        => '\"'.$hostGroup.'\" in host.groups',
253
-            "attrs"         => array('address','address','name')
254
-        );
255
-        try
256
-        {
257
-            $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
258
-        } catch (Exception $e)
259
-        {
260
-            throw new Exception($e->getMessage());
261
-        }
242
+	/**
243
+	 * Get all host and IP from hostgroup
244
+	 * @param string $hostGroup
245
+	 * @throws Exception
246
+	 * @return array : attributes : address, address6, name
247
+	 */
248
+	public function getHostsIPByHostGroup($hostGroup)
249
+	{        
250
+		$url='objects/hosts';
251
+		$body=array(
252
+			"filter"        => '\"'.$hostGroup.'\" in host.groups',
253
+			"attrs"         => array('address','address','name')
254
+		);
255
+		try
256
+		{
257
+			$result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
258
+		} catch (Exception $e)
259
+		{
260
+			throw new Exception($e->getMessage());
261
+		}
262 262
         
263
-        if (property_exists($result,'error') )
264
-        {
265
-            if (property_exists($result,'status'))
266
-            {
267
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
268
-            }
269
-            else
270
-            {
271
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
272
-            }
273
-        }
274
-        if (property_exists($result, 'results'))
275
-        {
276
-            $numHost=0;
277
-            $hostArray=array();
278
-            while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
279
-            {
280
-                $hostArray[$numHost] = $result->results[$numHost]->attrs;
281
-                $hostArray[$numHost]->name = $result->results[$numHost]->name;
282
-                $numHost++;
283
-            }
284
-            return $hostArray;
285
-        }
286
-        throw new Exception('Unkown result');
287
-    }
263
+		if (property_exists($result,'error') )
264
+		{
265
+			if (property_exists($result,'status'))
266
+			{
267
+				throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
268
+			}
269
+			else
270
+			{
271
+				throw new Exception('Ret code ' .$result->error.' : Unkown status');
272
+			}
273
+		}
274
+		if (property_exists($result, 'results'))
275
+		{
276
+			$numHost=0;
277
+			$hostArray=array();
278
+			while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
279
+			{
280
+				$hostArray[$numHost] = $result->results[$numHost]->attrs;
281
+				$hostArray[$numHost]->name = $result->results[$numHost]->name;
282
+				$numHost++;
283
+			}
284
+			return $hostArray;
285
+		}
286
+		throw new Exception('Unkown result');
287
+	}
288 288
     
289
-    /**
290
-     * Send request to API
291
-     * @param string $method get/post/...
292
-     * @param string $url (after /v1/ )
293
-     * @param array $headers
294
-     * @param array $body 
295
-     * @throws Exception
296
-     * @return array
297
-     */
298
-    public function request($method, $url, $headers, $body) {
299
-        $auth = sprintf('%s:%s', $this->user, $this->pass);
300
-        $curlHeaders = array("Accept: application/json");
301
-        if ($body !== null) {
302
-            $body = json_encode($body);
303
-            array_push($curlHeaders, 'Content-Type: application/json');
304
-            //array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
305
-        }
306
-        //var_dump($body);
307
-        //var_dump($this->url($url));
308
-        if ($headers !== null) {
309
-            $curlFinalHeaders = array_merge($curlHeaders, $headers);
310
-        } else 
311
-        {
312
-            $curlFinalHeaders=$curlHeaders;
313
-        }
314
-        $curl = $this->curl();
315
-        $opts = array(
316
-            CURLOPT_URL		=> $this->url($url),
317
-            CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
318
-            CURLOPT_USERPWD		=> $auth,
319
-            CURLOPT_CUSTOMREQUEST	=> strtoupper($method),
320
-            CURLOPT_RETURNTRANSFER 	=> true,
321
-            CURLOPT_CONNECTTIMEOUT 	=> 10,
322
-            CURLOPT_SSL_VERIFYHOST 	=> false,
323
-            CURLOPT_SSL_VERIFYPEER 	=> false,
324
-        );
325
-        if ($body !== null) {
326
-            $opts[CURLOPT_POSTFIELDS] = $body;
327
-        }
328
-        curl_setopt_array($curl, $opts);
329
-        $res = curl_exec($curl);
330
-        if ($res === false) {
331
-            throw new Exception('CURL ERROR: ' . curl_error($curl));
332
-        }
333
-        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
334
-        if ($statusCode === 401) {
335
-            throw new Exception('Unable to authenticate, please check your API credentials');
336
-        }
337
-        return $this->fromJsonResult($res);
338
-    }
289
+	/**
290
+	 * Send request to API
291
+	 * @param string $method get/post/...
292
+	 * @param string $url (after /v1/ )
293
+	 * @param array $headers
294
+	 * @param array $body 
295
+	 * @throws Exception
296
+	 * @return array
297
+	 */
298
+	public function request($method, $url, $headers, $body) {
299
+		$auth = sprintf('%s:%s', $this->user, $this->pass);
300
+		$curlHeaders = array("Accept: application/json");
301
+		if ($body !== null) {
302
+			$body = json_encode($body);
303
+			array_push($curlHeaders, 'Content-Type: application/json');
304
+			//array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
305
+		}
306
+		//var_dump($body);
307
+		//var_dump($this->url($url));
308
+		if ($headers !== null) {
309
+			$curlFinalHeaders = array_merge($curlHeaders, $headers);
310
+		} else 
311
+		{
312
+			$curlFinalHeaders=$curlHeaders;
313
+		}
314
+		$curl = $this->curl();
315
+		$opts = array(
316
+			CURLOPT_URL		=> $this->url($url),
317
+			CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
318
+			CURLOPT_USERPWD		=> $auth,
319
+			CURLOPT_CUSTOMREQUEST	=> strtoupper($method),
320
+			CURLOPT_RETURNTRANSFER 	=> true,
321
+			CURLOPT_CONNECTTIMEOUT 	=> 10,
322
+			CURLOPT_SSL_VERIFYHOST 	=> false,
323
+			CURLOPT_SSL_VERIFYPEER 	=> false,
324
+		);
325
+		if ($body !== null) {
326
+			$opts[CURLOPT_POSTFIELDS] = $body;
327
+		}
328
+		curl_setopt_array($curl, $opts);
329
+		$res = curl_exec($curl);
330
+		if ($res === false) {
331
+			throw new Exception('CURL ERROR: ' . curl_error($curl));
332
+		}
333
+		$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
334
+		if ($statusCode === 401) {
335
+			throw new Exception('Unable to authenticate, please check your API credentials');
336
+		}
337
+		return $this->fromJsonResult($res);
338
+	}
339 339
     
340
-    /**
341
-     * 
342
-     * @param string $json json encoded 
343
-     * @throws Exception
344
-     * @return array json decoded
345
-     */
346
-    protected function fromJsonResult($json) {
347
-        $result = @json_decode($json);
348
-        //var_dump($json);
349
-        if ($result === null) {
350
-            throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
351
-        }
352
-        return $result;
353
-    }
340
+	/**
341
+	 * 
342
+	 * @param string $json json encoded 
343
+	 * @throws Exception
344
+	 * @return array json decoded
345
+	 */
346
+	protected function fromJsonResult($json) {
347
+		$result = @json_decode($json);
348
+		//var_dump($json);
349
+		if ($result === null) {
350
+			throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
351
+		}
352
+		return $result;
353
+	}
354 354
     
355
-    /**
356
-     * Return text error no json error
357
-     * @param string $errorCode
358
-     * @return string
359
-     */
360
-    protected function getLastJsonErrorMessage($errorCode) {
361
-        if (!array_key_exists($errorCode, $this->errorReference)) {
362
-            return self::JSON_UNKNOWN_ERROR;
363
-        }
364
-        return $this->errorReference[$errorCode];
365
-    }
355
+	/**
356
+	 * Return text error no json error
357
+	 * @param string $errorCode
358
+	 * @return string
359
+	 */
360
+	protected function getLastJsonErrorMessage($errorCode) {
361
+		if (!array_key_exists($errorCode, $this->errorReference)) {
362
+			return self::JSON_UNKNOWN_ERROR;
363
+		}
364
+		return $this->errorReference[$errorCode];
365
+	}
366 366
 }
367 367
 
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -8,19 +8,19 @@  discard block
 block discarded – undo
8 8
 
9 9
 class Icinga2API 
10 10
 {
11
-    protected $version = 'v1';      //< icinga2 api version
11
+    protected $version='v1'; //< icinga2 api version
12 12
     
13
-    protected $host;                //< icinga2 host name or IP
14
-    protected $port;                //< icinga2 api port
13
+    protected $host; //< icinga2 host name or IP
14
+    protected $port; //< icinga2 api port
15 15
     
16
-    protected $user;                //< user name
17
-    protected $pass;                //< user password
18
-    protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
-    protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
16
+    protected $user; //< user name
17
+    protected $pass; //< user password
18
+    protected $usercert; //< user key for certificate auth (NOT IMPLEMENTED)
19
+    protected $authmethod='pass'; //< Authentication : 'pass' or 'cert'
20 20
 
21 21
     protected $curl;
22 22
     // http://php.net/manual/de/function.json-last-error.php#119985
23
-    protected $errorReference = [
23
+    protected $errorReference=[
24 24
         JSON_ERROR_NONE => 'No error has occurred.',
25 25
         JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
26 26
         JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
         JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
32 32
         JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
33 33
     ];
34
-    const JSON_UNKNOWN_ERROR = 'Unknown error.';
34
+    const JSON_UNKNOWN_ERROR='Unknown error.';
35 35
     
36 36
     /**
37 37
      * Creates Icinga2API object
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      * @param string $host host name or IP
40 40
      * @param number $port API port
41 41
      */
42
-    public function __construct($host, $port = 5665)
42
+    public function __construct($host, $port=5665)
43 43
     {
44 44
         $this->host=$host;
45 45
         $this->port=$port;
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
      * @param string $user
50 50
      * @param string $pass
51 51
      */
52
-    public function setCredentials($user,$pass)
52
+    public function setCredentials($user, $pass)
53 53
     {
54 54
         $this->user=$user;
55 55
         $this->pass=$pass;
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      * @param string $user
62 62
      * @param string $usercert
63 63
      */
64
-    public function setCredentialskey($user,$usercert)
64
+    public function setCredentialskey($user, $usercert)
65 65
     {
66 66
         $this->user=$user;
67 67
         $this->usercert=$usercert;
@@ -84,13 +84,13 @@  discard block
 block discarded – undo
84 84
         if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
85 85
         {
86 86
             
87
-            foreach ( $permissions as $mustPermission)
87
+            foreach ($permissions as $mustPermission)
88 88
             {
89 89
                 $curPermOK=0;
90
-                foreach ( $result->results[0]->permissions as $curPermission)
90
+                foreach ($result->results[0]->permissions as $curPermission)
91 91
                 {
92
-                    $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
93
-                    if (preg_match('#'.$curPermission.'#',$mustPermission))
92
+                    $curPermission=preg_replace('/\*/', '.*', $curPermission); // put * as .* to created a regexp
93
+                    if (preg_match('#'.$curPermission.'#', $mustPermission))
94 94
                     {
95 95
                         $curPermOK=1;
96 96
                         break;
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
             }
106 106
             if ($permOk == 0)
107 107
             {
108
-                return array(true,'API connection OK, but missing permission : '.$permMissing);
108
+                return array(true, 'API connection OK, but missing permission : '.$permMissing);
109 109
             }
110
-            return array(false,'API connection OK');
110
+            return array(false, 'API connection OK');
111 111
             
112 112
         }
113
-        return array(true,'API connection OK, but cannot get permissions');
113
+        return array(true, 'API connection OK, but cannot get permissions');
114 114
     }
115 115
     
116 116
     
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
      */
126 126
     protected function curl() {
127 127
         if ($this->curl === null) {
128
-            $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
128
+            $this->curl=curl_init(sprintf('https://%s:%d', $this->host, $this->port));
129 129
             if (!$this->curl) {
130
-                throw new Exception('CURL INIT ERROR: ' . curl_error($this->curl));
130
+                throw new Exception('CURL INIT ERROR: '.curl_error($this->curl));
131 131
             }
132 132
         }
133 133
         return $this->curl;
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      * @param string $display : service passive check output
142 142
      * @return array (status = true (oK) or false (nok), string message)
143 143
      */
144
-    public function serviceCheckResult($host,$service,$state,$display)
144
+    public function serviceCheckResult($host, $service, $state, $display)
145 145
     {
146 146
         //Send a POST request to the URL endpoint /v1/actions/process-check-result
147 147
         //actions/process-check-result?service=example.localdomain!passive-ping6
@@ -159,9 +159,9 @@  discard block
 block discarded – undo
159 159
         {
160 160
             return array(false, $e->getMessage());
161 161
         }
162
-        if (property_exists($result,'error') )
162
+        if (property_exists($result, 'error'))
163 163
         {
164
-            if (property_exists($result,'status'))
164
+            if (property_exists($result, 'status'))
165 165
             {
166 166
                 $message=$result->status;
167 167
             }
@@ -169,21 +169,21 @@  discard block
 block discarded – undo
169 169
             {
170 170
                 $message="Unkown status";
171 171
             }
172
-            return array(false , 'Ret code ' .$result->error.' : '.$message);
172
+            return array(false, 'Ret code '.$result->error.' : '.$message);
173 173
         }
174 174
         if (property_exists($result, 'results'))
175 175
         {
176 176
             if (isset($result->results[0]))
177 177
             {
178
-                return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
178
+                return array(true, 'code '.$result->results[0]->code.' : '.$result->results[0]->status);
179 179
             }
180 180
             else
181 181
             {
182
-                return array(false,'Service not found');
182
+                return array(false, 'Service not found');
183 183
             }
184 184
             
185 185
         }
186
-        return array(false,'Unkown result, open issue with this : '.print_r($result,true));
186
+        return array(false, 'Unkown result, open issue with this : '.print_r($result, true));
187 187
     }
188 188
  
189 189
     /**
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
         $url='objects/hosts';
205 205
         $body=array(
206 206
             "filter"        => 'host.address=="'.$ip.'" || host.address6=="'.$ip.'"',
207
-            "attrs"         => array('__name','name','display_name')
207
+            "attrs"         => array('__name', 'name', 'display_name')
208 208
         );
209 209
         try
210 210
         {
@@ -214,24 +214,24 @@  discard block
 block discarded – undo
214 214
             throw new Exception($e->getMessage());
215 215
         }
216 216
         
217
-        if (property_exists($result,'error') )
217
+        if (property_exists($result, 'error'))
218 218
         {
219
-            if (property_exists($result,'status'))
219
+            if (property_exists($result, 'status'))
220 220
             {
221
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
221
+                throw new Exception('Ret code '.$result->error.' : '.$result->status);
222 222
             }
223 223
             else
224 224
             {
225
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
225
+                throw new Exception('Ret code '.$result->error.' : Unkown status');
226 226
             }
227 227
         }
228 228
         if (property_exists($result, 'results'))
229 229
         {
230 230
             $numHost=0;
231 231
             $hostArray=array();
232
-            while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
232
+            while (isset($result->results[$numHost]) && property_exists($result->results[$numHost], 'attrs'))
233 233
             {
234
-                $hostArray[$numHost] = $result->results[$numHost]->attrs;
234
+                $hostArray[$numHost]=$result->results[$numHost]->attrs;
235 235
                 $numHost++;
236 236
             }
237 237
             return $hostArray;            
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
         $url='objects/hosts';
251 251
         $body=array(
252 252
             "filter"        => '\"'.$hostGroup.'\" in host.groups',
253
-            "attrs"         => array('address','address','name')
253
+            "attrs"         => array('address', 'address', 'name')
254 254
         );
255 255
         try
256 256
         {
@@ -260,25 +260,25 @@  discard block
 block discarded – undo
260 260
             throw new Exception($e->getMessage());
261 261
         }
262 262
         
263
-        if (property_exists($result,'error') )
263
+        if (property_exists($result, 'error'))
264 264
         {
265
-            if (property_exists($result,'status'))
265
+            if (property_exists($result, 'status'))
266 266
             {
267
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
267
+                throw new Exception('Ret code '.$result->error.' : '.$result->status);
268 268
             }
269 269
             else
270 270
             {
271
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
271
+                throw new Exception('Ret code '.$result->error.' : Unkown status');
272 272
             }
273 273
         }
274 274
         if (property_exists($result, 'results'))
275 275
         {
276 276
             $numHost=0;
277 277
             $hostArray=array();
278
-            while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
278
+            while (isset($result->results[$numHost]) && property_exists($result->results[$numHost], 'attrs'))
279 279
             {
280
-                $hostArray[$numHost] = $result->results[$numHost]->attrs;
281
-                $hostArray[$numHost]->name = $result->results[$numHost]->name;
280
+                $hostArray[$numHost]=$result->results[$numHost]->attrs;
281
+                $hostArray[$numHost]->name=$result->results[$numHost]->name;
282 282
                 $numHost++;
283 283
             }
284 284
             return $hostArray;
@@ -296,23 +296,23 @@  discard block
 block discarded – undo
296 296
      * @return array
297 297
      */
298 298
     public function request($method, $url, $headers, $body) {
299
-        $auth = sprintf('%s:%s', $this->user, $this->pass);
300
-        $curlHeaders = array("Accept: application/json");
299
+        $auth=sprintf('%s:%s', $this->user, $this->pass);
300
+        $curlHeaders=array("Accept: application/json");
301 301
         if ($body !== null) {
302
-            $body = json_encode($body);
302
+            $body=json_encode($body);
303 303
             array_push($curlHeaders, 'Content-Type: application/json');
304 304
             //array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
305 305
         }
306 306
         //var_dump($body);
307 307
         //var_dump($this->url($url));
308 308
         if ($headers !== null) {
309
-            $curlFinalHeaders = array_merge($curlHeaders, $headers);
309
+            $curlFinalHeaders=array_merge($curlHeaders, $headers);
310 310
         } else 
311 311
         {
312 312
             $curlFinalHeaders=$curlHeaders;
313 313
         }
314
-        $curl = $this->curl();
315
-        $opts = array(
314
+        $curl=$this->curl();
315
+        $opts=array(
316 316
             CURLOPT_URL		=> $this->url($url),
317 317
             CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
318 318
             CURLOPT_USERPWD		=> $auth,
@@ -323,14 +323,14 @@  discard block
 block discarded – undo
323 323
             CURLOPT_SSL_VERIFYPEER 	=> false,
324 324
         );
325 325
         if ($body !== null) {
326
-            $opts[CURLOPT_POSTFIELDS] = $body;
326
+            $opts[CURLOPT_POSTFIELDS]=$body;
327 327
         }
328 328
         curl_setopt_array($curl, $opts);
329
-        $res = curl_exec($curl);
329
+        $res=curl_exec($curl);
330 330
         if ($res === false) {
331
-            throw new Exception('CURL ERROR: ' . curl_error($curl));
331
+            throw new Exception('CURL ERROR: '.curl_error($curl));
332 332
         }
333
-        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
333
+        $statusCode=curl_getinfo($curl, CURLINFO_HTTP_CODE);
334 334
         if ($statusCode === 401) {
335 335
             throw new Exception('Unable to authenticate, please check your API credentials');
336 336
         }
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      * @return array json decoded
345 345
      */
346 346
     protected function fromJsonResult($json) {
347
-        $result = @json_decode($json);
347
+        $result=@json_decode($json);
348 348
         //var_dump($json);
349 349
         if ($result === null) {
350 350
             throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -164,8 +164,7 @@  discard block
 block discarded – undo
164 164
             if (property_exists($result,'status'))
165 165
             {
166 166
                 $message=$result->status;
167
-            }
168
-            else 
167
+            } else 
169 168
             {
170 169
                 $message="Unkown status";
171 170
             }
@@ -176,8 +175,7 @@  discard block
 block discarded – undo
176 175
             if (isset($result->results[0]))
177 176
             {
178 177
                 return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
179
-            }
180
-            else
178
+            } else
181 179
             {
182 180
                 return array(false,'Service not found');
183 181
             }
@@ -219,8 +217,7 @@  discard block
 block discarded – undo
219 217
             if (property_exists($result,'status'))
220 218
             {
221 219
                 throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
222
-            }
223
-            else
220
+            } else
224 221
             {
225 222
                 throw new Exception('Ret code ' .$result->error.' : Unkown status');
226 223
             }
@@ -265,8 +262,7 @@  discard block
 block discarded – undo
265 262
             if (property_exists($result,'status'))
266 263
             {
267 264
                 throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
268
-            }
269
-            else
265
+            } else
270 266
             {
271 267
                 throw new Exception('Ret code ' .$result->error.' : Unkown status');
272 268
             }
Please login to merge, or discard this patch.
library/Trapdirector/Config/TrapModuleConfig.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -4,9 +4,9 @@  discard block
 block discarded – undo
4 4
 
5 5
 class TrapModuleConfig
6 6
 {
7
-    /********** Database configuration ***********************/
7
+	/********** Database configuration ***********************/
8 8
 	// Database prefix for tables 
9
-    protected $table_prefix; //< Database prefix for tables 	
9
+	protected $table_prefix; //< Database prefix for tables 	
10 10
 	protected $DBConfigDefaults=array(
11 11
 		'db_remove_days' => 60, // number of days before removing traps
12 12
 		'log_destination' => 'syslog', // Log destination for trap handler
@@ -113,27 +113,27 @@  discard block
 block discarded – undo
113 113
 	// Note : must have 'source_ip' and 'last_sent'
114 114
 	public function getTrapHostListDisplayColumns()
115 115
 	{
116
-	    return array(
117
-	        'source_name'  =>  't.source_name',
118
-	        'source_ip'    =>  't.source_ip',
119
-	        'trap_oid'     =>  't.trap_oid',
120
-	        'count'        =>  'count(*)',
121
-	        'last_sent'    =>  'UNIX_TIMESTAMP(max(t.date_received))'
122
-	    );
116
+		return array(
117
+			'source_name'  =>  't.source_name',
118
+			'source_ip'    =>  't.source_ip',
119
+			'trap_oid'     =>  't.trap_oid',
120
+			'count'        =>  'count(*)',
121
+			'last_sent'    =>  'UNIX_TIMESTAMP(max(t.date_received))'
122
+		);
123 123
 	}
124 124
 
125 125
 	public function getTrapHostListSearchColumns()
126 126
 	{
127
-	    return array(); // No search needed on this table
127
+		return array(); // No search needed on this table
128 128
 	}
129 129
 	// Titles display in Trap List table
130 130
 	public function getTrapHostListTitles()
131 131
 	{
132
-	    return array(
133
-	        'trap_oid'		=> 'Trap OID',
134
-	        'count'		    => 'Number of traps received',
135
-	        'last_sent'     => 'Last trap received'
136
-	    );
132
+		return array(
133
+			'trap_oid'		=> 'Trap OID',
134
+			'count'		    => 'Number of traps received',
135
+			'last_sent'     => 'Last trap received'
136
+		);
137 137
 	}
138 138
 	
139 139
 	
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 			'revert_ok'		=> 'r.revert_ok',
189 189
 			'display'		=> 'r.display',
190 190
 			'modified'		=> 'UNIX_TIMESTAMP(r.modified)',
191
-            'modifier'		=> 'r.modifier'
191
+			'modifier'		=> 'r.modifier'
192 192
 		);
193 193
 	}	
194 194
 		
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -14,22 +14,22 @@  discard block
 block discarded – undo
14 14
 		'log_level' => 2, // log level
15 15
 	);
16 16
 	// get default values for dbconfig
17
-	public function getDBConfigDefaults() { return $this->DBConfigDefaults;}
17
+	public function getDBConfigDefaults() { return $this->DBConfigDefaults; }
18 18
 	// Minimum DB version
19
-	static public function getDbMinVersion() { return 2;}	
19
+	static public function getDbMinVersion() { return 2; }	
20 20
 	// Current DB version
21
-	static public function getDbCurVersion() { return 2;}
21
+	static public function getDbCurVersion() { return 2; }
22 22
 
23 23
 	/************ Module configuration **********************/
24 24
 	// Module base path
25 25
 	static public function urlPath() { return 'trapdirector'; }
26
-	static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/Service" , "actions/process-check-result"); } //< api user permissions required
26
+	static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/Service", "actions/process-check-result"); } //< api user permissions required
27 27
 	
28 28
 	/*********** Log configuration *************************/
29 29
 	protected $logLevels=array(0=>'No output', 1=>'critical', 2=>'warning', 3=>'trace', 4=>'ALL');
30
-	public function getlogLevels() { return $this->logLevels;}
31
-	protected $logDestinations=array('syslog'=>'syslog','file'=>'file','display'=>'display');
32
-	public function getLogDestinations() { return $this->logDestinations;}
30
+	public function getlogLevels() { return $this->logLevels; }
31
+	protected $logDestinations=array('syslog'=>'syslog', 'file'=>'file', 'display'=>'display');
32
+	public function getLogDestinations() { return $this->logDestinations; }
33 33
 	
34 34
 	function __construct($prefix)
35 35
 	{
@@ -40,29 +40,29 @@  discard block
 block discarded – undo
40 40
 	// DB table name of trap received list : prefix 't'
41 41
 	public function getTrapTableName() 
42 42
 	{ 
43
-		return array('t' => $this->table_prefix . 'received'); 
43
+		return array('t' => $this->table_prefix.'received'); 
44 44
 	}
45 45
 	// DB table name of trap data  list : prefix 'd'
46 46
 	public function getTrapDataTableName() 
47 47
 	{ 
48
-		return array('d' => $this->table_prefix . 'received_data'); 
48
+		return array('d' => $this->table_prefix.'received_data'); 
49 49
 	}	
50 50
 
51 51
 	// DB table name of rules : prefix 'r'
52 52
 	public function getTrapRuleName() 
53 53
 	{ 
54
-		return array('r' => $this->table_prefix . 'rules'); 
54
+		return array('r' => $this->table_prefix.'rules'); 
55 55
 	}		
56 56
 	
57 57
 	// DB table name of db config : prefix 'c'
58 58
 	public function getDbConfigTableName() 
59 59
 	{ 
60
-		return array('c' => $this->table_prefix . 'db_config');
60
+		return array('c' => $this->table_prefix.'db_config');
61 61
 	}
62 62
 	
63 63
 	// Mib cache tables
64
-	public function getMIBCacheTableName() { return $this->table_prefix . 'mib_cache'; }
65
-	public function getMIBCacheTableTrapObjName() { return $this->table_prefix . 'mib_cache_trap_object'; }
64
+	public function getMIBCacheTableName() { return $this->table_prefix.'mib_cache'; }
65
+	public function getMIBCacheTableTrapObjName() { return $this->table_prefix.'mib_cache_trap_object'; }
66 66
 	
67 67
 	
68 68
 	/****************** Database queries *******************/
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 	public function getHandlerListDisplayColumns()
144 144
 	{
145 145
 		return array(
146
-			'host_name'		=> 'r.host_name',//'UNIX_TIMESTAMP(t.date_received)',
146
+			'host_name'		=> 'r.host_name', //'UNIX_TIMESTAMP(t.date_received)',
147 147
 			'host_group_name'=> 'r.host_group_name',
148 148
 			'source_ip'		=> "CASE WHEN r.ip4 IS NULL THEN r.ip6 ELSE r.ip4 END",
149 149
 			'trap_oid'		=> 'r.trap_oid',
@@ -196,32 +196,32 @@  discard block
 block discarded – undo
196 196
 	public function trapDetailQuery()
197 197
 	{
198 198
 		return array(
199
-			'timestamp'			=> array('Date','UNIX_TIMESTAMP(t.date_received)'),
200
-			'source_ip'			=> array('Source IP','t.source_ip'),
201
-			'source_name'		=> array('Source name','t.source_name'),
202
-			'source_port'		=> array('Source port','t.source_port'),
203
-			'destination_ip'	=> array('Destination IP','t.destination_ip'),
204
-			'destination_port'	=> array('Destination port','t.destination_port'),			
205
-			'trap_oid'			=> array('Numeric OID','t.trap_oid'),
206
-			'trap_name'			=> array('Trap name','t.trap_name'),
207
-			'trap_name_mib'		=> array('Trap MIB','t.trap_name_mib'),
208
-			'status'			=> array('Processing status','t.status'),
209
-			'status_detail'		=> array('Status details','t.status_detail'),
210
-			'process_time'		=> array('Trap processing time','t.process_time'),			
199
+			'timestamp'			=> array('Date', 'UNIX_TIMESTAMP(t.date_received)'),
200
+			'source_ip'			=> array('Source IP', 't.source_ip'),
201
+			'source_name'		=> array('Source name', 't.source_name'),
202
+			'source_port'		=> array('Source port', 't.source_port'),
203
+			'destination_ip'	=> array('Destination IP', 't.destination_ip'),
204
+			'destination_port'	=> array('Destination port', 't.destination_port'),			
205
+			'trap_oid'			=> array('Numeric OID', 't.trap_oid'),
206
+			'trap_name'			=> array('Trap name', 't.trap_name'),
207
+			'trap_name_mib'		=> array('Trap MIB', 't.trap_name_mib'),
208
+			'status'			=> array('Processing status', 't.status'),
209
+			'status_detail'		=> array('Status details', 't.status_detail'),
210
+			'process_time'		=> array('Trap processing time', 't.process_time'),			
211 211
 		);
212 212
 	}
213 213
 	// Trap detail : additional data (<key> => <title> <sql select>)
214 214
 	public function trapDataDetailQuery()
215 215
 	{
216 216
 		return array(
217
-			'oid'				=> array('Numeric OID','d.oid'),
218
-			'oid_name'			=> array('Text OID','d.oid_name'),
219
-			'oid_name_mib'		=> array('MIB','d.oid_name_mib'),
220
-			'value'				=> array('Value','d.value'),
217
+			'oid'				=> array('Numeric OID', 'd.oid'),
218
+			'oid_name'			=> array('Text OID', 'd.oid_name'),
219
+			'oid_name_mib'		=> array('MIB', 'd.oid_name_mib'),
220
+			'value'				=> array('Value', 'd.value'),
221 221
 		);
222 222
 	}
223 223
 	// foreign key of trap data table
224
-	public function trapDataFK() { return 'trap_id';}
224
+	public function trapDataFK() { return 'trap_id'; }
225 225
 	
226 226
 	// Max items in a list
227 227
 	public function itemListDisplay() { return 25; }
Please login to merge, or discard this patch.
library/Trapdirector/Config/MIBLoader.php 3 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -54,9 +54,9 @@  discard block
 block discarded – undo
54 54
 	
55 55
 	
56 56
 	/** Get trap list from a mib 
57
-	*	@param $mib string mib name
58
-	*	@return array(traps)
59
-	*/
57
+	 *	@param $mib string mib name
58
+	 *	@return array(traps)
59
+	 */
60 60
 	public function getTrapList($mib)
61 61
 	{
62 62
 		$traps=array();
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		$query=$dbconn->select()
65 65
 				->from(
66 66
 					$this->config->getMIBCacheTableName(),
67
-				    array('name' => 'name', 'oid' => 'oid', 'description' => 'description'))
67
+					array('name' => 'name', 'oid' => 'oid', 'description' => 'description'))
68 68
 				->where("mib = '".$mib."' AND type='21'") ;
69 69
 		$names=$dbconn->fetchAll($query);
70 70
 		foreach ($names as $val)
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
 	}
76 76
 	
77 77
 	/** Get objects a trap can have
78
-	*	@param int oid of trap
79
-	*	@return : null if trap not found, or array ( <oid> => name/mib/type )
80
-	*/
78
+	 *	@param int oid of trap
79
+	 *	@return : null if trap not found, or array ( <oid> => name/mib/type )
80
+	 */
81 81
 	public function getObjectList($trap)
82 82
 	{
83 83
 		$objects=array();
@@ -93,15 +93,15 @@  discard block
 block discarded – undo
93 93
 		if ( ($id == null) || ! property_exists($id,'id') ) return null;
94 94
 		
95 95
 		$query=$dbconn->select()
96
-		        ->from(
97
-		            array('c' => $this->config->getMIBCacheTableName()),
98
-		            array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum',
99
-		                'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint',
100
-		                'description' => 'c.description'))
101
-		        ->join(
102
-		            array('o' => $this->config->getMIBCacheTableTrapObjName()),
103
-		            'o.trap_id='.$id->id )
104
-		        ->where("o.object_id = c.id");
96
+				->from(
97
+					array('c' => $this->config->getMIBCacheTableName()),
98
+					array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum',
99
+						'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint',
100
+						'description' => 'c.description'))
101
+				->join(
102
+					array('o' => $this->config->getMIBCacheTableTrapObjName()),
103
+					'o.trap_id='.$id->id )
104
+				->where("o.object_id = c.id");
105 105
 		$listObjects=$dbconn->fetchAll($query);
106 106
 		if ( count($listObjects)==0 ) return null;
107 107
 		
@@ -119,12 +119,12 @@  discard block
 block discarded – undo
119 119
 	}
120 120
 
121 121
 	/** translate oid in MIB::Name 
122
-	*	@param string oid
123
-	*	@return array (oid -> oid, mib -> mib name, name -> oid name, type -> oid type)
124
-	*/
122
+	 *	@param string oid
123
+	 *	@return array (oid -> oid, mib -> mib name, name -> oid name, type -> oid type)
124
+	 */
125 125
 	public function translateOID($oid)
126 126
 	{
127
-	    if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.'
127
+		if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.'
128 128
 		$retArray=array('oid' => $oid, 'mib' => null, 'name'=>null,'type'=>null);
129 129
 		$dbconn = $this->db->getConnection();
130 130
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 				->from(
133 133
 					array('o' => $this->config->getMIBCacheTableName()),
134 134
 					array('mib'=>'o.mib','name' => 'o.name','type'=>'o.syntax',
135
-					    'type_enum'=>'o.type_enum', 'description'=>'o.description'))
135
+						'type_enum'=>'o.type_enum', 'description'=>'o.description'))
136 136
 				->where('o.oid=\''.$oid.'\'');
137 137
 		$object=$dbconn->fetchRow($query);
138 138
 		if ($object != null) 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 		// Try to get oid name from snmptranslate
149 149
 		$matches=array();
150 150
 		$translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
151
-		    ' '.$oid);
151
+			' '.$oid);
152 152
 		$ret_code=preg_match('/(.*)::(.*)/',$translate,$matches);
153 153
 		if ($ret_code==0 || $ret_code==FALSE) {
154 154
 			return null;
@@ -160,8 +160,8 @@  discard block
 block discarded – undo
160 160
 			" | grep SYNTAX | sed 's/SYNTAX[[:blank:]]*//'");
161 161
 		if (preg_match('/(.*)\{(.*)\}/',$translate,$matches))
162 162
 		{
163
-		    $retArray['type']=$matches[1];
164
-		    $retArray['type_enum']=$matches[2];
163
+			$retArray['type']=$matches[1];
164
+			$retArray['type_enum']=$matches[2];
165 165
 		}
166 166
 		else
167 167
 		{
@@ -225,25 +225,25 @@  discard block
 block discarded – undo
225 225
 	 */
226 226
 	public function getTrapDetails($oid=null,$id=null)
227 227
 	{	    
228
-	    // Get trap id in DB
229
-	    if ($oid==null)
230
-	    {
231
-	        $where="c.id = '$id'";
232
-	    }
233
-	    else
234
-	    {
235
-	        $where="c.oid = '$oid'";
236
-	    }
237
-	    $query=$this->db->getConnection()->select()
238
-           ->from(
239
-            array('c' => $this->config->getMIBCacheTableName()),
240
-            array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum',
241
-                'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint',
242
-                'description' => 'c.description'))
243
-            ->where($where);
244
-        $trap=$this->db->getConnection()->fetchRow($query);
228
+		// Get trap id in DB
229
+		if ($oid==null)
230
+		{
231
+			$where="c.id = '$id'";
232
+		}
233
+		else
234
+		{
235
+			$where="c.oid = '$oid'";
236
+		}
237
+		$query=$this->db->getConnection()->select()
238
+		   ->from(
239
+			array('c' => $this->config->getMIBCacheTableName()),
240
+			array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum',
241
+				'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint',
242
+				'description' => 'c.description'))
243
+			->where($where);
244
+		$trap=$this->db->getConnection()->fetchRow($query);
245 245
         
246
-        return $trap;
246
+		return $trap;
247 247
 	}
248 248
 	
249 249
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 * @param string $db current database
22 22
 	 * @param TrapModuleConfig $config TrapModuleConfig class instance
23 23
 	 */
24
-	public function __construct($snmptranslate,$snmptranslate_dirs,$db,$config)
24
+	public function __construct($snmptranslate, $snmptranslate_dirs, $db, $config)
25 25
 	{
26 26
 		$this->snmptranslate=$snmptranslate;
27 27
 		$this->snmptranslate_dirs=$snmptranslate_dirs;
@@ -34,19 +34,19 @@  discard block
 block discarded – undo
34 34
 	// Get all mibs in db which have at least one trap
35 35
 	public function getMIBList()
36 36
 	{
37
-		$dbconn = $this->db->getConnection();
37
+		$dbconn=$this->db->getConnection();
38 38
 		$query=$dbconn->select()
39 39
 				->distinct()
40 40
 				->from(
41 41
 					$this->config->getMIBCacheTableName(),
42 42
 					array('mib' => 'mib'))
43 43
 				->where("type = '21'")
44
-				->order('mib ASC');				;
44
+				->order('mib ASC'); ;
45 45
 		$names=$dbconn->fetchAll($query);
46 46
 		$mib=array();
47
-		foreach($names as $val)
47
+		foreach ($names as $val)
48 48
 		{
49
-			array_push($mib,$val->mib);
49
+			array_push($mib, $val->mib);
50 50
 		}
51 51
 		return $mib;
52 52
 		
@@ -60,12 +60,12 @@  discard block
 block discarded – undo
60 60
 	public function getTrapList($mib)
61 61
 	{
62 62
 		$traps=array();
63
-		$dbconn = $this->db->getConnection();
63
+		$dbconn=$this->db->getConnection();
64 64
 		$query=$dbconn->select()
65 65
 				->from(
66 66
 					$this->config->getMIBCacheTableName(),
67 67
 				    array('name' => 'name', 'oid' => 'oid', 'description' => 'description'))
68
-				->where("mib = '".$mib."' AND type='21'") ;
68
+				->where("mib = '".$mib."' AND type='21'");
69 69
 		$names=$dbconn->fetchAll($query);
70 70
 		foreach ($names as $val)
71 71
 		{
@@ -83,19 +83,19 @@  discard block
 block discarded – undo
83 83
 		$objects=array();
84 84
 		
85 85
 		// Get trap id in DB
86
-		$dbconn = $this->db->getConnection();
86
+		$dbconn=$this->db->getConnection();
87 87
 		$query=$dbconn->select()
88 88
 				->from(
89 89
 					$this->config->getMIBCacheTableName(),
90 90
 					array('id' => 'id'))
91
-				->where("oid = '".$trap."'") ;
91
+				->where("oid = '".$trap."'");
92 92
 		$id=$dbconn->fetchRow($query);
93
-		if ( ($id == null) || ! property_exists($id,'id') ) return null;
93
+		if (($id == null) || !property_exists($id, 'id')) return null;
94 94
 		
95 95
 		$query=$dbconn->select()
96 96
 		        ->from(
97 97
 		            array('c' => $this->config->getMIBCacheTableName()),
98
-		            array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum',
98
+		            array('name' => 'c.name', 'mib' => 'c.mib', 'oid' => 'c.oid', 'type_enum'=>'c.type_enum',
99 99
 		                'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint',
100 100
 		                'description' => 'c.description'))
101 101
 		        ->join(
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 		            'o.trap_id='.$id->id )
104 104
 		        ->where("o.object_id = c.id");
105 105
 		$listObjects=$dbconn->fetchAll($query);
106
-		if ( count($listObjects)==0 ) return null;
106
+		if (count($listObjects) == 0) return null;
107 107
 		
108 108
 		foreach ($listObjects as $val)
109 109
 		{
@@ -124,14 +124,14 @@  discard block
 block discarded – undo
124 124
 	*/
125 125
 	public function translateOID($oid)
126 126
 	{
127
-	    if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.'
128
-		$retArray=array('oid' => $oid, 'mib' => null, 'name'=>null,'type'=>null);
129
-		$dbconn = $this->db->getConnection();
127
+	    if (!preg_match('/^\./', $oid)) $oid='.'.$oid; // Add a leading '.'
128
+		$retArray=array('oid' => $oid, 'mib' => null, 'name'=>null, 'type'=>null);
129
+		$dbconn=$this->db->getConnection();
130 130
 
131 131
 		$query=$dbconn->select()
132 132
 				->from(
133 133
 					array('o' => $this->config->getMIBCacheTableName()),
134
-					array('mib'=>'o.mib','name' => 'o.name','type'=>'o.syntax',
134
+					array('mib'=>'o.mib', 'name' => 'o.name', 'type'=>'o.syntax',
135 135
 					    'type_enum'=>'o.type_enum', 'description'=>'o.description'))
136 136
 				->where('o.oid=\''.$oid.'\'');
137 137
 		$object=$dbconn->fetchRow($query);
@@ -147,18 +147,18 @@  discard block
 block discarded – undo
147 147
 		
148 148
 		// Try to get oid name from snmptranslate
149 149
 		$matches=array();
150
-		$translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
150
+		$translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
151 151
 		    ' '.$oid);
152
-		$ret_code=preg_match('/(.*)::(.*)/',$translate,$matches);
153
-		if ($ret_code==0 || $ret_code==FALSE) {
152
+		$ret_code=preg_match('/(.*)::(.*)/', $translate, $matches);
153
+		if ($ret_code == 0 || $ret_code == FALSE) {
154 154
 			return null;
155 155
 		} 
156 156
 		$retArray['mib']=$matches[1];
157 157
 		$retArray['name']=$matches[2];
158 158
 		
159
-		$translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.' -Td -On ' . $matches[0] .
159
+		$translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.' -Td -On '.$matches[0].
160 160
 			" | grep SYNTAX | sed 's/SYNTAX[[:blank:]]*//'");
161
-		if (preg_match('/(.*)\{(.*)\}/',$translate,$matches))
161
+		if (preg_match('/(.*)\{(.*)\}/', $translate, $matches))
162 162
 		{
163 163
 		    $retArray['type']=$matches[1];
164 164
 		    $retArray['type_enum']=$matches[2];
@@ -193,9 +193,9 @@  discard block
 block discarded – undo
193 193
 	 * @param string $type filter by type (21=trap)
194 194
 	 * @return number number of entries in db.
195 195
 	 */
196
-	public function countObjects($mib=null,$type=null)
196
+	public function countObjects($mib=null, $type=null)
197 197
 	{
198
-		$dbconn = $this->db->getConnection();
198
+		$dbconn=$this->db->getConnection();
199 199
 		$query=$dbconn->select()
200 200
 				->from(
201 201
 					$this->config->getMIBCacheTableName(),
@@ -203,11 +203,11 @@  discard block
 block discarded – undo
203 203
 		$where=null;
204 204
 		if ($mib != null)
205 205
 		{
206
-			$where ="mib = '$mib' ";
206
+			$where="mib = '$mib' ";
207 207
 		}
208 208
 		if ($type != null)
209 209
 		{
210
-			$where=($where != null)?' AND ':'';
210
+			$where=($where != null) ? ' AND ' : '';
211 211
 			$where.="type='$type'";
212 212
 		}
213 213
 		if ($where != null)
@@ -223,10 +223,10 @@  discard block
 block discarded – undo
223 223
 	 * @param number $id
224 224
 	 * @return array trap details
225 225
 	 */
226
-	public function getTrapDetails($oid=null,$id=null)
226
+	public function getTrapDetails($oid=null, $id=null)
227 227
 	{	    
228 228
 	    // Get trap id in DB
229
-	    if ($oid==null)
229
+	    if ($oid == null)
230 230
 	    {
231 231
 	        $where="c.id = '$id'";
232 232
 	    }
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 	    $query=$this->db->getConnection()->select()
238 238
            ->from(
239 239
             array('c' => $this->config->getMIBCacheTableName()),
240
-            array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum',
240
+            array('name' => 'c.name', 'mib' => 'c.mib', 'oid' => 'c.oid', 'type_enum'=>'c.type_enum',
241 241
                 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint',
242 242
                 'description' => 'c.description'))
243 243
             ->where($where);
Please login to merge, or discard this patch.
Braces   +12 added lines, -7 removed lines patch added patch discarded remove patch
@@ -90,7 +90,9 @@  discard block
 block discarded – undo
90 90
 					array('id' => 'id'))
91 91
 				->where("oid = '".$trap."'") ;
92 92
 		$id=$dbconn->fetchRow($query);
93
-		if ( ($id == null) || ! property_exists($id,'id') ) return null;
93
+		if ( ($id == null) || ! property_exists($id,'id') ) {
94
+			return null;
95
+		}
94 96
 		
95 97
 		$query=$dbconn->select()
96 98
 		        ->from(
@@ -103,7 +105,9 @@  discard block
 block discarded – undo
103 105
 		            'o.trap_id='.$id->id )
104 106
 		        ->where("o.object_id = c.id");
105 107
 		$listObjects=$dbconn->fetchAll($query);
106
-		if ( count($listObjects)==0 ) return null;
108
+		if ( count($listObjects)==0 ) {
109
+			return null;
110
+		}
107 111
 		
108 112
 		foreach ($listObjects as $val)
109 113
 		{
@@ -124,7 +128,10 @@  discard block
 block discarded – undo
124 128
 	*/
125 129
 	public function translateOID($oid)
126 130
 	{
127
-	    if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.'
131
+	    if (!preg_match('/^\./',$oid)) {
132
+	    	$oid = '.' . $oid;
133
+	    }
134
+	    // Add a leading '.'
128 135
 		$retArray=array('oid' => $oid, 'mib' => null, 'name'=>null,'type'=>null);
129 136
 		$dbconn = $this->db->getConnection();
130 137
 
@@ -162,8 +169,7 @@  discard block
 block discarded – undo
162 169
 		{
163 170
 		    $retArray['type']=$matches[1];
164 171
 		    $retArray['type_enum']=$matches[2];
165
-		}
166
-		else
172
+		} else
167 173
 		{
168 174
 			$retArray['type']=$translate;
169 175
 			$retArray['type_enum']='';			
@@ -229,8 +235,7 @@  discard block
 block discarded – undo
229 235
 	    if ($oid==null)
230 236
 	    {
231 237
 	        $where="c.id = '$id'";
232
-	    }
233
-	    else
238
+	    } else
234 239
 	    {
235 240
 	        $where="c.oid = '$oid'";
236 241
 	    }
Please login to merge, or discard this patch.