Passed
Branch master (608a4b)
by Patrick
48:57 queued 46:05
created
library/Trapdirector/TrapsProcess/Mib.php 1 patch
Spacing   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
      * @param Logging $logClass : where to log
32 32
      * @param Database $dbClass : Database
33 33
      */
34
-    function __construct($logClass,$dbClass,$snmptrans,$snmptransdir)
34
+    function __construct($logClass, $dbClass, $snmptrans, $snmptransdir)
35 35
     {
36 36
         $this->logging=$logClass;
37 37
         $this->trapsDB=$dbClass;
@@ -58,9 +58,9 @@  discard block
 block discarded – undo
58 58
             }
59 59
             $oidIndex=$this->dbOidIndex[$this->oidDesc['oid']]['key']; // Get index in dbOidAll
60 60
             $dbOid=$this->dbOidAll[$oidIndex]; // Get array of element
61
-            if ( $this->oidDesc['name'] != $dbOid['name'] ||
61
+            if ($this->oidDesc['name'] != $dbOid['name'] ||
62 62
                 $this->oidDesc['mib'] != $dbOid['mib'] ||
63
-                $this->oidDesc['type'] !=$dbOid['type']
63
+                $this->oidDesc['type'] != $dbOid['type']
64 64
                )
65 65
             { // Do update
66 66
                 $sql='UPDATE '.$this->trapsDB->dbPrefix.'mib_cache SET '.
@@ -74,22 +74,22 @@  discard block
 block discarded – undo
74 74
                     ':type' => $this->oidDesc['type'],
75 75
                     ':mib' => $this->oidDesc['mib'],
76 76
                     ':tc' =>  $this->oidDesc['textconv']??'null',
77
-                    ':display_hint' => $this->oidDesc['dispHint']??'null' ,
78
-                    ':syntax' => $this->oidDesc['syntax']==null??'null',
77
+                    ':display_hint' => $this->oidDesc['dispHint']??'null',
78
+                    ':syntax' => $this->oidDesc['syntax'] == null??'null',
79 79
                     ':type_enum' => $this->oidDesc['type_enum']??'null',
80 80
                     ':description' => $this->oidDesc['description']??'null',
81 81
                     ':id' => $this->dbOidAll[$this->dbOidIndex[$this->oidDesc['oid']]['id']]
82 82
                 );
83 83
                 
84 84
                 if ($sqlQuery->execute($sqlParam) === false) {
85
-                    $this->logging->log('Error in query : ' . $sql,ERROR,'');
85
+                    $this->logging->log('Error in query : '.$sql, ERROR, '');
86 86
                 }
87
-                $this->logging->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
87
+                $this->logging->log('Trap updated : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], DEBUG);
88 88
                 return 1;
89 89
             }
90 90
             else
91 91
             {
92
-                $this->logging->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
92
+                $this->logging->log('Trap unchanged : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], DEBUG);
93 93
                 return 0;
94 94
             }
95 95
         }
@@ -99,11 +99,11 @@  discard block
 block discarded – undo
99 99
         
100 100
         $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache '.
101 101
             '(oid, name, type , mib, textual_convention, display_hint '.
102
-            ', syntax, type_enum , description ) ' .
102
+            ', syntax, type_enum , description ) '.
103 103
             'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
104 104
             ', :syntax, :type_enum, :description )';
105 105
         
106
-        if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id';
106
+        if ($this->trapsDB->trapDBType == 'pgsql') $sql.='RETURNING id';
107 107
         
108 108
         $sqlQuery=$db_conn->prepare($sql);
109 109
         
@@ -112,15 +112,15 @@  discard block
 block discarded – undo
112 112
             ':name' => $this->oidDesc['name'],
113 113
             ':type' => $this->oidDesc['type'],
114 114
             ':mib' => $this->oidDesc['mib'],
115
-            ':tc' =>  ($this->oidDesc['textconv']==null)?'null':$this->oidDesc['textconv'] ,
116
-            ':display_hint' => ($this->oidDesc['dispHint']==null)?'null':$this->oidDesc['dispHint'] ,
117
-            ':syntax' => ($this->oidDesc['syntax']==null)?'null':$this->oidDesc['syntax'],
118
-            ':type_enum' => ($this->oidDesc['type_enum']==null)?'null':$this->oidDesc['type_enum'],
119
-            ':description' => ($this->oidDesc['description']==null)?'null':$this->oidDesc['description']
115
+            ':tc' =>  ($this->oidDesc['textconv'] == null) ? 'null' : $this->oidDesc['textconv'],
116
+            ':display_hint' => ($this->oidDesc['dispHint'] == null) ? 'null' : $this->oidDesc['dispHint'],
117
+            ':syntax' => ($this->oidDesc['syntax'] == null) ? 'null' : $this->oidDesc['syntax'],
118
+            ':type_enum' => ($this->oidDesc['type_enum'] == null) ? 'null' : $this->oidDesc['type_enum'],
119
+            ':description' => ($this->oidDesc['description'] == null) ? 'null' : $this->oidDesc['description']
120 120
         );
