Passed
Branch master (9f9a4d)
by Patrick
02:33
created
bin/trap_class.php 3 patches
Indentation   +576 added lines, -576 removed lines patch added patch discarded remove patch
@@ -88,24 +88,24 @@  discard block
 block discarded – undo
88 88
 	 */
89 89
 	protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = 2, $message = null)
90 90
 	{
91
-	    if (!isset($option_array[$option_category][$option_name]))
92
-	    {
93
-	        if ($message == null)
94
-	        {
95
-	            $message='No ' . $option_name . ' in config file: '. $this->trap_module_config;
96
-	        }
97
-	        $this->trapLog($message,$log_level,'syslog');
98
-	        return false;
99
-	    }
100
-	    else
101
-	    {
102
-	        $option_var=$option_array[$option_category][$option_name];
103
-	        return true;
104
-	    }
91
+		if (!isset($option_array[$option_category][$option_name]))
92
+		{
93
+			if ($message == null)
94
+			{
95
+				$message='No ' . $option_name . ' in config file: '. $this->trap_module_config;
96
+			}
97
+			$this->trapLog($message,$log_level,'syslog');
98
+			return false;
99
+		}
100
+		else
101
+		{
102
+			$option_var=$option_array[$option_category][$option_name];
103
+			return true;
104
+		}
105 105
 	}
106 106
 	
107 107
 	/** Get options from ini file and database
108
-	*/
108
+	 */
109 109
 	protected function getOptions()
110 110
 	{
111 111
 		$trap_config=parse_ini_file($this->trap_module_config,true);
@@ -128,10 +128,10 @@  discard block
 block discarded – undo
128 128
 		// API options
129 129
 		if ($this->getOptionIfSet($trap_config,'config','icingaAPI_host', $this->api_hostname))
130 130
 		{
131
-		    $this->api_use=true;
132
-		    $this->getOptionIfSet($trap_config,'config','icingaAPI_port', $this->api_port);
133
-		    $this->getOptionIfSet($trap_config,'config','icingaAPI_user', $this->api_username);
134
-		    $this->getOptionIfSet($trap_config,'config','icingaAPI_password', $this->api_password);
131
+			$this->api_use=true;
132
+			$this->getOptionIfSet($trap_config,'config','icingaAPI_port', $this->api_port);
133
+			$this->getOptionIfSet($trap_config,'config','icingaAPI_user', $this->api_username);
134
+			$this->getOptionIfSet($trap_config,'config','icingaAPI_password', $this->api_password);
135 135
 		}
136 136
 				
137 137
 		/***** Database options :  ***/
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
 	}
149 149
 	
150 150
 	/** Get data from db_config
151
-	*	@param $element string name of param
152
-	*	@return $value (or null)
153
-	*/	
151
+	 *	@param $element string name of param
152
+	 *	@return $value (or null)
153
+	 */	
154 154
 	protected function getDBConfig($element)
155 155
 	{
156 156
 		$db_conn=$this->db_connect_trap();
@@ -168,11 +168,11 @@  discard block
 block discarded – undo
168 168
 	}
169 169
 	
170 170
 	/** Send log. Throws exception on critical error
171
-	*	@param	string $message Message to log
172
-	*	@param	int $level 1=critical 2=warning 3=trace 4=debug
173
-	*	@param  int $destination file/syslog/display
174
-	*	@return void
175
-	**/	
171
+	 *	@param	string $message Message to log
172
+	 *	@param	int $level 1=critical 2=warning 3=trace 4=debug
173
+	 *	@param  int $destination file/syslog/display
174
+	 *	@return void
175
+	 **/	
176 176
 	public function trapLog( $message, $level, $destination ='')
177 177
 	{	
178 178
 		if ($this->debug_level >= $level) 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 		switch ($output_type)
217 217
 		{
218 218
 			case 'file':
219
-			    if ($output_option == null) throw new Exception("File logging without file !");
219
+				if ($output_option == null) throw new Exception("File logging without file !");
220 220
 				$this->debug_file=$output_option;
221 221
 				$this->alert_output='file';
222 222
 				break;
@@ -233,28 +233,28 @@  discard block
 block discarded – undo
233 233
 	
234 234
 	protected function getAPI()
235 235
 	{
236
-	    if ($this->icinga2api == null)
237
-	    {
238
-	        $this->icinga2api = new Icinga2API($this->api_hostname,$this->api_port);
239
-	    }
240
-	    return $this->icinga2api;
236
+		if ($this->icinga2api == null)
237
+		{
238
+			$this->icinga2api = new Icinga2API($this->api_hostname,$this->api_port);
239
+		}
240
+		return $this->icinga2api;
241 241
 	}
242 242
 
243 243
 	/** Connects to trapdb 
244
-	*	@return PDO connection
245
-	*/
244
+	 *	@return PDO connection
245
+	 */
246 246
 	public function db_connect_trap() 
247 247
 	{
248 248
 		if ($this->trapDB != null) {
249
-		    // Check if connection is still alive
250
-		    try {
251
-		        $this->trapDB->query('select 1')->fetchColumn();
252
-		        return $this->trapDB;
253
-		    } catch (Exception $e) {
254
-		        // select 1 failed, try to reconnect.
255
-		        $this->trapDB=null;
256
-		        $this->trapLog('Databse connection lost, reconnecting',WARN,'');
257
-		    }
249
+			// Check if connection is still alive
250
+			try {
251
+				$this->trapDB->query('select 1')->fetchColumn();
252
+				return $this->trapDB;
253
+			} catch (Exception $e) {
254
+				// select 1 failed, try to reconnect.
255
+				$this->trapDB=null;
256
+				$this->trapLog('Databse connection lost, reconnecting',WARN,'');
257
+			}
258 258
 		     
259 259
 		}
260 260
 		$this->trapDB=$this->db_connect('traps');
@@ -263,8 +263,8 @@  discard block
 block discarded – undo
263 263
 	
264 264
 
265 265
 	/** Connects to idodb 
266
-	*	@return PDO connection
267
-	*/
266
+	 *	@return PDO connection
267
+	 */
268 268
 	public function db_connect_ido() 
269 269
 	{
270 270
 		if ($this->idoDB != null) { return $this->idoDB; }
@@ -273,9 +273,9 @@  discard block
 block discarded – undo
273 273
 	}	
274 274
 	
275 275
 	/** connects to database named by parameter
276
-	*	@param string database : 'traps' for traps database, 'ido' for ido database
277
-	*	@return PDO connection
278
-	**/
276
+	 *	@param string database : 'traps' for traps database, 'ido' for ido database
277
+	 *	@return PDO connection
278
+	 **/
279 279
 	protected function db_connect($database) {
280 280
 		$confarray=$this->get_database($database);
281 281
 		//	$dsn = 'mysql:dbname=traps;host=127.0.0.1';
@@ -292,9 +292,9 @@  discard block
 block discarded – undo
292 292
 	}
293 293
 
294 294
 	/** Get database connexion options
295
-	*	@param string database : 'traps' for traps database, 'ido' for ido database
296
-	*	@return array( DB type (mysql, pgsql.) , db_host, database name , db_user, db_pass)
297
-	**/
295
+	 *	@param string database : 'traps' for traps database, 'ido' for ido database
296
+	 *	@return array( DB type (mysql, pgsql.) , db_host, database name , db_user, db_pass)
297
+	 **/
298 298
 	protected function get_database($database) {
299 299
 
300 300
 		$trap_config=parse_ini_file($this->trap_module_config,true);
@@ -345,9 +345,9 @@  discard block
 block discarded – undo
345 345
 	}	
346 346
 	
347 347
 	/** read data from stream
348
-	*	@param $stream string input stream, defaults to "php://stdin"
349
-	*	@return array trap data
350
-	*/
348
+	 *	@param $stream string input stream, defaults to "php://stdin"
349
+	 *	@return array trap data
350
+	 */
351 351
 	public function read_trap($stream='php://stdin')
352 352
 	{
353 353
 		//Read data from snmptrapd from stdin
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 
356 356
 		if ($input_stream==FALSE)
357 357
 		{
358
-		    $this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)");
358
+			$this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)");
359 359
 			$this->trapLog("Error reading stdin !",ERROR,''); 
360 360
 		}
361 361
 
@@ -363,21 +363,21 @@  discard block
 block discarded – undo
363 363
 		$this->receivingHost=chop(fgets($input_stream));
364 364
 		if ($this->receivingHost == FALSE)
365 365
 		{
366
-		    $this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)");
366
+			$this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)");
367 367
 			$this->trapLog("Error reading Host !",ERROR,''); 
368 368
 		}
369 369
 		// line 2 IP:port=>IP:port
370 370
 		$IP=chop(fgets($input_stream));
371 371
 		if ($IP == FALSE)
372 372
 		{
373
-		    $this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)");
373
+			$this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)");
374 374
 			$this->trapLog("Error reading IP !",ERROR,''); 
375 375
 		}
376 376
 		$matches=array();
377 377
 		$ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/',$IP,$matches);
378 378
 		if ($ret_code==0 || $ret_code==FALSE) 
379 379
 		{
380
-		    $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
380
+			$this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
381 381
 			$this->trapLog('Error parsing IP : '.$IP,ERROR,'');
382 382
 		} 
383 383
 		else 
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
 			}
398 398
 			else 
399 399
 			{
400
-			    if (($matches[1]=='.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1]=='.1.3.6.1.6.3.1.1.4.1'))
400
+				if (($matches[1]=='.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1]=='.1.3.6.1.6.3.1.1.4.1'))
401 401
 				{
402 402
 					$this->trap_data['trap_oid']=$matches[2];				
403 403
 				}
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
 
414 414
 		if ($this->trap_data['trap_oid']=='unknown') 
415 415
 		{
416
-		    $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trap_data['source_ip']);
416
+			$this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trap_data['source_ip']);
417 417
 			$this->trapLog('no trap oid found',ERROR,'');
418 418
 		} 
419 419
 
@@ -442,9 +442,9 @@  discard block
 block discarded – undo
442 442
 	}
443 443
 
444 444
 	/** Translate oid into array(MIB,Name)
445
-	* @param $oid string oid to translate
446
-	* @return null if not found or array(MIB,Name)
447
-	*/
445
+	 * @param $oid string oid to translate
446
+	 * @return null if not found or array(MIB,Name)
447
+	 */
448 448
 	public function translateOID($oid)
449 449
 	{
450 450
 		// try from database
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 		
478 478
 		// Try to get oid name from snmptranslate
479 479
 		$translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
480
-		    ' '.$oid);
480
+			' '.$oid);
481 481
 		$matches=array();
482 482
 		$ret_code=preg_match('/(.*)::(.*)/',$translate,$matches);
483 483
 		if ($ret_code==0 || $ret_code==FALSE) {
@@ -489,9 +489,9 @@  discard block
 block discarded – undo
489 489
 	}
490 490
 	
491 491
 	/** Erase old trap records 
492
-	*	@param $days : erase traps when more than $days old
493
-	*	@return : number of lines deleted
494
-	**/
492
+	 *	@param $days : erase traps when more than $days old
493
+	 *	@return : number of lines deleted
494
+	 **/
495 495
 	public function eraseOldTraps($days=0)
496 496
 	{
497 497
 		if ($days==0)
@@ -516,74 +516,74 @@  discard block
 block discarded – undo
516 516
 	public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null)
517 517
 	{
518 518
 	    
519
-	    $db_conn=$this->db_connect_trap();
519
+		$db_conn=$this->db_connect_trap();
520 520
 	    
521
-	    $insert_col='';
522
-	    $insert_val='';
523
-	    // add date time
524
-	    $insert_col ='date_received,status';
525
-	    $insert_val = "'" . date("Y-m-d H:i:s")."','error'";
521
+		$insert_col='';
522
+		$insert_val='';
523
+		// add date time
524
+		$insert_col ='date_received,status';
525
+		$insert_val = "'" . date("Y-m-d H:i:s")."','error'";
526 526
         
527
-	    if ($sourceIP !=null)
528
-	    {
529
-	        $insert_col .=',source_ip';
530
-	        $insert_val .=",'". $sourceIP ."'";
531
-	    }
532
-	    if ($trapoid !=null)
533
-	    {
534
-	        $insert_col .=',trap_oid';
535
-	        $insert_val .=",'". $trapoid ."'";
536
-	    }
537
-	    $insert_col .=',status_detail';
538
-	    $insert_val .=",'". $message ."'";
527
+		if ($sourceIP !=null)
528
+		{
529
+			$insert_col .=',source_ip';
530
+			$insert_val .=",'". $sourceIP ."'";
531
+		}
532
+		if ($trapoid !=null)
533
+		{
534
+			$insert_col .=',trap_oid';
535
+			$insert_val .=",'". $trapoid ."'";
536
+		}
537
+		$insert_col .=',status_detail';
538
+		$insert_val .=",'". $message ."'";
539 539
 	    
540
-	    $sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
540
+		$sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
541 541
 	    
542
-	    switch ($this->trapDBType)
543
-	    {
544
-	        case 'pgsql':
545
-	            $sql .= ' RETURNING id;';
546
-	            $this->trapLog('sql : '.$sql,3,'');
547
-	            if (($ret_code=$db_conn->query($sql)) == FALSE) {
548
-	                $this->trapLog('Error SQL insert : '.$sql,1,'');
549
-	            }
550
-	            $this->trapLog('SQL insertion OK',3,'');
551
-	            // Get last id to insert oid/values in secondary table
552
-	            if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) == FALSE) {
542
+		switch ($this->trapDBType)
543
+		{
544
+			case 'pgsql':
545
+				$sql .= ' RETURNING id;';
546
+				$this->trapLog('sql : '.$sql,3,'');
547
+				if (($ret_code=$db_conn->query($sql)) == FALSE) {
548
+					$this->trapLog('Error SQL insert : '.$sql,1,'');
549
+				}
550
+				$this->trapLog('SQL insertion OK',3,'');
551
+				// Get last id to insert oid/values in secondary table
552
+				if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) == FALSE) {
553 553
 	                
554
-	                $this->trapLog('Erreur recuperation id',1,'');
555
-	            }
556
-	            if (! isset($inserted_id_ret['id'])) {
557
-	                $this->trapLog('Error getting id',1,'');
558
-	            }
559
-	            $this->trap_id=$inserted_id_ret['id'];
560
-	            break;
561
-	        case 'mysql':
562
-	            $sql .= ';';
563
-	            $this->trapLog('sql : '.$sql,3,'');
564
-	            if (($ret_code=$db_conn->query($sql)) == FALSE) {
565
-	                $this->trapLog('Error SQL insert : '.$sql,1,'');
566
-	            }
567
-	            $this->trapLog('SQL insertion OK',3,'');
568
-	            // Get last id to insert oid/values in secondary table
569
-	            $sql='SELECT LAST_INSERT_ID();';
570
-	            if (($ret_code=$db_conn->query($sql)) == FALSE) {
571
-	                $this->trapLog('Erreur recuperation id',1,'');
572
-	            }
554
+					$this->trapLog('Erreur recuperation id',1,'');
555
+				}
556
+				if (! isset($inserted_id_ret['id'])) {
557
+					$this->trapLog('Error getting id',1,'');
558
+				}
559
+				$this->trap_id=$inserted_id_ret['id'];
560
+				break;
561
+			case 'mysql':
562
+				$sql .= ';';
563
+				$this->trapLog('sql : '.$sql,3,'');
564
+				if (($ret_code=$db_conn->query($sql)) == FALSE) {
565
+					$this->trapLog('Error SQL insert : '.$sql,1,'');
566
+				}
567
+				$this->trapLog('SQL insertion OK',3,'');
568
+				// Get last id to insert oid/values in secondary table
569
+				$sql='SELECT LAST_INSERT_ID();';
570
+				if (($ret_code=$db_conn->query($sql)) == FALSE) {
571
+					$this->trapLog('Erreur recuperation id',1,'');
572
+				}
573 573
 	            
574
-	            $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
575
-	            if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
576
-	            $this->trap_id=$inserted_id;
577
-	            break;
578
-	        default:
579
-	            $this->trapLog('Error SQL type  : '.$this->trapDBType,1,'');
580
-	    }
574
+				$inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
575
+				if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
576
+				$this->trap_id=$inserted_id;
577
+				break;
578
+			default:
579
+				$this->trapLog('Error SQL type  : '.$this->trapDBType,1,'');
580
+		}
581 581
 	    
582
-	    $this->trapLog('id found: '. $this->trap_id,3,'');    
582
+		$this->trapLog('id found: '. $this->trap_id,3,'');    
583 583
 	}
584 584
 	
585 585
 	/** Write trap data to trap database
586
-	*/
586
+	 */
587 587
 	public function writeTrapToDB()
588 588
 	{
589 589
 		
@@ -681,10 +681,10 @@  discard block
 block discarded – undo
681 681
 	}
682 682
 
683 683
 	/** Get rules from rule database with ip and oid
684
-	*	@param $ip string ipv4 or ipv6
685
-	*	@param $oid string oid in numeric
686
-	*	@return PDO object or false
687
-	*/	
684
+	 *	@param $ip string ipv4 or ipv6
685
+	 *	@param $oid string oid in numeric
686
+	 *	@return PDO object or false
687
+	 */	
688 688
 	protected function getRules($ip,$oid)
689 689
 	{
690 690
 		$db_conn=$this->db_connect_trap();
@@ -743,8 +743,8 @@  discard block
 block discarded – undo
743 743
 	}
744 744
 
745 745
 	/** Add rule match to rule
746
-	*	@param rule id
747
-	*/
746
+	 *	@param rule id
747
+	 */
748 748
 	protected function add_rule_match($id, $set)
749 749
 	{
750 750
 		$db_conn=$this->db_connect_trap();
@@ -761,53 +761,53 @@  discard block
 block discarded – undo
761 761
 	 * @param number $state numerical staus 
762 762
 	 * @param string $display
763 763
 	 * @returnn bool true is service check was sent without error
764
-	*/
764
+	 */
765 765
 	public function serviceCheckResult($host,$service,$state,$display)
766 766
 	{
767
-	    if ($this->api_use == false)
768
-	    {
769
-    		$send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' .
770
-    			$host.';' .$service .';' . $state . ';'.$display;
771
-    		$this->trapLog( $send." : to : " .$this->icinga2cmd,3,'');
767
+		if ($this->api_use == false)
768
+		{
769
+			$send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' .
770
+				$host.';' .$service .';' . $state . ';'.$display;
771
+			$this->trapLog( $send." : to : " .$this->icinga2cmd,3,'');
772 772
     		
773
-    		// TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
774
-    		exec('echo "'.$send.'" > ' .$this->icinga2cmd);
775
-    		return true;
776
-	    }
777
-	    else
778
-	    {
779
-	        $api = $this->getAPI();
780
-	        $api->setCredentials($this->api_username, $this->api_password);
781
-	        list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display);
782
-	        if ($retcode == false)
783
-	        {
784
-	            $this->trapLog( "Error sending result : " .$retmessage,WARN,'');
785
-	            return false;
786
-	        }
787
-	        else 
788
-	        {
789
-	            $this->trapLog( "Sent result : " .$retmessage,3,'');
790
-	            return true;
791
-	        }
792
-	    }
773
+			// TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
774
+			exec('echo "'.$send.'" > ' .$this->icinga2cmd);
775
+			return true;
776
+		}
777
+		else
778
+		{
779
+			$api = $this->getAPI();
780
+			$api->setCredentials($this->api_username, $this->api_password);
781
+			list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display);
782
+			if ($retcode == false)
783
+			{
784
+				$this->trapLog( "Error sending result : " .$retmessage,WARN,'');
785
+				return false;
786
+			}
787
+			else 
788
+			{
789
+				$this->trapLog( "Sent result : " .$retmessage,3,'');
790
+				return true;
791
+			}
792
+		}
793 793
 	}
794 794
 	
795 795
 	public function getHostByIP($ip)
796 796
 	{
797
-	    $api = $this->getAPI();
798
-	    $api->setCredentials($this->api_username, $this->api_password);
799
-	    return $api->getHostByIP($ip);
797
+		$api = $this->getAPI();
798
+		$api->setCredentials($this->api_username, $this->api_password);
799
+		return $api->getHostByIP($ip);
800 800
 	}
801 801
 	
802 802
 	/** Resolve display. 
803
-	*	Changes OID(<oid>) to value if found or text "<not in trap>"
804
-	*	@param $display string
805
-	*	@return string display
806
-	*/
803
+	 *	Changes OID(<oid>) to value if found or text "<not in trap>"
804
+	 *	@param $display string
805
+	 *	@return string display
806
+	 */
807 807
 	protected function applyDisplay($display)
808 808
 	{
809
-	    $matches=array();
810
-	    while (preg_match('/_OID\(([0-9\.]+)\)/',$display,$matches) == 1)
809
+		$matches=array();
810
+		while (preg_match('/_OID\(([0-9\.]+)\)/',$display,$matches) == 1)
811 811
 		{
812 812
 			$oid=$matches[1];
813 813
 			$found=0;
@@ -867,11 +867,11 @@  discard block
 block discarded – undo
867 867
 		
868 868
 		if ($rule[$item] == '(')
869 869
 		{ // grouping
870
-		    $item++;
870
+			$item++;
871 871
 			$start=$item;
872 872
 			$parenthesis_count=0; 
873 873
 			while (($item < strlen($rule)) // Not end of string AND
874
-			      && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded ()
874
+				  && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded ()
875 875
 			{ 
876 876
 				if ($rule[$item] == '"' )
877 877
 				{ // pass through string
@@ -879,14 +879,14 @@  discard block
 block discarded – undo
879 879
 					$item=$this->eval_getNext($rule,$item,'"');
880 880
 				} 
881 881
 				else{
882
-				    if ($rule[$item] == '(')
883
-				    {
884
-				        $parenthesis_count++;
885
-				    }
886
-				    if ($rule[$item] == ')')
887
-				    {
888
-				        $parenthesis_count--;
889
-				    }
882
+					if ($rule[$item] == '(')
883
+					{
884
+						$parenthesis_count++;
885
+					}
886
+					if ($rule[$item] == ')')
887
+					{
888
+						$parenthesis_count--;
889
+					}
890 890
 					$item++;
891 891
 				}
892 892
 			}
@@ -938,24 +938,24 @@  discard block
 block discarded – undo
938 938
 	}
939 939
 	
940 940
 	/** Evaluation : makes token and evaluate. 
941
-	*	Public function for expressions testing
942
-	*	accepts : < > = <= >= !=  (typec = 0)
943
-	*	operators : & | (typec=1)
944
-	*	with : integers/float  (type 0) or strings "" (type 1) or results (type 2)
945
-	*   comparison int vs strings will return null (error)
946
-	*	return : bool or null on error
947
-	*/
941
+	 *	Public function for expressions testing
942
+	 *	accepts : < > = <= >= !=  (typec = 0)
943
+	 *	operators : & | (typec=1)
944
+	 *	with : integers/float  (type 0) or strings "" (type 1) or results (type 2)
945
+	 *   comparison int vs strings will return null (error)
946
+	 *	return : bool or null on error
947
+	 */
948 948
 	public function evaluation($rule,&$item)
949 949
 	{
950
-	    //echo "Evaluation of ".substr($rule,$item)."\n";
950
+		//echo "Evaluation of ".substr($rule,$item)."\n";
951 951
 		if ( $rule[$item] == '!') // If '!' found, negate next expression.
952 952
 		{
953
-		    $negate=true;
954
-		    $item++;
953
+			$negate=true;
954
+			$item++;
955 955
 		}
956 956
 		else
957 957
 		{
958
-		    $negate=false;
958
+			$negate=false;
959 959
 		}
960 960
 		// First element : number, string or ()
961 961
 		list($type1,$val1) = $this->eval_getElement($rule,$item);
@@ -975,24 +975,24 @@  discard block
 block discarded – undo
975 975
 		// Third element : number, string or ()
976 976
 		if ( $rule[$item] == '!') // starts with a ! so evaluate whats next
977 977
 		{
978
-		    $item++;
979
-		    if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule);
980
-		    $val2= ! $this->evaluation($rule,$item);
981
-		    $type2=2; // result is a boolean 
978
+			$item++;
979
+			if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule);
980
+			$val2= ! $this->evaluation($rule,$item);
981
+			$type2=2; // result is a boolean 
982 982
 		}
983 983
 		else 
984 984
 		{
985
-		    list($type2,$val2) = $this->eval_getElement($rule,$item);
985
+			list($type2,$val2) = $this->eval_getElement($rule,$item);
986 986
 		}
987 987
 		//echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n";
988 988
 		
989 989
 		if ($type1!=$type2)  // cannot compare different types
990 990
 		{ 
991
-		    throw new Exception("Cannot compare string & number : ".$rule);
991
+			throw new Exception("Cannot compare string & number : ".$rule);
992 992
 		}
993 993
 		if ($typec==1 && $type1 !=2) // cannot use & or | with string/number
994 994
 		{
995
-		    throw new Exception("Cannot use boolean operators with string & number : ".$rule);
995
+			throw new Exception("Cannot use boolean operators with string & number : ".$rule);
996 996
 		}
997 997
 		
998 998
 		switch ($comp){
@@ -1050,9 +1050,9 @@  discard block
 block discarded – undo
1050 1050
 	}		
1051 1051
 	
1052 1052
 	/** Evaluation rule (uses eval_* functions recursively)
1053
-	*	@param $rule string rule ( _OID(.1.3.6.1.4.1.8072.2.3.2.1)=_OID(.1.3.6.1.2.1.1.3.0) )
1054
-	*	@return : true : rule match, false : rule don't match , throw exception on error.
1055
-	*/
1053
+	 *	@param $rule string rule ( _OID(.1.3.6.1.4.1.8072.2.3.2.1)=_OID(.1.3.6.1.2.1.1.3.0) )
1054
+	 *	@return : true : rule match, false : rule don't match , throw exception on error.
1055
+	 */
1056 1056
 	
1057 1057
 	protected function eval_rule($rule)
1058 1058
 	{
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
 			}
1098 1098
 			if ($found==0)
1099 1099
 			{	// OID not found : throw error
1100
-			    throw new Exception('OID '.$oid.' not found in trap');
1100
+				throw new Exception('OID '.$oid.' not found in trap');
1101 1101
 			}
1102 1102
 		}
1103 1103
 		$item=0;
@@ -1108,7 +1108,7 @@  discard block
 block discarded – undo
1108 1108
 	}
