Passed
Push — master ( 782f23...8a769b )
by Patrick
02:09
created
application/controllers/HandlerController.php 3 patches
Indentation   +250 added lines, -251 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->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->getHostByName($this->view->hostname);
203
+		// Check if hostname still exists
204
+		$host_get=$this->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->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
 		}		
@@ -465,7 +464,7 @@  discard block
 block discarded – undo
465 464
 			$isHostGroup=($params['hostgroup']['val'] == 1)?true:false;
466 465
 			if (! $isHostGroup ) 
467 466
 			{  // checks if selection by host 
468
-			    $hostAddr=$this->getUIDatabase()->getHostInfoByID($params['hostid']['val']);
467
+				$hostAddr=$this->getUIDatabase()->getHostInfoByID($params['hostid']['val']);
469 468
 				$params['ip4']['val']=$hostAddr->ip4;
470 469
 				$params['ip6']['val']=$hostAddr->ip6;
471 470
 				$checkHostName=$hostAddr->name;
@@ -476,8 +475,8 @@  discard block
 block discarded – undo
476 475
 				}
477 476
 				if (!is_numeric($params['serviceid']['val']))
478 477
 				{
479
-				    $this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val']));
480
-				    return;
478
+					$this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val']));
479
+					return;
481 480
 				}
482 481
 				$serviceName=$this->getUIDatabase()->getObjectNameByid($params['serviceid']['val']);
483 482
 				if ($params['service_name']['val'] != $serviceName->name2)
@@ -488,7 +487,7 @@  discard block
 block discarded – undo
488 487
 			}
489 488
 			else
490 489
 			{
491
-			    $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']);
490
+				$object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']);
492 491
 				if ($params['host_name']['val'] != $object->name1)
493 492
 				{
494 493
 					$this->_helper->json(array('status'=>"Invalid object group id : Please re enter service"));
@@ -509,11 +508,11 @@  discard block
 block discarded – undo
509 508
 			// echo '<br>';	print_r($dbparams);echo '<br>';
510 509
 			if ($params['db_rule']['val'] == -1 ) 
511 510
 			{
512
-			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
511
+				$ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
513 512
 			}
514 513
 			else
515 514
 			{
516
-			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
515
+				$this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
517 516
 				$ruleID=$params['db_rule']['val'];
518 517
 			}
519 518
 		}
@@ -527,9 +526,9 @@  discard block
 block discarded – undo
527 526
 	}
528 527
 
529 528
 	/** Get trap detail by trapid. 
530
-	*	@param integer $trapid : id of trap in received table
531
-	*	@return array (objects)
532
-	*/
529
+	 *	@param integer $trapid : id of trap in received table
530
+	 *	@return array (objects)
531
+	 */
533 532
 	protected function getTrapDetail($trapid) 
534 533
 	{
535 534
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -545,14 +544,14 @@  discard block
 block discarded – undo
545 544
 		}
546 545
 		try
547 546
 		{		
548
-		    $query = $dbConn->select()
547
+			$query = $dbConn->select()
549 548
 				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
550 549
 				->where('id=?',$trapid);
551 550
 				$trapDetail=$dbConn->fetchRow($query);
552 551
 			if ( $trapDetail == null ) 
553 552
 			{
554
-			    $trapDetail = 'NULL';
555
-			    throw new Exception('No traps was found with id = '.$trapid);
553
+				$trapDetail = 'NULL';
554
+				throw new Exception('No traps was found with id = '.$trapid);
556 555
 			}
557 556
 		}
558 557
 		catch (Exception $e)
@@ -566,9 +565,9 @@  discard block
 block discarded – undo
566 565
 	}
567 566
 
568 567
 	/** Get trap objects
569
-	*	@param integer $trapid : trap id
570
-	* 	@return array : full column in db of trap id
571
-	*/
568
+	 *	@param integer $trapid : trap id
569
+	 * 	@return array : full column in db of trap id
570
+	 */
572 571
 	protected function getTrapobjects($trapid)
573 572
 	{	
574 573
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -584,7 +583,7 @@  discard block
 block discarded – undo
584 583
 		}
585 584
 		try
586 585
 		{		
587
-		    $query = $dbConn->select()
586
+			$query = $dbConn->select()
588 587
 				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
589 588
 				->where('trap_id=?',$trapid);
590 589
 				$trapDetail=$dbConn->fetchAll($query);
@@ -600,10 +599,10 @@  discard block
 block discarded – undo
600 599
 	}
601 600
 
602 601
 	/** Get rule detail by ruleid.
603
-	*	@param integer $ruleid int id of rule in rule table
604
-	*	@return object|array : column objects in db 
605
-	*
606
-	*/
602
+	 *	@param integer $ruleid int id of rule in rule table
603
+	 *	@return object|array : column objects in db 
604
+	 *
605
+	 */
607 606
 	protected function getRuleDetail($ruleid) 
608 607
 	{
609 608
 		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
@@ -614,7 +613,7 @@  discard block
 block discarded – undo
614 613
 		// ***************  Get main data
615 614
 		try
616 615
 		{		
617
-		    $query = $dbConn->select()
616
+			$query = $dbConn->select()
618 617
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
619 618
 				->where('id=?',$ruleid);
620 619
 			$ruleDetail=$dbConn->fetchRow($query);
@@ -631,7 +630,7 @@  discard block
 block discarded – undo
631 630
 	}
632 631
 
633 632
 	/** Setup tabs for rules 
634
-	*/
633
+	 */
635 634
 	protected function prepareTabs()
636 635
 	{
637 636
 		return $this->getTabs()->add('status', array(
Please login to merge, or discard this patch.
Spacing   +82 added lines, -82 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->getUIDatabase()->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->getUIDatabase()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
218
-	        if (count($serviceID) ==0)
217
+	        $serviceID=$this->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->getHostInfoByID($params['hostid']['val']);
469 469
 				$params['ip4']['val']=$hostAddr->ip4;
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
 				}
477 477
 				if (!is_numeric($params['serviceid']['val']))
478 478
 				{
479
-				    $this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val']));
479
+				    $this->_helper->json(array('status'=>"Invalid service id ".$params['serviceid']['val']));
480 480
 				    return;
481 481
 				}
482 482
 				$serviceName=$this->getUIDatabase()->getObjectNameByid($params['serviceid']['val']);
@@ -495,25 +495,25 @@  discard block
 block discarded – undo
495 495
 					return;					
496 496
 				}
497 497
 				// Put param in correct column (group_name)
498
-				$params['host_group_name']['val'] = $params['host_name']['val'];
498
+				$params['host_group_name']['val']=$params['host_name']['val'];
499 499
 				$params['host_name']['val']=null;
500 500
 			}
501 501
 			$dbparams=array();
502 502
 			foreach ($params as $key=>$val)
503 503
 			{
504
-				if ($val['db']==true )
504
+				if ($val['db'] == true)
505 505
 				{
506
-					$dbparams[$key] = $val['val'];
506
+					$dbparams[$key]=$val['val'];
507 507
 				}
508 508
 			}
509 509
 			// echo '<br>';	print_r($dbparams);echo '<br>';
510
-			if ($params['db_rule']['val'] == -1 ) 
510
+			if ($params['db_rule']['val'] == -1) 
511 511
 			{
512 512
 			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
513 513
 			}
514 514
 			else
515 515
 			{
516
-			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
516
+			    $this->getUIDatabase()->updateHandlerRule($dbparams, $params['db_rule']['val']);
517 517
 				$ruleID=$params['db_rule']['val'];
518 518
 			}
519 519
 		}
@@ -532,10 +532,10 @@  discard block
 block discarded – undo
532 532
 	*/
533 533
 	protected function getTrapDetail($trapid) 
534 534
 	{
535
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
535
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
536 536
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
537 537
 		
538
-		$dbConn = $this->getUIDatabase()->getDbConn();
538
+		$dbConn=$this->getUIDatabase()->getDbConn();
539 539
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
540 540
 		// ***************  Get main data
541 541
 		// extract columns and titles;
@@ -545,19 +545,19 @@  discard block
 block discarded – undo
545 545
 		}
546 546
 		try
547 547
 		{		
548
-		    $query = $dbConn->select()
549
-				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
550
-				->where('id=?',$trapid);
548
+		    $query=$dbConn->select()
549
+				->from($this->getModuleConfig()->getTrapTableName(), $elmts)
550
+				->where('id=?', $trapid);
551 551
 				$trapDetail=$dbConn->fetchRow($query);
552
-			if ( $trapDetail == null ) 
552
+			if ($trapDetail == null) 
553 553
 			{
554
-			    $trapDetail = 'NULL';
554
+			    $trapDetail='NULL';
555 555
 			    throw new Exception('No traps was found with id = '.$trapid);
556 556
 			}
557 557
 		}
558 558
 		catch (Exception $e)
559 559
 		{
560
-			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
560
+			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail, true), $e->getMessage());
561 561
 			return;
562 562
 		}
563 563
 
@@ -571,10 +571,10 @@  discard block
 block discarded – undo
571 571
 	*/
572 572
 	protected function getTrapobjects($trapid)
573 573
 	{	
574
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
574
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
575 575
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
576 576
 		
577
-		$dbConn = $this->getUIDatabase()->getDbConn();
577
+		$dbConn=$this->getUIDatabase()->getDbConn();
578 578
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
579 579
 		// ***************  Get object data
580 580
 		// extract columns and titles;
@@ -584,15 +584,15 @@  discard block
 block discarded – undo
584 584
 		}
