Passed
Push — master ( b8f383...dcdb45 )
by Patrick
02:09
created
bin/trap_in.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -15,13 +15,13 @@  discard block
 block discarded – undo
15 15
 
16 16
 try
17 17
 {
18
-    $Trap = new Trap($icingaweb2_etc);
19
-    //$Trap = new Trap($icingaweb2_etc,4,'display'); // For debug
20
-    //$Trap = new Trap($icingaweb2_etc,4,'syslog'); // For debug
21
-    //$Trap->setLogging(4,'syslog'); 
18
+	$Trap = new Trap($icingaweb2_etc);
19
+	//$Trap = new Trap($icingaweb2_etc,4,'display'); // For debug
20
+	//$Trap = new Trap($icingaweb2_etc,4,'syslog'); // For debug
21
+	//$Trap->setLogging(4,'syslog'); 
22 22
     
23
-    // TODO : tranfer this to reset_trap cli command
24
-    $Trap->eraseOldTraps();
23
+	// TODO : tranfer this to reset_trap cli command
24
+	$Trap->eraseOldTraps();
25 25
 
26 26
 	$Trap->read_trap('php://stdin');
27 27
 
@@ -34,15 +34,15 @@  discard block
 block discarded – undo
34 34
 }
35 35
 catch (Exception $e) 
36 36
 {
37
-    if ($Trap == null)
38
-    {  // Exception in trap creation : log in display & syslog
39
-        $logging = new Logging();
40
-        $logging->log("Caught exception creating Trap class",2);
41
-    }
42
-    else
43
-    {
37
+	if ($Trap == null)
38
+	{  // Exception in trap creation : log in display & syslog
39
+		$logging = new Logging();
40
+		$logging->log("Caught exception creating Trap class",2);
41
+	}
42
+	else
43
+	{
44 44
 	   $Trap->trapLog("Exception : ". $e->getMessage(),2,0);
45
-    }
45
+	}
46 46
 }
47 47
 
48 48
 //end
Please login to merge, or discard this patch.
bin/trap_class.php 1 patch
Indentation   +597 added lines, -597 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	
55 55
 	function __construct($etc_dir='/etc/icingaweb2',$baseLogLevel=null,$baseLogMode='syslog',$baseLogFile='')
56 56
 	{
57
-	    // Paths of ini files
57
+		// Paths of ini files
58 58
 		$this->icingaweb2_etc=$etc_dir;
59 59
 		$this->trap_module_config=$this->icingaweb2_etc."/modules/trapdirector/config.ini";		
60 60
 		$this->icingaweb2_ressources=$this->icingaweb2_etc."/resources.ini";
@@ -63,18 +63,18 @@  discard block
 block discarded – undo
63 63
 		$this->logging = new Logging();
64 64
 		if ($baseLogLevel != null)
65 65
 		{
66
-		    $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile);
67
-		    $this->logSetup=true;
66
+			$this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile);
67
+			$this->logSetup=true;
68 68
 		}
69 69
 		else 
70
-		    $this->logSetup=false;
70
+			$this->logSetup=false;
71 71
 		$this->logging->log('Loggin started', INFO);
72 72
 
73 73
 		// Get options from ini files
74 74
 		$trapConfig=parse_ini_file($this->trap_module_config,true);
75 75
 		if ($trapConfig == false)
76 76
 		{
77
-		    $this->logging->log("Error reading ini file : ".$this->trap_module_config,ERROR,'syslog');
77
+			$this->logging->log("Error reading ini file : ".$this->trap_module_config,ERROR,'syslog');
78 78
 		}
79 79
 		$this->getMainOptions($trapConfig); // Get main options from ini file
80 80
 		$this->setupDatabase($trapConfig); // Setup database class
@@ -104,26 +104,26 @@  discard block
 block discarded – undo
104 104
 	 */
105 105
 	protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = 2, $message = null)
106 106
 	{
107
-	    if (!isset($option_array[$option_category][$option_name]))
108
-	    {
109
-	        if ($message === null)
110
-	        {
111
-	            $message='No ' . $option_name . ' in config file: '. $this->trap_module_config;
112
-	        }
113
-	        $this->logging->log($message,$log_level,'syslog');
114
-	        return false;
115
-	    }
116
-	    else
117
-	    {
118
-	        $option_var=$option_array[$option_category][$option_name];
119
-	        return true;
120
-	    }
107
+		if (!isset($option_array[$option_category][$option_name]))
108
+		{
109
+			if ($message === null)
110
+			{
111
+				$message='No ' . $option_name . ' in config file: '. $this->trap_module_config;
112
+			}
113
+			$this->logging->log($message,$log_level,'syslog');
114
+			return false;
115
+		}
116
+		else
117
+		{
118
+			$option_var=$option_array[$option_category][$option_name];
119
+			return true;
120
+		}
121 121
 	}
122 122
 	
123 123
 	/** 
124 124
 	 * Get options from ini file
125 125
 	 * @param array $trap_config : ini file array
126
-	*/
126
+	 */
127 127
 	protected function getMainOptions($trapConfig)
128 128
 	{
129 129
 
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
 		// API options
143 143
 		if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->api_hostname))
144 144
 		{
145
-		    $this->api_use=true;
146
-		    $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->api_port);
147
-		    $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->api_username);
148
-		    $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->api_password);
145
+			$this->api_use=true;
146
+			$this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->api_port);
147
+			$this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->api_username);
148
+			$this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->api_password);
149 149
 		}
150 150
 	}
151 151
 	
@@ -155,45 +155,45 @@  discard block
 block discarded – undo
155 155
 	 */
156 156
 	protected function setupDatabase($trapConfig)
157 157
 	{
158
-	    // Trap database
159
-	    if (!array_key_exists('database',$trapConfig['config']))
160
-        {
161
-            $this->logging->log("No database in config file: ".$this->trap_module_config,ERROR,'');
162
-            return;
163
-        }
164
-        $dbTrapName=$trapConfig['config']['database'];
165
-        $this->logging->log("Found database in config file: ".$dbTrapName,INFO );
158
+		// Trap database
159
+		if (!array_key_exists('database',$trapConfig['config']))
160
+		{
161
+			$this->logging->log("No database in config file: ".$this->trap_module_config,ERROR,'');
162
+			return;
163
+		}
164
+		$dbTrapName=$trapConfig['config']['database'];
165
+		$this->logging->log("Found database in config file: ".$dbTrapName,INFO );
166 166
 	    
167 167
 	   if ( ($dbConfig=parse_ini_file($this->icingaweb2_ressources,true)) === false)
168
-	    {
169
-	        $this->logging->log("Error reading ini file : ".$this->icingaweb2_ressources,ERROR,'');
170
-	        return;
171
-	    }
172
-	    if (!array_key_exists($dbTrapName,$dbConfig))
173
-	    {
174
-	        $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
175
-	        return;
176
-	    }
168
+		{
169
+			$this->logging->log("Error reading ini file : ".$this->icingaweb2_ressources,ERROR,'');
170
+			return;
171
+		}
172
+		if (!array_key_exists($dbTrapName,$dbConfig))
173
+		{
174
+			$this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
175
+			return;
176
+		}
177 177
 	    
178
-        $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName]);
178
+		$this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName]);
179 179
 	    
180
-	    if ($this->api_use === true) return; // In case of API use, no IDO is necessary
180
+		if ($this->api_use === true) return; // In case of API use, no IDO is necessary
181 181
         
182
-	    // IDO Database
183
-	    if (!array_key_exists('IDOdatabase',$trapConfig['config']))
184
-	    {
185
-	        $this->logging->log("No IDOdatabase in config file: ".$this->trap_module_config,ERROR,'');
186
-	    }
187
-	    $dbIdoName=$trapConfig['config']['IDOdatabase'];		
182
+		// IDO Database
183
+		if (!array_key_exists('IDOdatabase',$trapConfig['config']))
184
+		{
185
+			$this->logging->log("No IDOdatabase in config file: ".$this->trap_module_config,ERROR,'');
186
+		}
187
+		$dbIdoName=$trapConfig['config']['IDOdatabase'];		
188 188
 
189
-	    $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
190
-        if (!array_key_exists($dbIdoName,$dbConfig))
191
-	    {
192
-	        $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
193
-	        return;
194
-	    }
189
+		$this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
190
+		if (!array_key_exists($dbIdoName,$dbConfig))
191
+		{
192
+			$this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
193
+			return;
194
+		}
195 195
 	    
196
-	    $this->trapsDB->setupIDO($dbConfig[$dbIdoName]);
196
+		$this->trapsDB->setupIDO($dbConfig[$dbIdoName]);
197 197
 	}
198 198
 	
199 199
 	/**
@@ -204,9 +204,9 @@  discard block
 block discarded – undo
204 204
 		// Database options
205 205
 		if ($this->logSetup === false) // Only if logging was no setup in constructor
206 206
 		{
207
-    		$this->getDBConfigIfSet('log_level',$this->logging->debugLevel);
208
-    		$this->getDBConfigIfSet('log_destination',$this->logging->outputMode);
209
-    		$this->getDBConfigIfSet('log_file',$this->logging->outputFile);
207
+			$this->getDBConfigIfSet('log_level',$this->logging->debugLevel);
208
+			$this->getDBConfigIfSet('log_destination',$this->logging->outputMode);
209
+			$this->getDBConfigIfSet('log_file',$this->logging->outputFile);
210 210
 		}
211 211
 	}
212 212
 
@@ -217,10 +217,10 @@  discard block
 block discarded – undo
217 217
 	}
218 218
 	
219 219
 	/** 
220
-	*   Get data from db_config
221
-	*	@param $element string name of param
222
-	*	@return mixed : value (or null)
223
-	*/	
220
+	 *   Get data from db_config
221
+	 *	@param $element string name of param
222
+	 *	@return mixed : value (or null)
223
+	 */	
224 224
 	protected function getDBConfig($element)
225 225
 	{
226 226
 		$db_conn=$this->trapsDB->db_connect_trap();
@@ -238,15 +238,15 @@  discard block
 block discarded – undo
238 238
 	}
239 239
 	
240 240
 	/** OBSOLETE Send log. Throws exception on critical error
241
-	*	@param	string $message Message to log
242
-	*	@param	int $level 1=critical 2=warning 3=trace 4=debug
243
-	*	@param  string $destination file/syslog/display
244
-	*	@return void
245
-	**/	
241
+	 *	@param	string $message Message to log
242
+	 *	@param	int $level 1=critical 2=warning 3=trace 4=debug
243
+	 *	@param  string $destination file/syslog/display
244
+	 *	@return void
245
+	 **/	
246 246
 	public function trapLog( $message, $level, $destination ='') // OBSOLETE
247 247
 	{	
248 248
 		// TODO : replace ref with $this->logging->log 
249
-	    $this->logging->log($message, $level, $destination);
249
+		$this->logging->log($message, $level, $destination);
250 250
 	}
251 251
 	
252 252
 	public function setLogging($debugLvl,$outputType,$outputOption=null)  // OBSOLETE
@@ -256,19 +256,19 @@  discard block
 block discarded – undo
256 256
 	
257 257
 	protected function getAPI()
258 258
 	{
259
-	    if ($this->icinga2api == null)
260
-	    {
261
-	        $this->icinga2api = new Icinga2API($this->api_hostname,$this->api_port);
262
-	    }
263
-	    return $this->icinga2api;
259
+		if ($this->icinga2api == null)
260
+		{
261
+			$this->icinga2api = new Icinga2API($this->api_hostname,$this->api_port);
262
+		}
263
+		return $this->icinga2api;
264 264
 	}
