function addIPAllocation() { $ip_bin = assertIPArg('ip'); assertUIntArg('object_id'); assertStringArg('bond_name', TRUE); genericAssertion('bond_type', 'enum/alloc_type'); if (getConfigVar('IPV4_JAYWALK') != 'yes' and NULL === getIPAddressNetworkId($ip_bin)) { showFuncMessage(__FUNCTION__, 'ERR1', array(ip_format($ip_bin))); return; } bindIPToObject($ip_bin, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']); showFuncMessage(__FUNCTION__, 'OK'); return buildRedirectURL(NULL, NULL, array('hl_ip' => ip_format($ip_bin))); }
function spotNetworkByIP($ip_bin, $masklen = NULL) { $net_id = getIPAddressNetworkId($ip_bin, $masklen); if (!$net_id) { return NULL; } switch (strlen($ip_bin)) { case 4: return spotEntity('ipv4net', $net_id); case 16: return spotEntity('ipv6net', $net_id); default: throw new InvalidArgException('ip_bin', $ip_bin, "Invalid binary IP"); } }
function addIPAllocation() { $ip_bin = assertIPArg('ip'); assertUIntArg('object_id'); assertStringArg('bond_name', TRUE); genericAssertion('bond_type', 'enum/alloc_type'); if (getConfigVar('IPV4_JAYWALK') != 'yes' and NULL === getIPAddressNetworkId($ip_bin)) { showFuncMessage(__FUNCTION__, 'ERR1', array(ip_format($ip_bin))); return; } bindIPToObject($ip_bin, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']); ############################################################################################### # add zabbix interface $object = spotEntity('object', $_REQUEST['object_id']); $result = addInterface($object['dname'], $_REQUEST['ip']); if (isset($result['error'])) { showError('Adding zabbix interface is failed. Error message:' . $result['error']); } # END ############################################################################################### showFuncMessage(__FUNCTION__, 'OK'); return buildRedirectURL(NULL, NULL, array('hl_ip' => ip_format($ip_bin))); }
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; }
function addIPAllocation() { setFuncMessages(__FUNCTION__, array('OK' => 48, 'ERR1' => 170)); $ip_bin = assertIPArg('ip'); assertUIntArg('object_id'); assertStringArg('bond_name', TRUE); genericAssertion('bond_type', 'enum/alloc_type'); // check if address is alread allocated $address = getIPAddress($ip_bin); if (!empty($address['allocs']) && ($address['allocs'][0]['type'] != 'shared' || $_REQUEST['bond_type'] != 'shared')) { showWarning("IP " . ip_format($ip_bin) . " already in use by " . $address['allocs'][0]['object_name'] . " - " . $address['allocs'][0]['name']); } if (getConfigVar('IPV4_JAYWALK') != 'yes' and NULL === getIPAddressNetworkId($ip_bin)) { showFuncMessage(__FUNCTION__, 'ERR1', array(ip_format($ip_bin))); return; } if ($address['reserved'] && strlen($address['name'])) { showWarning("IP " . ip_format($ip_bin) . " reservation \"" . $address['name'] . "\" is removed"); //TODO ask to take reserved IP or not ! } bindIPToObject($ip_bin, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']); showFuncMessage(__FUNCTION__, 'OK'); return buildRedirectURL(NULL, NULL, array('hl_ip' => ip_format($ip_bin))); }
function dynamic_title_decoder($path_position) { global $sic, $page_by_realm; static $net_id; try { switch ($path_position) { case 'index': return array('name' => '/' . getConfigVar('enterprise'), 'params' => array()); case 'chapter': $chapter_no = assertUIntArg('chapter_no'); $chapters = getChapterList(); $chapter_name = isset($chapters[$chapter_no]) ? $chapters[$chapter_no]['name'] : 'N/A'; return array('name' => "Chapter '{$chapter_name}'", 'params' => array('chapter_no' => $chapter_no)); case 'user': $userinfo = spotEntity('user', assertUIntArg('user_id')); return array('name' => "Local user '" . $userinfo['user_name'] . "'", 'params' => array('user_id' => $userinfo['user_id'])); case 'ipv4rspool': $pool_info = spotEntity('ipv4rspool', assertUIntArg('pool_id')); return array('name' => !strlen($pool_info['name']) ? 'ANONYMOUS' : $pool_info['name'], 'params' => array('pool_id' => $pool_info['id'])); case 'ipv4vs': $vs_info = spotEntity('ipv4vs', assertUIntArg('vs_id')); return array('name' => $vs_info['dname'], 'params' => array('vs_id' => $vs_info['id'])); case 'ipvs': $vs_info = spotEntity('ipvs', assertUIntArg('vs_id')); return array('name' => $vs_info['name'], 'params' => array('vs_id' => $vs_info['id'])); case 'object': $object = spotEntity('object', assertUIntArg('object_id')); return array('name' => $object['dname'], 'params' => array('object_id' => $object['id'])); case 'location': $location = spotEntity('location', assertUIntArg('location_id')); return array('name' => $location['name'], 'params' => array('location_id' => $location['id'])); case 'row': global $pageno; switch ($pageno) { case 'rack': $rack = spotEntity('rack', assertUIntArg('rack_id')); return array('name' => $rack['row_name'], 'params' => array('row_id' => $rack['row_id'], 'location_id' => $rack['location_id'])); case 'row': $row_info = getRowInfo(assertUIntArg('row_id')); return array('name' => $row_info['name'], 'params' => array('row_id' => $row_info['id'], 'location_id' => $row_info['location_id'])); default: break; } case 'rack': $rack_info = spotEntity('rack', assertUIntArg('rack_id')); return array('name' => $rack_info['name'], 'params' => array('rack_id' => $rack_info['id'])); case 'search': if (isset($_REQUEST['q'])) { return array('name' => "search results for '{$_REQUEST['q']}'", 'params' => array('q' => $_REQUEST['q'])); } else { return array('name' => 'search results', 'params' => array()); } case 'file': $file = spotEntity('file', assertUIntArg('file_id')); return array('name' => niftyString($file['name'], 30, FALSE), 'params' => array('file_id' => $_REQUEST['file_id'])); case 'ipaddress': $address = getIPAddress(ip_parse($_REQUEST['ip'])); return array('name' => niftyString($address['ip'] . ($address['name'] != '' ? ' (' . $address['name'] . ')' : ''), 50, FALSE), 'params' => array('ip' => $address['ip'])); case 'ipv4net': case 'ipv6net': global $pageno; switch ($pageno) { case 'ipaddress': $net = spotNetworkByIP(ip_parse($_REQUEST['ip'])); $ret = array('name' => $net['ip'] . '/' . $net['mask'], 'params' => array('id' => $net['id'], 'page' => $net['realm'], 'hl_ip' => $_REQUEST['ip'])); return $ret; default: $net = spotEntity($path_position, assertUIntArg('id')); return array('name' => $net['ip'] . '/' . $net['mask'], 'params' => array('id' => $net['id'])); } break; case 'ipv4space': case 'ipv6space': global $pageno; switch ($pageno) { case 'ipaddress': $net_id = getIPAddressNetworkId(ip_parse($_REQUEST['ip'])); break; case 'ipv4net': case 'ipv6net': $net_id = $_REQUEST['id']; break; default: $net_id = NULL; } $params = array(); if (isset($net_id)) { $params = array('eid' => $net_id, 'hl_net' => 1, 'clear-cf' => ''); } unset($net_id); $ip_ver = preg_replace('/[^\\d]*/', '', $path_position); return array('name' => "IPv{$ip_ver} space", 'params' => $params); case 'vlandomain': global $pageno; switch ($pageno) { case 'vlandomain': $vdom_id = $_REQUEST['vdom_id']; break; case 'vlan': list($vdom_id, $dummy) = decodeVLANCK($_REQUEST['vlan_ck']); break; default: break; } $vdlist = getVLANDomainOptions(); if (!array_key_exists($vdom_id, $vdlist)) { throw new EntityNotFoundException('VLAN domain', $vdom_id); } return array('name' => niftyString("domain '" . $vdlist[$vdom_id] . "'", 20, FALSE), 'params' => array('vdom_id' => $vdom_id)); case 'vlan': return array('name' => formatVLANAsPlainText(getVLANInfo($sic['vlan_ck'])), 'params' => array('vlan_ck' => $sic['vlan_ck'])); case 'vst': $vst = spotEntity('vst', $sic['vst_id']); return array('name' => niftyString("template '" . $vst['description'] . "'", 50, FALSE), 'params' => array('vst_id' => $sic['vst_id'])); case 'dqueue': global $dqtitle; return array('name' => 'queue "' . $dqtitle[$sic['dqcode']] . '"', 'params' => array('qcode' => $sic['dqcode'])); default: break; } // default behaviour is throwing an exception throw new RackTablesError('dynamic_title decoding error', RackTablesError::INTERNAL); } catch (RackTablesError $e) { return array('name' => __FUNCTION__ . '() failure', 'params' => array()); } }
assertUIntArg('object_id'); // default value for bond_name if (!isset($_REQUEST['bond_name'])) { $_REQUEST['bond_name'] = ''; } // default value for bond_type // note on meanings of on 'bond_type' values: // 'regular': Connected // 'virtual': Loopback // 'shared': Shared // 'router': Router if (!isset($_REQUEST['bond_type'])) { $_REQUEST['bond_type'] = 'regular'; } // confirm that a network exists that matches the IP address if (getConfigVar('IPV4_JAYWALK') != 'yes' and NULL === getIPAddressNetworkId($ip_bin)) { throw new InvalidRequestArgException('ip', $_REQUEST['ip'], 'no network covering the requested IP address'); } bindIPToObject($ip_bin, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']); redirectUser($_SERVER['SCRIPT_NAME'] . '?method=get_object&object_id=' . $_REQUEST['object_id']); break; // delete an IP address allocation for an object // UI equivalent: /index.php? // UI handler: delIPAllocation() // delete an IP address allocation for an object // UI equivalent: /index.php? // UI handler: delIPAllocation() case 'delete_object_ip_allocation': require_once 'inc/init.php'; $ip_bin = assertIPArg('ip'); assertUIntArg('object_id');
function getEmployedVlans($object_id, $domain_vlanlist) { $employed = array(); // keyed by vlan_id. Value is dummy int // find persistent VLANs in domain foreach ($domain_vlanlist as $vlan_id => $vlan) { if ($vlan['vlan_type'] == 'compulsory') { $employed[$vlan_id] = 1; } } // find VLANs for object's L3 allocations $cell = spotEntity('object', $object_id); amplifyCell($cell); foreach (array('ipv4', 'ipv6') as $family) { $seen_nets = array(); foreach ($cell[$family] as $ip_bin => $allocation) { if ($net_id = getIPAddressNetworkId($ip_bin)) { if (!isset($seen_nets[$net_id])) { $seen_nets[$net_id] = 1; } else { continue; } $net = spotEntity("{$family}net", $net_id); foreach ($net['8021q'] as $vlan) { if (!isset($employed[$vlan['vlan_id']])) { $employed[$vlan['vlan_id']] = 1; } } } } } return array_keys($employed); }