Passed
Push — master ( 3d7e39...d44cfc )
by Patrick
02:50
created
application/controllers/HelperController.php 3 patches
Indentation   +128 added lines, -128 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();
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
 	}
33 33
 	
34 34
 	/** Get hostgroup list with filter (name) : hostgroup=<hostFilter>
35
-	*	returns in JSON : status=>OK/NOK  hosts=>array of hosts
36
-	*/
35
+	 *	returns in JSON : status=>OK/NOK  hosts=>array of hosts
36
+	 */
37 37
 	public function gethostgroupsAction()
38 38
 	{
39 39
 		$postData=$this->getRequest()->getPost();
@@ -52,11 +52,11 @@  discard block
 block discarded – undo
52 52
 	}
53 53
 	
54 54
 	/** Get service list by host name ( host=<host> )
55
-	*	returns in JSON : 
56
-	*		status=>OK/No services found/More than one host matches
57
-	*		services=>array of services (name)
58
-	*		hostid = host object id or -1 if not found.
59
-	*/
55
+	 *	returns in JSON : 
56
+	 *		status=>OK/No services found/More than one host matches
57
+	 *		services=>array of services (name)
58
+	 *		hostid = host object id or -1 if not found.
59
+	 */
60 60
 	public function getservicesAction()
61 61
 	{
62 62
 		$postData=$this->getRequest()->getPost();
@@ -98,11 +98,11 @@  discard block
 block discarded – undo
98 98
 	}
99 99
 	
100 100
 	/** Get service list by host group ( name=<host> )
101
-	*	returns in JSON : 
102
-	*		status=>OK/No services found/More than one host matches
103
-	*		services=>array of services (name)
104
-	*		groupid = group object id or -1 if not found.
105
-	*/
101
+	 *	returns in JSON : 
102
+	 *		status=>OK/No services found/More than one host matches
103
+	 *		services=>array of services (name)
104
+	 *		groupid = group object id or -1 if not found.
105
+	 */
106 106
 	public function gethostgroupservicesAction()
107 107
 	{
108 108
 		$postData=$this->getRequest()->getPost();
@@ -132,10 +132,10 @@  discard block
 block discarded – undo
132 132
 	}
133 133
 
134 134
 	/** Get traps from mib  : entry : mib=<mib>
135
-	*	returns in JSON : 
136
-	*		status=>OK/No mib/Error getting mibs
137
-	*		traps=>array of array( oid -> name)
138
-	*/
135
+	 *	returns in JSON : 
136
+	 *		status=>OK/No mib/Error getting mibs
137
+	 *		traps=>array of array( oid -> name)
138
+	 */
139 139
 	public function gettrapsAction()
140 140
 	{
141 141
 		$postData=$this->getRequest()->getPost();
@@ -155,10 +155,10 @@  discard block
 block discarded – undo
155 155
 	}	
156 156
 
157 157
 	/** Get trap objects from mib  : entry : trap=<oid>
158
-	*	returns in JSON : 
159
-	*		status=>OK/no trap/not found
160
-	*		objects=>array of array( oid -> name, oid->mib)
161
-	*/
158
+	 *	returns in JSON : 
159
+	 *		status=>OK/no trap/not found
160
+	 *		objects=>array of array( oid -> name, oid->mib)
161
+	 */
162 162
 	public function gettrapobjectsAction()
163 163
 	{
164 164
 		$postData=$this->getRequest()->getPost();
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
 	}	
179 179
 	
180 180
 	/** Get list of all loaded mibs : entry : none
181
-	*	return : array of strings.
182
-	*/
181
+	 *	return : array of strings.
182
+	 */
183 183
 	public function getmiblistAction()
184 184
 	{
185 185
 		try
@@ -194,10 +194,10 @@  discard block
 block discarded – undo
194 194
 	}
195 195
 	
196 196
 	/** Get MIB::Name from OID : entry : oid
197
-	*		status=>OK/No oid/not found
198
-	*		mib=>string
199
-	*		name=>string
200
-	*/	
197
+	 *		status=>OK/No oid/not found
198
+	 *		mib=>string
199
+	 *		name=>string
200
+	 */	
201 201
 	public function translateoidAction()
202 202
 	{
203 203
 		$postData=$this->getRequest()->getPost();
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 					'name' => $object['name'],
219 219
 					'type' => $object['type'],
220 220
 					'type_enum' => $object['type_enum'],
221
-				    'description' => $object['description']
221
+					'description' => $object['description']
222 222
 				)
223 223
 			);
224 224
 		}
@@ -226,10 +226,10 @@  discard block
 block discarded – undo
226 226
 	}
227 227
 	
228 228
 	/** Save or execute database purge of <n> days
229
-	*	days=>int 
230
-	*	action=>save/execute
231
-	*	return : status=>OK/Message error
232
-	*/
229
+	 *	days=>int 
230
+	 *	action=>save/execute
231
+	 *	return : status=>OK/Message error
232
+	 */
233 233
 	public function dbmaintenanceAction()
234 234
 	{
235 235
 		
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 		{
244 244
 			try
245 245
 			{
246
-			    $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days);
246
+				$this->getUIDatabase()->setDBConfigValue('db_remove_days',$days);
247 247
 			}
248 248
 			catch (Exception $e)
249 249
 			{
@@ -275,11 +275,11 @@  discard block
 block discarded – undo
275 275
 	}	
276 276
 
277 277
 	/** Save log output to db
278
-	*	destination=>log destination 
279
-	*	file=>file name
280
-	*	level => int 
281
-	*	return : status=>OK/Message error
282
-	*/
278
+	 *	destination=>log destination 
279
+	 *	file=>file name
280
+	 *	level => int 
281
+	 *	return : status=>OK/Message error
282
+	 */
283 283
 	public function logdestinationAction()
284 284
 	{
285 285
 		$postData=$this->getRequest()->getPost();
@@ -298,8 +298,8 @@  discard block
 block discarded – undo
298 298
 			$fileHandler=@fopen($file,'w');
299 299
 			if ($fileHandler == false)
300 300
 			{   // File os note writabe / cannot create
301
-			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
302
-			    return;
301
+				$this->_helper->json(array('status'=>'File not writable :  '.$file));
302
+				return;
303 303
 			}
304 304
 		}
305 305
 		else
@@ -319,9 +319,9 @@  discard block
 block discarded – undo
319 319
 				
320 320
 		try
321 321
 		{
322
-		    $this->getUIDatabase()->setDBConfigValue('log_destination',$destination);
323
-		    $this->getUIDatabase()->setDBConfigValue('log_file',$file);
324
-		    $this->getUIDatabase()->setDBConfigValue('log_level',$level);
322
+			$this->getUIDatabase()->setDBConfigValue('log_destination',$destination);
323
+			$this->getUIDatabase()->setDBConfigValue('log_file',$file);
324
+			$this->getUIDatabase()->setDBConfigValue('log_level',$level);
325 325
 		}
326 326
 		catch (Exception $e)
327 327
 		{
@@ -341,33 +341,33 @@  discard block
 block discarded – undo
341 341
 	public function testruleAction()
342 342
 	{
343 343
 	    
344
-	    $postData=$this->getRequest()->getPost();
344
+		$postData=$this->getRequest()->getPost();
345 345
 	   
346
-	    $rule = $this->checkPostVar($postData, 'rule', '.*');
346
+		$rule = $this->checkPostVar($postData, 'rule', '.*');
347 347
 
348
-	    $action = $this->checkPostVar($postData, 'action', 'evaluate');
348
+		$action = $this->checkPostVar($postData, 'action', 'evaluate');
349 349
 
350
-	    if ($action == 'evaluate')
351
-	    {
352
-	        try
353
-	        {
354
-	            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
355
-	            $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
356
-	            $trap = new Trap($icingaweb2_etc);
357
-	            // Cleanup spaces before eval
358
-	            $rule=$trap->ruleClass->eval_cleanup($rule);
359
-	            // Eval
360
-	            $item=0;
361
-	            $rule=$trap->ruleClass->evaluation($rule,$item);
362
-	        }
363
-	        catch (Exception $e)
364
-	        {
365
-	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
366
-	            return;
367
-	        }
368
-	        $return=($rule==true)?'true':'false';
369
-	        $this->_helper->json(array('status'=>'OK', 'message' => $return));
370
-	    }
350
+		if ($action == 'evaluate')
351
+		{
352
+			try
353
+			{
354
+				require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
355
+				$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
356
+				$trap = new Trap($icingaweb2_etc);
357
+				// Cleanup spaces before eval
358
+				$rule=$trap->ruleClass->eval_cleanup($rule);
359
+				// Eval
360
+				$item=0;
361
+				$rule=$trap->ruleClass->evaluation($rule,$item);
362
+			}
363
+			catch (Exception $e)
364
+			{
365
+				$this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
366
+				return;
367
+			}
368
+			$return=($rule==true)?'true':'false';
369
+			$this->_helper->json(array('status'=>'OK', 'message' => $return));
370
+		}
371 371
 	    
372 372
 	}	
373 373
 
@@ -378,35 +378,35 @@  discard block
 block discarded – undo
378 378
 	 */
379 379
 	public function pluginAction()
380 380
 	{
381
-	    $postData=$this->getRequest()->getPost();
381
+		$postData=$this->getRequest()->getPost();
382 382
 	    
383
-	    $pluginName = $this->checkPostVar($postData, 'name', '.*');
383
+		$pluginName = $this->checkPostVar($postData, 'name', '.*');
384 384
 	    
385
-	    $action = $this->checkPostVar($postData, 'action', 'enable|disable');
385
+		$action = $this->checkPostVar($postData, 'action', 'enable|disable');
386 386
 	    
387
-        try
388
-        {
389
-            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
390
-            $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
391
-            $trap = new Trap($icingaweb2_etc);
392
-            // Enable plugin.
393
-            $action=($action == 'enable') ? true : false;
394
-            $retVal=$trap->pluginClass->enablePlugin($pluginName, $action);
387
+		try
388
+		{
389
+			require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
390
+			$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
391
+			$trap = new Trap($icingaweb2_etc);
392
+			// Enable plugin.
393
+			$action=($action == 'enable') ? true : false;
394
+			$retVal=$trap->pluginClass->enablePlugin($pluginName, $action);
395 395
             
396
-        }
397
-        catch (Exception $e)
398
-        {
399
-            $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
400
-            return;
401
-        }
402
-        if ($retVal === true)
403
-        {
404
-            $this->_helper->json(array('status'=>'OK'));
405
-        }
406
-        else
407
-        {
408
-            $this->_helper->json(array('status'=>'Error, see logs'));
409
-        }
396
+		}
397
+		catch (Exception $e)
398
+		{
399
+			$this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
400
+			return;
401
+		}
402
+		if ($retVal === true)
403
+		{
404
+			$this->_helper->json(array('status'=>'OK'));
405
+		}
406
+		else
407
+		{
408
+			$this->_helper->json(array('status'=>'Error, see logs'));
409
+		}
410 410
 	}
411 411
 	
412 412
 	/** Function evaluation
@@ -416,49 +416,49 @@  discard block
 block discarded – undo
416 416
 	 */
417 417
 	public function functionAction()
418 418
 	{
419
-	    $postData=$this->getRequest()->getPost();
419
+		$postData=$this->getRequest()->getPost();
420 420
 	    
421
-	    $functionString = $this->checkPostVar($postData, 'function', '.*');
421
+		$functionString = $this->checkPostVar($postData, 'function', '.*');
422 422
 	    
423
-	    $this->checkPostVar($postData, 'action', 'evaluate');
423
+		$this->checkPostVar($postData, 'action', 'evaluate');
424 424
 	    
425
-	    // Only one action possible for now, no tests on action.
426
-	    try
427
-	    {
428
-	        require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
429
-	        $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc');
430
-	        $trap = new Trap($icingaweb2Etc);
431
-	        // load all plugins in case tested function is not enabled.
432
-	        $trap->pluginClass->registerAllPlugins(false);
433
-	        // Clean all spaces
434
-	        $functionString = $trap->ruleClass->eval_cleanup($functionString);
435
-	        // Eval functions
436
-	        $result = $trap->pluginClass->evaluateFunctionString($functionString);	        
437
-	    }
438
-	    catch (Exception $e)
439
-	    {
440
-	        $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
441
-	        return;
442
-	    }
425
+		// Only one action possible for now, no tests on action.
426
+		try
427
+		{
428
+			require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
429
+			$icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc');
430
+			$trap = new Trap($icingaweb2Etc);
431
+			// load all plugins in case tested function is not enabled.
432
+			$trap->pluginClass->registerAllPlugins(false);
433
+			// Clean all spaces
434
+			$functionString = $trap->ruleClass->eval_cleanup($functionString);
435
+			// Eval functions
436
+			$result = $trap->pluginClass->evaluateFunctionString($functionString);	        
437
+		}
438
+		catch (Exception $e)
439
+		{
440
+			$this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
441
+			return;
442
+		}
443 443
 	    
444
-        $result = ($result === true)?'True':'False';
445
-        $this->_helper->json(array('status'=>'OK','message' => $result));
444
+		$result = ($result === true)?'True':'False';
445
+		$this->_helper->json(array('status'=>'OK','message' => $result));
446 446
 	}
447 447
 
448
-    /**************   Utilities **********************/
448
+	/**************   Utilities **********************/
449 449
 
450 450
 	private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string
451 451
 	{
452
-	    if (!isset ($postData[$postVar]))
453
-	    {
454
-	        $this->_helper->json(array('status'=>'No ' . $postVar));
455
-	        return '';
456
-	    }
457
-	    if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1)
458
-	    {
459
-	        $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar]));
460
-	        return '';
461
-	    }
462
-	    return $postData[$postVar];
452
+		if (!isset ($postData[$postVar]))
453
+		{
454
+			$this->_helper->json(array('status'=>'No ' . $postVar));
455
+			return '';
456
+		}
457
+		if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1)
458
+		{
459
+			$this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar]));
460
+			return '';
461
+		}
462
+		return $postData[$postVar];
463 463
 	}
464 464
 }
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -18,14 +18,14 @@  discard block
 block discarded – undo
18 18
 	{
19 19
 		$postData=$this->getRequest()->getPost();
20 20
 		
21
-		$hostFilter = $this->checkPostVar($postData, 'hostFilter', '.*');
21
+		$hostFilter=$this->checkPostVar($postData, 'hostFilter', '.*');
22 22
 		
23
-		$retHosts=array('status'=>'OK','hosts' => array());
23
+		$retHosts=array('status'=>'OK', 'hosts' => array());
24 24
 
25 25
 		$hosts=$this->getHostByIP($hostFilter);
26 26
 		foreach ($hosts as $val)
27 27
 		{
28
-			array_push($retHosts['hosts'],$val->name);
28
+			array_push($retHosts['hosts'], $val->name);
29 29
 		}
30 30
 		
31 31
 		$this->_helper->json($retHosts);
@@ -38,14 +38,14 @@  discard block
 block discarded – undo
38 38
 	{
39 39
 		$postData=$this->getRequest()->getPost();
40 40
 		
41
-		$hostFilter = $this->checkPostVar($postData, 'hostFilter', '.*');
41
+		$hostFilter=$this->checkPostVar($postData, 'hostFilter', '.*');
42 42
 		
43
-		$retHosts=array('status'=>'OK','hosts' => array());
43
+		$retHosts=array('status'=>'OK', 'hosts' => array());
44 44
 
45 45
 		$hosts=$this->getHostGroupByName($hostFilter);
46 46
 		foreach ($hosts as $val)
47 47
 		{
48
-			array_push($retHosts['hosts'],$val->name);
48
+			array_push($retHosts['hosts'], $val->name);
49 49
 		}
50 50
 		
51 51
 		$this->_helper->json($retHosts);
@@ -68,31 +68,31 @@  discard block
 block discarded – undo
68 68
 		}
69 69
 		else
70 70
 		{
71
-			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1));
71
+			$this->_helper->json(array('status'=>'No Hosts', 'hostid' => -1));
72 72
 			return;
73 73
 		}
74 74
 		
75 75
 		$hostArray=$this->getHostByName($host);
76 76
 		if (count($hostArray) > 1)
77 77
 		{	
78
-			$this->_helper->json(array('status'=>'More than one host matches','hostid' => -1));
78
+			$this->_helper->json(array('status'=>'More than one host matches', 'hostid' => -1));
79 79
 			return;
80 80
 		}
81 81
 		else if (count($hostArray) == 0)
82 82
 		{
83
-			$this->_helper->json(array('status'=>'No host matches','hostid' => -1));
83
+			$this->_helper->json(array('status'=>'No host matches', 'hostid' => -1));
84 84
 			return;
85 85
 		}
86 86
 		$services=$this->getServicesByHostid($hostArray[0]->id);
87 87
 		if (count($services) < 1)
88 88
 		{
89
-			$this->_helper->json(array('status'=>'No services found for host','hostid' => $hostArray[0]->id));
89
+			$this->_helper->json(array('status'=>'No services found for host', 'hostid' => $hostArray[0]->id));
90 90
 			return;
91 91
 		}
92
-		$retServices=array('status'=>'OK','services' => array(),'hostid' => $hostArray[0]->id);
92
+		$retServices=array('status'=>'OK', 'services' => array(), 'hostid' => $hostArray[0]->id);
93 93
 		foreach ($services as $val)
94 94
 		{
95
-			array_push($retServices['services'],array($val->id , $val->name));
95
+			array_push($retServices['services'], array($val->id, $val->name));
96 96
 		}
97 97
 		$this->_helper->json($retServices);
98 98
 	}
@@ -107,26 +107,26 @@  discard block
 block discarded – undo
107 107
 	{
108 108
 		$postData=$this->getRequest()->getPost();
109 109
 		
110
-		$host = $this->checkPostVar($postData, 'host', '.+');
110
+		$host=$this->checkPostVar($postData, 'host', '.+');
111 111
 		
112 112
 		$hostArray=$this->getHostGroupByName($host);
113 113
 		if (count($hostArray) > 1)
114 114
 		{	
115
-			$this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1));
115
+			$this->_helper->json(array('status'=>'More than one hostgroup matches', 'hostid' => -1));
116 116
 			return;
117 117
 		}
118 118
 		else if (count($hostArray) == 0)
119 119
 		{
120
-			$this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1));
120
+			$this->_helper->json(array('status'=>'No hostgroup matches', 'hostid' => -1));
121 121
 			return;
122 122
 		}
123 123
 		$services=$this->getServicesByHostGroupid($hostArray[0]->id);
124 124
 		if (count($services) < 1)
125 125
 		{
126
-			$this->_helper->json(array('status'=>'No services found for hostgroup','hostid' => $hostArray[0]->id));
126
+			$this->_helper->json(array('status'=>'No services found for hostgroup', 'hostid' => $hostArray[0]->id));
127 127
 			return;
128 128
 		}
129
-		$retServices=array('status'=>'OK','services' => $services,'hostid' => $hostArray[0]->id);
129
+		$retServices=array('status'=>'OK', 'services' => $services, 'hostid' => $hostArray[0]->id);
130 130
 		
131 131
 		$this->_helper->json($retServices);
132 132
 	}
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
 	{
141 141
 		$postData=$this->getRequest()->getPost();
142 142
 		
143
-		$mib = $this->checkPostVar($postData, 'mib', '.*');
143
+		$mib=$this->checkPostVar($postData, 'mib', '.*');
144 144
 
145 145
 		try
146 146
 		{
147 147
 			$traplist=$this->getMIB()->getTrapList($mib);
148
-			$retTraps=array('status'=>'OK','traps' => $traplist);
148
+			$retTraps=array('status'=>'OK', 'traps' => $traplist);
149 149
 		} 
150 150
 		catch (Exception $e) 
151 151
 		{ 
@@ -163,12 +163,12 @@  discard block
 block discarded – undo
163 163
 	{
164 164
 		$postData=$this->getRequest()->getPost();
165 165
 		
166
-		$trap = $this->checkPostVar($postData, 'trap', '.*');
166
+		$trap=$this->checkPostVar($postData, 'trap', '.*');
167 167
 		
168 168
 		try
169 169
 		{
170 170
 			$objectlist=$this->getMIB()->getObjectList($trap);
171
-			$retObjects=array('status'=>'OK','objects' => $objectlist);
171
+			$retObjects=array('status'=>'OK', 'objects' => $objectlist);
172 172
 		} 
173 173
 		catch (Exception $e) 
174 174
 		{ 
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 	{
203 203
 		$postData=$this->getRequest()->getPost();
204 204
 		
205
-		$oid = $this->checkPostVar($postData, 'oid', '.*');
205
+		$oid=$this->checkPostVar($postData, 'oid', '.*');
206 206
 		
207 207
 		// Try to get oid name from snmptranslate
208 208
 		if (($object=$this->getMIB()->translateOID($oid)) == null)
@@ -235,19 +235,19 @@  discard block
 block discarded – undo
235 235
 		
236 236
 		$postData=$this->getRequest()->getPost();
237 237
 		
238
-		$days = $this->checkPostVar($postData, 'days', '^[0-9]+$');
238
+		$days=$this->checkPostVar($postData, 'days', '^[0-9]+$');
239 239
 
240
-		$action = $this->checkPostVar($postData, 'action', 'save|execute');
240
+		$action=$this->checkPostVar($postData, 'action', 'save|execute');
241 241
 		
242 242
 		if ($action == 'save')
243 243
 		{
244 244
 			try
245 245
 			{
246
-			    $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days);
246
+			    $this->getUIDatabase()->setDBConfigValue('db_remove_days', $days);
247 247
 			}
248 248
 			catch (Exception $e)
249 249
 			{
250
-				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
250
+				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage()));
251 251
 				return;
252 252
 			}
253 253
 			$this->_helper->json(array('status'=>'OK'));
@@ -257,16 +257,16 @@  discard block
 block discarded – undo
257 257
 		{
258 258
 			try
259 259
 			{
260
-				require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
260
+				require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
261 261
 				$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
262 262
 				$debug_level=4;
263
-				$trap = new Trap($icingaweb2_etc);
264
-				$trap->setLogging($debug_level,'syslog');
263
+				$trap=new Trap($icingaweb2_etc);
264
+				$trap->setLogging($debug_level, 'syslog');
265 265
 				$trap->eraseOldTraps($days);
266 266
 			}
267 267
 			catch (Exception $e)
268 268
 			{
269
-				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage() ));
269
+				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage()));
270 270
 				return;
271 271
 			}			
272 272
 			$this->_helper->json(array('status'=>'OK'));
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 	{
285 285
 		$postData=$this->getRequest()->getPost();
286 286
 		
287
-		$destination = $this->checkPostVar($postData, 'destination', '.*');
287
+		$destination=$this->checkPostVar($postData, 'destination', '.*');
288 288
 		$logDest=$this->getModuleConfig()->getLogDestinations();
289 289
 		if (!isset($logDest[$destination]))
290 290
 		{
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 		if (isset($postData['file']))
296 296
 		{ 
297 297
 			$file=$postData['file'];
298
-			$fileHandler=@fopen($file,'w');
298
+			$fileHandler=@fopen($file, 'w');
299 299
 			if ($fileHandler == false)
300 300
 			{   // File os note writabe / cannot create
301 301
 			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
@@ -315,17 +315,17 @@  discard block
 block discarded – undo
315 315
 			}
316 316
 		}
317 317
 
318
-		$level = $this->checkPostVar($postData, 'level', '[0-9]');
318
+		$level=$this->checkPostVar($postData, 'level', '[0-9]');
319 319
 				
320 320
 		try
321 321
 		{
322
-		    $this->getUIDatabase()->setDBConfigValue('log_destination',$destination);
323
-		    $this->getUIDatabase()->setDBConfigValue('log_file',$file);
324
-		    $this->getUIDatabase()->setDBConfigValue('log_level',$level);
322
+		    $this->getUIDatabase()->setDBConfigValue('log_destination', $destination);
323
+		    $this->getUIDatabase()->setDBConfigValue('log_file', $file);
324
+		    $this->getUIDatabase()->setDBConfigValue('log_level', $level);
325 325
 		}
326 326
 		catch (Exception $e)
327 327
 		{
328
-			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
328
+			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage()));
329 329
 			return;
330 330
 		}