265 265
 	
266 266
 	
267 267
 	/** 
268 268
 	 * read data from stream
269
-	*	@param $stream string input stream, defaults to "php://stdin"
270
-	*	@return mixed array trap data or exception with error
271
-	*/
269
+	 *	@param $stream string input stream, defaults to "php://stdin"
270
+	 *	@return mixed array trap data or exception with error
271
+	 */
272 272
 	public function read_trap($stream='php://stdin')
273 273
 	{
274 274
 		//Read data from snmptrapd from stdin
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 
277 277
 		if ($input_stream === false)
278 278
 		{
279
-		    $this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)");
279
+			$this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)");
280 280
 			$this->logging->log("Error reading stdin !",ERROR,'');
281 281
 			return null; // note : exception thrown by logging
282 282
 		}
@@ -285,21 +285,21 @@  discard block
 block discarded – undo
285 285
 		$this->receivingHost=chop(fgets($input_stream));
286 286
 		if ($this->receivingHost === false)
287 287
 		{
288
-		    $this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)");
288
+			$this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)");
289 289
 			$this->logging->log("Error reading Host !",ERROR,''); 
290 290
 		}
291 291
 		// line 2 IP:port=>IP:port
292 292
 		$IP=chop(fgets($input_stream));
293 293
 		if ($IP === false)
294 294
 		{
295
-		    $this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)");
295
+			$this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)");
296 296
 			$this->logging->log("Error reading IP !",ERROR,''); 
297 297
 		}
298 298
 		$matches=array();
299 299
 		$ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/',$IP,$matches);
300 300
 		if ($ret_code===0 || $ret_code===false) 
301 301
 		{
302
-		    $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
302
+			$this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
303 303
 			$this->logging->log('Error parsing IP : '.$IP,ERROR,'');
304 304
 		} 
305 305
 		else 
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 			}
321 321
 			else 
322 322
 			{
323
-			    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'))
323
+				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'))
324 324
 				{
325 325
 					$this->trap_data['trap_oid']=$matches[2];				
326 326
 				}
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 
337 337
 		if ($this->trap_data['trap_oid']=='unknown') 
338 338
 		{
339
-		    $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trap_data['source_ip']);
339
+			$this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trap_data['source_ip']);
340 340
 			$this->logging->log('no trap oid found',ERROR,'');
341 341
 		} 
342 342
 
@@ -366,9 +366,9 @@  discard block
 block discarded – undo
366 366
 
367 367
 	/** 
368 368
 	 * Translate oid into array(MIB,Name)
369
-	* @param $oid string oid to translate
370
-	* @return mixed : null if not found or array(MIB,Name)
371
-	*/
369
+	 * @param $oid string oid to translate
370
+	 * @return mixed : null if not found or array(MIB,Name)
371
+	 */
372 372
 	public function translateOID($oid)
373 373
 	{
374 374
 		// try from database
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 		
402 402
 		// Try to get oid name from snmptranslate
403 403
 		$translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
404
-		    ' '.$oid);
404
+			' '.$oid);
405 405
 		$matches=array();
406 406
 		$ret_code=preg_match('/(.*)::(.*)/',$translate,$matches);
407 407
 		if ($ret_code===0 || $ret_code === false) {
@@ -414,9 +414,9 @@  discard block
 block discarded – undo
414 414
 	
415 415
 	/** 
416 416
 	 * Erase old trap records 
417
-	*	@param integer $days : erase traps when more than $days old
418
-	*	@return integer : number of lines deleted
419
-	**/
417
+	 *	@param integer $days : erase traps when more than $days old
418
+	 *	@return integer : number of lines deleted
419
+	 **/
420 420
 	public function eraseOldTraps($days=0)
421 421
 	{
422 422
 		if ($days==0)
@@ -441,72 +441,72 @@  discard block
 block discarded – undo
441 441
 	public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null)
442 442
 	{
443 443
 	    
444
-	    $db_conn=$this->trapsDB->db_connect_trap();
444
+		$db_conn=$this->trapsDB->db_connect_trap();
445 445
 	    
446
-	    // add date time
447
-	    $insert_col ='date_received,status';
448
-	    $insert_val = "'" . date("Y-m-d H:i:s")."','error'";
446
+		// add date time
447
+		$insert_col ='date_received,status';
448
+		$insert_val = "'" . date("Y-m-d H:i:s")."','error'";
449 449
         
450
-	    if ($sourceIP !=null)
451
-	    {
452
-	        $insert_col .=',source_ip';
453
-	        $insert_val .=",'". $sourceIP ."'";
454
-	    }
455
-	    if ($trapoid !=null)
456
-	    {
457
-	        $insert_col .=',trap_oid';
458
-	        $insert_val .=",'". $trapoid ."'";
459
-	    }
460
-	    $insert_col .=',status_detail';
461
-	    $insert_val .=",'". $message ."'";
450
+		if ($sourceIP !=null)
451
+		{
452
+			$insert_col .=',source_ip';
453
+			$insert_val .=",'". $sourceIP ."'";
454
+		}
455
+		if ($trapoid !=null)
456
+		{
457
+			$insert_col .=',trap_oid';
458
+			$insert_val .=",'". $trapoid ."'";
459
+		}
460
+		$insert_col .=',status_detail';
461
+		$insert_val .=",'". $message ."'";
462 462
 	    
463
-	    $sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
463
+		$sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
464 464
 	    
465
-	    switch ($this->trapsDB->trapDBType)
466
-	    {
467
-	        case 'pgsql':
468
-	            $sql .= ' RETURNING id;';
469
-	            $this->logging->log('sql : '.$sql,INFO);
470
-	            if (($ret_code=$db_conn->query($sql)) === false) {
471
-	                $this->logging->log('Error SQL insert : '.$sql,1,'');
472
-	            }
473
-	            $this->logging->log('SQL insertion OK',INFO );
474
-	            // Get last id to insert oid/values in secondary table
475
-	            if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
465
+		switch ($this->trapsDB->trapDBType)
466
+		{
467
+			case 'pgsql':
468
+				$sql .= ' RETURNING id;';
469
+				$this->logging->log('sql : '.$sql,INFO);
470
+				if (($ret_code=$db_conn->query($sql)) === false) {
471
+					$this->logging->log('Error SQL insert : '.$sql,1,'');
472
+				}
473
+				$this->logging->log('SQL insertion OK',INFO );
474
+				// Get last id to insert oid/values in secondary table
475
+				if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
476 476
 	                
477
-	                $this->logging->log('Erreur recuperation id',1,'');
478
-	            }
479
-	            if (! isset($inserted_id_ret['id'])) {
480
-	                $this->logging->log('Error getting id',1,'');
481
-	            }
482
-	            $this->trap_id=$inserted_id_ret['id'];
483
-	            break;
484
-	        case 'mysql':
485
-	            $sql .= ';';
486
-	            $this->logging->log('sql : '.$sql,INFO );
487
-	            if ($db_conn->query($sql) === false) {
488
-	                $this->logging->log('Error SQL insert : '.$sql,1,'');
489
-	            }
490
-	            $this->logging->log('SQL insertion OK',INFO );
491
-	            // Get last id to insert oid/values in secondary table
492
-	            $sql='SELECT LAST_INSERT_ID();';
493
-	            if (($ret_code=$db_conn->query($sql)) === false) {
494
-	                $this->logging->log('Erreur recuperation id',1,'');
495
-	            }
477
+					$this->logging->log('Erreur recuperation id',1,'');
478
+				}
479
+				if (! isset($inserted_id_ret['id'])) {
480
+					$this->logging->log('Error getting id',1,'');
481
+				}
482
+				$this->trap_id=$inserted_id_ret['id'];
483
+				break;
484
+			case 'mysql':
485
+				$sql .= ';';
486
+				$this->logging->log('sql : '.$sql,INFO );
487
+				if ($db_conn->query($sql) === false) {
488
+					$this->logging->log('Error SQL insert : '.$sql,1,'');
489
+				}
490
+				$this->logging->log('SQL insertion OK',INFO );
491
+				// Get last id to insert oid/values in secondary table
492
+				$sql='SELECT LAST_INSERT_ID();';
493
+				if (($ret_code=$db_conn->query($sql)) === false) {
494
+					$this->logging->log('Erreur recuperation id',1,'');
495
+				}
496 496
 	            
497
-	            $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
498
-	            if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
499
-	            $this->trap_id=$inserted_id;
500
-	            break;
501
-	        default:
502
-	            $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType,1,'');
503
-	    }
497
+				$inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
498
+				if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
499
+				$this->trap_id=$inserted_id;
500
+				break;
501
+			default:
502
+				$this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType,1,'');
503
+		}
504 504
 	    
505
-	    $this->logging->log('id found: '. $this->trap_id,INFO );    
505
+		$this->logging->log('id found: '. $this->trap_id,INFO );    
506 506
 	}
507 507
 	
508 508
 	/** Write trap data to trap database
509
-	*/
509
+	 */
510 510
 	public function writeTrapToDB()
511 511
 	{
512 512
 		
@@ -604,10 +604,10 @@  discard block
 block discarded – undo
604 604
 	}
605 605
 
606 606
 	/** Get rules from rule database with ip and oid
607
-	*	@param $ip string ipv4 or ipv6
608
-	*	@param $oid string oid in numeric
609
-	*	@return mixed : PDO object or false
610
-	*/	
607
+	 *	@param $ip string ipv4 or ipv6
608
+	 *	@param $oid string oid in numeric
609
+	 *	@return mixed : PDO object or false
610
+	 */	
611 611
 	protected function getRules($ip,$oid)
612 612
 	{
613 613
 		$db_conn=$this->trapsDB->db_connect_trap();
@@ -666,9 +666,9 @@  discard block
 block discarded – undo
666 666
 	}
667 667
 
668 668
 	/** Add rule match to rule
669
-	*	@param id int : rule id
670
-	*   @param set int : value to set
671
-	*/
669
+	 *	@param id int : rule id
670
+	 *   @param set int : value to set
671
+	 */
672 672
 	protected function add_rule_match($id, $set)
673 673
 	{
674 674
 		$db_conn=$this->trapsDB->db_connect_trap();
@@ -685,53 +685,53 @@  discard block
 block discarded – undo
685 685
 	 * @param integer $state numerical staus 
686 686
 	 * @param string $display
687 687
 	 * @returnn bool true is service check was sent without error
688
-	*/
688
+	 */
689 689
 	public function serviceCheckResult($host,$service,$state,$display)
690 690
 	{
691
-	    if ($this->api_use === false)
692
-	    {
693
-    		$send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' .
694
-    			$host.';' .$service .';' . $state . ';'.$display;
695
-    		$this->logging->log( $send." : to : " .$this->icinga2cmd,INFO );
691
+		if ($this->api_use === false)
692
+		{
693
+			$send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' .
694
+				$host.';' .$service .';' . $state . ';'.$display;
695
+			$this->logging->log( $send." : to : " .$this->icinga2cmd,INFO );
696 696
     		
697
-    		// TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
698
-    		exec('echo "'.$send.'" > ' .$this->icinga2cmd);
699
-    		return true;
700
-	    }
701
-	    else
702
-	    {
703
-	        $api = $this->getAPI();
704
-	        $api->setCredentials($this->api_username, $this->api_password);
705
-	        list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display);
706
-	        if ($retcode == false)
707
-	        {
708
-	            $this->logging->log( "Error sending result : " .$retmessage,WARN,'');
709
-	            return false;
710
-	        }
711
-	        else 
712
-	        {
713
-	            $this->logging->log( "Sent result : " .$retmessage,INFO );
714
-	            return true;
715
-	        }
716
-	    }
697
+			// TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
698
+			exec('echo "'.$send.'" > ' .$this->icinga2cmd);
699
+			return true;
700
+		}
701
+		else
702
+		{
703
+			$api = $this->getAPI();
704
+			$api->setCredentials($this->api_username, $this->api_password);
705
+			list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display);
706
+			if ($retcode == false)
707
+			{
708
+				$this->logging->log( "Error sending result : " .$retmessage,WARN,'');
709
+				return false;
710
+			}
711
+			else 
712
+			{
713
+				$this->logging->log( "Sent result : " .$retmessage,INFO );
714
+				return true;
715
+			}
716
+		}
717 717
 	}