585 585
 		try
586 586
 		{		
587
-		    $query = $dbConn->select()
588
-				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
589
-				->where('trap_id=?',$trapid);
587
+		    $query=$dbConn->select()
588
+				->from($this->moduleConfig->getTrapDataTableName(), $data_elmts)
589
+				->where('trap_id=?', $trapid);
590 590
 				$trapDetail=$dbConn->fetchAll($query);
591 591
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
592 592
 		}
593 593
 		catch (Exception $e)
594 594
 		{
595
-			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
595
+			$this->displayExitError('Add handler : get trap data detail : ', $e->getMessage());
596 596
 			return array();
597 597
 		}
598 598
 
@@ -606,24 +606,24 @@  discard block
 block discarded – undo
606 606
 	*/
607 607
 	protected function getRuleDetail($ruleid) 
608 608
 	{
609
-		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
609
+		if (!preg_match('/^[0-9]+$/', $ruleid)) { throw new Exception('Invalid id'); }
610 610
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
611 611
 		
612
-		$dbConn = $this->getUIDatabase()->getDbConn();
612
+		$dbConn=$this->getUIDatabase()->getDbConn();
613 613
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
614 614
 		// ***************  Get main data
615 615
 		try
616 616
 		{		
617
-		    $query = $dbConn->select()
618
-				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
619
-				->where('id=?',$ruleid);
617
+		    $query=$dbConn->select()
618
+				->from($this->getModuleConfig()->getTrapRuleName(), $queryArray)
619
+				->where('id=?', $ruleid);
620 620
 			$ruleDetail=$dbConn->fetchRow($query);
621
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
621
+			if ($ruleDetail == null) throw new Exception('No rule was found with id = '.$ruleid);
622 622
 		}
623 623
 		catch (Exception $e)
624 624
 		{
625
-			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
626
-			throw new Exception('Error : ' . $e->getMessage());
625
+			$this->displayExitError('Update handler : get rule detail', $e->getMessage());
626
+			throw new Exception('Error : '.$e->getMessage());
627 627
 		}
628 628
 
629 629
 		return $ruleDetail;
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
 	{
637 637
 		return $this->getTabs()->add('status', array(
638 638
 			'label' => $this->translate('Traps'),
639
-			'url'   => $this->getModuleConfig()->urlPath() . '/handler')
639
+			'url'   => $this->getModuleConfig()->urlPath().'/handler')
640 640
 		);
641 641
 	} 
642 642
 	
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->getUIDatabase()->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->getUIDatabase()->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 !="")
@@ -485,8 +485,7 @@  discard block
 block discarded – undo
485 485
 					$this->_helper->json(array('status'=>"Invalid service id : Please re enter service"));
486 486
 					return;
487 487
 				}
488
-			}
489
-			else
488
+			} else
490 489
 			{
491 490
 			    $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']);
492 491
 				if ($params['host_name']['val'] != $object->name1)
@@ -510,14 +509,12 @@  discard block
 block discarded – undo
510 509
 			if ($params['db_rule']['val'] == -1 ) 
511 510
 			{
512 511
 			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
513
-			}
514
-			else
512
+			} else
515 513
 			{
516 514
 			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
517 515
 				$ruleID=$params['db_rule']['val'];
518 516
 			}
519
-		}
520
-		catch (Exception $e)
517
+		} catch (Exception $e)
521 518
 		{
522 519
 			$this->_helper->json(array('status'=>$e->getMessage()));
523 520
 			return;
@@ -536,7 +533,9 @@  discard block
 block discarded – undo
536 533
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
537 534
 		
538 535
 		$dbConn = $this->getUIDatabase()->getDbConn();
539
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
536
+		if ($dbConn === null) {
537
+			throw new \ErrorException('uncatched db error');
538
+		}
540 539
 		// ***************  Get main data
541 540
 		// extract columns and titles;
542 541
 		$elmts=NULL;
@@ -554,8 +553,7 @@  discard block
 block discarded – undo
554 553
 			    $trapDetail = 'NULL';
555 554
 			    throw new Exception('No traps was found with id = '.$trapid);
556 555
 			}
557
-		}
558
-		catch (Exception $e)
556
+		} catch (Exception $e)
559 557
 		{
560 558
 			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
561 559
 			return;
@@ -575,7 +573,9 @@  discard block
 block discarded – undo
575 573
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
576 574
 		
577 575
 		$dbConn = $this->getUIDatabase()->getDbConn();
578
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
576
+		if ($dbConn === null) {
577
+			throw new \ErrorException('uncatched db error');
578
+		}
579 579
 		// ***************  Get object data
580 580
 		// extract columns and titles;
581 581
 		$data_elmts=NULL;
@@ -589,8 +589,7 @@  discard block
 block discarded – undo
589 589
 				->where('trap_id=?',$trapid);
590 590
 				$trapDetail=$dbConn->fetchAll($query);
591 591
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
592
-		}
593
-		catch (Exception $e)
592
+		} catch (Exception $e)
594 593
 		{
595 594
 			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
596 595
 			return array();
@@ -610,7 +609,9 @@  discard block
 block discarded – undo
610 609
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
611 610
 		
612 611
 		$dbConn = $this->getUIDatabase()->getDbConn();
613
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
612
+		if ($dbConn === null) {
613
+			throw new \ErrorException('uncatched db error');
614
+		}
614 615
 		// ***************  Get main data
615 616
 		try
616 617
 		{		
@@ -618,9 +619,10 @@  discard block
 block discarded – undo
618 619
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
619 620
 				->where('id=?',$ruleid);
620 621
 			$ruleDetail=$dbConn->fetchRow($query);
621
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
622
-		}
623
-		catch (Exception $e)
622
+			if ( $ruleDetail == null ) {
623
+				throw new Exception('No rule was found with id = '.$ruleid);
624
+			}
625
+		} catch (Exception $e)
624 626
 		{
625 627
 			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
626 628
 			throw new Exception('Error : ' . $e->getMessage());
Please login to merge, or discard this patch.
tests/expr_test.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
   $inputStream=fopen('php://stdin', 'r');
21 21
   if ($inputStream === false)
22 22
   {
23
-      exit(1);
23
+	  exit(1);
24 24
   }
25 25
   $rule=chop(fgets($inputStream));
26 26
 } else
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -5,18 +5,18 @@  discard block
 block discarded – undo
5 5
 
6 6
 require_once 'bin/trap_class.php';
7 7
 
8
-$options = getopt("r:d:");
8
+$options=getopt("r:d:");
9 9
 
10
-$icingaweb2Etc=(array_key_exists('d',$options))?$options['d']:"/etc/icingaweb2";
10
+$icingaweb2Etc=(array_key_exists('d', $options)) ? $options['d'] : "/etc/icingaweb2";
11 11
 
12
-$debugLevel=4;// 0=No output 1=critical 2=warning 3=trace 4=ALL
12
+$debugLevel=4; // 0=No output 1=critical 2=warning 3=trace 4=ALL
13 13
 
14
-$trap = new trap($icingaweb2Etc);
15
-$trap->setLogging($debugLevel,'display');
14
+$trap=new trap($icingaweb2Etc);
15
+$trap->setLogging($debugLevel, 'display');
16 16
 
17
-$input=array_key_exists('r',$options);
17
+$input=array_key_exists('r', $options);
18 18
 
19
-if (! $input) {
19
+if (!$input) {
20 20
   $inputStream=fopen('php://stdin', 'r');
21 21
   if ($inputStream === false)
22 22
   {
@@ -31,10 +31,10 @@  discard block
 block discarded – undo
31 31
   $rule=$trap->ruleClass->eval_cleanup($rule);
32 32
   //echo 'After cleanup : #'.$rule."#\n";
33 33
   $item=0;
34
-  $val = $trap->ruleClass->evaluation($rule,$item);
35
-  if ($val==true) { printf( "true"); } else { printf( "false");}
34
+  $val=$trap->ruleClass->evaluation($rule, $item);
35
+  if ($val == true) { printf("true"); } else { printf("false"); }
36 36
   printf("\n");
37 37
 }
38
-catch (Exception $e) { printf("%s\n",$e->getMessage()); exit(1);}
38
+catch (Exception $e) { printf("%s\n", $e->getMessage()); exit(1); }
39 39
 
40 40
 exit(0);
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -23,8 +23,9 @@  discard block
 block discarded – undo
23 23
       exit(1);
24 24
   }
25 25
   $rule=chop(fgets($inputStream));
26
-} else
26
+} else {
27 27
   $rule=$options['r'];
28
+}
28 29
 
29 30
 try
30 31
 {
@@ -34,7 +35,6 @@  discard block
 block discarded – undo
34 35
   $val = $trap->ruleClass->evaluation($rule,$item);
35 36
   if ($val==true) { printf( "true"); } else { printf( "false");}
36 37
   printf("\n");
37
-}
38
-catch (Exception $e) { printf("%s\n",$e->getMessage()); exit(1);}
38
+} catch (Exception $e) { printf("%s\n",$e->getMessage()); exit(1);}
39 39
 
40 40
 exit(0);
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/Rule.php 3 patches
Indentation   +253 added lines, -253 removed lines patch added patch discarded remove patch
@@ -6,291 +6,291 @@
 block discarded – undo
6 6
 
