demo: simplify demoreload.sh
[racktables-contribs] / snmpgeneric.php
index 120e431..9fa9979 100644 (file)
  *             - ifxTable
  *             - ipAddrTable (ipv4 only)
  *             - ipAddressTable (ipv4 + ipv6)
+ *             - ipv6AddrAddress (ipv6)
  *
  *     Features:
  *             - update object attributes
  *             - create networks
  *             - create ports
  *             - add and bind ip addresses
+ *             - create as new object
+ *             - save snmp settings per object (uses comment field)
  *
  *     Known to work with:
  *             - Enterasys SecureStacks, S-Series
  * TESTED on FreeBSD 9.0, nginx/1.0.12, php 5.3.10, NET-SNMP 5.7.1
  *     and RackTables <= 0.20.3
  *
- * (c)2012,2013 Maik Ehinger <m.ehinger@ltur.de>
+ * (c)2015 Maik Ehinger <github138@t-online.de>
  */
 
 /****
  * INSTALL
  *     just place file in plugins directory
  *
+ *     Increase max_input_vars in php.ini if not all ports were added on one run.
+ *
  */
 
 /**
  *
  *  - code cleanup
  *
- *  - update visible label on ifAlias change !?
- *
  *  - test if device supports mibs
  *  - gethostbyaddr / gethostbyname host list
  *  - correct iif_name display if != 1
  *
  *  - set more Object attributs / fields
  *
+ *  - Input variables exceeded 1000
+ *  - update iftypes
+ *
  */
 
 /* RackTables Debug Mode */
 //$debug_mode=1;
 
-require_once('inc/snmp.php');
+require_once(realpath (dirname (__FILE__).'/../wwwroot').'/inc/snmp.php');
 
 $tab['object']['snmpgeneric'] = 'SNMP Generic sync';
 $tabhandler['object']['snmpgeneric'] = 'snmpgeneric_tabhandler';
-//$trigger['object']['snmpgeneric'] = 'snmpgeneric_tabtrigger';
+$trigger['object']['snmpgeneric'] = 'snmpgeneric_tabtrigger';
 
 $ophandler['object']['snmpgeneric']['create'] = 'snmpgeneric_opcreate';
 
