Beispiel #1
0
function addPortToVS()
{
    global $vs_proto;
    $proto = assertStringArg('proto');
    if (!in_array($proto, $vs_proto)) {
        throw new InvalidRequestArgException('proto', "Invalid VS protocol");
    }
    $vport = assertUIntArg('port', TRUE);
    if ($proto == 'MARK') {
        if ($vport > 0xffffffff) {
            showError("fwmark value is too large");
            return;
        }
    } else {
        if ($vport == 0 || $vport >= 0xffff) {
            showError("Invalid {$proto} port value");
            return;
        }
    }
    $vsinfo = spotEntity('ipvs', assertUIntArg('vs_id'));
    amplifyCell($vsinfo);
    $row = array('vs_id' => $vsinfo['id'], 'proto' => $proto, 'vport' => $vport, 'vsconfig' => NULL, 'rsconfig' => NULL);
    if ($port = isPortEnabled($row, $vsinfo['ports'])) {
        showError("Service already contains port " . formatVSPort($port));
        return;
    }
    usePreparedInsertBlade('VSPorts', $row);
    showSuccess("port addded");
}
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>';
}