Passed
Push — master ( f89732...ddbf74 )
by Patrick
02:13
created
library/Trapdirector/TrapsProcess/MibDatabase.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -25,9 +25,9 @@  discard block
 block discarded – undo
25 25
         }
26 26
         $oidIndex=$this->dbOidIndex[$this->oidDesc['oid']]['key']; // Get index in dbOidAll
27 27
         $dbOid=$this->dbOidAll[$oidIndex]; // Get array of element
28
-        if ( $this->oidDesc['name'] != $dbOid['name'] ||
28
+        if ($this->oidDesc['name'] != $dbOid['name'] ||
29 29
             $this->oidDesc['mib'] != $dbOid['mib'] ||
30
-            $this->oidDesc['type'] !=$dbOid['type']
30
+            $this->oidDesc['type'] != $dbOid['type']
31 31
             )
32 32
         { // Do update
33 33
             $sql='UPDATE '.$this->getTrapsDB()->dbPrefix.'mib_cache SET '.
@@ -41,22 +41,22 @@  discard block
 block discarded – undo
41 41
                 ':type' => $this->oidDesc['type'],
42 42
                 ':mib' => $this->oidDesc['mib'],
43 43
                 ':tc' =>  $this->oidDesc['textconv']??'null',
44
-                ':display_hint' => $this->oidDesc['dispHint']??'null' ,
45
-                ':syntax' => $this->oidDesc['syntax']==null??'null',
44
+                ':display_hint' => $this->oidDesc['dispHint']??'null',
45
+                ':syntax' => $this->oidDesc['syntax'] == null??'null',
46 46
                 ':type_enum' => $this->oidDesc['type_enum']??'null',
47 47
                 ':description' => $this->oidDesc['description']??'null',
48 48
                 ':id' => $this->dbOidAll[$this->dbOidIndex[$this->oidDesc['oid']]['id']]
49 49
             );
50 50
             
51 51
             if ($sqlQuery->execute($sqlParam) === false) {
52
-                $this->getLogging()->log('Error in query : ' . $sql,ERROR,'');
52
+                $this->getLogging()->log('Error in query : '.$sql, ERROR, '');
53 53
             }
54
-            $this->getLogging()->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
54
+            $this->getLogging()->log('Trap updated : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], DEBUG);
55 55
             return 1;
56 56
         }
57 57
         else
58 58
         {
59
-            $this->getLogging()->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
59
+            $this->getLogging()->log('Trap unchanged : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], DEBUG);
60 60
             return 0;
61 61
         }
62 62
     }
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/Mib.php 1 patch
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      * @param Logging $logClass : where to log
45 45
      * @param Database $dbClass : Database
46 46
      */
47
-    function __construct($logClass,$dbClass,$snmptrans,$snmptransdir)
47
+    function __construct($logClass, $dbClass, $snmptrans, $snmptransdir)
48 48
     {
49 49
         $this->logging=$logClass;
50 50
         $this->trapsDB=$dbClass;
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
         $db_conn=$this->trapsDB->db_connect_trap();
83 83
         $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache '.
84 84
             '(oid, name, type , mib, textual_convention, display_hint '.
85
-            ', syntax, type_enum , description ) ' .
85
+            ', syntax, type_enum , description ) '.
86 86
             'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
87 87
             ', :syntax, :type_enum, :description )';
88 88
         
89
-        if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id';
89
+        if ($this->trapsDB->trapDBType == 'pgsql') $sql.='RETURNING id';
90 90
         
91 91
         $sqlQuery=$db_conn->prepare($sql);
92 92
         
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
         );
104 104
         
105 105
         if ($sqlQuery->execute($sqlParam) === false) {
106
-            $this->logging->log('Error in query : ' . $sql,1,'');
106
+            $this->logging->log('Error in query : '.$sql, 1, '');
107 107
         }
108 108
         
109 109
         switch ($this->trapsDB->trapDBType)
@@ -111,10 +111,10 @@  discard block
 block discarded – undo
111 111
             case 'pgsql':
112 112
                 // Get last id to insert oid/values in secondary table
113 113
                 if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {
114
-                    $this->logging->log('Error getting id - pgsql - ',1,'');
114
+                    $this->logging->log('Error getting id - pgsql - ', 1, '');
115 115
                 }
116
-                if (! isset($inserted_id_ret['id'])) {
117
-                    $this->logging->log('Error getting id - pgsql - empty.',ERROR);
116
+                if (!isset($inserted_id_ret['id'])) {
117
+                    $this->logging->log('Error getting id - pgsql - empty.', ERROR);
118 118
                     return 0;
119 119
                 }
120 120
                 $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id_ret['id'];
@@ -123,16 +123,16 @@  discard block
 block discarded – undo
123 123
                 // Get last id to insert oid/values in secondary table
124 124
                 $sql='SELECT LAST_INSERT_ID();';
125 125
                 if (($ret_code=$db_conn->query($sql)) === false) {
126
-                    $this->logging->log('Erreur getting id - mysql - ',ERROR);
126
+                    $this->logging->log('Erreur getting id - mysql - ', ERROR);
127 127
                     return 0;
128 128
                 }
129 129
                 
130 130
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
131
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
131
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
132 132
                 $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id;
133 133
                 break;
134 134
             default:
135
-                $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,ERROR);
135
+                $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType, ERROR);
136 136
                 return 0;