121 121
         
122 122
         if ($sqlQuery->execute($sqlParam) === false) {
123
-            $this->logging->log('Error in query : ' . $sql,1,'');
123
+            $this->logging->log('Error in query : '.$sql, 1, '');
124 124
         }
125 125
         
126 126
         switch ($this->trapsDB->trapDBType)
@@ -128,10 +128,10 @@  discard block
 block discarded – undo
128 128
             case 'pgsql':
129 129
                 // Get last id to insert oid/values in secondary table
130 130
                 if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {
131
-                    $this->logging->log('Error getting id - pgsql - ',1,'');
131
+                    $this->logging->log('Error getting id - pgsql - ', 1, '');
132 132
                 }
133
-                if (! isset($inserted_id_ret['id'])) {
134
-                    $this->logging->log('Error getting id - pgsql - empty.',1,'');
133
+                if (!isset($inserted_id_ret['id'])) {
134
+                    $this->logging->log('Error getting id - pgsql - empty.', 1, '');
135 135
                 }
136 136
                 $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id_ret['id'];
137 137
                 break;
@@ -139,15 +139,15 @@  discard block
 block discarded – undo
139 139
                 // Get last id to insert oid/values in secondary table
140 140
                 $sql='SELECT LAST_INSERT_ID();';
141 141
                 if (($ret_code=$db_conn->query($sql)) === false) {
142
-                    $this->logging->log('Erreur getting id - mysql - ',1,'');
142
+                    $this->logging->log('Erreur getting id - mysql - ', 1, '');
143 143
                 }
144 144
                 
145 145
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
146
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
146
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
147 147
                 $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id;
148 148
                 break;
149 149
             default:
150
-                $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,1,'');
150
+                $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType, 1, '');
151 151
         }
152 152
         
153 153
         // Set as newly created.
@@ -166,9 +166,9 @@  discard block
 block discarded – undo
166 166
         $db_conn=$this->trapsDB->db_connect_trap();
167 167
         // Get all objects
168 168
         $sql='SELECT * FROM '.$this->trapsDB->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';';
169
-        $this->logging->log('SQL query get all traps: '.$sql,DEBUG );
169
+        $this->logging->log('SQL query get all traps: '.$sql, DEBUG);
170 170
         if (($ret_code=$db_conn->query($sql)) === false) {
171
-            $this->logging->log('No result in query : ' . $sql,1,'');
171
+            $this->logging->log('No result in query : '.$sql, 1, '');
172 172
         }
173 173
         $dbObjectsRaw=$ret_code->fetchAll();
174 174
         
@@ -185,30 +185,30 @@  discard block
 block discarded – undo
185 185
  * @param string $trapmib : mib of trap
