Passed
Push — master ( d03ea5...4fd4ae )
by Patrick
02:40
created
library/Trapdirector/TrapsProcess/Mib.php 1 patch
Indentation   +574 added lines, -574 removed lines patch added patch discarded remove patch
@@ -11,197 +11,197 @@  discard block
 block discarded – undo
11 11
 class Mib
12 12
 {
13 13
     
14
-    protected $logging; //< logging class
15
-    protected $trapsDB; //< Database class
14
+	protected $logging; //< logging class
15
+	protected $trapsDB; //< Database class
16 16
     
17
-    public $snmptranslate;
18
-    public $snmptranslateDirs;
17
+	public $snmptranslate;
18
+	public $snmptranslateDirs;
19 19
     
20
-    private $dbOidAll; //< All oid in database;
21
-    private $dbOidIndex; //< Index of oid in dbOidAll
22
-    private $objectsAll; //< output lines of snmptranslate list
23
-    private $trapObjectsIndex; //< array of traps objects (as OID)
20
+	private $dbOidAll; //< All oid in database;
21
+	private $dbOidIndex; //< Index of oid in dbOidAll
22
+	private $objectsAll; //< output lines of snmptranslate list
23
+	private $trapObjectsIndex; //< array of traps objects (as OID)
24 24
     
25
-    private $oidDesc=array(); //< $oid,$mib,$name,$type,$textConv,$dispHint,$syntax,$type_enum,$description=NULL
25
+	private $oidDesc=array(); //< $oid,$mib,$name,$type,$textConv,$dispHint,$syntax,$type_enum,$description=NULL
26 26
 
27
-    // Timing vars for update
28
-    private $timing=array();
27
+	// Timing vars for update
28
+	private $timing=array();
29 29
     
30
-    /**
31
-     * Setup Mib Class
32
-     * @param Logging $logClass : where to log
33
-     * @param Database $dbClass : Database
34
-     */
35
-    function __construct($logClass,$dbClass,$snmptrans,$snmptransdir)
36
-    {
37
-        $this->logging=$logClass;
38
-        $this->trapsDB=$dbClass;
39
-        $this->snmptranslate=$snmptrans;
40
-        $this->snmptranslateDirs=$snmptransdir;
30
+	/**
31
+	 * Setup Mib Class
32
+	 * @param Logging $logClass : where to log
33
+	 * @param Database $dbClass : Database
34
+	 */
35
+	function __construct($logClass,$dbClass,$snmptrans,$snmptransdir)
36
+	{
37
+		$this->logging=$logClass;
38
+		$this->trapsDB=$dbClass;
39
+		$this->snmptranslate=$snmptrans;
40
+		$this->snmptranslateDirs=$snmptransdir;
41 41
 
42
-    }
42
+	}
43 43
     
44
-    /**
45
-     * Update object in DB with object in dbOidIndex if name/mib/type has changed.
46
-     * @return number : 0=unchanged, 1 = changed, 2=created
47
-     */
48
-    private function update_oid_update()
49
-    {
44
+	/**
45
+	 * Update object in DB with object in dbOidIndex if name/mib/type has changed.
46
+	 * @return number : 0=unchanged, 1 = changed, 2=created
47
+	 */
48
+	private function update_oid_update()
49
+	{
50 50
         
51
-        $db_conn=$this->trapsDB->db_connect_trap();
51
+		$db_conn=$this->trapsDB->db_connect_trap();
52 52
         
53
-        if ($this->dbOidIndex[$this->oidDesc['oid']]['key'] == -1)
54
-        { // newly created.
55
-            return 0;
56
-        }
57
-        $oidIndex=$this->dbOidIndex[$this->oidDesc['oid']]['key']; // Get index in dbOidAll
58
-        $dbOid=$this->dbOidAll[$oidIndex]; // Get array of element
59
-        if ( $this->oidDesc['name'] != $dbOid['name'] ||
60
-            $this->oidDesc['mib'] != $dbOid['mib'] ||
61
-            $this->oidDesc['type'] !=$dbOid['type']
62
-            )
63
-        { // Do update
64
-            $sql='UPDATE '.$this->trapsDB->dbPrefix.'mib_cache SET '.
65
-                'name = :name , type = :type , mib = :mib , textual_convention = :tc , display_hint = :display_hint'.
66
-                ', syntax = :syntax, type_enum = :type_enum, description = :description '.
67
-                ' WHERE id= :id';
68
-            $sqlQuery=$db_conn->prepare($sql);
53
+		if ($this->dbOidIndex[$this->oidDesc['oid']]['key'] == -1)
54
+		{ // newly created.
55
+			return 0;
56
+		}
57
+		$oidIndex=$this->dbOidIndex[$this->oidDesc['oid']]['key']; // Get index in dbOidAll
58
+		$dbOid=$this->dbOidAll[$oidIndex]; // Get array of element
59
+		if ( $this->oidDesc['name'] != $dbOid['name'] ||
60
+			$this->oidDesc['mib'] != $dbOid['mib'] ||
61
+			$this->oidDesc['type'] !=$dbOid['type']
62
+			)
63
+		{ // Do update
64
+			$sql='UPDATE '.$this->trapsDB->dbPrefix.'mib_cache SET '.
65
+				'name = :name , type = :type , mib = :mib , textual_convention = :tc , display_hint = :display_hint'.
66
+				', syntax = :syntax, type_enum = :type_enum, description = :description '.
67
+				' WHERE id= :id';
68
+			$sqlQuery=$db_conn->prepare($sql);
69 69
             
70
-            $sqlParam=array(
71
-                ':name' => $this->oidDesc['name'],
72
-                ':type' => $this->oidDesc['type'],
73
-                ':mib' => $this->oidDesc['mib'],
74
-                ':tc' =>  $this->oidDesc['textconv']??'null',
75
-                ':display_hint' => $this->oidDesc['dispHint']??'null' ,
76
-                ':syntax' => $this->oidDesc['syntax']==null??'null',
77
-                ':type_enum' => $this->oidDesc['type_enum']??'null',
78
-                ':description' => $this->oidDesc['description']??'null',
79
-                ':id' => $this->dbOidAll[$this->dbOidIndex[$this->oidDesc['oid']]['id']]
80
-            );
70
+			$sqlParam=array(
71
+				':name' => $this->oidDesc['name'],
72
+				':type' => $this->oidDesc['type'],
73
+				':mib' => $this->oidDesc['mib'],
74
+				':tc' =>  $this->oidDesc['textconv']??'null',
75
+				':display_hint' => $this->oidDesc['dispHint']??'null' ,
76
+				':syntax' => $this->oidDesc['syntax']==null??'null',
77
+				':type_enum' => $this->oidDesc['type_enum']??'null',
78
+				':description' => $this->oidDesc['description']??'null',
79
+				':id' => $this->dbOidAll[$this->dbOidIndex[$this->oidDesc['oid']]['id']]
80
+			);
81 81
             
82
-            if ($sqlQuery->execute($sqlParam) === false) {
83
-                $this->logging->log('Error in query : ' . $sql,ERROR,'');
84
-            }
85
-            $this->logging->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
86
-            return 1;
87
-        }
88
-        else
89
-        {
90
-            $this->logging->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
91
-            return 0;
92
-        }
93
-    }
82
+			if ($sqlQuery->execute($sqlParam) === false) {
83
+				$this->logging->log('Error in query : ' . $sql,ERROR,'');
84
+			}
85
+			$this->logging->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
86
+			return 1;
87
+		}
88
+		else
89
+		{
90
+			$this->logging->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
91
+			return 0;
92
+		}
93
+	}
94 94
 
95
-    /**
96
-     * Create object in DB with object in dbOidIndex
97
-     * @return number : 0=unchanged, 1 = changed, 2=created
98
-     */
99
-    private function update_oid_create()
100
-    {
101
-        // Insert data
95
+	/**
96
+	 * Create object in DB with object in dbOidIndex
97
+	 * @return number : 0=unchanged, 1 = changed, 2=created
98
+	 */
99
+	private function update_oid_create()
100
+	{
101
+		// Insert data
102 102
         
103
-        $db_conn=$this->trapsDB->db_connect_trap();
104
-        $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache '.
105
-            '(oid, name, type , mib, textual_convention, display_hint '.
106
-            ', syntax, type_enum , description ) ' .
107
-            'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
108
-            ', :syntax, :type_enum, :description )';
103
+		$db_conn=$this->trapsDB->db_connect_trap();
104
+		$sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache '.
105
+			'(oid, name, type , mib, textual_convention, display_hint '.
106
+			', syntax, type_enum , description ) ' .
107
+			'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
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
-        $sqlQuery=$db_conn->prepare($sql);
112
+		$sqlQuery=$db_conn->prepare($sql);
113 113
         
114
-        $sqlParam=array(
115
-            ':oid' => $this->oidDesc['oid'],
116
-            ':name' => $this->oidDesc['name'],
117
-            ':type' => $this->oidDesc['type'],
118
-            ':mib' => $this->oidDesc['mib'],
119
-            ':tc' =>  ($this->oidDesc['textconv']==null)?'null':$this->oidDesc['textconv'] ,
120
-            ':display_hint' => ($this->oidDesc['dispHint']==null)?'null':$this->oidDesc['dispHint'] ,
121
-            ':syntax' => ($this->oidDesc['syntax']==null)?'null':$this->oidDesc['syntax'],
122
-            ':type_enum' => ($this->oidDesc['type_enum']==null)?'null':$this->oidDesc['type_enum'],
123
-            ':description' => ($this->oidDesc['description']==null)?'null':$this->oidDesc['description']
124
-        );
114
+		$sqlParam=array(
115
+			':oid' => $this->oidDesc['oid'],
116
+			':name' => $this->oidDesc['name'],
117
+			':type' => $this->oidDesc['type'],
118
+			':mib' => $this->oidDesc['mib'],
119
+			':tc' =>  ($this->oidDesc['textconv']==null)?'null':$this->oidDesc['textconv'] ,
120
+			':display_hint' => ($this->oidDesc['dispHint']==null)?'null':$this->oidDesc['dispHint'] ,
121
+			':syntax' => ($this->oidDesc['syntax']==null)?'null':$this->oidDesc['syntax'],
122
+			':type_enum' => ($this->oidDesc['type_enum']==null)?'null':$this->oidDesc['type_enum'],
123
+			':description' => ($this->oidDesc['description']==null)?'null':$this->oidDesc['description']
124
+		);
125 125
         
126
-        if ($sqlQuery->execute($sqlParam) === false) {
127
-            $this->logging->log('Error in query : ' . $sql,1,'');
128
-        }
126
+		if ($sqlQuery->execute($sqlParam) === false) {
127
+			$this->logging->log('Error in query : ' . $sql,1,'');
128
+		}
129 129
         
130
-        switch ($this->trapsDB->trapDBType)
131
-        {
132
-            case 'pgsql':
133
-                // Get last id to insert oid/values in secondary table
134
-                if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {
135
-                    $this->logging->log('Error getting id - pgsql - ',1,'');
136
-                }
137
-                if (! isset($inserted_id_ret['id'])) {
138
-                    $this->logging->log('Error getting id - pgsql - empty.',1,'');
139
-                }
140
-                $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id_ret['id'];
141
-                break;
142
-            case 'mysql':
143
-                // Get last id to insert oid/values in secondary table
144
-                $sql='SELECT LAST_INSERT_ID();';
145
-                if (($ret_code=$db_conn->query($sql)) === false) {
146
-                    $this->logging->log('Erreur getting id - mysql - ',1,'');
147
-                }
130
+		switch ($this->trapsDB->trapDBType)
131
+		{
132
+			case 'pgsql':
133
+				// Get last id to insert oid/values in secondary table
134
+				if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {
135
+					$this->logging->log('Error getting id - pgsql - ',1,'');
136
+				}
137
+				if (! isset($inserted_id_ret['id'])) {
138
+					$this->logging->log('Error getting id - pgsql - empty.',1,'');
139
+				}
140
+				$this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id_ret['id'];
141
+				break;
142
+			case 'mysql':
143
+				// Get last id to insert oid/values in secondary table
144
+				$sql='SELECT LAST_INSERT_ID();';
145
+				if (($ret_code=$db_conn->query($sql)) === false) {
146
+					$this->logging->log('Erreur getting id - mysql - ',1,'');
147
+				}
148 148
                 
149
-                $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
150
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
151
-                $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id;
152
-                break;
153
-            default:
154
-                $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,1,'');
155
-        }
149
+				$inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
150
+				if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
151
+				$this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id;
152
+				break;
153
+			default:
154
+				$this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,1,'');
155
+		}
156 156
         
157
-        // Set as newly created.
158
-        $this->dbOidIndex[$this->oidDesc['oid']]['key']=-1;
159
-        return 2;
160
-    }
157
+		// Set as newly created.
158
+		$this->dbOidIndex[$this->oidDesc['oid']]['key']=-1;
159
+		return 2;
160
+	}
161 161
     