137 137
         }
138 138
         
@@ -172,9 +172,9 @@  discard block
 block discarded – undo
172 172
         $db_conn=$this->trapsDB->db_connect_trap();
173 173
         // Get all objects
174 174
         $sql='SELECT * FROM '.$this->trapsDB->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';';
175
-        $this->logging->log('SQL query get all traps: '.$sql,DEBUG );
175
+        $this->logging->log('SQL query get all traps: '.$sql, DEBUG);
176 176
         if (($ret_code=$db_conn->query($sql)) === false) {
177
-            $this->logging->log('No result in query : ' . $sql,1,'');
177
+            $this->logging->log('No result in query : '.$sql, 1, '');
178 178
         }
179 179
         $dbObjectsRaw=$ret_code->fetchAll();
180 180
         
@@ -191,30 +191,30 @@  discard block
 block discarded – undo
191 191
  * @param string $trapmib : mib of trap
192 192
  * @return NULL|array : null if not found, or output of snmptranslate
193 193
  */
194
-    private function get_object_details($object,$trapmib)
194
+    private function get_object_details($object, $trapmib)
195 195
     {
196 196
         $match=$snmptrans=array();
197 197
         $retVal=0;
198 198
         $this->oidDesc['mib']=$trapmib;
199
-        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
200
-            ' -On -Td '.$this->oidDesc['mib'].'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
201
-        if ($retVal!=0)
199
+        exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
200
+            ' -On -Td '.$this->oidDesc['mib'].'::'.$object.' 2>/dev/null', $snmptrans, $retVal);
201
+        if ($retVal != 0)
202 202
         {
203 203
             // Maybe not trap mib, search with IR
204
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
205
-                ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
206
-            if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
204
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
205
+                ' -IR '.$object.' 2>/dev/null', $snmptrans, $retVal);
206
+            if ($retVal != 0 || !preg_match('/(.*)::(.*)/', $snmptrans[0], $match))
207 207
             { // Not found -> continue with warning
208
-                $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
208
+                $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object, 2, '');
209 209
                 return null;
210 210
             }
211 211
             $this->oidDesc['mib']=$match[1];
212 212
             
213 213
             // Do the snmptranslate again.
214
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
215
-                ' -On -Td '.$this->oidDesc['mib'].'::'.$object,$snmptrans,$retVal);
216
-            if ($retVal!=0) {
217
-                $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object,2,'');
214
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
215
+                ' -On -Td '.$this->oidDesc['mib'].'::'.$object, $snmptrans, $retVal);
216
+            if ($retVal != 0) {
217
+                $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object, 2, '');
218 218
                 return null;