186 186
  * @return NULL|array : null if not found, or output of snmptranslate
187 187
  */
188
-    private function get_object_details($object,$trapmib)
188
+    private function get_object_details($object, $trapmib)
189 189
     {
190 190
         $match=$snmptrans=array();
191 191
         $retVal=0;
192 192
         $this->oidDesc['mib']=$trapmib;
193
-        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
194
-            ' -On -Td '.$this->oidDesc['mib'].'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
195
-        if ($retVal!=0)
193
+        exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
194
+            ' -On -Td '.$this->oidDesc['mib'].'::'.$object.' 2>/dev/null', $snmptrans, $retVal);
195
+        if ($retVal != 0)
196 196
         {
197 197
             // Maybe not trap mib, search with IR
198
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
199
-                ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
200
-            if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
198
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
199
+                ' -IR '.$object.' 2>/dev/null', $snmptrans, $retVal);
200
+            if ($retVal != 0 || !preg_match('/(.*)::(.*)/', $snmptrans[0], $match))
201 201
             { // Not found -> continue with warning
202
-                $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
202
+                $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object, 2, '');
203 203
                 return null;
204 204
             }
205 205
             $this->oidDesc['mib']=$match[1];
206 206
             
207 207
             // Do the snmptranslate again.
208
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
209
-                ' -On -Td '.$this->oidDesc['mib'].'::'.$object,$snmptrans,$retVal);
210
-            if ($retVal!=0) {
211
-                $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object,2,'');
208
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
209
+                ' -On -Td '.$this->oidDesc['mib'].'::'.$object, $snmptrans, $retVal);
210
+            if ($retVal != 0) {
211
+                $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object, 2, '');
212 212
                 return null;
213 213
             }
214 214
             
@@ -228,12 +228,12 @@  discard block
 block discarded – undo
228 228
         
229 229
         foreach ($snmptrans as $line)
230 230
         {
231
-            if ($indesc===true)
231
+            if ($indesc === true)
232 232
             {
233
-                $line=preg_replace('/[\t ]+/',' ',$line);
234
-                if (preg_match('/(.*)"$/', $line,$match))
233
+                $line=preg_replace('/[\t ]+/', ' ', $line);
234
+                if (preg_match('/(.*)"$/', $line, $match))
235 235
                 {
236
-                    $this->oidDesc['description'] = $tmpdesc . $match[1];
236
+                    $this->oidDesc['description']=$tmpdesc.$match[1];
237 237
                     $indesc=false;
238 238
                 }
239 239
                 $tmpdesc.=$line;
@@ -244,34 +244,34 @@  discard block
 block discarded – undo
244 244
                 $this->oidDesc['oid']=$line;
245 245
                 continue;
246 246
             }
247
-            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
247
+            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/', $line, $match))
248 248
             {
249 249
                 $this->oidDesc['syntax']=$match[1];
250 250
                 $this->oidDesc['type_enum']=$match[2];
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
                 continue;
257 257
             }
258
-            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
258
+            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/', $line, $match))
259 259
             {
260 260
                 $this->oidDesc['dispHint']=$match[1];
261 261
                 continue;
262 262
             }
263
-            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
263
+            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/', $line, $match))
264 264
             {
265 265
                 $this->oidDesc['description']=$match[1];
266 266
                 continue;
267 267
             }
268
-            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
268
+            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $line, $match))
269 269
             {
270 270
                 $tmpdesc=$match[1];
271 271
                 $indesc=true;
272 272
                 continue;
273 273
             }
