Passed
Push — master ( 7048d4...c63076 )
by Patrick
02:08
created
library/Trapdirector/TrapsProcess/MibDatabase.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
         }
47 47
         $oidIndex=$this->dbOidIndex[$this->oidDesc['oid']]['key']; // Get index in dbOidAll
48 48
         $dbOid=$this->dbOidAll[$oidIndex]; // Get array of element
49
-        if ( $this->oidDesc['name'] != $dbOid['name'] ||
49
+        if ($this->oidDesc['name'] != $dbOid['name'] ||
50 50
             $this->oidDesc['mib'] != $dbOid['mib'] ||
51
-            $this->oidDesc['type'] !=$dbOid['type']
51
+            $this->oidDesc['type'] != $dbOid['type']
52 52
             )
53 53
         { // Do update
54 54
             $sql='UPDATE '.$this->getTrapsDB()->dbPrefix.'mib_cache SET '.
@@ -62,22 +62,22 @@  discard block
 block discarded – undo
62 62
                 ':type' => $this->oidDesc['type'],
63 63
                 ':mib' => $this->oidDesc['mib'],
64 64
                 ':tc' =>  $this->oidDesc['textconv']??'null',
65
-                ':display_hint' => $this->oidDesc['dispHint']??'null' ,
66
-                ':syntax' => $this->oidDesc['syntax']==null??'null',
65
+                ':display_hint' => $this->oidDesc['dispHint']??'null',
66
+                ':syntax' => $this->oidDesc['syntax'] == null??'null',
67 67
                 ':type_enum' => $this->oidDesc['type_enum']??'null',
68 68
                 ':description' => $this->oidDesc['description']??'null',
69 69
                 ':id' => $this->dbOidAll[$this->dbOidIndex[$this->oidDesc['oid']]['id']]
70 70
             );
71 71
             
72 72
             if ($sqlQuery->execute($sqlParam) === false) {
73
-                $this->getLogging()->log('Error in query : ' . $sql,ERROR,'');
73
+                $this->getLogging()->log('Error in query : '.$sql, ERROR, '');
74 74
             }
75
-            $this->getLogging()->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
75
+            $this->getLogging()->log('Trap updated : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], DEBUG);
76 76
             return 1;
77 77
         }
78 78
         else
79 79
         {
80
-            $this->getLogging()->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
80
+            $this->getLogging()->log('Trap unchanged : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], DEBUG);
81 81
             return 0;
82 82
         }
83 83
     }
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
         $db_conn=$this->getTrapsDB()->db_connect_trap();
94 94
         $sql='INSERT INTO '.$this->getTrapsDB()->dbPrefix.'mib_cache '.
95 95
             '(oid, name, type , mib, textual_convention, display_hint '.
96
-            ', syntax, type_enum , description ) ' .
96
+            ', syntax, type_enum , description ) '.
97 97
             'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
98 98
             ', :syntax, :type_enum, :description )';
99 99
         
100
-        if ($this->getTrapsDB()->trapDBType == 'pgsql') $sql .= 'RETURNING id';
100
+        if ($this->getTrapsDB()->trapDBType == 'pgsql') $sql.='RETURNING id';
101 101
         
102 102
         $sqlQuery=$db_conn->prepare($sql);
103 103
         
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         );
115 115
         
116 116
         if ($sqlQuery->execute($sqlParam) === false) {
117
-            $this->getLogging()->log('Error in query : ' . $sql,1,'');
117
+            $this->getLogging()->log('Error in query : '.$sql, 1, '');
118 118
         }
119 119
         
120 120
         switch ($this->getTrapsDB()->trapDBType)
@@ -122,10 +122,10 @@  discard block
 block discarded – undo
122 122
             case 'pgsql':
123 123
                 // Get last id to insert oid/values in secondary table
124 124
                 if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {
125
-                    $this->getLogging()->log('Error getting id - pgsql - ',1,'');
125
+                    $this->getLogging()->log('Error getting id - pgsql - ', 1, '');
126 126
                 }