219 219
             }
220 220
             
@@ -234,12 +234,12 @@  discard block
 block discarded – undo
234 234
         
235 235
         foreach ($snmptrans as $line)
236 236
         {
237
-            if ($indesc===true)
237
+            if ($indesc === true)
238 238
             {
239
-                $line=preg_replace('/[\t ]+/',' ',$line);
240
-                if (preg_match('/(.*)"$/', $line,$match))
239
+                $line=preg_replace('/[\t ]+/', ' ', $line);
240
+                if (preg_match('/(.*)"$/', $line, $match))
241 241
                 {
242
-                    $this->oidDesc['description'] = $tmpdesc . $match[1];
242
+                    $this->oidDesc['description']=$tmpdesc.$match[1];
243 243
                     $indesc=false;
244 244
                 }
245 245
                 $tmpdesc.=$line;
@@ -250,34 +250,34 @@  discard block
 block discarded – undo
250 250
                 $this->oidDesc['oid']=$line;
251 251
                 continue;
252 252
             }
253
-            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
253
+            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/', $line, $match))
254 254
             {
255 255
                 $this->oidDesc['syntax']=$match[1];
256 256
                 $this->oidDesc['type_enum']=$match[2];
257 257
                 continue;
258 258
             }
259
-            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
259
+            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/', $line, $match))
260 260
             {
261 261
                 $this->oidDesc['syntax']=$match[1];
262 262
                 continue;
263 263
             }
264
-            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
264
+            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/', $line, $match))
265 265
             {
266 266
                 $this->oidDesc['dispHint']=$match[1];
267 267
                 continue;
268 268
             }
269
-            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
269
+            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/', $line, $match))
270 270
             {
271 271
                 $this->oidDesc['description']=$match[1];
272 272
                 continue;
273 273
             }
274
-            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
274
+            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $line, $match))
275 275
             {
276 276
                 $tmpdesc=$match[1];
277 277
                 $indesc=true;
278 278
                 continue;
279 279
             }
280
-            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
280
+            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/', $line, $match))
281 281
             {
282 282
                 $this->oidDesc['textconv']=$match[1];
283 283
                 continue;
@@ -292,9 +292,9 @@  discard block
 block discarded – undo
292 292
      * @param array $objects : array of objects name (without MIB)
293 293
      * @param bool $check_existing : check instead of create
294 294
      */
295
-    public function trap_objects($trapOID,$trapmib,$objects,$check_existing)
295
+    public function trap_objects($trapOID, $trapmib, $objects, $check_existing)
296 296
     {              
297
-        $trapId = $this->dbOidIndex[$trapOID]['id']; // Get id of trap
297
+        $trapId=$this->dbOidIndex[$trapOID]['id']; // Get id of trap
298 298
         
299 299
         if ($check_existing === true)
300 300
         {
@@ -311,9 +311,9 @@  discard block
 block discarded – undo
311 311
             
312 312
             $this->parse_object($snmptrans);
313 313
 
314
-            $this->oidDesc['name'] = $object;
314
+            $this->oidDesc['name']=$object;
315 315
             
316
-            $this->logging->log("Adding object ".$this->oidDesc['name']." : ".$this->oidDesc['oid']." / ".$this->oidDesc['syntax']." / ".$this->oidDesc['type_enum']." / ".$this->oidDesc['dispHint']." / ".$this->oidDesc['textconv'],DEBUG );
316
+            $this->logging->log("Adding object ".$this->oidDesc['name']." : ".$this->oidDesc['oid']." / ".$this->oidDesc['syntax']." / ".$this->oidDesc['type_enum']." / ".$this->oidDesc['dispHint']." / ".$this->oidDesc['textconv'], DEBUG);
317 317
 
318 318
             // Update
319 319
             $this->update_oid();
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
             );
339 339
             
340 340
             if ($sqlQuery->execute($sqlParam) === false) {
341
-                $this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$this->oidDesc['oid']]['id'] ,1,'');
341
+                $this->logging->log('Error adding trap object : '.$sql.' / '.$trapId.'/'.$this->dbOidIndex[$this->oidDesc['oid']]['id'], 1, '');
342 342
             }
