function snmpgeneric_list($object_id)
{
    global $sg_create_noconnector_ports, $sg_known_sysObjectIDs, $sg_portoifoptions, $sg_ifType_ignore;
    if (isset($_POST['snmpconfig'])) {
        $snmpconfig = $_POST;
    } else {
        showError("Missing SNMP Config");
        return;
    }
    //	sg_var_dump_html($snmpconfig);
    echo '<body onload="document.getElementById(\'createbutton\').focus();">';
    addJS('function setchecked(classname) { var boxes = document.getElementsByClassName(classname);
				 var value = document.getElementById(classname).checked;
				 for(i=0;i<boxes.length;i++) {
					if(boxes[i].disabled == false)
						boxes[i].checked=value;
				 }
		};', TRUE);
    $object = spotEntity('object', $object_id);
    $object['attr'] = getAttrValues($object_id);
    $snmpdev = new mySNMP($snmpconfig['version'], $snmpconfig['host'], $snmpconfig['community']);
    if ($snmpconfig['version'] == "v3") {
        $snmpdev->setSecurity($snmpconfig['sec_level'], $snmpconfig['auth_protocol'], $snmpconfig['auth_passphrase'], $snmpconfig['priv_protocol'], $snmpconfig['priv_passphrase']);
    }
    $snmpdev->init();
    if ($snmpdev->getErrno()) {
        showError($snmpdev->getError());
        return;
    }
    /* SNMP connect successfull */
    showSuccess("SNMP " . $snmpconfig['version'] . " connect to {$snmpconfig['host']} successfull");
    echo '<form name=CreatePorts method=post action=' . $_SERVER['REQUEST_URI'] . '&module=redirect&op=create>';
    echo "<strong>System Informations</strong>";
    echo "<table>";
    //	echo "<tr><th>OID</th><th>Value</th></tr>";
    $systemoids = array('sysDescr', 'sysObjectID', 'sysUpTime', 'sysContact', 'sysName', 'sysLocation');
    foreach ($systemoids as $shortoid) {
        $value = $snmpdev->{$shortoid};
        if ($shortoid == 'sysUpTime') {
            /* in hundredths of a second */
            $secs = (int) ($value / 100);
            $days = (int) ($secs / (60 * 60 * 24));
            $secs -= $days * 60 * 60 * 24;
            $hours = (int) ($secs / (60 * 60));
            $secs -= $hours * 60 * 60;
            $mins = (int) ($secs / 60);
            $secs -= $mins * 60;
            $value = "{$value} ({$days} {$hours}:{$mins}:{$secs})";
        }
        echo "<tr><td title=\"" . $snmpdev->lastgetoid . "\" align=\"right\">{$shortoid}: </td><td>{$value}</td></tr>";
    }
    unset($shortoid);
    echo "</table>";
    /* sysObjectID Attributes and Ports */
    $sysObjectID['object'] =& $object;
    /* get sysObjectID */
    $sysObjectID['raw_value'] = $snmpdev->sysObjectID;
    //$sysObjectID['raw_value'] = 'NET-SNMP-MIB::netSnmpAgentOIDs.10';
    $sysObjectID['value'] = preg_replace('/^.*enterprises\\.([\\.[:digit:]]+)$/', '\\1', $sysObjectID['raw_value']);
    /* try snmptranslate to numeric */
    if (preg_match('/[^\\.0-9]+/', $sysObjectID['value'])) {
        $numeric_value = $snmpdev->translatetonumeric($sysObjectID['value']);
        if (!empty($numeric_value)) {
            showSuccess("sysObjectID: " . $sysObjectID['value'] . " translated to {$numeric_value}");
            $sysObjectID['value'] = preg_replace('/^.1.3.6.1.4.1.([\\.[:digit:]]+)$/', '\\1', $numeric_value);
        }
    }
    /* array_merge doesn't work with numeric keys !! */
    $sysObjectID['attr'] = array();
    $sysObjectID['port'] = array();
    $sysobjid = $sysObjectID['value'];
    $count = 1;
    while ($count) {
        if (isset($sg_known_sysObjectIDs[$sysobjid])) {
            $sysObjectID = $sysObjectID + $sg_known_sysObjectIDs[$sysobjid];
            if (isset($sg_known_sysObjectIDs[$sysobjid]['attr'])) {
                $sysObjectID['attr'] = $sysObjectID['attr'] + $sg_known_sysObjectIDs[$sysobjid]['attr'];
            }
            if (isset($sg_known_sysObjectIDs[$sysobjid]['port'])) {
                $sysObjectID['port'] = $sysObjectID['port'] + $sg_known_sysObjectIDs[$sysobjid]['port'];
            }
            if (isset($sg_known_sysObjectIDs[$sysobjid]['text'])) {
                showSuccess("found sysObjectID ({$sysobjid}) " . $sg_known_sysObjectIDs[$sysobjid]['text']);
            }
        }
        $sysobjid = preg_replace('/\\.[[:digit:]]+$/', '', $sysobjid, 1, $count);
        /* add default sysobjectid */
        if ($count == 0 && $sysobjid != 'default') {
            $sysobjid = 'default';
            $count = 1;
        }
    }
    $sysObjectID['vendor_number'] = $sysobjid;
    /* device pf */
    if (isset($sysObjectID['pf'])) {
        foreach ($sysObjectID['pf'] as $function) {
            if (function_exists($function)) {
                /* call device pf */
                $function($snmpdev, $sysObjectID, NULL);
            } else {
                showWarning("Missing processor function " . $function . " for device {$sysobjid}");
            }
        }
    }
    /* sort attributes maintain numeric keys */
    ksort($sysObjectID['attr']);
    /* DEBUG */
    //sg_var_dump_html($sysObjectID['attr'], "Before processing");
    /* 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 => $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']):
                    if (function_exists($attr['pf'])) {
                        $attr['pf']($snmpdev, $sysObjectID, $attr_id);
                    } else {
                        showWarning("Missing processor function " . $attr['pf'] . " for attribute {$attr_id}");
                    }
                    break;
                case isset($attr['oid']):
                    $attrvalue = $snmpdev->get($attr['oid']);
                    if (isset($attr['regex'])) {
                        $regex = $attr['regex'];
                        if (isset($attr['replacement'])) {
                            $replacement = $attr['replacement'];
                            $attrvalue = preg_replace($regex, $replacement, $attrvalue);
                        } else {
                            if (!preg_match($regex, $attrvalue)) {
                                if (!isset($attr['uncheck'])) {
                                    $attr['uncheck'] = "regex doesn't match";
                                }
                            } else {
                                unset($attr['uncheck']);
                            }
                        }
                    }
                    $attr['value'] = $attrvalue;
                    break;
                case isset($attr['value']):
                    break;
                default:
                    showError("Error handling attribute id: {$attr_id}");
            }
        } else {
            showWarning("Object has no attribute id: {$attr_id}");
            unset($sysObjectID['attr'][$attr_id]);
        }
    }
    unset($attr_id);
    /* sort again in case there where attribs added ,maintain numeric keys */
    ksort($sysObjectID['attr']);
    /* print attributes */
    echo '<br>Attributes<br><table>';
    echo '<tr><th><input type="checkbox" id="attribute" checked="checked" onclick="setchecked(this.id)"></td>';
    echo '<th>Name</th><th>Current Value</th><th>new value</th></tr>';
    /* DEBUG */
    //sg_var_dump_html($sysObjectID['attr'], "After processing");
    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'] . ')' : '';
            $comment = '';
            if (isset($attr['comment'])) {
                if (!empty($attr['comment'])) {
                    $comment = $attr['comment'];
                }
            }
            if (isset($attr['uncheck'])) {
                $checked = '';
                $comment .= ', ' . $attr['uncheck'];
            } else {
                $checked = ' checked="checked"';
            }
            $updateattrcheckbox = '<b style="background-color:#00ff00">' . '<input style="background-color:#00ff00" class="attribute" type="checkbox" name="updateattr[' . $attr_id . ']" value="' . $value . '"' . $checked . '></b>';
            $comment = trim($comment, ', ');
            echo "<tr><td>{$updateattrcheckbox}</td><td title=\"id: {$attr_id}\">" . $object['attr'][$attr_id]['name'] . '</td><td style="background-color:#d8d8d8">' . $object['attr'][$attr_id]['value'] . $val_key . '</td><td>' . $value . '</td>' . '<td style="color:#888888">' . $comment . '</td></tr>';
        }
    }
    unset($attr_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 lowercase port name */
    foreach ($object['ports'] as $key => $values) {
        $object['ports'][strtolower(shortenIfName($values['name'], $object['breed']))] = $values;
        unset($object['ports'][$key]);
    }
    $newporttypeoptions = getNewPortTypeOptions();
    //	sg_var_dump_html($sysObjectID['port']);
    if (!empty($sysObjectID['port'])) {
        echo '<br>Vendor / Device specific ports<br>';
        echo '<table><tr><th><input type="checkbox" id="moreport" checked="checked" onclick="setchecked(this.id)"></th><th>ifName</th><th>porttypeid</th></tr>';
        foreach ($sysObjectID['port'] as $name => $port) {
            if (array_key_exists(strtolower($name), $object['ports'])) {
                $disableport = TRUE;
            } else {
                $disableport = FALSE;
            }
            $comment = '';
            if (isset($port['comment'])) {
                if (!empty($port['comment'])) {
                    $comment = $port['comment'];
                }
            }
            if (isset($port['uncheck'])) {
                $checked = '';
                $comment .= ', ' . $port['uncheck'];
            } else {
                $checked = ' checked="checked"';
            }
            $portcreatecheckbox = '<b style="background-color:' . ($disableport ? '#ff0000' : '#00ff00') . '"><input style="background-color:' . ($disableport ? '#ff0000' : '#00ff00') . '" class="moreport" type="checkbox" name="portcreate[' . $name . ']" value="' . $name . '"' . ($disableport ? ' disabled="disbaled"' : $checked) . '></b>';
            $formfield = '<input type="hidden" name="ifName[' . $name . ']" value="' . $name . '">';
            echo "<tr>{$formfield}<td>{$portcreatecheckbox}</td><td>{$name}</td>";
            if (isset($port['disabled'])) {
                $disabledselect = array('disabled' => "disabled");
            } else {
                $disabledselect = array();
            }
            foreach ($port as $key => $value) {
                if ($key == 'uncheck' || $key == 'comment') {
                    continue;
                }
                /* TODO iif_name */
                if ($key == 'porttypeid') {
                    $displayvalue = getNiftySelect($newporttypeoptions, array('name' => "porttypeid[{$name}]") + $disabledselect, $value);
                } else {
                    $displayvalue = $value;
                }
                $formfield = '<input type="hidden" name="' . $key . '[' . $name . ']" value="' . $value . '">';
                echo "{$formfield}<td>{$displayvalue}</td>";
            }
            $comment = trim($comment, ', ');
            echo "<td style=\"color:#888888\">{$comment}</td></tr>";
        }
        unset($name);
        unset($port);
        echo '</table>';
    }
    /* snmp ports */
    $ifsnmp = new ifSNMP($snmpdev);
    // needed for shortenIfName()
    $ifsnmp->object_breed = $object['breed'];
    /* ip spaces */
    $ipspace = NULL;
    foreach ($ifsnmp->ipaddress as $ifindex => $ipaddresses) {
        foreach ($ipaddresses as $ipaddr => $value) {
            $addrtype = $value['addrtype'];
            $netaddr = $value['net'];
            $maskbits = $value['maskbits'];
            $netid = NULL;
            $linklocal = FALSE;
            //echo "<br> - DEBUG: ipspace $ipaddr - $netaddr - $addrtype - $maskbits<br>";
            /* check for ip space */
            switch ($addrtype) {
                case 'ipv4':
                case 'ipv4z':
                    if ($maskbits == 32) {
                        $netid = 'host';
                    } else {
                        $netid = getIPv4AddressNetworkId(ip_parse($ipaddr));
                    }
                    break;
                case 'ipv6':
                    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
                    $ip6_bin = ip6_parse($ipaddr);
                    $ip6_addr = ip_format($ip6_bin);
                    $netid = getIPv6AddressNetworkId($ip6_bin);
                    $node = constructIPRange($ip6_bin, $maskbits);
                    $netaddr = $node['ip'];
                    $linklocal = substr($ip6_addr, 0, 5) == "fe80:";
                    //echo "<br> - DEBUG: ipspace $ipaddr - $addrtype - $maskbits - $netaddr - >$linklocal<<br>";
                    break;
                case 'ipv6z':
                    /* link local */
                    $netid = 'ignore';
                    break;
                default:
            }
            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] = array('addrtype' => $addrtype, 'checked' => $maskbits > 0 ? true : false);
            }
        }
        unset($ipaddr);
        unset($value);
        unset($addrtype);
    }
    unset($ifindex);
    unset($ipaddresses);
    /* print ip spaces table */
    if (!empty($ipspace)) {
        echo '<br><br>Create IP Spaces';
        echo '<table><tr><th><input type="checkbox" id="ipspace" onclick="setchecked(this.id)" checked=\\"checked\\"></th>';
        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 => $ipspace) {
            $netcreatecheckbox = '<b style="background-color:#00ff00">' . '<input class="ipspace" style="background-color:#00ff00" type="checkbox" name="netcreate[' . $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 . ']" checked="checked">';
            echo "<tr><td>{$netcreatecheckbox}</td><td style=\"color:#888888\">{$ipspace['addrtype']}</td><td>{$netprefixfield}</td><td>{$netnamefield}</td><td>{$netreservecheckbox}</td></tr>";
            $i++;
        }
        unset($prefix);
        unset($addrtype);
        unset($i);
        echo '</table>';
    }
    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>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);" 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="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) {
        $createport = TRUE;
        $disableport = FALSE;
        $ignoreport = FALSE;
        $port_info = NULL;
        $updatelabel = false;
        $updateporttype = false;
        $updatemaccheckbox = '';
        $hrefs = array();
        $comment = "";
        if (trim($ifsnmp->ifName($if)) == '') {
            $comment .= "no ifName";
            $createport = FALSE;
        } else {
            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;
            }
        }
        if ($ifsnmp->ifPhysAddress($if) != '') {
            $ifPhysAddress = $ifsnmp->ifPhysAddress($if);
            $l2port = sg_checkL2Address($ifPhysAddress);
            if (!empty($l2port)) {
                $l2object_id = key($l2port);
                $porthref = makeHref(array('page' => 'object', 'tab' => 'ports', 'object_id' => $l2object_id, 'hl_port_id' => $l2port[$l2object_id]));
                $comment .= ", L2Address exists";
                $hrefs['ifPhysAddress'] = $porthref;
                $createport = FALSE;
                //	$disableport = TRUE;
                $updatemaccheckbox = '';
            }
            $disablemac = true;
            if ($disableport) {
                if ($port_info !== NULL) {
                    if (str_replace(':', '', $port_info['l2address']) != $ifPhysAddress) {
                        $disablemac = false;
                    } else {
                        $disablemac = true;
                    }
                }
            } else {
                /* port create always updates mac */
                $updatemaccheckbox = '<b style="background-color:#00ff00">' . '<input style="background-color:' . '#00ff00" type="checkbox"' . ' checked="checked"' . ' disabled=\\"disabled\\"></b>';
            }
            if (!$disablemac) {
                $updatemaccheckbox = '<b style="background-color:' . ($disablemac ? '#ff0000' : '#00ff00') . '">' . '<input class="mac" style="background-color:' . ($disablemac ? '#ff0000' : '#00ff00') . '" type="checkbox" name="updatemac[' . $if . ']" value="' . $object['ports'][$ifsnmp->ifName($if)]['id'] . '" checked="checked"' . ($disablemac ? ' disabled=\\"disabled\\"' : '') . '></b>';
            }
        }
        $porttypeid = guessRToif_id($ifsnmp->ifType($if), $ifsnmp->ifDescr($if));
        if (in_array($ifsnmp->ifType($if), $sg_ifType_ignore)) {
            $comment .= ", ignore if type";
            $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) {
            $comment .= ", no Connector";
            $createport = FALSE;
        }
        /* Allocate IPs ipv4 and ipv6 */
        $ipaddresses = $ifsnmp->ipaddress($if);
        if (!empty($ipaddresses)) {
            $ipaddrcell = '<table>';
            foreach ($ipaddresses as $ipaddr => $value) {
                $createipaddr = FALSE;
                $disableipaddr = FALSE;
                $ipaddrhref = '';
                $linklocal = FALSE;
                $addrtype = $value['addrtype'];
                $maskbits = $value['maskbits'];
                $bcast = $value['bcast'];
                //echo "<br> - DEBUG: ip $ipaddr - $addrtype - $maskbits - $bcast<br>";
                switch ($addrtype) {
                    case 'ipv4z':
                    case 'ipv4':
                        if ($maskbits == 32) {
                            $bcast = "host";
                        }
                        $inputname = 'ip';
                        break;
                    case 'ipv6z':
                        $disableipaddr = TRUE;
                    case 'ipv6':
                        $inputname = 'ipv6';
                        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
                        /* ip_parse throws exception on parse errors */
                        $ip6_bin = ip_parse($ipaddr);
                        $ipaddr = ip_format($ip6_bin);
                        $node = constructIPRange($ip6_bin, $maskbits);
                        $linklocal = $node['ip'] == 'fe80::';
                        $createipaddr = FALSE;
                        break;
                }
                //switch
                $address = getIPAddress(ip_parse($ipaddr));
                /* only if ip not already allocated */
                if (empty($address['allocs'])) {
                    if (!$ignoreport) {
                        $createipaddr = TRUE;
                    }
                } else {
                    $disableipaddr = TRUE;
                    $ipobject_id = $address['allocs'][0]['object_id'];
                    $ipaddrhref = makeHref(array('page' => 'object', 'object_id' => $ipobject_id, 'hl_ipv4_addr' => $ipaddr));
                }
                /* reserved addresses */
                if ($address['reserved'] == 'yes') {
                    $comment .= ', ' . $address['ip'] . ' reserved ' . $address['name'];
                    $createipaddr = FALSE;
                    //	$disableipaddr = TRUE;
                }
                if ($ipaddr == '127.0.0.1' || $ipaddr == '0.0.0.0' || $ipaddr == '::1' || $ipaddr == '::' || $linklocal) {
                    $createipaddr = FALSE;
                    $disableipaddr = TRUE;
                }
                if ($ipaddr === $bcast) {
                    $comment .= ", {$ipaddr} broadcast";
                    $createipaddr = FALSE;
                    $disableipaddr = TRUE;
                }
                if (!$disableipaddr) {
                    $ipaddrcheckbox = '<b style="background-color:' . ($disableipaddr ? '#ff0000' : '#00ff00') . '"><input class="' . $inputname . 'addr" style="background-color:' . ($disableipaddr ? '#ff0000' : '#00ff00') . '" type="checkbox" name="' . $inputname . 'addrcreate[' . $ipaddr . ']" value="' . $if . '"' . ($disableipaddr ? ' disabled="disabled"' : '') . ($createipaddr ? ' checked="checked"' : '') . '></b>';
                } else {
                    $ipaddrcheckbox = '';
                }
                $ipaddrcell .= "<tr><td>{$ipaddrcheckbox}</td>";
                if (!empty($ipaddrhref)) {
                    $ipaddrcell .= "<td><a href={$ipaddrhref}>{$ipaddr}/{$maskbits}</a></td></tr>";
                } else {
                    $ipaddrcell .= "<td>{$ipaddr}/{$maskbits}</td></tr>";
                }
            }
            // foreach
            unset($ipaddr);
            unset($value);
            $ipaddrcell .= '</table>';
            // if(!empty($ipaddresses))
        } else {
            $ipaddrcreatecheckbox = '';
            $ipaddrcell = '';
        }
        /* checkboxes for add port and add ip */
        /* FireFox needs <b style=..>, IE and Opera work with <td style=..> */
        if (!$disableport) {
            $portcreatecheckbox = '<b style="background-color:' . ($disableport ? '#ff0000' : '#00ff00') . '"><input class="ports" style="background-color:' . ($disableport ? '#ff0000' : '#00ff00') . '" type="checkbox" name="portcreate[' . $if . ']" value="' . $if . '"' . ($disableport ? ' disabled="disbaled"' : '') . ($createport ? ' checked="checked"' : '') . '></b>';
        } else {
            $portcreatecheckbox = '';
        }
        /* port type id */
        /* add port type to newporttypeoptions if missing */
        if (strpos(serialize($newporttypeoptions), $porttypeid) === FALSE) {
            $portids = explode('-', $porttypeid);
            $oif_name = $sg_portoifoptions[$portids[1]];
            $newporttypeoptions['auto'] = array($porttypeid => "*{$oif_name}");
        }
        $selectoptions = array('name' => "porttypeid[{$if}]");
        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>{$updatelabelcheckbox}</td><td>{$updatemaccheckbox}</td><td>{$updateporttypecheckbox}</td><td>{$porttypeidselect}</td><td nowrap=\"nowrap\">{$comment}</td>", $hrefs);
    }
    unset($if);
    /* preserve snmpconfig */
    foreach ($_POST as $key => $value) {
        echo '<input type=hidden name=' . $key . ' value=' . $value . ' />';
    }
    unset($key);
    unset($value);
    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>';
}
Esempio n. 2
0
function renderSearchResults($terms, $summary)
{
    // calculate the number of found objects
    $nhits = 0;
    foreach ($summary as $realm => $list) {
        $nhits += count($list);
    }
    if ($nhits == 0) {
        echo "<center><h2>Nothing found for '{$terms}'</h2></center>";
    } elseif ($nhits == 1) {
        foreach ($summary as $realm => $record) {
            if (is_array($record)) {
                $record = array_shift($record);
            }
            break;
        }
        switch ($realm) {
            case 'ipv4addressbydq':
                if ($record['net_id'] !== NULL) {
                    echo "<script language='Javascript'>document.location='index.php?page=ipv4net&tab=default&id={$record['net_id']}&hl_ip={$record['ip']}';//</script>";
                }
                break;
            case 'ipv6addressbydq':
                $fmt = ip6_format($record['ip']);
                if ($record['net_id'] !== NULL) {
                    echo "<script language='Javascript'>document.location='index.php?page=ipv6net&tab=default&id={$record['net_id']}&hl_ip={$fmt}';//</script>";
                }
                break;
            case 'ipv4addressbydescr':
                $parentnet = getIPv4AddressNetworkId($record['ip']);
                if ($parentnet !== NULL) {
                    $fmt = ip4_format($record['ip']);
                    echo "<script language='Javascript'>document.location='index.php?page=ipv4net&tab=default&id={$parentnet}&hl_ip={$fmt}';//</script>";
                }
                break;
            case 'ipv6addressbydescr':
                $parentnet = getIPv6AddressNetworkId($record['ip']);
                if ($parentnet !== NULL) {
                    $fmt = ip6_format($record['ip']);
                    echo "<script language='Javascript'>document.location='index.php?page=ipv6net&tab=default&id={$parentnet}&hl_ip={$fmt}';//</script>";
                }
                break;
            case 'ipv4network':
                echo "<script language='Javascript'>document.location='index.php?page=ipv4net";
                echo "&id={$record['id']}";
                echo "';//</script>";
                break;
            case 'ipv6network':
                echo "<script language='Javascript'>document.location='index.php?page=ipv6net";
                echo "&id={$record['id']}";
                echo "';//</script>";
                break;
            case 'object':
                if (isset($record['by_port']) and 1 == count($record['by_port'])) {
                    $found_ports_ids = array_keys($record['by_port']);
                    $hl = '&hl_port_id=' . $found_ports_ids[0];
                } else {
                    $hl = '';
                }
                echo "<script language='Javascript'>document.location='index.php?page=object&object_id={$record['id']}{$hl}';//</script>";
                break;
            case 'ipv4rspool':
                echo "<script language='Javascript'>document.location='index.php?page=ipv4rspool&pool_id={$record['id']}';//</script>";
                break;
            case 'ipv4vs':
                echo "<script language='Javascript'>document.location='index.php?page=ipv4vs&vs_id={$record['id']}';//</script>";
                break;
            case 'user':
                echo "<script language='Javascript'>document.location='index.php?page=user&user_id={$record['user_id']}';//</script>";
                break;
            case 'file':
                echo "<script language='Javascript'>document.location='index.php?page=file&file_id={$record['id']}';//</script>";
                break;
            case 'rack':
                echo "<script language='Javascript'>document.location='index.php?page=rack&rack_id={$record['id']}';//</script>";
                break;
            case 'vlan':
                echo "<script language='Javascript'>document.location='index.php?page=vlan&vlan_ck={$record}';//</script>";
                break;
            default:
                startPortlet($realm);
                echo $record;
                finishPortlet();
        }
        return;
    } else {
        global $nextorder;
        $order = 'odd';
        echo "<center><h2>{$nhits} result(s) found for '{$terms}'</h2></center>";
        foreach ($summary as $where => $what) {
            switch ($where) {
                case 'object':
                    startPortlet("<a href='index.php?page=depot'>Objects</a>");
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    echo '<tr><th>what</th><th>why</th></tr>';
                    foreach ($what as $obj) {
                        echo "<tr class=row_{$order} valign=top><td>";
                        $object = spotEntity('object', $obj['id']);
                        renderCell($object);
                        echo "</td><td class=tdleft>";
                        if (isset($obj['by_attr'])) {
                            // only explain non-obvious reasons for listing
                            echo '<ul>';
                            foreach ($obj['by_attr'] as $attr_name) {
                                if ($attr_name != 'name') {
                                    echo "<li>{$attr_name} matched</li>";
                                }
                            }
                            echo '</ul>';
                        }
                        if (isset($obj['by_sticker'])) {
                            echo '<table>';
                            $aval = getAttrValues($obj['id']);
                            foreach ($obj['by_sticker'] as $attr_id) {
                                $record = $aval[$attr_id];
                                echo "<tr><th width='50%' class=sticker>{$record['name']}:</th>";
                                echo "<td class=sticker>" . formatAttributeValue($record) . "</td></tr>";
                            }
                            echo '</table>';
                        }
                        if (isset($obj['by_port'])) {
                            echo '<table>';
                            amplifyCell($object);
                            foreach ($obj['by_port'] as $port_id => $text) {
                                foreach ($object['ports'] as $port) {
                                    if ($port['id'] == $port_id) {
                                        $port_href = '<a href="' . makeHref(array('page' => 'object', 'object_id' => $object['id'], 'hl_port_id' => $port_id)) . '">port ' . $port['name'] . '</a>';
                                        echo "<tr><td>{$port_href}:</td>";
                                        echo "<td class=tdleft>{$text}</td></tr>";
                                        break;
                                        // next reason
                                    }
                                }
                            }
                            echo '</table>';
                        }
                        if (isset($obj['by_iface'])) {
                            echo '<ul>';
                            foreach ($obj['by_iface'] as $ifname) {
                                echo "<li>interface {$ifname}</li>";
                            }
                            echo '</ul>';
                        }
                        if (isset($obj['by_nat'])) {
                            echo '<ul>';
                            foreach ($obj['by_nat'] as $comment) {
                                echo "<li>NAT rule: {$comment}</li>";
                            }
                            echo '</ul>';
                        }
                        if (isset($obj['by_cableid'])) {
                            echo '<ul>';
                            foreach ($obj['by_cableid'] as $cableid) {
                                echo "<li>link cable ID: {$cableid}</li>";
                            }
                            echo '</ul>';
                        }
                        echo "</td></tr>";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                case 'ipv4network':
                    startPortlet("<a href='index.php?page=ipv4space'>IPv4 networks</a>");
                case 'ipv6network':
                    if ($where == 'ipv6network') {
                        startPortlet("<a href='index.php?page=ipv6space'>IPv6 networks</a>");
                    }
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    foreach ($what as $cell) {
                        echo "<tr class=row_{$order} valign=top><td>";
                        renderCell($cell);
                        echo "</td></tr>\n";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                case 'ipv4addressbydescr':
                    startPortlet('IPv4 addresses');
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    // FIXME: address, parent network, routers (if extended view is enabled)
                    echo '<tr><th>Address</th><th>Description</th></tr>';
                    foreach ($what as $addr) {
                        echo "<tr class=row_{$order}><td class=tdleft>";
                        $fmt = ip4_format($addr['ip']);
                        $parentnet = getIPv4AddressNetworkId($addr['ip']);
                        if ($parentnet !== NULL) {
                            echo "<a href='index.php?page=ipv4net&tab=default&id={$parentnet}&hl_ip={$fmt}'>{$fmt}</a></td>";
                        } else {
                            echo "<a href='index.php?page=ipaddress&ip={$fmt}'>{$fmt}</a></td>";
                        }
                        echo "<td class=tdleft>{$addr['name']}</td></tr>";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                case 'ipv6addressbydescr':
                    startPortlet('IPv6 addresses');
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    // FIXME: address, parent network, routers (if extended view is enabled)
                    echo '<tr><th>Address</th><th>Description</th></tr>';
                    foreach ($what as $addr) {
                        echo "<tr class=row_{$order}><td class=tdleft>";
                        $fmt = ip6_format($addr['ip']);
                        $parentnet = getIPv6AddressNetworkId($addr['ip']);
                        if ($parentnet !== NULL) {
                            echo "<a href='index.php?page=ipv6net&tab=default&id={$parentnet}&hl_ip={$fmt}'>{$fmt}</a></td>";
                        } else {
                            echo "<a href='index.php?page=ipaddress&ip={$fmt}'>{$fmt}</a></td>";
                        }
                        echo "<td class=tdleft>{$addr['name']}</td></tr>";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                case 'ipv4rspool':
                    startPortlet("<a href='index.php?page=ipv4slb&tab=rspools'>RS pools</a>");
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    foreach ($what as $cell) {
                        echo "<tr class=row_{$order}><td class=tdleft>";
                        renderCell($cell);
                        echo "</td></tr>";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                case 'ipv4vs':
                    startPortlet("<a href='index.php?page=ipv4slb&tab=default'>Virtual services</a>");
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    foreach ($what as $cell) {
                        echo "<tr class=row_{$order}><td class=tdleft>";
                        renderCell($cell);
                        echo "</td></tr>";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                case 'user':
                    startPortlet("<a href='index.php?page=userlist'>Users</a>");
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    foreach ($what as $item) {
                        echo "<tr class=row_{$order}><td class=tdleft>";
                        renderCell($item);
                        echo "</td></tr>";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                case 'file':
                    startPortlet("<a href='index.php?page=files'>Files</a>");
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    foreach ($what as $cell) {
                        echo "<tr class=row_{$order}><td class=tdleft>";
                        renderCell($cell);
                        echo "</td></tr>";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                case 'rack':
                    startPortlet("<a href='index.php?page=rackspace'>Racks</a>");
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    foreach ($what as $cell) {
                        echo "<tr class=row_{$order}><td class=tdleft>";
                        renderCell($cell);
                        echo "</td></tr>";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                case 'vlan':
                    startPortlet("<a href='index.php?page=8021q'>VLANs</a>");
                    echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                    foreach ($what as $vlan_ck) {
                        echo "<tr class=row_{$order}><td class=tdleft>";
                        echo formatVLANName(getVLANInfo($vlan_ck), 'hyperlink') . "</td></tr>";
                        $order = $nextorder[$order];
                    }
                    echo '</table>';
                    finishPortlet();
                    break;
                default:
                    // you can use that in your plugins to add some non-standard search results
                    startPortlet($where);
                    echo $what;
                    finishPortlet();
            }
        }
    }
}
Esempio n. 3
0
function newPortForwarding($object_id, $localip_bin, $localport, $remoteip_bin, $remoteport, $proto, $description)
{
    if (NULL === getIPv4AddressNetworkId($localip_bin)) {
        throw new InvalidArgException('localip_bin', $localip_bin, "Non-existant ip");
    }
    if (NULL === getIPv4AddressNetworkId($remoteip_bin)) {
        throw new InvalidArgException('remoteip_bin', $remoteip_bin, "Non-existant ip");
    }
    if ($localport <= 0 or $localport >= 65536) {
        throw new InvalidArgException('localport', $localport, "invaild port");
    }
    if ($remoteport <= 0 or $remoteport >= 65536) {
        throw new InvalidArgException('remoteport', $remoteport, "invaild port");
    }
    return usePreparedInsertBlade('IPv4NAT', array('object_id' => $object_id, 'localip' => ip4_bin2db($localip_bin), 'localport' => $localport, 'remoteip' => ip4_bin2db($remoteip_bin), 'remoteport' => $remoteport, 'proto' => $proto, 'description' => $description));
}
Esempio n. 4
0
function searchEntitiesByText($terms)
{
    $summary = array();
    if (preg_match(RE_IP4_ADDR, $terms)) {
        if ($net_id = getIPv4AddressNetworkId(ip4_parse($terms))) {
            $summary['ipv4addressbydq'][$terms] = array('net_id' => $net_id, 'ip' => $terms);
        }
    } elseif (FALSE !== ($ip_bin = ip6_checkparse($terms))) {
        if ($net_id = getIPv6AddressNetworkId($ip_bin)) {
            $summary['ipv6addressbydq'][$net_id] = array('net_id' => $net_id, 'ip' => $ip_bin);
        }
    } elseif (preg_match(RE_IP4_NET, $terms)) {
        list($base, $len) = explode('/', $terms);
        if (NULL !== ($net_id = getIPv4AddressNetworkId(ip4_parse($base), $len + 1))) {
            $summary['ipv4network'][$net_id] = spotEntity('ipv4net', $net_id);
        }
    } elseif (preg_match('@(.*)/(\\d+)$@', $terms, $matches) && FALSE !== ($ip_bin = ip6_checkparse($matches[1]))) {
        if (NULL !== ($net_id = getIPv6AddressNetworkId($ip_bin, $matches[2] + 1))) {
            $summary['ipv6network'][$net_id] = spotEntity('ipv6net', $net_id);
        }
    } else {
        // search by FQDN has special treatment - if single object found, do not search by other fields
        $object_id_by_fqdn = NULL;
        $domains = preg_split('/\\s*,\\s*/', strtolower(getConfigVar('SEARCH_DOMAINS')));
        if (!empty($domains) and $object_id = searchByMgmtHostname($terms)) {
            // get FQDN
            $attrs = getAttrValues($object_id);
            $fqdn = '';
            if (isset($attrs[3]['value'])) {
                $fqdn = strtolower(trim($attrs[3]['value']));
            }
            foreach ($domains as $domain) {
                if ('.' . $domain === substr($fqdn, -strlen($domain) - 1)) {
                    $object_id_by_fqdn = $object_id;
                    break;
                }
            }
        }
        if ($object_id_by_fqdn) {
            $summary['object'][$object_id_by_fqdn] = array('id' => $object_id_by_fqdn, 'method' => 'fqdn');
        } else {
            $summary['object'] = getObjectSearchResults($terms);
            $summary['ipv4addressbydescr'] = getIPv4AddressSearchResult($terms);
            $summary['ipv6addressbydescr'] = getIPv6AddressSearchResult($terms);
            $summary['ipv4network'] = getIPv4PrefixSearchResult($terms);
            $summary['ipv6network'] = getIPv6PrefixSearchResult($terms);
            $summary['ipv4rspool'] = getIPv4RSPoolSearchResult($terms);
            $summary['ipv4vs'] = getIPv4VServiceSearchResult($terms);
            $summary['user'] = getAccountSearchResult($terms);
            $summary['file'] = getFileSearchResult($terms);
            $summary['rack'] = getRackSearchResult($terms);
            $summary['vlan'] = getVLANSearchResult($terms);
        }
    }
    # Filter search results in a way in some realms to omit records, which the
    # user would not be able to browse anyway.
    if (isset($summary['object'])) {
        foreach ($summary['object'] as $key => $record) {
            if (!isolatedPermission('object', 'default', spotEntity('object', $record['id']))) {
                unset($summary['object'][$key]);
            }
        }
    }
    if (isset($summary['ipv4network'])) {
        foreach ($summary['ipv4network'] as $key => $netinfo) {
            if (!isolatedPermission('ipv4net', 'default', $netinfo)) {
                unset($summary['ipv4network'][$key]);
            }
        }
    }
    if (isset($summary['ipv6network'])) {
        foreach ($summary['ipv6network'] as $key => $netinfo) {
            if (!isolatedPermission('ipv6net', 'default', $netinfo)) {
                unset($summary['ipv6network'][$key]);
            }
        }
    }
    if (isset($summary['file'])) {
        foreach ($summary['file'] as $key => $fileinfo) {
            if (!isolatedPermission('file', 'default', $fileinfo)) {
                unset($summary['file'][$key]);
            }
        }
    }
    // clear empty search result realms
    foreach ($summary as $key => $data) {
        if (!count($data)) {
            unset($summary[$key]);
        }
    }
    return $summary;
}