Passed
Push — master ( f89732...ddbf74 )
by Patrick
02:13
created
application/controllers/HandlerController.php 3 patches
Indentation   +248 added lines, -249 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;
@@ -483,7 +482,7 @@  discard block
 block discarded – undo
483 482
 			}
484 483
 			else
485 484
 			{
486
-			    $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']);
485
+				$object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']);
487 486
 				if ($params['host_name']['val'] != $object->name1)
488 487
 				{
489 488
 					$this->_helper->json(array('status'=>"Invalid object group id : Please re enter service"));
@@ -504,11 +503,11 @@  discard block
 block discarded – undo
504 503
 			// echo '<br>';	print_r($dbparams);echo '<br>';
505 504
 			if ($params['db_rule']['val'] == -1 ) 
506 505
 			{
507
-			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
506
+				$ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
508 507
 			}
509 508
 			else
510 509
 			{
511
-			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
510
+				$this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
512 511
 				$ruleID=$params['db_rule']['val'];
513 512
 			}
514 513
 		}
@@ -522,9 +521,9 @@  discard block
 block discarded – undo
522 521
 	}
523 522
 
524 523
 	/** Get trap detail by trapid. 
525
-	*	@param integer $trapid : id of trap in received table
526
-	*	@return array (objects)
527
-	*/
524
+	 *	@param integer $trapid : id of trap in received table
525
+	 *	@return array (objects)
526
+	 */
528 527
 	protected function getTrapDetail($trapid) 
529 528
 	{
530 529
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -540,14 +539,14 @@  discard block
 block discarded – undo
540 539
 		}
541 540
 		try
542 541
 		{		
543
-		    $query = $dbConn->select()
542
+			$query = $dbConn->select()
544 543
 				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
545 544
 				->where('id=?',$trapid);
546 545
 				$trapDetail=$dbConn->fetchRow($query);
547 546
 			if ( $trapDetail == null ) 
548 547
 			{
549
-			    $trapDetail = 'NULL';
550
-			    throw new Exception('No traps was found with id = '.$trapid);
548
+				$trapDetail = 'NULL';
549
+				throw new Exception('No traps was found with id = '.$trapid);
551 550
 			}
552 551
 		}
553 552
 		catch (Exception $e)
@@ -561,9 +560,9 @@  discard block
 block discarded – undo
561 560
 	}
562 561
 
563 562
 	/** Get trap objects
564
-	*	@param integer $trapid : trap id
565
-	* 	@return array : full column in db of trap id
566
-	*/
563
+	 *	@param integer $trapid : trap id
564
+	 * 	@return array : full column in db of trap id
565
+	 */
567 566
 	protected function getTrapobjects($trapid)
568 567
 	{	
569 568
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -579,7 +578,7 @@  discard block
 block discarded – undo
579 578
 		}
580 579
 		try
581 580
 		{		
582
-		    $query = $dbConn->select()
581
+			$query = $dbConn->select()
583 582
 				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
584 583
 				->where('trap_id=?',$trapid);
585 584
 				$trapDetail=$dbConn->fetchAll($query);
@@ -595,10 +594,10 @@  discard block
 block discarded – undo
595 594
 	}
596 595
 
597 596
 	/** Get rule detail by ruleid.
598
-	*	@param integer $ruleid int id of rule in rule table
599
-	*	@return object : column objects in db 
600
-	*
601
-	*/
597
+	 *	@param integer $ruleid int id of rule in rule table
598
+	 *	@return object : column objects in db 
599
+	 *
600
+	 */
602 601
 	protected function getRuleDetail($ruleid) 
603 602
 	{
604 603
 		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
@@ -609,7 +608,7 @@  discard block
 block discarded – undo
609 608
 		// ***************  Get main data
610 609
 		try
611 610
 		{		
612
-		    $query = $dbConn->select()
611
+			$query = $dbConn->select()
613 612
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
614 613
 				->where('id=?',$ruleid);
615 614
 			$ruleDetail=$dbConn->fetchRow($query);
@@ -626,7 +625,7 @@  discard block
 block discarded – undo
626 625
 	}
627 626
 
628 627
 	/** Setup tabs for rules 
629
-	*/
628
+	 */
630 629
 	protected function prepareTabs()
631 630
 	{
632 631
 		return $this->getTabs()->add('status', array(
Please login to merge, or discard this patch.
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -23,16 +23,16 @@  discard block
 block discarded – undo
23 23
 		$this->checkReadPermission();
24 24
 		$this->prepareTabs()->activate('status');
25 25
 
26
-		$dbConn = $this->getUIDatabase()->getDb();
26
+		$dbConn=$this->getUIDatabase()->getDb();
27 27
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
28 28
 		
29 29
 		$this->getHandlerListTable()->setConnection($dbConn);
30 30
 		$this->getHandlerListTable()->setMibloader($this->getMIB());
31 31
 		// Apply pagination limits 
32
-		$this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(),$this->getModuleConfig()->itemListDisplay());		
32
+		$this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(), $this->getModuleConfig()->itemListDisplay());		
33 33
 		
34 34
 		// Set Filter
35
-		$this->view->filterEditor = $this->getHandlerListTable()->getFilterEditor($this->getRequest());		
35
+		$this->view->filterEditor=$this->getHandlerListTable()->getFilterEditor($this->getRequest());		
36 36
 	
37 37
 		//$this->displayExitError('Handler/indexAction','Not implemented');
38 38
 	}
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	public function testruleAction()
43 43
 	{
44 44
 	    $this->checkReadPermission();
45
-	    $this->getTabs()->add('get',array(
45
+	    $this->getTabs()->add('get', array(
46 46
 	        'active'	=> true,
47 47
 	        'label'		=> $this->translate('Test Rule'),
48 48
 	        'url'		=> Url::fromRequest()
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
 	    if ($this->params->get('rule') !== null) 
53 53
 	    {
54
-	        $this->view->rule= $this->params->get('rule');
54
+	        $this->view->rule=$this->params->get('rule');
55 55
 	    }
56 56
 	    else
57 57
 	    {
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
 	    }
111 111
 	    catch (Exception $e)
112 112
 	    {
113
-	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
113
+	        $this->displayExitError('Add handler : get host by IP/Name ', $e->getMessage());
114 114
 	    }
115 115
 	    
116 116
 	    
117 117
 	    // if one unique host found -> put id text input
118
-	    if (count($hosts)==1) {
118
+	    if (count($hosts) == 1) {
119 119
 	        $this->view->hostname=$hosts[0]->name;
120 120
 	        //$hostid=$hosts[0]->id;
121 121
 	        // Tell JS to get services when page is loaded
@@ -124,9 +124,9 @@  discard block
 block discarded – undo
124 124
 	    }
125 125
 	    else
126 126
 	    {
127
-	        foreach($hosts as $key=>$val)
127
+	        foreach ($hosts as $key=>$val)
128 128
 	        {
129
-	            array_push($this->view->hostlist,$hosts[$key]->name);
129
+	            array_push($this->view->hostlist, $hosts[$key]->name);
130 130
 	        }
131 131
 	    }
132 132
 	    
@@ -165,18 +165,18 @@  discard block
 block discarded – undo
165 165
 	            $currentObjectTypeEnum
166 166
 	        );
167 167
 	        $oid_index++;
168
-	        array_push($this->view->objectList,$currentObject);
168
+	        array_push($this->view->objectList, $currentObject);
169 169
 	        // set currrent object to null in allObjects
170 170
 	        if (isset($allObjects[$val->oid]))
171 171
 	        {
172 172
 	            $allObjects[$val->oid]=null;
173 173
 	        }
174 174
 	    }
175
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
175
+	    if ($allObjects != null) // in case trap doesn't have objects or is not resolved
176 176
 	    {
177 177
 	        foreach ($allObjects as $key => $val)
178 178
 	        {
179
-	            if ($val==null) { continue; }
179
+	            if ($val == null) { continue; }
180 180
 	            array_push($this->view->objectList, array(
181 181
 	                $oid_index,
182 182
 	                $key,
@@ -204,9 +204,9 @@  discard block
 block discarded – undo
204 204
 	    // Check if hostname still exists
205 205
 	    $host_get=$this->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;
@@ -490,25 +490,25 @@  discard block
 block discarded – undo
490 490
 					return;					
491 491
 				}
492 492
 				// Put param in correct column (group_name)
493
-				$params['host_group_name']['val'] = $params['host_name']['val'];
493
+				$params['host_group_name']['val']=$params['host_name']['val'];
494 494
 				$params['host_name']['val']=null;
495 495
 			}
496 496
 			$dbparams=array();
497 497
 			foreach ($params as $key=>$val)
498 498
 			{
499
-				if ($val['db']==true )
499
+				if ($val['db'] == true)
500 500
 				{
501
-					$dbparams[$key] = $val['val'];
501
+					$dbparams[$key]=$val['val'];
502 502
 				}
503 503
 			}
504 504
 			// echo '<br>';	print_r($dbparams);echo '<br>';
505
-			if ($params['db_rule']['val'] == -1 ) 
505
+			if ($params['db_rule']['val'] == -1) 
506 506
 			{
507 507
 			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
508 508
 			}
509 509
 			else
510 510
 			{
511
-			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
511
+			    $this->getUIDatabase()->updateHandlerRule($dbparams, $params['db_rule']['val']);
512 512
 				$ruleID=$params['db_rule']['val'];
513 513
 			}
514 514
 		}
@@ -527,10 +527,10 @@  discard block
 block discarded – undo
527 527
 	*/
528 528
 	protected function getTrapDetail($trapid) 
529 529
 	{
530
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
530
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
531 531
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
532 532
 		
533
-		$dbConn = $this->getUIDatabase()->getDbConn();
533
+		$dbConn=$this->getUIDatabase()->getDbConn();
534 534
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
535 535
 		// ***************  Get main data
536 536
 		// extract columns and titles;
@@ -540,19 +540,19 @@  discard block
 block discarded – undo
540 540
 		}
541 541
 		try
542 542
 		{		
543
-		    $query = $dbConn->select()
544
-				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
545
-				->where('id=?',$trapid);
543
+		    $query=$dbConn->select()
544
+				->from($this->getModuleConfig()->getTrapTableName(), $elmts)
545
+				->where('id=?', $trapid);
546 546
 				$trapDetail=$dbConn->fetchRow($query);
547
-			if ( $trapDetail == null ) 
547
+			if ($trapDetail == null) 
548 548
 			{
549
-			    $trapDetail = 'NULL';
549
+			    $trapDetail='NULL';
550 550
 			    throw new Exception('No traps was found with id = '.$trapid);
551 551
 			}
552 552
 		}
553 553
 		catch (Exception $e)
554 554
 		{
555
-			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
555
+			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail, true), $e->getMessage());
556 556
 			return;
557 557
 		}
558 558
 
@@ -566,10 +566,10 @@  discard block
 block discarded – undo
566 566
 	*/
567 567
 	protected function getTrapobjects($trapid)
568 568
 	{	
569
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
569
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
570 570
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
571 571
 		
572
-		$dbConn = $this->getUIDatabase()->getDbConn();
572
+		$dbConn=$this->getUIDatabase()->getDbConn();
573 573
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
574 574
 		// ***************  Get object data
575 575
 		// extract columns and titles;
@@ -579,15 +579,15 @@  discard block
 block discarded – undo
579 579
 		}
580 580
 		try
581 581
 		{		
582
-		    $query = $dbConn->select()
583
-				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
584
-				->where('trap_id=?',$trapid);
582
+		    $query=$dbConn->select()
583
+				->from($this->moduleConfig->getTrapDataTableName(), $data_elmts)
584
+				->where('trap_id=?', $trapid);
585 585
 				$trapDetail=$dbConn->fetchAll($query);
586 586
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
587 587
 		}
588 588
 		catch (Exception $e)
589 589
 		{
590
-			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
590
+			$this->displayExitError('Add handler : get trap data detail : ', $e->getMessage());
591 591
 			return array();
592 592
 		}
593 593
 
@@ -601,24 +601,24 @@  discard block
 block discarded – undo
601 601
 	*/
602 602
 	protected function getRuleDetail($ruleid) 
603 603
 	{
604
-		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
604
+		if (!preg_match('/^[0-9]+$/', $ruleid)) { throw new Exception('Invalid id'); }
605 605
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
606 606
 		
607
-		$dbConn = $this->getUIDatabase()->getDbConn();
607
+		$dbConn=$this->getUIDatabase()->getDbConn();
608 608
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
609 609
 		// ***************  Get main data
610 610
 		try
611 611
 		{		
612
-		    $query = $dbConn->select()
613
-				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
614
-				->where('id=?',$ruleid);
612
+		    $query=$dbConn->select()
613
+				->from($this->getModuleConfig()->getTrapRuleName(), $queryArray)
614
+				->where('id=?', $ruleid);
615 615
 			$ruleDetail=$dbConn->fetchRow($query);
616
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
616
+			if ($ruleDetail == null) throw new Exception('No rule was found with id = '.$ruleid);
617 617
 		}
618 618
 		catch (Exception $e)
619 619
 		{
620
-			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
621
-			throw new Exception('Error : ',$e->getMessage());
620
+			$this->displayExitError('Update handler : get rule detail', $e->getMessage());
621
+			throw new Exception('Error : ', $e->getMessage());
622 622
 		}
623 623
 
624 624
 		return $ruleDetail;
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
 	{
632 632
 		return $this->getTabs()->add('status', array(
633 633
 			'label' => $this->translate('Traps'),
634
-			'url'   => $this->getModuleConfig()->urlPath() . '/handler')
634
+			'url'   => $this->getModuleConfig()->urlPath().'/handler')
635 635
 		);
636 636
 	} 
637 637
 	
Please login to merge, or discard this patch.
Braces   +44 added lines, -42 removed lines patch added patch discarded remove patch
@@ -24,7 +24,9 @@  discard block
 block discarded – undo
24 24
 		$this->prepareTabs()->activate('status');
25 25
 
26 26
 		$dbConn = $this->getUIDatabase()->getDb();
27
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
27
+		if ($dbConn === null) {
28
+			throw new \ErrorException('uncatched db error');
29
+		}
28 30
 		
29 31
 		$this->getHandlerListTable()->setConnection($dbConn);
30 32
 		$this->getHandlerListTable()->setMibloader($this->getMIB());
@@ -52,8 +54,7 @@  discard block
 block discarded – undo
52 54
 	    if ($this->params->get('rule') !== null) 
53 55
 	    {
54 56
 	        $this->view->rule= $this->params->get('rule');
55
-	    }
56
-	    else
57
+	    } else
57 58
 	    {
58 59
 	        $this->view->rule='';
59 60
 	    }
@@ -107,8 +108,7 @@  discard block
 block discarded – undo
107 108
 	    try
108 109
 	    {
109 110
 	        $hosts=$this->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 !="")
@@ -480,8 +480,7 @@  discard block
 block discarded – undo
480 480
 					$this->_helper->json(array('status'=>"Invalid service id : Please re enter service"));
481 481
 					return;
482 482
 				}
483
-			}
484
-			else
483
+			} else
485 484
 			{
486 485
 			    $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']);
487 486
 				if ($params['host_name']['val'] != $object->name1)
@@ -505,14 +504,12 @@  discard block
 block discarded – undo
505 504
 			if ($params['db_rule']['val'] == -1 ) 
506 505
 			{
507 506
 			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
508
-			}
509
-			else
507
+			} else
510 508
 			{
511 509
 			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
512 510
 				$ruleID=$params['db_rule']['val'];
513 511
 			}