127
-                if (! isset($inserted_id_ret['id'])) {
128
-                    $this->getLogging()->log('Error getting id - pgsql - empty.',ERROR);
127
+                if (!isset($inserted_id_ret['id'])) {
128
+                    $this->getLogging()->log('Error getting id - pgsql - empty.', ERROR);
129 129
                     return 0;
130 130
                 }
131 131
                 $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id_ret['id'];
@@ -134,16 +134,16 @@  discard block
 block discarded – undo
134 134
                 // Get last id to insert oid/values in secondary table
135 135
                 $sql='SELECT LAST_INSERT_ID();';
136 136
                 if (($ret_code=$db_conn->query($sql)) === false) {
137
-                    $this->getLogging()->log('Erreur getting id - mysql - ',ERROR);
137
+                    $this->getLogging()->log('Erreur getting id - mysql - ', ERROR);
138 138
                     return 0;
139 139
                 }
140 140
                 
141 141
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
142
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
142
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
143 143
                 $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id;
144 144
                 break;
145 145
             default:
146
-                $this->getLogging()->log('Error SQL type Unknown : '.$this->getTrapsDB()->trapDBType,ERROR);
146
+                $this->getLogging()->log('Error SQL type Unknown : '.$this->getTrapsDB()->trapDBType, ERROR);
147 147
                 return 0;
148 148
         }
149 149
         
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
         $db_conn=$this->getTrapsDB()->db_connect_trap();
164 164
         // Get all objects
165 165
         $sql='SELECT * FROM '.$this->getTrapsDB()->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';';
166
-        $this->getLogging()->log('SQL query get all traps: '.$sql,DEBUG );
166
+        $this->getLogging()->log('SQL query get all traps: '.$sql, DEBUG);
167 167
         if (($ret_code=$db_conn->query($sql)) === false) {
168
-            $this->getLogging()->log('No result in query : ' . $sql,1,'');
168
+            $this->getLogging()->log('No result in query : '.$sql, 1, '');
169 169
         }
170 170
         $dbObjectsRaw=$ret_code->fetchAll();
171 171
         
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/Mib.php 1 patch
Spacing   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      * @param Logging $logClass : where to log
42 42
      * @param Database $dbClass : Database
43 43
      */
44
-    function __construct($logClass,$dbClass,$snmptrans,$snmptransdir)
44
+    function __construct($logClass, $dbClass, $snmptrans, $snmptransdir)
45 45
     {
46 46
         $this->logging=$logClass;
47 47
         $this->trapsDB=$dbClass;
@@ -72,30 +72,30 @@  discard block
 block discarded – undo
72 72
  * @param string $trapmib : mib of trap
73 73
  * @return NULL|array : null if not found, or output of snmptranslate
74 74
  */
75
-    private function get_object_details($object,$trapmib)
75
+    private function get_object_details($object, $trapmib)
76 76
     {
77 77
         $match=$snmptrans=array();
78 78
         $retVal=0;
79 79
         $this->oidDesc['mib']=$trapmib;
80
-        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
81
-            ' -On -Td '.$this->oidDesc['mib'].'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
82
-        if ($retVal!=0)
80
+        exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
81
+            ' -On -Td '.$this->oidDesc['mib'].'::'.$object.' 2>/dev/null', $snmptrans, $retVal);
82
+        if ($retVal != 0)
83 83
         {
84 84
             // Maybe not trap mib, search with IR
85
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
86
-                ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
87
-            if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
85
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
86
+                ' -IR '.$object.' 2>/dev/null', $snmptrans, $retVal);
87
+            if ($retVal != 0 || !preg_match('/(.*)::(.*)/', $snmptrans[0], $match))
88 88
             { // Not found -> continue with warning
89
-                $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
89
+                $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object, 2, '');
90 90
                 return null;
91 91
             }
92 92
             $this->oidDesc['mib']=$match[1];
93 93
             
94 94
             // Do the snmptranslate again.
95
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
96
-                ' -On -Td '.$this->oidDesc['mib'].'::'.$object,$snmptrans,$retVal);
97
-            if ($retVal!=0) {
98
-                $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object,2,'');
95
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
96
+                ' -On -Td '.$this->oidDesc['mib'].'::'.$object, $snmptrans, $retVal);
97
+            if ($retVal != 0) {
98
+                $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object, 2, '');
99 99
                 return null;
100 100
             }
101 101
             
@@ -115,12 +115,12 @@  discard block
 block discarded – undo
115 115
         
116 116
         foreach ($snmptrans as $line)