331 331
 		$this->_helper->json(array('status'=>'OK'));
@@ -343,29 +343,29 @@  discard block
 block discarded – undo
343 343
 	    
344 344
 	    $postData=$this->getRequest()->getPost();
345 345
 	   
346
-	    $rule = $this->checkPostVar($postData, 'rule', '.*');
346
+	    $rule=$this->checkPostVar($postData, 'rule', '.*');
347 347
 
348
-	    $action = $this->checkPostVar($postData, 'action', 'evaluate');
348
+	    $action=$this->checkPostVar($postData, 'action', 'evaluate');
349 349
 
350 350
 	    if ($action == 'evaluate')
351 351
 	    {
352 352
 	        try
353 353
 	        {
354
-	            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
354
+	            require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
355 355
 	            $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
356
-	            $trap = new Trap($icingaweb2_etc);
356
+	            $trap=new Trap($icingaweb2_etc);
357 357
 	            // Cleanup spaces before eval
358 358
 	            $rule=$trap->ruleClass->eval_cleanup($rule);
359 359
 	            // Eval
360 360
 	            $item=0;
361
-	            $rule=$trap->ruleClass->evaluation($rule,$item);
361
+	            $rule=$trap->ruleClass->evaluation($rule, $item);
362 362
 	        }
363 363
 	        catch (Exception $e)
364 364
 	        {
365
-	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
365
+	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage()));
366 366
 	            return;
367 367
 	        }
368
-	        $return=($rule==true)?'true':'false';
368
+	        $return=($rule == true) ? 'true' : 'false';
369 369
 	        $this->_helper->json(array('status'=>'OK', 'message' => $return));
370 370
 	    }
371 371
 	    
@@ -380,15 +380,15 @@  discard block
 block discarded – undo
380 380
 	{
381 381
 	    $postData=$this->getRequest()->getPost();
382 382
 	    
383
-	    $pluginName = $this->checkPostVar($postData, 'name', '.*');
383
+	    $pluginName=$this->checkPostVar($postData, 'name', '.*');
384 384
 	    
385
-	    $action = $this->checkPostVar($postData, 'action', 'enable|disable');
385
+	    $action=$this->checkPostVar($postData, 'action', 'enable|disable');
386 386
 	    
387 387
         try
388 388
         {
389
-            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
389
+            require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
390 390
             $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
391
-            $trap = new Trap($icingaweb2_etc);
391
+            $trap=new Trap($icingaweb2_etc);
392 392
             // Enable plugin.
393 393
             $action=($action == 'enable') ? true : false;
394 394
             $retVal=$trap->pluginClass->enablePlugin($pluginName, $action);
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
         }
397 397
         catch (Exception $e)
398 398
         {
399
-            $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
399
+            $this->_helper->json(array('status'=>'Action error : '.$e->getMessage()));
400 400
             return;
401 401
         }
402 402
         if ($retVal === true)
@@ -418,45 +418,45 @@  discard block
 block discarded – undo
418 418
 	{
419 419
 	    $postData=$this->getRequest()->getPost();
420 420
 	    
421
-	    $functionString = $this->checkPostVar($postData, 'function', '.*');
421
+	    $functionString=$this->checkPostVar($postData, 'function', '.*');
422 422
 	    
423 423
 	    $this->checkPostVar($postData, 'action', 'evaluate');
424 424
 	    
425 425
 	    // Only one action possible for now, no tests on action.
426 426
 	    try
427 427
 	    {
428
-	        require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
428
+	        require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
429 429
 	        $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc');
430
-	        $trap = new Trap($icingaweb2Etc);
430
+	        $trap=new Trap($icingaweb2Etc);
431 431
 	        // load all plugins in case tested function is not enabled.
432 432
 	        $trap->pluginClass->registerAllPlugins(false);
433 433
 	        // Clean all spaces
434
-	        $functionString = $trap->ruleClass->eval_cleanup($functionString);
434
+	        $functionString=$trap->ruleClass->eval_cleanup($functionString);
435 435
 	        // Eval functions
436
-	        $result = $trap->pluginClass->evaluateFunctionString($functionString);	        
436
+	        $result=$trap->pluginClass->evaluateFunctionString($functionString);	        
437 437
 	    }
438 438
 	    catch (Exception $e)
439 439
 	    {
440
-	        $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
440
+	        $this->_helper->json(array('status'=>'Action error : '.$e->getMessage()));
441 441
 	        return;
442 442
 	    }
443 443
 	    
444
-        $result = ($result === true)?'True':'False';
445
-        $this->_helper->json(array('status'=>'OK','message' => $result));
444
+        $result=($result === true) ? 'True' : 'False';
445
+        $this->_helper->json(array('status'=>'OK', 'message' => $result));
446 446
 	}
447 447
 
448 448
     /**************   Utilities **********************/
449 449
 
450
-	private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string
450
+	private function checkPostVar(array $postData, string $postVar, string $validRegexp) : string
451 451
 	{
452 452
 	    if (!isset ($postData[$postVar]))
453 453
 	    {
454
-	        $this->_helper->json(array('status'=>'No ' . $postVar));
454
+	        $this->_helper->json(array('status'=>'No '.$postVar));
455 455
 	        return '';
456 456
 	    }
457 457
 	    if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1)
458 458
 	    {
459
-	        $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar]));
459
+	        $this->_helper->json(array('status'=>'Unknown '.$postVar.' value '.$postData[$postVar]));
460 460
 	        return '';
461 461
 	    }
462 462
 	    return $postData[$postVar];
Please login to merge, or discard this patch.
Braces   +16 added lines, -32 removed lines patch added patch discarded remove patch
@@ -65,8 +65,7 @@  discard block
 block discarded – undo
65 65
 		if (isset($postData['host']))
66 66
 		{
67 67
 			$host=$postData['host'];
68
-		}
69
-		else
68
+		} else
70 69
 		{
71 70
 			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1));
72 71
 			return;
@@ -77,8 +76,7 @@  discard block
 block discarded – undo
77 76
 		{	
78 77
 			$this->_helper->json(array('status'=>'More than one host matches','hostid' => -1));
79 78
 			return;
80
-		}
81
-		else if (count($hostArray) == 0)
79
+		} else if (count($hostArray) == 0)
82 80
 		{
83 81
 			$this->_helper->json(array('status'=>'No host matches','hostid' => -1));
84 82
 			return;
@@ -114,8 +112,7 @@  discard block
 block discarded – undo
114 112
 		{	
115 113
 			$this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1));
116 114
 			return;
117
-		}
118
-		else if (count($hostArray) == 0)
115
+		} else if (count($hostArray) == 0)
119 116
 		{
120 117
 			$this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1));
121 118
 			return;
@@ -146,8 +143,7 @@  discard block
 block discarded – undo
146 143
 		{
147 144
 			$traplist=$this->getMIB()->getTrapList($mib);
148 145
 			$retTraps=array('status'=>'OK','traps' => $traplist);
149
-		} 
150
-		catch (Exception $e) 
146
+		} catch (Exception $e) 
151 147
 		{ 
152 148
 			$retTraps=array('status' => 'Error getting mibs');
153 149
 		}
@@ -169,8 +165,7 @@  discard block
 block discarded – undo
169 165
 		{
170 166
 			$objectlist=$this->getMIB()->getObjectList($trap);
171 167
 			$retObjects=array('status'=>'OK','objects' => $objectlist);
172
-		} 
173
-		catch (Exception $e) 
168
+		} catch (Exception $e) 
174 169
 		{ 
175 170
 			$retObjects=array('status' => 'not found');
176 171
 		}
@@ -185,8 +180,7 @@  discard block
 block discarded – undo
185 180
 		try
186 181
 		{
187 182
 			$miblist=$this->getMIB()->getMIBList();
188
-		} 
189
-		catch (Exception $e) 
183
+		} catch (Exception $e) 
190 184
 		{ 
191 185
 			$miblist=array('Error getting mibs');
192 186
 		}
@@ -209,8 +203,7 @@  discard block
 block discarded – undo
209 203
 		{
210 204
 			$this->_helper->json(array('status'=>'Not found'));
211 205
 			return;
212
-		}
213
-		else
206
+		} else
214 207
 		{
215 208
 			$this->_helper->json(
216 209
 				array('status'=>'OK',
@@ -244,8 +237,7 @@  discard block
 block discarded – undo
244 237
 			try
245 238
 			{
246 239
 			    $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days);
247
-			}
248
-			catch (Exception $e)
240
+			} catch (Exception $e)
249 241
 			{
250 242
 				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
251 243
 				return;
@@ -263,8 +255,7 @@  discard block
 block discarded – undo
263 255
 				$trap = new Trap($icingaweb2_etc);
264 256
 				$trap->setLogging($debug_level,'syslog');
265 257
 				$trap->eraseOldTraps($days);
266
-			}
267
-			catch (Exception $e)
258
+			} catch (Exception $e)
268 259
 			{
269 260
 				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage() ));
270 261
 				return;
@@ -301,14 +292,12 @@  discard block
 block discarded – undo
301 292
 			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
302 293
 			    return;
303 294
 			}
304
-		}
305
-		else
295
+		} else
306 296
 		{
307 297
 			if ($destination != 'file')
308 298
 			{
309 299
 				$file=null;
310
-			}
311
-			else
300
+			} else
312 301
 			{
313 302
 				$this->_helper->json(array('status'=>'No file'));
314 303
 				return;
@@ -322,8 +311,7 @@  discard block
 block discarded – undo
322 311
 		    $this->getUIDatabase()->setDBConfigValue('log_destination',$destination);
323 312
 		    $this->getUIDatabase()->setDBConfigValue('log_file',$file);
324 313
 		    $this->getUIDatabase()->setDBConfigValue('log_level',$level);
325
-		}
326
-		catch (Exception $e)
314
+		} catch (Exception $e)
327 315
 		{
328 316
 			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
329 317
 			return;
@@ -359,8 +347,7 @@  discard block
 block discarded – undo
359 347
 	            // Eval
360 348
 	            $item=0;
361 349
 	            $rule=$trap->ruleClass->evaluation($rule,$item);
362
-	        }
363
-	        catch (Exception $e)
350
+	        } catch (Exception $e)
364 351
 	        {
365 352
 	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
366 353
 	            return;
@@ -393,8 +380,7 @@  discard block
 block discarded – undo
393 380
             $action=($action == 'enable') ? true : false;
394 381
             $retVal=$trap->pluginClass->enablePlugin($pluginName, $action);
395 382
             
396
-        }
397
-        catch (Exception $e)
383
+        } catch (Exception $e)
398 384
         {
399 385
             $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
400 386
             return;
@@ -402,8 +388,7 @@  discard block
 block discarded – undo
402 388
         if ($retVal === true)
403 389
         {
404 390
             $this->_helper->json(array('status'=>'OK'));
405
-        }
406
-        else
391
+        } else
407 392
         {
408 393
             $this->_helper->json(array('status'=>'Error, see logs'));
409 394
         }
@@ -434,8 +419,7 @@  discard block
 block discarded – undo
434 419
 	        $functionString = $trap->ruleClass->eval_cleanup($functionString);
435 420
 	        // Eval functions
436 421
 	        $result = $trap->pluginClass->evaluateFunctionString($functionString);	        
437
-	    }
438
-	    catch (Exception $e)
422
+	    } catch (Exception $e)
439 423
 	    {
440 424
 	        $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
441 425
 	        return;
Please login to merge, or discard this patch.
application/controllers/HandlerController.php 3 patches
Indentation   +246 added lines, -247 removed lines patch added patch discarded remove patch
@@ -11,13 +11,12 @@  discard block
 block discarded – undo
11 11
 
12 12
 //use Icinga\Web\Form as Form;
13 13
 /** Rules management
14
-
15
-*/
14
+ */
16 15
 class HandlerController extends TrapsController
17 16
 {
18 17
 
19 18
 	/** index : list existing rules 
20
-	*/
19
+	 */
21 20
 	public function indexAction()
22 21
 	{	
23 22
 		$this->checkReadPermission();
@@ -41,22 +40,22 @@  discard block
 block discarded – undo
41 40
 	 */
42 41
 	public function testruleAction()
43 42
 	{
44
-	    $this->checkReadPermission();
45
-	    $this->getTabs()->add('get',array(
46
-	        'active'	=> true,
47
-	        'label'		=> $this->translate('Test Rule'),
48
-	        'url'		=> Url::fromRequest()
49
-	    ));
43
+		$this->checkReadPermission();
44
+		$this->getTabs()->add('get',array(
45
+			'active'	=> true,
46
+			'label'		=> $this->translate('Test Rule'),
47
+			'url'		=> Url::fromRequest()
48
+		));
50 49
 	    
51 50
 
52
-	    if ($this->params->get('rule') !== null) 
53
-	    {
54
-	        $this->view->rule= $this->params->get('rule');
55
-	    }
56
-	    else
57
-	    {
58
-	        $this->view->rule='';
59
-	    }
51
+		if ($this->params->get('rule') !== null) 
52
+		{
53
+			$this->view->rule= $this->params->get('rule');
54
+		}
55
+		else
56
+		{
57
+			$this->view->rule='';
58
+		}
60 59
 	}
61 60
 	
62 61
 	/**
@@ -64,31 +63,31 @@  discard block
 block discarded – undo
64 63
 	 */
65 64
 	private function add_setup_vars()
66 65
 	{
67
-	    // variables to send to view
68
-	    $this->view->hostlist=array(); // host list to input datalist
69
-	    $this->view->hostname=''; // Host name in input text
70
-	    $this->view->serviceGet=false; // Set to true to get list of service if only one host set
71
-	    $this->view->serviceSet=null; // Select service in services select (must have serviceGet=true).
72
-	    $this->view->mainoid=''; // Trap OID
73
-	    $this->view->mib=''; // Trap mib
74
-	    $this->view->name=''; // Trap name
75
-	    $this->view->trapListForMIB=array(); // Trap list if mib exists for trap
76
-	    $this->view->objectList=array(); // objects sent with trap
77
-	    $this->view->display=''; // Initial display
78
-	    $this->view->rule=''; // rule display
79
-	    $this->view->revertOK=''; // revert OK in seconds
80
-	    $this->view->hostid=-1; // normally set by javascript serviceGet()
81
-	    $this->view->ruleid=-1; // Rule id in DB for update & delete
82
-	    $this->view->setToUpdate=false; // set form as update form
83
-	    $this->view->setRuleMatch=-1; // set action on rule match (default nothing)
84
-	    $this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing)
66
+		// variables to send to view
67
+		$this->view->hostlist=array(); // host list to input datalist
68
+		$this->view->hostname=''; // Host name in input text
69
+		$this->view->serviceGet=false; // Set to true to get list of service if only one host set
70
+		$this->view->serviceSet=null; // Select service in services select (must have serviceGet=true).
71
+		$this->view->mainoid=''; // Trap OID
72
+		$this->view->mib=''; // Trap mib
73
+		$this->view->name=''; // Trap name
74
+		$this->view->trapListForMIB=array(); // Trap list if mib exists for trap
75
+		$this->view->objectList=array(); // objects sent with trap
76
+		$this->view->display=''; // Initial display
77
+		$this->view->rule=''; // rule display
78
+		$this->view->revertOK=''; // revert OK in seconds
79
+		$this->view->hostid=-1; // normally set by javascript serviceGet()
80
+		$this->view->ruleid=-1; // Rule id in DB for update & delete
81
+		$this->view->setToUpdate=false; // set form as update form
82
+		$this->view->setRuleMatch=-1; // set action on rule match (default nothing)
83
+		$this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing)
85 84
 	    
86
-	    $this->view->selectGroup=false; // Select by group if true
87
-	    $this->view->hostgroupid=-1; // host group id
88
-	    $this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one)
85
+		$this->view->selectGroup=false; // Select by group if true
86
+		$this->view->hostgroupid=-1; // host group id
87
+		$this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one)
89 88
 	    
90
-	    $this->view->modifier=null;
91
-	    $this->view->modified=null;
89
+		$this->view->modifier=null;
90
+		$this->view->modified=null;
92 91
 	}
93 92
 	
94 93
 	/**
@@ -97,102 +96,102 @@  discard block
 block discarded – undo
97 96
 	 */
98 97
 	private function add_from_existing($trapid)
99 98
 	{
100
-	    /********** Setup from existing trap ***************/
101
-	    // Get the full trap info
102
-	    $trapDetail=$this->getTrapDetail($trapid);
99
+		/********** Setup from existing trap ***************/
100
+		// Get the full trap info
101
+		$trapDetail=$this->getTrapDetail($trapid);
103 102
 	    
104
-	    $hostfilter=$trapDetail->source_ip;
103
+		$hostfilter=$trapDetail->source_ip;
105 104
 	    
106
-	    // Get host
107
-	    try
108
-	    {
109
-	        $hosts=$this->getHostByIP($hostfilter);
110
-	    }
111
-	    catch (Exception $e)
112
-	    {
113
-	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
114
-	    }
105
+		// Get host
106
+		try
107
+		{
108
+			$hosts=$this->getHostByIP($hostfilter);
109
+		}
110
+		catch (Exception $e)
111
+		{
112
+			$this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
113
+		}
115 114
 	    
116 115
 	    
117
-	    // if one unique host found -> put id text input
118
-	    if (count($hosts)==1) {
119
-	        $this->view->hostname=$hosts[0]->name;
120
-	        //$hostid=$hosts[0]->id;
121
-	        // Tell JS to get services when page is loaded
122
-	        $this->view->serviceGet=true;
116
+		// if one unique host found -> put id text input
117
+		if (count($hosts)==1) {
118
+			$this->view->hostname=$hosts[0]->name;
119
+			//$hostid=$hosts[0]->id;
120
+			// Tell JS to get services when page is loaded
121
+			$this->view->serviceGet=true;
123 122
 	        
124
-	    }
125
-	    else
126
-	    {
127
-	        foreach($hosts as $key=>$val)
128
-	        {
129
-	            array_push($this->view->hostlist,$hosts[$key]->name);
130
-	        }
131
-	    }
123
+		}
124
+		else
125
+		{
126
+			foreach($hosts as $key=>$val)
127
+			{
128
+				array_push($this->view->hostlist,$hosts[$key]->name);
129
+			}
130
+		}
132 131
 	    
133
-	    // set up trap oid and objects received by the trap
132
+		// set up trap oid and objects received by the trap
134 133
 	    
135
-	    $this->view->mainoid=$trapDetail->trap_oid;
136
-	    if ($trapDetail->trap_name_mib != null)
137
-	    {
138
-	        $this->view->mib=$trapDetail->trap_name_mib;
139
-	        $this->view->name=$trapDetail->trap_name;
140
-	        $this->view->trapListForMIB=$this->getMIB()
141
-	        ->getTrapList($trapDetail->trap_name_mib);
142
-	    }
134
+		$this->view->mainoid=$trapDetail->trap_oid;
135
+		if ($trapDetail->trap_name_mib != null)
136
+		{
137
+			$this->view->mib=$trapDetail->trap_name_mib;
138
+			$this->view->name=$trapDetail->trap_name;
139
+			$this->view->trapListForMIB=$this->getMIB()
140
+			->getTrapList($trapDetail->trap_name_mib);
141
+		}
143 142
 	    
144
-	    // Get all objects that can be in trap from MIB
145
-	    $allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid);
146
-	    // Get all objects in current Trap
147
-	    $currentTrapObjects=$this->getTrapobjects($trapid);
148
-	    $oid_index=1;
149
-	    foreach ($currentTrapObjects as $key => $val)
150
-	    {
151
-	        $currentObjectType='Unknown';
152
-	        $currentObjectTypeEnum='Unknown';
153
-	        if (isset($allObjects[$val->oid]['type']))
154
-	        {
155
-	            $currentObjectType=$allObjects[$val->oid]['type'];
156
-	            $currentObjectTypeEnum=$allObjects[$val->oid]['type_enum'];
157
-	        }
158
-	        $currentObject=array(
159
-	            $oid_index,
160
-	            $val->oid,
161
-	            $val->oid_name_mib,
162
-	            $val->oid_name,
163
-	            $val->value,
164
-	            $currentObjectType,
165
-	            $currentObjectTypeEnum
166
-	        );
167
-	        $oid_index++;
168
-	        array_push($this->view->objectList,$currentObject);
169
-	        // set currrent object to null in allObjects
170
-	        if (isset($allObjects[$val->oid]))
171
-	        {
172
-	            $allObjects[$val->oid]=null;
173
-	        }
174
-	    }
175
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
176
-	    {
177
-	        foreach ($allObjects as $key => $val)
178
-	        {
179
-	            if ($val==null) { continue; }
180
-	            array_push($this->view->objectList, array(
181
-	                $oid_index,
182
-	                $key,
183
-	                $allObjects[$key]['mib'],
184
-	                $allObjects[$key]['name'],
185
-	                '',
186
-	                $allObjects[$key]['type'],
187
-	                $allObjects[$key]['type_enum']
188
-	            ));
189
-	            $oid_index++;
190
-	        }
191
-	    }
143
+		// Get all objects that can be in trap from MIB
144
+		$allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid);
145
+		// Get all objects in current Trap
146
+		$currentTrapObjects=$this->getTrapobjects($trapid);
147
+		$oid_index=1;
148
+		foreach ($currentTrapObjects as $key => $val)
149
+		{
150
+			$currentObjectType='Unknown';
151
+			$currentObjectTypeEnum='Unknown';
152
+			if (isset($allObjects[$val->oid]['type']))
153
+			{
154
+				$currentObjectType=$allObjects[$val->oid]['type'];
155
+				$currentObjectTypeEnum=$allObjects[$val->oid]['type_enum'];
156
+			}
157
+			$currentObject=array(
158
+				$oid_index,
159
+				$val->oid,
160
+				$val->oid_name_mib,
161
+				$val->oid_name,
162
+				$val->value,
163
+				$currentObjectType,
164
+				$currentObjectTypeEnum
165
+			);
166
+			$oid_index++;
167
+			array_push($this->view->objectList,$currentObject);
168
+			// set currrent object to null in allObjects
169
+			if (isset($allObjects[$val->oid]))
170
+			{
171
+				$allObjects[$val->oid]=null;
172
+			}
173
+		}
174
+		if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
175
+		{
176
+			foreach ($allObjects as $key => $val)
177
+			{
178
+				if ($val==null) { continue; }
179
+				array_push($this->view->objectList, array(
180
+					$oid_index,
181
+					$key,
182
+					$allObjects[$key]['mib'],
183
+					$allObjects[$key]['name'],
184
+					'',
185
+					$allObjects[$key]['type'],
186
+					$allObjects[$key]['type_enum']
187
+				));
188
+				$oid_index++;
189
+			}
190
+		}
192 191
 	    
193
-	    // Add a simple display
194
-	    $this->view->display='Trap '.$trapDetail->trap_name.' received';
195
-	    $this->view->create_basic_rule=true;
192
+		// Add a simple display
193
+		$this->view->display='Trap '.$trapDetail->trap_name.' received';
194
+		$this->view->create_basic_rule=true;
196 195
 	}
197 196
 
198 197
 	/**
@@ -201,29 +200,29 @@  discard block
 block discarded – undo
201 200
 	 */
202 201
 	private function add_check_host_exists($ruleDetail)