1109 1109
 	
1110 1110
 	/** Match rules for current trap and do action
1111
-	*/
1111
+	 */
1112 1112
 	public function applyRules()
1113 1113
 	{
1114 1114
 		$rules = $this->getRules($this->trap_data['source_ip'],$this->trap_data['trap_oid']);
@@ -1145,12 +1145,12 @@  discard block
 block discarded – undo
1145 1145
 					{
1146 1146
 						if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
1147 1147
 						{
1148
-						    $this->trap_action.='Error sending status : check cmd/API';
1148
+							$this->trap_action.='Error sending status : check cmd/API';
1149 1149
 						}
1150 1150
 						else
1151 1151
 						{
1152
-						    $this->add_rule_match($rule['id'],$rule['num_match']+1);
1153
-						    $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1152
+							$this->add_rule_match($rule['id'],$rule['num_match']+1);
1153
+							$this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1154 1154
 						}
1155 1155
 					}
1156 1156
 					else
@@ -1167,15 +1167,15 @@  discard block
 block discarded – undo
1167 1167
 					$this->trapLog('action NOK : '.$action,3,'');
1168 1168
 					if ($action >= 0)
1169 1169
 					{
1170
-					    if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
1171
-					    {
1172
-					        $this->trap_action.='Error sending status : check cmd/API';
1173
-					    }
1174
-					    else
1175
-					    {
1176
-    						$this->add_rule_match($rule['id'],$rule['num_match']+1);
1177
-    						$this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1178
-					    }
1170
+						if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
1171
+						{
1172
+							$this->trap_action.='Error sending status : check cmd/API';
1173
+						}
1174
+						else
1175
+						{
1176
+							$this->add_rule_match($rule['id'],$rule['num_match']+1);
1177
+							$this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1178
+						}
1179 1179
 					}
1180 1180
 					else
1181 1181
 					{
@@ -1198,9 +1198,9 @@  discard block
 block discarded – undo
1198 1198
 			}
1199 1199
 			catch (Exception $e) 
1200 1200
 			{ 
1201
-			    $this->trapLog('Error in rule eval : '.$e->getMessage(),WARN,'');
1202
-			    $this->trap_action.=' ERR : '.$e->getMessage();
1203
-			    $this->trap_data['status']='error';
1201
+				$this->trapLog('Error in rule eval : '.$e->getMessage(),WARN,'');
1202
+				$this->trap_action.=' ERR : '.$e->getMessage();
1203
+				$this->trap_data['status']='error';
1204 1204
 			}
1205 1205
 			
1206 1206
 		}
@@ -1215,8 +1215,8 @@  discard block
 block discarded – undo
1215 1215
 	}
1216 1216
 
1217 1217
 	/** Add Time a action to rule
1218
-	*	@param rule id
1219
-	*/
1218
+	 *	@param rule id
1219
+	 */
1220 1220
 	public function add_rule_final($time)
1221 1221
 	{
1222 1222
 		$db_conn=$this->db_connect_trap();
@@ -1233,9 +1233,9 @@  discard block
 block discarded – undo
1233 1233
 	/*********** UTILITIES *********************/
1234 1234
 	
1235 1235
 	/** Create database schema 
1236
-	*	@param $schema_file	string File to read schema from
1237
-	*	@param $table_prefix string to replace #PREFIX# in schema file by this
1238
-	*/
1236
+	 *	@param $schema_file	string File to read schema from
1237
+	 *	@param $table_prefix string to replace #PREFIX# in schema file by this
1238
+	 */
1239 1239
 	public function create_schema($schema_file,$table_prefix)
1240 1240
 	{
1241 1241
 		//Read data from snmptrapd from stdin
@@ -1254,30 +1254,30 @@  discard block
 block discarded – undo
1254 1254
 		{
1255 1255
 			$newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line));
1256 1256
 			if (preg_match('/; *$/', $newline)) 
1257
-            {
1258
-                $sql= $newline;
1259
-                if ($db_conn->query($sql) == FALSE) {
1260
-                    $this->trapLog('Error create schema : '.$sql,ERROR,'');
1261
-                }
1262
-                if (preg_match('/^ *CREATE TABLE ([^ ]+)/',$newline,$cur_table_array))
1263
-                {
1264
-                    $cur_table='table '.$cur_table_array[1];
1265
-                }
1266
-                else
1267
-                {
1268
-                    $cur_table='secret SQL stuff :-)';
1269
-                }
1270
-                $this->trapLog('Creating : ' . $cur_table, 3,'');
1271
-                $newline='';
1272
-            }
1257
+			{
1258
+				$sql= $newline;
1259
+				if ($db_conn->query($sql) == FALSE) {
1260
+					$this->trapLog('Error create schema : '.$sql,ERROR,'');
1261
+				}
1262
+				if (preg_match('/^ *CREATE TABLE ([^ ]+)/',$newline,$cur_table_array))
1263
+				{
1264
+					$cur_table='table '.$cur_table_array[1];
1265
+				}
1266
+				else
1267
+				{
1268
+					$cur_table='secret SQL stuff :-)';
1269
+				}
1270
+				$this->trapLog('Creating : ' . $cur_table, 3,'');
1271
+				$newline='';
1272
+			}
1273 1273
 		}
1274 1274
 		
1275 1275
 		$sql= $newline;
1276 1276
 		if ($sql != '')
1277 1277
 		{
1278
-    		if ($db_conn->query($sql) == FALSE) {
1279
-    			$this->trapLog('Error create schema : '.$sql,ERROR,'');
1280
-    		}
1278
+			if ($db_conn->query($sql) == FALSE) {
1279
+				$this->trapLog('Error create schema : '.$sql,ERROR,'');
1280
+			}
1281 1281
 		}
1282 1282
 		$this->trapLog('Schema created',3);		
1283 1283
 	}
@@ -1292,113 +1292,113 @@  discard block
 block discarded – undo
1292 1292
 	 */
1293 1293
 	public function update_schema($prefix,$target_version,$table_prefix,$getmsg=false)
1294 1294
 	{
1295
-	    // Get current db number
1296
-	    $db_conn=$this->db_connect_trap();
1297
-	    $sql='SELECT id,value from '.$this->db_prefix.'db_config WHERE name=\'db_version\' ';
1298
-	    $this->trapLog('SQL query : '.$sql,4,'');
1299
-	    if (($ret_code=$db_conn->query($sql)) == FALSE) {
1300
-	        $this->trapLog('Cannot get db version. Query : ' . $sql,2,'');
1301
-	        return;
1302
-	    }
1303
-	    $version=$ret_code->fetchAll();
1304
-	    $cur_version=$version[0]['value'];
1305
-	    $db_version_id=$version[0]['id'];
1295
+		// Get current db number
1296
+		$db_conn=$this->db_connect_trap();
1297
+		$sql='SELECT id,value from '.$this->db_prefix.'db_config WHERE name=\'db_version\' ';
1298
+		$this->trapLog('SQL query : '.$sql,4,'');
1299
+		if (($ret_code=$db_conn->query($sql)) == FALSE) {
1300
+			$this->trapLog('Cannot get db version. Query : ' . $sql,2,'');
1301
+			return;
1302
+		}
1303
+		$version=$ret_code->fetchAll();
1304
+		$cur_version=$version[0]['value'];
1305
+		$db_version_id=$version[0]['id'];
1306 1306
 	    
1307
-	    if ($this->trapDBType == 'pgsql')
1308
-	    {
1309
-	        $prefix .= 'update_pgsql/schema_';
1310
-	    }
1311
-	    else
1312
-	    {
1313
-	        $prefix .= 'update_sql/schema_';
1314
-	    }
1315
-	    //echo "version all :\n";print_r($version);echo " \n $cur_ver \n";
1316
-	    if ($getmsg == true)
1317
-	    {
1318
-	        $message='';
1319
-	        $this->trapLog('getting message for upgrade',4,'');
1320
-	        while($cur_version<$target_version)
1321
-	        {
1322
-	            $cur_version++;
1323
-	            $updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql';
1324
-	            $input_stream=fopen($updateFile, 'r');
1325
-	            if ($input_stream==FALSE)
1326
-	            {
1327
-	                $this->trapLog("Error reading update file ". $updateFile,2,'');
1328
-	                return;
1329
-	            }
1330
-	            do { $line=fgets($input_stream); }
1331
-	            while ($line != false && !preg_match('/#MESSAGE/',$line));
1332
-	            if ($line ==false)
1333
-	            {
1334
-	                $this->trapLog("No message in file ". $updateFile,2,'');
1335
-	                return;
1336
-	            }
1337
-	            $message .= ($cur_version-1) . '->' . $cur_version. ' : ' . preg_replace('/#MESSAGE : /','',$line)."\n";
1338
-	        }
1339
-	        return $message;
1340
-	    }
1341
-	    while($cur_version<$target_version)
1342
-	    { // tODO : execute pre & post scripts
1343
-	       $cur_version++;
1344
-	       $this->trapLog('Updating to version : ' .$cur_version ,3,'');
1345
-	       $updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql';
1346
-	       $input_stream=fopen($updateFile, 'r');
1347
-	       if ($input_stream==FALSE)
1348
-	       {
1349
-	           $this->trapLog("Error reading update file ". $updateFile,2,'');
1350
-	           return;
1351
-	       }
1352
-	       $newline='';
1353
-	       $db_conn=$this->db_connect_trap();
1354
-	       $db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
1355
-	       while (($line=fgets($input_stream)) != FALSE)
1356
-	       {
1357
-	           if (preg_match('/^#/', $line)) continue; // ignore comment lines
1358
-	           $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line));
1359
-	           if (preg_match('/; *$/', $newline))
1360
-	           {
1361
-	               $sql_req=$db_conn->prepare($newline);
1362
-	               if ($sql_req->execute() == FALSE) {
1363
-	                   $this->trapLog('Error create schema : '.$newline,1,'');
1364
-	               }
1365
-	               $cur_table_array=array();
1366
-	               if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/',$newline,$cur_table_array))
1367
-	               {
1368
-	                   $cur_table=$cur_table_array[1] . ' SQL table '.$cur_table_array[2];
1369
-	               }
1370
-	               else
1371
-	               {
1372
-	                   $cur_table='secret SQL stuff :-)';
1373
-	                   $cur_table=$newline;
1374
-	               }
1375
-	               $this->trapLog('Doing : ' . $cur_table, 3,'');
1307
+		if ($this->trapDBType == 'pgsql')
1308
+		{
1309
+			$prefix .= 'update_pgsql/schema_';
1310
+		}
1311
+		else
1312
+		{
1313
+			$prefix .= 'update_sql/schema_';
1314
+		}
1315
+		//echo "version all :\n";print_r($version);echo " \n $cur_ver \n";
1316
+		if ($getmsg == true)
1317
+		{
1318
+			$message='';
1319
+			$this->trapLog('getting message for upgrade',4,'');
1320
+			while($cur_version<$target_version)
1321
+			{
1322
+				$cur_version++;
1323
+				$updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql';
1324
+				$input_stream=fopen($updateFile, 'r');
1325
+				if ($input_stream==FALSE)
1326
+				{
1327
+					$this->trapLog("Error reading update file ". $updateFile,2,'');
1328
+					return;
1329
+				}
1330
+				do { $line=fgets($input_stream); }
1331
+				while ($line != false && !preg_match('/#MESSAGE/',$line));
1332
+				if ($line ==false)
1333
+				{
1334
+					$this->trapLog("No message in file ". $updateFile,2,'');
1335
+					return;
1336
+				}
1337
+				$message .= ($cur_version-1) . '->' . $cur_version. ' : ' . preg_replace('/#MESSAGE : /','',$line)."\n";
1338
+			}
1339
+			return $message;
1340
+		}
1341
+		while($cur_version<$target_version)
1342
+		{ // tODO : execute pre & post scripts
1343
+		   $cur_version++;
1344
+		   $this->trapLog('Updating to version : ' .$cur_version ,3,'');
1345
+		   $updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql';
1346
+		   $input_stream=fopen($updateFile, 'r');
1347
+		   if ($input_stream==FALSE)
1348
+		   {
1349
+			   $this->trapLog("Error reading update file ". $updateFile,2,'');
1350
+			   return;
1351
+		   }
1352
+		   $newline='';
1353
+		   $db_conn=$this->db_connect_trap();
1354
+		   $db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
1355
+		   while (($line=fgets($input_stream)) != FALSE)
1356
+		   {
1357
+			   if (preg_match('/^#/', $line)) continue; // ignore comment lines
1358
+			   $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line));
1359
+			   if (preg_match('/; *$/', $newline))
1360
+			   {
1361
+				   $sql_req=$db_conn->prepare($newline);
1362
+				   if ($sql_req->execute() == FALSE) {
1363
+					   $this->trapLog('Error create schema : '.$newline,1,'');
1364
+				   }
1365
+				   $cur_table_array=array();
1366
+				   if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/',$newline,$cur_table_array))
1367
+				   {
1368
+					   $cur_table=$cur_table_array[1] . ' SQL table '.$cur_table_array[2];
1369
+				   }
1370
+				   else
1371
+				   {
1372
+					   $cur_table='secret SQL stuff :-)';
1373
+					   $cur_table=$newline;
1374
+				   }
1375
+				   $this->trapLog('Doing : ' . $cur_table, 3,'');
1376 1376
 	               
1377
-	               $newline='';
1378
-	           }
1379
-	       }
1380
-	       fclose($input_stream);
1377
+				   $newline='';
1378
+			   }
1379
+		   }
1380
+		   fclose($input_stream);
1381 1381
 	       
1382
-	       //$sql= $newline;
1383
-	       //if ($db_conn->query($sql) == FALSE) {
1384
-	       //    $this->trapLog('Error updating schema : '.$sql,1,'');
1385
-	       //}
1382
+		   //$sql= $newline;
1383
+		   //if ($db_conn->query($sql) == FALSE) {
1384
+		   //    $this->trapLog('Error updating schema : '.$sql,1,'');
1385
+		   //}
1386 1386
 	       
1387
-	       $sql='UPDATE '.$this->db_prefix.'db_config SET value='.$cur_version.' WHERE ( id = '.$db_version_id.' )';
1388
-	       $this->trapLog('SQL query : '.$sql,4,'');
1389
-	       if (($ret_code=$db_conn->query($sql)) == FALSE) {
1390
-	           $this->trapLog('Cannot update db version. Query : ' . $sql,2,'');
1391
-	           return;
1392
-	       }
1387
+		   $sql='UPDATE '.$this->db_prefix.'db_config SET value='.$cur_version.' WHERE ( id = '.$db_version_id.' )';
1388
+		   $this->trapLog('SQL query : '.$sql,4,'');
1389
+		   if (($ret_code=$db_conn->query($sql)) == FALSE) {
1390
+			   $this->trapLog('Cannot update db version. Query : ' . $sql,2,'');
1391
+			   return;
1392
+		   }
1393 1393
 	       
1394
-	       $this->trapLog('Schema updated to version : '.$cur_version ,3);
1395
-	    }
1394
+		   $this->trapLog('Schema updated to version : '.$cur_version ,3);
1395
+		}
1396 1396
 	}
1397 1397
 	
1398 1398
 	/** reset service to OK after time defined in rule
1399
-	*	TODO logic is : get all service in error + all rules, see if getting all rules then select services is better 
1400
-	*	@return : like a plugin : status code (0->3) <message> | <perfdata>
1401
-	**/
1399
+	 *	TODO logic is : get all service in error + all rules, see if getting all rules then select services is better 
1400
+	 *	@return : like a plugin : status code (0->3) <message> | <perfdata>
1401
+	 **/
1402 1402
 	public function reset_services()
1403 1403
 	{
1404 1404
 		// Get all services not in 'ok' state
@@ -1468,105 +1468,105 @@  discard block
 block discarded – undo
1468 1468
 		$description=$db_conn->quote($description);
1469 1469
 		if (isset($this->dbOidIndex[$oid]))
1470 1470
 		{
1471
-		    if ($this->dbOidIndex[$oid]['key'] == -1)
1472
-		    { // newly created.
1473
-		        return 0;
1474
-		    }
1471
+			if ($this->dbOidIndex[$oid]['key'] == -1)
1472
+			{ // newly created.
1473
+				return 0;
1474
+			}
1475 1475
 			if ( $name != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['name'] ||
1476
-			    $mib != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['mib'] ||
1477
-			    $type != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type'] //||
1478
-			    //$textConv != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['textual_convention'] //||
1479
-			    //$dispHint != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['display_hint'] ||
1480
-			    //$syntax != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['syntax'] ||
1481
-			    //$type_enum != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type_enum'] ||
1482
-			    //$description != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['description']
1483
-			    )
1476
+				$mib != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['mib'] ||
1477
+				$type != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type'] //||
1478
+				//$textConv != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['textual_convention'] //||
1479
+				//$dispHint != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['display_hint'] ||
1480
+				//$syntax != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['syntax'] ||
1481
+				//$type_enum != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type_enum'] ||
1482
+				//$description != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['description']
1483
+				)
1484 1484
 			{ // Do update
1485
-			    $sql='UPDATE '.$this->db_prefix.'mib_cache SET '.
1486
- 			    'name = :name , type = :type , mib = :mib , textual_convention = :tc , display_hint = :display_hint'. 
1487
- 			    ', syntax = :syntax, type_enum = :type_enum, description = :description '.
1488
- 			    ' WHERE id= :id';
1489
-			    $sqlQuery=$db_conn->prepare($sql);
1485
+				$sql='UPDATE '.$this->db_prefix.'mib_cache SET '.
1486
+ 				'name = :name , type = :type , mib = :mib , textual_convention = :tc , display_hint = :display_hint'. 
1487
+ 				', syntax = :syntax, type_enum = :type_enum, description = :description '.
1488
+ 				' WHERE id= :id';
1489
+				$sqlQuery=$db_conn->prepare($sql);
1490 1490
 			    
1491
-			    $sqlParam=array(
1492
-			        ':name' => $name,
1493
-			        ':type' => $type, 
1494
-			        ':mib' => $mib, 
1495
-			        ':tc' =>  ($textConv==null)?'null':$textConv , 
1496
-			        ':display_hint' => ($dispHint==null)?'null':$dispHint ,
1497
-			        ':syntax' => ($syntax==null)?'null':$syntax,
1498
-			        ':type_enum' => ($type_enum==null)?'null':$type_enum, 
1499
-			        ':description' => ($description==null)?'null':$description,
1500
-			        ':id' => $this->dbOidAll[$this->dbOidIndex[$oid]['id']]
1501
-			    );
1491
+				$sqlParam=array(
1492
+					':name' => $name,
1493
+					':type' => $type, 
1494
+					':mib' => $mib, 
1495
+					':tc' =>  ($textConv==null)?'null':$textConv , 
1496
+					':display_hint' => ($dispHint==null)?'null':$dispHint ,
1497
+					':syntax' => ($syntax==null)?'null':$syntax,
1498
+					':type_enum' => ($type_enum==null)?'null':$type_enum, 
1499
+					':description' => ($description==null)?'null':$description,
1500
+					':id' => $this->dbOidAll[$this->dbOidIndex[$oid]['id']]
1501
+				);
1502 1502
 			    
1503
-			    if ($sqlQuery->execute($sqlParam) == FALSE) {
1504
-			        $this->trapLog('Error in query : ' . $sql,ERROR,'');
1505
-			    }
1506
-			    $this->trapLog('Trap updated : '.$name . ' / OID : '.$oid,4,'');
1503
+				if ($sqlQuery->execute($sqlParam) == FALSE) {
1504
+					$this->trapLog('Error in query : ' . $sql,ERROR,'');
1505
+				}
1506
+				$this->trapLog('Trap updated : '.$name . ' / OID : '.$oid,4,'');
1507 1507
 				return 1;
1508 1508
 			}
1509 1509
 			else
1510 1510
 			{
1511
-			    $this->trapLog('Trap unchanged : '.$name . ' / OID : '.$oid,4,'');
1512
-			    return 0;
1511
+				$this->trapLog('Trap unchanged : '.$name . ' / OID : '.$oid,4,'');
1512
+				return 0;
1513 1513
 			}
1514 1514
 		}
1515
-        // create new OID.
1515
+		// create new OID.
1516 1516
 			
1517 1517
 		// Insert data
1518 1518
 
1519 1519
 		$sql='INSERT INTO '.$this->db_prefix.'mib_cache '.
1520
-		      '(oid, name, type , mib, textual_convention, display_hint '.
1521
-              ', syntax, type_enum , description ) ' . 
1522
-              'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
1523
-              ', :syntax, :type_enum, :description )';
1520
+			  '(oid, name, type , mib, textual_convention, display_hint '.
1521
+			  ', syntax, type_enum , description ) ' . 
1522
+			  'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
1523
+			  ', :syntax, :type_enum, :description )';
1524 1524
         
1525 1525
 		if ($this->trapDBType == 'pgsql') $sql .= 'RETURNING id';
1526 1526
 		
1527 1527
 		$sqlQuery=$db_conn->prepare($sql);
1528 1528
 		
1529 1529
 		$sqlParam=array(
1530
-		    ':oid' => $oid,
1531
-		    ':name' => $name,
1532
-		    ':type' => $type,
1533
-		    ':mib' => $mib,
1534
-		    ':tc' =>  ($textConv==null)?'null':$textConv ,
1535
-		    ':display_hint' => ($dispHint==null)?'null':$dispHint ,
1536
-		    ':syntax' => ($syntax==null)?'null':$syntax,
1537
-		    ':type_enum' => ($type_enum==null)?'null':$type_enum,
1538
-		    ':description' => ($description==null)?'null':$description
1530
+			':oid' => $oid,
1531
+			':name' => $name,
1532
+			':type' => $type,
1533
+			':mib' => $mib,
1534
+			':tc' =>  ($textConv==null)?'null':$textConv ,
1535
+			':display_hint' => ($dispHint==null)?'null':$dispHint ,
1536
+			':syntax' => ($syntax==null)?'null':$syntax,
1537
+			':type_enum' => ($type_enum==null)?'null':$type_enum,
1538
+			':description' => ($description==null)?'null':$description
1539 1539
 		);
1540 1540
 		
1541 1541
 		if ($sqlQuery->execute($sqlParam) == FALSE) {
1542
-		    $this->trapLog('Error in query : ' . $sql,1,'');
1542
+			$this->trapLog('Error in query : ' . $sql,1,'');
1543 1543
 		}
1544 1544
 		
1545 1545
 		switch ($this->trapDBType)
1546 1546
 		{
1547
-		    case 'pgsql':
1548
-		        // Get last id to insert oid/values in secondary table
1549
-		        if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) == FALSE) {		            
1550
-		            $this->trapLog('Error getting id - pgsql - ',1,'');
1551
-		        }
1552
-		        if (! isset($inserted_id_ret['id'])) {
1553
-		            $this->trapLog('Error getting id - pgsql - empty.',1,'');
1554
-		        }
1555
-		        $this->dbOidIndex[$oid]['id']=$inserted_id_ret['id'];
1556
-		        break;
1557
-		    case 'mysql':
1558
-		        // Get last id to insert oid/values in secondary table
1559
-		        $sql='SELECT LAST_INSERT_ID();';
1560
-		        if (($ret_code=$db_conn->query($sql)) == FALSE) {
1561
-		            $this->trapLog('Erreur getting id - mysql - ',1,'');
1562
-		        }
1547
+			case 'pgsql':
1548
+				// Get last id to insert oid/values in secondary table
1549
+				if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) == FALSE) {		            
1550
+					$this->trapLog('Error getting id - pgsql - ',1,'');
1551
+				}
1552
+				if (! isset($inserted_id_ret['id'])) {
1553
+					$this->trapLog('Error getting id - pgsql - empty.',1,'');
1554
+				}
1555
+				$this->dbOidIndex[$oid]['id']=$inserted_id_ret['id'];
1556
+				break;
1557
+			case 'mysql':
1558
+				// Get last id to insert oid/values in secondary table
1559
+				$sql='SELECT LAST_INSERT_ID();';
1560
+				if (($ret_code=$db_conn->query($sql)) == FALSE) {
1561
+					$this->trapLog('Erreur getting id - mysql - ',1,'');
1562
+				}
1563 1563
 		        