274
-            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
274
+            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/', $line, $match))
275 275
             {
276 276
                 $this->oidDesc['textconv']=$match[1];
277 277
                 continue;
@@ -286,9 +286,9 @@  discard block
 block discarded – undo
286 286
      * @param array $objects : array of objects name (without MIB)
287 287
      * @param bool $check_existing : check instead of create
288 288
      */
289
-    public function trap_objects($trapOID,$trapmib,$objects,$check_existing)
289
+    public function trap_objects($trapOID, $trapmib, $objects, $check_existing)
290 290
     {              
291
-        $trapId = $this->dbOidIndex[$trapOID]['id']; // Get id of trap
291
+        $trapId=$this->dbOidIndex[$trapOID]['id']; // Get id of trap
292 292
         
293 293
         if ($check_existing === true)
294 294
         {
@@ -305,9 +305,9 @@  discard block
 block discarded – undo
305 305
             
306 306
             $this->parse_object($snmptrans);
307 307
 
308
-            $this->oidDesc['name'] = $object;
308
+            $this->oidDesc['name']=$object;
309 309
             
310
-            $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 );
310
+            $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);
311 311
 
312 312
             // Update
313 313
             $this->update_oid();
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
             );
333 333
             
334 334
             if ($sqlQuery->execute($sqlParam) === false) {
335
-                $this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$this->oidDesc['oid']]['id'] ,1,'');
335
+                $this->logging->log('Error adding trap object : '.$sql.' / '.$trapId.'/'.$this->dbOidIndex[$this->oidDesc['oid']]['id'], 1, '');
336 336
             }
337 337
         }
338 338
         if ($check_existing === true)
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
         $this->oidDesc['type']=null;
350 350
         $this->oidDesc['mib']=null;
351 351
         $this->oidDesc['textconv']=null;
352
-        $this->oidDesc['dispHint'] =null;
352
+        $this->oidDesc['dispHint']=null;
353 353
         $this->oidDesc['syntax']=null;
354 354
         $this->oidDesc['type_enum']=null;
355 355
         $this->oidDesc['description']=null;
@@ -363,17 +363,17 @@  discard block
 block discarded – undo
363 363
     {
364 364
         $retVal=0;
365 365
         // Get all mib objects from all mibs
366
-        $snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null';
367
-        $this->logging->log('Getting all traps : '.$snmpCommand,DEBUG );
366
+        $snmpCommand=$this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null';
367
+        $this->logging->log('Getting all traps : '.$snmpCommand, DEBUG);
368 368
         unset($this->objectsAll);
369
-        exec($snmpCommand,$this->objectsAll,$retVal);
370
-        if ($retVal!=0)
369
+        exec($snmpCommand, $this->objectsAll, $retVal);
370
+        if ($retVal != 0)
371 371
         {
372
-            $this->logging->log('error executing snmptranslate',ERROR,'');
372
+            $this->logging->log('error executing snmptranslate', ERROR, '');
373 373
         }
374 374
         // Count elements to show progress
375 375
         $numElements=count($this->objectsAll);
376
-        $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO );
376
+        $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements, INFO);
377 377
         return $numElements;
378 378
     }
379 379
 
@@ -387,14 +387,14 @@  discard block
 block discarded – undo
387 387
         $db_conn=$this->trapsDB->db_connect_trap();
388 388
         
389 389
         $sql='SELECT * from '.$this->trapsDB->dbPrefix.'mib_cache;';
390
-        $this->logging->log('SQL query : '.$sql,DEBUG );
390
+        $this->logging->log('SQL query : '.$sql, DEBUG);
391 391
         if (($ret_code=$db_conn->query($sql)) === false) {
392
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
392
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
393 393
         }
394 394
         $this->dbOidAll=$ret_code->fetchAll();
395 395
         $this->dbOidIndex=array();
396 396
         // Create the index for db;