7 7
 class Rule
8 8
 {
9
-    use \RuleUtils;
9
+	use \RuleUtils;
10 10
     
11
-    /** @var Logging $logging logging class*/
12
-    protected $logging;
11
+	/** @var Logging $logging logging class*/
12
+	protected $logging;
13 13
     
14
-    /** @var Trap $trapClass */
15
-    protected $trapClass;
14
+	/** @var Trap $trapClass */
15
+	protected $trapClass;
16 16
     
17 17
 
18
-    /**
19
-     * Setup Rule Class
20
-     * @param Trap $trapClass : To get logging class & plugin class
21
-     */
22
-    function __construct($trapClass)
23
-    {
24
-        $this->trapClass=$trapClass;
25
-        $this->logging=$trapClass->logging;
26
-    }
18
+	/**
19
+	 * Setup Rule Class
20
+	 * @param Trap $trapClass : To get logging class & plugin class
21
+	 */
22
+	function __construct($trapClass)
23
+	{
24
+		$this->trapClass=$trapClass;
25
+		$this->logging=$trapClass->logging;
26
+	}
27 27
     
28 28
     
29
-    protected function eval_getElement($rule,&$item)
30
-    {
31
-        if ($item >= strlen($rule))
32
-        {
33
-            throw new Exception("Early end of string ".$rule ." at " .$item );
34
-        }
35
-        while ($rule[$item]==' ') $item++;
36
-        if (preg_match('/[\-0-9\.]/',$rule[$item]))
37
-        { // number
38
-            return $this->get_number($rule, $item);
39
-        }
40
-        if ($rule[$item] == '"')
41
-        { // string
42
-            return $this->get_string($rule, $item);
43
-        }
29
+	protected function eval_getElement($rule,&$item)
30
+	{
31
+		if ($item >= strlen($rule))
32
+		{
33
+			throw new Exception("Early end of string ".$rule ." at " .$item );
34
+		}
35
+		while ($rule[$item]==' ') $item++;
36
+		if (preg_match('/[\-0-9\.]/',$rule[$item]))
37
+		{ // number
38
+			return $this->get_number($rule, $item);
39
+		}
40
+		if ($rule[$item] == '"')
41
+		{ // string
42
+			return $this->get_string($rule, $item);
43
+		}
44 44
         
45
-        if ($rule[$item] == '(')
46
-        { // grouping
47
-            return $this->get_group($rule, $item);
48
-        }
49
-        if ($rule[$item] == '_')
50
-        { // function
51
-            return $this->get_function($rule, $item);
52
-        }
53
-        throw new Exception("number/string not found in ".$rule ." at " .$item . ' : ' .$rule[$item]);
45
+		if ($rule[$item] == '(')
46
+		{ // grouping
47
+			return $this->get_group($rule, $item);
48
+		}
49
+		if ($rule[$item] == '_')
50
+		{ // function
51
+			return $this->get_function($rule, $item);
52
+		}
53
+		throw new Exception("number/string not found in ".$rule ." at " .$item . ' : ' .$rule[$item]);
54 54
         
55
-    }
55
+	}
56 56
     
57
-    protected function eval_getNext($rule,$item,$tok)
58
-    {
59
-        while (
60
-            ($rule[$item] != $tok ) 
61
-            && ($item < strlen($rule))) 
62
-        { 
63
-            $item++;
64
-        }
65
-        if ($item==strlen($rule)) {
66
-            throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item);
67
-        }
68
-        return $item+1;
69
-    }
57
+	protected function eval_getNext($rule,$item,$tok)
58
+	{
59
+		while (
60
+			($rule[$item] != $tok ) 
61
+			&& ($item < strlen($rule))) 
62
+		{ 
63
+			$item++;
64
+		}
65
+		if ($item==strlen($rule)) {
66
+			throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item);
67
+		}
68
+		return $item+1;
69
+	}
70 70
     
71
-    protected function eval_getOper($rule,&$item)
72
-    {
73
-        while ($rule[$item]==' ') $item++;
74
-        switch ($rule[$item])
75
-        {
76
-            case '<':
77
-                if ($rule[$item+1]=='=') { $item+=2; return array(0,"<=");}
78
-                $item++; return array(0,"<");
79
-            case '>':
80
-                if ($rule[$item+1]=='=') { $item+=2; return array(0,">=");}
81
-                $item++; return array(0,">");
82
-            case '=':
83
-                $item++; return array(0,"=");
84
-            case '!':
85
-                if ($rule[$item+1]=='=') { $item+=2; return array(0,"!=");}
86
-                throw new Exception("Erreur in expr - incorrect operator '!'  found in ".$rule ." at " .$item);
87
-            case '~':
88
-                $item++; return array(0,"~");
89
-            case '|':
90
-                $item++; return array(1,"|");
91
-            case '&':
92
-                $item++; return array(1,"&");
93
-            default	:
94
-                throw new Exception("Erreur in expr - operator not found in ".$rule ." at " .$item);
95
-        }
96
-    }
71
+	protected function eval_getOper($rule,&$item)
72
+	{
73
+		while ($rule[$item]==' ') $item++;
74
+		switch ($rule[$item])
75
+		{
76
+			case '<':
77
+				if ($rule[$item+1]=='=') { $item+=2; return array(0,"<=");}
78
+				$item++; return array(0,"<");
79
+			case '>':
80
+				if ($rule[$item+1]=='=') { $item+=2; return array(0,">=");}
81
+				$item++; return array(0,">");
82
+			case '=':
83
+				$item++; return array(0,"=");
84
+			case '!':
85
+				if ($rule[$item+1]=='=') { $item+=2; return array(0,"!=");}
86
+				throw new Exception("Erreur in expr - incorrect operator '!'  found in ".$rule ." at " .$item);
87
+			case '~':
88
+				$item++; return array(0,"~");
89
+			case '|':
90
+				$item++; return array(1,"|");
91
+			case '&':
92
+				$item++; return array(1,"&");
93
+			default	:
94
+				throw new Exception("Erreur in expr - operator not found in ".$rule ." at " .$item);
95
+		}
96
+	}
97 97
     
98
-    private function check_negate_first($rule,&$item)
99
-    {
100
-        if ( $rule[$item] == '!') // If '!' found, negate next expression.
101
-        {
102
-            $item++;
103
-            return true;
104
-        }
105
-        else
106
-        {
107
-            return false;
108
-        }
109
-    }
98
+	private function check_negate_first($rule,&$item)
99
+	{
100
+		if ( $rule[$item] == '!') // If '!' found, negate next expression.
101
+		{
102
+			$item++;
103
+			return true;
104
+		}
105
+		else
106
+		{
107
+			return false;
108
+		}
109
+	}
110 110
 
111
-    private function do_compare($val1,$val2,$comp,$negate)
112
-    {
113
-        switch ($comp){
114
-            case '<':	$retVal= ($val1 < $val2); break;
115
-            case '<=':	$retVal= ($val1 <= $val2); break;
116
-            case '>':	$retVal= ($val1 > $val2); break;
117
-            case '>=':	$retVal= ($val1 >= $val2); break;
118
-            case '=':	$retVal= ($val1 == $val2); break;
119
-            case '!=':	$retVal= ($val1 != $val2); break;
120
-            case '~':	$retVal= (preg_match('/'.preg_replace('/"/','',$val2).'/',$val1)); break;
121
-            case '|':	$retVal= ($val1 || $val2); break;
122
-            case '&':	$retVal= ($val1 && $val2); break;
123
-            default:  throw new Exception("Error in expression - unknown comp : ".$comp);
124
-        }
125
-        if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression
111
+	private function do_compare($val1,$val2,$comp,$negate)
112
+	{
113
+		switch ($comp){
114
+			case '<':	$retVal= ($val1 < $val2); break;
115
+			case '<=':	$retVal= ($val1 <= $val2); break;
116
+			case '>':	$retVal= ($val1 > $val2); break;
117
+			case '>=':	$retVal= ($val1 >= $val2); break;
118
+			case '=':	$retVal= ($val1 == $val2); break;
119
+			case '!=':	$retVal= ($val1 != $val2); break;
120
+			case '~':	$retVal= (preg_match('/'.preg_replace('/"/','',$val2).'/',$val1)); break;
121
+			case '|':	$retVal= ($val1 || $val2); break;
122
+			case '&':	$retVal= ($val1 && $val2); break;
123
+			default:  throw new Exception("Error in expression - unknown comp : ".$comp);
124
+		}
125
+		if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression
126 126
         
127
-        return $retVal;
128
-    }
127
+		return $retVal;
128
+	}
129 129
     