1564
-		        $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
1565
-		        if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
1566
-		        $this->dbOidIndex[$oid]['id']=$inserted_id;
1567
-		        break;
1568
-		    default:
1569
-		        $this->trapLog('Error SQL type  : '.$this->trapDBType,1,'');
1564
+				$inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
1565
+				if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
1566
+				$this->dbOidIndex[$oid]['id']=$inserted_id;
1567
+				break;
1568
+			default:
1569
+				$this->trapLog('Error SQL type  : '.$this->trapDBType,1,'');
1570 1570
 		}
1571 1571
 
1572 1572
 		// Set as newly created.
@@ -1574,148 +1574,148 @@  discard block
 block discarded – undo
1574 1574
 		return 2;
1575 1575
 	}
1576 1576
 
1577
-    /**
1578
-     * create or update (with check_existing = true) objects of trap
1579
-     * @param string $trapOID : trap oid
1580
-     * @param string $trapmib : mib of trap
1581
-     * @param array $objects : array of objects name (without MIB)
1582
-     * @param bool $check_existing : check instead of create
1583
-     */
1577
+	/**
1578
+	 * create or update (with check_existing = true) objects of trap
1579
+	 * @param string $trapOID : trap oid
1580
+	 * @param string $trapmib : mib of trap
1581
+	 * @param array $objects : array of objects name (without MIB)
1582
+	 * @param bool $check_existing : check instead of create
1583
+	 */
1584 1584
 	public function trap_objects($trapOID,$trapmib,$objects,$check_existing)
1585 1585
 	{
1586
-	    $dbObjects=null; // cache of objects for trap in db
1587
-	    $db_conn=$this->db_connect_trap();
1586
+		$dbObjects=null; // cache of objects for trap in db
1587
+		$db_conn=$this->db_connect_trap();
1588 1588
 	    
1589
-	    // Get id of trapmib.
1589
+		// Get id of trapmib.
1590 1590
 
1591
-	    $trapId = $this->dbOidIndex[$trapOID]['id'];
1592
-	    if ($check_existing == true)
1593
-	    {
1594
-	        // Get all objects
1595
-	        $sql='SELECT * FROM '.$this->db_prefix.'mib_cache_trap_object where trap_id='.$trapId.';';
1596
-	        $this->trapLog('SQL query get all traps: '.$sql,4,'');
1597
-	        if (($ret_code=$db_conn->query($sql)) == FALSE) {
1598
-	            $this->trapLog('No result in query : ' . $sql,1,'');
1599
-	        }
1600
-	        $dbObjectsRaw=$ret_code->fetchAll();
1591
+		$trapId = $this->dbOidIndex[$trapOID]['id'];
1592
+		if ($check_existing == true)
1593
+		{
1594
+			// Get all objects
1595
+			$sql='SELECT * FROM '.$this->db_prefix.'mib_cache_trap_object where trap_id='.$trapId.';';
1596
+			$this->trapLog('SQL query get all traps: '.$sql,4,'');
1597
+			if (($ret_code=$db_conn->query($sql)) == FALSE) {
1598
+				$this->trapLog('No result in query : ' . $sql,1,'');
1599
+			}
1600
+			$dbObjectsRaw=$ret_code->fetchAll();
1601 1601
 	        
1602
-	        foreach ($dbObjectsRaw as $val)
1603
-	        {
1604
-	            $dbObjects[$val['object_id']]=1;
1605
-	        }
1606
-	    }
1607
-	    foreach ($objects as $object)
1608
-	    {
1609
-	        $match=$snmptrans=array();
1610
-	        $retVal=0;
1611
-	        $objOid=$objTc=$objDispHint=$objSyntax=$objDesc=$objEnum=NULL;
1612
-	        $tmpdesc='';$indesc=false;
1602
+			foreach ($dbObjectsRaw as $val)
1603
+			{
1604
+				$dbObjects[$val['object_id']]=1;
1605
+			}
1606
+		}
1607
+		foreach ($objects as $object)
1608
+		{
1609
+			$match=$snmptrans=array();
1610
+			$retVal=0;
1611
+			$objOid=$objTc=$objDispHint=$objSyntax=$objDesc=$objEnum=NULL;
1612
+			$tmpdesc='';$indesc=false;
1613 1613
 	        
1614
-	        $objMib=$trapmib;
1615
-	        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1616
-	            ' -On -Td '.$objMib.'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
1617
-	        if ($retVal!=0)
1618
-	        {
1619
-	            // Maybe not trap mib, search with IR
1620
-	            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1621
-	                ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
1622
-	            if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
1623
-	            { // Not found -> continue with warning
1624
-	               $this->trapLog('Error finding trap object : '.$trapmib.'::'.$object,2,'');
1625
-	               continue;
1626
-	            }
1627
-	            $objMib=$match[1];
1614
+			$objMib=$trapmib;
1615
+			exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1616
+				' -On -Td '.$objMib.'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
1617
+			if ($retVal!=0)
1618
+			{
1619
+				// Maybe not trap mib, search with IR
1620
+				exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1621
+					' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
1622
+				if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
1623
+				{ // Not found -> continue with warning
1624
+				   $this->trapLog('Error finding trap object : '.$trapmib.'::'.$object,2,'');
1625
+				   continue;
1626
+				}
1627
+				$objMib=$match[1];
1628 1628
 	            
1629
-	            // Do the snmptranslate again.
1630
-	            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1631
-	                ' -On -Td '.$objMib.'::'.$object,$snmptrans,$retVal);
1632
-	            if ($retVal!=0) {
1633
-	                $this->trapLog('Error finding trap object : '.$objMib.'::'.$object,2,'');
1634
-	            }
1629
+				// Do the snmptranslate again.
1630
+				exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1631
+					' -On -Td '.$objMib.'::'.$object,$snmptrans,$retVal);
1632
+				if ($retVal!=0) {
1633
+					$this->trapLog('Error finding trap object : '.$objMib.'::'.$object,2,'');
1634
+				}
1635 1635
 	            
1636
-	        }
1637
-	        foreach ($snmptrans as $line)
1638
-	        {
1639
-	            if ($indesc==true)
1640
-	            {
1641
-	                $line=preg_replace('/[\t ]+/',' ',$line);
1642
-	                if (preg_match('/(.*)"$/', $line,$match))
1643
-	                {
1644
-	                    $objDesc = $tmpdesc . $match[1];
1645
-	                    $indesc=false;
1646
-	                }
1647
-	                $tmpdesc.=$line;
1648
-	                continue;
1649
-	            }
1650
-	            if (preg_match('/^\.[0-9\.]+$/', $line))
1651
-	            {
1652
-	                $objOid=$line;
1653
-	                continue;
1654
-	            }
1655
-	            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
1656
-	            {
1657
-	                $objSyntax=$match[1];
1658
-                    $objEnum=$match[2];
1659
-	                continue;
1660
-	            }
1661
-	            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
1662
-	            {
1663
-	                $objSyntax=$match[1];
1664
-	                continue;
1665
-	            }
1666
-	            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
1667
-	            {
1668
-	                $objDispHint=$match[1];
1669
-	                continue;
1670
-	            }
1671
-	            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
1672
-	            {
1673
-	                $objDesc=$match[1];
1674
-	                continue;
1675
-	            }
1676
-	            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
1677
-	            {
1678
-	                $tmpdesc=$match[1];
1679
-	                $indesc=true;
1680
-	                continue;
1681
-	            }
1682
-	            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
1683
-	            {
1684
-	                $objTc=$match[1];
1685
-	                continue;
1686
-	            }
1687
-	        }
1688
-	        $this->trapLog("Adding trap $object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc",4,'');
1689
-	        //echo "$object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc / $objDesc\n";
1690
-	        // Update 
1691
-	        $this->update_oid($objOid, $objMib, $object, '3', $objTc, $objDispHint, $objSyntax, $objEnum,$objDesc);
1636
+			}
1637
+			foreach ($snmptrans as $line)
1638
+			{
1639
+				if ($indesc==true)
1640
+				{
1641
+					$line=preg_replace('/[\t ]+/',' ',$line);
1642
+					if (preg_match('/(.*)"$/', $line,$match))
1643
+					{
1644
+						$objDesc = $tmpdesc . $match[1];
1645
+						$indesc=false;
1646
+					}
1647
+					$tmpdesc.=$line;
1648
+					continue;
1649
+				}
1650
+				if (preg_match('/^\.[0-9\.]+$/', $line))
1651
+				{
1652
+					$objOid=$line;
1653
+					continue;
1654
+				}
1655
+				if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
1656
+				{
1657
+					$objSyntax=$match[1];
1658
+					$objEnum=$match[2];
1659
+					continue;
1660
+				}
1661
+				if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
1662
+				{
1663
+					$objSyntax=$match[1];
1664
+					continue;
1665
+				}
1666
+				if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
1667
+				{
1668
+					$objDispHint=$match[1];
1669
+					continue;
1670
+				}
1671
+				if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
1672
+				{
1673
+					$objDesc=$match[1];
1674
+					continue;
1675
+				}
1676
+				if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
1677
+				{
1678
+					$tmpdesc=$match[1];
1679
+					$indesc=true;
1680
+					continue;
1681
+				}
1682
+				if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
1683
+				{
1684
+					$objTc=$match[1];
1685
+					continue;
1686
+				}
1687
+			}
1688
+			$this->trapLog("Adding trap $object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc",4,'');
1689
+			//echo "$object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc / $objDesc\n";
1690
+			// Update 
1691
+			$this->update_oid($objOid, $objMib, $object, '3', $objTc, $objDispHint, $objSyntax, $objEnum,$objDesc);
1692 1692
             
1693
-	        if (isset($dbObjects[$this->dbOidIndex[$objOid]['id']]))
1694
-	        {   // if link exists, continue
1695
-	            $dbObjects[$this->dbOidIndex[$objOid]['id']]=2;
1696
-	            continue;
1697
-	        }
1698
-	        if ($check_existing == true) 
1699
-	        {
1700
-	            // TODO : check link trap - objects exists, mark them.
1701
-	        }
1702
-	        // Associate in object table
1703
-	        $sql='INSERT INTO '.$this->db_prefix.'mib_cache_trap_object (trap_id,object_id) '.
1704
-	   	        'values (:trap_id, :object_id)';	        
1705
-	        $sqlQuery=$db_conn->prepare($sql);	        
1706
-	        $sqlParam=array(
1707
-	            ':trap_id' => $trapId,
1708
-	            ':object_id' => $this->dbOidIndex[$objOid]['id'],
1709
-	        );
1693
+			if (isset($dbObjects[$this->dbOidIndex[$objOid]['id']]))
1694
+			{   // if link exists, continue
1695
+				$dbObjects[$this->dbOidIndex[$objOid]['id']]=2;
1696
+				continue;
1697
+			}
1698
+			if ($check_existing == true) 
1699
+			{
1700
+				// TODO : check link trap - objects exists, mark them.
1701
+			}
1702
+			// Associate in object table
1703
+			$sql='INSERT INTO '.$this->db_prefix.'mib_cache_trap_object (trap_id,object_id) '.
1704
+	   			'values (:trap_id, :object_id)';	        
1705
+			$sqlQuery=$db_conn->prepare($sql);	        
1706
+			$sqlParam=array(
1707
+				':trap_id' => $trapId,
1708
+				':object_id' => $this->dbOidIndex[$objOid]['id'],
1709
+			);
1710 1710
 	        
1711
-	        if ($sqlQuery->execute($sqlParam) == FALSE) {
1712
-	            $this->trapLog('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$objOid]['id'] ,1,'');
1713
-	        }
1714
-	    }
1715
-	    if ($check_existing == true)
1716
-	    {
1717
-	        // TODO : remove link trap - objects that wasn't marked.
1718
-	    }
1711
+			if ($sqlQuery->execute($sqlParam) == FALSE) {
1712
+				$this->trapLog('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$objOid]['id'] ,1,'');
1713
+			}
1714
+		}
1715
+		if ($check_existing == true)
1716
+		{
1717
+			// TODO : remove link trap - objects that wasn't marked.
1718
+		}
1719 1719
 	    
1720 1720
 	}
1721 1721
 	
@@ -1725,7 +1725,7 @@  discard block
 block discarded – undo
1725 1725
 	 * @param boolean $check_change : Force check of trap params & objects
1726 1726
 	 * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
1727 1727
 	 * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
1728
-	*/	
1728
+	 */	
1729 1729
 	public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
1730 1730
 	{
1731 1731
 		// Timing 
@@ -1777,7 +1777,7 @@  discard block
 block discarded – undo
1777 1777
 		
1778 1778
 		for ($curElement=0;$curElement < $numElements;$curElement++)
1779 1779
 		{
1780
-		    $time_1= microtime(true);
1780
+			$time_1= microtime(true);
1781 1781
 			if ((microtime(true)-$timeFiveSec) > 2 && $display_progress)
1782 1782
 			{ // echo a . every 2 sec
1783 1783
 				echo '.';
@@ -1795,8 +1795,8 @@  discard block
 block discarded – undo
1795 1795
 			// Get oid or pass if not found
1796 1796
 			if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
1797 1797
 			{
1798
-			    $time_parse1 += microtime(true) - $time_1;
1799
-			    $time_parse1N ++;
1798
+				$time_parse1 += microtime(true) - $time_1;
1799
+				$time_parse1N ++;
1800 1800
 				continue;
1801 1801
 			}
1802 1802
 			$oid=$this->objectsAll[$curElement];
@@ -1807,7 +1807,7 @@  discard block
 block discarded – undo
1807 1807
 			if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
1808 1808
 						$this->objectsAll[$curElement],$match))
1809 1809
 			{
1810
-			    $time_check1 += microtime(true) - $time_1;
1810
+				$time_check1 += microtime(true) - $time_1;
1811 1811
 				$time_check1N++;
1812 1812
 				continue;
1813 1813
 			}
@@ -1820,8 +1820,8 @@  discard block
 block discarded – undo
1820 1820
 				// Check if next is suboid -> in that case is cannot be a trap
1821 1821
 				if (preg_match("/^$oid/",$this->objectsAll[$curElement+1]))
1822 1822
 				{
1823
-				    $time_check2 += microtime(true) - $time_1;
1824
-				    $time_check2N++;
1823
+					$time_check2 += microtime(true) - $time_1;
1824
+					$time_check2N++;
1825 1825
 					continue;
1826 1826
 				}		
1827 1827
 				unset($snmptrans);
@@ -1829,8 +1829,8 @@  discard block
 block discarded – undo
1829 1829
 					' -Td '.$oid . ' | grep OBJECTS ',$snmptrans,$retVal);
1830 1830
 				if ($retVal!=0)
1831 1831
 				{
1832
-				    $time_check2 += microtime(true) - $time_1;
1833
-				    $time_check2N++;
1832
+					$time_check2 += microtime(true) - $time_1;
1833
+					$time_check2N++;
1834 1834
 					continue;
1835 1835
 				}
1836 1836
 				//echo "\n v1 trap found : $oid \n";
@@ -1839,7 +1839,7 @@  discard block
 block discarded – undo
1839 1839
 			}
1840 1840
 			if ($onlyTraps==true && $type!=21) // if only traps and not a trap, continue
1841 1841
 			{
1842
-			    $time_check3 += microtime(true) - $time_1;
1842
+				$time_check3 += microtime(true) - $time_1;
1843 1843
 				$time_check3N++;
1844 1844
 				continue;
1845 1845
 			}
@@ -1860,7 +1860,7 @@  discard block
 block discarded – undo
1860 1860
 			
1861 1861
 			if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
1862 1862
 			{
1863
-			    $this->trapLog('Error getting mib from trap '.$oid.' : ' . $snmptrans[0],1,'');
1863
+				$this->trapLog('Error getting mib from trap '.$oid.' : ' . $snmptrans[0],1,'');
1864 1864
 			}
1865 1865
 			$trapMib=$match[1];
1866 1866
 			
@@ -1868,17 +1868,17 @@  discard block
 block discarded – undo
1868 1868
 			while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
1869 1869
 			if (isset($snmptrans[$numLine]))
1870 1870
 			{
1871
-			    $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
1871
+				$snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
1872 1872
 
1873
-			    while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
1874
-			    {
1875
-			        $trapDesc.=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
1876
-			        $numLine++;
1877
-			    }
1878
-			    if (isset($snmptrans[$numLine])) {
1879
-			        $trapDesc.=preg_replace('/".*/','',$snmptrans[$numLine]);
1880
-			        $trapDesc=preg_replace('/[\t ]+/',' ',$trapDesc);
1881
-			    }
1873
+				while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
1874
+				{
1875
+					$trapDesc.=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
1876
+					$numLine++;
1877
+				}
1878
+				if (isset($snmptrans[$numLine])) {
1879
+					$trapDesc.=preg_replace('/".*/','',$snmptrans[$numLine]);
1880
+					$trapDesc=preg_replace('/[\t ]+/',' ',$trapDesc);
1881
+				}
1882 1882
 
1883 1883
 			}
1884 1884
 			$update=$this->update_oid($oid,$trapMib,$name,$type,NULL,NULL,NULL,NULL,$trapDesc);
@@ -1886,23 +1886,23 @@  discard block
 block discarded – undo
1886 1886
 			
1887 1887
 			if (($update==0) && ($check_change==false))
1888 1888
 			{ // Trapd didn't change & force check disabled
1889
-			    $time_objects += microtime(true) - $time_1;
1890
-			    if ($display_progress) echo "C";
1891
-			    continue;
1889
+				$time_objects += microtime(true) - $time_1;
1890
+				if ($display_progress) echo "C";
1891
+				continue;
1892 1892
 			}
1893 1893
 			
1894 1894
 			$synt=null;
1895 1895
 			foreach ($snmptrans as $line)
1896 1896
 			{	
1897
-    			if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
1898
-    				{
1899
-    					$synt=$match[1];
1900
-    				}
1897
+				if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
1898
+					{
1899
+						$synt=$match[1];
1900
+					}
1901 1901
 			}
1902 1902
 			if ($synt == null) 
1903 1903
 			{
1904 1904
 				//echo "No objects for $trapOID\n";
1905
-			    $time_objects += microtime(true) - $time_1;
1905
+				$time_objects += microtime(true) - $time_1;
1906 1906
 				continue;
1907 1907
 			}
1908 1908
 			//echo "$synt \n";
@@ -1921,18 +1921,18 @@  discard block
 block discarded – undo
1921 1921
 		
1922 1922
 		if ($display_progress)
1923 1923
 		{
1924
-    		echo "\nNumber of processed traps : $time_num_traps \n";
1925
-    		echo "\nParsing : " . number_format($time_parse1+$time_check1,1) ." sec / " . ($time_parse1N+ $time_check1N)  . " occurences\n";
1926
-    		echo "Detecting traps : " . number_format($time_check2+$time_check3,1) . " sec / " . ($time_check2N+$time_check3N) ." occurences\n";
1927
-    		echo "Trap processing ($time_updateN): ".number_format($time_update,1)." sec , ";
1928
-    		echo "Objects processing ($time_objectsN) : ".number_format($time_objects,1)." sec \n";
1924
+			echo "\nNumber of processed traps : $time_num_traps \n";
1925
+			echo "\nParsing : " . number_format($time_parse1+$time_check1,1) ." sec / " . ($time_parse1N+ $time_check1N)  . " occurences\n";
1926
+			echo "Detecting traps : " . number_format($time_check2+$time_check3,1) . " sec / " . ($time_check2N+$time_check3N) ." occurences\n";
1927
+			echo "Trap processing ($time_updateN): ".number_format($time_update,1)." sec , ";
1928
+			echo "Objects processing ($time_objectsN) : ".number_format($time_objects,1)." sec \n";
1929 1929
 		}
1930 1930
 		
1931 1931
 		// Timing ends
1932 1932
 		$timeTaken=microtime(true) - $timeTaken;
1933 1933
 		if ($display_progress)
1934 1934
 		{
1935
-		    echo "Global time : ".round($timeTaken)." seconds\n";
1935
+			echo "Global time : ".round($timeTaken)." seconds\n";
1936 1936
 		}
1937 1937
 		
1938 1938
 	}
Please login to merge, or discard this patch.
Spacing   +432 added lines, -432 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 use Icinga\Module\Trapdirector\Icinga2API;
9 9
 
10
-define("ERROR", 1);define("WARN", 2);define("INFO", 3);define("DEBUG", 4);
10
+define("ERROR", 1); define("WARN", 2); define("INFO", 3); define("DEBUG", 4);
11 11
 
12 12
 class Trap
