Passed
Push — master ( 4fd4ae...300cc7 )
by Patrick
02:12
created
library/Trapdirector/TrapsProcess/Mib.php 1 patch
Spacing   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      * @param Logging $logClass : where to log
33 33
      * @param Database $dbClass : Database
34 34
      */
35
-    function __construct($logClass,$dbClass,$snmptrans,$snmptransdir)
35
+    function __construct($logClass, $dbClass, $snmptrans, $snmptransdir)
36 36
     {
37 37
         $this->logging=$logClass;
38 38
         $this->trapsDB=$dbClass;
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
         }
57 57
         $oidIndex=$this->dbOidIndex[$this->oidDesc['oid']]['key']; // Get index in dbOidAll
58 58
         $dbOid=$this->dbOidAll[$oidIndex]; // Get array of element
59
-        if ( $this->oidDesc['name'] != $dbOid['name'] ||
59
+        if ($this->oidDesc['name'] != $dbOid['name'] ||
60 60
             $this->oidDesc['mib'] != $dbOid['mib'] ||
61
-            $this->oidDesc['type'] !=$dbOid['type']
61
+            $this->oidDesc['type'] != $dbOid['type']
62 62
             )
63 63
         { // Do update
64 64
             $sql='UPDATE '.$this->trapsDB->dbPrefix.'mib_cache SET '.
@@ -72,22 +72,22 @@  discard block
 block discarded – undo
72 72
                 ':type' => $this->oidDesc['type'],
73 73
                 ':mib' => $this->oidDesc['mib'],
74 74
                 ':tc' =>  $this->oidDesc['textconv']??'null',
75
-                ':display_hint' => $this->oidDesc['dispHint']??'null' ,
76
-                ':syntax' => $this->oidDesc['syntax']==null??'null',
75
+                ':display_hint' => $this->oidDesc['dispHint']??'null',
76
+                ':syntax' => $this->oidDesc['syntax'] == null??'null',
77 77
                 ':type_enum' => $this->oidDesc['type_enum']??'null',
78 78
                 ':description' => $this->oidDesc['description']??'null',
79 79
                 ':id' => $this->dbOidAll[$this->dbOidIndex[$this->oidDesc['oid']]['id']]
80 80
             );
81 81
             
82 82
             if ($sqlQuery->execute($sqlParam) === false) {
83
-                $this->logging->log('Error in query : ' . $sql,ERROR,'');
83
+                $this->logging->log('Error in query : '.$sql, ERROR, '');
84 84
             }
85
-            $this->logging->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
85
+            $this->logging->log('Trap updated : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], DEBUG);
86 86
             return 1;
87 87
         }
88 88
         else
89 89
         {
90
-            $this->logging->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
90
+            $this->logging->log('Trap unchanged : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], DEBUG);
91 91
             return 0;
92 92
         }
93 93
     }
@@ -103,11 +103,11 @@  discard block
 block discarded – undo
103 103
         $db_conn=$this->trapsDB->db_connect_trap();
104 104
         $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache '.
105 105
             '(oid, name, type , mib, textual_convention, display_hint '.
106
-            ', syntax, type_enum , description ) ' .
106
+            ', syntax, type_enum , description ) '.
107 107
             'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
108 108
             ', :syntax, :type_enum, :description )';
109 109
         
110
-        if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id';
110
+        if ($this->trapsDB->trapDBType == 'pgsql') $sql.='RETURNING id';
111 111
         
112 112
         $sqlQuery=$db_conn->prepare($sql);
113 113
         
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
         );
125 125
         
126 126
         if ($sqlQuery->execute($sqlParam) === false) {
127
-            $this->logging->log('Error in query : ' . $sql,1,'');
127
+            $this->logging->log('Error in query : '.$sql, 1, '');
128 128
         }
129 129
         
130 130
         switch ($this->trapsDB->trapDBType)
@@ -132,10 +132,10 @@  discard block
 block discarded – undo
132 132
             case 'pgsql':
133 133
                 // Get last id to insert oid/values in secondary table
134 134
                 if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {
135
-                    $this->logging->log('Error getting id - pgsql - ',1,'');
135
+                    $this->logging->log('Error getting id - pgsql - ', 1, '');
136 136
                 }