718 718
 	
719 719
 	public function getHostByIP($ip)
720 720
 	{
721
-	    $api = $this->getAPI();
722
-	    $api->setCredentials($this->api_username, $this->api_password);
723
-	    return $api->getHostByIP($ip);
721
+		$api = $this->getAPI();
722
+		$api->setCredentials($this->api_username, $this->api_password);
723
+		return $api->getHostByIP($ip);
724 724
 	}
725 725
 	
726 726
 	/** Resolve display. 
727
-	*	Changes OID(<oid>) to value if found or text "<not in trap>"
728
-	*	@param $display string
729
-	*	@return string display
730
-	*/
727
+	 *	Changes OID(<oid>) to value if found or text "<not in trap>"
728
+	 *	@param $display string
729
+	 *	@return string display
730
+	 */
731 731
 	protected function applyDisplay($display)
732 732
 	{
733
-	    $matches=array();
734
-	    while (preg_match('/_OID\(([0-9\.]+)\)/',$display,$matches) == 1)
733
+		$matches=array();
734
+		while (preg_match('/_OID\(([0-9\.]+)\)/',$display,$matches) == 1)
735 735
 		{
736 736
 			$oid=$matches[1];
737 737
 			$found=0;
@@ -791,11 +791,11 @@  discard block
 block discarded – undo
791 791
 		
792 792
 		if ($rule[$item] == '(')
793 793
 		{ // grouping
794
-		    $item++;
794
+			$item++;
795 795
 			$start=$item;
796 796
 			$parenthesis_count=0; 
797 797
 			while (($item < strlen($rule)) // Not end of string AND
798
-			      && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded ()
798
+				  && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded ()
799 799
 			{ 
800 800
 				if ($rule[$item] == '"' )
801 801
 				{ // pass through string
@@ -803,14 +803,14 @@  discard block
 block discarded – undo
803 803
 					$item=$this->eval_getNext($rule,$item,'"');
804 804
 				} 
805 805
 				else{
806
-				    if ($rule[$item] == '(')
807
-				    {
808
-				        $parenthesis_count++;
809
-				    }
810
-				    if ($rule[$item] == ')')
811
-				    {
812
-				        $parenthesis_count--;
813
-				    }
806
+					if ($rule[$item] == '(')
807
+					{
808
+						$parenthesis_count++;
809
+					}
810
+					if ($rule[$item] == ')')
811
+					{
812
+						$parenthesis_count--;
813
+					}
814 814
 					$item++;
815 815
 				}
816 816
 			}
@@ -862,24 +862,24 @@  discard block
 block discarded – undo
862 862
 	}
863 863
 	
864 864
 	/** Evaluation : makes token and evaluate. 
865
-	*	Public function for expressions testing
866
-	*	accepts : < > = <= >= !=  (typec = 0)
867
-	*	operators : & | (typec=1)
868
-	*	with : integers/float  (type 0) or strings "" (type 1) or results (type 2)
869
-	*   comparison int vs strings will return null (error)
870
-	*	return : bool or null on error
871
-	*/
865
+	 *	Public function for expressions testing
866
+	 *	accepts : < > = <= >= !=  (typec = 0)
867
+	 *	operators : & | (typec=1)
868
+	 *	with : integers/float  (type 0) or strings "" (type 1) or results (type 2)
869
+	 *   comparison int vs strings will return null (error)
870
+	 *	return : bool or null on error
871
+	 */
872 872
 	public function evaluation($rule,&$item)
873 873
 	{
874
-	    //echo "Evaluation of ".substr($rule,$item)."\n";
874
+		//echo "Evaluation of ".substr($rule,$item)."\n";
875 875
 		if ( $rule[$item] == '!') // If '!' found, negate next expression.
876 876
 		{
877
-		    $negate=true;
878
-		    $item++;
877
+			$negate=true;
878
+			$item++;
879 879
 		}
880 880
 		else
881 881
 		{
882
-		    $negate=false;
882
+			$negate=false;
883 883
 		}
884 884
 		// First element : number, string or ()
885 885
 		list($type1,$val1) = $this->eval_getElement($rule,$item);
@@ -899,24 +899,24 @@  discard block
 block discarded – undo
899 899
 		// Third element : number, string or ()
900 900
 		if ( $rule[$item] == '!') // starts with a ! so evaluate whats next
901 901
 		{
902
-		    $item++;
903
-		    if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule);
904
-		    $val2= ! $this->evaluation($rule,$item);
905
-		    $type2=2; // result is a boolean 
902
+			$item++;
903
+			if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule);
904
+			$val2= ! $this->evaluation($rule,$item);
905
+			$type2=2; // result is a boolean 
906 906
 		}
907 907
 		else 
908 908
 		{
909
-		    list($type2,$val2) = $this->eval_getElement($rule,$item);
909
+			list($type2,$val2) = $this->eval_getElement($rule,$item);
910 910
 		}
911 911
 		//echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n";
912 912
 		
913 913
 		if ($type1!=$type2)  // cannot compare different types
914 914
 		{ 
915
-		    throw new Exception("Cannot compare string & number : ".$rule);
915
+			throw new Exception("Cannot compare string & number : ".$rule);
916 916
 		}
917 917
 		if ($typec==1 && $type1 !=2) // cannot use & or | with string/number
918 918
 		{
919
-		    throw new Exception("Cannot use boolean operators with string & number : ".$rule);
919
+			throw new Exception("Cannot use boolean operators with string & number : ".$rule);
920 920
 		}
921 921
 		
922 922
 		switch ($comp){
@@ -974,9 +974,9 @@  discard block
 block discarded – undo
974 974
 	}		
975 975
 	
976 976
 	/** Evaluation rule (uses eval_* functions recursively)
977
-	*	@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) )
978
-	*	@return bool : true : rule match, false : rule don't match , throw exception on error.
979
-	*/
977
+	 *	@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) )
978
+	 *	@return bool : true : rule match, false : rule don't match , throw exception on error.
979
+	 */
980 980
 	
981 981
 	protected function eval_rule($rule)
982 982
 	{
@@ -1021,7 +1021,7 @@  discard block
 block discarded – undo
1021 1021
 			}
1022 1022
 			if ($found==0)
1023 1023
 			{	// OID not found : throw error
1024
-			    throw new Exception('OID '.$oid.' not found in trap');
1024
+				throw new Exception('OID '.$oid.' not found in trap');
1025 1025
 			}
1026 1026
 		}
1027 1027
 		$item=0;
@@ -1032,7 +1032,7 @@  discard block
 block discarded – undo
1032 1032
 	}
1033 1033
 	
1034 1034
 	/** Match rules for current trap and do action
1035
-	*/
1035
+	 */
1036 1036
 	public function applyRules()
1037 1037
 	{
1038 1038
 		$rules = $this->getRules($this->trap_data['source_ip'],$this->trap_data['trap_oid']);
@@ -1069,12 +1069,12 @@  discard block
 block discarded – undo
1069 1069
 					{
1070 1070
 						if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
1071 1071
 						{
1072
-						    $this->trap_action.='Error sending status : check cmd/API';
1072
+							$this->trap_action.='Error sending status : check cmd/API';
1073 1073
 						}
1074 1074
 						else
1075 1075
 						{
1076
-						    $this->add_rule_match($rule['id'],$rule['num_match']+1);
1077
-						    $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1076
+							$this->add_rule_match($rule['id'],$rule['num_match']+1);
1077
+							$this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1078 1078
 						}
1079 1079
 					}
1080 1080
 					else
@@ -1091,15 +1091,15 @@  discard block
 block discarded – undo
1091 1091
 					$this->logging->log('action NOK : '.$action,INFO );
1092 1092
 					if ($action >= 0)
1093 1093
 					{
1094
-					    if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
1095
-					    {
1096
-					        $this->trap_action.='Error sending status : check cmd/API';
1097
-					    }
1098
-					    else
1099
-					    {
1100
-    						$this->add_rule_match($rule['id'],$rule['num_match']+1);
1101
-    						$this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1102
-					    }
1094
+						if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
1095
+						{
1096
+							$this->trap_action.='Error sending status : check cmd/API';
1097
+						}
1098
+						else
1099
+						{
1100
+							$this->add_rule_match($rule['id'],$rule['num_match']+1);
1101
+							$this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1102
+						}
1103 1103
 					}
1104 1104
 					else
1105 1105
 					{
@@ -1122,9 +1122,9 @@  discard block
 block discarded – undo
1122 1122
 			}
1123 1123
 			catch (Exception $e) 
1124 1124
 			{ 
1125
-			    $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
1126
-			    $this->trap_action.=' ERR : '.$e->getMessage();
1127
-			    $this->trap_data['status']='error';
1125
+				$this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
1126
+				$this->trap_action.=' ERR : '.$e->getMessage();
1127
+				$this->trap_data['status']='error';
1128 1128
 			}
1129 1129
 			
1130 1130
 		}
@@ -1139,8 +1139,8 @@  discard block
 block discarded – undo
1139 1139
 	}
1140 1140
 
1141 1141
 	/** Add Time a action to rule
1142
-	*	@param string $time : time to process to insert in SQL
1143
-	*/
1142
+	 *	@param string $time : time to process to insert in SQL
1143
+	 */
1144 1144
 	public function add_rule_final($time)