130
-    /** Evaluation : makes token and evaluate.
131
-     *	Public function for expressions testing
132
-     *	accepts : < > = <= >= !=  (typec = 0)
133
-     *	operators : & | (typec=1)
134
-     *	with : integers/float  (type 0) or strings "" (type 1) or results (type 2)
135
-     *   comparison int vs strings will return null (error)
136
-     *	return : bool or null on error
137
-     */
138
-    public function evaluation($rule,&$item)
139
-    {
140
-        //echo "Evaluation of ".substr($rule,$item)."\n";
141
-        $negate=$this->check_negate_first($rule, $item);
142
-        // First element : number, string or ()
143
-        list($type1,$val1) = $this->eval_getElement($rule,$item);
144
-        //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n";
130
+	/** Evaluation : makes token and evaluate.
131
+	 *	Public function for expressions testing
132
+	 *	accepts : < > = <= >= !=  (typec = 0)
133
+	 *	operators : & | (typec=1)
134
+	 *	with : integers/float  (type 0) or strings "" (type 1) or results (type 2)
135
+	 *   comparison int vs strings will return null (error)
136
+	 *	return : bool or null on error
137
+	 */
138
+	public function evaluation($rule,&$item)
139
+	{
140
+		//echo "Evaluation of ".substr($rule,$item)."\n";
141
+		$negate=$this->check_negate_first($rule, $item);
142
+		// First element : number, string or ()
143
+		list($type1,$val1) = $this->eval_getElement($rule,$item);
144
+		//echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n";
145 145
         
146
-        if ($item==strlen($rule)) // If only element, return value, but only boolean
147
-        {
148
-            if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule);
149
-            if ($negate === true) $val1= ! $val1;
150
-            return $val1;
151
-        }
146
+		if ($item==strlen($rule)) // If only element, return value, but only boolean
147
+		{
148
+			if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule);
149
+			if ($negate === true) $val1= ! $val1;
150
+			return $val1;
151
+		}
152 152
         
153
-        // Second element : operator
154
-        list($typec,$comp) = $this->eval_getOper($rule,$item);
155
-        //echo "Comp : ".$comp." : ".substr($rule,$item)."\n";
153
+		// Second element : operator
154
+		list($typec,$comp) = $this->eval_getOper($rule,$item);
155
+		//echo "Comp : ".$comp." : ".substr($rule,$item)."\n";
156 156
         
157
-        // Third element : number, string or ()
158
-        if ( $rule[$item] == '!') // starts with a ! so evaluate whats next
159
-        {
160
-            $item++;
161
-            if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule);
162
-            $val2= ! $this->evaluation($rule,$item);
163
-            $type2=2; // result is a boolean
164
-        }
165
-        else
166
-        {
167
-            list($type2,$val2) = $this->eval_getElement($rule,$item);
168
-        }
169
-        //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n";
157
+		// Third element : number, string or ()
158
+		if ( $rule[$item] == '!') // starts with a ! so evaluate whats next
159
+		{
160
+			$item++;
161
+			if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule);
162
+			$val2= ! $this->evaluation($rule,$item);
163
+			$type2=2; // result is a boolean
164
+		}
165
+		else
166
+		{
167
+			list($type2,$val2) = $this->eval_getElement($rule,$item);
168
+		}
169
+		//echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n";
170 170
         
171
-        if ($type1!=$type2)  // cannot compare different types
172
-        {
173
-            throw new Exception("Cannot compare string & number : ".$rule);
174
-        }
175
-        if ($typec==1 && $type1 !=2) // cannot use & or | with string/number
176
-        {
177
-            throw new Exception("Cannot use boolean operators with string & number : ".$rule);
178
-        }
171
+		if ($type1!=$type2)  // cannot compare different types
172
+		{
173
+			throw new Exception("Cannot compare string & number : ".$rule);
174
+		}
175
+		if ($typec==1 && $type1 !=2) // cannot use & or | with string/number
176
+		{
177
+			throw new Exception("Cannot use boolean operators with string & number : ".$rule);
178
+		}
179 179
         
180
-        $retVal = $this->do_compare($val1, $val2, $comp, $negate);
180
+		$retVal = $this->do_compare($val1, $val2, $comp, $negate);
181 181
         
182
-        if ($item==strlen($rule)) return $retVal; // End of string : return evaluation
183
-        // check for logical operator :
184
-        switch ($rule[$item])
185
-        {
186
-            case '|':	$item++; return ($retVal || $this->evaluation($rule,$item) );
187
-            case '&':	$item++; return ($retVal && $this->evaluation($rule,$item) );
182
+		if ($item==strlen($rule)) return $retVal; // End of string : return evaluation
183
+		// check for logical operator :
184
+		switch ($rule[$item])
185
+		{
186
+			case '|':	$item++; return ($retVal || $this->evaluation($rule,$item) );
187
+			case '&':	$item++; return ($retVal && $this->evaluation($rule,$item) );
188 188
             
189
-            default:  throw new Exception("Erreur in expr - garbadge at end of expression : ".$rule[$item]);
190
-        }
191
-    }
189
+			default:  throw new Exception("Erreur in expr - garbadge at end of expression : ".$rule[$item]);
190
+		}
191
+	}
192 192
     
193
-    // Remove all whitespaces (when not quoted)
194
-    public function eval_cleanup($rule)
195
-    {
196
-        $item=0;
197
-        $rule2='';
198
-        while ($item < strlen($rule))
199
-        {
200
-            if ($rule[$item]==' ') { $item++; continue; }
201
-            if ($rule[$item]=='"')
202
-            {
203
-                $rule2.=$rule[$item];
204
-                $item++;
205
-                while (($item < strlen($rule)) && ($rule[$item]!='"') )
206
-                {
207
-                    $rule2.=$rule[$item];
208
-                    $item++;
209
-                }
210
-                if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item);
211
-                $rule2.=$rule[$item];
212
-                $item++;
213
-                continue;
214
-            }
193
+	// Remove all whitespaces (when not quoted)
194
+	public function eval_cleanup($rule)
195
+	{
196
+		$item=0;
197
+		$rule2='';
198
+		while ($item < strlen($rule))
199
+		{
200
+			if ($rule[$item]==' ') { $item++; continue; }
201
+			if ($rule[$item]=='"')
202
+			{
203
+				$rule2.=$rule[$item];
204
+				$item++;
205
+				while (($item < strlen($rule)) && ($rule[$item]!='"') )
206
+				{
207
+					$rule2.=$rule[$item];
208
+					$item++;
209
+				}
210
+				if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item);
211
+				$rule2.=$rule[$item];
212
+				$item++;
213
+				continue;
214
+			}
215 215
             
216
-            $rule2.=$rule[$item];
217
-            $item++;
218
-        }
216
+			$rule2.=$rule[$item];
217
+			$item++;
218
+		}
219 219
         
220
-        return $rule2;
221
-    }
220
+		return $rule2;
221
+	}
222 222
 
223 223
 
224
-    /**
225
-     * Get '*' or '**' and transform in [0-9]+ or .* in return string
226
-     * @param string $oid OID in normal or regexp format. '*' will be escaped ('\*')
227
-     * @return string correct regexp format
228
-     */
229
-    public function regexp_eval(string &$oid)
230
-    {
231
-        // ** replaced by .*
232
-        $oidR=preg_replace('/\*\*/', '.*', $oid);
233
-        // * replaced by [0-9]+
234
-        $oidR=preg_replace('/\*/', '[0-9]+', $oidR);
224
+	/**
225
+	 * Get '*' or '**' and transform in [0-9]+ or .* in return string
226
+	 * @param string $oid OID in normal or regexp format. '*' will be escaped ('\*')
227
+	 * @return string correct regexp format
228
+	 */
229
+	public function regexp_eval(string &$oid)
230
+	{
231
+		// ** replaced by .*
232
+		$oidR=preg_replace('/\*\*/', '.*', $oid);
233
+		// * replaced by [0-9]+
234
+		$oidR=preg_replace('/\*/', '[0-9]+', $oidR);
235 235
         
236
-        // replace * with \* in oid for preg_replace
237
-        $oid=preg_replace('/\*/', '\*', $oid);
236
+		// replace * with \* in oid for preg_replace
237
+		$oid=preg_replace('/\*/', '\*', $oid);
238 238
         
239
-        $this->logging->log('Regexp eval : '.$oid.' / '.$oidR,DEBUG );
239
+		$this->logging->log('Regexp eval : '.$oid.' / '.$oidR,DEBUG );
240 240
         
241
-        return $oidR;
242
-    }
241
+		return $oidR;
242
+	}
243 243
     
244 244
     
