Passed
Push — master ( 409614...84c1e8 )
by Patrick
02:14
created
application/controllers/HelperController.php 3 patches
Indentation   +124 added lines, -124 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
 		
@@ -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
@@ -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
-	        $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
430
-	        $trap = new Trap($icingaweb2_etc);
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
+			$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
430
+			$trap = new Trap($icingaweb2_etc);
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->setDBConfigValue('db_remove_days',$days);
246
+				$this->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->setDBConfigValue('log_destination',$destination);
323
-			$this->setDBConfigValue('log_file',$file);
324
-			$this->setDBConfigValue('log_level',$level);
322
+			$this->setDBConfigValue('log_destination', $destination);
323
+			$this->setDBConfigValue('log_file', $file);
324
+			$this->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
 	        $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
430
-	        $trap = new Trap($icingaweb2_etc);
430
+	        $trap=new Trap($icingaweb2_etc);
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->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->setDBConfigValue('log_destination',$destination);
323 312
 			$this->setDBConfigValue('log_file',$file);
324 313
 			$this->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.