162
-    /**
163
-     * Update or add an OID to database uses $this->dbOidIndex for mem cache
164
-     * and $this->oidDesc doe data
165
-     * @return number : 0=unchanged, 1 = changed, 2=created
166
-     */
167
-    public function update_oid()
168
-    {
169
-        $db_conn=$this->trapsDB->db_connect_trap();
170
-        // Quote description.
171
-        $this->oidDesc['description']=$db_conn->quote($this->oidDesc['description']);
162
+	/**
163
+	 * Update or add an OID to database uses $this->dbOidIndex for mem cache
164
+	 * and $this->oidDesc doe data
165
+	 * @return number : 0=unchanged, 1 = changed, 2=created
166
+	 */
167
+	public function update_oid()
168
+	{
169
+		$db_conn=$this->trapsDB->db_connect_trap();
170
+		// Quote description.
171
+		$this->oidDesc['description']=$db_conn->quote($this->oidDesc['description']);
172 172
         
173
-        if (isset($this->dbOidIndex[$this->oidDesc['oid']]))
174
-        { // oid exists in db, so update
175
-            return $this->update_oid_update();
176
-        }
177
-        // create new OID.
178
-        return $this->update_oid_create();
173
+		if (isset($this->dbOidIndex[$this->oidDesc['oid']]))
174
+		{ // oid exists in db, so update
175
+			return $this->update_oid_update();
176
+		}
177
+		// create new OID.
178
+		return $this->update_oid_create();
179 179
 
180
-    }
180
+	}
181 181
     
