Esempio n. 1
0
function updateTripletConfig()
{
    $key_fields = array('object_id' => assertUIntArg('object_id'), 'vs_id' => assertUIntArg('vs_id'), 'rspool_id' => assertUIntArg('rspool_id'));
    $config_fields = array('vsconfig' => nullEmptyStr(assertStringArg('vsconfig', TRUE)), 'rsconfig' => nullEmptyStr(assertStringArg('rsconfig', TRUE)));
    $vsinfo = spotEntity('ipvs', $key_fields['vs_id']);
    amplifyCell($vsinfo);
    $found = FALSE;
    if ($_REQUEST['op'] == 'updPort') {
        $table = 'VSEnabledPorts';
        $proto = assertStringArg('proto');
        $vport = assertUIntArg('port', TRUE);
        $key_fields['proto'] = $proto;
        $key_fields['vport'] = $vport;
        $key = "Port {$proto}-{$vport}";
        // check if such port exists in VS
        foreach ($vsinfo['ports'] as $vs_port) {
            if ($vs_port['proto'] == $proto && $vs_port['vport'] == $vport) {
                $found = TRUE;
                break;
            }
        }
    } else {
        $table = 'VSEnabledIPs';
        $vip = assertIPArg('vip');
        $config_fields['prio'] = nullEmptyStr(assertStringArg('prio', TRUE));
        $key_fields['vip'] = $vip;
        $key = "IP " . ip_format($vip);
        // check if such VIP exists in VS
        foreach ($vsinfo['vips'] as $vs_vip) {
            if ($vs_vip['vip'] === $vip) {
                $found = TRUE;
                break;
            }
        }
    }
    if (!$found) {
        showError("{$key} not found in VS");
        return;
    }
    $nchanged = 0;
    if (!isCheckSet('enabled')) {
        if ($nchanged += usePreparedDeleteBlade($table, $key_fields)) {
            showSuccess("{$key} disabled");
            return;
        }
    } else {
        global $dbxlink;
        $dbxlink->beginTransaction();
        $q = "SELECT * FROM {$table} WHERE";
        $sep = '';
        $params = array();
        foreach ($key_fields as $field => $value) {
            $q .= " {$sep} {$field} = ?";
            $params[] = $value;
            $sep = 'AND';
        }
        $result = usePreparedSelectBlade("{$q} FOR UPDATE", $params);
        $row = $result->fetch(PDO::FETCH_ASSOC);
        unset($result);
        if ($row) {
            if ($nchanged += usePreparedUpdateBlade($table, $config_fields, $key_fields)) {
                showSuccess("{$key} config updated");
            }
        } else {
            if ($nchanged += $table == 'VSEnabledIPs' ? addSLBIPLink($key_fields + $config_fields) : addSLBPortLink($key_fields + $config_fields)) {
                showSuccess("{$key} enabled");
            }
        }
        $dbxlink->commit();
    }
    if (!$nchanged) {
        showNotice("No changes made");
    }
}
Esempio n. 2
0
function updateIPCommentAJAX()
{
    global $sic;
    assertStringArg('text', TRUE);
    $ip_bin = assertIPArg('id');
    $addr = getIPAddress($ip_bin);
    $net = spotNetworkByIP($ip_bin);
    if (isset($net)) {
        fixContext($net);
    }
    assertPermission('ipaddress', 'properties', 'editAddress');
    updateAddress($ip_bin, $addr['name'], $addr['reserved'], $sic['text']);
    echo 'OK';
}
Esempio n. 3
0
File: api.php Progetto: xtha/salt
     // confirm that a network exists that matches the IP address
     if (getConfigVar('IPV4_JAYWALK') != 'yes' and NULL === getIPAddressNetworkId($ip_bin)) {
         throw new InvalidRequestArgException('ip', $_REQUEST['ip'], 'no network covering the requested IP address');
     }
     bindIPToObject($ip_bin, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']);
     redirectUser($_SERVER['SCRIPT_NAME'] . '?method=get_object&object_id=' . $_REQUEST['object_id']);
     break;
     // delete an IP address allocation for an object
     //    UI equivalent: /index.php?
     //    UI handler: delIPAllocation()
 // delete an IP address allocation for an object
 //    UI equivalent: /index.php?
 //    UI handler: delIPAllocation()
 case 'delete_object_ip_allocation':
     require_once 'inc/init.php';
     $ip_bin = assertIPArg('ip');
     assertUIntArg('object_id');
     // TODO: raise exception if the IP doesn't exist
     unbindIPFromObject($ip_bin, $_REQUEST['object_id']);
     redirectUser($_SERVER['SCRIPT_NAME'] . '?method=get_object&object_id=' . $_REQUEST['object_id']);
     break;
     // add a port to an object
     //    UI equivalent: /index.php?page=
     //    UI handler: addPortForObject()
 // add a port to an object
 //    UI equivalent: /index.php?page=
 //    UI handler: addPortForObject()
 case 'add_port':
     require_once 'inc/init.php';
     assertUIntArg('object_id');
     assertStringArg('port_name', TRUE);
Esempio n. 4
0
function renderIPAddressLog()
{
    $ip_bin = assertIPArg('ip');
    startPortlet('Log messages');
    echo '<table class="widetable" cellspacing="0" cellpadding="5" align="center" width="50%"><tr>';
    echo '<th>Date &uarr;</th>';
    echo '<th>User</th>';
    echo '<th>Log message</th>';
    echo '</tr>';
    $odd = FALSE;
    foreach (array_reverse(fetchIPLogEntry($ip_bin)) as $line) {
        $tr_class = $odd ? 'row_odd' : 'row_even';
        echo "<tr class='{$tr_class}'>";
        echo '<td>' . $line['date'] . '</td>';
        echo '<td>' . $line['user'] . '</td>';
        echo '<td>' . $line['message'] . '</td>';
        echo '</tr>';
        $odd = !$odd;
    }
    echo '</table>';
    finishPortlet();
}
Esempio n. 5
0
function triggerIPAddressLog()
{
    $ip_bin = assertIPArg('ip');
    switch (strlen($ip_bin)) {
        case 4:
            $result = usePreparedSelectBlade("SELECT COUNT(id) FROM IPv4Log WHERE ip = ?", array(ip4_bin2db($ip_bin)));
            break;
        case 16:
            $result = usePreparedSelectBlade("SELECT COUNT(id) FROM IPv6Log WHERE ip = ?", array($ip_bin));
            break;
    }
    if ($row = $result->fetch(PDO::FETCH_NUM)) {
        if ($row[0] > 0) {
            return 'std';
        }
    }
    return '';
}
Esempio n. 6
0
function updateVService()
{
    global $sic;
    assertUIntArg('vs_id');
    $vip_bin = assertIPArg('vip');
    genericAssertion('proto', 'enum/ipproto');
    if ($_REQUEST['proto'] == 'MARK') {
        assertStringArg('vport', TRUE);
    } else {
        assertUIntArg('vport');
    }
    assertStringArg('name', TRUE);
    assertStringArg('vsconfig', TRUE);
    assertStringArg('rsconfig', TRUE);
    commitUpdateVS($_REQUEST['vs_id'], $vip_bin, $_REQUEST['vport'], $_REQUEST['proto'], $_REQUEST['name'], $sic['vsconfig'], $sic['rsconfig']);
    return showFuncMessage(__FUNCTION__, 'OK');
}
Esempio n. 7
0
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
    }
}