397
-        foreach($this->dbOidAll as $key=>$val)
397
+        foreach ($this->dbOidAll as $key=>$val)
398 398
         {
399 399
             $this->dbOidIndex[$val['oid']]['key']=$key;
400 400
             $this->dbOidIndex[$val['oid']]['id']=$val['id'];
@@ -427,13 +427,13 @@  discard block
 block discarded – undo
427 427
      * @param bool $onlyTraps : set to false to get all and not only traps.
428 428
      * @return boolean : false if it's a trap , true if not
429 429
      */
430
-    private function detect_trap($curElement,$onlyTraps)
430
+    private function detect_trap($curElement, $onlyTraps)
431 431
     {
432 432
         // Get oid or pass if not found
433
-        if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
433
+        if (!preg_match('/^\.[0-9\.]+$/', $this->objectsAll[$curElement]))
434 434
         {
435
-            $this->timing['base_parse_time'] += microtime(true) - $this->timing['base_time'];
436
-            $this->timing['base_parse_num'] ++;
435
+            $this->timing['base_parse_time']+=microtime(true) - $this->timing['base_time'];
436
+            $this->timing['base_parse_num']++;
437 437
             return true;
438 438
         }
439 439
         $this->oidDesc['oid']=$this->objectsAll[$curElement];
@@ -442,9 +442,9 @@  discard block
 block discarded – undo
442 442
         $curElement++;
443 443
         $match=$snmptrans=array();
444 444
         if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
445
-            $this->objectsAll[$curElement],$match))
445
+            $this->objectsAll[$curElement], $match))
446 446
         {
447
-            $this->timing['base_check_time'] += microtime(true) - $this->timing['base_time'];
447
+            $this->timing['base_check_time']+=microtime(true) - $this->timing['base_time'];
448 448
             $this->timing['base_check_num']++;
449 449
             return true;
450 450
         }
@@ -452,22 +452,22 @@  discard block
 block discarded – undo
452 452
         $this->oidDesc['name']=$match[1]; // Name
453 453
         $this->oidDesc['type']=$match[2]; // type (21=trap, 0: may be trap, else : not trap
454 454
         
455
-        if ($this->oidDesc['type']==0) // object type=0 : check if v1 trap
455
+        if ($this->oidDesc['type'] == 0) // object type=0 : check if v1 trap
456 456
         {
457 457
             // Check if next is suboid -> in that case is cannot be a trap
458
-            if (preg_match("/^".$this->oidDesc['oid']."/",$this->objectsAll[$curElement+1]))
458
+            if (preg_match("/^".$this->oidDesc['oid']."/", $this->objectsAll[$curElement + 1]))
459 459
             {
460
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
460
+                $this->timing['type0_check_time']+=microtime(true) - $this->timing['base_time'];
461 461
                 $this->timing['type0_check_num']++;
462 462
                 return true;
463 463
             }
464 464
             unset($snmptrans);
465 465
             $retVal=0;
466
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
467
-                ' -Td '.$this->oidDesc['oid'] . ' | grep OBJECTS ',$snmptrans,$retVal);
468
-            if ($retVal!=0)
466
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
467
+                ' -Td '.$this->oidDesc['oid'].' | grep OBJECTS ', $snmptrans, $retVal);
468
+            if ($retVal != 0)
469 469
             {
470
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
470
+                $this->timing['type0_check_time']+=microtime(true) - $this->timing['base_time'];
471 471
                 $this->timing['type0_check_num']++;
472 472
                 return true;
473 473
             }
@@ -475,9 +475,9 @@  discard block
 block discarded – undo
475 475
             // Force as trap.
476 476
             $this->oidDesc['type']=21;
477 477
         }
478
-        if ($onlyTraps===true && $this->oidDesc['type']!=21) // if only traps and not a trap, continue
478
+        if ($onlyTraps === true && $this->oidDesc['type'] != 21) // if only traps and not a trap, continue
479 479
         {
480
-            $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time'];
480
+            $this->timing['nottrap_time']+=microtime(true) - $this->timing['base_time'];
481 481
             $this->timing['nottrap_num']++;
482 482
             return true;
483 483
         }
@@ -489,33 +489,33 @@  discard block
 block discarded – undo