182 182
 /**
183 183
  * get all objects for a trap.
184 184
  * @param integer $trapId
185 185
  * @return array : array of cached objects
186 186
  */    
187
-    private function cache_db_objects($trapId)
188
-    {
189
-        $dbObjects=array(); // cache of objects for trap in db
190
-        $db_conn=$this->trapsDB->db_connect_trap();
191
-        // Get all objects
192
-        $sql='SELECT * FROM '.$this->trapsDB->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';';
193
-        $this->logging->log('SQL query get all traps: '.$sql,DEBUG );
194
-        if (($ret_code=$db_conn->query($sql)) === false) {
195
-            $this->logging->log('No result in query : ' . $sql,1,'');
196
-        }
197
-        $dbObjectsRaw=$ret_code->fetchAll();
187
+	private function cache_db_objects($trapId)
188
+	{
189
+		$dbObjects=array(); // cache of objects for trap in db
190
+		$db_conn=$this->trapsDB->db_connect_trap();
191
+		// Get all objects
192
+		$sql='SELECT * FROM '.$this->trapsDB->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';';
193
+		$this->logging->log('SQL query get all traps: '.$sql,DEBUG );
194
+		if (($ret_code=$db_conn->query($sql)) === false) {
195
+			$this->logging->log('No result in query : ' . $sql,1,'');
196
+		}
197
+		$dbObjectsRaw=$ret_code->fetchAll();
198 198
         
199
-        foreach ($dbObjectsRaw as $val)
200
-        {
201
-            $dbObjects[$val['object_id']]=1;
202
-        }
203
-        return $dbObjects;
204
-    }
199
+		foreach ($dbObjectsRaw as $val)
200
+		{
201
+			$dbObjects[$val['object_id']]=1;
202
+		}
203
+		return $dbObjects;
204
+	}
205 205
 
206 206
 /**
207 207
  * Get object details & mib , returns snmptranslate output
@@ -209,478 +209,478 @@  discard block
 block discarded – undo
209 209
  * @param string $trapmib : mib of trap
210 210
  * @return NULL|array : null if not found, or output of snmptranslate
211 211
  */
212
-    private function get_object_details($object,$trapmib)
213
-    {
214
-        $match=$snmptrans=array();
215
-        $retVal=0;
216
-        $this->oidDesc['mib']=$trapmib;
217
-        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
218
-            ' -On -Td '.$this->oidDesc['mib'].'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
219
-        if ($retVal!=0)
220
-        {
221
-            // Maybe not trap mib, search with IR
222
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
223
-                ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
224
-            if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
225
-            { // Not found -> continue with warning
226
-                $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
227
-                return null;
228
-            }
229
-            $this->oidDesc['mib']=$match[1];
212
+	private function get_object_details($object,$trapmib)
213
+	{
214
+		$match=$snmptrans=array();
215
+		$retVal=0;
216
+		$this->oidDesc['mib']=$trapmib;
217
+		exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
218
+			' -On -Td '.$this->oidDesc['mib'].'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
219
+		if ($retVal!=0)
220
+		{
221
+			// Maybe not trap mib, search with IR
222
+			exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
223
+				' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
224
+			if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
225
+			{ // Not found -> continue with warning
226
+				$this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
227
+				return null;
228
+			}
229
+			$this->oidDesc['mib']=$match[1];
230 230
             
231
-            // Do the snmptranslate again.
232
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
233
-                ' -On -Td '.$this->oidDesc['mib'].'::'.$object,$snmptrans,$retVal);
234
-            if ($retVal!=0) {
235
-                $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object,2,'');
236
-                return null;
237
-            }
231
+			// Do the snmptranslate again.
232
+			exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
233
+				' -On -Td '.$this->oidDesc['mib'].'::'.$object,$snmptrans,$retVal);
234
+			if ($retVal!=0) {
235
+				$this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object,2,'');
236
+				return null;
237
+			}
238 238
             
239
-        }
240
-        return $snmptrans;
241
-    }
239
+		}
240
+		return $snmptrans;
241
+	}
242 242
 
243 243
 /**
244 244
  * Parse snmptranslate output and set  $this->oidDesc with elements 
245 245
  * @param array $snmptrans : multi line output of snmptrans
246 246
  */
247
-    private function parse_object($snmptrans)
248
-    {
249
-        $tmpdesc=''; // For multiline description
250
-        $indesc=false; // true if currently inside multiline description
251
-        $match=array();
247
+	private function parse_object($snmptrans)
248
+	{
249
+		$tmpdesc=''; // For multiline description
250
+		$indesc=false; // true if currently inside multiline description
251
+		$match=array();
252 252
         
253
-        foreach ($snmptrans as $line)
254
-        {
255
-            if ($indesc===true)
256
-            {
257
-                $line=preg_replace('/[\t ]+/',' ',$line);
258
-                if (preg_match('/(.*)"$/', $line,$match))
259
-                {
260
-                    $this->oidDesc['description'] = $tmpdesc . $match[1];
261
-                    $indesc=false;
262
-                }
263
-                $tmpdesc.=$line;
264
-                continue;
265
-            }
266
-            if (preg_match('/^\.[0-9\.]+$/', $line))
267
-            {
268
-                $this->oidDesc['oid']=$line;
269
-                continue;
270
-            }
271
-            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
272
-            {
273
-                $this->oidDesc['syntax']=$match[1];
274
-                $this->oidDesc['type_enum']=$match[2];
275
-                continue;
276
-            }
277
-            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
278
-            {
279
-                $this->oidDesc['syntax']=$match[1];
280
-                continue;
281
-            }
282
-            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
283
-            {
284
-                $this->oidDesc['dispHint']=$match[1];
285
-                continue;
286
-            }
287
-            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
288
-            {
289
-                $this->oidDesc['description']=$match[1];
290
-                continue;
291
-            }
292
-            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
293
-            {
294
-                $tmpdesc=$match[1];
295
-                $indesc=true;
296
-                continue;
297
-            }
298
-            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
299
-            {
300
-                $this->oidDesc['textconv']=$match[1];
301
-                continue;
302
-            }
303
-        }
304
-    }
253
+		foreach ($snmptrans as $line)
254
+		{
255
+			if ($indesc===true)
256
+			{
257
+				$line=preg_replace('/[\t ]+/',' ',$line);
258
+				if (preg_match('/(.*)"$/', $line,$match))
259
+				{
260
+					$this->oidDesc['description'] = $tmpdesc . $match[1];
261
+					$indesc=false;
262
+				}
263
+				$tmpdesc.=$line;
264
+				continue;
265
+			}
266
+			if (preg_match('/^\.[0-9\.]+$/', $line))
267
+			{
268
+				$this->oidDesc['oid']=$line;
269
+				continue;
270
+			}
271
+			if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
272
+			{
273
+				$this->oidDesc['syntax']=$match[1];
274
+				$this->oidDesc['type_enum']=$match[2];
275
+				continue;
276
+			}
277
+			if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
278
+			{
279
+				$this->oidDesc['syntax']=$match[1];
280
+				continue;
281
+			}
282
+			if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
283
+			{
284
+				$this->oidDesc['dispHint']=$match[1];
285
+				continue;
286
+			}
287
+			if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
288
+			{
289
+				$this->oidDesc['description']=$match[1];
290
+				continue;
291
+			}
292
+			if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
293
+			{
294
+				$tmpdesc=$match[1];
295
+				$indesc=true;
296
+				continue;
297
+			}
298
+			if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
299
+			{
300
+				$this->oidDesc['textconv']=$match[1];
301
+				continue;
302
+			}
303
+		}
304
+	}
305 305
 
