Example #1
0
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);
    }
}
Example #2
0
function submitEditRequest()
{
    global $user, $submitErr, $viewmode, $mode;
    $data = getContinuationVar();
    $request = getRequestInfo($data["requestid"]);
    print "<H2>Modify Reservation</H2>\n";
    $hour = $data["hour"];
    if ($data["hour"] == 12) {
        if ($data["meridian"] == "am") {
            $hour = 0;
        }
    } elseif ($data["meridian"] == "pm") {
        $hour = $data["hour"] + 12;
    }
    $tmp = explode('/', $data["day"]);
    $start = mktime($hour, $data["minute"], "0", $tmp[0], $tmp[1], $tmp[2]);
    if ($data['openend'] && $data['ending'] == 'date') {
        $end = datetimeToUnix($data['enddate']);
    } else {
        if (datetimeToUnix($request["start"]) < datetimeToUnix($request["daterequested"])) {
            $end = $start + $data["length"] * 60 + 900;
        } else {
            $end = $start + $data["length"] * 60;
        }
    }
    // get semaphore lock
    if (!semLock()) {
        abort(3);
    }
    $max = getMaxOverlap($user['id']);
    if (checkOverlap($start, $end, $max, $data["requestid"])) {
        if ($max == 0) {
            print "<font color=\"#ff0000\">The time you requested overlaps with ";
            print "another reservation you currently have.  You are only allowed ";
            print "to have a single reservation at any given time. Please select ";
            print "another time to use the application.</font><br><br>\n";
        } else {
            print "<font color=\"#ff0000\">The time you requested overlaps with ";
            print "another reservation you currently have.  You are allowed ";
            print "to have {$max} overlapping reservations at any given time. ";
            print "Please select another time to use the application.</font><br>";
            print "<br>\n";
        }
        $submitErr = 1;
        editRequest();
        return;
    }
    $rc = isAvailable(getImages(), $data["imageid"], $start, $end, $data["os"], $data["requestid"]);
    if ($rc == -1) {
        print "You have requested an environment that is limited in the number ";
        print "of concurrent reservations that can be made. No further ";
        print "reservations for the environment can be made for the time you ";
        print "have selected. Please select another time to use the ";
        print "environment.<br>";
        addChangeLogEntry($request["logid"], NULL, unixToDatetime($end), unixToDatetime($start), NULL, NULL, 0);
    } elseif ($rc > 0) {
        updateRequest($data["requestid"]);
        if ($data["started"]) {
            if ($data['openend'] && $data['ending'] == 'date') {
                print "Your request to change the ending of your reservation for <b>";
                print "{$data["prettyimage"]}</b> to {$data['enddate']} ";
                print "has been accepted.<br><br>\n";
            } else {
                $remaining = ($end - time()) / 60;
                print "Your request to extend your reservation for <b>";
                print "{$data["prettyimage"]}</b> by " . prettyLength($data["extend"]);
                print " has been accepted.<br><br>\n";
                print "You now have " . prettyLength($remaining) . " remaining for ";
                print "your reservation<br>\n";
            }
        } else {
            print "Your request to use <b>" . $data["prettyimage"] . "</b> on ";
            if (datetimeToUnix($request["start"]) < datetimeToUnix($request["daterequested"])) {
                print prettyDatetime($request["daterequested"]);
            } else {
                print prettyDatetime($start);
            }
            if ($data['openend'] && $data['ending'] == 'date') {
                print " until " . prettyDatetime($end);
            } else {
                print " for " . prettyLength($data["length"]);
            }
            print " has been accepted.<br>\n";
        }
    } else {
        $cdata = array('imageid' => $data['imageid'], 'length' => $data['length'], 'requestid' => $data['requestid']);
        $cont = addContinuationsEntry('selectTimeTable', $cdata);
        print "The time you have requested is not available. You may ";
        print "<a href=\"" . BASEURL . SCRIPT . "?continuation={$cont}\">";
        print "view a timetable</a> of free and reserved times to find ";
        print "a time that will work for you.<br>\n";
        addChangeLogEntry($request["logid"], NULL, unixToDatetime($end), unixToDatetime($start), NULL, NULL, 0);
    }
}
Example #3
0
function XMLRPCaddRequest($imageid, $start, $length, $foruser = '')
{
    global $user;
    $imageid = processInputData($imageid, ARG_NUMERIC);
    $start = processInputData($start, ARG_STRING, 1);
    $length = processInputData($length, ARG_NUMERIC);
    #$foruser = processInputData($foruser, ARG_STRING, 1);
    // make sure user didn't submit a request for an image he
    // doesn't have access to
    $resources = getUserResources(array("imageAdmin", "imageCheckOut"));
    $validImageids = array_keys($resources['image']);
    if (!in_array($imageid, $validImageids)) {
        return array('status' => 'error', 'errorcode' => 3, 'errormsg' => "access denied to {$imageid}");
    }
    # validate $start
    if ($start != 'now' && !is_numeric($start)) {
        return array('status' => 'error', 'errorcode' => 4, 'errormsg' => "received invalid input");
    }
    # validate $length
    $maxtimes = getUserMaxTimes();
    if ($maxtimes['initial'] < $length) {
        return array('status' => 'error', 'errorcode' => 6, 'errormsg' => "max allowed initial length is {$maxtimes['initial']} minutes");
    }
    $nowfuture = 'future';
    if ($start == 'now') {
        $start = time();
        $nowfuture = 'now';
    } else {
        if ($start < time() - 30) {
            return array('status' => 'error', 'errorcode' => 5, 'errormsg' => "start time is in the past");
        }
    }
    $start = unixFloor15($start);
    $end = $start + $length * 60;
    if ($end % (15 * 60)) {
        $end = unixFloor15($end) + 15 * 60;
    }
    $max = getMaxOverlap($user['id']);
    if (checkOverlap($start, $end, $max)) {
        return array('status' => 'error', 'errorcode' => 7, 'errormsg' => "reservation overlaps with another one you " . "have, and you are allowed {$max} " . "overlapping reservations at a time");
    }
    $images = getImages();
    $rc = isAvailable($images, $imageid, $start, $end, '');
    if ($rc < 1) {
        addLogEntry($nowfuture, unixToDatetime($start), unixToDatetime($end), 0, $imageid);
        return array('status' => 'notavailable');
    }
    $return['requestid'] = addRequest();
    $return['status'] = 'success';
    return $return;
}
Example #4
0
function submitCreateImage()
{
    global $submitErr, $user, $viewmode, $HTMLheader, $printedHTMLheader, $mode;
    if ($mode == 'submitCreateTestProd') {
        $data = getContinuationVar();
        $data["revisionid"] = processInputVar("revisionid", ARG_MULTINUMERIC);
        # TODO check for valid revisionid
    } else {
        $data = processRequestInput(0);
        $data['length'] = getContinuationVar('length');
    }
    $showrevisions = 0;
    $subimages = 0;
    $images = getImages();
    $revcount = count($images[$data['imageid']]['imagerevision']);
    if ($revcount > 1) {
        $showrevisions = 1;
    }
    if ($images[$data['imageid']]['imagemetaid'] != NULL && count($images[$data['imageid']]['subimages'])) {
        $subimages = 1;
        foreach ($images[$data['imageid']]['subimages'] as $subimage) {
            $revcount = count($images[$subimage]['imagerevision']);
            if ($revcount > 1) {
                $showrevisions = 1;
            }
        }
    }
    if ($data["time"] == "now") {
        $nowArr = getdate();
        if ($nowArr["minutes"] == 0) {
            $subtract = 0;
            $add = 0;
        } elseif ($nowArr["minutes"] < 15) {
            $subtract = $nowArr["minutes"] * 60;
            $add = 900;
        } elseif ($nowArr["minutes"] < 30) {
            $subtract = ($nowArr["minutes"] - 15) * 60;
            $add = 900;
        } elseif ($nowArr["minutes"] < 45) {
            $subtract = ($nowArr["minutes"] - 30) * 60;
            $add = 900;
        } elseif ($nowArr["minutes"] < 60) {
            $subtract = ($nowArr["minutes"] - 45) * 60;
            $add = 900;
        }
        $start = time() - $subtract;
        $start -= $start % 60;
        $nowfuture = "now";
    } else {
        $add = 0;
        $hour = $data["hour"];
        if ($data["hour"] == 12) {
            if ($data["meridian"] == "am") {
                $hour = 0;
            }
        } elseif ($data["meridian"] == "pm") {
            $hour = $data["hour"] + 12;
        }
        $tmp = explode('/', $data["day"]);
        $start = mktime($hour, $data["minute"], "0", $tmp[0], $tmp[1], $tmp[2]);
        if ($start < time()) {
            print $HTMLheader;
            print "<H2>Create / Update an Image</H2>\n";
            print "<font color=\"#ff0000\">The time you requested is in the past.";
            print " Please select \"Now\" or use a time in the future.</font><br>\n";
            $submitErr = 1;
            createSelectImage();
            return;
        }
        $nowfuture = "future";
    }
    // FIXME hard code length to 8 hours
    $data["length"] = 480;
    $end = $start + $data["length"] * 60 + $add;
    // get semaphore lock
    if (!semLock()) {
        abort(3);
    }
    $max = getMaxOverlap($user['id']);
    if (checkOverlap($start, $end, $max)) {
        $printedHTMLheader = 1;
        print $HTMLheader;
        print "<H2>New Reservation</H2>\n";
        if ($max == 0) {
            print "<font color=\"#ff0000\">The time you requested overlaps with ";
            print "another reservation you currently have.  You are only allowed ";
            print "to have a single reservation at any given time. Please select ";
            print "another time to use the application. If you are finished with ";
            print "an active reservation, click \"Current Reservations\", ";
            print "then click the \"End\" button of your active reservation.";
            print "</font><br><br>\n";
        } else {
            print "<font color=\"#ff0000\">The time you requested overlaps with ";
            print "another reservation you currently have.  You are allowed ";
            print "to have {$max} overlapping reservations at any given time. ";
            print "Please select another time to use the application. If you are ";
            print "finished with an active reservation, click \"Current ";
            print "Reservations\", then click the \"End\" button of your active ";
            print "reservation.</font><br><br>\n";
        }
        $submitErr = 1;
        createSelectImage();
        return;
    }
    // if user is owner of the image and there is a test revision of the image
    #   available, ask user if production or test image desired
    if ($mode != "submitCreateTestProd" && $showrevisions && $images[$data["imageid"]]["ownerid"] == $user["id"]) {
        $printedHTMLheader = 1;
        print $HTMLheader;
        print "<H2>New Reservation</H2>\n";
        if ($subimages) {
            print "This is a cluster environment. At least one image in the ";
            print "cluster has more than one revision available. Please select ";
            print "the revision you desire for each image listed below:<br>\n";
        } else {
            print "There are multiple revisions of this environment available.  Please ";
            print "select the revision you would like to check out:<br>\n";
        }
        print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post><br>\n";
        if (!array_key_exists('subimages', $images[$data['imageid']])) {
            $images[$data['imageid']]['subimages'] = array();
        }
        array_unshift($images[$data['imageid']]['subimages'], $data['imageid']);
        foreach ($images[$data['imageid']]['subimages'] as $subimage) {
            print "{$images[$subimage]['prettyname']}:<br>\n";
            print "<table summary=\"lists revisions of the selected environment, one must be selected to continue\">\n";
            print "  <TR>\n";
            print "    <TD></TD>\n";
            print "    <TH>Revision</TH>\n";
            print "    <TH>Creator</TH>\n";
            print "    <TH>Created</TH>\n";
            print "    <TH>Currently in Production</TH>\n";
            print "  </TR>\n";
            foreach ($images[$subimage]['imagerevision'] as $revision) {
                print "  <TR>\n";
                if (array_key_exists($subimage, $data['revisionid']) && $data['revisionid'][$subimage] == $revision['id']) {
                    print "    <TD align=center><INPUT type=radio name=revisionid[{$subimage}] value={$revision['id']} checked></TD>\n";
                } elseif ($revision['production']) {
                    print "    <TD align=center><INPUT type=radio name=revisionid[{$subimage}] value={$revision['id']} checked></TD>\n";
                } else {
                    print "    <TD align=center><INPUT type=radio name=revisionid[{$subimage}] value={$revision['id']}></TD>\n";
                }
                print "    <TD align=center>{$revision['revision']}</TD>\n";
                print "    <TD align=center>{$revision['user']}</TD>\n";
                print "    <TD align=center>{$revision['prettydate']}</TD>\n";
                if ($revision['production']) {
                    print "    <TD align=center>Yes</TD>\n";
                } else {
                    print "    <TD align=center>No</TD>\n";
                }
                print "  </TR>\n";
            }
            print "</TABLE>\n";
        }
        addContinuationsEntry('submitCreateImage', array(), SECINDAY, 1, 0);
        // we add this continuation back
        //   so the currently displayed
        //   page can be reloaded
        $cont = addContinuationsEntry('submitCreateTestProd', $data);
        print "<br><INPUT type=hidden name=continuation value=\"{$cont}\">\n";
        print "<INPUT type=submit value=Submit>\n";
        print "</FORM>\n";
        return;
    }
    $rc = isAvailable($images, $data["imageid"], $start, $end, $data["os"], 0, 0, 0, 1);
    if ($rc == -1) {
        $printedHTMLheader = 1;
        print $HTMLheader;
        print "<H2>Create / Update an Image</H2>\n";
        print "You have requested an environment that is limited in the number ";
        print "of concurrent reservations that can be made. No further ";
        print "reservations for the environment can be made for the time you ";
        print "have selected. Please select another time to use the ";
        print "environment.<br>";
    } elseif ($rc > 0) {
        $requestid = addRequest(1, $data['revisionid']);
        if ($data["time"] == "now") {
            header("Location: " . BASEURL . SCRIPT . "?mode=viewRequests");
            dbDisconnect();
            exit;
        } else {
            $time = prettyLength($data["length"]);
            if ($data["minute"] == 0) {
                $data["minute"] = "00";
            }
            $printedHTMLheader = 1;
            print $HTMLheader;
            print "<H2>Create / Update an Image</H2>\n";
            print "Your request to use <b>" . $images[$data["imageid"]]["prettyname"];
            print "</b> on " . prettyDatetime($start) . " for {$time} has been ";
            print "accepted.<br><br>\n";
            print "When your reservation time has been reached, the ";
            print "<b>Current Reservations</b> page will give you more ";
            print "information on connecting to the reserved computer. If you ";
            print "would like to modify your reservation, you can do that from ";
            print "the <b>Current Reservations</b> page as well.<br>\n";
        }
    } else {
        $printedHTMLheader = 1;
        print $HTMLheader;
        $cdata = array('imageid' => $data['imageid'], 'length' => $data['length']);
        $cont = addContinuationsEntry('selectTimeTable', $cdata);
        print "<H2>Create / Update an Image</H2>\n";
        print "The reservation you have requested is not available. You may ";
        print "<a href=\"" . BASEURL . SCRIPT . "?continuation={$cont}\">";
        print "view a timetable</a> of free and reserved times to find ";
        print "a time that will work for you.<br>\n";
        #addLogEntry($nowfuture, unixToDatetime($start),
        #            unixToDatetime($end), 0, $data["imageid"]);
    }
}
Example #5
0
function XMLRPCsetRequestEnding($requestid, $end)
{
    global $user;
    $requestid = processInputData($requestid, ARG_NUMERIC);
    $userRequests = getUserRequests('all', $user['id']);
    $found = 0;
    foreach ($userRequests as $req) {
        if ($req['id'] == $requestid) {
            $request = getRequestInfo($requestid);
            $found = 1;
            break;
        }
    }
    if (!$found) {
        return array('status' => 'error', 'errorcode' => 1, 'errormsg' => 'unknown requestid');
    }
    // make sure user is a member of the 'Specify End Time' group
    $groupid = getUserGroupID('Specify End Time');
    $members = getUserGroupMembers($groupid);
    if (!$request['serverrequest'] && !array_key_exists($user['id'], $members)) {
        return array('status' => 'error', 'errorcode' => 35, 'errormsg' => "access denied to specify end time");
    }
    $end = processInputData($end, ARG_NUMERIC);
    $maxend = datetimeToUnix("2038-01-01 00:00:00");
    if ($end < 0 || $end > $maxend) {
        return array('status' => 'error', 'errorcode' => 36, 'errormsg' => "received invalid input for end");
    }
    $startts = datetimeToUnix($request['start']);
    if ($end % (15 * 60)) {
        $end = unixFloor15($end) + 15 * 60;
    }
    // check that reservation has started
    if ($startts > time()) {
        return array('status' => 'error', 'errorcode' => 38, 'errormsg' => 'reservation has not started');
    }
    // check for overlap
    $max = getMaxOverlap($user['id']);
    if (checkOverlap($startts, $end, $max, $requestid)) {
        return array('status' => 'error', 'errorcode' => 41, 'errormsg' => 'overlapping reservation restriction', 'maxoverlap' => $max);
    }
    // check for computer being available for extended time?
    $timeToNext = timeToNextReservation($request);
    $movedall = 1;
    if ($timeToNext > -1) {
        $lockedall = 1;
        if (count($request['reservations']) > 1) {
            # get semaphore on each existing node in cluster so that nothing
            # can get moved to the nodes during this process
            $unixend = datetimeToUnix($request['end']);
            $checkend = unixToDatetime($unixend + 900);
            $resources = getUserResources(array("imageAdmin", "imageCheckOut"));
            $tmp = array_keys($resources['image']);
            $semimageid = $tmp[0];
            $semrevid = getProductionRevisionid($semimageid);
            foreach ($request["reservations"] as $res) {
                if (!retryGetSemaphore($semimageid, $semrevid, $res['managementnodeid'], $res['computerid'], $request['start'], $checkend, $requestid)) {
                    $lockedall = 0;
                    break;
                }
            }
        }
        if ($lockedall) {
            foreach ($request["reservations"] as $res) {
                if (!moveReservationsOffComputer($res["computerid"])) {
                    $movedall = 0;
                    break;
                }
            }
        } else {
            cleanSemaphore();
            return array('status' => 'error', 'errorcode' => 42, 'errormsg' => 'cannot extend due to another reservation immediately after this one');
        }
        cleanSemaphore();
    }
    if (!$movedall) {
        $timeToNext = timeToNextReservation($request);
        if ($timeToNext >= 15) {
            $timeToNext -= 15;
        }
        $oldendts = datetimeToUnix($request['end']);
        // reservation immediately after this one, cannot extend
        if ($timeToNext < 15) {
            return array('status' => 'error', 'errorcode' => 42, 'errormsg' => 'cannot extend due to another reservation immediately after this one');
        } elseif (($end - $oldendts) / 60 > $timeToNext) {
            $maxend = $oldendts + $timeToNext * 60;
            return array('status' => 'error', 'errorcode' => 43, 'errormsg' => 'cannot extend by requested amount due to another reservation', 'maxend' => $maxend);
        }
    }
    $rc = isAvailable(getImages(), $request['reservations'][0]["imageid"], $request['reservations'][0]['imagerevisionid'], $startts, $end, 1, $requestid);
    // conflicts with scheduled maintenance
    if ($rc == -2) {
        addChangeLogEntry($request["logid"], NULL, unixToDatetime($end), $request['start'], NULL, NULL, 0);
        return array('status' => 'error', 'errorcode' => 46, 'errormsg' => 'requested time is during a maintenance window');
    } elseif ($rc == -1) {
        addChangeLogEntry($request["logid"], NULL, unixToDatetime($end), $request['start'], NULL, NULL, 0);
        return array('status' => 'error', 'errorcode' => 44, 'errormsg' => 'concurrent license restriction');
    } elseif ($rc == 0) {
        addChangeLogEntry($request["logid"], NULL, unixToDatetime($end), $request['start'], NULL, NULL, 0);
        return array('status' => 'error', 'errorcode' => 45, 'errormsg' => 'cannot extend at this time');
    }
    // success
    updateRequest($requestid);
    cleanSemaphore();
    return array('status' => 'success');
}