137
-                if (! isset($inserted_id_ret['id'])) {
138
-                    $this->logging->log('Error getting id - pgsql - empty.',ERROR);
137
+                if (!isset($inserted_id_ret['id'])) {
138
+                    $this->logging->log('Error getting id - pgsql - empty.', ERROR);
139 139
                     return 0;
140 140
                 }
141 141
                 $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id_ret['id'];
@@ -144,16 +144,16 @@  discard block
 block discarded – undo
144 144
                 // Get last id to insert oid/values in secondary table
145 145
                 $sql='SELECT LAST_INSERT_ID();';
146 146
                 if (($ret_code=$db_conn->query($sql)) === false) {
147
-                    $this->logging->log('Erreur getting id - mysql - ',ERROR);
147
+                    $this->logging->log('Erreur getting id - mysql - ', ERROR);
148 148
                     return 0;
149 149
                 }
150 150
                 
151 151
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
152
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
152
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
153 153
                 $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id;
154 154
                 break;
155 155
             default:
156
-                $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,ERROR);
156
+                $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType, ERROR);
157 157
                 return 0;
158 158
         }
159 159
         
@@ -193,9 +193,9 @@  discard block
 block discarded – undo
193 193
         $db_conn=$this->trapsDB->db_connect_trap();
194 194
         // Get all objects
195 195
         $sql='SELECT * FROM '.$this->trapsDB->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';';
196
-        $this->logging->log('SQL query get all traps: '.$sql,DEBUG );
196
+        $this->logging->log('SQL query get all traps: '.$sql, DEBUG);
197 197
         if (($ret_code=$db_conn->query($sql)) === false) {
198
-            $this->logging->log('No result in query : ' . $sql,1,'');
198
+            $this->logging->log('No result in query : '.$sql, 1, '');
199 199
         }
200 200
         $dbObjectsRaw=$ret_code->fetchAll();
201 201
         
@@ -212,30 +212,30 @@  discard block
 block discarded – undo
212 212
  * @param string $trapmib : mib of trap
213 213
  * @return NULL|array : null if not found, or output of snmptranslate
214 214
  */
215
-    private function get_object_details($object,$trapmib)
215
+    private function get_object_details($object, $trapmib)
216 216
     {
217 217
         $match=$snmptrans=array();
218 218
         $retVal=0;
219 219
         $this->oidDesc['mib']=$trapmib;
220
-        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
221
-            ' -On -Td '.$this->oidDesc['mib'].'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
222
-        if ($retVal!=0)
220
+        exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
221
+            ' -On -Td '.$this->oidDesc['mib'].'::'.$object.' 2>/dev/null', $snmptrans, $retVal);
222
+        if ($retVal != 0)
223 223
         {
224 224
             // Maybe not trap mib, search with IR
225
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
226
-                ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
227
-            if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
225
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
226
+                ' -IR '.$object.' 2>/dev/null', $snmptrans, $retVal);
227
+            if ($retVal != 0 || !preg_match('/(.*)::(.*)/', $snmptrans[0], $match))
228 228
             { // Not found -> continue with warning
229
-                $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
229
+                $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object, 2, '');
230 230
                 return null;
231 231
             }
232 232
             $this->oidDesc['mib']=$match[1];
233 233
             
234 234
             // Do the snmptranslate again.
235
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
236
-                ' -On -Td '.$this->oidDesc['mib'].'::'.$object,$snmptrans,$retVal);
237
-            if ($retVal!=0) {
238
-                $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object,2,'');
235
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
236
+                ' -On -Td '.$this->oidDesc['mib'].'::'.$object, $snmptrans, $retVal);
237
+            if ($retVal != 0) {
238
+                $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object, 2, '');
239 239
                 return null;
240 240
             }
241 241
             
@@ -255,12 +255,12 @@  discard block
 block discarded – undo
255 255
         
256 256
         foreach ($snmptrans as $line)