306
-    /**
307
-     * create or update (with check_existing = true) objects of trap
308
-     * @param string $trapOID : trap oid
309
-     * @param string $trapmib : mib of trap
310
-     * @param array $objects : array of objects name (without MIB)
311
-     * @param bool $check_existing : check instead of create
312
-     */
313
-    public function trap_objects($trapOID,$trapmib,$objects,$check_existing)
314
-    {              
315
-        $trapId = $this->dbOidIndex[$trapOID]['id']; // Get id of trap
306
+	/**
307
+	 * create or update (with check_existing = true) objects of trap
308
+	 * @param string $trapOID : trap oid
309
+	 * @param string $trapmib : mib of trap
310
+	 * @param array $objects : array of objects name (without MIB)
311
+	 * @param bool $check_existing : check instead of create
312
+	 */
313
+	public function trap_objects($trapOID,$trapmib,$objects,$check_existing)
314
+	{              
315
+		$trapId = $this->dbOidIndex[$trapOID]['id']; // Get id of trap
316 316
         
317
-        if ($check_existing === true)
318
-        {
319
-            $dbObjects=$this->cache_db_objects($trapId);
320
-        }
317
+		if ($check_existing === true)
318
+		{
319
+			$dbObjects=$this->cache_db_objects($trapId);
320
+		}
321 321
         
322
-        foreach ($objects as $object)
323
-        {
322
+		foreach ($objects as $object)
323
+		{
324 324
             
325
-            $this->reset_oidDesc();
325
+			$this->reset_oidDesc();
326 326
             
327
-            $snmptrans=$this->get_object_details($object, $trapmib); // Get object mib & details
328
-            if ($snmptrans === null) continue; // object not found
327
+			$snmptrans=$this->get_object_details($object, $trapmib); // Get object mib & details
328
+			if ($snmptrans === null) continue; // object not found
329 329
             
330
-            $this->parse_object($snmptrans);
330
+			$this->parse_object($snmptrans);
331 331
 
332
-            $this->oidDesc['name'] = $object;
332
+			$this->oidDesc['name'] = $object;
333 333
             
334
-            $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 );
334
+			$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 );
335 335
 
336
-            // Update
337
-            $this->update_oid();
336
+			// Update
337
+			$this->update_oid();
338 338
             
339
-            if (isset($dbObjects[$this->dbOidIndex[$this->oidDesc['oid']]['id']]))
340
-            {   // if link exists, continue
341
-                $dbObjects[$this->dbOidIndex[$this->oidDesc['oid']]['id']]=2;
342
-                continue;
343
-            }
344
-            if ($check_existing === true)
345
-            {
346
-                // TODO : check link trap - objects exists, mark them.
347
-            }
348
-            // Associate in object table
349
-            $db_conn=$this->trapsDB->db_connect_trap();
350
-            $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache_trap_object (trap_id,object_id) '.
351
-                'values (:trap_id, :object_id)';
352
-            $sqlQuery=$db_conn->prepare($sql);
353
-            $sqlParam=array(
354
-                ':trap_id' => $trapId,
355
-                ':object_id' => $this->dbOidIndex[$this->oidDesc['oid']]['id'],
356
-            );
339
+			if (isset($dbObjects[$this->dbOidIndex[$this->oidDesc['oid']]['id']]))
340
+			{   // if link exists, continue
341
+				$dbObjects[$this->dbOidIndex[$this->oidDesc['oid']]['id']]=2;
342
+				continue;
343
+			}
344
+			if ($check_existing === true)
345
+			{
346
+				// TODO : check link trap - objects exists, mark them.
347
+			}
348
+			// Associate in object table
349
+			$db_conn=$this->trapsDB->db_connect_trap();
350
+			$sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache_trap_object (trap_id,object_id) '.
351
+				'values (:trap_id, :object_id)';
352
+			$sqlQuery=$db_conn->prepare($sql);
353
+			$sqlParam=array(
354
+				':trap_id' => $trapId,
355
+				':object_id' => $this->dbOidIndex[$this->oidDesc['oid']]['id'],
356
+			);
357 357
             
358
-            if ($sqlQuery->execute($sqlParam) === false) {
359
-                $this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$this->oidDesc['oid']]['id'] ,1,'');
360
-            }
361
-        }
362
-        if ($check_existing === true)
363
-        {
364
-            // TODO : remove link trap - objects that wasn't marked.
365
-        }
358
+			if ($sqlQuery->execute($sqlParam) === false) {
359
+				$this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$this->oidDesc['oid']]['id'] ,1,'');
360
+			}
361
+		}
362
+		if ($check_existing === true)
363
+		{
364
+			// TODO : remove link trap - objects that wasn't marked.
365
+		}
366 366
         
367
-    }
367
+	}
368 368
 
369
-    private function reset_oidDesc()
370
-    {
371
-        $this->oidDesc['oid']=null;
372
-        $this->oidDesc['name']=null;
373
-        $this->oidDesc['type']=null;
374
-        $this->oidDesc['mib']=null;
375
-        $this->oidDesc['textconv']=null;
376
-        $this->oidDesc['dispHint'] =null;
377
-        $this->oidDesc['syntax']=null;
378
-        $this->oidDesc['type_enum']=null;
379
-        $this->oidDesc['description']=null;
380
-    }
369
+	private function reset_oidDesc()
370
+	{
371
+		$this->oidDesc['oid']=null;
372
+		$this->oidDesc['name']=null;
373
+		$this->oidDesc['type']=null;
374
+		$this->oidDesc['mib']=null;
375
+		$this->oidDesc['textconv']=null;
376
+		$this->oidDesc['dispHint'] =null;
377
+		$this->oidDesc['syntax']=null;
378
+		$this->oidDesc['type_enum']=null;
379
+		$this->oidDesc['description']=null;
380
+	}
381 381
     