1145 1145
 	{
1146 1146
 		$db_conn=$this->trapsDB->db_connect_trap();
@@ -1157,9 +1157,9 @@  discard block
 block discarded – undo
1157 1157
 	/*********** UTILITIES *********************/
1158 1158
 	
1159 1159
 	/** Create database schema 
1160
-	*	@param $schema_file	string File to read schema from
1161
-	*	@param $table_prefix string to replace #PREFIX# in schema file by this
1162
-	*/
1160
+	 *	@param $schema_file	string File to read schema from
1161
+	 *	@param $table_prefix string to replace #PREFIX# in schema file by this
1162
+	 */
1163 1163
 	public function create_schema($schema_file,$table_prefix)
1164 1164
 	{
1165 1165
 		//Read data from snmptrapd from stdin
@@ -1179,30 +1179,30 @@  discard block
 block discarded – undo
1179 1179
 		{
1180 1180
 			$newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line));
1181 1181
 			if (preg_match('/; *$/', $newline)) 
1182
-            {
1183
-                $sql= $newline;
1184
-                if ($db_conn->query($sql) === false) {
1185
-                    $this->logging->log('Error create schema : '.$sql,ERROR,'');
1186
-                }
1187
-                if (preg_match('/^ *CREATE TABLE ([^ ]+)/',$newline,$cur_table_array))
1188
-                {
1189
-                    $cur_table='table '.$cur_table_array[1];
1190
-                }
1191
-                else
1192
-                {
1193
-                    $cur_table='secret SQL stuff :-)';
1194
-                }
1195
-                $this->logging->log('Creating : ' . $cur_table,INFO );
1196
-                $newline='';
1197
-            }
1182
+			{
1183
+				$sql= $newline;
1184
+				if ($db_conn->query($sql) === false) {
1185
+					$this->logging->log('Error create schema : '.$sql,ERROR,'');
1186
+				}
1187
+				if (preg_match('/^ *CREATE TABLE ([^ ]+)/',$newline,$cur_table_array))
1188
+				{
1189
+					$cur_table='table '.$cur_table_array[1];
1190
+				}
1191
+				else
1192
+				{
1193
+					$cur_table='secret SQL stuff :-)';
1194
+				}
1195
+				$this->logging->log('Creating : ' . $cur_table,INFO );
1196
+				$newline='';
1197
+			}
1198 1198
 		}
1199 1199
 		
1200 1200
 		$sql= $newline;
1201 1201
 		if ($sql != '')
1202 1202
 		{
1203
-    		if ($db_conn->query($sql) === false) {
1204
-    			$this->logging->log('Error create schema : '.$sql,ERROR,'');
1205
-    		}
1203
+			if ($db_conn->query($sql) === false) {
1204
+				$this->logging->log('Error create schema : '.$sql,ERROR,'');
1205
+			}
1206 1206
 		}
1207 1207
 		$this->logging->log('Schema created',INFO);		
1208 1208
 	}
@@ -1217,113 +1217,113 @@  discard block
 block discarded – undo
1217 1217
 	 */
1218 1218
 	public function update_schema($prefix,$target_version,$table_prefix,$getmsg=false)
1219 1219
 	{
1220
-	    // Get current db number
1221
-	    $db_conn=$this->trapsDB->db_connect_trap();
1222
-	    $sql='SELECT id,value from '.$this->db_prefix.'db_config WHERE name=\'db_version\' ';
1223
-	    $this->logging->log('SQL query : '.$sql,DEBUG );
1224
-	    if (($ret_code=$db_conn->query($sql)) === false) {
1225
-	        $this->logging->log('Cannot get db version. Query : ' . $sql,2,'');
1226
-	        return;
1227
-	    }
1228
-	    $version=$ret_code->fetchAll();
1229
-	    $cur_version=$version[0]['value'];
1230
-	    $db_version_id=$version[0]['id'];
1220
+		// Get current db number
1221
+		$db_conn=$this->trapsDB->db_connect_trap();
1222
+		$sql='SELECT id,value from '.$this->db_prefix.'db_config WHERE name=\'db_version\' ';
1223
+		$this->logging->log('SQL query : '.$sql,DEBUG );
1224
+		if (($ret_code=$db_conn->query($sql)) === false) {
1225
+			$this->logging->log('Cannot get db version. Query : ' . $sql,2,'');
1226
+			return;
1227
+		}
1228
+		$version=$ret_code->fetchAll();
1229
+		$cur_version=$version[0]['value'];
1230
+		$db_version_id=$version[0]['id'];
1231 1231
 	    
1232
-	    if ($this->trapsDB->trapDBType == 'pgsql')
1233
-	    {
1234
-	        $prefix .= 'update_pgsql/schema_';
1235
-	    }
1236
-	    else
1237
-	    {
1238
-	        $prefix .= 'update_sql/schema_';
1239
-	    }
1240
-	    //echo "version all :\n";print_r($version);echo " \n $cur_ver \n";
1241
-	    if ($getmsg === true)
1242
-	    {
1243
-	        $message='';
1244
-	        $this->logging->log('getting message for upgrade',DEBUG );
1245
-	        while($cur_version<$target_version)
1246
-	        {
1247
-	            $cur_version++;
1248
-	            $updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql';
1249
-	            $input_stream=fopen($updateFile, 'r');
1250
-	            if ($input_stream=== false)
1251
-	            {
1252
-	                $this->logging->log("Error reading update file ". $updateFile,2,'');
1253
-	                return;
1254
-	            }
1255
-	            do { $line=fgets($input_stream); }
1256
-	            while ($line !== false && !preg_match('/#MESSAGE/',$line));
1257
-	            if ($line === false)
1258
-	            {
1259
-	                $this->logging->log("No message in file ". $updateFile,2,'');
1260
-	                return;
1261
-	            }
1262
-	            $message .= ($cur_version-1) . '->' . $cur_version. ' : ' . preg_replace('/#MESSAGE : /','',$line)."\n";
1263
-	        }
1264
-	        return $message;
1265
-	    }
1266
-	    while($cur_version<$target_version)
1267
-	    { // tODO : execute pre & post scripts
1268
-	       $cur_version++;
1269
-	       $this->logging->log('Updating to version : ' .$cur_version ,INFO );
1270
-	       $updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql';
1271
-	       $input_stream=fopen($updateFile, 'r');
1272
-	       if ($input_stream=== false)
1273
-	       {
1274
-	           $this->logging->log("Error reading update file ". $updateFile,2,'');
1275
-	           return;
1276
-	       }
1277
-	       $newline='';
1278
-	       $db_conn=$this->trapsDB->db_connect_trap();
1279
-	       $db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
1280
-	       while (($line=fgets($input_stream)) !== false)
1281
-	       {
1282
-	           if (preg_match('/^#/', $line)) continue; // ignore comment lines
1283
-	           $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line));
1284
-	           if (preg_match('/; *$/', $newline))
1285
-	           {
1286
-	               $sql_req=$db_conn->prepare($newline);
1287
-	               if ($sql_req->execute() === false) {
1288
-	                   $this->logging->log('Error create schema : '.$newline,1,'');
1289
-	               }
1290
-	               $cur_table_array=array();
1291
-	               if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/',$newline,$cur_table_array))
1292
-	               {
1293
-	                   $cur_table=$cur_table_array[1] . ' SQL table '.$cur_table_array[2];
1294
-	               }
1295
-	               else
1296
-	               {
1297
-	                   $cur_table='secret SQL stuff :-)';
1298
-	                   //$cur_table=$newline;
1299
-	               }
1300
-	               $this->logging->log('Doing : ' . $cur_table,INFO );
1232
+		if ($this->trapsDB->trapDBType == 'pgsql')
1233
+		{
1234
+			$prefix .= 'update_pgsql/schema_';
1235
+		}
1236
+		else
1237
+		{
1238
+			$prefix .= 'update_sql/schema_';
1239
+		}
1240
+		//echo "version all :\n";print_r($version);echo " \n $cur_ver \n";
1241
+		if ($getmsg === true)
1242
+		{
1243
+			$message='';
1244
+			$this->logging->log('getting message for upgrade',DEBUG );
1245
+			while($cur_version<$target_version)
1246
+			{
1247
+				$cur_version++;
1248
+				$updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql';
1249
+				$input_stream=fopen($updateFile, 'r');
1250
+				if ($input_stream=== false)
1251
+				{
1252
+					$this->logging->log("Error reading update file ". $updateFile,2,'');
1253
+					return;
1254
+				}
1255
+				do { $line=fgets($input_stream); }
1256
+				while ($line !== false && !preg_match('/#MESSAGE/',$line));
1257
+				if ($line === false)
1258
+				{
1259
+					$this->logging->log("No message in file ". $updateFile,2,'');
1260
+					return;
1261
+				}
1262
+				$message .= ($cur_version-1) . '->' . $cur_version. ' : ' . preg_replace('/#MESSAGE : /','',$line)."\n";
1263
+			}
1264
+			return $message;
1265
+		}
1266
+		while($cur_version<$target_version)
1267
+		{ // tODO : execute pre & post scripts
1268
+		   $cur_version++;
1269
+		   $this->logging->log('Updating to version : ' .$cur_version ,INFO );
1270
+		   $updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql';
1271
+		   $input_stream=fopen($updateFile, 'r');
1272
+		   if ($input_stream=== false)
1273
+		   {
1274
+			   $this->logging->log("Error reading update file ". $updateFile,2,'');
1275
+			   return;
1276
+		   }
1277
+		   $newline='';
1278
+		   $db_conn=$this->trapsDB->db_connect_trap();
1279
+		   $db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
1280
+		   while (($line=fgets($input_stream)) !== false)
1281
+		   {
1282
+			   if (preg_match('/^#/', $line)) continue; // ignore comment lines
1283
+			   $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line));
1284
+			   if (preg_match('/; *$/', $newline))
1285
+			   {
1286
+				   $sql_req=$db_conn->prepare($newline);
1287
+				   if ($sql_req->execute() === false) {
1288
+					   $this->logging->log('Error create schema : '.$newline,1,'');
1289
+				   }
1290
+				   $cur_table_array=array();
1291
+				   if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/',$newline,$cur_table_array))
1292
+				   {
1293
+					   $cur_table=$cur_table_array[1] . ' SQL table '.$cur_table_array[2];
1294
+				   }
1295
+				   else
1296
+				   {
1297
+					   $cur_table='secret SQL stuff :-)';
1298
+					   //$cur_table=$newline;
1299
+				   }
1300
+				   $this->logging->log('Doing : ' . $cur_table,INFO );
1301 1301
 	               
1302
-	               $newline='';
1303
-	           }
1304
-	       }
1305
-	       fclose($input_stream);
1302
+				   $newline='';
1303
+			   }
1304
+		   }
1305
+		   fclose($input_stream);
1306 1306
 	       
1307
-	       //$sql= $newline;
1308
-	       //if ($db_conn->query($sql) === false) {
1309
-	       //    $this->logging->log('Error updating schema : '.$sql,1,'');
1310
-	       //}
1307
+		   //$sql= $newline;
1308
+		   //if ($db_conn->query($sql) === false) {
1309
+		   //    $this->logging->log('Error updating schema : '.$sql,1,'');
1310
+		   //}
1311 1311
 	       
1312
-	       $sql='UPDATE '.$this->db_prefix.'db_config SET value='.$cur_version.' WHERE ( id = '.$db_version_id.' )';
1313
-	       $this->logging->log('SQL query : '.$sql,DEBUG );
1314
-	       if ($db_conn->query($sql) === false) {
1315
-	           $this->logging->log('Cannot update db version. Query : ' . $sql,2);
1316
-	           return;
1317
-	       }
1312
+		   $sql='UPDATE '.$this->db_prefix.'db_config SET value='.$cur_version.' WHERE ( id = '.$db_version_id.' )';
1313
+		   $this->logging->log('SQL query : '.$sql,DEBUG );
1314
+		   if ($db_conn->query($sql) === false) {
1315
+			   $this->logging->log('Cannot update db version. Query : ' . $sql,2);
1316
+			   return;
1317
+		   }
1318 1318
 	       
1319
-	       $this->logging->log('Schema updated to version : '.$cur_version ,INFO);
1320
-	    }
1319
+		   $this->logging->log('Schema updated to version : '.$cur_version ,INFO);
1320
+		}
1321 1321
 	}
1322 1322
 	
