Ejemplo n.º 1
0
function AJblockAllocationSubmit()
{
    global $user;
    $data = processBlockAllocationInput();
    if ($data['err']) {
        return;
    }
    $method = getContinuationVar('method');
    if ($method == 'new') {
        $managementnodes = getManagementNodes('future');
        if (empty($managementnodes)) {
            print "alert('" . i("Error encountered while trying to create block allocation:") . "\\n";
            print i("No active management nodes were found. Please try creating the block allocation at a later time.") . "');";
            $data = array('extragroups' => getContinuationVar('extragroups'), 'method' => $method);
            if ($method == 'edit') {
                $data['blockid'] = getContinuationVar('blockid');
            }
            $cont = addContinuationsEntry('AJblockAllocationSubmit', $data, SECINWEEK, 1, 0);
            print "dojo.byId('submitcont').value = '{$cont}';";
            return;
        }
        $mnid = array_rand($managementnodes);
        $escname = mysql_real_escape_string($data['name']);
        $query = "INSERT INTO blockRequest " . "(name, " . "imageid, " . "numMachines, " . "groupid, " . "repeating, " . "ownerid, " . "managementnodeid, " . "expireTime, " . "status) " . "VALUES " . "('{$escname}', " . "{$data['imageid']}, " . "{$data['seats']}, " . "{$data['groupid']}, " . "'{$data['type']}', " . "{$data['ownerid']}, " . "{$mnid}, " . "'{$data['expiretime']}', " . "'accepted')";
        doQuery($query, 101);
        $blockreqid = dbLastInsertID();
    } elseif ($method == 'edit') {
        $blockreqid = getContinuationVar('blockid');
        # FIXME need to handle creation of a block time that we're currently in the
        #    middle of if there wasn't already one we're in the middle of
        # get blockTime entry for this allocation if we're in the middle of one
        $checkCurBlockTime = 0;
        $query = "SELECT id, " . "start, " . "end " . "FROM blockTimes " . "WHERE start <= NOW() AND " . "end > NOW() AND " . "blockRequestid = {$blockreqid}";
        $qh = doQuery($query, 101);
        if ($row = mysql_fetch_assoc($qh)) {
            $checkCurBlockTime = 1;
            $curBlockTime = $row;
        }
        # delete entries from blockTimes that start later than now
        $query = "DELETE FROM blockTimes " . "WHERE blockRequestid = {$blockreqid} AND " . "start > NOW() AND " . "skip = 0";
        doQuery($query, 101);
        # delete entries from blockWebDate and blockWebTime
        $query = "DELETE FROM blockWebDate WHERE blockRequestid = {$blockreqid}";
        doQuery($query, 101);
        $query = "DELETE FROM blockWebTime WHERE blockRequestid = {$blockreqid}";
        doQuery($query, 101);
        $escname = mysql_real_escape_string($data['name']);
        $query = "UPDATE blockRequest " . "SET name = '{$escname}', " . "imageid = {$data['imageid']}, " . "numMachines = {$data['seats']}, " . "groupid = {$data['groupid']}, " . "ownerid = {$data['ownerid']}, " . "repeating = '{$data['type']}', " . "expireTime = '{$data['expiretime']}' " . "WHERE  id = {$blockreqid}";
        doQuery($query, 101);
    } elseif ($method == 'request') {
        $esccomments = mysql_real_escape_string($data['comments']);
        $query = "INSERT INTO blockRequest " . "(name, " . "imageid, " . "numMachines, " . "groupid, " . "repeating, " . "ownerid, " . "expireTime, " . "status, " . "comments) " . "VALUES " . "('(" . i("awaiting approval") . ")', " . "{$data['imageid']}, " . "{$data['seats']}, " . "{$data['groupid']}, " . "'{$data['type']}', " . "{$user['id']}, " . "'{$data['expiretime']}', " . "'requested', " . "'{$esccomments}')";
        doQuery($query, 101);
        $blockreqid = dbLastInsertID();
        # send email notifying about a new block allocation request
        $imagedata = getImages(0, $data['imageid']);
        if ($data['groupid'] == 0) {
            $grpname = "(Unspecified)";
        } else {
            $grpname = getUserGroupName($data['groupid']);
        }
        if (!empty($data['comments'])) {
            $comments = "Comments:\n{$data['comments']}\n";
        } else {
            $comments = '';
        }
        $message = "A new block allocation request has been submitted by ";
        if (!empty($user['firstname']) && !empty($user['lastname']) && !empty($user['email'])) {
            $message .= "{$user['firstname']} {$user['lastname']} ({$user['email']}). ";
        } elseif (!empty($user['email'])) {
            $message .= "{$user['email']}. ";
        } else {
            $message .= "{$user['unityid']}. ";
        }
        $message .= "Please visit the following URL to accept or reject it:\n\n" . BASEURL . SCRIPT . "?mode=blockAllocations\n\n" . "Image: {$imagedata[$data['imageid']]['prettyname']}\n" . "Seats: {$data['seats']}\n" . "User Group: {$grpname}\n{$comments}\n\n" . "This is an automated message sent by VCL.\n" . "You are receiving this message because you have access " . "to create and approve block allocations.";
        $mailParams = "-f" . ENVELOPESENDER;
        $blockNotifyUsers = getBlockNotifyUsers($user['affiliationid']);
        mail($blockNotifyUsers, "VCL Block Allocation Request ({$user['unityid']})", $message, '', $mailParams);
    }
    if ($data['type'] == 'weekly') {
        $query = "INSERT INTO blockWebDate " . "(blockRequestid, " . "start, " . "end, " . "days) " . "VALUES " . "({$blockreqid}, " . "'{$data['startdate']}', " . "'{$data['enddate']}', " . "{$data['daymask']})";
        doQuery($query, 101);
        $today = mktime(0, 0, 0);
        if ($method == 'edit' && $data['startts'] < $today) {
            createWeeklyBlockTimes($blockreqid, $today, $data['endts'], $data['daymask'], $data['times']);
        } elseif ($method == 'new' || $method == 'edit') {
            createWeeklyBlockTimes($blockreqid, $data['startts'], $data['endts'], $data['daymask'], $data['times']);
        }
    } elseif ($data['type'] == 'monthly') {
        $query = "INSERT INTO blockWebDate " . "(blockRequestid, " . "start, " . "end, " . "days, " . "weeknum) " . "VALUES " . "({$blockreqid}, " . "'{$data['startdate']}', " . "'{$data['enddate']}', " . "{$data['day']}, " . "{$data['weeknum']})";
        doQuery($query, 101);
        $today = mktime(0, 0, 0);
        if ($method == 'edit' && $data['startts'] < $today) {
            createMonthlyBlockTimes($blockreqid, $today, $data['endts'], $data['day'], $data['weeknum'], $data['times']);
        } elseif ($method == 'new' || $method == 'edit') {
            createMonthlyBlockTimes($blockreqid, $data['startts'], $data['endts'], $data['day'], $data['weeknum'], $data['times']);
        }
    }
    if ($data['type'] == 'weekly' || $data['type'] == 'monthly') {
        $vals = array();
        $i = 0;
        foreach ($data['times'] as $time) {
            $tmp = explode('|', $time);
            $start = explode(':', $tmp[0]);
            $startmin = $start[1];
            list($starth, $startm) = hour24to12($start[0]);
            $end = explode(':', $tmp[1]);
            $endmin = $end[1];
            list($endh, $endm) = hour24to12($end[0]);
            $vals[] = "({$blockreqid}, " . "'{$starth}', " . "'{$startmin}', " . "'{$startm}', " . "'{$endh}', " . "'{$endmin}', " . "'{$endm}', " . "{$i})";
            $i++;
        }
        $allvals = implode(',', $vals);
        $query = "INSERT INTO blockWebTime " . "(blockRequestid, " . "starthour, " . "startminute, " . "startmeridian, " . "endhour, " . "endminute, " . "endmeridian, " . "`order`) " . "VALUES {$allvals}";
        doQuery($query, 101);
    }
    if ($data['type'] == 'list') {
        createListBlockData($blockreqid, $data['slots'], $method);
    }
    if ($method == 'edit' && $checkCurBlockTime) {
        $query = "SELECT id, " . "start, " . "end " . "FROM blockTimes " . "WHERE start <= NOW() AND " . "end > NOW() AND " . "blockRequestid = {$blockreqid} AND " . "id != {$curBlockTime['id']}";
        $qh = doQuery($query, 101);
        if ($row = mysql_fetch_assoc($qh)) {
            if ($curBlockTime['end'] != $row['end']) {
                # update old end time
                $query = "UPDATE blockTimes " . "SET end = '{$row['end']}' " . "WHERE id = {$curBlockTime['id']}";
                doQuery($query, 101);
            }
            # delete $row entry
            doQuery("DELETE FROM blockTimes WHERE id = {$row['id']}", 101);
        } else {
            # the blockTime we were in the middle of was not recreated, so
            #    delete the old one
            doQuery("DELETE FROM blockTimes WHERE id = {$curBlockTime['id']}", 101);
        }
    }
    if ($method == 'request') {
        print "clearHideConfirmForm();";
        $txt = "<h2>" . i("Request New Block Allocation") . "</h2>";
        $txt .= i("Your request for a Block Allocation has been submitted for approval.") . " ";
        if (!empty($user['email'])) {
            $txt .= i("You should be notified within a few business days of its acceptance or rejection.");
        } else {
            $txt .= "<br><br><font color=\"red\"><strong>" . i("Note:") . "</strong> ";
            $h = "      " . i("You do not have an email address registered with VCL. Therefore, you will not receive automatic notification when this block allocation is accepted or rejected.");
            $txt .= preg_replace("/(.{1,50}([ \n]|\$))/", '\\1<br>', $h) . "</font>";
        }
        print "dojo.byId('content').innerHTML = '{$txt}';";
        print "scroll(0, 0);";
        return;
    }
    print "window.location.href = '" . BASEURL . SCRIPT . "?mode=blockAllocations';";
}
Ejemplo n.º 2
0
 function addConfigMapping($data, $maptypes)
 {
     $configdata = $this->_getData($data['configid']);
     if (is_null($configdata[$data['configid']]['configstageid'])) {
         $stageid = $data['stageid'];
     } else {
         $stageid = $configdata[$data['configid']]['configstageid'];
     }
     $query = "INSERT INTO configmap " . "(configid, " . "configmaptypeid, " . "subid, " . "affiliationid, " . "disabled, " . "configstageid) " . "VALUES " . "({$data['configid']}, " . "{$data['maptypeid']}, " . "{$data['subid']}, " . "{$data['affiliationid']}, " . "0, " . "{$stageid})";
     doQuery($query);
     $configmapid = dbLastInsertID();
     $id = $data['configid'];
     $configdata = $this->_getData($id);
     $stages = $this->getConfigMapStages();
     $item = array('id' => $configmapid, 'configid' => $id, 'configname' => $configdata[$id]['name'], 'description' => $configdata[$id]['description'], 'configtypeid' => $configdata[$id]['configtypeid'], 'configtype' => $configdata[$id]['configtype'], 'configmaptypeid' => $data['maptypeid'], 'configmaptype' => $maptypes[$data['maptypeid']], 'affiliationid' => $data['affiliationid'], 'mapto' => $data['mapto'], 'affiliation' => getAffiliationName($data['affiliationid']), 'disabled' => 0, 'stageid' => $data['stageid'], 'configstage' => $stages[$data['stageid']]);
     $ret = array('status' => 'success', 'item' => $item, 'action' => 'add');
     sendJSON($ret);
     return;
 }