382
-    /**
383
-     * Fills $this->objectsAll with all mibs from snmptranslate
384
-     * @return integer : number of elements 
385
-     */
386
-    private function load_mibs_snmptranslate()
387
-    {
388
-        $retVal=0;
389
-        // Get all mib objects from all mibs
390
-        $snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null';
391
-        $this->logging->log('Getting all traps : '.$snmpCommand,DEBUG );
392
-        unset($this->objectsAll);
393
-        exec($snmpCommand,$this->objectsAll,$retVal);
394
-        if ($retVal!=0)
395
-        {
396
-            $this->logging->log('error executing snmptranslate',ERROR,'');
397
-        }
398
-        // Count elements to show progress
399
-        $numElements=count($this->objectsAll);
400
-        $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO );
401
-        return $numElements;
402
-    }
382
+	/**
383
+	 * Fills $this->objectsAll with all mibs from snmptranslate
384
+	 * @return integer : number of elements 
385
+	 */
386
+	private function load_mibs_snmptranslate()
387
+	{
388
+		$retVal=0;
389
+		// Get all mib objects from all mibs
390
+		$snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null';
391
+		$this->logging->log('Getting all traps : '.$snmpCommand,DEBUG );
392
+		unset($this->objectsAll);
393
+		exec($snmpCommand,$this->objectsAll,$retVal);
394
+		if ($retVal!=0)
395
+		{
396
+			$this->logging->log('error executing snmptranslate',ERROR,'');
397
+		}
398
+		// Count elements to show progress
399
+		$numElements=count($this->objectsAll);
400
+		$this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO );
401
+		return $numElements;
402
+	}
403 403
 
404
-    /**
405
-     * load all mib objects db in dbOidAll (raw) and index in dbOidIndex
406
-     */
407
-    private function load_mibs_from_db()
408
-    {
409
-        // Get all mibs from databse to have a memory index
404
+	/**
405
+	 * load all mib objects db in dbOidAll (raw) and index in dbOidIndex
406
+	 */
407
+	private function load_mibs_from_db()
408
+	{
409
+		// Get all mibs from databse to have a memory index
410 410
         
411
-        $db_conn=$this->trapsDB->db_connect_trap();
411
+		$db_conn=$this->trapsDB->db_connect_trap();
412 412
         
413
-        $sql='SELECT * from '.$this->trapsDB->dbPrefix.'mib_cache;';
414
-        $this->logging->log('SQL query : '.$sql,DEBUG );
415
-        if (($ret_code=$db_conn->query($sql)) === false) {
416
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
417
-        }
418
-        $this->dbOidAll=$ret_code->fetchAll();
419
-        $this->dbOidIndex=array();
420
-        // Create the index for db;
421
-        foreach($this->dbOidAll as $key=>$val)
422
-        {
423
-            $this->dbOidIndex[$val['oid']]['key']=$key;
424
-            $this->dbOidIndex[$val['oid']]['id']=$val['id'];
425
-        }
426
-    }
413
+		$sql='SELECT * from '.$this->trapsDB->dbPrefix.'mib_cache;';
414
+		$this->logging->log('SQL query : '.$sql,DEBUG );
415
+		if (($ret_code=$db_conn->query($sql)) === false) {
416
+			$this->logging->log('No result in query : ' . $sql,ERROR,'');
417
+		}
418
+		$this->dbOidAll=$ret_code->fetchAll();
419
+		$this->dbOidIndex=array();
420
+		// Create the index for db;
421
+		foreach($this->dbOidAll as $key=>$val)
422
+		{
423
+			$this->dbOidIndex[$val['oid']]['key']=$key;
424
+			$this->dbOidIndex[$val['oid']]['id']=$val['id'];
425
+		}
426
+	}
427 427
 
428
-    /**
429
-     * Reset all update timers & count to zero
430
-     */
431
-    private function reset_update_timers()
432
-    {
433
-        $this->timing['base_parse_time']=0;
434
-        $this->timing['base_check_time']=0;
435
-        $this->timing['type0_check_time']=0;
436
-        $this->timing['nottrap_time']=0;
437
-        $this->timing['update_time']=0;
438
-        $this->timing['objects_time']=0;
439
-        $this->timing['base_parse_num']=0;
440
-        $this->timing['base_check_num']=0;
441
-        $this->timing['type0_check_num']=0;
442
-        $this->timing['nottrap_num']=0;
443
-        $this->timing['update_num']=0;
444
-        $this->timing['objects_num']=0;
445
-        $this->timing['num_traps']=0;
446
-    }
428
+	/**
429
+	 * Reset all update timers & count to zero
430
+	 */
431
+	private function reset_update_timers()
432
+	{
433
+		$this->timing['base_parse_time']=0;
434
+		$this->timing['base_check_time']=0;
435
+		$this->timing['type0_check_time']=0;
436
+		$this->timing['nottrap_time']=0;
437
+		$this->timing['update_time']=0;
438
+		$this->timing['objects_time']=0;
439
+		$this->timing['base_parse_num']=0;
440
+		$this->timing['base_check_num']=0;
441
+		$this->timing['type0_check_num']=0;
442
+		$this->timing['nottrap_num']=0;
443
+		$this->timing['update_num']=0;
444
+		$this->timing['objects_num']=0;
445
+		$this->timing['num_traps']=0;
446
+	}
447 447
 
448
-    /**
449
-     * Detect if $this->objectsAll[$curElement] is a trap 
450
-     * @param integer $curElement
451
-     * @param bool $onlyTraps : set to false to get all and not only traps.
452
-     * @return boolean : false if it's a trap , true if not
453
-     */
454
-    private function detect_trap($curElement,$onlyTraps)
455
-    {
456
-        // Get oid or pass if not found
457
-        if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
458
-        {
459
-            $this->timing['base_parse_time'] += microtime(true) - $this->timing['base_time'];
460
-            $this->timing['base_parse_num'] ++;
461
-            return true;
462
-        }
463
-        $this->oidDesc['oid']=$this->objectsAll[$curElement];
448
+	/**
449
+	 * Detect if $this->objectsAll[$curElement] is a trap 
450
+	 * @param integer $curElement
451
+	 * @param bool $onlyTraps : set to false to get all and not only traps.
452
+	 * @return boolean : false if it's a trap , true if not
453
+	 */
454
+	private function detect_trap($curElement,$onlyTraps)
455
+	{
456
+		// Get oid or pass if not found
457
+		if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
458
+		{
459
+			$this->timing['base_parse_time'] += microtime(true) - $this->timing['base_time'];
460
+			$this->timing['base_parse_num'] ++;
461
+			return true;
462
+		}
463
+		$this->oidDesc['oid']=$this->objectsAll[$curElement];
464 464
         
465
-        // get next line
466
-        $curElement++;
467
-        $match=$snmptrans=array();
468
-        if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
469
-            $this->objectsAll[$curElement],$match))
470
-        {
471
-            $this->timing['base_check_time'] += microtime(true) - $this->timing['base_time'];
472
-            $this->timing['base_check_num']++;
473
-            return true;
474
-        }
465
+		// get next line
466
+		$curElement++;
467
+		$match=$snmptrans=array();
468
+		if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
469
+			$this->objectsAll[$curElement],$match))
470
+		{
471
+			$this->timing['base_check_time'] += microtime(true) - $this->timing['base_time'];
472
+			$this->timing['base_check_num']++;
473
+			return true;
474
+		}
475 475
         