489 489
     {
490 490
         $retVal=0;
491 491
         $match=$snmptrans=array();
492
-        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
493
-            ' -Td '.$this->oidDesc['oid'],$snmptrans,$retVal);
494
-        if ($retVal!=0)
492
+        exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
493
+            ' -Td '.$this->oidDesc['oid'], $snmptrans, $retVal);
494
+        if ($retVal != 0)
495 495
         {
496
-            $this->logging->log('error executing snmptranslate',ERROR);
496
+            $this->logging->log('error executing snmptranslate', ERROR);
497 497
         }
498 498
         
499
-        if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
499
+        if (!preg_match('/^(.*)::/', $snmptrans[0], $match))
500 500
         {
501
-            $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : ' . $snmptrans[0],ERROR);
501
+            $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : '.$snmptrans[0], ERROR);
502 502
         }
503 503
         $this->oidDesc['mib']=$match[1];
504 504
         
505 505
         $numLine=1;
506
-        while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
506
+        while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $snmptrans[$numLine], $match)) $numLine++;
507 507
         if (isset($snmptrans[$numLine]))
508 508
         {
509
-            $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
509
+            $snmptrans[$numLine]=preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/', '', $snmptrans[$numLine]);
510 510
             
511
-            while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
511
+            while (isset($snmptrans[$numLine]) && !preg_match('/"/', $snmptrans[$numLine]))
512 512
             {
513
-                $this->oidDesc['description'].=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
513
+                $this->oidDesc['description'].=preg_replace('/[\t ]+/', ' ', $snmptrans[$numLine]);
514 514
                 $numLine++;
515 515
             }
516 516
             if (isset($snmptrans[$numLine])) {
517
-                $this->oidDesc['description'].=preg_replace('/".*/','',$snmptrans[$numLine]);
518
-                $this->oidDesc['description']=preg_replace('/[\t ]+/',' ',$this->oidDesc['description']);
517
+                $this->oidDesc['description'].=preg_replace('/".*/', '', $snmptrans[$numLine]);
518
+                $this->oidDesc['description']=preg_replace('/[\t ]+/', ' ', $this->oidDesc['description']);
519 519
             }
520 520
             
521 521
         }
@@ -529,18 +529,18 @@  discard block
 block discarded – undo
529 529
      * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
530 530
      * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
531 531
      */