1323 1323
 	/** reset service to OK after time defined in rule
1324
-	*	TODO logic is : get all service in error + all rules, see if getting all rules then select services is better 
1325
-	*	@return integer : not in use
1326
-	**/
1324
+	 *	TODO logic is : get all service in error + all rules, see if getting all rules then select services is better 
1325
+	 *	@return integer : not in use
1326
+	 **/
1327 1327
 	public function reset_services()
1328 1328
 	{
1329 1329
 		// Get all services not in 'ok' state
@@ -1395,105 +1395,105 @@  discard block
 block discarded – undo
1395 1395
 		$description=$db_conn->quote($description);
1396 1396
 		if (isset($this->dbOidIndex[$oid]))
1397 1397
 		{
1398
-		    if ($this->dbOidIndex[$oid]['key'] == -1)
1399
-		    { // newly created.
1400
-		        return 0;
1401
-		    }
1398
+			if ($this->dbOidIndex[$oid]['key'] == -1)
1399
+			{ // newly created.
1400
+				return 0;
1401
+			}
1402 1402
 			if ( $name != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['name'] ||
1403
-			    $mib != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['mib'] ||
1404
-			    $type != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type'] //||
1405
-			    //$textConv != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['textual_convention'] //||
1406
-			    //$dispHint != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['display_hint'] ||
1407
-			    //$syntax != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['syntax'] ||
1408
-			    //$type_enum != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type_enum'] ||
1409
-			    //$description != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['description']
1410
-			    )
1403
+				$mib != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['mib'] ||
1404
+				$type != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type'] //||
1405
+				//$textConv != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['textual_convention'] //||
1406
+				//$dispHint != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['display_hint'] ||
1407
+				//$syntax != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['syntax'] ||
1408
+				//$type_enum != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type_enum'] ||
1409
+				//$description != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['description']
1410
+				)
1411 1411
 			{ // Do update
1412
-			    $sql='UPDATE '.$this->db_prefix.'mib_cache SET '.
1413
- 			    'name = :name , type = :type , mib = :mib , textual_convention = :tc , display_hint = :display_hint'. 
1414
- 			    ', syntax = :syntax, type_enum = :type_enum, description = :description '.
1415
- 			    ' WHERE id= :id';
1416
-			    $sqlQuery=$db_conn->prepare($sql);
1412
+				$sql='UPDATE '.$this->db_prefix.'mib_cache SET '.
1413
+ 				'name = :name , type = :type , mib = :mib , textual_convention = :tc , display_hint = :display_hint'. 
1414
+ 				', syntax = :syntax, type_enum = :type_enum, description = :description '.
1415
+ 				' WHERE id= :id';
1416
+				$sqlQuery=$db_conn->prepare($sql);
1417 1417
 			    
1418
-			    $sqlParam=array(
1419
-			        ':name' => $name,
1420
-			        ':type' => $type, 
1421
-			        ':mib' => $mib, 
1422
-			        ':tc' =>  ($textConv==null)?'null':$textConv , 
1423
-			        ':display_hint' => ($dispHint==null)?'null':$dispHint ,
1424
-			        ':syntax' => ($syntax==null)?'null':$syntax,
1425
-			        ':type_enum' => ($type_enum==null)?'null':$type_enum, 
1426
-			        ':description' => ($description==null)?'null':$description,
1427
-			        ':id' => $this->dbOidAll[$this->dbOidIndex[$oid]['id']]
1428
-			    );
1418
+				$sqlParam=array(
1419
+					':name' => $name,
1420
+					':type' => $type, 
1421
+					':mib' => $mib, 
1422
+					':tc' =>  ($textConv==null)?'null':$textConv , 
1423
+					':display_hint' => ($dispHint==null)?'null':$dispHint ,
1424
+					':syntax' => ($syntax==null)?'null':$syntax,
1425
+					':type_enum' => ($type_enum==null)?'null':$type_enum, 
1426
+					':description' => ($description==null)?'null':$description,
1427
+					':id' => $this->dbOidAll[$this->dbOidIndex[$oid]['id']]
1428
+				);
1429 1429
 			    
1430
-			    if ($sqlQuery->execute($sqlParam) === false) {
1431
-			        $this->logging->log('Error in query : ' . $sql,ERROR,'');
1432
-			    }
1433
-			    $this->logging->log('Trap updated : '.$name . ' / OID : '.$oid,DEBUG );
1430
+				if ($sqlQuery->execute($sqlParam) === false) {
1431
+					$this->logging->log('Error in query : ' . $sql,ERROR,'');
1432
+				}
1433
+				$this->logging->log('Trap updated : '.$name . ' / OID : '.$oid,DEBUG );
1434 1434
 				return 1;
1435 1435
 			}
1436 1436
 			else
1437 1437
 			{
1438
-			    $this->logging->log('Trap unchanged : '.$name . ' / OID : '.$oid,DEBUG );
1439
-			    return 0;
1438
+				$this->logging->log('Trap unchanged : '.$name . ' / OID : '.$oid,DEBUG );
1439
+				return 0;
1440 1440
 			}
1441 1441
 		}
1442
-        // create new OID.
1442
+		// create new OID.
1443 1443
 			
1444 1444
 		// Insert data
1445 1445
 
1446 1446
 		$sql='INSERT INTO '.$this->db_prefix.'mib_cache '.
1447
-		      '(oid, name, type , mib, textual_convention, display_hint '.
1448
-              ', syntax, type_enum , description ) ' . 
1449
-              'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
1450
-              ', :syntax, :type_enum, :description )';
1447
+			  '(oid, name, type , mib, textual_convention, display_hint '.
1448
+			  ', syntax, type_enum , description ) ' . 
1449
+			  'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
1450
+			  ', :syntax, :type_enum, :description )';
1451 1451
         
1452 1452
 		if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id';
1453 1453
 		
1454 1454
 		$sqlQuery=$db_conn->prepare($sql);
1455 1455
 		
1456 1456
 		$sqlParam=array(
1457
-		    ':oid' => $oid,
1458
-		    ':name' => $name,
1459
-		    ':type' => $type,
1460
-		    ':mib' => $mib,
1461
-		    ':tc' =>  ($textConv==null)?'null':$textConv ,
1462
-		    ':display_hint' => ($dispHint==null)?'null':$dispHint ,
1463
-		    ':syntax' => ($syntax==null)?'null':$syntax,
1464
-		    ':type_enum' => ($type_enum==null)?'null':$type_enum,
1465
-		    ':description' => ($description==null)?'null':$description
1457
+			':oid' => $oid,
1458
+			':name' => $name,
1459
+			':type' => $type,
1460
+			':mib' => $mib,
1461
+			':tc' =>  ($textConv==null)?'null':$textConv ,
1462
+			':display_hint' => ($dispHint==null)?'null':$dispHint ,
1463
+			':syntax' => ($syntax==null)?'null':$syntax,
1464
+			':type_enum' => ($type_enum==null)?'null':$type_enum,
1465
+			':description' => ($description==null)?'null':$description
1466 1466
 		);
1467 1467
 		
1468 1468
 		if ($sqlQuery->execute($sqlParam) === false) {
1469
-		    $this->logging->log('Error in query : ' . $sql,1,'');
1469
+			$this->logging->log('Error in query : ' . $sql,1,'');
1470 1470
 		}
1471 1471
 		
1472 1472
 		switch ($this->trapsDB->trapDBType)
1473 1473
 		{
1474
-		    case 'pgsql':
1475
-		        // Get last id to insert oid/values in secondary table
1476
-		        if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {		            
1477
-		            $this->logging->log('Error getting id - pgsql - ',1,'');
1478
-		        }
1479
-		        if (! isset($inserted_id_ret['id'])) {
1480
-		            $this->logging->log('Error getting id - pgsql - empty.',1,'');
1481
-		        }
1482
-		        $this->dbOidIndex[$oid]['id']=$inserted_id_ret['id'];
1483
-		        break;
1484
-		    case 'mysql':
1485
-		        // Get last id to insert oid/values in secondary table
1486
-		        $sql='SELECT LAST_INSERT_ID();';
1487
-		        if (($ret_code=$db_conn->query($sql)) === false) {
1488
-		            $this->logging->log('Erreur getting id - mysql - ',1,'');
1489
-		        }
1474
+			case 'pgsql':
1475
+				// Get last id to insert oid/values in secondary table
1476
+				if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {		            
1477
+					$this->logging->log('Error getting id - pgsql - ',1,'');
1478
+				}
1479
+				if (! isset($inserted_id_ret['id'])) {
1480
+					$this->logging->log('Error getting id - pgsql - empty.',1,'');
1481
+				}
1482
+				$this->dbOidIndex[$oid]['id']=$inserted_id_ret['id'];
1483
+				break;
1484
+			case 'mysql':
1485
+				// Get last id to insert oid/values in secondary table
1486
+				$sql='SELECT LAST_INSERT_ID();';
1487
+				if (($ret_code=$db_conn->query($sql)) === false) {
1488
+					$this->logging->log('Erreur getting id - mysql - ',1,'');
1489
+				}
1490 1490
 		        
1491
-		        $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
1492
-		        if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
1493
-		        $this->dbOidIndex[$oid]['id']=$inserted_id;
1494
-		        break;
1495
-		    default:
1496
-		        $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,1,'');
1491
+				$inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
1492
+				if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
1493
+				$this->dbOidIndex[$oid]['id']=$inserted_id;
1494
+				break;
1495
+			default:
1496
+				$this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,1,'');
1497 1497
 		}
1498 1498
 
1499 1499
 		// Set as newly created.
@@ -1501,148 +1501,148 @@  discard block
 block discarded – undo
1501 1501
 		return 2;
1502 1502
 	}
1503 1503
 
1504
-    /**
1505
-     * create or update (with check_existing = true) objects of trap
1506
-     * @param string $trapOID : trap oid
1507
-     * @param string $trapmib : mib of trap
1508
-     * @param array $objects : array of objects name (without MIB)
1509
-     * @param bool $check_existing : check instead of create
1510
-     */
1504
+	/**
1505
+	 * create or update (with check_existing = true) objects of trap
1506
+	 * @param string $trapOID : trap oid
1507
+	 * @param string $trapmib : mib of trap
1508
+	 * @param array $objects : array of objects name (without MIB)
1509
+	 * @param bool $check_existing : check instead of create
1510
+	 */
1511 1511
 	public function trap_objects($trapOID,$trapmib,$objects,$check_existing)