476
-        $this->oidDesc['name']=$match[1]; // Name
477
-        $this->oidDesc['type']=$match[2]; // type (21=trap, 0: may be trap, else : not trap
476
+		$this->oidDesc['name']=$match[1]; // Name
477
+		$this->oidDesc['type']=$match[2]; // type (21=trap, 0: may be trap, else : not trap
478 478
         
479
-        if ($this->oidDesc['type']==0) // object type=0 : check if v1 trap
480
-        {
481
-            // Check if next is suboid -> in that case is cannot be a trap
482
-            if (preg_match("/^".$this->oidDesc['oid']."/",$this->objectsAll[$curElement+1]))
483
-            {
484
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
485
-                $this->timing['type0_check_num']++;
486
-                return true;
487
-            }
488
-            unset($snmptrans);
489
-            $retVal=0;
490
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
491
-                ' -Td '.$this->oidDesc['oid'] . ' | grep OBJECTS ',$snmptrans,$retVal);
492
-            if ($retVal!=0)
493
-            {
494
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
495
-                $this->timing['type0_check_num']++;
496
-                return true;
497
-            }
498
-            //echo "\n v1 trap found : $this->oidDesc['oid'] \n";
499
-            // Force as trap.
500
-            $this->oidDesc['type']=21;
501
-        }
502
-        if ($onlyTraps===true && $this->oidDesc['type']!=21) // if only traps and not a trap, continue
503
-        {
504
-            $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time'];
505
-            $this->timing['nottrap_num']++;
506
-            return true;
507
-        }
508
-        return false;
509
-    }
479
+		if ($this->oidDesc['type']==0) // object type=0 : check if v1 trap
480
+		{
481
+			// Check if next is suboid -> in that case is cannot be a trap
482
+			if (preg_match("/^".$this->oidDesc['oid']."/",$this->objectsAll[$curElement+1]))
483
+			{
484
+				$this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
485
+				$this->timing['type0_check_num']++;
486
+				return true;
487
+			}
488
+			unset($snmptrans);
489
+			$retVal=0;
490
+			exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
491
+				' -Td '.$this->oidDesc['oid'] . ' | grep OBJECTS ',$snmptrans,$retVal);
492
+			if ($retVal!=0)
493
+			{
494
+				$this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
495
+				$this->timing['type0_check_num']++;
496
+				return true;
497
+			}
498
+			//echo "\n v1 trap found : $this->oidDesc['oid'] \n";
499
+			// Force as trap.
500
+			$this->oidDesc['type']=21;
501
+		}
502
+		if ($onlyTraps===true && $this->oidDesc['type']!=21) // if only traps and not a trap, continue
503
+		{
504
+			$this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time'];
505
+			$this->timing['nottrap_num']++;
506
+			return true;
507
+		}
508
+		return false;
509
+	}
510 510
    
511
-    /**
512
-     * get_trap_mib_description
513
-     * @return array|null : array of snmptranslate output or null on error
514
-    **/
515
-    private function get_trap_mib_description()
516
-    {
517
-        $retVal=0;
518
-        $match=$snmptrans=array();
519
-        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
520
-            ' -Td '.$this->oidDesc['oid'],$snmptrans,$retVal);
521
-        if ($retVal!=0)
522
-        {
523
-            $this->logging->log('error executing snmptranslate',ERROR);
524
-            return $snmptrans;
525
-        }
511
+	/**
512
+	 * get_trap_mib_description
513
+	 * @return array|null : array of snmptranslate output or null on error
514
+	 **/
515
+	private function get_trap_mib_description()
516
+	{
517
+		$retVal=0;
518
+		$match=$snmptrans=array();
519
+		exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
520
+			' -Td '.$this->oidDesc['oid'],$snmptrans,$retVal);
521
+		if ($retVal!=0)
522
+		{
523
+			$this->logging->log('error executing snmptranslate',ERROR);
524
+			return $snmptrans;
525
+		}
526 526
         
527
-        if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
528
-        {
529
-            $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : ' . $snmptrans[0],ERROR);
530
-            return $snmptrans;
531
-        }
532
-        $this->oidDesc['mib']=$match[1];
527
+		if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
528
+		{
529
+			$this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : ' . $snmptrans[0],ERROR);
530
+			return $snmptrans;
531
+		}
532
+		$this->oidDesc['mib']=$match[1];
533 533
         
534
-        $numLine=1;
535
-        while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
536
-        if (isset($snmptrans[$numLine]))
537
-        {
538
-            $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
534
+		$numLine=1;
535
+		while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
536
+		if (isset($snmptrans[$numLine]))
537
+		{
538
+			$snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
539 539
             
540
-            while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
541
-            {
542
-                $this->oidDesc['description'].=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
543
-                $numLine++;
544
-            }
545
-            if (isset($snmptrans[$numLine])) {
546
-                $this->oidDesc['description'].=preg_replace('/".*/','',$snmptrans[$numLine]);
547
-                $this->oidDesc['description']=preg_replace('/[\t ]+/',' ',$this->oidDesc['description']);
548
-            }
540
+			while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
541
+			{
542
+				$this->oidDesc['description'].=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
543
+				$numLine++;
544
+			}
545
+			if (isset($snmptrans[$numLine])) {
546
+				$this->oidDesc['description'].=preg_replace('/".*/','',$snmptrans[$numLine]);
547
+				$this->oidDesc['description']=preg_replace('/[\t ]+/',' ',$this->oidDesc['description']);
548
+			}
549 549
             
550
-        }
551
-        return $snmptrans;
552
-    }
550
+		}
551
+		return $snmptrans;
552
+	}
553 553
 
554
-    /**
555
-     * Get trap objects
556
-     * @param array $snmptrans : output of snmptranslate for TrapModuleConfig
557
-     * @return array|null : array of objects or null if not found
558
-    **/
559
-    private function get_trap_objects($snmptrans)
560
-    {
561
-        $objectName=null;
562
-        $match=array();
563
-        foreach ($snmptrans as $line)
564
-        {
565
-            if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
566
-            {
567
-                $objectName=$match[1];
568
-            }
569
-        }
570
-        if ($objectName == null)
571
-        {
572
-            $this->logging->log('No objects for ' . $this->oidDesc['oid'],DEBUG);
573
-            $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
574
-            return null;
575
-        }
554
+	/**
555
+	 * Get trap objects
556
+	 * @param array $snmptrans : output of snmptranslate for TrapModuleConfig
557
+	 * @return array|null : array of objects or null if not found
558
+	 **/
559
+	private function get_trap_objects($snmptrans)
560
+	{
561
+		$objectName=null;
562
+		$match=array();
563
+		foreach ($snmptrans as $line)
564
+		{
565
+			if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
566
+			{
567
+				$objectName=$match[1];
568
+			}
569
+		}
570
+		if ($objectName == null)
571
+		{
572
+			$this->logging->log('No objects for ' . $this->oidDesc['oid'],DEBUG);
573
+			$this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
574
+			return null;
575
+		}
576 576
         
577
-        $trapObjects=array();
578
-        while (preg_match('/ *([^ ,]+) *,* */',$objectName,$match))
579
-        {
580
-            array_push($trapObjects,$match[1]);
581
-            $objectName=preg_replace('/'.$match[0].'/','',$objectName);
582
-        }
583
-        return $trapObjects;
584
-    }
577
+		$trapObjects=array();
578
+		while (preg_match('/ *([^ ,]+) *,* */',$objectName,$match))
579
+		{
580
+			array_push($trapObjects,$match[1]);
581
+			$objectName=preg_replace('/'.$match[0].'/','',$objectName);
582
+		}
583
+		return $trapObjects;
584
+	}
585 585
     
