extend SNMPgeneric to mimic php >= 5.4.0 SNMP Class
[racktables-contribs] / snmpgeneric.php
CommitLineData
9276dc97
ME
1<?php
2
3/********************************************
4 *
30bf198b 5 * RackTables 0.20.x snmpgeneric extension
9276dc97 6 *
30bf198b 7 * sync an RackTables object with an SNMP device.
9276dc97 8 *
30bf198b 9 * Should work with almost any SNMP capable device.
9276dc97 10 *
30bf198b 11 * reads SNMP tables:
12 * - system
13 * - ifTable
14 * - ifxTable
15 * - ipAddrTable (ipv4 only)
16 * - ipAddressTable (ipv4 + ipv6)
17 *
18 * Features:
19 * - update object attributes
20 * - create networks
21 * - create ports
22 * - add and bind ip addresses
7c2cfc75 23 * - create as new object
365fb193 24 * - save snmp settings per object (uses comment field)
30bf198b 25 *
26 * Known to work with:
27 * - Enterasys SecureStacks, S-Series
28 * - cisco 2620XM (thx to Rob)
29 * - hopefully many others
30 *
31 *
32 * Usage:
33 *
34 * 1. select "SNMP generic sync" tap
35 * 2. select your SNMP config (host, v1, v2c or v3, ...)
36 * 3. hit "Show List"
37 * 4. you will see a selection of all information that could be retrieved
38 * 5. select what should be updated and/or created
39 * 6. hit "Create" Button to make changes to RackTables
40 * 7. repeat step 1. to 6. as often as you like / need
9276dc97 41 *
9276dc97 42 *
9276dc97 43 * needs PHP 5
30bf198b 44 *
9276dc97 45 * TESTED on FreeBSD 9.0, nginx/1.0.12, php 5.3.10, NET-SNMP 5.7.1
30bf198b 46 * and RackTables <= 0.20.3
9276dc97 47 *
af78a786 48 * (c)2015 Maik Ehinger <m.ehinger@ltur.de>
9276dc97
ME
49 */
50
51/****
52 * INSTALL
02a702a1 53 * just place file in plugins directory
30bf198b 54 *
55 */
56
57/**
58 * The newest version of this plugin can be found at:
59 *
60 * https://github.com/github138/myRT-contribs/tree/develop-0.20.x
61 *
9276dc97
ME
62 */
63
64/* TODOs
30bf198b 65 *
9276dc97
ME
66 * - code cleanup
67 *
68 * - update visible label on ifAlias change !?
69 *
30bf198b 70 * - test if device supports mibs
9276dc97
ME
71 * - gethostbyaddr / gethostbyname host list
72 * - correct iif_name display if != 1
73 *
74 * - set more Object attributs / fields
9276dc97 75 *
365fb193 76 * - Input variables exceeded 1000
ccf830c6 77 * - update iftypes
365fb193 78 *
9276dc97
ME
79 */
80
1fc7fc7d 81/* RackTables Debug Mode */
82//$debug_mode=1;
83
30bf198b 84require_once('inc/snmp.php');
9276dc97
ME
85
86$tab['object']['snmpgeneric'] = 'SNMP Generic sync';
87$tabhandler['object']['snmpgeneric'] = 'snmpgeneric_tabhandler';
88//$trigger['object']['snmpgeneric'] = 'snmpgeneric_tabtrigger';
89
90$ophandler['object']['snmpgeneric']['create'] = 'snmpgeneric_opcreate';
91
92/* snmptranslate command */
93$sg_cmd_snmptranslate = '/usr/local/bin/snmptranslate';
94
95/* create ports without connector */
96$sg_create_noconnector_ports = FALSE;
97
98/* deselect add port for this snmp port types */
99$sg_ifType_ignore = array(
100 '1', /* other */
101 '24', /* softwareLoopback */
102 '23', /* ppp */
103 '33', /* rs232 */
30bf198b 104 '34', /* para */
9276dc97
ME
105 '53', /* propVirtual */
106 '77', /* lapd */
107 '131', /* tunnel */
108 '136', /* l3ipvlan */
109 '160', /* usb */
110 '161', /* ieee8023adLag */
111);
112
113/* ifType to RT oif_id mapping */
114$sg_ifType2oif_id = array(
115 /* 440 causes SQLSTATE[23000]: Integrity constraint violation:
30bf198b 116 * 1452 Cannot add or update a child row:
9276dc97
ME
117 * a foreign key constraint fails
118 */
119 // '1' => 440, /* other => unknown 440 */
120 '1' => 1469, /* other => virutal port 1469 */
30bf198b 121 '6' => 24, /* ethernetCsmacd => 1000BASE-T 24 */
9276dc97
ME
122 '24' => 1469, /* softwareLoopback => virtual port 1469 */
123 '33' => 1469, /* rs232 => RS-232 (DB-9) 681 */
30bf198b 124 '34' => 1469, /* para => virtual port 1469 */
9276dc97
ME
125 '53' => 1469, /* propVirtual => virtual port 1469 */
126 '62' => 1195, /* fastEther => 100BASE-FX 1195 */
127 '131' => 1469, /* tunnel => virtual port 1469 */
128 '136' => 1469, /* l3ipvlan => virtual port 1469 */
129 '160' => 1469, /* usb => virtual port 1469 */
130 '161' => 1469, /* ieee8023adLag => virtual port 1469 */
131);
132
133/* -------------------------------------------------- */
134
135/* snmp vendor list http://www.iana.org/assignments/enterprise-numbers */
136
137$sg_known_sysObjectIDs = array
138(
139 /* ------------ default ------------ */
140 'default' => array
141 (
142 // 'text' => 'default',
143 'pf' => array('snmpgeneric_pf_entitymib'),
144 'attr' => array
145 (
30bf198b 146 2 => array('pf' => 'snmpgeneric_pf_hwtype'), /* HW Typ*/
9276dc97
ME
147 3 => array('oid' => 'sysName.0'),
148 /* FQDN check only if regex matches */
149 //3 => array('oid' => 'sysName.0', 'regex' => '/^[^ .]+(\.[^ .]+)+\.?/', 'uncheck' => 'no FQDN'),
150 4 => array('pf' => 'snmpgeneric_pf_swtype', 'uncheck' => 'experimental'), /* SW type */
151 14 => array('oid' => 'sysContact.0'), /* Contact person */
152 // 1235 => array('value' => 'Constant'),
30bf198b 153 ),
9276dc97 154 'port' => array
30bf198b 155 (
9276dc97
ME
156 // 'AC-in' => array('porttypeid' => '1-16', 'uncheck' => 'uncheck reason/comment'),
157 // 'name' => array('porttypeid' => '1-24', 'ifDescr' => 'visible label'),
158 ),
159 ),
160
161 /* ------------ ciscoSystems --------------- */
162/* '9' => array
163 * (
164 * 'text' => 'ciscoSystems',
165 * ),
166 */
167 '9.1' => array
168 (
169 'text' => 'ciscoProducts',
170 'attr' => array(
171 4 => array('pf' => 'snmpgeneric_pf_catalyst'), /* SW type/version */
172 16 => array('pf' => 'snmpgeneric_pf_ciscoflash'), /* flash memory */
30bf198b 173
9276dc97 174 ),
30bf198b 175
9276dc97
ME
176 ),
177 /* ------------ Microsoft --------------- */
178 '311' => array
179 (
180 'text' => 'Microsoft',
181 'attr' => array(
182 4 => array('pf' => 'snmpgeneric_pf_swtype', 'oid' => 'sysDescr.0', 'regex' => '/.* Windows Version (.*?) .*/', 'replacement' => 'Windows \\1', 'uncheck' => 'TODO RT matching'), /*SW type */
183 ),
184 ),
185 /* ------------ Enterasys --------------- */
186 '5624' => array
187 (
188 'text' => 'Enterasys',
189 'attr' => array(
190 4 => array('pf' => 'snmpgeneric_pf_enterasys'), /* SW type/version */
191 ),
192 ),
193
194 /* Enterasys N3 */
195 '5624.2.1.53' => array
30bf198b 196 (
0ffff63b 197 'dict_key' => 2021,
198 'text' => 'Matrix N3',
30bf198b 199 ),
9276dc97
ME
200
201 '5624.2.2.284' => array
30bf198b 202 (
9276dc97 203 'dict_key' => 50002,
30bf198b 204 'text' => 'Securestack C2',
205 ),
9276dc97
ME
206
207 '5624.2.1.98' => array
30bf198b 208 (
9276dc97 209 'dict_key' => 50002,
30bf198b 210 'text' => 'Securestack C3',
211 ),
9276dc97
ME
212
213 '5624.2.1.100' => array
30bf198b 214 (
9276dc97 215 'dict_key' => 50002,
30bf198b 216 'text' => 'Securestack B3',
217 ),
9276dc97
ME
218
219 '5624.2.1.128' => array
30bf198b 220 (
0ffff63b 221 'dict_key' => 1970,
222 'text' => 'S-series SSA130',
30bf198b 223 ),
9276dc97
ME
224
225 '5624.2.1.129' => array
30bf198b 226 (
0ffff63b 227 'dict_key' => 1970,
228 'text' => 'S-series SSA150',
30bf198b 229 ),
9276dc97
ME
230
231 '5624.2.1.137' => array
30bf198b 232 (
0ffff63b 233 'dict_key' => 1987,
30bf198b 234 'text' => 'Securestack B5 POE',
235 ),
9276dc97
ME
236
237 /* S3 */
238 '5624.2.1.131' => array
239 (
0ffff63b 240 'dict_key' => 1974,
241 'text' => 'S-series S3',
9276dc97
ME
242 ),
243
244 /* S4 */
245 '5624.2.1.132' => array
246 (
0ffff63b 247 'dict_key' => 1975,
248 'text' => 'S-series S4'
9276dc97
ME
249 ),
250
251 /* S8 */
252 '5624.2.1.133' => array
253 (
0ffff63b 254 'dict_key' => 1977,
255 'text' => 'S-series S8'
256 ),
257
258 '5624.2.1.165' => array
259 (
260 'dict_key' => 1971,
261 'text' => 'S-series Bonded SSA',
9276dc97
ME
262 ),
263
264 /* ------------ net-snmp --------------- */
265 '8072' => array
266 (
30bf198b 267 'text' => 'net-snmp',
9276dc97
ME
268 'attr' => array(
269 4 => array('pf' => 'snmpgeneric_pf_swtype', 'oid' => 'sysDescr.0', 'regex' => '/(.*?) .*? (.*?) .*/', 'replacement' => '\\1 \\2', 'uncheck' => 'TODO RT matching'), /*SW type */
270 ),
271 ),
272
273 /* ------------ Frauenhofer FOKUS ------------ */
274 '12325' => array
275 (
276 'text' => 'Fraunhofer FOKUS',
277 'attr' => array(
278 4 => array('pf' => 'snmpgeneric_pf_swtype', 'oid' => 'sysDescr.0', 'regex' => '/.*? .*? (.*? .*).*/', 'replacement' => '\\1', 'uncheck' => 'TODO RT matching'), /*SW type */
279 ),
280 ),
281
282 '12325.1.1.2.1.1' => array
283 (
284 'dict_key' => 42, /* Server model noname/unknown */
285 'text' => 'BSNMP - mini SNMP daemon (bsnmpd)',
286 ),
287
288) + $known_switches;
289/* add snmp.php known_switches */
290
291/* ------------ Sample function --------------- */
292/*
293 * Sample Precessing Function (pf)
294 */
295function snmpgeneric_pf_sample(&$snmp, &$sysObjectID, $attr_id) {
296
297 $object = &$sysObjectID['object'];
298 $attr = &$sysObjectID['attr'][$attr_id];
299
300 if(!isset($attr['oid']))
301 return;
302
303 /* output success banner */
304 showSuccess('Found sysObjectID '.$sysObjectID['value']);
305
306 /* access attribute oid setting and do snmpget */
307 $oid = $attr['oid'];
308 $value = $snmp->get($oid);
309
310 /* set new attribute value */
311 $attr['value'] = $value;
312
313 /* do not check attribute per default */
314 $attr['uncheck'] = "comment";
315
316 /* set informal comment */
317 $attr['comment'] = "comment";
318
319 /* add additional ports */
320 // $sysObjectID['port']['name'] = array('porttypeid' => '1-24', 'ifPhysAddress' => '001122334455', 'ifDescr' => 'visible label', 'uncheck' => 'comment', 'disabled' => 'porttypeid select disabled');
321
322 /* set other attribute */
323// $sysObjectID['attr'][1234]['value'] = 'attribute value';
324
325} /* snmpgeneric_pf_sample */
326
327/* ------------ Enterasys --------------- */
328
329function snmpgeneric_pf_enterasys(&$snmp, &$sysObjectID, $attr_id) {
330
331 $attrs = &$sysObjectID['attr'];
332
333 //snmpgeneric_pf_entitymib($snmp, $sysObjectID, $attr_id);
334
335 /* TODO find correct way to get Bootroom and Firmware versions */
336
337 /* Model */
30bf198b 338 /*if(preg_match('/.*\.([^.]+)$/', $sysObjectID['value'], $matches)) {
9276dc97
ME
339 * showNotice('Device '.$matches[1]);
340 *}
341 */
342
343 /* TODO SW type */
344 //$attrs[4]['value'] = 'Enterasys'; /* SW type */
345
346 /* set SW version only if not already set by entitymib */
347 if(isset($attrs[5]['value']) && !empty($attrs[5]['value'])) {
30bf198b 348
9276dc97 349 /* SW version from sysDescr */
30bf198b 350 if(preg_match('/^Enterasys .* Inc\. (.+) [Rr]ev ([^ ]+) ?(.*)$/', $snmp->sysDescr, $matches)) {
9276dc97
ME
351
352 $attrs[5]['value'] = $matches[2]; /* SW version */
30bf198b 353
9276dc97
ME
354 // showSuccess("Found Enterasys Model ".$matches[1]);
355 }
356
357 } /* SW version */
358
359 /* add serial port */
30bf198b 360 //$sysObjectID['port']['console'] = array('porttypeid' => '1-29', 'ifDescr' => 'console', 'disabled' => 'disabled');
9276dc97
ME
361
362}
363
364/* ------------ Cisco --------------- */
365
366/* logic from snmp.php */
367function snmpgeneric_pf_catalyst(&$snmp, &$sysObjectID, $attr_id) {
368 $attrs = &$sysObjectID['attr'];
30bf198b 369 $ports = &$sysObjectID['port'];
9276dc97
ME
370
371 /* sysDescr multiline on C5200 */
372 if(preg_match ('/.*, Version ([^ ]+), .*/', $snmp->sysDescr, $matches)) {
373 $exact_release = $matches[1];
30bf198b 374 $major_line = preg_replace ('/^([[:digit:]]+\.[[:digit:]]+)[^[:digit:]].*/', '\\1', $exact_release);
9276dc97
ME
375
376 $ios_codes = array
30bf198b 377 (
378 '12.0' => 244,
379 '12.1' => 251,
380 '12.2' => 252,
381 );
382
9276dc97
ME
383 $attrs[5]['value'] = $exact_release;
384
30bf198b 385 if (array_key_exists ($major_line, $ios_codes))
9276dc97
ME
386 $attrs[4]['value'] = $ios_codes[$major_line];
387
388 } /* sw type / version */
389
390 $sysChassi = $snmp->get ('1.3.6.1.4.1.9.3.6.3.0');
391 if ($sysChassi !== FALSE or $sysChassi !== NULL)
392 $attrs[1]['value'] = str_replace ('"', '', $sysChassi);
393
30bf198b 394 $ports['con0'] = array('porttypeid' => '1-29', 'ifDescr' => 'console'); // RJ-45 RS-232 console
9276dc97
ME
395
396 if (preg_match ('/Cisco IOS Software, C2600/', $snmp->sysDescr))
30bf198b 397 $ports['aux0'] = array('porttypeid' => '1-29', 'ifDescr' => 'auxillary'); // RJ-45 RS-232 aux port
9276dc97
ME
398
399 // blade devices are powered through internal circuitry of chassis
400 if ($sysObjectID['value'] != '9.1.749' and $sysObjectID['value'] != '9.1.920')
401 {
30bf198b 402 $ports['AC-in'] = array('porttypeid' => '1-16');
9276dc97
ME
403 }
404
405} /* snmpgeneric_pf_catalyst */
406
407/* -------------------------------------------------- */
408function snmpgeneric_pf_ciscoflash(&$snmp, &$sysObjectID, $attr_id) {
30bf198b 409 /*
9276dc97
ME
410 * ciscoflashMIB = 1.3.6.1.4.1.9.9.10
411 */
412 /*
413 | 16 | uint | flash memory, MB |
414 */
415 $attrs = &$sysObjectID['attr'];
416
30bf198b 417 $ciscoflash = $snmp->walk('1.3.6.1.4.1.9.9.10.1.1.2'); /* ciscoFlashDeviceTable */
9276dc97
ME
418
419 $flash = array_keys($ciscoflash, 'flash');
420
421 foreach($flash as $oid) {
422 if(!preg_match('/(.*)?\.[^\.]+\.([^\.]+)$/',$oid,$matches))
423 continue;
424
425 $index = $matches[2];
426 $prefix = $matches[1];
427
428 showSuccess("Found Flash: ".$ciscoflash[$prefix.'.8.'.$index]." ".$ciscoflash[$prefix.'.2.'.$index]." bytes");
429
30bf198b 430 $attrs[16]['value'] = ceil($ciscoflash[$prefix.'.2.'.$index] / 1024 / 1024); /* ciscoFlashDeviceSize */
9276dc97
ME
431
432 }
433
434 /*
435 * ciscoMemoryPoolMIB = 1.3.6.1.4.1.9.9.48
436 * ciscoMemoryPoolUsed .1.1.1.5
437 * ciscoMemoryPoolFree .1.1.1.6
438 */
439
440 $ciscomem = $snmp->walk('1.3.6.1.4.1.9.9.48');
441
442 if(!empty($ciscomem)) {
443
444 $used = 0;
445 $free = 0;
446
447 foreach($ciscomem as $oid => $value) {
30bf198b 448
9276dc97
ME
449 switch(preg_replace('/.*?(\.1\.1\.1\.[^\.]+)\.[^\.]+$/','\\1',$oid)) {
450 case '.1.1.1.5':
451 $used += $value;
452 break;
453 case '.1.1.1.6':
454 $free += $value;
455 break;
456 }
457
458 }
459
30bf198b 460 $attrs[17]['value'] = ceil(($free + $used) / 1024 / 1024); /* RAM, MB */
9276dc97
ME
461 }
462
463} /* snmpgeneric_pf_ciscoflash */
464
465/* -------------------------------------------------- */
466/* -------------------------------------------------- */
467
468/* HW Type processor function */
469function snmpgeneric_pf_hwtype(&$snmp, &$sysObjectID, $attr_id) {
470
471 $attr = &$sysObjectID['attr'][$attr_id];
472
473 if (isset($sysObjectID['dict_key'])) {
474
475 $value = $sysObjectID['dict_key'];
476 showSuccess("Found HW type dict_key: $value");
30bf198b 477
9276dc97
ME
478 /* return array of attr_id => attr_value) */
479 $attr['value'] = $value;
480
481 } else {
482 showNotice("HW type dict_key not set - Unknown OID");
483 }
484
485} /* snmpgeneric_pf_hwtype */
486
487/* -------------------------------------------------- */
488
489/* SW type processor function */
490/* experimental */
491/* Find a way to match RT SW types !? */
492function snmpgeneric_pf_swtype(&$snmp, &$sysObjectID, $attr_id) {
493
494 /* 4 = SW type */
495
30bf198b 496 $attr = &$sysObjectID['attr'][$attr_id];
9276dc97
ME
497
498 $object = &$sysObjectID['object'];
499
500 $objtype_id = $object['objtype_id'];
501
502 if(isset($attr['oid']))
503 $oid = $attr['oid'];
504 else
30bf198b 505 $oid = 'sysDescr.0';
9276dc97
ME
506
507 $raw_value = $snmp->get($oid);
508
509 $replacement = '\\1';
510
511 if(isset($attr['regex'])) {
512 $regex = $attr['regex'];
513
514 if(isset($attr['replacement']))
515 $replacement = $attr['replacement'];
516
517 } else {
518 $list = array('bsd','linux','centos','suse','fedora','ubuntu','windows','solaris','vmware');
519
520 $regex = '/.* ([^ ]*('.implode($list,'|').')[^ ]*) .*/i';
521 $replacement = '\\1';
522 }
523
524 $value = preg_replace($regex, $replacement, $raw_value, -1, $count);
525 //$attr['value'] = $value;
526
527 if(!empty($value) && $count > 0) {
528 /* search dict_key for value in RT Dictionary */
529 /* depends on object type server(13)/switch(14)/router(15) */
30bf198b 530 $result = usePreparedSelectBlade
531 (
532 'SELECT dict_key,dict_value FROM Dictionary WHERE chapter_id in (13,14,15) and dict_value like ? order by dict_key desc limit 1',
533 array ('%'.$value.'%')
534 );
535 $row = $result->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_UNIQUE|PDO::FETCH_COLUMN);
9276dc97
ME
536
537 if(!empty($row)) {
538 $RTvalue = key($row);
539
540 if(isset($attr['comment']))
541 $attr['comment'] .= ", $value ($RTvalue) ".$row[$RTvalue];
542 else
543 $attr['comment'] = "$value ($RTvalue) ".$row[$RTvalue];
544
545 showSuccess("Found SW type: $value ($RTvalue) ".$row[$RTvalue]);
546 $value = $RTvalue;
547 }
548
549 /* set attr value */
550 $attr['value'] = $value;
551 // unset($attr['uncheck']);
552
553 }
554
555 if(isset($attr['comment']))
556 $attr['comment'] .= ' (experimental)';
557 else
558 $attr['comment'] = '(experimental)';
559
560} /* snmpgeneric_pf_swtype */
561
562/* -------------------------------------------------- */
30bf198b 563/* try to set SW version
9276dc97
ME
564 * and add some AC ports
565 *
566 */
567/* needs more testing */
568function snmpgeneric_pf_entitymib(&$snmp, &$sysObjectID, $attr_id) {
30bf198b 569
9276dc97
ME
570 /* $attr_id == NULL -> device pf */
571
572 $attrs = &$sysObjectID['attr'];
573 $ports = &$sysObjectID['port'];
574
575 $entPhysicalClass = $snmp->walk('.1.3.6.1.2.1.47.1.1.1.1.5'); /* entPhysicalClass */
576
577 if(empty($entPhysicalClass))
578 return;
579
580 showNotice("Found Entity Table (Experimental)");
581
30bf198b 582/* PhysicalClass
9276dc97
ME
583 * 1:other
584 * 2:unknown
585 * 3:chassis
586 * 4:backplane
587 * 5:container
588 * 6:powerSupply
589 * 7:fan
590 * 8:sensor
591 * 9:module
592 * 10:port
593 * 11:stack
594 * 12:cpu
595 */
596
597 /* chassis */
598
599 /* always index = 1 ??? */
600 $chassis = array_keys($entPhysicalClass, '3'); /* 3 chassis */
601
602 if(0)
603 if(!empty($chassis)) {
604 echo '<table>';
605
606 foreach($chassis as $key => $oid) {
607 /* get index */
30bf198b 608 if(!preg_match('/\.(\d+)$/',$oid, $matches))
9276dc97
ME
609 continue;
610
30bf198b 611 $index = $matches[1];
612
613 $name = $snmp->get(".1.3.6.1.2.1.47.1.1.1.1.7.$index");
614 $serialnum = $snmp->get(".1.3.6.1.2.1.47.1.1.1.1.11.$index");
615 $mfgname = $snmp->get(".1.3.6.1.2.1.47.1.1.1.1.12.$index");
616 $modelname = $snmp->get(".1.3.6.1.2.1.47.1.1.1.1.13.$index");
9276dc97 617
9276dc97
ME
618 //showNotice("$name $mfgname $modelname $serialnum");
619
620 echo("<tr><td>$name</td><td>$mfgname</td><td>$modelname</td><td>$serialnum</td>");
621 }
622 unset($key);
623 unset($oid);
624
625 echo '</table>';
626 } /* chassis */
627
628
629
630 /* modules */
631
632 $modules = array_keys($entPhysicalClass, '9'); /* 9 Modules */
633
634 if(!empty($modules)) {
635
636 echo '<br><br>Modules<br><table>';
637 echo("<tr><th>Name</th><th>MfgName</th><th>ModelName</th><th>HardwareRev</th><th>FirmwareRev</th><th>SoftwareRev</th><th>SerialNum</th>");
30bf198b 638
9276dc97
ME
639 foreach($modules as $key => $oid) {
640
641 /* get index */
30bf198b 642 if(!preg_match('/\.(\d+)$/',$oid, $matches))
9276dc97
ME
643 continue;
644
30bf198b 645 $index = $matches[1];
646
647 $name = $snmp->get(".1.3.6.1.2.1.47.1.1.1.1.7.$index");
648 $hardwarerev = $snmp->get(".1.3.6.1.2.1.47.1.1.1.1.8.$index");
649 $firmwarerev = $snmp->get(".1.3.6.1.2.1.47.1.1.1.1.9.$index");
650 $softwarerev = $snmp->get(".1.3.6.1.2.1.47.1.1.1.1.10.$index");
651 $serialnum = $snmp->get(".1.3.6.1.2.1.47.1.1.1.1.11.$index");
652 $mfgname = $snmp->get(".1.3.6.1.2.1.47.1.1.1.1.12.$index");
653 $modelname = $snmp->get(".1.3.6.1.2.1.47.1.1.1.1.13.$index");
9276dc97 654
9276dc97
ME
655 //showNotice("$name $mfgname $modelname $hardwarerev $firmwarerev $softwarerev $serialnum");
656
657 echo("<tr><td>".(empty($name) ? '-' : $name )."</td><td>$mfgname</td><td>$modelname</td><td>$hardwarerev</td><td>$firmwarerev</td><td>$softwarerev</td><td>$serialnum</td>");
658
659 /* set SW version to first module software version */
660 if($key == 0 ) {
661
662 $attrs[5]['value'] = $softwarerev; /* SW version */
663 $attrs[5]['comment'] = 'entity MIB';
664 }
665
666 }
667 unset($key);
668 unset($oid);
669
670 echo '</table>';
671 }
672
673
674 /* add AC ports */
675 $powersupply = array_keys($entPhysicalClass, '6'); /* 6 powerSupply */
676 $count = 1;
677 foreach($powersupply as $oid) {
678
679 /* get index */
30bf198b 680 if(!preg_match('/\.(\d+)$/',$oid, $matches))
9276dc97
ME
681 continue;
682
30bf198b 683 $index = $matches[1];
684 $descr = $snmp->get(".1.3.6.1.2.1.47.1.1.1.1.2.$index");
9276dc97 685
30bf198b 686 $ports['AC-'.$count] = array('porttypeid' => '1-16', 'ifDescr' => $descr, 'comment' => 'entity MIB', 'uncheck' => '');
9276dc97
ME
687 $count++;
688 }
689 unset($oid);
690}
691
692/* -------------------------------------------------- */
693
694/*
695 * regex processor function
696 * needs 'oid' and 'regex'
697 * uses first back reference as attribute value
698 */
699function snmpgeneric_pf_regex(&$snmp, &$sysObjectID, $attr_id) {
700
701 $attr = &$sysObjectID['attr'][$attr_id];
702
703 if (isset($attr['oid']) && isset($attr['regex'])) {
704
705 $oid = $attr['oid'];
706 $regex = $attr['regex'];
707
708 $raw_value = $snmp->get($oid);
709
710
711 if(isset($attr['replacement']))
712 $replace = $attr['replacement'];
713 else
714 $replace = '\\1';
715
716 $value = preg_replace($regex,$replace, $raw_value);
30bf198b 717
9276dc97
ME
718 /* return array of attr_id => attr_value) */
719 $attr['value'] = $value;
720
30bf198b 721 }
9276dc97
ME
722 // else Warning ??
723
724} /* snmpgeneric_pf_regex */
725
726/* -------------------------------------------------- */
727
728$sg_portiifoptions= getPortIIFOptions();
729$sg_portiifoptions[-1] = 'sfp'; /* generic sfp */
730
5130f8be 731$sg_portoifoptions= getPortOIFOptions();
9276dc97
ME
732
733/* -------------------------------------------------- */
734/* -------------------------------------------------- */
735
736function snmpgeneric_tabhandler($object_id) {
737
8188a17c 738// sg_var_dump_html($_POST);
739
740 if(isset($_POST['asnewobject']) && $_POST['asnewobject'] == "1")
741 {
742 $newobject_name = $_POST['object_name'];
743 $newobject_label = $_POST['object_label'];
744 $newobject_type_id = $_POST['object_type_id'];
745 $newobject_asset_no = $_POST['object_asset_no'];
746
747 if(sg_checkObjectNameUniqueness($newobject_name, $newobject_type_id))
748 {
749
750 $object_id = commitAddObject($newobject_name, $newobject_label, $newobject_type_id, $newobject_asset_no);
751
752 $_POST['asnewobject'] = "0";
753
754 parse_str($_SERVER['QUERY_STRING'],$query_string);
755
756 $query_string['object_id'] = $object_id;
757
758 $_SERVER['QUERY_STRING'] = http_build_query($query_string);
759
760 list($path, $qs) = explode('?',$_SERVER['REQUEST_URI'],2);
761 $_SERVER['REQUEST_URI'] = $path.'?'.$_SERVER['QUERY_STRING'];
762
763
764 // switch to new object
765 echo '<body>';
766 echo '<body onload="document.forms[\'newobject\'].submit();">';
767
768 echo '<form method=POST id=newobject action='.$_SERVER['REQUEST_URI'].'>';
769
770 foreach($_POST as $name => $value)
771 {
772 echo "<input type=hidden name=$name value=$value>";
773 }
774
775 echo '<input type=submit id="submitbutton" tabindex="1" value="Show List">';
776 echo '</from></body>';
777 exit;
30bf198b 778 }
8188a17c 779 else
780 {
781 showError("Object with name: \"$newobject_name\" already exists!!!");
782 $_POST['snmpconfig'] = "0";
783 }
784 }
785
365fb193 786 // save snmp settings
787 if(isset($_POST['save']) && $_POST['save'] == "1")
788 {
789 // TODO save only on success !!
790
791 $object = spotEntity('object', $object_id);
792
793 $snmpvalues[0] = 'SNMP';
794 $snmpnames = array('host', 'version', 'community');
2bfc8235 795 if($_POST['version'] == "v3")
365fb193 796 $snmpnames = array_merge($snmpnames, array('sec_level','auth_protocol','auth_passphrase','priv_protocol','priv_passphrase'));
797
798 foreach($snmpnames as $key => $value)
799 {
800 if(isset($_POST[$value]))
801 {
802 switch($value)
803 {
804 case "auth_passphrase":
805 case "priv_passphrase":
806 $snmpvalues[$key + 1] = base64_encode($_POST[$value]);
807 break;
808
809 default: $snmpvalues[$key + 1] = $_POST[$value];
810 }
811 }
812 }
813
814 // sg_var_dump_html($snmpvalues);
815
816 $newsnmpstr = implode($snmpvalues,":");
817
818 $snmpstr = strtok($object['comment'],"\n\r");
819
820 $snmpstrarray = explode(':', $snmpstr);
821
822 $setcomment = "set";
823 if($snmpstrarray[0] == "SNMP")
824 {
825 if($newsnmpstr == $snmpstr)
826 $setcomment = "ok";
827 else
828 $setcomment = "update";
829 }
830
831 if($setcomment != "ok")
832 {
833
834 if($setcomment == "update")
835 $comment = str_replace($snmpstr,$newsnmpstr, $object['comment']);
836 else
837 $comment = "$newsnmpstr\n".$object['comment'];
838
839 // echo "$snmpnewstr ".$object['comment']." --> $comment";
840
841 commitUpdateObject($object_id, $object['name'], NULL, $object['has_problems'], NULL, $comment );
842 showNotice("$setcomment SNMP Settings: $newsnmpstr");
843
844 }
845
846 }
847
8188a17c 848 if(isset($_POST['snmpconfig']) && $_POST['snmpconfig'] == '1') {
849 snmpgeneric_list($object_id);
9276dc97
ME
850 } else {
851 snmpgeneric_snmpconfig($object_id);
852 }
853} /* snmpgeneric_tabhandler */
854
855/* -------------------------------------------------- */
856
857//function snmpgeneric_tabtrigger() {
858// return 'std';
859//} /* snmpgeneric_tabtrigger */
860
861/* -------------------------------------------------- */
862
863function snmpgeneric_snmpconfig($object_id) {
864
9276dc97
ME
865
866 $object = spotEntity ('object', $object_id);
867 //$object['attr'] = getAttrValues($object_id);
868 $endpoints = findAllEndpoints ($object_id, $object['name']);
869
870 addJS('function showsnmpv3(element) {
30bf198b 871 var style;
2bfc8235 872 if(element.value != \'v3\') {
9276dc97
ME
873 style = \'none\';
874 document.getElementById(\'snmp_community_label\').style.display=\'\';
875 } else {
876 style = \'\';
877 document.getElementById(\'snmp_community_label\').style.display=\'none\';
878 }
879
30bf198b 880 var elements = document.getElementsByName(\'snmpv3\');
881 for(var i=0;i<elements.length;i++) {
9276dc97
ME
882 elements[i].style.display=style;
883 }
884 };',TRUE);
885
8188a17c 886 addJS('function shownewobject(element) {
887 var style;
888
889 if(element.checked) {
890 style = \'\';
891 } else {
892 style = \'none\';
893 }
894
895 var elements = document.getElementsByName(\'newobject\');
896 for(var i=0;i<elements.length;i++) {
897 elements[i].style.display=style;
898 }
899 };',TRUE);
900
30bf198b 901 addJS('function checkInput() {
902 var host = document.getElementById(\'host\');
903
904 if(host.value == "-1") {
905 var newvalue = prompt("Enter Hostname or IP Address","");
906 if(newvalue != "") {
907 host.options[host.options.length] = new Option(newvalue, newvalue);
908 host.value = newvalue;
909 }
910 }
911
912 if(host.value != "-1" && host.value != "")
913 return true;
914 else
915 return false;
916 };',TRUE);
917
8188a17c 918 echo '<body onload="document.getElementById(\'submitbutton\').focus(); showsnmpv3(document.getElementById(\'snmpversion\')); shownewobject(document.getElementById(\'asnewobject\'));">';
919
9276dc97
ME
920 foreach( $endpoints as $key => $value) {
921 $endpoints[$value] = $value;
922 unset($endpoints[$key]);
923 }
924 unset($key);
925 unset($value);
926
927 foreach( getObjectIPv4Allocations($object_id) as $ip => $value) {
928
30bf198b 929 $ip = ip_format($ip);
930
9276dc97
ME
931 if(!in_array($ip, $endpoints))
932 $endpoints[$ip] = $ip;
933 }
934 unset($ip);
935 unset($value);
936
937 foreach( getObjectIPv6Allocations($object_id) as $value) {
30bf198b 938 $ip = ip_format(ip_parse($value['addrinfo']['ip']));
9276dc97
ME
939
940 if(!in_array($ip, $endpoints))
941 $endpoints[$ip] = $ip;
942 }
943 unset($value);
944
30bf198b 945 /* ask for ip/host name on submit see js checkInput() */
946 $endpoints['-1'] = 'ask me';
947
365fb193 948 // saved snmp settings
949 $snmpstr = strtok($object['comment'],"\n\r");
950 $snmpstrarray = explode(':', $snmpstr);
951
952 if($snmpstrarray[0] == "SNMP")
953 {
2bfc8235 954 /* keep it compatible with older version */
955 switch($snmpstrarray[2])
956 {
957 case "1":
958 $snmpstrarray[2] = 'v1';
959 break;
960 case "2":
961 case "v2C":
962 $snmpstrarray[2] = 'v2c';
963 break;
964 case "3":
965 $snmpstrarray[2] = 'v3';
966 break;
967 }
968
365fb193 969 $snmpnames = array('SNMP','host', 'version', 'community');
2bfc8235 970 if($snmpstrarray[2] == "v3")
365fb193 971 $snmpnames = array_merge($snmpnames, array('sec_level','auth_protocol','auth_passphrase','priv_protocol','priv_passphrase'));
972
973 $snmpvalues = array();
974 foreach($snmpnames as $key => $value)
975 {
976 if(isset($snmpstrarray[$key]))
977 {
978 switch($key)
979 {
980 case 6:
981 case 8:
982 $snmpvalues[$value] = base64_decode($snmpstrarray[$key]);
983 break;
984
985 default: $snmpvalues[$value] = $snmpstrarray[$key];
986 }
987 }
988 }
989
990 unset($snmpvalues['SNMP']);
991
992 $snmpconfig = $snmpvalues;
993 }
994 else
995 $snmpconfig = array();
996
997 $snmpconfig += $_POST;
9276dc97
ME
998
999 if(!isset($snmpconfig['host'])) {
30bf198b 1000 $snmpconfig['host'] = -1;
9276dc97
ME
1001
1002 /* try to find first FQDN or IP */
1003 foreach($endpoints as $value) {
1004 if(preg_match('/^[^ .]+(\.[^ .]+)+\.?/',$value)) {
1005 $snmpconfig['host'] = $value;
1006 break;
1007 }
1008 }
1009 unset($value);
1010 }
1011
30bf198b 1012// sg_var_dump_html($endpoints);
9276dc97 1013
8188a17c 1014 if(!isset($snmpconfig['version']))
9276dc97
ME
1015 $snmpconfig['version'] = mySNMP::SNMP_VERSION;
1016
1017 if(!isset($snmpconfig['community']))
1018 $snmpconfig['community'] = getConfigVar('DEFAULT_SNMP_COMMUNITY');
1019
1020 if(empty($snmpconfig['community']))
1021 $snmpconfig['community'] = mySNMP::SNMP_COMMUNITY;
1022
1023 if(!isset($snmpconfig['sec_level']))
1024 $snmpconfig['sec_level'] = NULL;
1025
1026 if(!isset($snmpconfig['auth_protocol']))
1027 $snmpconfig['auth_protocol'] = NULL;
1028
1029 if(!isset($snmpconfig['auth_passphrase']))
1030 $snmpconfig['auth_passphrase'] = NULL;
1031
1032 if(!isset($snmpconfig['priv_protocol']))
1033 $snmpconfig['priv_protocol'] = NULL;
1034
1035 if(!isset($snmpconfig['priv_passphrase']))
1036 $snmpconfig['priv_passphrase'] = NULL;
1037
8188a17c 1038 if(!isset($snmpconfig['asnewobject']))
1039 $snmpconfig['asnewobject'] = NULL;
1040
1041 if(!isset($snmpconfig['object_type_id']))
1042 $snmpconfig['object_type_id'] = '8';
1043
1044 if(!isset($snmpconfig['object_name']))
1045 $snmpconfig['object_name'] = NULL;
1046
1047 if(!isset($snmpconfig['object_label']))
1048 $snmpconfig['object_label'] = NULL;
1049
1050 if(!isset($snmpconfig['object_asset_no']))
1051 $snmpconfig['object_asset_no'] = NULL;
1052
365fb193 1053 if(!isset($snmpconfig['save']))
1054 $snmpconfig['save'] = true;
1055
8188a17c 1056// sg_var_dump_html($snmpconfig);
1057
1058// $snmpv3displaystyle = ($snmpconfig['version'] == "3" ? "style=\"\"" : "style=\"display:none;\"");
1059
9276dc97 1060 echo '<h1 align=center>SNMP Config</h1>';
30bf198b 1061 echo '<form method=post name="snmpconfig" onsubmit="return checkInput()" action='.$_SERVER['REQUEST_URI'].' />';
9276dc97
ME
1062
1063 echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>
1064 <tr><th class=tdright>Host:</th><td>';
30bf198b 1065
365fb193 1066 //if($snmpconfig['asnewobject'] == '1' )
1067 if($snmpconfig['host'] != '-1' and !isset($endpoints[$snmpconfig['host']]))
8188a17c 1068 $endpoints[$snmpconfig['host']] = $snmpconfig['host'];
1069
30bf198b 1070 echo getSelect ($endpoints, array ('id' => 'host','name' => 'host'), $snmpconfig['host'], FALSE);
9276dc97
ME
1071
1072 echo'</td></tr>
30bf198b 1073 <tr>
9276dc97
ME
1074 <th class=tdright><label for=snmpversion>Version:</label></th>
1075 <td class=tdleft>';
1076
2bfc8235 1077 echo getSelect (array("v1" => 'v1', "v2c" => 'v2c', "v3" => 'v3'),
9276dc97
ME
1078 array ('name' => 'version', 'id' => 'snmpversion', 'onchange' => 'showsnmpv3(this)'),
1079 $snmpconfig['version'], FALSE);
1080
1081 echo '</td>
1082 </tr>
1083 <tr>
1084 <th id="snmp_community_label" class=tdright><label for=community>Community:</label></th>
8188a17c 1085 <th name="snmpv3" style="display:none;" class=tdright><label for=community>Security Name:</label></th>
9276dc97
ME
1086 <td class=tdleft><input type=text name=community value='.$snmpconfig['community'].' ></td>
1087 </tr>
1088 <tr name="snmpv3" style="display:none;">
1089 <th></th>
1090 </tr>
1091 <tr name="snmpv3" style="display:none;">
1092 <th class=tdright><label">Security Level:</label></th>
1093 <td class=tdleft>';
1094
1095 echo getSelect (array('noAuthNoPriv' => 'no Auth and no Priv', 'authNoPriv'=> 'auth without Priv', 'authPriv' => 'auth with Priv'),
1096 array ('name' => 'sec_level'),
1097 $snmpconfig['sec_level'], FALSE);
1098
1099 echo '</td></tr>
1100 <tr name="snmpv3" style="display:none;">
1101 <th class=tdright><label>Auth Type:</label></th>
1102 <td class=tdleft>
1103 <input name=auth_protocol type=radio value=MD5 '.($snmpconfig['auth_protocol'] == 'MD5' ? ' checked="checked"' : '').'/><label>MD5</label>
1104 <input name=auth_protocol type=radio value=SHA '.($snmpconfig['auth_protocol'] == 'SHA' ? ' checked="checked"' : '').'/><label>SHA</label>
1105 </td>
1106 </tr>
1107 <tr name="snmpv3" style="display:none;">
1108 <th class=tdright><label>Auth Key:</label></th>
1109 <td class=tdleft><input type=password id=auth_passphrase name=auth_passphrase value="'.$snmpconfig['auth_passphrase'].'"></td>
1110 </tr>
1111 <tr name="snmpv3" style="display:none;">
1112 <th class=tdright><label>Priv Type:</label></th>
1113 <td class=tdleft>
1114 <input name=priv_protocol type=radio value=DES '.($snmpconfig['priv_protocol'] == 'DES' ? ' checked="checked"' : '').'/><label>DES</label>
1115 <input name=priv_protocol type=radio value=AES '.($snmpconfig['priv_protocol'] == 'AES' ? ' checked="checked"' : '').'/><label>AES</label>
1116 </td>
1117 </tr>
1118 <tr name="snmpv3" style="display:none;">
1119 <th class=tdright><label>Priv Key</label></th>
1120 <td class=tdleft><input type=password name=priv_passphrase value="'.$snmpconfig['priv_passphrase'].'"></td>
1121 </tr>
1122 </tr>
8188a17c 1123
1124 <tr>
1125 <th></th>
1126 <td class=tdleft>
1127 <input name=asnewobject id=asnewobject type=checkbox value=1 onchange="shownewobject(this)"'.($snmpconfig['asnewobject'] == '1' ? ' checked="checked"' : '').'>
1128 <label>Create as new object</label></td>
1129 </tr>';
1130
1131// $newobjectdisplaystyle = ($snmpconfig['asnewobject'] == '1' ? "" : "style=\"display:none;\"");
1132
1133 echo '<tr name="newobject" style="display:none;">
1134 <th class=tdright>Type:</th><td class=tdleft>';
1135
1136 $typelist = withoutLocationTypes (readChapter (CHAP_OBJTYPE, 'o'));
1137 $typelist = cookOptgroups ($typelist);
1138
1139 printNiftySelect ($typelist, array ('name' => "object_type_id"), $snmpconfig['object_type_id']);
1140
1141 echo '</td></tr>
1142
1143 <tr name="newobject" style="display:none;">
1144 <th class=tdright>Common name:</th><td class=tdleft><input type=text name=object_name value='.$snmpconfig['object_name'].'></td></tr>
1145 <tr name="newobject" style="display:none;">
1146 <th class=tdright>Visible label:</th><td class=tdleft><input type=text name=object_label value='.$snmpconfig['object_label'].'></td></tr>
1147 <tr name="newobject" style="display:none;">
1148 <th class=tdright>Asset tag:</th><td class=tdleft><input type=text name=object_asset_no value='.$snmpconfig['object_asset_no'].'></td></tr>
1149
365fb193 1150 <tr>
1151 <th></th>
1152 <td class=tdleft>
1153 <input name=save id=save type=checkbox value=1'.($snmpconfig['save'] == '1' ? ' checked="checked"' : '').'>
1154 <label>Save SNMP settings for object</label></td>
1155 </tr>
9276dc97
ME
1156 <td colspan=2>
1157
1158 <input type=hidden name=snmpconfig value=1>
1159 <input type=submit id="submitbutton" tabindex="1" value="Show List"></td></tr>
1160
1161 </table></form>';
1162
1163} /* snmpgeneric_snmpconfig */
1164
1165function snmpgeneric_list($object_id) {
1166
30bf198b 1167 global $sg_create_noconnector_ports, $sg_known_sysObjectIDs, $sg_portoifoptions, $sg_ifType_ignore;
9276dc97
ME
1168
1169 if(isset($_POST['snmpconfig'])) {
30bf198b 1170 $snmpconfig = $_POST;
9276dc97
ME
1171 } else {
1172 showError("Missing SNMP Config");
1173 return;
1174 }
1175
8188a17c 1176// sg_var_dump_html($snmpconfig);
1177
9276dc97
ME
1178 echo '<body onload="document.getElementById(\'createbutton\').focus();">';
1179
1180 addJS('function setchecked(classname) { var boxes = document.getElementsByClassName(classname);
30bf198b 1181 var value = document.getElementById(classname).checked;
9276dc97
ME
1182 for(i=0;i<boxes.length;i++) {
1183 if(boxes[i].disabled == false)
1184 boxes[i].checked=value;
1185 }
1186 };', TRUE);
1187
1188 $object = spotEntity ('object', $object_id);
1189
1190 $object['attr'] = getAttrValues($object_id);
1191
1192 $snmpdev = new mySNMP($snmpconfig['version'], $snmpconfig['host'], $snmpconfig['community']);
1193
2bfc8235 1194 if($snmpconfig['version'] == "v3" ) {
9276dc97
ME
1195 $snmpdev->setSecurity( $snmpconfig['sec_level'],
1196 $snmpconfig['auth_protocol'],
1197 $snmpconfig['auth_passphrase'],
1198 $snmpconfig['priv_protocol'],
1199 $snmpconfig['priv_passphrase']
1200 );
1201 }
1202
1203 $snmpdev->init();
1204
1205 if($snmpdev->getErrno()) {
1206 showError($snmpdev->getError());
1207 return;
1208 }
1209
1210 /* SNMP connect successfull */
1211
2bfc8235 1212 showSuccess("SNMP ".$snmpconfig['version']." connect to ${snmpconfig['host']} successfull");
9276dc97
ME
1213
1214 echo '<form name=CreatePorts method=post action='.$_SERVER['REQUEST_URI'].'&module=redirect&op=create>';
1215
1216 echo "<strong>System Informations</strong>";
1217 echo "<table>";
1218// echo "<tr><th>OID</th><th>Value</th></tr>";
1219
1220 $systemoids = array('sysDescr', 'sysObjectID', 'sysUpTime', 'sysContact', 'sysName', 'sysLocation');
1221 foreach ($systemoids as $shortoid) {
1222
1223 $value = $snmpdev->{$shortoid};
1224
1225 if($shortoid == 'sysUpTime') {
1226 /* in hundredths of a second */
1227 $secs = (int)($value / 100);
1228 $days = (int)($secs / (60 * 60 * 24));
1229 $secs -= $days * 60 *60 * 24;
1230 $hours = (int)($secs / (60 * 60));
1231 $secs -= $hours * 60 * 60;
1232 $mins = (int)($secs / (60));
1233 $secs -= $mins * 60;
1234 $value = "$value ($days $hours:$mins:$secs)";
1235 }
1236
1237 echo "<tr><td title=\"".$snmpdev->lastgetoid."\" align=\"right\">$shortoid: </td><td>$value</td></tr>";
1238
1239 }
1240 unset($shortoid);
1241
1242 echo "</table>";
1243
1244 /* sysObjectID Attributes and Ports */
1245 $sysObjectID['object'] = &$object;
1246
1247 /* get sysObjectID */
1248 $sysObjectID['raw_value'] = $snmpdev->sysObjectID;
1249 //$sysObjectID['raw_value'] = 'NET-SNMP-MIB::netSnmpAgentOIDs.10';
1250
1251 $sysObjectID['value'] = preg_replace('/^.*enterprises\.([\.[:digit:]]+)$/','\\1', $sysObjectID['raw_value']);
1252
1253 /* try snmptranslate to numeric */
1254 if(preg_match('/[^\.0-9]+/',$sysObjectID['value'])) {
1255 $numeric_value = $snmpdev->translatetonumeric($sysObjectID['value']);
1256
1257 if(!empty($numeric_value)) {
1258 showSuccess("sysObjectID: ".$sysObjectID['value']." translated to $numeric_value");
1259 $sysObjectID['value'] = preg_replace('/^.1.3.6.1.4.1.([\.[:digit:]]+)$/','\\1', $numeric_value);
1260 }
1261 }
1262
1263 /* array_merge doesn't work with numeric keys !! */
1264 $sysObjectID['attr'] = array();
1265 $sysObjectID['port'] = array();
30bf198b 1266
9276dc97
ME
1267 $sysobjid = $sysObjectID['value'];
1268
1269 $count = 1;
1270
1271 while($count) {
1272
1273 if(isset($sg_known_sysObjectIDs[$sysobjid])) {
1274 $sysObjectID = $sysObjectID + $sg_known_sysObjectIDs[$sysobjid];
30bf198b 1275
9276dc97
ME
1276 if(isset($sg_known_sysObjectIDs[$sysobjid]['attr']))
1277 $sysObjectID['attr'] = $sysObjectID['attr'] + $sg_known_sysObjectIDs[$sysobjid]['attr'];
30bf198b 1278
9276dc97
ME
1279 if(isset($sg_known_sysObjectIDs[$sysobjid]['port']))
1280 $sysObjectID['port'] = $sysObjectID['port'] + $sg_known_sysObjectIDs[$sysobjid]['port'];
30bf198b 1281
9276dc97
ME
1282 if(isset($sg_known_sysObjectIDs[$sysobjid]['text'])) {
1283 showSuccess("found sysObjectID ($sysobjid) ".$sg_known_sysObjectIDs[$sysobjid]['text']);
1284 }
1285 }
1286
1287 $sysobjid = preg_replace('/\.[[:digit:]]+$/','',$sysobjid, 1, $count);
30bf198b 1288
9276dc97
ME
1289 /* add default sysobjectid */
1290 if($count == 0 && $sysobjid != 'default') {
1291 $sysobjid = 'default';
1292 $count = 1;
1293 }
1294 }
1295
1296 $sysObjectID['vendor_number'] = $sysobjid;
1297
1298 /* device pf */
1299 if(isset($sysObjectID['pf']))
1300 foreach($sysObjectID['pf'] as $function) {
1301 if(function_exists($function)) {
1302 /* call device pf */
1303 $function($snmpdev, $sysObjectID, NULL);
1304 } else {
1305 showWarning("Missing processor function ".$function." for device $sysobjid");
1306 }
1307 }
1308
1309
1310 /* sort attributes maintain numeric keys */
1311 ksort($sysObjectID['attr']);
1312
1313 /* DEBUG */
1314 //sg_var_dump_html($sysObjectID['attr'], "Before processing");
1315
1316 /* needs PHP >= 5 foreach call by reference */
1317 /* php 5.1.6 doesn't seem to work */
ccf830c6 1318 //foreach($sysObjectID['attr'] as $attr_id => &$attr)
9276dc97
ME
1319 foreach($sysObjectID['attr'] as $attr_id => $value) {
1320
1321 $attr = &$sysObjectID['attr'][$attr_id];
1322
1323 if(isset($object['attr'][$attr_id])) {
1324
1325 switch(TRUE) {
1326
1327 case isset($attr['pf']):
1328 if(function_exists($attr['pf'])) {
1329
1330 $attr['pf']($snmpdev, $sysObjectID, $attr_id);
1331
1332 } else {
1333 showWarning("Missing processor function ".$attr['pf']." for attribute $attr_id");
1334 }
1335
1336 break;
1337
1338 case isset($attr['oid']):
1339
1340 $attrvalue = $snmpdev->get($attr['oid']);
1341
1342 if(isset($attr['regex'])) {
1343 $regex = $attr['regex'];
1344
1345 if(isset($attr['replacement'])) {
1346 $replacement = $attr['replacement'];
1347 $attrvalue = preg_replace($regex, $replacement, $attrvalue);
1348 } else {
1349 if(!preg_match($regex, $attrvalue)) {
1350 if(!isset($attr['uncheck']))
1351 $attr['uncheck'] = "regex doesn't match";
30bf198b 1352 } else
9276dc97
ME
1353 unset($attr['uncheck']);
1354 }
1355 }
1356
30bf198b 1357 $attr['value'] = $attrvalue;
9276dc97
ME
1358
1359 break;
1360
1361 case isset($attr['value']):
1362 break;
1363
1364 default:
1365 showError("Error handling attribute id: $attr_id");
1366
1367 }
1368
1369 } else {
1370 showWarning("Object has no attribute id: $attr_id");
1371 unset($sysObjectID['attr'][$attr_id]);
1372 }
1373
1374 }
1375 unset($attr_id);
1376
1377 /* sort again in case there where attribs added ,maintain numeric keys */
1378 ksort($sysObjectID['attr']);
1379
1380 /* print attributes */
1381 echo '<br>Attributes<br><table>';
1382 echo '<tr><th><input type="checkbox" id="attribute" checked="checked" onclick="setchecked(this.id)"></td>';
1383 echo '<th>Name</th><th>Current Value</th><th>new value</th></tr>';
1384
1385 /* DEBUG */
1386 //sg_var_dump_html($sysObjectID['attr'], "After processing");
1387
30bf198b 1388 foreach($sysObjectID['attr'] as $attr_id => &$attr) {
9276dc97
ME
1389
1390 if(isset($object['attr'][$attr_id]) && isset($attr['value'])) {
1391
1392 if($attr['value'] == $object['attr'][$attr_id]['value'])
30bf198b 1393 $attr['uncheck'] = 'Current = new value';
9276dc97
ME
1394
1395 $value = $attr['value'];
1396
1397 $val_key = (isset($object['attr'][$attr_id]['key']) ? ' ('.$object['attr'][$attr_id]['key'].')' : '' );
1398 $comment = '';
1399
1400 if(isset($attr['comment'])) {
1401 if(!empty($attr['comment']))
1402 $comment = $attr['comment'];
1403 }
1404
1405 if(isset($attr['uncheck'])) {
1406 $checked = '';
1407 $comment .= ', '.$attr['uncheck'];
1408 } else {
1409 $checked = ' checked="checked"';
1410 }
1411
1412 $updateattrcheckbox = '<b style="background-color:#00ff00">'
1413 .'<input style="background-color:#00ff00" class="attribute" type="checkbox" name="updateattr['.$attr_id.']" value="'.$value.'"'
1414 .$checked.'></b>';
1415
1416 $comment = trim($comment,', ');
1417
1418 echo "<tr><td>$updateattrcheckbox</td><td title=\"id: $attr_id\">"
1419 .$object['attr'][$attr_id]['name'].'</td><td style="background-color:#d8d8d8">'
1420 .$object['attr'][$attr_id]['value'].$val_key.'</td><td>'.$value.'</td>'
1421 .'<td style="color:#888888">'.$comment.'</td></tr>';
1422 }
1423 }
1424 unset($attr_id);
1425
1426 echo '</table>';
1427
1428 /* ports */
1429
1430 /* get ports */
1431 amplifyCell($object);
1432
30bf198b 1433 /* set array key to port name */
9276dc97
ME
1434 foreach($object['ports'] as $key => $values) {
1435 $object['ports'][$values['name']] = $values;
1436 unset($object['ports'][$key]);
1437 }
1438
1439 $newporttypeoptions = getNewPortTypeOptions();
1440
1441// sg_var_dump_html($sysObjectID['port']);
1442
1443 if(!empty($sysObjectID['port'])) {
1444
1445 echo '<br>Vendor / Device specific ports<br>';
1446 echo '<table><tr><th><input type="checkbox" id="moreport" checked="checked" onclick="setchecked(this.id)"></th><th>ifName</th><th>porttypeid</th></tr>';
30bf198b 1447
9276dc97
ME
1448 foreach($sysObjectID['port'] as $name => $port) {
1449
1450 if(array_key_exists($name,$object['ports']))
1451 $disableport = TRUE;
1452 else
1453 $disableport = FALSE;
1454
1455 $comment = '';
1456
1457 if(isset($port['comment'])) {
1458 if(!empty($port['comment']))
1459 $comment = $port['comment'];
1460 }
1461 if(isset($port['uncheck'])) {
1462 $checked = '';
1463 $comment .= ', '.$port['uncheck'];
1464 } else {
1465 $checked = ' checked="checked"';
1466 }
1467
1468 $portcreatecheckbox = '<b style="background-color:'.($disableport ? '#ff0000' : '#00ff00')
1469 .'"><input style="background-color:'.($disableport ? '#ff0000' : '#00ff00').'" class="moreport" type="checkbox" name="portcreate['.$name.']" value="'.$name.'"'
1470 .($disableport ? ' disabled="disbaled"' : $checked ).'></b>';
1471
1472 $formfield = '<input type="hidden" name="ifName['.$name.']" value="'.$name.'">';
1473 echo "<tr>$formfield<td>$portcreatecheckbox</td><td>$name</td>";
1474
1475 if(isset($port['disabled'])) {
1476 $disabledselect = array('disabled' => "disabled");
1477 } else
1478 $disabledselect = array();
1479
1480
1481 foreach($port as $key => $value) {
1482
1483 if($key == 'uncheck' || $key == 'comment')
1484 continue;
30bf198b 1485
9276dc97
ME
1486 /* TODO iif_name */
1487 if($key == 'porttypeid')
1488 $displayvalue = getNiftySelect($newporttypeoptions,
1489 array('name' => "porttypeid[$name]") + $disabledselect, $value);
1490 /* disabled formfied won't be submitted ! */
30bf198b 1491 else
9276dc97
ME
1492 $displayvalue = $value;
1493
1494 $formfield = '<input type="hidden" name="'.$key.'['.$name.']" value="'.$value.'">';
1495 echo "$formfield<td>$displayvalue</td>";
1496 }
1497
1498 $comment = trim($comment,', ');
1499 echo "<td style=\"color:#888888\">$comment</td></tr>";
1500 }
1501 unset($name);
1502 unset($port);
30bf198b 1503
9276dc97
ME
1504 echo '</table>';
1505 }
1506
1507 /* snmp ports */
1508
1509 $ifsnmp = new ifSNMP($snmpdev);
1510
1511 /* ip spaces */
1512
1513 $ipspace = NULL;
1514 foreach($ifsnmp->ipaddress as $ifindex => $ipaddresses) {
1515
1516 foreach($ipaddresses as $ipaddr => $value) {
1517 $addrtype = $value['addrtype'];
1518 $netaddr = $value['net'];
1519 $maskbits = $value['maskbits'];
1520 $netid = NULL;
1521 $linklocal = FALSE;
1522
30bf198b 1523 //echo "<br> - DEBUG: ipspace $ipaddr - $netaddr - $addrtype - $maskbits<br>";
1524
9276dc97
ME
1525 /* check for ip space */
1526 switch($addrtype) {
1527 case 'ipv4':
1528 case 'ipv4z':
cc6eb4ee 1529 if($maskbits == 32)
1530 $netid = 'host';
1531 else
1532 $netid = getIPv4AddressNetworkId(ip_parse($ipaddr));
9276dc97 1533 break;
30bf198b 1534
9276dc97 1535 case 'ipv6':
30bf198b 1536
1537 /* format ipaddr for ip6_parse */
9276dc97
ME
1538 $ipaddr = preg_replace('/((..):(..))/','\\2\\3',$ipaddr);
1539 $ipaddr = preg_replace('/%.*$/','',$ipaddr);
1540
1fc7fc7d 1541 if(ip_checkparse($ipaddr) === false)
1542 continue(2); // 2 because of switch
1543
30bf198b 1544 $ip6_bin = ip6_parse($ipaddr);
1545 $ip6_addr = ip_format($ip6_bin);
1546 $netid = getIPv6AddressNetworkId($ip6_bin);
1547
1548 $node = constructIPRange($ip6_bin, $maskbits);
1549
1550 $netaddr = $node['ip'];
1551 $linklocal = substr($ip6_addr,0,5) == "fe80:";
1552
1553 //echo "<br> - DEBUG: ipspace $ipaddr - $addrtype - $maskbits - $netaddr - >$linklocal<<br>";
1554
9276dc97
ME
1555 break;
1556
1557 case 'ipv6z':
1558 /* link local */
1559 $netid = 'ignore';
1560 break;
1561 default:
1562 }
30bf198b 1563
9276dc97
ME
1564 if(empty($netid) && $netaddr != '::1' && $netaddr != '127.0.0.1' && $netaddr != '127.0.0.0' && $netaddr != '0.0.0.0' && !$linklocal) {
1565
1566 $netaddr .= "/$maskbits";
1567 $ipspace[$netaddr] = $addrtype;
1568 }
1569 }
1570 unset($ipaddr);
1571 unset($value);
1572 unset($addrtype);
1573 }
1574 unset($ifindex);
1575 unset($ipaddresses);
1576
1577 /* print ip spaces table */
1578 if(!empty($ipspace)) {
1579 echo '<br><br>Create IP Spaces';
1580 echo '<table><tr><th><input type="checkbox" id="ipspace" onclick="setchecked(this.id)" checked=\"checked\"></th>';
1581 echo '<th>Type</th><th>prefix</th><th>name</th><th width=150 title="reserve network and router addresses">reserve network / router addresses</th></tr>';
30bf198b 1582
9276dc97
ME
1583 $i = 1;
1584 foreach($ipspace as $prefix => $addrtype) {
30bf198b 1585
9276dc97
ME
1586 $netcreatecheckbox = '<b style="background-color:#00ff00">'
1587 .'<input class="ipspace" style="background-color:#00ff00" type="checkbox" name="netcreate['
1588 .$i.']" value="'.$addrtype.'" checked=\"checked\"></b>';
1589
1590 $netprefixfield = '<input type="text" size=50 name="netprefix['.$i.']" value="'.$prefix.'">';
1591
1592 $netnamefield = '<input type="text" name="netname['.$i.']">';
1593
1594 $netreservecheckbox = '<input type="checkbox" name="netreserve['.$i.']">';
1595
1596 echo "<tr><td>$netcreatecheckbox</td><td style=\"color:#888888\">$addrtype</td><td>$netprefixfield</td><td>$netnamefield</td><td>$netreservecheckbox</td></tr>";
1597
1598 $i++;
1599 }
1600 unset($prefix);
1601 unset($addrtype);
1602 unset($i);
1603
1604 echo '</table>';
1605 }
1606
1607
ccf830c6 1608 echo "<br><br>ifNumber: ".$ifsnmp->ifNumber."<br>indexcount: ".$ifsnmp->indexcount."<br><table><tbody valign=\"top\">";
9276dc97
ME
1609
1610 $portcompat = getPortInterfaceCompat();
1611
1612 $ipnets = array();
1613
cb15032d 1614 $ifsnmp->printifInfoTableHeader("<th>add ip</th><th>add port</th><th title=\"update mac\">upd mac</th><td>upd port type</th><th>porttypeid</th><th>comment</th></tr>");
9276dc97
ME
1615
1616 echo '<tr><td colspan="11"></td>
1617 <td><input type="checkbox" id="ipaddr" onclick="setchecked(this.id)">IPv4<br>
1618 <input type="checkbox" id="ipv6addr" onclick="setchecked(this.id)">IPv6</td>
1619 <td><input type="checkbox" id="ports" onclick="setchecked(this.id)"></td>
1620 <td><input type="checkbox" id="mac" onclick="setchecked(this.id)" checked="checked"></td></tr>';
1621
1622 foreach($ifsnmp as $if) {
1623
1624 $createport = TRUE;
1625 $disableport = FALSE;
1626 $ignoreport = FALSE;
1627 $port_info = NULL;
cb15032d 1628 $updateporttype = false;
9276dc97
ME
1629
1630 $updatemaccheckbox = '';
1631
1632 $hrefs = array();
1633
1634 $comment = "";
1635
1636 if(trim($ifsnmp->ifName($if)) == '') {
1637 $comment .= "no ifName";
1638 $createport = FALSE;
1639 } else {
1640
1641 if(array_key_exists($ifsnmp->ifName($if),$object['ports'])){
1642 $port_info = &$object['ports'][$ifsnmp->ifName($if)];
1643 $comment .= "Name exists";
1644 $createport = FALSE;
1645 $disableport = TRUE;
1646 }
1647 }
1648
1649 if($ifsnmp->ifPhysAddress($if) != '' ) {
1650
1651 $ifPhysAddress = $ifsnmp->ifPhysAddress($if);
1652
1653 $l2port = sg_checkL2Address($ifPhysAddress);
1654
9276dc97
ME
1655 if(!empty($l2port)) {
1656 $l2object_id = key($l2port);
1657
1658 $porthref = makeHref(array('page'=>'object', 'tab' => 'ports',
1659 'object_id' => $l2object_id, 'hl_port_id' => $l2port[$l2object_id]));
1660
1661 $comment .= ", L2Address exists";
1662 $hrefs['ifPhysAddress'] = $porthref;
1663 $createport = FALSE;
1664 // $disableport = TRUE;
1665 $updatemaccheckbox = '';
1666 }
1667
1668 $disablemac = true;
30bf198b 1669 if($disableport) {
9276dc97
ME
1670 if($port_info !== NULL) {
1671 if(str_replace(':','',$port_info['l2address']) != $ifPhysAddress)
1672 $disablemac = false;
1673 else
1674 $disablemac = true;
1675 }
1676 } else {
1677 /* port create always updates mac */
1678 $updatemaccheckbox = '<b style="background-color:#00ff00">'
1679 .'<input style="background-color:'
1680 .'#00ff00" type="checkbox"'
1681 .' checked="checked"'
1682 .' disabled=\"disabled\"></b>';
1683 }
1684
1685 if(!$disablemac)
1686 $updatemaccheckbox = '<b style="background-color:'.($disablemac ? '#ff0000' : '#00ff00').'">'
1687 .'<input class="mac" style="background-color:'
1688 .($disablemac ? '#ff0000' : '#00ff00').'" type="checkbox" name="updatemac['.$if.']" value="'
1689 .$object['ports'][$ifsnmp->ifName($if)]['id'].'" checked="checked"'
1690 .($disablemac ? ' disabled=\"disabled\"' : '' ).'></b>';
30bf198b 1691
9276dc97
ME
1692 }
1693
1694
1695 $porttypeid = guessRToif_id($ifsnmp->ifType($if), $ifsnmp->ifDescr($if));
1696
1697 if(in_array($ifsnmp->ifType($if),$sg_ifType_ignore)) {
1698 $comment .= ", ignore if type";
1699 $createport = FALSE;
1700 $ignoreport = TRUE;
1701 }
cb15032d 1702 else
1703 {
1704 if($port_info)
1705 {
1706 $ptid = $port_info['iif_id']."-".$port_info['oif_id'];
1707 if($porttypeid != $ptid)
1708 {
1709 $comment .= ", Update Type $ptid -> $porttypeid";
1710 $updateporttype = true;
1711 }
1712 }
1713 }
30bf198b 1714
9276dc97
ME
1715 /* ignore ports without an Connector */
1716 if(!$sg_create_noconnector_ports && ($ifsnmp->ifConnectorPresent($if) == 2)) {
1717 $comment .= ", no Connector";
1718 $createport = FALSE;
1719 }
1720
9276dc97
ME
1721 /* Allocate IPs ipv4 and ipv6 */
1722
1723 $ipaddresses = $ifsnmp->ipaddress($if);
30bf198b 1724
9276dc97
ME
1725 if(!empty($ipaddresses)) {
1726
1727 $ipaddrcell = '<table>';
1728
1729 foreach($ipaddresses as $ipaddr => $value) {
1730 $createipaddr = FALSE;
1731 $disableipaddr = FALSE;
1732 $ipaddrhref = '';
1733 $linklocal = FALSE;
30bf198b 1734
9276dc97
ME
1735 $addrtype = $value['addrtype'];
1736 $maskbits = $value['maskbits'];
1737 $bcast = $value['bcast'];
1738
30bf198b 1739 //echo "<br> - DEBUG: ip $ipaddr - $addrtype - $maskbits - $bcast<br>";
1740
9276dc97
ME
1741 switch($addrtype) {
1742 case 'ipv4z':
1743 case 'ipv4':
cc6eb4ee 1744 if($maskbits == 32)
1745 $bcast = "host";
1746
9276dc97
ME
1747 $inputname = 'ip';
1748 break;
30bf198b 1749
9276dc97
ME
1750 case 'ipv6z':
1751 $disableipaddr = TRUE;
1752 case 'ipv6':
1753 $inputname = 'ipv6';
1754
30bf198b 1755 /* format ipaddr for ip6_parse */
9276dc97
ME
1756 $ipaddr = preg_replace('/((..):(..))/','\\2\\3',$ipaddr);
1757 $ipaddr = preg_replace('/%.*$/','',$ipaddr);
30bf198b 1758
1fc7fc7d 1759 if(ip_checkparse($ipaddr) === false)
1760 continue(2); // 2 because of switch
1761
30bf198b 1762 /* ip_parse throws exception on parse errors */
1763 $ip6_bin = ip_parse($ipaddr);
1764 $ipaddr = ip_format($ip6_bin);
1765
1766 $node = constructIPRange($ip6_bin, $maskbits);
1767
1768 $linklocal = ($node['ip'] == 'fe80::');
9276dc97
ME
1769
1770 $createipaddr = FALSE;
1771 break;
1772
30bf198b 1773 } //switch
1774
1775 $address = getIPAddress(ip_parse($ipaddr));
9276dc97
ME
1776
1777 /* only if ip not already allocated */
1778 if(empty($address['allocs'])) {
30bf198b 1779 if(!$ignoreport) {
9276dc97 1780 $createipaddr = TRUE;
30bf198b 1781 }
9276dc97
ME
1782 } else {
1783 $disableipaddr = TRUE;
30bf198b 1784
9276dc97 1785 $ipobject_id = $address['allocs'][0]['object_id'];
30bf198b 1786
9276dc97
ME
1787 $ipaddrhref = makeHref(array('page'=>'object',
1788 'object_id' => $ipobject_id, 'hl_ipv4_addr' => $ipaddr));
30bf198b 1789
9276dc97 1790 }
30bf198b 1791
9276dc97
ME
1792 /* reserved addresses */
1793 if($address['reserved'] == 'yes') {
1794 $comment .= ', '.$address['ip'].' reserved '.$address['name'];
1795 $createipaddr = FALSE;
1796 // $disableipaddr = TRUE;
1797 }
1798
1799 if($ipaddr == '127.0.0.1' || $ipaddr == '0.0.0.0' || $ipaddr == '::1' || $ipaddr == '::' || $linklocal) {
1800 $createipaddr = FALSE;
1801 $disableipaddr = TRUE;
1802 }
1803
1804 if($ipaddr === $bcast) {
1805 $comment .= ", $ipaddr broadcast";
1806 $createipaddr = FALSE;
1807 $disableipaddr = TRUE;
1808 }
1809
30bf198b 1810 if(!$disableipaddr) {
1811 $ipaddrcheckbox = '<b style="background-color:'.($disableipaddr ? '#ff0000' : '#00ff00')
1812 .'"><input class="'.$inputname.'addr" style="background-color:'
1813 .($disableipaddr ? '#ff0000' : '#00ff00')
1814 .'" type="checkbox" name="'.$inputname.'addrcreate['.$ipaddr.']" value="'.$if.'"'
1815 .($disableipaddr ? ' disabled="disabled"' : '')
1816 .($createipaddr ? ' checked="checked"' : '').'></b>';
1817 } else {
1818 $ipaddrcheckbox = '';
1819 }
9276dc97
ME
1820
1821 $ipaddrcell .= "<tr><td>$ipaddrcheckbox</td>";
1822
30bf198b 1823 if(!empty($ipaddrhref)) {
9276dc97 1824 $ipaddrcell .= "<td><a href=$ipaddrhref>$ipaddr/$maskbits</a></td></tr>";
30bf198b 1825 } else {
9276dc97 1826 $ipaddrcell .= "<td>$ipaddr/$maskbits</td></tr>";
30bf198b 1827 }
9276dc97 1828
30bf198b 1829 } // foreach
9276dc97
ME
1830 unset($ipaddr);
1831 unset($value);
30bf198b 1832
9276dc97 1833 $ipaddrcell .= '</table>';
30bf198b 1834
1835 // if(!empty($ipaddresses))
9276dc97
ME
1836 } else {
1837 $ipaddrcreatecheckbox = '';
1838 $ipaddrcell = '';
9276dc97
ME
1839 }
1840
9276dc97 1841 /* checkboxes for add port and add ip */
30bf198b 1842 /* FireFox needs <b style=..>, IE and Opera work with <td style=..> */
9276dc97
ME
1843 if(!$disableport)
1844 $portcreatecheckbox = '<b style="background-color:'.($disableport ? '#ff0000' : '#00ff00')
1845 .'"><input class="ports" style="background-color:'.($disableport ? '#ff0000' : '#00ff00')
1846 .'" type="checkbox" name="portcreate['.$if.']" value="'.$if.'"'
1847 .($disableport ? ' disabled="disbaled"' : '').($createport ? ' checked="checked"' : '').'></b>';
1848 else
1849 $portcreatecheckbox = '';
30bf198b 1850
9276dc97
ME
1851 /* port type id */
1852 /* add port type to newporttypeoptions if missing */
1853 if(strpos(serialize($newporttypeoptions),$porttypeid) === FALSE) {
1854
1855 $portids = explode('-',$porttypeid);
1856 $oif_name = $sg_portoifoptions[$portids[1]];
1857
30bf198b 1858 $newporttypeoptions['auto'] = array($porttypeid => "*$oif_name");
9276dc97
ME
1859 }
1860
1861 $selectoptions = array('name' => "porttypeid[$if]");
1862
cb15032d 1863 if($disableport && !$updateporttype)
9276dc97
ME
1864 $selectoptions['disabled'] = "disabled";
1865
cb15032d 1866 $updateporttypecheckbox = "";
1867
1868
1869 if($updateporttype)
1870 $updateporttypecheckbox = '<b style="background-color:#00ff00;">'
1871 .'<input class="porttype" style="background-color:#00ff00;" type="checkbox" name="updateporttype['.$if.']" value="'
1872 .$port_info['id'].($updateporttype ? '" checked="checked"' : '' ).'></b>';
1873
9276dc97
ME
1874 $porttypeidselect = getNiftySelect($newporttypeoptions, $selectoptions, $porttypeid);
1875
1876 $comment = trim($comment,', ');
1877
cb15032d 1878 $ifsnmp->printifInfoTableRow($if,"<td>$ipaddrcell</td><td>$portcreatecheckbox</td><td>$updatemaccheckbox</td><td>$updateporttypecheckbox</td><td>$porttypeidselect</td><td nowrap=\"nowrap\">$comment</td>", $hrefs);
9276dc97
ME
1879
1880 }
1881 unset($if);
1882
1883 /* preserve snmpconfig */
1884 foreach($_POST as $key => $value) {
1885 echo '<input type=hidden name='.$key.' value='.$value.' />';
1886 }
1887 unset($key);
1888 unset($value);
1889
1890 echo '<tr><td colspan=15 align="right"><p><input id="createbutton" type=submit value="Create Ports and IPs" onclick="return confirm(\'Create selected items?\')"></p></td></tr></tbody></table></form>';
1891
ccf830c6 1892} // END function snmpgeneric_list
9276dc97
ME
1893
1894/* -------------------------------------------------- */
1895function snmpgeneric_opcreate() {
1896
1897 $object_id = $_REQUEST['object_id'];
1898 $attr = getAttrValues($object_id);
1899
1900// sg_var_dump_html($_REQUEST);
1901// sg_var_dump_html($attr);
1902
1903 /* commitUpdateAttrValue ($object_id, $attr_id, $new_value); */
1904 if(isset($_POST['updateattr'])) {
1905 foreach($_POST['updateattr'] as $attr_id => $value) {
1906 // if(empty($attr[$attr_id]['value']))
1907 if(!empty($value)) {
1908 commitUpdateAttrValue ($object_id, $attr_id, $value);
1909 showSuccess("Attribute ".$attr[$attr_id]['name']." set to $value");
1910 }
1911 }
1912 unset($attr_id);
1913 unset($value);
1914 }
1915 /* updateattr */
1916
1917 /* create ports */
1918 if(isset($_POST['portcreate'])) {
1919 foreach($_POST['portcreate'] as $if => $value) {
1920
1921 $ifName = (isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : '' );
1922 $ifPhysAddress = (isset($_POST['ifPhysAddress'][$if]) ? trim($_POST['ifPhysAddress'][$if]) : '' );
1923 $ifAlias = (isset($_POST['ifAlias'][$if]) ? trim($_POST['ifAlias'][$if]) : '' );
1924 $ifDescr = (isset($_POST['ifDescr'][$if]) ? trim($_POST['ifDescr'][$if]) : '' );
1925
1926 $visible_label = (empty($ifAlias) ? '' : $ifAlias.'; ').$ifDescr;
1927
1928 if(empty($ifName)) {
1929 showError('Port without ifName '.$_POST['porttypeid'][$if].', '.$visible_label.', '.$ifPhysAddress);
1930 } else {
30bf198b 1931 commitAddPort ($object_id, $ifName, $_POST['porttypeid'][$if], $visible_label, $ifPhysAddress);
9276dc97
ME
1932 showSuccess('Port created '.$ifName.', '.$_POST['porttypeid'][$if].', '.$visible_label.', '.$ifPhysAddress);
1933 }
1934 }
1935 unset($if);
1936 unset($value);
1937 }
1938 /* portcreate */
1939
1940 /* net create */
1941 if(isset($_POST['netcreate'])) {
1942 foreach($_POST['netcreate'] as $id => $addrtype) {
1943 $range = $_POST['netprefix'][$id];
1944 $name = $_POST['netname'][$id];
1945 $is_reserved = isset($_POST['netreserve'][$id]);
1946
1947 if($addrtype == 'ipv4' || $addrtype == 'ipv4z')
1948 createIPv4Prefix($range, $name, $is_reserved);
1949 else
1950 createIPv6Prefix($range, $name, $is_reserved);
1951
1952 showSuccess("$range $name created");
1953
1954 }
1955 unset($id);
1956 unset($addrtype);
1957 }
1958 /* netcreate */
1959
1960 /* allocate ipv6 adresses */
1961 if(isset($_POST['ipv6addrcreate'])) {
30bf198b 1962 foreach($_POST['ipv6addrcreate'] as $ipaddr => $if) {
1963
1964 bindIPv6ToObject(ip6_parse($ipaddr), $object_id,$_POST['ifName'][$if], 1); /* connected */
1965 showSuccess("$ipaddr allocated");
9276dc97
ME
1966 }
1967 unset($ipaddr);
1968 unset($if);
1969 }
1970 /* allocate ip adresses */
1971 if(isset($_POST['ipaddrcreate'])) {
30bf198b 1972 foreach($_POST['ipaddrcreate'] as $ipaddr => $if) {
9276dc97 1973
30bf198b 1974 bindIPToObject(ip_parse($ipaddr), $object_id,$_POST['ifName'][$if], 1); /* connected */
1975 showSuccess("$ipaddr allocated");
9276dc97
ME
1976 }
1977 unset($ipaddr);
1978 unset($if);
1979 }
1980 /* ipaddrecreate */
1981
1982 /* update mac addresses only */
1983 if(isset($_POST['updatemac'])) {
1984 foreach($_POST['updatemac'] as $if => $port_id) {
1985
1986 $ifPhysAddress = (isset($_POST['ifPhysAddress'][$if]) ? trim($_POST['ifPhysAddress'][$if]) : '' );
1987
1988 sg_commitUpdatePortl2address($object_id, $port_id, $ifPhysAddress);
1989
1990 $ifName = (isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : '' );
1991 showSuccess("l2address updated on $ifName to $ifPhysAddress");
1992 }
1993 unset($if);
1994 unset($port_id);
1995 }
1996 /* updatemac */
1997
cb15032d 1998 /* update port type */
1999 if(isset($_POST['updateporttype'])) {
2000 foreach($_POST['updateporttype'] as $if => $port_id) {
2001
2002 $porttypeid = (isset($_POST['porttypeid'][$if]) ? trim($_POST['porttypeid'][$if]) : '' );
2003
2004 sg_commitUpdatePortType($object_id, $port_id, $porttypeid);
2005
2006 $ifName = (isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : '' );
2007 showSuccess("port type updated on $ifName");
2008 }
2009 unset($if);
2010 unset($port_id);
2011 }
2012 /* updateporttype */
9276dc97
ME
2013} /* snmpgeneric_opcreate */
2014
2015/* -------------------------------------------------- */
2016
2017/* returns RT interface type depending on ifType, ifDescr, .. */
2018function guessRToif_id($ifType,$ifDescr = NULL) {
2019 global $sg_ifType2oif_id;
2020 global $sg_portiifoptions;
2021 global $sg_portoifoptions;
2022
2023 /* default value */
2024 $retval = '24'; /* 1000BASE-T */
2025
2026 if(isset($sg_ifType2oif_id[$ifType])) {
2027 $retval = $sg_ifType2oif_id[$ifType];
2028 }
2029
2030 if(strpos($retval,'-') === FALSE)
2031 $retval = "1-$retval";
2032
2033 /* no ethernetCsmacd */
30bf198b 2034 if($ifType != 6)
9276dc97
ME
2035 return $retval;
2036
2037
2038 /* try to identify outer and inner interface type from ifDescr */
2039
2040 /**********************
2041 * ifDescr samples
2042 *
2043 * Enterasys C3
2044 *
2045 * Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 45 - no sfp inserted
2046 * Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 47 - sfp 1000BASE-SX inserted
2047 *
2048 *
2049 * Enterasys S4
2050 *
2051 * Enterasys Networks, Inc. 1000BASE Gigabit Ethernet Port; No GBIC/MGBIC Inserted
2052 * Enterasys Networks, Inc. 1000BASE-SX Mini GBIC w/LC connector
2053 * Enterasys Networks, Inc. 10GBASE SFP+ 10-Gigabit Ethernet Port; No SFP+ Inserted
2054 * Enterasys Networks, Inc. 10GBASE-SR SFP+ 10-Gigabit Ethernet Port (850nm Short Wavelength, 33/82m MMF, LC)
2055 * Enterasys Networks, Inc. 1000BASE Gigabit Ethernet Port; Unknown GBIC/MGBIC Inserted
30bf198b 2056 *
9276dc97
ME
2057 */
2058
2059 foreach($sg_portiifoptions as $iif_id => $iif_type) {
30bf198b 2060
9276dc97
ME
2061 /* TODO better matching */
2062
2063
2064 /* find iif_type */
2065 if(preg_match('/(.*?)('.preg_quote($iif_type).')(.*)/i',$ifDescr,$matches)) {
2066
2067 $oif_type = "empty ".$iif_type;
2068
2069 $no = preg_match('/ no $/i', $matches[1]);
2070
2071 if(preg_match('/(\d+[G]?)BASE[^ ]+/i', $matches[1], $basematch)) {
2072 $oif_type=$basematch[0];
2073 } else {
2074 if(preg_match('/(\d+[G]?)BASE[^ ]+/i', $matches[3], $basematch)) {
2075 $oif_type=$basematch[0];
2076 }
2077 }
2078
2079 if($iif_id == -1) {
2080 /* 2 => SFP-100 or 4 => SFP-1000 */
2081
2082 if(isset($basematch[1])) {
2083 switch($basematch[1]) {
2084 case '100' :
2085 $iif_id = 2;
2086 $iif_type = "SFP-100";
2087 break;
2088 default:
2089 case '1000' :
30bf198b 2090 $iif_id = 4;
9276dc97
ME
2091 $iif_type = "SFP-1000";
2092 break;
2093 }
2094 }
30bf198b 2095
3049413e 2096 if(preg_match('/sfp 1000-sx/i',$ifDescr))
2097 $oif_type = '1000BASE-SX';
2098
2099 if(preg_match('/sfp 1000-lx/i',$ifDescr))
2100 $oif_type = '1000BASE-LX';
2101
9276dc97
ME
2102 }
2103
2104 if($no) {
2105 $oif_type = "empty ".$iif_type;
2106 }
2107
2108 $oif_type = preg_replace('/BASE/',"Base",$oif_type);
2109
2110 $oif_id = array_search($oif_type,$sg_portoifoptions);
2111
2112 if($oif_id != '') {
2113 $retval = "$iif_id-$oif_id";
2114 }
2115
2116 /* TODO check port compat */
2117
2118 /* stop foreach */
2119 break;
2120 }
2121 }
2122 unset($iif_id);
2123 unset($iif_type);
2124
2125 if(strpos($retval,'-') === FALSE)
2126 $retval = "1-$retval";
2127
2128 return $retval;
2129
2130}
2131
2132/* --------------------------------------------------- */
2133
2134function sg_commitUpdatePortl2address($object_id, $port_id, $port_l2address)
2135{
2136 $db_l2address = l2addressForDatabase ($port_l2address);
2137
2138 global $dbxlink;
2139 $dbxlink->exec ('LOCK TABLES Port WRITE');
2140 if (alreadyUsedL2Address ($db_l2address, $object_id))
2141 {
2142 $dbxlink->exec ('UNLOCK TABLES');
2143 // FIXME: it is more correct to throw InvalidArgException here
2144 // and convert it to InvalidRequestArgException at upper level,
2145 // when there is a mean to do that.
2146 throw new InvalidRequestArgException ('port_l2address', $db_l2address, 'address belongs to another object');
2147 }
2148 usePreparedUpdateBlade
2149 (
2150 'Port',
2151 array
2152 (
2153 'l2address' => ($db_l2address === '') ? NULL : $db_l2address,
2154 ),
2155 array
2156 (
2157 'id' => $port_id,
2158 'object_id' => $object_id
2159 )
2160 );
2161 $dbxlink->exec ('UNLOCK TABLES');
2162} /* sg_commitUpdatePortl2address */
2163
cb15032d 2164/* --------------------------------------------------- */
2165
2166function sg_commitUpdatePortType($object_id, $port_id, $porttypeid)
2167{
2168 global $dbxlink;
2169
2170 list($iif_id, $type) = explode("-",$porttypeid);
2171
2172 $dbxlink->exec ('LOCK TABLES Port WRITE');
2173 usePreparedUpdateBlade
2174 (
2175 'Port',
2176 array
2177 (
2178 'iif_id' => ($iif_id === '') ? NULL : $iif_id,
2179 'type' => ($type === '') ? NULL : $type
2180 ),
2181 array
2182 (
2183 'id' => $port_id,
2184 'object_id' => $object_id
2185 )
2186 );
2187 $dbxlink->exec ('UNLOCK TABLES');
2188} /* sg_commitUpdatePortType */
9276dc97
ME
2189/* ----------------------------------------------------- */
2190
2191/* returns object_id and port_id to a given l2address */
2192function sg_checkL2Address ($address)
2193{
2194 $result = usePreparedSelectBlade
2195 (
2196 'SELECT object_id,id FROM Port WHERE BINARY l2address = ?',
2197 array ($address)
2198 );
2199 $row = $result->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_UNIQUE|PDO::FETCH_COLUMN);
2200 return $row;
2201}
2202
2203/* returns oi_id and name */
2204function getPortOIOptions()
2205{
2206 $result = usePreparedSelectBlade
2207 (
2208 'SELECT dict_key,dict_value from Dictionary where chapter_id = 2',
2209 array ()
2210 );
2211 $row = $result->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_UNIQUE|PDO::FETCH_COLUMN);
2212 return $row;
2213}
2214
8188a17c 2215function sg_checkObjectNameUniqueness ($name, $type_id, $object_id = 0)
2216{
2217 // Some object types do not need unique names
2218 // 1560 - Rack
2219 // 1561 - Row
2220 $dupes_allowed = array (1560, 1561);
2221 if (in_array ($type_id, $dupes_allowed))
2222 return;
2223
2224 $result = usePreparedSelectBlade
2225 (
2226 'SELECT COUNT(*) FROM Object WHERE name = ? AND id != ?',
2227 array ($name, $object_id)
2228 );
2229 $row = $result->fetch (PDO::FETCH_NUM);
2230 if ($row[0] != 0)
2231 return false;
2232 else
2233 return true;
2234}
2235
2236
9276dc97
ME
2237/* ------------------------------------------------------- */
2238class SNMPgeneric {
2239
2240 protected $host;
2241 protected $version;
2242
2243 /* SNMPv1 and SNMPv2c */
2244 protected $community;
2245
2246 /* SNMPv3 */
2247 protected $sec_level;
2248 protected $auth_protocol;
2249 protected $auth_passphrase;
2250 protected $priv_protocol;
2251 protected $priv_passphrase;
2252// protected $contextName;
2253// protected $contextEngineID;
2254
2bfc8235 2255 const VERSION_1 = 0;
2256 const VERSION_2C = 1;
2257 const VERSION_2c = 1;
9276dc97
ME
2258 const VERSION_3 = 3;
2259
2260 protected $result;
2261
2262 function __construct($version, $host, $community) {
30bf198b 2263
9276dc97 2264 $this->host = $host;
2bfc8235 2265
9276dc97 2266 $this->version = $version;
30bf198b 2267 $this->community = $community;
2268
2269 set_error_handler(array($this,'ErrorHandler'), E_WARNING);
9276dc97
ME
2270 }
2271
2272 function setSecurity($sec_level, $auth_protocol = 'md5', $auth_passphrase = '', $priv_protocol = 'des', $priv_passphrase = '') {
2273 $this->sec_level = $sec_level;
2274 $this->auth_protocol = $auth_protocol;
2275 $this->auth_passphrase = $auth_passphrase;
2276 $this->priv_protocol = $priv_protocol;
2277 $this->priv_passphrase = $priv_passphrase;
2bfc8235 2278
2279 return true;
2280 }
2281
2282 function __set($name, $value)
2283 {
2284 switch($name)
2285 {
2286 case 'quick_print':
2287 snmp_set_quick_print($value);
2288 break;
2289 case 'oid_output_format':
2290 snmp_set_oid_output_format($value);
2291 break;
2292 case 'enum_print':
2293 snmp_set_enum_print($value);
2294 break;
2295 case 'valueretrieval':
2296 snmp_set_valueretrieval($value);
2297 break;
2298 default:
2299 $trace = debug_backtrace();
2300 trigger_error(
2301 'Undefined property via __set(): ' . $name .
2302 ' in ' . $trace[0]['file'] .
2303 ' on line ' . $trace[0]['line'],
2304 E_USER_NOTICE);
2305 return null;
2306 }
9276dc97
ME
2307 }
2308
2309 function walk( $oid, $suffix_as_key = FALSE) {
2310
2311 switch($this->version) {
2312 case self::VERSION_1:
2313 if($suffix_as_key){
2314 $this->result = snmpwalk($this->host,$this->community,$oid);
2315 } else {
2316 $this->result = snmprealwalk($this->host,$this->community,$oid);
2317 }
2318 break;
2319
2320 case self::VERSION_2C:
2bfc8235 2321 case self::VERSION_2c:
9276dc97
ME
2322 if($suffix_as_key){
2323 $this->result = snmp2_walk($this->host,$this->community,$oid);
2324 } else {
2325 $this->result = snmp2_real_walk($this->host,$this->community,$oid);
2326 }
2327 break;
2328
2329 case self::VERSION_3:
2330 if($suffix_as_key){
2331 $this->result = snmp3_walk($this->host,$this->community, $this->sec_level, $this->auth_protocol, $this->auth_passphrase, $this->priv_protocol, $this->priv_passphrase,$oid);
2332 } else {
2333 $this->result = snmp3_real_walk($this->host,$this->community, $this->sec_level, $this->auth_protocol, $this->auth_passphrase, $this->priv_protocol, $this->priv_passphrase,$oid);
2334 }
2335 break;
2336 }
2337
2338 return $this->result;
2339
2340 }
2341
2342 private function __snmpget($object_id) {
2343
2344 $retval = FALSE;
30bf198b 2345
9276dc97
ME
2346 switch($this->version) {
2347 case self::VERSION_1:
2348 $retval = snmpget($this->host,$this->community,$object_id);
2349 break;
2350
2351 case self::VERSION_2C:
2bfc8235 2352 case self::VERSION_2c:
9276dc97
ME
2353 $retval = snmp2_get($this->host,$this->community,$object_id);
2354 break;
2355
2356 case self::VERSION_3:
2357 $retval = snmp3_get($this->host,$this->community, $this->sec_level, $this->auth_protocol, $this->auth_passphrase, $this->priv_protocol, $this->priv_passphrase,$object_id);
2358 break;
2359 }
2360
2361 return $retval;
2362 }
2363
2364 function get($object_id, $preserve_keys = false) {
2365
2366 if(is_array($object_id)) {
2367
2368 if( $preserve_keys ) {
2369 foreach($object_id as $oid) {
2370 $this->result[$oid] = $this->__snmpget($oid);
2371 }
2372 unset($oid);
2373 } else {
2374 foreach($object_id as $oid) {
2375 $result_oid = preg_replace('/.\d$/','',$oid);
2376 $this->result[$result_oid] = $this->__snmpget($oid);
2377 }
2378 unset($oid);
2379 }
2380 } else {
2381 $this->result = $this->__snmpget($object_id);
2382 }
2383
2384 return $this->result;
30bf198b 2385
9276dc97
ME
2386 }
2387
2388 function close() {
2389 }
2390
2391 function getErrno() {
2392 return ($this->result === FALSE);
2393 }
2394
2395 function getError() {
2396 $var = error_get_last();
2397 return $var['message'];
2398 }
30bf198b 2399
2400 function Errorhandler($errno, $errstr, $errfile, $errline) {
2401 switch(TRUE) {
2402 case (False !== strpos($errstr,'No Such Object available on this agent at this OID')):
2403 /* no further error processing */
2404 return true;
2405 break;
2406 }
2407
2408 /* proceed with default error handling */
2409 return false;
2410 }
9276dc97
ME
2411} /* SNMPgeneric */
2412
2413/* ------------------------------------------------------- */
2414/*
30bf198b 2415 * SNMP with system OIDs
9276dc97
ME
2416 */
2417class mySNMP extends SNMPgeneric implements Iterator {
2418
2bfc8235 2419 const SNMP_VERSION = parent::VERSION_2C;
9276dc97
ME
2420 const SNMP_COMMUNITY = 'public';
2421
2422 public $lastgetoid;
2423
2424 //private $sysInfo;
2425 private $system;
2426
2427 /* is system table available ? */
2428 private $systemerror = TRUE;
2429
2430 function __construct($version, $host, $community) {
2bfc8235 2431
2432 switch($version)
2433 {
2434 case '1':
2435 case 'v1':
2436 $version = parent::VERSION_1;
2437 break;
2438 case '2':
2439 case 'v2C':
2440 case 'v2c':
2441 $version = parent::VERSION_2c;
2442 break;
2443 case '3':
2444 case 'v3':
2445 $version = parent::VERSION_3;
2446 break;
2447 };
2448
9276dc97
ME
2449 parent::__construct($version, $host, $community);
2450
2451 //snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
2452
2453 /* Return values without SNMP type hint */
2bfc8235 2454 //snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
2455 $this->valueretrieval = SNMP_VALUE_PLAIN;
9276dc97
ME
2456
2457 /* needs php >= 5.2.0 */
2458 // snmp_set_oid_output_format(SNMP_OID_OUTPUT_FULL);
30bf198b 2459
9276dc97
ME
2460 // snmp_set_quick_print(1);
2461
2462 } /* __construct */
2463
2464 function init() {
2465 /* .iso.org.dod.internet.mgmt.mib-2.system */
2466 $this->system = $this->walk(".1.3.6.1.2.1.1");
2467
2468 $this->systemerror = $this->getErrno() || empty($this->system);
2469 } /* init() */
2470
2471 /* get value from system cache */
2472 private function _getvalue($object_id) {
2473
2474 /* TODO better matching */
2475
2476 if( isset($this->system["SNMPv2-MIB::$object_id"])) {
2477 $this->lastgetoid = "SNMPv2-MIB::$object_id";
2478 return $this->system["SNMPv2-MIB::$object_id"];
2479 } else {
2480 if( isset($this->system[".iso.org.dod.internet.mgmt.mib-2.system.$object_id"])) {
2481 $this->lastgetoid = ".iso.org.dod.internet.mgmt.mib-2.system.$object_id";
2482 return $this->system[".iso.org.dod.internet.mgmt.mib-2.system.$object_id"];
2483 } else {
2484 if( isset($this->system[$object_id])) {
2485 $this->lastgetoid = $object_id;
2486 return $this->system[$object_id];
2487 } else {
2488 foreach($this->system as $key => $value) {
2489 if(strpos($key, $object_id)) {
2490 $this->lastgetoid = $key;
2491 return $value;
2492 }
2493 }
2494 unset($key);
2495 unset($value);
2496 }
2497 }
2498 }
2499
2500 return NULL;
2501 }
2502
2503 function get($object_id, $preserve_keys = false) {
2504
2505 if(!$this->systemerror)
2506 $retval = $this->_getvalue($object_id);
2507 else
2508 $retval = NULL;
2509
2510 if($retval === NULL) {
2511 $this->lastgetoid = $object_id;
2512 $retval = parent::get($object_id,$preserve_keys);
2513 }
2514
2515 return $retval;
2516
2517 } /* get */
2518
2519 function translatetonumeric($oid) {
2520 global $sg_cmd_snmptranslate;
2521
2522 $val = exec(escapeshellcmd($sg_cmd_snmptranslate).' -On '.escapeshellarg($oid), $output, $retval);
2523
2524 if($retval == 0)
2525 return $val;
2526
2527 return FALSE;
2528
2529 } /* translatetonumeric */
2530/*
2531 function get_new($object_id, $preserve_keys = false) {
2532 $result = parent::get($object_id,$preserve_keys);
2533 return $this->removeDatatype($result);
2534 }
2535
2536 function walk_new($object_id) {
2537 $result = parent::walk($object_id);
2538 return $this->removeDatatype($result);
2539 }
2540
2541*/
2542 /* use snmp_set_valueretrieval(SNMP_VALUE_PLAIN) instead */
2543/* function removeDatatype($val) {
2544 return preg_replace('/^\w+: /','',$val);
2545 }
2546*/
2547 /* make something like $class->sysDescr work */
2548 function __get($name) {
2549 if($this->systemerror) {
2550 return;
2551 }
30bf198b 2552
9276dc97
ME
2553 $retval = $this->_getvalue($name);
2554
2555 if($retval === NULL) {
2556
2557 $trace = debug_backtrace();
30bf198b 2558 trigger_error(
2559