コード例 #1
0
ファイル: statistics.php プロジェクト: bq-xiao/apache-vcl
function getStatGraphConVMUserData($start, $end, $affilid, $mode, $provid)
{
    $startdt = $start . " 00:00:00";
    $enddt = $end . " 23:59:59";
    $startunix = datetimeToUnix($startdt);
    $endunix = datetimeToUnix($enddt) + 1;
    $daycnt = ($endunix - $startunix) / SECINDAY;
    if ($daycnt - (int) $daycnt > 0.5) {
        $daycnt = (int) $daycnt + 1;
    } else {
        $daycnt = (int) $daycnt;
    }
    if ($endunix >= time()) {
        $daycnt--;
    }
    $data = array();
    $data["points"] = array();
    $data["xlabels"] = array();
    $data["maxy"] = 0;
    $cachepts = array();
    $addcache = array();
    $reloadid = getUserlistID('vclreload@Local');
    $cnt = 0;
    $query = "SELECT statdate, " . "value " . "FROM statgraphcache " . "WHERE graphtype = 'concurvm' AND " . "affiliationid = {$affilid} AND " . "statdate >= '{$start}' AND " . "statdate <= '{$end}' AND " . "provisioningid = {$provid}";
    $qh = doQuery($query, 101);
    while ($row = mysql_fetch_assoc($qh)) {
        $cachepts[$row['statdate']] = $row['value'];
    }
    if (count($cachepts) + 31 < $daycnt) {
        $data = array('nodata' => i('(too much computational time required to generate this graph)'));
        return $data;
    }
    for ($daystart = $startunix; $daystart < $endunix; $daystart += SECINDAY) {
        $cnt++;
        $startdt = unixToDatetime($daystart);
        $enddt = unixToDatetime($daystart + SECINDAY);
        $tmp = explode(' ', $startdt);
        $key = $tmp[0];
        if (array_key_exists($key, $cachepts)) {
            $value = $cachepts[$key];
        } else {
            $count = array();
            for ($j = 0; $j < 24; $j++) {
                $count[$j] = 0;
            }
            if ($affilid != 0) {
                $query = "SELECT l.start AS start, " . "l.finalend AS end " . "FROM log l, " . "sublog s, " . "computer c, " . "user u " . "WHERE l.userid = u.id AND " . "l.start < '{$enddt}' AND " . "l.finalend > '{$startdt}' AND " . "s.logid = l.id AND " . "s.computerid = c.id AND " . "l.wasavailable = 1 AND " . "c.type = 'virtualmachine' AND " . "l.userid != {$reloadid} AND " . "u.affiliationid = {$affilid}";
            } else {
                if ($mode == 'default') {
                    $query = "SELECT l.start AS start, " . "l.finalend AS end " . "FROM log l, " . "sublog s, " . "computer c " . "WHERE l.start < '{$enddt}' AND " . "l.finalend > '{$startdt}' AND " . "s.logid = l.id AND " . "s.computerid = c.id AND " . "l.wasavailable = 1 AND " . "c.type = 'virtualmachine' AND " . "l.userid != {$reloadid}";
                } elseif ($mode == 'provisioning') {
                    $query = "SELECT l.start AS start, " . "l.finalend AS end " . "FROM computer c, " . "sublog s, " . "log l " . "JOIN (" . "SELECT s.logid, " . "MIN(s.computerid) AS computerid " . "FROM sublog s, " . "computer c " . "WHERE s.computerid = c.id AND " . "c.provisioningid = {$provid} " . "GROUP BY logid " . ") AS s2 ON (s2.logid = l.id) " . "WHERE l.start < '{$enddt}' AND " . "l.finalend > '{$startdt}' AND " . "s.logid = l.id AND " . "s.computerid = c.id AND " . "l.wasavailable = 1 AND " . "c.type = 'virtualmachine' AND " . "l.userid != {$reloadid}";
                }
            }
            $qh = doQuery($query, 101);
            while ($row = mysql_fetch_assoc($qh)) {
                $unixstart = datetimeToUnix($row["start"]);
                $unixend = datetimeToUnix($row["end"]);
                for ($binstart = $daystart, $binend = $daystart + 3600, $binindex = 0; $binstart <= $unixend && $binend <= $daystart + SECINDAY; $binstart += 3600, $binend += 3600, $binindex++) {
                    if ($binend <= $unixstart) {
                        continue;
                    } elseif ($unixstart < $binend && $unixend > $binstart) {
                        $count[$binindex]++;
                    } elseif ($binstart >= $unixend) {
                        break;
                    }
                }
            }
            rsort($count);
            $value = $count[0];
            $addcache[$startdt] = (int) $value;
        }
        $label = date('m/d/Y', $daystart);
        $data["points"][] = array('y' => $value, 'tooltip' => "{$label}: {$value}");
        if ($value > $data['maxy']) {
            $data['maxy'] = $value;
        }
        $data['xlabels'][] = array('value' => $cnt, 'text' => $label);
    }
    if (count($addcache)) {
        addToStatGraphCache('concurvm', $addcache, $affilid, $provid);
    }
    return $data;
}
コード例 #2
0
ファイル: requests.php プロジェクト: bq-xiao/apache-vcl
function AJsubmitEditRequest()
{
    global $user;
    $requestid = getContinuationVar('requestid');
    $openend = getContinuationVar('openend');
    $allownousercheck = getContinuationVar('nousercheck');
    $modifystart = getContinuationVar('modifystart');
    $startdays = getContinuationVar('startdays');
    $lengths = getContinuationVar('lengths');
    $maxextend = getContinuationVar('maxextend');
    $allowindefiniteend = getContinuationVar('allowindefiniteend');
    $request = getRequestInfo($requestid, 1);
    if (is_null($request)) {
        $cdata = getContinuationVar();
        $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
        sendJSON(array('status' => 'norequest', 'html' => i('The selected reservation no longer exists.') . '<br><br>', 'cont' => $cont));
        return;
    }
    if ($modifystart) {
        $day = processInputVar('day', ARG_NUMERIC, 0);
        if (!in_array($day, $startdays)) {
            $cdata = getContinuationVar();
            $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
            sendJSON(array('status' => 'error', 'errmsg' => i('Invalid start day submitted'), 'cont' => $cont));
            return;
        }
        $starttime = processInputVar('starttime', ARG_STRING);
        if (!preg_match('/^(([01][0-9])|(2[0-3]))([0-5][0-9])$/', $starttime, $matches)) {
            $cdata = getContinuationVar();
            $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
            sendJSON(array('status' => 'error', 'errmsg' => i("Invalid start time submitted"), 'cont' => $cont));
            return;
        }
        preg_match('/^([0-9]{4})([0-9]{2})([0-9]{2})$/', $day, $tmp);
        $startdt = "{$tmp[1]}-{$tmp[2]}-{$tmp[3]} {$matches[1]}:{$matches[4]}:00";
        $startts = datetimeToUnix($startdt);
    } else {
        $startdt = $request['start'];
        $startts = datetimeToUnix($startdt);
    }
    $endmode = processInputVar('endmode', ARG_STRING);
    if ($endmode == 'length') {
        $length = processInputVar('length', ARG_NUMERIC);
        if (!in_array($length, $lengths)) {
            $cdata = getContinuationVar();
            $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
            sendJSON(array('status' => 'error', 'errmsg' => i("Invalid duration submitted"), 'cont' => $cont));
            return;
        }
        if ($modifystart) {
            $endts = $startts + $length * 60;
        } else {
            $tmp = datetimeToUnix($request['end']);
            $endts = $tmp + $length * 60;
        }
        $enddt = unixToDatetime($endts);
    } elseif ($endmode == 'ending') {
        $ending = processInputVar('ending', ARG_NUMERIC);
        if (!preg_match('/^([0-9]{4})([0-9]{2})([0-9]{2})(([01][0-9])|(2[0-3]))([0-5][0-9])$/', $ending, $tmp) || !checkdate($tmp[2], $tmp[3], $tmp[1])) {
            $cdata = getContinuationVar();
            $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
            sendJSON(array('status' => 'error', 'errmsg' => i("Invalid end date/time submitted"), 'cont' => $cont));
            return;
        }
        $enddt = "{$tmp[1]}-{$tmp[2]}-{$tmp[3]} {$tmp[4]}:{$tmp[7]}:00";
        $endts = datetimeToUnix($enddt);
    } elseif ($allowindefiniteend && $endmode == 'indefinite') {
        $endts = datetimeToUnix('2038-01-01 00:00:00');
        $enddt = unixToDatetime($endts);
    } else {
        $cdata = getContinuationVar();
        $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
        sendJSON(array('status' => 'error', 'errmsg' => i("Invalid data submitted"), 'cont' => $cont));
        return;
    }
    $updategroups = 0;
    $updateservername = 0;
    if ($request['serverrequest']) {
        if ($user['showallgroups']) {
            $groups = getUserGroups(0);
        } else {
            $groups = getUserGroups(0, $user['affiliationid']);
        }
        $admingroupid = processInputVar('admingroupid', ARG_NUMERIC);
        $logingroupid = processInputVar('logingroupid', ARG_NUMERIC);
        if ($admingroupid != 0 && !array_key_exists($admingroupid, $groups) && $admingroupid != $request['admingroupid'] || $logingroupid != 0 && !array_key_exists($logingroupid, $groups) && $logingroupid != $request['logingroupid']) {
            $cdata = getContinuationVar();
            $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
            sendJSON(array('status' => 'error', 'errmsg' => i("Invalid user group submitted"), 'cont' => $cont));
            return;
        }
        $testadmingroupid = $admingroupid;
        if ($admingroupid == 0) {
            $testadmingroupid = '';
        }
        $testlogingroupid = $logingroupid;
        if ($logingroupid == 0) {
            $testlogingroupid = '';
        }
        if ($testadmingroupid != $request['admingroupid'] || $testlogingroupid != $request['logingroupid']) {
            $updategroups = 1;
        }
        $servername = processInputVar('servername', ARG_STRING);
        if (!preg_match('/^([-a-zA-Z0-9\\.\\(\\)_ ]){3,255}$/', $servername)) {
            $cdata = getContinuationVar();
            $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
            sendJSON(array('status' => 'error', 'errmsg' => i("The name can only contain letters, numbers, spaces, dashes(-), and periods(.) and can be from 3 to 255 characters long"), 'cont' => $cont));
            return;
        }
        if ($servername != $request['servername']) {
            $servername = mysql_real_escape_string($servername);
            $updateservername = 1;
        }
    }
    $h = '';
    $max = getMaxOverlap($user['id']);
    if (checkOverlap($startts, $endts, $max, $requestid)) {
        if ($max == 0) {
            $m = i("The time you requested overlaps with another reservation you currently have. You are only allowed to have a single reservation at any given time. Please select another time for the reservation.");
            $h .= preg_replace("/(.{1,60}([ \n]|\$))/", '\\1<br>', $m) . "<br>";
        } else {
            $m = sprintf(i("The time you requested overlaps with another reservation you currently have. You are allowed to have %s overlapping reservations at any given time. Please select another time for the reservation."), $max);
            $h .= preg_replace("/(.{1,60}([ \n]|\$))/", '\\1<br>', $m) . "<br>";
        }
        $cdata = getContinuationVar();
        $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
        sendJSON(array('status' => 'error', 'errmsg' => $h, 'cont' => $cont));
        return;
    }
    if ($request['serverrequest'] && (!empty($request['fixedIP']) || !empty($request['fixedMAC']))) {
        $ip = $request['fixedIP'];
        $mac = $request['fixedMAC'];
    } else {
        $ip = '';
        $mac = '';
    }
    $imageid = $request['reservations'][0]['imageid'];
    $images = getImages();
    $revisions = array();
    foreach ($request['reservations'] as $key => $res) {
        $revisions[$res['imageid']][$key] = $res['imagerevisionid'];
    }
    $rc = isAvailable($images, $imageid, $revisions, $startts, $endts, 1, $requestid, 0, 0, 0, $ip, $mac);
    $data = array();
    if ($rc < 1) {
        $cdata = array('now' => 0, 'start' => $startts, 'end' => $endts, 'server' => $allowindefiniteend, 'imageid' => $imageid, 'requestid' => $requestid);
        if (!$modifystart) {
            $cdata['extendonly'] = 1;
        }
        $sugcont = addContinuationsEntry('AJshowRequestSuggestedTimes', $cdata);
        if (array_key_exists('subimages', $images[$imageid]) && count($images[$imageid]['subimages'])) {
            $data['sugcont'] = 'cluster';
        } else {
            $data['sugcont'] = $sugcont;
        }
        addChangeLogEntry($request["logid"], NULL, $enddt, $startdt, NULL, NULL, 0);
    }
    if ($rc == -3) {
        $msgip = '';
        $msgmac = '';
        if (!empty($ip)) {
            $msgip = " ({$ip})";
        }
        if (!empty($mac)) {
            $msgmac = " ({$mac})";
        }
        $h .= sprintf(i("The reserved IP (%s) or MAC address (%s) conflicts with another reservation using the same IP or MAC address. Please select a different time to use the image."), $msgip, $msgmac);
        $h = preg_replace("/(.{1,60}([ \n]|\$))/", '\\1<br>', $h);
        $cdata = getContinuationVar();
        $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
        $data['status'] = 'conflict';
        $data['errmsg'] = $h;
        $data['cont'] = $cont;
        sendJSON($data);
        return;
    } elseif ($rc == -2) {
        $m = i("The time you requested overlaps with a maintenance window. Please select a different time to use the image.");
        $h .= preg_replace("/(.{1,60}([ \n]|\$))/", '\\1<br>', $m) . "<br>";
        $cdata = getContinuationVar();
        $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
        $data['status'] = 'conflict';
        $data['errmsg'] = $h;
        $data['cont'] = $cont;
        sendJSON($data);
        return;
    } elseif ($rc == -1) {
        $m = i("The reservation you are modifying is for an environment limited in the number of concurrent reservations that can be made. The time or duration you have requested overlaps with too many other reservations for the same image. Please select another time or duration for the reservation.");
        $h .= preg_replace("/(.{1,60}([ \n]|\$))/", '\\1<br>', $m) . "<br>";
        $cdata = getContinuationVar();
        $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
        $data['status'] = 'conflict';
        $data['errmsg'] = $h;
        $data['cont'] = $cont;
        sendJSON($data);
        return;
    } elseif ($rc > 0) {
        updateRequest($requestid);
        $serversets = array();
        $reqsets = array();
        if ($updategroups && $request['laststateid'] != 24) {
            if ($admingroupid == 0) {
                $admingroupid = 'NULL';
            }
            if ($logingroupid == 0) {
                $logingroupid = 'NULL';
            }
            $serversets[] = "admingroupid = {$admingroupid}";
            $serversets[] = "logingroupid = {$logingroupid}";
            addChangeLogEntryOther($request['logid'], "event:usergroups|admingroupid:{$admingroupid}|logingroupid:{$logingroupid}");
            $reqsets[] = "stateid = 29";
        }
        if ($updateservername) {
            $serversets[] = "name = '{$servername}'";
        }
        if ($allownousercheck) {
            $newnousercheck = processInputVar('newnousercheck', ARG_NUMERIC);
            if (($newnousercheck == 1 || $newnousercheck == 0) && $newnousercheck == $request['checkuser']) {
                $reqsets[] = "checkuser = (1 - checkuser)";
            }
        }
        if (count($serversets)) {
            $sets = implode(',', $serversets);
            $query = "UPDATE serverrequest " . "SET {$sets} " . "WHERE requestid = {$requestid}";
            doQuery($query);
        }
        if (count($reqsets)) {
            $sets = implode(',', $reqsets);
            $query = "UPDATE request " . "SET {$sets} " . "WHERE id = {$requestid}";
            doQuery($query);
        }
        sendJSON(array('status' => 'success'));
        cleanSemaphore();
        return;
    } else {
        $m = i("The time period you have requested is not available. Please select a different time.");
        $h .= preg_replace("/(.{1,55}([ \n]|\$))/", '\\1<br>', $m) . "<br>";
        $cdata = getContinuationVar();
        $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
        $data['status'] = 'conflict';
        $data['errmsg'] = $h;
        $data['cont'] = $cont;
        sendJSON($data);
    }
}
コード例 #3
0
ファイル: computer.php プロジェクト: bq-xiao/apache-vcl
 function scheduleVMsToAvailable($vmids)
 {
     # TODO test with vcld that will handle reservation for noimage okay
     # schedule $vmids to have noimage "loaded" on them in 15 minutes
     $allids = implode(',', $vmids);
     $query = "UPDATE computer " . "SET stateid = 5, " . "notes = '' " . "WHERE id IN ({$allids})";
     doQuery($query);
     $imageid = getImageId('noimage');
     $revid = getProductionRevisionid($imageid);
     $start = time() + 900;
     $end = $start + 3600;
     $startdt = unixToDatetime($start);
     $enddt = unixToDatetime($end);
     $vclreloadid = getUserlistID('vclreload@Local');
     foreach ($vmids as $vmid) {
         // if simpleAddRequest fails, vm is left assigned and in failed state, which is fine
         simpleAddRequest($vmid, $imageid, $revid, $startdt, $enddt, 19, $vclreloadid);
     }
 }