Ejemplo n.º 3
0
function saveRequestConfigs($reqid, $imageid, $configs, $vars)
{
    global $user;
    $query = "SELECT id, " . "imageid " . "FROM reservation " . "WHERE requestid = {$reqid} " . "ORDER BY id";
    $qh = doQuery($query);
    $resids = array();
    while ($row = mysql_fetch_assoc($qh)) {
        if (!array_key_exists($row['imageid'], $resids)) {
            $resids[$row['imageid']] = array();
        }
        $resids[$row['imageid']][] = $row['id'];
    }
    $bysubimage = array(0 => array('imageid' => $imageid));
    foreach ($configs as $id => $cfg) {
        if (preg_match('|^([0-9]+)/([0-9]+)-([0-9]+)$|', $id, $keys)) {
            $bysubimage[$keys[1]][$keys[2]] = $cfg['configid'];
            $bysubimage[$keys[3]]['imageid'] = $cfg['imageid'];
        } elseif (preg_match('|^([0-9]+)/([-0-9]+)$|', $id, $keys)) {
            $bysubimage[$keys[1]][$keys[2]] = $cfg['configid'];
        }
    }
    $qbase = "INSERT INTO configinstance " . "(reservationid, " . "configid, " . "configmapid, " . "configinstancestatusid) " . "VALUES ";
    $qbase2 = "INSERT INTO configinstancevariable " . "(configinstanceid, " . "configvariableid, " . "value) " . "VALUES ";
    $qbase3 = "INSERT INTO configmap " . "(configid, " . "configmaptypeid, " . "subid, " . "affiliationid, " . "disabled, " . "configstageid) " . "VALUES ";
    $residmaps = array();
    foreach ($bysubimage as $cfgsubimgid => $data) {
        $resid = array_pop($resids[$data['imageid']]);
        unset($data['imageid']);
        foreach ($data as $mapid => $cfgid) {
            $insmapid = $mapid;
            if ($mapid < 0) {
                $query = $qbase3;
                $query .= "({$cfgid}, ";
                $query .= "(SELECT id FROM configmaptype WHERE name = 'reservation'), ";
                $query .= "{$resid}, {$user['affiliationid']}, 0, ";
                $query .= $configs["{$cfgsubimgid}/{$mapid}"]['configstageid'] . ")";
                doQuery($query);
                $insmapid = dbLastInsertID();
            }
            $query = $qbase;
            $query .= "({$resid}, {$cfgid}, {$insmapid}, 1)";
            doQuery($query);
            $instid = dbLastInsertID();
            if (array_key_exists("{$cfgsubimgid}/{$mapid}", $vars)) {
                $sets = array();
                foreach ($vars["{$cfgsubimgid}/{$mapid}"] as $varid => $varval) {
                    $_val = mysql_real_escape_string($varval['value']);
                    $sets[] = "({$instid}, {$varid}, '{$_val}')";
                }
                $query = $qbase2 . implode(',', $sets);
                doQuery($query);
            }
        }
    }
}
Ejemplo n.º 4
0
 function AJaddSubimage()
 {
     $imageid = getContinuationVar('imageid');
     $adminids = getContinuationVar('adminids');
     $userimageids = getContinuationVar('userimageids');
     $subimages = getContinuationVar('subimages');
     $imagemetaid = getContinuationVar('imagemetaid');
     if (!in_array($imageid, $adminids)) {
         $arr = array('error' => 'noimageaccess', 'msg' => i("You do not have access to manage this image."));
         sendJSON($arr);
         return;
     }
     $newid = processInputVar('imageid', ARG_NUMERIC);
     if (!in_array($newid, $userimageids)) {
         $arr = array('error' => 'nosubimageaccess', 'msg' => i("You do not have access to add this subimage."));
         sendJSON($arr);
         return;
     }
     if (is_null($imagemetaid)) {
         $query = "INSERT INTO imagemeta " . "(subimages) " . "VALUES (1)";
         doQuery($query, 101);
         $imagemetaid = dbLastInsertID();
         $query = "UPDATE image " . "SET imagemetaid = {$imagemetaid} " . "WHERE id = {$imageid}";
         doQuery($query, 101);
     } elseif (!count($subimages)) {
         $query = "UPDATE imagemeta " . "SET subimages = 1 " . "WHERE id = {$imagemetaid}";
         doQuery($query, 101);
     }
     $query = "INSERT INTO subimages " . "(imagemetaid, " . "imageid) " . "VALUES ({$imagemetaid}, " . "{$newid})";
     doQuery($query, 101);
     $subimages[] = $newid;
     $data = array('imageid' => $imageid, 'adminids' => $adminids, 'imagemetaid' => $imagemetaid, 'userimageids' => $userimageids, 'subimages' => $subimages, 'obj' => $this);
     $addcont = addContinuationsEntry('AJaddSubimage', $data, SECINDAY, 1, 0);
     $remcont = addContinuationsEntry('AJremSubimage', $data, SECINDAY, 1, 0);
     $image = getImages(0, $newid);
     $name = $image[$newid]['prettyname'];
     $arr = array('newid' => $newid, 'name' => $name, 'addcont' => $addcont, 'remcont' => $remcont);
     sendJSON($arr);
 }
