Example #1
0
function importDPData()
{
    global $sic, $dbxlink;
    assertUIntArg('nports');
    $nignored = $ndone = 0;
    for ($i = 0; $i < $sic['nports']; $i++) {
        if (array_key_exists("do_{$i}", $sic)) {
            $params = array();
            assertStringArg("ports_{$i}");
            foreach (explode(',', $_REQUEST["ports_{$i}"]) as $item) {
                $pair = explode(':', $item);
                if (count($pair) != 2) {
                    continue;
                }
                $params[$pair[0]] = $pair[1];
            }
            if (!isset($params['a_id']) || !isset($params['b_id']) || !intval($params['a_id']) || !intval($params['b_id'])) {
                throw new InvalidArgException("ports_{$i}", $_REQUEST["ports_{$i}"], "can not unpack port ids");
            }
            $porta = getPortInfo($params['a_id']);
            $portb = getPortInfo($params['b_id']);
            if ($porta['linked'] or $portb['linked'] or $porta['object_id'] != $sic['object_id'] and $portb['object_id'] != $sic['object_id']) {
                $nignored++;
                continue;
            }
            $oif_a = intval(@$params['a_oif']);
            // these parameters are optional
            $oif_b = intval(@$params['b_oif']);
            $dbxlink->beginTransaction();
            try {
                if ($oif_a) {
                    commitUpdatePortOIF($params['a_id'], $oif_a);
                    $porta['oif_id'] = $oif_a;
                }
                if ($oif_b) {
                    commitUpdatePortOIF($params['b_id'], $oif_b);
                    $portb['oif_id'] = $oif_b;
                }
                if (arePortsCompatible($porta, $portb)) {
                    linkPorts($params['a_id'], $params['b_id']);
                    $ndone++;
                    $dbxlink->commit();
                } else {
                    $dbxlink->rollback();
                    $nignored++;
                }
            } catch (RTDatabaseError $e) {
                $dbxlink->rollBack();
                $nignored++;
            }
        }
    }
    showFuncMessage(__FUNCTION__, 'OK', array($nignored, $ndone));
}
Example #2
0
File: api.php Project: xtha/salt
     $remote_port_info = getPortInfo($_REQUEST['remote_port']);
     $POIFC = getPortOIFCompat();
     // (removed the ability to specify remote and local port types)
     $matches = FALSE;
     foreach ($POIFC as $pair) {
         if ($pair['type1'] == $port_info['oif_id'] && $pair['type2'] == $remote_port_info['oif_id']) {
             $matches = TRUE;
             break;
         }
     }
     if (!$matches) {
         $port_type = $port_info['oif_name'];
         $remote_port_type = $remote_port_info['oif_name'];
         throw new InvalidArgException('remote_port', $_REQUEST['remote_port'], "invalid argument: port types {$port_type} (local) and {$remote_port_type} (remote) can't be linked");
     }
     linkPorts($port_info['id'], $remote_port_info['id'], $_REQUEST['cable']);
     sendAPIResponse(array(), array('message' => 'ports linked successfully', 'local_object' => $port_info['object_id'], 'remote_object' => $remote_port_info['object_id'], 'local_port' => $_REQUEST['port'], 'remote_port' => $_REQUEST['remote_port']));
     break;
     // unlink a port
     //    UI equivalent: /index.php?module=redirect&op=unlinkPort&port_id=<<ID>>&object_id=<<ID>>&page=object&tab=ports
     //    UI handler: unlinkPort()
 // unlink a port
 //    UI equivalent: /index.php?module=redirect&op=unlinkPort&port_id=<<ID>>&object_id=<<ID>>&page=object&tab=ports
 //    UI handler: unlinkPort()
 case 'unlink_port':
     require_once 'inc/init.php';
     assertUIntArg('port_id');
     commitUnlinkPort($_REQUEST['port_id']);
     sendAPIResponse(array(), array('message' => 'port unlinked successfully', 'port_id' => $_REQUEST['port_id']));
     break;
     // get data on a given port
Example #3
0
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 ' &mdash; ';
        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">&#10005; Not compatible port types</p>';
        echo '<p class="compat-hint" id="hint-compat">&#10004; Compatible port types</p>';
        echo '<p><input type=submit name="do_link" value="Link">';
    }
}
function execute_PortLinker()
{
    global $localSplit, $remoteSplit;
    $errorText = determine_PortLinker();
    $object = spotEntity('object', $_REQUEST['object_id']);
    if (strlen($errorText) == 0) {
        $count = 0;
        // loop through all remote objects as defined
        foreach ($localSplit as $aKey => $aValue) {
            $numAdd = $remoteSplit[$aKey][$object['name']]['start'] - $aValue['start'];
            foreach ($aValue['ports'] as $aPortNum => $aPort) {
                linkPorts($aPort['id'], $aValue['remote_ports'][$aPortNum + $numAdd]['id']);
                $count++;
            }
        }
    }
    if (strlen($errorText) == 0) {
        return buildRedirectURL(__FUNCTION__, 'OK', array("{$count} ports successfully linked"));
    } else {
        return buildRedirectURL(__FUNCTION__, 'ERR', array($errorText));
    }
}