13 13
 {
@@ -31,10 +31,10 @@  discard block
 block discarded – undo
31 31
 
32 32
 	//**** Options from config database
33 33
 	// Logs 
34
-	protected $debug_level=2;  // 0=No output 1=critical 2=warning 3=trace 4=ALL
34
+	protected $debug_level=2; // 0=No output 1=critical 2=warning 3=trace 4=ALL
35 35
 	protected $alert_output='display'; // alert type : file, syslog, display
36 36
 	protected $debug_file="/tmp/trapdebug.txt";
37
-	protected $debug_text=array("","Error","Warning","Info","Debug");
37
+	protected $debug_text=array("", "Error", "Warning", "Info", "Debug");
38 38
 	
39 39
 	//**** End options from database
40 40
 	
@@ -86,15 +86,15 @@  discard block
 block discarded – undo
86 86
 	 * @param string $message warning message if not found
87 87
 	 * @return boolean true if found, or false
88 88
 	 */
89
-	protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = 2, $message = null)
89
+	protected function getOptionIfSet($option_array, $option_category, $option_name, &$option_var, $log_level=2, $message=null)
90 90
 	{
91 91
 	    if (!isset($option_array[$option_category][$option_name]))
92 92
 	    {
93 93
 	        if ($message == null)
94 94
 	        {
95
-	            $message='No ' . $option_name . ' in config file: '. $this->trap_module_config;
95
+	            $message='No '.$option_name.' in config file: '.$this->trap_module_config;
96 96
 	        }
97
-	        $this->trapLog($message,$log_level,'syslog');
97
+	        $this->trapLog($message, $log_level, 'syslog');
98 98
 	        return false;
99 99
 	    }
100 100
 	    else
@@ -108,40 +108,40 @@  discard block
 block discarded – undo
108 108
 	*/
109 109
 	protected function getOptions()
110 110
 	{
111
-		$trap_config=parse_ini_file($this->trap_module_config,true);
111
+		$trap_config=parse_ini_file($this->trap_module_config, true);
112 112
 		if ($trap_config == false) 
113 113
 		{
114
-			$this->trapLog("Error reading ini file : ".$this->trap_module_config,ERROR,'syslog'); 
114
+			$this->trapLog("Error reading ini file : ".$this->trap_module_config, ERROR, 'syslog'); 
115 115
 		}
116 116
 		// Snmptranslate binary path
117
-		$this->getOptionIfSet($trap_config,'config','snmptranslate', $this->snmptranslate);
117
+		$this->getOptionIfSet($trap_config, 'config', 'snmptranslate', $this->snmptranslate);
118 118
 
119 119
 		// mibs path
120
-		$this->getOptionIfSet($trap_config,'config','snmptranslate_dirs', $this->snmptranslate_dirs);
120
+		$this->getOptionIfSet($trap_config, 'config', 'snmptranslate_dirs', $this->snmptranslate_dirs);
121 121
 
122 122
 		// icinga2cmd path
123
-		$this->getOptionIfSet($trap_config,'config','icingacmd', $this->icinga2cmd);
123
+		$this->getOptionIfSet($trap_config, 'config', 'icingacmd', $this->icinga2cmd);
124 124
 		
125 125
 		// table prefix
126
-		$this->getOptionIfSet($trap_config,'config','database_prefix', $this->db_prefix);
126
+		$this->getOptionIfSet($trap_config, 'config', 'database_prefix', $this->db_prefix);
127 127
 
128 128
 		// API options
129
-		if ($this->getOptionIfSet($trap_config,'config','icingaAPI_host', $this->api_hostname))
129
+		if ($this->getOptionIfSet($trap_config, 'config', 'icingaAPI_host', $this->api_hostname))
130 130
 		{
131 131
 		    $this->api_use=true;
132
-		    $this->getOptionIfSet($trap_config,'config','icingaAPI_port', $this->api_port);
133
-		    $this->getOptionIfSet($trap_config,'config','icingaAPI_user', $this->api_username);
134
-		    $this->getOptionIfSet($trap_config,'config','icingaAPI_password', $this->api_password);
132
+		    $this->getOptionIfSet($trap_config, 'config', 'icingaAPI_port', $this->api_port);
133
+		    $this->getOptionIfSet($trap_config, 'config', 'icingaAPI_user', $this->api_username);
134
+		    $this->getOptionIfSet($trap_config, 'config', 'icingaAPI_password', $this->api_password);
135 135
 		}
136 136
 				
137 137
 		/***** Database options :  ***/
138
-		$this->getDBConfigIfSet('log_level',$this->debug_level);
139
-		$this->getDBConfigIfSet('log_destination',$this->alert_output);
140
-		$this->getDBConfigIfSet('log_file',$this->debug_file);
138
+		$this->getDBConfigIfSet('log_level', $this->debug_level);
139
+		$this->getDBConfigIfSet('log_destination', $this->alert_output);
140
+		$this->getDBConfigIfSet('log_file', $this->debug_file);
141 141
 		$this->getAPI();
142 142
 	}
143 143
 
144
-	protected function getDBConfigIfSet($element,&$variable)
144
+	protected function getDBConfigIfSet($element, &$variable)
145 145
 	{
146 146
 		$value=$this->getDBConfig($element);
147 147
 		if ($value != 'null') $variable=$value;
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 		$db_conn=$this->db_connect_trap();
157 157
 		$sql='SELECT value from '.$this->db_prefix.'db_config WHERE ( name=\''.$element.'\' )';
158 158
 		if (($ret_code=$db_conn->query($sql)) == FALSE) {
159
-			$this->trapLog('No result in query : ' . $sql,WARN,'');
159
+			$this->trapLog('No result in query : '.$sql, WARN, '');
160 160
 			return null;
161 161
 		}
162 162
 		$value=$ret_code->fetch();
@@ -173,29 +173,29 @@  discard block
 block discarded – undo
173 173
 	*	@param  int $destination file/syslog/display
174 174
 	*	@return void
175 175
 	**/	
176
-	public function trapLog( $message, $level, $destination ='')
176
+	public function trapLog($message, $level, $destination='')
177 177
 	{	
178 178
 		if ($this->debug_level >= $level) 
179 179
 		{
180
-			$message = '['.  date("Y/m/d H:i:s") . '] ' .
181
-				'['. basename(__FILE__) . '] ['.$this->debug_text[$level].']: ' .$message . "\n";
180
+			$message='['.date("Y/m/d H:i:s").'] '.
181
+				'['.basename(__FILE__).'] ['.$this->debug_text[$level].']: '.$message."\n";
182 182
 			
183
-			if ( $destination != '' ) $output=$destination;
183
+			if ($destination != '') $output=$destination;
184 184
 			else $output=$this->alert_output;
185 185
 			switch ($output)
186 186
 			{
187 187
 				case 'file':
188
-					file_put_contents ($this->debug_file, $message , FILE_APPEND);
188
+					file_put_contents($this->debug_file, $message, FILE_APPEND);
189 189
 					break;
190 190
 				case 'syslog':
191
-					switch($level)
191
+					switch ($level)
192 192
 					{
193
-						case 1 : $prio = LOG_ERR;break;
194
-						case 2 : $prio = LOG_WARNING;break;
195
-						case 3 : $prio = LOG_INFO;break;
196
-						case 4 : $prio = LOG_DEBUG;break;
193
+						case 1 : $prio=LOG_ERR; break;
194
+						case 2 : $prio=LOG_WARNING; break;
195
+						case 3 : $prio=LOG_INFO; break;
196
+						case 4 : $prio=LOG_DEBUG; break;
197 197
 					}
198
-					syslog($prio,$message);
198
+					syslog($prio, $message);
199 199
 					break;
200 200
 				case 'display':
201 201
 					echo $message;
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 		}
211 211
 	}
212 212
 	
213
-	public function setLogging($debug_lvl,$output_type,$output_option=null)
213
+	public function setLogging($debug_lvl, $output_type, $output_option=null)
214 214
 	{
215 215
 		$this->debug_level=$debug_lvl;
216 216
 		switch ($output_type)
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 				$this->alert_output='display';
228 228
 				break;
229 229
 			default : // syslog should always work....
230
-				$this->trapLog("Error in log output : ".$output_type,ERROR,'syslog');
230
+				$this->trapLog("Error in log output : ".$output_type, ERROR, 'syslog');
231 231
 		}
232 232
 	}
233 233
 	
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 	{
236 236
 	    if ($this->icinga2api == null)
237 237
 	    {
238
-	        $this->icinga2api = new Icinga2API($this->api_hostname,$this->api_port);
238
+	        $this->icinga2api=new Icinga2API($this->api_hostname, $this->api_port);
239 239
 	    }
240 240
 	    return $this->icinga2api;
241 241
 	}
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 		    } catch (Exception $e) {
254 254
 		        // select 1 failed, try to reconnect.
255 255
 		        $this->trapDB=null;
256
-		        $this->trapLog('Databse connection lost, reconnecting',WARN,'');
256
+		        $this->trapLog('Databse connection lost, reconnecting', WARN, '');
257 257
 		    }
258 258
 		     
259 259
 		}
@@ -279,14 +279,14 @@  discard block
 block discarded – undo
279 279
 	protected function db_connect($database) {
280 280
 		$confarray=$this->get_database($database);
281 281
 		//	$dsn = 'mysql:dbname=traps;host=127.0.0.1';
282
-		$dsn= $confarray[0].':dbname='.$confarray[2].';host='.$confarray[1];
283
-		$user = $confarray[3];
284
-		$password = $confarray[4];
285
-		$this->trapLog('DSN : '.$dsn,3);
282
+		$dsn=$confarray[0].':dbname='.$confarray[2].';host='.$confarray[1];
283
+		$user=$confarray[3];
284
+		$password=$confarray[4];
285
+		$this->trapLog('DSN : '.$dsn, 3);
286 286
 		try {
287
-			$dbh = new PDO($dsn, $user, $password);
287
+			$dbh=new PDO($dsn, $user, $password);
288 288
 		} catch (PDOException $e) {
289
-			$this->trapLog('Connection failed : ' . $e->getMessage(),ERROR,'');
289
+			$this->trapLog('Connection failed : '.$e->getMessage(), ERROR, '');
290 290
 		}
291 291
 		return $dbh;
292 292
 	}
@@ -297,16 +297,16 @@  discard block
 block discarded – undo
297 297
 	**/
298 298
 	protected function get_database($database) {
299 299
 
300
-		$trap_config=parse_ini_file($this->trap_module_config,true);
300
+		$trap_config=parse_ini_file($this->trap_module_config, true);
301 301
 		if ($trap_config == false) 
302 302
 		{
303
-			$this->trapLog("Error reading ini file : ".$this->trap_module_config,ERROR,''); 
303
+			$this->trapLog("Error reading ini file : ".$this->trap_module_config, ERROR, ''); 
304 304
 		}
305 305
 		if ($database == 'traps')
306 306
 		{
307 307
 			if (!isset($trap_config['config']['database'])) 
308 308
 			{
309
-				$this->trapLog("No Config/database in config file: ".$this->trap_module_config,ERROR,''); 
309
+				$this->trapLog("No Config/database in config file: ".$this->trap_module_config, ERROR, ''); 
310 310
 			}
311 311
 			$db_name=$trap_config['config']['database'];
312 312
 		} 
@@ -314,34 +314,34 @@  discard block
 block discarded – undo
314 314
 		{
315 315
 			if (!isset($trap_config['config']['IDOdatabase'])) 
316 316
 			{
317
-				$this->trapLog("No Config/IDOdatabase in config file: ".$this->trap_module_config,ERROR,''); 
317
+				$this->trapLog("No Config/IDOdatabase in config file: ".$this->trap_module_config, ERROR, ''); 
318 318
 			}
319 319
 			$db_name=$trap_config['config']['IDOdatabase'];		
320 320
 		}
321 321
 		else
322 322
 		{
323
-			$this->trapLog("Unknown database type : ".$database,ERROR,''); 		
323
+			$this->trapLog("Unknown database type : ".$database, ERROR, ''); 		
324 324
 		}	
325
-		$this->trapLog("Found database in config file: ".$db_name,3,''); 
326
-		$db_config=parse_ini_file($this->icingaweb2_ressources,true);
325
+		$this->trapLog("Found database in config file: ".$db_name, 3, ''); 
326
+		$db_config=parse_ini_file($this->icingaweb2_ressources, true);
327 327
 		if ($db_config == false) 
328 328
 		{
329
-			$this->trapLog("Error reading ini file : ".$this->icingaweb2_ressources,ERROR,''); 
329
+			$this->trapLog("Error reading ini file : ".$this->icingaweb2_ressources, ERROR, ''); 
330 330
 		}
331 331
 		if (!isset($db_config[$db_name])) 
332 332
 		{
333
-			$this->trapLog("No Config/database in config file: ".$this->icingaweb2_ressources,ERROR,''); 
333
+			$this->trapLog("No Config/database in config file: ".$this->icingaweb2_ressources, ERROR, ''); 
334 334
 		}
335 335
 		$db_type=$db_config[$db_name]['db'];
336 336
 		$db_host=$db_config[$db_name]['host'];
337 337
 		$db_sql_name=$db_config[$db_name]['dbname'];
338 338
 		$db_user=$db_config[$db_name]['username'];
339 339
 		$db_pass=$db_config[$db_name]['password'];
340
-		if ($database == 'traps') $this->trapDBType = $db_type;
341
-		if ($database == 'ido') $this->idoDBType = $db_type;
340
+		if ($database == 'traps') $this->trapDBType=$db_type;
341
+		if ($database == 'ido') $this->idoDBType=$db_type;
342 342
 		
343
-		$this->trapLog( "DB selected : $db_type $db_host $db_sql_name $db_user",3,''); 
344
-		return array($db_type,$db_host,$db_sql_name,$db_user,$db_pass);
343
+		$this->trapLog("DB selected : $db_type $db_host $db_sql_name $db_user", 3, ''); 
344
+		return array($db_type, $db_host, $db_sql_name, $db_user, $db_pass);
345 345
 	}	
346 346
 	
347 347
 	/** read data from stream
@@ -353,10 +353,10 @@  discard block
 block discarded – undo
353 353
 		//Read data from snmptrapd from stdin
354 354
 		$input_stream=fopen($stream, 'r');
355 355
 
356
-		if ($input_stream==FALSE)
356
+		if ($input_stream == FALSE)
357 357
 		{
358 358
 		    $this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)");
359
-			$this->trapLog("Error reading stdin !",ERROR,''); 
359
+			$this->trapLog("Error reading stdin !", ERROR, ''); 
360 360
 		}
361 361
 
362 362
 		// line 1 : host
@@ -364,21 +364,21 @@  discard block
 block discarded – undo
364 364
 		if ($this->receivingHost == FALSE)
365 365
 		{
366 366
 		    $this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)");
367
-			$this->trapLog("Error reading Host !",ERROR,''); 
367
+			$this->trapLog("Error reading Host !", ERROR, ''); 
368 368
 		}
369 369
 		// line 2 IP:port=>IP:port
370 370
 		$IP=chop(fgets($input_stream));
371 371
 		if ($IP == FALSE)
372 372
 		{
373 373
 		    $this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)");
374
-			$this->trapLog("Error reading IP !",ERROR,''); 
374
+			$this->trapLog("Error reading IP !", ERROR, ''); 
375 375
 		}
376 376
 		$matches=array();
377
-		$ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/',$IP,$matches);
378
-		if ($ret_code==0 || $ret_code==FALSE) 
377
+		$ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/', $IP, $matches);
378
+		if ($ret_code == 0 || $ret_code == FALSE) 
379 379
 		{
380 380
 		    $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
381
-			$this->trapLog('Error parsing IP : '.$IP,ERROR,'');
381
+			$this->trapLog('Error parsing IP : '.$IP, ERROR, '');
382 382
 		} 
383 383
 		else 
384 384
 		{		
@@ -388,33 +388,33 @@  discard block
 block discarded – undo
388 388
 			$this->trap_data['destination_port']=$matches[4];
389 389
 		}
390 390
 
391
-		while (($vars=chop(fgets($input_stream))) !=FALSE)
391
+		while (($vars=chop(fgets($input_stream))) != FALSE)
392 392
 		{
393
-			$ret_code=preg_match('/^([^ ]+) (.*)$/',$vars,$matches);
394
-			if ($ret_code==0 || $ret_code==FALSE) 
393
+			$ret_code=preg_match('/^([^ ]+) (.*)$/', $vars, $matches);
394
+			if ($ret_code == 0 || $ret_code == FALSE) 
395 395
 			{
396
-				$this->trapLog('No match on trap data : '.$vars,WARN,'');
396
+				$this->trapLog('No match on trap data : '.$vars, WARN, '');
397 397
 			}
398 398
 			else 
399 399
 			{
400
-			    if (($matches[1]=='.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1]=='.1.3.6.1.6.3.1.1.4.1'))
400
+			    if (($matches[1] == '.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1] == '.1.3.6.1.6.3.1.1.4.1'))
401 401
 				{
402 402
 					$this->trap_data['trap_oid']=$matches[2];				
403 403
 				}
404 404
 				else
405 405
 				{
406
-					$object= new stdClass;
407
-					$object->oid =$matches[1];
408
-					$object->value = $matches[2];
409
-					array_push($this->trap_data_ext,$object);
406
+					$object=new stdClass;
407
+					$object->oid=$matches[1];
408
+					$object->value=$matches[2];
409
+					array_push($this->trap_data_ext, $object);
410 410
 				}
411 411
 			}
412 412
 		}
413 413
 
414
-		if ($this->trap_data['trap_oid']=='unknown') 
414
+		if ($this->trap_data['trap_oid'] == 'unknown') 
415 415
 		{
416
-		    $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trap_data['source_ip']);
417
-			$this->trapLog('no trap oid found',ERROR,'');
416
+		    $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)", $this->trap_data['source_ip']);
417
+			$this->trapLog('no trap oid found', ERROR, '');
418 418
 		} 
419 419
 
420 420
 		// Translate oids.
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
 		}
437 437
 		
438 438
 
439
-		$this->trap_data['status']= 'waiting';
439
+		$this->trap_data['status']='waiting';
440 440
 		
441 441
 		return $this->trap_data;
442 442
 	}
@@ -451,40 +451,40 @@  discard block
 block discarded – undo
451 451
 		$db_conn=$this->db_connect_trap();
452 452
 		
453 453
 		$sql='SELECT mib,name from '.$this->db_prefix.'mib_cache WHERE oid=\''.$oid.'\';';
454
-		$this->trapLog('SQL query : '.$sql,4,'');
454
+		$this->trapLog('SQL query : '.$sql, 4, '');
455 455
 		if (($ret_code=$db_conn->query($sql)) == FALSE) {
456
-			$this->trapLog('No result in query : ' . $sql,ERROR,'');
456
+			$this->trapLog('No result in query : '.$sql, ERROR, '');
457 457
 		}
458 458
 		$name=$ret_code->fetch();
459 459
 		if ($name['name'] != null)
460 460
 		{
461
-			return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
461
+			return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
462 462
 		}
463 463
 		
464 464
 		// Also check if it is an instance of OID
465
-		$oid_instance=preg_replace('/\.[0-9]+$/','',$oid);
465
+		$oid_instance=preg_replace('/\.[0-9]+$/', '', $oid);
466 466
 		
467 467
 		$sql='SELECT mib,name from '.$this->db_prefix.'mib_cache WHERE oid=\''.$oid_instance.'\';';
468
-		$this->trapLog('SQL query : '.$sql,4,'');
468
+		$this->trapLog('SQL query : '.$sql, 4, '');
469 469
 		if (($ret_code=$db_conn->query($sql)) == FALSE) {
470
-			$this->trapLog('No result in query : ' . $sql,ERROR,'');
470
+			$this->trapLog('No result in query : '.$sql, ERROR, '');
471 471
 		}
472 472
 		$name=$ret_code->fetch();
473 473
 		if ($name['name'] != null)
474 474
 		{
475
-			return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
475
+			return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
476 476
 		}
477 477
 		
478 478
 		// Try to get oid name from snmptranslate
479
-		$translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
479
+		$translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
480 480
 		    ' '.$oid);
481 481
 		$matches=array();
482
-		$ret_code=preg_match('/(.*)::(.*)/',$translate,$matches);
483
-		if ($ret_code==0 || $ret_code==FALSE) {
482
+		$ret_code=preg_match('/(.*)::(.*)/', $translate, $matches);
483
+		if ($ret_code == 0 || $ret_code == FALSE) {
484 484
 			return NULL;
485 485
 		} else {
486
-			$this->trapLog('Found name with snmptrapd and not in DB for oid='.$oid,INFO,'');
487
-			return array('trap_name_mib'=>$matches[1],'trap_name'=>$matches[2]);
486
+			$this->trapLog('Found name with snmptrapd and not in DB for oid='.$oid, INFO, '');
487
+			return array('trap_name_mib'=>$matches[1], 'trap_name'=>$matches[2]);
488 488
 		}	
489 489
 	}
490 490
 	
@@ -494,26 +494,26 @@  discard block
 block discarded – undo
494 494
 	**/
495 495
 	public function eraseOldTraps($days=0)
496 496
 	{
497
-		if ($days==0)
497
+		if ($days == 0)
498 498
 		{
499 499
 			if (($days=$this->getDBConfig('db_remove_days')) == null)
500 500
 			{
501
-				$this->trapLog('No days specified & no db value : no tap erase' ,WARN,'');
501
+				$this->trapLog('No days specified & no db value : no tap erase', WARN, '');
502 502
 				return;
503 503
 			}
504 504
 		}
505 505
 		$db_conn=$this->db_connect_trap();
506
-		$daysago = strtotime("-".$days." day");
507
-		$sql= 'delete from '.$this->db_prefix.'received where date_received < \''.date("Y-m-d H:i:s",$daysago).'\';';
506
+		$daysago=strtotime("-".$days." day");
507
+		$sql='delete from '.$this->db_prefix.'received where date_received < \''.date("Y-m-d H:i:s", $daysago).'\';';
508 508
 		if ($db_conn->query($sql) == FALSE) {
509
-			$this->trapLog('Error erasing traps : '.$sql,ERROR,'');
509
+			$this->trapLog('Error erasing traps : '.$sql, ERROR, '');
510 510
 		}
511
-		$this->trapLog('Erased traps older than '.$days.' day(s) : '.$sql,3);
511
+		$this->trapLog('Erased traps older than '.$days.' day(s) : '.$sql, 3);
512 512
 	}
513 513
 
514 514
 	/** Write error to received trap database
515 515
 	 */
516
-	public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null)
516
+	public function writeTrapErrorToDB($message, $sourceIP=null, $trapoid=null)
517 517
 	{
518 518
 	    
519 519
 	    $db_conn=$this->db_connect_trap();
@@ -521,65 +521,65 @@  discard block
 block discarded – undo
521 521
 	    $insert_col='';
522 522
 	    $insert_val='';
523 523
 	    // add date time
524
-	    $insert_col ='date_received,status';
525
-	    $insert_val = "'" . date("Y-m-d H:i:s")."','error'";
524
+	    $insert_col='date_received,status';
525
+	    $insert_val="'".date("Y-m-d H:i:s")."','error'";
526 526
         
527
-	    if ($sourceIP !=null)
527
+	    if ($sourceIP != null)
528 528
 	    {
529
-	        $insert_col .=',source_ip';
530
-	        $insert_val .=",'". $sourceIP ."'";
529
+	        $insert_col.=',source_ip';
530
+	        $insert_val.=",'".$sourceIP."'";
531 531
 	    }
532
-	    if ($trapoid !=null)
532
+	    if ($trapoid != null)
533 533
 	    {
534
-	        $insert_col .=',trap_oid';
535
-	        $insert_val .=",'". $trapoid ."'";
534
+	        $insert_col.=',trap_oid';
535
+	        $insert_val.=",'".$trapoid."'";
536 536
 	    }
537
-	    $insert_col .=',status_detail';
538
-	    $insert_val .=",'". $message ."'";
537
+	    $insert_col.=',status_detail';
538
+	    $insert_val.=",'".$message."'";
539 539
 	    
540
-	    $sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
540
+	    $sql='INSERT INTO '.$this->db_prefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
541 541
 	    
542 542
 	    switch ($this->trapDBType)
543 543
 	    {
544 544
 	        case 'pgsql':
545
-	            $sql .= ' RETURNING id;';
546
-	            $this->trapLog('sql : '.$sql,3,'');
545
+	            $sql.=' RETURNING id;';
546
+	            $this->trapLog('sql : '.$sql, 3, '');
547 547
 	            if (($ret_code=$db_conn->query($sql)) == FALSE) {
548
-	                $this->trapLog('Error SQL insert : '.$sql,1,'');
548
+	                $this->trapLog('Error SQL insert : '.$sql, 1, '');
549 549
 	            }
550
-	            $this->trapLog('SQL insertion OK',3,'');
550
+	            $this->trapLog('SQL insertion OK', 3, '');
551 551
 	            // Get last id to insert oid/values in secondary table
552 552
 	            if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) == FALSE) {
553 553
 	                
554
-	                $this->trapLog('Erreur recuperation id',1,'');
554
+	                $this->trapLog('Erreur recuperation id', 1, '');
555 555
 	            }
556
-	            if (! isset($inserted_id_ret['id'])) {
557
-	                $this->trapLog('Error getting id',1,'');
556
+	            if (!isset($inserted_id_ret['id'])) {
557
+	                $this->trapLog('Error getting id', 1, '');
558 558
 	            }
559 559
 	            $this->trap_id=$inserted_id_ret['id'];
560 560
 	            break;
561 561
 	        case 'mysql':
562
-	            $sql .= ';';
563
-	            $this->trapLog('sql : '.$sql,3,'');
562
+	            $sql.=';';
563
+	            $this->trapLog('sql : '.$sql, 3, '');
564 564
 	            if (($ret_code=$db_conn->query($sql)) == FALSE) {
565
-	                $this->trapLog('Error SQL insert : '.$sql,1,'');
565
+	                $this->trapLog('Error SQL insert : '.$sql, 1, '');
566 566
 	            }
567
-	            $this->trapLog('SQL insertion OK',3,'');
567
+	            $this->trapLog('SQL insertion OK', 3, '');
568 568
 	            // Get last id to insert oid/values in secondary table
569 569
 	            $sql='SELECT LAST_INSERT_ID();';
570 570
 	            if (($ret_code=$db_conn->query($sql)) == FALSE) {
571
-	                $this->trapLog('Erreur recuperation id',1,'');
571
+	                $this->trapLog('Erreur recuperation id', 1, '');
572 572
 	            }
573 573
 	            
574 574
 	            $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
575
-	            if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
575
+	            if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
576 576
 	            $this->trap_id=$inserted_id;
577 577
 	            break;
578 578
 	        default:
579
-	            $this->trapLog('Error SQL type  : '.$this->trapDBType,1,'');
579
+	            $this->trapLog('Error SQL type  : '.$this->trapDBType, 1, '');
580 580
 	    }
581 581
 	    
582
-	    $this->trapLog('id found: '. $this->trap_id,3,'');    
582
+	    $this->trapLog('id found: '.$this->trap_id, 3, '');    
583 583
 	}
584 584
 	