257 257
         {
258
-            if ($indesc===true)
258
+            if ($indesc === true)
259 259
             {
260
-                $line=preg_replace('/[\t ]+/',' ',$line);
261
-                if (preg_match('/(.*)"$/', $line,$match))
260
+                $line=preg_replace('/[\t ]+/', ' ', $line);
261
+                if (preg_match('/(.*)"$/', $line, $match))
262 262
                 {
263
-                    $this->oidDesc['description'] = $tmpdesc . $match[1];
263
+                    $this->oidDesc['description']=$tmpdesc.$match[1];
264 264
                     $indesc=false;
265 265
                 }
266 266
                 $tmpdesc.=$line;
@@ -271,34 +271,34 @@  discard block
 block discarded – undo
271 271
                 $this->oidDesc['oid']=$line;
272 272
                 continue;
273 273
             }
274
-            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
274
+            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/', $line, $match))
275 275
             {
276 276
                 $this->oidDesc['syntax']=$match[1];
277 277
                 $this->oidDesc['type_enum']=$match[2];
278 278
                 continue;
279 279
             }
280
-            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
280
+            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/', $line, $match))
281 281
             {
282 282
                 $this->oidDesc['syntax']=$match[1];
283 283
                 continue;
284 284
             }
285
-            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
285
+            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/', $line, $match))
286 286
             {
287 287
                 $this->oidDesc['dispHint']=$match[1];
288 288
                 continue;
289 289
             }
290
-            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
290
+            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/', $line, $match))
291 291
             {
292 292
                 $this->oidDesc['description']=$match[1];
293 293
                 continue;
294 294
             }
295
-            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
295
+            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $line, $match))
296 296
             {
297 297
                 $tmpdesc=$match[1];
298 298
                 $indesc=true;
299 299
                 continue;
300 300
             }
301
-            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
301
+            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/', $line, $match))
302 302
             {
303 303
                 $this->oidDesc['textconv']=$match[1];
304 304
                 continue;
@@ -313,9 +313,9 @@  discard block
 block discarded – undo
313 313
      * @param array $objects : array of objects name (without MIB)
314 314
      * @param bool $check_existing : check instead of create
315 315
      */
316
-    public function trap_objects($trapOID,$trapmib,$objects,$check_existing)
316
+    public function trap_objects($trapOID, $trapmib, $objects, $check_existing)
317 317
     {              
318
-        $trapId = $this->dbOidIndex[$trapOID]['id']; // Get id of trap
318
+        $trapId=$this->dbOidIndex[$trapOID]['id']; // Get id of trap
319 319
         
320 320
         if ($check_existing === true)
321 321
         {
@@ -332,9 +332,9 @@  discard block
 block discarded – undo
332 332
             
333 333
             $this->parse_object($snmptrans);
334 334
 
335
-            $this->oidDesc['name'] = $object;
335
+            $this->oidDesc['name']=$object;
336 336
             
337
-            $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 );
337
+            $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);
338 338
 
339 339
             // Update
340 340
             $this->update_oid();
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
             );
360 360
             
361 361
             if ($sqlQuery->execute($sqlParam) === false) {
362
-                $this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$this->oidDesc['oid']]['id'] ,1,'');
362
+                $this->logging->log('Error adding trap object : '.$sql.' / '.$trapId.'/'.$this->dbOidIndex[$this->oidDesc['oid']]['id'], 1, '');
363 363
             }
364 364
         }
365 365
         if ($check_existing === true)
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
         $this->oidDesc['type']=null;
377 377
         $this->oidDesc['mib']=null;
378 378
         $this->oidDesc['textconv']=null;
379
-        $this->oidDesc['dispHint'] =null;
379
+        $this->oidDesc['dispHint']=null;
380 380
         $this->oidDesc['syntax']=null;
381 381
         $this->oidDesc['type_enum']=null;
382 382
         $this->oidDesc['description']=null;
@@ -390,17 +390,17 @@  discard block
 block discarded – undo
390 390
     {
391 391
         $retVal=0;
392 392
         // Get all mib objects from all mibs
393
-        $snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null';
394
-        $this->logging->log('Getting all traps : '.$snmpCommand,DEBUG );
393
+        $snmpCommand=$this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null';
394
+        $this->logging->log('Getting all traps : '.$snmpCommand, DEBUG);
395 395
         unset($this->objectsAll);
396
-        exec($snmpCommand,$this->objectsAll,$retVal);
397
-        if ($retVal!=0)
396
+        exec($snmpCommand, $this->objectsAll, $retVal);
397
+        if ($retVal != 0)
398 398
         {
399
-            $this->logging->log('error executing snmptranslate',ERROR,'');
399
+            $this->logging->log('error executing snmptranslate', ERROR, '');
400 400
         }
401 401
         // Count elements to show progress
402 402
         $numElements=count($this->objectsAll);
403
-        $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO );
403
+        $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements, INFO);
404 404
         return $numElements;
405 405
     }
406 406
 
@@ -414,14 +414,14 @@  discard block
 block discarded – undo