343 343
         }
344 344
         if ($check_existing === true)
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
         $this->oidDesc['type']=null;
356 356
         $this->oidDesc['mib']=null;
357 357
         $this->oidDesc['textconv']=null;
358
-        $this->oidDesc['dispHint'] =null;
358
+        $this->oidDesc['dispHint']=null;
359 359
         $this->oidDesc['syntax']=null;
360 360
         $this->oidDesc['type_enum']=null;
361 361
         $this->oidDesc['description']=null;
@@ -369,17 +369,17 @@  discard block
 block discarded – undo
369 369
     {
370 370
         $retVal=0;
371 371
         // Get all mib objects from all mibs
372
-        $snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null';
373
-        $this->logging->log('Getting all traps : '.$snmpCommand,DEBUG );
372
+        $snmpCommand=$this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null';
373
+        $this->logging->log('Getting all traps : '.$snmpCommand, DEBUG);
374 374
         unset($this->objectsAll);
375
-        exec($snmpCommand,$this->objectsAll,$retVal);
376
-        if ($retVal!=0)
375
+        exec($snmpCommand, $this->objectsAll, $retVal);
376
+        if ($retVal != 0)
377 377
         {
378
-            $this->logging->log('error executing snmptranslate',ERROR,'');
378
+            $this->logging->log('error executing snmptranslate', ERROR, '');
379 379
         }
380 380
         // Count elements to show progress
381 381
         $numElements=count($this->objectsAll);
382
-        $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO );
382
+        $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements, INFO);
383 383
         return $numElements;
384 384
     }
385 385
 
@@ -393,14 +393,14 @@  discard block
 block discarded – undo
393 393
         $db_conn=$this->trapsDB->db_connect_trap();
394 394
         
395 395
         $sql='SELECT * from '.$this->trapsDB->dbPrefix.'mib_cache;';
396
-        $this->logging->log('SQL query : '.$sql,DEBUG );
396
+        $this->logging->log('SQL query : '.$sql, DEBUG);
397 397
         if (($ret_code=$db_conn->query($sql)) === false) {
398
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
398
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
399 399
         }
400 400
         $this->dbOidAll=$ret_code->fetchAll();
401 401
         $this->dbOidIndex=array();
402 402
         // Create the index for db;
403
-        foreach($this->dbOidAll as $key=>$val)
403
+        foreach ($this->dbOidAll as $key=>$val)
404 404
         {
405 405
             $this->dbOidIndex[$val['oid']]['key']=$key;
406 406
             $this->dbOidIndex[$val['oid']]['id']=$val['id'];
@@ -433,13 +433,13 @@  discard block
 block discarded – undo
433 433
      * @param bool $onlyTraps : set to false to get all and not only traps.
434 434
      * @return boolean : false if it's a trap , true if not
435 435
      */
436
-    private function detect_trap($curElement,$onlyTraps)
436
+    private function detect_trap($curElement, $onlyTraps)
437 437
     {
438 438
         // Get oid or pass if not found
439
-        if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
439
+        if (!preg_match('/^\.[0-9\.]+$/', $this->objectsAll[$curElement]))
440 440
         {
441
-            $this->timing['base_parse_time'] += microtime(true) - $this->timing['base_time'];
442
-            $this->timing['base_parse_num'] ++;
441
+            $this->timing['base_parse_time']+=microtime(true) - $this->timing['base_time'];
442
+            $this->timing['base_parse_num']++;
443 443
             return true;
444 444
         }
445 445
         $this->oidDesc['oid']=$this->objectsAll[$curElement];
@@ -448,9 +448,9 @@  discard block
 block discarded – undo
448 448
         $curElement++;
449 449
         $match=$snmptrans=array();
450 450
         if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
451
-            $this->objectsAll[$curElement],$match))
451
+            $this->objectsAll[$curElement], $match))
452 452
         {
453
-            $this->timing['base_check_time'] += microtime(true) - $this->timing['base_time'];
453
+            $this->timing['base_check_time']+=microtime(true) - $this->timing['base_time'];
454 454
             $this->timing['base_check_num']++;
455 455
             return true;
456 456
         }