Ejemplo n.º 5
0
 function addResource($data)
 {
     global $user;
     $ownerid = getUserlistID($data['owner']);
     $noimageid = getImageId('noimage');
     $norevid = getProductionRevisionid($noimageid);
     $keys = array('hostname', 'ownerid', 'type', 'IPaddress', 'privateIPaddress', 'eth0macaddress', 'eth1macaddress', 'provisioningid', 'stateid', 'platformid', 'scheduleid', 'RAM', 'procnumber', 'procspeed', 'network', 'currentimageid', 'imagerevisionid', 'location', 'predictivemoduleid');
     if ($data['addmode'] == 'single') {
         $eth0 = "'{$data['eth0macaddress']}'";
         if ($data['eth0macaddress'] == '') {
             $eth0 = 'NULL';
         }
         $eth1 = "'{$data['eth1macaddress']}'";
         if ($data['eth1macaddress'] == '') {
             $eth1 = 'NULL';
         }
         $values = array("'{$data['name']}'", $ownerid, "'{$data['type']}'", "'{$data['IPaddress']}'", "'{$data['privateIPaddress']}'", $eth0, $eth1, $data['provisioningid'], $data['stateid'], $data['platformid'], $data['scheduleid'], $data['ram'], $data['cores'], $data['procspeed'], $data['network'], $noimageid, $norevid, "'{$data['location']}'", $data['predictivemoduleid']);
         $query = "INSERT INTO computer (" . implode(', ', $keys) . ") VALUES (" . implode(', ', $values) . ")";
         doQuery($query);
         $rscid = dbLastInsertID();
         # vmhost entry
         if ($data['stateid'] == '20') {
             $query = "INSERT INTO vmhost " . "(computerid, " . "vmlimit, " . "vmprofileid) " . "VALUES ({$rscid}, " . "5, " . "{$data['vmprofileid']})";
             doQuery($query);
         }
         # NAT
         if ($data['natenabled']) {
             $query = "INSERT INTO nathostcomputermap " . "(computerid, " . "nathostid) " . "VALUES ({$rscid}, " . "{$data['nathostid']})";
             doQuery($query);
         }
         // add entry in resource table
         $query = "INSERT INTO resource " . "(resourcetypeid, " . "subid) " . "VALUES (12, " . "{$rscid})";
         doQuery($query);
         $resourceid = dbLastInsertID();
         # NAT host
         if ($data['nathostenabled']) {
             $query = "INSERT INTO nathost " . "(resourceid, " . "publicIPaddress, " . "internalIPaddress) " . "VALUES " . "({$resourceid}, " . "'{$data['natpublicIPaddress']}', " . "'{$data['natinternalIPaddress']}')";
             doQuery($query);
         }
         return $rscid;
     } else {
         # add multiple computers
         $alldis = array();
         for ($i = $data['startnum'], $cnt = 0; $i <= $data['endnum']; $i++, $cnt++) {
             $hostname = str_replace('%', $i, $data["name"]);
             $pubip = long2ip($data['startpubiplong'] + $cnt);
             $privip = long2ip($data['startpriviplong'] + $cnt);
             if (count($data['macs'])) {
                 $eth0 = "'" . $data['macs'][$cnt * 2] . "'";
                 $eth1 = "'" . $data['macs'][$cnt * 2 + 1] . "'";
             } else {
                 $eth0 = 'NULL';
                 $eth1 = 'NULL';
             }
             $values = array("'{$hostname}'", $ownerid, "'{$data['type']}'", "'{$pubip}'", "'{$privip}'", $eth0, $eth1, $data['provisioningid'], $data['stateid'], $data['platformid'], $data['scheduleid'], $data['ram'], $data['cores'], $data['procspeed'], $data['network'], $noimageid, $norevid, "'{$data['location']}'", $data['predictivemoduleid']);
             $query = "INSERT INTO computer (" . implode(', ', $keys) . ") VALUES (" . implode(', ', $values) . ")";
             doQuery($query);
             $rscid = dbLastInsertID();
             # vmhost entry
             if ($data['stateid'] == '20') {
                 $query = "INSERT INTO vmhost " . "(computerid, " . "vmlimit, " . "vmprofileid) " . "VALUES ({$rscid}, " . "5, " . "{$data['vmprofileid']})";
                 doQuery($query);
             }
             # NAT
             if ($data['natenabled']) {
                 $query = "INSERT INTO nathostcomputermap " . "(computerid, " . "nathostid) " . "VALUES ({$rscid}, " . "{$data['nathostid']})";
                 doQuery($query);
             }
             // add entry in resource table
             $query = "INSERT INTO resource " . "(resourcetypeid, " . "subid) " . "VALUES (12, " . "{$rscid})";
             doQuery($query);
             $allids[] = $rscid;
         }
         return $allids;
     }
 }