585 585
 	/** Write trap data to trap database
@@ -596,86 +596,86 @@  discard block
 block discarded – undo
596 596
 		$insert_col='';
597 597
 		$insert_val='';
598 598
 		// add date time
599
-		$this->trap_data['date_received'] = date("Y-m-d H:i:s");
599
+		$this->trap_data['date_received']=date("Y-m-d H:i:s");
600 600
 
601 601
 		$firstcol=1;
602 602
 		foreach ($this->trap_data as $col => $val)
603 603
 		{
604
-			if ($firstcol==0) 
604
+			if ($firstcol == 0) 
605 605
 			{
606
-				$insert_col .=',';
607
-				$insert_val .=',';
606
+				$insert_col.=',';
607
+				$insert_val.=',';
608 608
 			}
609
-			$insert_col .= $col ;
610
-			$insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
609
+			$insert_col.=$col;
610
+			$insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
611 611
 			$firstcol=0;
612 612
 		}
613 613
 		
614
-		$sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
614
+		$sql='INSERT INTO '.$this->db_prefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
615 615
 		switch ($this->trapDBType)
616 616
 		{
617 617
 			case 'pgsql': 
618
-				$sql .= ' RETURNING id;';
619
-				$this->trapLog('sql : '.$sql,3,'');
618
+				$sql.=' RETURNING id;';
619
+				$this->trapLog('sql : '.$sql, 3, '');
620 620
 				if (($ret_code=$db_conn->query($sql)) == FALSE) {
621
-					$this->trapLog('Error SQL insert : '.$sql,ERROR,'');
621
+					$this->trapLog('Error SQL insert : '.$sql, ERROR, '');
622 622
 				}
623
-				$this->trapLog('SQL insertion OK',3,'');
623
+				$this->trapLog('SQL insertion OK', 3, '');
624 624
 				// Get last id to insert oid/values in secondary table
625 625
 				if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) == FALSE) {
626 626
 														   
627
-					$this->trapLog('Erreur recuperation id',ERROR,'');
627
+					$this->trapLog('Erreur recuperation id', ERROR, '');
628 628
 				}
629
-				if (! isset($inserted_id_ret['id'])) {
630
-					$this->trapLog('Error getting id',ERROR,'');
629
+				if (!isset($inserted_id_ret['id'])) {
630
+					$this->trapLog('Error getting id', ERROR, '');
631 631
 				}
632 632
 				$this->trap_id=$inserted_id_ret['id'];
633 633
 			break;
634 634
 			case 'mysql': 
635
-				$sql .= ';';
636
-				$this->trapLog('sql : '.$sql,3,'');
635
+				$sql.=';';
636
+				$this->trapLog('sql : '.$sql, 3, '');
637 637
 				if (($ret_code=$db_conn->query($sql)) == FALSE) {
638
-					$this->trapLog('Error SQL insert : '.$sql,ERROR,'');
638
+					$this->trapLog('Error SQL insert : '.$sql, ERROR, '');
639 639
 				}
640
-				$this->trapLog('SQL insertion OK',3,'');
640
+				$this->trapLog('SQL insertion OK', 3, '');
641 641
 				// Get last id to insert oid/values in secondary table
642 642
 				$sql='SELECT LAST_INSERT_ID();';
643 643
 				if (($ret_code=$db_conn->query($sql)) == FALSE) {
644
-					$this->trapLog('Erreur recuperation id',ERROR,'');
644
+					$this->trapLog('Erreur recuperation id', ERROR, '');
645 645
 				}
646 646
 
647 647
 				$inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
648
-				if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
648
+				if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
649 649
 				$this->trap_id=$inserted_id;
650 650
 			break;
651 651
 			default: 
652
-				$this->trapLog('Error SQL type  : '.$this->trapDBType,ERROR,'');
652
+				$this->trapLog('Error SQL type  : '.$this->trapDBType, ERROR, '');
653 653
 		}
654
-		$this->trapLog('id found: '.$this->trap_id,3,'');
654
+		$this->trapLog('id found: '.$this->trap_id, 3, '');
655 655
 		
656 656
 		// Fill trap extended data table
657 657
 		foreach ($this->trap_data_ext as $value) {			
658 658
 			// TODO : detect if trap value is encoded and decode it to UTF-8 for database
659 659
 			$firstcol=1;
660
-			$value->trap_id = $this->trap_id;
660
+			$value->trap_id=$this->trap_id;
661 661
 			$insert_col='';
662 662
 			$insert_val='';
663 663
 			foreach ($value as $col => $val)
664 664
 			{
665
-				if ($firstcol==0) 
665
+				if ($firstcol == 0) 
666 666
 				{
667
-					$insert_col .=',';
668
-					$insert_val .=',';
667
+					$insert_col.=',';
668
+					$insert_val.=',';
669 669
 				}
670
-				$insert_col .= $col;
671
-				$insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
670
+				$insert_col.=$col;
671
+				$insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
672 672
 				$firstcol=0;
673 673
 			}
674 674
 
675
-			$sql= 'INSERT INTO '.$this->db_prefix.'received_data (' . $insert_col . ') VALUES ('.$insert_val.');';			
675
+			$sql='INSERT INTO '.$this->db_prefix.'received_data ('.$insert_col.') VALUES ('.$insert_val.');';			
676 676
 
677 677
 			if (($ret_code=$db_conn->query($sql)) == FALSE) {
678
-				$this->trapLog('Erreur insertion data : ' . $sql,WARN,'');
678
+				$this->trapLog('Erreur insertion data : '.$sql, WARN, '');
679 679
 			}	
680 680
 		}	
681 681
 	}
@@ -685,14 +685,14 @@  discard block
 block discarded – undo
685 685
 	*	@param $oid string oid in numeric
686 686
 	*	@return PDO object or false
687 687
 	*/	
