function updateRack() { assertUIntArg('row_id'); assertStringArg('name'); assertUIntArg('height'); assertStringArg('asset_no', TRUE); assertStringArg('comment', TRUE); $taglist = genericAssertion('taglist', 'array0'); $rack_id = getBypassValue(); ############################################################################################### # update zabbix group $rack = spotEntity("rack", $rack_id); if ($rack['name'] != $_REQUEST['name']) { $result = updateGroup($rack["name"], $_REQUEST["name"]); if (isset($result["error"])) { showError("Updating zabbix group is failed. Error message:" . $result["error"]); return; } } # update table rack_airconditioner if ($rack['row_id'] != $_REQUEST['row_id']) { usePreparedUpdateBlade('rack_airconditioner', array('row_id' => $_REQUEST['row_id']), array('rack_id' => $rack_id)); } # END ############################################################################################### usePreparedDeleteBlade('RackThumbnail', array('rack_id' => $rack_id)); commitUpdateRack($rack_id, $_REQUEST['row_id'], $_REQUEST['name'], $_REQUEST['height'], isCheckSet('has_problems', 'yesno'), $_REQUEST['asset_no'], $_REQUEST['comment']); updateObjectAttributes($rack_id); rebuildTagChainForEntity('rack', $rack_id, buildTagChainFromIds($taglist), TRUE); showFuncMessage(__FUNCTION__, 'OK', array($_REQUEST['name'])); }
function updateRack() { assertUIntArg('row_id'); assertStringArg('name'); assertUIntArg('height'); assertStringArg('asset_no', TRUE); assertStringArg('comment', TRUE); $taglist = genericAssertion('taglist', 'array0'); $rack_id = getBypassValue(); usePreparedDeleteBlade('RackThumbnail', array('rack_id' => $rack_id)); commitUpdateRack($rack_id, $_REQUEST['row_id'], $_REQUEST['name'], $_REQUEST['height'], isCheckSet('has_problems', 'yesno'), $_REQUEST['asset_no'], $_REQUEST['comment']); updateObjectAttributes($rack_id); rebuildTagChainForEntity('rack', $rack_id, buildTagChainFromIds($taglist), TRUE); showFuncMessage(__FUNCTION__, 'OK', array($_REQUEST['name'])); }
function importFingData() { $net = spotEntity('ipv4net', getBypassValue()); assertUIntArg('addrcount'); $nbad = $ngood = 0; for ($i = 1; $i <= $_REQUEST['addrcount']; $i++) { $inputname = "import_{$i}"; if (!isCheckSet($inputname)) { continue; } $ip_bin = assertIPv4Arg("addr_{$i}"); assertStringArg("descr_{$i}", TRUE); assertStringArg("rsvd_{$i}"); // Non-existent addresses will not have this argument set in request. $rsvd = 'no'; if ($_REQUEST["rsvd_{$i}"] == 'yes') { $rsvd = 'yes'; } try { if (!ip_in_range($ip_bin, $net)) { throw new InvalidArgException('ip_bin', $ip_bin); } updateAddress($ip_bin, $_REQUEST["descr_{$i}"], $rsvd); $ngood++; } catch (RackTablesError $e) { $nbad++; } } if (!$nbad) { showFuncMessage(__FUNCTION__, 'OK', array($ngood)); } else { showFuncMessage(__FUNCTION__, 'ERR', array($nbad, $ngood)); } }
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; }
case 'edit_object': require_once 'inc/init.php'; // check required args genericAssertion('object_id', 'uint0'); genericAssertion('object_name', 'string0'); genericAssertion('object_label', 'string0'); genericAssertion('object_asset_no', 'string0'); genericAssertion('object_comment', 'string0'); genericAssertion('object_type_id', 'uint'); // TODO: really required for API? $object_id = $_REQUEST['object_id']; // make this transactional, so we can double check the whole upate before committing at the end global $dbxlink, $sic; $dbxlink->beginTransaction(); // TODO: may need to wrap this in a try/catch block to redirect to API exception response commitUpdateObject($object_id, $_REQUEST['object_name'], $_REQUEST['object_label'], isCheckSet('object_has_problems', 'yesno'), $_REQUEST['object_asset_no'], $_REQUEST['object_comment']); // update optional attributes // get the valid / old values for the object $oldvalues = getAttrValues($object_id); // look for values to be updated. // note: in UI, a "num_attrs" input is used to loop and search for update fields foreach ($_REQUEST as $name => $value) { if (preg_match('/^attr_(\\d+)$/', $name, $matches)) { $attr_id = $matches[1]; // make sure the attribute actually exists in the object if (!array_key_exists($attr_id, $oldvalues)) { throw new InvalidRequestArgException('attr_id', $attr_id, 'malformed request'); } // convert date arguments if ('date' == $oldvalues[$attr_id]['type']) { // if given date looks like UNIX timestamp, leave as-is,
function renderPopupPortSelector() { if (isset($_REQUEST['do_link'])) { return handlePopupPortLink(); } assertPermission('depot', 'default'); assertUIntArg('port'); $port_id = $_REQUEST['port']; $port_info = getPortInfo($port_id); $in_rack = isCheckSet('in_rack'); // fill port filter structure $filter = array('racks' => array(), 'objects' => '', 'ports' => '', 'asset_no' => ''); if (isset($_REQUEST['filter-obj'])) { $filter['objects'] = trim($_REQUEST['filter-obj']); } if (isset($_REQUEST['filter-port'])) { $filter['ports'] = trim($_REQUEST['filter-port']); } if (isset($_REQUEST['filter-asset_no'])) { $filter['asset_no'] = trim($_REQUEST['filter-asset_no']); } if ($in_rack) { $object = spotEntity('object', $port_info['object_id']); if ($object['rack_id']) { // the object itself is mounted in a rack $filter['racks'] = getProximateRacks($object['rack_id'], getConfigVar('PROXIMITY_RANGE')); } elseif ($object['container_id']) { $container = spotEntity('object', $object['container_id']); if ($container['rack_id']) { $filter['racks'] = getProximateRacks($container['rack_id'], getConfigVar('PROXIMITY_RANGE')); } } } $spare_ports = array(); if (!empty($filter['racks']) || !empty($filter['objects']) || !empty($filter['ports']) || !empty($filter['asset_no'])) { $spare_ports = findSparePorts($port_info, $filter); } // display search form echo 'Link ' . formatPort($port_info) . ' to...'; echo '<form method=GET>'; startPortlet('Port list filter'); echo '<input type=hidden name="module" value="popup">'; echo '<input type=hidden name="helper" value="portlist">'; echo '<input type=hidden name="port" value="' . $port_id . '">'; echo '<table align="center" valign="bottom"><tr>'; echo '<td class="tdleft"><label>Object name:<br><input type=text size=8 name="filter-obj" value="' . htmlspecialchars($filter['objects'], ENT_QUOTES) . '"></label></td>'; echo '<td class="tdleft"><label>Asset tag:<br><input type=text size=8 name="filter-asset_no" value="' . htmlspecialchars($filter['asset_no'], ENT_QUOTES) . '"></label></td>'; echo '<td class="tdleft"><label>Port name:<br><input type=text size=6 name="filter-port" value="' . htmlspecialchars($filter['ports'], ENT_QUOTES) . '"></label></td>'; echo '<td class="tdleft" valign="bottom"><label><input type=checkbox name="in_rack"' . ($in_rack ? ' checked' : '') . '>Nearest racks</label></td>'; echo '<td valign="bottom"><input type=submit value="show ports"></td>'; echo '</tr></table>'; finishPortlet(); // display results startPortlet('Compatible spare ports'); if (empty($spare_ports)) { echo '(nothing found)'; } else { echo getSelect($spare_ports, array('name' => 'remote_port', 'size' => getConfigVar('MAXSELSIZE')), NULL, FALSE); echo "<p>Cable ID: <input type=text id=cable name=cable>"; // suggest patch cables where it makes sense $heaps = getPatchCableHeapOptionsForOIF($port_info['oif_id']); if (count($heaps)) { // Use + instead of array_merge() to avoid renumbering the keys. echo '<p>Patch cable: ' . getSelect(array(0 => 'none') + $heaps, array('name' => 'heap_id')); } echo "<p><input type='submit' value='Link' name='do_link'>"; } finishPortlet(); echo '</form>'; }
function queryTerminal($object_id, $commands, $tolerate_remote_errors = TRUE) { $objectInfo = spotEntity('object', $object_id); $endpoints = findAllEndpoints($object_id, $objectInfo['name']); if (count($endpoints) == 0) { throw new RTGatewayError('no management address set'); } if (count($endpoints) > 1) { throw new RTGatewayError('cannot pick management address'); } // telnet prompt and mode specification switch ($breed = detectDeviceBreed($object_id)) { case 'ios12': case 'fdry5': case 'ftos8': $protocol = 'netcat'; // default is netcat mode $prompt = '^(Login|Username|Password): $|^\\S+[>#]$'; // set the prompt in case user would like to specify telnet protocol break; case 'air12': $protocol = 'telnet'; # Aironet IOS is broken $prompt = '^(Username|Password): $|^\\S+[>#]$'; break; case 'vrp53': case 'vrp55': $protocol = 'telnet'; $prompt = '^\\[[^[\\]]+\\]$|^<[^<>]+>$|^(Username|Password):$|(?:\\[Y\\/N\\]|\\(Y\\/N\\)\\[[YN]\\]):?$'; break; case 'nxos4': $protocol = 'telnet'; $prompt = '(^([Ll]ogin|[Pp]assword):|[>#]) $'; break; case 'xos12': $protocol = 'telnet'; $prompt = ': $|\\.\\d+ # $|\\?\\s*\\([Yy]\\/[Nn]\\)\\s*$'; break; case 'jun10': $protocol = 'telnet'; $prompt = '^login: $|^Password:$|^\\S+@\\S+[>#] $'; break; case 'eos4': $protocol = 'telnet'; # strict RFC854 implementation, netcat won't work $prompt = '^(\\xf2?login|Username|Password): $|^\\S+[>#]$'; break; case 'ros11': $protocol = 'netcat'; # see ftos8 case $prompt = '^(User Name|\\rPassword):$|^\\r?\\S+# $'; break; case 'iosxr4': $protocol = 'telnet'; $prompt = '^\\r?(Login|Username|Password): $|^\\r?\\S+[>#]$'; break; case 'ucs': $protocol = 'ucssdk'; break; default: $protocol = 'netcat'; $prompt = NULL; } // set the default settings before calling user-defined callback $settings = array('hostname' => $endpoints[0], 'protocol' => $protocol, 'port' => NULL, 'prompt' => $prompt, 'username' => NULL, 'password' => NULL, 'timeout' => 15, 'connect_timeout' => 2, 'prompt_delay' => 0.001, 'sudo_user' => NULL, 'identity_file' => NULL); if (is_callable('terminal_settings')) { call_user_func('terminal_settings', $objectInfo, array(&$settings)); } // override settings if (!isset($settings['port']) and $settings['protocol'] == 'netcat') { $settings['port'] = 23; } $params = array($settings['hostname']); $params_from_settings = array(); switch ($settings['protocol']) { case 'telnet': case 'netcat': // prepend command list with vendor-specific disabling pager command switch ($breed) { case 'ios12': $commands = "terminal length 0\n" . $commands; break; case 'nxos4': case 'air12': case 'ftos8': $commands = "terminal length 0\nterminal no monitor\n" . $commands; break; case 'xos12': $commands = "disable clipaging\n" . $commands; break; case 'vrp55': $commands = "screen-length 0 temporary\n" . $commands; break; case 'fdry5': $commands = "skip-page-display\n" . $commands; break; case 'jun10': $commands = "set cli screen-length 0\n" . $commands; break; case 'eos4': $commands = "enable\nno terminal monitor\nterminal length 0\n" . $commands; break; case 'ros11': $commands = "terminal datadump\n" . $commands; $commands .= "\n\n"; # temporary workaround for telnet server break; case 'iosxr4': $commands = "terminal length 0\nterminal monitor disable\n" . $commands; break; case 'dlink': $commands = "disable clipaging\n" . $commands; break; } // prepend telnet commands by credentials if (isset($settings['password'])) { $commands = $settings['password'] . "\n" . $commands; } if (isset($settings['username'])) { $commands = $settings['username'] . "\n" . $commands; } // command-line options are specific to client: telnet or netcat switch ($settings['protocol']) { case 'telnet': $params_from_settings['port'] = 'port'; $params_from_settings['prompt'] = 'prompt'; $params_from_settings['connect-timeout'] = 'connect_timeout'; $params_from_settings['timeout'] = 'timeout'; $params_from_settings['prompt-delay'] = 'prompt_delay'; break; case 'netcat': $params_from_settings['p'] = 'port'; $params_from_settings['w'] = 'timeout'; $params_from_settings['b'] = 'ncbin'; break; } break; case 'ssh': $params_from_settings['port'] = 'port'; $params_from_settings['proto'] = 'proto'; $params_from_settings['username'] = '******'; $params_from_settings['i'] = 'identity_file'; $params_from_settings['sudo-user'] = '******'; $params_from_settings['connect-timeout'] = 'connect_timeout'; break; case 'ucssdk': # remote XML through a Python backend $params = array(); # reset # UCS in its current implementation besides the terminal_settings() provides # an additional username/password feed through the HTML from. Whenever the # user provides the credentials through the form, use these instead of the # credentials [supposedly] set by terminal_settings(). if ($script_mode != TRUE && !isCheckSet('use_terminal_settings')) { genericAssertion('ucs_login', 'string'); genericAssertion('ucs_password', 'string'); $settings['username'] = $_REQUEST['ucs_login']; $settings['password'] = $_REQUEST['ucs_password']; } foreach (array('hostname', 'username', 'password') as $item) { if (empty($settings[$item])) { throw new RTGatewayError("{$item} not available, check terminal_settings()"); } } $commands = "login {$settings['hostname']} {$settings['username']} {$settings['password']}\n" . $commands; break; default: throw RTGatewayError("Invalid terminal protocol '{$settings['protocol']}' specified"); } foreach ($params_from_settings as $param_name => $setting_name) { if (isset($settings[$setting_name])) { if (is_int($param_name)) { $params[] = $settings[$setting_name]; } else { $params[$param_name] = $settings[$setting_name]; } } } callHook('alterTerminalParams', $object_id, $tolerate_remote_errors, array(&$settings['protocol']), array(&$params)); $ret_code = callScript($settings['protocol'], $params, $commands, $out, $errors); if ($settings['protocol'] != 'ssh' || !$tolerate_remote_errors) { if (!empty($errors)) { throw new RTGatewayError("{$settings['protocol']} error: " . rtrim($errors)); } elseif ($ret_code !== 0) { throw new RTGatewayError("{$settings['protocol']} error: result code {$ret_code}"); } } elseif (!empty($errors)) { // ssh and tolerate and non-empty $errors foreach (explode("\n", $errors) as $line) { if (strlen($line)) { showWarning("{$settings['protocol']} {$settings['hostname']}: {$line}"); } } } return strtr($out, array("\r" => "")); // cut ^M symbols }
function makeGatewayParams($object_id, $tolerate_remote_errors, $ref_settings, $ref_commands) { $ret = array(); $settings =& $ref_settings[0]; $commands =& $ref_commands[0]; $prepend_credentials = FALSE; switch ($settings['protocol']) { case 'telnet': $prepend_credentials = TRUE; $params_from_settings['port'] = 'port'; $params_from_settings['prompt'] = 'prompt'; $params_from_settings['connect-timeout'] = 'connect_timeout'; $params_from_settings['timeout'] = 'timeout'; $params_from_settings['prompt-delay'] = 'prompt_delay'; $params_from_settings[] = $settings['hostname']; break; case 'netcat': $prepend_credentials = TRUE; $params_from_settings['p'] = 'port'; $params_from_settings['w'] = 'timeout'; $params_from_settings['b'] = 'ncbin'; $params_from_settings[] = $settings['hostname']; break; case 'sshnokey': $prepend_credentials = TRUE; $params_from_settings['proto'] = 'proto'; $params_from_settings['prompt'] = 'prompt'; $params_from_settings['prompt-delay'] = 'prompt_delay'; $params_from_settings['username'] = '******'; $params_from_settings['password'] = '******'; $params_from_settings[] = $settings['hostname']; break; case 'ssh': $params_from_settings['sudo-user'] = '******'; $params_from_settings[] = '--'; $params_from_settings['p'] = 'port'; $params_from_settings['l'] = 'username'; $params_from_settings['i'] = 'identity_file'; if (isset($settings['proto'])) { switch ($settings['proto']) { case 4: $params_from_settings[] = '-4'; break; case 6: $params_from_settings[] = '-6'; break; default: throw new RTGatewayError("Proto '{$settings['proto']}' is invalid. Valid protocols are: '4', '6'"); } } if (isset($settings['connect_timeout'])) { $params_from_settings[] = '-oConnectTimeout=' . $settings['connect_timeout']; } $params_from_settings[] = '-T'; $params_from_settings[] = '-oStrictHostKeyChecking=no'; $params_from_settings[] = '-oBatchMode=yes'; $params_from_settings[] = '-oCheckHostIP=no'; $params_from_settings[] = '-oLogLevel=ERROR'; $params_from_settings[] = $settings['hostname']; break; case 'ucssdk': # remote XML through a Python backend # UCS in its current implementation besides the terminal_settings() provides # an additional username/password feed through the HTML from. Whenever the # user provides the credentials through the form, use these instead of the # credentials [supposedly] set by terminal_settings(). global $script_mode; if ($script_mode != TRUE && !isCheckSet('use_terminal_settings')) { $settings['username'] = assertStringArg('ucs_login'); $settings['password'] = assertStringArg('ucs_password'); } foreach (array('hostname', 'username', 'password') as $item) { if (empty($settings[$item])) { throw new RTGatewayError("{$item} not available, check terminal_settings()"); } } $commands = "login {$settings['hostname']} {$settings['username']} {$settings['password']}\n" . $commands; break; default: throw new RTGatewayError("Invalid terminal protocol '{$settings['protocol']}' specified"); } // prepend commands by credentials if ($prepend_credentials) { if (isset($settings['password'])) { $commands = $settings['password'] . "\n" . $commands; } if (isset($settings['username'])) { $commands = $settings['username'] . "\n" . $commands; } } foreach ($params_from_settings as $param_name => $setting_name) { if (is_int($param_name)) { $ret[] = $setting_name; } elseif (isset($settings[$setting_name])) { $ret[$param_name] = $settings[$setting_name]; } } return $ret; }
function updateRack() { assertUIntArg('row_id'); assertStringArg('name'); assertUIntArg('height'); assertStringArg('asset_no', TRUE); assertStringArg('comment', TRUE); $rack_id = getBypassValue(); usePreparedDeleteBlade('RackThumbnail', array('rack_id' => $rack_id)); commitUpdateRack($rack_id, $_REQUEST['row_id'], $_REQUEST['name'], $_REQUEST['height'], isCheckSet('has_problems', 'yesno'), $_REQUEST['asset_no'], $_REQUEST['comment']); // Update optional attributes $oldvalues = getAttrValues($rack_id); $num_attrs = isset($_REQUEST['num_attrs']) ? $_REQUEST['num_attrs'] : 0; for ($i = 0; $i < $num_attrs; $i++) { assertUIntArg("{$i}_attr_id"); $attr_id = $_REQUEST["{$i}_attr_id"]; // Skip the 'height' attribute as it's already handled by commitUpdateRack // Also skip 'sort_order' if ($attr_id == 27 or $attr_id == 29) { continue; } // Field is empty, delete attribute and move on. OR if the field type is a dictionary and it is the --NOT SET-- value of 0 if (!strlen($_REQUEST["{$i}_value"]) || $oldvalues[$attr_id]['type'] == 'dict' && $_REQUEST["{$i}_value"] == 0) { commitUpdateAttrValue($rack_id, $attr_id); continue; } // The value could be uint/float, but we don't know ATM. Let SQL // server check this and complain. assertStringArg("{$i}_value"); $value = $_REQUEST["{$i}_value"]; switch ($oldvalues[$attr_id]['type']) { case 'uint': case 'float': case 'string': $oldvalue = $oldvalues[$attr_id]['value']; break; case 'dict': $oldvalue = $oldvalues[$attr_id]['key']; break; default: } if ($value === $oldvalue) { // ('' == 0), but ('' !== 0) continue; } commitUpdateAttrValue($rack_id, $attr_id, $value); } return showFuncMessage(__FUNCTION__, 'OK', array($_REQUEST['name'])); }
function updateRack() { assertUIntArg('row_id'); assertStringArg('name'); assertUIntArg('height'); assertStringArg('asset_no', TRUE); assertStringArg('comment', TRUE); $rack_id = getBypassValue(); usePreparedDeleteBlade('RackThumbnail', array('rack_id' => $rack_id)); commitUpdateRack($rack_id, $_REQUEST['row_id'], $_REQUEST['name'], $_REQUEST['height'], isCheckSet('has_problems', 'yesno'), $_REQUEST['asset_no'], $_REQUEST['comment']); updateObjectAttributes($rack_id); return showFuncMessage(__FUNCTION__, 'OK', array($_REQUEST['name'])); }
function renderPopupPortSelector() { assertUIntArg('port'); $port_id = $_REQUEST['port']; $port_info = getPortInfo($port_id); $in_rack = isCheckSet('in_rack'); // fill port filter structure $filter = array('racks' => array(), 'objects' => '', 'ports' => ''); if (isset($_REQUEST['filter-obj'])) { $filter['objects'] = trim($_REQUEST['filter-obj']); } if (isset($_REQUEST['filter-port'])) { $filter['ports'] = trim($_REQUEST['filter-port']); } if ($in_rack) { $object = spotEntity('object', $port_info['object_id']); if ($object['rack_id']) { $filter['racks'] = getProximateRacks($object['rack_id'], getConfigVar('PROXIMITY_RANGE')); } } $spare_ports = array(); if (!empty($filter['racks']) || !empty($filter['objects']) || !empty($filter['ports'])) { $spare_ports = findSparePorts($port_info, $filter); } // display search form echo 'Link ' . formatPort($port_info) . ' to...'; echo '<form method=GET>'; startPortlet('Port list filter'); echo '<input type=hidden name="module" value="popup">'; echo '<input type=hidden name="helper" value="portlist">'; echo '<input type=hidden name="port" value="' . $port_id . '">'; echo '<table align="center" valign="bottom"><tr>'; echo '<td class="tdleft"><label>Object name:<br><input type=text size=8 name="filter-obj" value="' . htmlspecialchars($filter['objects'], ENT_QUOTES) . '"></label></td>'; echo '<td class="tdleft"><label>Port name:<br><input type=text size=6 name="filter-port" value="' . htmlspecialchars($filter['ports'], ENT_QUOTES) . '"></label></td>'; echo '<td class="tdleft" valign="bottom"><label><input type=checkbox name="in_rack"' . ($in_rack ? ' checked' : '') . '>Nearest racks</label></td>'; echo '<td valign="bottom"><input type=submit value="show ports"></td>'; echo '</tr></table>'; finishPortlet(); // display results startPortlet('Compatible spare ports'); if (empty($spare_ports)) { echo '(nothing found)'; } else { echo getSelect($spare_ports, array('name' => 'remote_port', 'size' => getConfigVar('MAXSELSIZE')), NULL, FALSE); echo "<p>Cable ID: <input type=text id=cable name=cable>"; echo "<p><input type='submit' value='Link' name='do_link'>"; } finishPortlet(); echo '</form>'; }