245
-    /** Evaluation rule (uses eval_* functions recursively)
246
-     *	@param string $rule : rule ( _OID(.1.3.6.1.4.1.8072.2.3.2.1)=_OID(.1.3.6.1.2.1.1.3.0) )
247
-     *  @param array $oidList : OIDs values to sustitute.
248
-     *	@return bool : true : rule match, false : rule don't match , throw exception on error.
249
-     */   
250
-    public function eval_rule($rule,$oidList)
251
-    {
252
-        if ($rule==null || $rule == '') // Empty rule is always true
253
-        {
254
-            return true;
255
-        }
256
-        $matches=array();
257
-        while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1)
258
-        {
259
-            $oid=$matches[1];
260
-            $found=0;
261
-            // Test and transform regexp
262
-            $oidR = $this->regexp_eval($oid);
245
+	/** Evaluation rule (uses eval_* functions recursively)
246
+	 *	@param string $rule : rule ( _OID(.1.3.6.1.4.1.8072.2.3.2.1)=_OID(.1.3.6.1.2.1.1.3.0) )
247
+	 *  @param array $oidList : OIDs values to sustitute.
248
+	 *	@return bool : true : rule match, false : rule don't match , throw exception on error.
249
+	 */   
250
+	public function eval_rule($rule,$oidList)
251
+	{
252
+		if ($rule==null || $rule == '') // Empty rule is always true
253
+		{
254
+			return true;
255
+		}
256
+		$matches=array();
257
+		while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1)
258
+		{
259
+			$oid=$matches[1];
260
+			$found=0;
261
+			// Test and transform regexp
262
+			$oidR = $this->regexp_eval($oid);
263 263
             
264
-            foreach($oidList as $val)
265
-            {
266
-                if (preg_match("/^$oidR$/",$val->oid) == 1)
267
-                {
268
-                    if (!preg_match('/^-?[0-9]*\.?[0-9]+$/',$val->value))
269
-                    { // If not a number, change " to ' and put " around it
270
-                        $val->value=preg_replace('/"/',"'",$val->value);
271
-                        $val->value='"'.$val->value.'"';
272
-                    }
273
-                    $rep=0;
274
-                    $rule=preg_replace('/_OID\('.$oid.'\)/',$val->value,$rule,-1,$rep);
275
-                    if ($rep==0)
276
-                    {
277
-                        $this->logging->log("Error in rule_eval",WARN,'');
278
-                        return false;
279
-                    }
280
-                    $found=1;
281
-                    break;
282
-                }
283
-            }
284
-            if ($found==0)
285
-            {	// OID not found : throw error
286
-                throw new Exception('OID '.$oid.' not found in trap');
287
-            }
288
-        }
289
-        $item=0;
290
-        $rule=$this->eval_cleanup($rule);
291
-        $this->logging->log('Rule after clenup: '.$rule,INFO );
264
+			foreach($oidList as $val)
265
+			{
266
+				if (preg_match("/^$oidR$/",$val->oid) == 1)
267
+				{
268
+					if (!preg_match('/^-?[0-9]*\.?[0-9]+$/',$val->value))
269
+					{ // If not a number, change " to ' and put " around it
270
+						$val->value=preg_replace('/"/',"'",$val->value);
271
+						$val->value='"'.$val->value.'"';
272
+					}
273
+					$rep=0;
274
+					$rule=preg_replace('/_OID\('.$oid.'\)/',$val->value,$rule,-1,$rep);
275
+					if ($rep==0)
276
+					{
277
+						$this->logging->log("Error in rule_eval",WARN,'');
278
+						return false;
279
+					}
280
+					$found=1;
281
+					break;
282
+				}
283
+			}
284
+			if ($found==0)
285
+			{	// OID not found : throw error
286
+				throw new Exception('OID '.$oid.' not found in trap');
287
+			}
288
+		}
289
+		$item=0;
290
+		$rule=$this->eval_cleanup($rule);
291
+		$this->logging->log('Rule after clenup: '.$rule,INFO );
292 292
         
293
-        return  $this->evaluation($rule,$item);
294
-    }
293
+		return  $this->evaluation($rule,$item);
294
+	}
295 295
     
296 296
 }
297 297
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -26,14 +26,14 @@  discard block
 block discarded – undo
26 26
     }
27 27
     
28 28
     
29
-    protected function eval_getElement($rule,&$item)
29
+    protected function eval_getElement($rule, &$item)
30 30
     {
31 31
         if ($item >= strlen($rule))
32 32
         {
33
-            throw new Exception("Early end of string ".$rule ." at " .$item );
33
+            throw new Exception("Early end of string ".$rule." at ".$item);
34 34
         }
35
-        while ($rule[$item]==' ') $item++;
36
-        if (preg_match('/[\-0-9\.]/',$rule[$item]))
35
+        while ($rule[$item] == ' ') $item++;
36
+        if (preg_match('/[\-0-9\.]/', $rule[$item]))
37 37
         { // number
38 38
             return $this->get_number($rule, $item);
39 39
         }
@@ -50,54 +50,54 @@  discard block
 block discarded – undo
50 50
         { // function
51 51
             return $this->get_function($rule, $item);
52 52
         }
53
-        throw new Exception("number/string not found in ".$rule ." at " .$item . ' : ' .$rule[$item]);
53
+        throw new Exception("number/string not found in ".$rule." at ".$item.' : '.$rule[$item]);
54 54
         
55 55
     }
56 56
     
57
-    protected function eval_getNext($rule,$item,$tok)
57
+    protected function eval_getNext($rule, $item, $tok)
58 58
     {
59 59
         while (
60
-            ($rule[$item] != $tok ) 
60
+            ($rule[$item] != $tok) 
61 61
             && ($item < strlen($rule))) 
62 62
         { 
63 63
             $item++;
64 64
         }
65
-        if ($item==strlen($rule)) {
66
-            throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item);
65
+        if ($item == strlen($rule)) {
66
+            throw new Exception("closing '".$tok."' not found in ".$rule." at ".$item);
67 67
         }
68
-        return $item+1;
68
+        return $item + 1;
69 69
     }
70 70
     
71
-    protected function eval_getOper($rule,&$item)
71
+    protected function eval_getOper($rule, &$item)
72 72
     {
73
-        while ($rule[$item]==' ') $item++;
73
+        while ($rule[$item] == ' ') $item++;
74 74
         switch ($rule[$item])
75 75
         {
76 76
             case '<':
77
-                if ($rule[$item+1]=='=') { $item+=2; return array(0,"<=");}
78
-                $item++; return array(0,"<");
77
+                if ($rule[$item + 1] == '=') { $item+=2; return array(0, "<="); }
78
+                $item++; return array(0, "<");
79 79
             case '>':
80
-                if ($rule[$item+1]=='=') { $item+=2; return array(0,">=");}
81
-                $item++; return array(0,">");
80
+                if ($rule[$item + 1] == '=') { $item+=2; return array(0, ">="); }
81
+                $item++; return array(0, ">");
82 82
             case '=':
83
-                $item++; return array(0,"=");
83
+                $item++; return array(0, "=");
84 84
             case '!':
85
-                if ($rule[$item+1]=='=') { $item+=2; return array(0,"!=");}
86
-                throw new Exception("Erreur in expr - incorrect operator '!'  found in ".$rule ." at " .$item);
85
+                if ($rule[$item + 1] == '=') { $item+=2; return array(0, "!="); }
86
+                throw new Exception("Erreur in expr - incorrect operator '!'  found in ".$rule." at ".$item);
87 87
             case '~':
88
-                $item++; return array(0,"~");
88
+                $item++; return array(0, "~");
89 89
             case '|':
90
-                $item++; return array(1,"|");
90
+                $item++; return array(1, "|");
91 91
             case '&':
92
-                $item++; return array(1,"&");
92
+                $item++; return array(1, "&");
93 93
             default	:
94
-                throw new Exception("Erreur in expr - operator not found in ".$rule ." at " .$item);
94
+                throw new Exception("Erreur in expr - operator not found in ".$rule." at ".$item);
95 95
         }
96 96
     }
97 97
     
98
-    private function check_negate_first($rule,&$item)
98
+    private function check_negate_first($rule, &$item)
99 99
     {
100
-        if ( $rule[$item] == '!') // If '!' found, negate next expression.
100
+        if ($rule[$item] == '!') // If '!' found, negate next expression.
101 101
         {
102 102
             $item++;
103 103
             return true;
@@ -108,21 +108,21 @@  discard block
 block discarded – undo
108 108
         }
109 109
     }
110 110
 
111
-    private function do_compare($val1,$val2,$comp,$negate)
111
+    private function do_compare($val1, $val2, $comp, $negate)
112 112
     {
113
-        switch ($comp){
114
-            case '<':	$retVal= ($val1 < $val2); break;
115
-            case '<=':	$retVal= ($val1 <= $val2); break;
116
-            case '>':	$retVal= ($val1 > $val2); break;
117
-            case '>=':	$retVal= ($val1 >= $val2); break;
118
-            case '=':	$retVal= ($val1 == $val2); break;
119
-            case '!=':	$retVal= ($val1 != $val2); break;
120
-            case '~':	$retVal= (preg_match('/'.preg_replace('/"/','',$val2).'/',$val1)); break;
121
-            case '|':	$retVal= ($val1 || $val2); break;
122
-            case '&':	$retVal= ($val1 && $val2); break;
113
+        switch ($comp) {
114
+            case '<':	$retVal=($val1 < $val2); break;
115
+            case '<=':	$retVal=($val1 <= $val2); break;
116
+            case '>':	$retVal=($val1 > $val2); break;
117
+            case '>=':	$retVal=($val1 >= $val2); break;
118
+            case '=':	$retVal=($val1 == $val2); break;
119
+            case '!=':	$retVal=($val1 != $val2); break;
120
+            case '~':	$retVal=(preg_match('/'.preg_replace('/"/', '', $val2).'/', $val1)); break;
121
+            case '|':	$retVal=($val1 || $val2); break;
122
+            case '&':	$retVal=($val1 && $val2); break;
123 123
             default:  throw new Exception("Error in expression - unknown comp : ".$comp);
124 124
         }
125
-        if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression
125
+        if ($negate === true) $retVal=!$retVal; // Inverse result if negate before expression
126 126
         
127 127
         return $retVal;
128 128
     }
@@ -135,56 +135,56 @@  discard block
 block discarded – undo
135 135
      *   comparison int vs strings will return null (error)
136 136
      *	return : bool or null on error
137 137
      */
138
-    public function evaluation($rule,&$item)
138
+    public function evaluation($rule, &$item)
139 139
     {
140 140
         //echo "Evaluation of ".substr($rule,$item)."\n";
141 141
         $negate=$this->check_negate_first($rule, $item);
142 142
         // First element : number, string or ()
143
-        list($type1,$val1) = $this->eval_getElement($rule,$item);
143
+        list($type1, $val1)=$this->eval_getElement($rule, $item);
144 144
         //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n";
145 145
         
146
-        if ($item==strlen($rule)) // If only element, return value, but only boolean
146
+        if ($item == strlen($rule)) // If only element, return value, but only boolean
147 147
         {
148 148
             if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule);
149
-            if ($negate === true) $val1= ! $val1;
149
+            if ($negate === true) $val1=!$val1;
150 150
             return $val1;
151 151
         }
152 152
         
153 153
         // Second element : operator
154
-        list($typec,$comp) = $this->eval_getOper($rule,$item);
154
+        list($typec, $comp)=$this->eval_getOper($rule, $item);
155 155
         //echo "Comp : ".$comp." : ".substr($rule,$item)."\n";
156 156
         
157 157
         // Third element : number, string or ()
158
-        if ( $rule[$item] == '!') // starts with a ! so evaluate whats next
158
+        if ($rule[$item] == '!') // starts with a ! so evaluate whats next
159 159
         {
160 160
             $item++;
161 161
             if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule);
162
-            $val2= ! $this->evaluation($rule,$item);
162
+            $val2=!$this->evaluation($rule, $item);
163 163
             $type2=2; // result is a boolean
164 164
         }