688
-	protected function getRules($ip,$oid)
688
+	protected function getRules($ip, $oid)
689 689
 	{
690 690
 		$db_conn=$this->db_connect_trap();
691 691
 		// fetch rules based on IP in rule and OID
692 692
 		$sql='SELECT * from '.$this->db_prefix.'rules WHERE trap_oid=\''.$oid.'\' ';
693
-		$this->trapLog('SQL query : '.$sql,4,'');
693
+		$this->trapLog('SQL query : '.$sql, 4, '');
694 694
 		if (($ret_code=$db_conn->query($sql)) == FALSE) {
695
-			$this->trapLog('No result in query : ' . $sql,WARN,'');
695
+			$this->trapLog('No result in query : '.$sql, WARN, '');
696 696
 			return false;
697 697
 		}
698 698
 		$rules_all=$ret_code->fetchAll();
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
 		$rule_ret_key=0;
702 702
 		foreach ($rules_all as $key => $rule)
703 703
 		{
704
-			if ($rule['ip4']==$ip || $rule['ip6']==$ip)
704
+			if ($rule['ip4'] == $ip || $rule['ip6'] == $ip)
705 705
 			{
706 706
 				$rules_ret[$rule_ret_key]=$rules_all[$key];
707 707
 				//TODO : get host name by API (and check if correct in rule).
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
 				continue;
710 710
 			}
711 711
 			// TODO : get hosts IP by API
712
-			if (isset($rule['host_group_name']) && $rule['host_group_name']!=null)
712
+			if (isset($rule['host_group_name']) && $rule['host_group_name'] != null)
713 713
 			{ // get ips of group members by oid
714 714
 				$db_conn2=$this->db_connect_ido();
715 715
 				$sql="SELECT m.host_object_id, a.address as ip4, a.address6 as ip6, b.name1 as host_name
@@ -720,15 +720,15 @@  discard block
 block discarded – undo
720 720
 						LEFT JOIN icinga_objects as b ON b.object_id = a.host_object_id
721 721
 						WHERE o.name1='".$rule['host_group_name']."';";
722 722
 				if (($ret_code2=$db_conn2->query($sql)) == FALSE) {
723
-					$this->trapLog('No result in query : ' . $sql,WARN,'');
723
+					$this->trapLog('No result in query : '.$sql, WARN, '');
724 724
 					continue;
725 725
 				}
726 726
 				$grouphosts=$ret_code2->fetchAll();
727 727
 				//echo "rule grp :\n";print_r($grouphosts);echo "\n";
728
-				foreach ( $grouphosts as $host)
728
+				foreach ($grouphosts as $host)
729 729
 				{
730 730
 					//echo $host['ip4']."\n";
731
-					if ($host['ip4']==$ip || $host['ip6']==$ip)
731
+					if ($host['ip4'] == $ip || $host['ip6'] == $ip)
732 732
 					{
733 733
 						//echo "Rule added \n";
734 734
 						$rules_ret[$rule_ret_key]=$rules_all[$key];
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
 		$db_conn=$this->db_connect_trap();
751 751
 		$sql="UPDATE ".$this->db_prefix."rules SET num_match = '".$set."' WHERE (id = '".$id."');";
752 752
 		if ($db_conn->query($sql) == FALSE) {
753
-			$this->trapLog('Error in update query : ' . $sql,WARN,'');
753
+			$this->trapLog('Error in update query : '.$sql, WARN, '');
754 754
 		}
755 755
 	}
756 756
 	
@@ -762,31 +762,31 @@  discard block
 block discarded – undo
762 762
 	 * @param string $display
763 763
 	 * @returnn bool true is service check was sent without error
764 764
 	*/
765
-	public function serviceCheckResult($host,$service,$state,$display)
765
+	public function serviceCheckResult($host, $service, $state, $display)
766 766
 	{
767 767
 	    if ($this->api_use == false)
768 768
 	    {
769
-    		$send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' .
770
-    			$host.';' .$service .';' . $state . ';'.$display;
771
-    		$this->trapLog( $send." : to : " .$this->icinga2cmd,3,'');
769
+    		$send='['.date('U').'] PROCESS_SERVICE_CHECK_RESULT;'.
770
+    			$host.';'.$service.';'.$state.';'.$display;
771
+    		$this->trapLog($send." : to : ".$this->icinga2cmd, 3, '');
772 772
     		
773 773
     		// TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
774
-    		exec('echo "'.$send.'" > ' .$this->icinga2cmd);
774
+    		exec('echo "'.$send.'" > '.$this->icinga2cmd);
775 775
     		return true;
776 776
 	    }
777 777
 	    else
778 778
 	    {
779
-	        $api = $this->getAPI();
779
+	        $api=$this->getAPI();
780 780
 	        $api->setCredentials($this->api_username, $this->api_password);
781
-	        list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display);
781
+	        list($retcode, $retmessage)=$api->serviceCheckResult($host, $service, $state, $display);
782 782
 	        if ($retcode == false)
783 783
 	        {
784
-	            $this->trapLog( "Error sending result : " .$retmessage,WARN,'');
784
+	            $this->trapLog("Error sending result : ".$retmessage, WARN, '');
785 785
 	            return false;
786 786
 	        }
787 787
 	        else 
788 788
 	        {
789
-	            $this->trapLog( "Sent result : " .$retmessage,3,'');
789
+	            $this->trapLog("Sent result : ".$retmessage, 3, '');
790 790
 	            return true;
791 791
 	        }
792 792
 	    }
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
 	
795 795
 	public function getHostByIP($ip)
796 796
 	{
797
-	    $api = $this->getAPI();
797
+	    $api=$this->getAPI();
798 798
 	    $api->setCredentials($this->api_username, $this->api_password);
799 799
 	    return $api->getHostByIP($ip);
800 800
 	}
@@ -807,32 +807,32 @@  discard block
 block discarded – undo
807 807
 	protected function applyDisplay($display)
808 808
 	{
809 809
 	    $matches=array();
810
-	    while (preg_match('/_OID\(([0-9\.]+)\)/',$display,$matches) == 1)
810
+	    while (preg_match('/_OID\(([0-9\.]+)\)/', $display, $matches) == 1)
811 811
 		{
812 812
 			$oid=$matches[1];
813 813
 			$found=0;
814
-			foreach($this->trap_data_ext as $val)
814
+			foreach ($this->trap_data_ext as $val)
815 815
 			{
816 816
 				if ($oid == $val->oid)
817 817
 				{
818
-					$val->value=preg_replace('/"/','',$val->value);
818
+					$val->value=preg_replace('/"/', '', $val->value);
819 819
 					$rep=0;
820
-					$display=preg_replace('/_OID\('.$oid.'\)/',$val->value,$display,-1,$rep);
821
-					if ($rep==0)
820
+					$display=preg_replace('/_OID\('.$oid.'\)/', $val->value, $display, -1, $rep);
821
+					if ($rep == 0)
822 822
 					{
823
-						$this->trapLog("Error in display",WARN,'');
823
+						$this->trapLog("Error in display", WARN, '');
824 824
 						return $display;
825 825
 					}
826 826
 					$found=1;
827 827
 					break;
828 828
 				}
829 829
 			}
830
-			if ($found==0)
830
+			if ($found == 0)
831 831
 			{
832
-				$display=preg_replace('/_OID\('.$oid.'\)/','<not in trap>',$display,-1,$rep);
833
-				if ($rep==0)
832
+				$display=preg_replace('/_OID\('.$oid.'\)/', '<not in trap>', $display, -1, $rep);
833
+				if ($rep == 0)
834 834
 				{
835
-					$this->trapLog("Error in display",WARN,'');
835
+					$this->trapLog("Error in display", WARN, '');
836 836
 					return $display;
837 837
 				}				
838 838
 			}
@@ -842,27 +842,27 @@  discard block
 block discarded – undo
842 842
 
843 843
 	
844 844
 	/***************** Eval & tokenizer functions ****************/
845
-	protected function eval_getElement($rule,&$item)
845
+	protected function eval_getElement($rule, &$item)
846 846
 	{
847
-		while ($rule[$item]==' ') $item++;
848
-		if (preg_match('/[0-9\.]/',$rule[$item]))
847
+		while ($rule[$item] == ' ') $item++;
848
+		if (preg_match('/[0-9\.]/', $rule[$item]))
849 849
 		{ // number
850 850
 	
851
-			$item2=$item+1; 
852
-			while (($item2!=strlen($rule)) && (preg_match('/[0-9\.]/',$rule[$item2]))) { $item2++ ;}
853
-			$val=substr($rule,$item,$item2-$item);
851
+			$item2=$item + 1; 
852
+			while (($item2 != strlen($rule)) && (preg_match('/[0-9\.]/', $rule[$item2]))) { $item2++; }
853
+			$val=substr($rule, $item, $item2 - $item);
854 854
 			$item=$item2;
855 855
 			//echo "number ".$val."\n";
856
-			return array(0,$val);
856
+			return array(0, $val);
857 857
 		}
858 858
 		if ($rule[$item] == '"')
859 859
 		{ // string
860 860
 			$item++;
861
-			$item2=$this->eval_getNext($rule,$item,'"');
862
-			$val=substr($rule,$item,$item2-$item-1);
861
+			$item2=$this->eval_getNext($rule, $item, '"');
862
+			$val=substr($rule, $item, $item2 - $item - 1);
863 863
 			$item=$item2;
864 864
 			//echo "string : ".$val."\n";
865
-			return array(1,$val);
865
+			return array(1, $val);
866 866
 		}
867 867
 		
868 868
 		if ($rule[$item] == '(')
@@ -871,14 +871,14 @@  discard block
 block discarded – undo
871 871
 			$start=$item;
872 872
 			$parenthesis_count=0; 
873 873
 			while (($item < strlen($rule)) // Not end of string AND
874
-			      && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded ()
874
+			      && (($rule[$item] != ')') || $parenthesis_count > 0)) // Closing ')' or embeded ()
875 875
 			{ 
876
-				if ($rule[$item] == '"' )
876
+				if ($rule[$item] == '"')
877 877
 				{ // pass through string
878 878
 					$item++;
879
-					$item=$this->eval_getNext($rule,$item,'"');
879
+					$item=$this->eval_getNext($rule, $item, '"');
880 880
 				} 
881
-				else{
881
+				else {
882 882
 				    if ($rule[$item] == '(')
883 883
 				    {
884 884
 				        $parenthesis_count++;
@@ -891,49 +891,49 @@  discard block
 block discarded – undo
891 891
 				}
892 892
 			}
893 893
 			
894
-			if ($item==strlen($rule)) {throw new Exception("no closing () in ".$rule ." at " .$item);}
895
-			$val=substr($rule,$start,$item-$start);
894
+			if ($item == strlen($rule)) {throw new Exception("no closing () in ".$rule." at ".$item); }
895
+			$val=substr($rule, $start, $item - $start);
896 896
 			$item++;
897 897
 			$start=0;
898 898
 			//echo "group : ".$val."\n";
899 899
 			// returns evaluation of group as type 2 (boolean)
900
-			return array(2,$this->evaluation($val,$start));		
900
+			return array(2, $this->evaluation($val, $start));		
901 901
 		}
902
-		throw new Exception("number/string not found in ".$rule ." at " .$item . ' : ' .$rule[$item]);
902
+		throw new Exception("number/string not found in ".$rule." at ".$item.' : '.$rule[$item]);
903 903
 		
904 904
 	}
905 905
 	
906
-	protected function eval_getNext($rule,$item,$tok)
906
+	protected function eval_getNext($rule, $item, $tok)
907 907
 	{
908
-		while (($rule[$item] != $tok ) && ($item < strlen($rule))) { $item++;}
909
-		if ($item==strlen($rule)) throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item);
910
-		return $item+1;
908
+		while (($rule[$item] != $tok) && ($item < strlen($rule))) { $item++; }
909
+		if ($item == strlen($rule)) throw new Exception("closing '".$tok."' not found in ".$rule." at ".$item);
910
+		return $item + 1;
911 911
 	}
912 912
 	
913
-	protected function eval_getOper($rule,&$item)
913
+	protected function eval_getOper($rule, &$item)
914 914
 	{
915
-		while ($rule[$item]==' ') $item++;
915
+		while ($rule[$item] == ' ') $item++;
916 916
 		switch ($rule[$item])
917 917
 		{
918 918
 			case '<':
919
-				if ($rule[$item+1]=='=') { $item+=2; return array(0,"<=");}
920
-				$item++; return array(0,"<");
919
+				if ($rule[$item + 1] == '=') { $item+=2; return array(0, "<="); }
920
+				$item++; return array(0, "<");
921 921
 			case '>':
922
-				if ($rule[$item+1]=='=') { $item+=2; return array(0,">=");}
923
-				$item++; return array(0,">");
922
+				if ($rule[$item + 1] == '=') { $item+=2; return array(0, ">="); }
923
+				$item++; return array(0, ">");
924 924
 			case '=':
925
-				$item++; return array(0,"=");	
925
+				$item++; return array(0, "=");	
926 926
 			case '!':
927
-				if ($rule[$item+1]=='=') { $item+=2; return array(0,"!=");}
928
-				throw new Exception("Erreur in expr - incorrect operator '!'  found in ".$rule ." at " .$item);
927
+				if ($rule[$item + 1] == '=') { $item+=2; return array(0, "!="); }
928
+				throw new Exception("Erreur in expr - incorrect operator '!'  found in ".$rule." at ".$item);
929 929
 			case '~':
930
-				$item++; return array(0,"~");	
930
+				$item++; return array(0, "~");	
931 931
 			case '|':
932
-				$item++; return array(1,"|");	
932
+				$item++; return array(1, "|");	
933 933
 			case '&':
934
-				$item++; return array(1,"&");
934
+				$item++; return array(1, "&");
935 935
 			default	:
936
-				throw new Exception("Erreur in expr - operator not found in ".$rule ." at " .$item);
936
+				throw new Exception("Erreur in expr - operator not found in ".$rule." at ".$item);
937 937
 		}
938 938
 	}
939 939
 	
@@ -945,10 +945,10 @@  discard block
 block discarded – undo
945 945
 	*   comparison int vs strings will return null (error)
946 946
 	*	return : bool or null on error
947 947
 	*/
948
-	public function evaluation($rule,&$item)
948
+	public function evaluation($rule, &$item)
949 949
 	{
950 950
 	    //echo "Evaluation of ".substr($rule,$item)."\n";
951
-		if ( $rule[$item] == '!') // If '!' found, negate next expression.
951
+		if ($rule[$item] == '!') // If '!' found, negate next expression.
952 952
 		{
953 953
 		    $negate=true;
954 954
 		    $item++;
@@ -958,63 +958,63 @@  discard block
 block discarded – undo
958 958
 		    $negate=false;
959 959
 		}
960 960
 		// First element : number, string or ()
961
-		list($type1,$val1) = $this->eval_getElement($rule,$item);
961
+		list($type1, $val1)=$this->eval_getElement($rule, $item);
962 962
 		//echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n";
963 963
 		
964
-		if ($item==strlen($rule)) // If only element, return value, but only boolean
964
+		if ($item == strlen($rule)) // If only element, return value, but only boolean
965 965
 		{
966 966
 		  if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule);
967
-		  if ($negate == true) $val1= ! $val1;
967
+		  if ($negate == true) $val1=!$val1;
968 968
 		  return $val1;
969 969
 		}  
970 970
 		
971 971
 		// Second element : operator
972
-		list($typec,$comp) = $this->eval_getOper($rule,$item);
972
+		list($typec, $comp)=$this->eval_getOper($rule, $item);
973 973
 		//echo "Comp : ".$comp." : ".substr($rule,$item)."\n";
974 974
         
975 975
 		// Third element : number, string or ()
976
-		if ( $rule[$item] == '!') // starts with a ! so evaluate whats next
976
+		if ($rule[$item] == '!') // starts with a ! so evaluate whats next
977 977
 		{
978 978
 		    $item++;
979 979
 		    if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule);
980
-		    $val2= ! $this->evaluation($rule,$item);
980
+		    $val2=!$this->evaluation($rule, $item);
981 981
 		    $type2=2; // result is a boolean 
982 982
 		}
983 983
 		else 
984 984
 		{
985
-		    list($type2,$val2) = $this->eval_getElement($rule,$item);
985
+		    list($type2, $val2)=$this->eval_getElement($rule, $item);
986 986
 		}
987 987
 		//echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n";
988 988
 		
989
-		if ($type1!=$type2)  // cannot compare different types
989
+		if ($type1 != $type2)  // cannot compare different types
990 990
 		{ 
991 991
 		    throw new Exception("Cannot compare string & number : ".$rule);
992 992
 		}
993
-		if ($typec==1 && $type1 !=2) // cannot use & or | with string/number
993
+		if ($typec == 1 && $type1 != 2) // cannot use & or | with string/number
994 994
 		{
995 995
 		    throw new Exception("Cannot use boolean operators with string & number : ".$rule);
996 996
 		}
997 997
 		
998
-		switch ($comp){
999
-			case '<':	$retVal= ($val1 < $val2); break;
1000
-			case '<=':	$retVal= ($val1 <= $val2); break;
1001
-			case '>':	$retVal= ($val1 > $val2); break;
1002
-			case '>=':	$retVal= ($val1 >= $val2); break;
1003
-			case '=':	$retVal= ($val1 == $val2); break;
1004
-			case '!=':	$retVal= ($val1 != $val2); break;
1005
-			case '~':	$retVal= (preg_match('/'.preg_replace('/"/','',$val2).'/',$val1)); break;
1006
-			case '|':	$retVal= ($val1 || $val2); break;
1007
-			case '&':	$retVal= ($val1 && $val2); break;
998
+		switch ($comp) {
999
+			case '<':	$retVal=($val1 < $val2); break;
1000
+			case '<=':	$retVal=($val1 <= $val2); break;
1001
+			case '>':	$retVal=($val1 > $val2); break;
1002
+			case '>=':	$retVal=($val1 >= $val2); break;
1003
+			case '=':	$retVal=($val1 == $val2); break;
1004
+			case '!=':	$retVal=($val1 != $val2); break;
1005
+			case '~':	$retVal=(preg_match('/'.preg_replace('/"/', '', $val2).'/', $val1)); break;
1006
+			case '|':	$retVal=($val1 || $val2); break;
1007
+			case '&':	$retVal=($val1 && $val2); break;
1008 1008
 			default:  throw new Exception("Error in expression - unknown comp : ".$comp);
1009 1009
 		}
1010
-		if ($negate == true) $retVal = ! $retVal; // Inverse result if negate before expression
1010
+		if ($negate == true) $retVal=!$retVal; // Inverse result if negate before expression
1011 1011
 		
1012
-		if ($item==strlen($rule)) return $retVal; // End of string : return evaluation
1012
+		if ($item == strlen($rule)) return $retVal; // End of string : return evaluation
1013 1013
 		// check for logical operator :
1014 1014
 		switch ($rule[$item])
1015 1015
 		{
1016
-			case '|':	$item++; return ($retVal || $this->evaluation($rule,$item) ); break;
1017
-			case '&':	$item++; return ($retVal && $this->evaluation($rule,$item) ); break;
1016
+			case '|':	$item++; return ($retVal || $this->evaluation($rule, $item)); break;
1017
+			case '&':	$item++; return ($retVal && $this->evaluation($rule, $item)); break;
1018 1018
 			
1019 1019
 			default:  throw new Exception("Erreur in expr - garbadge at end of expression : ".$rule[$item]);
1020 1020
 		}
@@ -1026,17 +1026,17 @@  discard block
 block discarded – undo
1026 1026
 		$rule2='';
1027 1027
 		while ($item < strlen($rule))
1028 1028
 		{
1029
-			if ($rule[$item]==' ') { $item++; continue; }
1030
-			if ($rule[$item]=='"')
1029
+			if ($rule[$item] == ' ') { $item++; continue; }
1030
+			if ($rule[$item] == '"')
1031 1031
 			{
1032 1032
 				$rule2.=$rule[$item];
1033 1033
 				$item++;
1034
-				while (($rule[$item]!='"') && ($item < strlen($rule)))
1034
+				while (($rule[$item] != '"') && ($item < strlen($rule)))
1035 1035
 				{
1036 1036
 					$rule2.=$rule[$item];
1037 1037
 					$item++;
1038 1038
 				}
1039
-				if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item);
1039
+				if ($item == strlen($rule)) throw new Exception("closing '\"' not found in ".$rule." at ".$item);
1040 1040
 				$rule2.=$rule[$item];
1041 1041
 				$item++;
1042 1042
 				continue;
@@ -1056,12 +1056,12 @@  discard block
 block discarded – undo
1056 1056
 	
1057 1057
 	protected function eval_rule($rule)
1058 1058
 	{
1059
-		if ($rule==null || $rule == '') // Empty rule is always true
1059
+		if ($rule == null || $rule == '') // Empty rule is always true
1060 1060
 		{
1061 1061
 			return true;
1062 1062
 		}
1063 1063
 		$matches=array();
1064
-		while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1)
1064
+		while (preg_match('/_OID\(([0-9\.\*]+)\)/', $rule, $matches) == 1)
1065 1065
 		{
1066 1066
 			$oid=$matches[1];
1067 1067
 			$found=0;
@@ -1073,49 +1073,49 @@  discard block
 block discarded – undo
1073 1073
 			// replace * with \* in oid for preg_replace
1074 1074
 			$oid=preg_replace('/\*/', '\*', $oid);
1075 1075
 			
1076
-			$this->trapLog('OID in rule : '.$oid.' / '.$oidR,4,'');
1076
+			$this->trapLog('OID in rule : '.$oid.' / '.$oidR, 4, '');
1077 1077
 			
1078
-			foreach($this->trap_data_ext as $val)
1078
+			foreach ($this->trap_data_ext as $val)
1079 1079
 			{
1080
-				if (preg_match("/^$oidR$/",$val->oid) == 1)
1080
+				if (preg_match("/^$oidR$/", $val->oid) == 1)
1081 1081
 				{
1082
-					if (!preg_match('/^[0-9]*\.?[0-9]+$/',$val->value))
1082
+					if (!preg_match('/^[0-9]*\.?[0-9]+$/', $val->value))
1083 1083
 					{ // If not a number, change " to ' and put " around it
1084
-						$val->value=preg_replace('/"/',"'",$val->value);
1084
+						$val->value=preg_replace('/"/', "'", $val->value);
1085 1085
 						$val->value='"'.$val->value.'"';
1086 1086
 					}
1087 1087
 					$rep=0;
1088
-					$rule=preg_replace('/_OID\('.$oid.'\)/',$val->value,$rule,-1,$rep);
1089
-					if ($rep==0)
1088
+					$rule=preg_replace('/_OID\('.$oid.'\)/', $val->value, $rule, -1, $rep);
1089
+					if ($rep == 0)
1090 1090
 					{
1091
-						$this->trapLog("Error in rule_eval",WARN,'');
1091
+						$this->trapLog("Error in rule_eval", WARN, '');
1092 1092
 						return false;
1093 1093
 					}
1094 1094
 					$found=1;
1095 1095
 					break;
1096 1096
 				}
1097 1097
 			}
1098
-			if ($found==0)
1098
+			if ($found == 0)
1099 1099
 			{	// OID not found : throw error
1100 1100
 			    throw new Exception('OID '.$oid.' not found in trap');
1101 1101
 			}
1102 1102
 		}
1103 1103
 		$item=0;
1104 1104
 		$rule=$this->eval_cleanup($rule);
1105
-		$this->trapLog('Rule after clenup: '.$rule,3,'');
1105
+		$this->trapLog('Rule after clenup: '.$rule, 3, '');
1106 1106
 		
1107
-		return  $this->evaluation($rule,$item);
1107
+		return  $this->evaluation($rule, $item);
1108 1108
 	}
1109 1109
 	
1110 1110
 	/** Match rules for current trap and do action
1111 1111
 	*/
1112 1112
 	public function applyRules()
1113 1113
 	{
1114
-		$rules = $this->getRules($this->trap_data['source_ip'],$this->trap_data['trap_oid']);
1114
+		$rules=$this->getRules($this->trap_data['source_ip'], $this->trap_data['trap_oid']);
1115 1115
 		
1116
-		if ($rules==FALSE || count($rules)==0)
1116
+		if ($rules == FALSE || count($rules) == 0)
1117 1117
 		{
1118
-			$this->trapLog('No rules found for this trap',3,'');
1118
+			$this->trapLog('No rules found for this trap', 3, '');
1119 1119
 			$this->trap_data['status']='unknown';
1120 1120
 			$this->trap_to_db=true;
1121 1121
 			return;
@@ -1130,58 +1130,58 @@  discard block
 block discarded – undo
1130 1130
 			$service_name=$rule['service_name'];
1131 1131
 			
1132 1132
 			$display=$this->applyDisplay($rule['display']);
1133
-			$this->trap_action = ($this->trap_action==null)? '' : $this->trap_action . ', ';
1133
+			$this->trap_action=($this->trap_action == null) ? '' : $this->trap_action.', ';
1134 1134
 			try
1135 1135
 			{
1136
-				$this->trapLog('Rule to eval : '.$rule['rule'],3,'');
1136
+				$this->trapLog('Rule to eval : '.$rule['rule'], 3, '');
1137 1137
 				$evalr=$this->eval_rule($rule['rule']);
1138 1138
 				
1139 1139
 				if ($evalr == true)
1140 1140
 				{
1141 1141
 					//$this->trapLog('rules OOK: '.print_r($rule),3,'');
1142 1142
 					$action=$rule['action_match'];
1143
-					$this->trapLog('action OK : '.$action,3,'');
1143
+					$this->trapLog('action OK : '.$action, 3, '');
1144 1144
 					if ($action >= 0)
1145 1145
 					{
1146
-						if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
1146
+						if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
1147 1147
 						{
1148 1148
 						    $this->trap_action.='Error sending status : check cmd/API';
1149 1149
 						}
1150 1150
 						else
1151 1151
 						{
1152
-						    $this->add_rule_match($rule['id'],$rule['num_match']+1);
1152
+						    $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
1153 1153
 						    $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1154 1154
 						}
1155 1155
 					}
1156 1156
 					else
1157 1157
 					{
1158
-						$this->add_rule_match($rule['id'],$rule['num_match']+1);
1158
+						$this->add_rule_match($rule['id'], $rule['num_match'] + 1);
1159 1159
 					}
1160
-					$this->trap_to_db=($action==-2)?false:true;
1160
+					$this->trap_to_db=($action == -2) ?false:true;
1161 1161
 				}
1162 1162
 				else
1163 1163
 				{
1164 1164
 					//$this->trapLog('rules KOO : '.print_r($rule),3,'');
1165 1165
 					
1166 1166
 					$action=$rule['action_nomatch'];
1167
-					$this->trapLog('action NOK : '.$action,3,'');
1167
+					$this->trapLog('action NOK : '.$action, 3, '');
1168 1168
 					if ($action >= 0)
1169 1169
 					{
1170
-					    if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
1170
+					    if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
1171 1171
 					    {
1172 1172
 					        $this->trap_action.='Error sending status : check cmd/API';
1173 1173
 					    }
1174 1174
 					    else
1175 1175
 					    {
1176
-    						$this->add_rule_match($rule['id'],$rule['num_match']+1);
1176
+    						$this->add_rule_match($rule['id'], $rule['num_match'] + 1);
1177 1177
     						$this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1178 1178
 					    }
1179 1179
 					}
1180 1180
 					else
1181 1181
 					{
1182
-						$this->add_rule_match($rule['id'],$rule['num_match']+1);
1182
+						$this->add_rule_match($rule['id'], $rule['num_match'] + 1);
1183 1183
 					}
1184
-					$this->trap_to_db=($action==-2)?false:true;					
1184
+					$this->trap_to_db=($action == -2) ?false:true;					
1185 1185
 				}
1186 1186
 				// Put name in source_name
1187 1187
 				if (!isset($this->trap_data['source_name']))
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
 				}
1191 1191
 				else
1192 1192
 				{
1193
-					if (!preg_match('/'.$rule['host_name'].'/',$this->trap_data['source_name']))
1193
+					if (!preg_match('/'.$rule['host_name'].'/', $this->trap_data['source_name']))
1194 1194
 					{ // only add if not present
1195 1195
 						$this->trap_data['source_name'].=','.$rule['host_name'];
1196 1196
 					}
@@ -1198,13 +1198,13 @@  discard block
 block discarded – undo
1198 1198
 			}
1199 1199
 			catch (Exception $e) 
1200 1200
 			{ 
1201
-			    $this->trapLog('Error in rule eval : '.$e->getMessage(),WARN,'');
1201
+			    $this->trapLog('Error in rule eval : '.$e->getMessage(), WARN, '');
1202 1202
 			    $this->trap_action.=' ERR : '.$e->getMessage();
1203 1203
 			    $this->trap_data['status']='error';
1204 1204
 			}
1205 1205
 			
1206 1206
 		}
1207
-		if ($this->trap_data['status']=='error')
1207
+		if ($this->trap_data['status'] == 'error')
1208 1208
 		{
1209 1209
 		  $this->trap_to_db=true; // Always put errors in DB for the use can see
1210 1210
 		}
@@ -1220,13 +1220,13 @@  discard block
 block discarded – undo
1220 1220
 	public function add_rule_final($time)
1221 1221
 	{
1222 1222
 		$db_conn=$this->db_connect_trap();
1223
-		if ($this->trap_action==null) 
1223
+		if ($this->trap_action == null) 
1224 1224
 		{
1225 1225
 			$this->trap_action='No action';
1226 1226
 		}
1227 1227
 		$sql="UPDATE ".$this->db_prefix."received SET process_time = '".$time."' , status_detail='".$this->trap_action."'  WHERE (id = '".$this->trap_id."');";
1228 1228
 		if ($db_conn->query($sql) == FALSE) {
1229
-			$this->trapLog('Error in update query : ' . $sql,WARN,'');
1229
+			$this->trapLog('Error in update query : '.$sql, WARN, '');
1230 1230
 		}
1231 1231
 	}
1232 1232
 	
@@ -1236,14 +1236,14 @@  discard block
 block discarded – undo
1236 1236
 	*	@param $schema_file	string File to read schema from
1237 1237
 	*	@param $table_prefix string to replace #PREFIX# in schema file by this
1238 1238
 	*/
1239
-	public function create_schema($schema_file,$table_prefix)
1239
+	public function create_schema($schema_file, $table_prefix)
1240 1240
 	{
1241 1241
 		//Read data from snmptrapd from stdin
1242 1242
 		$input_stream=fopen($schema_file, 'r');
1243 1243
 
1244
-		if ($input_stream==FALSE)
1244
+		if ($input_stream == FALSE)
1245 1245
 		{
1246
-			$this->trapLog("Error reading schema !",ERROR,''); 
1246
+			$this->trapLog("Error reading schema !", ERROR, ''); 
1247 1247
 		}
1248 1248
 		$newline='';
1249 1249
 		$cur_table='';
@@ -1252,14 +1252,14 @@  discard block
 block discarded – undo
1252 1252
 		
1253 1253
 		while (($line=fgets($input_stream)) != FALSE)
1254 1254
 		{
1255
-			$newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line));
1255
+			$newline.=chop(preg_replace('/#PREFIX#/', $table_prefix, $line));
1256 1256
 			if (preg_match('/; *$/', $newline)) 
1257 1257
             {
1258
-                $sql= $newline;
1258
+                $sql=$newline;
1259 1259
                 if ($db_conn->query($sql) == FALSE) {
1260
-                    $this->trapLog('Error create schema : '.$sql,ERROR,'');
1260
+                    $this->trapLog('Error create schema : '.$sql, ERROR, '');
1261 1261
                 }
1262
-                if (preg_match('/^ *CREATE TABLE ([^ ]+)/',$newline,$cur_table_array))
1262
+                if (preg_match('/^ *CREATE TABLE ([^ ]+)/', $newline, $cur_table_array))
1263 1263
                 {
1264 1264
                     $cur_table='table '.$cur_table_array[1];
1265 1265
                 }
@@ -1267,19 +1267,19 @@  discard block
 block discarded – undo
1267 1267
                 {
1268 1268
                     $cur_table='secret SQL stuff :-)';
1269 1269
                 }
1270
-                $this->trapLog('Creating : ' . $cur_table, 3,'');
1270
+                $this->trapLog('Creating : '.$cur_table, 3, '');
1271 1271
                 $newline='';
1272 1272
             }
1273 1273
 		}
1274 1274
 		
1275
-		$sql= $newline;
1275
+		$sql=$newline;
1276 1276
 		if ($sql != '')
1277 1277
 		{
1278 1278
     		if ($db_conn->query($sql) == FALSE) {
1279
-    			$this->trapLog('Error create schema : '.$sql,ERROR,'');
1279
+    			$this->trapLog('Error create schema : '.$sql, ERROR, '');
1280 1280
     		}
1281 1281
 		}
1282
-		$this->trapLog('Schema created',3);		
1282
+		$this->trapLog('Schema created', 3);		
1283 1283
 	}
1284 1284
 
1285 1285
 	/** 
@@ -1290,14 +1290,14 @@  discard block
 block discarded – undo
1290 1290
 	 *     @param bool $getmsg : only get messages from version upgrades
1291 1291
 	 *     @return string : if $getmsg=true, return messages.
1292 1292
 	 */
1293
-	public function update_schema($prefix,$target_version,$table_prefix,$getmsg=false)
1293
+	public function update_schema($prefix, $target_version, $table_prefix, $getmsg=false)
1294 1294
 	{
1295 1295
 	    // Get current db number
1296 1296
 	    $db_conn=$this->db_connect_trap();
1297 1297
 	    $sql='SELECT id,value from '.$this->db_prefix.'db_config WHERE name=\'db_version\' ';
1298
-	    $this->trapLog('SQL query : '.$sql,4,'');
1298
+	    $this->trapLog('SQL query : '.$sql, 4, '');
1299 1299
 	    if (($ret_code=$db_conn->query($sql)) == FALSE) {
1300
-	        $this->trapLog('Cannot get db version. Query : ' . $sql,2,'');
1300
+	        $this->trapLog('Cannot get db version. Query : '.$sql, 2, '');
1301 1301
 	        return;
1302 1302
 	    }
1303 1303
 	    $version=$ret_code->fetchAll();
@@ -1306,47 +1306,47 @@  discard block
 block discarded – undo
1306 1306
 	    
1307 1307
 	    if ($this->trapDBType == 'pgsql')
1308 1308
 	    {
1309
-	        $prefix .= 'update_pgsql/schema_';
1309
+	        $prefix.='update_pgsql/schema_';
1310 1310
 	    }
1311 1311
 	    else
1312 1312
 	    {
1313
-	        $prefix .= 'update_sql/schema_';
1313
+	        $prefix.='update_sql/schema_';
1314 1314
 	    }
1315 1315
 	    //echo "version all :\n";print_r($version);echo " \n $cur_ver \n";
1316 1316
 	    if ($getmsg == true)
1317 1317
 	    {
1318 1318
 	        $message='';
1319
-	        $this->trapLog('getting message for upgrade',4,'');
1320
-	        while($cur_version<$target_version)
1319
+	        $this->trapLog('getting message for upgrade', 4, '');
1320
+	        while ($cur_version < $target_version)
1321 1321
 	        {
1322 1322
 	            $cur_version++;
1323
-	            $updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql';
1323
+	            $updateFile=$prefix.'v'.($cur_version - 1).'_v'.$cur_version.'.sql';
1324 1324
 	            $input_stream=fopen($updateFile, 'r');
1325
-	            if ($input_stream==FALSE)
1325
+	            if ($input_stream == FALSE)
1326 1326
 	            {
1327
-	                $this->trapLog("Error reading update file ". $updateFile,2,'');
1327
+	                $this->trapLog("Error reading update file ".$updateFile, 2, '');
1328 1328
 	                return;
1329 1329
 	            }
1330 1330
 	            do { $line=fgets($input_stream); }
1331
-	            while ($line != false && !preg_match('/#MESSAGE/',$line));
1332
-	            if ($line ==false)
1331
+	            while ($line != false && !preg_match('/#MESSAGE/', $line));
1332
+	            if ($line == false)
1333 1333
 	            {
1334
-	                $this->trapLog("No message in file ". $updateFile,2,'');
1334
+	                $this->trapLog("No message in file ".$updateFile, 2, '');
1335 1335
 	                return;
1336 1336
 	            }
1337
-	            $message .= ($cur_version-1) . '->' . $cur_version. ' : ' . preg_replace('/#MESSAGE : /','',$line)."\n";
1337
+	            $message.=($cur_version - 1).'->'.$cur_version.' : '.preg_replace('/#MESSAGE : /', '', $line)."\n";
1338 1338
 	        }
1339 1339
 	        return $message;
1340 1340
 	    }
1341
-	    while($cur_version<$target_version)
1341
+	    while ($cur_version < $target_version)
1342 1342
 	    { // tODO : execute pre & post scripts
1343 1343
 	       $cur_version++;
1344
-	       $this->trapLog('Updating to version : ' .$cur_version ,3,'');
1345
-	       $updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql';
1344
+	       $this->trapLog('Updating to version : '.$cur_version, 3, '');
1345
+	       $updateFile=$prefix.'v'.($cur_version - 1).'_v'.$cur_version.'.sql';
1346 1346
 	       $input_stream=fopen($updateFile, 'r');
1347
-	       if ($input_stream==FALSE)
1347
+	       if ($input_stream == FALSE)
1348 1348
 	       {
1349
-	           $this->trapLog("Error reading update file ". $updateFile,2,'');
1349
+	           $this->trapLog("Error reading update file ".$updateFile, 2, '');
1350 1350
 	           return;
1351 1351
 	       }
1352 1352
 	       $newline='';
@@ -1355,24 +1355,24 @@  discard block
 block discarded – undo
1355 1355
 	       while (($line=fgets($input_stream)) != FALSE)
1356 1356
 	       {
1357 1357
 	           if (preg_match('/^#/', $line)) continue; // ignore comment lines
1358
-	           $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line));
1358
+	           $newline.=chop(preg_replace('/#PREFIX#/', $table_prefix, $line));
1359 1359
 	           if (preg_match('/; *$/', $newline))
1360 1360
 	           {
1361 1361
 	               $sql_req=$db_conn->prepare($newline);
1362 1362
 	               if ($sql_req->execute() == FALSE) {
1363
-	                   $this->trapLog('Error create schema : '.$newline,1,'');
1363
+	                   $this->trapLog('Error create schema : '.$newline, 1, '');
1364 1364
 	               }
1365 1365
 	               $cur_table_array=array();
1366
-	               if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/',$newline,$cur_table_array))
1366
+	               if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/', $newline, $cur_table_array))
1367 1367
 	               {
1368
-	                   $cur_table=$cur_table_array[1] . ' SQL table '.$cur_table_array[2];
1368
+	                   $cur_table=$cur_table_array[1].' SQL table '.$cur_table_array[2];
1369 1369
 	               }
1370 1370
 	               else
1371 1371
 	               {
1372 1372
 	                   $cur_table='secret SQL stuff :-)';
1373 1373
 	                   $cur_table=$newline;
1374 1374
 	               }
1375
-	               $this->trapLog('Doing : ' . $cur_table, 3,'');
1375
+	               $this->trapLog('Doing : '.$cur_table, 3, '');
1376 1376
 	               
1377 1377
 	               $newline='';
1378 1378
 	           }
@@ -1385,13 +1385,13 @@  discard block
 block discarded – undo
1385 1385
 	       //}
1386 1386
 	       
1387 1387
 	       $sql='UPDATE '.$this->db_prefix.'db_config SET value='.$cur_version.' WHERE ( id = '.$db_version_id.' )';
1388
-	       $this->trapLog('SQL query : '.$sql,4,'');
1388
+	       $this->trapLog('SQL query : '.$sql, 4, '');
1389 1389
 	       if (($ret_code=$db_conn->query($sql)) == FALSE) {
1390
-	           $this->trapLog('Cannot update db version. Query : ' . $sql,2,'');
1390
+	           $this->trapLog('Cannot update db version. Query : '.$sql, 2, '');
1391 1391
 	           return;
1392 1392
 	       }
1393 1393
 	       
1394
-	       $this->trapLog('Schema updated to version : '.$cur_version ,3);
1394
+	       $this->trapLog('Schema updated to version : '.$cur_version, 3);
1395 1395
 	    }
1396 1396
 	}
1397 1397
 	
@@ -1412,7 +1412,7 @@  discard block
 block discarded – undo
1412 1412
     WHERE s.current_state != 0;";
1413 1413
 		$db_conn=$this->db_connect_ido();
1414 1414
 		if (($services_db=$db_conn->query($sql_query)) == FALSE) { // set err to 1 to throw exception.
1415
-			$this->trapLog('No result in query : ' . $sql_query,ERROR,'');
1415
+			$this->trapLog('No result in query : '.$sql_query, ERROR, '');
1416 1416
 		}
1417 1417
 		$services=$services_db->fetchAll();
1418 1418
 		
@@ -1420,7 +1420,7 @@  discard block
 block discarded – undo
1420 1420
 		$sql_query="SELECT host_name, service_name, revert_ok FROM ".$this->db_prefix."rules where revert_ok != 0;";
1421 1421
 		$db_conn2=$this->db_connect_trap();
1422 1422
 		if (($rules_db=$db_conn2->query($sql_query)) == FALSE) {
1423
-			$this->trapLog('No result in query : ' . $sql_query,ERROR,''); 
1423
+			$this->trapLog('No result in query : '.$sql_query, ERROR, ''); 
1424 1424
 		}
1425 1425
 		$rules=$rules_db->fetchAll();
1426 1426
 		
@@ -1435,13 +1435,13 @@  discard block
 block discarded – undo
1435 1435
 					$service['host_name'] == $rule['host_name'] &&
1436 1436
 					($service['last_check'] + $rule['revert_ok']) < $now)
1437 1437
 				{
1438
-					$this->serviceCheckResult($service['host_name'],$service['service_name'],0,'Reset service to OK after '.$rule['revert_ok'].' seconds');
1438
+					$this->serviceCheckResult($service['host_name'], $service['service_name'], 0, 'Reset service to OK after '.$rule['revert_ok'].' seconds');
1439 1439
 					$numreset++;
1440 1440
 				}
1441 1441
 			}
1442 1442
 		}
1443 1443
 		echo "\n";
1444
-		echo $numreset . " service(s) reset to OK\n";
1444
+		echo $numreset." service(s) reset to OK\n";
1445 1445
 		return 0;
1446 1446
 		
1447 1447
 	}
@@ -1462,7 +1462,7 @@  discard block
 block discarded – undo
1462 1462
 	 * @param string $description
1463 1463
 	 * @return number : 0=unchanged, 1 = changed, 2=created
1464 1464
 	 */
1465
-	public function update_oid($oid,$mib,$name,$type,$textConv,$dispHint,$syntax,$type_enum,$description=NULL)
1465
+	public function update_oid($oid, $mib, $name, $type, $textConv, $dispHint, $syntax, $type_enum, $description=NULL)
1466 1466
 	{
1467 1467
 		$db_conn=$this->db_connect_trap();
1468 1468
 		$description=$db_conn->quote($description);
@@ -1472,7 +1472,7 @@  discard block
 block discarded – undo
1472 1472
 		    { // newly created.
1473 1473
 		        return 0;
1474 1474
 		    }
1475
-			if ( $name != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['name'] ||
1475
+			if ($name != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['name'] ||
1476 1476
 			    $mib != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['mib'] ||
1477 1477
 			    $type != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type'] //||
1478 1478
 			    //$textConv != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['textual_convention'] //||
@@ -1492,23 +1492,23 @@  discard block
 block discarded – undo
1492 1492
 			        ':name' => $name,
1493 1493
 			        ':type' => $type, 
1494 1494
 			        ':mib' => $mib, 
1495
-			        ':tc' =>  ($textConv==null)?'null':$textConv , 
1496
-			        ':display_hint' => ($dispHint==null)?'null':$dispHint ,
1497
-			        ':syntax' => ($syntax==null)?'null':$syntax,
1498
-			        ':type_enum' => ($type_enum==null)?'null':$type_enum, 
1499
-			        ':description' => ($description==null)?'null':$description,
1495
+			        ':tc' =>  ($textConv == null) ? 'null' : $textConv, 
1496
+			        ':display_hint' => ($dispHint == null) ? 'null' : $dispHint,
1497
+			        ':syntax' => ($syntax == null) ? 'null' : $syntax,
1498
+			        ':type_enum' => ($type_enum == null) ? 'null' : $type_enum, 
1499
+			        ':description' => ($description == null) ? 'null' : $description,
1500 1500
 			        ':id' => $this->dbOidAll[$this->dbOidIndex[$oid]['id']]
1501 1501
 			    );
1502 1502
 			    
1503 1503
 			    if ($sqlQuery->execute($sqlParam) == FALSE) {
1504
-			        $this->trapLog('Error in query : ' . $sql,ERROR,'');
1504
+			        $this->trapLog('Error in query : '.$sql, ERROR, '');
1505 1505
 			    }
1506
-			    $this->trapLog('Trap updated : '.$name . ' / OID : '.$oid,4,'');
1506
+			    $this->trapLog('Trap updated : '.$name.' / OID : '.$oid, 4, '');
1507 1507
 				return 1;
1508 1508
 			}
1509 1509
 			else
1510 1510
 			{
1511
-			    $this->trapLog('Trap unchanged : '.$name . ' / OID : '.$oid,4,'');
1511
+			    $this->trapLog('Trap unchanged : '.$name.' / OID : '.$oid, 4, '');
1512 1512
 			    return 0;
1513 1513
 			}
1514 1514
 		}