@@ -458,22 +458,22 @@  discard block
 block discarded – undo
458 458
         $this->oidDesc['name']=$match[1]; // Name
459 459
         $this->oidDesc['type']=$match[2]; // type (21=trap, 0: may be trap, else : not trap
460 460
         
461
-        if ($this->oidDesc['type']==0) // object type=0 : check if v1 trap
461
+        if ($this->oidDesc['type'] == 0) // object type=0 : check if v1 trap
462 462
         {
463 463
             // Check if next is suboid -> in that case is cannot be a trap
464
-            if (preg_match("/^".$this->oidDesc['oid']."/",$this->objectsAll[$curElement+1]))
464
+            if (preg_match("/^".$this->oidDesc['oid']."/", $this->objectsAll[$curElement + 1]))
465 465
             {
466
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
466
+                $this->timing['type0_check_time']+=microtime(true) - $this->timing['base_time'];
467 467
                 $this->timing['type0_check_num']++;
468 468
                 return true;
469 469
             }
470 470
             unset($snmptrans);
471 471
             $retVal=0;
472
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
473
-                ' -Td '.$this->oidDesc['oid'] . ' | grep OBJECTS ',$snmptrans,$retVal);
474
-            if ($retVal!=0)
472
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
473
+                ' -Td '.$this->oidDesc['oid'].' | grep OBJECTS ', $snmptrans, $retVal);
474
+            if ($retVal != 0)
475 475
             {
476
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
476
+                $this->timing['type0_check_time']+=microtime(true) - $this->timing['base_time'];
477 477
                 $this->timing['type0_check_num']++;
478 478
                 return true;
479 479
             }
@@ -481,9 +481,9 @@  discard block
 block discarded – undo
481 481
             // Force as trap.
482 482
             $this->oidDesc['type']=21;
483 483
         }
484
-        if ($onlyTraps===true && $this->oidDesc['type']!=21) // if only traps and not a trap, continue
484
+        if ($onlyTraps === true && $this->oidDesc['type'] != 21) // if only traps and not a trap, continue
485 485
         {
486
-            $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time'];
486
+            $this->timing['nottrap_time']+=microtime(true) - $this->timing['base_time'];
487 487
             $this->timing['nottrap_num']++;
488 488
             return true;
489 489
         }
@@ -498,35 +498,35 @@  discard block
 block discarded – undo
498 498
     {
499 499
         $retVal=0;
500 500
         $match=$snmptrans=array();
501
-        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
502
-            ' -Td '.$this->oidDesc['oid'],$snmptrans,$retVal);
503
-        if ($retVal!=0)
501
+        exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
502
+            ' -Td '.$this->oidDesc['oid'], $snmptrans, $retVal);
503
+        if ($retVal != 0)
504 504
         {
505
-            $this->logging->log('error executing snmptranslate',ERROR);
505
+            $this->logging->log('error executing snmptranslate', ERROR);
506 506
             return $snmptrans;
507 507
         }
508 508
         
509
-        if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
509
+        if (!preg_match('/^(.*)::/', $snmptrans[0], $match))
510 510
         {
511
-            $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : ' . $snmptrans[0],ERROR);
511
+            $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : '.$snmptrans[0], ERROR);
512 512
             return $snmptrans;
513 513
         }
514 514
         $this->oidDesc['mib']=$match[1];
515 515
         
516 516
         $numLine=1;
517
-        while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
517
+        while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $snmptrans[$numLine], $match)) $numLine++;
518 518
         if (isset($snmptrans[$numLine]))
