示例#1
0
function confirmEditRequest()
{
    global $submitErr;
    $data = processRequestInput(1);
    if ($submitErr) {
        editRequest();
        return;
    }
    $cdata = getContinuationVar();
    $request = getRequestInfo($cdata["requestid"]);
    if ($request['forimaging']) {
        $reservation = $request['reservations'][0];
    } else {
        foreach ($request["reservations"] as $res) {
            if ($res["forcheckout"]) {
                $reservation = $res;
                break;
            }
        }
    }
    print "<H2>Modify Reservation</H2>\n";
    print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
    if ($cdata["started"]) {
        if ($cdata['openend'] && $data['ending'] == 'date') {
            print "Change ending for <b>{$reservation["prettyimage"]}</b> ";
            print "to {$data['enddate']}?<br><br>\n";
        } else {
            print "Extend reservation for <b>{$reservation["prettyimage"]}</b> ";
            print "by " . prettyLength($data["length"]) . "?<br><br>\n";
        }
        $unixstart = datetimeToUnix($request["start"]);
        $curlen = (datetimeToUnix($request["end"]) - $unixstart) / 60;
        if ($unixstart < datetimeToUnix($request["daterequested"])) {
            $curlen -= 15;
        }
        $cdata["extend"] = $data["length"];
        $cdata["length"] = $curlen + $data["length"];
    } else {
        print "Change reservation for <b>" . $reservation["prettyimage"];
        print "</b> starting ";
        if (datetimeToUnix($request["start"]) < datetimeToUnix($request["daterequested"])) {
            print prettyDatetime($request["daterequested"]);
        } else {
            print prettyDatetime($request["start"]);
        }
        print "<br>\nto ";
        if ($data['ending'] == 'date') {
            print "start {$data["day"]} at {$data["hour"]}:";
            if ($data["minute"] == 0) {
                print "00";
            } else {
                print $data["minute"];
            }
            print " {$data["meridian"]} and end ";
            $tmp = date('n/j/Y-g:i a', datetimeToUnix($data["enddate"]));
            $tmp = explode('-', $tmp);
            print "{$tmp[0]} at {$tmp[1]}?<br><br>\n";
        } else {
            print "{$data["day"]}, at {$data["hour"]}:";
            if ($data["minute"] == 0) {
                print "00";
            } else {
                print $data["minute"];
            }
            print " {$data["meridian"]} ";
            print "for " . prettyLength($data["length"]) . "?<br><br>\n";
        }
    }
    print "<table summary=\"\">\n";
    print "  <TR valign=top>\n";
    print "    <TD>\n";
    $cdata = array_merge($data, $cdata);
    $cdata['imageid'] = $reservation['imageid'];
    $cdata['prettyimage'] = $reservation['prettyimage'];
    $cdata['os'] = $reservation['OS'];
    if ($submitErr) {
        $cont = addContinuationsEntry('submitEditRequest', $cdata, SECINDAY, 1, 0);
    } else {
        $cont = addContinuationsEntry('submitEditRequest', $cdata, SECINDAY, 0, 0);
    }
    print "      <INPUT type=hidden name=continuation value=\"{$cont}\">\n";
    print "      <INPUT type=submit value=Submit>\n";
    print "      </FORM>\n";
    print "    </TD>\n";
    print "    <TD>\n";
    print "      <FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
    $cont = addContinuationsEntry('viewRequests');
    print "      <INPUT type=hidden name=continuation value=\"{$cont}\">\n";
    print "      <INPUT type=submit value=Cancel>\n";
    print "      </FORM>\n";
    print "    </TD>\n";
    print "  </TR>\n";
    print "</table>\n";
}
示例#2
0
function AJnewRequest()
{
    global $user, $remoteIP;
    $data = processRequestInput();
    #$data['err'] = 1;
    #$data['errmsg'] = 'none';
    if ($data['err']) {
        sendJSON($data);
        return;
    }
    if ($data['start'] == 0) {
        $nowfuture = 'now';
        $startts = unixFloor15();
        if ($data['ending'] == 'duration') {
            $endts = $startts + $data['duration'] * 60;
            $nowArr = getdate();
            if ($nowArr['minutes'] % 15 != 0) {
                $endts += 900;
            }
        }
    } else {
        $nowfuture = 'future';
        $startts = $data['start'];
        if ($data['ending'] == 'duration') {
            $endts = $startts + $data['duration'] * 60;
        }
    }
    if ($data['ending'] == 'indefinite') {
        $endts = datetimeToUnix('2038-01-01 00:00:00');
    } elseif ($data['ending'] == 'endat') {
        $endts = $data['end'];
    }
    $images = getImages();
    # TODO initially, this is a hack where we munge the datastructure
    # finishconfigs
    /*if($data['type'] == 'server') {
    		$tmp = getConfigClusters($data['imageid'], 1);
    		if(count($tmp)) {
    			$subimages = array();
    			foreach($tmp as $cluster) {
    				for($i = 0; $i < $cluster['maxinstance']; $i++)
    					$subimages[] = $cluster['childimageid'];
    			}
    			$images[$data['imageid']]['subimages'] = $subimages;
    			if($images[$data['imageid']]['imagemetaid'] == NULL)
    				$images[$data['imageid']]['imagemetaid'] = 1;
    		}
    		elseif($images[$data['imageid']]['imagemetaid'] != NULL &&
    			count($images[$data['imageid']]['subimages'])) {
    			$images[$data['imageid']]['subimages'] = array();
    		}
    	}*/
    # check for exceeding max overlaps
    $max = getMaxOverlap($user['id']);
    if (checkOverlap($startts, $endts, $max)) {
        print "dojo.byId('deployerr').innerHTML = '";
        print i("The selected time overlaps with another reservation you have.");
        print "<br>";
        if ($max == 0) {
            print i("You cannot have any overlapping reservations.");
        } else {
            printf(i("You can have up to %d overlapping reservations."), $max);
        }
        print "'; dojo.removeClass('deployerr', 'hidden');";
        return;
    }
    $imaging = 0;
    if ($data['type'] == 'imaging') {
        $imaging = 1;
    }
    $availablerc = isAvailable($images, $data['imageid'], $data['revisionids'], $startts, $endts, 1, 0, 0, 0, $imaging, $data['ipaddr'], $data['macaddr']);
    if ($availablerc == -4) {
        $msg = i("The IP address you specified is assigned to another VCL node and cannot be used at this time. Submitting a time in the future may allow you to make the reservation, but if the IP remains assigned to the other node, the reservation will fail at deploy time.");
        $data = array('err' => 1, 'errmsg' => $msg);
        sendJSON($data);
        return;
    } elseif ($availablerc == -3) {
        $msg = i("The IP or MAC address you specified overlaps with another reservation using the same IP or MAC address you specified. Please use a different IP or MAC or select a different time to deploy the server.");
        $data = array('err' => 1, 'errmsg' => $msg);
        sendJSON($data);
        return;
    } elseif ($availablerc == -2) {
        $msg = i("The time you requested overlaps with a maintenance window.");
        $data = array('err' => 1, 'errmsg' => $msg);
        sendJSON($data);
        return;
    } elseif ($availablerc == -1) {
        cleanSemaphore();
        $msg = i("You have requested an environment that is limited in the number of concurrent reservations that can be made. No further reservations for the environment can be made for the time you have selected.");
        $data = array('err' => 1, 'errmsg' => $msg);
        sendJSON($data);
        return;
    } elseif ($availablerc == 0) {
        cleanSemaphore();
        $data = array('err' => 2);
        sendJSON($data);
        return;
    }
    $requestid = addRequest($imaging, $data['revisionids'], 1 - $data['nousercheck']);
    if ($data['type'] == 'server') {
        if ($data['ipaddr'] != '') {
            # save additional network info in variable table
            $allnets = getVariable('fixedIPavailnetworks', array());
            $key = long2ip($data['network']) . "/{$data['netmask']}";
            $allnets[$key] = array('router' => $data['router'], 'dns' => $data['dnsArr']);
            setVariable('fixedIPavailnetworks', $allnets, 'yaml');
        }
        $query = "UPDATE reservation " . "SET remoteIP = '{$remoteIP}' " . "WHERE requestid = {$requestid}";
        doQuery($query);
        $fields = array('requestid', 'serverprofileid');
        $values = array($requestid, $data['profileid']);
        if ($data['name'] == '') {
            $fields[] = 'name';
            $name = $images[$data['imageid']]['prettyname'];
            $values[] = "'{$name}'";
        } else {
            $fields[] = 'name';
            $name = mysql_real_escape_string($data['name']);
            $values[] = "'{$name}'";
        }
        if ($data['ipaddr'] != '') {
            $fields[] = 'fixedIP';
            $values[] = "'{$data['ipaddr']}'";
        }
        if ($data['macaddr'] != '') {
            $fields[] = 'fixedMAC';
            $values[] = "'{$data['macaddr']}'";
        }
        if ($data['admingroupid'] != 0) {
            $fields[] = 'admingroupid';
            $values[] = $data['admingroupid'];
        }
        if ($data['logingroupid'] != 0) {
            $fields[] = 'logingroupid';
            $values[] = $data['logingroupid'];
        }
        if ($data['monitored'] != 0) {
            $fields[] = 'monitored';
            $values[] = 1;
        }
        $allfields = implode(',', $fields);
        $allvalues = implode(',', $values);
        $query = "INSERT INTO serverrequest ({$allfields}) VALUES ({$allvalues})";
        doQuery($query, 101);
        if ($data['ipaddr'] != '') {
            $srqid = dbLastInsertID();
            $var = array('netmask' => $data['netmask'], 'router' => $data['router'], 'dns' => $data['dnsArr']);
            setVariable("fixedIPsr{$srqid}", $var, 'yaml');
        }
        # TODO configs
        //saveRequestConfigs($requestid, $data['imageid'], $data['configs'], $data['configvars']);
    }
    $data = array('err' => 0);
    sendJSON($data);
}
示例#3
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"]);
    }
}