203 202
 	{
204
-	    // Check if hostname still exists
205
-	    $host_get=$this->getHostByName($this->view->hostname);
203
+		// Check if hostname still exists
204
+		$host_get=$this->getHostByName($this->view->hostname);
206 205
 	    
207
-	    if (count($host_get)==0)
208
-	    {
209
-	        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
210
-	        $this->view->serviceGet=false;
211
-	    }
212
-	    else
213
-	    {
214
-	        // Tell JS to get services when page is loaded
215
-	        $this->view->serviceGet=true;
216
-	        // get service id for form to set :
217
-	        $serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
218
-	        if (count($serviceID) ==0)
219
-	        {
220
-	            $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
221
-	        }
222
-	        else
223
-	        {
224
-	            $this->view->serviceSet=$serviceID[0]->id;
225
-	        }
226
-	    }
206
+		if (count($host_get)==0)
207
+		{
208
+			$this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
209
+			$this->view->serviceGet=false;
210
+		}
211
+		else
212
+		{
213
+			// Tell JS to get services when page is loaded
214
+			$this->view->serviceGet=true;
215
+			// get service id for form to set :
216
+			$serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
217
+			if (count($serviceID) ==0)
218
+			{
219
+				$this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
220
+			}
221
+			else
222
+			{
223
+				$this->view->serviceSet=$serviceID[0]->id;
224
+			}
225
+		}
227 226
 	}
228 227
 
229 228
 	/**
@@ -232,33 +231,33 @@  discard block
 block discarded – undo
232 231
 	 */
233 232
 	private function add_check_hostgroup_exists($ruleDetail)
234 233
 	{
235
-	    // Check if groupe exists
236
-	    $group_get=$this->getHostGroupByName($this->view->hostgroupname);
237
-	    if (count($group_get)==0)
238
-	    {
239
-	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
240
-	        $this->view->serviceGroupGet=false;
241
-	    }
242
-	    else
243
-	    {
244
-	        $grpServices=$this->getServicesByHostGroupid($group_get[0]->id);
245
-	        $foundGrpService=0;
246
-	        foreach ($grpServices as $grpService)
247
-	        {
248
-	            if ($grpService[0] == $ruleDetail->service_name)
249
-	            {
250
-	                $foundGrpService=1;
251
-	                $this->view->serviceSet=$ruleDetail->service_name;
252
-	            }
253
-	        }
234
+		// Check if groupe exists
235
+		$group_get=$this->getHostGroupByName($this->view->hostgroupname);
236
+		if (count($group_get)==0)
237
+		{
238
+			$this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
239
+			$this->view->serviceGroupGet=false;
240
+		}
241
+		else
242
+		{
243
+			$grpServices=$this->getServicesByHostGroupid($group_get[0]->id);
244
+			$foundGrpService=0;
245
+			foreach ($grpServices as $grpService)
246
+			{
247
+				if ($grpService[0] == $ruleDetail->service_name)
248
+				{
249
+					$foundGrpService=1;
250
+					$this->view->serviceSet=$ruleDetail->service_name;
251
+				}
252
+			}
254 253
 	        
255
-	        // Tell JS to get services when page is loaded
256
-	        $this->view->serviceGroupGet=true;
257
-	        if ($foundGrpService==0)
258
-	        {
259
-	            $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
260
-	        }
261
-	    }
254
+			// Tell JS to get services when page is loaded
255
+			$this->view->serviceGroupGet=true;
256
+			if ($foundGrpService==0)
257
+			{
258
+				$this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
259
+			}
260
+		}
262 261
 	}
263 262
 	
264 263
 	/**
@@ -270,52 +269,52 @@  discard block
 block discarded – undo
270 269
 	 */
271 270
 	private function add_create_trap_object_list(&$display, &$rule)
272 271
 	{
273
-	    $curObjectList=array();
274
-	    $index=1;
275
-	    // check in display & rule for : OID(<oid>)
276
-	    $matches=array();
277
-	    while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) ||
278
-	        preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches))
279
-	    {
280
-	        $curOid=$matches[1];
272
+		$curObjectList=array();
273
+		$index=1;
274
+		// check in display & rule for : OID(<oid>)
275
+		$matches=array();
276
+		while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) ||
277
+			preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches))
278
+		{
279
+			$curOid=$matches[1];
281 280
 	        
282
-	        if ( (preg_match('/\*/',$curOid) == 0 ) 
283
-	            && ($object=$this->getMIB()->translateOID($curOid)) != null)
284
-	        {
285
-	            array_push($curObjectList, array(
286
-	                $index,
287
-	                $curOid,
288
-	                $object['mib'],
289
-	                $object['name'],
290
-	                '',
291
-	                $object['type'],
292
-	                $object['type_enum']
293
-	            ));
294
-	        }
295
-	        else
296
-	        {
297
-	            array_push($curObjectList, array(
298
-	                $index,
299
-	                $curOid,
300
-	                'not found',
301
-	                'not found',
302
-	                '',
303
-	                'not found',
304
-	                'not found'
305
-	            ));
306
-	        }
307
-	        $curOid = preg_replace('/\*/','\*',$curOid);
308
-	        $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
309
-	        $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
310
-	        $index++;
311
-	    }
312
-	    return $curObjectList;
281
+			if ( (preg_match('/\*/',$curOid) == 0 ) 
282
+				&& ($object=$this->getMIB()->translateOID($curOid)) != null)
283
+			{
284
+				array_push($curObjectList, array(
285
+					$index,
286
+					$curOid,
287
+					$object['mib'],
288
+					$object['name'],
289
+					'',
290
+					$object['type'],
291
+					$object['type_enum']
292
+				));
293
+			}
294
+			else
295
+			{
296
+				array_push($curObjectList, array(
297
+					$index,
298
+					$curOid,
299
+					'not found',
300
+					'not found',
301
+					'',
302
+					'not found',
303
+					'not found'
304
+				));
305
+			}
306
+			$curOid = preg_replace('/\*/','\*',$curOid);
307
+			$display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
308
+			$rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
309
+			$index++;
310
+		}
311
+		return $curObjectList;
313 312
 	}
314 313
 	
315 314
 	/** Add a handler  
316
-	*	Get params fromid : setup from existing trap (id of trap table)
317
-	*	Get param ruleid : edit from existing handler (id of rule table)
318
-	*/
315
+	 *	Get params fromid : setup from existing trap (id of trap table)
316
+	 *	Get param ruleid : edit from existing handler (id of rule table)
317
+	 */
319 318
 	public function addAction()
320 319
 	{
321 320
 		$this->checkConfigPermission();
@@ -334,8 +333,8 @@  discard block
 block discarded – undo
334 333
 		//$this->view->trapvalues=false; // Set to true to display 'value' colum in objects
335 334
 		
336 335
 		if (($trapid = $this->params->get('fromid')) !== null) {
337
-		    /********** Setup from existing trap ***************/
338
-            $this->add_from_existing($trapid);
336
+			/********** Setup from existing trap ***************/
337
+			$this->add_from_existing($trapid);
339 338
 			return;
340 339
 		}
341 340
 		
@@ -360,14 +359,14 @@  discard block
 block discarded – undo
360 359
 			$this->view->warning_message='';
361 360
 			if ($this->view->hostname != null)
362 361
 			{
363
-			    $this->view->selectGroup=false;
364
-			    // Check if hostname still exists
365
-			    $this->add_check_host_exists($ruleDetail);
362
+				$this->view->selectGroup=false;
363
+				// Check if hostname still exists
364
+				$this->add_check_host_exists($ruleDetail);
366 365
 			}
367 366
 			else
368 367
 			{
369
-			    $this->view->selectGroup=true;
370
-			    $this->add_check_hostgroup_exists($ruleDetail); //  Check if groupe exists				
368
+				$this->view->selectGroup=true;
369
+				$this->add_check_hostgroup_exists($ruleDetail); //  Check if groupe exists				
371 370
 			}
372 371
 			
373 372
 			$this->view->mainoid=$ruleDetail->trap_oid;
@@ -395,9 +394,9 @@  discard block
 block discarded – undo
395 394
 	}
396 395
 	
397 396
 	/** Validate form and output message to user  
398
-	*	@param in postdata 
399
-	* 	@return string status : OK / <Message>
400
-	**/
397
+	 *	@param in postdata 
398
+	 * 	@return string status : OK / <Message>
399
+	 **/
401 400
 	protected function handlerformAction()
402 401
 	{
403 402
 		$postData=$this->getRequest()->getPost();
@@ -428,7 +427,7 @@  discard block
 block discarded – undo
428 427
 		{
429 428
 			try
430 429
 			{
431
-			    $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]);
430
+				$this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]);
432 431
 			}
433 432
 			catch (Exception $e)
434 433
 			{
@@ -438,7 +437,7 @@  discard block
 block discarded – undo
438 437
 			//$this->Module()->
439 438
 			$this->_helper->json(array(
440 439
 				'status'=>'OK',
441
-			    'redirect'=>'trapdirector/handler'
440
+				'redirect'=>'trapdirector/handler'
442 441
 			      
443 442
 			));
444 443
 		}		
@@ -504,11 +503,11 @@  discard block
 block discarded – undo
504 503
 			// echo '<br>';	print_r($dbparams);echo '<br>';
505 504
 			if ($params['db_rule']['val'] == -1 ) 
506 505
 			{
507
-			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
506
+				$ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
508 507
 			}
509 508
 			else
510 509
 			{
511
-			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
510
+				$this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
512 511
 				$ruleID=$params['db_rule']['val'];
513 512
 			}
514 513
 		}
@@ -522,9 +521,9 @@  discard block
 block discarded – undo
522 521
 	}
523 522
 
524 523
 	/** Get trap detail by trapid. 
525
-	*	@param integer $trapid : id of trap in received table
526
-	*	@return array (objects)
527
-	*/
524
+	 *	@param integer $trapid : id of trap in received table
525
+	 *	@return array (objects)
526
+	 */
528 527
 	protected function getTrapDetail($trapid) 
529 528
 	{
530 529
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -540,14 +539,14 @@  discard block
 block discarded – undo
540 539
 		}
541 540
 		try
542 541
 		{		
543
-		    $query = $dbConn->select()
542
+			$query = $dbConn->select()
544 543
 				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
545 544
 				->where('id=?',$trapid);
546 545
 				$trapDetail=$dbConn->fetchRow($query);
547 546
 			if ( $trapDetail == null ) 
548 547
 			{
549
-			    $trapDetail = 'NULL';
550
-			    throw new Exception('No traps was found with id = '.$trapid);
548
+				$trapDetail = 'NULL';
549
+				throw new Exception('No traps was found with id = '.$trapid);
551 550
 			}
552 551
 		}
553 552
 		catch (Exception $e)
@@ -561,9 +560,9 @@  discard block
 block discarded – undo
561 560
 	}
562 561
 
563 562
 	/** Get trap objects
564
-	*	@param integer $trapid : trap id
565
-	* 	@return array : full column in db of trap id
566
-	*/
563
+	 *	@param integer $trapid : trap id
564
+	 * 	@return array : full column in db of trap id
565
+	 */
567 566
 	protected function getTrapobjects($trapid)
568 567
 	{	
569 568
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -579,7 +578,7 @@  discard block
 block discarded – undo
579 578
 		}
580 579
 		try
581 580
 		{		
582
-		    $query = $dbConn->select()
581
+			$query = $dbConn->select()
583 582
 				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
584 583
 				->where('trap_id=?',$trapid);
585 584
 				$trapDetail=$dbConn->fetchAll($query);
@@ -595,10 +594,10 @@  discard block
 block discarded – undo
595 594
 	}
596 595
 
597 596
 	/** Get rule detail by ruleid.
598
-	*	@param integer $ruleid int id of rule in rule table
599
-	*	@return object : column objects in db 
600
-	*
601
-	*/
597
+	 *	@param integer $ruleid int id of rule in rule table
598
+	 *	@return object : column objects in db 
599
+	 *
600
+	 */
602 601
 	protected function getRuleDetail($ruleid) 