117 117
         {
118
-            if ($indesc===true)
118
+            if ($indesc === true)
119 119
             {
120
-                $line=preg_replace('/[\t ]+/',' ',$line);
121
-                if (preg_match('/(.*)"$/', $line,$match))
120
+                $line=preg_replace('/[\t ]+/', ' ', $line);
121
+                if (preg_match('/(.*)"$/', $line, $match))
122 122
                 {
123
-                    $this->oidDesc['description'] = $tmpdesc . $match[1];
123
+                    $this->oidDesc['description']=$tmpdesc.$match[1];
124 124
                     $indesc=false;
125 125
                 }
126 126
                 $tmpdesc.=$line;
@@ -131,34 +131,34 @@  discard block
 block discarded – undo
131 131
                 $this->oidDesc['oid']=$line;
132 132
                 continue;
133 133
             }
134
-            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
134
+            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/', $line, $match))
135 135
             {
136 136
                 $this->oidDesc['syntax']=$match[1];
137 137
                 $this->oidDesc['type_enum']=$match[2];
138 138
                 continue;
139 139
             }
140
-            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
140
+            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/', $line, $match))
141 141
             {
142 142
                 $this->oidDesc['syntax']=$match[1];
143 143
                 continue;
144 144
             }
145
-            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
145
+            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/', $line, $match))
146 146
             {
147 147
                 $this->oidDesc['dispHint']=$match[1];
148 148
                 continue;
149 149
             }
150
-            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
150
+            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/', $line, $match))
151 151
             {
152 152
                 $this->oidDesc['description']=$match[1];
153 153
                 continue;
154 154
             }
155
-            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
155
+            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $line, $match))
156 156
             {
157 157
                 $tmpdesc=$match[1];
158 158
                 $indesc=true;
159 159
                 continue;
160 160
             }
161
-            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
161
+            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/', $line, $match))
162 162
             {
163 163
                 $this->oidDesc['textconv']=$match[1];
164 164
                 continue;
@@ -173,9 +173,9 @@  discard block
 block discarded – undo
173 173
      * @param array $objects : array of objects name (without MIB)
174 174
      * @param bool $check_existing : check instead of create
175 175
      */
176
-    public function trap_objects($trapOID,$trapmib,$objects,$check_existing)
176
+    public function trap_objects($trapOID, $trapmib, $objects, $check_existing)
177 177
     {              
178
-        $trapId = $this->dbOidIndex[$trapOID]['id']; // Get id of trap
178
+        $trapId=$this->dbOidIndex[$trapOID]['id']; // Get id of trap
179 179
         
180 180
         if ($check_existing === true)
181 181
         {
@@ -192,9 +192,9 @@  discard block
 block discarded – undo
192 192
             
193 193
             $this->parse_object($snmptrans);
194 194
 
195
-            $this->oidDesc['name'] = $object;
195
+            $this->oidDesc['name']=$object;
196 196
             
197
-            $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 );
197
+            $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);
198 198
 
199 199
             // Update
200 200
             $this->update_oid();
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
             );
220 220
             
221 221
             if ($sqlQuery->execute($sqlParam) === false) {
222
-                $this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$this->oidDesc['oid']]['id'] ,1,'');
222
+                $this->logging->log('Error adding trap object : '.$sql.' / '.$trapId.'/'.$this->dbOidIndex[$this->oidDesc['oid']]['id'], 1, '');
223 223
             }
224 224
         }
225 225
         if ($check_existing === true)
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
         $this->oidDesc['type']=null;
237 237
         $this->oidDesc['mib']=null;
238 238
         $this->oidDesc['textconv']=null;
239
-        $this->oidDesc['dispHint'] =null;
239
+        $this->oidDesc['dispHint']=null;
240 240
         $this->oidDesc['syntax']=null;
241 241
         $this->oidDesc['type_enum']=null;
242 242
         $this->oidDesc['description']=null;
@@ -250,17 +250,17 @@  discard block
 block discarded – undo
250 250
     {
251 251
         $retVal=0;
252 252
         // Get all mib objects from all mibs
253
-        $snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null';
254
-        $this->logging->log('Getting all traps : '.$snmpCommand,DEBUG );
253
+        $snmpCommand=$this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null';
254
+        $this->logging->log('Getting all traps : '.$snmpCommand, DEBUG);
255 255
         unset($this->objectsAll);
256
-        exec($snmpCommand,$this->objectsAll,$retVal);
257
-        if ($retVal!=0)
256
+        exec($snmpCommand, $this->objectsAll, $retVal);
257
+        if ($retVal != 0)
258 258
         {
259
-            $this->logging->log('error executing snmptranslate',ERROR,'');
259
+            $this->logging->log('error executing snmptranslate', ERROR, '');
260 260
         }
261 261
         // Count elements to show progress
262 262
         $numElements=count($this->objectsAll);
263
-        $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO );
263
+        $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements, INFO);
264 264
         return $numElements;
