function formatPortMacHints($object_id)
{
    $result = array();
    if ($_REQUEST['ac'] == 'get-port-portmac') {
        $port_name = $_REQUEST['port_name'];
        $ports = reduceSubarraysToColumn(getObjectPortsAndLinks($_REQUEST['object_id']), 'name');
        $macList = in_array($port_name, $ports) ? queryDevice($object_id, 'getportmaclist', array($port_name)) : array();
    } else {
        $macList = queryDevice($object_id, 'getmaclist');
    }
    foreach ($macList as $portname => $list) {
        $list = $macList[$portname];
        $visible_part = count($list) . ' MACs';
        $result[$portname]['inline'] = $visible_part;
        if (count($list)) {
            $hidden_part = '<table width="100%"><tr><th>MAC<th>VID</tr>';
            foreach ($list as $mac) {
                $hidden_part .= '<tr><td>' . $mac['mac'] . '<td>' . $mac['vid'] . '</tr>';
            }
            $result[$portname]['popup'] = $hidden_part;
        }
    }
    return $result;
}
Exemple #2
0
function getVSIDsByGroup($group_id)
{
    $ret = array();
    $vsinfo = spotEntity('ipvs', $group_id);
    amplifyCell($vsinfo);
    if (count($vsinfo['vips'])) {
        $ips = reduceSubarraysToColumn($vsinfo['vips'], 'vip');
        $qm = questionMarks(count($ips));
        $result = usePreparedSelectBlade("SELECT id FROM IPv4VS WHERE vip IN ({$qm}) ORDER BY vip", $ips);
        $ret = array_merge($ret, $result->fetchAll(PDO::FETCH_COLUMN, 0));
        unset($result);
    }
    $bin_marks = array();
    foreach ($vsinfo['ports'] as $port) {
        if ($port['proto'] == 'MARK') {
            $bin_marks[] = pack('N', $port['vport']);
        }
    }
    if (count($bin_marks)) {
        $qm = questionMarks(count($bin_marks));
        $result = usePreparedSelectBlade("SELECT id FROM IPv4VS WHERE proto = 'MARK' AND vip IN ({$qm}) ORDER BY vip", $bin_marks);
        $ret = array_merge($ret, $result->fetchAll(PDO::FETCH_COLUMN, 0));
    }
    return $ret;
}
function updateObjectAllocation()
{
    global $remote_username, $sic;
    if (!isset($_REQUEST['got_atoms'])) {
        unset($_GET['page']);
        unset($_GET['tab']);
        unset($_GET['op']);
        unset($_POST['page']);
        unset($_POST['tab']);
        unset($_POST['op']);
        return buildRedirectURL(NULL, NULL, $_REQUEST);
    }
    $object_id = getBypassValue();
    $object = spotEntity('object', $object_id);
    $changecnt = 0;
    // Get a list of rack ids which are parents of the object
    $parentRacks = reduceSubarraysToColumn(getParents($object, 'rack'), 'id');
    $workingRacksData = array();
    foreach ($_REQUEST['rackmulti'] as $cand_id) {
        if (!isset($workingRacksData[$cand_id])) {
            $rackData = spotEntity('rack', $cand_id);
            amplifyCell($rackData);
            $workingRacksData[$cand_id] = $rackData;
        } else {
            $rackData = $workingRacksData[$cand_id];
        }
        $is_ro = !rackModificationPermitted($rackData, 'updateObjectAllocation', FALSE);
        // It's zero-U mounted to this rack on the form, but not in the DB.  Mount it.
        if (isset($_REQUEST["zerou_{$cand_id}"]) && !in_array($cand_id, $parentRacks)) {
            if ($is_ro) {
                continue;
            }
            $changecnt++;
            commitLinkEntities('rack', $cand_id, 'object', $object_id);
        }
        // It's not zero-U mounted to this rack on the form, but it is in the DB.  Unmount it.
        if (!isset($_REQUEST["zerou_{$cand_id}"]) && in_array($cand_id, $parentRacks)) {
            if ($is_ro) {
                continue;
            }
            $changecnt++;
            commitUnlinkEntities('rack', $cand_id, 'object', $object_id);
        }
    }
    foreach ($workingRacksData as &$rd) {
        applyObjectMountMask($rd, $object_id);
    }
    $oldMolecule = getMoleculeForObject($object_id);
    foreach ($workingRacksData as $rack_id => $rackData) {
        $is_ro = !rackModificationPermitted($rackData, 'updateObjectAllocation', FALSE);
        if ($is_ro || !processGridForm($rackData, 'F', 'T', $object_id)) {
            continue;
        }
        $changecnt++;
        // Reload our working copy after form processing.
        $rackData = spotEntity('rack', $cand_id);
        amplifyCell($rackData);
        applyObjectMountMask($rackData, $object_id);
        $workingRacksData[$rack_id] = $rackData;
    }
    if ($changecnt) {
        // Log a record.
        $newMolecule = getMoleculeForObject($object_id);
        usePreparedInsertBlade('MountOperation', array('object_id' => $object_id, 'old_molecule_id' => count($oldMolecule) ? createMolecule($oldMolecule) : NULL, 'new_molecule_id' => count($newMolecule) ? createMolecule($newMolecule) : NULL, 'user_name' => $remote_username, 'comment' => empty($sic['comment']) ? NULL : $sic['comment']));
    }
    ###############################################################################################
    # set hostgroup for zabbix host
    $allracks = getMoleculeForObject($object_id);
    $rackids = array();
    $racknames = array();
    foreach ($allracks as $rack) {
        if (in_array($rack['rack_id'], $rackids)) {
            continue;
        }
        array_push($rackids, $rack['rack_id']);
        $rackdata = spotEntity('rack', $rack['rack_id']);
        array_push($racknames, $rackdata['name']);
    }
    $result = updateHostGroup($object['name'], $racknames);
    if (isset($result['error'])) {
        showError('Setting hostgroup for zabbix host is failed. Error message:' . $result['error']);
    }
    # END
    ###############################################################################################
    showFuncMessage(__FUNCTION__, 'OK', array($changecnt));
}
function initRackTablesObject($rackDatas)
{
    // zabbix host data
    $params = array('output' => 'extend');
    $result = doPost('host.get', $params);
    $hosts = isset($result['result']) ? $result['result'] : array();
    $objectDatas = array();
    foreach ($hosts as $host) {
        $object_type_id = 4;
        $object_name = isset($host['host']) ? $host['host'] : "";
        $object_label = "";
        $object_asset_no = "";
        $taglist = array();
        $has_problems = $host['status'] == 0 ? 'no' : 'yes';
        $object_id = commitAddObject($object_name, $object_label, $object_type_id, $object_asset_no, $taglist);
        usePreparedUpdateBlade('Object', array('has_problems' => $has_problems), array('id' => $object_id));
        $objectDatas[$host['hostid']] = $object_id;
        // set hostgroup
        $params = array('output' => array('name'), 'hostids' => array($host['hostid']));
        $result = doPost('hostgroup.get', $params);
        $hostgroups = isset($result['result']) ? $result['result'] : array();
        $rack_ids = array();
        $_REQUEST = array();
        foreach ($hostgroups as $hostgroup) {
            if (isset($rackDatas[$hostgroup['name']])) {
                $rack = $rackDatas[$hostgroup['name']];
                amplifyCell($rack);
                array_push($rack_ids, $rack['id']);
                $height = $rack['height'];
                for ($i = 0; $i < 3; $i++) {
                    for ($j = $height; $j > 0; $j--) {
                        if ($rack[$j][$i]['state'] == 'F') {
                            # state == "T" : mounted
                            $_REQUEST['atom_' . $rack['id'] . "_{$j}" . "_{$i}"] = 'on';
                            break 2;
                        }
                    }
                }
            }
        }
        $_REQUEST['object_id'] = $object_id;
        $_REQUEST['rackmulti'] = $rack_ids;
        $object = spotEntity('object', $object_id);
        $changecnt = 0;
        // Get a list of rack ids which are parents of the object
        $parentRacks = reduceSubarraysToColumn(getParents($object, 'rack'), 'id');
        $workingRacksData = array();
        foreach ($_REQUEST['rackmulti'] as $cand_id) {
            if (!isset($workingRacksData[$cand_id])) {
                $rackData = spotEntity('rack', $cand_id);
                amplifyCell($rackData);
                $workingRacksData[$cand_id] = $rackData;
            } else {
                $rackData = $workingRacksData[$cand_id];
            }
            $is_ro = !rackModificationPermitted($rackData, 'updateObjectAllocation', FALSE);
            // It's zero-U mounted to this rack on the form, but not in the DB.  Mount it.
            if (isset($_REQUEST["zerou_{$cand_id}"]) && !in_array($cand_id, $parentRacks)) {
                if ($is_ro) {
                    continue;
                }
                $changecnt++;
                commitLinkEntities('rack', $cand_id, 'object', $object_id);
            }
            // It's not zero-U mounted to this rack on the form, but it is in the DB.  Unmount it.
            if (!isset($_REQUEST["zerou_{$cand_id}"]) && in_array($cand_id, $parentRacks)) {
                if ($is_ro) {
                    continue;
                }
                $changecnt++;
                commitUnlinkEntities('rack', $cand_id, 'object', $object_id);
            }
        }
        foreach ($workingRacksData as &$rd) {
            applyObjectMountMask($rd, $object_id);
        }
        $oldMolecule = getMoleculeForObject($object_id);
        foreach ($workingRacksData as $rack_id => $rackData) {
            $is_ro = !rackModificationPermitted($rackData, 'updateObjectAllocation', FALSE);
            if ($is_ro || !processGridForm($rackData, 'F', 'T', $object_id)) {
                continue;
            }
            $changecnt++;
            // Reload our working copy after form processing.
            $rackData = spotEntity('rack', $cand_id);
            amplifyCell($rackData);
            applyObjectMountMask($rackData, $object_id);
            $workingRacksData[$rack_id] = $rackData;
        }
        if ($changecnt) {
            // Log a record.
            $newMolecule = getMoleculeForObject($object_id);
            global $remote_username, $sic;
            usePreparedInsertBlade('MountOperation', array('object_id' => $object_id, 'old_molecule_id' => count($oldMolecule) ? createMolecule($oldMolecule) : NULL, 'new_molecule_id' => count($newMolecule) ? createMolecule($newMolecule) : NULL, 'user_name' => $remote_username, 'comment' => empty($sic['comment']) ? NULL : $sic['comment']));
        }
        // set IP
        $params = array('output' => 'extend', 'hostids' => $host['hostid']);
        $result = doPost('hostinterface.get', $params);
        $hostinterfaces = isset($result['result']) ? $result['result'] : array();
        foreach ($hostinterfaces as $interface) {
            if (isset($interface['ip']) && $interface['ip'] != '127.0.0.1') {
                $allocs = getObjectIPAllocations($object_id);
                $current_ips = array();
                foreach ($allocs as $alloc) {
                    $ip = $alloc["addrinfo"]["ip"];
                    $current_ips[$ip] = $ip;
                }
                $ip = $interface['ip'];
                if (!in_array($ip, array_values($current_ips))) {
                    // new IP
                    $ip_bin = ip_parse($ip);
                    if (null == getIPAddressNetworkId($ip_bin)) {
                        // if ip is not exists, adding it into RackTables IPv4Prefix.
                        $range = substr($ip, 0, strripos($ip, '.')) . '.0/24';
                        $vlan_ck = NULL;
                        $net_id = createIPv4Prefix($range, 'admim', isCheckSet('is_connected'), $taglist);
                        $net_cell = spotEntity('ipv4net', $net_id);
                        if (isset($vlan_ck)) {
                            if (considerConfiguredConstraint($net_cell, 'VLANIPV4NET_LISTSRC')) {
                                commitSupplementVLANIPv4($vlan_ck, $net_id);
                            }
                        }
                    }
                    bindIPToObject($ip_bin, $object_id, "", "");
                }
            }
        }
    }
    return $objectDatas;
}
Exemple #5
0
function renderVLANIPLinks($some_id)
{
    function printNewItemTR($sname, $options, $extra = array())
    {
        if (!count($options)) {
            return;
        }
        printOpFormIntro('bind', $extra);
        echo '<tr><td>' . getOptionTree($sname, $options, array('tabindex' => 101));
        echo '</td><td>' . getImageHREF('ATTACH', 'bind', TRUE, 102) . '</td></tr></form>';
    }
    global $pageno, $tabno;
    echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>';
    echo '<tr>';
    // fill $minuslines, $plusoptions, $select_name
    $minuslines = array();
    $plusoptions = array();
    $extra = array();
    switch ($pageno) {
        case 'vlan':
            $ip_ver = $tabno == 'ipv6' ? 'ipv6' : 'ipv4';
            echo '<th>' . getImageHREF('net') . '</th>';
            $vlan = getVLANInfo($some_id);
            $domainclass = array($vlan['domain_id'] => 'trbusy');
            foreach ($vlan[$ip_ver . "nets"] as $net_id) {
                $minuslines[] = array('net_id' => $net_id, 'domain_id' => $vlan['domain_id'], 'vlan_id' => $vlan['vlan_id']);
            }
            // Any VLAN can link to any network that isn't yet linked to current domain.
            // get free IP nets
            $netlist_func = $ip_ver == 'ipv6' ? 'getVLANIPv6Options' : 'getVLANIPv4Options';
            foreach ($netlist_func($vlan['domain_id']) as $net_id) {
                $netinfo = spotEntity($ip_ver . 'net', $net_id);
                if (considerConfiguredConstraint($netinfo, 'VLANIPV4NET_LISTSRC')) {
                    $plusoptions['other'][$net_id] = $netinfo['ip'] . '/' . $netinfo['mask'] . ' ' . $netinfo['name'];
                }
            }
            $select_name = 'id';
            $extra = array('vlan_ck' => $vlan['domain_id'] . '-' . $vlan['vlan_id']);
            break;
        case 'ipv4net':
        case 'ipv6net':
            echo '<th>VLAN</th>';
            $netinfo = spotEntity($pageno, $some_id);
            $reuse_domain = considerConfiguredConstraint($netinfo, '8021Q_MULTILINK_LISTSRC');
            # For each of the domains linked to the network produce class name based on
            # number of VLANs linked and the current "reuse" setting.
            $domainclass = array();
            foreach (array_count_values(reduceSubarraysToColumn($netinfo['8021q'], 'domain_id')) as $domain_id => $vlan_count) {
                $domainclass[$domain_id] = $vlan_count == 1 ? 'trbusy' : ($reuse_domain ? 'trwarning' : 'trerror');
            }
            # Depending on the setting and the currently linked VLANs reduce the list of new
            # options by either particular VLANs or whole domains.
            $except = array();
            foreach ($netinfo['8021q'] as $item) {
                if ($reuse_domain) {
                    $except[$item['domain_id']][] = $item['vlan_id'];
                } elseif (!array_key_exists($item['domain_id'], $except)) {
                    $except[$item['domain_id']] = range(VLAN_MIN_ID, VLAN_MAX_ID);
                }
                $minuslines[] = array('net_id' => $netinfo['id'], 'domain_id' => $item['domain_id'], 'vlan_id' => $item['vlan_id']);
            }
            $plusoptions = getAllVLANOptions($except);
            $select_name = 'vlan_ck';
            $extra = array('id' => $netinfo['id']);
            break;
    }
    echo '<th>&nbsp;</th></tr>';
    if (getConfigVar('ADDNEW_AT_TOP') == 'yes') {
        printNewItemTR($select_name, $plusoptions, $extra);
    }
    foreach ($minuslines as $item) {
        echo '<tr class=' . $domainclass[$item['domain_id']] . '><td>';
        switch ($pageno) {
            case 'vlan':
                renderCell(spotEntity($ip_ver . 'net', $item['net_id']));
                break;
            case 'ipv4net':
            case 'ipv6net':
                $vlaninfo = getVLANInfo($item['domain_id'] . '-' . $item['vlan_id']);
                echo formatVLANAsRichText($vlaninfo);
                break;
        }
        echo '</td><td>';
        echo getOpLink(array('id' => $some_id, 'op' => 'unbind', 'id' => $item['net_id'], 'vlan_ck' => $item['domain_id'] . '-' . $item['vlan_id']), '', 'Cut', 'unbind');
        echo '</td></tr>';
    }
    if (getConfigVar('ADDNEW_AT_TOP') != 'yes') {
        printNewItemTR($select_name, $plusoptions, $extra);
    }
    echo '</table>';
}