1512 1512
 	{
1513
-	    $dbObjects=null; // cache of objects for trap in db
1514
-	    $db_conn=$this->trapsDB->db_connect_trap();
1513
+		$dbObjects=null; // cache of objects for trap in db
1514
+		$db_conn=$this->trapsDB->db_connect_trap();
1515 1515
 	    
1516
-	    // Get id of trapmib.
1516
+		// Get id of trapmib.
1517 1517
 
1518
-	    $trapId = $this->dbOidIndex[$trapOID]['id'];
1519
-	    if ($check_existing === true)
1520
-	    {
1521
-	        // Get all objects
1522
-	        $sql='SELECT * FROM '.$this->db_prefix.'mib_cache_trap_object where trap_id='.$trapId.';';
1523
-	        $this->logging->log('SQL query get all traps: '.$sql,DEBUG );
1524
-	        if (($ret_code=$db_conn->query($sql)) === false) {
1525
-	            $this->logging->log('No result in query : ' . $sql,1,'');
1526
-	        }
1527
-	        $dbObjectsRaw=$ret_code->fetchAll();
1518
+		$trapId = $this->dbOidIndex[$trapOID]['id'];
1519
+		if ($check_existing === true)
1520
+		{
1521
+			// Get all objects
1522
+			$sql='SELECT * FROM '.$this->db_prefix.'mib_cache_trap_object where trap_id='.$trapId.';';
1523
+			$this->logging->log('SQL query get all traps: '.$sql,DEBUG );
1524
+			if (($ret_code=$db_conn->query($sql)) === false) {
1525
+				$this->logging->log('No result in query : ' . $sql,1,'');
1526
+			}
1527
+			$dbObjectsRaw=$ret_code->fetchAll();
1528 1528
 	        
1529
-	        foreach ($dbObjectsRaw as $val)
1530
-	        {
1531
-	            $dbObjects[$val['object_id']]=1;
1532
-	        }
1533
-	    }
1534
-	    foreach ($objects as $object)
1535
-	    {
1536
-	        $match=$snmptrans=array();
1537
-	        $retVal=0;
1538
-	        $objOid=$objTc=$objDispHint=$objSyntax=$objDesc=$objEnum=NULL;
1539
-	        $tmpdesc='';$indesc=false;
1529
+			foreach ($dbObjectsRaw as $val)
1530
+			{
1531
+				$dbObjects[$val['object_id']]=1;
1532
+			}
1533
+		}
1534
+		foreach ($objects as $object)
1535
+		{
1536
+			$match=$snmptrans=array();
1537
+			$retVal=0;
1538
+			$objOid=$objTc=$objDispHint=$objSyntax=$objDesc=$objEnum=NULL;
1539
+			$tmpdesc='';$indesc=false;
1540 1540
 	        
1541
-	        $objMib=$trapmib;
1542
-	        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1543
-	            ' -On -Td '.$objMib.'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
1544
-	        if ($retVal!=0)
1545
-	        {
1546
-	            // Maybe not trap mib, search with IR
1547
-	            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1548
-	                ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
1549
-	            if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
1550
-	            { // Not found -> continue with warning
1551
-	               $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
1552
-	               continue;
1553
-	            }
1554
-	            $objMib=$match[1];
1541
+			$objMib=$trapmib;
1542
+			exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1543
+				' -On -Td '.$objMib.'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
1544
+			if ($retVal!=0)
1545
+			{
1546
+				// Maybe not trap mib, search with IR
1547
+				exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1548
+					' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
1549
+				if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
1550
+				{ // Not found -> continue with warning
1551
+				   $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
1552
+				   continue;
1553
+				}
1554
+				$objMib=$match[1];
1555 1555
 	            
1556
-	            // Do the snmptranslate again.
1557
-	            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1558
-	                ' -On -Td '.$objMib.'::'.$object,$snmptrans,$retVal);
1559
-	            if ($retVal!=0) {
1560
-	                $this->logging->log('Error finding trap object : '.$objMib.'::'.$object,2,'');
1561
-	            }
1556
+				// Do the snmptranslate again.
1557
+				exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
1558
+					' -On -Td '.$objMib.'::'.$object,$snmptrans,$retVal);
1559
+				if ($retVal!=0) {
1560
+					$this->logging->log('Error finding trap object : '.$objMib.'::'.$object,2,'');
1561
+				}
1562 1562
 	            
1563
-	        }
1564
-	        foreach ($snmptrans as $line)
1565
-	        {
1566
-	            if ($indesc===true)
1567
-	            {
1568
-	                $line=preg_replace('/[\t ]+/',' ',$line);
1569
-	                if (preg_match('/(.*)"$/', $line,$match))
1570
-	                {
1571
-	                    $objDesc = $tmpdesc . $match[1];
1572
-	                    $indesc=false;
1573
-	                }
1574
-	                $tmpdesc.=$line;
1575
-	                continue;
1576
-	            }
1577
-	            if (preg_match('/^\.[0-9\.]+$/', $line))
1578
-	            {
1579
-	                $objOid=$line;
1580
-	                continue;
1581
-	            }
1582
-	            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
1583
-	            {
1584
-	                $objSyntax=$match[1];
1585
-                    $objEnum=$match[2];
1586
-	                continue;
1587
-	            }
1588
-	            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
1589
-	            {
1590
-	                $objSyntax=$match[1];
1591
-	                continue;
1592
-	            }
1593
-	            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
1594
-	            {
1595
-	                $objDispHint=$match[1];
1596
-	                continue;
1597
-	            }
1598
-	            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
1599
-	            {
1600
-	                $objDesc=$match[1];
1601
-	                continue;
1602
-	            }
1603
-	            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
1604
-	            {
1605
-	                $tmpdesc=$match[1];
1606
-	                $indesc=true;
1607
-	                continue;
1608
-	            }
1609
-	            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
1610
-	            {
1611
-	                $objTc=$match[1];
1612
-	                continue;
1613
-	            }
1614
-	        }
1615
-	        $this->logging->log("Adding trap $object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc",DEBUG );
1616
-	        //echo "$object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc / $objDesc\n";
1617
-	        // Update 
1618
-	        $this->update_oid($objOid, $objMib, $object, '3', $objTc, $objDispHint, $objSyntax, $objEnum,$objDesc);
1563
+			}
1564
+			foreach ($snmptrans as $line)
1565
+			{
1566
+				if ($indesc===true)
1567
+				{
1568
+					$line=preg_replace('/[\t ]+/',' ',$line);
1569
+					if (preg_match('/(.*)"$/', $line,$match))
1570
+					{
1571
+						$objDesc = $tmpdesc . $match[1];
1572
+						$indesc=false;
1573
+					}
1574
+					$tmpdesc.=$line;
1575
+					continue;
1576
+				}
1577
+				if (preg_match('/^\.[0-9\.]+$/', $line))
1578
+				{
1579
+					$objOid=$line;
1580
+					continue;
1581
+				}
1582
+				if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
1583
+				{
1584
+					$objSyntax=$match[1];
1585
+					$objEnum=$match[2];
1586
+					continue;
1587
+				}
1588
+				if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
1589
+				{
1590
+					$objSyntax=$match[1];
1591
+					continue;
1592
+				}
1593
+				if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
1594
+				{
1595
+					$objDispHint=$match[1];
1596
+					continue;
1597
+				}
1598
+				if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
1599
+				{
1600
+					$objDesc=$match[1];
1601
+					continue;
1602
+				}
1603
+				if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
1604
+				{
1605
+					$tmpdesc=$match[1];
1606
+					$indesc=true;
1607
+					continue;
1608
+				}
1609
+				if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
1610
+				{
1611
+					$objTc=$match[1];
1612
+					continue;
1613
+				}
1614
+			}
1615
+			$this->logging->log("Adding trap $object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc",DEBUG );
1616
+			//echo "$object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc / $objDesc\n";
1617
+			// Update 
1618
+			$this->update_oid($objOid, $objMib, $object, '3', $objTc, $objDispHint, $objSyntax, $objEnum,$objDesc);
1619 1619
             
1620
-	        if (isset($dbObjects[$this->dbOidIndex[$objOid]['id']]))
1621
-	        {   // if link exists, continue
1622
-	            $dbObjects[$this->dbOidIndex[$objOid]['id']]=2;
1623
-	            continue;
1624
-	        }
1625
-	        if ($check_existing === true) 
1626
-	        {
1627
-	            // TODO : check link trap - objects exists, mark them.
1628
-	        }
1629
-	        // Associate in object table
1630
-	        $sql='INSERT INTO '.$this->db_prefix.'mib_cache_trap_object (trap_id,object_id) '.
1631
-	   	        'values (:trap_id, :object_id)';	        
1632
-	        $sqlQuery=$db_conn->prepare($sql);	        
1633
-	        $sqlParam=array(
1634
-	            ':trap_id' => $trapId,
1635
-	            ':object_id' => $this->dbOidIndex[$objOid]['id'],
1636
-	        );
1620
+			if (isset($dbObjects[$this->dbOidIndex[$objOid]['id']]))
1621
+			{   // if link exists, continue
1622
+				$dbObjects[$this->dbOidIndex[$objOid]['id']]=2;
1623
+				continue;
1624
+			}
1625
+			if ($check_existing === true) 
1626
+			{
1627
+				// TODO : check link trap - objects exists, mark them.
1628
+			}
1629
+			// Associate in object table
1630
+			$sql='INSERT INTO '.$this->db_prefix.'mib_cache_trap_object (trap_id,object_id) '.
1631
+	   			'values (:trap_id, :object_id)';	        
1632
+			$sqlQuery=$db_conn->prepare($sql);	        
1633
+			$sqlParam=array(
1634
+				':trap_id' => $trapId,
1635
+				':object_id' => $this->dbOidIndex[$objOid]['id'],
1636
+			);
1637 1637
 	        
1638
-	        if ($sqlQuery->execute($sqlParam) === false) {
1639
-	            $this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$objOid]['id'] ,1,'');
1640
-	        }
1641
-	    }
1642
-	    if ($check_existing === true)
1643
-	    {
1644
-	        // TODO : remove link trap - objects that wasn't marked.
1645
-	    }
1638
+			if ($sqlQuery->execute($sqlParam) === false) {
1639
+				$this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$objOid]['id'] ,1,'');
1640
+			}
1641
+		}
1642
+		if ($check_existing === true)
1643
+		{
1644
+			// TODO : remove link trap - objects that wasn't marked.
1645
+		}
1646 1646
 	    
1647 1647
 	}
1648 1648
 	
@@ -1652,7 +1652,7 @@  discard block
 block discarded – undo
1652 1652
 	 * @param boolean $check_change : Force check of trap params & objects
1653 1653
 	 * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
1654 1654
 	 * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
1655
-	*/	
1655
+	 */	
1656 1656
 	public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
1657 1657
 	{
1658 1658
 		// Timing 
@@ -1704,7 +1704,7 @@  discard block
 block discarded – undo
1704 1704
 		
1705 1705
 		for ($curElement=0;$curElement < $numElements;$curElement++)
1706 1706
 		{
1707
-		    $time_1= microtime(true);
1707
+			$time_1= microtime(true);
1708 1708
 			if ((microtime(true)-$timeFiveSec) > 2 && $display_progress)
1709 1709
 			{ // echo a . every 2 sec
1710 1710
 				echo '.';
@@ -1722,8 +1722,8 @@  discard block
 block discarded – undo
1722 1722
 			// Get oid or pass if not found
1723 1723
 			if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
1724 1724
 			{
1725
-			    $time_parse1 += microtime(true) - $time_1;
1726
-			    $time_parse1N ++;
1725
+				$time_parse1 += microtime(true) - $time_1;
1726
+				$time_parse1N ++;
1727 1727
 				continue;
1728 1728
 			}
1729 1729
 			$oid=$this->objectsAll[$curElement];
@@ -1734,7 +1734,7 @@  discard block
 block discarded – undo
1734 1734
 			if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
1735 1735
 						$this->objectsAll[$curElement],$match))
1736 1736
 			{
1737
-			    $time_check1 += microtime(true) - $time_1;
1737
+				$time_check1 += microtime(true) - $time_1;
1738 1738
 				$time_check1N++;
1739 1739
 				continue;
1740 1740
 			}
@@ -1747,8 +1747,8 @@  discard block
 block discarded – undo
1747 1747
 				// Check if next is suboid -> in that case is cannot be a trap
1748 1748
 				if (preg_match("/^$oid/",$this->objectsAll[$curElement+1]))
1749 1749
 				{
1750
-				    $time_check2 += microtime(true) - $time_1;
1751
-				    $time_check2N++;
1750
+					$time_check2 += microtime(true) - $time_1;
1751
+					$time_check2N++;
1752 1752
 					continue;
1753 1753
 				}		
1754 1754
 				unset($snmptrans);
@@ -1756,8 +1756,8 @@  discard block
 block discarded – undo
1756 1756
 					' -Td '.$oid . ' | grep OBJECTS ',$snmptrans,$retVal);
