Exemple #1
0
function renameObjectPorts()
{
    $object_id = getBypassValue();
    $n = 0;
    foreach (getObjectPortsAndLinks($object_id) as $port) {
        $canon_pn = shortenPortName($port['name'], $port['object_id']);
        if ($canon_pn != $port['name']) {
            commitUpdatePort($object_id, $port['id'], $canon_pn, $port['oif_id'], $port['label'], $port['l2address'], $port['reservation_comment']);
            $n++;
        }
    }
    if ($n) {
        showSuccess("Renamed {$n} ports");
    } else {
        showNotice("Nothing renamed");
    }
}
Exemple #2
0
function renderPortsForObject($object_id)
{
    $prefs = getPortListPrefs();
    function printNewItemTR($prefs)
    {
        printOpFormIntro('addPort');
        echo "<tr><td>";
        printImageHREF('add', 'add a port', TRUE);
        echo "</td><td class='tdleft'><input type=text size=8 name=port_name tabindex=100></td>\n";
        echo "<td><input type=text name=port_label tabindex=101></td><td>";
        printNiftySelect(getNewPortTypeOptions(), array('name' => 'port_type_id', 'tabindex' => 102), $prefs['selected']);
        echo "<td><input type=text name=port_l2address tabindex=103 size=18 maxlength=24></td>\n";
        echo "<td colspan=4>&nbsp;</td><td>";
        printImageHREF('add', 'add a port', TRUE, 104);
        echo "</td></tr></form>";
    }
    if (getConfigVar('ENABLE_MULTIPORT_FORM') == 'yes' || getConfigVar('ENABLE_BULKPORT_FORM') == 'yes') {
        startPortlet('Ports and interfaces');
    } else {
        echo '<br>';
    }
    $object = spotEntity('object', $object_id);
    amplifyCell($object);
    if (getConfigVar('ADDNEW_AT_TOP') == 'yes' && getConfigVar('ENABLE_BULKPORT_FORM') == 'yes') {
        echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
        echo "<tr><th>&nbsp;</th><th class=tdleft>Local name</th><th class=tdleft>Visible label</th><th class=tdleft>Interface</th><th class=tdleft>Start Number</th>";
        echo "<th class=tdleft>Count</th><th>&nbsp;</th></tr>\n";
        printOpFormIntro('addBulkPorts');
        echo "<tr><td>";
        printImageHREF('add', 'add ports', TRUE);
        echo "</td><td><input type=text size=8 name=port_name tabindex=105></td>\n";
        echo "<td><input type=text name=port_label tabindex=106></td><td>";
        printNiftySelect(getNewPortTypeOptions(), array('name' => 'port_type_id', 'tabindex' => 107), $prefs['selected']);
        echo "<td><input type=text name=port_numbering_start tabindex=108 size=3 maxlength=3></td>\n";
        echo "<td><input type=text name=port_numbering_count tabindex=109 size=3 maxlength=3></td>\n";
        echo "<td>&nbsp;</td><td>";
        printImageHREF('add', 'add ports', TRUE, 110);
        echo "</td></tr></form>";
        echo "</table><br>\n";
    }
    echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
    echo "<tr><th>&nbsp;</th><th class=tdleft>Local name</th><th class=tdleft>Visible label</th><th class=tdleft>Interface</th><th class=tdleft>L2 address</th>";
    echo "<th class=tdcenter colspan=2>Remote object and port</th><th>Cable ID</th><th class=tdcenter>(Un)link or (un)reserve</th><th>&nbsp;</th></tr>\n";
    if (getConfigVar('ADDNEW_AT_TOP') == 'yes') {
        printNewItemTR($prefs);
    }
    // clear ports link
    echo getOpLink(array('op' => 'deleteAll'), 'Clear port list', 'clear', '', 'need-confirmation');
    // rename ports link
    $n_ports_to_rename = 0;
    foreach ($object['ports'] as $port) {
        if ($port['name'] != shortenPortName($port['name'], $object['id'])) {
            $n_ports_to_rename++;
        }
    }
    if ($n_ports_to_rename) {
        echo '<p>' . getOpLink(array('op' => 'renameAll'), "Auto-rename {$n_ports_to_rename} ports", 'recalc', 'Use RackTables naming convention for this device type') . '</p>';
    }
    if (isset($_REQUEST['hl_port_id'])) {
        assertUIntArg('hl_port_id');
        $hl_port_id = intval($_REQUEST['hl_port_id']);
        addAutoScrollScript("port-{$hl_port_id}");
    }
    switchportInfoJS($object_id);
    // load JS code to make portnames interactive
    foreach ($object['ports'] as $port) {
        // highlight port name with yellow if it's name is not canonical
        $canon_pn = shortenPortName($port['name'], $port['object_id']);
        $name_class = $canon_pn == $port['name'] ? '' : 'trwarning';
        $tr_class = isset($hl_port_id) && $hl_port_id == $port['id'] ? 'class="highlight"' : '';
        printOpFormIntro('editPort', array('port_id' => $port['id']));
        echo "<tr {$tr_class}><td><a name='port-{$port['id']}' href='" . makeHrefProcess(array('op' => 'delPort', 'port_id' => $port['id'])) . "'>";
        printImageHREF('delete', 'Unlink and Delete this port');
        echo "</a></td>\n";
        $a_class = isEthernetPort($port) ? 'port-menu' : '';
        echo "<td class='tdleft {$name_class}' NOWRAP><input type=text name=name class='interactive-portname {$a_class}' value='{$port['name']}' size=8></td>";
        echo "<td><input type=text name=label value='{$port['label']}'></td>";
        echo '<td>';
        if ($port['iif_id'] != 1) {
            echo '<label>' . $port['iif_name'] . ' ';
        }
        printSelect(getExistingPortTypeOptions($port['id']), array('name' => 'port_type_id'), $port['oif_id']);
        if ($port['iif_id'] != 1) {
            echo '</label>';
        }
        echo '</td>';
        // 18 is enough to fit 6-byte MAC address in its longest form,
        // while 24 should be Ok for WWN
        echo "<td><input type=text name=l2address value='{$port['l2address']}' size=18 maxlength=24></td>\n";
        if ($port['remote_object_id']) {
            echo "<td>" . formatLoggedSpan($port['last_log'], formatPortLink($port['remote_object_id'], $port['remote_object_name'], $port['remote_id'], NULL)) . "</td>";
            echo "<td> " . formatLoggedSpan($port['last_log'], $port['remote_name'], 'underline') . "<input type=hidden name=reservation_comment value=''></td>";
            echo "<td><input type=text name=cable value='{$port['cableid']}'></td>";
            echo "<td class=tdcenter>";
            echo getOpLink(array('op' => 'unlinkPort', 'port_id' => $port['id']), '', 'cut', 'Unlink this port');
            echo "</td>";
        } elseif (strlen($port['reservation_comment'])) {
            echo "<td>" . formatLoggedSpan($port['last_log'], 'Reserved:', 'strong underline') . "</td>";
            echo "<td><input type=text name=reservation_comment value='{$port['reservation_comment']}'></td>";
            echo "<td></td>";
            echo "<td class=tdcenter>";
            echo getOpLink(array('op' => 'useup', 'port_id' => $port['id']), '', 'clear', 'Use up this port');
            echo "</td>";
        } else {
            $in_rack = getConfigVar('NEAREST_RACKS_CHECKBOX');
            echo "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td class=tdcenter><span";
            $helper_args = array('port' => $port['id'], 'in_rack' => $in_rack == "yes" ? "on" : "");
            $popup_args = 'height=700, width=400, location=no, menubar=no, ' . 'resizable=yes, scrollbars=yes, status=no, titlebar=no, toolbar=no';
            echo " ondblclick='window.open(\"" . makeHrefForHelper('portlist', $helper_args);
            echo "\",\"findlink\",\"{$popup_args}\");'";
            // end of onclick=
            echo " onclick='window.open(\"" . makeHrefForHelper('portlist', $helper_args);
            echo "\",\"findlink\",\"{$popup_args}\");'";
            // end of onclick=
            echo '>';
            // end of <a>
            printImageHREF('plug', 'Link this port');
            echo "</span>";
            echo " <input type=text name=reservation_comment></td>\n";
        }
        echo "<td>";
        printImageHREF('save', 'Save changes', TRUE);
        echo "</td></form></tr>\n";
    }
    if (getConfigVar('ADDNEW_AT_TOP') != 'yes') {
        printNewItemTR($prefs);
    }
    echo "</table><br>\n";
    if (getConfigVar('ADDNEW_AT_TOP') != 'yes' && getConfigVar('ENABLE_BULKPORT_FORM') == 'yes') {
        echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
        echo "<tr><th>&nbsp;</th><th class=tdleft>Local name</th><th class=tdleft>Visible label</th><th class=tdleft>Interface</th><th class=tdleft>Start Number</th>";
        echo "<th class=tdleft>Count</th><th>&nbsp;</th></tr>\n";
        printOpFormIntro('addBulkPorts');
        echo "<tr><td>";
        printImageHREF('add', 'add ports', TRUE);
        echo "</td><td><input type=text size=8 name=port_name tabindex=105></td>\n";
        echo "<td><input type=text name=port_label tabindex=106></td><td>";
        printNiftySelect(getNewPortTypeOptions(), array('name' => 'port_type_id', 'tabindex' => 107), $prefs['selected']);
        echo "<td><input type=text name=port_numbering_start tabindex=108 size=3 maxlength=3></td>\n";
        echo "<td><input type=text name=port_numbering_count tabindex=109 size=3 maxlength=3></td>\n";
        echo "<td>&nbsp;</td><td>";
        printImageHREF('add', 'add ports', TRUE, 110);
        echo "</td></tr></form>";
        echo "</table><br>\n";
    }
    if (getConfigVar('ENABLE_MULTIPORT_FORM') == 'yes') {
        finishPortlet();
    }
    if (getConfigVar('ENABLE_MULTIPORT_FORM') != 'yes') {
        return;
    }
    startPortlet('Add/update multiple ports');
    printOpFormIntro('addMultiPorts');
    echo 'Format: <select name=format tabindex=201>';
    echo '<option value=c3600asy>Cisco 3600 async: sh line | inc TTY</option>';
    echo '<option value=fiwg selected>Foundry ServerIron/FastIron WorkGroup/Edge: sh int br</option>';
    echo '<option value=fisxii>Foundry FastIron SuperX/II4000: sh int br</option>';
    echo '<option value=ssv1>SSV:&lt;interface name&gt; &lt;MAC address&gt;</option>';
    echo "</select>";
    echo 'Default port type: ';
    printNiftySelect(getNewPortTypeOptions(), array('name' => 'port_type', 'tabindex' => 202), $prefs['selected']);
    echo "<input type=submit value='Parse output' tabindex=204><br>\n";
    echo "<textarea name=input cols=100 rows=50 tabindex=203></textarea><br>\n";
    echo '</form>';
    finishPortlet();
}