603 602
 	{
604 603
 		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
@@ -609,7 +608,7 @@  discard block
 block discarded – undo
609 608
 		// ***************  Get main data
610 609
 		try
611 610
 		{		
612
-		    $query = $dbConn->select()
611
+			$query = $dbConn->select()
613 612
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
614 613
 				->where('id=?',$ruleid);
615 614
 			$ruleDetail=$dbConn->fetchRow($query);
@@ -626,7 +625,7 @@  discard block
 block discarded – undo
626 625
 	}
627 626
 
628 627
 	/** Setup tabs for rules 
629
-	*/
628
+	 */
630 629
 	protected function prepareTabs()
631 630
 	{
632 631
 		return $this->getTabs()->add('status', array(
Please login to merge, or discard this patch.
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -23,16 +23,16 @@  discard block
 block discarded – undo
23 23
 		$this->checkReadPermission();
24 24
 		$this->prepareTabs()->activate('status');
25 25
 
26
-		$dbConn = $this->getUIDatabase()->getDb();
26
+		$dbConn=$this->getUIDatabase()->getDb();
27 27
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
28 28
 		
29 29
 		$this->getHandlerListTable()->setConnection($dbConn);
30 30
 		$this->getHandlerListTable()->setMibloader($this->getMIB());
31 31
 		// Apply pagination limits 
32
-		$this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(),$this->getModuleConfig()->itemListDisplay());		
32
+		$this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(), $this->getModuleConfig()->itemListDisplay());		
33 33
 		
34 34
 		// Set Filter
35
-		$this->view->filterEditor = $this->getHandlerListTable()->getFilterEditor($this->getRequest());		
35
+		$this->view->filterEditor=$this->getHandlerListTable()->getFilterEditor($this->getRequest());		
36 36
 	
37 37
 		//$this->displayExitError('Handler/indexAction','Not implemented');
38 38
 	}
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	public function testruleAction()
43 43
 	{
44 44
 	    $this->checkReadPermission();
45
-	    $this->getTabs()->add('get',array(
45
+	    $this->getTabs()->add('get', array(
46 46
 	        'active'	=> true,
47 47
 	        'label'		=> $this->translate('Test Rule'),
48 48
 	        'url'		=> Url::fromRequest()
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
 	    if ($this->params->get('rule') !== null) 
53 53
 	    {
54
-	        $this->view->rule= $this->params->get('rule');
54
+	        $this->view->rule=$this->params->get('rule');
55 55
 	    }
56 56
 	    else
57 57
 	    {
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
 	    }
111 111
 	    catch (Exception $e)
112 112
 	    {
113
-	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
113
+	        $this->displayExitError('Add handler : get host by IP/Name ', $e->getMessage());
114 114
 	    }
115 115
 	    
116 116
 	    
117 117
 	    // if one unique host found -> put id text input
118
-	    if (count($hosts)==1) {
118
+	    if (count($hosts) == 1) {
119 119
 	        $this->view->hostname=$hosts[0]->name;
120 120
 	        //$hostid=$hosts[0]->id;
121 121
 	        // Tell JS to get services when page is loaded
@@ -124,9 +124,9 @@  discard block
 block discarded – undo
124 124
 	    }
125 125
 	    else
126 126
 	    {
127
-	        foreach($hosts as $key=>$val)
127
+	        foreach ($hosts as $key=>$val)
128 128
 	        {
129
-	            array_push($this->view->hostlist,$hosts[$key]->name);
129
+	            array_push($this->view->hostlist, $hosts[$key]->name);
130 130
 	        }
131 131
 	    }
132 132
 	    
@@ -165,18 +165,18 @@  discard block
 block discarded – undo
165 165
 	            $currentObjectTypeEnum
166 166
 	        );
167 167
 	        $oid_index++;
168
-	        array_push($this->view->objectList,$currentObject);
168
+	        array_push($this->view->objectList, $currentObject);
169 169
 	        // set currrent object to null in allObjects
170 170
 	        if (isset($allObjects[$val->oid]))
171 171
 	        {
172 172
 	            $allObjects[$val->oid]=null;
173 173
 	        }
174 174
 	    }
175
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
175
+	    if ($allObjects != null) // in case trap doesn't have objects or is not resolved
176 176
 	    {
177 177
 	        foreach ($allObjects as $key => $val)
178 178
 	        {
179
-	            if ($val==null) { continue; }
179
+	            if ($val == null) { continue; }
180 180
 	            array_push($this->view->objectList, array(
181 181
 	                $oid_index,
182 182
 	                $key,
@@ -204,9 +204,9 @@  discard block
 block discarded – undo
204 204
 	    // Check if hostname still exists
205 205
 	    $host_get=$this->getHostByName($this->view->hostname);
206 206
 	    
207
-	    if (count($host_get)==0)
207
+	    if (count($host_get) == 0)
208 208
 	    {
209
-	        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
209
+	        $this->view->warning_message='Host '.$this->view->hostname.' doesn\'t exists anymore';
210 210
 	        $this->view->serviceGet=false;
211 211
 	    }
212 212
 	    else
@@ -214,10 +214,10 @@  discard block
 block discarded – undo
214 214
 	        // Tell JS to get services when page is loaded
215 215
 	        $this->view->serviceGet=true;
216 216
 	        // get service id for form to set :
217
-	        $serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
218
-	        if (count($serviceID) ==0)
217
+	        $serviceID=$this->getServiceIDByName($this->view->hostname, $ruleDetail->service_name);
218
+	        if (count($serviceID) == 0)
219 219
 	        {
220
-	            $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
220
+	            $this->view->warning_message=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore';
221 221
 	        }
222 222
 	        else
223 223
 	        {
@@ -234,9 +234,9 @@  discard block
 block discarded – undo
234 234
 	{
235 235
 	    // Check if groupe exists
236 236
 	    $group_get=$this->getHostGroupByName($this->view->hostgroupname);
237
-	    if (count($group_get)==0)
237
+	    if (count($group_get) == 0)
238 238
 	    {
239
-	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
239
+	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname.' doesn\'t exists anymore';
240 240
 	        $this->view->serviceGroupGet=false;
241 241
 	    }
242 242
 	    else
@@ -254,9 +254,9 @@  discard block
 block discarded – undo
254 254
 	        
255 255
 	        // Tell JS to get services when page is loaded
256 256
 	        $this->view->serviceGroupGet=true;
257
-	        if ($foundGrpService==0)
257
+	        if ($foundGrpService == 0)
258 258
 	        {
259
-	            $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
259
+	            $this->view->warning_message.=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore';
260 260
 	        }
261 261
 	    }
262 262
 	}
@@ -274,12 +274,12 @@  discard block
 block discarded – undo
274 274
 	    $index=1;
275 275
 	    // check in display & rule for : OID(<oid>)
276 276
 	    $matches=array();
277
-	    while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) ||
278
-	        preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches))
277
+	    while (preg_match('/_OID\(([\.0-9\*]+)\)/', $display, $matches) ||
278
+	        preg_match('/_OID\(([\.0-9\*]+)\)/', $rule, $matches))
279 279
 	    {
280 280
 	        $curOid=$matches[1];
281 281
 	        
282
-	        if ( (preg_match('/\*/',$curOid) == 0 ) 
282
+	        if ((preg_match('/\*/', $curOid) == 0) 
283 283
 	            && ($object=$this->getMIB()->translateOID($curOid)) != null)
284 284
 	        {
285 285
 	            array_push($curObjectList, array(
@@ -304,9 +304,9 @@  discard block
 block discarded – undo
304 304
 	                'not found'
305 305
 	            ));
306 306
 	        }
307
-	        $curOid = preg_replace('/\*/','\*',$curOid);
308
-	        $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
309
-	        $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
307
+	        $curOid=preg_replace('/\*/', '\*', $curOid);
308
+	        $display=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $display);
309
+	        $rule=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $rule);
310 310
 	        $index++;
311 311
 	    }
312 312
 	    return $curObjectList;
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 	{
321 321
 		$this->checkConfigPermission();
322 322
 		// set up tab
323
-		$this->getTabs()->add('get',array(
323
+		$this->getTabs()->add('get', array(
324 324
 			'active'	=> true,
325 325
 			'label'		=> $this->translate('Add handler'),
326 326
 			'url'		=> Url::fromRequest()
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 		
334 334
 		//$this->view->trapvalues=false; // Set to true to display 'value' colum in objects
335 335
 		
336
-		if (($trapid = $this->params->get('fromid')) !== null) {
336
+		if (($trapid=$this->params->get('fromid')) !== null) {
337 337
 		    /********** Setup from existing trap ***************/
338 338
             $this->add_from_existing($trapid);
339 339
 			return;
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 			$this->view->setRuleMatch=$ruleDetail->action_match;
354 354
 			$this->view->setRuleNoMatch=$ruleDetail->action_nomatch;
355 355
 			$this->view->hostgroupname=$ruleDetail->host_group_name;
356
-			$this->view->modified=gmdate("Y-m-d\TH:i:s\Z",$ruleDetail->modified);
356
+			$this->view->modified=gmdate("Y-m-d\TH:i:s\Z", $ruleDetail->modified);
357 357
 			$this->view->modifier=$ruleDetail->modifier;
358 358
 			
359 359
 			// Warning message if host/service don't exists anymore
@@ -405,26 +405,26 @@  discard block
 block discarded – undo
405 405
 	
406 406
 		$params=array(
407 407
 			// id (also db) => 	array('post' => post id, 'val' => default val, 'db' => send to table)
408
-			'hostgroup'		=>	array('post' => 'hostgroup','db'=>false),
409
-			'db_rule'		=>	array('post' => 'db_rule','db'=>false),
410
-			'hostid'		=>	array('post' => 'hostid','db'=>false),
411
-			'host_name'		=>	array('post' => 'hostname','val' => null,'db'=>true),
412
-			'host_group_name'=>	array('post' => null,'val' => null,'db'=>true),
413
-			'serviceid'		=>	array('post' => 'serviceid','db'=>false),
414
-			'service_name'	=>	array('post' => 'serviceName','db'=>true),
415
-			'trap_oid'		=>	array('post' => 'oid','db'=>true),
416
-			'revert_ok'		=>	array('post' => 'revertOK','val' => 0,'db'=>true),
417
-			'display'		=>	array('post' => 'display','val' => '','db'=>true),
418
-			'rule'			=>	array('post' => 'rule','val' => '','db'=>true),			
419
-			'action_match'	=>	array('post' => 'ruleMatch','val' => -1,'db'=>true),
420
-			'action_nomatch'=>	array('post' => 'ruleNoMatch','val' => -1,'db'=>true),					
421
-			'ip4'			=>	array('post' => null,'val' => null,'db'=>true),
422
-			'ip6'			=>	array('post' => null,'val' => null,'db'=>true),
423
-			'action_form'	=>	array('post' => 'action_form','db'=>false)
408
+			'hostgroup'		=>	array('post' => 'hostgroup', 'db'=>false),
409
+			'db_rule'		=>	array('post' => 'db_rule', 'db'=>false),
410
+			'hostid'		=>	array('post' => 'hostid', 'db'=>false),
411
+			'host_name'		=>	array('post' => 'hostname', 'val' => null, 'db'=>true),
412
+			'host_group_name'=>	array('post' => null, 'val' => null, 'db'=>true),
413
+			'serviceid'		=>	array('post' => 'serviceid', 'db'=>false),
414
+			'service_name'	=>	array('post' => 'serviceName', 'db'=>true),
415
+			'trap_oid'		=>	array('post' => 'oid', 'db'=>true),
416
+			'revert_ok'		=>	array('post' => 'revertOK', 'val' => 0, 'db'=>true),
417
+			'display'		=>	array('post' => 'display', 'val' => '', 'db'=>true),
418
+			'rule'			=>	array('post' => 'rule', 'val' => '', 'db'=>true),			
419
+			'action_match'	=>	array('post' => 'ruleMatch', 'val' => -1, 'db'=>true),
420
+			'action_nomatch'=>	array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true),					
421
+			'ip4'			=>	array('post' => null, 'val' => null, 'db'=>true),
422
+			'ip6'			=>	array('post' => null, 'val' => null, 'db'=>true),
423
+			'action_form'	=>	array('post' => 'action_form', 'db'=>false)
424 424
 		);
425 425
 		
426 426
 		if (isset($postData[$params['action_form']['post']]) 
427
-			&& $postData[$params['action_form']['post']] == 'delete' )
427
+			&& $postData[$params['action_form']['post']] == 'delete')
428 428
 		{
429 429
 			try
430 430
 			{
@@ -444,16 +444,16 @@  discard block
 block discarded – undo
444 444
 		}		
445 445
 		foreach (array_keys($params) as $key)
446 446
 		{
447
-			if ($params[$key]['post']==null) continue; // data not sent in post vars
448
-			if (! isset($postData[$params[$key]['post']]))
447
+			if ($params[$key]['post'] == null) continue; // data not sent in post vars
448
+			if (!isset($postData[$params[$key]['post']]))
449 449
 			{
450 450
 				// should not happen as the js checks data
451
-				$this->_helper->json(array('status'=>'No ' . $key));
451
+				$this->_helper->json(array('status'=>'No '.$key));
452 452
 			}
453 453
 			else
454 454
 			{
455 455
 				$data=$postData[$params[$key]['post']];
456
-				if ($data!=null && $data !="")
456
+				if ($data != null && $data != "")
457 457
 				{
458 458
 					$params[$key]['val']=$postData[$params[$key]['post']];
459 459
 				}
@@ -462,8 +462,8 @@  discard block
 block discarded – undo
462 462
 
463 463
 		try 
464 464
 		{
465
-			$isHostGroup=($params['hostgroup']['val'] == 1)?true:false;
466
-			if (! $isHostGroup ) 
465
+			$isHostGroup=($params['hostgroup']['val'] == 1) ?true:false;
466
+			if (!$isHostGroup) 
467 467
 			{  // checks if selection by host 
468 468
 				$hostAddr=$this->getHostInfoByID($params['hostid']['val']);
469 469
 				$params['ip4']['val']=$hostAddr->ip4;
@@ -490,25 +490,25 @@  discard block
 block discarded – undo
490 490
 					return;					
491 491
 				}
492 492
 				// Put param in correct column (group_name)
493
-				$params['host_group_name']['val'] = $params['host_name']['val'];
493
+				$params['host_group_name']['val']=$params['host_name']['val'];
494 494
 				$params['host_name']['val']=null;
495 495
 			}
496 496
 			$dbparams=array();
497 497
 			foreach ($params as $key=>$val)
498 498
 			{
499
-				if ($val['db']==true )
499
+				if ($val['db'] == true)
500 500
 				{
501
-					$dbparams[$key] = $val['val'];
501
+					$dbparams[$key]=$val['val'];
502 502
 				}
503 503
 			}
504 504
 			// echo '<br>';	print_r($dbparams);echo '<br>';
505
-			if ($params['db_rule']['val'] == -1 ) 
505
+			if ($params['db_rule']['val'] == -1) 
506 506
 			{
507 507
 			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
508 508
 			}
509 509
 			else
510 510
 			{
511
-			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
511
+			    $this->getUIDatabase()->updateHandlerRule($dbparams, $params['db_rule']['val']);
512 512
 				$ruleID=$params['db_rule']['val'];
513 513
 			}
514 514
 		}
@@ -527,10 +527,10 @@  discard block
 block discarded – undo
527 527
 	*/
528 528
 	protected function getTrapDetail($trapid) 
529 529
 	{
530
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
530
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
531 531
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
532 532
 		
533
-		$dbConn = $this->getUIDatabase()->getDbConn();
533
+		$dbConn=$this->getUIDatabase()->getDbConn();
534 534
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
535 535
 		// ***************  Get main data
536 536
 		// extract columns and titles;
@@ -540,19 +540,19 @@  discard block
 block discarded – undo
540 540
 		}
541 541
 		try
542 542
 		{		
543
-		    $query = $dbConn->select()
544
-				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
545
-				->where('id=?',$trapid);
543
+		    $query=$dbConn->select()
544
+				->from($this->getModuleConfig()->getTrapTableName(), $elmts)
545
+				->where('id=?', $trapid);
546 546
 				$trapDetail=$dbConn->fetchRow($query);
547
-			if ( $trapDetail == null ) 
547
+			if ($trapDetail == null) 
548 548
 			{
549
-			    $trapDetail = 'NULL';
549
+			    $trapDetail='NULL';
550 550
 			    throw new Exception('No traps was found with id = '.$trapid);
551 551
 			}
552 552
 		}
553 553
 		catch (Exception $e)
554 554
 		{
555
-			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
555
+			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail, true), $e->getMessage());
556 556
 			return;
557 557
 		}
558 558
 
@@ -566,10 +566,10 @@  discard block
 block discarded – undo
566 566
 	*/
567 567
 	protected function getTrapobjects($trapid)
568 568
 	{	
569
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
569
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
570 570
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
571 571
 		
572
-		$dbConn = $this->getUIDatabase()->getDbConn();
572
+		$dbConn=$this->getUIDatabase()->getDbConn();
573 573
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
574 574
 		// ***************  Get object data
575 575
 		// extract columns and titles;
@@ -579,15 +579,15 @@  discard block
 block discarded – undo
579 579
 		}
580 580
 		try
581 581
 		{		
582
-		    $query = $dbConn->select()
583
-				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
584
-				->where('trap_id=?',$trapid);
582
+		    $query=$dbConn->select()
583
+				->from($this->moduleConfig->getTrapDataTableName(), $data_elmts)
584
+				->where('trap_id=?', $trapid);
585 585
 				$trapDetail=$dbConn->fetchAll($query);
586 586
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
587 587
 		}
588 588
 		catch (Exception $e)
589 589
 		{
590
-			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
590
+			$this->displayExitError('Add handler : get trap data detail : ', $e->getMessage());
591 591
 			return array();
592 592
 		}
593 593
 
@@ -601,24 +601,24 @@  discard block
 block discarded – undo
601 601
 	*/
602 602
 	protected function getRuleDetail($ruleid) 
603 603
 	{
604
-		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
604
+		if (!preg_match('/^[0-9]+$/', $ruleid)) { throw new Exception('Invalid id'); }
605 605
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
606 606
 		
607
-		$dbConn = $this->getUIDatabase()->getDbConn();
607
+		$dbConn=$this->getUIDatabase()->getDbConn();
608 608
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
609 609
 		// ***************  Get main data
610 610
 		try
611 611
 		{		
612
-		    $query = $dbConn->select()
613
-				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
614
-				->where('id=?',$ruleid);
612
+		    $query=$dbConn->select()
613
+				->from($this->getModuleConfig()->getTrapRuleName(), $queryArray)
614
+				->where('id=?', $ruleid);
615 615
 			$ruleDetail=$dbConn->fetchRow($query);
616
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
616
+			if ($ruleDetail == null) throw new Exception('No rule was found with id = '.$ruleid);
617 617
 		}
618 618
 		catch (Exception $e)
619 619
 		{
620
-			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
621
-			throw new Exception('Error : ',$e->getMessage());
620
+			$this->displayExitError('Update handler : get rule detail', $e->getMessage());
621
+			throw new Exception('Error : ', $e->getMessage());
622 622
 		}
623 623
 
624 624
 		return $ruleDetail;
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
 	{
632 632
 		return $this->getTabs()->add('status', array(
633 633
 			'label' => $this->translate('Traps'),
634
-			'url'   => $this->getModuleConfig()->urlPath() . '/handler')
634
+			'url'   => $this->getModuleConfig()->urlPath().'/handler')
635 635
 		);
636 636
 	} 
637 637
 	
Please login to merge, or discard this patch.
Braces   +44 added lines, -42 removed lines patch added patch discarded remove patch
@@ -24,7 +24,9 @@  discard block
 block discarded – undo
24 24
 		$this->prepareTabs()->activate('status');
25 25
 
26 26
 		$dbConn = $this->getUIDatabase()->getDb();
27
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
27
+		if ($dbConn === null) {
28
+			throw new \ErrorException('uncatched db error');
29
+		}
28 30
 		
29 31
 		$this->getHandlerListTable()->setConnection($dbConn);
30 32
 		$this->getHandlerListTable()->setMibloader($this->getMIB());
@@ -52,8 +54,7 @@  discard block
 block discarded – undo
52 54
 	    if ($this->params->get('rule') !== null) 
53 55
 	    {
54 56
 	        $this->view->rule= $this->params->get('rule');
55
-	    }
56
-	    else
57
+	    } else
57 58
 	    {
58 59
 	        $this->view->rule='';
59 60
 	    }
@@ -107,8 +108,7 @@  discard block
 block discarded – undo
107 108
 	    try
108 109
 	    {
109 110
 	        $hosts=$this->getHostByIP($hostfilter);
110
-	    }
111
-	    catch (Exception $e)
111
+	    } catch (Exception $e)
112 112
 	    {
113 113
 	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
114 114
 	    }
@@ -121,8 +121,7 @@  discard block
 block discarded – undo
121 121
 	        // Tell JS to get services when page is loaded
122 122
 	        $this->view->serviceGet=true;
123 123
 	        
124
-	    }
125
-	    else
124
+	    } else
126 125
 	    {
127 126
 	        foreach($hosts as $key=>$val)
128 127
 	        {
@@ -172,11 +171,14 @@  discard block
 block discarded – undo
172 171
 	            $allObjects[$val->oid]=null;
173 172
 	        }
174 173
 	    }
175
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
174
+	    if ($allObjects!=null) {
175
+	    	// in case trap doesn't have objects or is not resolved
176 176
 	    {
177 177
 	        foreach ($allObjects as $key => $val)
178 178
 	        {
179
-	            if ($val==null) { continue; }
179
+	            if ($val==null) { continue;
180
+	    }
181
+	    }
180 182
 	            array_push($this->view->objectList, array(
181 183
 	                $oid_index,
182 184
 	                $key,
@@ -208,8 +210,7 @@  discard block
 block discarded – undo
208 210
 	    {
209 211
 	        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
210 212
 	        $this->view->serviceGet=false;
211
-	    }
212
-	    else
213
+	    } else
213 214
 	    {
214 215
 	        // Tell JS to get services when page is loaded
215 216
 	        $this->view->serviceGet=true;
@@ -218,8 +219,7 @@  discard block
 block discarded – undo
218 219
 	        if (count($serviceID) ==0)
219 220
 	        {
220 221
 	            $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
221
-	        }
222
-	        else
222
+	        } else
223 223
 	        {
224 224
 	            $this->view->serviceSet=$serviceID[0]->id;
225 225
 	        }
@@ -238,8 +238,7 @@  discard block
 block discarded – undo
238 238
 	    {
239 239
 	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
240 240
 	        $this->view->serviceGroupGet=false;
241
-	    }
242
-	    else
241
+	    } else
243 242
 	    {
244 243
 	        $grpServices=$this->getServicesByHostGroupid($group_get[0]->id);
245 244
 	        $foundGrpService=0;
@@ -291,8 +290,7 @@  discard block
 block discarded – undo
291 290
 	                $object['type'],
292 291
 	                $object['type_enum']
293 292
 	            ));
294
-	        }
295
-	        else
293
+	        } else
296 294
 	        {
297 295
 	            array_push($curObjectList, array(
298 296
 	                $index,
@@ -363,8 +361,7 @@  discard block
 block discarded – undo
363 361
 			    $this->view->selectGroup=false;
364 362
 			    // Check if hostname still exists
365 363
 			    $this->add_check_host_exists($ruleDetail);
366
-			}
367
-			else
364
+			} else
368 365
 			{
369 366
 			    $this->view->selectGroup=true;
370 367
 			    $this->add_check_hostgroup_exists($ruleDetail); //  Check if groupe exists				
@@ -372,9 +369,11 @@  discard block
 block discarded – undo
372 369
 			
373 370
 			$this->view->mainoid=$ruleDetail->trap_oid;
374 371
 			$oidName=$this->getMIB()->translateOID($ruleDetail->trap_oid);
375
-			if ($oidName != null)  // oid is found in mibs
372
+			if ($oidName != null) {
373
+				// oid is found in mibs
376 374
 			{
377
-				$this->view->mib=$oidName['mib']; 
375
+				$this->view->mib=$oidName['mib'];
376
+			}
378 377
 				$this->view->name=$oidName['name'];
379 378
 				$this->view->trapListForMIB=$this->getMIB()
380 379
 					->getTrapList($oidName['mib']);				
@@ -429,8 +428,7 @@  discard block
 block discarded – undo
429 428
 			try
430 429
 			{
431 430
 			    $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]);
432
-			}
433
-			catch (Exception $e)
431
+			} catch (Exception $e)
434 432
 			{
435 433
 				$this->_helper->json(array('status'=>$e->getMessage()));
436 434
 				return;
@@ -444,13 +442,15 @@  discard block
 block discarded – undo
444 442
 		}		
445 443
 		foreach (array_keys($params) as $key)
446 444
 		{
447
-			if ($params[$key]['post']==null) continue; // data not sent in post vars
445
+			if ($params[$key]['post']==null) {
446
+				continue;
447
+			}
448
+			// data not sent in post vars
448 449
 			if (! isset($postData[$params[$key]['post']]))
449 450
 			{
450 451
 				// should not happen as the js checks data
451 452
 				$this->_helper->json(array('status'=>'No ' . $key));
452
-			}
453
-			else
453
+			} else
454 454
 			{
455 455
 				$data=$postData[$params[$key]['post']];
456 456
 				if ($data!=null && $data !="")
@@ -480,8 +480,7 @@  discard block
 block discarded – undo
480 480
 					$this->_helper->json(array('status'=>"Invalid service id : Please re enter service"));
481 481
 					return;
482 482
 				}
483
-			}
484
-			else
483
+			} else
485 484
 			{
486 485
 				$object=$this->getObjectNameByid($params['hostid']['val']);
487 486
 				if ($params['host_name']['val'] != $object->name1)
@@ -505,14 +504,12 @@  discard block
 block discarded – undo
505 504
 			if ($params['db_rule']['val'] == -1 ) 
506 505
 			{
507 506
 			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
508
-			}
509
-			else
507
+			} else
510 508
 			{
511 509
 			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
512 510
 				$ruleID=$params['db_rule']['val'];
513 511
 			}
514
-		}
515
-		catch (Exception $e)
512
+		} catch (Exception $e)
516 513
 		{
517 514
 			$this->_helper->json(array('status'=>$e->getMessage()));
518 515
 			return;
@@ -531,7 +528,9 @@  discard block
 block discarded – undo
531 528
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
532 529
 		
533 530
 		$dbConn = $this->getUIDatabase()->getDbConn();
534
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
531
+		if ($dbConn === null) {
532
+			throw new \ErrorException('uncatched db error');
533
+		}
535 534
 		// ***************  Get main data
536 535
 		// extract columns and titles;
537 536
 		$elmts=NULL;
@@ -549,8 +548,7 @@  discard block
 block discarded – undo
549 548
 			    $trapDetail = 'NULL';
550 549
 			    throw new Exception('No traps was found with id = '.$trapid);
551 550
 			}
552
-		}
553
-		catch (Exception $e)
551
+		} catch (Exception $e)
554 552
 		{
555 553
 			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
556 554
 			return;
@@ -570,7 +568,9 @@  discard block
 block discarded – undo
570 568
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
571 569
 		
572 570
 		$dbConn = $this->getUIDatabase()->getDbConn();
573
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
571
+		if ($dbConn === null) {
572
+			throw new \ErrorException('uncatched db error');
573
+		}
574 574
 		// ***************  Get object data
575 575
 		// extract columns and titles;
576 576
 		$data_elmts=NULL;
@@ -584,8 +584,7 @@  discard block
 block discarded – undo
584 584
 				->where('trap_id=?',$trapid);
585 585
 				$trapDetail=$dbConn->fetchAll($query);
586 586
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
587
-		}
588
-		catch (Exception $e)
587
+		} catch (Exception $e)
589 588
 		{
590 589
 			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
591 590
 			return array();
@@ -605,7 +604,9 @@  discard block
 block discarded – undo
605 604
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
606 605
 		
607 606
 		$dbConn = $this->getUIDatabase()->getDbConn();
608
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
607
+		if ($dbConn === null) {
608
+			throw new \ErrorException('uncatched db error');
609
+		}
609 610
 		// ***************  Get main data
610 611
 		try
611 612
 		{		
@@ -613,9 +614,10 @@  discard block
 block discarded – undo
613 614
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
614 615
 				->where('id=?',$ruleid);
615 616
 			$ruleDetail=$dbConn->fetchRow($query);
616
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
617
-		}
618
-		catch (Exception $e)
617
+			if ( $ruleDetail == null ) {
618
+				throw new Exception('No rule was found with id = '.$ruleid);
619
+			}
620
+		} catch (Exception $e)
619 621
 		{
620 622
 			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
621 623
 			throw new Exception('Error : ',$e->getMessage());
Please login to merge, or discard this patch.
application/controllers/StatusController.php 2 patches
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
 		/************  Trapdb ***********/
22 22
 		try
23 23
 		{
24
-		    $dbConn = $this->getUIDatabase()->getDbConn();
25
-		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
24
+			$dbConn = $this->getUIDatabase()->getDbConn();
25
+			if ($dbConn === null) throw new \ErrorException('uncatched db error');
26 26
 			$query = $dbConn->select()->from(
27 27
 				$this->getModuleConfig()->getTrapTableName(),
28 28
 				array('COUNT(*)')
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 		
52 52
 		try
53 53
 		{		
54
-		    $this->view->currentLogDestination=$this->getUIDatabase()->getDBConfigValue('log_destination');
54
+			$this->view->currentLogDestination=$this->getUIDatabase()->getDBConfigValue('log_destination');
55 55
 			$this->view->logDestinations=$this->getModuleConfig()->getLogDestinations();
56 56
 			$this->view->currentLogFile=$this->getUIDatabase()->getDBConfigValue('log_file');
57 57
 			$this->view->logLevels=$this->getModuleConfig()->getlogLevels();
@@ -65,10 +65,10 @@  discard block
 block discarded – undo
65 65
 	} 
66 66
   
67 67
 	/** Mib management
68
-	*	Post param : action=update_mib_db : update mib database
69
-	*	Post param : ation=check_update : check if mib update is finished
70
-	*	File post : mibfile -> save mib file
71
-	*/
68
+	 *	Post param : action=update_mib_db : update mib database
69
+	 *	Post param : ation=check_update : check if mib update is finished
70
+	 *	File post : mibfile -> save mib file
71
+	 */
72 72
 	public function mibAction()
73 73
 	{
74 74
 		$this->prepareTabs()->activate('mib');
@@ -87,22 +87,22 @@  discard block
 block discarded – undo
87 87
 					$return=exec('icingacli trapdirector mib update --pid /tmp/trapdirector_update.pid');
88 88
 					if (preg_match('/OK/',$return))
89 89
 					{
90
-					    $this->_helper->json(array('status'=>'OK'));
90
+						$this->_helper->json(array('status'=>'OK'));
91 91
 					}
92 92
 					// Error
93 93
 					$this->_helper->json(array('status'=>$return));
94 94
 				}
95 95
 				if ($action == 'check_update')
96 96
 				{
97
-				    $file=@fopen('/tmp/trapdirector_update.pid','r');
98
-				    if ($file == false)
99
-				    {   // process is dead
100
-				        $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file'));
101
-				        return;
102
-				    }
103
-				    $pid=fgets($file);
104
-				    $output=array();
105
-				    $retVal=0;
97
+					$file=@fopen('/tmp/trapdirector_update.pid','r');
98
+					if ($file == false)
99
+					{   // process is dead
100
+						$this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file'));
101
+						return;
102
+					}
103
+					$pid=fgets($file);
104
+					$output=array();
105
+					$retVal=0;
106 106
 					exec('ps '.$pid,$output,$retVal);
107 107
 					if ($retVal == 0)
108 108
 					{ // process is alive
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 					}
111 111
 					else
112 112
 					{ // process is dead
113
-					    $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid));
113
+						$this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid));
114 114
 					}
115 115
 				}
116 116
 				$this->_helper->json(array('status'=>'ERR : no '.$action.' action possible' ));
@@ -118,32 +118,32 @@  discard block
 block discarded – undo
118 118
 			/** Check for mib file UPLOAD */
119 119
 			if (isset($_FILES['mibfile']))
120 120
 			{
121
-			    $name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING);
121
+				$name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING);
122 122
 				$DirConf=explode(':',$this->Config()->get('config', 'snmptranslate_dirs'));
123 123
 				$destDir=array_shift($DirConf);
124 124
 				if (!is_dir($destDir))
125 125
 				{
126
-				    $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration";
126
+					$this->view->uploadStatus="ERROR : no $destDir directory, check module configuration";
127 127
 				}
128 128
 				else
129 129
 				{
130
-				    if (!is_writable($destDir))
131
-				    {
132
-				        $this->view->uploadStatus="ERROR : $destDir directory is not writable";
133
-				    }
134
-				    else
135
-				    {
136
-				        $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name";
137
-				        $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING);
138
-				        if (move_uploaded_file($sourceTmpNam,$destination)===false)
139
-    				    {
140
-    				        $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations";
141
-    				    }
142
-    				    else
143
-    				    {
144
-    				        $this->view->uploadStatus="File $name uploaded in $destDir";
145
-    				    }
146
-				    }
130
+					if (!is_writable($destDir))
131
+					{
132
+						$this->view->uploadStatus="ERROR : $destDir directory is not writable";
133
+					}
134
+					else
135
+					{
136
+						$destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name";
137
+						$sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING);
138
+						if (move_uploaded_file($sourceTmpNam,$destination)===false)
139
+						{
140
+							$this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations";
141
+						}
142
+						else
143
+						{
144
+							$this->view->uploadStatus="File $name uploaded in $destDir";
145
+						}
146
+					}
147 147
 				}
148 148
 
149 149
 			}
@@ -263,47 +263,47 @@  discard block
 block discarded – undo
263 263
 	 */
264 264
 	public function pluginsAction()