Ejemplo n.º 6
0
function addShibUserStub($affilid, $userid)
{
    global $mysql_link_vcl;
    $query = "INSERT INTO user " . "(unityid, " . "affiliationid, " . "emailnotices, " . "lastupdated, " . "validated) " . "VALUES (" . "'{$userid}', " . "'{$affilid}', " . "0, " . "0, " . "0)";
    doQuery($query);
    if (mysql_affected_rows($mysql_link_vcl)) {
        return dbLastInsertID();
    } else {
        return NULL;
    }
}
Ejemplo n.º 7
0
function simpleAddRequest($compid, $imageid, $revisionid, $start, $end, $stateid, $userid)
{
    $mgmtnodeid = findManagementNode($compid, $start, 'now');
    if ($mgmtnodeid == 0) {
        return 0;
    }
    $query = "INSERT INTO request " . "(stateid, " . "userid, " . "laststateid, " . "start, " . "end, " . "daterequested) " . "VALUES " . "({$stateid}, " . "{$userid}, " . "{$stateid}, " . "'{$start}', " . "'{$end}', " . "NOW())";
    doQuery($query, 101);
    $requestid = dbLastInsertID();
    if ($requestid == 0) {
        abort(135);
    }
    # add an entry to the reservation table for each image
    $query = "INSERT INTO reservation " . "(requestid, " . "computerid, " . "imageid, " . "imagerevisionid, " . "managementnodeid) " . "VALUES " . "({$requestid}, " . "{$compid}, " . "{$imageid}, " . "{$revisionid}, " . "{$mgmtnodeid})";
    doQuery($query, 101);
    $testid = dbLastInsertID();
    if ($testid == 0) {
        abort(135);
    }
    return $requestid;
}
Ejemplo n.º 8
0
function XMLRPCblockAllocation($imageid, $start, $end, $requestcount, $usergroupid, $ignoreprivileges = 0)
{
    global $user, $xmlrpcBlockAPIUsers;
    if (!in_array($user['id'], $xmlrpcBlockAPIUsers)) {
        return array('status' => 'error', 'errorcode' => 34, 'errormsg' => 'access denied for managing block allocations');
    }
    $ownerid = getUserlistID('vclreload@Local');
    $name = "API:{$start}";
    $managementnodes = getManagementNodes('future');
    if (empty($managementnodes)) {
        return array('status' => 'error', 'errorcode' => 12, 'errormsg' => 'could not allocate a management node to handle block allocation');
    }
    $mnid = array_rand($managementnodes);
    $query = "INSERT INTO blockRequest " . "(name, " . "imageid, " . "numMachines, " . "groupid, " . "repeating, " . "ownerid, " . "admingroupid, " . "managementnodeid, " . "expireTime) " . "VALUES " . "('{$name}', " . "{$imageid}, " . "{$requestcount}, " . "{$usergroupid}, " . "'list', " . "{$ownerid}, " . "0, " . "{$mnid}, " . "'{$end}')";
    doQuery($query, 101);
    $brid = dbLastInsertID();
    $query = "INSERT INTO blockTimes " . "(blockRequestid, " . "start, " . "end) " . "VALUES " . "({$brid}, " . "'{$start}', " . "'{$end}')";
    doQuery($query, 101);
    $btid = dbLastInsertID();
    $return = XMLRPCprocessBlockTime($btid, $ignoreprivileges);
    $return['blockTimesid'] = $btid;
    return $return;
}
Ejemplo n.º 9
0
function AJsaveServerProfile()
{
    global $user;
    $data = processProfileInput();
    if (array_key_exists('error', $data)) {
        sendJSON($data);
        return;
    }
    $name = mysql_real_escape_string($data['name']);
    $desc = mysql_real_escape_string($data['desc']);
    $fixedIP = mysql_real_escape_string($data['fixedIP']);
    $fixedMAC = mysql_real_escape_string($data['fixedMAC']);
    $ret = array();
    if ($data['profileid'] == 70000) {
        $query = "INSERT INTO serverprofile " . "(name, " . "description, " . "imageid, " . "ownerid, " . "fixedIP, " . "fixedMAC, " . "admingroupid, " . "logingroupid, " . "monitored) " . "VALUES " . "('{$name}', " . "'{$desc}', " . "{$data['imageid']}, " . "{$user['id']}, " . "'{$fixedIP}', " . "'{$fixedMAC}', " . "{$data['admingroupid']}, " . "{$data['logingroupid']}, " . "{$data['monitored']})";
        doQuery($query, 101);
        $id = dbLastInsertID();
        $query = "INSERT INTO resource " . "(resourcetypeid, " . "subid) " . "VALUES " . "(17, " . "{$id})";
        doQuery($query, 101);
        $ret['success'] = 1;
        $ret['name'] = $data['name'];
        $ret['id'] = $id;
        $ret['newprofile'] = 1;
        if ($fixedIP != '') {
            $vdata = array('netmask' => $data['netmask'], 'router' => $data['router'], 'dns' => $data['dnsArr']);
            setVariable("fixedIPsp{$id}", $vdata, 'yaml');
        }
    } else {
        $query = "UPDATE serverprofile SET " . "name = '{$name}', " . "description = '{$desc}', " . "imageid = {$data['imageid']}, " . "fixedIP = '{$fixedIP}', " . "fixedMAC = '{$fixedMAC}', " . "admingroupid = {$data['admingroupid']}, " . "logingroupid = {$data['logingroupid']}, " . "monitored = {$data['monitored']} " . "WHERE id = {$data['profileid']}";
        doQuery($query, 101);
        $ret['success'] = 1;
        $ret['name'] = $data['name'];
        $ret['id'] = $data['profileid'];
        $ret['newprofile'] = 0;
    }
    if ($data['fixedIP'] != '') {
        $vdata = array('netmask' => $data['netmask'], 'router' => $data['router'], 'dns' => $data['dnsArr']);
        setVariable("fixedIPsp{$ret['id']}", $vdata, 'yaml');
        $ret['netmask'] = $data['netmask'];
        $ret['router'] = $data['router'];
        $ret['dns'] = $data['dns'];
        $allnets = getVariable('fixedIPavailnetworks', array());
        $network = ip2long($data['fixedIP']) & ip2long($data['netmask']);
        $key = long2ip($network) . "/{$data['netmask']}";
        $allnets[$key] = array('router' => $data['router'], 'dns' => $data['dnsArr']);
        setVariable('fixedIPavailnetworks', $allnets, 'yaml');
    }
    $ret['access'] = 'admin';
    $ret['desc'] = preg_replace("/\n/", "<br>", $data['desc']);
    $_SESSION['usersessiondata'] = array();
    $_SESSION['userresources'] = array();
    sendJSON($ret);
}
Ejemplo n.º 10
0
function XMLRPCblockAllocation($imageid, $start, $end, $numMachines, $usergroupid, $ignoreprivileges = 0)
{
    global $user, $xmlrpcBlockAPIUsers;
    if (!in_array($user['id'], $xmlrpcBlockAPIUsers)) {
        return array('status' => 'error', 'errorcode' => 34, 'errormsg' => 'access denied for managing block allocations');
    }
    # valid $imageid
    $resources = getUserResources(array("imageAdmin", "imageCheckOut"));
    $resources["image"] = removeNoCheckout($resources["image"]);
    if (!array_key_exists($imageid, $resources['image'])) {
        return array('status' => 'error', 'errorcode' => 3, 'errormsg' => "access denied to {$imageid}");
    }
    # validate $start and $end
    $dtreg = '([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})';
    $startts = datetimeToUnix($start);
    $endts = datetimeToUnix($end);
    $maxend = datetimeToUnix("2038-01-01 00:00:00");
    if (!preg_match("/^{$dtreg}\$/", $start) || $startts < 0 || $startts > $maxend) {
        return array('status' => 'error', 'errorcode' => 4, 'errormsg' => "received invalid input for start");
    }
    if (!preg_match("/^{$dtreg}\$/", $end) || $endts < 0 || $endts > $maxend) {
        return array('status' => 'error', 'errorcode' => 36, 'errormsg' => "received invalid input for end");
    }
    # validate $numMachines
    if (!is_numeric($numMachines) || $numMachines < MIN_BLOCK_MACHINES || $numMachines > MAX_BLOCK_MACHINES) {
        return array('status' => 'error', 'errorcode' => 64, 'errormsg' => 'The submitted number of seats must be between ' . MIN_BLOCK_MACHINES . ' and ' . MAX_BLOCK_MACHINES . '.');
    }
    # validate $usergroupid
    $groups = getUserGroups();
    if (!array_key_exists($usergroupid, $groups)) {
        return array('status' => 'error', 'errorcode' => 67, 'errormsg' => 'Submitted user group does not exist');
    }
    # validate ignoreprivileges
    if (!is_numeric($ignoreprivileges) || $ignoreprivileges < 0 || $ignoreprivileges > 1) {
        return array('status' => 'error', 'errorcode' => 86, 'errormsg' => 'ignoreprivileges must be 0 or 1');
    }
    $ownerid = getUserlistID('vclreload@Local');
    $name = "API:{$start}";
    $managementnodes = getManagementNodes('future');
    if (empty($managementnodes)) {
        return array('status' => 'error', 'errorcode' => 12, 'errormsg' => 'could not allocate a management node to handle block allocation');
    }
    $mnid = array_rand($managementnodes);
    $query = "INSERT INTO blockRequest " . "(name, " . "imageid, " . "numMachines, " . "groupid, " . "repeating, " . "ownerid, " . "managementnodeid, " . "expireTime, " . "status) " . "VALUES " . "('{$name}', " . "{$imageid}, " . "{$numMachines}, " . "{$usergroupid}, " . "'list', " . "{$ownerid}, " . "{$mnid}, " . "'{$end}', " . "'accepted')";
    doQuery($query, 101);
    $brid = dbLastInsertID();
    $query = "INSERT INTO blockTimes " . "(blockRequestid, " . "start, " . "end) " . "VALUES " . "({$brid}, " . "'{$start}', " . "'{$end}')";
    doQuery($query, 101);
    $btid = dbLastInsertID();
    $query = "INSERT INTO blockWebDate " . "(blockRequestid, " . "start, " . "end, " . "days) " . "VALUES " . "({$brid}, " . "'{$start}', " . "'{$end}', " . "0)";
    doQuery($query);
    $sh = date('g', $startts);
    $smi = date('i', $startts);
    $sme = date('a', $startts);
    $eh = date('g', $startts);
    $emi = date('i', $startts);
    $eme = date('a', $startts);
    $query = "INSERT INTO blockWebTime " . "(blockRequestid, " . "starthour, " . "startminute, " . "startmeridian, " . "endhour, " . "endminute, " . "endmeridian, " . "`order`) " . "VALUES " . "({$brid}, " . "{$sh}," . "{$smi}," . "'{$sme}'," . "{$eh}," . "{$emi}," . "'{$eme}'," . "0)";
    doQuery($query);
    $return = XMLRPCprocessBlockTime($btid, $ignoreprivileges);
    $return['blockTimesid'] = $btid;
    return $return;
}
Ejemplo n.º 11
0
 function addResource($data)
 {
     global $user;
     $ownerid = getUserlistID($data['owner']);
     $esc = array('sysadminemail' => mysql_real_escape_string($data['sysadminemail']), 'sharedmailbox' => mysql_real_escape_string($data['sharedmailbox']));
     $keys = array('IPaddress', 'hostname', 'ownerid', 'stateid', 'checkininterval', 'installpath', '`keys`', 'sshport', 'sysadminEmailAddress', 'sharedMailBox', 'availablenetworks', 'NOT_STANDALONE', 'imagelibenable', 'publicIPconfiguration', 'imagelibgroupid', 'imagelibuser', 'imagelibkey', 'publicSubnetMask', 'publicDefaultGateway', 'publicDNSserver');
     $values = array("'{$data['ipaddress']}'", "'{$data['name']}'", $ownerid, $data['stateid'], $data['checkininterval'], "'{$data['installpath']}'", "'{$data['keys']}'", $data['sshport'], "'{$esc['sysadminemail']}'", "'{$esc['sharedmailbox']}'", "'{$data['availablenetworks']}'", "'{$data['federatedauth']}'", $data['imagelibenable'], "'{$data['publicIPconfig']}'");
     if ($data['imagelibenable'] == 1) {
         $values[] = $data['imagelibgroupid'];
         $values[] = "'{$data['imagelibuser']}'";
         $values[] = "'{$data['imagelibkey']}'";
     } else {
         $values[] = 'NULL';
         $values[] = 'NULL';
         $values[] = 'NULL';
     }
     if ($data['publicIPconfig'] == 'static') {
         $values[] = "'{$data['publicnetmask']}'";
         $values[] = "'{$data['publicgateway']}'";
         $values[] = "'{$data['publicdnsserver']}'";
     } else {
         $values[] = 'NULL';
         $values[] = 'NULL';
         $values[] = 'NULL';
     }
     $query = "INSERT INTO managementnode (" . implode(', ', $keys) . ") VALUES (" . implode(', ', $values) . ")";
     doQuery($query);
     $rscid = dbLastInsertID();
     // add entry in resource table
     $query = "INSERT INTO resource " . "(resourcetypeid, " . "subid) " . "VALUES (16, " . "{$rscid})";
     doQuery($query);
     $resourceid = dbLastInsertID();
     # NAT host
     if ($data['nathostenabled']) {
         $query = "INSERT INTO nathost " . "(resourceid, " . "publicIPaddress, " . "internalIPaddress) " . "VALUES " . "({$resourceid}, " . "'{$data['natpublicIPaddress']}', " . "'{$data['natinternalIPaddress']}')";
         doQuery($query);
     }
     # time server
     $globalval = getVariable('timesource|global');
     if ($data['timeservers'] != $globalval) {
         setVariable("timesource|{$data['name']}", $data['timeservers'], 'none');
     }
     return $rscid;
 }
Ejemplo n.º 12
0
 function addResource($data)
 {
     global $user;
     $ownerid = getUserlistID($data['owner']);
     $query = "INSERT INTO schedule " . "(name, " . "ownerid) " . "VALUES ('{$data['name']}', " . "{$ownerid})";
     doQuery($query);
     $rscid = dbLastInsertID();
     if ($rscid == 0) {
         return 0;
     }
     $query = "INSERT INTO resource " . "(resourcetypeid, " . "subid) " . "VALUES (15, " . "{$rscid})";
     doQuery($query, 223);
     return $rscid;
 }