165 165
         else
166 166
         {
167
-            list($type2,$val2) = $this->eval_getElement($rule,$item);
167
+            list($type2, $val2)=$this->eval_getElement($rule, $item);
168 168
         }
169 169
         //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n";
170 170
         
171
-        if ($type1!=$type2)  // cannot compare different types
171
+        if ($type1 != $type2)  // cannot compare different types
172 172
         {
173 173
             throw new Exception("Cannot compare string & number : ".$rule);
174 174
         }
175
-        if ($typec==1 && $type1 !=2) // cannot use & or | with string/number
175
+        if ($typec == 1 && $type1 != 2) // cannot use & or | with string/number
176 176
         {
177 177
             throw new Exception("Cannot use boolean operators with string & number : ".$rule);
178 178
         }
179 179
         
180
-        $retVal = $this->do_compare($val1, $val2, $comp, $negate);
180
+        $retVal=$this->do_compare($val1, $val2, $comp, $negate);
181 181
         
182
-        if ($item==strlen($rule)) return $retVal; // End of string : return evaluation
182
+        if ($item == strlen($rule)) return $retVal; // End of string : return evaluation
183 183
         // check for logical operator :
184 184
         switch ($rule[$item])
185 185
         {
186
-            case '|':	$item++; return ($retVal || $this->evaluation($rule,$item) );
187
-            case '&':	$item++; return ($retVal && $this->evaluation($rule,$item) );
186
+            case '|':	$item++; return ($retVal || $this->evaluation($rule, $item));
187
+            case '&':	$item++; return ($retVal && $this->evaluation($rule, $item));
188 188
             
189 189
             default:  throw new Exception("Erreur in expr - garbadge at end of expression : ".$rule[$item]);
190 190
         }
@@ -197,17 +197,17 @@  discard block
 block discarded – undo
197 197
         $rule2='';
198 198
         while ($item < strlen($rule))
199 199
         {
200
-            if ($rule[$item]==' ') { $item++; continue; }
201
-            if ($rule[$item]=='"')
200
+            if ($rule[$item] == ' ') { $item++; continue; }
201
+            if ($rule[$item] == '"')
202 202
             {
203 203
                 $rule2.=$rule[$item];
204 204
                 $item++;
205
-                while (($item < strlen($rule)) && ($rule[$item]!='"') )
205
+                while (($item < strlen($rule)) && ($rule[$item] != '"'))
206 206
                 {
207 207
                     $rule2.=$rule[$item];
208 208
                     $item++;
209 209
                 }
210
-                if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item);
210
+                if ($item == strlen($rule)) throw new Exception("closing '\"' not found in ".$rule." at ".$item);
211 211
                 $rule2.=$rule[$item];
212 212
                 $item++;
213 213
                 continue;
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
         // replace * with \* in oid for preg_replace
237 237
         $oid=preg_replace('/\*/', '\*', $oid);
238 238
         
239
-        $this->logging->log('Regexp eval : '.$oid.' / '.$oidR,DEBUG );
239
+        $this->logging->log('Regexp eval : '.$oid.' / '.$oidR, DEBUG);
240 240
         
241 241
         return $oidR;
242 242
     }
@@ -247,50 +247,50 @@  discard block
 block discarded – undo
247 247
      *  @param array $oidList : OIDs values to sustitute.
248 248
      *	@return bool : true : rule match, false : rule don't match , throw exception on error.
249 249
      */   
250
-    public function eval_rule($rule,$oidList)
250
+    public function eval_rule($rule, $oidList)
251 251
     {
252
-        if ($rule==null || $rule == '') // Empty rule is always true
252
+        if ($rule == null || $rule == '') // Empty rule is always true
253 253
         {
254 254
             return true;
255 255
         }
256 256
         $matches=array();
257
-        while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1)
257
+        while (preg_match('/_OID\(([0-9\.\*]+)\)/', $rule, $matches) == 1)
258 258
         {
259 259
             $oid=$matches[1];
260 260
             $found=0;
261 261
             // Test and transform regexp
262
-            $oidR = $this->regexp_eval($oid);
262
+            $oidR=$this->regexp_eval($oid);
263 263
             
264
-            foreach($oidList as $val)
264
+            foreach ($oidList as $val)
265 265
             {
266
-                if (preg_match("/^$oidR$/",$val->oid) == 1)
266
+                if (preg_match("/^$oidR$/", $val->oid) == 1)
267 267
                 {
268
-                    if (!preg_match('/^-?[0-9]*\.?[0-9]+$/',$val->value))
268
+                    if (!preg_match('/^-?[0-9]*\.?[0-9]+$/', $val->value))
269 269
                     { // If not a number, change " to ' and put " around it
270
-                        $val->value=preg_replace('/"/',"'",$val->value);
270
+                        $val->value=preg_replace('/"/', "'", $val->value);
271 271
                         $val->value='"'.$val->value.'"';
272 272
                     }
273 273
                     $rep=0;
274
-                    $rule=preg_replace('/_OID\('.$oid.'\)/',$val->value,$rule,-1,$rep);
275
-                    if ($rep==0)
274
+                    $rule=preg_replace('/_OID\('.$oid.'\)/', $val->value, $rule, -1, $rep);
275
+                    if ($rep == 0)
276 276
                     {
277
-                        $this->logging->log("Error in rule_eval",WARN,'');
277
+                        $this->logging->log("Error in rule_eval", WARN, '');
278 278
                         return false;
279 279
                     }
280 280
                     $found=1;
281 281
                     break;
282 282
                 }
283 283
             }
284
-            if ($found==0)
284
+            if ($found == 0)
285 285
             {	// OID not found : throw error
286 286
                 throw new Exception('OID '.$oid.' not found in trap');
287 287
             }
288 288
         }
289 289
         $item=0;
290 290
         $rule=$this->eval_cleanup($rule);
291
-        $this->logging->log('Rule after clenup: '.$rule,INFO );
291
+        $this->logging->log('Rule after clenup: '.$rule, INFO);
292 292
         
293
-        return  $this->evaluation($rule,$item);
293
+        return  $this->evaluation($rule, $item);
294 294
     }
295 295
     
296 296
 }
297 297
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +43 added lines, -17 removed lines patch added patch discarded remove patch
@@ -32,7 +32,9 @@  discard block
 block discarded – undo
32 32
         {
33 33
             throw new Exception("Early end of string ".$rule ." at " .$item );
34 34
         }
35
-        while ($rule[$item]==' ') $item++;
35
+        while ($rule[$item]==' ') {
36
+        	$item++;
37
+        }
36 38
         if (preg_match('/[\-0-9\.]/',$rule[$item]))
37 39
         { // number
38 40
             return $this->get_number($rule, $item);
@@ -70,7 +72,9 @@  discard block
 block discarded – undo
70 72
     
71 73
     protected function eval_getOper($rule,&$item)
72 74
     {
73
-        while ($rule[$item]==' ') $item++;
75
+        while ($rule[$item]==' ') {
76
+        	$item++;
77
+        }
74 78
         switch ($rule[$item])
75 79
         {
76 80
             case '<':
@@ -97,12 +101,13 @@  discard block
 block discarded – undo
97 101
     
98 102
     private function check_negate_first($rule,&$item)
99 103
     {
100
-        if ( $rule[$item] == '!') // If '!' found, negate next expression.
104
+        if ( $rule[$item] == '!') {
105
+        	// If '!' found, negate next expression.
101 106
         {
102 107
             $item++;
103
-            return true;
104 108
         }
105
-        else
109
+            return true;
110
+        } else
106 111
         {
107 112
             return false;
108 113
         }
@@ -122,7 +127,10 @@  discard block
 block discarded – undo
122 127
             case '&':	$retVal= ($val1 && $val2); break;
123 128
             default:  throw new Exception("Error in expression - unknown comp : ".$comp);
124 129
         }
125
-        if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression
130
+        if ($negate === true) {
131
+        	$retVal = ! $retVal;
132
+        }
133
+        // Inverse result if negate before expression
126 134
         
127 135
         return $retVal;
128 136
     }
@@ -143,10 +151,14 @@  discard block
 block discarded – undo
143 151
         list($type1,$val1) = $this->eval_getElement($rule,$item);
144 152
         //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n";
145 153
         
146
-        if ($item==strlen($rule)) // If only element, return value, but only boolean
154
+        if ($item==strlen($rule)) {
155
+        	// If only element, return value, but only boolean
147 156
         {
148 157
             if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule);
149
-            if ($negate === true) $val1= ! $val1;
158
+        }
159
+            if ($negate === true) {
160
+            	$val1= ! $val1;
161
+            }
150 162
             return $val1;
151 163
         }
152 164
         
@@ -155,31 +167,41 @@  discard block
 block discarded – undo
155 167
         //echo "Comp : ".$comp." : ".substr($rule,$item)."\n";
156 168
         
157 169
         // Third element : number, string or ()
158
-        if ( $rule[$item] == '!') // starts with a ! so evaluate whats next
170
+        if ( $rule[$item] == '!') {
171
+        	// starts with a ! so evaluate whats next
159 172
         {
160 173
             $item++;
161
-            if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule);
174
+        }
175
+            if ($typec != 1) {
176
+            	throw new Exception("Mixing boolean and comparison : ".$rule);
177
+            }
162 178
             $val2= ! $this->evaluation($rule,$item);
163 179
             $type2=2; // result is a boolean
164
-        }
165
-        else
180
+        } else
166 181
         {
167 182
             list($type2,$val2) = $this->eval_getElement($rule,$item);
168 183
         }