586
-    /**
587
-     * Cache mib in database
588
-     * @param boolean $display_progress : Display progress on standard output
589
-     * @param boolean $check_change : Force check of trap params & objects
590
-     * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
591
-     * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
592
-     */
593
-    public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
594
-    {
595
-        // Global Timing
596
-        $timeTaken = microtime(true);
586
+	/**
587
+	 * Cache mib in database
588
+	 * @param boolean $display_progress : Display progress on standard output
589
+	 * @param boolean $check_change : Force check of trap params & objects
590
+	 * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
591
+	 * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
592
+	 */
593
+	public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
594
+	{
595
+		// Global Timing
596
+		$timeTaken = microtime(true);
597 597
         
598
-        $numElements=$this->load_mibs_snmptranslate(); // Load objectsAll
598
+		$numElements=$this->load_mibs_snmptranslate(); // Load objectsAll
599 599
         
600
-        $this->load_mibs_from_db(); // Load from db dbOidAll & dbOidIndex
600
+		$this->load_mibs_from_db(); // Load from db dbOidAll & dbOidIndex
601 601
         
602
-        $step=$basestep=$numElements/10; // output display of % done
603
-        $num_step=0;
604
-        $timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds
602
+		$step=$basestep=$numElements/10; // output display of % done
603
+		$num_step=0;
604
+		$timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds
605 605
         
606
-        // Create index for trap objects
607
-        $this->trapObjectsIndex=array();
606
+		// Create index for trap objects
607
+		$this->trapObjectsIndex=array();
608 608
         
609
-        // detailed timing (time_* vars)
610
-        $this->reset_update_timers();
609
+		// detailed timing (time_* vars)
610
+		$this->reset_update_timers();
611 611
         
612
-        for ($curElement=0;$curElement < $numElements;$curElement++)
613
-        {
614
-            $this->timing['base_time']= microtime(true);
615
-            if ($display_progress)
616
-            {
617
-                if ((microtime(true)-$timeFiveSec) > 2)
618
-                { // echo a . every 2 sec
619
-                    echo '.';
620
-                    $timeFiveSec = microtime(true);
621
-                }
622
-                if ($curElement>$step)
623
-                { // display progress
624
-                    $num_step++;
625
-                    $step+=$basestep;   
626
-                    echo "\n" . ($num_step*10). '% : ';
627
-                }
628
-            }
612
+		for ($curElement=0;$curElement < $numElements;$curElement++)
613
+		{
614
+			$this->timing['base_time']= microtime(true);
615
+			if ($display_progress)
616
+			{
617
+				if ((microtime(true)-$timeFiveSec) > 2)
618
+				{ // echo a . every 2 sec
619
+					echo '.';
620
+					$timeFiveSec = microtime(true);
621
+				}
622
+				if ($curElement>$step)
623
+				{ // display progress
624
+					$num_step++;
625
+					$step+=$basestep;   
626
+					echo "\n" . ($num_step*10). '% : ';
627
+				}
628
+			}
629 629
             
630
-            $this->reset_oidDesc();
631
-            if ($this->detect_trap($curElement,$onlyTraps)===true)
632
-            {
633
-                continue;
634
-            }
630
+			$this->reset_oidDesc();
631
+			if ($this->detect_trap($curElement,$onlyTraps)===true)
632
+			{
633
+				continue;
634
+			}
635 635
             
636
-            $this->timing['num_traps']++;
636
+			$this->timing['num_traps']++;
637 637
             
638
-            $this->logging->log('Found trap : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],INFO );
639
-            if ($display_progress) echo '#'; // echo a # when trap found
638
+			$this->logging->log('Found trap : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],INFO );
639
+			if ($display_progress) echo '#'; // echo a # when trap found
640 640
 
641
-            // get trap objects & source MIB
641
+			// get trap objects & source MIB
642 642
             
643
-            $snmptrans=$this->get_trap_mib_description(); // get MIB & description
643
+			$snmptrans=$this->get_trap_mib_description(); // get MIB & description
644 644
 
645 645
 
646
-            $update=$this->update_oid(); // Do update of trap.
646
+			$update=$this->update_oid(); // Do update of trap.
647 647
             
648
-            $this->timing['update_time'] += microtime(true) - $this->timing['base_time'];
649
-            $this->timing['update_num']++;
648
+			$this->timing['update_time'] += microtime(true) - $this->timing['base_time'];
649
+			$this->timing['update_num']++;
650 650
             
651
-            $this->timing['base_time']= microtime(true); // Reset to check object time
651
+			$this->timing['base_time']= microtime(true); // Reset to check object time
652 652
             
653
-            if (($update==0) && ($check_change===false))
654
-            { // Trapd didn't change & force check disabled
655
-                $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
656
-                if ($display_progress) echo "C";
657
-                continue;
658
-            }
653
+			if (($update==0) && ($check_change===false))
654
+			{ // Trapd didn't change & force check disabled
655
+				$this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
656
+				if ($display_progress) echo "C";
657
+				continue;
658
+			}
659 659
             
660
-            $trapObjects=$this->get_trap_objects($snmptrans); // Get trap objects from snmptranslate output            
661
-            if ($trapObjects == null)
662
-            {
663
-                continue;
664
-            }
660
+			$trapObjects=$this->get_trap_objects($snmptrans); // Get trap objects from snmptranslate output            
661
+			if ($trapObjects == null)
662
+			{
663
+				continue;
664
+			}
665 665
            
666
-            $this->trap_objects($this->oidDesc['oid'], $this->oidDesc['mib'], $trapObjects, false);
666
+			$this->trap_objects($this->oidDesc['oid'], $this->oidDesc['mib'], $trapObjects, false);
667 667
             
668
-            $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
669
-            $this->timing['objects_num']++;
670
-        }
668
+			$this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
669
+			$this->timing['objects_num']++;
670
+		}
671 671
         
672
-        if ($display_progress)
673
-        {
674
-            echo "\nNumber of processed traps :  ". $this->timing['num_traps'] ."\n";
675
-            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";
676
-            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";
677
-            echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'],1)." sec , ";
678
-            echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'],1)." sec \n";
672
+		if ($display_progress)
673
+		{
674
+			echo "\nNumber of processed traps :  ". $this->timing['num_traps'] ."\n";
675
+			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";
676
+			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";
677
+			echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'],1)." sec , ";
678
+			echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'],1)." sec \n";
679 679
             
680
-            $timeTaken=microtime(true) - $timeTaken;
681
-            echo "Global time : ".round($timeTaken)." seconds\n";
682
-        }
683
-    }
680
+			$timeTaken=microtime(true) - $timeTaken;
681
+			echo "Global time : ".round($timeTaken)." seconds\n";
682
+		}
683
+	}
684 684
     
685 685
     
686 686
 }
687 687
\ No newline at end of file
Please login to merge, or discard this patch.
library/Trapdirector/Config/MIBLoader.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -31,10 +31,10 @@  discard block
 block discarded – undo
31 31
 				
32 32
 	}