514
-		}
515
-		catch (Exception $e)
512
+		} catch (Exception $e)
516 513
 		{
517 514
 			$this->_helper->json(array('status'=>$e->getMessage()));
518 515
 			return;
@@ -531,7 +528,9 @@  discard block
 block discarded – undo
531 528
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
532 529
 		
533 530
 		$dbConn = $this->getUIDatabase()->getDbConn();
534
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
531
+		if ($dbConn === null) {
532
+			throw new \ErrorException('uncatched db error');
533
+		}
535 534
 		// ***************  Get main data
536 535
 		// extract columns and titles;
537 536
 		$elmts=NULL;
@@ -549,8 +548,7 @@  discard block
 block discarded – undo
549 548
 			    $trapDetail = 'NULL';
550 549
 			    throw new Exception('No traps was found with id = '.$trapid);
551 550
 			}
552
-		}
553
-		catch (Exception $e)
551
+		} catch (Exception $e)
554 552
 		{
555 553
 			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
556 554
 			return;
@@ -570,7 +568,9 @@  discard block
 block discarded – undo
570 568
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
571 569
 		
572 570
 		$dbConn = $this->getUIDatabase()->getDbConn();
573
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
571
+		if ($dbConn === null) {
572
+			throw new \ErrorException('uncatched db error');
573
+		}
574 574
 		// ***************  Get object data
575 575
 		// extract columns and titles;
576 576
 		$data_elmts=NULL;
@@ -584,8 +584,7 @@  discard block
 block discarded – undo
584 584
 				->where('trap_id=?',$trapid);
585 585
 				$trapDetail=$dbConn->fetchAll($query);
586 586
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
587
-		}
588
-		catch (Exception $e)
587
+		} catch (Exception $e)
589 588
 		{
590 589
 			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
591 590
 			return array();
@@ -605,7 +604,9 @@  discard block
 block discarded – undo
605 604
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
606 605
 		
607 606
 		$dbConn = $this->getUIDatabase()->getDbConn();
608
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
607
+		if ($dbConn === null) {
608
+			throw new \ErrorException('uncatched db error');
609
+		}
609 610
 		// ***************  Get main data
610 611
 		try
611 612
 		{		
@@ -613,9 +614,10 @@  discard block
 block discarded – undo
613 614
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
614 615
 				->where('id=?',$ruleid);
615 616
 			$ruleDetail=$dbConn->fetchRow($query);
616
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
617
-		}
618
-		catch (Exception $e)
617
+			if ( $ruleDetail == null ) {
618
+				throw new Exception('No rule was found with id = '.$ruleid);
619
+			}
620
+		} catch (Exception $e)
619 621
 		{
620 622
 			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
621 623
 			throw new Exception('Error : ',$e->getMessage());
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/MibDatabase.php 3 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -4,61 +4,61 @@
 block discarded – undo
4 4
 
5 5
 trait MibDatabase
6 6
 {
7
-    /** @return \Trapdirector\Logging */
8
-    abstract public function getLogging();
7
+	/** @return \Trapdirector\Logging */
8
+	abstract public function getLogging();
9 9
     
10
-    /** @return \Trapdirector\Database */
11
-    abstract public function getTrapsDB();
10
+	/** @return \Trapdirector\Database */
11
+	abstract public function getTrapsDB();
12 12
   
13
-    /**
14
-     * Update object in DB with object in dbOidIndex if name/mib/type has changed.
15
-     * @return number : 0=unchanged, 1 = changed, 2=created
16
-     */
17
-    private function update_oid_update()
18
-    {
13
+	/**
14
+	 * Update object in DB with object in dbOidIndex if name/mib/type has changed.
15
+	 * @return number : 0=unchanged, 1 = changed, 2=created
16
+	 */
17
+	private function update_oid_update()
18
+	{
19 19
         
20
-        $db_conn=$this->getTrapsDB()->db_connect_trap();
20
+		$db_conn=$this->getTrapsDB()->db_connect_trap();
21 21
         
22
-        if ($this->dbOidIndex[$this->oidDesc['oid']]['key'] == -1)
23
-        { // newly created.
24
-            return 0;
25
-        }
26
-        $oidIndex=$this->dbOidIndex[$this->oidDesc['oid']]['key']; // Get index in dbOidAll
27
-        $dbOid=$this->dbOidAll[$oidIndex]; // Get array of element
28
-        if ( $this->oidDesc['name'] != $dbOid['name'] ||
29
-            $this->oidDesc['mib'] != $dbOid['mib'] ||
30
-            $this->oidDesc['type'] !=$dbOid['type']
31
-            )
32
-        { // Do update
33
-            $sql='UPDATE '.$this->getTrapsDB()->dbPrefix.'mib_cache SET '.
34
-                'name = :name , type = :type , mib = :mib , textual_convention = :tc , display_hint = :display_hint'.
35
-                ', syntax = :syntax, type_enum = :type_enum, description = :description '.
36
-                ' WHERE id= :id';
37
-            $sqlQuery=$db_conn->prepare($sql);
22
+		if ($this->dbOidIndex[$this->oidDesc['oid']]['key'] == -1)
23
+		{ // newly created.
24
+			return 0;
25
+		}
26
+		$oidIndex=$this->dbOidIndex[$this->oidDesc['oid']]['key']; // Get index in dbOidAll
27
+		$dbOid=$this->dbOidAll[$oidIndex]; // Get array of element
28
+		if ( $this->oidDesc['name'] != $dbOid['name'] ||
29
+			$this->oidDesc['mib'] != $dbOid['mib'] ||
30
+			$this->oidDesc['type'] !=$dbOid['type']
31
+			)
32
+		{ // Do update
33
+			$sql='UPDATE '.$this->getTrapsDB()->dbPrefix.'mib_cache SET '.
34
+				'name = :name , type = :type , mib = :mib , textual_convention = :tc , display_hint = :display_hint'.
35
+				', syntax = :syntax, type_enum = :type_enum, description = :description '.
36
+				' WHERE id= :id';
37
+			$sqlQuery=$db_conn->prepare($sql);
38 38
             
39
-            $sqlParam=array(
40
-                ':name' => $this->oidDesc['name'],
41
-                ':type' => $this->oidDesc['type'],
42
-                ':mib' => $this->oidDesc['mib'],
43
-                ':tc' =>  $this->oidDesc['textconv']??'null',
44
-                ':display_hint' => $this->oidDesc['dispHint']??'null' ,
45
-                ':syntax' => $this->oidDesc['syntax']==null??'null',
46
-                ':type_enum' => $this->oidDesc['type_enum']??'null',
47
-                ':description' => $this->oidDesc['description']??'null',
48
-                ':id' => $this->dbOidAll[$this->dbOidIndex[$this->oidDesc['oid']]['id']]
49
-            );
39
+			$sqlParam=array(
40
+				':name' => $this->oidDesc['name'],
41
+				':type' => $this->oidDesc['type'],
42
+				':mib' => $this->oidDesc['mib'],
43
+				':tc' =>  $this->oidDesc['textconv']??'null',
44
+				':display_hint' => $this->oidDesc['dispHint']??'null' ,
45
+				':syntax' => $this->oidDesc['syntax']==null??'null',
46
+				':type_enum' => $this->oidDesc['type_enum']??'null',
47
+				':description' => $this->oidDesc['description']??'null',
48
+				':id' => $this->dbOidAll[$this->dbOidIndex[$this->oidDesc['oid']]['id']]
49
+			);
50 50
             
51
-            if ($sqlQuery->execute($sqlParam) === false) {
52
-                $this->getLogging()->log('Error in query : ' . $sql,ERROR,'');
53
-            }
54
-            $this->getLogging()->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
55
-            return 1;
56
-        }
57
-        else
58
-        {
59
-            $this->getLogging()->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
60
-            return 0;
61
-        }
62
-    }
51
+			if ($sqlQuery->execute($sqlParam) === false) {
52
+				$this->getLogging()->log('Error in query : ' . $sql,ERROR,'');
53
+			}
54
+			$this->getLogging()->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
55
+			return 1;
56
+		}
57
+		else
58
+		{
59
+			$this->getLogging()->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
60
+			return 0;
61
+		}
62
+	}
63 63
     
64 64
 }
65 65
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -25,9 +25,9 @@  discard block
 block discarded – undo
25 25
         }
26 26
         $oidIndex=$this->dbOidIndex[$this->oidDesc['oid']]['key']; // Get index in dbOidAll
27 27
         $dbOid=$this->dbOidAll[$oidIndex]; // Get array of element
28
-        if ( $this->oidDesc['name'] != $dbOid['name'] ||
28
+        if ($this->oidDesc['name'] != $dbOid['name'] ||
29 29
             $this->oidDesc['mib'] != $dbOid['mib'] ||
30
-            $this->oidDesc['type'] !=$dbOid['type']
30
+            $this->oidDesc['type'] != $dbOid['type']
31 31
             )
32 32
         { // Do update
33 33
             $sql='UPDATE '.$this->getTrapsDB()->dbPrefix.'mib_cache SET '.
@@ -41,22 +41,22 @@  discard block
 block discarded – undo
41 41
                 ':type' => $this->oidDesc['type'],
42 42
                 ':mib' => $this->oidDesc['mib'],
43 43
                 ':tc' =>  $this->oidDesc['textconv']??'null',
44
-                ':display_hint' => $this->oidDesc['dispHint']??'null' ,
45
-                ':syntax' => $this->oidDesc['syntax']==null??'null',
44
+                ':display_hint' => $this->oidDesc['dispHint']??'null',
45
+                ':syntax' => $this->oidDesc['syntax'] == null??'null',
46 46
                 ':type_enum' => $this->oidDesc['type_enum']??'null',
47 47
                 ':description' => $this->oidDesc['description']??'null',
48 48
                 ':id' => $this->dbOidAll[$this->dbOidIndex[$this->oidDesc['oid']]['id']]
49 49
             );
50 50
             
51 51
             if ($sqlQuery->execute($sqlParam) === false) {
52
-                $this->getLogging()->log('Error in query : ' . $sql,ERROR,'');
52
+                $this->getLogging()->log('Error in query : '.$sql, ERROR, '');
53 53
             }
54
-            $this->getLogging()->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
54
+            $this->getLogging()->log('Trap updated : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], DEBUG);
55 55
             return 1;
56 56
         }
57 57
         else
58 58
         {
59
-            $this->getLogging()->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
59
+            $this->getLogging()->log('Trap unchanged : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], DEBUG);
60 60
             return 0;
61 61
         }
62 62
     }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -53,8 +53,7 @@
 block discarded – undo
53 53
             }
