Passed
Push — master ( b6634d...971a50 )
by Patrick
01:58
created
application/controllers/HandlerController.php 3 patches
Indentation   +251 added lines, -252 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();
@@ -420,7 +419,7 @@  discard block
 block discarded – undo
420 419
 			'action_nomatch'=>	array('post' => 'ruleNoMatch',    'val' => -1,    'db'=>true),					
421 420
 			'ip4'			=>	array('post' => null,             'val' => null,  'db'=>true),
422 421
 			'ip6'			=>	array('post' => null,             'val' => null,  'db'=>true),
423
-		    'action_form'	=>	array('post' => 'action_form',    'val' => null, 'db'=>false)
422
+			'action_form'	=>	array('post' => 'action_form',    'val' => null, 'db'=>false)
424 423
 		);
425 424
 		
426 425
 		if (isset($postData[$params['action_form']['post']]) 
@@ -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"));
@@ -510,11 +509,11 @@  discard block
 block discarded – undo
510 509
 			
511 510
 			if ($params['db_rule']['val'] == -1 || $params['action_form']['val'] == 'clone') 
512 511
 			{  // If no rule number or action is clone, add the handler
513
-			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
512
+				$ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
514 513
 			}
515 514
 			else
516 515
 			{
517
-			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
516
+				$this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
518 517
 				$ruleID=$params['db_rule']['val'];
519 518
 			}
520 519
 		}
@@ -528,9 +527,9 @@  discard block
 block discarded – undo
528 527
 	}
529 528
 
530 529
 	/** Get trap detail by trapid. 
531
-	*	@param integer $trapid : id of trap in received table
532
-	*	@return array (objects)
533
-	*/
530
+	 *	@param integer $trapid : id of trap in received table
531
+	 *	@return array (objects)
532
+	 */
534 533
 	protected function getTrapDetail($trapid) 
535 534
 	{
536 535
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -546,14 +545,14 @@  discard block
 block discarded – undo
546 545
 		}
547 546
 		try
548 547
 		{		
549
-		    $query = $dbConn->select()
548
+			$query = $dbConn->select()
550 549
 				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
551 550
 				->where('id=?',$trapid);
552 551
 				$trapDetail=$dbConn->fetchRow($query);
553 552
 			if ( $trapDetail == null ) 
554 553
 			{
555
-			    $trapDetail = 'NULL';
556
-			    throw new Exception('No traps was found with id = '.$trapid);
554
+				$trapDetail = 'NULL';
555
+				throw new Exception('No traps was found with id = '.$trapid);
557 556
 			}
558 557
 		}
559 558
 		catch (Exception $e)
@@ -567,9 +566,9 @@  discard block
 block discarded – undo
567 566
 	}
568 567
 
569 568
 	/** Get trap objects
570
-	*	@param integer $trapid : trap id
571
-	* 	@return array : full column in db of trap id
572
-	*/
569
+	 *	@param integer $trapid : trap id
570
+	 * 	@return array : full column in db of trap id
571
+	 */
573 572
 	protected function getTrapobjects($trapid)
574 573
 	{	
575 574
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -585,7 +584,7 @@  discard block
 block discarded – undo
585 584
 		}
586 585
 		try
587 586
 		{		
588
-		    $query = $dbConn->select()
587
+			$query = $dbConn->select()
589 588
 				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
590 589
 				->where('trap_id=?',$trapid);
591 590
 				$trapDetail=$dbConn->fetchAll($query);
@@ -601,10 +600,10 @@  discard block
 block discarded – undo
601 600
 	}
602 601
 
603 602
 	/** Get rule detail by ruleid.
604
-	*	@param integer $ruleid int id of rule in rule table
605
-	*	@return object|array : column objects in db 
606
-	*
607
-	*/
603
+	 *	@param integer $ruleid int id of rule in rule table
604
+	 *	@return object|array : column objects in db 
605
+	 *
606
+	 */
608 607
 	protected function getRuleDetail($ruleid) 
