function importRipeData() { $ripe_db = "http://rest.db.ripe.net/search.xml?source=ripe&query-string="; // Prepare update assertStringArg('ripe_query'); assertUIntArg('net_id'); assertStringArg('net_name'); //$nbad = $ngood = 0; $net_id = $_REQUEST['net_id']; $ripe_query = htmlspecialchars_decode($_REQUEST['ripe_query']); $ripe_result_str = file_get_contents($ripe_query, false, NULL); $ripe_result = simplexml_load_string($ripe_result_str); $filedir = realpath(dirname(__FILE__)); $ripe_xsl = simplexml_load_file($filedir . '/ripe_text.xsl'); $proc = new XSLTProcessor(); $proc->importStyleSheet($ripe_xsl); $newName = htmlspecialchars_decode($_REQUEST['net_name']); $newComment = trim($proc->transformToXML($ripe_result)); // Update usePreparedUpdateBlade('IPv4Network', array('name' => $newName, 'comment' => $newComment), array('id' => $net_id), 'AND'); // $retcode = 51; // if (!$nbad) // return showFuncMessage (__FUNCTION__, 'OK', array ($ngood)); // else // return showFuncMessage (__FUNCTION__, 'ERR', array ($nbad, $ngood)); }
/** Create a Virtual Machine in the specified pool @param name The name of the new Virtual Machine @param ip The IP address to assign the VM @param asset Asset tag to use (VM UUID) @param osInfo Operating System information (to be stored as a comment) @param taglist Array of tags to use for this new object @param poolID Virtual Machine pool to parent this object to */ function createVMInPool($name, $ip, $asset, $osInfo, $taglist, $poolID, $vmTypeID) { // make sure there's no duplicates if (getSearchResultByField('RackObject', array('id'), 'name', $name, '', 2)) { return FALSE; } // commitAddObject ($new_name, $new_label, $new_type_id, $new_asset_no, $taglist = array()) $newObject = commitAddObject($name, $name, $vmTypeID, $asset, $taglist); // add IP address to new object if (!empty($ip)) { bindIpToObject(ip_parse($ip), $newObject, 'eth0', 'regular'); } // add OS info to new object if (!empty($osInfo)) { usePreparedUpdateBlade('Object', array('comment' => $osInfo), array('id' => $newObject)); } // set container //commitLinkEntities($parent_entity_type, $parent_entity_id, $child_entity_type, $child_entity_id); commitLinkEntities("object", $poolID, "object", $newObject); }
function updIPv4RSP() { $rspool_id = getBypassValue(); $name = genericAssertion('name', 'string0'); $vsconfig = genericAssertion('vsconfig', 'string0'); $rsconfig = genericAssertion('rsconfig', 'string0'); $taglist = genericAssertion('taglist', 'array0'); usePreparedUpdateBlade("IPv4RSPool", array('name' => $name, 'vsconfig' => $vsconfig, 'rsconfig' => $rsconfig), array('id' => $rspool_id)); rebuildTagChainForEntity('ipv4rspool', $rspool_id, buildTagChainFromIds($taglist), TRUE); showFuncMessage(__FUNCTION__, 'OK', array($_REQUEST['name'])); }
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'); }
function setConfigVar($varname = '', $varvalue = '', $softfail = FALSE) { global $configCache; if (!isset($configCache)) { throw new RackTablesError('configuration cache is unavailable', RackTablesError::INTERNAL); } if ($varname == '' or !array_key_exists($varname, $configCache)) { throw new InvalidArgException('$varname', $varname); } if ($configCache[$varname]['is_hidden'] != 'no') { throw new InvalidRequestArgException('$varname', $varname, 'a hidden variable cannot be changed by user'); } if (!mb_strlen($varvalue) && $configCache[$varname]['emptyok'] != 'yes') { throw new InvalidRequestArgException('$varvalue', $varvalue, "'{$varname}' is required to have a non-empty value"); } if (mb_strlen($varvalue) && $configCache[$varname]['vartype'] == 'uint' && (!is_numeric($varvalue) or $varvalue < 0)) { throw new InvalidRequestArgException('$varvalue', $varvalue, "'{$varname}' can accept UINT values only"); } // Update cache only if the changes went into DB. usePreparedUpdateBlade('Config', array('varvalue' => $varvalue), array('varname' => $varname)); $configCache[$varname]['varvalue'] = $varvalue; }
function commitUpdateVS($vsid, $vip_bin, $vport = 0, $proto = '', $name = '', $vsconfig = '', $rsconfig = '') { if ($proto != 'MARK' && $vport <= 0) { throw new InvalidArgException('vport', $vport); } if (!strlen($proto)) { throw new InvalidArgException('proto', $proto); } return usePreparedUpdateBlade('IPv4VS', array('vip' => $vip_bin, 'vport' => $proto == 'MARK' ? NULL : $vport, 'proto' => $proto, 'name' => !strlen($name) ? NULL : $name, 'vsconfig' => !strlen($vsconfig) ? NULL : $vsconfig, 'rsconfig' => !strlen($rsconfig) ? NULL : $rsconfig), array('id' => $vsid)); }
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; }
/** * @expectedException PDOException */ public function testInvalidateRackLink() { usePreparedInsertBlade('EntityLink', array('parent_entity_type' => 'row', 'parent_entity_id' => self::$rowa_id, 'child_entity_type' => 'rack', 'child_entity_id' => self::$racka_id)); usePreparedInsertBlade('EntityLink', array('parent_entity_type' => 'row', 'parent_entity_id' => self::$rowb_id, 'child_entity_type' => 'rack', 'child_entity_id' => self::$rackb_id)); usePreparedUpdateBlade('EntityLink', array('child_entity_id' => self::$racka_id), array('id' => lastInsertID())); }
/** * @expectedException PDOException */ public function testUpdateLinkBetweenIncompatiblePorts() { usePreparedInsertBlade('Link', array('porta' => self::$porta, 'portb' => self::$portb)); usePreparedUpdateBlade('Link', array('porta' => self::$porta, 'portb' => self::$portc), array('porta' => self::$porta, 'portb' => self::$portb)); }
function updateVLANDomain() { $domain_id = assertUIntArg('vdom_id'); $group_id = assertUIntArg('group_id', TRUE); $description = assertStringArg('vdom_descr'); if (!$group_id) { $group_id = NULL; } else { $dominfo = getVLANDomain($domain_id); $parent_dominfo = getVLANDomain($group_id); if ($group_id == $domain_id) { throw new InvalidRequestArgException('group_id', $group_id, "domains should not be the same"); } if ($parent_dominfo['group_id'] || $dominfo['subdomc']) { throw new InvalidRequestArgException('group_id', $group_id, "Multi-level domain groups are not allowed"); } } usePreparedUpdateBlade('VLANDomain', array('group_id' => $group_id, 'description' => $description), array('id' => $domain_id)); showSuccess("VLAN domain updated successfully"); }
continue; } // finally update our value error_log("update attribute ID {$attr_id} from {$oldvalue} to {$value}"); commitUpdateAttrValue($object_id, $attr_id, $value); } } // see if we also need to update the object type $object = spotEntity('object', $object_id); if ($sic['object_type_id'] != $object['objtype_id']) { error_log("object type id for object {$object_id} will be changed from " . $object['objtype_id'] . ' to ' . $sic['object_type_id']); // check that the two types are compatible if (!array_key_exists($sic['object_type_id'], getObjectTypeChangeOptions($object_id))) { throw new InvalidRequestArgException('new type_id', $sic['object_type_id'], 'incompatible with requested attribute values'); } usePreparedUpdateBlade('RackObject', array('objtype_id' => $sic['object_type_id']), array('id' => $object_id)); } // Invalidate thumb cache of all racks objects could occupy. foreach (getResidentRacksData($object_id, FALSE) as $rack_id) { usePreparedDeleteBlade('RackThumbnail', array('rack_id' => $rack_id)); } // ok, now we're good $dbxlink->commit(); // redirect to the get_object URL for the edited object redirectUser($_SERVER['SCRIPT_NAME'] . "?method=get_object&object_id={$object_id}"); break; // update user-defined tags for an object // UI equivalent: /index.php?module=redirect&page=object&tab=tags&op=saveTags // UI handler: saveEntityTags() // update user-defined tags for an object // UI equivalent: /index.php?module=redirect&page=object&tab=tags&op=saveTags
function commitUpdateAttrForNetwork($network, $attr_id, $value = '') { switch ($network['realm']) { case 'ipv4net': $av_table = 'AttributeValue_IPv4'; break; case 'ipv6net': $av_table = 'AttributeValue_IPv6'; break; default: throw new InvalidArgException('realm', $network['realm'], "Unknown realm"); } $key = array('net_id' => $network['id'], 'attr_id' => $attr_id); $result = usePreparedSelectBlade("SELECT type AS attr_type, av.* FROM Attribute a " . "LEFT JOIN {$av_table} av ON a.id = av.attr_id AND av.net_id = ?" . "WHERE a.id = ?", array($network['id'], $attr_id)); if (!($row = $result->fetch(PDO::FETCH_ASSOC))) { throw new InvalidArgException('$attr_id', $attr_id, 'No such attribute #' . $attr_id); } $attr_type = $row['attr_type']; unset($result); switch ($attr_type) { case 'uint': case 'float': case 'string': $column = $attr_type . '_value'; break; case 'dict': case 'date': $column = 'uint_value'; break; default: throw new InvalidArgException('$attr_type', $attr_type, 'Unknown attribute type found in ' . $network['realm'] . ' #' . $network['id'] . ', attribute #' . $attr_id); } $ret = 0; if (isset($row['attr_id'])) { // AttributeValue row present in table if ($value == '') { $ret = usePreparedDeleteBlade($av_table, $key); } else { $ret = usePreparedUpdateBlade($av_table, array($column => $value), $key); } } elseif ($value != '') { $ret = usePreparedInsertBlade($av_table, $key + array($column => $value)); } return $ret; }
function sg_commitUpdatePortl2address($object_id, $port_id, $port_l2address) { $db_l2address = l2addressForDatabase($port_l2address); global $dbxlink; $dbxlink->exec('LOCK TABLES Port WRITE'); if (alreadyUsedL2Address($db_l2address, $object_id)) { $dbxlink->exec('UNLOCK TABLES'); // FIXME: it is more correct to throw InvalidArgException here // and convert it to InvalidRequestArgException at upper level, // when there is a mean to do that. throw new InvalidRequestArgException('port_l2address', $db_l2address, 'address belongs to another object'); } usePreparedUpdateBlade('Port', array('l2address' => $db_l2address === '' ? NULL : $db_l2address), array('id' => $port_id, 'object_id' => $object_id)); $dbxlink->exec('UNLOCK TABLES'); }
function updateRackTemperature() { //showFuncMessage (__FUNCTION__, 'OK', array ($_REQUEST['name'])); //$row = array ('rackid' => $_REQUEST['rack_id'], 'top' => 10, 'middle' => 20, 'bottom' => 30); //usePreparedInsertBlade ('racktemperature', $row); $rack_id = $_REQUEST['rack_id']; $result = usePreparedSelectBlade("SELECT * FROM racktemperature WHERE rackid = ?", array($rack_id)); $row = $result->fetch(PDO::FETCH_ASSOC); if (isset($row['rackid'])) { usePreparedUpdateBlade('racktemperature', array('top' => $_REQUEST['top'], 'middle' => $_REQUEST['middle'], 'bottom' => $_REQUEST['bottom']), array('rackid' => $_REQUEST['rack_id'])); } else { $row = array('rackid' => $_REQUEST['rack_id'], 'top' => $_REQUEST['top'], 'middle' => $_REQUEST['middle'], 'bottom' => $_REQUEST['bottom']); //$row = array ('rackid' => $_REQUEST['rack_id'], 'top' => 10, 'middle' => 20, 'bottom' => 30); usePreparedInsertBlade('racktemperature', $row); } }
function tableHandler() { $opspec = getOpspec(); switch ($opspec['action']) { case 'INSERT': usePreparedInsertBlade($opspec['table'], buildOpspecColumns($opspec, 'arglist')); $retcode = 48; break; case 'DELETE': $conjunction = array_key_exists('conjunction', $opspec) ? $opspec['conjunction'] : 'AND'; usePreparedDeleteBlade($opspec['table'], buildOpspecColumns($opspec, 'arglist'), $conjunction); $retcode = 49; break; case 'UPDATE': usePreparedUpdateBlade($opspec['table'], buildOpspecColumns($opspec, 'set_arglist'), buildOpspecColumns($opspec, 'where_arglist'), array_key_exists('conjunction', $opspec) ? $opspec['conjunction'] : 'AND'); $retcode = 51; break; default: throw new InvalidArgException('opspec/action', $opspec['action']); } showOneLiner($retcode); }
function updateNodePingCheck() { assertUIntArg('check_id'); assertUIntArg('account_id'); assertStringArg('np_check_id'); $check = getNodePingCheck($_REQUEST['check_id']); $account = getNodePingAccount($_REQUEST['account_id']); $nodeping = new NodePingClient(array('token' => $account['token'])); $np_check = $nodeping->check->get(array('id' => $_REQUEST['np_check_id'], 'limit' => 1, 'clean' => true)); if (isset($check['error'])) { return showFuncMessage(__FUNCTION__, 'ERR1', array('Error: ' . $np_check['error'])); } usePreparedUpdateBlade('NodePingCheck', array('account_id' => $_REQUEST['account_id'], 'np_check_id' => $_REQUEST['np_check_id'], 'label' => $np_check['label'], 'type' => $np_check['type'], 'target' => $np_check['parameters']['target'], 'check_interval' => $np_check['interval']), array('id' => $_REQUEST['check_id'])); return showFuncMessage(__FUNCTION__, 'OK', array(htmlspecialchars($np_check['label']))); }