54 54
             $this->getLogging()->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
55 55
             return 1;
56
-        }
57
-        else
56
+        } else
58 57
         {
59 58
             $this->getLogging()->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
60 59
             return 0;
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/Mib.php 3 patches
Indentation   +550 added lines, -550 removed lines patch added patch discarded remove patch
@@ -17,173 +17,173 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class Mib
19 19
 {
20
-    use \MibDatabase;
20
+	use \MibDatabase;
21 21
     
22
-    /** @var Logging $logging logging class */
23
-    protected $logging;
24
-    /** @var Database $trapsDB Database class */
25
-    protected $trapsDB;
22
+	/** @var Logging $logging logging class */
23
+	protected $logging;
24
+	/** @var Database $trapsDB Database class */
25
+	protected $trapsDB;
26 26
     
27
-    /** @var string $snmptranslate */
28
-    public $snmptranslate;
29
-    /** @var string $snmptranslateDirs */
30
-    public $snmptranslateDirs;
27
+	/** @var string $snmptranslate */
28
+	public $snmptranslate;
29
+	/** @var string $snmptranslateDirs */
30
+	public $snmptranslateDirs;
31 31
     
32
-    private $dbOidAll; //< All oid in database;
33
-    private $dbOidIndex; //< Index of oid in dbOidAll
34
-    private $objectsAll; //< output lines of snmptranslate list
35
-    private $trapObjectsIndex; //< array of traps objects (as OID)
32
+	private $dbOidAll; //< All oid in database;
33
+	private $dbOidIndex; //< Index of oid in dbOidAll
34
+	private $objectsAll; //< output lines of snmptranslate list
35
+	private $trapObjectsIndex; //< array of traps objects (as OID)
36 36
     
37
-    private $oidDesc=array(); //< $oid,$mib,$name,$type,$textConv,$dispHint,$syntax,$type_enum,$description=NULL
37
+	private $oidDesc=array(); //< $oid,$mib,$name,$type,$textConv,$dispHint,$syntax,$type_enum,$description=NULL
38 38
 
39
-    // Timing vars for update
40
-    private $timing=array();
39
+	// Timing vars for update
40
+	private $timing=array();
41 41
     
42
-    /**
43
-     * Setup Mib Class
44
-     * @param Logging $logClass : where to log
45
-     * @param Database $dbClass : Database
46
-     */
47
-    function __construct($logClass,$dbClass,$snmptrans,$snmptransdir)
48
-    {
49
-        $this->logging=$logClass;
50
-        $this->trapsDB=$dbClass;
51
-        $this->snmptranslate=$snmptrans;
52
-        $this->snmptranslateDirs=$snmptransdir;
42
+	/**
43
+	 * Setup Mib Class
44
+	 * @param Logging $logClass : where to log
45
+	 * @param Database $dbClass : Database
46
+	 */
47
+	function __construct($logClass,$dbClass,$snmptrans,$snmptransdir)
48
+	{
49
+		$this->logging=$logClass;
50
+		$this->trapsDB=$dbClass;
51
+		$this->snmptranslate=$snmptrans;
52
+		$this->snmptranslateDirs=$snmptransdir;
53 53
 
54
-    }
54
+	}
55 55
     
56
-    /**
57
-     * @return \Trapdirector\Logging
58
-     */
59
-    public function getLogging()
60
-    {
61
-        return $this->logging;
62
-    }
56
+	/**
57
+	 * @return \Trapdirector\Logging
58
+	 */
59
+	public function getLogging()
60
+	{
61
+		return $this->logging;
62
+	}
63 63
 
64
-    /**
65
-     * @return \Trapdirector\Database
66
-     */
67
-    public function getTrapsDB()
68
-    {
69
-        return $this->trapsDB;
70
-    }
64
+	/**
65
+	 * @return \Trapdirector\Database
66
+	 */
67
+	public function getTrapsDB()
68
+	{
69
+		return $this->trapsDB;
70
+	}
71 71
 
72 72
 
73 73
 
74
-    /**
75
-     * Create object in DB with object in dbOidIndex
76
-     * @return number : 0=unchanged, 1 = changed, 2=created
77
-     */
78
-    private function update_oid_create()
79
-    {
80
-        // Insert data
74
+	/**
75
+	 * Create object in DB with object in dbOidIndex
76
+	 * @return number : 0=unchanged, 1 = changed, 2=created
77
+	 */
78
+	private function update_oid_create()
79
+	{
80
+		// Insert data
81 81
         
82
-        $db_conn=$this->trapsDB->db_connect_trap();
83
-        $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache '.
84
-            '(oid, name, type , mib, textual_convention, display_hint '.
85
-            ', syntax, type_enum , description ) ' .
86
-            'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
87
-            ', :syntax, :type_enum, :description )';
82
+		$db_conn=$this->trapsDB->db_connect_trap();
83
+		$sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache '.
84
+			'(oid, name, type , mib, textual_convention, display_hint '.
85
+			', syntax, type_enum , description ) ' .
86
+			'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
87
+			', :syntax, :type_enum, :description )';
88 88
         
89
-        if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id';
89
+		if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id';
90 90
         
91
-        $sqlQuery=$db_conn->prepare($sql);
91
+		$sqlQuery=$db_conn->prepare($sql);
92 92
         
93
-        $sqlParam=array(
94
-            ':oid' => $this->oidDesc['oid'],
95
-            ':name' => $this->oidDesc['name'],
96
-            ':type' => $this->oidDesc['type'],
97
-            ':mib' => $this->oidDesc['mib'],
98
-            ':tc' =>  $this->oidDesc['textconv']??'null',
99
-            ':display_hint' => $this->oidDesc['dispHint']??'null',
100
-            ':syntax' => $this->oidDesc['syntax']??'null',
101
-            ':type_enum' => $this->oidDesc['type_enum']??'null',
102
-            ':description' => $this->oidDesc['description']??'null'
103
-        );
93
+		$sqlParam=array(
94
+			':oid' => $this->oidDesc['oid'],
95
+			':name' => $this->oidDesc['name'],
96
+			':type' => $this->oidDesc['type'],
97
+			':mib' => $this->oidDesc['mib'],
98
+			':tc' =>  $this->oidDesc['textconv']??'null',
99
+			':display_hint' => $this->oidDesc['dispHint']??'null',
100
+			':syntax' => $this->oidDesc['syntax']??'null',
101
+			':type_enum' => $this->oidDesc['type_enum']??'null',
102
+			':description' => $this->oidDesc['description']??'null'
103
+		);
104 104
         
105
-        if ($sqlQuery->execute($sqlParam) === false) {
106
-            $this->logging->log('Error in query : ' . $sql,1,'');
107
-        }
105
+		if ($sqlQuery->execute($sqlParam) === false) {
106
+			$this->logging->log('Error in query : ' . $sql,1,'');
107
+		}
108 108
         
109
-        switch ($this->trapsDB->trapDBType)
110
-        {
111
-            case 'pgsql':
112
-                // Get last id to insert oid/values in secondary table
113
-                if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {
114
-                    $this->logging->log('Error getting id - pgsql - ',1,'');
115
-                }
116
-                if (! isset($inserted_id_ret['id'])) {
117
-                    $this->logging->log('Error getting id - pgsql - empty.',ERROR);
118
-                    return 0;
119
-                }
120
-                $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id_ret['id'];
121
-                break;
122
-            case 'mysql':
123
-                // Get last id to insert oid/values in secondary table
124
-                $sql='SELECT LAST_INSERT_ID();';
125
-                if (($ret_code=$db_conn->query($sql)) === false) {
126
-                    $this->logging->log('Erreur getting id - mysql - ',ERROR);
127
-                    return 0;
128
-                }
109
+		switch ($this->trapsDB->trapDBType)
110
+		{
111
+			case 'pgsql':
112
+				// Get last id to insert oid/values in secondary table
113
+				if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {
114
+					$this->logging->log('Error getting id - pgsql - ',1,'');
115
+				}
116
+				if (! isset($inserted_id_ret['id'])) {
117
+					$this->logging->log('Error getting id - pgsql - empty.',ERROR);
118
+					return 0;
119
+				}
120
+				$this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id_ret['id'];
121
+				break;
122
+			case 'mysql':
123
+				// Get last id to insert oid/values in secondary table
124
+				$sql='SELECT LAST_INSERT_ID();';
125
+				if (($ret_code=$db_conn->query($sql)) === false) {
126
+					$this->logging->log('Erreur getting id - mysql - ',ERROR);
127
+					return 0;
128
+				}
129 129
                 
130
-                $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
131
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
132
-                $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id;
133
-                break;
134
-            default:
135
-                $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,ERROR);
136
-                return 0;
137
-        }
130
+				$inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
131
+				if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
132
+				$this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id;
133
+				break;
134
+			default:
135
+				$this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,ERROR);
136
+				return 0;
137
+		}
138 138
         
139
-        // Set as newly created.
140
-        $this->dbOidIndex[$this->oidDesc['oid']]['key']=-1;
141
-        return 2;
142
-    }
139
+		// Set as newly created.
140
+		$this->dbOidIndex[$this->oidDesc['oid']]['key']=-1;
141
+		return 2;
142
+	}
143 143
     
144
-    /**
145
-     * Update or add an OID to database uses $this->dbOidIndex for mem cache
146
-     * and $this->oidDesc doe data
147
-     * @return number : 0=unchanged, 1 = changed, 2=created
148
-     */
149
-    public function update_oid()
150
-    {
151
-        $db_conn=$this->trapsDB->db_connect_trap();
152
-        // Quote description.
153
-        $this->oidDesc['description']=$db_conn->quote($this->oidDesc['description']);
144
+	/**
145
+	 * Update or add an OID to database uses $this->dbOidIndex for mem cache
146
+	 * and $this->oidDesc doe data
147
+	 * @return number : 0=unchanged, 1 = changed, 2=created
148
+	 */
149
+	public function update_oid()
150
+	{
151
+		$db_conn=$this->trapsDB->db_connect_trap();
152
+		// Quote description.
153
+		$this->oidDesc['description']=$db_conn->quote($this->oidDesc['description']);
154 154
         
155
-        if (isset($this->dbOidIndex[$this->oidDesc['oid']]))
156
-        { // oid exists in db, so update
157
-            return $this->update_oid_update();
158
-        }
159
-        // create new OID.
160
-        return $this->update_oid_create();
155
+		if (isset($this->dbOidIndex[$this->oidDesc['oid']]))
156
+		{ // oid exists in db, so update
157
+			return $this->update_oid_update();
158
+		}
159
+		// create new OID.
160
+		return $this->update_oid_create();
161 161
 
162
-    }
162
+	}
163 163
     
164 164
 /**
165 165
  * get all objects for a trap.
166 166
  * @param integer $trapId
167 167
  * @return array : array of cached objects
168 168
  */    
169
-    private function cache_db_objects($trapId)
170
-    {
171
-        $dbObjects=array(); // cache of objects for trap in db
172
-        $db_conn=$this->trapsDB->db_connect_trap();
173
-        // Get all objects
174
-        $sql='SELECT * FROM '.$this->trapsDB->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';';
175
-        $this->logging->log('SQL query get all traps: '.$sql,DEBUG );
176
-        if (($ret_code=$db_conn->query($sql)) === false) {
177
-            $this->logging->log('No result in query : ' . $sql,1,'');
178
-        }
179
-        $dbObjectsRaw=$ret_code->fetchAll();
169
+	private function cache_db_objects($trapId)
170
+	{
171
+		$dbObjects=array(); // cache of objects for trap in db
172
+		$db_conn=$this->trapsDB->db_connect_trap();
173
+		// Get all objects
174
+		$sql='SELECT * FROM '.$this->trapsDB->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';';
175
+		$this->logging->log('SQL query get all traps: '.$sql,DEBUG );
176
+		if (($ret_code=$db_conn->query($sql)) === false) {
177
+			$this->logging->log('No result in query : ' . $sql,1,'');
178
+		}
179
+		$dbObjectsRaw=$ret_code->fetchAll();
180 180
         
181
-        foreach ($dbObjectsRaw as $val)
182
-        {
183
-            $dbObjects[$val['object_id']]=1;
184
-        }
185
-        return $dbObjects;
186
-    }
181
+		foreach ($dbObjectsRaw as $val)
182
+		{
183
+			$dbObjects[$val['object_id']]=1;
184
+		}
185
+		return $dbObjects;
186
+	}
187 187
 