コード例 #4
0
ファイル: index.php プロジェクト: gw-acadtech/VCL
    $userdata = updateShibUser($userid);
    updateShibGroups($userdata['id'], $_SERVER['affiliation']);
    $usernid = $userdata['id'];
} else {
    $usernid = getUserlistID($userid);
}
# save data to shibauth table
$shibdata = array('Shib-Application-ID' => $_SERVER['Shib-Application-ID'], 'Shib-Identity-Provider' => $_SERVER['Shib-Identity-Provider'], 'Shib-AuthnContext-Dec' => $_SERVER['Shib-AuthnContext-Decl'], 'Shib-logouturl' => $_SERVER['Shib-logouturl'], 'eppn' => $_SERVER['Shib-logouturl'], 'unscoped-affiliation' => $_SERVER['unscoped-affiliation'], 'affiliation' => $_SERVER['affiliation']);
$serdata = mysql_escape_string(serialize($shibdata));
$query = "SELECT id " . "FROM shibauth " . "WHERE sessid = '{$_SERVER['Shib-Session-ID']}'";
$qh = doQuery($query, 101);
if ($row = mysql_fetch_assoc($qh)) {
    $shibauthid = $row['id'];
} else {
    $ts = strtotime($_SERVER['Shib-Authentication-Instant']);
    $ts = unixToDatetime($ts);
    $query = "INSERT INTO shibauth " . "(userid, " . "ts, " . "sessid, " . "data) " . "VALUES " . "({$usernid}, " . "'{$ts}', " . "'{$_SERVER['Shib-Session-ID']}', " . "'{$serdata}')";
    doQuery($query, 101);
    $qh = doQuery("SELECT LAST_INSERT_ID() FROM shibauth", 101);
    if (!($row = mysql_fetch_row($qh))) {
        # todo
    }
    $shibauthid = $row[0];
}
# get cookie data
$cookie = getAuthCookieData($userid, 600, $shibauthid);
# set cookie
if (version_compare(PHP_VERSION, "5.2", ">=") == true) {
    #setcookie("VCLAUTH", "{$cookie['data']}", $cookie['ts'], "/", COOKIEDOMAIN, 1, 1);
    setcookie("VCLAUTH", "{$cookie['data']}", 0, "/", COOKIEDOMAIN, 0, 1);
} else {
コード例 #5
0
ファイル: requests.php プロジェクト: gw-acadtech/VCL
function connectRequest()
{
    global $remoteIP, $user, $inContinuation;
    if ($inContinuation) {
        $requestid = getContinuationVar('requestid', 0);
    } else {
        $requestid = processInputVar("requestid", ARG_NUMERIC);
    }
    $requestData = getRequestInfo($requestid);
    if ($requestData['reservations'][0]['remoteIP'] != $remoteIP) {
        $setback = unixToDatetime(time() - 600);
        $query = "UPDATE reservation " . "SET remoteIP = '{$remoteIP}', " . "lastcheck = '{$setback}' " . "WHERE requestid = {$requestid}";
        $qh = doQuery($query, 226);
        addChangeLogEntry($requestData["logid"], $remoteIP);
    }
    print "<H2 align=center>Connect!</H2>\n";
    if ($requestData['forimaging']) {
        print "<font color=red><big><strong>NOTICE:</strong> Later in this process, you must accept a\n\t\t<a href=\"" . BASEURL . SCRIPT . "?mode=imageClickThrough\">click-through agreement</a> about software licensing.</big></font><br><br>\n";
    }
    if (count($requestData["reservations"]) == 1) {
        $serverIP = $requestData["reservations"][0]["reservedIP"];
        $osname = $requestData["reservations"][0]["OS"];
        $passwd = $requestData["reservations"][0]["password"];
        if (eregi("windows", $osname)) {
            print "You will need to use a ";
            print "Remote Desktop program to connect to the ";
            print "system. If you did not click on the <b>Connect!</b> button from ";
            print "the computer you will be using to access the VCL system, you ";
            print "will need to cancel this reservation, request a new one, and ";
            print "make sure you click the <strong>Connect!</strong> button in ";
            print "a web browser running on the same computer from which you will ";
            print "be connecting to the VCL system. Otherwise, you may be denied ";
            print "access to the remote computer.<br><br>\n";
            print "Use the following information when you are ready to connect:<br>\n";
            print "<UL>\n";
            print "<LI><b>Remote Computer</b>: {$serverIP}</LI>\n";
            if ($requestData["forimaging"]) {
                print "<LI><b>User ID</b>: Administrator</LI>\n";
            } else {
                if (preg_match('/(.*)@(.*)/', $user['unityid'], $matches)) {
                    print "<LI><b>User ID</b>: " . $matches[1] . "</LI>\n";
                } else {
                    print "<LI><b>User ID</b>: " . $user['unityid'] . "</LI>\n";
                }
            }
            if (strlen($passwd)) {
                print "<LI><b>Password</b>: {$passwd}<br></LI>\n";
                print "</UL>\n";
                print "<b>NOTE</b>: The given password is for <i>this reservation ";
                print "only</i>. You will be given a different password for any other ";
                print "reservations.<br>\n";
            } else {
                print "<LI><b>Password</b>: (use your campus password)</LI>\n";
                print "</UL>\n";
            }
            /*print "<br>\n";
            		print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
            		print "<h3>NEW!</h3>\n";
            		print "Connect to the server using a java applet:<br>\n";
            		print "<INPUT type=submit value=\"Connect with Applet\">\n";
            		print "<INPUT type=hidden name=mode value=connectRDPapplet>\n";
            		print "<INPUT type=hidden name=requestid value=$requestid>\n";
            		print "</FORM><br>\n";*/
            print "For automatic connection, you can download an RDP file that can ";
            print "be opened by the Remote Desktop Connection program.<br><br>\n";
            print "<table summary=\"\">\n";
            print "  <TR>\n";
            print "    <TD>\n";
            print "      <FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
            $cdata = array('requestid' => $requestid);
            $expire = datetimeToUnix($requestData['end']) - datetimeToUnix($requestData['start']) + 1800;
            # reservation time plus 30 min
            $cont = addContinuationsEntry('sendRDPfile', $cdata, $expire);
            print "      <INPUT type=hidden name=continuation value=\"{$cont}\">\n";
            print "      <INPUT type=submit value=\"Get RDP File\">\n";
            print "      </FORM>\n";
            print "    </TD>\n";
            print "  </TR>\n";
            print "</table>\n";
        } else {
            print "You will need to have an ";
            print "X server running on your local computer and use an ";
            print "ssh client to connect to the system. If you did not ";
            print "click on the <b>Connect!</b> button from the computer you will ";
            print "need to cancel this reservation, request a new one, and ";
            print "make sure you click the <strong>Connect!</strong> button in ";
            print "a web browser running on the same computer from which you will ";
            print "be connecting to the VCL system. Otherwise, you may be denied ";
            print "access to the remote computer.<br><br>\n";
            print "Use the following information when you are ready to connect:<br>\n";
            print "<UL>\n";
            print "<LI><b>Remote Computer</b>: {$serverIP}</LI>\n";
            if (preg_match('/(.*)@(.*)/', $user['unityid'], $matches)) {
                print "<LI><b>User ID</b>: " . $matches[1] . "</LI>\n";
            } else {
                print "<LI><b>User ID</b>: " . $user['unityid'] . "</LI>\n";
            }
            if (strlen($passwd)) {
                print "<LI><b>Password</b>: {$passwd}<br></LI>\n";
                print "</UL>\n";
                print "<b>NOTE</b>: The given password is for <i>this reservation ";
                print "only</i>. You will be given a different password for any other ";
                print "reservations.<br>\n";
            } else {
                print "<LI><b>Password</b>: (use your campus password)</LI>\n";
                print "</UL>\n";
            }
            print "<strong><big>NOTE:</big> You cannot use the Windows Remote ";
            print "Desktop Connection to connect to this computer. You must use an ";
            print "ssh client.</strong>\n";
            /*if(eregi("windows", $_SERVER["HTTP_USER_AGENT"])) {
            			print "<br><br><h3>NEW!</h3>\n";
            			print "Connect to the server using a java applet:<br>\n";
            			print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
            			print "<INPUT type=submit value=\"Connect with Applet\">\n";
            			print "<INPUT type=hidden name=mode value=connectMindterm>\n";
            			print "<INPUT type=hidden name=serverip value=\"$serverIP\">\n";
            			print "</FORM>\n";
            		}*/
        }
    } else {
        print "You will need an ";
        print "ssh client to connect to any unix systems.<br>\n";
        print "You will need a ";
        print "Remote Desktop program</a> to connect to any windows systems.<br><br>\n";
        print "Use the following information when you are ready to connect:<br>\n";
        $total = count($requestData["reservations"]);
        $count = 0;
        foreach ($requestData["reservations"] as $key => $res) {
            $count++;
            print "<h3>{$res["prettyimage"]}</h3>\n";
            print "<UL>\n";
            print "<LI><b>Platform</b>: {$res["OS"]}</LI>\n";
            print "<LI><b>Remote Computer</b>: {$res["reservedIP"]}</LI>\n";
            print "<LI><b>User ID</b>: " . $user['unityid'] . "</LI>\n";
            if (eregi("windows", $res["OS"])) {
                if (strlen($res['password'])) {
                    print "<LI><b>Password</b>: {$res['password']}<br></LI>\n";
                    print "</UL>\n";
                    print "<b>NOTE</b>: The given password is for <i>this reservation ";
                    print "only</i>. You will be given a different password for any other ";
                    print "reservations.<br>\n";
                } else {
                    print "<LI><b>Password</b>: (use your campus password)</LI>\n";
                    print "</UL>\n";
                }
                /*print "Connect to the server using a java applet:<br>\n";
                		print "<INPUT type=submit value=\"Connect with Applet\">\n";
                		print "<INPUT type=hidden name=mode value=connectRDPapplet>\n";
                		print "<INPUT type=hidden name=requestid value=$requestid>\n";
                		print "<INPUT type=hidden name=reservedIP value=\"{$res["reservedIP"]}\">\n";
                		print "</FORM><br><br>\n";*/
                print "Automatic connection using an RDP file:<br>\n";
                print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
                $cdata = array('requestid' => $requestid, 'reservedIP' => $res['reservedIP']);
                $expire = datetimeToUnix($requestData['end']) - datetimeToUnix($requestData['start']) + 1800;
                # reservation time plus 30 min
                $cont = addContinuationsEntry('sendRDPfile', $cdata, $expire);
                print "<INPUT type=hidden name=continuation value=\"{$cont}\">\n";
                print "<INPUT type=submit value=\"Get RDP File\">\n";
                print "</FORM>\n";
            } else {
                if (strlen($res['password'])) {
                    print "<LI><b>Password</b>: {$res['password']}<br></LI>\n";
                    print "</UL>\n";
                    print "<b>NOTE</b>: The given password is for <i>this reservation ";
                    print "only</i>. You will be given a different password for any other ";
                    print "reservations.<br>\n";
                } else {
                    print "<LI><b>Password</b>: (use your campus password)</LI>\n";
                    print "</UL>\n";
                }
                /*if(eregi("windows", $_SERVER["HTTP_USER_AGENT"])) {
                			print "Connect to the server using a java applet:<br>\n";
                			print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
                			print "<INPUT type=submit value=\"Connect with Applet\">\n";
                			print "<INPUT type=hidden name=mode value=connectMindterm>\n";
                			print "<INPUT type=hidden name=requestid value=$requestid>\n";
                			print "<INPUT type=hidden name=serverip value=\"{$res["reservedIP"]}\">\n";
                			print "</FORM>\n";
                		}*/
            }
            if ($count < $total) {
                print "<hr>\n";
            }
        }
    }
    foreach ($requestData["reservations"] as $res) {
        if ($res["forcheckout"]) {
            $imageid = $res["imageid"];
            break;
        }
    }
    $imagenotes = getImageNotes($imageid);
    if (preg_match('/\\w/', $imagenotes['usage'])) {
        print "<h3>Notes on using this environment:</h3>\n";
        print "{$imagenotes['usage']}<br><br><br>\n";
    }
}
コード例 #6
0
ファイル: statistics.php プロジェクト: gw-acadtech/VCL
function getStatGraphConBladeUserData($start, $end, $affilid)
{
    $startdt = $start . " 00:00:00";
    $enddt = $end . " 23:59:59";
    $startunix = datetimeToUnix($startdt);
    $endunix = datetimeToUnix($enddt) + 1;
    $days = ($endunix - $startunix) / SECINDAY;
    $data = array();
    $data["points"] = array();
    $data["labels"] = array();
    $reloadid = getUserlistID('vclreload@Local');
    for ($daystart = $startunix; $daystart < $endunix; $daystart += SECINDAY) {
        array_push($data["labels"], date('Y-m-d', $daystart));
        $count = array();
        for ($j = 0; $j < 24; $j++) {
            $count[$j] = 0;
        }
        $startdt = unixToDatetime($daystart);
        $enddt = unixToDatetime($daystart + SECINDAY);
        if ($affilid != 0) {
            $query = "SELECT l.start AS start, " . "l.finalend AS end " . "FROM log l, " . "sublog s, " . "computer c, " . "user u " . "WHERE l.userid = u.id AND " . "l.start < '{$enddt}' AND " . "l.finalend > '{$startdt}' AND " . "s.logid = l.id AND " . "s.computerid = c.id AND " . "l.wasavailable = 1 AND " . "c.type = 'blade' AND " . "l.userid != {$reloadid} AND " . "u.affiliationid = {$affilid}";
        } else {
            $query = "SELECT l.start AS start, " . "l.finalend AS end " . "FROM log l, " . "sublog s, " . "computer c " . "WHERE l.start < '{$enddt}' AND " . "l.finalend > '{$startdt}' AND " . "s.logid = l.id AND " . "s.computerid = c.id AND " . "l.wasavailable = 1 AND " . "c.type = 'blade' AND " . "l.userid != {$reloadid}";
        }
        $qh = doQuery($query, 101);
        while ($row = mysql_fetch_assoc($qh)) {
            $unixstart = datetimeToUnix($row["start"]);
            $unixend = datetimeToUnix($row["end"]);
            for ($binstart = $daystart, $binend = $daystart + 3600, $binindex = 0; $binstart <= $unixend && $binend <= $daystart + SECINDAY; $binstart += 3600, $binend += 3600, $binindex++) {
                if ($binend <= $unixstart) {
                    continue;
                } elseif ($unixstart < $binend && $unixend > $binstart) {
                    $count[$binindex]++;
                } elseif ($binstart >= $unixend) {
                    break;
                }
            }
        }
        rsort($count);
        array_push($data["points"], $count[0]);
    }
    return $data;
}
コード例 #7
0
ファイル: vm.php プロジェクト: gw-acadtech/VCL
function AJvmFromHostDelayed()
{
    $data = getContinuationVar();
    $vclreloadid = getUserlistID('vclreload@Local');
    foreach ($data as $comp) {
        $end = datetimeToUnix($comp['end2']) + SECINMONTH;
        $end = unixToDatetime($end);
        simpleAddRequest($comp['id'], 4, 3, $comp['end2'], $end, 18, $vclreloadid);
    }
    header('Content-Type: text/json-comment-filtered; charset=utf-8');
    $cont = addContinuationsEntry('vmhostdata');
    $arr = array('msg' => 'SUCCESS', 'cont' => $cont);
    print '/*{"items":' . json_encode($arr) . '}*/';
}
コード例 #8
0
ファイル: computers.php プロジェクト: gw-acadtech/VCL
function submitCompStateChange()
{
    global $user;
    print "<H2>Change State of Computers</H2>\n";
    $data = getContinuationVar();
    $computers = getComputers(1);
    # switching to available
    if ($data['stateid'] == 2) {
        $compids = implode(',', $data['computerids']);
        $query = "UPDATE computer " . "SET stateid = 2, " . "notes = '' " . "WHERE id IN ({$compids})";
        doQuery($query, 101);
        print "The following computers were changed to the available state:\n";
        print "<TABLE>\n";
        foreach ($data['computerids'] as $compid) {
            print "  <TR>\n";
            print "    <TD>{$computers[$compid]['hostname']}</TD>\n";
            print "  </TR>\n";
        }
        print "</TABLE>\n";
    } elseif ($data['stateid'] == 10) {
        $data['notes'] = processInputVar('notes', ARG_STRING);
        if (get_magic_quotes_gpc()) {
            $data['notes'] = stripslashes($data['notes']);
        }
        $data['notes'] = mysql_escape_string($data['notes']);
        $data["notes"] = $user["unityid"] . " " . unixToDatetime(time()) . "@" . $data["notes"];
        $vclreloadid = getUserlistID('vclreload@Local');
        // get semaphore lock
        if (!semLock()) {
            abort(3);
        }
        $noaction = array();
        $changenow = array();
        $changeasap = array();
        $changetimes = array();
        foreach ($data['computerids'] as $compid) {
            if ($computers[$compid]['state'] == 'maintenance') {
                array_push($noaction, $compid);
            } else {
                array_push($changeasap, $compid);
            }
        }
        $passes = array();
        $fails = array();
        foreach ($changeasap as $compid) {
            # TODO what about blockComputers?
            # try to move future reservations off of computer
            moveReservationsOffComputer($compid);
            # get end time of last reservation
            $query = "SELECT rq.end " . "FROM request rq, " . "reservation rs " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = {$compid} AND " . "rq.stateid NOT IN (1,5,12) " . "ORDER BY end DESC " . "LIMIT 1";
            $qh = doQuery($query, 101);
            # create a really long reservation starting at that time in state tomaintenance
            if ($row = mysql_fetch_assoc($qh)) {
                $start = $row['end'];
                $changetimes[$compid] = $start;
                $end = datetimeToUnix($start) + SECINWEEK;
                // hopefully keep future reservations off of it
                $end = unixToDatetime($end);
                if (simpleAddRequest($compid, 4, 3, $start, $end, 18, $vclreloadid)) {
                    $passes[] = $compid;
                } else {
                    $fails[] = $compid;
                }
            } else {
                $query = "UPDATE computer " . "SET stateid = 10, " . "notes = '{$data['notes']}' " . "WHERE id = {$compid}";
                doQuery($query, 101);
                unset_by_val($compid, $changeasap);
                array_push($changenow, $compid);
            }
        }
        // release semaphore lock
        semUnlock();
        if (count($noaction) || count($changeasap)) {
            $comparr = array_merge($noaction, $changeasap);
            $compids = implode(',', $comparr);
            $query = "UPDATE computer " . "SET notes = '{$data['notes']}' " . "WHERE id IN ({$compids})";
            doQuery($query, 101);
        }
        if (count($changenow)) {
            print "The following computers were immediately placed into the ";
            print "maintenance state:\n";
            print "<TABLE>\n";
            foreach ($changenow as $compid) {
                print "  <TR>\n";
                print "    <TD><font color=\"#008000\">{$computers[$compid]['hostname']}</font></TD>\n";
                print "  </TR>\n";
            }
            print "</TABLE>\n";
            print "<br>\n";
        }
        if (count($passes)) {
            print "The following computers currently have reservations on them ";
            print "and will be placed in the maintenance state at the time listed ";
            print "for each computer:\n";
            print "<TABLE>\n";
            print "  <TR>\n";
            print "    <TH>Computer</TH>\n";
            print "    <TH>Maintenance time</TH>\n";
            print "  </TR>\n";
            foreach ($passes as $compid) {
                print "  <TR>\n";
                print "    <TD align=center><font color=\"ff8c00\">{$computers[$compid]['hostname']}</font></TD>\n";
                $time = date('n/j/y g:i a', datetimeToUnix($changetimes[$compid]));
                print "    <TD align=center>{$time}</TD>\n";
                print "  </TR>\n";
            }
            print "</TABLE>\n";
            print "<br>\n";
        }
        if (count($fails)) {
            print "The following computers currently have reservations on them ";
            print "but no functional management node was found for them. Nothing ";
            print "be done with them at this time:\n";
            print "<TABLE>\n";
            print "  <TR>\n";
            print "    <TH>Computer</TH>\n";
            print "  </TR>\n";
            foreach ($passes as $compid) {
                print "  <TR>\n";
                print "    <TD align=center><font color=\"ff0000\">{$computers[$compid]['hostname']}</font></TD>\n";
                print "  </TR>\n";
            }
            print "</TABLE>\n";
            print "<br>\n";
        }
        if (count($noaction)) {
            print "The following computers were already in the maintenance ";
            print "state and had their notes on being in the maintenance state ";
            print "updated:\n";
            print "<TABLE>\n";
            foreach ($noaction as $compid) {
                print "  <TR>\n";
                print "    <TD>{$computers[$compid]['hostname']}</TD>\n";
                print "  </TR>\n";
            }
            print "</TABLE>\n";
            print "<br>\n";
        }
    } elseif ($data['stateid'] == 20) {
        $profileid = processInputVar('profileid', ARG_NUMERIC);
        if (!array_key_exists($profileid, $data['profiles'])) {
            $keys = array_keys($data['profiles']);
            $profileid = $keys[0];
        }
        $noaction = array();
        $changenow = array();
        $changeasap = array();
        $changetimes = array();
        foreach ($data['computerids'] as $compid) {
            if ($computers[$compid]['state'] == 'vmhostinuse') {
                array_push($noaction, $compid);
            } else {
                array_push($changeasap, $compid);
            }
        }
        if (!semLock()) {
            abort(3);
        }
        foreach ($changeasap as $compid) {
            # TODO what about blockComputers?
            moveReservationsOffComputer($compid);
            # get end time of last reservation
            $query = "SELECT rq.end " . "FROM request rq, " . "reservation rs " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = {$compid} AND " . "rq.stateid NOT IN (1,5,12) " . "ORDER BY end DESC " . "LIMIT 1";
            $qh = doQuery($query, 101);
            if ($row = mysql_fetch_assoc($qh)) {
                // if there is a reservation, leave in $changeasap so we can
                #   notify that we can't change this one
            } else {
                # create a reload reservation to load machine with image
                #   corresponding to selected vm profile
                $start = getReloadStartTime();
                $end = $start + SECINYEAR;
                # don't want anyone making a future reservation for this machine
                $start = unixToDatetime($start);
                $end = unixToDatetime($end);
                $imagerevisionid = getProductionRevisionid($data['profiles'][$profileid]['imageid']);
                $vclreloadid = getUserlistID('vclreload@Local');
                simpleAddRequest($compid, $data['profiles'][$profileid]['imageid'], $imagerevisionid, $start, $end, 21, $vclreloadid);
                unset_by_val($compid, $changeasap);
                array_push($changenow, $compid);
                # check for existing vmhost entry
                $query = "SELECT id, " . "vmprofileid " . "FROM vmhost " . "WHERE computerid = {$compid}";
                $qh = doQuery($query, 101);
                if ($row = mysql_fetch_assoc($qh)) {
                    if ($row['vmprofileid'] != $profileid) {
                        # update vmprofile
                        $query = "UPDATE vmhost " . "SET vmprofileid = {$profileid} " . "WHERE id = {$row['id']}";
                        doQuery($query, 101);
                    }
                } else {
                    # create vmhost entry
                    $query = "INSERT INTO vmhost " . "(computerid, " . "vmlimit, " . "vmprofileid) " . "VALUES ({$compid}, " . "2, " . "{$profileid})";
                    doQuery($query, 101);
                }
            }
        }
        // release semaphore lock
        semUnlock();
        if (count($changenow)) {
            print "The following computers were placed into the ";
            print "vmhostinuse state:\n";
            print "<TABLE>\n";
            foreach ($changenow as $compid) {
                print "  <TR>\n";
                print "    <TD><font color=\"#008000\">{$computers[$compid]['hostname']}</font></TD>\n";
                print "  </TR>\n";
            }
            print "</TABLE>\n";
            print "<br>\n";
        }
        if (count($changeasap)) {
            print "The following computers currently have reservations on them ";
            print "and cannot be placed in the vmhostinuse state at this time:\n";
            print "<TABLE>\n";
            foreach ($changeasap as $compid) {
                print "  <TR>\n";
                print "    <TD><font color=\"ff0000\">{$computers[$compid]['hostname']}</font></TD>\n";
                print "  </TR>\n";
            }
            print "</TABLE>\n";
            print "<br>\n";
        }
        if (count($noaction)) {
            print "The following computers were already in the vmhostinuse ";
            print "state:\n";
            print "<TABLE>\n";
            foreach ($noaction as $compid) {
                print "  <TR>\n";
                print "    <TD>{$computers[$compid]['hostname']}</TD>\n";
                print "  </TR>\n";
            }
            print "</TABLE>\n";
            print "<br>\n";
        }
    } elseif ($data['stateid'] == 23) {
        $noaction = array();
        $changenow = array();
        $changeasap = array();
        $changetimes = array();
        foreach ($data['computerids'] as $compid) {
            if ($computers[$compid]['state'] == 'hpc') {
                array_push($noaction, $compid);
            } else {
                array_push($changeasap, $compid);
            }
        }
        if (!semLock()) {
            abort(3);
        }
        foreach ($changeasap as $compid) {
            # TODO what about blockComputers?
            moveReservationsOffComputer($compid);
            # get end time of last reservation
            $query = "SELECT rq.end " . "FROM request rq, " . "reservation rs " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = {$compid} AND " . "rq.stateid NOT IN (1,5,12) " . "ORDER BY end DESC " . "LIMIT 1";
            $qh = doQuery($query, 101);
            if ($row = mysql_fetch_assoc($qh)) {
                // if there is a reservation, leave in $changeasap so we can
                #   notify that we can't change this one
            } else {
                $query = "UPDATE computer " . "SET stateid = 23 " . "WHERE id = {$compid}";
                doQuery($query, 101);
                unset_by_val($compid, $changeasap);
                array_push($changenow, $compid);
            }
        }
        // release semaphore lock
        semUnlock();
        if (count($changenow)) {
            print "The following computers were placed into the ";
            print "hpc state:\n";
            print "<TABLE>\n";
            foreach ($changenow as $compid) {
                print "  <TR>\n";
                print "    <TD><font color=\"#008000\">{$computers[$compid]['hostname']}</font></TD>\n";
                print "  </TR>\n";
            }
            print "</TABLE>\n";
            print "<br>\n";
        }
        if (count($changeasap)) {
            print "The following computers currently have reservations on them ";
            print "and cannot be placed in the hpc state at this time:\n";
            print "<TABLE>\n";
            foreach ($changeasap as $compid) {
                print "  <TR>\n";
                print "    <TD><font color=\"ff0000\">{$computers[$compid]['hostname']}</font></TD>\n";
                print "  </TR>\n";
            }
            print "</TABLE>\n";
            print "<br>\n";
        }
        if (count($noaction)) {
            print "The following computers were already in the hpc ";
            print "state:\n";
            print "<TABLE>\n";
            foreach ($noaction as $compid) {
                print "  <TR>\n";
                print "    <TD>{$computers[$compid]['hostname']}</TD>\n";
                print "  </TR>\n";
            }
            print "</TABLE>\n";
            print "<br>\n";
        }
    } else {
        abort(50);
    }
}
コード例 #9
0
ファイル: itecsauth.php プロジェクト: gw-acadtech/VCL
function updateITECSUser($userid)
{
    global $ENABLE_ITECSAUTH;
    if (!$ENABLE_ITECSAUTH) {
        return NULL;
    }
    $query = "SELECT id AS uid, " . "first, " . "last, " . "email, " . "created " . "FROM user " . "WHERE email = '{$userid}'";
    $qh = doQuery($query, 101, "accounts");
    if (!($userData = mysql_fetch_assoc($qh))) {
        return NULL;
    }
    $now = unixToDatetime(time());
    // select desired data from db
    $query = "SELECT i.name AS IMtype, " . "u.IMid AS IMid, " . "u.affiliationid, " . "af.name AS affiliation, " . "a.name AS adminlevel, " . "a.id AS adminlevelid, " . "u.preferredname AS preferredname, " . "u.uid AS uid, " . "u.id AS id, " . "u.width AS width, " . "u.height AS height, " . "u.bpp AS bpp, " . "u.audiomode AS audiomode, " . "u.mapdrives AS mapdrives, " . "u.mapprinters AS mapprinters, " . "u.mapserial AS mapserial, " . "u.showallgroups " . "FROM user u, " . "IMtype i, " . "affiliation af, " . "adminlevel a " . "WHERE u.IMtypeid = i.id AND " . "u.adminlevelid = a.id AND " . "u.affiliationid = af.id AND " . "u.uid = " . $userData["uid"];
    $qh = doQuery($query, 255);
    // if get a row
    //    update db
    //    update results from select
    $esc_userid = mysql_escape_string($userid);
    $first = mysql_escape_string($userData['first']);
    $last = mysql_escape_string($userData['last']);
    $email = mysql_escape_string($userData['email']);
    if ($user = mysql_fetch_assoc($qh)) {
        $user["unityid"] = $userid;
        $user["firstname"] = $userData['first'];
        $user["lastname"] = $userData["last"];
        $user["email"] = $userData["email"];
        $user["lastupdated"] = $now;
        $query = "UPDATE user " . "SET unityid = '{$esc_userid}', " . "firstname = '{$first}', " . "lastname = '{$last}', " . "email = '{$email}', " . "lastupdated = '{$now}' " . "WHERE uid = " . $userData["uid"];
        doQuery($query, 256, 'vcl', 1);
    } else {
        //    call addITECSUser
        $id = addITECSUser($userid);
        $query = "SELECT u.unityid AS unityid, " . "u.affiliationid, " . "af.name AS affiliation, " . "u.firstname AS firstname, " . "u.lastname AS lastname, " . "u.preferredname AS preferredname, " . "u.email AS email, " . "i.name AS IMtype, " . "u.IMid AS IMid, " . "u.uid AS uid, " . "u.id AS id, " . "a.name AS adminlevel, " . "a.id AS adminlevelid, " . "u.width AS width, " . "u.height AS height, " . "u.bpp AS bpp, " . "u.audiomode AS audiomode, " . "u.mapdrives AS mapdrives, " . "u.mapprinters AS mapprinters, " . "u.mapserial AS mapserial, " . "u.showallgroups, " . "u.lastupdated AS lastupdated " . "FROM user u, " . "IMtype i, " . "affiliation af, " . "adminlevel a " . "WHERE u.IMtypeid = i.id AND " . "u.adminlevelid = a.id AND " . "u.affiliationid = af.id AND " . "u.id = {$id}";
        $qh = doQuery($query, 101);
        $user = mysql_fetch_assoc($qh);
        # add account to demo group
        $demoid = getUserGroupID('demo', getAffiliationID('ITECS'));
        updateGroups(array($demoid), $user['id']);
    }
    $user["groups"] = getUsersGroups($user["id"], 1);
    checkExpiredDemoUser($user['id'], $user['groups']);
    $user["privileges"] = getOverallUserPrivs($user["id"]);
    $tmparr = explode('@', $user['unityid']);
    $user['login'] = $tmparr[0];
    return $user;
}
コード例 #10
0
ファイル: ldapauth.php プロジェクト: gw-acadtech/VCL
function updateLDAPUser($authtype, $userid)
{
    global $authMechs;
    $userData = getLDAPUserData($authtype, $userid);
    if (is_null($userData)) {
        return NULL;
    }
    $affilid = $authMechs[$authtype]['affiliationid'];
    $now = unixToDatetime(time());
    // select desired data from db
    $query = "SELECT i.name AS IMtype, " . "u.IMid AS IMid, " . "u.affiliationid, " . "af.name AS affiliation, " . "af.shibonly, " . "u.emailnotices, " . "a.name AS adminlevel, " . "a.id AS adminlevelid, " . "u.preferredname AS preferredname, " . "u.uid AS uid, " . "u.id AS id, " . "u.width AS width, " . "u.height AS height, " . "u.bpp AS bpp, " . "u.audiomode AS audiomode, " . "u.mapdrives AS mapdrives, " . "u.mapprinters AS mapprinters, " . "u.mapserial AS mapserial, " . "u.showallgroups " . "FROM user u, " . "IMtype i, " . "adminlevel a, " . "affiliation af " . "WHERE u.IMtypeid = i.id AND " . "u.adminlevelid = a.id AND " . "af.id = {$affilid} AND ";
    if (array_key_exists('numericid', $userData) && is_numeric($userData['numericid'])) {
        $query .= "u.uid = " . $userData["numericid"];
    } else {
        $query .= "u.unityid = '{$userid}' AND " . "u.affiliationid = {$affilid}";
    }
    $qh = doQuery($query, 255);
    // if get a row
    //    update db
    //    update results from select
    if ($user = mysql_fetch_assoc($qh)) {
        $user["unityid"] = $userid;
        $user["firstname"] = $userData['first'];
        $user["lastname"] = $userData["last"];
        $user["email"] = $userData["email"];
        $user["lastupdated"] = $now;
        $query = "UPDATE user " . "SET unityid = '{$userid}', " . "firstname = '{$userData['first']}', " . "lastname = '{$userData['last']}', " . "email = '{$userData['email']}', " . "lastupdated = '{$now}' ";
        if (array_key_exists('numericid', $userData) && is_numeric($userData['numericid'])) {
            $query .= "WHERE uid = " . $userData["numericid"];
        } else {
            $query .= "WHERE unityid = '{$userid}' AND " . "affiliationid = {$affilid}";
        }
        doQuery($query, 256, 'vcl', 1);
    } else {
        //    call addLDAPUser
        $id = addLDAPUser($authtype, $userid);
        $query = "SELECT u.unityid AS unityid, " . "u.affiliationid, " . "af.name AS affiliation, " . "u.firstname AS firstname, " . "u.lastname AS lastname, " . "u.preferredname AS preferredname, " . "u.email AS email, " . "i.name AS IMtype, " . "u.IMid AS IMid, " . "u.uid AS uid, " . "u.id AS id, " . "a.name AS adminlevel, " . "a.id AS adminlevelid, " . "u.width AS width, " . "u.height AS height, " . "u.bpp AS bpp, " . "u.audiomode AS audiomode, " . "u.mapdrives AS mapdrives, " . "u.mapprinters AS mapprinters, " . "u.mapserial AS mapserial, " . "u.showallgroups, " . "u.lastupdated AS lastupdated " . "FROM user u, " . "IMtype i, " . "affiliation af, " . "adminlevel a " . "WHERE u.IMtypeid = i.id AND " . "u.adminlevelid = a.id AND " . "u.affiliationid = af.id AND " . "u.id = {$id}";
        $qh = doQuery($query, 101);
        if (!($user = mysql_fetch_assoc($qh))) {
            return NULL;
        }
    }
    // TODO handle generic updating of groups
    switch (getAffiliationName($affilid)) {
        case 'EXAMPLE1':
            updateEXAMPLE1Groups($user);
            break;
        default:
            //TODO possibly add to a default group
    }
    $user["groups"] = getUsersGroups($user["id"], 1);
    $user["privileges"] = getOverallUserPrivs($user["id"]);
    $user['login'] = $user['unityid'];
    return $user;
}
コード例 #11
0
ファイル: vm.php プロジェクト: bq-xiao/apache-vcl
function AJvmFromHostDelayed()
{
    $data = getContinuationVar();
    $vclreloadid = getUserlistID('vclreload@Local');
    $imageid = getImageId('noimage');
    $imagerevisionid = getProductionRevisionid($imageid);
    $fails = array();
    foreach ($data as $comp) {
        $end = datetimeToUnix($comp['end2']) + SECINMONTH;
        $end = unixToDatetime($end);
        if (!simpleAddRequest($comp['id'], $imageid, $imagerevisionid, $comp['end2'], $end, 18, $vclreloadid)) {
            $fails[] = array('name' => $comp['hostname'], 'reason' => 'nomgtnode');
        }
    }
    $cont = addContinuationsEntry('vmhostdata');
    $arr = array('msg' => 'SUCCESS', 'cont' => $cont, 'fails' => $fails);
    sendJSON($arr);
}
コード例 #12
0
ファイル: privileges.php プロジェクト: bq-xiao/apache-vcl
function userLookup()
{
    global $user;
    $userid = processInputVar("userid", ARG_STRING);
    if (get_magic_quotes_gpc()) {
        $userid = stripslashes($userid);
    }
    $affilid = processInputVar('affiliationid', ARG_NUMERIC, $user['affiliationid']);
    $force = processInputVar('force', ARG_NUMERIC, 0);
    print "<div align=center>\n";
    print "<H2>User Lookup</H2>\n";
    print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
    print "<TABLE>\n";
    print "  <TR>\n";
    print "    <TH>Name (last, first) or User ID:</TH>\n";
    print "    <TD><INPUT type=text name=userid value=\"{$userid}\" size=25></TD>\n";
    if (checkUserHasPerm('User Lookup (global)')) {
        $affils = getAffiliations();
        print "    <TD>\n";
        print "@";
        printSelectInput("affiliationid", $affils, $affilid);
        print "    </TD>\n";
    }
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TD colspan=2>\n";
    print "      <input type=checkbox id=force name=force value=1>\n";
    print "      <label for=force>Attempt forcing an update from LDAP (User ID only)</label>\n";
    print "    </TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TD colspan=3 align=center><INPUT type=submit value=Submit>\n";
    print "  </TR>\n";
    print "</TABLE>\n";
    $cont = addContinuationsEntry('submitUserLookup');
    print "<INPUT type=hidden name=continuation value=\"{$cont}\">\n";
    print "</FORM><br>\n";
    if (!empty($userid)) {
        $esc_userid = mysql_real_escape_string($userid);
        if (preg_match('/,/', $userid)) {
            $mode = 'name';
            $force = 0;
        } else {
            $mode = 'userid';
        }
        if (!checkUserHasPerm('User Lookup (global)') && $user['affiliationid'] != $affilid) {
            print "<font color=red>{$userid} not found</font><br>\n";
            return;
        }
        if ($mode == 'userid') {
            $query = "SELECT id " . "FROM user " . "WHERE unityid = '{$esc_userid}' AND " . "affiliationid = {$affilid}";
            $affilname = getAffiliationName($affilid);
            $userid = "{$userid}@{$affilname}";
            $esc_userid = "{$esc_userid}@{$affilname}";
        } else {
            $tmp = explode(',', $userid);
            $last = mysql_real_escape_string(trim($tmp[0]));
            $first = mysql_real_escape_string(trim($tmp[1]));
            $query = "SELECT CONCAT(u.unityid, '@', a.name) AS unityid " . "FROM user u, " . "affiliation a " . "WHERE u.firstname = '{$first}' AND " . "u.lastname = '{$last}' AND " . "u.affiliationid = {$affilid} AND " . "a.id = {$affilid}";
        }
        $qh = doQuery($query, 101);
        if (!mysql_num_rows($qh)) {
            if ($mode == 'name') {
                print "<font color=red>User not found</font><br>\n";
                return;
            } else {
                print "<font color=red>{$userid} not currently found in VCL user database, will try to add...</font><br>\n";
            }
        } elseif ($force) {
            $_SESSION['userresources'] = array();
            $row = mysql_fetch_assoc($qh);
            $newtime = unixToDatetime(time() - SECINDAY - 5);
            $query = "UPDATE user SET lastupdated = '{$newtime}' WHERE id = {$row['id']}";
            doQuery($query, 101);
        } elseif ($mode == 'name') {
            $row = mysql_fetch_assoc($qh);
            $userid = $row['unityid'];
            $esc_userid = $row['unityid'];
        }
        $userdata = getUserInfo($esc_userid);
        if (is_null($userdata)) {
            $userdata = getUserInfo($esc_userid, 1);
            if (is_null($userdata)) {
                print "<font color=red>{$userid} not found</font><br>\n";
                return;
            }
        }
        $userdata["groups"] = getUsersGroups($userdata["id"], 1, 1);
        print "<TABLE>\n";
        if (!empty($userdata['unityid'])) {
            print "  <TR>\n";
            print "    <TH align=right>User ID:</TH>\n";
            print "    <TD>{$userdata["unityid"]}</TD>\n";
            print "  </TR>\n";
        }
        if (!empty($userdata['firstname'])) {
            print "  <TR>\n";
            print "    <TH align=right>First Name:</TH>\n";
            print "    <TD>{$userdata["firstname"]}</TD>\n";
            print "  </TR>\n";
        }
        if (!empty($userdata['lastname'])) {
            print "  <TR>\n";
            print "    <TH align=right>Last Name:</TH>\n";
            print "    <TD>{$userdata["lastname"]}</TD>\n";
            print "  </TR>\n";
        }
        if (!empty($userdata['preferredname'])) {
            print "  <TR>\n";
            print "    <TH align=right>Preferred Name:</TH>\n";
            print "    <TD>{$userdata["preferredname"]}</TD>\n";
            print "  </TR>\n";
        }
        if (!empty($userdata['affiliation'])) {
            print "  <TR>\n";
            print "    <TH align=right>Affiliation:</TH>\n";
            print "    <TD>{$userdata["affiliation"]}</TD>\n";
            print "  </TR>\n";
        }
        if (!empty($userdata['email'])) {
            print "  <TR>\n";
            print "    <TH align=right>Email:</TH>\n";
            print "    <TD>{$userdata["email"]}</TD>\n";
            print "  </TR>\n";
        }
        print "  <TR>\n";
        print "    <TH align=right style=\"vertical-align: top\">Groups:</TH>\n";
        print "    <TD>\n";
        uasort($userdata["groups"], "sortKeepIndex");
        foreach ($userdata["groups"] as $group) {
            print "      {$group}<br>\n";
        }
        print "    </TD>\n";
        print "  </TR>\n";
        print "  <TR>\n";
        print "    <TH align=right style=\"vertical-align: top\">User Group Permissions:</TH>\n";
        print "    <TD>\n";
        if (count($userdata['groupperms'])) {
            foreach ($userdata['groupperms'] as $perm) {
                print "      {$perm}<br>\n";
            }
        } else {
            print "      No additional user group permissions\n";
        }
        print "    </TD>\n";
        print "  </TR>\n";
        print "  <TR>\n";
        print "    <TH align=right style=\"vertical-align: top\">Privileges (found somewhere in the tree):</TH>\n";
        print "    <TD>\n";
        uasort($userdata["privileges"], "sortKeepIndex");
        foreach ($userdata["privileges"] as $priv) {
            if ($priv == "block" || $priv == "cascade") {
                continue;
            }
            print "      {$priv}<br>\n";
        }
        print "    </TD>\n";
        print "  </TR>\n";
        print "</TABLE>\n";
        # get user's resources
        $userResources = getUserResources(array("imageCheckOut"), array("available"), 0, 0, $userdata['id']);
        # find nodes where user has privileges
        $query = "SELECT p.name AS privnode, " . "upt.name AS userprivtype, " . "up.privnodeid " . "FROM userpriv up, " . "privnode p, " . "userprivtype upt " . "WHERE up.privnodeid = p.id AND " . "up.userprivtypeid = upt.id AND " . "up.userid = {$userdata['id']} " . "ORDER BY p.name, " . "upt.name";
        $qh = doQuery($query, 101);
        if (mysql_num_rows($qh)) {
            print "Nodes where user is granted privileges:<br>\n";
            print "<TABLE>\n";
            $privnodeid = 0;
            while ($row = mysql_fetch_assoc($qh)) {
                if ($privnodeid != $row['privnodeid']) {
                    if ($privnodeid) {
                        print "    </TD>\n";
                        print "  </TR>\n";
                    }
                    print "  <TR>\n";
                    $privnodeid = $row['privnodeid'];
                    $path = getNodePath($privnodeid);
                    print "    <TH align=right>{$path}</TH>\n";
                    print "    <TD>\n";
                }
                print "      {$row['userprivtype']}<br>\n";
            }
            print "    </TD>\n";
            print "  </TR>\n";
            print "</TABLE>\n";
        }
        # find nodes where user's groups have privileges
        if (!empty($userdata['groups'])) {
            $query = "SELECT DISTINCT p.name AS privnode, " . "upt.name AS userprivtype, " . "up.privnodeid " . "FROM userpriv up, " . "privnode p, " . "userprivtype upt " . "WHERE up.privnodeid = p.id AND " . "up.userprivtypeid = upt.id AND " . "upt.name != 'cascade' AND " . "upt.name != 'block' AND " . "up.usergroupid IN (" . implode(',', array_keys($userdata['groups'])) . ") " . "ORDER BY p.name, " . "upt.name";
            $qh = doQuery($query, 101);
            if (mysql_num_rows($qh)) {
                print "Nodes where user's groups are granted privileges:<br>\n";
                print "<TABLE>\n";
                $privnodeid = 0;
                while ($row = mysql_fetch_assoc($qh)) {
                    if ($privnodeid != $row['privnodeid']) {
                        if ($privnodeid) {
                            print "    </TD>\n";
                            print "  </TR>\n";
                        }
                        print "  <TR>\n";
                        $privnodeid = $row['privnodeid'];
                        $path = getNodePath($privnodeid);
                        print "    <TH align=right>{$path}</TH>\n";
                        print "    <TD>\n";
                    }
                    print "      {$row['userprivtype']}<br>\n";
                }
                print "    </TD>\n";
                print "  </TR>\n";
                print "</TABLE>\n";
            }
        }
        print "<table>\n";
        print "  <tr>\n";
        print "    <th>Images User Has Access To:<th>\n";
        print "    <td>\n";
        foreach ($userResources['image'] as $img) {
            print "      {$img}<br>\n";
        }
        print "    </td>\n";
        print "  </tr>\n";
        print "</table>\n";
        # login history
        $query = "SELECT authmech, " . "timestamp, " . "passfail, " . "remoteIP, " . "code " . "FROM loginlog " . "WHERE (user = '******'unityid']}' OR " . "user = '******'unityid']}@{$userdata['affiliation']}') AND " . "affiliationid = {$userdata['affiliationid']} " . "ORDER BY timestamp DESC " . "LIMIT 8";
        $logins = array();
        $qh = doQuery($query);
        while ($row = mysql_fetch_assoc($qh)) {
            $logins[] = $row;
        }
        if (count($logins)) {
            $logins = array_reverse($logins);
            print "<h3>Login History (last 8 attempts)</h3>\n";
            print "<table summary=\"login attempts\">\n";
            print "<colgroup>\n";
            print "<col class=\"logincol\" />\n";
            print "<col class=\"logincol\" />\n";
            print "<col class=\"logincol\" />\n";
            print "<col class=\"logincol\" />\n";
            print "<col />\n";
            print "</colgroup>\n";
            print "  <tr>\n";
            print "    <th>Authentication Method</th>\n";
            print "    <th>Timestamp</th>\n";
            print "    <th>Result</th>\n";
            print "    <th>Remote IP</th>\n";
            print "    <th>Extra Info</th>\n";
            print "  </tr>\n";
            foreach ($logins as $login) {
                print "  <tr>\n";
                print "    <td class=\"logincell\">{$login['authmech']}</td>\n";
                $ts = prettyDatetime($login['timestamp'], 1);
                print "    <td class=\"logincell\">{$ts}</td>\n";
                if ($login['passfail']) {
                    print "    <td class=\"logincell\"><font color=\"#008000\">Pass</font></td>\n";
                } else {
                    print "    <td class=\"logincell\"><font color=\"red\">Fail</font></td>\n";
                }
                print "    <td class=\"logincell\">{$login['remoteIP']}</td>\n";
                print "    <td class=\"logincell\">{$login['code']}</td>\n";
                print "  </tr>\n";
            }
            print "</table>\n";
        } else {
            print "<h3>Login History</h3>\n";
            print "There are no login attempts by this user.<br>\n";
        }
        # reservation history
        $requests = array();
        $query = "SELECT DATE_FORMAT(l.start, '%W, %b %D, %Y, %h:%i %p') AS start, " . "DATE_FORMAT(l.finalend, '%W, %b %D, %Y, %h:%i %p') AS end, " . "c.hostname, " . "i.prettyname AS prettyimage, " . "s.IPaddress, " . "l.ending " . "FROM log l, " . "image i, " . "computer c, " . "sublog s " . "WHERE l.userid = {$userdata['id']} AND " . "s.logid = l.id AND " . "i.id = s.imageid AND " . "c.id = s.computerid " . "ORDER BY l.start DESC " . "LIMIT 5";
        $qh = doQuery($query, 290);
        while ($row = mysql_fetch_assoc($qh)) {
            array_push($requests, $row);
        }
        $requests = array_reverse($requests);
        if (!empty($requests)) {
            print "<h3>User's last " . count($requests) . " reservations:</h3>\n";
            print "<table>\n";
            $first = 1;
            foreach ($requests as $req) {
                if ($first) {
                    $first = 0;
                } else {
                    print "  <tr>\n";
                    print "    <td colspan=2><hr></td>\n";
                    print "  </tr>\n";
                }
                print "  <tr>\n";
                print "    <th align=right>Image:</th>\n";
                print "    <td>{$req['prettyimage']}</td>\n";
                print "  </tr>\n";
                print "  <tr>\n";
                print "    <th align=right>Computer:</th>\n";
                print "    <td>{$req['hostname']}</td>\n";
                print "  </tr>\n";
                print "  <tr>\n";
                print "    <th align=right>Start:</th>\n";
                print "    <td>{$req['start']}</td>\n";
                print "  </tr>\n";
                print "  <tr>\n";
                print "    <th align=right>End:</th>\n";
                print "    <td>{$req['end']}</td>\n";
                print "  </tr>\n";
                if ($req['IPaddress'] != '') {
                    print "  <tr>\n";
                    print "    <th align=right>IP Address:</th>\n";
                    print "    <td>{$req['IPaddress']}</td>\n";
                    print "  </tr>\n";
                }
                print "  <tr>\n";
                print "    <th align=right>Ending:</th>\n";
                print "    <td>{$req['ending']}</td>\n";
                print "  </tr>\n";
            }
            print "</table>\n";
        } else {
            print "User made no reservations in the past week.<br>\n";
        }
        # current reservations
        $requests = array();
        $query = "SELECT DATE_FORMAT(rq.start, '%W, %b %D, %Y, %h:%i %p') AS start, " . "DATE_FORMAT(rq.end, '%W, %b %D, %Y, %h:%i %p') AS end, " . "rq.id AS requestid, " . "MIN(rs.id) AS reservationid, " . "c.hostname AS computer, " . "i.prettyname AS prettyimage, " . "c.IPaddress AS compIP, " . "rs.remoteIP AS userIP, " . "ch.hostname AS vmhost, " . "mn.hostname AS managementnode, " . "srq.name AS servername, " . "aug.name AS admingroup, " . "lug.name AS logingroup, " . "s1.name AS state, " . "s2.name AS laststate " . "FROM image i, " . "managementnode mn, " . "request rq " . "LEFT JOIN reservation rs ON (rs.requestid = rq.id) " . "LEFT JOIN computer c ON (rs.computerid = c.id) " . "LEFT JOIN vmhost vh ON (c.vmhostid = vh.id) " . "LEFT JOIN computer ch ON (vh.computerid = ch.id) " . "LEFT JOIN serverrequest srq ON (srq.requestid = rq.id) " . "LEFT JOIN usergroup aug ON (aug.id = srq.admingroupid) " . "LEFT JOIN usergroup lug ON (lug.id = srq.logingroupid) " . "LEFT JOIN state s1 ON (s1.id = rq.stateid) " . "LEFT JOIN state s2 ON (s2.id = rq.laststateid) " . "WHERE rq.userid = {$userdata['id']} AND " . "i.id = rs.imageid AND " . "mn.id = rs.managementnodeid " . "GROUP BY rq.id " . "ORDER BY rq.start";
        $qh = doQuery($query, 290);
        while ($row = mysql_fetch_assoc($qh)) {
            array_push($requests, $row);
        }
        $requests = array_reverse($requests);
        if (!empty($requests)) {
            print "<h3>User's current reservations:</h3>\n";
            print "<table>\n";
            $first = 1;
            foreach ($requests as $req) {
                if ($first) {
                    $first = 0;
                } else {
                    print "  <tr>\n";
                    print "    <td colspan=2><hr></td>\n";
                    print "  </tr>\n";
                }
                print "  <tr>\n";
                print "    <th align=right>Request ID:</th>\n";
                print "    <td>{$req['requestid']}</td>\n";
                print "  </tr>\n";
                if ($req['servername'] != '') {
                    print "  <tr>\n";
                    print "    <th align=right>Reservation Name:</th>\n";
                    print "    <td>{$req['servername']}</td>\n";
                    print "  </tr>\n";
                }
                print "  <tr>\n";
                print "    <th align=right>Image:</th>\n";
                print "    <td>{$req['prettyimage']}</td>\n";
                print "  </tr>\n";
                print "  <tr>\n";
                print "    <th align=right>State:</th>\n";
                if ($req['state'] == 'pending') {
                    print "    <td>{$req['laststate']}</td>\n";
                } else {
                    print "    <td>{$req['state']}</td>\n";
                }
                print "  </tr>\n";
                print "  <tr>\n";
                print "    <th align=right>Computer:</th>\n";
                print "    <td>{$req['computer']}</td>\n";
                print "  </tr>\n";
                if (!empty($req['vmhost'])) {
                    print "  <tr>\n";
                    print "    <th align=right>VM Host:</th>\n";
                    print "    <td>{$req['vmhost']}</td>\n";
                    print "  </tr>\n";
                }
                print "  <tr>\n";
                print "    <th align=right>Start:</th>\n";
                print "    <td>{$req['start']}</td>\n";
                print "  </tr>\n";
                print "  <tr>\n";
                print "    <th align=right>End:</th>\n";
                if ($req['end'] == 'Friday, Jan 1st, 2038, 12:00 AM') {
                    print "    <td>(indefinite)</td>\n";
                } else {
                    print "    <td>{$req['end']}</td>\n";
                }
                print "  </tr>\n";
                if ($req['compIP'] != '') {
                    print "  <tr>\n";
                    print "    <th align=right>Node's IP Address:</th>\n";
                    print "    <td>{$req['compIP']}</td>\n";
                    print "  </tr>\n";
                }
                if ($req['userIP'] != '') {
                    print "  <tr>\n";
                    print "    <th align=right>User's IP Address:</th>\n";
                    print "    <td>{$req['userIP']}</td>\n";
                    print "  </tr>\n";
                }
                if ($req['admingroup'] != '') {
                    print "  <tr>\n";
                    print "    <th align=right>Admin Group:</th>\n";
                    print "    <td>{$req['admingroup']}</td>\n";
                    print "  </tr>\n";
                }
                if ($req['logingroup'] != '') {
                    print "  <tr>\n";
                    print "    <th align=right>Access Group:</th>\n";
                    print "    <td>{$req['logingroup']}</td>\n";
                    print "  </tr>\n";
                }
                print "  <tr>\n";
                print "    <th align=right>Management Node:</th>\n";
                print "    <td>{$req['managementnode']}</td>\n";
                print "  </tr>\n";
            }
            print "</table>\n";
        } else {
            print "User does not have any current reservations.<br>\n";
        }
    }
    print "</div>\n";
}
コード例 #13
0
ファイル: xmlrpcWrappers.php プロジェクト: gw-acadtech/VCL
function XMLRPCprocessBlockTime($blockTimesid, $ignoreprivileges = 0)
{
    global $requestInfo, $user, $xmlrpcBlockAPIUsers;
    if (!in_array($user['id'], $xmlrpcBlockAPIUsers)) {
        return array('status' => 'error', 'errorcode' => 34, 'errormsg' => 'access denied for managing block allocations');
    }
    $return = array('status' => 'success');
    $query = "SELECT bt.start, " . "bt.end, " . "br.imageid, " . "br.numMachines, " . "br.groupid, " . "br.expireTime " . "FROM blockRequest br, " . "blockTimes bt " . "WHERE bt.blockRequestid = br.id AND " . "bt.id = {$blockTimesid}";
    $qh = doQuery($query, 101);
    if (!($rqdata = mysql_fetch_assoc($qh))) {
        return array('status' => 'error', 'errorcode' => 8, 'errormsg' => 'unknown blockTimesid');
    }
    if (datetimeToUnix($rqdata['expireTime']) < time()) {
        return array('status' => 'error', 'errorcode' => 9, 'errormsg' => 'expired block reservation');
    }
    $images = getImages(0, $rqdata['imageid']);
    if (empty($images)) {
        return array('status' => 'error', 'errorcode' => 10, 'errormsg' => 'invalid image associated with block request');
    }
    # check to see if all computers have been allocated
    $query = "SELECT COUNT(computerid) AS allocated " . "FROM blockComputers " . "WHERE blockTimeid = {$blockTimesid}";
    $qh = doQuery($query, 101);
    if (!($row = mysql_fetch_assoc($qh))) {
        return array('status' => 'error', 'errorcode' => 15, 'errormsg' => 'failure to communicate with database');
    }
    $compCompleted = $row['allocated'];
    $compsPerRequest = 1 + count($images[$rqdata['imageid']]['subimages']);
    $toallocate = $rqdata['numMachines'] * $compsPerRequest - $compCompleted;
    if ($toallocate == 0) {
        return array('status' => 'completed');
    }
    $reqToAlloc = $toallocate / $compsPerRequest;
    if (!$ignoreprivileges) {
        # get userids in user group
        $tmp = getUserGroupMembers($rqdata['groupid']);
        if (empty($tmp)) {
            return array('status' => 'error', 'errorcode' => 11, 'errormsg' => 'empty user group and ignoreprivileges set to 0');
        }
        $userids = array_keys($tmp);
        # make length of $userids match $reqToAlloc by duplicating or trimming some users
        while ($reqToAlloc > count($userids)) {
            $userids = array_merge($userids, $userids);
        }
        if ($reqToAlloc < count($userids)) {
            $userids = array_splice($userids, 0, $reqToAlloc);
        }
    }
    # staggering: stagger start times for this round (ie, don't worry about
    #   previous processing of this block time) such that there is 1 minute
    #   between the start times for each request
    $stagExtra = $reqToAlloc * 60;
    # determine estimated load time
    $imgLoadTime = getImageLoadEstimate($rqdata['imageid']);
    if ($imgLoadTime == 0) {
        $imgLoadTime = $images[$rqdata['imageid']]['reloadtime'] * 60;
    }
    $loadtime = $imgLoadTime + 10 * 60;
    # add 10 minute fudge factor
    $unixstart = datetimeToUnix($rqdata['start']);
    if (time() + $loadtime + $stagExtra > $unixstart) {
        $return['status'] = 'warning';
        $return['warningcode'] = 13;
        $return['warningmsg'] = 'possibly insufficient time to load machines';
    }
    $start = unixToDatetime($unixstart - $loadtime);
    $unixend = datetimeToUnix($rqdata['end']);
    $userid = 0;
    $allocated = 0;
    $vclreloadid = getUserlistID('vclreload@Local');
    $revisionid = getProductionRevisionid($rqdata['imageid']);
    $blockCompVals = array();
    # FIXME (maybe) - if some subset of users in the user group have available
    # computers, but others do not, $allocated will be less than the desired
    # number of machines; however, calling this function enough times will
    # result in enough machines being allocated because they will continue to be
    # allocated based on the ones with machines available; this seems like odd
    # behavior
    $stagCnt = 0;
    for ($i = 0; $i < $reqToAlloc; $i++) {
        $stagunixstart = $unixstart - $loadtime - $stagCnt * 60;
        $stagstart = unixToDatetime($stagunixstart);
        if (!$ignoreprivileges) {
            $userid = array_pop($userids);
        }
        # use end of block time to find available computers, but...
        $rc = isAvailable($images, $rqdata['imageid'], $stagunixstart, $unixend, 0, 0, $userid, $ignoreprivileges);
        if ($rc < 1) {
            continue;
        }
        $compid = $requestInfo['computers'][0];
        # ...use start of block time as end of reload reservation
        $reqid = simpleAddRequest($compid, $rqdata['imageid'], $revisionid, $stagstart, $rqdata['start'], 19, $vclreloadid);
        if ($reqid == 0) {
            continue;
        }
        $stagCnt++;
        $allocated++;
        $blockCompVals[] = "({$blockTimesid}, {$compid}, {$rqdata['imageid']})";
        # process any subimages
        for ($key = 1; $key < count($requestInfo['computers']); $key++) {
            $subimageid = $requestInfo['images'][$key];
            $subrevid = getProductionRevisionid($subimageid);
            $compid = $requestInfo['computers'][$key];
            $mgmtnodeid = $requestInfo['mgmtnodes'][$key];
            $blockCompVals[] = "({$blockTimesid}, {$compid}, {$subimageid})";
            $query = "INSERT INTO reservation " . "(requestid, " . "computerid, " . "imageid, " . "imagerevisionid, " . "managementnodeid) " . "VALUES " . "({$reqid}, " . "{$compid}, " . "{$subimageid}, " . "{$subrevid}, " . "{$mgmtnodeid})";
            doQuery($query, 101);
        }
        semUnlock();
        $blockComps = implode(',', $blockCompVals);
        $query = "INSERT INTO blockComputers " . "(blockTimeid, computerid, imageid) " . "VALUES {$blockComps}";
        doQuery($query, 101);
        $blockCompVals = array();
    }
    if ($allocated == 0) {
        $return['status'] = 'warning';
        $return['warningcode'] = 14;
        $return['warningmsg'] = 'unable to allocate any machines';
    }
    $return['allocated'] = $compCompleted / $compsPerRequest + $allocated;
    $return['unallocated'] = $rqdata['numMachines'] - $return['allocated'];
    return $return;
}
コード例 #14
0
function AJgetBlockAllocatedMachineData()
{
    global $user;
    $start = processInputVar('start', ARG_STRING);
    if (!preg_match('/^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}$/', $start)) {
        $start = unixFloor15(time() - 3600);
        $startdt = unixToDatetime($start);
    } else {
        $startdt = "{$start}:00";
        $start = datetimeToUnix($startdt);
    }
    $end = $start + 12 * 3600;
    $enddt = unixToDatetime($end);
    $alldata = array();
    # bare
    $data = array();
    if (checkUserHasPerm('Manage Block Allocations (global)')) {
        $query = "SELECT COUNT(id) " . "FROM computer " . "WHERE stateid IN (2, 3, 6, 8, 11) AND " . "type = 'blade'";
        $qh = doQuery($query, 101);
        if ($row = mysql_fetch_row($qh)) {
            $data['total'] = $row[0];
        }
    } else {
        // TODO once we allow limiting total machines by affiliation, put that value here
        $data['total'] = 0;
    }
    for ($time = $start, $i = 0; $time < $end; $time += 900, $i++) {
        $fmttime = date('g:i a', $time);
        $data["points"][$i] = array('x' => $i, 'y' => 0, 'value' => $i, 'text' => $fmttime);
    }
    $data['maxy'] = 0;
    if (checkUserHasPerm('Manage Block Allocations (global)')) {
        $query = "SELECT UNIX_TIMESTAMP(bt.start) as start, " . "UNIX_TIMESTAMP(bt.end) as end, " . "br.numMachines " . "FROM blockTimes bt, " . "blockRequest br, " . "image i, " . "OS o " . "WHERE bt.blockRequestid = br.id AND " . "bt.skip = 0 AND " . "bt.start < '{$enddt}' AND " . "bt.end > '{$startdt}' AND " . "br.imageid = i.id AND " . "i.OSid = o.id AND " . "o.installtype != 'vmware'";
    } else {
        $query = "SELECT UNIX_TIMESTAMP(bt.start) as start, " . "UNIX_TIMESTAMP(bt.end) as end, " . "br.numMachines " . "FROM blockTimes bt, " . "blockRequest br, " . "image i, " . "OS o, " . "user u " . "WHERE bt.blockRequestid = br.id AND " . "bt.skip = 0 AND " . "bt.start < '{$enddt}' AND " . "bt.end > '{$startdt}' AND " . "br.imageid = i.id AND " . "i.OSid = o.id AND " . "o.installtype != 'vmware' AND " . "br.ownerid = u.id AND " . "u.affiliationid = {$user['affiliationid']}";
    }
    $qh = doQuery($query, 101);
    while ($row = mysql_fetch_assoc($qh)) {
        for ($binstart = $start, $binend = $start + 900, $binindex = 0; $binend <= $end; $binstart += 900, $binend += 900, $binindex++) {
            if ($binend <= $row['start']) {
                continue;
            } elseif ($row['start'] < $binend && $row['end'] > $binstart) {
                $data["points"][$binindex]['y'] += $row['numMachines'];
            } elseif ($binstart >= $row['end']) {
                break;
            }
        }
    }
    for ($time = $start, $i = 0; $time < $end; $time += 900, $i++) {
        if ($data["points"][$i]['y'] > $data['maxy']) {
            $data['maxy'] = $data['points'][$i]['y'];
        }
        $data["points"][$i]['tooltip'] = "{$data['points'][$i]['text']}: {$data['points'][$i]['y']}";
    }
    $alldata['bare'] = $data;
    # virtual
    $data = array();
    if (checkUserHasPerm('Manage Block Allocations (global)')) {
        $query = "SELECT COUNT(id) " . "FROM computer " . "WHERE stateid IN (2, 3, 6, 8, 11) AND " . "type = 'virtualmachine'";
        $qh = doQuery($query, 101);
        if ($row = mysql_fetch_row($qh)) {
            $data['total'] = $row[0];
        }
    } else {
        // TODO once we allow limiting total machines by affiliation, put that value here
        $data['total'] = 0;
    }
    for ($time = $start, $i = 0; $time < $end; $time += 900, $i++) {
        $fmttime = date('g:i a', $time);
        $data["points"][$i] = array('x' => $i, 'y' => 0, 'value' => $i, 'text' => $fmttime);
    }
    $data['maxy'] = 0;
    if (checkUserHasPerm('Manage Block Allocations (global)')) {
        $query = "SELECT UNIX_TIMESTAMP(bt.start) as start, " . "UNIX_TIMESTAMP(bt.end) as end, " . "br.numMachines " . "FROM blockTimes bt, " . "blockRequest br, " . "image i, " . "OS o " . "WHERE bt.blockRequestid = br.id AND " . "bt.skip = 0 AND " . "bt.start < '{$enddt}' AND " . "bt.end > '{$startdt}' AND " . "br.imageid = i.id AND " . "i.OSid = o.id AND " . "o.installtype = 'vmware'";
    } else {
        $query = "SELECT UNIX_TIMESTAMP(bt.start) as start, " . "UNIX_TIMESTAMP(bt.end) as end, " . "br.numMachines " . "FROM blockTimes bt, " . "blockRequest br, " . "image i, " . "OS o, " . "user u " . "WHERE bt.blockRequestid = br.id AND " . "bt.skip = 0 AND " . "bt.start < '{$enddt}' AND " . "bt.end > '{$startdt}' AND " . "br.imageid = i.id AND " . "i.OSid = o.id AND " . "o.installtype = 'vmware' AND " . "br.ownerid = u.id AND " . "u.affiliationid = {$user['affiliationid']}";
    }
    $qh = doQuery($query, 101);
    while ($row = mysql_fetch_assoc($qh)) {
        for ($binstart = $start, $binend = $start + 900, $binindex = 0; $binend <= $end; $binstart += 900, $binend += 900, $binindex++) {
            if ($binend <= $row['start']) {
                continue;
            } elseif ($row['start'] < $binend && $row['end'] > $binstart) {
                $data["points"][$binindex]['y'] += $row['numMachines'];
            } elseif ($binstart >= $row['end']) {
                break;
            }
        }
    }
    for ($time = $start, $i = 0; $time < $end; $time += 900, $i++) {
        if ($data["points"][$i]['y'] > $data['maxy']) {
            $data['maxy'] = $data['points'][$i]['y'];
        }
        $data["points"][$i]['tooltip'] = "{$data['points'][$i]['text']}: {$data['points'][$i]['y']}";
    }
    $alldata['virtual'] = $data;
    $val = getContinuationVar('val') + 1;
    $cont = addContinuationsEntry('AJgetBlockAllocatedMachineData', array('val' => $val), SECINDAY, 1, 0);
    $alldata['cont'] = $cont;
    sendJSON($alldata);
}
コード例 #15
0
ファイル: utils.php プロジェクト: gw-acadtech/VCL
function addContinuationsEntry($nextmode, $data = array(), $duration = SECINWEEK, $deleteFromSelf = 1, $multicall = 1, $repeatProtect = 0)
{
    global $user, $mode, $inContinuation, $continuationid;
    if ($repeatProtect) {
        $data['______parent'] = $continuationid;
    }
    $serdata = serialize($data);
    $contid = md5($mode . $nextmode . $serdata . $user['id']);
    $serdata = mysql_escape_string($serdata);
    $expiretime = unixToDatetime(time() + $duration);
    $query = "SELECT id, " . "parentid " . "FROM continuations " . "WHERE id = '{$contid}' AND " . "userid = {$user['id']}";
    $qh = doQuery($query, 101);
    if ($row = mysql_fetch_assoc($qh)) {
        # update expiretime
        $query = "UPDATE continuations " . "SET expiretime = '{$expiretime}' " . "WHERE id = '{$contid}' AND " . "userid = {$user['id']}";
        doQuery($query, 101);
    } else {
        if (!$inContinuation) {
            $parent = 'NULL';
        } else {
            $parent = "'{$continuationid}'";
        }
        if ($deleteFromSelf || !$inContinuation) {
            $deletefromid = $contid;
            $parent = 'NULL';
        } else {
            $query = "SELECT deletefromid " . "FROM continuations " . "WHERE id = '{$continuationid}' AND " . "userid = {$user['id']}";
            $qh = doQuery($query, 101);
            if (!($row = mysql_fetch_assoc($qh))) {
                abort(108);
            }
            $deletefromid = $row['deletefromid'];
        }
        $query = "INSERT INTO continuations " . "(id, " . "userid, " . "expiretime, " . "frommode, " . "tomode, " . "data, " . "multicall, " . "parentid, " . "deletefromid) " . "VALUES " . "('{$contid}', " . "{$user['id']}, " . "'{$expiretime}', " . "'{$mode}', " . "'{$nextmode}', " . "'{$serdata}', " . "{$multicall}, " . "{$parent}, " . "'{$deletefromid}')";
        doQuery($query, 101);
    }
    $salt = generateString(8);
    $now = time();
    $data = "{$salt}:{$contid}:{$user['id']}:{$now}";
    $edata = encryptData($data);
    $udata = urlencode($edata);
    return $udata;
}
コード例 #16
0
ファイル: ldapauth.php プロジェクト: bq-xiao/apache-vcl
function updateLDAPUser($authtype, $userid)
{
    global $authMechs;
    $esc_userid = mysql_real_escape_string($userid);
    $userData = getLDAPUserData($authtype, $userid);
    if (is_null($userData)) {
        return NULL;
    }
    $affilid = $authMechs[$authtype]['affiliationid'];
    $now = unixToDatetime(time());
    // select desired data from db
    $qbase = "SELECT i.name AS IMtype, " . "u.IMid AS IMid, " . "u.affiliationid, " . "af.name AS affiliation, " . "af.shibonly, " . "u.emailnotices, " . "u.preferredname AS preferredname, " . "u.uid AS uid, " . "u.id AS id, " . "u.width AS width, " . "u.height AS height, " . "u.bpp AS bpp, " . "u.audiomode AS audiomode, " . "u.mapdrives AS mapdrives, " . "u.mapprinters AS mapprinters, " . "u.mapserial AS mapserial, " . "COALESCE(u.rdpport, 3389) AS rdpport, " . "u.showallgroups " . "FROM user u, " . "IMtype i, " . "affiliation af " . "WHERE u.IMtypeid = i.id AND " . "af.id = {$affilid} AND ";
    if (array_key_exists('numericid', $userData) && is_numeric($userData['numericid'])) {
        $query = $qbase . "u.uid = {$userData['numericid']}";
    } else {
        $query = $qbase . "u.unityid = '{$esc_userid}' AND " . "u.affiliationid = {$affilid}";
    }
    $qh = doQuery($query, 255);
    $updateuid = 0;
    # check to see if there is a matching entry where uid is NULL but unityid and affiliationid match
    if (array_key_exists('numericid', $userData) && is_numeric($userData['numericid']) && !mysql_num_rows($qh)) {
        $updateuid = 1;
        $query = $qbase . "u.unityid = '{$esc_userid}' AND " . "u.affiliationid = {$affilid}";
        $qh = doQuery($query, 255);
    }
    // if get a row
    //    update db
    //    update results from select
    if ($user = mysql_fetch_assoc($qh)) {
        $user["unityid"] = $userid;
        $user["firstname"] = $userData['first'];
        $user["lastname"] = $userData["last"];
        $user["email"] = $userData["email"];
        $user["lastupdated"] = $now;
        $query = "UPDATE user " . "SET unityid = '{$esc_userid}', " . "firstname = '{$userData['first']}', " . "lastname = '{$userData['last']}', " . "email = '{$userData['email']}', ";
        if ($updateuid) {
            $query .= "uid = {$userData['numericid']}, ";
        }
        $query .= "lastupdated = '{$now}' ";
        if (array_key_exists('numericid', $userData) && is_numeric($userData['numericid']) && !$updateuid) {
            $query .= "WHERE uid = {$userData['numericid']}";
        } else {
            $query .= "WHERE unityid = '{$esc_userid}' AND " . "affiliationid = {$affilid}";
        }
        doQuery($query, 256, 'vcl', 1);
    } else {
        //    call addLDAPUser
        $id = addLDAPUser($authtype, $userid);
        $query = "SELECT u.unityid AS unityid, " . "u.affiliationid, " . "af.name AS affiliation, " . "u.firstname AS firstname, " . "u.lastname AS lastname, " . "u.preferredname AS preferredname, " . "u.email AS email, " . "i.name AS IMtype, " . "u.IMid AS IMid, " . "u.uid AS uid, " . "u.id AS id, " . "u.width AS width, " . "u.height AS height, " . "u.bpp AS bpp, " . "u.audiomode AS audiomode, " . "u.mapdrives AS mapdrives, " . "u.mapprinters AS mapprinters, " . "u.mapserial AS mapserial, " . "COALESCE(u.rdpport, 3389) AS rdpport, " . "u.showallgroups, " . "u.usepublickeys, " . "u.sshpublickeys, " . "u.lastupdated AS lastupdated " . "FROM user u, " . "IMtype i, " . "affiliation af " . "WHERE u.IMtypeid = i.id AND " . "u.affiliationid = af.id AND " . "u.id = {$id}";
        $qh = doQuery($query, 101);
        if (!($user = mysql_fetch_assoc($qh))) {
            return NULL;
        }
        $user['sshpublickeys'] = htmlspecialchars($user['sshpublickeys']);
    }
    // TODO handle generic updating of groups
    switch (getAffiliationName($affilid)) {
        case 'EXAMPLE1':
            updateEXAMPLE1Groups($user);
            break;
        default:
            //TODO possibly add to a default group
    }
    $user["groups"] = getUsersGroups($user["id"], 1);
    $user["groupperms"] = getUsersGroupPerms(array_keys($user['groups']));
    $user["privileges"] = getOverallUserPrivs($user["id"]);
    $user['login'] = $user['unityid'];
    return $user;
}
コード例 #17
0
ファイル: xmlrpcWrappers.php プロジェクト: bq-xiao/apache-vcl
function XMLRPCprocessBlockTime($blockTimesid, $ignoreprivileges = 0)
{
    global $requestInfo, $user, $xmlrpcBlockAPIUsers;
    if (!in_array($user['id'], $xmlrpcBlockAPIUsers)) {
        return array('status' => 'error', 'errorcode' => 34, 'errormsg' => 'access denied for managing block allocations');
    }
    # validate $blockTimesid
    if (!is_numeric($blockTimesid)) {
        return array('status' => 'error', 'errorcode' => 77, 'errormsg' => 'Invalid blockTimesid specified');
    }
    # validate ignoreprivileges
    if (!is_numeric($ignoreprivileges) || $ignoreprivileges < 0 || $ignoreprivileges > 1) {
        return array('status' => 'error', 'errorcode' => 86, 'errormsg' => 'ignoreprivileges must be 0 or 1');
    }
    $return = array('status' => 'success');
    $query = "SELECT bt.start, " . "bt.end, " . "br.imageid, " . "br.numMachines, " . "br.groupid, " . "br.expireTime " . "FROM blockRequest br, " . "blockTimes bt " . "WHERE bt.blockRequestid = br.id AND " . "bt.id = {$blockTimesid}";
    $qh = doQuery($query, 101);
    if (!($rqdata = mysql_fetch_assoc($qh))) {
        return array('status' => 'error', 'errorcode' => 8, 'errormsg' => 'unknown blockTimesid');
    }
    if (datetimeToUnix($rqdata['expireTime']) < time()) {
        return array('status' => 'error', 'errorcode' => 9, 'errormsg' => 'expired block allocation');
    }
    $images = getImages(0, $rqdata['imageid']);
    if (empty($images)) {
        return array('status' => 'error', 'errorcode' => 10, 'errormsg' => 'invalid image associated with block allocation');
    }
    $unixstart = datetimeToUnix($rqdata['start']);
    $unixend = datetimeToUnix($rqdata['end']);
    $revisionid = getProductionRevisionid($rqdata['imageid']);
    $imgLoadTime = getImageLoadEstimate($rqdata['imageid']);
    if ($imgLoadTime == 0) {
        $imgLoadTime = $images[$rqdata['imageid']]['reloadtime'] * 60;
    }
    $vclreloadid = getUserlistID('vclreload@Local');
    $groupmembers = getUserGroupMembers($rqdata['groupid']);
    $userids = array_keys($groupmembers);
    # add any computers from future reservations users in the group made
    if (!empty($groupmembers)) {
        ## find reservations by users
        $allids = implode(',', $userids);
        $query = "SELECT rq.id AS reqid, " . "UNIX_TIMESTAMP(rq.start) AS start, " . "rq.userid " . "FROM request rq, " . "reservation rs " . "WHERE rs.requestid = rq.id AND " . "rq.userid IN ({$allids}) AND " . "rq.start < '{$rqdata['end']}' AND " . "rq.end > '{$rqdata['start']}' AND " . "rs.imageid = {$rqdata['imageid']} AND " . "rs.computerid NOT IN (SELECT computerid " . "FROM blockComputers " . "WHERE blockTimeid = {$blockTimesid})";
        $qh = doQuery($query);
        $donereqids = array();
        $blockCompVals = array();
        $checkstartbase = $unixstart - $imgLoadTime - 300;
        $reloadstartbase = unixToDatetime($checkstartbase);
        $rows = mysql_num_rows($qh);
        while ($row = mysql_fetch_assoc($qh)) {
            if (array_key_exists($row['reqid'], $donereqids)) {
                continue;
            }
            $donereqids[$row['reqid']] = 1;
            if ($row['start'] < datetimeToUnix($rqdata['start'])) {
                $checkstart = $row['start'] - $imgLoadTime - 300;
                $reloadstart = unixToDatetime($checkstart);
                $reloadend = unixToDatetime($row['start']);
            } else {
                $checkstart = $checkstartbase;
                $reloadstart = $reloadstartbase;
                $reloadend = $rqdata['start'];
            }
            # check to see if computer is available for whole block
            $rc = isAvailable($images, $rqdata['imageid'], $revisionid, $checkstart, $unixend, 1, $row['reqid'], $row['userid'], $ignoreprivileges, 0, '', '', 1);
            // if not available for whole block, just skip this one
            if ($rc < 1) {
                continue;
            }
            $compid = $requestInfo['computers'][0];
            # create reload reservation
            $reqid = simpleAddRequest($compid, $rqdata['imageid'], $revisionid, $reloadstart, $reloadend, 19, $vclreloadid);
            if ($reqid == 0) {
                continue;
            }
            # add to blockComputers
            $blockCompVals[] = "({$blockTimesid}, {$compid}, {$rqdata['imageid']}, {$reqid})";
            # process any subimages
            for ($key = 1; $key < count($requestInfo['computers']); $key++) {
                $subimageid = $requestInfo['images'][$key];
                $subrevid = getProductionRevisionid($subimageid);
                $compid = $requestInfo['computers'][$key];
                $mgmtnodeid = $requestInfo['mgmtnodes'][$key];
                $blockCompVals[] = "({$blockTimesid}, {$compid}, {$subimageid}, {$reqid})";
                $query = "INSERT INTO reservation " . "(requestid, " . "computerid, " . "imageid, " . "imagerevisionid, " . "managementnodeid) " . "VALUES " . "({$reqid}, " . "{$compid}, " . "{$subimageid}, " . "{$subrevid}, " . "{$mgmtnodeid})";
                doQuery($query, 101);
            }
        }
        if (count($blockCompVals)) {
            $blockComps = implode(',', $blockCompVals);
            $query = "INSERT INTO blockComputers " . "(blockTimeid, computerid, imageid, reloadrequestid) " . "VALUES {$blockComps}";
            doQuery($query);
        }
        cleanSemaphore();
    }
    # check to see if all computers have been allocated
    $query = "SELECT COUNT(computerid) AS allocated " . "FROM blockComputers " . "WHERE blockTimeid = {$blockTimesid}";
    $qh = doQuery($query, 101);
    if (!($row = mysql_fetch_assoc($qh))) {
        return array('status' => 'error', 'errorcode' => 15, 'errormsg' => 'failure to communicate with database');
    }
    $compCompleted = $row['allocated'];
    if (array_key_exists('subimages', $images[$rqdata['imageid']])) {
        $compsPerAlloc = 1 + count($images[$rqdata['imageid']]['subimages']);
    } else {
        $compsPerAlloc = 1;
    }
    $toallocate = $rqdata['numMachines'] * $compsPerAlloc - $compCompleted;
    if ($toallocate == 0) {
        if (count($blockCompVals)) {
            return array('status' => 'success', 'allocated' => $rqdata['numMachines'], 'unallocated' => 0);
        }
        return array('status' => 'completed');
    }
    $reqToAlloc = $toallocate / $compsPerAlloc;
    if (!$ignoreprivileges) {
        # get userids in user group
        if (empty($groupmembers)) {
            return array('status' => 'error', 'errorcode' => 11, 'errormsg' => 'empty user group and ignoreprivileges set to 0');
        }
        # make length of $userids match $reqToAlloc by duplicating or trimming some users
        while ($reqToAlloc > count($userids)) {
            $userids = array_merge($userids, $userids);
        }
        if ($reqToAlloc < count($userids)) {
            $userids = array_splice($userids, 0, $reqToAlloc);
        }
    }
    # staggering: stagger start times for this round (ie, do not worry about
    #   previous processing of this block time) such that there is 1 minute
    #   between the start times for each allocation
    $stagExtra = $reqToAlloc * 60;
    # determine estimated load time
    $loadtime = $imgLoadTime + 10 * 60;
    # add 10 minute fudge factor
    if (time() + $loadtime + $stagExtra > $unixstart) {
        $return['status'] = 'warning';
        $return['warningcode'] = 13;
        $return['warningmsg'] = 'possibly insufficient time to load machines';
    }
    $start = unixToDatetime($unixstart - $loadtime);
    $userid = 0;
    $allocated = 0;
    $blockCompVals = array();
    # FIXME (maybe) - if some subset of users in the user group have available
    # computers, but others do not, $allocated will be less than the desired
    # number of machines; however, calling this function enough times will
    # result in enough machines being allocated because they will continue to be
    # allocated based on the ones with machines available; this seems like odd
    # behavior
    $stagCnt = 0;
    $stagTime = 60;
    # stagger reload reservations by 1 min
    if ($imgLoadTime > 840) {
        // if estimated load time is > 14 min
        $stagTime = 120;
    }
    #    stagger reload reservations by 2 min
    for ($i = 0; $i < $reqToAlloc; $i++) {
        $stagunixstart = $unixstart - $loadtime - $stagCnt * $stagTime;
        $stagstart = unixToDatetime($stagunixstart);
        if (!$ignoreprivileges) {
            $userid = array_pop($userids);
        }
        # use end of block time to find available computers, but...
        $rc = isAvailable($images, $rqdata['imageid'], $revisionid, $stagunixstart, $unixend, 1, 0, $userid, $ignoreprivileges);
        if ($rc < 1) {
            continue;
        }
        $compid = $requestInfo['computers'][0];
        # ...use start of block time as end of reload reservation
        $reqid = simpleAddRequest($compid, $rqdata['imageid'], $revisionid, $stagstart, $rqdata['start'], 19, $vclreloadid);
        if ($reqid == 0) {
            continue;
        }
        $stagCnt++;
        $allocated++;
        $blockCompVals[] = "({$blockTimesid}, {$compid}, {$rqdata['imageid']}, {$reqid})";
        # process any subimages
        for ($key = 1; $key < count($requestInfo['computers']); $key++) {
            $subimageid = $requestInfo['images'][$key];
            $subrevid = getProductionRevisionid($subimageid);
            $compid = $requestInfo['computers'][$key];
            $mgmtnodeid = $requestInfo['mgmtnodes'][$key];
            $blockCompVals[] = "({$blockTimesid}, {$compid}, {$subimageid}, {$reqid})";
            $query = "INSERT INTO reservation " . "(requestid, " . "computerid, " . "imageid, " . "imagerevisionid, " . "managementnodeid) " . "VALUES " . "({$reqid}, " . "{$compid}, " . "{$subimageid}, " . "{$subrevid}, " . "{$mgmtnodeid})";
            doQuery($query, 101);
        }
        $blockComps = implode(',', $blockCompVals);
        $query = "INSERT INTO blockComputers " . "(blockTimeid, computerid, imageid, reloadrequestid) " . "VALUES {$blockComps}";
        doQuery($query, 101);
        cleanSemaphore();
        $blockCompVals = array();
    }
    if ($allocated == 0) {
        $return['status'] = 'warning';
        $return['warningcode'] = 14;
        $return['warningmsg'] = 'unable to allocate any machines';
    }
    $return['allocated'] = $compCompleted / $compsPerAlloc + $allocated;
    $return['unallocated'] = $rqdata['numMachines'] - $return['allocated'];
    return $return;
}