1757 1757
 				if ($retVal!=0)
1758 1758
 				{
1759
-				    $time_check2 += microtime(true) - $time_1;
1760
-				    $time_check2N++;
1759
+					$time_check2 += microtime(true) - $time_1;
1760
+					$time_check2N++;
1761 1761
 					continue;
1762 1762
 				}
1763 1763
 				//echo "\n v1 trap found : $oid \n";
@@ -1766,7 +1766,7 @@  discard block
 block discarded – undo
1766 1766
 			}
1767 1767
 			if ($onlyTraps===true && $type!=21) // if only traps and not a trap, continue
1768 1768
 			{
1769
-			    $time_check3 += microtime(true) - $time_1;
1769
+				$time_check3 += microtime(true) - $time_1;
1770 1770
 				$time_check3N++;
1771 1771
 				continue;
1772 1772
 			}
@@ -1787,7 +1787,7 @@  discard block
 block discarded – undo
1787 1787
 			
1788 1788
 			if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
1789 1789
 			{
1790
-			    $this->logging->log('Error getting mib from trap '.$oid.' : ' . $snmptrans[0],1,'');
1790
+				$this->logging->log('Error getting mib from trap '.$oid.' : ' . $snmptrans[0],1,'');
1791 1791
 			}
1792 1792
 			$trapMib=$match[1];
1793 1793
 			
@@ -1795,17 +1795,17 @@  discard block
 block discarded – undo
1795 1795
 			while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
1796 1796
 			if (isset($snmptrans[$numLine]))
1797 1797
 			{
1798
-			    $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
1798
+				$snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
1799 1799
 
1800
-			    while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
1801
-			    {
1802
-			        $trapDesc.=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
1803
-			        $numLine++;
1804
-			    }
1805
-			    if (isset($snmptrans[$numLine])) {
1806
-			        $trapDesc.=preg_replace('/".*/','',$snmptrans[$numLine]);
1807
-			        $trapDesc=preg_replace('/[\t ]+/',' ',$trapDesc);
1808
-			    }
1800
+				while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
1801
+				{
1802
+					$trapDesc.=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
1803
+					$numLine++;
1804
+				}
1805
+				if (isset($snmptrans[$numLine])) {
1806
+					$trapDesc.=preg_replace('/".*/','',$snmptrans[$numLine]);
1807
+					$trapDesc=preg_replace('/[\t ]+/',' ',$trapDesc);
1808
+				}
1809 1809
 
1810 1810
 			}
1811 1811
 			$update=$this->update_oid($oid,$trapMib,$name,$type,NULL,NULL,NULL,NULL,$trapDesc);
@@ -1813,23 +1813,23 @@  discard block
 block discarded – undo
1813 1813
 			
1814 1814
 			if (($update==0) && ($check_change===false))
1815 1815
 			{ // Trapd didn't change & force check disabled
1816
-			    $time_objects += microtime(true) - $time_1;
1817
-			    if ($display_progress) echo "C";
1818
-			    continue;
1816
+				$time_objects += microtime(true) - $time_1;
1817
+				if ($display_progress) echo "C";
1818
+				continue;
1819 1819
 			}
1820 1820
 			
1821 1821
 			$synt=null;
1822 1822
 			foreach ($snmptrans as $line)
1823 1823
 			{	
1824
-    			if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
1825
-    				{
1826
-    					$synt=$match[1];
1827
-    				}
1824
+				if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
1825
+					{
1826
+						$synt=$match[1];
1827
+					}
1828 1828
 			}
1829 1829
 			if ($synt == null) 
1830 1830
 			{
1831 1831
 				//echo "No objects for $trapOID\n";
1832
-			    $time_objects += microtime(true) - $time_1;
1832
+				$time_objects += microtime(true) - $time_1;
1833 1833
 				continue;
1834 1834
 			}
1835 1835
 			//echo "$synt \n";
@@ -1848,18 +1848,18 @@  discard block
 block discarded – undo
1848 1848
 		
1849 1849
 		if ($display_progress)
1850 1850
 		{
1851
-    		echo "\nNumber of processed traps : $time_num_traps \n";
1852
-    		echo "\nParsing : " . number_format($time_parse1+$time_check1,1) ." sec / " . ($time_parse1N+ $time_check1N)  . " occurences\n";
1853
-    		echo "Detecting traps : " . number_format($time_check2+$time_check3,1) . " sec / " . ($time_check2N+$time_check3N) ." occurences\n";
1854
-    		echo "Trap processing ($time_updateN): ".number_format($time_update,1)." sec , ";
1855
-    		echo "Objects processing ($time_objectsN) : ".number_format($time_objects,1)." sec \n";
1851
+			echo "\nNumber of processed traps : $time_num_traps \n";
1852
+			echo "\nParsing : " . number_format($time_parse1+$time_check1,1) ." sec / " . ($time_parse1N+ $time_check1N)  . " occurences\n";
1853
+			echo "Detecting traps : " . number_format($time_check2+$time_check3,1) . " sec / " . ($time_check2N+$time_check3N) ." occurences\n";
1854
+			echo "Trap processing ($time_updateN): ".number_format($time_update,1)." sec , ";
1855
+			echo "Objects processing ($time_objectsN) : ".number_format($time_objects,1)." sec \n";
1856 1856
 		}
1857 1857
 		
1858 1858
 		// Timing ends
1859 1859
 		$timeTaken=microtime(true) - $timeTaken;
1860 1860
 		if ($display_progress)
1861 1861
 		{
1862
-		    echo "Global time : ".round($timeTaken)." seconds\n";
1862
+			echo "Global time : ".round($timeTaken)." seconds\n";
1863 1863
 		}
1864 1864
 		
1865 1865
 	}
Please login to merge, or discard this patch.
library/Trapdirector/TrapsController.php 1 patch
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
 	protected $trapClass;		//< Trap class for bin/trap_class.php
33 33
 		
34 34
 	/** Get instance of TrapModuleConfig class
35
-	*	@return TrapModuleConfig
36
-	*/
35
+	 *	@return TrapModuleConfig
36
+	 */
37 37
 	public function getModuleConfig() 
38 38
 	{
39 39
 		if ($this->moduleConfig == Null) 
@@ -58,12 +58,12 @@  discard block
 block discarded – undo
58 58
 	
59 59
 	public function getTrapHostListTable()
60 60
 	{
61
-	    if ($this->trapTableHostList == Null) 
61
+		if ($this->trapTableHostList == Null) 
62 62
 		{
63
-	        $this->trapTableHostList = new TrapTableHostList();
64
-	        $this->trapTableHostList->setConfig($this->getModuleConfig());
65
-	    }
66
-	    return $this->trapTableHostList;
63
+			$this->trapTableHostList = new TrapTableHostList();
64
+			$this->trapTableHostList->setConfig($this->getModuleConfig());
65
+		}
66
+		return $this->trapTableHostList;
67 67
 	}
68 68
 	
69 69
 	public function getHandlerListTable() 
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
 	}	
78 78
 	
79 79
 	/**	Get Database connexion
80
-	*	@param $DBname string DB name in resource.ini_ge
81
-	*	@param $test bool if set to true, returns error code and not database
82
-	*	@param $test_version bool if set to flase, does not test database version of trapDB
83
-	*	@return array<integer,mixed>|mixed : if test=false, returns DB connexion, else array(error_num,message) or null on error.
84
-	*/
80
+	 *	@param $DBname string DB name in resource.ini_ge
81
+	 *	@param $test bool if set to true, returns error code and not database
82
+	 *	@param $test_version bool if set to flase, does not test database version of trapDB
83
+	 *	@return array<integer,mixed>|mixed : if test=false, returns DB connexion, else array(error_num,message) or null on error.
84
+	 */
85 85
 	public function getDbByName($DBname,$test=false,$test_version=true)
86 86
 	{
87 87
 		try 
@@ -166,20 +166,20 @@  discard block
 block discarded – undo
166 166
 
167 167
 		if ( ! $dbresource )
168 168
 		{
169
-		    if ($test) return array(1,'No database in config.ini');
170
-		    $this->redirectNow('trapdirector/settings?idodberror=1');
171
-		    return null;
169
+			if ($test) return array(1,'No database in config.ini');
170
+			$this->redirectNow('trapdirector/settings?idodberror=1');
171
+			return null;
172 172
 		}
173 173
 		
174 174
 		try
175 175
 		{
176
-		    $dbconn = IcingaDbConnection::fromResourceName($dbresource);
176
+			$dbconn = IcingaDbConnection::fromResourceName($dbresource);
177 177
 		}
178 178
 		catch (Exception $e)
179 179
 		{
180
-		    if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2");
181
-		    $this->redirectNow('trapdirector/settings?idodberror=2');
182
-		    return null;
180
+			if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2");
181
+			$this->redirectNow('trapdirector/settings?idodberror=2');
182
+			return null;
183 183
 		}
184 184
 		
185 185
 		if ($test == false) 
@@ -190,13 +190,13 @@  discard block
 block discarded – undo
190 190
 		
191 191
 		try
192 192
 		{
193
-		    $query = $dbconn->select()
194
-		    ->from('icinga_dbversion',array('version'));
195
-		    $version=$dbconn->fetchRow($query);
196
-		    if ( ($version == null) || ! property_exists($version,'version') )
197
-		    {
198
-		        return array(4,"$dbresource does not look like an IDO database");
199
-		    }
193
+			$query = $dbconn->select()
194
+			->from('icinga_dbversion',array('version'));
195
+			$version=$dbconn->fetchRow($query);
196
+			if ( ($version == null) || ! property_exists($version,'version') )
197
+			{
198
+				return array(4,"$dbresource does not look like an IDO database");
199
+			}
200 200
 		}
201 201
 		catch (Exception $e)
202 202
 		{
@@ -206,15 +206,15 @@  discard block
 block discarded – undo
206 206
 		return array(0,'');
207 207
 	}
208 208
 	
209
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
210
-    {
211
-        $limit = $this->params->get('limit', $limit);
212
-        $page = $this->params->get('page', $offset);
209
+	protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
210
+	{
211
+		$limit = $this->params->get('limit', $limit);
212
+		$page = $this->params->get('page', $offset);
213 213
 
214
-        $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
214
+		$paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
215 215
 
216
-        return $paginatable;
217
-    }	
216
+		return $paginatable;
217
+	}	
218 218
 	
219 219
 	public function displayExitError($source,$message)
220 220
 	{	// TODO : check better ways to transmit data (with POST ?)
@@ -223,33 +223,33 @@  discard block
 block discarded – undo
223 223
 	
224 224
 	protected function checkReadPermission()
225 225
 	{
226
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
227
-            $this->displayExitError('Permissions','No permission fo view content');
228
-        }		
226
+		if (! $this->Auth()->hasPermission('trapdirector/view')) {
227
+			$this->displayExitError('Permissions','No permission fo view content');
228
+		}		
229 229
 	}
230 230
 
231 231
 	protected function checkConfigPermission()
232 232
 	{
233
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
234
-            $this->displayExitError('Permissions','No permission fo configure');
235
-        }		
233
+		if (! $this->Auth()->hasPermission('trapdirector/config')) {
234
+			$this->displayExitError('Permissions','No permission fo configure');
235
+		}		
236 236
 	}