414 414
         $db_conn=$this->trapsDB->db_connect_trap();
415 415
         
416 416
         $sql='SELECT * from '.$this->trapsDB->dbPrefix.'mib_cache;';
417
-        $this->logging->log('SQL query : '.$sql,DEBUG );
417
+        $this->logging->log('SQL query : '.$sql, DEBUG);
418 418
         if (($ret_code=$db_conn->query($sql)) === false) {
419
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
419
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
420 420
         }
421 421
         $this->dbOidAll=$ret_code->fetchAll();
422 422
         $this->dbOidIndex=array();
423 423
         // Create the index for db;
424
-        foreach($this->dbOidAll as $key=>$val)
424
+        foreach ($this->dbOidAll as $key=>$val)
425 425
         {
426 426
             $this->dbOidIndex[$val['oid']]['key']=$key;
427 427
             $this->dbOidIndex[$val['oid']]['id']=$val['id'];
@@ -454,13 +454,13 @@  discard block
 block discarded – undo
454 454
      * @param bool $onlyTraps : set to false to get all and not only traps.
455 455
      * @return boolean : false if it's a trap , true if not
456 456
      */
457
-    private function detect_trap($curElement,$onlyTraps)
457
+    private function detect_trap($curElement, $onlyTraps)
458 458
     {
459 459
         // Get oid or pass if not found
460
-        if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
460
+        if (!preg_match('/^\.[0-9\.]+$/', $this->objectsAll[$curElement]))
461 461
         {
462
-            $this->timing['base_parse_time'] += microtime(true) - $this->timing['base_time'];
463
-            $this->timing['base_parse_num'] ++;
462
+            $this->timing['base_parse_time']+=microtime(true) - $this->timing['base_time'];
463
+            $this->timing['base_parse_num']++;
464 464
             return true;
465 465
         }
466 466
         $this->oidDesc['oid']=$this->objectsAll[$curElement];
@@ -469,9 +469,9 @@  discard block
 block discarded – undo
469 469
         $curElement++;
470 470
         $match=$snmptrans=array();
471 471
         if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
472
-            $this->objectsAll[$curElement],$match))
472
+            $this->objectsAll[$curElement], $match))
473 473
         {
474
-            $this->timing['base_check_time'] += microtime(true) - $this->timing['base_time'];
474
+            $this->timing['base_check_time']+=microtime(true) - $this->timing['base_time'];
475 475
             $this->timing['base_check_num']++;
476 476
             return true;
477 477
         }
@@ -479,22 +479,22 @@  discard block
 block discarded – undo
479 479
         $this->oidDesc['name']=$match[1]; // Name
480 480
         $this->oidDesc['type']=$match[2]; // type (21=trap, 0: may be trap, else : not trap
481 481
         
482
-        if ($this->oidDesc['type']==0) // object type=0 : check if v1 trap
482
+        if ($this->oidDesc['type'] == 0) // object type=0 : check if v1 trap
483 483
         {
484 484
             // Check if next is suboid -> in that case is cannot be a trap
485
-            if (preg_match("/^".$this->oidDesc['oid']."/",$this->objectsAll[$curElement+1]))
485
+            if (preg_match("/^".$this->oidDesc['oid']."/", $this->objectsAll[$curElement + 1]))
486 486
             {
487
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
487
+                $this->timing['type0_check_time']+=microtime(true) - $this->timing['base_time'];
488 488
                 $this->timing['type0_check_num']++;
489 489
                 return true;
490 490
             }
491 491
             unset($snmptrans);
492 492
             $retVal=0;
493
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
494
-                ' -Td '.$this->oidDesc['oid'] . ' | grep OBJECTS ',$snmptrans,$retVal);
495
-            if ($retVal!=0)
493
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
494
+                ' -Td '.$this->oidDesc['oid'].' | grep OBJECTS ', $snmptrans, $retVal);
495
+            if ($retVal != 0)
496 496
             {
497
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
497
+                $this->timing['type0_check_time']+=microtime(true) - $this->timing['base_time'];
498 498
                 $this->timing['type0_check_num']++;
499 499
                 return true;
500 500
             }
@@ -502,9 +502,9 @@  discard block
 block discarded – undo
502 502
             // Force as trap.
503 503
             $this->oidDesc['type']=21;
504 504
         }
