Beispiel #1
0
 /**
  * Parse a MIB file
  *
  * @param string $mibtext
  * @param boolean $full
  */
 function parse_mib($mibtext, $mib_name, $full = false)
 {
     $tokens = MibParser::get_tokens($mibtext);
     $cnt = count($tokens);
     $rec = array();
     for ($index = 0; $index < $cnt; $index++) {
         if ($tokens[$index] == 'DEFINITIONS' && $tokens[$index + 1] == "::=" && $tokens[$index + 2] == "BEGIN") {
             $mib_name = $tokens[$index - 1];
             $this->mib = $mib_name;
         } else {
             if (in_array($tokens[$index], array('OBJECT-IDENTITY', 'OBJECT-TYPE', 'OBJECT-GROUP', 'NOTIFICATION-GROUP', 'MODULE-IDENTITY', 'NOTIFICATION-TYPE'))) {
                 if ($tokens[$index - 1] != ',' && $tokens[$index + 1] != 'FROM' && $tokens[$index + 1] != 'MACRO') {
                     if (isset($rec['NAME']) && isset($rec['VALUE'])) {
                         $this->parsed[] = $rec;
                     }
                     $rec = array('NAME' => $tokens[$index - 1], 'MIB' => $mib_name, 'TYPE' => $tokens[$index]);
                 }
             } elseif ($tokens[$index] == "TEXTUAL-CONVENTION") {
                 if ($tokens[$index - 1] == '::=') {
                     if (isset($rec['NAME']) && isset($rec['VALUE'])) {
                         $this->parsed[] = $rec;
                     }
                     $rec = array('NAME' => $tokens[$index - 2], 'MIB' => $mib_name, 'TYPE' => $tokens[$index], 'VALUE' => "TEXTUAL-CONVENTION");
                 }
             } elseif ($tokens[$index] == 'OBJECT') {
                 if ($tokens[$index + 1] == 'IDENTIFIER' && $tokens[$index - 1] != '(' && $tokens[$index - 1] != '::=' && $tokens[$index - 1] != 'SYNTAX' && $tokens[$index - 2] != '(') {
                     if (isset($rec['NAME']) && isset($rec['VALUE'])) {
                         $this->parsed[] = $rec;
                     }
                     $rec = array('NAME' => $tokens[$index - 1], 'MIB' => $mib_name, 'TYPE' => $tokens[$index]);
                 }
             } elseif ($tokens[$index] == '{') {
                 MibParser::parse_bracket_token($tokens, $index, '{', '}');
             } elseif (isset($rec['NAME'])) {
                 if ($tokens[$index] == '::=' && $tokens[$index + 1] != "TEXTUAL-CONVENTION") {
                     $rec['VALUE'] = MibParser::parse_simple_token($tokens, $index);
                     $this->parsed[] = $rec;
                     $rec = array();
                 } elseif ($full) {
                     if ($tokens[$index] == 'ACCESS') {
                         $rec['ACCESS'] = MibParser::parse_simple_token($tokens, $index, array('read-only', 'not-accessible', 'read-write'));
                     } elseif ($tokens[$index] == 'OBJECTS') {
                         $rec['OBJECTS'] = MibParser::parse_simple_token($tokens, $index);
                     } elseif ($tokens[$index] == 'NOTIFICATIONS') {
                         $rec['NOTIFICATIONS'] = MibParser::parse_simple_token($tokens, $index);
                     } elseif ($tokens[$index] == 'DEFVAL') {
                         $rec['DEFVAL'] = MibParser::parse_simple_token($tokens, $index);
                     } elseif ($tokens[$index] == 'DESCRIPTION') {
                         $rec['DESCRIPTION'] = MibParser::parse_simple_token($tokens, $index);
                     } elseif ($tokens[$index] == 'INDEX') {
                         $rec['INDEX'] = MibParser::parse_simple_token($tokens, $index);
                     } elseif ($tokens[$index] == 'MAX-ACCESS') {
                         $rec['MAX-ACCESS'] = MibParser::parse_simple_token($tokens, $index, array('read-only', 'not-accessible', 'read-write', 'read-create', 'accessible-for-notify'));
                     } elseif ($tokens[$index] == 'REFERENCE') {
                         $rec['REFERENCE'] = MibParser::parse_simple_token($tokens, $index);
                     } elseif ($tokens[$index] == 'STATUS') {
                         $rec['STATUS'] = MibParser::parse_simple_token($tokens, $index, array('current', 'deprecated', 'obsolete', 'mandatory'));
                     } elseif ($tokens[$index] == 'SYNTAX') {
                         $rec['SYNTAX'] = MibParser::parse_SYNTAX_token($tokens, $index);
                     } elseif ($tokens[$index] == 'UNITS') {
                         $rec['UNITS'] = MibParser::parse_simple_token($tokens, $index);
                     }
                 }
             }
         }
     }
     if (isset($rec['NAME']) && isset($rec['VALUE'])) {
         $this->parsed[] = $rec;
     }
 }