function linkmgmt_oplinkPort() { $linktype = $_REQUEST['linktype']; $cable = $_REQUEST['cable']; /* check permissions */ if (!permitted(NULL, NULL, 'set_link')) { echo "Permission denied!"; return; } if (!isset($_REQUEST['link_list'])) { //portlist::var_dump_html($_REQUEST); $porta = $_REQUEST['port']; foreach ($_REQUEST['remote_ports'] as $portb) { $link_list[] = "{$porta}_{$portb}"; /* with no LM_MULTILINK process first value only */ if (!LM_MULTILINK) { break; } } } else { $link_list = $_REQUEST['link_list']; } foreach ($link_list as $link) { $ids = preg_split('/[^0-9]/', $link); $porta = $ids[0]; $portb = $ids[1]; $ret = linkmgmt_linkPorts($porta, $portb, $linktype, $cable); //error_log("$ret - $porta - $portb"); $port_info = getPortInfo($porta); $remote_port_info = getPortInfo($portb); showSuccess(sprintf('Port %s %s successfully linked with port %s %s', formatPortLink($port_info['id'], $port_info['name'], NULL, NULL), $linktype, formatPort($remote_port_info), $linktype)); } addJS(<<<END window.opener.location.reload(true); window.close(); END , TRUE); return; }
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); }