@@ -1518,11 +1518,11 @@  discard block
 block discarded – undo
1518 1518
 
1519 1519
 		$sql='INSERT INTO '.$this->db_prefix.'mib_cache '.
1520 1520
 		      '(oid, name, type , mib, textual_convention, display_hint '.
1521
-              ', syntax, type_enum , description ) ' . 
1521
+              ', syntax, type_enum , description ) '. 
1522 1522
               'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
1523 1523
               ', :syntax, :type_enum, :description )';
1524 1524
         
1525
-		if ($this->trapDBType == 'pgsql') $sql .= 'RETURNING id';
1525
+		if ($this->trapDBType == 'pgsql') $sql.='RETURNING id';
1526 1526
 		
1527 1527
 		$sqlQuery=$db_conn->prepare($sql);
1528 1528
 		
@@ -1531,15 +1531,15 @@  discard block
 block discarded – undo
1531 1531
 		    ':name' => $name,
1532 1532
 		    ':type' => $type,
1533 1533
 		    ':mib' => $mib,
1534
-		    ':tc' =>  ($textConv==null)?'null':$textConv ,
1535
-		    ':display_hint' => ($dispHint==null)?'null':$dispHint ,
1536
-		    ':syntax' => ($syntax==null)?'null':$syntax,
1537
-		    ':type_enum' => ($type_enum==null)?'null':$type_enum,
1538
-		    ':description' => ($description==null)?'null':$description
1534
+		    ':tc' =>  ($textConv == null) ? 'null' : $textConv,
1535
+		    ':display_hint' => ($dispHint == null) ? 'null' : $dispHint,
1536
+		    ':syntax' => ($syntax == null) ? 'null' : $syntax,
1537
+		    ':type_enum' => ($type_enum == null) ? 'null' : $type_enum,
1538
+		    ':description' => ($description == null) ? 'null' : $description
1539 1539
 		);
1540 1540
 		
1541 1541
 		if ($sqlQuery->execute($sqlParam) == FALSE) {
1542
-		    $this->trapLog('Error in query : ' . $sql,1,'');
1542
+		    $this->trapLog('Error in query : '.$sql, 1, '');
1543 1543
 		}
1544 1544
 		
1545 1545
 		switch ($this->trapDBType)
@@ -1547,10 +1547,10 @@  discard block
 block discarded – undo
1547 1547
 		    case 'pgsql':
1548 1548
 		        // Get last id to insert oid/values in secondary table
1549 1549
 		        if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) == FALSE) {		            
1550
-		            $this->trapLog('Error getting id - pgsql - ',1,'');
1550
+		            $this->trapLog('Error getting id - pgsql - ', 1, '');
1551 1551
 		        }
1552
-		        if (! isset($inserted_id_ret['id'])) {
1553
-		            $this->trapLog('Error getting id - pgsql - empty.',1,'');
1552
+		        if (!isset($inserted_id_ret['id'])) {
1553
+		            $this->trapLog('Error getting id - pgsql - empty.', 1, '');
1554 1554
 		        }
1555 1555
 		        $this->dbOidIndex[$oid]['id']=$inserted_id_ret['id'];
1556 1556
 		        break;
@@ -1558,15 +1558,15 @@  discard block
 block discarded – undo
1558 1558
 		        // Get last id to insert oid/values in secondary table
1559 1559
 		        $sql='SELECT LAST_INSERT_ID();';
1560 1560
 		        if (($ret_code=$db_conn->query($sql)) == FALSE) {
1561
-		            $this->trapLog('Erreur getting id - mysql - ',1,'');
1561
+		            $this->trapLog('Erreur getting id - mysql - ', 1, '');
1562 1562
 		        }
1563 1563
 		        
1564 1564
 		        $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
1565
-		        if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
1565
+		        if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
1566 1566
 		        $this->dbOidIndex[$oid]['id']=$inserted_id;
1567 1567
 		        break;
1568 1568
 		    default:
1569
-		        $this->trapLog('Error SQL type  : '.$this->trapDBType,1,'');
1569
+		        $this->trapLog('Error SQL type  : '.$this->trapDBType, 1, '');
1570 1570
 		}
1571 1571
 
1572 1572
 		// Set as newly created.
@@ -1581,21 +1581,21 @@  discard block
 block discarded – undo
1581 1581
      * @param array $objects : array of objects name (without MIB)
1582 1582
      * @param bool $check_existing : check instead of create
1583 1583
      */
1584
-	public function trap_objects($trapOID,$trapmib,$objects,$check_existing)
1584
+	public function trap_objects($trapOID, $trapmib, $objects, $check_existing)
1585 1585
 	{
1586 1586
 	    $dbObjects=null; // cache of objects for trap in db
1587 1587
 	    $db_conn=$this->db_connect_trap();
1588 1588
 	    
1589 1589
 	    // Get id of trapmib.
1590 1590
 
1591
-	    $trapId = $this->dbOidIndex[$trapOID]['id'];
1591
+	    $trapId=$this->dbOidIndex[$trapOID]['id'];
1592 1592
 	    if ($check_existing == true)
1593 1593
 	    {
1594 1594
 	        // Get all objects
1595 1595
 	        $sql='SELECT * FROM '.$this->db_prefix.'mib_cache_trap_object where trap_id='.$trapId.';';
1596
-	        $this->trapLog('SQL query get all traps: '.$sql,4,'');
1596
+	        $this->trapLog('SQL query get all traps: '.$sql, 4, '');
1597 1597
 	        if (($ret_code=$db_conn->query($sql)) == FALSE) {
1598
-	            $this->trapLog('No result in query : ' . $sql,1,'');
1598
+	            $this->trapLog('No result in query : '.$sql, 1, '');
1599 1599
 	        }
1600 1600
 	        $dbObjectsRaw=$ret_code->fetchAll();
1601 1601
 	        
@@ -1609,39 +1609,39 @@  discard block
 block discarded – undo
1609 1609
 	        $match=$snmptrans=array();
1610 1610
 	        $retVal=0;
1611 1611
 	        $objOid=$objTc=$objDispHint=$objSyntax=$objDesc=$objEnum=NULL;
1612
-	        $tmpdesc='';$indesc=false;
1612
+	        $tmpdesc=''; $indesc=false;
1613 1613
 	        
1614 1614
 	        $objMib=$trapmib;
1615
-	        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1616
-	            ' -On -Td '.$objMib.'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
1617
-	        if ($retVal!=0)
1615
+	        exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
1616
+	            ' -On -Td '.$objMib.'::'.$object.' 2>/dev/null', $snmptrans, $retVal);
1617
+	        if ($retVal != 0)
1618 1618
 	        {
1619 1619
 	            // Maybe not trap mib, search with IR
1620
-	            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1621
-	                ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
1622
-	            if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
1620
+	            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
1621
+	                ' -IR '.$object.' 2>/dev/null', $snmptrans, $retVal);
1622
+	            if ($retVal != 0 || !preg_match('/(.*)::(.*)/', $snmptrans[0], $match))
1623 1623
 	            { // Not found -> continue with warning
1624
-	               $this->trapLog('Error finding trap object : '.$trapmib.'::'.$object,2,'');
1624
+	               $this->trapLog('Error finding trap object : '.$trapmib.'::'.$object, 2, '');
1625 1625
 	               continue;
1626 1626
 	            }
1627 1627
 	            $objMib=$match[1];
1628 1628
 	            
1629 1629
 	            // Do the snmptranslate again.
1630
-	            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1631
-	                ' -On -Td '.$objMib.'::'.$object,$snmptrans,$retVal);
1632
-	            if ($retVal!=0) {
1633
-	                $this->trapLog('Error finding trap object : '.$objMib.'::'.$object,2,'');
1630
+	            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
1631
+	                ' -On -Td '.$objMib.'::'.$object, $snmptrans, $retVal);
1632
+	            if ($retVal != 0) {
1633
+	                $this->trapLog('Error finding trap object : '.$objMib.'::'.$object, 2, '');
1634 1634
 	            }
1635 1635
 	            
1636 1636
 	        }
1637 1637
 	        foreach ($snmptrans as $line)
1638 1638
 	        {
1639
-	            if ($indesc==true)
1639
+	            if ($indesc == true)
1640 1640
 	            {
1641
-	                $line=preg_replace('/[\t ]+/',' ',$line);
1642
-	                if (preg_match('/(.*)"$/', $line,$match))
1641
+	                $line=preg_replace('/[\t ]+/', ' ', $line);
1642
+	                if (preg_match('/(.*)"$/', $line, $match))
1643 1643
 	                {
1644
-	                    $objDesc = $tmpdesc . $match[1];
1644
+	                    $objDesc=$tmpdesc.$match[1];
1645 1645
 	                    $indesc=false;
1646 1646
 	                }
1647 1647
 	                $tmpdesc.=$line;
@@ -1652,43 +1652,43 @@  discard block
 block discarded – undo
1652 1652
 	                $objOid=$line;
1653 1653
 	                continue;
1654 1654
 	            }
1655
-	            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
1655
+	            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/', $line, $match))
1656 1656
 	            {
1657 1657
 	                $objSyntax=$match[1];
1658 1658
                     $objEnum=$match[2];
1659 1659
 	                continue;
1660 1660
 	            }
1661
-	            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
1661
+	            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/', $line, $match))
1662 1662
 	            {
1663 1663
 	                $objSyntax=$match[1];
1664 1664
 	                continue;
1665 1665
 	            }
1666
-	            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
1666
+	            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/', $line, $match))
1667 1667
 	            {
1668 1668
 	                $objDispHint=$match[1];
1669 1669
 	                continue;
1670 1670
 	            }
1671
-	            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
1671
+	            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/', $line, $match))
1672 1672
 	            {
1673 1673
 	                $objDesc=$match[1];
1674 1674
 	                continue;
1675 1675
 	            }
1676
-	            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
1676
+	            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $line, $match))
1677 1677
 	            {
1678 1678
 	                $tmpdesc=$match[1];
1679 1679
 	                $indesc=true;
1680 1680
 	                continue;
1681 1681
 	            }
1682
-	            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
1682
+	            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/', $line, $match))
1683 1683
 	            {
1684 1684
 	                $objTc=$match[1];
1685 1685
 	                continue;
1686 1686
 	            }
1687 1687
 	        }
1688
-	        $this->trapLog("Adding trap $object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc",4,'');
1688
+	        $this->trapLog("Adding trap $object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc", 4, '');
1689 1689
 	        //echo "$object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc / $objDesc\n";
1690 1690
 	        // Update 
1691
-	        $this->update_oid($objOid, $objMib, $object, '3', $objTc, $objDispHint, $objSyntax, $objEnum,$objDesc);
1691
+	        $this->update_oid($objOid, $objMib, $object, '3', $objTc, $objDispHint, $objSyntax, $objEnum, $objDesc);
1692 1692
             
1693 1693
 	        if (isset($dbObjects[$this->dbOidIndex[$objOid]['id']]))
1694 1694
 	        {   // if link exists, continue
@@ -1709,7 +1709,7 @@  discard block
 block discarded – undo
1709 1709
 	        );
1710 1710
 	        
1711 1711
 	        if ($sqlQuery->execute($sqlParam) == FALSE) {
1712
-	            $this->trapLog('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$objOid]['id'] ,1,'');
1712
+	            $this->trapLog('Error adding trap object : '.$sql.' / '.$trapId.'/'.$this->dbOidIndex[$objOid]['id'], 1, '');
1713 1713
 	        }
1714 1714
 	    }
1715 1715
 	    if ($check_existing == true)
@@ -1726,19 +1726,19 @@  discard block
 block discarded – undo
1726 1726
 	 * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
1727 1727
 	 * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
1728 1728
 	*/	
1729
-	public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
1729
+	public function update_mib_database($display_progress=false, $check_change=false, $onlyTraps=true, $startOID='.1')
1730 1730
 	{
1731 1731
 		// Timing 
1732
-		$timeTaken = microtime(true);
1732
+		$timeTaken=microtime(true);
1733 1733
 		$retVal=0;
1734 1734
 		// Get all mib objects from all mibs
1735
-		$snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.' -On -Tto 2>/dev/null';
1736
-		$this->trapLog('Getting all traps : '.$snmpCommand,4,'');
1735
+		$snmpCommand=$this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.' -On -Tto 2>/dev/null';
1736
+		$this->trapLog('Getting all traps : '.$snmpCommand, 4, '');
1737 1737
 		unset($this->objectsAll);
1738
-		exec($snmpCommand,$this->objectsAll,$retVal);		
1739
-		if ($retVal!=0)
1738
+		exec($snmpCommand, $this->objectsAll, $retVal);		
1739
+		if ($retVal != 0)
1740 1740
 		{
1741
-			$this->trapLog('error executing snmptranslate',ERROR,'');
1741
+			$this->trapLog('error executing snmptranslate', ERROR, '');
1742 1742
 		}
1743 1743
 		
1744 1744
 		// Get all mibs from databse to have a memory index
@@ -1746,14 +1746,14 @@  discard block
 block discarded – undo
1746 1746
 		$db_conn=$this->db_connect_trap();
1747 1747
 		
1748 1748
 		$sql='SELECT * from '.$this->db_prefix.'mib_cache;';
1749
-		$this->trapLog('SQL query : '.$sql,4,'');
1749
+		$this->trapLog('SQL query : '.$sql, 4, '');
1750 1750
 		if (($ret_code=$db_conn->query($sql)) == FALSE) {
1751
-			$this->trapLog('No result in query : ' . $sql,ERROR,'');
1751
+			$this->trapLog('No result in query : '.$sql, ERROR, '');
1752 1752
 		}
1753 1753
 		$this->dbOidAll=$ret_code->fetchAll();
1754 1754
 		$this->dbOidIndex=array();
1755 1755
 		// Create the index for db;
1756
-		foreach($this->dbOidAll as $key=>$val)
1756
+		foreach ($this->dbOidAll as $key=>$val)
1757 1757
 		{
1758 1758
 			$this->dbOidIndex[$val['oid']]['key']=$key;
1759 1759
 			$this->dbOidIndex[$val['oid']]['id']=$val['id'];
@@ -1761,11 +1761,11 @@  discard block
 block discarded – undo
1761 1761
 		
1762 1762
 		// Count elements to show progress
1763 1763
 		$numElements=count($this->objectsAll);
1764
-		$this->trapLog('Total snmp objects returned by snmptranslate : '.$numElements,3,'');
1764
+		$this->trapLog('Total snmp objects returned by snmptranslate : '.$numElements, 3, '');
1765 1765
 		
1766
-		$step=$basestep=$numElements/10; // output display of % done
1766
+		$step=$basestep=$numElements / 10; // output display of % done
1767 1767
 		$num_step=0;
1768
-		$timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds
1768
+		$timeFiveSec=microtime(true); // Used for display a '.' every <n> seconds
1769 1769
 		
1770 1770
 		// Create index for trap objects
1771 1771
 		$this->trapObjectsIndex=array();
@@ -1775,28 +1775,28 @@  discard block
 block discarded – undo
1775 1775
 		$time_parse1N=$time_check1N=$time_check2N=$time_check3N=$time_updateN=$time_objectsN=0;
1776 1776
 		$time_num_traps=0;
1777 1777
 		
1778
-		for ($curElement=0;$curElement < $numElements;$curElement++)
1778
+		for ($curElement=0; $curElement < $numElements; $curElement++)
1779 1779
 		{
1780
-		    $time_1= microtime(true);
1781
-			if ((microtime(true)-$timeFiveSec) > 2 && $display_progress)
1780
+		    $time_1=microtime(true);
1781
+			if ((microtime(true) - $timeFiveSec) > 2 && $display_progress)
1782 1782
 			{ // echo a . every 2 sec
1783 1783
 				echo '.';
1784
-				$timeFiveSec = microtime(true);
1784
+				$timeFiveSec=microtime(true);
1785 1785
 			}
1786
-			if ($curElement>$step) 
1786
+			if ($curElement > $step) 
1787 1787
 			{ // display progress
1788 1788
 				$num_step++;
1789 1789
 				$step+=$basestep;
1790 1790
 				if ($display_progress)
1791 1791
 				{				
1792
-					echo "\n" . ($num_step*10). '% : ';
1792
+					echo "\n".($num_step * 10).'% : ';
1793 1793
 				}
1794 1794
 			}
1795 1795
 			// Get oid or pass if not found
1796
-			if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
1796
+			if (!preg_match('/^\.[0-9\.]+$/', $this->objectsAll[$curElement]))
1797 1797
 			{
1798
-			    $time_parse1 += microtime(true) - $time_1;
1799
-			    $time_parse1N ++;
1798
+			    $time_parse1+=microtime(true) - $time_1;
1799
+			    $time_parse1N++;
1800 1800
 				continue;
1801 1801
 			}
1802 1802
 			$oid=$this->objectsAll[$curElement];
@@ -1805,9 +1805,9 @@  discard block
 block discarded – undo
1805 1805
 			$curElement++;
1806 1806
 			$match=$snmptrans=array();
1807 1807
 			if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
1808
-						$this->objectsAll[$curElement],$match))
1808
+						$this->objectsAll[$curElement], $match))
1809 1809
 			{
1810
-			    $time_check1 += microtime(true) - $time_1;
1810
+			    $time_check1+=microtime(true) - $time_1;
1811 1811
 				$time_check1N++;
1812 1812
 				continue;
1813 1813
 			}
@@ -1815,21 +1815,21 @@  discard block
 block discarded – undo
1815 1815
 			$name=$match[1]; // Name 
1816 1816
 			$type=$match[2]; // type (21=trap, 0: may be trap, else : not trap
1817 1817
 			
1818
-			if ($type==0) // object type=0 : check if v1 trap
1818
+			if ($type == 0) // object type=0 : check if v1 trap
1819 1819
 			{
1820 1820
 				// Check if next is suboid -> in that case is cannot be a trap
1821
-				if (preg_match("/^$oid/",$this->objectsAll[$curElement+1]))
1821
+				if (preg_match("/^$oid/", $this->objectsAll[$curElement + 1]))
1822 1822
 				{
1823
-				    $time_check2 += microtime(true) - $time_1;
1823
+				    $time_check2+=microtime(true) - $time_1;
1824 1824
 				    $time_check2N++;
1825 1825
 					continue;
1826 1826
 				}		
1827 1827
 				unset($snmptrans);
1828
-				exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1829
-					' -Td '.$oid . ' | grep OBJECTS ',$snmptrans,$retVal);
1830
-				if ($retVal!=0)
1828
+				exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
1829
+					' -Td '.$oid.' | grep OBJECTS ', $snmptrans, $retVal);
1830
+				if ($retVal != 0)
1831 1831
 				{
1832
-				    $time_check2 += microtime(true) - $time_1;
1832
+				    $time_check2+=microtime(true) - $time_1;
1833 1833
 				    $time_check2N++;
1834 1834
 					continue;
1835 1835
 				}
@@ -1837,56 +1837,56 @@  discard block
 block discarded – undo
1837 1837
 				// Force as trap.
1838 1838
 				$type=21;
1839 1839
 			}
1840
-			if ($onlyTraps==true && $type!=21) // if only traps and not a trap, continue
1840
+			if ($onlyTraps == true && $type != 21) // if only traps and not a trap, continue
1841 1841
 			{
1842
-			    $time_check3 += microtime(true) - $time_1;
1842
+			    $time_check3+=microtime(true) - $time_1;
1843 1843
 				$time_check3N++;
1844 1844
 				continue;
1845 1845
 			}
1846 1846
 			
1847 1847
 			$time_num_traps++;
1848 1848
 			
1849
-			$this->trapLog('Found trap : '.$match[1] . ' / OID : '.$oid,3,'');
1849
+			$this->trapLog('Found trap : '.$match[1].' / OID : '.$oid, 3, '');
1850 1850
 			if ($display_progress) echo '#'; // echo a # when trap found
1851 1851
 				
1852 1852
 			// get trap objects & source MIB
1853 1853
 			unset($snmptrans);
1854
-			exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1855
-					' -Td '.$oid,$snmptrans,$retVal);
1856
-			if ($retVal!=0)
1854
+			exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
1855
+					' -Td '.$oid, $snmptrans, $retVal);
1856
+			if ($retVal != 0)
1857 1857
 			{
1858
-				$this->trapLog('error executing snmptranslate',ERROR,'');
1858
+				$this->trapLog('error executing snmptranslate', ERROR, '');
1859 1859
 			}
1860 1860
 			
1861
-			if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
1861
+			if (!preg_match('/^(.*)::/', $snmptrans[0], $match))
1862 1862
 			{
1863
-			    $this->trapLog('Error getting mib from trap '.$oid.' : ' . $snmptrans[0],1,'');
1863
+			    $this->trapLog('Error getting mib from trap '.$oid.' : '.$snmptrans[0], 1, '');
1864 1864
 			}
1865 1865
 			$trapMib=$match[1];
1866 1866
 			
1867
-			$numLine=1;$trapDesc='';
1868
-			while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
1867
+			$numLine=1; $trapDesc='';
1868
+			while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $snmptrans[$numLine], $match)) $numLine++;
1869 1869
 			if (isset($snmptrans[$numLine]))
1870 1870
 			{
1871
-			    $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
1871
+			    $snmptrans[$numLine]=preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/', '', $snmptrans[$numLine]);
1872 1872
 
1873
-			    while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
1873
+			    while (isset($snmptrans[$numLine]) && !preg_match('/"/', $snmptrans[$numLine]))
1874 1874
 			    {
1875
-			        $trapDesc.=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
1875
+			        $trapDesc.=preg_replace('/[\t ]+/', ' ', $snmptrans[$numLine]);
1876 1876
 			        $numLine++;
1877 1877
 			    }
1878 1878
 			    if (isset($snmptrans[$numLine])) {
1879
-			        $trapDesc.=preg_replace('/".*/','',$snmptrans[$numLine]);
1880
-			        $trapDesc=preg_replace('/[\t ]+/',' ',$trapDesc);
1879
+			        $trapDesc.=preg_replace('/".*/', '', $snmptrans[$numLine]);
1880
+			        $trapDesc=preg_replace('/[\t ]+/', ' ', $trapDesc);
1881 1881
 			    }
1882 1882
 
1883 1883
 			}
1884
-			$update=$this->update_oid($oid,$trapMib,$name,$type,NULL,NULL,NULL,NULL,$trapDesc);
1885
-			$time_update += microtime(true) - $time_1; $time_1= microtime(true);
1884
+			$update=$this->update_oid($oid, $trapMib, $name, $type, NULL, NULL, NULL, NULL, $trapDesc);
1885
+			$time_update+=microtime(true) - $time_1; $time_1=microtime(true);
1886 1886
 			
1887
-			if (($update==0) && ($check_change==false))
1887
+			if (($update == 0) && ($check_change == false))
1888 1888
 			{ // Trapd didn't change & force check disabled
1889
-			    $time_objects += microtime(true) - $time_1;
1889
+			    $time_objects+=microtime(true) - $time_1;
1890 1890
 			    if ($display_progress) echo "C";
1891 1891
 			    continue;
1892 1892
 			}
@@ -1894,7 +1894,7 @@  discard block
 block discarded – undo
1894 1894
 			$synt=null;
1895 1895
 			foreach ($snmptrans as $line)
1896 1896
 			{	
1897
-    			if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
1897
+    			if (preg_match('/OBJECTS.*\{([^\}]+)\}/', $line, $match))
1898 1898
     				{
1899 1899
     					$synt=$match[1];
1900 1900
     				}
@@ -1902,30 +1902,30 @@  discard block
 block discarded – undo
1902 1902
 			if ($synt == null) 
1903 1903
 			{
1904 1904
 				//echo "No objects for $trapOID\n";
1905
-			    $time_objects += microtime(true) - $time_1;
1905
+			    $time_objects+=microtime(true) - $time_1;
1906 1906
 				continue;
1907 1907
 			}
1908 1908
 			//echo "$synt \n";
1909 1909
 			$trapObjects=array();
1910
-			while (preg_match('/ *([^ ,]+) *,* */',$synt,$match))
1910
+			while (preg_match('/ *([^ ,]+) *,* */', $synt, $match))
1911 1911
 			{
1912
-				array_push($trapObjects,$match[1]);
1913
-				$synt=preg_replace('/'.$match[0].'/','',$synt);
1912
+				array_push($trapObjects, $match[1]);
1913
+				$synt=preg_replace('/'.$match[0].'/', '', $synt);
1914 1914
 			}
1915 1915
 			
1916 1916
 			$this->trap_objects($oid, $trapMib, $trapObjects, false);
1917 1917
 			
1918
-			$time_objects += microtime(true) - $time_1;
1918
+			$time_objects+=microtime(true) - $time_1;
1919 1919
 			$time_objectsN++;
1920 1920
 		}
1921 1921
 		
