public static function setUpBeforeClass() { // add sample locations self::$first_location_id = $parent_location_id = commitAddObject('unit test location 0', NULL, 1562, NULL); for ($i = 1; $i <= self::$num_children; $i++) { $child_location_id = commitAddObject("unit test location {$i}", NULL, 1562, NULL); commitLinkEntities('location', $parent_location_id, 'location', $child_location_id); $parent_location_id = $child_location_id; } self::$last_location_id = $parent_location_id; // add sample objects usePreparedInsertBlade('Dictionary', array('chapter_id' => 1, 'dict_value' => 'unit test object type')); self::$objtype_id = lastInsertID(); commitSupplementOPC(self::$objtype_id, self::$objtype_id); self::$first_object_id = $parent_object_id = commitAddObject('unit test object 0', NULL, self::$objtype_id, NULL); for ($i = 1; $i <= self::$num_children; $i++) { $child_object_id = commitAddObject("unit test object {$i}", NULL, self::$objtype_id, NULL); commitLinkEntities('object', $parent_object_id, 'object', $child_object_id); $parent_object_id = $child_object_id; } self::$last_object_id = $parent_object_id; // add sample tags usePreparedInsertBlade('TagTree', array('tag' => 'unit test tag 0')); self::$first_tag_id = $parent_tag_id = lastInsertID(); for ($i = 1; $i <= self::$num_children; $i++) { usePreparedInsertBlade('TagTree', array('parent_id' => $parent_tag_id, 'tag' => "unit test tag {$i}")); $parent_tag_id = lastInsertID(); } self::$last_tag_id = $parent_tag_id; }
public function setUp() { // add sample data usePreparedInsertBlade('TagTree', array('tag' => 'unit test tag a')); $this->taga_id = lastInsertID(); usePreparedInsertBlade('TagTree', array('tag' => 'unit test tag b')); $this->tagb_id = lastInsertID(); usePreparedInsertBlade('TagTree', array('tag' => 'unit test tag c')); $this->tagc_id = lastInsertID(); }
public static function setUpBeforeClass() { // add sample data usePreparedInsertBlade('Dictionary', array('chapter_id' => 1, 'dict_value' => 'unit test object type')); self::$objtype_id = lastInsertID(); commitSupplementOPC(self::$objtype_id, self::$objtype_id); self::$objecta_id = commitAddObject('unit test object a', NULL, self::$objtype_id, NULL); self::$objectb_id = commitAddObject('unit test object b', NULL, self::$objtype_id, NULL); self::$objectc_id = commitAddObject('unit test object c', NULL, self::$objtype_id, NULL); self::$locationa_id = commitAddObject('unit test location a', NULL, 1562, NULL); self::$locationb_id = commitAddObject('unit test location b', NULL, 1562, NULL); self::$locationc_id = commitAddObject('unit test location c', NULL, 1562, NULL); }
function commitUpdateVSTRules($vst_id, $mutex_rev, $rules) { global $dbxlink, $remote_username; $dbxlink->beginTransaction(); $result = usePreparedSelectBlade('SELECT mutex_rev, saved_by FROM VLANSwitchTemplate ' . 'WHERE id = ? FOR UPDATE', array($vst_id)); $vst = $result->fetch(PDO::FETCH_ASSOC); unset($result); if ($vst['mutex_rev'] != $mutex_rev) { throw new InvalidRequestArgException('mutex_rev', $mutex_rev, "already saved by {$vst['saved_by']}"); } usePreparedDeleteBlade('VLANSTRule', array('vst_id' => $vst_id)); foreach ($rules as $rule) { usePreparedInsertBlade('VLANSTRule', array_merge(array('vst_id' => $vst_id), $rule)); } usePreparedExecuteBlade('UPDATE VLANSwitchTemplate SET mutex_rev=mutex_rev+1, saved_by=? WHERE id=?', array($remote_username, $vst_id)); $dbxlink->commit(); }
function commitCreateRSPool($name = '', $vsconfig = '', $rsconfig = '', $tagidlist = array()) { usePreparedInsertBlade('IPv4RSPool', array('name' => !strlen($name) ? NULL : $name, 'vsconfig' => !strlen($vsconfig) ? NULL : $vsconfig, 'rsconfig' => !strlen($rsconfig) ? NULL : $rsconfig)); $new_pool_id = lastInsertID(); lastCreated('ipv4rspool', $new_pool_id); produceTagsForNewRecord('ipv4rspool', $tagidlist, $new_pool_id); return $new_pool_id; }
function convertSLBTablesToBinIPs() { global $dbxlink; $dbxlink->query("DROP TABLE IF EXISTS `IPv4VS_new`, `IPv4RS_new`, `IPv4VS_old`, `IPv4RS_old`"); $dbxlink->query(<<<END CREATE TABLE `IPv4VS_new` ( `id` int(10) unsigned NOT NULL auto_increment, `vip` varbinary(16) NOT NULL, `vport` smallint(5) unsigned default NULL, `proto` enum('TCP','UDP','MARK') NOT NULL default 'TCP', `name` char(255) default NULL, `vsconfig` text, `rsconfig` text, PRIMARY KEY (`id`), KEY `vip` (`vip`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 END ); $result = $dbxlink->query("SELECT * FROM IPv4VS"); $rows = $result->fetchAll(PDO::FETCH_ASSOC); unset($result); foreach ($rows as $row) { $row['vip'] = ip4_int2bin($row['vip']); usePreparedInsertBlade('IPv4VS_new', $row); } $dbxlink->query(<<<END CREATE TABLE `IPv4RS_new` ( `id` int(10) unsigned NOT NULL auto_increment, `inservice` enum('yes','no') NOT NULL default 'no', `rsip` varbinary(16) NOT NULL, `rsport` smallint(5) unsigned default NULL, `rspool_id` int(10) unsigned default NULL, `rsconfig` text, `comment` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), KEY `rsip` (`rsip`), UNIQUE KEY `pool-endpoint` (`rspool_id`,`rsip`,`rsport`), CONSTRAINT `IPRS-FK` FOREIGN KEY (`rspool_id`) REFERENCES `IPv4RSPool` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 END ); $result = $dbxlink->query("SELECT * FROM IPv4RS"); $rows = $result->fetchAll(PDO::FETCH_ASSOC); unset($result); foreach ($rows as $row) { $row['rsip'] = ip4_int2bin($row['rsip']); usePreparedInsertBlade('IPv4RS_new', $row); } $dbxlink->query(<<<END RENAME TABLE \t`IPv4VS` TO `IPv4VS_old`, \t`IPv4VS_new` TO `IPv4VS`, \t`IPv4RS` TO `IPv4RS_old`, \t`IPv4RS_new` TO `IPv4RS` END ); // re-create foreign key in IPv4LB $dbxlink->query("ALTER TABLE `IPv4LB` DROP FOREIGN KEY `IPv4LB-FK-vs_id`"); $dbxlink->query("ALTER TABLE `IPv4LB` ADD CONSTRAINT `IPv4LB-FK-vs_id` FOREIGN KEY (`vs_id`) REFERENCES `IPv4VS` (`id`)"); $dbxlink->query("DROP TABLE `IPv4VS_old`, `IPv4RS_old`"); // re-create foreign key in IPv4RS $dbxlink->query("ALTER TABLE `IPv4RS` DROP FOREIGN KEY `IPRS-FK`"); $dbxlink->query("ALTER TABLE `IPv4RS` ADD CONSTRAINT `IPv4RS-FK` FOREIGN KEY (`rspool_id`) REFERENCES `IPv4RSPool` (`id`) ON DELETE CASCADE"); }
function initRackTablesItem($objectDatas) { // zabbix item data $params = array('output' => 'extend'); $result = doPost('item.get', $params); $items = isset($result['result']) ? $result['result'] : array(); foreach ($items as $item) { usePreparedInsertBlade('item_information', array('itemid' => $item['itemid'], 'objectid' => $objectDatas[$item['hostid']], 'hostid' => $item['hostid'], 'name' => $item['name'], 'type' => $item['type'], 'key_' => $item['key_'], 'interfaceid' => $item['interfaceid'], 'delay' => $item['delay'], 'history' => $item['history'], 'trends' => $item['trends'], 'value_type' => $item['value_type'], 'trapper_hosts' => $item['trapper_hosts'], 'units' => $item['units'], 'multiplier' => $item['multiplier'], 'delta' => $item['delta'], 'snmp_community' => $item['snmp_community'], 'snmp_oid' => $item['snmp_oid'], 'snmpv3_securityname' => $item['snmpv3_securityname'], 'snmpv3_securitylevel' => $item['snmpv3_securitylevel'], 'snmpv3_authpassphrase' => $item['snmpv3_authpassphrase'], 'snmpv3_privpassphrase' => $item['snmpv3_privpassphrase'], 'snmpv3_authprotocol' => $item['snmpv3_authprotocol'], 'snmpv3_privprotocol' => $item['snmpv3_privprotocol'], 'snmpv3_contextname' => $item['snmpv3_contextname'], 'formula' => $item['formula'], 'error' => $item['error'], 'lastlogsize' => $item['lastlogsize'], 'logtimefmt' => $item['logtimefmt'], 'templateid' => $item['templateid'], 'valuemapid' => $item['valuemapid'], 'delay_flex' => $item['delay_flex'], 'params' => $item['params'], 'ipmi_sensor' => $item['ipmi_sensor'], 'data_type' => $item['data_type'], 'authtype' => $item['authtype'], 'username' => $item['username'], 'password' => $item['password'], 'publickey' => $item['publickey'], 'privatekey' => $item['privatekey'], 'mtime' => $item['mtime'], 'flags' => $item['flags'], 'filter' => $item['filter'], 'port' => $item['port'], 'description' => $item['description'], 'inventory_link' => $item['inventory_link'], 'lifetime' => $item['lifetime'], 'status' => $item['status'])); } }
/** * @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 addNodePingCheck() { assertUIntArg('account_id'); assertStringArg('np_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($np_check['error'])) { return showFuncMessage(__FUNCTION__, 'ERR1', array('Error: ' . $np_check['error'])); } usePreparedInsertBlade('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'])); $check_id = lastInsertID(); global $sic; usePreparedInsertBlade('NodePingLink', array('check_id' => $check_id, 'object_id' => $sic['object_id'])); return showFuncMessage(__FUNCTION__, 'OK', array(htmlspecialchars($np_check['label']))); }
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 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(); $rf1 = $_REQUEST['rfid']; if (isset($_REQUEST['rfid'])) { // $rf1 = 1000000;//$_REQUEST['rfid']; $result = usePreparedSelectBlade("SELECT object_id FROM objecttorf WHERE rf_id = ?", array($rf1)); $row = $result->fetch(PDO::FETCH_ASSOC); if (isset($row)) { $object_id = $row['object_id']; } //получить значение из базы где rf1=njvenj //showError ('Permission deniedddddddd, "' . $object_id . '" left unchanged'); } $changecnt = 0; // Get a list of all of this object's parents, // then trim the list to only include parents that are racks $objectParents = getEntityRelatives('parents', 'object', $object_id); $parentRacks = array(); foreach ($objectParents as $parentData) { if ($parentData['entity_type'] == 'rack') { $parentRacks[] = $parentData['entity_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; } // 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)) { $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)) { $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) { if (!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'])); } showFuncMessage(__FUNCTION__, 'OK', array($changecnt)); }
function linkmgmt_linkPorts($porta, $portb, $linktype, $cable = NULL) { if ($porta == $portb) { throw new InvalidArgException('porta/portb', $porta, "Ports can't be the same"); } if ($linktype == 'back') { $table = 'LinkBackend'; $multilink = LM_MULTILINK; } else { $table = 'Link'; $multilink = false; } global $dbxlink; $dbxlink->exec('LOCK TABLES ' . $table . ' WRITE'); if (!$multilink) { $result = usePreparedSelectBlade('SELECT COUNT(*) FROM ' . $table . ' WHERE porta IN (?,?) OR portb IN (?,?)', array($porta, $portb, $porta, $portb)); if ($result->fetchColumn() != 0) { $dbxlink->exec('UNLOCK TABLES'); return "{$linktype} Port {$porta} or {$portb} is already linked"; } $result->closeCursor(); } if ($porta > $portb) { $tmp = $porta; $porta = $portb; $portb = $tmp; } $ret = FALSE !== usePreparedInsertBlade($table, array('porta' => $porta, 'portb' => $portb, 'cable' => mb_strlen($cable) ? $cable : '')); $dbxlink->exec('UNLOCK TABLES'); $ret = $ret and FALSE !== usePreparedExecuteBlade('UPDATE Port SET reservation_comment=NULL WHERE id IN(?, ?)', array($porta, $portb)); return $ret ? '' : 'query failed'; }
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 tableHandler() { $opspec = getOpspec(); switch ($opspec['action']) { case 'INSERT': switch ($opspec['table']) { case 'Attribute': $realm = 'attr'; break; case 'Chapter': $realm = 'chapter'; break; case 'Dictionary': $realm = 'dict'; break; case 'TagTree': $realm = 'tag'; break; case 'VLANSwitchTemplate': $realm = 'vst'; break; default: $realm = NULL; } usePreparedInsertBlade($opspec['table'], buildOpspecColumns($opspec, 'arglist')); if (isset($realm)) { lastCreated($realm, lastInsertID()); } $retcode = 48; break; case 'DELETE': usePreparedDeleteBlade($opspec['table'], buildOpspecColumns($opspec, 'arglist'), array_fetch($opspec, 'conjunction', 'AND')); $retcode = 49; break; case 'UPDATE': usePreparedUpdateBlade($opspec['table'], buildOpspecColumns($opspec, 'set_arglist'), buildOpspecColumns($opspec, 'where_arglist'), array_fetch($opspec, 'conjunction', 'AND')); $retcode = 51; break; default: throw new InvalidArgException('opspec/action', $opspec['action']); } showOneLiner($retcode); }
function addSLBIPLink($link_row) { global $dbxlink; $do_transaction = !isTransactionActive(); if ($do_transaction) { $dbxlink->beginTransaction(); } // lock on vip $result = usePreparedSelectBlade("SELECT * FROM VSIPs WHERE vip = ? FOR UPDATE", array($link_row['vip'])); unset($result); $ret = usePreparedInsertBlade('VSEnabledIPs', $link_row); $result = usePreparedSelectBlade("SELECT proto, vport FROM VSEnabledPorts vep INNER JOIN VSEnabledIPs vei USING (vs_id, object_id, rspool_id) WHERE vei.object_id = ? AND vip = ? HAVING COUNT(distinct proto,vport) != COUNT(vport)", array($link_row['object_id'], $link_row['vip'])); if ($row = $result->fetch(PDO::FETCH_ASSOC, 0)) { unset($result); if ($do_transaction) { $dbxlink->rollBack(); } throw new RTDatabaseError(sprintf("Duplicate link of %s [%s]:%s to object #%d", $row['proto'], ip_format($link_row['vip']), $row['vport'], $link_row['object_id'])); } if ($do_transaction) { $dbxlink->commit(); } return $ret; }
// add en entry to a chapter // UI equivalent: /index.php?module=redirect&page=chapter&tab=edit&op=add&chapter_no=10007&dict_value=asdf // UI handler: tableHandler() // add en entry to a chapter // UI equivalent: /index.php?module=redirect&page=chapter&tab=edit&op=add&chapter_no=10007&dict_value=asdf // UI handler: tableHandler() case 'add_chapter_entry': require_once 'inc/init.php'; assertUIntArg('chapter_no', TRUE); assertStringArg('dict_value', TRUE); // make sure the chapter exists $chapters = getChapterList(); if (!isset($chapters[$_REQUEST['chapter_no']])) { throw new InvalidArgException('chapter_no', $_REQUEST['chapter_no'], "invalid argument: no such chapter"); } usePreparedInsertBlade('Dictionary', array('chapter_id' => $_REQUEST['chapter_no'], 'dict_value' => $_REQUEST['dict_value'])); sendAPIResponse(array(), array('message' => 'dictionary entry added successfully', 'chapter_no' => $_REQUEST['chapter_no'])); break; // delete an entry from a chapter // UI equivalent: /index.php?page=chapter&module=redirect&op=del&dict_key=50228&tab=edit&chapter_no=10007 // UI handler: tableHandler() // delete an entry from a chapter // UI equivalent: /index.php?page=chapter&module=redirect&op=del&dict_key=50228&tab=edit&chapter_no=10007 // UI handler: tableHandler() case 'delete_chapter_entry': require_once 'inc/init.php'; assertUIntArg('chapter_no', TRUE); assertStringArg('dict_value', TRUE); // make sure the chapter exists $chapters = getChapterList(); if (!isset($chapters[$_REQUEST['chapter_no']])) {