188 188
 /**
189 189
  * Get object details & mib , returns snmptranslate output
@@ -191,478 +191,478 @@  discard block
 block discarded – undo
191 191
  * @param string $trapmib : mib of trap
192 192
  * @return NULL|array : null if not found, or output of snmptranslate
193 193
  */
194
-    private function get_object_details($object,$trapmib)
195
-    {
196
-        $match=$snmptrans=array();
197
-        $retVal=0;
198
-        $this->oidDesc['mib']=$trapmib;
199
-        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
200
-            ' -On -Td '.$this->oidDesc['mib'].'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
201
-        if ($retVal!=0)
202
-        {
203
-            // Maybe not trap mib, search with IR
204
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
205
-                ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
206
-            if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
207
-            { // Not found -> continue with warning
208
-                $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
209
-                return null;
210
-            }
211
-            $this->oidDesc['mib']=$match[1];
194
+	private function get_object_details($object,$trapmib)
195
+	{
196
+		$match=$snmptrans=array();
197
+		$retVal=0;
198
+		$this->oidDesc['mib']=$trapmib;
199
+		exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
200
+			' -On -Td '.$this->oidDesc['mib'].'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
201
+		if ($retVal!=0)
202
+		{
203
+			// Maybe not trap mib, search with IR
204
+			exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
205
+				' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
206
+			if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
207
+			{ // Not found -> continue with warning
208
+				$this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
209
+				return null;
210
+			}
211
+			$this->oidDesc['mib']=$match[1];
212 212
             
213
-            // Do the snmptranslate again.
214
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
215
-                ' -On -Td '.$this->oidDesc['mib'].'::'.$object,$snmptrans,$retVal);
216
-            if ($retVal!=0) {
217
-                $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object,2,'');
218
-                return null;
219
-            }
213
+			// Do the snmptranslate again.
214
+			exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
215
+				' -On -Td '.$this->oidDesc['mib'].'::'.$object,$snmptrans,$retVal);
216
+			if ($retVal!=0) {
217
+				$this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object,2,'');
218
+				return null;
219
+			}
220 220
             
221
-        }
222
-        return $snmptrans;
223
-    }
221
+		}
222
+		return $snmptrans;
223
+	}
224 224
 
225 225
 /**
226 226
  * Parse snmptranslate output and set  $this->oidDesc with elements 
227 227
  * @param array $snmptrans : multi line output of snmptrans
228 228
  */
229
-    private function parse_object($snmptrans)
230
-    {
231
-        $tmpdesc=''; // For multiline description
232
-        $indesc=false; // true if currently inside multiline description
233
-        $match=array();
229
+	private function parse_object($snmptrans)
230
+	{
231
+		$tmpdesc=''; // For multiline description
232
+		$indesc=false; // true if currently inside multiline description
233
+		$match=array();
234 234
         
235
-        foreach ($snmptrans as $line)
236
-        {
237
-            if ($indesc===true)
238
-            {
239
-                $line=preg_replace('/[\t ]+/',' ',$line);
240
-                if (preg_match('/(.*)"$/', $line,$match))
241
-                {
242
-                    $this->oidDesc['description'] = $tmpdesc . $match[1];
243
-                    $indesc=false;
244
-                }
245
-                $tmpdesc.=$line;
246
-                continue;
247
-            }
248
-            if (preg_match('/^\.[0-9\.]+$/', $line))
249
-            {
250
-                $this->oidDesc['oid']=$line;
251
-                continue;
252
-            }
253
-            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
254
-            {
255
-                $this->oidDesc['syntax']=$match[1];
256
-                $this->oidDesc['type_enum']=$match[2];
257
-                continue;
258
-            }
259
-            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
260
-            {
261
-                $this->oidDesc['syntax']=$match[1];
262
-                continue;
263
-            }
264
-            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
265
-            {
266
-                $this->oidDesc['dispHint']=$match[1];
267
-                continue;
268
-            }
269
-            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
270
-            {
271
-                $this->oidDesc['description']=$match[1];
272
-                continue;
273
-            }
274
-            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
275
-            {
276
-                $tmpdesc=$match[1];
277
-                $indesc=true;
278
-                continue;
279
-            }
280
-            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
281
-            {
282
-                $this->oidDesc['textconv']=$match[1];
283
-                continue;
284
-            }
285
-        }
286
-    }
235
+		foreach ($snmptrans as $line)
236
+		{
237
+			if ($indesc===true)
238
+			{
239
+				$line=preg_replace('/[\t ]+/',' ',$line);
240
+				if (preg_match('/(.*)"$/', $line,$match))
241
+				{
242
+					$this->oidDesc['description'] = $tmpdesc . $match[1];
243
+					$indesc=false;
244
+				}
245
+				$tmpdesc.=$line;
246
+				continue;
247
+			}
248
+			if (preg_match('/^\.[0-9\.]+$/', $line))
249
+			{
250
+				$this->oidDesc['oid']=$line;
251
+				continue;
252
+			}
253
+			if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
254
+			{
255
+				$this->oidDesc['syntax']=$match[1];
256
+				$this->oidDesc['type_enum']=$match[2];
257
+				continue;
258
+			}
259
+			if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
260
+			{
261
+				$this->oidDesc['syntax']=$match[1];
262
+				continue;
263
+			}
264
+			if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
265
+			{
266
+				$this->oidDesc['dispHint']=$match[1];
267
+				continue;
268
+			}
269
+			if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
270
+			{
271
+				$this->oidDesc['description']=$match[1];
272
+				continue;
273
+			}
274
+			if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
275
+			{
276
+				$tmpdesc=$match[1];
277
+				$indesc=true;
278
+				continue;
279
+			}
280
+			if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
281
+			{
282
+				$this->oidDesc['textconv']=$match[1];
283
+				continue;
284
+			}
285
+		}
286
+	}
287 287
 
288
-    /**
289
-     * create or update (with check_existing = true) objects of trap
290
-     * @param string $trapOID : trap oid
291
-     * @param string $trapmib : mib of trap
292
-     * @param array $objects : array of objects name (without MIB)
293
-     * @param bool $check_existing : check instead of create
294
-     */
295
-    public function trap_objects($trapOID,$trapmib,$objects,$check_existing)
296
-    {              
297
-        $trapId = $this->dbOidIndex[$trapOID]['id']; // Get id of trap
288
+	/**
289
+	 * create or update (with check_existing = true) objects of trap
290
+	 * @param string $trapOID : trap oid
291
+	 * @param string $trapmib : mib of trap
292
+	 * @param array $objects : array of objects name (without MIB)
293
+	 * @param bool $check_existing : check instead of create
294
+	 */
295
+	public function trap_objects($trapOID,$trapmib,$objects,$check_existing)
296
+	{              
297
+		$trapId = $this->dbOidIndex[$trapOID]['id']; // Get id of trap
298 298
         
299
-        if ($check_existing === true)
300
-        {
301
-            $dbObjects=$this->cache_db_objects($trapId);
302
-        }
299
+		if ($check_existing === true)
300
+		{
301
+			$dbObjects=$this->cache_db_objects($trapId);
302
+		}
303 303
         
304
-        foreach ($objects as $object)
305
-        {
304
+		foreach ($objects as $object)
305
+		{
306 306
             
307
-            $this->reset_oidDesc();
307
+			$this->reset_oidDesc();
308 308
             
309
-            $snmptrans=$this->get_object_details($object, $trapmib); // Get object mib & details
310
-            if ($snmptrans === null) continue; // object not found
309
+			$snmptrans=$this->get_object_details($object, $trapmib); // Get object mib & details
310
+			if ($snmptrans === null) continue; // object not found
311 311
             
312
-            $this->parse_object($snmptrans);
312
+			$this->parse_object($snmptrans);
313 313
 
314
-            $this->oidDesc['name'] = $object;
314
+			$this->oidDesc['name'] = $object;
315 315
             
316
-            $this->logging->log("Adding object ".$this->oidDesc['name']." : ".$this->oidDesc['oid']." / ".$this->oidDesc['syntax']." / ".$this->oidDesc['type_enum']." / ".$this->oidDesc['dispHint']." / ".$this->oidDesc['textconv'],DEBUG );
316
+			$this->logging->log("Adding object ".$this->oidDesc['name']." : ".$this->oidDesc['oid']." / ".$this->oidDesc['syntax']." / ".$this->oidDesc['type_enum']." / ".$this->oidDesc['dispHint']." / ".$this->oidDesc['textconv'],DEBUG );
317 317
 
318
-            // Update
319
-            $this->update_oid();
318
+			// Update
319
+			$this->update_oid();
320 320
             
321
-            if (isset($dbObjects[$this->dbOidIndex[$this->oidDesc['oid']]['id']]))
322
-            {   // if link exists, continue
323
-                $dbObjects[$this->dbOidIndex[$this->oidDesc['oid']]['id']]=2;
324
-                continue;
325
-            }
326
-            if ($check_existing === true)
327
-            {
328
-                // TODO : check link trap - objects exists, mark them.
329
-            }
330
-            // Associate in object table
331
-            $db_conn=$this->trapsDB->db_connect_trap();
332
-            $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache_trap_object (trap_id,object_id) '.
333
-                'values (:trap_id, :object_id)';
334
-            $sqlQuery=$db_conn->prepare($sql);
335
-            $sqlParam=array(
336
-                ':trap_id' => $trapId,
337
-                ':object_id' => $this->dbOidIndex[$this->oidDesc['oid']]['id'],
338
-            );
321
+			if (isset($dbObjects[$this->dbOidIndex[$this->oidDesc['oid']]['id']]))
322
+			{   // if link exists, continue
323
+				$dbObjects[$this->dbOidIndex[$this->oidDesc['oid']]['id']]=2;
324
+				continue;
325
+			}
326
+			if ($check_existing === true)
327
+			{
328
+				// TODO : check link trap - objects exists, mark them.
329
+			}
330
+			// Associate in object table
331
+			$db_conn=$this->trapsDB->db_connect_trap();
332
+			$sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache_trap_object (trap_id,object_id) '.
333
+				'values (:trap_id, :object_id)';
334
+			$sqlQuery=$db_conn->prepare($sql);
335
+			$sqlParam=array(
336
+				':trap_id' => $trapId,
337
+				':object_id' => $this->dbOidIndex[$this->oidDesc['oid']]['id'],
338
+			);
339 339
             
340
-            if ($sqlQuery->execute($sqlParam) === false) {
341
-                $this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$this->oidDesc['oid']]['id'] ,1,'');
342
-            }
343
-        }
344
-        if ($check_existing === true)
345
-        {
346
-            // TODO : remove link trap - objects that wasn't marked.
347
-        }
340
+			if ($sqlQuery->execute($sqlParam) === false) {
341
+				$this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$this->oidDesc['oid']]['id'] ,1,'');
342
+			}
343
+		}
344
+		if ($check_existing === true)
345
+		{
346
+			// TODO : remove link trap - objects that wasn't marked.
347
+		}
348 348
         
349
-    }
349
+	}
350 350
 
351
-    private function reset_oidDesc()
352
-    {
353
-        $this->oidDesc['oid']=null;
354
-        $this->oidDesc['name']=null;
355
-        $this->oidDesc['type']=null;
356
-        $this->oidDesc['mib']=null;
357
-        $this->oidDesc['textconv']=null;
358
-        $this->oidDesc['dispHint'] =null;
359
-        $this->oidDesc['syntax']=null;
360
-        $this->oidDesc['type_enum']=null;
361
-        $this->oidDesc['description']=null;
362
-    }
351
+	private function reset_oidDesc()
352
+	{
353
+		$this->oidDesc['oid']=null;
354
+		$this->oidDesc['name']=null;
355
+		$this->oidDesc['type']=null;
356
+		$this->oidDesc['mib']=null;
357
+		$this->oidDesc['textconv']=null;
358
+		$this->oidDesc['dispHint'] =null;
359
+		$this->oidDesc['syntax']=null;
360
+		$this->oidDesc['type_enum']=null;
361
+		$this->oidDesc['description']=null;
362
+	}
363 363
     