237 237
 	
238
-    /**
239
-     * Check if user has write permission
240
-     * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page
241
-     * @return boolean : user has permission
242
-     */
238
+	/**
239
+	 * Check if user has write permission
240
+	 * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page
241
+	 * @return boolean : user has permission
242
+	 */
243 243
 	protected function checkModuleConfigPermission($check=0)
244 244
 	{
245
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
246
-            if ($check == 0)
247
-            {
248
-                $this->displayExitError('Permissions','No permission fo configure module');
249
-            }
250
-            return false;
251
-        }
252
-        return true;
245
+		if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
246
+			if ($check == 0)
247
+			{
248
+				$this->displayExitError('Permissions','No permission fo configure module');
249
+			}
250
+			return false;
251
+		}
252
+		return true;
253 253
 	}
254 254
 
255 255
 	/*************************  Trap class get **********************/
@@ -269,8 +269,8 @@  discard block
 block discarded – undo
269 269
 	/************************** MIB related **************************/
270 270
 	
271 271
 	/** Get MIBLoader class
272
-	*	@return MIBLoader class
273
-	*/
272
+	 *	@return MIBLoader class
273
+	 */
274 274
 	protected function getMIB()
275 275
 	{
276 276
 		if ($this->MIBData == null)
@@ -288,9 +288,9 @@  discard block
 block discarded – undo
288 288
 	/**************************  Database queries *******************/
289 289
 	
290 290
 	/** Get host(s) by IP (v4 or v6) or by name in IDO database
291
-	*	does not catch exceptions
292
-	*	@return array of objects ( name, id (object_id), display_name)
293
-	*/
291
+	 *	does not catch exceptions
292
+	 *	@return array of objects ( name, id (object_id), display_name)
293
+	 */
294 294
 	protected function getHostByIP($ip) 
295 295
 	{
296 296
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
@@ -309,9 +309,9 @@  discard block
 block discarded – undo
309 309
 	}
310 310
 
311 311
 	/** Get host(s) by name in IDO database
312
-	*	does not catch exceptions
313
-	*	@return array of objects ( name, id (object_id), display_name)
314
-	*/
312
+	 *	does not catch exceptions
313
+	 *	@return array of objects ( name, id (object_id), display_name)
314
+	 */
315 315
 	protected function getHostByName($name) 
316 316
 	{
317 317
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
@@ -330,9 +330,9 @@  discard block
 block discarded – undo
330 330
 	}	
331 331
 	
332 332
 	/** Get host groups by  name in IDO database
333
-	*	does not catch exceptions
334
-	*	@return array of objects ( name, id (object_id), display_name)
335
-	*/
333
+	 *	does not catch exceptions
334
+	 *	@return array of objects ( name, id (object_id), display_name)
335
+	 */
336 336
 	protected function getHostGroupByName($ip) 
337 337
 	{
338 338
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
@@ -352,9 +352,9 @@  discard block
 block discarded – undo
352 352
 
353 353
 	
354 354
 	/** Get host IP (v4 and v6) by name in IDO database
355
-	*	does not catch exceptions
356
-	*	@return array ( name, display_name, ip4, ip6)
357
-	*/
355
+	 *	does not catch exceptions
356
+	 *	@return array ( name, display_name, ip4, ip6)
357
+	 */
358 358
 	protected function getHostInfoByID($id) 
359 359
 	{
360 360
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
@@ -373,9 +373,9 @@  discard block
 block discarded – undo
373 373
 
374 374
 	
375 375
 	/** Get host by objectid  in IDO database
376
-	*	does not catch exceptions
377
-	*	@return array of objects ( id, name, display_name, ip, ip6,  )
378
-	*/
376
+	 *	does not catch exceptions
377
+	 *	@return array of objects ( id, name, display_name, ip, ip6,  )
378
+	 */
379 379
 	protected function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above
380 380
 	{
381 381
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
@@ -393,10 +393,10 @@  discard block
 block discarded – undo
393 393
 	}	
394 394
 	
395 395
 	/** Get services from object ( host_object_id) in IDO database
396
-	*	does not catch exceptions
397
-	*	@param $id	int object_id
398
-	*	@return array display_name (of service), service_object_id
399
-	*/
396
+	 *	does not catch exceptions
397
+	 *	@param $id	int object_id
398
+	 *	@return array display_name (of service), service_object_id
399
+	 */
400 400
 	protected function getServicesByHostid($id) 
401 401
 	{
402 402
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
@@ -416,11 +416,11 @@  discard block
 block discarded – undo
416 416
 	}	
417 417
 	
418 418
 	/** Get services from hostgroup object id ( hostgroup_object_id) in IDO database
419
-	* 	gets all hosts in hostgroup and return common services
420
-	*	does not catch exceptions
421
-	*	@param $id	int object_id
422
-	*	@return array display_name (of service), service_object_id
423
-	*/
419
+	 * 	gets all hosts in hostgroup and return common services
420
+	 *	does not catch exceptions
421
+	 *	@param $id	int object_id
422
+	 *	@return array display_name (of service), service_object_id
423
+	 */
424 424
 	protected function getServicesByHostGroupid($id) 
425 425
 	{		
426 426
 		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
 		//print_r($common_services);
460 460
 		foreach (array_keys($common_services) as $key)
461 461
 		{
462
-		    if ($common_services[$key]['num'] == $num_hosts)
462
+			if ($common_services[$key]['num'] == $num_hosts)
463 463
 			{
464 464
 				array_push($result,array($key,$common_services[$key]['name']));
465 465
 			}
@@ -469,11 +469,11 @@  discard block
 block discarded – undo
469 469
 	}	
470 470
 
471 471
 	/** Get services object id by host name / service name in IDO database
472
-	*	does not catch exceptions
473
-	*	@param $hostname string host name
474
-	*	@param $name string service name
475
-	*	@return array  service id
476
-	*/
472
+	 *	does not catch exceptions
473
+	 *	@param $hostname string host name
474
+	 *	@param $name string service name
475
+	 *	@return array  service id
476
+	 */
477 477
 	protected function getServiceIDByName($hostname,$name) 
478 478
 	{
479 479
 		$db = $this->getIdoDb()->getConnection();
@@ -496,10 +496,10 @@  discard block
 block discarded – undo
496 496
 	}
497 497
 	
498 498
 	/** Get object name from object_id  in IDO database
499
-	*	does not catch exceptions
500
-	*	@param int $id object_id (default to null, used first if not null)
501
-	*	@return array name1 (host) name2 (service)
502
-	*/
499
+	 *	does not catch exceptions
500
+	 *	@param int $id object_id (default to null, used first if not null)
501
+	 *	@return array name1 (host) name2 (service)
502
+	 */
503 503
 	protected function getObjectNameByid($id) 
504 504
 	{
505 505
 		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
@@ -515,9 +515,9 @@  discard block
 block discarded – undo
515 515
 	}		
516 516
 
517 517
 	/** Add handler rule in traps DB
518
-	*	@param array $params : array(<db item>=><value>)
519
-	*	@return int inserted id
520
-	*/
518
+	 *	@param array $params : array(<db item>=><value>)
519
+	 *	@return int inserted id
520
+	 */
521 521
 	protected function addHandlerRule($params)
522 522
 	{
523 523
 		// TODO Check for rule consistency
@@ -539,10 +539,10 @@  discard block
 block discarded – undo
539 539
 	}	
540 540
 
541 541
 	/** Update handler rule in traps DB
542
-	*	@param array $params : (<db item>=><value>)
543
-	*   @param integer $ruleID : rule id in db
544
-	*	@return array affected rows
545
-	*/
542
+	 *	@param array $params : (<db item>=><value>)
543
+	 *   @param integer $ruleID : rule id in db
544
+	 *	@return array affected rows
545
+	 */
546 546
 	protected function updateHandlerRule($params,$ruleID)
547 547
 	{
548 548
 		// TODO Check for rule consistency
@@ -560,8 +560,8 @@  discard block
 block discarded – undo
560 560
 	}	
561 561
 	
562 562
 	/** Delete rule by id
563
-	*	@param int $ruleID rule id
564
-	*/
563
+	 *	@param int $ruleID rule id
564
+	 */
565 565
 	protected function deleteRule($ruleID)
566 566
 	{
567 567
 		if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
@@ -575,9 +575,9 @@  discard block
 block discarded – undo
575 575
 	}
576 576
 
577 577
 	/** Delete trap by ip & oid
578
-	*	@param $ip string source IP (v4 or v6)
579
-	*	@param $oid string oid
580
-	*/
578
+	 *	@param $ip string source IP (v4 or v6)
579
+	 *	@param $oid string oid
580
+	 */
581 581
 	protected function deleteTrap($ip,$oid)
582 582
 	{
583 583
 		
@@ -603,9 +603,9 @@  discard block
 block discarded – undo
603 603
    
604 604
 
605 605
 	/** count trap by ip & oid
606
-	*	@param $ip string source IP (v4 or v6)
607
-	*	@param $oid string oid
608
-	*/
606
+	 *	@param $ip string source IP (v4 or v6)
607
+	 *	@param $oid string oid
608
+	 */
609 609
 	protected function countTrap($ip,$oid)
610 610
 	{
611 611
 		
@@ -631,8 +631,8 @@  discard block
 block discarded – undo
631 631
 	}		
632 632
 	
633 633
 	/** get configuration value
634
-	*	@param string $element : configuration name in db
635
-	*/
634
+	 *	@param string $element : configuration name in db
635
+	 */
636 636
 	protected function getDBConfigValue($element)
637 637
 	{
638 638
 	
@@ -663,9 +663,9 @@  discard block
 block discarded – undo
663 663
 	}
664 664
 
665 665
 	/** add configuration value
666
-	*	@param string $element : name of config element
667
-	*   @param string $value : value
668
-	*/
666
+	 *	@param string $element : name of config element
667
+	 *   @param string $value : value
668
+	 */
669 669
 		
670 670
 	protected function addDBConfigValue($element,$value)
671 671
 	{
@@ -683,9 +683,9 @@  discard block
 block discarded – undo
683 683
 	}
684 684
 
685 685
 	/** set configuration value
686
-	*	@param string $element : name of config element
687
-	*   @param string $value : value
688
-	*/
686
+	 *	@param string $element : name of config element
687
+	 *   @param string $value : value
688
+	 */
689 689
 	protected function setDBConfigValue($element,$value)
690 690
 	{
691 691
 	
@@ -699,13 +699,13 @@  discard block
 block discarded – undo
699 699
 	}
700 700
 	
701 701
 	/** Check if director is installed
702
-	*	@return bool true/false
703
-	*/
702
+	 *	@return bool true/false
703
+	 */
704 704
 	protected function isDirectorInstalled()
705 705
 	{
706
-	    $output=array();
707
-	    exec('icingacli module list',$output);
708
-	    foreach ($output as $line)
706
+		$output=array();
707
+		exec('icingacli module list',$output);
708
+		foreach ($output as $line)
709 709
 		{
710 710
 			if (preg_match('/^director .*enabled/',$line))
711 711
 			{
Please login to merge, or discard this patch.