265 265
     }
266 266
 
@@ -274,14 +274,14 @@  discard block
 block discarded – undo
274 274
         $db_conn=$this->trapsDB->db_connect_trap();
275 275
         
276 276
         $sql='SELECT * from '.$this->trapsDB->dbPrefix.'mib_cache;';
277
-        $this->logging->log('SQL query : '.$sql,DEBUG );
277
+        $this->logging->log('SQL query : '.$sql, DEBUG);
278 278
         if (($ret_code=$db_conn->query($sql)) === false) {
279
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
279
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
280 280
         }
281 281
         $this->dbOidAll=$ret_code->fetchAll();
282 282
         $this->dbOidIndex=array();
283 283
         // Create the index for db;
284
-        foreach($this->dbOidAll as $key=>$val)
284
+        foreach ($this->dbOidAll as $key=>$val)
285 285
         {
286 286
             $this->dbOidIndex[$val['oid']]['key']=$key;
287 287
             $this->dbOidIndex[$val['oid']]['id']=$val['id'];
@@ -314,13 +314,13 @@  discard block
 block discarded – undo
314 314
      * @param bool $onlyTraps : set to false to get all and not only traps.
315 315
      * @return boolean : false if it's a trap , true if not
316 316
      */
317
-    private function detect_trap($curElement,$onlyTraps)
317
+    private function detect_trap($curElement, $onlyTraps)
318 318
     {
319 319
         // Get oid or pass if not found
320
-        if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
320
+        if (!preg_match('/^\.[0-9\.]+$/', $this->objectsAll[$curElement]))
321 321
         {
322
-            $this->timing['base_parse_time'] += microtime(true) - $this->timing['base_time'];
323
-            $this->timing['base_parse_num'] ++;
322
+            $this->timing['base_parse_time']+=microtime(true) - $this->timing['base_time'];
323
+            $this->timing['base_parse_num']++;
324 324
             return true;
325 325
         }
326 326
         $this->oidDesc['oid']=$this->objectsAll[$curElement];
@@ -329,9 +329,9 @@  discard block
 block discarded – undo
329 329
         $curElement++;
330 330
         $match=$snmptrans=array();
331 331
         if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
332
-            $this->objectsAll[$curElement],$match))
332
+            $this->objectsAll[$curElement], $match))
333 333
         {
334
-            $this->timing['base_check_time'] += microtime(true) - $this->timing['base_time'];
334
+            $this->timing['base_check_time']+=microtime(true) - $this->timing['base_time'];
335 335
             $this->timing['base_check_num']++;
336 336
             return true;
337 337
         }
@@ -339,22 +339,22 @@  discard block
 block discarded – undo
339 339
         $this->oidDesc['name']=$match[1]; // Name
340 340
         $this->oidDesc['type']=$match[2]; // type (21=trap, 0: may be trap, else : not trap
341 341
         
342
-        if ($this->oidDesc['type']==0) // object type=0 : check if v1 trap
342
+        if ($this->oidDesc['type'] == 0) // object type=0 : check if v1 trap
343 343
         {
344 344
             // Check if next is suboid -> in that case is cannot be a trap
345
-            if (preg_match("/^".$this->oidDesc['oid']."/",$this->objectsAll[$curElement+1]))
345
+            if (preg_match("/^".$this->oidDesc['oid']."/", $this->objectsAll[$curElement + 1]))
346 346
             {
347
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
347
+                $this->timing['type0_check_time']+=microtime(true) - $this->timing['base_time'];
348 348
                 $this->timing['type0_check_num']++;
349 349
                 return true;
350 350
             }
351 351
             unset($snmptrans);
352 352
             $retVal=0;
353
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
354
-                ' -Td '.$this->oidDesc['oid'] . ' | grep OBJECTS ',$snmptrans,$retVal);
355
-            if ($retVal!=0)
353
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
354
+                ' -Td '.$this->oidDesc['oid'].' | grep OBJECTS ', $snmptrans, $retVal);
355
+            if ($retVal != 0)
356 356
             {
357
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
357
+                $this->timing['type0_check_time']+=microtime(true) - $this->timing['base_time'];
358 358
                 $this->timing['type0_check_num']++;
359 359
                 return true;
360 360
             }
@@ -362,9 +362,9 @@  discard block
 block discarded – undo
362 362
             // Force as trap.