519 519
         {
520
-            $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
520
+            $snmptrans[$numLine]=preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/', '', $snmptrans[$numLine]);
521 521
             
522
-            while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
522
+            while (isset($snmptrans[$numLine]) && !preg_match('/"/', $snmptrans[$numLine]))
523 523
             {
524
-                $this->oidDesc['description'].=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
524
+                $this->oidDesc['description'].=preg_replace('/[\t ]+/', ' ', $snmptrans[$numLine]);
525 525
                 $numLine++;
526 526
             }
527 527
             if (isset($snmptrans[$numLine])) {
528
-                $this->oidDesc['description'].=preg_replace('/".*/','',$snmptrans[$numLine]);
529
-                $this->oidDesc['description']=preg_replace('/[\t ]+/',' ',$this->oidDesc['description']);
528
+                $this->oidDesc['description'].=preg_replace('/".*/', '', $snmptrans[$numLine]);
529
+                $this->oidDesc['description']=preg_replace('/[\t ]+/', ' ', $this->oidDesc['description']);
530 530
             }
531 531
             
532 532
         }
@@ -544,23 +544,23 @@  discard block
 block discarded – undo
544 544
         $match=array();
545 545
         foreach ($snmptrans as $line)
546 546
         {
547
-            if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
547
+            if (preg_match('/OBJECTS.*\{([^\}]+)\}/', $line, $match))
548 548
             {
549 549
                 $objectName=$match[1];
550 550
             }
551 551
         }
552 552
         if ($objectName == null)
553 553
         {
554
-            $this->logging->log('No objects for ' . $this->oidDesc['oid'],DEBUG);
555
-            $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
554
+            $this->logging->log('No objects for '.$this->oidDesc['oid'], DEBUG);
555
+            $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
556 556
             return null;
557 557
         }
558 558
         
559 559
         $trapObjects=array();
560
-        while (preg_match('/ *([^ ,]+) *,* */',$objectName,$match))
560
+        while (preg_match('/ *([^ ,]+) *,* */', $objectName, $match))
561 561
         {
562
-            array_push($trapObjects,$match[1]);
563
-            $objectName=preg_replace('/'.$match[0].'/','',$objectName);
562
+            array_push($trapObjects, $match[1]);
563
+            $objectName=preg_replace('/'.$match[0].'/', '', $objectName);
564 564
         }
565 565
         return $trapObjects;
566 566
     }
@@ -572,18 +572,18 @@  discard block
 block discarded – undo
572 572
      * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
573 573
      * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
574 574
      */