364
-    /**
365
-     * Fills $this->objectsAll with all mibs from snmptranslate
366
-     * @return integer : number of elements 
367
-     */
368
-    private function load_mibs_snmptranslate()
369
-    {
370
-        $retVal=0;
371
-        // Get all mib objects from all mibs
372
-        $snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null';
373
-        $this->logging->log('Getting all traps : '.$snmpCommand,DEBUG );
374
-        unset($this->objectsAll);
375
-        exec($snmpCommand,$this->objectsAll,$retVal);
376
-        if ($retVal!=0)
377
-        {
378
-            $this->logging->log('error executing snmptranslate',ERROR,'');
379
-        }
380
-        // Count elements to show progress
381
-        $numElements=count($this->objectsAll);
382
-        $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO );
383
-        return $numElements;
384
-    }
364
+	/**
365
+	 * Fills $this->objectsAll with all mibs from snmptranslate
366
+	 * @return integer : number of elements 
367
+	 */
368
+	private function load_mibs_snmptranslate()
369
+	{
370
+		$retVal=0;
371
+		// Get all mib objects from all mibs
372
+		$snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null';
373
+		$this->logging->log('Getting all traps : '.$snmpCommand,DEBUG );
374
+		unset($this->objectsAll);
375
+		exec($snmpCommand,$this->objectsAll,$retVal);
376
+		if ($retVal!=0)
377
+		{
378
+			$this->logging->log('error executing snmptranslate',ERROR,'');
379
+		}
380
+		// Count elements to show progress
381
+		$numElements=count($this->objectsAll);
382
+		$this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO );
383
+		return $numElements;
384
+	}
385 385
 
386
-    /**
387
-     * load all mib objects db in dbOidAll (raw) and index in dbOidIndex
388
-     */
389
-    private function load_mibs_from_db()
390
-    {
391
-        // Get all mibs from databse to have a memory index
386
+	/**
387
+	 * load all mib objects db in dbOidAll (raw) and index in dbOidIndex
388
+	 */
389
+	private function load_mibs_from_db()
390
+	{
391
+		// Get all mibs from databse to have a memory index
392 392
         
393
-        $db_conn=$this->trapsDB->db_connect_trap();
393
+		$db_conn=$this->trapsDB->db_connect_trap();
394 394
         
395
-        $sql='SELECT * from '.$this->trapsDB->dbPrefix.'mib_cache;';
396
-        $this->logging->log('SQL query : '.$sql,DEBUG );
397
-        if (($ret_code=$db_conn->query($sql)) === false) {
398
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
399
-        }
400
-        $this->dbOidAll=$ret_code->fetchAll();
401
-        $this->dbOidIndex=array();
402
-        // Create the index for db;
403
-        foreach($this->dbOidAll as $key=>$val)
404
-        {
405
-            $this->dbOidIndex[$val['oid']]['key']=$key;
406
-            $this->dbOidIndex[$val['oid']]['id']=$val['id'];
407
-        }
408
-    }
395
+		$sql='SELECT * from '.$this->trapsDB->dbPrefix.'mib_cache;';
396
+		$this->logging->log('SQL query : '.$sql,DEBUG );
397
+		if (($ret_code=$db_conn->query($sql)) === false) {
398
+			$this->logging->log('No result in query : ' . $sql,ERROR,'');
399
+		}
400
+		$this->dbOidAll=$ret_code->fetchAll();
401
+		$this->dbOidIndex=array();
402
+		// Create the index for db;
403
+		foreach($this->dbOidAll as $key=>$val)
404
+		{
405
+			$this->dbOidIndex[$val['oid']]['key']=$key;
406
+			$this->dbOidIndex[$val['oid']]['id']=$val['id'];
407
+		}
408
+	}
409 409
 
410
-    /**
411
-     * Reset all update timers & count to zero
412
-     */
413
-    private function reset_update_timers()
414
-    {
415
-        $this->timing['base_parse_time']=0;
416
-        $this->timing['base_check_time']=0;
417
-        $this->timing['type0_check_time']=0;
418
-        $this->timing['nottrap_time']=0;
419
-        $this->timing['update_time']=0;
420
-        $this->timing['objects_time']=0;
421
-        $this->timing['base_parse_num']=0;
422
-        $this->timing['base_check_num']=0;
423
-        $this->timing['type0_check_num']=0;
424
-        $this->timing['nottrap_num']=0;
425
-        $this->timing['update_num']=0;
426
-        $this->timing['objects_num']=0;
427
-        $this->timing['num_traps']=0;
428
-    }
410
+	/**
411
+	 * Reset all update timers & count to zero
412
+	 */
413
+	private function reset_update_timers()
414
+	{
415
+		$this->timing['base_parse_time']=0;
416
+		$this->timing['base_check_time']=0;
417
+		$this->timing['type0_check_time']=0;
418
+		$this->timing['nottrap_time']=0;
419
+		$this->timing['update_time']=0;
420
+		$this->timing['objects_time']=0;
421
+		$this->timing['base_parse_num']=0;
422
+		$this->timing['base_check_num']=0;
423
+		$this->timing['type0_check_num']=0;
424
+		$this->timing['nottrap_num']=0;
425
+		$this->timing['update_num']=0;
426
+		$this->timing['objects_num']=0;
427
+		$this->timing['num_traps']=0;
428
+	}
429 429
 
430
-    /**
431
-     * Detect if $this->objectsAll[$curElement] is a trap 
432
-     * @param integer $curElement
433
-     * @param bool $onlyTraps : set to false to get all and not only traps.
434
-     * @return boolean : false if it's a trap , true if not
435
-     */
436
-    private function detect_trap($curElement,$onlyTraps)
437
-    {
438
-        // Get oid or pass if not found
439
-        if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
440
-        {
441
-            $this->timing['base_parse_time'] += microtime(true) - $this->timing['base_time'];
442
-            $this->timing['base_parse_num'] ++;
443
-            return true;
444
-        }
445
-        $this->oidDesc['oid']=$this->objectsAll[$curElement];
430
+	/**
431
+	 * Detect if $this->objectsAll[$curElement] is a trap 
432
+	 * @param integer $curElement
433
+	 * @param bool $onlyTraps : set to false to get all and not only traps.
434
+	 * @return boolean : false if it's a trap , true if not
435
+	 */
436
+	private function detect_trap($curElement,$onlyTraps)
437
+	{
438
+		// Get oid or pass if not found
439
+		if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
440
+		{
441
+			$this->timing['base_parse_time'] += microtime(true) - $this->timing['base_time'];
442
+			$this->timing['base_parse_num'] ++;
443
+			return true;
444
+		}
445
+		$this->oidDesc['oid']=$this->objectsAll[$curElement];
446 446
         
447
-        // get next line
448
-        $curElement++;
449
-        $match=$snmptrans=array();
450
-        if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
451
-            $this->objectsAll[$curElement],$match))
452
-        {
453
-            $this->timing['base_check_time'] += microtime(true) - $this->timing['base_time'];
454
-            $this->timing['base_check_num']++;
455
-            return true;
456
-        }
447
+		// get next line
448
+		$curElement++;
449
+		$match=$snmptrans=array();
450
+		if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
451
+			$this->objectsAll[$curElement],$match))
452
+		{
453
+			$this->timing['base_check_time'] += microtime(true) - $this->timing['base_time'];
454
+			$this->timing['base_check_num']++;
455
+			return true;
456
+		}
457 457
         
458
-        $this->oidDesc['name']=$match[1]; // Name
459
-        $this->oidDesc['type']=$match[2]; // type (21=trap, 0: may be trap, else : not trap
458
+		$this->oidDesc['name']=$match[1]; // Name
459
+		$this->oidDesc['type']=$match[2]; // type (21=trap, 0: may be trap, else : not trap
460 460
         
461
-        if ($this->oidDesc['type']==0) // object type=0 : check if v1 trap
462
-        {
463
-            // Check if next is suboid -> in that case is cannot be a trap
464
-            if (preg_match("/^".$this->oidDesc['oid']."/",$this->objectsAll[$curElement+1]))
465
-            {
466
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
467
-                $this->timing['type0_check_num']++;
468
-                return true;
469
-            }
470
-            unset($snmptrans);
471
-            $retVal=0;
472
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
473
-                ' -Td '.$this->oidDesc['oid'] . ' | grep OBJECTS ',$snmptrans,$retVal);
474
-            if ($retVal!=0)
475
-            {
476
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
477
-                $this->timing['type0_check_num']++;
478
-                return true;
479
-            }
480
-            //echo "\n v1 trap found : $this->oidDesc['oid'] \n";
481
-            // Force as trap.
482
-            $this->oidDesc['type']=21;
483
-        }
484
-        if ($onlyTraps===true && $this->oidDesc['type']!=21) // if only traps and not a trap, continue
485
-        {
486
-            $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time'];
487
-            $this->timing['nottrap_num']++;
488
-            return true;
489
-        }
490
-        return false;
491
-    }
461
+		if ($this->oidDesc['type']==0) // object type=0 : check if v1 trap
462
+		{
463
+			// Check if next is suboid -> in that case is cannot be a trap
464
+			if (preg_match("/^".$this->oidDesc['oid']."/",$this->objectsAll[$curElement+1]))
465
+			{
466
+				$this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
467
+				$this->timing['type0_check_num']++;
468
+				return true;
469
+			}
470
+			unset($snmptrans);
471
+			$retVal=0;
472
+			exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
473
+				' -Td '.$this->oidDesc['oid'] . ' | grep OBJECTS ',$snmptrans,$retVal);
474
+			if ($retVal!=0)
475
+			{
476
+				$this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
477
+				$this->timing['type0_check_num']++;
478
+				return true;
479
+			}
480
+			//echo "\n v1 trap found : $this->oidDesc['oid'] \n";
481
+			// Force as trap.
482
+			$this->oidDesc['type']=21;
483
+		}
484
+		if ($onlyTraps===true && $this->oidDesc['type']!=21) // if only traps and not a trap, continue
485
+		{
486
+			$this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time'];
487
+			$this->timing['nottrap_num']++;
488
+			return true;
489
+		}
490
+		return false;
491
+	}
492 492
    
493
-    /**
494
-     * get_trap_mib_description
495
-     * @return array|null : array of snmptranslate output or null on error
496
-    **/
497
-    private function get_trap_mib_description()
498
-    {
499
-        $retVal=0;
500
-        $match=$snmptrans=array();
501
-        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
502
-            ' -Td '.$this->oidDesc['oid'],$snmptrans,$retVal);
503
-        if ($retVal!=0)
504
-        {
505
-            $this->logging->log('error executing snmptranslate',ERROR);
506
-            return $snmptrans;
507
-        }
493
+	/**
494
+	 * get_trap_mib_description
495
+	 * @return array|null : array of snmptranslate output or null on error
496
+	 **/
497
+	private function get_trap_mib_description()
498
+	{
499
+		$retVal=0;
500
+		$match=$snmptrans=array();
501
+		exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
502
+			' -Td '.$this->oidDesc['oid'],$snmptrans,$retVal);
503
+		if ($retVal!=0)
504
+		{
505
+			$this->logging->log('error executing snmptranslate',ERROR);
506
+			return $snmptrans;
507
+		}
508 508
         
509
-        if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
510
-        {
511
-            $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : ' . $snmptrans[0],ERROR);
512
-            return $snmptrans;
513
-        }
514
-        $this->oidDesc['mib']=$match[1];
509
+		if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
510
+		{
511
+			$this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : ' . $snmptrans[0],ERROR);
512
+			return $snmptrans;
513
+		}
514
+		$this->oidDesc['mib']=$match[1];
515 515
         
516
-        $numLine=1;
517
-        while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
518
-        if (isset($snmptrans[$numLine]))
519
-        {
520
-            $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
516
+		$numLine=1;
517
+		while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
518
+		if (isset($snmptrans[$numLine]))
519
+		{
520
+			$snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
521 521
             
522
-            while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
523
-            {
524
-                $this->oidDesc['description'].=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
525
-                $numLine++;
526
-            }
527
-            if (isset($snmptrans[$numLine])) {
528
-                $this->oidDesc['description'].=preg_replace('/".*/','',$snmptrans[$numLine]);
529
-                $this->oidDesc['description']=preg_replace('/[\t ]+/',' ',$this->oidDesc['description']);
530
-            }
522
+			while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
523
+			{
524
+				$this->oidDesc['description'].=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
525
+				$numLine++;
526
+			}
527
+			if (isset($snmptrans[$numLine])) {
528
+				$this->oidDesc['description'].=preg_replace('/".*/','',$snmptrans[$numLine]);
529
+				$this->oidDesc['description']=preg_replace('/[\t ]+/',' ',$this->oidDesc['description']);
530
+			}
531 531
             
532
-        }
533
-        return $snmptrans;
534
-    }
532
+		}
533
+		return $snmptrans;
534
+	}
535 535
 