@@ -118,7 +124,7 @@ $sg_ifType2oif_id = array(
         '33' => 1469,  /*  rs232 => RS-232 (DB-9) 681 */
         '34' => 1469,  /* para => virtual port 1469 */
         '53' => 1469,  /* propVirtual => virtual port 1469 */
-        '62' => 1195,  /* fastEther => 100BASE-FX 1195 */
+        '62' => 19,    /* fastEther => 100BASE-TX 19 */
        '131' => 1469,  /* tunnel => virtual port 1469 */
        '136' => 1469,  /* l3ipvlan => virtual port 1469 */
        '160' => 1469,  /* usb => virtual port 1469 */
@@ -337,6 +343,7 @@ function snmpgeneric_pf_enterasys(&$snmp, &$sysObjectID, $attr_id) {
 
                /* TODO SW type */
                //$attrs[4]['value'] = 'Enterasys'; /* SW type */
+               $attrs[4]['key'] = '0'; /* SW type dict key 0 = NOT SET*/
 
                /* set SW version only if not already set by entitymib */
                if(isset($attrs[5]['value']) && !empty($attrs[5]['value'])) {
@@ -378,7 +385,10 @@ function snmpgeneric_pf_catalyst(&$snmp, &$sysObjectID, $attr_id) {
                        $attrs[5]['value'] = $exact_release;
 
                        if (array_key_exists ($major_line, $ios_codes))
+                       {
                                $attrs[4]['value'] = $ios_codes[$major_line];
+                               $attrs[4]['key'] = $ios_codes[$major_line];
+                       }
 
                } /* sw type / version */
 
@@ -411,6 +421,9 @@ function snmpgeneric_pf_ciscoflash(&$snmp, &$sysObjectID, $attr_id) {
 
        $ciscoflash = $snmp->walk('1.3.6.1.4.1.9.9.10.1.1.2'); /* ciscoFlashDeviceTable */
 
+       if(!$ciscoflash)
+               return;
+
        $flash = array_keys($ciscoflash, 'flash');
 
        foreach($flash as $oid) {
@@ -472,6 +485,7 @@ function snmpgeneric_pf_hwtype(&$snmp, &$sysObjectID, $attr_id) {
 
                /* return array of attr_id => attr_value) */
                $attr['value'] = $value;
+               $attr['key'] = $value;
 
        } else {
                showNotice("HW type dict_key not set - Unknown OID");
@@ -543,6 +557,7 @@ function snmpgeneric_pf_swtype(&$snmp, &$sysObjectID, $attr_id) {
 
                /* set attr value */
                $attr['value'] = $value;
+               $attr['key'] = $value;
        //      unset($attr['uncheck']);
 
        }
@@ -640,6 +655,10 @@ function snmpgeneric_pf_entitymib(&$snmp, &$sysObjectID, $attr_id) {
                        $index = $matches[1];
 
                        $name = $snmp->get(".1.3.6.1.2.1.47.1.1.1.1.7.$index");
+
+                       if(!$name)
+                               continue;
+
                        $hardwarerev = $snmp->get(".1.3.6.1.2.1.47.1.1.1.1.8.$index");
                        $firmwarerev = $snmp->get(".1.3.6.1.2.1.47.1.1.1.1.9.$index");
                        $softwarerev = $snmp->get(".1.3.6.1.2.1.47.1.1.1.1.10.$index");
@@ -730,10 +749,118 @@ $sg_portoifoptions= getPortOIFOptions();
 
 function snmpgeneric_tabhandler($object_id) {
 
-       if(isset($_POST['snmpconfig'])) {
-               if($_POST['snmpconfig'] == '1') {
-                       snmpgeneric_list($object_id);
+//     sg_var_dump_html($_POST);
+
+       if(isset($_POST['asnewobject']) && $_POST['asnewobject'] == "1")
+       {
+               $newobject_name = $_POST['object_name'];
+               $newobject_label = $_POST['object_label'];
+               $newobject_type_id = $_POST['object_type_id'];
+               $newobject_asset_no = $_POST['object_asset_no'];
+
+               if(sg_checkObjectNameUniqueness($newobject_name, $newobject_type_id))
+               {
+
+                       $object_id = commitAddObject($newobject_name, $newobject_label, $newobject_type_id, $newobject_asset_no);
+
+                       $_POST['asnewobject'] = "0";
+
+                       parse_str($_SERVER['QUERY_STRING'],$query_string);
+
+                       $query_string['object_id'] = $object_id;
+
+                       $_SERVER['QUERY_STRING'] = http_build_query($query_string);
+
+                       list($path, $qs) = explode('?',$_SERVER['REQUEST_URI'],2);
+                       $_SERVER['REQUEST_URI'] = $path.'?'.$_SERVER['QUERY_STRING'];
+
+
+                       // switch to new object
+                       echo '<body>';
+                       echo '<body onload="document.forms[\'newobject\'].submit();">';
+
+                       echo '<form method=POST id=newobject action='.$_SERVER['REQUEST_URI'].'>';
+
+                       foreach($_POST as $name => $value)
+                       {
+                               echo "<input type=hidden name=$name value=$value>";
+                       }
+
+                       echo '<input type=submit id="submitbutton" tabindex="1" value="Show List">';
+                       echo '</from></body>';
+                       exit;
                }
+               else
+               {
+                       showError("Object with name: \"$newobject_name\" already exists!!!");
+                       $_POST['snmpconfig'] = "0";
+               }
+       }
+
+       // save snmp settings
+       if(isset($_POST['save']) && $_POST['save'] == "1")
+       {
+               // TODO save only on success !!
+
+               $object = spotEntity('object', $object_id);
+
+               $snmpvalues[0] = 'SNMP';
+               $snmpnames = array('host', 'version', 'community');
+               if($_POST['version'] == "v3")
+                       $snmpnames = array_merge($snmpnames, array('sec_level','auth_protocol','auth_passphrase','priv_protocol','priv_passphrase'));
+
+               foreach($snmpnames as $key => $value)
+               {
+                       if(isset($_POST[$value]))
+                       {
+                               switch($value)
+                               {
+                                       case "auth_passphrase":
+                                       case "priv_passphrase":
+                                               $snmpvalues[$key + 1] = base64_encode($_POST[$value]);
+                                               break;
+
+                                       default: $snmpvalues[$key + 1] = $_POST[$value];
+                               }
+                       }
+               }
+
+       //      sg_var_dump_html($snmpvalues);
+
+               $newsnmpstr = implode($snmpvalues,":");
+
+               $snmpstr = strtok($object['comment'],"\n\r");
+
+               $snmpstrarray = explode(':', $snmpstr);
+
+               $setcomment = "set";
+                if($snmpstrarray[0] == "SNMP")
+               {
+                       if($newsnmpstr == $snmpstr)
+                               $setcomment = "ok";
+                       else
+                               $setcomment = "update";
+               }
+
+               if($setcomment != "ok")
+               {
+
+                       if($setcomment == "update")
+                               $comment = str_replace($snmpstr,$newsnmpstr, $object['comment']);
+                       else
+                               $comment = "$newsnmpstr\n".$object['comment'];
+
+               //      echo "$snmpnewstr ".$object['comment']." --> $comment";
+
+                       commitUpdateObject($object_id, $object['name'], NULL, $object['has_problems'], NULL, $comment );
+                       showNotice("$setcomment SNMP Settings: $newsnmpstr");
+
+               }
+
+       }
+
+       if(isset($_POST['snmpconfig']) && $_POST['snmpconfig'] == '1') {
+               snmpgeneric_list($object_id);
        } else {
                snmpgeneric_snmpconfig($object_id);
        }
@@ -741,15 +868,15 @@ function snmpgeneric_tabhandler($object_id) {
 
 /* -------------------------------------------------- */
 
-//function snmpgeneric_tabtrigger() {
-//     return 'std';
-//} /* snmpgeneric_tabtrigger */
+function snmpgeneric_tabtrigger() {
+       // display tab only on IPv4 Objects
+       return considerConfiguredConstraint (spotEntity ('object', getBypassValue()), 'IPV4OBJ_LISTSRC') ? 'std' : '';
+} /* snmpgeneric_tabtrigger */
 
 /* -------------------------------------------------- */
 
 function snmpgeneric_snmpconfig($object_id) {
 
-       echo '<body onload="document.getElementById(\'submitbutton\').focus();">';
 
        $object = spotEntity ('object', $object_id);
        //$object['attr'] = getAttrValues($object_id);
@@ -757,7 +884,7 @@ function snmpgeneric_snmpconfig($object_id) {
 
        addJS('function showsnmpv3(element) {
                                var style;
-                               if(element.value != \''.SNMPgeneric::VERSION_3.'\') {
+                               if(element.value != \'v3\') {
                                        style = \'none\';
                                        document.getElementById(\'snmp_community_label\').style.display=\'\';
                                } else {
@@ -771,6 +898,21 @@ function snmpgeneric_snmpconfig($object_id) {
                                }
                        };',TRUE);
 
+       addJS('function shownewobject(element) {
+                               var style;
+
+                               if(element.checked) {
+                                       style = \'\';
+                               } else {
+                                       style = \'none\';
+                               }
+
+                               var elements = document.getElementsByName(\'newobject\');
+                               for(var i=0;i<elements.length;i++) {
+                                       elements[i].style.display=style;
+                               }
+                       };',TRUE);
+
        addJS('function checkInput() {
                                var host = document.getElementById(\'host\');
 
@@ -788,6 +930,8 @@ function snmpgeneric_snmpconfig($object_id) {
                                        return false;
                        };',TRUE);
 
+       echo '<body onload="document.getElementById(\'submitbutton\').focus(); showsnmpv3(document.getElementById(\'snmpversion\')); shownewobject(document.getElementById(\'asnewobject\'));">';
+
        foreach( $endpoints as $key => $value) {
                $endpoints[$value] = $value;
                unset($endpoints[$key]);
@@ -816,7 +960,56 @@ function snmpgeneric_snmpconfig($object_id) {
        /* ask for ip/host name on submit see js checkInput() */
        $endpoints['-1'] = 'ask me';
 
-       $snmpconfig = $_POST;
+       // saved snmp settings
+       $snmpstr = strtok($object['comment'],"\n\r");
+       $snmpstrarray = explode(':', $snmpstr);
+
+       if($snmpstrarray[0] == "SNMP")
+       {
+               /* keep it compatible with older version */
+               switch($snmpstrarray[2])
+               {
+                       case "1":
+                               $snmpstrarray[2] = 'v1';
+                               break;
+                       case "2":
+                       case "v2C":
+                               $snmpstrarray[2] = 'v2c';
+                               break;
+                       case "3":
+                               $snmpstrarray[2] = 'v3';
+                               break;
+               }
+
+               $snmpnames = array('SNMP','host', 'version', 'community');
+               if($snmpstrarray[2] == "v3")
+                       $snmpnames = array_merge($snmpnames, array('sec_level','auth_protocol','auth_passphrase','priv_protocol','priv_passphrase'));
+
+               $snmpvalues = array();
+               foreach($snmpnames as $key => $value)
+               {
+                       if(isset($snmpstrarray[$key]))
+                       {
+                               switch($key)
+                               {
+                                       case 6:
+                                       case 8:
+                                               $snmpvalues[$value] = base64_decode($snmpstrarray[$key]);
+                                               break;
+
+                                       default: $snmpvalues[$value] = $snmpstrarray[$key];
+                               }
+                       }
+               }
+
+               unset($snmpvalues['SNMP']);
+
+               $snmpconfig = $snmpvalues;
+       }
+       else
+               $snmpconfig = array();
+
+       $snmpconfig += $_POST;
 
        if(!isset($snmpconfig['host'])) {
                $snmpconfig['host'] = -1;
@@ -833,7 +1026,7 @@ function snmpgeneric_snmpconfig($object_id) {
 
 //     sg_var_dump_html($endpoints);
 
-       if(!isset($snmpconfig['snmpversion']))
+       if(!isset($snmpconfig['version']))
                $snmpconfig['version'] = mySNMP::SNMP_VERSION;
 
        if(!isset($snmpconfig['community']))
@@ -857,12 +1050,38 @@ function snmpgeneric_snmpconfig($object_id) {
        if(!isset($snmpconfig['priv_passphrase']))
                $snmpconfig['priv_passphrase'] = NULL;
 
+       if(!isset($snmpconfig['asnewobject']))
+               $snmpconfig['asnewobject'] = NULL;
+
+       if(!isset($snmpconfig['object_type_id']))
+               $snmpconfig['object_type_id'] = '8';
+
+       if(!isset($snmpconfig['object_name']))
+               $snmpconfig['object_name'] = NULL;
+
+       if(!isset($snmpconfig['object_label']))
+               $snmpconfig['object_label'] = NULL;
+
+       if(!isset($snmpconfig['object_asset_no']))
+               $snmpconfig['object_asset_no'] = NULL;
+
+       if(!isset($snmpconfig['save']))
+               $snmpconfig['save'] = true;
+
+//     sg_var_dump_html($snmpconfig);
+
+//     $snmpv3displaystyle = ($snmpconfig['version'] == "3" ? "style=\"\"" : "style=\"display:none;\"");
+
        echo '<h1 align=center>SNMP Config</h1>';
        echo '<form method=post name="snmpconfig" onsubmit="return checkInput()" action='.$_SERVER['REQUEST_URI'].' />';
 
         echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>
        <tr><th class=tdright>Host:</th><td>';
 
+       //if($snmpconfig['asnewobject'] == '1' )
+       if($snmpconfig['host'] != '-1' and !isset($endpoints[$snmpconfig['host']]))
+               $endpoints[$snmpconfig['host']] = $snmpconfig['host'];
+
        echo getSelect ($endpoints, array ('id' => 'host','name' => 'host'), $snmpconfig['host'], FALSE);
 
        echo'</td></tr>
@@ -870,7 +1089,7 @@ function snmpgeneric_snmpconfig($object_id) {
                 <th class=tdright><label for=snmpversion>Version:</label></th>
                 <td class=tdleft>';
 
-       echo getSelect (array(SNMPgeneric::VERSION_1 => 'v1', SNMPgeneric::VERSION_2C => 'v2c', SNMPgeneric::VERSION_3 => 'v3'),
+       echo getSelect (array("v1" => 'v1', "v2c" => 'v2c', "v3" => 'v3'),
                         array ('name' => 'version', 'id' => 'snmpversion', 'onchange' => 'showsnmpv3(this)'),
                         $snmpconfig['version'], FALSE);
 
@@ -878,7 +1097,7 @@ function snmpgeneric_snmpconfig($object_id) {
         </tr>
         <tr>
                 <th id="snmp_community_label" class=tdright><label for=community>Community:</label></th>
-                <th name="snmpv3" style="display:none" class=tdright><label for=community>Security Name:</label></th>
+                <th name="snmpv3" style="display:none;" class=tdright><label for=community>Security Name:</label></th>
                 <td class=tdleft><input type=text name=community value='.$snmpconfig['community'].' ></td>
         </tr>
         <tr name="snmpv3" style="display:none;">
@@ -916,6 +1135,39 @@ function snmpgeneric_snmpconfig($object_id) {
                 <td class=tdleft><input type=password name=priv_passphrase value="'.$snmpconfig['priv_passphrase'].'"></td>
         </tr>
        </tr>
+
+       <tr>
+               <th></th>
+               <td class=tdleft>
+               <input name=asnewobject id=asnewobject type=checkbox value=1 onchange="shownewobject(this)"'.($snmpconfig['asnewobject'] == '1' ? ' checked="checked"' : '').'>
+               <label>Create as new object</label></td>
+       </tr>';
+
+//     $newobjectdisplaystyle = ($snmpconfig['asnewobject'] == '1' ? "" : "style=\"display:none;\"");
+
+       echo '<tr name="newobject" style="display:none;">
+       <th class=tdright>Type:</th><td class=tdleft>';
+
+       $typelist = withoutLocationTypes (readChapter (CHAP_OBJTYPE, 'o'));
+        $typelist = cookOptgroups ($typelist);
+
+       printNiftySelect ($typelist, array ('name' => "object_type_id"), $snmpconfig['object_type_id']);
+
+        echo '</td></tr>
+
+       <tr name="newobject" style="display:none;">
+       <th class=tdright>Common name:</th><td class=tdleft><input type=text name=object_name value='.$snmpconfig['object_name'].'></td></tr>
+       <tr name="newobject" style="display:none;">
+       <th class=tdright>Visible label:</th><td class=tdleft><input type=text name=object_label value='.$snmpconfig['object_label'].'></td></tr>
+       <tr name="newobject" style="display:none;">
+       <th class=tdright>Asset tag:</th><td class=tdleft><input type=text name=object_asset_no value='.$snmpconfig['object_asset_no'].'></td></tr>
+
+       <tr>
+               <th></th>
+               <td class=tdleft>
+               <input name=save id=save type=checkbox value=1'.($snmpconfig['save'] == '1' ? ' checked="checked"' : '').'>
+               <label>Save SNMP settings for object</label></td>
+       </tr>
        <td colspan=2>
 
         <input type=hidden name=snmpconfig value=1>
@@ -936,6 +1188,8 @@ function snmpgeneric_list($object_id) {
                return;
        }
 
+//     sg_var_dump_html($snmpconfig);
+
        echo '<body onload="document.getElementById(\'createbutton\').focus();">';
 
        addJS('function setchecked(classname) { var boxes = document.getElementsByClassName(classname);
@@ -952,7 +1206,7 @@ function snmpgeneric_list($object_id) {
 
        $snmpdev = new mySNMP($snmpconfig['version'], $snmpconfig['host'], $snmpconfig['community']);
 
-       if($snmpconfig['version'] == SNMPgeneric::VERSION_3 ) {
+       if($snmpconfig['version'] == "v3" ) {
                $snmpdev->setSecurity( $snmpconfig['sec_level'],
                                        $snmpconfig['auth_protocol'],
                                        $snmpconfig['auth_passphrase'],
@@ -970,7 +1224,7 @@ function snmpgeneric_list($object_id) {
 
        /* SNMP connect successfull */
 
-       showSuccess("SNMP v".$snmpconfig['version']." connect to ${snmpconfig['host']} successfull");
+       showSuccess("SNMP ".$snmpconfig['version']." connect to ${snmpconfig['host']} successfull");
 
        echo '<form name=CreatePorts method=post action='.$_SERVER['REQUEST_URI'].'&module=redirect&op=create>';
 
@@ -1076,13 +1330,16 @@ function snmpgeneric_list($object_id) {
 
        /* needs PHP >= 5 foreach call by reference */
        /* php 5.1.6 doesn't seem to work */
-       //foreach($sysObjectID['attr'] as $attr_id => &$attr) {
+       //foreach($sysObjectID['attr'] as $attr_id => &$attr)
        foreach($sysObjectID['attr'] as $attr_id => $value) {
 
                $attr = &$sysObjectID['attr'][$attr_id];
 
                if(isset($object['attr'][$attr_id])) {
 
+                       if(array_key_exists('key',$object['attr'][$attr_id]))
+                               $attr['key'] = $object['attr'][$attr_id]['key'];
+
                        switch(TRUE) {
 
                                case isset($attr['pf']):
@@ -1148,11 +1405,19 @@ function snmpgeneric_list($object_id) {
 
        foreach($sysObjectID['attr'] as $attr_id => &$attr) {
 
+               $attr['id'] = $attr_id;
+
                if(isset($object['attr'][$attr_id]) && isset($attr['value'])) {
 
                        if($attr['value'] == $object['attr'][$attr_id]['value'])
                                $attr['uncheck'] = 'Current = new value';
 
+                       if(isset($attr['key']) && isset($object['attr'][$attr_id]['key']))
+                       {
+                               if($attr['key'] == $object['attr'][$attr_id]['key'])
+                                       $attr['uncheck'] = 'Current = new key';
+                       }
+
                        $value = $attr['value'];
 
                        $val_key = (isset($object['attr'][$attr_id]['key']) ? ' ('.$object['attr'][$attr_id]['key'].')' : '' );
@@ -1186,14 +1451,19 @@ function snmpgeneric_list($object_id) {
 
        echo '</table>';
 
+       $object['breed'] = sg_detectDeviceBreedByObject($sysObjectID);
+
+       if(!empty($object['breed']))
+               echo "Found Breed: ".$object['breed']."<br>";
+
        /* ports */
 
        /* get ports */
        amplifyCell($object);
 
-       /* set array key to port name */
+       /* set array key to lowercase port name */
        foreach($object['ports'] as $key => $values) {
-               $object['ports'][$values['name']] = $values;
+               $object['ports'][strtolower(shortenIfName($values['name'], $object['breed']))] = $values;
                unset($object['ports'][$key]);
        }
 
@@ -1208,7 +1478,7 @@ function snmpgeneric_list($object_id) {
 
                foreach($sysObjectID['port'] as $name => $port) {
 
-                       if(array_key_exists($name,$object['ports']))
+                       if(array_key_exists(strtolower($name),$object['ports']))
                                $disableport = TRUE;
                        else
                                $disableport = FALSE;
@@ -1269,6 +1539,9 @@ function snmpgeneric_list($object_id) {
 
        $ifsnmp = new ifSNMP($snmpdev);
 
+       // needed for shortenIfName()
+       $ifsnmp->object_breed = $object['breed'];
+
        /* ip spaces */
 
        $ipspace = NULL;
@@ -1295,9 +1568,12 @@ function snmpgeneric_list($object_id) {
 
                                case 'ipv6':
 
-                                       /* format ipaddr for ip6_parse */
-                                       $ipaddr =  preg_replace('/((..):(..))/','\\2\\3',$ipaddr);
-                                       $ipaddr =  preg_replace('/%.*$/','',$ipaddr);
+                                       if(ip_checkparse($ipaddr) === false)
+                                       {
+                                               /* format ipaddr for ip6_parse */
+                                               $ipaddr =  preg_replace('/((..):(..))/','\\2\\3',$ipaddr);
+                                               $ipaddr =  preg_replace('/%.*$/','',$ipaddr);
+                                       }
 
                                        if(ip_checkparse($ipaddr) === false)
                                                continue(2); // 2 because of switch
@@ -1325,7 +1601,7 @@ function snmpgeneric_list($object_id) {
                        if(empty($netid) && $netaddr != '::1' && $netaddr != '127.0.0.1' && $netaddr != '127.0.0.0' && $netaddr != '0.0.0.0' && !$linklocal) {
 
                                $netaddr .= "/$maskbits";
-                               $ipspace[$netaddr] = $addrtype;
+                               $ipspace[$netaddr] = array('addrtype' => $addrtype, 'checked' => ($maskbits > 0 ? true : false));
                        }
                }
                unset($ipaddr);
@@ -1342,19 +1618,19 @@ function snmpgeneric_list($object_id) {
                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>';
 
                $i = 1;
-               foreach($ipspace as $prefix => $addrtype) {
+               foreach($ipspace as $prefix => $ipspace) {
 
                        $netcreatecheckbox = '<b style="background-color:#00ff00">'
                                .'<input class="ipspace" style="background-color:#00ff00" type="checkbox" name="netcreate['
-                               .$i.']" value="'.$addrtype.'" checked=\"checked\"></b>';
+                               .$i.']" value="'.$ipspace['addrtype'].'"'.($ipspace['checked'] ? ' checked=\"checked\"' : '').'></b>';
 
                        $netprefixfield = '<input type="text" size=50 name="netprefix['.$i.']" value="'.$prefix.'">';
 
                        $netnamefield = '<input type="text" name="netname['.$i.']">';
 
-                       $netreservecheckbox = '<input type="checkbox" name="netreserve['.$i.']">';
+                       $netreservecheckbox = '<input type="checkbox" name="netreserve['.$i.']" checked="checked">';
 
-                       echo "<tr><td>$netcreatecheckbox</td><td style=\"color:#888888\">$addrtype</td><td>$netprefixfield</td><td>$netnamefield</td><td>$netreservecheckbox</td></tr>";
+                       echo "<tr><td>$netcreatecheckbox</td><td style=\"color:#888888\">${ipspace['addrtype']}</td><td>$netprefixfield</td><td>$netnamefield</td><td>$netreservecheckbox</td></tr>";
 
                        $i++;
                }
@@ -1366,19 +1642,21 @@ function snmpgeneric_list($object_id) {
        }
 
 
-       echo "<br><br>ifNumber: ".$ifsnmp->ifNumber."<br><table><tbody valign=\"top\">";
+       echo "<br><br>ifNumber: ".$ifsnmp->ifNumber."<br>indexcount: ".$ifsnmp->indexcount."<br><table><tbody valign=\"top\">";
 
        $portcompat = getPortInterfaceCompat();
 
        $ipnets = array();
 
-       $ifsnmp->printifInfoTableHeader("<th>add ip</th><th>add port</th><th title=\"update mac\">upd mac</th><th>porttypeid</th><th>comment</th></tr>");
+       $ifsnmp->printifInfoTableHeader("<th>add ip</th><th>add port</th><th>upd label</th><th title=\"update mac\">upd mac</th><td>upd port type</th><th>porttypeid</th><th>comment</th></tr>");
 
        echo '<tr><td colspan="11"></td>
-               <td><input type="checkbox" id="ipaddr" onclick="setchecked(this.id)">IPv4<br>
-               <input type="checkbox" id="ipv6addr" onclick="setchecked(this.id)">IPv6</td>
+               <td><input type="checkbox" id="ipaddr" onclick="setchecked(this.id);" checked="checked">IPv4<br>
+               <input type="checkbox" id="ipv6addr" onclick="setchecked(this.id);" checked="checked">IPv6</td>
                <td><input type="checkbox" id="ports" onclick="setchecked(this.id)"></td>
-               <td><input type="checkbox" id="mac" onclick="setchecked(this.id)" checked="checked"></td></tr>';
+               <td><input type="checkbox" id="label" onclick="setchecked(this.id);" checked="checked"></td>
+               <td><input type="checkbox" id="mac" onclick="setchecked(this.id);" checked="checked"></td>
+               <td><input type="checkbox" id="porttype" onclick="setchecked(this.id);"></td></tr>';
 
        foreach($ifsnmp as $if) {
 
@@ -1386,6 +1664,8 @@ function snmpgeneric_list($object_id) {
                $disableport = FALSE;
                $ignoreport = FALSE;
                $port_info = NULL;
+               $updatelabel = false;
+               $updateporttype = false;
 
                $updatemaccheckbox = '';
 
@@ -1401,6 +1681,11 @@ function snmpgeneric_list($object_id) {
                        if(array_key_exists($ifsnmp->ifName($if),$object['ports'])){
                                $port_info = &$object['ports'][$ifsnmp->ifName($if)];
                                $comment .= "Name exists";
+
+                               /* ifalias change */
+                               if($port_info['label'] != $ifsnmp->ifAlias($if))
+                                       $updatelabel = true;
+
                                $createport = FALSE;
                                $disableport = TRUE;
                        }
@@ -1412,9 +1697,8 @@ function snmpgeneric_list($object_id) {
 
                        $l2port =  sg_checkL2Address($ifPhysAddress);
 
-                       //if(alreadyUsedL2Address($ifPhysAddress, $object_id)) {
-
                        if(!empty($l2port)) {
+
                                $l2object_id = key($l2port);
 
                                $porthref = makeHref(array('page'=>'object', 'tab' => 'ports',
@@ -1461,6 +1745,18 @@ function snmpgeneric_list($object_id) {
                        $createport = FALSE;
                        $ignoreport = TRUE;
                }
+               else
+               {
+                       if($port_info)
+                       {
+                               $ptid = $port_info['iif_id']."-".$port_info['oif_id'];
+                               if($porttypeid != $ptid)
+                               {
+                                       $comment .= ", Update Type $ptid -> $porttypeid";
+                                       $updateporttype = true;
+                               }
+                       }
+               }
 
                /* ignore ports without an Connector */
                if(!$sg_create_noconnector_ports && ($ifsnmp->ifConnectorPresent($if) == 2)) {
@@ -1502,9 +1798,12 @@ function snmpgeneric_list($object_id) {
                                        case 'ipv6':
                                                $inputname = 'ipv6';
 
-                                               /* format ipaddr for ip6_parse */
-                                               $ipaddr =  preg_replace('/((..):(..))/','\\2\\3',$ipaddr);
-                                               $ipaddr =  preg_replace('/%.*$/','',$ipaddr);
+                                               if(ip_checkparse($ipaddr) === false)
+                                               {
+                                                       /* format ipaddr for ip6_parse */
+                                                       $ipaddr =  preg_replace('/((..):(..))/','\\2\\3',$ipaddr);
+                                                       $ipaddr =  preg_replace('/%.*$/','',$ipaddr);
+                                               }
 
                                                if(ip_checkparse($ipaddr) === false)
                                                        continue(2); // 2 because of switch
@@ -1610,14 +1909,28 @@ function snmpgeneric_list($object_id) {
 
                $selectoptions = array('name' => "porttypeid[$if]");
 
-               if($disableport)
+               if($disableport && !$updateporttype)
                        $selectoptions['disabled'] = "disabled";
 
+               $updateporttypecheckbox = "";
+
+               if($updateporttype)
+                       $updateporttypecheckbox = '<b style="background-color:#00ff00;">'
+                                       .'<input class="porttype" style="background-color:#00ff00;" type="checkbox" name="updateporttype['.$if.']" value="'
+                                       .$port_info['id'].'"></b>';
+
                $porttypeidselect = getNiftySelect($newporttypeoptions, $selectoptions, $porttypeid);
 
+               $updatelabelcheckbox = "";
+
+               if($updatelabel)
+                       $updatelabelcheckbox = '<b style="background-color:#00ff00;">'
+                                       .'<input class="label" style="background-color:#00ff00;" type="checkbox" name="updatelabel['.$if.']" value="'
+                                       .$port_info['id'].($updatelabel ? '" checked="checked"' : '' ).'></b>';
+
                $comment = trim($comment,', ');
 
-               $ifsnmp->printifInfoTableRow($if,"<td>$ipaddrcell</td><td>$portcreatecheckbox</td><td>$updatemaccheckbox</td><td>$porttypeidselect</td><td nowrap=\"nowrap\">$comment</td>", $hrefs);
+               $ifsnmp->printifInfoTableRow($if,"<td>$ipaddrcell</td><td>$portcreatecheckbox</td><td>$updatelabelcheckbox</td><td>$updatemaccheckbox</td><td>$updateporttypecheckbox</td><td>$porttypeidselect</td><td nowrap=\"nowrap\">$comment</td>", $hrefs);
 
        }
        unset($if);
@@ -1631,7 +1944,7 @@ function snmpgeneric_list($object_id) {
 
        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>';
 
-}
+} // END function  snmpgeneric_list
 
 /* -------------------------------------------------- */
 function snmpgeneric_opcreate() {
@@ -1665,7 +1978,8 @@ function snmpgeneric_opcreate() {
                        $ifAlias = (isset($_POST['ifAlias'][$if]) ? trim($_POST['ifAlias'][$if]) : '' );
                        $ifDescr = (isset($_POST['ifDescr'][$if]) ? trim($_POST['ifDescr'][$if]) : '' );
 
-                       $visible_label = (empty($ifAlias) ? '' : $ifAlias.'; ').$ifDescr;
+                       //$visible_label = (empty($ifAlias) ? '' : $ifAlias.'; ').$ifDescr;
+                       $visible_label = $ifAlias;
 
                        if(empty($ifName)) {
                                showError('Port without ifName '.$_POST['porttypeid'][$if].', '.$visible_label.', '.$ifPhysAddress);
@@ -1721,6 +2035,22 @@ function snmpgeneric_opcreate() {
        }
        /* ipaddrecreate */
 
+       /* update label */
+       if(isset($_POST['updatelabel'])) {
+               foreach($_POST['updatelabel'] as $if => $port_id) {
+
+                       $ifAlias = (isset($_POST['ifAlias'][$if]) ? trim($_POST['ifAlias'][$if]) : '' );
+
+                       sg_commitUpdatePortLabel($object_id, $port_id, $ifAlias);
+
+                       $ifName = (isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : '' );
+                       showSuccess("label updated on $ifName to $ifAlias");
+               }
+               unset($if);
+               unset($port_id);
+       }
+       /* updatemac */
+
        /* update mac addresses only */
        if(isset($_POST['updatemac'])) {
                foreach($_POST['updatemac'] as $if => $port_id) {
@@ -1737,6 +2067,21 @@ function snmpgeneric_opcreate() {
        }
        /* updatemac */
 
+       /* update port type */
+       if(isset($_POST['updateporttype'])) {
+               foreach($_POST['updateporttype'] as $if => $port_id) {
+
+                       $porttypeid = (isset($_POST['porttypeid'][$if]) ? trim($_POST['porttypeid'][$if]) : '' );
+
+                       sg_commitUpdatePortType($object_id, $port_id, $porttypeid);
+
+                       $ifName = (isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : '' );
+                       showSuccess("port type updated on $ifName");
+               }
+               unset($if);
+               unset($port_id);
+       }
+       /* updateporttype */
 } /* snmpgeneric_opcreate */
 
 /* -------------------------------------------------- */
@@ -1764,6 +2109,22 @@ function guessRToif_id($ifType,$ifDescr = NULL) {
 
        /* try to identify outer and inner interface type from ifDescr */
 
+       switch(true)
+       {
+               case preg_match('/fast.?ethernet/i',$ifDescr,$matches):
+                       // Fast Ethernet
+                       $retval = 19;
+                       break;
+               case preg_match('/10.?gigabit.?ethernet/i',$ifDescr,$matches):
+                       // 10-Gigabit Ethernet
+                       $retval = 1642;
+                       break;
+               case preg_match('/gigabit.?ethernet/i',$ifDescr,$matches):
+                       // Gigabit Ethernet
+                       $retval = 24;
+                       break;
+       }
+
        /**********************
         * ifDescr samples
         *
@@ -1888,6 +2249,52 @@ function sg_commitUpdatePortl2address($object_id, $port_id, $port_l2address)
         $dbxlink->exec ('UNLOCK TABLES');
 } /* sg_commitUpdatePortl2address */
 
+/* --------------------------------------------------- */
+
+function sg_commitUpdatePortType($object_id, $port_id, $porttypeid)
+{
+       global $dbxlink;
+
+       list($iif_id, $type) = explode("-",$porttypeid);
+
+        $dbxlink->exec ('LOCK TABLES Port WRITE');
+        usePreparedUpdateBlade
+        (
+                'Port',
+                array
+                (
+                        'iif_id' => ($iif_id === '') ? NULL : $iif_id,
+                       'type' => ($type === '') ? NULL : $type
+                ),
+                array
+                (
+                        'id' => $port_id,
+                        'object_id' => $object_id
+                )
+        );
+        $dbxlink->exec ('UNLOCK TABLES');
+} /* sg_commitUpdatePortType */
+
+function sg_commitUpdatePortLabel($object_id, $port_id, $label)
+{
+       global $dbxlink;
+
+        $dbxlink->exec ('LOCK TABLES Port WRITE');
+        usePreparedUpdateBlade
+        (
+                'Port',
+                array
+                (
+                        'label' => ($label === '') ? NULL : $label
+                ),
+                array
+                (
+                        'id' => $port_id,
+                        'object_id' => $object_id
+                )
+        );
+        $dbxlink->exec ('UNLOCK TABLES');
+} /* sg_commitUpdatePortLabel */
 /* ----------------------------------------------------- */
 
 /* returns object_id and port_id to a given l2address */
@@ -1902,16 +2309,41 @@ function sg_checkL2Address ($address)
         return $row;
 }
 
-/* returns oi_id and name */
-function getPortOIOptions()
+function sg_checkObjectNameUniqueness ($name, $type_id, $object_id = 0)
 {
-        $result = usePreparedSelectBlade
-        (
-               'SELECT dict_key,dict_value from Dictionary where chapter_id = 2',
-                array ()
-        );
-        $row = $result->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_UNIQUE|PDO::FETCH_COLUMN);
-        return $row;
+       // Some object types do not need unique names
+       // 1560 - Rack
+       // 1561 - Row
+       $dupes_allowed = array (1560, 1561);
+       if (in_array ($type_id, $dupes_allowed))
+       return;
+
+       $result = usePreparedSelectBlade
+       (
+               'SELECT COUNT(*) FROM Object WHERE name = ? AND id != ?',
+               array ($name, $object_id)
+       );
+       $row = $result->fetch (PDO::FETCH_NUM);
+       if ($row[0] != 0)
+               return false;
+       else
+               return true;
+}
+
+function sg_detectDeviceBreedByObject($object)
+{
+       global $breed_by_swcode, $breed_by_hwcode, $breed_by_mgmtcode;
+
+       foreach ($object['attr'] as $record)
+       {
+               if ($record['id'] == 4 and array_key_exists ($record['key'], $breed_by_swcode))
+                       return $breed_by_swcode[$record['key']];
+               elseif ($record['id'] == 2 and array_key_exists ($record['key'], $breed_by_hwcode))
+                       return $breed_by_hwcode[$record['key']];
+               elseif ($record['id'] == 30 and array_key_exists ($record['key'], $breed_by_mgmtcode))
+                       return $breed_by_mgmtcode[$record['key']];
+       }
+       return '';
 }
 
 /* ------------------------------------------------------- */
@@ -1932,8 +2364,9 @@ class SNMPgeneric {
 //     protected $contextName;
 //     protected $contextEngineID;
 
-       const VERSION_1 = 1;
-       const VERSION_2C = 2;
+       const VERSION_1 = 0;
+       const VERSION_2C = 1;
+       const VERSION_2c = 1;
        const VERSION_3 = 3;
 
        protected $result;
@@ -1941,6 +2374,7 @@ class SNMPgeneric {
        function __construct($version, $host, $community) {
 
                $this->host = $host;
+
                $this->version = $version;
                $this->community = $community;
 
@@ -1953,6 +2387,36 @@ class SNMPgeneric {
                $this->auth_passphrase = $auth_passphrase;
                $this->priv_protocol = $priv_protocol;
                $this->priv_passphrase = $priv_passphrase;
+
+               return true;
+       }
+
+       function __set($name, $value)
+       {
+               switch($name)
+               {
+                       case 'quick_print':
+                               snmp_set_quick_print($value);
+                               break;
+                       case 'oid_output_format':
+                               /* needs php >= 5.2.0 */
+                               snmp_set_oid_output_format($value);
+                               break;
+                       case 'enum_print':
+                               snmp_set_enum_print($value);
+                               break;
+                       case 'valueretrieval':
+                               snmp_set_valueretrieval($value);
+                               break;
+                       default:
+                               $trace = debug_backtrace();
+                               trigger_error(
+                                       'Undefined property via __set(): ' . $name .
+                                       ' in ' . $trace[0]['file'] .
+                                       ' on line ' . $trace[0]['line'],
+                                       E_USER_NOTICE);
+                               return null;
+               }
        }
 
        function walk( $oid, $suffix_as_key = FALSE) {
@@ -1967,6 +2431,7 @@ class SNMPgeneric {
                                break;
 
                        case self::VERSION_2C:
+                       case self::VERSION_2c:
                                if($suffix_as_key){
                                        $this->result = snmp2_walk($this->host,$this->community,$oid);
                                } else {
@@ -1997,6 +2462,7 @@ class SNMPgeneric {
                                break;
 
                        case self::VERSION_2C:
+                       case self::VERSION_2c:
                                $retval = snmp2_get($this->host,$this->community,$object_id);
                                break;
 
@@ -2063,7 +2529,7 @@ class SNMPgeneric {
  */
 class mySNMP extends SNMPgeneric implements Iterator {
 
-       const SNMP_VERSION = SNMPgeneric::VERSION_2C;
+       const SNMP_VERSION = parent::VERSION_2C;
        const SNMP_COMMUNITY = 'public';
 
        public $lastgetoid;
@@ -2075,21 +2541,34 @@ class mySNMP extends SNMPgeneric implements Iterator {
        private $systemerror = TRUE;
 
        function __construct($version, $host, $community) {
-               parent::__construct($version, $host, $community);
 
-               //snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
-
-               /* Return values without SNMP type hint */
-               snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
+               switch($version)
+               {
+                       case '1':
+                       case 'v1':
+                               $version = parent::VERSION_1;
+                               break;
+                       case '2':
+                       case 'v2C':
+                       case 'v2c':
+                               $version = parent::VERSION_2c;
+                               break;
+                       case '3':
+                       case 'v3':
+                               $version = parent::VERSION_3;
+                               break;
+               };
 
-               /* needs php >= 5.2.0 */
-       //      snmp_set_oid_output_format(SNMP_OID_OUTPUT_FULL);
+               parent::__construct($version, $host, $community);
 
-       //      snmp_set_quick_print(1);
+               /* Return values without SNMP type hint */
+               $this->valueretrieval = SNMP_VALUE_PLAIN;
 
        } /* __construct */
 
        function init() {
+
+               $this->oid_output_format = SNMP_OID_OUTPUT_FULL;
                /* .iso.org.dod.internet.mgmt.mib-2.system */
                $this->system = $this->walk(".1.3.6.1.2.1.1");
 
@@ -2184,7 +2663,7 @@ class mySNMP extends SNMPgeneric implements Iterator {
 
                        $trace = debug_backtrace();
                        trigger_error(
-                                       'Undefinierte Eigenschaft für __call(): ' . $name .
+                                       'Undefinierte Eigenschaft fuer __call(): ' . $name .
                                        ' in ' . $trace[0]['file'] .
                                        ' Zeile ' . $trace[0]['line'],
                                        E_USER_NOTICE);
@@ -2235,10 +2714,13 @@ class mySNMP extends SNMPgeneric implements Iterator {
 class ifSNMP implements Iterator {
        private $snmpdevice;
        private $ifNumber = 0;
+       private $indexcount = 0;
        private $ifTable;
 
        private $interfaceserror = TRUE;
 
+       public $object_breed = NULL;
+
        function __construct(&$snmpdevice) {
                $this->snmpdevice = $snmpdevice;
 
@@ -2253,6 +2735,9 @@ class ifSNMP implements Iterator {
 
        function getifTable() {
                $this->ifTable['ifIndex'] = $this->snmpdevice->walk('ifIndex',TRUE);
+
+               $this->indexcount = count($this->ifTable['ifIndex']);
+
                $this->ifTable['ifDescr'] = $this->snmpdevice->walk('ifDescr',TRUE);
                $this->ifTable['ifAlias'] = $this->snmpdevice->walk('ifAlias',TRUE);
                $this->ifTable['ifName'] =  $this->snmpdevice->walk('ifName',TRUE);
@@ -2370,6 +2855,59 @@ class ifSNMP implements Iterator {
        //              sg_var_dump_html($ipAddressPrefix);
                } /* ipaddressifindex */
 
+               /* ipv6 MIB  */
+               /* overwrites ipv6 from ipaddresstable */
+               $ipv6interfaces = $this->snmpdevice->get('ipv6Interfaces.0');
+
+               if($ipv6interfaces)
+               {
+                       echo"Found $ipv6interfaces ipv6 interfaces<br>";
+
+                       $ipv6addraddress =  $this->snmpdevice->walk('ipv6AddrAddress');
+
+                       if(!empty($ipv6addraddress)) {
+                               $ipv6addrpfxlength =  $this->snmpdevice->walk('ipv6AddrPfxLength');
+                       //      $ipv6addrtype =  $this->snmpdevice->walk('ipv6AddrType'); /* 1 stateless, 2 stateful, 3 unknown */
+
+                               reset($ipv6addrpfxlength);
+                               //reset($ipv6addrtype);
+
+                               foreach($ipv6addraddress as $oid => $addr_bin) {
+
+                                       $addr = ip_format($addr_bin);
+
+                                       //$type = current($ipv6addrtype);
+                                       //next($ipv6addrtype);
+
+                                       if(!preg_match('/.*(ipv6).*\.([0-9]+)\..*$/',$oid, $matches))
+                                               continue;
+
+                                       $ifindex =  array_search($matches[2],$this->ifTable['ifIndex']);
+
+                                       if($ifindex === false)
+                                               continue;
+
+                                       $maskbits = current($ipv6addrpfxlength);
+                                       next($ipv6addrpfxlength);
+
+                                       $range = constructIPRange($addr_bin, $maskbits);
+
+                                       $net = ip_format($range['ip_bin']);
+                                       $bcast = NULL;
+
+                                       $this->ifTable['ipaddress'][$ifindex][$addr] = array(
+                                                                               'addrtype' => $matches[1],
+                                                                               'maskbits' => $maskbits,
+                                                                               'net' => $net,
+                                                                               'bcast' => $bcast,
+                                                                       //      'type' => ($type == 1 ? "stateless" : $type == 2 ? "statefull" : "unknown" )
+                                                                               );
+                               }
+                               unset($oid);
+                               unset($value);
+
+                       } /* ipv6addraddress */
+               } /* ipv6interfaces */
        }
 
        function printifInfoTableHeader($suffix = "") {
@@ -2439,7 +2977,7 @@ class ifSNMP implements Iterator {
                                        if($key == 'ifName') {
                                                /* create textfield set to ifDescr */
                                                $formfield = '<input type="text" size="8" name="'.$key.'['.$ifIndex.']" value="'
-                                                               .$this->ifDescr($ifIndex).'">';
+                                                               .strtolower(shortenIfName($this->ifDescr($ifIndex), $this->object_breed)).'">';
                                                $textfield = TRUE;
                                        }
 
@@ -2498,10 +3036,17 @@ class ifSNMP implements Iterator {
 
        }
 
+       function ifName($index) {
+               if(isset($this->ifTable['ifName'][$index-1])) {
+                       return strtolower(shortenIfName($this->ifTable['ifName'][$index-1], $this->object_breed));
+               }
+
+       }
        function &__get($name) {
 
                switch($name) {
                        case 'ifNumber':
+                       case 'indexcount':
                                return $this->{$name};
                                break;
                        case 'ipaddress':
@@ -2512,7 +3057,7 @@ class ifSNMP implements Iterator {
                $trace = debug_backtrace();
 
                trigger_error(
-                       'Undefinierte Eigenschaft für __get(): ' . $name .
+                       'Undefinierte Eigenschaft fuer __get(): ' . $name .
                        ' in ' . $trace[0]['file'] .
                        ' Zeile ' . $trace[0]['line'],
                        E_USER_NOTICE);
@@ -2536,7 +3081,7 @@ class ifSNMP implements Iterator {
                        $trace = debug_backtrace();
 
                        trigger_error(
-                               'Undefinierte Methode für __call(): ' . $name .
+                               'Undefinierte Methode für __call(): ' . $name .
                                ' in ' . $trace[0]['file'] .
                                ' Zeile ' . $trace[0]['line'],
                                E_USER_NOTICE);
@@ -2562,7 +3107,7 @@ class ifSNMP implements Iterator {
        }
 
        function valid() {
-               return ($this->IteratorIndex<=$this->ifNumber);
+               return ($this->IteratorIndex<=$this->indexcount);
        }
 
        function rewind() {
@@ -2581,4 +3126,3 @@ function sg_var_dump_html(&$var, $text = '') {
        var_dump($var);
        echo "\n---------------------END Var Dump - $text -----------------------</pre>";
 }
-?>