609 608
 	{
610 609
 		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
@@ -615,7 +614,7 @@  discard block
 block discarded – undo
615 614
 		// ***************  Get main data
616 615
 		try
617 616
 		{		
618
-		    $query = $dbConn->select()
617
+			$query = $dbConn->select()
619 618
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
620 619
 				->where('id=?',$ruleid);
621 620
 			$ruleDetail=$dbConn->fetchRow($query);
@@ -632,7 +631,7 @@  discard block
 block discarded – undo
632 631
 	}
633 632
 
634 633
 	/** Setup tabs for rules 
635
-	*/
634
+	 */
636 635
 	protected function prepareTabs()
637 636
 	{
638 637
 		return $this->getTabs()->add('status', array(
Please login to merge, or discard this patch.
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -23,16 +23,16 @@  discard block
 block discarded – undo
23 23
 		$this->checkReadPermission();
24 24
 		$this->prepareTabs()->activate('status');
25 25
 
26
-		$dbConn = $this->getUIDatabase()->getDb();
26
+		$dbConn=$this->getUIDatabase()->getDb();
27 27
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
28 28
 		
29 29
 		$this->getHandlerListTable()->setConnection($dbConn);
30 30
 		$this->getHandlerListTable()->setMibloader($this->getMIB());
31 31
 		// Apply pagination limits 
32
-		$this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(),$this->getModuleConfig()->itemListDisplay());		
32
+		$this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(), $this->getModuleConfig()->itemListDisplay());		
33 33
 		
34 34
 		// Set Filter
35
-		$this->view->filterEditor = $this->getHandlerListTable()->getFilterEditor($this->getRequest());		
35
+		$this->view->filterEditor=$this->getHandlerListTable()->getFilterEditor($this->getRequest());		
36 36
 	
37 37
 		//$this->displayExitError('Handler/indexAction','Not implemented');
38 38
 	}
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	public function testruleAction()
43 43
 	{
44 44
 	    $this->checkReadPermission();
45
-	    $this->getTabs()->add('get',array(
45
+	    $this->getTabs()->add('get', array(
46 46
 	        'active'	=> true,
47 47
 	        'label'		=> $this->translate('Test Rule'),
48 48
 	        'url'		=> Url::fromRequest()
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
 	    if ($this->params->get('rule') !== null) 
53 53
 	    {
54
-	        $this->view->rule= $this->params->get('rule');
54
+	        $this->view->rule=$this->params->get('rule');
55 55
 	    }
56 56
 	    else
57 57
 	    {
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
 	    }
111 111
 	    catch (Exception $e)
112 112
 	    {
113
-	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
113
+	        $this->displayExitError('Add handler : get host by IP/Name ', $e->getMessage());
114 114
 	    }
115 115
 	    
116 116
 	    
117 117
 	    // if one unique host found -> put id text input
118
-	    if (count($hosts)==1) {
118
+	    if (count($hosts) == 1) {
119 119
 	        $this->view->hostname=$hosts[0]->name;
120 120
 	        //$hostid=$hosts[0]->id;
121 121
 	        // Tell JS to get services when page is loaded
@@ -124,9 +124,9 @@  discard block
 block discarded – undo
124 124
 	    }
125 125
 	    else
126 126
 	    {
127
-	        foreach($hosts as $key=>$val)
127
+	        foreach ($hosts as $key=>$val)
128 128
 	        {
129
-	            array_push($this->view->hostlist,$hosts[$key]->name);
129
+	            array_push($this->view->hostlist, $hosts[$key]->name);
130 130
 	        }
131 131
 	    }
132 132
 	    
@@ -165,18 +165,18 @@  discard block
 block discarded – undo
165 165
 	            $currentObjectTypeEnum
166 166
 	        );
167 167
 	        $oid_index++;
168
-	        array_push($this->view->objectList,$currentObject);
168
+	        array_push($this->view->objectList, $currentObject);
169 169
 	        // set currrent object to null in allObjects
170 170
 	        if (isset($allObjects[$val->oid]))
171 171
 	        {
172 172
 	            $allObjects[$val->oid]=null;
173 173
 	        }
174 174
 	    }
175
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
175
+	    if ($allObjects != null) // in case trap doesn't have objects or is not resolved
176 176
 	    {
177 177
 	        foreach ($allObjects as $key => $val)
178 178
 	        {
179
-	            if ($val==null) { continue; }
179
+	            if ($val == null) { continue; }
180 180
 	            array_push($this->view->objectList, array(
181 181
 	                $oid_index,
182 182
 	                $key,
@@ -204,9 +204,9 @@  discard block
 block discarded – undo
204 204
 	    // Check if hostname still exists
205 205
 	    $host_get=$this->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',    'val' => null, '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', 'val' => null, '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,15 +495,15 @@  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>';
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
 			}
515 515
 			else
516 516
 			{
517
-			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
517
+			    $this->getUIDatabase()->updateHandlerRule($dbparams, $params['db_rule']['val']);
518 518
 				$ruleID=$params['db_rule']['val'];
519 519
 			}
520 520
 		}
@@ -533,10 +533,10 @@  discard block
 block discarded – undo
533 533
 	*/
534 534
 	protected function getTrapDetail($trapid) 
535 535
 	{
536
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
536
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
537 537
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
538 538
 		
539
-		$dbConn = $this->getUIDatabase()->getDbConn();
539
+		$dbConn=$this->getUIDatabase()->getDbConn();
540 540
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
541 541
 		// ***************  Get main data
542 542
 		// extract columns and titles;
@@ -546,19 +546,19 @@  discard block
 block discarded – undo
546 546
 		}
547 547
 		try
548 548
 		{		
549
-		    $query = $dbConn->select()
550
-				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
551
-				->where('id=?',$trapid);
549
+		    $query=$dbConn->select()
550
+				->from($this->getModuleConfig()->getTrapTableName(), $elmts)
551
+				->where('id=?', $trapid);
552 552
 				$trapDetail=$dbConn->fetchRow($query);
553
-			if ( $trapDetail == null ) 
553
+			if ($trapDetail == null) 
554 554
 			{
555
-			    $trapDetail = 'NULL';
555
+			    $trapDetail='NULL';
556 556
 			    throw new Exception('No traps was found with id = '.$trapid);
557 557
 			}
558 558
 		}
559 559
 		catch (Exception $e)
560 560
 		{
561
-			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
561
+			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail, true), $e->getMessage());
562 562
 			return;
563 563
 		}
564 564
 
@@ -572,10 +572,10 @@  discard block
 block discarded – undo
572 572
 	*/
573 573
 	protected function getTrapobjects($trapid)
574 574
 	{	
575
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
575
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
576 576
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
577 577
 		
578
-		$dbConn = $this->getUIDatabase()->getDbConn();
578
+		$dbConn=$this->getUIDatabase()->getDbConn();
579 579
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
580 580
 		// ***************  Get object data
581 581
 		// extract columns and titles;
@@ -585,15 +585,15 @@  discard block
 block discarded – undo
585 585
 		}
586 586
 		try
587 587
 		{		
588
-		    $query = $dbConn->select()
589
-				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
590
-				->where('trap_id=?',$trapid);
588
+		    $query=$dbConn->select()
589
+				->from($this->moduleConfig->getTrapDataTableName(), $data_elmts)
590
+				->where('trap_id=?', $trapid);
591 591
 				$trapDetail=$dbConn->fetchAll($query);
592 592
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
593 593
 		}
594 594
 		catch (Exception $e)
595 595
 		{
596
-			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
596
+			$this->displayExitError('Add handler : get trap data detail : ', $e->getMessage());
597 597
 			return array();
598 598
 		}
599 599
 
@@ -607,24 +607,24 @@  discard block
 block discarded – undo
607 607
 	*/
608 608
 	protected function getRuleDetail($ruleid) 
609 609
 	{
610
-		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
610
+		if (!preg_match('/^[0-9]+$/', $ruleid)) { throw new Exception('Invalid id'); }
611 611
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
612 612
 		
613
-		$dbConn = $this->getUIDatabase()->getDbConn();
613
+		$dbConn=$this->getUIDatabase()->getDbConn();
614 614
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
615 615
 		// ***************  Get main data
616 616
 		try
617 617
 		{		
618
-		    $query = $dbConn->select()
619
-				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
620
-				->where('id=?',$ruleid);
618
+		    $query=$dbConn->select()
619
+				->from($this->getModuleConfig()->getTrapRuleName(), $queryArray)
620
+				->where('id=?', $ruleid);
621 621
 			$ruleDetail=$dbConn->fetchRow($query);
622
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
622
+			if ($ruleDetail == null) throw new Exception('No rule was found with id = '.$ruleid);
623 623
 		}
624 624
 		catch (Exception $e)
625 625
 		{
626
-			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
627
-			throw new Exception('Error : ' . $e->getMessage());
626
+			$this->displayExitError('Update handler : get rule detail', $e->getMessage());
627
+			throw new Exception('Error : '.$e->getMessage());
628 628
 		}
629 629
 
630 630
 		return $ruleDetail;
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
 	{
638 638
 		return $this->getTabs()->add('status', array(
639 639
 			'label' => $this->translate('Traps'),
640
-			'url'   => $this->getModuleConfig()->urlPath() . '/handler')
640
+			'url'   => $this->getModuleConfig()->urlPath().'/handler')
641 641
 		);
642 642
 	} 
643 643
 	
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)
@@ -511,14 +510,12 @@  discard block
 block discarded – undo
511 510
 			if ($params['db_rule']['val'] == -1 || $params['action_form']['val'] == 'clone') 
512 511
 			{  // If no rule number or action is clone, add the handler
513 512
 			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
514
-			}
515
-			else
513
+			} else
516 514
 			{
517 515
 			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
518 516
 				$ruleID=$params['db_rule']['val'];
519 517
 			}
520
-		}
521
-		catch (Exception $e)
518
+		} catch (Exception $e)
522 519
 		{
523 520
 			$this->_helper->json(array('status'=>$e->getMessage()));
524 521
 			return;
@@ -537,7 +534,9 @@  discard block
 block discarded – undo
537 534
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
538 535
 		
539 536
 		$dbConn = $this->getUIDatabase()->getDbConn();
540
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
537
+		if ($dbConn === null) {
538
+			throw new \ErrorException('uncatched db error');
539
+		}
541 540
 		// ***************  Get main data
542 541
 		// extract columns and titles;
543 542
 		$elmts=NULL;
@@ -555,8 +554,7 @@  discard block
 block discarded – undo
555 554
 			    $trapDetail = 'NULL';
556 555
 			    throw new Exception('No traps was found with id = '.$trapid);
557 556
 			}
558
-		}
559
-		catch (Exception $e)
557
+		} catch (Exception $e)
560 558
 		{
561 559
 			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
562 560
 			return;
@@ -576,7 +574,9 @@  discard block
 block discarded – undo
576 574
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
577 575
 		
578 576
 		$dbConn = $this->getUIDatabase()->getDbConn();
579
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
577
+		if ($dbConn === null) {
578
+			throw new \ErrorException('uncatched db error');
579
+		}
580 580
 		// ***************  Get object data
581 581
 		// extract columns and titles;
582 582
 		$data_elmts=NULL;
@@ -590,8 +590,7 @@  discard block
 block discarded – undo
590 590
 				->where('trap_id=?',$trapid);
591 591
 				$trapDetail=$dbConn->fetchAll($query);
592 592
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
593
-		}
594
-		catch (Exception $e)
593
+		} catch (Exception $e)
595 594
 		{
596 595
 			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
597 596
 			return array();
@@ -611,7 +610,9 @@  discard block
 block discarded – undo
611 610
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
612 611
 		
613 612
 		$dbConn = $this->getUIDatabase()->getDbConn();
614
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
613
+		if ($dbConn === null) {
614
+			throw new \ErrorException('uncatched db error');
615
+		}
615 616
 		// ***************  Get main data
616 617
 		try
617 618
 		{		
@@ -619,9 +620,10 @@  discard block
 block discarded – undo
619 620
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
620 621
 				->where('id=?',$ruleid);
621 622
 			$ruleDetail=$dbConn->fetchRow($query);
622
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
623
-		}
624
-		catch (Exception $e)
623
+			if ( $ruleDetail == null ) {
624
+				throw new Exception('No rule was found with id = '.$ruleid);
625
+			}
626
+		} catch (Exception $e)
625 627
 		{
626 628
 			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
627 629
 			throw new Exception('Error : ' . $e->getMessage());
Please login to merge, or discard this patch.