536
-    /**
537
-     * Get trap objects
538
-     * @param array $snmptrans : output of snmptranslate for TrapModuleConfig
539
-     * @return array|null : array of objects or null if not found
540
-    **/
541
-    private function get_trap_objects($snmptrans)
542
-    {
543
-        $objectName=null;
544
-        $match=array();
545
-        foreach ($snmptrans as $line)
546
-        {
547
-            if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
548
-            {
549
-                $objectName=$match[1];
550
-            }
551
-        }
552
-        if ($objectName == null)
553
-        {
554
-            $this->logging->log('No objects for ' . $this->oidDesc['oid'],DEBUG);
555
-            $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
556
-            return null;
557
-        }
536
+	/**
537
+	 * Get trap objects
538
+	 * @param array $snmptrans : output of snmptranslate for TrapModuleConfig
539
+	 * @return array|null : array of objects or null if not found
540
+	 **/
541
+	private function get_trap_objects($snmptrans)
542
+	{
543
+		$objectName=null;
544
+		$match=array();
545
+		foreach ($snmptrans as $line)
546
+		{
547
+			if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
548
+			{
549
+				$objectName=$match[1];
550
+			}
551
+		}
552
+		if ($objectName == null)
553
+		{
554
+			$this->logging->log('No objects for ' . $this->oidDesc['oid'],DEBUG);
555
+			$this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
556
+			return null;
557
+		}
558 558
         
559
-        $trapObjects=array();
560
-        while (preg_match('/ *([^ ,]+) *,* */',$objectName,$match))
561
-        {
562
-            array_push($trapObjects,$match[1]);
563
-            $objectName=preg_replace('/'.$match[0].'/','',$objectName);
564
-        }
565
-        return $trapObjects;
566
-    }
559
+		$trapObjects=array();
560
+		while (preg_match('/ *([^ ,]+) *,* */',$objectName,$match))
561
+		{
562
+			array_push($trapObjects,$match[1]);
563
+			$objectName=preg_replace('/'.$match[0].'/','',$objectName);
564
+		}
565
+		return $trapObjects;
566
+	}
567 567
     
568
-    /**
569
-     * Cache mib in database
570
-     * @param boolean $display_progress : Display progress on standard output
571
-     * @param boolean $check_change : Force check of trap params & objects
572
-     * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
573
-     * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
574
-     */
575
-    public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
576
-    {
577
-        // Global Timing
578
-        $timeTaken = microtime(true);
568
+	/**
569
+	 * Cache mib in database
570
+	 * @param boolean $display_progress : Display progress on standard output
571
+	 * @param boolean $check_change : Force check of trap params & objects
572
+	 * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
573
+	 * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
574
+	 */
575
+	public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
576
+	{
577
+		// Global Timing
578
+		$timeTaken = microtime(true);
579 579
         
580
-        $numElements=$this->load_mibs_snmptranslate(); // Load objectsAll
580
+		$numElements=$this->load_mibs_snmptranslate(); // Load objectsAll
581 581
         
582
-        $this->load_mibs_from_db(); // Load from db dbOidAll & dbOidIndex
582
+		$this->load_mibs_from_db(); // Load from db dbOidAll & dbOidIndex
583 583
         
584
-        $step=$basestep=$numElements/10; // output display of % done
585
-        $num_step=0;
586
-        $timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds
584
+		$step=$basestep=$numElements/10; // output display of % done
585
+		$num_step=0;
586
+		$timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds
587 587
         
588
-        // Create index for trap objects
589
-        $this->trapObjectsIndex=array();
588
+		// Create index for trap objects
589
+		$this->trapObjectsIndex=array();
590 590
         
591
-        // detailed timing (time_* vars)
592
-        $this->reset_update_timers();
591
+		// detailed timing (time_* vars)
592
+		$this->reset_update_timers();
593 593
         
594
-        for ($curElement=0;$curElement < $numElements;$curElement++)
595
-        {
596
-            $this->timing['base_time']= microtime(true);
597
-            if ($display_progress)
598
-            {
599
-                if ((microtime(true)-$timeFiveSec) > 2)
600
-                { // echo a . every 2 sec
601
-                    echo '.';
602
-                    $timeFiveSec = microtime(true);
603
-                }
604
-                if ($curElement>$step)
605
-                { // display progress
606
-                    $num_step++;
607
-                    $step+=$basestep;   
608
-                    echo "\n" . ($num_step*10). '% : ';
609
-                }
610
-            }
594
+		for ($curElement=0;$curElement < $numElements;$curElement++)
595
+		{
596
+			$this->timing['base_time']= microtime(true);
597
+			if ($display_progress)
598
+			{
599
+				if ((microtime(true)-$timeFiveSec) > 2)
600
+				{ // echo a . every 2 sec
601
+					echo '.';
602
+					$timeFiveSec = microtime(true);
603
+				}
604
+				if ($curElement>$step)
605
+				{ // display progress
606
+					$num_step++;
607
+					$step+=$basestep;   
608
+					echo "\n" . ($num_step*10). '% : ';
609
+				}
610
+			}
611 611
             
612
-            $this->reset_oidDesc();
613
-            if ($this->detect_trap($curElement,$onlyTraps)===true)
614
-            {
615
-                continue;
616
-            }
612
+			$this->reset_oidDesc();
613
+			if ($this->detect_trap($curElement,$onlyTraps)===true)
614
+			{
615
+				continue;
616
+			}
617 617
             
618
-            $this->timing['num_traps']++;
618
+			$this->timing['num_traps']++;
619 619
             
620
-            $this->logging->log('Found trap : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],INFO );
621
-            if ($display_progress) echo '#'; // echo a # when trap found
620
+			$this->logging->log('Found trap : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],INFO );
621
+			if ($display_progress) echo '#'; // echo a # when trap found
622 622
 
623
-            // get trap objects & source MIB
623
+			// get trap objects & source MIB
624 624
             
625
-            $snmptrans=$this->get_trap_mib_description(); // get MIB & description
625
+			$snmptrans=$this->get_trap_mib_description(); // get MIB & description
626 626
 
627 627
 
628
-            $update=$this->update_oid(); // Do update of trap.
628
+			$update=$this->update_oid(); // Do update of trap.
629 629
             
630
-            $this->timing['update_time'] += microtime(true) - $this->timing['base_time'];
631
-            $this->timing['update_num']++;
630
+			$this->timing['update_time'] += microtime(true) - $this->timing['base_time'];
631
+			$this->timing['update_num']++;
632 632
             
633
-            $this->timing['base_time']= microtime(true); // Reset to check object time
633
+			$this->timing['base_time']= microtime(true); // Reset to check object time
634 634
             
635
-            if (($update==0) && ($check_change===false))
636
-            { // Trapd didn't change & force check disabled
637
-                $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
638
-                if ($display_progress) echo "C";
639
-                continue;
640
-            }
635
+			if (($update==0) && ($check_change===false))
636
+			{ // Trapd didn't change & force check disabled
637
+				$this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
638
+				if ($display_progress) echo "C";
639
+				continue;
640
+			}
641 641
             
642
-            $trapObjects=$this->get_trap_objects($snmptrans); // Get trap objects from snmptranslate output            
643
-            if ($trapObjects == null)
644
-            {
645
-                continue;
646
-            }
642
+			$trapObjects=$this->get_trap_objects($snmptrans); // Get trap objects from snmptranslate output            
643
+			if ($trapObjects == null)
644
+			{
645
+				continue;
646
+			}
647 647
            
648
-            $this->trap_objects($this->oidDesc['oid'], $this->oidDesc['mib'], $trapObjects, false);
648
+			$this->trap_objects($this->oidDesc['oid'], $this->oidDesc['mib'], $trapObjects, false);
649 649
             
650
-            $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
651
-            $this->timing['objects_num']++;
652
-        }
650
+			$this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
651
+			$this->timing['objects_num']++;
652
+		}
653 653
         
654
-        if ($display_progress)
655
-        {
656
-            echo "\nNumber of processed traps :  ". $this->timing['num_traps'] ."\n";
657
-            echo "\nParsing : " . number_format($this->timing['base_parse_time']+$this->timing['base_check_time'],1) ." sec / " . ($this->timing['base_parse_num']+ $this->timing['base_check_num'])  . " occurences\n";
658
-            echo "Detecting traps : " . number_format($this->timing['type0_check_time']+$this->timing['nottrap_time'],1) . " sec / " . ($this->timing['type0_check_num']+$this->timing['nottrap_num']) ." occurences\n";
659
-            echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'],1)." sec , ";
660
-            echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'],1)." sec \n";
654
+		if ($display_progress)
655
+		{
656
+			echo "\nNumber of processed traps :  ". $this->timing['num_traps'] ."\n";
657
+			echo "\nParsing : " . number_format($this->timing['base_parse_time']+$this->timing['base_check_time'],1) ." sec / " . ($this->timing['base_parse_num']+ $this->timing['base_check_num'])  . " occurences\n";
658
+			echo "Detecting traps : " . number_format($this->timing['type0_check_time']+$this->timing['nottrap_time'],1) . " sec / " . ($this->timing['type0_check_num']+$this->timing['nottrap_num']) ." occurences\n";
659
+			echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'],1)." sec , ";
660
+			echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'],1)." sec \n";
661 661
             
662
-            $timeTaken=microtime(true) - $timeTaken;
663
-            echo "Global time : ".round($timeTaken)." seconds\n";
664
-        }
665
-    }
662
+			$timeTaken=microtime(true) - $timeTaken;
663
+			echo "Global time : ".round($timeTaken)." seconds\n";
664
+		}
665
+	}
666 666
     
667 667
     
668 668
 }
669 669
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      * @param Logging $logClass : where to log
45 45
      * @param Database $dbClass : Database
46 46
      */
47
-    function __construct($logClass,$dbClass,$snmptrans,$snmptransdir)
47
+    function __construct($logClass, $dbClass, $snmptrans, $snmptransdir)
48 48
     {
49 49
         $this->logging=$logClass;
50 50
         $this->trapsDB=$dbClass;
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
         $db_conn=$this->trapsDB->db_connect_trap();
83 83
         $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache '.
84 84
             '(oid, name, type , mib, textual_convention, display_hint '.
85
-            ', syntax, type_enum , description ) ' .
85
+            ', syntax, type_enum , description ) '.
86 86
             'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
87 87
             ', :syntax, :type_enum, :description )';
88 88
         
89
-        if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id';
89
+        if ($this->trapsDB->trapDBType == 'pgsql') $sql.='RETURNING id';
90 90
         
91 91
         $sqlQuery=$db_conn->prepare($sql);
92 92
         
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
         );
104 104
         
105 105
         if ($sqlQuery->execute($sqlParam) === false) {
106
-            $this->logging->log('Error in query : ' . $sql,1,'');
106
+            $this->logging->log('Error in query : '.$sql, 1, '');
107 107
         }
108 108
         
109 109
         switch ($this->trapsDB->trapDBType)
@@ -111,10 +111,10 @@  discard block
 block discarded – undo
111 111
             case 'pgsql':
112 112
                 // Get last id to insert oid/values in secondary table
113 113
                 if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {
114
-                    $this->logging->log('Error getting id - pgsql - ',1,'');
114
+                    $this->logging->log('Error getting id - pgsql - ', 1, '');
115 115
                 }
116
-                if (! isset($inserted_id_ret['id'])) {
117
-                    $this->logging->log('Error getting id - pgsql - empty.',ERROR);
116
+                if (!isset($inserted_id_ret['id'])) {
117
+                    $this->logging->log('Error getting id - pgsql - empty.', ERROR);
118 118
                     return 0;
119 119
                 }
120 120
                 $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id_ret['id'];
@@ -123,16 +123,16 @@  discard block
 block discarded – undo
123 123
                 // Get last id to insert oid/values in secondary table
124 124
                 $sql='SELECT LAST_INSERT_ID();';
125 125
                 if (($ret_code=$db_conn->query($sql)) === false) {
126
-                    $this->logging->log('Erreur getting id - mysql - ',ERROR);
126
+                    $this->logging->log('Erreur getting id - mysql - ', ERROR);
127 127
                     return 0;
128 128
                 }
129 129
                 
130 130
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
131
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
131
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
132 132
                 $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id;
133 133
                 break;
134 134
             default:
135
-                $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,ERROR);
135
+                $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType, ERROR);
136 136
                 return 0;
137 137
         }
138 138
         
@@ -172,9 +172,9 @@  discard block
 block discarded – undo
172 172
         $db_conn=$this->trapsDB->db_connect_trap();
173 173
         // Get all objects
174 174
         $sql='SELECT * FROM '.$this->trapsDB->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';';