265 265
 	{
266
-	    $this->prepareTabs()->activate('plugins');
266
+		$this->prepareTabs()->activate('plugins');
267 267
 	    
268
-	    require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
269
-	    $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
270
-	    $Trap = new Trap($icingaweb2_etc,4);
268
+		require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
269
+		$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
270
+		$Trap = new Trap($icingaweb2_etc,4);
271 271
 	    
272
-	    $this->view->pluginLoaded = htmlentities($Trap->pluginClass->registerAllPlugins(false));
272
+		$this->view->pluginLoaded = htmlentities($Trap->pluginClass->registerAllPlugins(false));
273 273
 	    
274
-	    $enabledPlugins = $Trap->pluginClass->getEnabledPlugins();
274
+		$enabledPlugins = $Trap->pluginClass->getEnabledPlugins();
275 275
 
276
-	    $pluginList = $Trap->pluginClass->pluginList();
276
+		$pluginList = $Trap->pluginClass->pluginList();
277 277
 	    
278
-	    // Plugin list and fill function name list
279
-	    $functionList=array();
280
-	    $this->view->pluginArray=array();
281
-	    foreach ($pluginList as $plugin)
282
-	    {
283
-	        $pluginDetails=$Trap->pluginClass->pluginDetails($plugin);
284
-	        $pluginDetails->enabled =  (in_array($plugin, $enabledPlugins)) ? true : false;
285
-	        $pluginDetails->catchAllTraps = ($pluginDetails->catchAllTraps === true )? 'Yes' : 'No';
286
-	        $pluginDetails->processTraps = ($pluginDetails->processTraps === true )? 'Yes' : 'No';
287
-	        $pluginDetails->description = htmlentities($pluginDetails->description);
288
-	        $pluginDetails->description = preg_replace('/\n/','<br>',$pluginDetails->description);
289
-	        array_push($this->view->pluginArray, $pluginDetails);
290
-	        // Get functions for function details
291
-	        foreach ($pluginDetails->funcArray as $function)
292
-	        {
293
-	            array_push($functionList,$function);
294
-	        }
295
-	    }
278
+		// Plugin list and fill function name list
279
+		$functionList=array();
280
+		$this->view->pluginArray=array();
281
+		foreach ($pluginList as $plugin)
282
+		{
283
+			$pluginDetails=$Trap->pluginClass->pluginDetails($plugin);
284
+			$pluginDetails->enabled =  (in_array($plugin, $enabledPlugins)) ? true : false;
285
+			$pluginDetails->catchAllTraps = ($pluginDetails->catchAllTraps === true )? 'Yes' : 'No';
286
+			$pluginDetails->processTraps = ($pluginDetails->processTraps === true )? 'Yes' : 'No';
287
+			$pluginDetails->description = htmlentities($pluginDetails->description);
288
+			$pluginDetails->description = preg_replace('/\n/','<br>',$pluginDetails->description);
289
+			array_push($this->view->pluginArray, $pluginDetails);
290
+			// Get functions for function details
291
+			foreach ($pluginDetails->funcArray as $function)
292
+			{
293
+				array_push($functionList,$function);
294
+			}
295
+		}
296 296
 	    
297
-	    // Function list with details
298
-	    $this->view->functionList=array();
299
-	    foreach ($functionList as $function)
300
-	    {
301
-	        $functionDetail = $Trap->pluginClass->getFunctionDetails($function);
302
-	        $functionDetail->params = htmlentities($functionDetail->params);
303
-	        $functionDetail->description = htmlentities($functionDetail->description);
304
-	        $functionDetail->description = preg_replace('/\n/','<br>',$functionDetail->description);
305
-	        array_push($this->view->functionList, $functionDetail);
306
-	    }
297
+		// Function list with details
298
+		$this->view->functionList=array();
299
+		foreach ($functionList as $function)
300
+		{
301
+			$functionDetail = $Trap->pluginClass->getFunctionDetails($function);
302
+			$functionDetail->params = htmlentities($functionDetail->params);
303
+			$functionDetail->description = htmlentities($functionDetail->description);
304
+			$functionDetail->description = preg_replace('/\n/','<br>',$functionDetail->description);
305
+			array_push($this->view->functionList, $functionDetail);
306
+		}
307 307
 
308 308
 	}
309 309
 	
@@ -318,30 +318,30 @@  discard block
 block discarded – undo
318 318
 		)->add('services', array(
319 319
 			'label' => $this->translate('Services management'),
320 320
 			'url'   => $this->getModuleConfig()->urlPath() . '/status/services')
321
-	    )->add('plugins', array(
322
-	        'label' => $this->translate('Plugins management'),
323
-	        'url'   => $this->getModuleConfig()->urlPath() . '/status/plugins')
324
-	    );
321
+		)->add('plugins', array(
322
+			'label' => $this->translate('Plugins management'),
323
+			'url'   => $this->getModuleConfig()->urlPath() . '/status/plugins')
324
+		);
325 325
 	} 
326 326
 }
327 327
 
328 328
 // TODO : see if useless 
329 329
 class UploadForm extends Form
330 330
 { 
331
-    public function __construct($options = null) 
332
-    {
333
-        parent::__construct($options);
334
-        $this->addElements2();
335
-    }
331
+	public function __construct($options = null) 
332
+	{
333
+		parent::__construct($options);
334
+		$this->addElements2();
335
+	}
336 336
 
337
-    public function addElements2()
338
-    {
339
-        // File Input
340
-        $file = new File('mib-file');
341
-        $file->setLabel('Mib upload');
342
-             //->setAttrib('multiple', null);
343
-        $this->addElement($file);
337
+	public function addElements2()
338
+	{
339
+		// File Input
340
+		$file = new File('mib-file');
341
+		$file->setLabel('Mib upload');
342
+			 //->setAttrib('multiple', null);
343
+		$this->addElement($file);
344 344
 		$button = new Submit("upload",array('ignore'=>false));
345 345
 		$this->addElement($button);//->setIgnore(false);
346
-    }
346
+	}
347 347
 }
Please login to merge, or discard this patch.
Braces   +13 added lines, -21 removed lines patch added patch discarded remove patch
@@ -22,7 +22,9 @@  discard block
 block discarded – undo
22 22
 		try
23 23
 		{
24 24
 		    $dbConn = $this->getUIDatabase()->getDbConn();
25
-		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
25
+		    if ($dbConn === null) {
26
+		    	throw new \ErrorException('uncatched db error');
27
+		    }
26 28
 			$query = $dbConn->select()->from(
27 29
 				$this->getModuleConfig()->getTrapTableName(),
28 30
 				array('COUNT(*)')
@@ -41,8 +43,7 @@  discard block
 block discarded – undo
41 43
  			
42 44
 			$this->view->trap_days_delete=$this->getUIDatabase()->getDBConfigValue('db_remove_days');
43 45
 			
44
-		}
45
-		catch (Exception $e)
46
+		} catch (Exception $e)
46 47
 		{
47 48
 			$this->displayExitError('status',$e->getMessage());
48 49
 		}
@@ -56,8 +57,7 @@  discard block
 block discarded – undo
56 57
 			$this->view->currentLogFile=$this->getUIDatabase()->getDBConfigValue('log_file');
57 58
 			$this->view->logLevels=$this->getModuleConfig()->getlogLevels();
58 59
 			$this->view->currentLogLevel=$this->getUIDatabase()->getDBConfigValue('log_level');
59
-		}
60
-		catch (Exception $e)
60
+		} catch (Exception $e)
61 61
 		{
62 62
 			$this->displayExitError('status',$e->getMessage());
63 63
 		}		
@@ -107,8 +107,7 @@  discard block
 block discarded – undo
107 107
 					if ($retVal == 0)
108 108
 					{ // process is alive
109 109
 						$this->_helper->json(array('status'=>'Alive and kicking'));
110
-					}
111
-					else
110
+					} else
112 111
 					{ // process is dead
113 112
 					    $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid));
114 113
 					}
@@ -124,22 +123,19 @@  discard block
 block discarded – undo
124 123
 				if (!is_dir($destDir))
125 124
 				{
126 125
 				    $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration";
127
-				}
128
-				else
126
+				} else
129 127
 				{
130 128
 				    if (!is_writable($destDir))
131 129
 				    {
132 130
 				        $this->view->uploadStatus="ERROR : $destDir directory is not writable";
133
-				    }
134
-				    else
131
+				    } else
135 132
 				    {
136 133
 				        $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name";
137 134
 				        $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING);
138 135
 				        if (move_uploaded_file($sourceTmpNam,$destination)===false)
139 136
     				    {
140 137
     				        $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations";
141
-    				    }
142
-    				    else
138
+    				    } else
143 139
     				    {
144 140
     				        $this->view->uploadStatus="File $name uploaded in $destDir";
145 141
     				    }
@@ -161,13 +157,11 @@  discard block
 block discarded – undo
161 157
 			{
162 158
 				$this->view->snmptranslate='works fine';
163 159
 				$this->view->snmptranslate_state='ok';
164
-			}
165
-			else
160
+			} else
166 161
 			{
167 162
 				$this->view->snmptranslate='can execute but no resolution';
168 163
 			}
169
-		}
170
-		else
164
+		} else
171 165
 		{
172 166
 			$this->view->snmptranslate='cannot execute';
173 167
 		}
@@ -188,15 +182,13 @@  discard block
 block discarded – undo
188 182
 		if ($retVal==0)
189 183
 		{
190 184
 			$dirArray=array_merge($dirArray,explode(':',$sysDirs));
191
-		}
192
-		else
185
+		} else
193 186
 		{
194 187
 			$translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS');
195 188
 			if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches))
196 189
 			{
197 190
 				$dirArray=array_merge($dirArray,explode(':',$matches[1]));
198
-			}
199
-			else
191
+			} else
200 192
 			{
201 193
 				array_push($dirArray,'Install net-snmp-config to see system directories');
202 194
 			}
Please login to merge, or discard this patch.
application/controllers/ReceivedController.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
 	}
41 41
 
42 42
 	/** 
43
-	*	Trap detail page
44
-	*/	
43
+	 *	Trap detail page
44
+	 */	
45 45
 	public function trapdetailAction() 
46 46
 	{
47 47
 		
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 		// Do DB query for trap. 
75 75
 		try
76 76
 		{
77
-		    $query = $dbConn->select()
77
+			$query = $dbConn->select()
78 78
 				->from($this->moduleConfig->getTrapTableName(),$elmts)
79 79
 				->where('id=?',$trapid);
80 80
 				$trapDetail=$dbConn->fetchRow($query);
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 		}
108 108
 		try
109 109
 		{		
110
-		    $query = $dbConn->select()
110
+			$query = $dbConn->select()
111 111
 				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
112 112
 				->where('trap_id=?',$trapid);
113 113
 			$trapDetail=$dbConn->fetchAll($query);
@@ -144,24 +144,24 @@  discard block
 block discarded – undo
144 144
 	 */
145 145
 	public function hostsAction()
146 146
 	{
147
-	    $this->checkReadPermission();
148
-	    $this->prepareTabs()->activate('hosts');
147
+		$this->checkReadPermission();
148
+		$this->prepareTabs()->activate('hosts');
149 149
 	    
150
-	    $dbConn = $this->getUIDatabase()->getDb();
151
-	    if ($dbConn === null) throw new \ErrorException('uncatched db error');
150
+		$dbConn = $this->getUIDatabase()->getDb();
151
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
152 152
 	    
153
-	    $this->getTrapHostListTable()->setConnection($dbConn);
153
+		$this->getTrapHostListTable()->setConnection($dbConn);
154 154
 	    
155
-	    // Apply pagination limits
156
-	    $this->view->table=$this->applyPaginationLimits($this->getTrapHostListTable(),$this->getModuleConfig()->itemListDisplay());
155
+		// Apply pagination limits
156
+		$this->view->table=$this->applyPaginationLimits($this->getTrapHostListTable(),$this->getModuleConfig()->itemListDisplay());
157 157
 	    
158
-	    // Set Filter
159
-	    //$postData=$this->getRequest()->getPost();
160
-	    $filter=array();
161
-	    $filter['q']=$this->params->get('q');//(isset($postData['q']))?$postData['q']:'';
162
-	    $filter['done']=$this->params->get('done');
163
-	    $this->view->filter=$filter;
164
-	    $this->view->table->updateFilter(Url::fromRequest(),$filter);
158
+		// Set Filter
159
+		//$postData=$this->getRequest()->getPost();
160
+		$filter=array();
161
+		$filter['q']=$this->params->get('q');//(isset($postData['q']))?$postData['q']:'';
162
+		$filter['done']=$this->params->get('done');
163
+		$this->view->filter=$filter;
164
+		$this->view->table->updateFilter(Url::fromRequest(),$filter);
165 165
 	}
166 166
 	
167 167
 	public function deleteAction()
@@ -181,12 +181,12 @@  discard block
 block discarded – undo
181 181
 		return $this->getTabs()->add('traps', array(
182 182
 			'label'	=> $this->translate('Traps'),
183 183
 			'url'   => $this->getModuleConfig()->urlPath() . '/received')
184
-		    )
185
-		    ->add('hosts', array(
186
-		        'label' => $this->translate('Hosts'),
187
-		        'url'   => $this->getModuleConfig()->urlPath() . '/received/hosts')
188
-		    )
189
-		    ->add('delete', array(
184
+			)
185
+			->add('hosts', array(
186
+				'label' => $this->translate('Hosts'),
187
+				'url'   => $this->getModuleConfig()->urlPath() . '/received/hosts')
188
+			)
189
+			->add('delete', array(
190 190
 			'label' => $this->translate('Delete'),
191 191
 			'url'   => $this->getModuleConfig()->urlPath() . '/received/delete')
192 192
 		  );
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 		}
223 223
 		if ($action =="delete")
224 224
 		{
225
-		    $this->_helper->json(array('status'=>'OK','count'=>$this->getUIDatabase()->deleteTrap($ip,$oid)));
225
+			$this->_helper->json(array('status'=>'OK','count'=>$this->getUIDatabase()->deleteTrap($ip,$oid)));
226 226
 			return;
227 227
 		}		
228 228
 		$this->_helper->json(array('status'=>'unknown action'));
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -20,20 +20,20 @@  discard block
 block discarded – undo
20 20
 		$this->checkReadPermission();
21 21
 		$this->prepareTabs()->activate('traps');
22 22
 
23
-		$dbConn = $this->getUIDatabase()->getDb();
23
+		$dbConn=$this->getUIDatabase()->getDb();
24 24
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
25 25
 		$this->getTrapListTable()->setConnection($dbConn);
26 26
 		
27 27
 		// Apply pagination limits
28
-		$this->view->table=$this->applyPaginationLimits($this->getTrapListTable(),$this->getModuleConfig()->itemListDisplay());		
28
+		$this->view->table=$this->applyPaginationLimits($this->getTrapListTable(), $this->getModuleConfig()->itemListDisplay());		
29 29
 		
30 30
 		// Set Filter
31 31
 		//$postData=$this->getRequest()->getPost();
32 32
 		$filter=array();
33
-		$filter['q']=$this->params->get('q');//(isset($postData['q']))?$postData['q']:'';
33
+		$filter['q']=$this->params->get('q'); //(isset($postData['q']))?$postData['q']:'';
34 34
 		$filter['done']=$this->params->get('done');
35 35
 		$this->view->filter=$filter;
36
-		$this->view->table->updateFilter(Url::fromRequest(),$filter);
36
+		$this->view->table->updateFilter(Url::fromRequest(), $filter);
37 37
 		
38 38
 		//$this->view->filterEditor = $this->getTrapListTable()->getFilterEditor($this->getRequest());
39 39
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 		
48 48
 		$this->checkReadPermission();
49 49
 		// set up tab
50
-		$this->getTabs()->add('get',array(
50
+		$this->getTabs()->add('get', array(
51 51
 			'active'	=> true,
52 52
 			'label'		=> $this->translate('Detailed status'),
53 53
 			'url'		=> Url::fromRequest()
@@ -57,12 +57,12 @@  discard block
 block discarded – undo
57 57
 		$this->view->trapid=$trapid;
58 58
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
59 59
 		
60
-		$dbConn = $this->getUIDatabase()->getDbConn();
60
+		$dbConn=$this->getUIDatabase()->getDbConn();
61 61
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
62 62
 		
63 63
 		// URL to add a handler
64 64
 		$this->view->addHandlerUrl=Url::fromPath(
65
-			$this->getModuleConfig()->urlPath() . '/handler/add',
65
+			$this->getModuleConfig()->urlPath().'/handler/add',
66 66
 			array('fromid' => $trapid));
67 67
 		// ***************  Get main data
68 68
 		// extract columns and titles;
@@ -74,28 +74,28 @@  discard block
 block discarded – undo
74 74
 		// Do DB query for trap. 
75 75
 		try
76 76
 		{
77
-		    $query = $dbConn->select()
78
-				->from($this->moduleConfig->getTrapTableName(),$elmts)
79
-				->where('id=?',$trapid);
77
+		    $query=$dbConn->select()
78
+				->from($this->moduleConfig->getTrapTableName(), $elmts)
79
+				->where('id=?', $trapid);
80 80
 				$trapDetail=$dbConn->fetchRow($query);
81
-			if ( $trapDetail == null) throw new Exception('No traps was found with id = '.$trapid);
81
+			if ($trapDetail == null) throw new Exception('No traps was found with id = '.$trapid);
82 82
 		}
83 83
 		catch (Exception $e)
84 84
 		{
85
-			$this->displayExitError('Trap detail',$e->getMessage());
85
+			$this->displayExitError('Trap detail', $e->getMessage());
86 86
 			return;
87 87
 		}
88 88
 
89 89
 		// Store result in array (with Titles).
90 90
 		foreach ($queryArray as $key => $val) {
91 91
 			if ($key == 'timestamp') {
92
-				$cval=strftime('%c',$trapDetail->$key);
92
+				$cval=strftime('%c', $trapDetail->$key);
93 93
 			} else {
94 94
 				$cval=$trapDetail->$key;
95 95
 			}
96
-			array_push($queryArray[$key],$cval);
96
+			array_push($queryArray[$key], $cval);
97 97
 		}
98
-		$this->view->rowset = $queryArray;
98
+		$this->view->rowset=$queryArray;
99 99
 
100 100
 		// **************   Check for additionnal data
101 101
 		
@@ -107,17 +107,17 @@  discard block
 block discarded – undo
107 107
 		}
108 108
 		try
109 109
 		{		
110
-		    $query = $dbConn->select()
111
-				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
112
-				->where('trap_id=?',$trapid);
110
+		    $query=$dbConn->select()
111
+				->from($this->moduleConfig->getTrapDataTableName(), $data_elmts)
112
+				->where('trap_id=?', $trapid);
113 113
 			$trapDetail=$dbConn->fetchAll($query);
114 114
 		}
115 115
 		catch (Exception $e)
116 116
 		{
117
-			$this->displayExitError('Trap detail',$e->getMessage());
117
+			$this->displayExitError('Trap detail', $e->getMessage());
118 118
 		}
119 119
 		// TODO : code this in a better & simpler way
120
-		if ($trapDetail == null ) 
120
+		if ($trapDetail == null) 
121 121
 		{
122 122
 			$this->view->data=false;
123 123
 		}
@@ -129,9 +129,9 @@  discard block
 block discarded – undo
129 129
 			foreach ($trapDetail as $key => $val) 
130 130
 			{	
131 131
 				$trapval[$key]=array();
132
-				foreach (array_keys($queryArrayData) as $vkey ) 
132
+				foreach (array_keys($queryArrayData) as $vkey) 
133 133
 				{
134
-					array_push($trapval[$key],$val->$vkey);
134
+					array_push($trapval[$key], $val->$vkey);
135 135
 				}
136 136
 			}
137 137
 			$this->view->data_val=$trapval;
@@ -147,21 +147,21 @@  discard block
 block discarded – undo
147 147
 	    $this->checkReadPermission();
148 148
 	    $this->prepareTabs()->activate('hosts');
149 149
 	    
150
-	    $dbConn = $this->getUIDatabase()->getDb();
150
+	    $dbConn=$this->getUIDatabase()->getDb();
151 151
 	    if ($dbConn === null) throw new \ErrorException('uncatched db error');
152 152
 	    
153 153
 	    $this->getTrapHostListTable()->setConnection($dbConn);
154 154
 	    
155 155
 	    // Apply pagination limits
156
-	    $this->view->table=$this->applyPaginationLimits($this->getTrapHostListTable(),$this->getModuleConfig()->itemListDisplay());
156
+	    $this->view->table=$this->applyPaginationLimits($this->getTrapHostListTable(), $this->getModuleConfig()->itemListDisplay());
157 157
 	    
158 158
 	    // Set Filter
159 159
 	    //$postData=$this->getRequest()->getPost();
160 160
 	    $filter=array();
161
-	    $filter['q']=$this->params->get('q');//(isset($postData['q']))?$postData['q']:'';
161
+	    $filter['q']=$this->params->get('q'); //(isset($postData['q']))?$postData['q']:'';
162 162
 	    $filter['done']=$this->params->get('done');
163 163
 	    $this->view->filter=$filter;
164
-	    $this->view->table->updateFilter(Url::fromRequest(),$filter);
164
+	    $this->view->table->updateFilter(Url::fromRequest(), $filter);
165 165
 	}
166 166
 	
167 167
 	public function deleteAction()
@@ -180,15 +180,15 @@  discard block
 block discarded – undo
180 180
 	{
181 181
 		return $this->getTabs()->add('traps', array(
182 182
 			'label'	=> $this->translate('Traps'),
183
-			'url'   => $this->getModuleConfig()->urlPath() . '/received')
183
+			'url'   => $this->getModuleConfig()->urlPath().'/received')
184 184
 		    )
185 185
 		    ->add('hosts', array(
186 186
 		        'label' => $this->translate('Hosts'),
187
-		        'url'   => $this->getModuleConfig()->urlPath() . '/received/hosts')
187
+		        'url'   => $this->getModuleConfig()->urlPath().'/received/hosts')
188 188
 		    )
189 189
 		    ->add('delete', array(
190 190
 			'label' => $this->translate('Delete'),
191
-			'url'   => $this->getModuleConfig()->urlPath() . '/received/delete')
191
+			'url'   => $this->getModuleConfig()->urlPath().'/received/delete')
192 192
 		  );
193 193
 	} 
194 194
 
@@ -215,14 +215,14 @@  discard block
 block discarded – undo
215 215
 			$this->_helper->json(array('status'=>'Missing variables'));
216 216
 			return;
217 217
 		}
218
-		if ($action =="count")
218
+		if ($action == "count")
219 219
 		{
220
-			$this->_helper->json(array('status'=>'OK','count'=>$this->getUIDatabase()->countTrap($ip,$oid)));
220
+			$this->_helper->json(array('status'=>'OK', 'count'=>$this->getUIDatabase()->countTrap($ip, $oid)));
221 221
 			return;
222 222
 		}
223
-		if ($action =="delete")
223
+		if ($action == "delete")
224 224
 		{
225
-		    $this->_helper->json(array('status'=>'OK','count'=>$this->getUIDatabase()->deleteTrap($ip,$oid)));
225
+		    $this->_helper->json(array('status'=>'OK', 'count'=>$this->getUIDatabase()->deleteTrap($ip, $oid)));
226 226
 			return;
227 227
 		}		
228 228
 		$this->_helper->json(array('status'=>'unknown action'));
Please login to merge, or discard this patch.
library/Trapdirector/TrapsController.php 3 patches
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	
44 44
 	
45 45
 	/** Get instance of TrapModuleConfig class
46
-	*	@return TrapModuleConfig
47
-	*/
46
+	 *	@return TrapModuleConfig
47
+	 */
48 48
 	public function getModuleConfig() 
49 49
 	{
50 50
 		if ($this->moduleConfig == Null) 
@@ -76,12 +76,12 @@  discard block
 block discarded – undo
76 76
 	 */
77 77
 	public function getTrapHostListTable()
78 78
 	{
79
-	    if ($this->trapTableHostList == Null) 
79
+		if ($this->trapTableHostList == Null) 
80 80
 		{
81
-	        $this->trapTableHostList = new TrapTableHostList();
82
-	        $this->trapTableHostList->setConfig($this->getModuleConfig());
83
-	    }
84
-	    return $this->trapTableHostList;
81
+			$this->trapTableHostList = new TrapTableHostList();
82
+			$this->trapTableHostList->setConfig($this->getModuleConfig());
83
+		}
84
+		return $this->trapTableHostList;
85 85
 	}
86 86
 	
87 87
 	/**
@@ -102,23 +102,23 @@  discard block
 block discarded – undo
102 102
 	 */
103 103
 	public function getUIDatabase()
104 104
 	{
105
-	    if ($this->UIDatabase == Null)
106
-	    {
107
-	        $this->UIDatabase = new UIDatabase($this);
105
+		if ($this->UIDatabase == Null)
106
+		{
107
+			$this->UIDatabase = new UIDatabase($this);
108 108
 	       
109
-	    }
110
-	    return $this->UIDatabase;
109
+		}
110
+		return $this->UIDatabase;
111 111
 	}