169 184
         //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n";
170 185
         
171
-        if ($type1!=$type2)  // cannot compare different types
186
+        if ($type1!=$type2) {
187
+        	// cannot compare different types
172 188
         {
173 189
             throw new Exception("Cannot compare string & number : ".$rule);
174 190
         }
175
-        if ($typec==1 && $type1 !=2) // cannot use & or | with string/number
191
+        }
192
+        if ($typec==1 && $type1 !=2) {
193
+        	// cannot use & or | with string/number
176 194
         {
177 195
             throw new Exception("Cannot use boolean operators with string & number : ".$rule);
178 196
         }
197
+        }
179 198
         
180 199
         $retVal = $this->do_compare($val1, $val2, $comp, $negate);
181 200
         
182
-        if ($item==strlen($rule)) return $retVal; // End of string : return evaluation
201
+        if ($item==strlen($rule)) {
202
+        	return $retVal;
203
+        }
204
+        // End of string : return evaluation
183 205
         // check for logical operator :
184 206
         switch ($rule[$item])
185 207
         {
@@ -207,7 +229,9 @@  discard block
 block discarded – undo
207 229
                     $rule2.=$rule[$item];
208 230
                     $item++;
209 231
                 }
210
-                if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item);
232
+                if ($item == strlen ($rule)) {
233
+                	throw new Exception("closing '\"' not found in ".$rule ." at " .$item);
234
+                }
211 235
                 $rule2.=$rule[$item];
212 236
                 $item++;
213 237
                 continue;
@@ -249,10 +273,12 @@  discard block
 block discarded – undo
249 273
      */   
250 274
     public function eval_rule($rule,$oidList)
251 275
     {
252
-        if ($rule==null || $rule == '') // Empty rule is always true
276
+        if ($rule==null || $rule == '') {
277
+        	// Empty rule is always true
253 278
         {
254 279
             return true;
255 280
         }
281
+        }
256 282
         $matches=array();
257 283
         while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1)