363 363
             $this->oidDesc['type']=21;
364 364
         }
365
-        if ($onlyTraps===true && $this->oidDesc['type']!=21) // if only traps and not a trap, continue
365
+        if ($onlyTraps === true && $this->oidDesc['type'] != 21) // if only traps and not a trap, continue
366 366
         {
367
-            $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time'];
367
+            $this->timing['nottrap_time']+=microtime(true) - $this->timing['base_time'];
368 368
             $this->timing['nottrap_num']++;
369 369
             return true;
370 370
         }
@@ -379,35 +379,35 @@  discard block
 block discarded – undo
379 379
     {
380 380
         $retVal=0;
381 381
         $match=$snmptrans=array();
382
-        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
383
-            ' -Td '.$this->oidDesc['oid'],$snmptrans,$retVal);
384
-        if ($retVal!=0)
382
+        exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
383
+            ' -Td '.$this->oidDesc['oid'], $snmptrans, $retVal);
384
+        if ($retVal != 0)
385 385
         {
386
-            $this->logging->log('error executing snmptranslate',ERROR);
386
+            $this->logging->log('error executing snmptranslate', ERROR);
387 387
             return $snmptrans;
388 388
         }
389 389
         
390
-        if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
390
+        if (!preg_match('/^(.*)::/', $snmptrans[0], $match))
391 391
         {
392
-            $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : ' . $snmptrans[0],ERROR);
392
+            $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : '.$snmptrans[0], ERROR);
393 393
             return $snmptrans;
394 394
         }
395 395
         $this->oidDesc['mib']=$match[1];
396 396
         
397 397
         $numLine=1;
398
-        while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
398
+        while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $snmptrans[$numLine], $match)) $numLine++;
399 399
         if (isset($snmptrans[$numLine]))
400 400
         {
401
-            $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
401
+            $snmptrans[$numLine]=preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/', '', $snmptrans[$numLine]);
402 402
             
403
-            while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
403
+            while (isset($snmptrans[$numLine]) && !preg_match('/"/', $snmptrans[$numLine]))
404 404
             {
405
-                $this->oidDesc['description'].=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
405
+                $this->oidDesc['description'].=preg_replace('/[\t ]+/', ' ', $snmptrans[$numLine]);
406 406
                 $numLine++;
407 407
             }
408 408
             if (isset($snmptrans[$numLine])) {
409
-                $this->oidDesc['description'].=preg_replace('/".*/','',$snmptrans[$numLine]);
410
-                $this->oidDesc['description']=preg_replace('/[\t ]+/',' ',$this->oidDesc['description']);
409
+                $this->oidDesc['description'].=preg_replace('/".*/', '', $snmptrans[$numLine]);
410
+                $this->oidDesc['description']=preg_replace('/[\t ]+/', ' ', $this->oidDesc['description']);
411 411
             }
412 412
             
413 413
         }
@@ -425,23 +425,23 @@  discard block
 block discarded – undo
425 425
         $match=array();
426 426
         foreach ($snmptrans as $line)
427 427
         {
428
-            if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
428
+            if (preg_match('/OBJECTS.*\{([^\}]+)\}/', $line, $match))
429 429
             {
430 430
                 $objectName=$match[1];
431 431
             }
432 432
         }
433 433
         if ($objectName == null)
434 434
         {
435
-            $this->logging->log('No objects for ' . $this->oidDesc['oid'],DEBUG);
436
-            $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
435
+            $this->logging->log('No objects for '.$this->oidDesc['oid'], DEBUG);
436
+            $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
437 437
             return null;
438 438
         }
439 439
         
440 440
         $trapObjects=array();
441
-        while (preg_match('/ *([^ ,]+) *,* */',$objectName,$match))
441
+        while (preg_match('/ *([^ ,]+) *,* */', $objectName, $match))
442 442
         {
443
-            array_push($trapObjects,$match[1]);
444
-            $objectName=preg_replace('/'.$match[0].'/','',$objectName);
443
+            array_push($trapObjects, $match[1]);
444
+            $objectName=preg_replace('/'.$match[0].'/', '', $objectName);
445 445
         }
446 446
         return $trapObjects;
447 447
     }
@@ -453,18 +453,18 @@  discard block
 block discarded – undo
453 453
      * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
454 454
      * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
455 455
      */