112 112
 	
113
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
114
-    {
115
-        $limit = $this->params->get('limit', $limit);
116
-        $page = $this->params->get('page', $offset);
113
+	protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
114
+	{
115
+		$limit = $this->params->get('limit', $limit);
116
+		$page = $this->params->get('page', $offset);
117 117
 
118
-        $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
118
+		$paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
119 119
 
120
-        return $paginatable;
121
-    }	
120
+		return $paginatable;
121
+	}	
122 122
 	
123 123
 	public function displayExitError($source,$message)
124 124
 	{	// TODO : check better ways to transmit data (with POST ?)
@@ -127,33 +127,33 @@  discard block
 block discarded – undo
127 127
 	
128 128
 	protected function checkReadPermission()
129 129
 	{
130
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
131
-            $this->displayExitError('Permissions','No permission fo view content');
132
-        }		
130
+		if (! $this->Auth()->hasPermission('trapdirector/view')) {
131
+			$this->displayExitError('Permissions','No permission fo view content');
132
+		}		
133 133
 	}
134 134
 
135 135
 	protected function checkConfigPermission()
136 136
 	{
137
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
138
-            $this->displayExitError('Permissions','No permission fo configure');
139
-        }		
137
+		if (! $this->Auth()->hasPermission('trapdirector/config')) {
138
+			$this->displayExitError('Permissions','No permission fo configure');
139
+		}		
140 140
 	}
141 141
 	
142
-    /**
143
-     * Check if user has write permission
144
-     * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page
145
-     * @return boolean : user has permission
146
-     */
142
+	/**
143
+	 * Check if user has write permission
144
+	 * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page
145
+	 * @return boolean : user has permission
146
+	 */
147 147
 	protected function checkModuleConfigPermission($check=0)
148 148
 	{
149
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
150
-            if ($check == 0)
151
-            {
152
-                $this->displayExitError('Permissions','No permission fo configure module');
153
-            }
154
-            return false;
155
-        }
156
-        return true;
149
+		if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
150
+			if ($check == 0)
151
+			{
152
+				$this->displayExitError('Permissions','No permission fo configure module');
153
+			}
154
+			return false;
155
+		}
156
+		return true;
157 157
 	}
158 158
 
159 159
 	/*************************  Trap class get **********************/
@@ -173,18 +173,18 @@  discard block
 block discarded – undo
173 173
 	/************************** MIB related **************************/
174 174
 	
175 175
 	/** Get MIBLoader class
176
-	*	@return MIBLoader class
177
-	*/
176
+	 *	@return MIBLoader class
177
+	 */
178 178
 	protected function getMIB()