532
-    public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
532
+    public function update_mib_database($display_progress=false, $check_change=false, $onlyTraps=true, $startOID='.1')
533 533
     {
534 534
         // Global Timing
535
-        $timeTaken = microtime(true);
535
+        $timeTaken=microtime(true);
536 536
         
537 537
         $numElements=$this->load_mibs_snmptranslate(); // Load objectsAll
538 538
         
539 539
         $this->load_mibs_from_db(); // Load from db dbOidAll & dbOidIndex
540 540
         
541
-        $step=$basestep=$numElements/10; // output display of % done
541
+        $step=$basestep=$numElements / 10; // output display of % done
542 542
         $num_step=0;
543
-        $timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds
543
+        $timeFiveSec=microtime(true); // Used for display a '.' every <n> seconds
544 544
         
545 545
         // Create index for trap objects
546 546
         $this->trapObjectsIndex=array();
@@ -548,33 +548,33 @@  discard block
 block discarded – undo
548 548
         // detailed timing (time_* vars)
549 549
         $this->reset_update_timers();
550 550
         
551
-        for ($curElement=0;$curElement < $numElements;$curElement++)
551
+        for ($curElement=0; $curElement < $numElements; $curElement++)
552 552
         {
553
-            $this->timing['base_time']= microtime(true);
553
+            $this->timing['base_time']=microtime(true);
554 554
             if ($display_progress)
555 555
             {
556
-                if ((microtime(true)-$timeFiveSec) > 2)
556
+                if ((microtime(true) - $timeFiveSec) > 2)
557 557
                 { // echo a . every 2 sec
558 558
                     echo '.';
559
-                    $timeFiveSec = microtime(true);
559
+                    $timeFiveSec=microtime(true);
560 560
                 }
561
-                if ($curElement>$step)
561
+                if ($curElement > $step)
562 562
                 { // display progress
563 563
                     $num_step++;
564 564
                     $step+=$basestep;   
565
-                    echo "\n" . ($num_step*10). '% : ';
565
+                    echo "\n".($num_step * 10).'% : ';
566 566
                 }
567 567
             }
568 568
             
569 569
             $this->reset_oidDesc();
570
-            if ($this->detect_trap($curElement,$onlyTraps)===true)
570
+            if ($this->detect_trap($curElement, $onlyTraps) === true)
571 571
             {
572 572
                 continue;
573 573
             }
574 574
             
575 575
             $this->timing['num_traps']++;
576 576
             
577
-            $this->logging->log('Found trap : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],INFO );
577
+            $this->logging->log('Found trap : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], INFO);
578 578
             if ($display_progress) echo '#'; // echo a # when trap found
579 579
             
580 580
             //################################
@@ -585,14 +585,14 @@  discard block
 block discarded – undo
585 585
             //################################
586 586
             $update=$this->update_oid(); // Do update of trap.
587 587
             
588
-            $this->timing['update_time'] += microtime(true) - $this->timing['base_time'];
588
+            $this->timing['update_time']+=microtime(true) - $this->timing['base_time'];
589 589
             $this->timing['update_num']++;
590 590
             
591
-            $this->timing['base_time']= microtime(true); // Reset to check object time
591
+            $this->timing['base_time']=microtime(true); // Reset to check object time
592 592
             
593
-            if (($update==0) && ($check_change===false))
593
+            if (($update == 0) && ($check_change === false))
594 594
             { // Trapd didn't change & force check disabled
595
-                $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
595
+                $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
596 596
                 if ($display_progress) echo "C";
597 597
                 continue;
598 598
             }
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
             $match=array();
602 602
             foreach ($snmptrans as $line)
603 603
             {
604
-                if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
604
+                if (preg_match('/OBJECTS.*\{([^\}]+)\}/', $line, $match))
605 605
                 {
606 606
                     $synt=$match[1];
607 607
                 }
@@ -609,30 +609,30 @@  discard block
 block discarded – undo
609 609
             if ($synt == null)
610 610
             {
611 611
                 //echo "No objects for $trapOID\n";
612
-                $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
612
+                $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
613 613
                 continue;
614 614
             }
615 615
             //echo "$synt \n";
616 616
             $trapObjects=array();
617
-            while (preg_match('/ *([^ ,]+) *,* */',$synt,$match))
617
+            while (preg_match('/ *([^ ,]+) *,* */', $synt, $match))
618 618
             {
619
-                array_push($trapObjects,$match[1]);
620
-                $synt=preg_replace('/'.$match[0].'/','',$synt);
619
+                array_push($trapObjects, $match[1]);
620
+                $synt=preg_replace('/'.$match[0].'/', '', $synt);
621 621
             }
622 622
             
623 623
             $this->trap_objects($this->oidDesc['oid'], $this->oidDesc['mib'], $trapObjects, false);
624 624
             
625
-            $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
625
+            $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
626 626
             $this->timing['objects_num']++;
627 627
         }
628 628
         
629 629
         if ($display_progress)
630 630
         {
631
-            echo "\nNumber of processed traps :  ". $this->timing['num_traps'] ."\n";
632
-            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";
633
-            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";
634
-            echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'],1)." sec , ";
635
-            echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'],1)." sec \n";
631
+            echo "\nNumber of processed traps :  ".$this->timing['num_traps']."\n";
632
+            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";
633
+            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";
634
+            echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'], 1)." sec , ";
635
+            echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'], 1)." sec \n";
636 636
             
637 637
             $timeTaken=microtime(true) - $timeTaken;
638 638
             echo "Global time : ".round($timeTaken)." seconds\n";
Please login to merge, or discard this patch.