505
-        if ($onlyTraps===true && $this->oidDesc['type']!=21) // if only traps and not a trap, continue
505
+        if ($onlyTraps === true && $this->oidDesc['type'] != 21) // if only traps and not a trap, continue
506 506
         {
507
-            $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time'];
507
+            $this->timing['nottrap_time']+=microtime(true) - $this->timing['base_time'];
508 508
             $this->timing['nottrap_num']++;
509 509
             return true;
510 510
         }
@@ -519,35 +519,35 @@  discard block
 block discarded – undo
519 519
     {
520 520
         $retVal=0;
521 521
         $match=$snmptrans=array();
522
-        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
523
-            ' -Td '.$this->oidDesc['oid'],$snmptrans,$retVal);
524
-        if ($retVal!=0)
522
+        exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
523
+            ' -Td '.$this->oidDesc['oid'], $snmptrans, $retVal);
524
+        if ($retVal != 0)
525 525
         {
526
-            $this->logging->log('error executing snmptranslate',ERROR);
526
+            $this->logging->log('error executing snmptranslate', ERROR);
527 527
             return $snmptrans;
528 528
         }
529 529
         
530
-        if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
530
+        if (!preg_match('/^(.*)::/', $snmptrans[0], $match))
531 531
         {
532
-            $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : ' . $snmptrans[0],ERROR);
532
+            $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : '.$snmptrans[0], ERROR);
533 533
             return $snmptrans;
534 534
         }
535 535
         $this->oidDesc['mib']=$match[1];
536 536
         
537 537
         $numLine=1;
538
-        while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
538
+        while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $snmptrans[$numLine], $match)) $numLine++;
539 539
         if (isset($snmptrans[$numLine]))
540 540
         {
541
-            $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
541
+            $snmptrans[$numLine]=preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/', '', $snmptrans[$numLine]);
542 542
             
543
-            while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
543
+            while (isset($snmptrans[$numLine]) && !preg_match('/"/', $snmptrans[$numLine]))
544 544
             {
545
-                $this->oidDesc['description'].=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
545
+                $this->oidDesc['description'].=preg_replace('/[\t ]+/', ' ', $snmptrans[$numLine]);
546 546
                 $numLine++;
547 547
             }
548 548
             if (isset($snmptrans[$numLine])) {
549
-                $this->oidDesc['description'].=preg_replace('/".*/','',$snmptrans[$numLine]);
550
-                $this->oidDesc['description']=preg_replace('/[\t ]+/',' ',$this->oidDesc['description']);
549
+                $this->oidDesc['description'].=preg_replace('/".*/', '', $snmptrans[$numLine]);
550
+                $this->oidDesc['description']=preg_replace('/[\t ]+/', ' ', $this->oidDesc['description']);
551 551
             }
552 552
             
553 553
         }
@@ -565,23 +565,23 @@  discard block
 block discarded – undo
565 565
         $match=array();
566 566
         foreach ($snmptrans as $line)
567 567
         {
568
-            if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
568
+            if (preg_match('/OBJECTS.*\{([^\}]+)\}/', $line, $match))
569 569
             {
570 570
                 $objectName=$match[1];
571 571
             }
572 572
         }
573 573
         if ($objectName == null)
574 574
         {
575
-            $this->logging->log('No objects for ' . $this->oidDesc['oid'],DEBUG);
576
-            $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
575
+            $this->logging->log('No objects for '.$this->oidDesc['oid'], DEBUG);
576
+            $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
577 577
             return null;
578 578
         }
579 579
         
580 580
         $trapObjects=array();
581
-        while (preg_match('/ *([^ ,]+) *,* */',$objectName,$match))
581
+        while (preg_match('/ *([^ ,]+) *,* */', $objectName, $match))
582 582
         {
583
-            array_push($trapObjects,$match[1]);
584
-            $objectName=preg_replace('/'.$match[0].'/','',$objectName);
583
+            array_push($trapObjects, $match[1]);
584
+            $objectName=preg_replace('/'.$match[0].'/', '', $objectName);
585 585
         }
586 586
         return $trapObjects;
587 587
     }
@@ -593,18 +593,18 @@  discard block
 block discarded – undo
593 593
      * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
594 594
      * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
595 595
      */