179 179
 	{
180 180
 		if ($this->MIBData == null)
181 181
 		{
182
-		    $dbConn = $this->getUIDatabase()->getDbConn();
183
-		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
182
+			$dbConn = $this->getUIDatabase()->getDbConn();
183
+			if ($dbConn === null) throw new \ErrorException('uncatched db error');
184 184
 			$this->MIBData=new MIBLoader(
185 185
 				$this->Config()->get('config', 'snmptranslate'),
186 186
 				$this->Config()->get('config', 'snmptranslate_dirs'),
187
-			    $dbConn,
187
+				$dbConn,
188 188
 				$this->getModuleConfig()
189 189
 			);
190 190
 		}
@@ -194,14 +194,14 @@  discard block
 block discarded – undo
194 194
 	/**************************  Database queries *******************/
195 195
 	
196 196
 	/** Get host(s) by IP (v4 or v6) or by name in IDO database
197
-	*	does not catch exceptions
198
-	*	@return array of objects ( name, id (object_id), display_name)
199
-	*/
197
+	 *	does not catch exceptions
198
+	 *	@return array of objects ( name, id (object_id), display_name)
199
+	 */
200 200
 	protected function getHostByIP($ip) 
201 201
 	{
202 202
 		// 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
203
-	    $dbConn = $this->getUIDatabase()->getIdoDbConn();
204
-	    if ($dbConn === null) throw new \ErrorException('uncatched db error');
203
+		$dbConn = $this->getUIDatabase()->getIdoDbConn();
204
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
205 205
 	    
206 206
 		// TODO : check for SQL injections
207 207
 		$query=$dbConn->select()
@@ -217,16 +217,16 @@  discard block
 block discarded – undo
217 217
 	}
218 218
 
219 219
 	/** Get host(s) by name in IDO database
220
-	*	does not catch exceptions
221
-	*	@return array of objects ( name, id (object_id), display_name)
222
-	*/
220
+	 *	does not catch exceptions
221
+	 *	@return array of objects ( name, id (object_id), display_name)
222
+	 */
223 223
 	protected function getHostByName($name) 
224 224
 	{
225 225
 		// 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
226
-	    $dbConn = $this->getUIDatabase()->getIdoDbConn();
227
-	    if ($dbConn === null) throw new \ErrorException('uncatched db error');
226
+		$dbConn = $this->getUIDatabase()->getIdoDbConn();
227
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
228 228
 	    
229
-	    // TODO : check for SQL injections
229
+		// TODO : check for SQL injections
230 230
 		$query=$dbConn->select()
231 231
 				->from(
232 232
 					array('a' => 'icinga_objects'),
@@ -240,14 +240,14 @@  discard block
 block discarded – undo
240 240
 	}	
241 241
 	
242 242
 	/** Get host groups by  name in IDO database
243
-	*	does not catch exceptions
244
-	*	@return array of objects ( name, id (object_id), display_name)
245
-	*/
243
+	 *	does not catch exceptions
244
+	 *	@return array of objects ( name, id (object_id), display_name)
245
+	 */
246 246
 	protected function getHostGroupByName($ip) 
247 247
 	{
248 248
 		// 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
249
-	    $dbConn = $this->getUIDatabase()->getIdoDbConn();
250
-	    if ($dbConn === null) throw new \ErrorException('uncatched db error');
249
+		$dbConn = $this->getUIDatabase()->getIdoDbConn();
250
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
251 251
 		// TODO : check for SQL injections
252 252
 		$query=$dbConn->select()
253 253
 				->from(
@@ -263,9 +263,9 @@  discard block
 block discarded – undo
263 263
 
264 264
 	
265 265
 	/** Get host IP (v4 and v6) by name in IDO database
266
-	*	does not catch exceptions
267
-	*	@return array ( name, display_name, ip4, ip6)
268
-	*/
266
+	 *	does not catch exceptions
267
+	 *	@return array ( name, display_name, ip4, ip6)
268
+	 */
269 269
 	protected function getHostInfoByID($id) 
270 270
 	{
271 271
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
@@ -285,9 +285,9 @@  discard block
 block discarded – undo
285 285
 
286 286
 	
287 287
 	/** Get host by objectid  in IDO database
288
-	*	does not catch exceptions
289
-	*	@return array of objects ( id, name, display_name, ip, ip6,  )
290
-	*/
288
+	 *	does not catch exceptions
289
+	 *	@return array of objects ( id, name, display_name, ip, ip6,  )
290
+	 */
291 291
 	protected function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above
292 292
 	{
293 293
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
@@ -306,10 +306,10 @@  discard block
 block discarded – undo
306 306
 	}	
307 307
 	
308 308
 	/** Get services from object ( host_object_id) in IDO database
309
-	*	does not catch exceptions
310
-	*	@param $id	int object_id
311
-	*	@return array display_name (of service), service_object_id
312
-	*/
309
+	 *	does not catch exceptions
310
+	 *	@param $id	int object_id
311
+	 *	@return array display_name (of service), service_object_id
312
+	 */
313 313
 	protected function getServicesByHostid($id) 
314 314
 	{
315 315
 		// 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
@@ -329,11 +329,11 @@  discard block
 block discarded – undo
329 329
 	}	
330 330
 	
331 331
 	/** Get services from hostgroup object id ( hostgroup_object_id) in IDO database
332
-	* 	gets all hosts in hostgroup and return common services
333
-	*	does not catch exceptions
334
-	*	@param $id	int object_id
335
-	*	@return array display_name (of service), service_object_id
336
-	*/
332
+	 * 	gets all hosts in hostgroup and return common services
333
+	 *	does not catch exceptions
334
+	 *	@param $id	int object_id
335
+	 *	@return array display_name (of service), service_object_id
336
+	 */
337 337
 	protected function getServicesByHostGroupid($id) 
338 338
 	{		
339 339
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
 		//print_r($common_services);
373 373
 		foreach (array_keys($common_services) as $key)
374 374
 		{
375
-		    if ($common_services[$key]['num'] == $num_hosts)
375
+			if ($common_services[$key]['num'] == $num_hosts)
376 376
 			{
377 377
 				array_push($result,array($key,$common_services[$key]['name']));
378 378
 			}
@@ -382,15 +382,15 @@  discard block
 block discarded – undo
382 382
 	}	
383 383
 
384 384
 	/** Get services object id by host name / service name in IDO database
385
-	*	does not catch exceptions
386
-	*	@param $hostname string host name
387
-	*	@param $name string service name
388
-	*	@return array  service id
389
-	*/
385
+	 *	does not catch exceptions
386
+	 *	@param $hostname string host name
387
+	 *	@param $name string service name
388
+	 *	@return array  service id
389
+	 */
390 390
 	protected function getServiceIDByName($hostname,$name) 
391 391
 	{
392
-	    $dbConn = $this->getUIDatabase()->getIdoDbConn();
393
-	    if ($dbConn === null) throw new \ErrorException('uncatched db error');
392
+		$dbConn = $this->getUIDatabase()->getIdoDbConn();
393
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
394 394
 	    
395 395
 		if ($name == null)
396 396
 		{
@@ -411,10 +411,10 @@  discard block
 block discarded – undo
411 411
 	}
412 412
 	
413 413
 	/** Get object name from object_id  in IDO database
414
-	*	does not catch exceptions
415
-	*	@param int $id object_id (default to null, used first if not null)
416
-	*	@return array name1 (host) name2 (service)
417
-	*/
414
+	 *	does not catch exceptions
415
+	 *	@param int $id object_id (default to null, used first if not null)
416
+	 *	@return array name1 (host) name2 (service)
417
+	 */
418 418
 	protected function getObjectNameByid($id) 
419 419
 	{
420 420
 		// 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
@@ -432,13 +432,13 @@  discard block
 block discarded – undo
432 432
 	}		
433 433
 	
434 434
 	/** Check if director is installed
435
-	*	@return bool true/false
436
-	*/
435
+	 *	@return bool true/false
436
+	 */
437 437
 	protected function isDirectorInstalled()
438 438
 	{
439
-	    $output=array();
440
-	    exec('icingacli module list',$output);
441
-	    foreach ($output as $line)
439
+		$output=array();
440
+		exec('icingacli module list',$output);
441
+		foreach ($output as $line)
442 442
 		{
443 443
 			if (preg_match('/^director .*enabled/',$line))
444 444
 			{
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 			{
55 55
 				$this->redirectNow('trapdirector/settings?message=No database prefix');
56 56
 			}
57
-			$this->moduleConfig = new TrapModuleConfig($db_prefix);
57
+			$this->moduleConfig=new TrapModuleConfig($db_prefix);
58 58
 		}
59 59
 		return $this->moduleConfig;
60 60
 	}
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 */
66 66
 	public function getTrapListTable() {
67 67
 		if ($this->trapTableList == Null) {
68
-			$this->trapTableList = new TrapTableList();
68
+			$this->trapTableList=new TrapTableList();
69 69
 			$this->trapTableList->setConfig($this->getModuleConfig());
70 70
 		}
71 71
 		return $this->trapTableList;
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	{
79 79
 	    if ($this->trapTableHostList == Null) 
80 80
 		{
81
-	        $this->trapTableHostList = new TrapTableHostList();
81
+	        $this->trapTableHostList=new TrapTableHostList();
82 82
 	        $this->trapTableHostList->setConfig($this->getModuleConfig());
83 83
 	    }
84 84
 	    return $this->trapTableHostList;
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	{
92 92
 		if ($this->handlerTableList == Null) 
93 93
 		{
94
-			$this->handlerTableList = new HandlerTableList();
94
+			$this->handlerTableList=new HandlerTableList();
95 95
 			$this->handlerTableList->setConfig($this->getModuleConfig());
96 96
 		}
97 97
 		return $this->handlerTableList;
@@ -104,38 +104,38 @@  discard block
 block discarded – undo
104 104
 	{
105 105
 	    if ($this->UIDatabase == Null)
106 106
 	    {
107
-	        $this->UIDatabase = new UIDatabase($this);
107
+	        $this->UIDatabase=new UIDatabase($this);
108 108
 	       
109 109
 	    }
110 110
 	    return $this->UIDatabase;
111 111
 	}
112 112
 	
113
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
113
+    protected function applyPaginationLimits(Paginatable $paginatable, $limit=25, $offset=null)
114 114
     {
115
-        $limit = $this->params->get('limit', $limit);
116
-        $page = $this->params->get('page', $offset);
115
+        $limit=$this->params->get('limit', $limit);
116
+        $page=$this->params->get('page', $offset);
117 117
 
118 118
         $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
119 119
 
120 120
         return $paginatable;
121 121
     }	
122 122
 	
123
-	public function displayExitError($source,$message)
123
+	public function displayExitError($source, $message)
124 124
 	{	// TODO : check better ways to transmit data (with POST ?)
125 125
 		$this->redirectNow('trapdirector/error?source='.$source.'&message='.$message);
126 126
 	}
127 127
 	
128 128
 	protected function checkReadPermission()
129 129
 	{
130
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
131
-            $this->displayExitError('Permissions','No permission fo view content');
130
+        if (!$this->Auth()->hasPermission('trapdirector/view')) {
131
+            $this->displayExitError('Permissions', 'No permission fo view content');
132 132
         }		
133 133
 	}
134 134
 
135 135
 	protected function checkConfigPermission()
136 136
 	{
137
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
138
-            $this->displayExitError('Permissions','No permission fo configure');
137
+        if (!$this->Auth()->hasPermission('trapdirector/config')) {
138
+            $this->displayExitError('Permissions', 'No permission fo configure');
139 139
         }		
140 140
 	}
141 141
 	
@@ -146,10 +146,10 @@  discard block
 block discarded – undo
146 146
      */
147 147
 	protected function checkModuleConfigPermission($check=0)
148 148
 	{
149
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
149
+        if (!$this->Auth()->hasPermission('trapdirector/module_config')) {
150 150
             if ($check == 0)
151 151
             {
152
-                $this->displayExitError('Permissions','No permission fo configure module');
152
+                $this->displayExitError('Permissions', 'No permission fo configure module');
153 153
             }
154 154
             return false;
155 155
         }
@@ -161,10 +161,10 @@  discard block
 block discarded – undo
161 161
 	{ // TODO : try/catch here ? or within caller
162 162
 		if ($this->trapClass == null)
163 163
 		{
164
-			require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
164
+			require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
165 165
 			$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
166 166
 			//$debug_level=4;
167
-			$this->trapClass = new Trap($icingaweb2_etc);
167
+			$this->trapClass=new Trap($icingaweb2_etc);
168 168
 			//$Trap->setLogging($debug_level,'syslog');
169 169
 		}
170 170
 		return $this->trapClass;
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	{
180 180
 		if ($this->MIBData == null)
181 181
 		{
182
-		    $dbConn = $this->getUIDatabase()->getDbConn();
182
+		    $dbConn=$this->getUIDatabase()->getDbConn();
183 183
 		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
184 184
 			$this->MIBData=new MIBLoader(
185 185
 				$this->Config()->get('config', 'snmptranslate'),
@@ -200,14 +200,14 @@  discard block
 block discarded – undo
200 200
 	protected function getHostByIP($ip) 
201 201
 	{
202 202
 		// 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
203
-	    $dbConn = $this->getUIDatabase()->getIdoDbConn();
203
+	    $dbConn=$this->getUIDatabase()->getIdoDbConn();
204 204
 	    if ($dbConn === null) throw new \ErrorException('uncatched db error');
205 205
 	    
206 206
 		// TODO : check for SQL injections
207 207
 		$query=$dbConn->select()
208 208
 				->from(
209 209
 					array('a' => 'icinga_objects'),
210
-					array('name' => 'a.name1','id' => 'object_id'))
210
+					array('name' => 'a.name1', 'id' => 'object_id'))
211 211
 				->join(
212 212
 					array('b' => 'icinga_hosts'),
213 213
 					'b.host_object_id=a.object_id',
@@ -223,14 +223,14 @@  discard block
 block discarded – undo
223 223
 	protected function getHostByName($name) 
224 224
 	{
225 225
 		// 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
226
-	    $dbConn = $this->getUIDatabase()->getIdoDbConn();
226
+	    $dbConn=$this->getUIDatabase()->getIdoDbConn();
227 227
 	    if ($dbConn === null) throw new \ErrorException('uncatched db error');
228 228
 	    
229 229
 	    // TODO : check for SQL injections
230 230
 		$query=$dbConn->select()
231 231
 				->from(
232 232
 					array('a' => 'icinga_objects'),
233
-					array('name' => 'a.name1','id' => 'object_id'))
233
+					array('name' => 'a.name1', 'id' => 'object_id'))
234 234
 				->join(
235 235
 					array('b' => 'icinga_hosts'),
236 236
 					'b.host_object_id=a.object_id',
@@ -246,13 +246,13 @@  discard block
 block discarded – undo
246 246
 	protected function getHostGroupByName($ip) 
247 247
 	{
248 248
 		// 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
249
-	    $dbConn = $this->getUIDatabase()->getIdoDbConn();
249
+	    $dbConn=$this->getUIDatabase()->getIdoDbConn();
250 250
 	    if ($dbConn === null) throw new \ErrorException('uncatched db error');
251 251
 		// TODO : check for SQL injections
252 252
 		$query=$dbConn->select()
253 253
 				->from(
254 254
 					array('a' => 'icinga_objects'),
255
-					array('name' => 'a.name1','id' => 'object_id'))
255
+					array('name' => 'a.name1', 'id' => 'object_id'))
256 256
 				->join(
257 257
 					array('b' => 'icinga_hostgroups'),
258 258
 					'b.hostgroup_object_id=a.object_id',
@@ -268,8 +268,8 @@  discard block
 block discarded – undo
268 268
 	*/
269 269
 	protected function getHostInfoByID($id) 
270 270
 	{
271
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
272
-		$dbConn = $this->getUIDatabase()->getIdoDbConn();
271
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
272
+		$dbConn=$this->getUIDatabase()->getIdoDbConn();
273 273
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
274 274
 		$query=$dbConn->select()
275 275
 				->from(
@@ -290,18 +290,18 @@  discard block
 block discarded – undo
290 290
 	*/
291 291
 	protected function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above
292 292
 	{
293
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
294
-		$dbConn = $this->getUIDatabase()->getIdoDbConn();
293
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
294
+		$dbConn=$this->getUIDatabase()->getIdoDbConn();
295 295
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
296 296
 		$query=$dbConn->select()
297 297
 				->from(
298 298
 					array('a' => 'icinga_objects'),
299
-					array('name' => 'a.name1','id' => 'a.object_id'))
299
+					array('name' => 'a.name1', 'id' => 'a.object_id'))
300 300
 				->join(
301 301
 					array('b' => 'icinga_hosts'),
302 302
 					'b.host_object_id=a.object_id',
303
-					array('display_name' => 'b.display_name' , 'ip' => 'b.address', 'ip6' => 'b.address6'))
304
-				->where('a.object_id = ?',$id);
303
+					array('display_name' => 'b.display_name', 'ip' => 'b.address', 'ip6' => 'b.address6'))
304
+				->where('a.object_id = ?', $id);
305 305
 		return $dbConn->fetchRow($query);
306 306
 	}	
307 307
 	
@@ -313,17 +313,17 @@  discard block
 block discarded – undo
313 313
 	protected function getServicesByHostid($id) 
314 314
 	{
315 315
 		// 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
316
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
317
-		$dbConn = $this->getUIDatabase()->getIdoDbConn();
316
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
317
+		$dbConn=$this->getUIDatabase()->getIdoDbConn();
318 318
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
319 319
 		$query=$dbConn->select()
320 320
 				->from(
321 321
 					array('s' => 'icinga_services'),
322
-					array('name' => 's.display_name','id' => 's.service_object_id'))
322
+					array('name' => 's.display_name', 'id' => 's.service_object_id'))
323 323
 				->join(
324 324
 					array('a' => 'icinga_objects'),
325 325
 					's.service_object_id=a.object_id',
326
-					array('is_active'=>'a.is_active','name2'=>'a.name2'))
326
+					array('is_active'=>'a.is_active', 'name2'=>'a.name2'))
327 327
 				->where('s.host_object_id='.$id.' AND a.is_active = 1');
328 328
 		return $dbConn->fetchAll($query);
329 329
 	}	
@@ -336,8 +336,8 @@  discard block
 block discarded – undo
336 336
 	*/
337 337
 	protected function getServicesByHostGroupid($id) 
338 338
 	{		
339
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
340
-		$dbConn = $this->getUIDatabase()->getIdoDbConn();
339
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
340
+		$dbConn=$this->getUIDatabase()->getIdoDbConn();
341 341
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
342 342
 		$query=$dbConn->select()
343 343
 				->from(
@@ -354,11 +354,11 @@  discard block
 block discarded – undo
354 354
 		foreach ($hosts as $key => $host)
355 355
 		{ // For each host, get all services and add in common_services if not found or add counter
356 356
 			$host_services=$this->getServicesByHostid($host->host_object_id);
357
-			foreach($host_services as $service)
357
+			foreach ($host_services as $service)
358 358
 			{
359 359
 				if (isset($common_services[$service->name2]['num']))
360 360
 				{
361
-					$common_services[$service->name2]['num'] +=1;
361
+					$common_services[$service->name2]['num']+=1;
362 362
 				}
363 363
 				else
364 364
 				{
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
 		{
375 375
 		    if ($common_services[$key]['num'] == $num_hosts)
376 376
 			{
377
-				array_push($result,array($key,$common_services[$key]['name']));
377
+				array_push($result, array($key, $common_services[$key]['name']));
378 378
 			}
379 379
 		}
380 380
 		
@@ -387,9 +387,9 @@  discard block
 block discarded – undo
387 387
 	*	@param $name string service name
388 388
 	*	@return array  service id
389 389
 	*/
390
-	protected function getServiceIDByName($hostname,$name) 
390
+	protected function getServiceIDByName($hostname, $name) 
391 391
 	{
392
-	    $dbConn = $this->getUIDatabase()->getIdoDbConn();
392
+	    $dbConn=$this->getUIDatabase()->getIdoDbConn();
393 393
 	    if ($dbConn === null) throw new \ErrorException('uncatched db error');
394 394
 	    
395 395
 		if ($name == null)
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 		$query=$dbConn->select()
401 401
 				->from(
402 402
 					array('s' => 'icinga_services'),
403
-					array('name' => 's.display_name','id' => 's.service_object_id'))
403
+					array('name' => 's.display_name', 'id' => 's.service_object_id'))
404 404
 				->join(
405 405
 					array('a' => 'icinga_objects'),
406 406
 					's.service_object_id=a.object_id',
@@ -418,14 +418,14 @@  discard block
 block discarded – undo
418 418
 	protected function getObjectNameByid($id) 
419 419
 	{
420 420
 		// 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
421
-		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
422
-		$dbConn = $this->getUIDatabase()->getIdoDbConn();
421
+		if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
422
+		$dbConn=$this->getUIDatabase()->getIdoDbConn();
423 423
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
424 424
 		
425 425
 		$query=$dbConn->select()
426 426
 				->from(
427 427
 					array('a' => 'icinga_objects'),
428
-					array('name1' => 'a.name1','name2' => 'a.name2'))
428
+					array('name1' => 'a.name1', 'name2' => 'a.name2'))
429 429
 				->where('a.object_id='.$id.' AND a.is_active = 1');
430 430
 
431 431
 		return $dbConn->fetchRow($query);
@@ -437,10 +437,10 @@  discard block
 block discarded – undo
437 437
 	protected function isDirectorInstalled()
438 438
 	{
439 439
 	    $output=array();
440
-	    exec('icingacli module list',$output);
440
+	    exec('icingacli module list', $output);
441 441
 	    foreach ($output as $line)
442 442
 		{
443
-			if (preg_match('/^director .*enabled/',$line))
443
+			if (preg_match('/^director .*enabled/', $line))
444 444
 			{
445 445
 				return true;
446 446
 			}
Please login to merge, or discard this patch.
Braces   +31 added lines, -12 removed lines patch added patch discarded remove patch
@@ -180,7 +180,9 @@  discard block
 block discarded – undo
180 180
 		if ($this->MIBData == null)
181 181
 		{
182 182
 		    $dbConn = $this->getUIDatabase()->getDbConn();
183
-		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
183
+		    if ($dbConn === null) {
184
+		    	throw new \ErrorException('uncatched db error');
185
+		    }
184 186
 			$this->MIBData=new MIBLoader(
185 187
 				$this->Config()->get('config', 'snmptranslate'),
186 188
 				$this->Config()->get('config', 'snmptranslate_dirs'),
@@ -201,7 +203,9 @@  discard block
 block discarded – undo
201 203
 	{
202 204
 		// 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
203 205
 	    $dbConn = $this->getUIDatabase()->getIdoDbConn();
204
-	    if ($dbConn === null) throw new \ErrorException('uncatched db error');
206
+	    if ($dbConn === null) {
207
+	    	throw new \ErrorException('uncatched db error');
208
+	    }
205 209
 	    
206 210
 		// TODO : check for SQL injections
207 211
 		$query=$dbConn->select()
@@ -224,7 +228,9 @@  discard block
 block discarded – undo
224 228
 	{
225 229
 		// 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
226 230
 	    $dbConn = $this->getUIDatabase()->getIdoDbConn();
227
-	    if ($dbConn === null) throw new \ErrorException('uncatched db error');
231
+	    if ($dbConn === null) {
232
+	    	throw new \ErrorException('uncatched db error');
233
+	    }
228 234
 	    
229 235
 	    // TODO : check for SQL injections
230 236
 		$query=$dbConn->select()
@@ -247,7 +253,9 @@  discard block
 block discarded – undo
247 253
 	{
248 254
 		// 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
249 255
 	    $dbConn = $this->getUIDatabase()->getIdoDbConn();
250
-	    if ($dbConn === null) throw new \ErrorException('uncatched db error');
256
+	    if ($dbConn === null) {
257
+	    	throw new \ErrorException('uncatched db error');
258
+	    }
251 259
 		// TODO : check for SQL injections
252 260
 		$query=$dbConn->select()
253 261
 				->from(
@@ -270,7 +278,9 @@  discard block
 block discarded – undo
270 278
 	{
271 279
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
272 280
 		$dbConn = $this->getUIDatabase()->getIdoDbConn();
273
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
281
+		if ($dbConn === null) {
282
+			throw new \ErrorException('uncatched db error');
283
+		}
274 284
 		$query=$dbConn->select()
275 285
 				->from(
276 286
 					array('a' => 'icinga_objects'),
@@ -292,7 +302,9 @@  discard block
 block discarded – undo
292 302
 	{
293 303
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
294 304
 		$dbConn = $this->getUIDatabase()->getIdoDbConn();
295
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
305
+		if ($dbConn === null) {
306
+			throw new \ErrorException('uncatched db error');
307
+		}
296 308
 		$query=$dbConn->select()
297 309
 				->from(
298 310
 					array('a' => 'icinga_objects'),
@@ -315,7 +327,9 @@  discard block
 block discarded – undo
315 327
 		// 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
316 328
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
317 329
 		$dbConn = $this->getUIDatabase()->getIdoDbConn();
318
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
330
+		if ($dbConn === null) {
331
+			throw new \ErrorException('uncatched db error');
332
+		}
319 333
 		$query=$dbConn->select()
320 334
 				->from(
321 335
 					array('s' => 'icinga_services'),
@@ -338,7 +352,9 @@  discard block
 block discarded – undo
338 352
 	{		
339 353
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
340 354
 		$dbConn = $this->getUIDatabase()->getIdoDbConn();
341
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
355
+		if ($dbConn === null) {
356
+			throw new \ErrorException('uncatched db error');
357
+		}
342 358
 		$query=$dbConn->select()
343 359
 				->from(
344 360
 					array('s' => 'icinga_hostgroup_members'),
@@ -359,8 +375,7 @@  discard block
 block discarded – undo
359 375
 				if (isset($common_services[$service->name2]['num']))
360 376
 				{
361 377
 					$common_services[$service->name2]['num'] +=1;
362
-				}
363
-				else
378
+				} else
364 379
 				{
365 380
 					$common_services[$service->name2]['num']=1;
366 381
 					$common_services[$service->name2]['name']=$service->name;
@@ -390,7 +405,9 @@  discard block
 block discarded – undo
390 405
 	protected function getServiceIDByName($hostname,$name) 
391 406
 	{
392 407
 	    $dbConn = $this->getUIDatabase()->getIdoDbConn();
393
-	    if ($dbConn === null) throw new \ErrorException('uncatched db error');
408
+	    if ($dbConn === null) {
409
+	    	throw new \ErrorException('uncatched db error');
410
+	    }
394 411
 	    
395 412
 		if ($name == null)
396 413
 		{
@@ -420,7 +437,9 @@  discard block
 block discarded – undo
420 437
 		// 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
421 438
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
422 439
 		$dbConn = $this->getUIDatabase()->getIdoDbConn();
423
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
440
+		if ($dbConn === null) {
441
+			throw new \ErrorException('uncatched db error');
442
+		}
424 443
 		
425 444
 		$query=$dbConn->select()
426 445
 				->from(
Please login to merge, or discard this patch.
library/Trapdirector/TrapsActions/TrapDBQuery.php 3 patches
Indentation   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -18,204 +18,204 @@
 block discarded – undo
18 18
 {
19 19
 
20 20
 
21
-    abstract protected function getTrapCtrl();
22
-    abstract public function getDbConn();
21
+	abstract protected function getTrapCtrl();
22
+	abstract public function getDbConn();
23 23
     
24
-    /** Add handler rule in traps DB
25
-     *	@param array $params : array(<db item>=><value>)
26
-     *	@return int inserted id
27
-     */
28
-    public function addHandlerRule($params)
29
-    {
30
-        // TODO Check for rule consistency
24
+	/** Add handler rule in traps DB
25
+	 *	@param array $params : array(<db item>=><value>)
26
+	 *	@return int inserted id
27
+	 */
28
+	public function addHandlerRule($params)
29
+	{
30
+		// TODO Check for rule consistency
31 31
         
32
-        $dbConn = $this->getDbConn();
33
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
34
-        // Add last modified date = creation date and username
35
-        $params['created'] = new Zend_Db_Expr('NOW()');
36
-        $params['modified'] = new 	Zend_Db_Expr('NOW()');
37
-        $params['modifier'] = $this->Auth()->getUser()->getUsername();
32
+		$dbConn = $this->getDbConn();
33
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
34
+		// Add last modified date = creation date and username
35
+		$params['created'] = new Zend_Db_Expr('NOW()');
36
+		$params['modified'] = new 	Zend_Db_Expr('NOW()');
37
+		$params['modifier'] = $this->Auth()->getUser()->getUsername();
38 38
         
39
-        $query=$dbConn->insert(
40
-            $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
41
-            $params
42
-            );
43
-        if($query==false)
44
-        {
45
-            return null;
46
-        }
47
-        return $dbConn->lastInsertId();
48
-    }
39
+		$query=$dbConn->insert(
40
+			$this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
41
+			$params
42
+			);
43
+		if($query==false)
44
+		{
45
+			return null;
46
+		}
47
+		return $dbConn->lastInsertId();
48
+	}
49 49
     
50
-    /** Update handler rule in traps DB
51
-     *	@param array $params : (<db item>=><value>)
52
-     *   @param integer $ruleID : rule id in db
53
-     *	@return array affected rows
54
-     */
55
-    public function updateHandlerRule($params,$ruleID)
56
-    {
57
-        // TODO Check for rule consistency
58
-        $dbConn = $this->getDbConn();
59
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
60
-        // Add last modified date = creation date and username
61
-        $params['modified'] = new 	Zend_Db_Expr('NOW()');
62
-        $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
50
+	/** Update handler rule in traps DB
51
+	 *	@param array $params : (<db item>=><value>)
52
+	 *   @param integer $ruleID : rule id in db
53
+	 *	@return array affected rows
54
+	 */
55
+	public function updateHandlerRule($params,$ruleID)
56
+	{
57
+		// TODO Check for rule consistency
58
+		$dbConn = $this->getDbConn();
59
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
60
+		// Add last modified date = creation date and username
61
+		$params['modified'] = new 	Zend_Db_Expr('NOW()');
62
+		$params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
63 63
         
64
-        $numRows=$dbConn->update(
65
-            $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
66
-            $params,
67
-            'id='.$ruleID
68
-            );
69
-        return $numRows;
70
-    }
64
+		$numRows=$dbConn->update(
65
+			$this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
66
+			$params,
67
+			'id='.$ruleID
68
+			);
69
+		return $numRows;
70
+	}
71 71
     
72
-    /** Delete rule by id
73
-     *	@param int $ruleID rule id
74
-     */
75
-    public function deleteRule($ruleID)
76
-    {
77
-        if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
72
+	/** Delete rule by id
73
+	 *	@param int $ruleID rule id
74
+	 */
75
+	public function deleteRule($ruleID)
76
+	{
77
+		if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
78 78
         
79
-        $dbConn = $this->getDbConn();
80
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
79
+		$dbConn = $this->getDbConn();
80
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
81 81
         
82
-        $query=$dbConn->delete(
83
-            $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
84
-            'id='.$ruleID
85
-            );
86
-        return $query;
87
-    }
82
+		$query=$dbConn->delete(
83
+			$this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
84
+			'id='.$ruleID
85
+			);
86
+		return $query;
87
+	}
88 88
     
89
-    /** Delete trap by ip & oid
90
-     *	@param $ip string source IP (v4 or v6)
91
-     *	@param $oid string oid
92
-     */
93
-    public function deleteTrap($ip,$oid)
94
-    {
89
+	/** Delete trap by ip & oid
90
+	 *	@param $ip string source IP (v4 or v6)
91
+	 *	@param $oid string oid
92
+	 */
93
+	public function deleteTrap($ip,$oid)
94
+	{
95 95
         
96
-        $dbConn = $this->getDbConn();
97
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
98
-        $condition=null;
99
-        if ($ip != null)
100
-        {
101
-            $condition="source_ip='$ip'";
102
-        }
103
-        if ($oid != null)
104
-        {
105
-            $condition=($condition===null)?'':$condition.' AND ';
106
-            $condition.="trap_oid='$oid'";
107
-        }
108
-        if($condition === null) return null;
109
-        $query=$dbConn->delete(
110
-            $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
111
-            $condition
112
-            );
113
-        // TODO test ret code etc...
114
-        return $query;
115
-    }
96
+		$dbConn = $this->getDbConn();
97
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
98
+		$condition=null;
99
+		if ($ip != null)
100
+		{
101
+			$condition="source_ip='$ip'";
102
+		}
103
+		if ($oid != null)
104
+		{
105
+			$condition=($condition===null)?'':$condition.' AND ';
106
+			$condition.="trap_oid='$oid'";
107
+		}
108
+		if($condition === null) return null;
109
+		$query=$dbConn->delete(
110
+			$this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
111
+			$condition
112
+			);
113
+		// TODO test ret code etc...
114
+		return $query;
115
+	}
116 116
     
117 117
     
118
-    /** count trap by ip & oid
119
-     *	@param $ip string source IP (v4 or v6)
120
-     *	@param $oid string oid
121
-     */
122
-    public function countTrap($ip,$oid)
123
-    {
118
+	/** count trap by ip & oid
119
+	 *	@param $ip string source IP (v4 or v6)
120
+	 *	@param $oid string oid
121
+	 */
122
+	public function countTrap($ip,$oid)
123
+	{
124 124
         
125
-        $dbConn = $this->getDbConn();
126
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
125
+		$dbConn = $this->getDbConn();
126
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
127 127
         
128
-        $condition=null;
129
-        if ($ip != null)
130
-        {
131
-            $condition="source_ip='$ip'";
132
-        }
133
-        if ($oid != null)
134
-        {
135
-            $condition=($condition===null)?'':$condition.' AND ';
136
-            $condition.="trap_oid='$oid'";
137
-        }
138
-        if($condition === null) return 0;
139
-        $query=$dbConn->select()
140
-        ->from(
141
-            $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
142
-            array('num'=>'count(*)'))
143
-            ->where($condition);
144
-            $return_row=$dbConn->fetchRow($query);
145
-            return $return_row->num;
146
-    }
128
+		$condition=null;
129
+		if ($ip != null)
130
+		{
131
+			$condition="source_ip='$ip'";
132
+		}
133
+		if ($oid != null)
134
+		{
135
+			$condition=($condition===null)?'':$condition.' AND ';
136
+			$condition.="trap_oid='$oid'";
137
+		}
138
+		if($condition === null) return 0;
139
+		$query=$dbConn->select()
140
+		->from(
141
+			$this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
142
+			array('num'=>'count(*)'))
143
+			->where($condition);
144
+			$return_row=$dbConn->fetchRow($query);
145
+			return $return_row->num;
146
+	}
147 147
     
148
-    /** get configuration value
149
-     *	@param string $element : configuration name in db
150
-     */
151
-    public function getDBConfigValue($element)
152
-    {
148
+	/** get configuration value
149
+	 *	@param string $element : configuration name in db
150
+	 */
151
+	public function getDBConfigValue($element)
152
+	{
153 153
         
154
-        $dbConn = $this->getDbConn();
155
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
154
+		$dbConn = $this->getDbConn();
155
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
156 156
         
157
-        $query=$dbConn->select()
158
-        ->from(
159
-            $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
160
-            array('value'=>'value'))
161
-            ->where('name=?',$element);
162
-            $return_row=$dbConn->fetchRow($query);
163
-            if ($return_row==null)  // value does not exists
164
-            {
165
-                $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
166
-                if ( ! isset($default[$element])) return null; // no default and not value
157
+		$query=$dbConn->select()
158
+		->from(
159
+			$this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
160
+			array('value'=>'value'))
161
+			->where('name=?',$element);
162
+			$return_row=$dbConn->fetchRow($query);
163
+			if ($return_row==null)  // value does not exists
164
+			{
165
+				$default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
166
+				if ( ! isset($default[$element])) return null; // no default and not value
167 167
                 
168
-                $this->addDBConfigValue($element,$default[$element]);
169
-                return $default[$element];
170
-            }
171
-            if ($return_row->value == null) // value id empty
172
-            {
173
-                $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
174
-                if ( ! isset($default[$element])) return null; // no default and not value
175
-                $this->setDBConfigValue($element,$default[$element]);
176
-                return $default[$element];
177
-            }
178
-            return $return_row->value;
179
-    }
168
+				$this->addDBConfigValue($element,$default[$element]);
169
+				return $default[$element];
170
+			}
171
+			if ($return_row->value == null) // value id empty
172
+			{
173
+				$default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
174
+				if ( ! isset($default[$element])) return null; // no default and not value
175
+				$this->setDBConfigValue($element,$default[$element]);
176
+				return $default[$element];
177
+			}
178
+			return $return_row->value;
179
+	}
180 180
     
181
-    /** add configuration value
182
-     *	@param string $element : name of config element
183
-     *   @param string $value : value
184
-     */
181
+	/** add configuration value
182
+	 *	@param string $element : name of config element
183
+	 *   @param string $value : value
184
+	 */
185 185
     
186
-    public function addDBConfigValue($element,$value)
187
-    {
186
+	public function addDBConfigValue($element,$value)
187
+	{
188 188
         
189
-        $dbConn = $this->getDbConn();
190
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
189
+		$dbConn = $this->getDbConn();
190
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
191 191
         
192
-        $query=$dbConn->insert(
193
-            $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
194
-            array(
195
-                'name' => $element,
196
-                'value'=>$value
197
-            )
198
-            );
199
-        return $query;
200
-    }
192
+		$query=$dbConn->insert(
193
+			$this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
194
+			array(
195
+				'name' => $element,
196
+				'value'=>$value
197
+			)
198
+			);
199
+		return $query;
200
+	}
201 201
     
202
-    /** set configuration value
203
-     *	@param string $element : name of config element
204
-     *   @param string $value : value
205
-     */
206
-    public function setDBConfigValue($element,$value)
207
-    {
202
+	/** set configuration value
203
+	 *	@param string $element : name of config element
204
+	 *   @param string $value : value
205
+	 */
206
+	public function setDBConfigValue($element,$value)
207
+	{
208 208
         
209
-        $dbConn = $this->getDbConn();
210
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
209
+		$dbConn = $this->getDbConn();
210
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
211 211
         
212
-        $query=$dbConn->update(
213
-            $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
214
-            array('value'=>$value),
215
-            'name=\''.$element.'\''
216
-            );
217
-        return $query;
218
-    }
212
+		$query=$dbConn->update(
213
+			$this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
214
+			array('value'=>$value),
215
+			'name=\''.$element.'\''
216
+			);
217
+		return $query;
218
+	}
219 219
     
220 220
     
221 221
 }
222 222
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -29,18 +29,18 @@  discard block
 block discarded – undo
29 29
     {
30 30
         // TODO Check for rule consistency
31 31
         
32
-        $dbConn = $this->getDbConn();
32
+        $dbConn=$this->getDbConn();
33 33
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
34 34
         // Add last modified date = creation date and username
35
-        $params['created'] = new Zend_Db_Expr('NOW()');
36
-        $params['modified'] = new 	Zend_Db_Expr('NOW()');
37
-        $params['modifier'] = $this->Auth()->getUser()->getUsername();
35
+        $params['created']=new Zend_Db_Expr('NOW()');
36
+        $params['modified']=new 	Zend_Db_Expr('NOW()');
37
+        $params['modifier']=$this->Auth()->getUser()->getUsername();
38 38
         
39 39
         $query=$dbConn->insert(
40 40
             $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
41 41
             $params
42 42
             );
43
-        if($query==false)
43
+        if ($query == false)
44 44
         {
45 45
             return null;
46 46
         }
@@ -52,14 +52,14 @@  discard block
 block discarded – undo
52 52
      *   @param integer $ruleID : rule id in db
53 53
      *	@return array affected rows
54 54
      */
55
-    public function updateHandlerRule($params,$ruleID)
55
+    public function updateHandlerRule($params, $ruleID)
56 56
     {
57 57
         // TODO Check for rule consistency
58
-        $dbConn = $this->getDbConn();
58
+        $dbConn=$this->getDbConn();
59 59
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
60 60
         // Add last modified date = creation date and username
61
-        $params['modified'] = new 	Zend_Db_Expr('NOW()');
62
-        $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
61
+        $params['modified']=new 	Zend_Db_Expr('NOW()');
62
+        $params['modifier']=$this->getTrapCtrl()->Auth()->getUser()->getUsername();
63 63
         
64 64
         $numRows=$dbConn->update(
65 65
             $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
@@ -74,9 +74,9 @@  discard block
 block discarded – undo
74 74
      */
75 75
     public function deleteRule($ruleID)
76 76
     {
77
-        if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
77
+        if (!preg_match('/^[0-9]+$/', $ruleID)) { throw new Exception('Invalid id'); }
78 78
         
79
-        $dbConn = $this->getDbConn();
79
+        $dbConn=$this->getDbConn();
80 80
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
81 81
         
82 82
         $query=$dbConn->delete(
@@ -90,10 +90,10 @@  discard block
 block discarded – undo
90 90
      *	@param $ip string source IP (v4 or v6)
91 91
      *	@param $oid string oid
92 92
      */
93
-    public function deleteTrap($ip,$oid)
93
+    public function deleteTrap($ip, $oid)
94 94
     {
95 95
         
96
-        $dbConn = $this->getDbConn();
96
+        $dbConn=$this->getDbConn();
97 97
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
98 98
         $condition=null;
99 99
         if ($ip != null)
@@ -102,10 +102,10 @@  discard block
 block discarded – undo
102 102
         }
103 103
         if ($oid != null)
104 104
         {
105
-            $condition=($condition===null)?'':$condition.' AND ';
105
+            $condition=($condition === null) ? '' : $condition.' AND ';
106 106
             $condition.="trap_oid='$oid'";
107 107
         }
108
-        if($condition === null) return null;
108
+        if ($condition === null) return null;
109 109
         $query=$dbConn->delete(
110 110
             $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
111 111
             $condition
@@ -119,10 +119,10 @@  discard block
 block discarded – undo
119 119
      *	@param $ip string source IP (v4 or v6)
120 120
      *	@param $oid string oid
121 121
      */
122
-    public function countTrap($ip,$oid)
122
+    public function countTrap($ip, $oid)
123 123
     {
124 124
         
125
-        $dbConn = $this->getDbConn();
125
+        $dbConn=$this->getDbConn();
126 126
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
127 127
         
128 128
         $condition=null;
@@ -132,10 +132,10 @@  discard block
 block discarded – undo
132 132
         }
133 133
         if ($oid != null)
134 134
         {
135
-            $condition=($condition===null)?'':$condition.' AND ';
135
+            $condition=($condition === null) ? '' : $condition.' AND ';
136 136
             $condition.="trap_oid='$oid'";
137 137
         }
138
-        if($condition === null) return 0;
138
+        if ($condition === null) return 0;
139 139
         $query=$dbConn->select()
140 140
         ->from(
141 141
             $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
@@ -151,28 +151,28 @@  discard block
 block discarded – undo
151 151
     public function getDBConfigValue($element)
152 152
     {
153 153
         
154
-        $dbConn = $this->getDbConn();
154
+        $dbConn=$this->getDbConn();
155 155
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
156 156
         
157 157
         $query=$dbConn->select()
158 158
         ->from(
159 159
             $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
160 160
             array('value'=>'value'))
161
-            ->where('name=?',$element);
161
+            ->where('name=?', $element);
162 162
             $return_row=$dbConn->fetchRow($query);
163
-            if ($return_row==null)  // value does not exists
163
+            if ($return_row == null)  // value does not exists
164 164
             {
165 165
                 $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
166
-                if ( ! isset($default[$element])) return null; // no default and not value
166
+                if (!isset($default[$element])) return null; // no default and not value
167 167
                 
168
-                $this->addDBConfigValue($element,$default[$element]);
168
+                $this->addDBConfigValue($element, $default[$element]);
169 169
                 return $default[$element];
170 170
             }
171 171
             if ($return_row->value == null) // value id empty
172 172
             {
173 173
                 $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
174
-                if ( ! isset($default[$element])) return null; // no default and not value
175
-                $this->setDBConfigValue($element,$default[$element]);
174
+                if (!isset($default[$element])) return null; // no default and not value
175
+                $this->setDBConfigValue($element, $default[$element]);
176 176
                 return $default[$element];
177 177
             }
178 178
             return $return_row->value;
@@ -183,10 +183,10 @@  discard block
 block discarded – undo
183 183
      *   @param string $value : value
184 184
      */
185 185
     
186
-    public function addDBConfigValue($element,$value)
186
+    public function addDBConfigValue($element, $value)
187 187
     {
188 188
         
189
-        $dbConn = $this->getDbConn();
189
+        $dbConn=$this->getDbConn();
190 190
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
191 191
         
192 192
         $query=$dbConn->insert(
@@ -203,10 +203,10 @@  discard block
 block discarded – undo
203 203
      *	@param string $element : name of config element
204 204
      *   @param string $value : value
205 205
      */
206
-    public function setDBConfigValue($element,$value)
206
+    public function setDBConfigValue($element, $value)
207 207
     {
208 208
         
209
-        $dbConn = $this->getDbConn();
209
+        $dbConn=$this->getDbConn();
210 210
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
211 211
         
212 212
         $query=$dbConn->update(
Please login to merge, or discard this patch.
Braces   +44 added lines, -14 removed lines patch added patch discarded remove patch
@@ -30,7 +30,9 @@  discard block
 block discarded – undo
30 30
         // TODO Check for rule consistency
31 31
         
32 32
         $dbConn = $this->getDbConn();
33
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
33
+        if ($dbConn === null) {
34
+        	throw new \ErrorException('uncatched db error');
35
+        }
34 36
         // Add last modified date = creation date and username
35 37
         $params['created'] = new Zend_Db_Expr('NOW()');
36 38
         $params['modified'] = new 	Zend_Db_Expr('NOW()');
@@ -56,7 +58,9 @@  discard block
 block discarded – undo
56 58
     {
57 59
         // TODO Check for rule consistency
58 60
         $dbConn = $this->getDbConn();
59
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
61
+        if ($dbConn === null) {
62
+        	throw new \ErrorException('uncatched db error');
63
+        }
60 64
         // Add last modified date = creation date and username
61 65
         $params['modified'] = new 	Zend_Db_Expr('NOW()');
62 66
         $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
@@ -77,7 +81,9 @@  discard block
 block discarded – undo
77 81
         if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
78 82
         
79 83
         $dbConn = $this->getDbConn();
80
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
84
+        if ($dbConn === null) {
85
+        	throw new \ErrorException('uncatched db error');
86
+        }
81 87
         
82 88
         $query=$dbConn->delete(
83 89
             $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
@@ -94,7 +100,9 @@  discard block
 block discarded – undo
94 100
     {
95 101
         
96 102
         $dbConn = $this->getDbConn();
97
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
103
+        if ($dbConn === null) {
104
+        	throw new \ErrorException('uncatched db error');
105
+        }
98 106
         $condition=null;
99 107
         if ($ip != null)
100 108
         {
@@ -105,7 +113,9 @@  discard block
 block discarded – undo
105 113
             $condition=($condition===null)?'':$condition.' AND ';
106 114
             $condition.="trap_oid='$oid'";
107 115
         }
108
-        if($condition === null) return null;
116
+        if($condition === null) {
117
+        	return null;
118
+        }
109 119
         $query=$dbConn->delete(
110 120
             $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
111 121
             $condition
@@ -123,7 +133,9 @@  discard block
 block discarded – undo
123 133
     {
124 134
         
125 135
         $dbConn = $this->getDbConn();
126
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
136
+        if ($dbConn === null) {
137
+        	throw new \ErrorException('uncatched db error');
138
+        }
127 139
         
128 140
         $condition=null;
129 141
         if ($ip != null)
@@ -135,7 +147,9 @@  discard block
 block discarded – undo
135 147
             $condition=($condition===null)?'':$condition.' AND ';
136 148
             $condition.="trap_oid='$oid'";
137 149
         }
138
-        if($condition === null) return 0;
150
+        if($condition === null) {
151
+        	return 0;
152
+        }
139 153
         $query=$dbConn->select()
140 154
         ->from(
141 155
             $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
@@ -152,7 +166,9 @@  discard block
 block discarded – undo
152 166
     {
153 167
         
154 168
         $dbConn = $this->getDbConn();
155
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
169
+        if ($dbConn === null) {
170
+        	throw new \ErrorException('uncatched db error');
171
+        }
156 172
         
157 173
         $query=$dbConn->select()
158 174
         ->from(
@@ -160,18 +176,28 @@  discard block
 block discarded – undo
160 176
             array('value'=>'value'))
161 177
             ->where('name=?',$element);
162 178
             $return_row=$dbConn->fetchRow($query);
163
-            if ($return_row==null)  // value does not exists
179
+            if ($return_row==null) {
180
+            	// value does not exists
164 181
             {
165 182
                 $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
166
-                if ( ! isset($default[$element])) return null; // no default and not value
183
+            }
184
+                if ( ! isset($default[$element])) {
185
+                	return null;
186
+                }
187
+                // no default and not value
167 188
                 
168 189
                 $this->addDBConfigValue($element,$default[$element]);
169 190
                 return $default[$element];
170 191
             }
171
-            if ($return_row->value == null) // value id empty
192
+            if ($return_row->value == null) {
193
+            	// value id empty
172 194
             {
173 195
                 $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
174
-                if ( ! isset($default[$element])) return null; // no default and not value
196
+            }
197
+                if ( ! isset($default[$element])) {
198
+                	return null;
199
+                }
200
+                // no default and not value
175 201
                 $this->setDBConfigValue($element,$default[$element]);
176 202
                 return $default[$element];
177 203
             }
@@ -187,7 +213,9 @@  discard block
 block discarded – undo
187 213
     {
188 214
         
189 215
         $dbConn = $this->getDbConn();
190
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
216
+        if ($dbConn === null) {
217
+        	throw new \ErrorException('uncatched db error');
218
+        }
191 219
         
192 220
         $query=$dbConn->insert(
193 221
             $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
@@ -207,7 +235,9 @@  discard block
 block discarded – undo
207 235
     {
208 236
         
209 237
         $dbConn = $this->getDbConn();
210
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
238
+        if ($dbConn === null) {
239
+        	throw new \ErrorException('uncatched db error');
240
+        }
211 241
         
212 242
         $query=$dbConn->update(
213 243
             $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
Please login to merge, or discard this patch.
library/Trapdirector/TrapsActions/UIDatabase.php 1 patch
Indentation   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -19,30 +19,30 @@  discard block
 block discarded – undo
19 19
  */
20 20
 class DBException extends Exception
21 21
 {
22
-    /** @var array $returnArray */
23
-    private $returnArray;
22
+	/** @var array $returnArray */
23
+	private $returnArray;
24 24
     
25
-    /**
26
-     * Buil DBException
27
-     * @param array $retarray
28
-     * @param string $message
29
-     * @param int $code
30
-     * @param Exception $previous
31
-     */
32
-    public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null)
33
-    {
34
-        parent::__construct($message,$code,$previous);
35
-        $this->returnArray = $retarray;
36
-    }
25
+	/**
26
+	 * Buil DBException
27
+	 * @param array $retarray
28
+	 * @param string $message
29
+	 * @param int $code
30
+	 * @param Exception $previous
31
+	 */
32
+	public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null)
33
+	{
34
+		parent::__construct($message,$code,$previous);
35
+		$this->returnArray = $retarray;
36
+	}
37 37
     
38
-    /**
39
-     * Get exception array
40
-     * @return array
41
-     */
42
-    public function getArray()
43
-    {
44
-        return $this->returnArray;
45
-    }
38
+	/**
39
+	 * Get exception array
40
+	 * @return array
41
+	 */
42
+	public function getArray()
43
+	{
44
+		return $this->returnArray;
45
+	}
46 46
 }
47 47
 
48 48
 /**
@@ -57,272 +57,272 @@  discard block
 block discarded – undo
57 57
 class UIDatabase extends TrapDBQuery
58 58
 {
59 59
     
60
-    /** @var TrapsController $trapController TrapController 'parent' class */
61
-    protected  $trapController=null;
60
+	/** @var TrapsController $trapController TrapController 'parent' class */
61
+	protected  $trapController=null;
62 62
     
63
-    /** @var Selectable $trapDB Trap Database*/
64
-    protected $trapDB=null;
63
+	/** @var Selectable $trapDB Trap Database*/
64
+	protected $trapDB=null;
65 65
  
66
-    /** @var Selectable $trapDB Icinga IDO database*/
67
-    protected $idoDB=null;
66
+	/** @var Selectable $trapDB Icinga IDO database*/
67
+	protected $idoDB=null;
68 68
     
69
-    /** @var array $testResult */
70
-    protected $testResult;
69
+	/** @var array $testResult */
70
+	protected $testResult;
71 71
     
72
-    /**
73
-     * 
74
-     * @param TrapsController $trapCtrl
75
-     */
76
-    function __construct(TrapsController $trapCtrl)
77
-    {
78
-        $this->trapController=$trapCtrl;
79
-    }
72
+	/**
73
+	 * 
74
+	 * @param TrapsController $trapCtrl
75
+	 */
76
+	function __construct(TrapsController $trapCtrl)
77
+	{
78
+		$this->trapController=$trapCtrl;
79
+	}
80 80
     
81
-    protected function getTrapCtrl()
82
-    {
83
-        return $this->trapController;
84
-    }
81
+	protected function getTrapCtrl()
82
+	{
83
+		return $this->trapController;
84
+	}
85 85
     
86
-    /**
87
-     * Test if database version >= min database version
88
-     * 
89
-     * @param \Zend_Db_Adapter_Abstract $dbConn
90
-     * @param int $min Minimum version
91
-     * @param bool $test Test mode
92
-     * @param string $DBname Name of DB
93
-     * @return bool true if OK, false if version < min version
94
-     * @throws Exception if error and test = true
95
-     */
96
-    protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname)
97
-    {
98
-        try
99
-        {
100
-            $query = $dbAdapter->select()
101
-            ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value')
102
-            ->where('name=\'db_version\'');
103
-            $version=$dbAdapter->fetchRow($query);
104
-            if ( ($version == null) || ! property_exists($version,'value') )
105
-            {
106
-                if ($test === true) 
107
-                {
108
-                    $this->testResult = array(4,$DBname);
109
-                    return false;
110
-                }
111
-                $this->trapController->redirectNow('trapdirector/settings?dberror=4');
112
-                return false;
113
-            }
114
-            if ($version->value < $min)
115
-            {
116
-                if ($test === true) 
117
-                {
118
-                    $this->testResult = array(5,$version->value,$min);
119
-                    return false;
120
-                }
121
-                $this->trapController->redirectNow('trapdirector/settings?dberror=5');
122
-                return false;
123
-            }
124
-        }
125
-        catch (Exception $e)
126
-        {
127
-            if ($test === true) 
128
-            {
129
-                $this->testResult = array(3,$DBname,$e->getMessage());
130
-                return false;
131
-            }
132
-            $this->trapController->redirectNow('trapdirector/settings?dberror=4');
133
-            return false;
134
-        }
135
-        return true;
136
-    }
86
+	/**
87
+	 * Test if database version >= min database version
88
+	 * 
89
+	 * @param \Zend_Db_Adapter_Abstract $dbConn
90
+	 * @param int $min Minimum version
91
+	 * @param bool $test Test mode
92
+	 * @param string $DBname Name of DB
93
+	 * @return bool true if OK, false if version < min version
94
+	 * @throws Exception if error and test = true
95
+	 */
96
+	protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname)
97
+	{
98
+		try
99
+		{
100
+			$query = $dbAdapter->select()
101
+			->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value')
102
+			->where('name=\'db_version\'');
103
+			$version=$dbAdapter->fetchRow($query);
104
+			if ( ($version == null) || ! property_exists($version,'value') )
105
+			{
106
+				if ($test === true) 
107
+				{
108
+					$this->testResult = array(4,$DBname);
109
+					return false;
110
+				}
111
+				$this->trapController->redirectNow('trapdirector/settings?dberror=4');
112
+				return false;
113
+			}
114
+			if ($version->value < $min)
115
+			{
116
+				if ($test === true) 
117
+				{
118
+					$this->testResult = array(5,$version->value,$min);
119
+					return false;
120
+				}
121
+				$this->trapController->redirectNow('trapdirector/settings?dberror=5');
122
+				return false;
123
+			}
124
+		}
125
+		catch (Exception $e)
126
+		{
127
+			if ($test === true) 
128
+			{
129
+				$this->testResult = array(3,$DBname,$e->getMessage());
130
+				return false;
131
+			}
132
+			$this->trapController->redirectNow('trapdirector/settings?dberror=4');
133
+			return false;
134
+		}
135
+		return true;
136
+	}
137 137
     
138
-    /**	Get Database connexion
139
-     *	@param $DBname string DB name in resource.ini_ge
140
-     *	@param $test bool if set to true, returns error code and not database
141
-     *	@param $test_version bool if set to flase, does not test database version of trapDB
142
-     *  @throws DBException if test = true and error
143
-     *	@return Selectable|null : if test=false, returns DB connexion, else array(error_num,message) or null on error.
144
-     */
145
-    protected function getDbByName($DBname , $test = false , $test_version = true)
146
-    {
147
-        try
148
-        {
149
-            $dbconn = IcingaDbConnection::fromResourceName($DBname);
150
-        }
151
-        catch (Exception $e)
152
-        {
153
-            if ($test === true) 
154
-            {
155
-                throw new DBException(array(2,$DBname));
156
-            }
157
-            $this->trapController->redirectNow('trapdirector/settings?dberror=2');
158
-            return null;
159
-        }
138
+	/**	Get Database connexion
139
+	 *	@param $DBname string DB name in resource.ini_ge
140
+	 *	@param $test bool if set to true, returns error code and not database
141
+	 *	@param $test_version bool if set to flase, does not test database version of trapDB
142
+	 *  @throws DBException if test = true and error
143
+	 *	@return Selectable|null : if test=false, returns DB connexion, else array(error_num,message) or null on error.
144
+	 */
145
+	protected function getDbByName($DBname , $test = false , $test_version = true)
146
+	{
147
+		try
148
+		{
149
+			$dbconn = IcingaDbConnection::fromResourceName($DBname);
150
+		}
151
+		catch (Exception $e)
152
+		{
153
+			if ($test === true) 
154
+			{
155
+				throw new DBException(array(2,$DBname));
156
+			}
157
+			$this->trapController->redirectNow('trapdirector/settings?dberror=2');
158
+			return null;
159
+		}
160 160
         
161
-        try
162
-        {
163
-            $dbAdapter=$dbconn->getDbAdapter();
161
+		try
162
+		{
163
+			$dbAdapter=$dbconn->getDbAdapter();
164 164
             
165
-        }
166
-        catch (Exception $e)
167
-        {
168
-            if ($test === true)
169
-            {
170
-                throw new DBException(array(3,$DBname,$e->getMessage()));
171
-            }
172
-            $this->trapController->redirectNow('trapdirector/settings?dberror=3');
173
-            return null;
174
-        }
165
+		}
166
+		catch (Exception $e)
167
+		{
168
+			if ($test === true)
169
+			{
170
+				throw new DBException(array(3,$DBname,$e->getMessage()));
171
+			}
172
+			$this->trapController->redirectNow('trapdirector/settings?dberror=3');
173
+			return null;
174
+		}
175 175
         
176
-        if ($test_version == true) {
177
-            $testRet=$this->testDbVersion($dbAdapter, $this->trapController->getModuleConfig()->getDbMinVersion(), $test, $DBname);
178
-            if ($testRet !== true) 
179
-            {
180
-                throw new DBException($this->testResult);
181
-            }
182
-        }
176
+		if ($test_version == true) {
177
+			$testRet=$this->testDbVersion($dbAdapter, $this->trapController->getModuleConfig()->getDbMinVersion(), $test, $DBname);
178
+			if ($testRet !== true) 
179
+			{
180
+				throw new DBException($this->testResult);
181
+			}
182
+		}
183 183
         
184
-        return $dbconn;
185
-    }
184
+		return $dbconn;
185
+	}
186 186
 
187
-    /**
188
-     * Get Trap database
189
-     * @return Selectable|null : returns DB connexion or null on error.
190
-     */
191
-    public function getDb()
192
-    {
193
-        if ( $this->trapDB != null ) return $this->trapDB;
187
+	/**
188
+	 * Get Trap database
189
+	 * @return Selectable|null : returns DB connexion or null on error.
190
+	 */
191
+	public function getDb()
192
+	{
193
+		if ( $this->trapDB != null ) return $this->trapDB;
194 194
         
195 195
         
196
-        $dbresource=$this->trapController->Config()->get('config', 'database');
196
+		$dbresource=$this->trapController->Config()->get('config', 'database');
197 197
         
198
-        if ( ! $dbresource )
199
-        {
200
-            $this->trapController->redirectNow('trapdirector/settings?dberror=1');
201
-            return null;
202
-        }
198
+		if ( ! $dbresource )
199
+		{
200
+			$this->trapController->redirectNow('trapdirector/settings?dberror=1');
201
+			return null;
202
+		}
203 203
 
204
-        try {
205
-            $this->trapDB = $this->getDbByName($dbresource,false,true);
206
-        } catch (DBException $e) {
207
-            return null; // Should not happen as test = false
208
-        }
204
+		try {
205
+			$this->trapDB = $this->getDbByName($dbresource,false,true);
206
+		} catch (DBException $e) {
207
+			return null; // Should not happen as test = false
208
+		}
209 209
         
210
-        //$this->trapDB->getConnection();
210
+		//$this->trapDB->getConnection();
211 211
         
212
-        return $this->trapDB;
213
-    }
212
+		return $this->trapDB;
213
+	}
214 214
 
215
-    /**
216
-     * Get Zend adapter of DB.
217
-     * @return \Zend_Db_Adapter_Abstract|null
218
-     */
219
-    public function getDbConn()
220
-    {
221
-        if ($this->getDb() == null) return null;
222
-        return $this->getDb()->getConnection();
223
-    }
215
+	/**
216
+	 * Get Zend adapter of DB.
217
+	 * @return \Zend_Db_Adapter_Abstract|null
218
+	 */
219
+	public function getDbConn()
220
+	{
221
+		if ($this->getDb() == null) return null;
222
+		return $this->getDb()->getConnection();
223
+	}
224 224
     
225
-    /**
226
-     * Test Trap database
227
-     * @param boolean $test
228
-     * @throws DBException on error.
229
-     * @return \Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error.
230
-     */
231
-    public function testGetDb()
232
-    {       
233
-        $dbresource=$this->trapController->Config()->get('config', 'database');
225
+	/**
226
+	 * Test Trap database
227
+	 * @param boolean $test
228
+	 * @throws DBException on error.
229
+	 * @return \Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error.
230
+	 */
231
+	public function testGetDb()
232
+	{       
233
+		$dbresource=$this->trapController->Config()->get('config', 'database');
234 234
         
235
-        if ( ! $dbresource )
236
-        {
237
-                throw new DBException(array(1,''));
238
-        }
235
+		if ( ! $dbresource )
236
+		{
237
+				throw new DBException(array(1,''));
238
+		}
239 239
         
240
-        $this->trapDB = $this->getDbByName($dbresource,true,true);       
241
-        return;
242
-    }
240
+		$this->trapDB = $this->getDbByName($dbresource,true,true);       
241
+		return;
242
+	}
243 243
     
244 244
 
245
-    /**
246
-     * Get IDO Database
247
-     * @return \Zend_Db_Adapter_Abstract|NULL  returns DB connexion or null on error.
248
-     */
249
-    public function getIdoDb()
250
-    {
251
-        if ( $this->idoDB != null ) return $this->idoDB;
252
-        // TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
253
-        $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');;
245
+	/**
246
+	 * Get IDO Database
247
+	 * @return \Zend_Db_Adapter_Abstract|NULL  returns DB connexion or null on error.
248
+	 */
249
+	public function getIdoDb()
250
+	{
251
+		if ( $this->idoDB != null ) return $this->idoDB;
252
+		// TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
253
+		$dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');;
254 254
         
255
-        if ( ! $dbresource )
256
-        {
257
-            $this->trapController->redirectNow('trapdirector/settings?idodberror=1');
258
-            return null;
259
-        }
255
+		if ( ! $dbresource )
256
+		{
257
+			$this->trapController->redirectNow('trapdirector/settings?idodberror=1');
258
+			return null;
259
+		}
260 260
         
261
-        try
262
-        {
263
-            $dbconn = IcingaDbConnection::fromResourceName($dbresource);
264
-        }
265
-        catch (Exception $e)
266
-        {
267
-            $this->trapController->redirectNow('trapdirector/settings?idodberror=2');
268
-            return null;
269
-        }
261
+		try
262
+		{
263
+			$dbconn = IcingaDbConnection::fromResourceName($dbresource);
264
+		}
265
+		catch (Exception $e)
266
+		{
267
+			$this->trapController->redirectNow('trapdirector/settings?idodberror=2');
268
+			return null;
269
+		}
270 270
 
271
-        $this->idoDB = $dbconn;
272
-        return $this->idoDB;
273
-    }
271
+		$this->idoDB = $dbconn;
272
+		return $this->idoDB;
273
+	}
274 274
 
275 275
 
276
-    /**
277
-     * Get Zend adapter of DB.
278
-     * @return \Zend_Db_Adapter_Abstract|null
279
-     */
280
-    public function getIdoDbConn()
281
-    {
282
-        if ($this->getIdoDb() == null) return null;
283
-        return $this->getIdoDb()->getConnection();
284
-    }
276
+	/**
277
+	 * Get Zend adapter of DB.
278
+	 * @return \Zend_Db_Adapter_Abstract|null
279
+	 */
280
+	public function getIdoDbConn()
281
+	{
282
+		if ($this->getIdoDb() == null) return null;
283
+		return $this->getIdoDb()->getConnection();
284
+	}
285 285
     
286
-    /**
287
-     * Get IDO Database
288
-     * @param boolean $test
289
-     * @throws DBException on error
290
-     */
291
-    public function testGetIdoDb()
292
-    {
293
-        // TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
294
-        $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');;
286
+	/**
287
+	 * Get IDO Database
288
+	 * @param boolean $test
289
+	 * @throws DBException on error
290
+	 */
291
+	public function testGetIdoDb()
292
+	{
293
+		// TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
294
+		$dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');;
295 295
         
296
-        if ( ! $dbresource )
297
-        {
298
-            throw new DBException(array(1,'No database in config.ini'));
299
-        }
296
+		if ( ! $dbresource )
297
+		{
298
+			throw new DBException(array(1,'No database in config.ini'));
299
+		}
300 300
         
301
-        try
302
-        {
303
-            $dbconn = IcingaDbConnection::fromResourceName($dbresource);
304
-        }
305
-        catch (Exception $e)
306
-        {
307
-            throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") );
308
-        }
301
+		try
302
+		{
303
+			$dbconn = IcingaDbConnection::fromResourceName($dbresource);
304
+		}
305
+		catch (Exception $e)
306
+		{
307
+			throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") );
308
+		}
309 309
                
310
-        try
311
-        {
312
-            $query = $dbconn->select()
313
-            ->from('icinga_dbversion',array('version'));
314
-            $version=$dbconn->fetchRow($query);
315
-            if ( ($version == null) || ! property_exists($version,'version') )
316
-            {
317
-                throw new DBException( array(4,"$dbresource does not look like an IDO database"));
318
-            }
319
-        }
320
-        catch (Exception $e)
321
-        {
322
-            throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage()));
323
-        }
310
+		try
311
+		{
312
+			$query = $dbconn->select()
313
+			->from('icinga_dbversion',array('version'));
314
+			$version=$dbconn->fetchRow($query);
315
+			if ( ($version == null) || ! property_exists($version,'version') )
316
+			{
317
+				throw new DBException( array(4,"$dbresource does not look like an IDO database"));
318
+			}
319
+		}
320
+		catch (Exception $e)
321
+		{
322
+			throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage()));
323
+		}
324 324
         
325
-        return;
326
-    }
325
+		return;
326
+	}
327 327
     
328 328
 }
329 329
\ No newline at end of file
Please login to merge, or discard this patch.