575
-    public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
575
+    public function update_mib_database($display_progress=false, $check_change=false, $onlyTraps=true, $startOID='.1')
576 576
     {
577 577
         // Global Timing
578
-        $timeTaken = microtime(true);
578
+        $timeTaken=microtime(true);
579 579
         
580 580
         $numElements=$this->load_mibs_snmptranslate(); // Load objectsAll
581 581
         
582 582
         $this->load_mibs_from_db(); // Load from db dbOidAll & dbOidIndex
583 583
         
584
-        $step=$basestep=$numElements/10; // output display of % done
584
+        $step=$basestep=$numElements / 10; // output display of % done
585 585
         $num_step=0;
586
-        $timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds
586
+        $timeFiveSec=microtime(true); // Used for display a '.' every <n> seconds
587 587
         
588 588
         // Create index for trap objects
589 589
         $this->trapObjectsIndex=array();
@@ -591,33 +591,33 @@  discard block
 block discarded – undo
591 591
         // detailed timing (time_* vars)
592 592
         $this->reset_update_timers();
593 593
         
594
-        for ($curElement=0;$curElement < $numElements;$curElement++)
594
+        for ($curElement=0; $curElement < $numElements; $curElement++)
595 595
         {
596
-            $this->timing['base_time']= microtime(true);
596
+            $this->timing['base_time']=microtime(true);
597 597
             if ($display_progress)
598 598
             {
599
-                if ((microtime(true)-$timeFiveSec) > 2)
599
+                if ((microtime(true) - $timeFiveSec) > 2)
600 600
                 { // echo a . every 2 sec
601 601
                     echo '.';
602
-                    $timeFiveSec = microtime(true);
602
+                    $timeFiveSec=microtime(true);
603 603
                 }
604
-                if ($curElement>$step)
604
+                if ($curElement > $step)
605 605
                 { // display progress
606 606
                     $num_step++;
607 607
                     $step+=$basestep;   
608
-                    echo "\n" . ($num_step*10). '% : ';
608
+                    echo "\n".($num_step * 10).'% : ';
609 609
                 }
610 610
             }
611 611
             
612 612
             $this->reset_oidDesc();
613
-            if ($this->detect_trap($curElement,$onlyTraps)===true)
613
+            if ($this->detect_trap($curElement, $onlyTraps) === true)
614 614
             {
615 615
                 continue;
616 616
             }
617 617
             
618 618
             $this->timing['num_traps']++;
619 619
             
620
-            $this->logging->log('Found trap : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],INFO );
620
+            $this->logging->log('Found trap : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], INFO);
621 621
             if ($display_progress) echo '#'; // echo a # when trap found
622 622
 
623 623
             // get trap objects & source MIB
@@ -627,14 +627,14 @@  discard block
 block discarded – undo
627 627
 
628 628
             $update=$this->update_oid(); // Do update of trap.
629 629
             
630
-            $this->timing['update_time'] += microtime(true) - $this->timing['base_time'];
630
+            $this->timing['update_time']+=microtime(true) - $this->timing['base_time'];
631 631
             $this->timing['update_num']++;
632 632
             
633
-            $this->timing['base_time']= microtime(true); // Reset to check object time
633
+            $this->timing['base_time']=microtime(true); // Reset to check object time
634 634
             
635
-            if (($update==0) && ($check_change===false))
635
+            if (($update == 0) && ($check_change === false))
636 636
             { // Trapd didn't change & force check disabled
637
-                $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
637
+                $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
638 638
                 if ($display_progress) echo "C";
639 639
                 continue;
640 640
             }
@@ -647,17 +647,17 @@  discard block
 block discarded – undo
647 647
            
648 648
             $this->trap_objects($this->oidDesc['oid'], $this->oidDesc['mib'], $trapObjects, false);
649 649
             
650
-            $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
650
+            $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
651 651
             $this->timing['objects_num']++;
652 652
         }
653 653
         
654 654
         if ($display_progress)
655 655
         {
656
-            echo "\nNumber of processed traps :  ". $this->timing['num_traps'] ."\n";
657
-            echo "\nParsing : " . number_format($this->timing['base_parse_time']+$this->timing['base_check_time'],1) ." sec / " . ($this->timing['base_parse_num']+ $this->timing['base_check_num'])  . " occurences\n";
658
-            echo "Detecting traps : " . number_format($this->timing['type0_check_time']+$this->timing['nottrap_time'],1) . " sec / " . ($this->timing['type0_check_num']+$this->timing['nottrap_num']) ." occurences\n";
659
-            echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'],1)." sec , ";
660
-            echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'],1)." sec \n";
656
+            echo "\nNumber of processed traps :  ".$this->timing['num_traps']."\n";
657
+            echo "\nParsing : ".number_format($this->timing['base_parse_time'] + $this->timing['base_check_time'], 1)." sec / ".($this->timing['base_parse_num'] + $this->timing['base_check_num'])." occurences\n";
658
+            echo "Detecting traps : ".number_format($this->timing['type0_check_time'] + $this->timing['nottrap_time'], 1)." sec / ".($this->timing['type0_check_num'] + $this->timing['nottrap_num'])." occurences\n";
659
+            echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'], 1)." sec , ";
660
+            echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'], 1)." sec \n";
661 661
             
662 662
             $timeTaken=microtime(true) - $timeTaken;
663 663
             echo "Global time : ".round($timeTaken)." seconds\n";
Please login to merge, or discard this patch.