r2352 - fixed authenticate_admin()
[racktables] / inc / snmp.php
CommitLineData
2ffd5a2a
DO
1<?php
2
3function doSNMPmining ($object_id, $community)
4{
7056988c 5 // FIXME: switch to message log version 2
2ffd5a2a
DO
6 $log = array();
7// IDs: http://cisco.com/en/US/products/sw/cscowork/ps2064/products_device_support_table09186a0080803bb4.html
8// 2950: http://www.cisco.com/en/US/products/hw/switches/ps628/prod_models_home.html
9// 2960: http://www.cisco.com/en/US/products/ps6406/prod_models_comparison.html
10// 2970: http://cisco.com/en/US/products/hw/switches/ps5206/products_qanda_item09186a00801b1750.shtml
11// 3500XL: http://cisco.com/en/US/products/hw/switches/ps637/products_eol_models.html
12// 3560: http://cisco.com/en/US/products/hw/switches/ps5528/products_data_sheet09186a00801f3d7f.html
13// 3750: http://cisco.com/en/US/products/hw/switches/ps5023/products_data_sheet09186a008016136f.html
14
389e01ee 15 // Cisco sysObjectID to model (not product number, i.e. image code is missing) decoder
2ffd5a2a
DO
16 $ciscomodel = array
17 (
b3f866fc 18 278 => 'WS-C3548-XL (48 Ethernet 10/100 ports and 2 10/100/1000 uplinks)',
2ffd5a2a 19 283 => 'WS-C6509-E (9-slot system)',
bbcf1dde 20 324 => 'WS-C2950-24 (24 Ethernet 10/100 ports)',
2ffd5a2a
DO
21# 694 => 'WS-C2960-24TC-L (24 Ethernet 10/100 ports and 2 dual-purpose uplinks)',
22# 695 => 'WS-C2960-48TC-L (48 Ethernet 10/100 ports and 2 dual-purpose uplinks)',
23 696 => 'WS-C2960G-24TC-L (20 Ethernet 10/100/1000 ports and 4 dual-purpose uplinks)',
24 697 => 'WS-C2960G-48TC-L (44 Ethernet 10/100/1000 ports and 4 dual-purpose uplinks)',
069c186f
DO
25 716 => 'WS-C2960-24TT-L (24 Ethernet 10/100 ports and 2 10/100/1000 uplinks)',
26 717 => 'WS-C2960-48TT-L (48 Ethernet 10/100 ports and 2 10/100/1000 uplinks)',
2ffd5a2a
DO
27 527 => 'WS-C2970G-24T (24 Ethernet 10/100/1000 ports)',
28 561 => 'WS-C2970G-24TS (24 Ethernet 10/100/1000 ports and 4 10/100/1000 SFP uplinks)',
29 633 => 'WS-C3560-24TS (24 Ethernet 10/100 ports and 2 10/100/1000 SFP uplinks)',
30 634 => 'WS-C3560-48TS (48 Ethernet 10/100 ports and 4 10/100/1000 SFP uplinks)',
31 563 => 'WS-C3560-24PS (24 Ethernet 10/100 POE ports and 2 10/100/1000 SFP uplinks)',
32 564 => 'WS-C3560-48PS (48 Ethernet 10/100 POE ports and 4 10/100/1000 SFP uplinks)',
b3f866fc 33 516 => 'WS-C3750-XXPS (24 or 48 Ethernet 10/100 POE ports and 4 10/100/1000 SFP uplinks)',
2ffd5a2a
DO
34 614 => 'WS-C3560G-24PS (24 Ethernet 10/100/1000 POE ports and 4 10/100/1000 SFP uplinks)',
35 615 => 'WS-C3560G-24TS (24 Ethernet 10/100/1000 ports and 4 10/100/1000 SFP uplinks)',
36 616 => 'WS-C3560G-48PS (48 Ethernet 10/100/1000 POE ports and 4 10/100/1000 SFP uplinks)',
37 617 => 'WS-C3560G-48TS (48 Ethernet 10/100/1000 ports and 4 10/100/1000 SFP uplinks)',
b3f866fc 38 624 => 'WS-C3750G-24TS (24 Ethernet 10/100/1000 ports and 4 10/100/1000 SFP uplinks)',
2ffd5a2a
DO
39 58 => 'WS-C4503 (3-slot system)',
40 503 => '4503 (3-slot system)',
41 59 => 'WS-C4506 (6-slot system)',
42 502 => '4506 (6-slot system)',
43 626 => 'WS-C4948 (48 Ethernet 10/100/1000 ports and 4 10/100/1000 SFP uplinks)',
44 659 => 'WS-C4948-10GE (48 Ethernet 10/100/1000 ports and 2 10Gb X2 uplinks)',
3ec29bf4
DO
45 428 => 'WS-C2950G-24 (24 Ethernet 10/100 ports and 2 1000 GBIC uplinks)',
46 429 => 'WS-C2950G-48 (48 Ethernet 10/100 ports and 2 1000 GBIC uplinks)',
389e01ee 47 559 => 'WS-C2950T-48 (48 Ethernet 10/100 ports and 2 10/100/1000 uplinks)',
b3f866fc 48 920 => 'WS-CBS3032-DEL-F (16 Ethernet 10/100/1000 and up to 8 10/100/1000 uplinks)',
2ffd5a2a 49 );
389e01ee 50 // Cisco sysObjectID to Dictionary dict_key map
2ffd5a2a
DO
51 $hwtype = array
52 (
b3f866fc 53 278 => 395,
2ffd5a2a 54 283 => 148,
de89d7f3 55 324 => 380,
2ffd5a2a
DO
56 696 => 167,
57 697 => 166,
58 527 => 210,
59 561 => 115,
60 633 => 169,
61 634 => 170,
62 563 => 171,
63 564 => 172,
64 614 => 175,
65 615 => 173,
66 616 => 176,
67 617 => 174,
b3f866fc 68 624 => 143,
2ffd5a2a
DO
69 58 => 145,
70 503 => 145,
71 59 => 156,
72 502 => 156,
73 626 => 147,
3ec29bf4
DO
74 659 => 377,
75 428 => 389,
76 429 => 390,
389e01ee 77 559 => 387,
069c186f
DO
78 516 => 179,
79 716 => 164,
80 717 => 162,
b3f866fc
AD
81 920 => 795,
82 );
83 // Cisco portType to Dictionary dict_key map
84 $porttype = array
85 (
86 18 => 19, // 10/100BaseT => RJ-45/100Base-T
87 28 => 25, // 1000BaseSX => SC/1000Base-SX
88 31 => 440, // No Transceiver => unknown
89 61 => 24, // 10/100/1000BaseT => RJ-45/1000Base-T
2ffd5a2a
DO
90 );
91
92 $objectInfo = getObjectInfo ($object_id);
93 $endpoints = findAllEndpoints ($object_id, $objectInfo['name']);
94 $sysName = substr (snmpget ($endpoints[0], $community, 'sysName.0'), strlen ('STRING: '));
95 $sysDescr = snmpget ($endpoints[0], $community, 'sysDescr.0');
96 $sysChassi = snmpget ($endpoints[0], $community, '1.3.6.1.4.1.9.3.6.3.0');
97 // Strip the object type, it's always string here.
98 $sysDescr = substr ($sysDescr, strlen ('STRING: '));
3ec29bf4 99 $IOSversion = ereg_replace ('^.*, Version ([^ ]+), .*$', '\\1', $sysDescr);
2ffd5a2a
DO
100 $sysChassi = str_replace ('"', '', substr ($sysChassi, strlen ('STRING: ')));
101 if (strpos ($sysDescr, 'Cisco IOS Software') === 0 or strpos ($sysDescr, 'Cisco Internetwork Operating System Software') === 0)
102 $log[] = array ('code' => 'success', 'message' => 'Seems to be a Cisco box');
103 else
104 {
105 $log[] = array ('code' => 'error', 'message' => 'No idea how to handle ' . $sysDescr);
3ec29bf4 106 return $log;
2ffd5a2a
DO
107 }
108
109 // It's a Cisco box. Go on.
110 $attrs = getAttrValues ($object_id);
111 // Only fill in attribute values, if they are not set.
112 // FIXME: this is hardcoded
113
114 if (empty ($attrs[3]['value']) && !empty ($sysName)) // FQDN
115 {
116 $error = commitUpdateAttrValue ($object_id, 3, $sysName);
117 if ($error == TRUE)
118 $log[] = array ('code' => 'success', 'message' => 'FQDN set to ' . $sysName);
119 else
120 $log[] = array ('code' => 'error', 'message' => 'Failed settig FQDN: ' . $error);
121 }
122
3ec29bf4 123 if (empty ($attrs[5]['value']) and strlen ($IOSversion) > 0) // SW version
2ffd5a2a 124 {
2ffd5a2a
DO
125 $error = commitUpdateAttrValue ($object_id, 5, $IOSversion);
126 if ($error == TRUE)
127 $log[] = array ('code' => 'success', 'message' => 'SW version set to ' . $IOSversion);
128 else
129 $log[] = array ('code' => 'error', 'message' => 'Failed settig SW version: ' . $error);
130 }
131
132 if (empty ($attrs[1]['value']) and strlen ($sysChassi) > 0) // OEM Serial #1
133 {
134 $error = commitUpdateAttrValue ($object_id, 1, $sysChassi);
135 if ($error == TRUE)
136 $log[] = array ('code' => 'success', 'message' => 'OEM S/N 1 set to ' . $sysChassi);
137 else
138 $log[] = array ('code' => 'error', 'message' => 'Failed settig OEM S/N 1: ' . $error);
139 }
140
141 if (empty ($attrs[4]['value'])) // switch OS type
3ec29bf4 142 {
2ffd5a2a
DO
143 switch (substr ($IOSversion, 0, 4))
144 {
145 case '12.2':
146 $error = commitUpdateAttrValue ($object_id, 4, 252);
147 break;
148 case '12.1':
149 $error = commitUpdateAttrValue ($object_id, 4, 251);
150 break;
151 case '12.0':
152 $error = commitUpdateAttrValue ($object_id, 4, 244);
153 break;
3ec29bf4
DO
154 default:
155 $log[] = array ('code' => 'error', 'message' => "Unknown IOS version ${IOSversion}");
156 $error = TRUE;
157 break;
2ffd5a2a 158 }
3ec29bf4
DO
159 if ($error == TRUE)
160 $log[] = array ('code' => 'success', 'message' => 'Switch OS type set to Cisco IOS ' . substr ($IOSversion, 0, 4));
161 else
162 $log[] = array ('code' => 'error', 'message' => 'Failed setting Switch OS type');
163 }
2ffd5a2a
DO
164
165 $sysObjectID = snmpget ($endpoints[0], $community, 'sysObjectID.0');
166 // Transform OID
167 $sysObjectID = substr ($sysObjectID, strlen ('OID: SNMPv2-SMI::enterprises.9.1.'));
168 if (!isset ($ciscomodel[$sysObjectID]))
169 {
170 $log[] = array ('code' => 'error', 'message' => 'Could not guess exact HW model!');
3ec29bf4 171 return $log;
2ffd5a2a
DO
172 }
173 $log[] = array ('code' => 'success', 'message' => 'HW is ' . $ciscomodel[$sysObjectID]);
174 if (empty ($attrs[2]['value']) and isset ($hwtype[$sysObjectID])) // switch HW type
175 {
176 $error = commitUpdateAttrValue ($object_id, 2, $hwtype[$sysObjectID]);
177 if ($error == TRUE)
178 $log[] = array ('code' => 'success', 'message' => 'HW type updated Ok');
179 else
180 $log[] = array ('code' => 'error', 'message' => 'Failed settig HW type: ' . $error);
181 }
182 // Now fetch ifType, ifDescr and ifPhysAddr and let model-specific code sort the data out.
183 $ifType = snmpwalkoid ($endpoints[0], $community, 'ifType');
184 $ifDescr = snmpwalkoid ($endpoints[0], $community, 'ifdescr');
185 $ifPhysAddress = snmpwalkoid ($endpoints[0], $community, 'ifPhysAddress');
186 // Combine 3 tables into 1...
187 $ifList1 = array();
188 foreach ($ifType as $key => $val)
189 {
190 list ($dummy, $ifIndex) = explode ('.', $key);
191 list ($dummy, $type) = explode (' ', $val);
192 $ifList1[$ifIndex]['type'] = $type;
193 }
194 foreach ($ifDescr as $key => $val)
195 {
196 list ($dummy, $ifIndex) = explode ('.', $key);
197 list ($dummy, $descr) = explode (' ', $val);
198 $ifList1[$ifIndex]['descr'] = trim ($descr, '"');
199 }
200 foreach ($ifPhysAddress as $key => $val)
201 {
5fc57c5b 202 $val = trim ($val);
2ffd5a2a 203 list ($dummy, $ifIndex) = explode ('.', $key);
5fc57c5b
DO
204 // NET-SNMP may return MAC addresses in one of two (?) formats depending on
205 // DISPLAY-HINT internal database. The best we can do about it is to accept both.
206 // Bug originally reported by Walery Wysotsky against openSUSE 11.0.
207 if (preg_match ('/^string: /i', $val)) // STRING: x:yy:z:xx:y:zz
208 {
209 list ($dummy, $val) = explode (' ', $val);
210 $addrbytes = explode (':', $val);
211 foreach ($addrbytes as $bidx => $bytestr)
212 if (strlen ($bytestr) == 1)
213 $addrbytes[$bidx] = '0' . $bytestr;
214 }
215 elseif (preg_match ('/^hex-string: /i', $val)) // Hex-STRING: xx yy zz xx yy zz
216 $addrbytes = explode (' ', substr ($val, -17));
217 else
218 continue; // martian format
219 $ifList1[$ifIndex]['phyad'] = implode ('', $addrbytes);
2ffd5a2a
DO
220 }
221 // ...and then reverse it inside out to make description the key.
222 $ifList2 = array();
223 foreach ($ifList1 as $ifIndex => $data)
224 {
225 $ifList2[$data['descr']]['type'] = $data['type'];
226 $ifList2[$data['descr']]['phyad'] = $data['phyad'];
227 $ifList2[$data['descr']]['idx'] = $ifIndex;
228 }
229 $newports = 0;
230 // Now we can directly pick necessary ports from the table accordingly
231 // to our known hardware model.
232 switch ($sysObjectID)
233 {
234 // FIXME: chassis edge switches often share a common naming scheme, so
235 // the sequences below have to be generalized. Let's have some duplicated
236 // code for the time being, as this is the first implementation ever.
237 case '697': // WS-C2960G-48TC-L
238 // 44 copper ports: 1X, 2X, 3X...
239 // 4 combo ports: 45, 46, 47, 48. Don't list SFP connectors atm, as it's not
240 // clear how to fit them into current Ports table structure.
241 for ($i = 1; $i <= 48; $i++)
242 {
243 $label = ($i >= 45) ? "${i}" : "${i}X";
244 $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
245 if ($error == '')
246 $newports++;
247 else
248 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
bbcf1dde
AD
249 }
250 break;
251 case '324': // WS-C2950-24
252 for ($i = 1; $i <= 24; $i++)
253 {
254 $label = "${i}X";
255 $error = commitAddPort ($object_id, 'fa0/' . $i, 24, $label, $ifList2["FastEthernet0/${i}"]['phyad']);
256 if ($error == '')
257 $newports++;
258 else
259 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
2ffd5a2a
DO
260 }
261 break;
b3f866fc 262 case '624': // WS-C3750-24TS
2ffd5a2a
DO
263 case '696': // WS-C2960G-24TC-L
264 // Quite similar to the above.
265 for ($i = 1; $i <= 24; $i++)
266 {
267 $label = ($i >= 21) ? "${i}" : "${i}X";
268 $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
269 if ($error == '')
270 $newports++;
271 else
272 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
273 }
274 break;
069c186f 275 case '716': // WS-C2960-24TT-L
2ffd5a2a
DO
276 case '563': // WS-C3560-24PS
277 case '633': // WS-C3560-24TS
3ec29bf4 278 case '428': // WS-C2950G-24
2ffd5a2a
DO
279 for ($i = 1; $i <= 24; $i++)
280 {
281 $label = "${i}X";
282 $error = commitAddPort ($object_id, 'fa0/' . $i, 19, $label, $ifList2["FastEthernet0/${i}"]['phyad']);
283 if ($error == '')
284 $newports++;
285 else
286 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
287 }
288 for ($i = 1; $i <= 2; $i++)
289 {
290 $label = "${i}";
291 $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
292 if ($error == '')
293 $newports++;
294 else
295 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
296 }
297 break;
069c186f 298 case '717': // WS-C2960-48TT-L
3ec29bf4 299 case '429': // WS-C2950G-48
389e01ee 300 case '559': // WS-C2950T-48
3ec29bf4
DO
301 for ($i = 1; $i <= 48; $i++)
302 {
303 $label = "${i}X";
304 $error = commitAddPort ($object_id, 'fa0/' . $i, 19, $label, $ifList2["FastEthernet0/${i}"]['phyad']);
305 if ($error == '')
306 $newports++;
307 else
308 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
309 }
310 for ($i = 1; $i <= 2; $i++)
311 {
312 $label = "${i}";
313 $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
314 if ($error == '')
315 $newports++;
316 else
317 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
318 }
319 break;
b3f866fc
AD
320 case '516': // WS-C3750G-24TS OR WS-C3750-48PS
321 // FIXME: only handles 2 models of 3750, make it handle all of them
322 // see if it has 24 or 48 ports
323 $numports = substr (snmpget ($endpoints[0], $community, '.1.3.6.1.4.1.9.5.1.3.1.1.14.1'), strlen('INTEGER: '));
324
325 if ($numports == 28) // has 24 ports (+4 SFP) meaning it's a WS-C3750G-24TS
069c186f 326 {
b3f866fc
AD
327 for ($i = 1; $i <= 28; $i++)
328 {
329 $label = "${i}";
330 $error = commitAddPort ($object_id, 'gi1/0/' . $i, 24, $label, $ifList2["GigabitEthernet1/0/${i}"]['phyad']);
331 if ($error == '')
332 $newports++;
333 else
334 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
335 }
069c186f 336 }
b3f866fc 337 elseif ($numports == 52) // has 48 ports (+4 SFP) meaning it's a WS-C3750-48PS
069c186f 338 {
b3f866fc
AD
339 for ($i = 1; $i <= 48; $i++)
340 {
341 $label = "${i}X";
342 $error = commitAddPort ($object_id, 'fa1/0/' . $i, 19, $label, $ifList2["FastEthernet1/0/${i}"]['phyad']);
343 if ($error == '')
344 $newports++;
345 else
346 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
347 }
348 for ($i = 1; $i <= 4; $i++)
349 {
350 $label = "${i}";
351 $error = commitAddPort ($object_id, 'gi1/0/' . $i, 24, $label, $ifList2["GigabitEthernet1/0/${i}"]['phyad']);
352 if ($error == '')
353 $newports++;
354 else
355 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
356 }
069c186f
DO
357 }
358 break;
2ffd5a2a
DO
359 case '564': // WS-C3560-48PS
360 case '634': // WS-C3560-48TS
361 for ($i = 1; $i <= 48; $i++)
362 {
363 $label = "${i}X";
364 $error = commitAddPort ($object_id, 'fa0/' . $i, 19, $label, $ifList2["FastEthernet0/${i}"]['phyad']);
365 if ($error == '')
366 $newports++;
367 else
368 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
369 }
370 for ($i = 1; $i <= 4; $i++)
371 {
372 $label = "${i}";
373 $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
374 if ($error == '')
375 $newports++;
376 else
377 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
378 }
379 break;
380 case '614': // WS-C3560G-24PS
381 case '615': // WS-C3560G-24TS
382 case '527': // WS-C2970G-24T
383 case '561': // WS-C2970G-24TS
2ffd5a2a
DO
384 for ($i = 1; $i <= 24; $i++)
385 {
386 $label = "${i}X";
387 $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
388 if ($error == '')
389 $newports++;
390 else
391 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
392 }
393 break;
394 case '616': // WS-C3560G-48PS
395 case '617': // WS-C3560G-48TS
2ffd5a2a
DO
396 for ($i = 1; $i <= 48; $i++)
397 {
398 $label = "${i}X";
399 $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
400 if ($error == '')
401 $newports++;
402 else
403 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
404 }
405 break;
406 case '626': // WS-C4948
407 case '659': // WS-C4948-10GE
408 for ($i = 1; $i <= 48; $i++)
409 {
410 $label = "${i}X";
411 $error = commitAddPort ($object_id, 'gi1/' . $i, 24, $label, $ifList2["GigabitEthernet1/${i}"]['phyad']);
412 if ($error == '')
413 $newports++;
414 else
415 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
416 }
417 break;
b3f866fc
AD
418 // For modular devices we issue a separate SNMP query to determine port type,
419 // then extract blade & port numbers from the results.
420 case '58': // WS-C4503
421 case '503': // WS-C4503
422 case '59': // WS-C4506
423 case '502': // WS-C4506
2ffd5a2a 424 case '283': // WS-C6509-E
b3f866fc
AD
425 // get slot #, port # and port type using Cisco's MIB
426 $portType = snmpwalkoid ($endpoints[0], $community, '.1.3.6.1.4.1.9.5.1.4.1.1.5');
427 $ifList = array();
428 $i = 0;
429 foreach ($portType as $key => $val)
2ffd5a2a 430 {
b3f866fc
AD
431 // slot = $portIndex[8]
432 // port = $portIndex[9]
433 $portIndex = explode('.', $key);
434 $ifList[$i]['slotno'] = $portIndex[8];
435 $ifList[$i]['portno'] = $portIndex[9];
436
437 // note the Cisco port type and corresponding RackTables port type
438 list ($dummy, $cptype) = explode (' ', $val);
439 $ifList[$i]['cptype'] = $cptype;
440 if (array_key_exists($cptype, $porttype))
441 $ifList[$i]['ptype'] = $porttype[$cptype];
442 else
443 $ifList[$i]['ptype'] = null;
444 $i++;
445 }
446
447 // use Cisco's ifIndex attribute to map Cisco table to standard SNMP table
448 $ifIndex = snmpwalkoid ($endpoints[0], $community, '.1.3.6.1.4.1.9.5.1.4.1.1.11');
449 $i = 0;
450 foreach ($ifIndex as $val)
451 {
452 if (is_null($ifList[$i]['ptype']))
2ffd5a2a 453 {
b3f866fc
AD
454 $log[] = array ('code' => 'error', 'message' => 'Unknown port type: ' . $ifList[$i]['cptype']);
455 } else {
456 switch ($ifList[$i]['ptype'])
457 {
458 case 19: // fast eth
459 $prefix = 'fa';
460 break;
461 case 28: // 1000base-sx
462 case 61: // gig eth
463 $prefix = 'gi';
464 break;
465 default: // unknown, default to gig eth
466 $prefix = 'gi';
467 }
468 $pname = "{$prefix}{$ifList[$i]['slotno']}/{$ifList[$i]['portno']}";
469 $label = "slot {$ifList[$i]['slotno']} port {$ifList[$i]['portno']}";
470 list($dummy, $index) = explode(' ', $val);
471
472 // if l2address already exists in DB, nullify value so new row gets added without error
473 if (!is_null(searchByl2address($ifList1[$index]['phyad']))) $ifList1[$index]['phyad'] = null;
474
475 $error = commitAddPort ($object_id, $pname, $ifList[$i]['ptype'], $label, $ifList1[$index]['phyad']);
476 if ($error == '')
477 $newports++;
478 else
479 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $pname . ': ' . $error);
2ffd5a2a 480 }
b3f866fc
AD
481 $i++;
482 }
483 break;
484 case '278': // WS-C3548-XL
485 for ($i = 1; $i <= 48; $i++)
486 {
487 $label = "${i}X";
488 $error = commitAddPort ($object_id, 'fa0/' . $i, 19, $label, $ifList2["FastEthernet0/${i}"]['phyad']);
2ffd5a2a
DO
489 if ($error == '')
490 $newports++;
491 else
b3f866fc
AD
492 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
493 }
494 for ($i = 1; $i <= 2; $i++)
495 {
496 $label = "${i}";
497 $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
498 if ($error == '')
499 $newports++;
500 else
501 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
502 }
503 break;
504 case '920': // WS-CBS3032-DEL-F
505 for ($i = 1; $i <= 24; $i++)
506 {
507 $label = "${i}";
508 $error = commitAddPort ($object_id, 'gi0/' . $i, 24, $label, $ifList2["GigabitEthernet0/${i}"]['phyad']);
509 if ($error == '')
510 $newports++;
511 else
512 $log[] = array ('code' => 'error', 'message' => 'Failed to add port ' . $label . ': ' . $error);
2ffd5a2a
DO
513 }
514 break;
515 default:
516 showError ("Unexpected sysObjectID '${sysObjectID}'", __FUNCTION__);
517 }
518 $error = commitAddPort ($object_id, 'con0', 29, 'console', '');
519 if ($error == '')
520 $newports++;
521 else
522 $log[] = array ('code' => 'error', 'message' => 'Failed to add console port : ' . $error);
523 if ($newports > 0)
524 $log[] = array ('code' => 'success', 'message' => "Added ${newports} new ports");
525 return $log;
526}
527
528?>