33 33
 
34
-    /**
35
-     * Get all mibs in db which have at least one trap
36
-     * @return array
37
-     */	
34
+	/**
35
+	 * Get all mibs in db which have at least one trap
36
+	 * @return array
37
+	 */	
38 38
 	
39 39
 	public function getMIBList()
40 40
 	{
@@ -58,9 +58,9 @@  discard block
 block discarded – undo
58 58
 	
59 59
 	
60 60
 	/** Get trap list from a mib 
61
-	*	@param $mib string mib name
62
-	*	@return array : traps
63
-	*/
61
+	 *	@param $mib string mib name
62
+	 *	@return array : traps
63
+	 */
64 64
 	public function getTrapList($mib)
65 65
 	{
66 66
 		$traps=array();
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		$query=$dbconn->select()
69 69
 				->from(
70 70
 					$this->config->getMIBCacheTableName(),
71
-				    array('name' => 'name', 'oid' => 'oid', 'description' => 'description'))
71
+					array('name' => 'name', 'oid' => 'oid', 'description' => 'description'))
72 72
 				->where("mib = '".$mib."' AND type='21'") ;
73 73
 		$names=$dbconn->fetchAll($query);
74 74
 		foreach ($names as $val)
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
 	}
80 80
 	
81 81
 	/** Get objects a trap can have
82
-	*	@param int $trap oid of trap
83
-	*	@return array|null : null if trap not found, or array ( <oid> => name/mib/type )
84
-	*/
82
+	 *	@param int $trap oid of trap
83
+	 *	@return array|null : null if trap not found, or array ( <oid> => name/mib/type )
84
+	 */
85 85
 	public function getObjectList($trap)
86 86
 	{
87 87
 		$objects=array();
@@ -97,15 +97,15 @@  discard block
 block discarded – undo
97 97
 		if ( ($id == null) || ! property_exists($id,'id') ) return null;
98 98
 		
99 99
 		$query=$dbconn->select()
100
-		        ->from(
101
-		            array('c' => $this->config->getMIBCacheTableName()),
102
-		            array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum',
103
-		                'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint',
104
-		                'description' => 'c.description'))
105
-		        ->join(
106
-		            array('o' => $this->config->getMIBCacheTableTrapObjName()),
107
-		            'o.trap_id='.$id->id )
108
-		        ->where("o.object_id = c.id");
100
+				->from(
101
+					array('c' => $this->config->getMIBCacheTableName()),
102
+					array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum',
103
+						'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint',
104
+						'description' => 'c.description'))
105
+				->join(
106
+					array('o' => $this->config->getMIBCacheTableTrapObjName()),
107
+					'o.trap_id='.$id->id )
108
+				->where("o.object_id = c.id");
109 109
 		$listObjects=$dbconn->fetchAll($query);
110 110
 		if ( count($listObjects)==0 ) return null;
111 111
 		
@@ -123,12 +123,12 @@  discard block
 block discarded – undo
123 123
 	}
124 124
 
125 125
 	/** translate oid in MIB::Name 
126
-	*	@param string $oid
127
-	*	@return array|null :  return array with index (oid -> oid, mib -> mib name, name -> oid name, type -> oid type)
128
-	*/
126
+	 *	@param string $oid
127
+	 *	@return array|null :  return array with index (oid -> oid, mib -> mib name, name -> oid name, type -> oid type)
128
+	 */
129 129
 	public function translateOID($oid)
130 130
 	{
131
-	    if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.'
131
+		if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.'
132 132
 		$retArray=array('oid' => $oid, 'mib' => null, 'name'=>null,'type'=>null);
133 133
 		$dbconn = $this->db->getConnection();
134 134
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 				->from(
137 137
 					array('o' => $this->config->getMIBCacheTableName()),
138 138
 					array('mib'=>'o.mib','name' => 'o.name','type'=>'o.syntax',
139
-					    'type_enum'=>'o.type_enum', 'description'=>'o.description'))
139
+						'type_enum'=>'o.type_enum', 'description'=>'o.description'))
140 140
 				->where('o.oid=\''.$oid.'\'');
141 141
 		$object=$dbconn->fetchRow($query);
142 142
 		if ($object != null) 
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 		// Try to get oid name from snmptranslate
153 153
 		$matches=array();
154 154
 		$translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
155
-		    ' '.$oid);
155
+			' '.$oid);
156 156
 		$ret_code=preg_match('/(.*)::(.*)/',$translate,$matches);
157 157
 		if ($ret_code===0 || $ret_code===false) {
158 158
 			return null;
@@ -164,8 +164,8 @@  discard block
 block discarded – undo
164 164
 			" | grep SYNTAX | sed 's/SYNTAX[[:blank:]]*//'");
165 165
 		if (preg_match('/(.*)\{(.*)\}/',$translate,$matches))
166 166
 		{
167
-		    $retArray['type']=$matches[1];
168
-		    $retArray['type_enum']=$matches[2];
167
+			$retArray['type']=$matches[1];
168
+			$retArray['type_enum']=$matches[2];
169 169
 		}
170 170
 		else
171 171
 		{
@@ -229,25 +229,25 @@  discard block
 block discarded – undo
229 229
 	 */
230 230
 	public function getTrapDetails($oid=null,$id=null)
231 231
 	{	    
232
-	    // Get trap id in DB
233
-	    if ($oid===null)
234
-	    {
235
-	        $where="c.id = '$id'";
236
-	    }
237
-	    else
238
-	    {
239
-	        $where="c.oid = '$oid'";
240
-	    }
241
-	    $query=$this->db->getConnection()->select()
242
-           ->from(
243
-            array('c' => $this->config->getMIBCacheTableName()),
244
-            array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum',
245
-                'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint',
246
-                'description' => 'c.description'))
247
-            ->where($where);
248
-        $trap=$this->db->getConnection()->fetchRow($query);
232
+		// Get trap id in DB
233
+		if ($oid===null)
234
+		{
235
+			$where="c.id = '$id'";
236
+		}
237
+		else
238
+		{
239
+			$where="c.oid = '$oid'";
240
+		}
241
+		$query=$this->db->getConnection()->select()
242
+		   ->from(
243
+			array('c' => $this->config->getMIBCacheTableName()),
244
+			array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum',
245
+				'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint',
246
+				'description' => 'c.description'))
247
+			->where($where);
248
+		$trap=$this->db->getConnection()->fetchRow($query);
249 249
         
250
-        return $trap;
250
+		return $trap;
251 251
 	}
252 252
 	
253 253
 }
Please login to merge, or discard this patch.