456
-    public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
456
+    public function update_mib_database($display_progress=false, $check_change=false, $onlyTraps=true, $startOID='.1')
457 457
     {
458 458
         // Global Timing
459
-        $timeTaken = microtime(true);
459
+        $timeTaken=microtime(true);
460 460
         
461 461
         $numElements=$this->load_mibs_snmptranslate(); // Load objectsAll
462 462
         
463 463
         $this->load_mibs_from_db(); // Load from db dbOidAll & dbOidIndex
464 464
         
465
-        $step=$basestep=$numElements/10; // output display of % done
465
+        $step=$basestep=$numElements / 10; // output display of % done
466 466
         $num_step=0;
467
-        $timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds
467
+        $timeFiveSec=microtime(true); // Used for display a '.' every <n> seconds
468 468
         
469 469
         // Create index for trap objects
470 470
         $this->trapObjectsIndex=array();
@@ -472,33 +472,33 @@  discard block
 block discarded – undo
472 472
         // detailed timing (time_* vars)
473 473
         $this->reset_update_timers();
474 474
         
475
-        for ($curElement=0;$curElement < $numElements;$curElement++)
475
+        for ($curElement=0; $curElement < $numElements; $curElement++)
476 476
         {
477
-            $this->timing['base_time']= microtime(true);
477
+            $this->timing['base_time']=microtime(true);
478 478
             if ($display_progress)
479 479
             {
480
-                if ((microtime(true)-$timeFiveSec) > 2)
480
+                if ((microtime(true) - $timeFiveSec) > 2)
481 481
                 { // echo a . every 2 sec
482 482
                     echo '.';
483
-                    $timeFiveSec = microtime(true);
483
+                    $timeFiveSec=microtime(true);
484 484
                 }
485
-                if ($curElement>$step)
485
+                if ($curElement > $step)
486 486
                 { // display progress
487 487
                     $num_step++;
488 488
                     $step+=$basestep;   
489
-                    echo "\n" . ($num_step*10). '% : ';
489
+                    echo "\n".($num_step * 10).'% : ';
490 490
                 }
491 491
             }
492 492
             
493 493
             $this->reset_oidDesc();
494
-            if ($this->detect_trap($curElement,$onlyTraps)===true)
494
+            if ($this->detect_trap($curElement, $onlyTraps) === true)
495 495
             {
496 496
                 continue;
497 497
             }
498 498
             
499 499
             $this->timing['num_traps']++;
500 500
             
501
-            $this->logging->log('Found trap : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],INFO );
501
+            $this->logging->log('Found trap : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], INFO);
502 502
             if ($display_progress) echo '#'; // echo a # when trap found
503 503
 
504 504
             // get trap objects & source MIB
@@ -508,14 +508,14 @@  discard block
 block discarded – undo
508 508
 
509 509
             $update=$this->update_oid(); // Do update of trap.
510 510
             
511
-            $this->timing['update_time'] += microtime(true) - $this->timing['base_time'];
511
+            $this->timing['update_time']+=microtime(true) - $this->timing['base_time'];
512 512
             $this->timing['update_num']++;
513 513
             
514
-            $this->timing['base_time']= microtime(true); // Reset to check object time
514
+            $this->timing['base_time']=microtime(true); // Reset to check object time
515 515
             
516
-            if (($update==0) && ($check_change===false))
516
+            if (($update == 0) && ($check_change === false))
517 517
             { // Trapd didn't change & force check disabled
518
-                $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
518
+                $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
519 519
                 if ($display_progress) echo "C";
520 520
                 continue;
521 521
             }
@@ -528,17 +528,17 @@  discard block
 block discarded – undo
528 528
            
529 529
             $this->trap_objects($this->oidDesc['oid'], $this->oidDesc['mib'], $trapObjects, false);
530 530
             
531
-            $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
531
+            $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
532 532
             $this->timing['objects_num']++;
533 533
         }
534 534
         
535 535
         if ($display_progress)
536 536
         {
537
-            echo "\nNumber of processed traps :  ". $this->timing['num_traps'] ."\n";
538
-            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";
539
-            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";
540
-            echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'],1)." sec , ";
541
-            echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'],1)." sec \n";
537
+            echo "\nNumber of processed traps :  ".$this->timing['num_traps']."\n";
538
+            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";
539
+            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";
540
+            echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'], 1)." sec , ";
541
+            echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'], 1)." sec \n";
542 542
             
543 543
             $timeTaken=microtime(true) - $timeTaken;
544 544
             echo "Global time : ".round($timeTaken)." seconds\n";
Please login to merge, or discard this patch.