1922 1922
 		if ($display_progress)
1923 1923
 		{
1924 1924
     		echo "\nNumber of processed traps : $time_num_traps \n";
1925
-    		echo "\nParsing : " . number_format($time_parse1+$time_check1,1) ." sec / " . ($time_parse1N+ $time_check1N)  . " occurences\n";
1926
-    		echo "Detecting traps : " . number_format($time_check2+$time_check3,1) . " sec / " . ($time_check2N+$time_check3N) ." occurences\n";
1927
-    		echo "Trap processing ($time_updateN): ".number_format($time_update,1)." sec , ";
1928
-    		echo "Objects processing ($time_objectsN) : ".number_format($time_objects,1)." sec \n";
1925
+    		echo "\nParsing : ".number_format($time_parse1 + $time_check1, 1)." sec / ".($time_parse1N + $time_check1N)." occurences\n";
1926
+    		echo "Detecting traps : ".number_format($time_check2 + $time_check3, 1)." sec / ".($time_check2N + $time_check3N)." occurences\n";
1927
+    		echo "Trap processing ($time_updateN): ".number_format($time_update, 1)." sec , ";
1928
+    		echo "Objects processing ($time_objectsN) : ".number_format($time_objects, 1)." sec \n";
1929 1929
 		}
1930 1930
 		
1931 1931
 		// Timing ends
Please login to merge, or discard this patch.
Braces   +122 added lines, -78 removed lines patch added patch discarded remove patch
@@ -96,8 +96,7 @@  discard block
 block discarded – undo
96 96
 	        }
97 97
 	        $this->trapLog($message,$log_level,'syslog');
98 98
 	        return false;
99
-	    }
100
-	    else
99
+	    } else
101 100
 	    {
102 101
 	        $option_var=$option_array[$option_category][$option_name];
103 102
 	        return true;
@@ -144,7 +143,9 @@  discard block
 block discarded – undo
144 143
 	protected function getDBConfigIfSet($element,&$variable)
145 144
 	{
146 145
 		$value=$this->getDBConfig($element);
147
-		if ($value != 'null') $variable=$value;
146
+		if ($value != 'null') {
147
+			$variable=$value;
148
+		}
148 149
 	}
149 150
 	
150 151
 	/** Get data from db_config
@@ -180,8 +181,11 @@  discard block
 block discarded – undo
180 181
 			$message = '['.  date("Y/m/d H:i:s") . '] ' .
181 182
 				'['. basename(__FILE__) . '] ['.$this->debug_text[$level].']: ' .$message . "\n";
182 183
 			
183
-			if ( $destination != '' ) $output=$destination;
184
-			else $output=$this->alert_output;
184
+			if ( $destination != '' ) {
185
+				$output=$destination;
186
+			} else {
187
+				$output=$this->alert_output;
188
+			}
185 189
 			switch ($output)
186 190
 			{
187 191
 				case 'file':
@@ -216,7 +220,9 @@  discard block
 block discarded – undo
216 220
 		switch ($output_type)
217 221
 		{
218 222
 			case 'file':
219
-			    if ($output_option == null) throw new Exception("File logging without file !");
223
+			    if ($output_option == null) {
224
+			    	throw new Exception("File logging without file !");
225
+			    }
220 226
 				$this->debug_file=$output_option;
221 227
 				$this->alert_output='file';
222 228
 				break;
@@ -309,16 +315,14 @@  discard block
 block discarded – undo
309 315
 				$this->trapLog("No Config/database in config file: ".$this->trap_module_config,ERROR,''); 
310 316
 			}
311 317
 			$db_name=$trap_config['config']['database'];
312
-		} 
313
-		else if ($database == 'ido')
318
+		} else if ($database == 'ido')
314 319
 		{
315 320
 			if (!isset($trap_config['config']['IDOdatabase'])) 
316 321
 			{
317 322
 				$this->trapLog("No Config/IDOdatabase in config file: ".$this->trap_module_config,ERROR,''); 
318 323
 			}
319 324
 			$db_name=$trap_config['config']['IDOdatabase'];		
320
-		}
321
-		else
325
+		} else
322 326
 		{
323 327
 			$this->trapLog("Unknown database type : ".$database,ERROR,''); 		
324 328
 		}	
@@ -337,8 +341,12 @@  discard block
 block discarded – undo
337 341
 		$db_sql_name=$db_config[$db_name]['dbname'];
338 342
 		$db_user=$db_config[$db_name]['username'];
339 343
 		$db_pass=$db_config[$db_name]['password'];
340
-		if ($database == 'traps') $this->trapDBType = $db_type;
341
-		if ($database == 'ido') $this->idoDBType = $db_type;
344
+		if ($database == 'traps') {
345
+			$this->trapDBType = $db_type;
346
+		}
347
+		if ($database == 'ido') {
348
+			$this->idoDBType = $db_type;
349
+		}
342 350
 		
343 351
 		$this->trapLog( "DB selected : $db_type $db_host $db_sql_name $db_user",3,''); 
344 352
 		return array($db_type,$db_host,$db_sql_name,$db_user,$db_pass);
@@ -379,8 +387,7 @@  discard block
 block discarded – undo
379 387
 		{
380 388
 		    $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
381 389
 			$this->trapLog('Error parsing IP : '.$IP,ERROR,'');
382
-		} 
383
-		else 
390
+		} else 
384 391
 		{		
385 392
 			$this->trap_data['source_ip']=$matches[1];
386 393
 			$this->trap_data['destination_ip']=$matches[3];
@@ -394,14 +401,12 @@  discard block
 block discarded – undo
394 401
 			if ($ret_code==0 || $ret_code==FALSE) 
395 402
 			{
396 403
 				$this->trapLog('No match on trap data : '.$vars,WARN,'');
397
-			}
398
-			else 
404
+			} else 
399 405
 			{
400 406
 			    if (($matches[1]=='.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1]=='.1.3.6.1.6.3.1.1.4.1'))
401 407
 				{
402 408
 					$this->trap_data['trap_oid']=$matches[2];				
403
-				}
404
-				else
409
+				} else
405 410
 				{
406 411
 					$object= new stdClass;
407 412
 					$object->oid =$matches[1];
@@ -572,7 +577,9 @@  discard block
 block discarded – undo
572 577
 	            }
573 578
 	            
574 579
 	            $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
575
-	            if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
580
+	            if ($inserted_id==false) {
581
+	            	throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
582
+	            }
576 583
 	            $this->trap_id=$inserted_id;
577 584
 	            break;
578 585
 	        default:
@@ -588,7 +595,9 @@  discard block
 block discarded – undo
588 595
 	{
589 596
 		
590 597
 		// If action is ignore -> don't send t DB
591
-		if ($this->trap_to_db == false) return;
598
+		if ($this->trap_to_db == false) {
599
+			return;
600
+		}
592 601
 		
593 602
 		
594 603
 		$db_conn=$this->db_connect_trap();
@@ -645,7 +654,9 @@  discard block
 block discarded – undo
645 654
 				}
646 655
 
647 656
 				$inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
648
-				if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
657
+				if ($inserted_id==false) {
658
+					throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
659
+				}
649 660
 				$this->trap_id=$inserted_id;
650 661
 			break;
651 662
 			default: 
@@ -773,8 +784,7 @@  discard block
 block discarded – undo
773 784
     		// TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
774 785
     		exec('echo "'.$send.'" > ' .$this->icinga2cmd);
775 786
     		return true;
776
-	    }
777
-	    else
787
+	    } else
778 788
 	    {
779 789
 	        $api = $this->getAPI();
780 790
 	        $api->setCredentials($this->api_username, $this->api_password);
@@ -783,8 +793,7 @@  discard block
 block discarded – undo
783 793
 	        {
784 794
 	            $this->trapLog( "Error sending result : " .$retmessage,WARN,'');
785 795
 	            return false;
786
-	        }
787
-	        else 
796
+	        } else 
788 797
 	        {
789 798
 	            $this->trapLog( "Sent result : " .$retmessage,3,'');
790 799
 	            return true;
@@ -844,7 +853,9 @@  discard block
 block discarded – undo
844 853
 	/***************** Eval & tokenizer functions ****************/
845 854
 	protected function eval_getElement($rule,&$item)
846 855
 	{
847
-		while ($rule[$item]==' ') $item++;
856
+		while ($rule[$item]==' ') {
857
+			$item++;
858
+		}
848 859
 		if (preg_match('/[0-9\.]/',$rule[$item]))
849 860
 		{ // number
850 861
 	
@@ -871,14 +882,15 @@  discard block
 block discarded – undo
871 882
 			$start=$item;
872 883
 			$parenthesis_count=0; 
873 884
 			while (($item < strlen($rule)) // Not end of string AND
874
-			      && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded ()
885
+			      && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) {
886
+				// Closing ')' or embeded ()
875 887
 			{ 
876 888
 				if ($rule[$item] == '"' )
877 889
 				{ // pass through string
878 890
 					$item++;
891
+			}
879 892
 					$item=$this->eval_getNext($rule,$item,'"');
880
-				} 
881
-				else{
893
+				} else{
882 894
 				    if ($rule[$item] == '(')
883 895
 				    {
884 896
 				        $parenthesis_count++;
@@ -906,13 +918,17 @@  discard block
 block discarded – undo
906 918
 	protected function eval_getNext($rule,$item,$tok)
907 919
 	{
908 920
 		while (($rule[$item] != $tok ) && ($item < strlen($rule))) { $item++;}
909
-		if ($item==strlen($rule)) throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item);
921
+		if ($item==strlen($rule)) {
922
+			throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item);
923
+		}
910 924
 		return $item+1;
911 925
 	}
912 926
 	
913 927
 	protected function eval_getOper($rule,&$item)
914 928
 	{
915
-		while ($rule[$item]==' ') $item++;
929
+		while ($rule[$item]==' ') {
930
+			$item++;
931
+		}
916 932
 		switch ($rule[$item])
917 933
 		{
918 934
 			case '<':
@@ -948,12 +964,13 @@  discard block
 block discarded – undo
948 964
 	public function evaluation($rule,&$item)
949 965
 	{
950 966
 	    //echo "Evaluation of ".substr($rule,$item)."\n";
951
-		if ( $rule[$item] == '!') // If '!' found, negate next expression.
967
+		if ( $rule[$item] == '!') {
968
+			// If '!' found, negate next expression.
952 969
 		{
953 970
 		    $negate=true;
954
-		    $item++;
955 971
 		}
956
-		else
972
+		    $item++;
973
+		} else
957 974
 		{
958 975
 		    $negate=false;
959 976
 		}
@@ -961,10 +978,14 @@  discard block
 block discarded – undo
961 978
 		list($type1,$val1) = $this->eval_getElement($rule,$item);
962 979
 		//echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n";
963 980
 		
964
-		if ($item==strlen($rule)) // If only element, return value, but only boolean
981
+		if ($item==strlen($rule)) {
982
+			// If only element, return value, but only boolean
965 983
 		{
966 984
 		  if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule);
967
-		  if ($negate == true) $val1= ! $val1;
985
+		}
986
+		  if ($negate == true) {
987
+		  	$val1= ! $val1;
988
+		  }
968 989
 		  return $val1;
969 990
 		}  
970 991
 		
@@ -973,27 +994,34 @@  discard block
 block discarded – undo
973 994
 		//echo "Comp : ".$comp." : ".substr($rule,$item)."\n";
974 995
         
975 996
 		// Third element : number, string or ()
976
-		if ( $rule[$item] == '!') // starts with a ! so evaluate whats next
997
+		if ( $rule[$item] == '!') {
998
+			// starts with a ! so evaluate whats next
977 999
 		{
978 1000
 		    $item++;
979
-		    if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule);
1001
+		}
1002
+		    if ($typec != 1) {
1003
+		    	throw new Exception("Mixing boolean and comparison : ".$rule);
1004
+		    }
980 1005
 		    $val2= ! $this->evaluation($rule,$item);
981 1006
 		    $type2=2; // result is a boolean 
982
-		}
983
-		else 
1007
+		} else 
984 1008
 		{
985 1009
 		    list($type2,$val2) = $this->eval_getElement($rule,$item);
986 1010
 		}
987 1011
 		//echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n";
988 1012
 		
989
-		if ($type1!=$type2)  // cannot compare different types
1013
+		if ($type1!=$type2) {
1014
+			// cannot compare different types
990 1015
 		{ 
991 1016
 		    throw new Exception("Cannot compare string & number : ".$rule);
992 1017
 		}
993
-		if ($typec==1 && $type1 !=2) // cannot use & or | with string/number
1018
+		}
1019
+		if ($typec==1 && $type1 !=2) {
1020
+			// cannot use & or | with string/number
994 1021
 		{
995 1022
 		    throw new Exception("Cannot use boolean operators with string & number : ".$rule);
996 1023
 		}
1024
+		}
997 1025
 		
998 1026
 		switch ($comp){
999 1027
 			case '<':	$retVal= ($val1 < $val2); break;
@@ -1007,9 +1035,15 @@  discard block
 block discarded – undo
1007 1035
 			case '&':	$retVal= ($val1 && $val2); break;
1008 1036
 			default:  throw new Exception("Error in expression - unknown comp : ".$comp);
1009 1037
 		}
1010
-		if ($negate == true) $retVal = ! $retVal; // Inverse result if negate before expression
1038
+		if ($negate == true) {
1039
+			$retVal = ! $retVal;
1040
+		}
1041
+		// Inverse result if negate before expression
1011 1042
 		
1012
-		if ($item==strlen($rule)) return $retVal; // End of string : return evaluation
1043
+		if ($item==strlen($rule)) {
1044
+			return $retVal;
1045
+		}
1046
+		// End of string : return evaluation
1013 1047
 		// check for logical operator :
1014 1048
 		switch ($rule[$item])
1015 1049
 		{
@@ -1036,7 +1070,9 @@  discard block
 block discarded – undo
1036 1070
 					$rule2.=$rule[$item];
1037 1071
 					$item++;
1038 1072
 				}
1039
-				if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item);
1073
+				if ($item == strlen ($rule)) {
1074
+					throw new Exception("closing '\"' not found in ".$rule ." at " .$item);
1075
+				}
1040 1076
 				$rule2.=$rule[$item];
1041 1077
 				$item++;
1042 1078
 				continue;
@@ -1056,10 +1092,12 @@  discard block
 block discarded – undo
1056 1092
 	
1057 1093
 	protected function eval_rule($rule)
1058 1094
 	{
1059
-		if ($rule==null || $rule == '') // Empty rule is always true
1095
+		if ($rule==null || $rule == '') {
1096
+			// Empty rule is always true
1060 1097
 		{
1061 1098
 			return true;
1062 1099
 		}
1100
+		}
1063 1101
 		$matches=array();
1064 1102
 		while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1)
1065 1103
 		{
@@ -1146,20 +1184,17 @@  discard block
 block discarded – undo
1146 1184
 						if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
1147 1185
 						{
1148 1186
 						    $this->trap_action.='Error sending status : check cmd/API';
1149
-						}
1150
-						else
1187
+						} else
1151 1188
 						{
1152 1189
 						    $this->add_rule_match($rule['id'],$rule['num_match']+1);
1153 1190
 						    $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1154 1191
 						}
1155
-					}
1156
-					else
1192
+					} else
1157 1193
 					{
1158 1194
 						$this->add_rule_match($rule['id'],$rule['num_match']+1);
1159 1195
 					}
1160 1196
 					$this->trap_to_db=($action==-2)?false:true;
1161
-				}
1162
-				else
1197
+				} else
1163 1198
 				{
1164 1199
 					//$this->trapLog('rules KOO : '.print_r($rule),3,'');
1165 1200
 					
@@ -1170,14 +1205,12 @@  discard block
 block discarded – undo
1170 1205
 					    if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
1171 1206
 					    {
1172 1207
 					        $this->trap_action.='Error sending status : check cmd/API';
1173
-					    }
1174
-					    else
1208
+					    } else
1175 1209
 					    {
1176 1210
     						$this->add_rule_match($rule['id'],$rule['num_match']+1);
1177 1211
     						$this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1178 1212
 					    }
1179
-					}
1180
-					else
1213
+					} else
1181 1214
 					{
1182 1215
 						$this->add_rule_match($rule['id'],$rule['num_match']+1);
1183 1216
 					}
@@ -1187,16 +1220,14 @@  discard block
 block discarded – undo
1187 1220
 				if (!isset($this->trap_data['source_name']))
1188 1221
 				{
1189 1222
 					$this->trap_data['source_name']=$rule['host_name'];
1190
-				}
1191
-				else
1223
+				} else
1192 1224
 				{
1193 1225
 					if (!preg_match('/'.$rule['host_name'].'/',$this->trap_data['source_name']))
1194 1226
 					{ // only add if not present
1195 1227
 						$this->trap_data['source_name'].=','.$rule['host_name'];
1196 1228
 					}
1197 1229
 				}
1198
-			}
1199
-			catch (Exception $e) 
1230
+			} catch (Exception $e) 
1200 1231
 			{ 
1201 1232
 			    $this->trapLog('Error in rule eval : '.$e->getMessage(),WARN,'');
1202 1233
 			    $this->trap_action.=' ERR : '.$e->getMessage();
@@ -1207,8 +1238,7 @@  discard block
 block discarded – undo
1207 1238
 		if ($this->trap_data['status']=='error')
1208 1239
 		{
1209 1240
 		  $this->trap_to_db=true; // Always put errors in DB for the use can see
1210
-		}
1211
-		else
1241
+		} else
1212 1242
 		{
1213 1243
 		  $this->trap_data['status']='done';
1214 1244
 		}
@@ -1262,8 +1292,7 @@  discard block
 block discarded – undo
1262 1292
                 if (preg_match('/^ *CREATE TABLE ([^ ]+)/',$newline,$cur_table_array))
1263 1293
                 {
1264 1294
                     $cur_table='table '.$cur_table_array[1];
1265
-                }
1266
-                else
1295
+                } else
1267 1296
                 {
1268 1297
                     $cur_table='secret SQL stuff :-)';
1269 1298
                 }
@@ -1307,8 +1336,7 @@  discard block
 block discarded – undo
1307 1336
 	    if ($this->trapDBType == 'pgsql')
1308 1337
 	    {
1309 1338
 	        $prefix .= 'update_pgsql/schema_';
1310
-	    }
1311
-	    else
1339
+	    } else
1312 1340
 	    {
1313 1341
 	        $prefix .= 'update_sql/schema_';
1314 1342
 	    }
@@ -1354,7 +1382,10 @@  discard block
 block discarded – undo
1354 1382
 	       $db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
1355 1383
 	       while (($line=fgets($input_stream)) != FALSE)
1356 1384
 	       {
1357
-	           if (preg_match('/^#/', $line)) continue; // ignore comment lines
1385
+	           if (preg_match('/^#/', $line)) {
1386
+	           	continue;
1387
+	           }
1388
+	           // ignore comment lines
1358 1389
 	           $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line));
1359 1390
 	           if (preg_match('/; *$/', $newline))
1360 1391
 	           {
@@ -1366,8 +1397,7 @@  discard block
 block discarded – undo
1366 1397
 	               if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/',$newline,$cur_table_array))
1367 1398
 	               {
1368 1399
 	                   $cur_table=$cur_table_array[1] . ' SQL table '.$cur_table_array[2];
1369
-	               }
1370
-	               else
1400
+	               } else
1371 1401
 	               {
1372 1402
 	                   $cur_table='secret SQL stuff :-)';
1373 1403
 	                   $cur_table=$newline;
@@ -1505,8 +1535,7 @@  discard block
 block discarded – undo
1505 1535
 			    }
1506 1536
 			    $this->trapLog('Trap updated : '.$name . ' / OID : '.$oid,4,'');
1507 1537
 				return 1;
1508
-			}
1509
-			else
1538
+			} else
1510 1539
 			{
1511 1540
 			    $this->trapLog('Trap unchanged : '.$name . ' / OID : '.$oid,4,'');
1512 1541
 			    return 0;
@@ -1522,7 +1551,9 @@  discard block
 block discarded – undo
1522 1551
               'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
1523 1552
               ', :syntax, :type_enum, :description )';
1524 1553
         
1525
-		if ($this->trapDBType == 'pgsql') $sql .= 'RETURNING id';
1554
+		if ($this->trapDBType == 'pgsql') {
1555
+			$sql .= 'RETURNING id';
1556
+		}
1526 1557
 		
1527 1558
 		$sqlQuery=$db_conn->prepare($sql);
1528 1559
 		
@@ -1562,7 +1593,9 @@  discard block
 block discarded – undo
1562 1593
 		        }
1563 1594
 		        
1564 1595
 		        $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
1565
-		        if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
1596
+		        if ($inserted_id==false) {
1597
+		        	throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
1598
+		        }
1566 1599
 		        $this->dbOidIndex[$oid]['id']=$inserted_id;
1567 1600
 		        break;
1568 1601
 		    default:
@@ -1815,12 +1848,14 @@  discard block
 block discarded – undo
1815 1848
 			$name=$match[1]; // Name 
1816 1849
 			$type=$match[2]; // type (21=trap, 0: may be trap, else : not trap
1817 1850
 			
1818
-			if ($type==0) // object type=0 : check if v1 trap
1851
+			if ($type==0) {
1852
+				// object type=0 : check if v1 trap
1819 1853
 			{
1820 1854
 				// Check if next is suboid -> in that case is cannot be a trap
1821 1855
 				if (preg_match("/^$oid/",$this->objectsAll[$curElement+1]))
1822 1856
 				{
1823 1857
 				    $time_check2 += microtime(true) - $time_1;
1858
+			}
1824 1859
 				    $time_check2N++;
1825 1860
 					continue;
1826 1861
 				}		
@@ -1837,9 +1872,11 @@  discard block
 block discarded – undo
1837 1872
 				// Force as trap.
1838 1873
 				$type=21;
1839 1874
 			}
1840
-			if ($onlyTraps==true && $type!=21) // if only traps and not a trap, continue
1875
+			if ($onlyTraps==true && $type!=21) {
1876
+				// if only traps and not a trap, continue
1841 1877
 			{
1842 1878
 			    $time_check3 += microtime(true) - $time_1;
1879
+			}
1843 1880
 				$time_check3N++;
1844 1881
 				continue;
1845 1882
 			}
@@ -1847,7 +1884,10 @@  discard block
 block discarded – undo
1847 1884
 			$time_num_traps++;
1848 1885
 			
1849 1886
 			$this->trapLog('Found trap : '.$match[1] . ' / OID : '.$oid,3,'');
1850
-			if ($display_progress) echo '#'; // echo a # when trap found
1887
+			if ($display_progress) {
1888
+				echo '#';
1889
+			}
1890
+			// echo a # when trap found
1851 1891
 				
1852 1892
 			// get trap objects & source MIB
1853 1893
 			unset($snmptrans);
@@ -1865,7 +1905,9 @@  discard block
 block discarded – undo
1865 1905
 			$trapMib=$match[1];
1866 1906
 			
1867 1907
 			$numLine=1;$trapDesc='';
1868
-			while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
1908
+			while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) {
1909
+				$numLine++;
1910
+			}
1869 1911
 			if (isset($snmptrans[$numLine]))
1870 1912
 			{
1871 1913
 			    $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
@@ -1887,7 +1929,9 @@  discard block
 block discarded – undo
1887 1929
 			if (($update==0) && ($check_change==false))
1888 1930
 			{ // Trapd didn't change & force check disabled
1889 1931
 			    $time_objects += microtime(true) - $time_1;
1890
-			    if ($display_progress) echo "C";
1932
+			    if ($display_progress) {
1933
+			    	echo "C";
1934
+			    }
1891 1935
 			    continue;
1892 1936
 			}
1893 1937
 			
Please login to merge, or discard this patch.
bin/trap_in.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // start
4
-$time1 = microtime(true);
4
+$time1=microtime(true);
5 5
 
6 6
 require_once ('trap_class.php');
7 7
 
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 // Icinga etc path : need to change this on non standard icinga installation.
10 10
 $icingaweb2_etc="/etc/icingaweb2";
11 11
 
12
-$Trap = new Trap($icingaweb2_etc);
12
+$Trap=new Trap($icingaweb2_etc);
13 13
 
14 14
 //$Trap->setLogging(4,'display'); // For debug
15 15
 
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 }
30 30
 catch (Exception $e) 
31 31
 {
32
-	$Trap->trapLog("Exception : ". $e->getMessage(),2,0);
32
+	$Trap->trapLog("Exception : ".$e->getMessage(), 2, 0);
33 33
 }
34 34
 
35 35
 //end
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,8 +26,7 @@
 block discarded – undo
26 26
 
27 27
 	$Trap->add_rule_final(microtime(true) - $time1);
28 28
 	
29
-}
30
-catch (Exception $e) 
29
+} catch (Exception $e) 
31 30
 {
32 31
 	$Trap->trapLog("Exception : ". $e->getMessage(),2,0);
33 32
 }
Please login to merge, or discard this patch.