596
-    public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
596
+    public function update_mib_database($display_progress=false, $check_change=false, $onlyTraps=true, $startOID='.1')
597 597
     {
598 598
         // Global Timing
599
-        $timeTaken = microtime(true);
599
+        $timeTaken=microtime(true);
600 600
         
601 601
         $numElements=$this->load_mibs_snmptranslate(); // Load objectsAll
602 602
         
603 603
         $this->load_mibs_from_db(); // Load from db dbOidAll & dbOidIndex
604 604
         
605
-        $step=$basestep=$numElements/10; // output display of % done
605
+        $step=$basestep=$numElements / 10; // output display of % done
606 606
         $num_step=0;
607
-        $timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds
607
+        $timeFiveSec=microtime(true); // Used for display a '.' every <n> seconds
608 608
         
609 609
         // Create index for trap objects
610 610
         $this->trapObjectsIndex=array();
@@ -612,33 +612,33 @@  discard block
 block discarded – undo
612 612
         // detailed timing (time_* vars)
613 613
         $this->reset_update_timers();
614 614
         
615
-        for ($curElement=0;$curElement < $numElements;$curElement++)
615
+        for ($curElement=0; $curElement < $numElements; $curElement++)
616 616
         {
617
-            $this->timing['base_time']= microtime(true);
617
+            $this->timing['base_time']=microtime(true);
618 618
             if ($display_progress)
619 619
             {
620
-                if ((microtime(true)-$timeFiveSec) > 2)
620
+                if ((microtime(true) - $timeFiveSec) > 2)
621 621
                 { // echo a . every 2 sec
622 622
                     echo '.';
623
-                    $timeFiveSec = microtime(true);
623
+                    $timeFiveSec=microtime(true);
624 624
                 }
625
-                if ($curElement>$step)
625
+                if ($curElement > $step)
626 626
                 { // display progress
627 627
                     $num_step++;
628 628
                     $step+=$basestep;   
629
-                    echo "\n" . ($num_step*10). '% : ';
629
+                    echo "\n".($num_step * 10).'% : ';
630 630
                 }
631 631
             }
632 632
             
633 633
             $this->reset_oidDesc();
634
-            if ($this->detect_trap($curElement,$onlyTraps)===true)
634
+            if ($this->detect_trap($curElement, $onlyTraps) === true)
635 635
             {
636 636
                 continue;
637 637
             }
638 638
             
639 639
             $this->timing['num_traps']++;
640 640
             
641
-            $this->logging->log('Found trap : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],INFO );
641
+            $this->logging->log('Found trap : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], INFO);
642 642
             if ($display_progress) echo '#'; // echo a # when trap found
643 643
 
644 644
             // get trap objects & source MIB
@@ -648,14 +648,14 @@  discard block
 block discarded – undo
648 648
 
649 649
             $update=$this->update_oid(); // Do update of trap.
650 650
             
651
-            $this->timing['update_time'] += microtime(true) - $this->timing['base_time'];
651
+            $this->timing['update_time']+=microtime(true) - $this->timing['base_time'];
652 652
             $this->timing['update_num']++;
653 653
             
654
-            $this->timing['base_time']= microtime(true); // Reset to check object time
654
+            $this->timing['base_time']=microtime(true); // Reset to check object time
655 655
             
656
-            if (($update==0) && ($check_change===false))
656
+            if (($update == 0) && ($check_change === false))
657 657
             { // Trapd didn't change & force check disabled
658
-                $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
658
+                $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
659 659
                 if ($display_progress) echo "C";
660 660
                 continue;
661 661
             }
@@ -668,17 +668,17 @@  discard block
 block discarded – undo
668 668
            
669 669
             $this->trap_objects($this->oidDesc['oid'], $this->oidDesc['mib'], $trapObjects, false);
670 670
             
671
-            $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
671
+            $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
672 672
             $this->timing['objects_num']++;
673 673
         }
674 674
         
675 675
         if ($display_progress)
676 676
         {
677
-            echo "\nNumber of processed traps :  ". $this->timing['num_traps'] ."\n";
678
-            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";
679
-            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";
680
-            echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'],1)." sec , ";
681
-            echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'],1)." sec \n";
677
+            echo "\nNumber of processed traps :  ".$this->timing['num_traps']."\n";
678
+            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";
679
+            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";
680
+            echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'], 1)." sec , ";
681
+            echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'], 1)." sec \n";
682 682
             
683 683
             $timeTaken=microtime(true) - $timeTaken;
684 684
             echo "Global time : ".round($timeTaken)." seconds\n";
Please login to merge, or discard this patch.