175
-        $this->logging->log('SQL query get all traps: '.$sql,DEBUG );
175
+        $this->logging->log('SQL query get all traps: '.$sql, DEBUG);
176 176
         if (($ret_code=$db_conn->query($sql)) === false) {
177
-            $this->logging->log('No result in query : ' . $sql,1,'');
177
+            $this->logging->log('No result in query : '.$sql, 1, '');
178 178
         }
179 179
         $dbObjectsRaw=$ret_code->fetchAll();
180 180
         
@@ -191,30 +191,30 @@  discard block
 block discarded – undo
191 191
  * @param string $trapmib : mib of trap
192 192
  * @return NULL|array : null if not found, or output of snmptranslate
193 193
  */
194
-    private function get_object_details($object,$trapmib)
194
+    private function get_object_details($object, $trapmib)
195 195
     {
196 196
         $match=$snmptrans=array();
197 197
         $retVal=0;
198 198
         $this->oidDesc['mib']=$trapmib;
199
-        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
200
-            ' -On -Td '.$this->oidDesc['mib'].'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
201
-        if ($retVal!=0)
199
+        exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
200
+            ' -On -Td '.$this->oidDesc['mib'].'::'.$object.' 2>/dev/null', $snmptrans, $retVal);
201
+        if ($retVal != 0)
202 202
         {
203 203
             // Maybe not trap mib, search with IR
204
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
205
-                ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
206
-            if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
204
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
205
+                ' -IR '.$object.' 2>/dev/null', $snmptrans, $retVal);
206
+            if ($retVal != 0 || !preg_match('/(.*)::(.*)/', $snmptrans[0], $match))
207 207
             { // Not found -> continue with warning
208
-                $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
208
+                $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object, 2, '');
209 209
                 return null;
210 210
             }
211 211
             $this->oidDesc['mib']=$match[1];
212 212
             
213 213
             // Do the snmptranslate again.
214
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
215
-                ' -On -Td '.$this->oidDesc['mib'].'::'.$object,$snmptrans,$retVal);
216
-            if ($retVal!=0) {
217
-                $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object,2,'');
214
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
215
+                ' -On -Td '.$this->oidDesc['mib'].'::'.$object, $snmptrans, $retVal);
216
+            if ($retVal != 0) {
217
+                $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object, 2, '');
218 218
                 return null;
219 219
             }
220 220
             
@@ -234,12 +234,12 @@  discard block
 block discarded – undo
234 234
         
235 235
         foreach ($snmptrans as $line)
236 236
         {
237
-            if ($indesc===true)
237
+            if ($indesc === true)
238 238
             {
239
-                $line=preg_replace('/[\t ]+/',' ',$line);
240
-                if (preg_match('/(.*)"$/', $line,$match))
239
+                $line=preg_replace('/[\t ]+/', ' ', $line);
240
+                if (preg_match('/(.*)"$/', $line, $match))
241 241
                 {
242
-                    $this->oidDesc['description'] = $tmpdesc . $match[1];
242
+                    $this->oidDesc['description']=$tmpdesc.$match[1];
243 243
                     $indesc=false;
244 244
                 }
245 245
                 $tmpdesc.=$line;
@@ -250,34 +250,34 @@  discard block
 block discarded – undo
250 250
                 $this->oidDesc['oid']=$line;
251 251
                 continue;
252 252
             }
253
-            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
253
+            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/', $line, $match))
254 254
             {
255 255
                 $this->oidDesc['syntax']=$match[1];
256 256
                 $this->oidDesc['type_enum']=$match[2];
257 257
                 continue;
258 258
             }
259
-            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
259
+            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/', $line, $match))
260 260
             {
261 261
                 $this->oidDesc['syntax']=$match[1];
262 262
                 continue;
263 263
             }
264
-            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
264
+            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/', $line, $match))
265 265
             {
266 266
                 $this->oidDesc['dispHint']=$match[1];
267 267
                 continue;
268 268
             }
269
-            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
269
+            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/', $line, $match))
270 270
             {
271 271
                 $this->oidDesc['description']=$match[1];
272 272
                 continue;
273 273
             }
274
-            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
274
+            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $line, $match))
275 275
             {
276 276
                 $tmpdesc=$match[1];
277 277
                 $indesc=true;
278 278
                 continue;
279 279
             }
280
-            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
280
+            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/', $line, $match))
281 281
             {
282 282
                 $this->oidDesc['textconv']=$match[1];
283 283
                 continue;
@@ -292,9 +292,9 @@  discard block
 block discarded – undo
292 292
      * @param array $objects : array of objects name (without MIB)
293 293
      * @param bool $check_existing : check instead of create
294 294
      */
295
-    public function trap_objects($trapOID,$trapmib,$objects,$check_existing)
295
+    public function trap_objects($trapOID, $trapmib, $objects, $check_existing)
296 296
     {              
297
-        $trapId = $this->dbOidIndex[$trapOID]['id']; // Get id of trap
297
+        $trapId=$this->dbOidIndex[$trapOID]['id']; // Get id of trap
298 298
         
299 299
         if ($check_existing === true)
300 300
         {
@@ -311,9 +311,9 @@  discard block
 block discarded – undo
311 311
             
312 312
             $this->parse_object($snmptrans);
313 313
 
314
-            $this->oidDesc['name'] = $object;
314
+            $this->oidDesc['name']=$object;
315 315
             
316
-            $this->logging->log("Adding object ".$this->oidDesc['name']." : ".$this->oidDesc['oid']." / ".$this->oidDesc['syntax']." / ".$this->oidDesc['type_enum']." / ".$this->oidDesc['dispHint']." / ".$this->oidDesc['textconv'],DEBUG );
316
+            $this->logging->log("Adding object ".$this->oidDesc['name']." : ".$this->oidDesc['oid']." / ".$this->oidDesc['syntax']." / ".$this->oidDesc['type_enum']." / ".$this->oidDesc['dispHint']." / ".$this->oidDesc['textconv'], DEBUG);
317 317
 
318 318
             // Update
319 319
             $this->update_oid();
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
             );
339 339
             
340 340
             if ($sqlQuery->execute($sqlParam) === false) {
341
-                $this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$this->oidDesc['oid']]['id'] ,1,'');
341
+                $this->logging->log('Error adding trap object : '.$sql.' / '.$trapId.'/'.$this->dbOidIndex[$this->oidDesc['oid']]['id'], 1, '');
342 342
             }
343 343
         }
344 344
         if ($check_existing === true)
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
         $this->oidDesc['type']=null;
356 356
         $this->oidDesc['mib']=null;
357 357
         $this->oidDesc['textconv']=null;
358
-        $this->oidDesc['dispHint'] =null;
358
+        $this->oidDesc['dispHint']=null;
359 359
         $this->oidDesc['syntax']=null;
360 360
         $this->oidDesc['type_enum']=null;
361 361
         $this->oidDesc['description']=null;
@@ -369,17 +369,17 @@  discard block
 block discarded – undo
369 369
     {
370 370
         $retVal=0;
371 371
         // Get all mib objects from all mibs
372
-        $snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null';
373
-        $this->logging->log('Getting all traps : '.$snmpCommand,DEBUG );
372
+        $snmpCommand=$this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null';
373
+        $this->logging->log('Getting all traps : '.$snmpCommand, DEBUG);
374 374
         unset($this->objectsAll);
375
-        exec($snmpCommand,$this->objectsAll,$retVal);
376
-        if ($retVal!=0)
375
+        exec($snmpCommand, $this->objectsAll, $retVal);
376
+        if ($retVal != 0)
377 377
         {
378
-            $this->logging->log('error executing snmptranslate',ERROR,'');
378
+            $this->logging->log('error executing snmptranslate', ERROR, '');
379 379
         }
380 380
         // Count elements to show progress
381 381
         $numElements=count($this->objectsAll);
382
-        $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO );
382
+        $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements, INFO);
383 383
         return $numElements;
384 384
     }
385 385
 
@@ -393,14 +393,14 @@  discard block
 block discarded – undo
393 393
         $db_conn=$this->trapsDB->db_connect_trap();
394 394
         
395 395
         $sql='SELECT * from '.$this->trapsDB->dbPrefix.'mib_cache;';
396
-        $this->logging->log('SQL query : '.$sql,DEBUG );
396
+        $this->logging->log('SQL query : '.$sql, DEBUG);
397 397
         if (($ret_code=$db_conn->query($sql)) === false) {
398
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
398
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
399 399
         }
400 400
         $this->dbOidAll=$ret_code->fetchAll();
401 401
         $this->dbOidIndex=array();
402 402
         // Create the index for db;
403
-        foreach($this->dbOidAll as $key=>$val)
403
+        foreach ($this->dbOidAll as $key=>$val)
404 404
         {
405 405
             $this->dbOidIndex[$val['oid']]['key']=$key;
406 406
             $this->dbOidIndex[$val['oid']]['id']=$val['id'];
@@ -433,13 +433,13 @@  discard block
 block discarded – undo
433 433
      * @param bool $onlyTraps : set to false to get all and not only traps.
434 434
      * @return boolean : false if it's a trap , true if not
435 435
      */
436
-    private function detect_trap($curElement,$onlyTraps)
436
+    private function detect_trap($curElement, $onlyTraps)
437 437
     {
438 438
         // Get oid or pass if not found
439
-        if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
439
+        if (!preg_match('/^\.[0-9\.]+$/', $this->objectsAll[$curElement]))
440 440
         {
441
-            $this->timing['base_parse_time'] += microtime(true) - $this->timing['base_time'];
442
-            $this->timing['base_parse_num'] ++;
441
+            $this->timing['base_parse_time']+=microtime(true) - $this->timing['base_time'];
442
+            $this->timing['base_parse_num']++;
443 443
             return true;
444 444
         }
445 445
         $this->oidDesc['oid']=$this->objectsAll[$curElement];
@@ -448,9 +448,9 @@  discard block
 block discarded – undo
448 448
         $curElement++;
449 449
         $match=$snmptrans=array();
450 450
         if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
451
-            $this->objectsAll[$curElement],$match))
451
+            $this->objectsAll[$curElement], $match))
452 452
         {
453
-            $this->timing['base_check_time'] += microtime(true) - $this->timing['base_time'];
453
+            $this->timing['base_check_time']+=microtime(true) - $this->timing['base_time'];
454 454
             $this->timing['base_check_num']++;
455 455
             return true;
456 456
         }
@@ -458,22 +458,22 @@  discard block
 block discarded – undo
458 458
         $this->oidDesc['name']=$match[1]; // Name
459 459
         $this->oidDesc['type']=$match[2]; // type (21=trap, 0: may be trap, else : not trap
460 460
         
461
-        if ($this->oidDesc['type']==0) // object type=0 : check if v1 trap
461
+        if ($this->oidDesc['type'] == 0) // object type=0 : check if v1 trap
462 462
         {
463 463
             // Check if next is suboid -> in that case is cannot be a trap
464
-            if (preg_match("/^".$this->oidDesc['oid']."/",$this->objectsAll[$curElement+1]))
464
+            if (preg_match("/^".$this->oidDesc['oid']."/", $this->objectsAll[$curElement + 1]))
465 465
             {
466
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
466
+                $this->timing['type0_check_time']+=microtime(true) - $this->timing['base_time'];
467 467
                 $this->timing['type0_check_num']++;
468 468
                 return true;
469 469
             }
470 470
             unset($snmptrans);
471 471
             $retVal=0;
472
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
473
-                ' -Td '.$this->oidDesc['oid'] . ' | grep OBJECTS ',$snmptrans,$retVal);
474
-            if ($retVal!=0)
472
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
473
+                ' -Td '.$this->oidDesc['oid'].' | grep OBJECTS ', $snmptrans, $retVal);
474
+            if ($retVal != 0)
475 475
             {
476
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
476
+                $this->timing['type0_check_time']+=microtime(true) - $this->timing['base_time'];
477 477
                 $this->timing['type0_check_num']++;
478 478
                 return true;
479 479
             }
@@ -481,9 +481,9 @@  discard block
 block discarded – undo
481 481
             // Force as trap.
482 482
             $this->oidDesc['type']=21;
483 483
         }
484
-        if ($onlyTraps===true && $this->oidDesc['type']!=21) // if only traps and not a trap, continue
484
+        if ($onlyTraps === true && $this->oidDesc['type'] != 21) // if only traps and not a trap, continue
485 485
         {
486
-            $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time'];
486
+            $this->timing['nottrap_time']+=microtime(true) - $this->timing['base_time'];
487 487
             $this->timing['nottrap_num']++;
488 488
             return true;
489 489
         }
@@ -498,35 +498,35 @@  discard block
 block discarded – undo
