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)); }
function handleOneShotRequest() { assertStringArg('realm'); assertStringArg('q'); switch ($_REQUEST['realm']) { case 'object': if (NULL === ($id = lookupEntityByString($_REQUEST['realm'], $_REQUEST['q']))) { echo "<h2>Nothing found for '{$_REQUEST['q']}'</h2>"; } else { echo "<script language='Javascript'>document.location='index.php?page=object&object_id={$id}';//</script>"; } break; default: dragon(); break; } }
function addObjectlog() { assertStringArg('logentry'); global $remote_username, $sic; if (isset($sic['object_id'])) { $object_id = $sic['object_id']; } elseif (isset($sic['location_id'])) { $object_id = $sic['location_id']; } else { $object_id = $sic['rack_id']; } usePreparedExecuteBlade('INSERT INTO ObjectLog SET object_id=?, user=?, date=NOW(), content=?', array($object_id, $remote_username, $sic['logentry'])); showSuccess('Log entry added'); }
function renderSLBFormAJAX() { global $pageno, $tabno; parse_str(assertStringArg('form'), $orig_request); parse_str(ltrim(assertStringArg('action'), '?'), $action); $pageno = $action['page']; $tabno = $action['tab']; printOpFormIntro($action['op'], $orig_request); $realm_list = array_diff(array('ipvs', 'object', 'ipv4rspool'), array($pageno)); echo '<table align=center><tr class="tdleft">'; foreach ($realm_list as $realm) { switch ($realm) { case 'object': $slb_cell = spotEntity('object', $orig_request['object_id']); break; case 'ipv4rspool': $slb_cell = spotEntity('ipv4rspool', $orig_request['rspool_id']); break; case 'ipvs': $slb_cell = spotEntity('ipvs', $orig_request['vs_id']); break; } echo '<td>'; renderSLBEntityCell($slb_cell); echo '</td>'; } $vsinfo = spotEntity('ipvs', $orig_request['vs_id']); amplifyCell($vsinfo); echo '<td><ul style="list-style: none">'; foreach ($vsinfo['ports'] as $port) { $key = $port['proto'] . '-' . $port['vport']; echo '<li><label><input type=checkbox name="enabled_ports[]" value="' . htmlspecialchars($key, ENT_QUOTES) . '" checked>' . formatVSPort($port) . '</label></li>'; } echo '</ul></td>'; echo '<td><ul style="list-style: none">'; foreach ($vsinfo['vips'] as $vip) { $key = ip_format($vip['vip']); echo '<li><label><input type=checkbox name="enabled_vips[]" value="' . htmlspecialchars($key, ENT_QUOTES) . '" checked>' . $key . '</label></li>'; } echo '</ul></td>'; echo '<td>'; printImageHREF('ADD', 'Configure LB', TRUE); echo '</td>'; echo '</tr></table>'; echo '</form>'; }
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 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"); }
function handlePopupPortLink() { assertPermission('depot', 'default'); assertUIntArg('port'); assertUIntArg('remote_port'); assertStringArg('cable', TRUE); $port_info = getPortInfo($_REQUEST['port']); $remote_port_info = getPortInfo($_REQUEST['remote_port']); $POIFC = getPortOIFCompat(); if (isset($_REQUEST['port_type']) and isset($_REQUEST['remote_port_type'])) { $type_local = $_REQUEST['port_type']; $type_remote = $_REQUEST['remote_port_type']; } else { $type_local = $port_info['oif_id']; $type_remote = $remote_port_info['oif_id']; } $matches = FALSE; $js_table = ''; foreach ($POIFC as $pair) { if ($pair['type1'] == $type_local && $pair['type2'] == $type_remote) { $matches = TRUE; break; } else { $js_table .= "POIFC['{$pair['type1']}-{$pair['type2']}'] = 1;\n"; } } if ($matches) { if ($port_info['oif_id'] != $type_local) { commitUpdatePortOIF($port_info['id'], $type_local); } if ($remote_port_info['oif_id'] != $type_remote) { commitUpdatePortOIF($remote_port_info['id'], $type_remote); } linkPorts($port_info['id'], $remote_port_info['id'], $_REQUEST['cable']); // patch cable? if (array_key_exists('heap_id', $_REQUEST)) { // Leave the compatibility constraints check up to the foreign keys. if (0 != ($heap_id = genericAssertion('heap_id', 'uint0'))) { $heaps = getPatchCableHeapSummary(); if (commitModifyPatchCableAmount($heap_id, -1)) { showSuccess('consumed a patch cable from ' . formatPatchCableHeapAsPlainText($heaps[$heap_id])); } else { showError('failed to consume a patch cable'); } } } showOneLiner(8, array(formatPortLink($port_info['object_id'], NULL, $port_info['id'], $port_info['name']), formatPort($remote_port_info))); addJS(<<<END window.opener.location.reload(true); window.close(); END , TRUE); backupLogMessages(); } else { // JS code to display port compatibility hint addJS(<<<END POIFC = {}; {$js_table} \$(document).ready(function () { \t\$('select.porttype').change(onPortTypeChange);\t \tonPortTypeChange(); }); function onPortTypeChange() { \tvar key = \$('*[name=port_type]')[0].value + '-' + \$('*[name=remote_port_type]')[0].value; \tif (POIFC[key] == 1) \t{ \t\t\$('#hint-not-compat').hide(); \t\t\$('#hint-compat').show(); \t} \telse \t{ \t\t\$('#hint-compat').hide(); \t\t\$('#hint-not-compat').show(); \t} } END , TRUE); addCSS(<<<END .compat-hint { \tdisplay: none; \tfont-size: 125%; } .compat-hint#hint-compat { \tcolor: green; } .compat-hint#hint-not-compat { \tcolor: #804040; } END , TRUE); // render port type editor form echo '<form method=GET>'; echo '<input type=hidden name="module" value="popup">'; echo '<input type=hidden name="helper" value="portlist">'; echo '<input type=hidden name="port" value="' . $port_info['id'] . '">'; echo '<input type=hidden name="remote_port" value="' . $remote_port_info['id'] . '">'; echo '<input type=hidden name="cable" value="' . htmlspecialchars($_REQUEST['cable'], ENT_QUOTES) . '">'; echo '<p>The ports you have selected are not compatible. Please select a compatible transceiver pair.'; echo '<p>'; echo formatPort($port_info) . ' '; if ($port_info['iif_id'] == 1) { echo formatPortIIFOIF($port_info); echo '<input type=hidden name="port_type" value="' . $port_info['oif_id'] . '">'; } else { echo '<label>' . $port_info['iif_name'] . ' '; printSelect(getExistingPortTypeOptions($port_info), array('class' => 'porttype', 'name' => 'port_type'), $type_local); echo '</label>'; } echo ' — '; if ($remote_port_info['iif_id'] == 1) { echo formatPortIIFOIF($remote_port_info); echo '<input type=hidden name="remote_port_type" value="' . $remote_port_info['oif_id'] . '">'; } else { echo '<label>' . $remote_port_info['iif_name'] . ' '; printSelect(getExistingPortTypeOptions($remote_port_info), array('class' => 'porttype', 'name' => 'remote_port_type'), $type_remote); echo '</label>'; } echo ' ' . formatPort($remote_port_info); echo '<p class="compat-hint" id="hint-not-compat">✕ Not compatible port types</p>'; echo '<p class="compat-hint" id="hint-compat">✔ Compatible port types</p>'; echo '<p><input type=submit name="do_link" value="Link">'; } }
$words = readChapter($_REQUEST['chapter_no'], 'o'); if (!in_array($_REQUEST['dict_value'], $words)) { throw new InvalidArgException('dict_value', $_REQUEST['dict_value'], "invalid argument: no such value in chapter ID " . $_REQUEST['chapter_no']); } usePreparedDeleteBlade('Dictionary', array('chapter_id' => $_REQUEST['chapter_no'], 'dict_value' => $_REQUEST['dict_value'])); sendAPIResponse(array(), array('message' => 'dictionary entry deleted successfully', 'chapter_no' => $_REQUEST['chapter_no'], 'dict_value' => $_REQUEST['dict_value'])); break; // perform a generic search // UI equivalent: /index.php?page=search // UI handler: searchEntitiesByText() // perform a generic search // UI equivalent: /index.php?page=search // UI handler: searchEntitiesByText() case 'search': require_once 'inc/init.php'; assertStringArg('term', TRUE); sendAPIResponse(searchEntitiesByText($_REQUEST['term'])); break; // <<DESCRIPTION>> // UI equivalent: /index.php?page= // UI handler: () //case '': // require_once 'inc/init.php'; // ...do stuff... // sendAPIResponse(); // break; // <<DESCRIPTION>> // UI equivalent: /index.php?page= // UI handler: () //case '': // require_once 'inc/init.php';
function genericAssertion($argname, $argtype) { global $sic; switch ($argtype) { case 'string': assertStringArg($argname); break; case 'string0': assertStringArg($argname, TRUE); break; case 'uint': assertUIntArg($argname); break; case 'uint-uint': assertStringArg($argname); if (1 != preg_match('/^[1-9][0-9]*-[1-9][0-9]*$/', $_REQUEST[$argname])) { throw new InvalidRequestArgException($argname, $_REQUEST[$argname], 'illegal format'); } break; case 'uint0': assertUIntArg($argname, TRUE); break; case 'inet': assertIPArg($argname); break; case 'inet4': assertIPv4Arg($argname); break; case 'inet6': assertIPv6Arg($argname); break; case 'l2address': assertStringArg($argname); case 'l2address0': assertStringArg($argname, TRUE); try { l2addressForDatabase($sic[$argname]); } catch (InvalidArgException $e) { throw new InvalidRequestArgException($argname, $sic[$argname], 'malformed MAC/WWN address'); } break; case 'tag': assertStringArg($argname); if (!validTagName($sic[$argname])) { throw new InvalidRequestArgException($argname, $sic[$argname], 'Invalid tag name'); } break; case 'pcre': assertPCREArg($argname); break; case 'json': assertStringArg($argname); if (NULL === json_decode($sic[$argname], TRUE)) { throw new InvalidRequestArgException($argname, '(omitted)', 'Invalid JSON code received from client'); } break; case 'array': if (!array_key_exists($argname, $_REQUEST)) { throw new InvalidRequestArgException($argname, '(missing argument)'); } if (!is_array($_REQUEST[$argname])) { throw new InvalidRequestArgException($argname, '(omitted)', 'argument is not an array'); } break; case 'enum/attr_type': assertStringArg($argname); if (!in_array($sic[$argname], array('uint', 'float', 'string', 'dict', 'date'))) { throw new InvalidRequestArgException($argname, $sic[$argname], 'Unknown value'); } break; case 'enum/vlan_type': assertStringArg($argname); // "Alien" type is not valid until the logic is fixed to implement it in full. if (!in_array($sic[$argname], array('ondemand', 'compulsory'))) { throw new InvalidRequestArgException($argname, $sic[$argname], 'Unknown value'); } break; case 'enum/wdmstd': assertStringArg($argname); global $wdm_packs; if (!array_key_exists($sic[$argname], $wdm_packs)) { throw new InvalidRequestArgException($argname, $sic[$argname], 'Unknown value'); } break; case 'enum/ipproto': assertStringArg($argname); global $vs_proto; if (!array_key_exists($sic[$argname], $vs_proto)) { throw new InvalidRequestArgException($argname, $sic[$argname], 'Unknown value'); } break; case 'enum/alloc_type': assertStringArg($argname); if (!in_array($sic[$argname], array('regular', 'shared', 'virtual', 'router'))) { throw new InvalidRequestArgException($argname, $sic[$argname], 'Unknown value'); } break; case 'enum/dqcode': assertStringArg($argname); global $dqtitle; if (!array_key_exists($sic[$argname], $dqtitle)) { throw new InvalidRequestArgException($argname, $sic[$argname], 'Unknown value'); } break; case 'iif': if (!array_key_exists($sic[$argname], getPortIIFOptions())) { throw new InvalidRequestArgException($argname, $sic[$argname], 'Unknown value'); } break; case 'vlan': case 'vlan1': genericAssertion($argname, 'uint'); if ($argtype == 'vlan' and $sic[$argname] == VLAN_DFL_ID) { throw new InvalidRequestArgException($argname, $sic[$argname], 'default VLAN cannot be changed'); } if ($sic[$argname] > VLAN_MAX_ID or $sic[$argname] < VLAN_MIN_ID) { throw new InvalidRequestArgException($argname, $sic[$argname], 'out of valid range'); } break; case 'rackcode/expr': genericAssertion($argname, 'string0'); if ($sic[$argname] == '') { return; } $parse = spotPayload($sic[$argname], 'SYNT_EXPR'); if ($parse['result'] != 'ACK') { throw new InvalidRequestArgException($argname, $sic[$argname], 'RackCode parsing error'); } break; default: throw new InvalidArgException('argtype', $argtype); // comes not from user's input } }
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; }
ob_clean(); showError('Database error: ' . $e->getMessage()); } catch (RTPermissionDenied $e) { ob_clean(); showError('Operation not permitted'); } redirectUser($location); // any other error requires no special handling and will be caught outside break; case 'popup': require_once 'inc/popup.php'; require_once 'inc/init.php'; prepareNavigation(); fixContext(); assertPermission(); $helper = assertStringArg('helper'); header('Content-Type: text/html; charset=UTF-8'); // call the main handler - page or tab handler. if (isset($popuphandler[$helper]) and is_callable($popuphandler[$helper])) { call_user_func($popuphandler[$helper], $helper); } else { throw new RackTablesError("Missing handler function for node '{$handler}'", RackTablesError::INTERNAL); } $contents = ob_get_contents(); ob_clean(); renderPopupHTML($contents); break; case 'upgrade': require_once 'inc/config.php'; // for CODE_VERSION require_once 'inc/database.php';
function handleNetworkAttrsChange() { genericAssertion('num_attrs', 'uint0'); global $dbxlink, $sic, $pageno; $network = spotEntity($pageno === 'ipv4net' ? 'ipv4net' : 'ipv6net', getBypassValue()); $dbxlink->beginTransaction(); // Update optional attributes $oldvalues = getAttrValuesForNetwork($network); for ($i = 0; $i < $_REQUEST['num_attrs']; $i++) { genericAssertion("{$i}_attr_id", 'uint'); $attr_id = $_REQUEST["{$i}_attr_id"]; if (!array_key_exists($attr_id, $oldvalues)) { throw new InvalidRequestArgException('attr_id', $attr_id, 'malformed request'); } $value = $_REQUEST["{$i}_value"]; if ('date' == $oldvalues[$attr_id]['type']) { assertDateArg("{$i}_value", TRUE); if ($value != '') { $value = strtotime($value); } } # Delete attribute and move on, when the field is empty or if the field # type is a dictionary and it is the "--NOT SET--" value of 0. if ($value == '' || $oldvalues[$attr_id]['type'] == 'dict' && $value == 0) { if (permitted(NULL, NULL, NULL, array(array('tag' => '$attr_' . $attr_id)))) { commitUpdateAttrForNetwork($network, $attr_id); } else { showError('Permission denied, "' . $oldvalues[$attr_id]['name'] . '" left unchanged'); } continue; } // The value could be uint/float, but we don't know ATM. Let SQL // server check this and complain. assertStringArg("{$i}_value"); switch ($oldvalues[$attr_id]['type']) { case 'uint': case 'float': case 'string': case 'date': $oldvalue = $oldvalues[$attr_id]['value']; break; case 'dict': $oldvalue = $oldvalues[$attr_id]['key']; break; default: } if ($value === $oldvalue) { // ('' == 0), but ('' !== 0) continue; } if (permitted(NULL, NULL, NULL, array(array('tag' => '$attr_' . $attr_id)))) { commitUpdateAttrForNetwork($network, $attr_id, $value); } else { showError('Permission denied, "' . $oldvalues[$attr_id]['name'] . '" left unchanged'); } } $dbxlink->commit(); return showSuccess("Attributes were updated successfully"); }
function deleteVlan() { assertStringArg('vlan_ck'); $confports = getVLANConfiguredPorts($_REQUEST['vlan_ck']); if (!empty($confports)) { throw new RackTablesError("You can not delete vlan which has assosiated ports"); } list($vdom_id, $vlan_id) = decodeVLANCK($_REQUEST['vlan_ck']); usePreparedDeleteBlade('VLANDescription', array('domain_id' => $vdom_id, 'vlan_id' => $vlan_id)); showSuccess("VLAN {$vlan_id} has been deleted"); return buildRedirectURL('vlandomain', 'default', array('vdom_id' => $vdom_id)); }
function copyLotOfObjects() { global $dbxlink; $dbrollback = 0; if (!$dbxlink->beginTransaction()) { throw new RTDatabaseError("can not start transaction"); } // do we need this ? $log = emptyLog(); $taglist = isset($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array(); assertUIntArg('global_type_id', TRUE); assertStringArg('namelist', TRUE); $global_type_id = $_REQUEST['global_type_id']; $source_object_id = $_REQUEST['object_id']; $source_object = spotEntity('object', $source_object_id); amplifyCell($source_object); // only call amplifyCell_object_Backend_Port if we have function linkmgmt_linkPorts from linkmgmt.php if (function_exists('amplifyCell_object_Backend_Port') && function_exists('linkmgmt_linkPorts')) { amplifyCell_object_Backend_Port($source_object); } if ($global_type_id == 0 or !strlen($_REQUEST['namelist'])) { // Log something reasonable with showError Here // We do not have names to copy our object to ! // Pls check what makes $global_type_id == 0 an error $log = mergeLogs($log, oneLiner(186)); return; } // The name extractor below was stolen from ophandlers.php:addMultiPorts() $names1 = explode("\n", $_REQUEST['namelist']); $names2 = array(); foreach ($names1 as $line) { $parts = explode('\\r', $line); reset($parts); if (!strlen($parts[0])) { continue; } else { $names2[] = rtrim($parts[0]); } } foreach ($names2 as $name_or_csv) { $label = ''; $asset_no = ''; $object_name = ''; $regexp = '/^\\"([^\\"]*)\\","([^\\"]*)\\","([^\\"]*)\\"/'; $object_name_or_csv = htmlspecialchars_decode($name_or_csv, ENT_QUOTES); // error_log( "$regexp $object_name" ); if (preg_match($regexp, $object_name_or_csv, $matches)) { $object_name = $matches[1]; $label = $matches[2]; $asset_no = $matches[3]; } else { $object_name = $name_or_csv; } try { $object_id = commitAddObject($object_name, $label, $global_type_id, $asset_no, $taglist); if (!$object_id) { throw new RTDatabaseError("could not create {$object_name}"); } $info = spotEntity('object', $object_id); amplifyCell($info); foreach ($source_object['ports'] as $source_port) { $update_port = 0; foreach ($info['ports'] as $new_port) { if ($new_port['name'] == $source_port['name']) { commitUpdatePort($object_id, $new_port['id'], $new_port['name'], $new_port['oif_id'], $source_port['label'], ""); $update_port = 1; } } if ($update_port) { true; } else { commitAddPort($object_id, $source_port['name'], sprintf("%s-%s", $source_port['iif_id'], $source_port['oif_id']), $source_port['label'], ""); } } // Copy Backendlinks only start if we ghave function linkmgmt_linkPorts from linkmgmt.php if (function_exists('amplifyCell_object_Backend_Port') && function_exists('linkmgmt_linkPorts')) { $info = spotEntity('object', $object_id); amplifyCell($info); amplifyCell_object_Backend_Port($info); /* showError( '<div align="left"><pre>\n===== Source Object ======\n\n' . varDumpToString ( $source_object ) . '\n\n===== New Object ======\n\n' . varDumpToString ( $info ) . '</pre></div>' ); */ $name_by_id = array(); foreach ($info['BackendPorts'] as $new_be_port) { $name_by_id[$new_be_port['name']] = $new_be_port['id']; } $linked_ports = array(); foreach ($source_object['BackendPorts'] as $source_be_port) { if ($source_be_port['object_id'] == $source_be_port['remote_object_id']) { // We have a Port that has the own object as remote object we want to copy this type of Linko // We have backend Links $new_be_port_a = $name_by_id[$source_be_port['name']]; $new_be_port_b = $name_by_id[$source_be_port['remote_name']]; if ($new_be_port_a && $new_be_port_b && !array_key_exists($new_be_port_a, $linked_ports) && !array_key_exists($new_be_port_b, $linked_ports)) { // error_log ( sprintf ('new_be_port_a %s // new_be_port_b %s // cableid %s', $new_be_port_a , $new_be_port_b, $source_be_port['cableid'] )); $ret_val = linkmgmt_linkPorts($new_be_port_a, $new_be_port_b, 'back', $source_be_port['cableid']); // error_log ( sprintf (' linkmgmt_linkPorts ret val: "%s" ', $ret_val)) ; if ($ret_val) { throw new RTDatabaseError("could not copy Backend Links for {$object_name} because: {$ret_val}"); } else { $linked_ports[$new_be_port_a] = True; $linked_ports[$new_be_port_b] = True; } } } } } // Copy attributes foreach (getAttrValues($source_object_id) as $record) { $value = $record['value']; switch ($record['type']) { case 'uint': case 'float': case 'string': $value = $record['value']; break; case 'dict': $value = $record['key']; break; default: } if (permitted(NULL, NULL, NULL, array(array('tag' => '$attr_' . $record['id'])))) { if (empty($value)) { commitUpdateAttrValue($object_id, $record['id']); } else { commitUpdateAttrValue($object_id, $record['id'], $value); } } else { showError('Permission denied, "' . $record['name'] . '" can not be set'); } } //$log = mergeLogs ($log, oneLiner (5, array ('<a href="' . // makeHref (array ('page' => 'object', 'tab' => 'default', 'object_id' => $object_id)) . // '">' . $info['dname'] . '</a>')) //); showSuccess(sprintf("Copied Object %s ; new Object: %s", $source_object['name'], formatPortLink($object_id, $info['dname'], 1, '', ''))); } catch (RTDatabaseError $e) { error_log("rolling back DB"); $dbrollback = 1; $dbxlink->rollBack(); $log = mergeLogs($log, oneLiner(147, array($object_name))); throw new RTDatabaseError($e->getMessage() . sprintf(' (%s)', $name_or_csv)); } } if (!$dbrollback) { $dbxlink->commit(); } // return buildWideRedirectURL ($log); }
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']))); }
function getNetUsageAJAX() { assertStringArg('net_id'); list($ip, $mask) = explode('/', $_REQUEST['net_id']); $ip_bin = ip_parse($ip); $net = spotNetworkByIP($ip_bin, $mask + 1); if (!isset($net) or $net['mask'] != $mask) { $net = constructIPRange($ip_bin, $mask); } loadIPAddrList($net); echo getRenderedIPNetCapacity($net); }
function renderPopupHTML() { global $pageno, $tabno; header('Content-Type: text/html; charset=UTF-8'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" style="height: 100%;"> <?php assertStringArg('helper'); $text = ''; switch ($_REQUEST['helper']) { case 'objlist': $pageno = 'object'; $tabno = 'default'; fixContext(); assertPermission(); $text .= getOutputOf('renderPopupObjectSelector'); break; case 'portlist': $pageno = 'depot'; $tabno = 'default'; fixContext(); assertPermission(); $text .= '<div style="background-color: #f0f0f0; border: 1px solid #3c78b5; padding: 10px; height: 100%; text-align: center; margin: 5px;">'; if (isset($_REQUEST['do_link'])) { $text .= getOutputOf('callHook', 'handlePopupPortLink'); } else { $text .= getOutputOf('callHook', 'renderPopupPortSelector'); } $text .= '</div>'; break; case 'inet4list': $pageno = 'ipv4space'; $tabno = 'default'; fixContext(); assertPermission(); $text .= getOutputOf('renderPopupIPv4Selector'); break; default: throw new InvalidRequestArgException('helper', $_REQUEST['helper']); } echo '<head><title>RackTables pop-up</title>'; printPageHeaders(); echo '</head>'; echo '<body style="height: 100%;">' . $text . '</body>'; ?> </html> <?php }
function getWattsPerRow() { // assertions // find the needed attributes global $nextorder; // Was this function called with a specific row_id? if (isset($_REQUEST['row_id'])) { assertStringArg('row_id'); $row_toshow = $_REQUEST['row_id']; } else { $row_toshow = -1; } //from renderRackspace(), interface.php:151 $found_racks = array(); $rows = array(); $cellfilter = getCellFilter(); $rackCount = 0; $order = 'odd'; // get rackspace information foreach (getAllRows() as $row_id => $rowInfo) { $rackList = filterCellList(listCells('rack', $row_id), $cellfilter['expression']); $found_racks = array_merge($found_racks, $rackList); $rows[] = array('location_id' => $rowInfo['location_id'], 'location_name' => $rowInfo['location_name'], 'row_id' => $row_id, 'row_name' => $rowInfo['name'], 'racks' => $rackList); $rackCount += count($rackList); } // Main layout starts. echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>"; // Left portlet with list of rows. echo "<tr><td class=pcleft width='50%'>"; startPortlet('Rack Rows (' . count($rows) . ')'); echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n"; foreach ($rows as $row) { $row_id = $row['row_id']; $row_name = $row['row_name']; $row_location = $row['location_name']; $rackList = $row['racks']; echo "<tr class=row_{$order}><td width='20%'></td><td class=tdleft>"; if (!count($rackList)) { echo "{$row_location} - {$row_name} (empty row)"; } else { echo "<a href='" . makeHref(array('page' => 'reports', 'tab' => 'watts_per_row', 'row_id' => $row_id)) . "'>{$row_location} - {$row_name}</a>"; } echo "<td><tr>\n"; $order = $nextorder[$order]; } echo "</td></tr>\n"; echo "</table><br>\n"; finishPortlet(); echo "</td><td class=pcright>"; // Right Portlet: Draw the racks in the selected row if ($row_toshow > -1) { $rowInfo = getRowInfo($row_toshow); $cellfilter = getCellFilter(); $rackList = filterCellList(listCells('rack', $row_toshow), $cellfilter['expression']); $rackwidth = getRackImageWidth() * getConfigVar('ROW_SCALE'); // Maximum number of racks per row is proportionally less, but at least 1. $maxPerRow = max(floor(getConfigVar('RACKS_PER_ROW') / getConfigVar('ROW_SCALE')), 1); $rackListIdx = 0; $rowTotalWattage = 0; $order = 'odd'; startPortlet('Racks within ' . $rowInfo['name'] . ' (' . count($rackList) . ')'); echo "<table border=0 cellspacing=5 align='center'><tr>"; foreach ($rackList as $rack) { $rackTotalWattage = 0; // see renderRack(), interface.php:311 $rackData = spotEntity('rack', $rack['id']); amplifyCell($rackData); $objectChildren = getEntityRelatives('children', 'object', $objectData['id']); foreach ($rackData['mountedObjects'] as $object) { $objectData = spotEntity('object', $object); amplifyCell($objectData); foreach (getAttrValues($objectData['id']) as $record) { if ($record['name'] == 'Wattage consumption') { $rackTotalWattage += $record['value']; } } } if ($rackListIdx % $maxPerRow == 0) { echo $rackListIdx > 0 ? '</tr><tr>' : '<tr>'; } echo "<td align=center class=row_{$order}><a href='" . makeHref(array('page' => 'rack', 'rack_id' => $rack['id'])) . "'>"; echo "<img border=0 width={$rackwidth} height=" . getRackImageHeight($rack['height']) * getConfigVar('ROW_SCALE'); echo " title='{$rack['height']} units'"; echo "src='?module=image&img=minirack&rack_id={$rack['id']}'>"; echo "<br>{$rack['name']} ({$rackTotalWattage})</a></td>"; $order = $nextorder[$order]; $rackListIdx++; $rowTotalWattage += $rackTotalWattage; } echo "</tr><tr><td align=center colspan="; print count($rackList); echo "><br><b>The row total for attribute Wattage consuption is: {$rowTotalWattage}</b></td>\n"; echo "</tr></table>\n"; finishPortlet(); } echo "</td></tr></table>"; }