258 284
         {
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/RuleUtils.php 3 patches
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -12,126 +12,126 @@
 block discarded – undo
12 12
 trait RuleUtils
13 13
 {
14 14
 
15
-    /**
16
-     * Get full number
17
-     * @param string $rule Rule as string
18
-     * @param int item current eval position
19
-     * @return array<int,string>
20
-     */
21
-    private function get_number(string $rule,int &$item)
22
-    {
23
-        $item2=$item+1;
24
-        while (
25
-            ($item2!=strlen($rule))
26
-            && (preg_match('/[\-0-9\.]/',$rule[$item2])))
27
-        {
28
-            $item2++ ;
29
-        }
30
-        $val=substr($rule,$item,$item2-$item);
31
-        $item=$item2;
32
-        //echo "number ".$val."\n";
15
+	/**
16
+	 * Get full number
17
+	 * @param string $rule Rule as string
18
+	 * @param int item current eval position
19
+	 * @return array<int,string>
20
+	 */
21
+	private function get_number(string $rule,int &$item)
22
+	{
23
+		$item2=$item+1;
24
+		while (
25
+			($item2!=strlen($rule))
26
+			&& (preg_match('/[\-0-9\.]/',$rule[$item2])))
27
+		{
28
+			$item2++ ;
29
+		}
30
+		$val=substr($rule,$item,$item2-$item);
31
+		$item=$item2;
32
+		//echo "number ".$val."\n";
33 33
         
34
-        return array(0,$val);
35
-    }
34
+		return array(0,$val);
35
+	}
36 36
 
37
-    /**
38
-     * Get a string (between ") 
39
-     * @param string $rule Rule as string
40
-     * @param int item current eval position
41
-     * @return array<int,string>
42
-     */
43
-    private function get_string(string $rule,int &$item)
44
-    {
45
-        $item++;
46
-        $item2=$this->eval_getNext($rule,$item,'"');
47
-        $val=substr($rule,$item,$item2-$item-1);
48
-        $item=$item2;
49
-        //echo "string : ".$val."\n";
50
-        return array(1,$val);
37
+	/**
38
+	 * Get a string (between ") 
39
+	 * @param string $rule Rule as string
40
+	 * @param int item current eval position
41
+	 * @return array<int,string>
42
+	 */
43
+	private function get_string(string $rule,int &$item)
44
+	{
45
+		$item++;
46
+		$item2=$this->eval_getNext($rule,$item,'"');
47
+		$val=substr($rule,$item,$item2-$item-1);
48
+		$item=$item2;
49
+		//echo "string : ".$val."\n";
50
+		return array(1,$val);
51 51
         
52
-    }
52
+	}
53 53
     
54
-    /**
55
-     * Parse elements inside () : jumps over "" and count parenthesis.
56
-     * Ex : ( "test" != ")test" & (1==2) ) will return "test" != ")test" & (1==2)
57
-     * @param string $rule : the current rule
58
-     * @param int $item : actual position in rule
59
-     * @throws Exception
60
-     * @return string : everything inside parenthesis
61
-     */
62
-    private function parse_parenthesis(string $rule,int &$item) : string
63
-    {
64
-        $item++;
65
-        $start=$item;
66
-        $parenthesis_count=0;
67
-        while (($item < strlen($rule)) // Not end of string AND
68
-            && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded ()
69
-        {
70
-            if ($rule[$item] == '"' )
71
-            { // pass through string
72
-                $item++;
73
-                $item=$this->eval_getNext($rule,$item,'"');
74
-            }
75
-            else{
76
-                if ($rule[$item] == '(')
77
-                {
78
-                    $parenthesis_count++;
79
-                }
80
-                if ($rule[$item] == ')')
81
-                {
82
-                    $parenthesis_count--;
83
-                }
84
-                $item++;
85
-            }
86
-        }
54
+	/**
55
+	 * Parse elements inside () : jumps over "" and count parenthesis.
56
+	 * Ex : ( "test" != ")test" & (1==2) ) will return "test" != ")test" & (1==2)
57
+	 * @param string $rule : the current rule
58
+	 * @param int $item : actual position in rule
59
+	 * @throws Exception
60
+	 * @return string : everything inside parenthesis
61
+	 */
62
+	private function parse_parenthesis(string $rule,int &$item) : string
63
+	{
64
+		$item++;
65
+		$start=$item;
66
+		$parenthesis_count=0;
67
+		while (($item < strlen($rule)) // Not end of string AND
68
+			&& ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded ()
69
+		{
70
+			if ($rule[$item] == '"' )
71
+			{ // pass through string
72
+				$item++;
73
+				$item=$this->eval_getNext($rule,$item,'"');
74
+			}
75
+			else{
76
+				if ($rule[$item] == '(')
77
+				{
78
+					$parenthesis_count++;
79
+				}
80
+				if ($rule[$item] == ')')
81
+				{
82
+					$parenthesis_count--;
83
+				}
84
+				$item++;
85
+			}
86
+		}
87 87
         
88
-        if ($item==strlen($rule)) {throw new Exception("no closing () in ".$rule ." at " .$item);}
89
-        $val=substr($rule,$start,$item-$start);
90
-        $item++;
91
-        return $val;
92
-    }
88
+		if ($item==strlen($rule)) {throw new Exception("no closing () in ".$rule ." at " .$item);}
89
+		$val=substr($rule,$start,$item-$start);
90
+		$item++;
91
+		return $val;
92
+	}
93 93
 
94
-    /**
95
-     * Get and eval a grouped condition - ex : (1==1)
96
-     * @param string $rule
97
-     * @param int $item
98
-     * @return array<int,string>
99
-     */
100
-    private function get_group(string $rule,int &$item) : array
101
-    {
102
-        // gets eveything inside parenthesis
103
-        $val=$this->parse_parenthesis($rule, $item);
104
-        // Returns boolean with evaluation of all inside parenthesis
105
-        $start=0;
106
-        return array(2,$this->evaluation($val,$start));
107
-    }
94
+	/**
95
+	 * Get and eval a grouped condition - ex : (1==1)
96
+	 * @param string $rule
97
+	 * @param int $item
98
+	 * @return array<int,string>
99
+	 */
100
+	private function get_group(string $rule,int &$item) : array
101
+	{
102
+		// gets eveything inside parenthesis
103
+		$val=$this->parse_parenthesis($rule, $item);
104
+		// Returns boolean with evaluation of all inside parenthesis
105
+		$start=0;
106
+		return array(2,$this->evaluation($val,$start));
107
+	}
108 108
     
109
-    /**
110
-     * @param string $rule
111
-     * @param int $item
112
-     * @throws Exception
113
-     * @return array<int,string>
114
-     */
115
-    private function get_function(string $rule,int &$item) : array
116
-    {
117
-        // function is : __function(param1,param2...)
118
-        $start=$item;
119
-        while (($item < strlen($rule)) && ($rule[$item] != '(' )) // Not end of string AND not opening '('
120
-        {
121
-            $item++;
122
-        }
123
-        if ($item==strlen($rule)) {throw new Exception("no opening () for function in ".$rule ." at " .$item);}
109
+	/**
110
+	 * @param string $rule
111
+	 * @param int $item
112
+	 * @throws Exception
113
+	 * @return array<int,string>
114
+	 */
115
+	private function get_function(string $rule,int &$item) : array
116
+	{
117
+		// function is : __function(param1,param2...)
118
+		$start=$item;
119
+		while (($item < strlen($rule)) && ($rule[$item] != '(' )) // Not end of string AND not opening '('
120
+		{
121
+			$item++;
122
+		}
123
+		if ($item==strlen($rule)) {throw new Exception("no opening () for function in ".$rule ." at " .$item);}
124 124
         
125
-        // get parameters between parenthesis
125
+		// get parameters between parenthesis
126 126
         
127
-        $this->parse_parenthesis($rule, $item);
127
+		$this->parse_parenthesis($rule, $item);
128 128
         
129
-        $val=substr($rule,$start,$item-$start);
129
+		$val=substr($rule,$start,$item-$start);
130 130
         
131
-        $this->logging->log('got function ' . $val,DEBUG);
131
+		$this->logging->log('got function ' . $val,DEBUG);
132 132
         
133
-        return array(2,$this->trapClass->pluginClass->evaluateFunctionString($val));
133
+		return array(2,$this->trapClass->pluginClass->evaluateFunctionString($val));
134 134
         
135
-    }
135
+	}
136 136
     
137 137
 }
138 138
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -18,20 +18,20 @@  discard block
 block discarded – undo
18 18
      * @param int item current eval position
19 19
      * @return array<int,string>
20 20
      */
21
-    private function get_number(string $rule,int &$item)
21
+    private function get_number(string $rule, int &$item)
22 22
     {
23
-        $item2=$item+1;
23
+        $item2=$item + 1;
24 24
         while (
25
-            ($item2!=strlen($rule))
26
-            && (preg_match('/[\-0-9\.]/',$rule[$item2])))
25
+            ($item2 != strlen($rule))
26
+            && (preg_match('/[\-0-9\.]/', $rule[$item2])))
27 27
         {
28
-            $item2++ ;
28
+            $item2++;
29 29
         }
30
-        $val=substr($rule,$item,$item2-$item);
30
+        $val=substr($rule, $item, $item2 - $item);
31 31
         $item=$item2;
32 32
         //echo "number ".$val."\n";
33 33
         
34
-        return array(0,$val);
34
+        return array(0, $val);
35 35
     }
36 36
 
37 37
     /**
@@ -40,14 +40,14 @@  discard block
 block discarded – undo
40 40
      * @param int item current eval position
41 41
      * @return array<int,string>
42 42
      */
43
-    private function get_string(string $rule,int &$item)
43
+    private function get_string(string $rule, int &$item)
44 44
     {
45 45
         $item++;
46
-        $item2=$this->eval_getNext($rule,$item,'"');
47
-        $val=substr($rule,$item,$item2-$item-1);
46
+        $item2=$this->eval_getNext($rule, $item, '"');
47
+        $val=substr($rule, $item, $item2 - $item - 1);
48 48
         $item=$item2;
49 49
         //echo "string : ".$val."\n";
50
-        return array(1,$val);
50
+        return array(1, $val);
51 51
         
52 52
     }
53 53
     
@@ -59,20 +59,20 @@  discard block
 block discarded – undo
59 59
      * @throws Exception
60 60
      * @return string : everything inside parenthesis
61 61
      */
62
-    private function parse_parenthesis(string $rule,int &$item) : string
62
+    private function parse_parenthesis(string $rule, int &$item) : string
63 63
     {
64 64
         $item++;
65 65
         $start=$item;
66 66
         $parenthesis_count=0;
67 67
         while (($item < strlen($rule)) // Not end of string AND
68
-            && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded ()
68
+            && (($rule[$item] != ')') || $parenthesis_count > 0)) // Closing ')' or embeded ()
69 69
         {
70
-            if ($rule[$item] == '"' )
70
+            if ($rule[$item] == '"')
71 71
             { // pass through string
72 72
                 $item++;
73
-                $item=$this->eval_getNext($rule,$item,'"');
73
+                $item=$this->eval_getNext($rule, $item, '"');
74 74
             }
75
-            else{
75
+            else {
76 76
                 if ($rule[$item] == '(')
77 77
                 {
78 78
                     $parenthesis_count++;
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
             }
86 86
         }
87 87
         
88
-        if ($item==strlen($rule)) {throw new Exception("no closing () in ".$rule ." at " .$item);}
89
-        $val=substr($rule,$start,$item-$start);
88
+        if ($item == strlen($rule)) {throw new Exception("no closing () in ".$rule." at ".$item); }
89
+        $val=substr($rule, $start, $item - $start);
90 90
         $item++;
91 91
         return $val;
92 92
     }
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
      * @param int $item
98 98
      * @return array<int,string>
99 99
      */
100
-    private function get_group(string $rule,int &$item) : array
100
+    private function get_group(string $rule, int &$item) : array
101 101
     {
102 102
         // gets eveything inside parenthesis
103 103
         $val=$this->parse_parenthesis($rule, $item);
104 104
         // Returns boolean with evaluation of all inside parenthesis
105 105
         $start=0;
106
-        return array(2,$this->evaluation($val,$start));
106
+        return array(2, $this->evaluation($val, $start));
107 107
     }
108 108
     
109 109
     /**
@@ -112,25 +112,25 @@  discard block
 block discarded – undo
112 112
      * @throws Exception
113 113
      * @return array<int,string>
114 114
      */
115
-    private function get_function(string $rule,int &$item) : array
115
+    private function get_function(string $rule, int &$item) : array
116 116
     {
117 117
         // function is : __function(param1,param2...)
118 118
         $start=$item;
119
-        while (($item < strlen($rule)) && ($rule[$item] != '(' )) // Not end of string AND not opening '('
119
+        while (($item < strlen($rule)) && ($rule[$item] != '(')) // Not end of string AND not opening '('
120 120
         {
121 121
             $item++;
122 122
         }
123
-        if ($item==strlen($rule)) {throw new Exception("no opening () for function in ".$rule ." at " .$item);}
123
+        if ($item == strlen($rule)) {throw new Exception("no opening () for function in ".$rule." at ".$item); }
124 124
         
125 125
         // get parameters between parenthesis
126 126
         
127 127
         $this->parse_parenthesis($rule, $item);
128 128
         
129
-        $val=substr($rule,$start,$item-$start);
129
+        $val=substr($rule, $start, $item - $start);
130 130
         
131
-        $this->logging->log('got function ' . $val,DEBUG);
131
+        $this->logging->log('got function '.$val, DEBUG);
132 132
         
133
-        return array(2,$this->trapClass->pluginClass->evaluateFunctionString($val));
133
+        return array(2, $this->trapClass->pluginClass->evaluateFunctionString($val));
134 134
         
135 135
     }
136 136
     
Please login to merge, or discard this patch.
Braces   +7 added lines, -4 removed lines patch added patch discarded remove patch
@@ -65,14 +65,15 @@  discard block
 block discarded – undo
65 65
         $start=$item;
66 66
         $parenthesis_count=0;
67 67
         while (($item < strlen($rule)) // Not end of string AND
68
-            && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded ()
68
+            && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) {
69
+        	// Closing ')' or embeded ()
69 70
         {
70 71
             if ($rule[$item] == '"' )
71 72
             { // pass through string
72 73
                 $item++;
74
+        }
73 75
                 $item=$this->eval_getNext($rule,$item,'"');
74
-            }
75
-            else{
76
+            } else{
76 77
                 if ($rule[$item] == '(')
77 78
                 {
78 79
                     $parenthesis_count++;
@@ -116,10 +117,12 @@  discard block
 block discarded – undo
116 117
     {
117 118
         // function is : __function(param1,param2...)
118 119
         $start=$item;
119
-        while (($item < strlen($rule)) && ($rule[$item] != '(' )) // Not end of string AND not opening '('
120
+        while (($item < strlen($rule)) && ($rule[$item] != '(' )) {
121
+        	// Not end of string AND not opening '('
120 122
         {
121 123
             $item++;
122 124
         }
125
+        }
123 126
         if ($item==strlen($rule)) {throw new Exception("no opening () for function in ".$rule ." at " .$item);}
124 127
         
125 128
         // get parameters between parenthesis
Please login to merge, or discard this patch.