498 498
     {
499 499
         $retVal=0;
500 500
         $match=$snmptrans=array();
501
-        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
502
-            ' -Td '.$this->oidDesc['oid'],$snmptrans,$retVal);
503
-        if ($retVal!=0)
501
+        exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
502
+            ' -Td '.$this->oidDesc['oid'], $snmptrans, $retVal);
503
+        if ($retVal != 0)
504 504
         {
505
-            $this->logging->log('error executing snmptranslate',ERROR);
505
+            $this->logging->log('error executing snmptranslate', ERROR);
506 506
             return $snmptrans;
507 507
         }
508 508
         
509
-        if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
509
+        if (!preg_match('/^(.*)::/', $snmptrans[0], $match))
510 510
         {
511
-            $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : ' . $snmptrans[0],ERROR);
511
+            $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : '.$snmptrans[0], ERROR);
512 512
             return $snmptrans;
513 513
         }
514 514
         $this->oidDesc['mib']=$match[1];
515 515
         
516 516
         $numLine=1;
517
-        while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
517
+        while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $snmptrans[$numLine], $match)) $numLine++;
518 518
         if (isset($snmptrans[$numLine]))
519 519
         {
520
-            $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
520
+            $snmptrans[$numLine]=preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/', '', $snmptrans[$numLine]);
521 521
             
522
-            while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
522
+            while (isset($snmptrans[$numLine]) && !preg_match('/"/', $snmptrans[$numLine]))
523 523
             {
524
-                $this->oidDesc['description'].=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
524
+                $this->oidDesc['description'].=preg_replace('/[\t ]+/', ' ', $snmptrans[$numLine]);
525 525
                 $numLine++;
526 526
             }
527 527
             if (isset($snmptrans[$numLine])) {
528
-                $this->oidDesc['description'].=preg_replace('/".*/','',$snmptrans[$numLine]);
529
-                $this->oidDesc['description']=preg_replace('/[\t ]+/',' ',$this->oidDesc['description']);
528
+                $this->oidDesc['description'].=preg_replace('/".*/', '', $snmptrans[$numLine]);
529
+                $this->oidDesc['description']=preg_replace('/[\t ]+/', ' ', $this->oidDesc['description']);
530 530
             }
531 531
             
532 532
         }
@@ -544,23 +544,23 @@  discard block
 block discarded – undo
544 544
         $match=array();
545 545
         foreach ($snmptrans as $line)
546 546
         {
547
-            if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
547
+            if (preg_match('/OBJECTS.*\{([^\}]+)\}/', $line, $match))
548 548
             {
549 549
                 $objectName=$match[1];
550 550
             }
551 551
         }
552 552
         if ($objectName == null)
553 553
         {
554
-            $this->logging->log('No objects for ' . $this->oidDesc['oid'],DEBUG);
555
-            $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
554
+            $this->logging->log('No objects for '.$this->oidDesc['oid'], DEBUG);
555
+            $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
556 556
             return null;
557 557
         }
558 558
         
559 559
         $trapObjects=array();
560
-        while (preg_match('/ *([^ ,]+) *,* */',$objectName,$match))
560
+        while (preg_match('/ *([^ ,]+) *,* */', $objectName, $match))
561 561
         {
562
-            array_push($trapObjects,$match[1]);
563
-            $objectName=preg_replace('/'.$match[0].'/','',$objectName);
562
+            array_push($trapObjects, $match[1]);
563
+            $objectName=preg_replace('/'.$match[0].'/', '', $objectName);
564 564
         }
565 565
         return $trapObjects;
566 566
     }
@@ -572,18 +572,18 @@  discard block
 block discarded – undo
572 572
      * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
573 573
      * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
574 574
      */
575
-    public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
575
+    public function update_mib_database($display_progress=false, $check_change=false, $onlyTraps=true, $startOID='.1')
576 576
     {
577 577
         // Global Timing
578
-        $timeTaken = microtime(true);
578
+        $timeTaken=microtime(true);
579 579
         
580 580
         $numElements=$this->load_mibs_snmptranslate(); // Load objectsAll
581 581
         
582 582
         $this->load_mibs_from_db(); // Load from db dbOidAll & dbOidIndex
583 583
         
584
-        $step=$basestep=$numElements/10; // output display of % done
584
+        $step=$basestep=$numElements / 10; // output display of % done
585 585
         $num_step=0;
586
-        $timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds
586
+        $timeFiveSec=microtime(true); // Used for display a '.' every <n> seconds
587 587
         
588 588
         // Create index for trap objects
589 589
         $this->trapObjectsIndex=array();
@@ -591,33 +591,33 @@  discard block
 block discarded – undo
591 591
         // detailed timing (time_* vars)
592 592
         $this->reset_update_timers();
593 593
         
594
-        for ($curElement=0;$curElement < $numElements;$curElement++)
594
+        for ($curElement=0; $curElement < $numElements; $curElement++)
595 595
         {
596
-            $this->timing['base_time']= microtime(true);
596
+            $this->timing['base_time']=microtime(true);
597 597
             if ($display_progress)
598 598
             {
599
-                if ((microtime(true)-$timeFiveSec) > 2)
599
+                if ((microtime(true) - $timeFiveSec) > 2)
600 600
                 { // echo a . every 2 sec
601 601
                     echo '.';
602
-                    $timeFiveSec = microtime(true);
602
+                    $timeFiveSec=microtime(true);
603 603
                 }
604
-                if ($curElement>$step)
604
+                if ($curElement > $step)
605 605
                 { // display progress
606 606
                     $num_step++;
607 607
                     $step+=$basestep;   
608
-                    echo "\n" . ($num_step*10). '% : ';
608
+                    echo "\n".($num_step * 10).'% : ';
609 609
                 }
610 610
             }
611 611
             
612 612
             $this->reset_oidDesc();
613
-            if ($this->detect_trap($curElement,$onlyTraps)===true)
613
+            if ($this->detect_trap($curElement, $onlyTraps) === true)
614 614
             {
615 615
                 continue;
616 616
             }
617 617
             
618 618
             $this->timing['num_traps']++;
619 619
             
620
-            $this->logging->log('Found trap : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],INFO );
620
+            $this->logging->log('Found trap : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], INFO);
621 621
             if ($display_progress) echo '#'; // echo a # when trap found
622 622
 
623 623
             // get trap objects & source MIB
@@ -627,14 +627,14 @@  discard block
 block discarded – undo
627 627
 
628 628
             $update=$this->update_oid(); // Do update of trap.
629 629
             
630
-            $this->timing['update_time'] += microtime(true) - $this->timing['base_time'];
630
+            $this->timing['update_time']+=microtime(true) - $this->timing['base_time'];
631 631
             $this->timing['update_num']++;
632 632
             
633
-            $this->timing['base_time']= microtime(true); // Reset to check object time
633
+            $this->timing['base_time']=microtime(true); // Reset to check object time
634 634
             
635
-            if (($update==0) && ($check_change===false))
635
+            if (($update == 0) && ($check_change === false))
636 636
             { // Trapd didn't change & force check disabled
637
-                $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
637
+                $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
638 638
                 if ($display_progress) echo "C";
639 639
                 continue;
640 640
             }
@@ -647,17 +647,17 @@  discard block
 block discarded – undo
647 647
            
648 648
             $this->trap_objects($this->oidDesc['oid'], $this->oidDesc['mib'], $trapObjects, false);
649 649
             
650
-            $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
650
+            $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
651 651
             $this->timing['objects_num']++;
652 652
         }
653 653
         
654 654
         if ($display_progress)
655 655
         {
656
-            echo "\nNumber of processed traps :  ". $this->timing['num_traps'] ."\n";
657
-            echo "\nParsing : " . number_format($this->timing['base_parse_time']+$this->timing['base_check_time'],1) ." sec / " . ($this->timing['base_parse_num']+ $this->timing['base_check_num'])  . " occurences\n";
658
-            echo "Detecting traps : " . number_format($this->timing['type0_check_time']+$this->timing['nottrap_time'],1) . " sec / " . ($this->timing['type0_check_num']+$this->timing['nottrap_num']) ." occurences\n";
659
-            echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'],1)." sec , ";
660
-            echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'],1)." sec \n";
656
+            echo "\nNumber of processed traps :  ".$this->timing['num_traps']."\n";
657
+            echo "\nParsing : ".number_format($this->timing['base_parse_time'] + $this->timing['base_check_time'], 1)." sec / ".($this->timing['base_parse_num'] + $this->timing['base_check_num'])." occurences\n";
658
+            echo "Detecting traps : ".number_format($this->timing['type0_check_time'] + $this->timing['nottrap_time'], 1)." sec / ".($this->timing['type0_check_num'] + $this->timing['nottrap_num'])." occurences\n";
659
+            echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'], 1)." sec , ";
660
+            echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'], 1)." sec \n";
661 661
             
662 662
             $timeTaken=microtime(true) - $timeTaken;
663 663
             echo "Global time : ".round($timeTaken)." seconds\n";
Please login to merge, or discard this patch.
Braces   +26 added lines, -8 removed lines patch added patch discarded remove patch
@@ -86,7 +86,9 @@  discard block
 block discarded – undo
86 86
             'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
87 87
             ', :syntax, :type_enum, :description )';
88 88
         
89
-        if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id';
89
+        if ($this->trapsDB->trapDBType == 'pgsql') {
90
+        	$sql .= 'RETURNING id';
91
+        }
90 92
         
91 93
         $sqlQuery=$db_conn->prepare($sql);
92 94
         
@@ -128,7 +130,9 @@  discard block
 block discarded – undo
128 130
                 }
129 131
                 
130 132
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
131
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
133
+                if ($inserted_id==false) {
134
+                	throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
135
+                }
132 136
                 $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id;
133 137
                 break;
134 138
             default:
@@ -307,7 +311,10 @@  discard block
 block discarded – undo
307 311
             $this->reset_oidDesc();
308 312
             
309 313
             $snmptrans=$this->get_object_details($object, $trapmib); // Get object mib & details
310
-            if ($snmptrans === null) continue; // object not found
314
+            if ($snmptrans === null) {
315
+            	continue;
316
+            }
317
+            // object not found
311 318
             
312 319
             $this->parse_object($snmptrans);
313 320
 
@@ -458,12 +465,14 @@  discard block
 block discarded – undo
458 465
         $this->oidDesc['name']=$match[1]; // Name
459 466
         $this->oidDesc['type']=$match[2]; // type (21=trap, 0: may be trap, else : not trap
460 467
         
461
-        if ($this->oidDesc['type']==0) // object type=0 : check if v1 trap
468
+        if ($this->oidDesc['type']==0) {
469
+        	// object type=0 : check if v1 trap
462 470
         {
463 471
             // Check if next is suboid -> in that case is cannot be a trap
464 472
             if (preg_match("/^".$this->oidDesc['oid']."/",$this->objectsAll[$curElement+1]))
465 473
             {
466 474
                 $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
475
+        }
467 476
                 $this->timing['type0_check_num']++;
468 477
                 return true;
469 478
             }
@@ -481,9 +490,11 @@  discard block
 block discarded – undo
481 490
             // Force as trap.
482 491
             $this->oidDesc['type']=21;
483 492
         }
484
-        if ($onlyTraps===true && $this->oidDesc['type']!=21) // if only traps and not a trap, continue
493
+        if ($onlyTraps===true && $this->oidDesc['type']!=21) {
494
+        	// if only traps and not a trap, continue
485 495
         {
486 496
             $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time'];
497
+        }
487 498
             $this->timing['nottrap_num']++;
488 499
             return true;
489 500
         }
@@ -514,7 +525,9 @@  discard block
 block discarded – undo
514 525
         $this->oidDesc['mib']=$match[1];
515 526
         
516 527
         $numLine=1;
517
-        while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
528
+        while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) {
529
+        	$numLine++;
530
+        }
518 531
         if (isset($snmptrans[$numLine]))
519 532
         {
520 533
             $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
@@ -618,7 +631,10 @@  discard block
 block discarded – undo
618 631
             $this->timing['num_traps']++;
619 632
             
620 633
             $this->logging->log('Found trap : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],INFO );
621
-            if ($display_progress) echo '#'; // echo a # when trap found
634
+            if ($display_progress) {
635
+            	echo '#';
636
+            }
637
+            // echo a # when trap found
622 638
 
623 639
             // get trap objects & source MIB
624 640
             
@@ -635,7 +651,9 @@  discard block
 block discarded – undo
635 651
             if (($update==0) && ($check_change===false))
636 652
             { // Trapd didn't change & force check disabled
637 653
                 $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
638
-                if ($display_progress) echo "C";
654
+                if ($display_progress) {
655
+                	echo "C";
656
+                }
639 657
                 continue;
640 658
             }
641 659
             
Please login to merge, or discard this patch.