\n";
$newbtnh .= " " . _("New Reservation") . "\n";
$newbtnh .= " \n";
$newbtnh .= " \n";
}
if($mode != 'AJviewRequests') {
print "
" . _("Current Reservations") . " \n";
if(count($requests) == 0)
print "\n";
else
print "\n";
if($newbtnh == '')
print _("You have no current reservations and do not have access to create new ones.") . " \n";
else
print _("You have no current reservations.") . " \n";
print " \n";
print $newbtnh;
}
if($newbtnh == '')
return;
if($mode != 'AJviewRequests')
print "\n";
$refresh = 0;
$connect = 0;
$failed = 0;
$normal = '';
$imaging = '';
$long = '';
$server = '';
$pendingcnt = 0;
$reqids = array();
if(checkUserHasPerm('View Debug Information'))
$nodes = getManagementNodes();
if($count = count($requests)) {
$now = time();
for($i = 0, $failed = 0, $timedout = 0, $text = '', $showcreateimage = 0, $cluster = 0;
$i < $count;
$i++, $failed = 0, $timedout = 0, $text = '', $cluster = 0) {
if($requests[$i]['forcheckout'] == 0 &&
$requests[$i]['forimaging'] == 0)
continue;
if(count($requests[$i]['reservations']))
$cluster = 1;
$cdata = array('requestid' => $requests[$i]['id']);
$reqids[] = $requests[$i]['id'];
$imageid = $requests[$i]["imageid"];
$text .= "
\n";
if(requestIsReady($requests[$i]) && $requests[$i]['useraccountready']) {
$connect = 1;
# request is ready, print Connect! and End buttons
$cont = addContinuationsEntry('AJconnectRequest', $cdata, SECINDAY);
$text .= getViewRequestHTMLitem('connectbtn', $cont);
if($requests[$i]['serveradmin']) {
$cdata2 = $cdata;
$cdata2['notbyowner'] = 0;
if($user['id'] != $requests[$i]['userid'])
$cdata2['notbyowner'] = 1;
$cont = addContinuationsEntry('AJconfirmDeleteRequest', $cdata2, SECINDAY);
$text .= getViewRequestHTMLitem('deletebtn', $cont);
}
else
$text .= " \n";
}
elseif($requests[$i]["currstateid"] == 5) {
# request has failed
$text .= getViewRequestHTMLitem('failedblock', $requests[$i]['id']);
if($requests[$i]['serveradmin']) {
$cont = addContinuationsEntry('AJconfirmRemoveRequest', $cdata, SECINDAY);
$text .= getViewRequestHTMLitem('removebtn', $cont);
}
else
$text .= " \n";
$failed = 1;
}
elseif(datetimeToUnix($requests[$i]["start"]) < $now) {
# other cases where the reservation start time has been reached
if(($requests[$i]["currstateid"] == 12 &&
$requests[$i]['laststateid'] == 11) ||
$requests[$i]["currstateid"] == 11 ||
($requests[$i]["currstateid"] == 14 &&
$requests[$i]["laststateid"] == 11)) {
# request has timed out
$text .= getViewRequestHTMLitem('timeoutblock');
$timedout = 1;
if($requests[$i]['serveradmin']) {
$cont = addContinuationsEntry('AJconfirmRemoveRequest', $cdata, SECINDAY);
$text .= getViewRequestHTMLitem('removebtn', $cont);
}
else
$text .= " \n";
}
else {
# computer is loading, print Pending... and Delete button
# TODO figure out a different way to estimate for reboot and reinstall states
# TODO if user account not ready, print accurate information in details
$pendingcnt++;
$remaining = 1;
if(isComputerLoading($requests[$i], $computers)) {
if(datetimeToUnix($requests[$i]["daterequested"]) >=
datetimeToUnix($requests[$i]["start"])) {
$startload = datetimeToUnix($requests[$i]["daterequested"]);
}
else {
$startload = datetimeToUnix($requests[$i]["start"]);
}
$imgLoadTime = getImageLoadEstimate($imageid);
if($imgLoadTime == 0)
$imgLoadTime = $images[$imageid]['reloadtime'] * 60;
$tmp = ($imgLoadTime - ($now - $startload)) / 60;
$remaining = sprintf("%d", $tmp) + 1;
if($remaining < 1) {
$remaining = 1;
}
}
$data = array('text' => '');
if($requests[$i]['currstateid'] != 26 &&
$requests[$i]['currstateid'] != 27 &&
$requests[$i]['currstateid'] != 28 &&
$requests[$i]['currstateid'] != 24 &&
($requests[$i]["currstateid"] != 14 ||
($requests[$i]['laststateid'] != 26 &&
$requests[$i]['laststateid'] != 27 &&
$requests[$i]['laststateid'] != 28 &&
$requests[$i]['laststateid'] != 24)))
$data['text'] = _(" Est: ") . $remaining . _(" min remaining\n");
$text .= getViewRequestHTMLitem('pendingblock', $requests[$i]['id'], $data);
$refresh = 1;
if($requests[$i]['serveradmin'] && $requests[$i]['laststateid'] != 24) {
$cdata2 = $cdata;
$cdata2['notbyowner'] = 0;
if($user['id'] != $requests[$i]['userid'])
$cdata2['notbyowner'] = 1;
$cont = addContinuationsEntry('AJconfirmDeleteRequest', $cdata2, SECINDAY);
$text .= getViewRequestHTMLitem('deletebtn', $cont);
}
else
$text .= " \n";
}
}
else {
# reservation is in the future
$text .= " \n";
if($requests[$i]['serveradmin']) {
$cdata2 = $cdata;
$cdata2['notbyowner'] = 0;
if($user['id'] != $requests[$i]['userid'])
$cdata2['notbyowner'] = 1;
$cont = addContinuationsEntry('AJconfirmDeleteRequest', $cdata2, SECINDAY);
$text .= getViewRequestHTMLitem('deletebtn', $cont);
}
else
$text .= " \n";
}
if(! $failed && ! $timedout) {
# print edit button
$editcont = addContinuationsEntry('AJeditRequest', $cdata, SECINDAY);
$imgcont = addContinuationsEntry('AJstartImage', $cdata, SECINDAY);
if($requests[$i]['serveradmin']) {
$text .= getViewRequestHTMLitem('openmoreoptions');
$text .= getViewRequestHTMLitem('editoption', $editcont);
if(array_key_exists($imageid, $resources['image']) && ! $cluster && # imageAdmin access, not a cluster,
($requests[$i]['currstateid'] == 8 || $requests[$i]['laststateid'] == 8)) { # reservation has been in inuse state
$text .= getViewRequestHTMLitem('endcreateoption', $imgcont);
}
/*else
$text .= getViewRequestHTMLitem('endcreateoptiondisable');*/
if(array_key_exists($imageid, $resources['image']) && ! $cluster &&
$requests[$i]['server'] && ($requests[$i]['currstateid'] == 8 ||
($requests[$i]['currstateid'] == 14 && $requests[$i]['laststateid'] == 8))) {
$chkcdata = $cdata;
$chkcdata['checkpoint'] = 1;
$imgcont = addContinuationsEntry('AJstartImage', $chkcdata, SECINDAY);
$text .= getViewRequestHTMLitem('checkpointoption', $imgcont);
}
elseif($requests[$i]['server'] && $requests[$i]['currstateid'] == 24)
$text .= getViewRequestHTMLitem('checkpointoptiondisable');
if($requests[$i]['currstateid'] == 8 ||
(! $cluster &&
$requests[$i]['OSinstalltype'] != 'none' &&
$requests[$i]['currstateid'] != 3 &&
$requests[$i]['laststateid'] != 3 &&
$requests[$i]['currstateid'] != 13 &&
$requests[$i]['laststateid'] != 13 &&
$requests[$i]['currstateid'] != 24 &&
$requests[$i]['laststateid'] != 24 &&
$requests[$i]['currstateid'] != 16 &&
$requests[$i]['laststateid'] != 16 &&
$requests[$i]['currstateid'] != 26 &&
$requests[$i]['laststateid'] != 26 &&
$requests[$i]['currstateid'] != 28 &&
$requests[$i]['laststateid'] != 28 &&
$requests[$i]['currstateid'] != 27 &&
$requests[$i]['laststateid'] != 27)) {
$cont = addContinuationsEntry('AJrebootRequest', $cdata, SECINDAY);
$text .= getViewRequestHTMLitem('rebootoption', $cont);
$cont = addContinuationsEntry('AJshowReinstallRequest', $cdata, SECINDAY);
$text .= getViewRequestHTMLitem('reinstalloption', $cont);
}
else {
$text .= getViewRequestHTMLitem('rebootoptiondisable');
$text .= getViewRequestHTMLitem('reinstalloptiondisable');
}
$text .= " \n";
$text .= " \n";
$text .= getViewRequestHTMLitem('timeoutdata', $requests[$i]['id'], $requests[$i]);
$text .= " \n";
}
else {
$text .= " ";
$text .= getViewRequestHTMLitem('timeoutdata', $requests[$i]['id'], $requests[$i]);
$text .= " \n";
}
}
else
$text .= " \n";
# print name of server request
if($requests[$i]['server']) {
if($requests[$i]['servername'] == '')
$text .= getViewRequestHTMLitem('servername', $requests[$i]['prettyimage']);
else
$text .= getViewRequestHTMLitem('servername', $requests[$i]['servername']);
}
# print name of image, add (Testing) if it is the test version of an image
if(!$requests[$i]['server']) {
$data = array('addtest' => 0);
if($requests[$i]["test"])
$data['addtest'] = 1;
$text .= getViewRequestHTMLitem('imagename', $requests[$i]['prettyimage'], $data);
}
# print start time
if(! $requests[$i]['server']) {
$data = array('start' => $requests[$i]['start'],
'requested' => $requests[$i]['daterequested']);
$text .= getViewRequestHTMLitem('starttime', '', $data);
}
# print end time
$data = array('end' => $requests[$i]['end']);
$text .= getViewRequestHTMLitem('endtime', '', $data);
# print date requested
if(! $requests[$i]['server'])
$text .= getViewRequestHTMLitem('requesttime', $requests[$i]['daterequested']);
# print server request details
if($requests[$i]['server']) {
$data = array('owner' => getUserUnityID($requests[$i]['userid']),
'requesttime' => $requests[$i]['daterequested'],
'admingroup' => $requests[$i]['serveradmingroup'],
'logingroup' => $requests[$i]['serverlogingroup'],
'image' => $requests[$i]['prettyimage'],
'starttime' => $requests[$i]['start']);
if($requests[$i]['currstateid'] == 14)
$data['stateid'] = $requests[$i]['laststateid'];
else
$data['stateid'] = $requests[$i]['currstateid'];
$text .= getViewRequestHTMLitem('serverdetails', $requests[$i]['id'], $data);
}
if(checkUserHasPerm('View Debug Information')) {
if(! is_null($requests[$i]['vmhostid'])) {
$query = "SELECT c.hostname "
. "FROM computer c, "
. "vmhost v "
. "WHERE v.id = {$requests[$i]['vmhostid']} AND "
. "v.computerid = c.id";
$qh = doQuery($query, 101);
$row = mysql_fetch_assoc($qh);
$vmhost = $row['hostname'];
}
$text .= " \n";
$text .= "";
$text .= "Mgmt node : {$nodes[$requests[$i]["managementnodeid"]]['hostname']} \n";
$text .= "Computer ID : {$requests[$i]['computerid']} \n";
$text .= "Comp hostname : {$computers[$requests[$i]["computerid"]]["hostname"]} \n";
$text .= "Comp IP : {$requests[$i]["IPaddress"]} \n";
$text .= "Comp State ID : {$computers[$requests[$i]["computerid"]]["stateid"]} \n";
$text .= "Comp Type : {$requests[$i]['comptype']} \n";
if(! is_null($requests[$i]['vmhostid']))
$text .= "VM Host : $vmhost \n";
$text .= "Current State ID : {$requests[$i]["currstateid"]} \n";
$text .= "Last State ID : {$requests[$i]["laststateid"]} \n";
$text .= "
\n";
}
$text .= " \n";
if($requests[$i]['server'])
$server .= $text;
elseif($requests[$i]['forimaging'])
$imaging .= $text;
elseif($requests[$i]['longterm'])
$long .= $text;
else
$normal .= $text;
}
}
if(! empty($normal)) {
if(! empty($imaging) || ! empty($long))
$text .= _("You currently have the following
normal reservations:") . "
\n";
else
$text .= _("You currently have the following normal reservations:") . "
\n";
if($lengthchanged) {
$text .= "
";
$text .= _("NOTE: The maximum allowed reservation length for one of these reservations was less than the length you submitted, and the length of that reservation has been adjusted accordingly.");
$text .= " \n";
}
$text .= "
\n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Environment") . " \n";
$text .= " " . _("Starting") . " \n";
$text .= " " . _("Ending") . " \n";
$text .= " " . _("Initially requested") . " \n";
if(checkUserHasPerm('View Debug Information'))
$text .= " " . _("Req ID") . " \n";
$text .= " \n";
$text .= $normal;
$text .= "
\n";
}
if(! empty($imaging)) {
if(! empty($normal))
$text .= "
\n";
$text .= _("You currently have the following
imaging reservations:") . "
\n";
$text .= "
\n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Environment") . " \n";
$text .= " " . _("Starting") . " \n";
$text .= " " . _("Ending") . " \n";
$text .= " " . _("Initially requested") . " \n";
$computers = getComputers();
if(checkUserHasPerm('View Debug Information'))
$text .= " Req ID \n";
$text .= " \n";
$text .= $imaging;
$text .= "
\n";
}
if(! empty($long)) {
if(! empty($normal) || ! empty($imaging))
$text .= "
\n";
$text .= _("You currently have the following
long term reservations:") . "
\n";
$text .= "
\n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Environment") . " \n";
$text .= " " . _("Starting") . " \n";
$text .= " " . _("Ending") . " \n";
$text .= " " . _("Initially requested") . " \n";
$computers = getComputers();
if(checkUserHasPerm('View Debug Information'))
$text .= " Req ID \n";
$text .= " \n";
$text .= $long;
$text .= "
\n";
}
if(! empty($server)) {
if(! empty($normal) || ! empty($imaging) || ! empty($long))
$text .= "
\n";
$text .= _("You currently have the following
server reservations:") . "
\n";
$text .= "
\n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Name") . " \n";
$text .= " " . _("Ending") . " \n";
$computers = getComputers();
$text .= " " . _("Details") . " \n";
if(checkUserHasPerm('View Debug Information'))
$text .= " " . _("Req ID") . " \n";
$text .= " \n";
$text .= $server;
$text .= "
\n";
}
# connect div
if($connect) {
$text .= "
";
$text .= _("Click the
Connect! button to get further information about connecting to the reserved system. You must click the button from a web browser running on the same computer from which you will be connecting to the remote computer; otherwise, you may be denied access to the machine.") . "\n";
}
if($refresh) {
$text .= "
";
$text .= _("This page will automatically update every 20 seconds until the
Pending... reservation is ready.") . "\n";
}
if($failed) {
$text .= "
";
$text .= _("An error has occurred that has kept one of your reservations from being processed. We apologize for any inconvenience this may have caused.") . "\n";
}
$cont = addContinuationsEntry('AJviewRequests', array(), SECINDAY);
$text .= "
\n";
$cont = addContinuationsEntry('AJpreviewClickThrough', array());
$text .= "
\n";
$text .= "
\n";
if($mode != 'AJviewRequests') {
$text .= newReservationHTML();
$text .= newReservationConfigHTML();
/*$text .= "\n";
#$text .= " style=\"height: 80%; width: 50%;\">\n";
$text .= " style=\"width: 50%;\">\n";
#$text .= "
\n";
#$text .= "
\n";
$text .= _("There are multiple versions of this environment available.");
$text .= " " . _("Please select the version you would like to check out:");
#$text .= "\n
\n"; # ContentPane
#$text .= "
\n";
#$text .= "
\n";
$text .= "
\n";
#$text .= "
\n"; # ContentPane
#$text .= "
\n";
$text .= "
\n";
$text .= " \n";
$text .= " " . _("Create Reservation") . "\n";
$text .= " \n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Cancel") . "\n";
$text .= " \n";
$text .= " \n";
$text .= "
\n"; # center
#$text .= "
\n"; # ContentPane
#$text .= "
\n"; # BorderContainer
$text .= "
\n"; # Dialog*/
$text .= "\n";
$text .= " this.hide();\n";
$text .= "\n";
$text .= "\n";
$text .= "
\n";
$text .= "
\n";
$text .= "
\n";
$text .= "\n";
$text .= "
\n";
$text .= "
\n";
$text .= "
\n";
$text .= "
\n";
$text .= " \n";
$text .= " " . _("Delete Reservation") . "\n";
$text .= " \n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Cancel") . "\n";
$text .= " \n";
$text .= " \n";
$text .= "
\n";
$text .= "
\n";
$text .= "
\n";
$text .= " \n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Remove Reservation") . "\n";
$text .= " \n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Cancel") . "\n";
$text .= " \n";
$text .= " \n";
$text .= "
\n";
$text .= "\n";
$text .= "\n";
$text .= " hideEditResDlg();\n";
$text .= " \n";
$text .= "
\n";
$text .= "
\n";
$text .= "
\n";
$text .= "
\n";
$text .= "
\n";
$text .= " \n";
$text .= " " . _("Modify Reservation") . "\n";
$text .= " \n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Cancel") . "\n";
$text .= " \n";
$text .= " \n";
$text .= "
\n";
$text .= "
\n";
$text .= "\n";
$text .= " hideRebootResDlg();\n";
$text .= " \n";
$text .= "
";
$h = _("You can select either a soft or a hard reboot. A soft reboot issues a reboot command to the operating system. A hard reboot is akin to toggling the power switch on a computer. After issuing the reboot, it may take several minutes before the machine is available again. It is also possible that it will not come back up at all. Are you sure you want to continue?");
$text .= preg_replace("/(.{1,60}([ \n]|$))/", '\1 ', $h);
$text .= "
\n";
$text .= "
\n";
$text .= " \n";
$text .= " " . _("Soft Reboot") . " \n";
$text .= " \n";
$text .= " " . _("Hard Reboot") . " \n";
$text .= "
\n";
$text .= "
\n";
$text .= "
\n";
$text .= "
\n";
$text .= " \n";
$text .= " " . _("Reboot Reservation") . "\n";
$text .= " \n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Cancel") . "\n";
$text .= " \n";
$text .= " \n";
$text .= "
\n";
$text .= "
\n";
$text .= "\n";
$text .= " hideReinstallResDlg();\n";
$text .= " \n";
$text .= "
";
$text .= "
" . _("Loading...") . "
\n";
$text .= "
\n";
$text .= "
\n";
$text .= "
\n";
$text .= "
\n";
$text .= " \n";
$text .= " " . _("Reinstall Reservation") . "\n";
$text .= " \n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Cancel") . "\n";
$text .= " \n";
$text .= " \n";
$text .= "
\n";
$text .= "
\n";
$text .= "";
$text .= "
" . _("Loading...") . "
\n";
$text .= "
\n";
$text .= " \n";
$text .= " \n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Use Selected Time") . "\n";
$text .= " \n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Cancel") . "\n";
$text .= " \n";
$text .= " \n";
$text .= "
\n";
$text .= "\n";
$text .= "\n";
$text .= " hideStartImageDlg();\n";
$text .= " \n";
$text .= "
\n";
$text .= "
" . _("Create / Update an Image") . " \n";
$text .= "\n"; # imageendrescontent
$text .= "
\n";
$text .= "
" . _("Keep Reservation & Create / Update an Image") . " \n";
$h = _("This process will create a new image or new revision of the image while allowing you to keep your reservation. The node will be taken offline during the image capture process.");
$h .= "\n \n";
$h .= "" . _("NOTE: The same sanitizing that occurs during normal image capture will take place. This includes things such as deleting temporary files, cleaning out firewall rules, removing user home space, and removing user accounts.");
$h .= "\n \n";
$h .= _("After the imaging occurs, you will be able to connect to the reservation again. The image will appear to you as if you had just made a new reservation for it.");
$h .= "\n \n";
$text .= preg_replace("/(.{1,80}([ \n]|$))/", '\1 ', $h);
$text .= "\n"; # imagekeeprescontent
$text .= _("Are you creating a new image or updating an existing image?") . "
\n";
$text .= "
\n";
$text .= "
" . _("Creating New Image") . " \n";
$text .= "
\n";
$text .= "
";
$text .= _("Update Existing Image") . " ";
$text .= "
\n";
$text .= "
\n";
$text .= " \n";
$text .= " " . _("Submit") . "\n";
$text .= " \n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Cancel") . "\n";
$text .= " \n";
$text .= " \n";
$text .= "
\n";
$text .= "
\n";
$text .= "
\n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Close") . "\n";
$text .= " \n";
$text .= " \n";
$text .= "
\n";
$text .= "\n";
$text .= "', $h);
$text .= "
\n";
$text .= "
\n";
$text .= " \n";
$text .= " " . _("Okay") . "\n";
$text .= " \n";
$text .= " \n";
$text .= "
\n";
$text .= "
\n";
$text .= " \n";
$obj = new Image();
$text .= $obj->addEditDialogHTML(1);
$text .= "\n";
$text .= " hideUpdateImageDlg();\n";
$text .= " \n";
$text .= "
\n";
$text .= "
" . _("New Revision Comments") . " \n";
$h = _("Enter any notes for yourself and other admins about the current state of the image. These are optional and are not visible to end users:");
$text .= preg_replace("/(.{1,85}([ \n]|$))/", '\1 ', $h);
$text .= " \n";
$text .= " " . _("Previous Revision Comments") . " \n";
$text .= " \n";
$text .= " \n";
$text .= "
\n";
$text .= " \n";
$text .= " " . _("Submit") . "\n";
$text .= " \n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Cancel") . "\n";
$text .= " \n";
$text .= " \n";
$text .= "
\n";
$text .= "
\n";
$text .= "\n";
$text .= " hideClickThroughDlg();\n";
$text .= " \n";
$text .= "
\n";
$text .= "
\n";
$text .= "
\n";
$text .= " \n";
$text .= " " . _("I agree") . "\n";
$text .= " \n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("I do not agree") . "\n";
$text .= " \n";
$text .= " \n";
$text .= "
\n";
$text .= "
\n";
$text .= "
\n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Close") . "\n";
$text .= " \n";
$text .= " \n";
$text .= "
\n";
$text .= "\n";
$text .= "\n";
$text .= "
Confirm Server Delete \n";
$text .= " \n";
$warn = _("WARNING: You are not the owner of this reservation. You have been granted access to manage this reservation by another user. Hover over the details icon to see who the owner is. You should not delete this reservation unless the owner is aware that you are deleting it.");
$text .= preg_replace("/(.{1,80}([ \n]|$))/", '\1 ', $warn);
$text .= " \n";
$text .= " \n";
$text .= " \n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Confirm Delete Reservation") . "\n";
$text .= " \n";
$text .= " \n";
$text .= " \n";
$text .= " " . _("Cancel") . "\n";
$text .= " \n";
$text .= " \n";
$text .= "
\n";
$text .= "\n";
print $text;
}
else {
$text = str_replace("\n", ' ', $text);
$text = str_replace("('", "(\'", $text);
$text = str_replace("')", "\')", $text);
print "document.body.style.cursor = 'default';";
if(count($requests) == 0)
print "dojo.removeClass('noresspan', 'hidden');";
else
print "dojo.addClass('noresspan', 'hidden');";
if($refresh)
print "refresh_timer = setTimeout(resRefresh, 20000);\n";
print(setAttribute('subcontent', 'innerHTML', $text));
print "AJdojoCreate('subcontent');";
if($incPaneDetails) {
$text = detailStatusHTML($refreqid);
print(setAttribute('resStatusText', 'innerHTML', $text));
}
print "checkResGone(" . json_encode($reqids) . ");";
if($pendingcnt)
print "document.title = '$pendingcnt Pending :: VCL :: Virtual Computing Lab';";
else
print "document.title = 'VCL :: Virtual Computing Lab';";
return;
}
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn getViewRequestHTMLitem($item, $var1, $data)
///
/// \param $item - name of HTML section to be generated
/// \param $var1 - generic variable to be used in HTML
/// \param $data - an array of any extra data to be used in HTML
///
/// \return a string of HTML
///
/// \brief generates HTML for a specific portion of the current reservations
/// page
///
////////////////////////////////////////////////////////////////////////////////
function getViewRequestHTMLitem($item, $var1='', $data=array()) {
global $user;
$r = '';
if($item == 'connectbtn') {
$r .= " \n";
$r .= dijitButton('', _("Connect!"), "connectRequest('$var1');");
$r .= " \n";
return $r;
}
if($item == 'deletebtn') {
$r .= " \n";
$r .= " \n";
$r .= " " . _("Delete Reservation") . "\n";
$r .= " \n";
$r .= " \n";
$r .= " \n";
return $r;
}
if($item == 'failedblock') {
$r .= " \n";
$r .= " \n";
$r .= " ";
$r .= "" . _("Reservation failed") . " \n";
$r .= " \n";
$r .= " \n";
$r .= " \n";
$r .= " ";
$r .= _("Reservation failed") . " \n";
$r .= " \n";
$r .= " \n";
$r .= " \n";
return $r;
}
if($item == 'removebtn') {
$r .= " \n";
$r .= " \n";
$r .= " " . _("Remove") . "\n";
$r .= " \n";
$r .= " \n";
$r .= " \n";
return $r;
}
if($item == 'timeoutblock') {
$r .= " \n";
$r .= " " . _("Reservation has timed out") . " \n";
$r .= " \n";
return $r;
}
if($item == 'pendingblock') {
$r .= " \n";
$r .= " \n";
$r .= " ";
$r .= "" . _("Pending...") . " \n";
$r .= " \n";
$r .= " \n";
$r .= " \n";
$r .= " ";
$r .= "" . _("Pending...") . " \n";
$r .= " \n";
$r .= " \n";
if(! empty($data['text']))
$r .= " {$data['text']}";
$r .= " \n";
return $r;
}
if($item == 'openmoreoptions') {
$r .= " \n";
$r .= " \n";
$r .= "
" . _("More Options") . "... \n";
$r .= "
\n";
return $r;
}
if($item == 'editoption') {
$r .= "
\n";
$r .= "
\n";
return $r;
}
if($item == 'endcreateoption') {
$r .= "
\n";
$r .= "
\n";
return $r;
}
if($item == 'endcreateoptiondisable') {
$r .= "
\n";
$r .= "
\n";
return $r;
}
if($item == 'checkpointoptiondisable') {
$r .= "
\n";
$r .= " \n";
$r .= "
\n";
return $r;
}
if($item == 'rebootoptiondisable') {
$r .= "
\n";
$r .= "
\n";
return $r;
}
if($item == 'reinstalloption') {
$r .= "
\n";
$r .= " \n";
$r .= "
\n";
return $r;
}
if($item == 'reinstalloptiondisable') {
$r .= "
\n";
$r .= "
\n";
return $r;
}
if($item == 'imagename') {
$r .= "
" . str_replace("'", "'", $var1);
if($data['addtest'])
$r .= " " . _("(Testing)");
$r .= " \n";
return $r;
}
if($item == 'starttime') {
if(datetimeToUnix($data['start']) < datetimeToUnix($data['requested']))
$r .= "
" . prettyDatetime($data['requested'], 1) . " \n";
else
$r .= "
" . prettyDatetime($data['start'], 1) . " \n";
return $r;
}
if($item == 'endtime') {
if($data['end'] == '2038-01-01 00:00:00')
$r .= "
" . _("(none)") . " \n";
else
$r .= "
" . prettyDatetime($data['end'], 1) . " \n";
return $r;
}
if($item == 'requesttime') {
$r .= "
" . prettyDatetime($var1, 1) . " \n";
return $r;
}
if($item == 'servername') {
$r .= "
$var1 \n";
return $r;
}
if($item == 'serverdetails') {
$r .= "
\n";
$r .= "";
$r .= " \n";
$r .= "\n";
$r .= "" . _("Owner:") . " " . " {$data['owner']} \n";
$r .= "" . _("Environment:") . " " . " {$data['image']} \n";
$r .= "" . _("Start Time:") . " " . prettyDatetime($data['starttime'], 1) . " \n";
$r .= "" . _("Initially Requested:") . " " . prettyDatetime($data['requesttime'], 1) . " \n";
if(empty($data['admingroup']))
$r .= "" . _("Admin User Group:") . " (" . _("none") . ") \n";
else
$r .= "" . _("Admin User Group:") . " " . " {$data['admingroup']} \n";
if(empty($data['logingroup']))
$r .= "" . _("Access User Group:") . " " . _("(none)") . " \n";
else
$r .= "" . _("Access User Group:") . " " . " {$data['logingroup']} \n";
if($data['stateid'] == 8)
$r .= "" . _("Status:") . " " . _("In Use") . "\n";
elseif($data['stateid'] == 24)
$r .= "" . _("Status:") . " " . _("Checkpointing") . "\n";
elseif($data['stateid'] == 5)
$r .= "" . _("Status:") . " " . _("Failed") . "\n";
elseif($data['stateid'] == 13)
$r .= "" . _("Status:") . " " . _("New") . "\n";
elseif($data['stateid'] == 28)
$r .= "" . _("Status:") . " " . _("Hard Rebooting") . "\n";
elseif($data['stateid'] == 26)
$r .= "" . _("Status:") . " " . _("Soft Rebooting") . "\n";
elseif($data['stateid'] == 27)
$r .= "" . _("Status:") . " " . _("Reinstalling") . "\n";
elseif($data['stateid'] == 6)
$r .= "" . _("Status:") . " " . _("Loading") . "\n";
elseif($data['stateid'] == 3)
$r .= "" . _("Status:") . " " . _("In Use") . "\n";
elseif($data['stateid'] == 11)
$r .= "" . _("Status:") . " " . _("Timed Out") . "\n";
$r .= "
\n";
$r .= " \n";
return $r;
}
if($item == 'timeoutdata') {
$timeout = getReservationNextTimeout($data['resid']);
$end = datetimeToUnix($data['end']);
if(! is_null($timeout)) {
if($timeout > $end)
$timeout = $end;
$r .= "
\n";
}
else {
$timeout = getVariable("reconnecttimeout|{$user['affiliation']}");
if(is_null($timeout))
$timeout = getVariable("reconnecttimeout", 900);
$timeout = time() + $timeout + 15;
if($timeout > $end)
$timeout = $end;
$r .= "
\n";
}
return $r;
}
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn newReservationHTML()
///
/// \return html
///
/// \brief generates HTML for dialog for creating new reservation
///
////////////////////////////////////////////////////////////////////////////////
function newReservationHTML() {
global $user, $skin;
$forimaging = getContinuationVar('imaging', processInputVar('imaging', ARG_NUMERIC, 0));
$checkout = getUserResources(array("imageAdmin", "imageCheckOut"));
$imaging = getUserResources(array("imageAdmin"));
$server = getUserResources(array("serverCheckOut"), array("available"));
$imagedata = getImages();
$baseaccess = 0;
$imagingaccess = 0;
$serveraccess = 0;
$images = array();
$serverimages = array();
$dorevisionscont = 0;
if(in_array('imageAdmin', $user['privileges']) &&
count($imaging['image'])) {
$imagingaccess = 1;
}
if(in_array('imageCheckOut', $user['privileges']) &&
count($checkout['image'])) {
$baseaccess = 1;
foreach($checkout['image'] as $id => $name) {
$images[$id] = array('name' => $name,
'basic' => 1,
'imaging' => 0,
'server' => 1,
'checkout' => 1,
'maxinitialtime' => 0,
'revisions' => 0);
if(array_key_exists($id, $imagedata) &&
! $imagedata[$id]["forcheckout"])
$images[$id]['checkout'] = 0;
if($imagingaccess && array_key_exists($id, $imaging['image']))
$images[$id]['imaging'] = 1;
if(array_key_exists($id, $imagedata) &&
$imagedata[$id]["maxinitialtime"] != 0)
$images[$id]['maxinitialtime'] = $imagedata[$id]['maxinitialtime'];
$subowner = 0;
if(array_key_exists($id, $imagedata) &&
$imagedata[$id]['imagemetaid'] != NULL &&
count($imagedata[$id]['subimages'])) {
foreach($imagedata[$id]['subimages'] as $subid) {
if(array_key_exists($subid, $imagedata) &&
$imagedata[$subid]['ownerid'] == $user['id'] &&
count($imagedata[$subid]['imagerevision']) > 1)
$subowner = 1;
}
}
if($subowner ||
(array_key_exists($id, $imagedata) &&
count($imagedata[$id]['imagerevision']) > 1 &&
($imagedata[$id]['ownerid'] == $user['id'] ||
checkUserHasPerm('View Debug Information')))) {
$images[$id]['revisions'] = 1;
$dorevisionscont = 1;
}
}
}
if(in_array('serverCheckOut', $user['privileges']) &&
count($checkout['image'])) {
$serveraccess = 1;
$extraimages = getServerProfileImages($user['id']);
foreach($extraimages as $id => $name) {
if(! array_key_exists($id, $images)) {
$images[$id] = array('name' => $name,
'basic' => 0,
'imaging' => 0,
'server' => 1,
'checkout' => 1,
'maxinitialtime' => 0,
'revisions' => 0);
if(array_key_exists($id, $imagedata) &&
! $imagedata[$id]["forcheckout"])
$images[$id]['checkout'] = 0;
if(array_key_exists($id, $imagedata) &&
$imagedata[$id]["maxinitialtime"] != 0)
$images[$id]['maxinitialtime'] = $imagedata[$id]['maxinitialtime'];
$subowner = 0;
if(array_key_exists($id, $imagedata) &&
$imagedata[$id]['imagemetaid'] != NULL &&
count($imagedata[$id]['subimages'])) {
foreach($imagedata[$id]['subimages'] as $subid) {
if(array_key_exists($subid, $imagedata) &&
$imagedata[$subid]['ownerid'] == $user['id'] &&
count($imagedata[$subid]['imagerevision']) > 1)
$subowner = 1;
}
}
if($subowner ||
(array_key_exists($id, $imagedata) &&
count($imagedata[$id]['imagerevision']) > 1 &&
($imagedata[$id]['ownerid'] == $user['id'] ||
checkUserHasPerm('View Debug Information')))) {
$images[$id]['revisions'] = 1;
$dorevisionscont = 1;
}
}
}
}
$imageid = getUsersLastImage($user['id']);
if(is_null($imageid) && count($images)) {
$tmp = array_keys($images);
$imageid = $tmp[0];
}
uasort($images, "sortKeepIndex");
$groupid = getUserGroupID('Specify End Time', 1);
$members = getUserGroupMembers($groupid);
if(array_key_exists($user['id'], $members))
$openend = 1;
else
$openend = 0;
$groupid = getUserGroupID('Allow No User Check', 1);
$members = getUserGroupMembers($groupid);
if(array_key_exists($user['id'], $members))
$nousercheck = 1;
else
$nousercheck = 0;
$cdata = array('baseaccess' => $baseaccess,
'imagingaccess' => $imagingaccess,
'serveraccess' => $serveraccess,
'openend' => $openend,
'nousercheck' => $nousercheck,
'imaging' => $forimaging);
$debug = processInputVar('debug', ARG_NUMERIC, 0);
if($debug && checkUserHasPerm('View Debug Information'))
$cdata['debug'] = 1;
$h = '';
$h = "
\n";
$h .= "
\n";
/*$cbtn = "
\n";
$cbtn .= " \n";
$cbtn .= " " . _("Close") . "\n";
$cbtn .= " \n";
$cbtn .= " \n";
$cbtn .= "
\n"; # center
if($forimaging) {
$h .= "
" . _("Create / Update an Image") . " \n";
if($imagingaccess == 0) {
$h .= _("You don't have access to any base images from which to create new images.") . "
\n";
return $h . $cbtn;
}
}
else*/
$h .= "
" . _("New Reservation") . " \n";
if(! count($images)) {
$h .= _("You do not have access to any images.");
$h .= "
\n";
$h .= "
\n";
$h .= " \n";
$h .= " " . _("Close") . "\n";
$h .= " \n";
$h .= " \n";
$h .= "
\n"; # center
$h .= "
\n"; # newResDlgContent
$h .= "
\n"; # newResDlg
return $h;
}
$chk = array('base' => '', 'imaging' => '', 'server' => '');
if(! $baseaccess && $serveraccess)
$chk['server'] = 'checked';
elseif($forimaging)
$chk['imaging'] = 'checked';
else
$chk['base'] = 'checked';
$showradios = 0;
if($baseaccess + $imagingaccess + $serveraccess > 1)
$showradios = 1;
if($showradios)
$h .= _("Reservation type:") . "
\n";
$h .= "
\n";
$h .= "" . _("Basic Reservation");
$h .= " \n";
$h .= "
\n";
$h .= "" . _("Imaging Reservation");
$h .= " \n";
$h .= "
\n";
$h .= "" . _("Server Reservation");
$h .= " \n";
if($showradios)
$h .= "
\n";
$h .= "
\n";
$h .= "
\n";
$h .= _("Profile:") . " ";
$h .= " \n";
$h .= "\n";
$h .= "" . _("Description:") . " \n";
$h .= "
\n";
$h .= " \n";
$cont = addContinuationsEntry('AJserverProfileData', array('mode' => 'checkout'));
$h .= "\n";
$h .= " " . _("Apply Profile") . "\n";
$h .= " \n";
$h .= " ";
$h .= " \n";
$h .= " \n";
$h .= " \n"; # deployprofileslist
$h .= "
\n";
# directions
$h .= "
";
$h .= _("Please select the environment you want to use from the list:");
$h .= " \n";
# javascript for max duration and image store
$maxTimes = getUserMaxTimes();
$maximaging = $maxTimes['initial'];
if($imagingaccess && $maxTimes['initial'] < MAXINITIALIMAGINGTIME)
$maximaging = MAXINITIALIMAGINGTIME;
$h .= "\n";
$cdata['maxinitial'] = $maxTimes['initial'];
# image
$h .= "
";
$h .= resourceStore('image', 1, 'detailimagestore');
$h .= "
\n";
$h .= " \n";
$h .= " \n";
$imagenotes = getImageNotes($imageid);
$desc = '';
if(! preg_match('/^\s*$/', $imagenotes['description'])) {
$desc = preg_replace("/\n/", '
', $imagenotes['description']);
$desc = preg_replace("/\r/", '', $desc);
$desc = "
" . _("Image Description") . " :
\n"
. "$desc
\n";
}
$h .= "
$desc
\n";
# name
$h .= "
\n"; # newreslabelfields
$h .= "
";
$h .= _("When would you like to use the environment?");
$h .= " \n";
$h .= "
";
$h .= _("When would you like to start the imaging process?");
$h .= " \n";
$h .= "
";
$h .= _("When would you like to deploy the server?");
$h .= " ";
$h .= "
\n";
# duration radios
$h .= " ";
$h .= "
\n";
$h .= "
" . _("Now") . " \n";
$h .= " ";
$h .= "
\n";
$h .= "
" . _("Later:") . " \n";
# limited start
$days = getReserveDayData();
$h .= "
\n";
$h .= selectInputHTML('day', $days, 'deploystartday', "onChange='setStartLater();'");
$h .= " " . _("At") . " \n";
$tmpArr = array();
for($i = 1; $i < 13; $i++)
$tmpArr[$i] = $i;
$timestamp = unixFloor15(time() + 4500);
$timeArr = explode(',', date('g,i,a', $timestamp));
$h .= selectInputHTML('hour', $tmpArr, 'deployhour', "onChange='setStartLater();'", $timeArr[0]);
$minutes = array("0" => "00", "15" => "15", "30" => "30", "45" => "45");
$h .= selectInputHTML('minute', $minutes, 'deploymin', "onChange='setStartLater();'", $timeArr[1]);
$h .= selectInputHTML('meridian', array("am" => "a.m.", "pm" => "p.m."),
'deploymeridian', "onChange='setStartLater();'", $timeArr[2]);
$h .= " \n";
# any start
$h .= "
\n";
$h .= "
\n";
$h .= "
\n";
$h .= " \n";
$h .= "
(" . date('T') . ") \n";
$h .= "
\n";
# ending by duration
$h .= "
\n";
$h .= " ";
if($openend) {
$h .= " \n";
$h .= "";
}
$h .= _("Duration");
if($openend)
$h .= ": \n";
$maxtimes = getUserMaxTimes();
if($imaging && $maxtimes['initial'] < 720) # make sure at least 12 hours available for imaging reservations
$maxtimes['initial'] = 720;
$lengths = getReservationLengths($maxtimes['initial']);
$h .= selectInputHTML('length', $lengths, 'reqlength',
"onChange='updateWaitTime(0); setEndDuration(); durationChange();'", 60);
$h .= " \n";
# ending is indefinite
$h .= "
\n";
if($serveraccess) {
$h .= " ";
$h .= " \n";
$h .= "" . _("Indefinite") . " \n";
}
$h .= " \n";
# ending by date/time
$h .= "
\n";
$h .= "" . _("At this time:") . " \n";
$h .= "
\n";
$h .= "
\n";
$h .= "(" . date('T') . ") \n";
}
$h .= " \n";
$h .= "
\n";
$h .= "
\n";
$h .= "
\n"; # deployprofilediv
$h .= "
\n";
$h .= "
\n";
$h .= "
\n";
/*$h .= " \n";
$h .= " " . _("Configure System") . "\n";
$h .= " \n";
$h .= " \n";*/
$h .= dijitButton('newResDlgBtn', _("Create Reservation"), "submitNewReservation();");
$h .= dijitButton('', _("Cancel"), "dijit.byId('newResDlg').hide();");
$h .= "
\n";
$cont = addContinuationsEntry('AJnewRequest', $cdata, SECINDAY);
$h .= "
\n";
if($serveraccess) {
$cont = addContinuationsEntry('AJfetchRouterDNS');
$h .= "
\n";
}
$cont = addContinuationsEntry('AJupdateWaitTime', $cdata);
$h .= "
\n";
$h .= "
\n";
return $h;
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJupdateWaitTime()
///
/// \brief generates html update for ajax call to display estimated wait time
/// for current selection on new reservation page
///
////////////////////////////////////////////////////////////////////////////////
function AJupdateWaitTime() {
global $user, $requestInfo;
$imageid = processInputVar('imageid', ARG_NUMERIC);
$baseaccess = getContinuationVar('baseaccess');
$imagingaccess = getContinuationVar('imagingaccess');
$serveraccess = getContinuationVar('serveraccess');
$openend = getContinuationVar('openend');
$imaging = getContinuationVar('imaging');
$type = processInputVar('type', ARG_STRING);
$desconly = processInputVar('desconly', ARG_NUMERIC, 0);
# process imageid
$resources = getUserResources(array("imageAdmin", "imageCheckOut"));
$validImageids = array_keys($resources['image']);
if($type == 'server') {
$extraimages = getServerProfileImages($user['id']);
$validImageids = array_merge($validImageids, array_keys($extraimages));
}
if(! in_array($imageid, $validImageids))
return;
if($desconly) {
printImageDescription($imageid);
return;
}
# process type
if(! preg_match('/^basic|imaging|server$/', $type))
return;
if(($type == 'basic' && ! $baseaccess) ||
($type == 'imaging' && ! $imagingaccess) ||
($type == 'server' && ! $serveraccess))
return;
# process start
$start = processInputVar('start', ARG_NUMERIC);
$now = time();
if($start == 0) {
$start = unixFloor15($now);
}
else {
if($start < $now)
$start = unixFloor15($now);
if($type == 'basic' || $type == 'imaging') {
# compute maxstart based on 11:45 pm on start day
$tmp = $now + DAYSAHEAD * SECINDAY;
$maxstart = mktime(23, 45, 0, date('n', $tmp), date('j', $tmp), date('Y', $tmp));
if($start > $maxstart)
return;
}
}
# process length/end
$ending = processInputVar('ending', ARG_STRING);
if(! preg_match('/^indefinite|endat|duration$/', $ending))
return;
if($ending == 'indefinite') {
$end = datetimeToUnix('2038-01-01 00:00:00');
}
elseif($ending == 'endat') {
$end = processInputVar('end', ARG_NUMERIC);
}
elseif($ending == 'duration') {
$length = processInputVar('duration', ARG_NUMERIC);
$maxinitial = getContinuationVar('maxinitial');
if(($type == 'basic' || $type == 'imaging') && ! $openend) {
if($length > $maxinitial)
$length = $maxinitial;
}
$end = $start + $length * 60;
}
if($end < $start) {
print "dojo.byId('deployerr').innerHTML = '";
print _("The end time must be later than the start time.") . "';";
print "dojo.removeClass('deployerr', 'hidden');";
return;
}
if($start < $now)
$end += 15 * 60;
# process fixed IP
$fixedIP = processInputVar('fixedIP', ARG_STRING, '');
if($type == 'server' && $fixedIP != '') {
if(! validateIPv4addr($fixedIP)) {
print "dojo.byId('deployerr').innerHTML = '";
print _("Invalid IP address specified.") . "';";
print "dojo.removeClass('deployerr', 'hidden');";
return;
}
$mappedmns = getMnsFromImage($imageid);
$mnnets = checkAvailableNetworks($fixedIP);
$intersect = array_intersect($mappedmns, $mnnets);
if(empty($intersect)) {
print "dojo.byId('deployerr').innerHTML = '";
print _("There are no management nodes that can deploy the selected image with the specified IP address.") . "';";
print "dojo.removeClass('deployerr', 'hidden');";
return;
}
}
printImageDescription($imageid);
$images = getImages();
$imagerevisionid = getProductionRevisionid($imageid);
# TODO initially, this is a hack where we munge the datastructure
# finishconfigs
/*if($type == 'server') {
$tmp = getConfigClusters($imageid, 1);
if(count($tmp)) {
$subimages = array();
foreach($tmp as $cluster) {
for($i = 0; $i < $cluster['maxinstance']; $i++)
$subimages[] = $cluster['childimageid'];
}
$images[$imageid]['subimages'] = $subimages;
if($images[$imageid]['imagemetaid'] == NULL)
$images[$imageid]['imagemetaid'] = 1;
}
elseif($images[$imageid]['imagemetaid'] != NULL &&
count($images[$imageid]['subimages'])) {
$images[$imageid]['subimages'] = array();
}
}*/
# check for exceeding max overlaps
$max = getMaxOverlap($user['id']);
if(checkOverlap($start, $end, $max)) {
print "dojo.byId('deployerr').innerHTML = '";
print _("The selected time overlaps with another reservation you have.");
print " ";
if($max == 0)
print _("You cannot have any overlapping reservations.");
else
printf(_("You can have up to %d overlapping reservations."), $max);
print "'; dojo.removeClass('deployerr', 'hidden');";
return;
}
$rc = isAvailable($images, $imageid, $imagerevisionid, $start, $end, 0, 0, 0, 0, $imaging, $fixedIP);
if($rc < 1) {
$cdata = array('now' => 0,
'start' => $start,
'end' => $end,
'server' => 0,
'imageid' => $imageid);
if($start < $now)
$cdata['now'] = 1;
$cont = addContinuationsEntry('AJshowRequestSuggestedTimes', $cdata);
if(array_key_exists('subimages', $images[$imageid]) &&
count($images[$imageid]['subimages'])) {
print "dojo.byId('suggestcont').value = 'cluster';";
print "dijit.byId('newResDlgBtn').set('disabled', true);";
}
else
print "dojo.byId('suggestcont').value = '$cont';";
print "if(dijit.byId('newResDlgBtn')) {";
print "if(dijit.byId('newResDlgBtn').get('label') != _('View Available Times')) ";
print "resbtntxt = dijit.byId('newResDlgBtn').get('label'); ";
print "dijit.byId('newResDlgBtn').set('label', _('View Available Times'));";
print "}";
}
if($rc < 1) {
print "dojo.removeClass('deployerr', 'hidden');";
print "showSuggestedTimes();";
print "dojo.byId('deployerr').innerHTML = '";
}
else {
print "dojo.removeClass('waittime', 'hidden');";
print "dojo.addClass('deployerr', 'hidden');";
print "dojo.byId('waittime').innerHTML = '";
}
if($rc == -2)
print _("Selection not currently available due to scheduled system downtime for maintenance");
elseif($rc == -3)
print _("IP address not available for selected time");
elseif($rc == -4)
print _("IP address not available");
elseif($rc < 1)
if(array_key_exists('subimages', $images[$imageid]) &&
count($images[$imageid]['subimages']))
print _("Selection not currently available. Times cannot be suggested for cluster reservations.");
else
print _("Selection not currently available");
elseif(array_key_exists(0, $requestInfo['loaded']) &&
$requestInfo['loaded'][0]) {
print _("Estimated load time:");
if($start < $now) {
print " < ";
print _("1 minute");
}
else
print ' ' . _("Ready at start of reservation");
}
else {
print _("Estimated load time:");
$loadtime = getImageLoadEstimate($imageid);
if($start < $now) {
$loadtime = (int)($loadtime / 60);
print " < ";
if($loadtime == 0)
print $images[$imageid]['reloadtime'];
else
printf("%2.0f", $loadtime + 1);
print " " . _("minutes");
}
elseif($loadtime != 0 && ($start - $now < $loadtime))
print ' ' . _("Ready at") . date(" g:i a", ($now + $loadtime));
else
print ' ' . _("Ready at start of reservation");
}
print "';";
if($requestInfo['ipwarning']) {
print "dojo.removeClass('deployerr', 'hidden');";
print "dojo.byId('deployerr').innerHTML = '";
$h = _("WARNING: Current conflict with specified IP address. If the conflict is not resolved by the start of your reservation, the reservation will fail.");
print preg_replace("/(.{1,68}([ ]|$))/", '\1 ', $h);
print " ';";
}
if($rc > 0)
print "resetDeployBtnLabel();";
print "resizeRecenterDijitDialog('newResDlg');";
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn printImageDescription($imageid)
///
/// \param $imageid - id of image
///
/// \brief prints the image description
///
////////////////////////////////////////////////////////////////////////////////
function printImageDescription($imageid) {
$imagenotes = getImageNotes($imageid);
if(! preg_match('/^\s*$/', $imagenotes['description'])) {
$desc = preg_replace("/\n/", ' ', $imagenotes['description']);
$desc = preg_replace("/\r/", '', $desc);
$desc = preg_replace("/'/", ''', $desc);
$desc = preg_replace("/(.{1,60}([ \n]|$))/", '\1 ', $desc);
print "dojo.byId('imgdesc').innerHTML = '";
print _("Image Description") . " : ";
print "$desc '; ";
}
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJshowRequestSuggestedTimes()
///
/// \brief builds html to display list of available times the selected image
/// can be used
///
////////////////////////////////////////////////////////////////////////////////
function AJshowRequestSuggestedTimes() {
global $user;
# TODO remove slots with overlapping IP address
$data = array();
$start = getContinuationVar('start');
$end = getContinuationVar('end');
$imageid = getContinuationVar('imageid');
$now = getContinuationVar('now');
$server = getContinuationVar('server');
$ip = getContinuationVar('ip', '');
$mac = getContinuationVar('mac', '');
$requestid = getContinuationVar('requestid', '');
$extendonly = getContinuationVar('extendonly', 0);
if($now && $start < time()) {
# $start should have been decreased by 15 minutes
$start = $start + 900;
}
if($server)
$slots = findAvailableTimes($start, $end, $imageid, $user['id'], 0,
$requestid, $extendonly, $ip, $mac);
else
$slots = findAvailableTimes($start, $end, $imageid, $user['id'], 1,
$requestid, $extendonly);
$data['status'] = 'success';
if($requestid != '') {
$reqdata = getRequestInfo($requestid, 0);
if(is_null($reqdata)) {
$data['status'] = 'resgone';
sendJSON($data);
return;
}
}
if(empty($slots)) {
$h = _("There are no available times that the selected image can be used.");
$data['html'] = preg_replace("/(.{1,33}([ \n]|$))/", '\1 ', $h) . " ";
$data['status'] = 'error';
sendJSON($data);
return;
}
$data['data'] = $slots;
$html = '';
$html .= "";
if($extendonly) {
$slot = array_pop($slots);
$maxextend = $slot['duration'] - (datetimeToUnix($reqdata['end']) - datetimeToUnix($reqdata['start']));
if($maxextend < 900) {
$h = _('This reservation can no longer be extended due to a reservation immediately following yours.');
$data['html'] = preg_replace("/(.{1,50}([ \n]|$))/", '\1 ', $h) . " ";
$data['status'] = 'noextend';
sendJSON($data);
return;
}
$html .= "";
$html .= " ";
$html .= "" . _("End Time") . " ";
$html .= "" . _("Extend By") . " ";
$html .= " ";
$cnt = 0;
$e = datetimeToUnix($reqdata['end']);
$slots = array();
for($cnt = 0, $amount = 900, $e = datetimeToUnix($reqdata['end']) + 900;
$cnt < 15 && $amount <= $maxextend && $amount < 7200;
$cnt++, $amount += 900, $e += 900) {
$end = strftime('%x %l:%M %P', $e);
$extenstion = getReservationExtenstion($amount / 60);
if($cnt % 2)
$html .= "";
else
$html .= " ";
$html .= " ";
$html .= "$end ";
$html .= "";
$html .= "$extenstion ";
$slots[$e] = array('duration' => $amount,
'startts' => $slot['startts']);
}
for(; $cnt < 15 && $amount <= $maxextend;
$cnt++, $amount += 3600, $e += 3600) {
$end = strftime('%x %l:%M %P', $e);
$extenstion = getReservationExtenstion($amount / 60);
if($cnt % 2)
$html .= "";
else
$html .= " ";
$html .= " ";
$html .= "$end ";
$html .= "";
$html .= "$extenstion ";
$slots[$e] = array('duration' => $amount,
'startts' => $slot['startts']);
}
$data['data'] = $slots;
}
else {
$html .= "";
$html .= " ";
$html .= "" . _("Start Time") . " ";
$html .= "" . _("Duration") . " ";
if(checkUserHasPerm('View Debug Information'))
$html .= "" . _("Comp. ID") . " ";
$html .= " ";
$cnt = 0;
foreach($slots as $key => $slot) {
$cnt++;
$start = strftime('%x %l:%M %P', $slot['startts']);
if(($slot['startts'] - time()) + $slot['startts'] + $slot['duration'] >= 2114402400)
# end time >= 2037-01-01 00:00:00
$duration = 'indefinite';
else
$duration = getReservationLength($slot['duration'] / 60);
if($cnt % 2)
$html .= "";
else
$html .= " ";
$html .= " ";
$html .= "$start ";
$html .= "";
$html .= "$duration ";
if(checkUserHasPerm('View Debug Information'))
$html .= "{$slot['compid']} ";
$html .= " ";
if($cnt >= 15)
break;
}
}
$html .= "
";
$data['html'] = $html;
$cdata = array('slots' => $slots);
sendJSON($data);
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJconfigSystem()
///
/// \brief generates data for setting up configs for server reservation
///
////////////////////////////////////////////////////////////////////////////////
function AJconfigSystem() {
$imageid = processInputVar('imageid', ARG_NUMERIC);
$resources = getUserResources(array("imageAdmin", "imageCheckOut"));
$validImageids = array_keys($resources['image']);
if(! in_array($imageid, $validImageids)) {
sendJSON(array('status' => 'noaccess'));
return;
}
$configs = getMappedConfigs($imageid);
$configs = array_values($configs);
$configvars = getImageConfigVariables($configs);
$configvars = array_values($configvars);
$data = array('status' => 'success',
'configs' => $configs,
'variables' => $configvars,
'cluster' => 0);
$subs = getConfigClusters($imageid);
if(! empty($subs)) {
$data['cluster'] = 1;
$data['subimages'] = $subs;
}
sendJSON($data);
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJnewRequest()
///
/// \brief handles submitting a new reservation
///
////////////////////////////////////////////////////////////////////////////////
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 _("The selected time overlaps with another reservation you have.");
print " ";
if($max == 0)
print _("You cannot have any overlapping reservations.");
else
printf(_("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 = _("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 = _("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 = _("The time you requested overlaps with a maintenance window.");
$data = array('err' => 1,
'errmsg' => $msg);
sendJSON($data);
return;
}
elseif($availablerc == -1) {
cleanSemaphore();
$msg = _("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);
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn saveRequestConfigs($reqid, $imageid, $configs, $vars)
///
/// \param $reqid - id of request
/// \param $imageid - id of image of reservation
/// \param $configs - array of config data
/// \param $vars - array of config variable data
///
/// \brief creates config entries for reservation
///
////////////////////////////////////////////////////////////////////////////////
function saveRequestConfigs($reqid, $imageid, $configs, $vars) {
global $user;
$query = "SELECT id, "
. "imageid "
. "FROM reservation "
. "WHERE requestid = $reqid "
. "ORDER BY id";
$qh = doQuery($query);
$resids = array();
while($row = mysql_fetch_assoc($qh)) {
if(! array_key_exists($row['imageid'], $resids))
$resids[$row['imageid']] = array();
$resids[$row['imageid']][] = $row['id'];
}
$bysubimage = array(0 => array('imageid' => $imageid));
foreach($configs as $id => $cfg) {
if(preg_match('|^([0-9]+)/([0-9]+)-([0-9]+)$|', $id, $keys)) {
$bysubimage[$keys[1]][$keys[2]] = $cfg['configid'];
$bysubimage[$keys[3]]['imageid'] = $cfg['imageid'];
}
elseif(preg_match('|^([0-9]+)/([-0-9]+)$|', $id, $keys)) {
$bysubimage[$keys[1]][$keys[2]] = $cfg['configid'];
}
}
$qbase = "INSERT INTO configinstance "
. "(reservationid, "
. "configid, "
. "configmapid, "
. "configinstancestatusid) "
. "VALUES ";
$qbase2 = "INSERT INTO configinstancevariable "
. "(configinstanceid, "
. "configvariableid, "
. "value) "
. "VALUES ";
$qbase3 = "INSERT INTO configmap "
. "(configid, "
. "configmaptypeid, "
. "subid, "
. "affiliationid, "
. "disabled, "
. "configstageid) "
. "VALUES ";
$residmaps = array();
foreach($bysubimage as $cfgsubimgid => $data) {
$resid = array_pop($resids[$data['imageid']]);
unset($data['imageid']);
foreach($data as $mapid => $cfgid) {
$insmapid = $mapid;
if($mapid < 0) {
$query = $qbase3;
$query .= "($cfgid, ";
$query .= "(SELECT id FROM configmaptype WHERE name = 'reservation'), ";
$query .= "$resid, {$user['affiliationid']}, 0, ";
$query .= $configs["$cfgsubimgid/$mapid"]['configstageid'] . ")";
doQuery($query);
$insmapid = dbLastInsertID();
}
$query = $qbase;
$query .= "($resid, $cfgid, $insmapid, 1)";
doQuery($query);
$instid = dbLastInsertID();
if(array_key_exists("$cfgsubimgid/$mapid", $vars)) {
$sets = array();
foreach($vars["$cfgsubimgid/$mapid"] as $varid => $varval) {
$_val = mysql_real_escape_string($varval['value']);
$sets[] = "($instid, $varid, '$_val')";
}
$query = $qbase2 . implode(',', $sets);
doQuery($query);
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn newReservationConfigHTML()
///
/// \return html
///
/// \brief generates HTML for setting up configs for a server reservation
///
////////////////////////////////////////////////////////////////////////////////
function newReservationConfigHTML() {
$h = '';
$h = "\n";
$h .= "
\n";
# cluster tree
$h .= "
\n";
$h .= "
Cluster :
\n";
$h .= "(select an image to configure any associated configs)
\n";
$h .= "
\n";
# TODO edit CSS to set icons for tree nodes
$h .= " \n";
$h .= "
\n";
$h .= "
\n";
$h .= "
\n"; # clusterdiv
# configs
$h .= "Add config for this reservation:
\n";
$h .= resourceStore('config', 1, 'configdetailstore', 1);
$h .= "
\n";
$h .= " \n";
$h .= "
\n";
$h .= " " . _("Add") . "\n";
$h .= " \n";
$h .= " \n";
$h .= "
\n";
$h .= "\n";
$h .= "\n"; # list of configs
$h .= "Configs mapped to system: \n";
$h .= "\n";
$h .= "
\n";
$h .= "\n";
$h .= "\n";
$h .= " \n";
$h .= " \n";
$h .= " \n";
$h .= "
\n";
$h .= "
\n";
$h .= " \n"; # end list of configs
$h .= "\n"; # config variables
$h .= _("Type:") . " \n";
$h .= _("Apply this config:") . " \n";
$h .= "\n";
$h .= "
\n";
$h .= "
" . _("View Config Data") . " \n";
$h .= "
\n";
$h .= "
\n";
# variables
$h .= "
\n";
$h .= _("Config variables:") . "
\n";
# select
$h .= "
\n";
# key
$h .= _("Key:") . "
\n";
$h .= _("Value:");
# bool
$h .= "
\n";
$h .= selectInputAutoDijitHTML('', array('true', 'false'), 'configvaluebool', 'onChange="saveSelectedConfigVar();"');
$h .= " \n";
# int
$h .= "
";
$h .= "\n";
# float
$h .= "
";
$h .= "\n";
# string
$h .= "
";
$h .= "\n";
# text
$h .= "
";
$h .= "
\n";
$h .= "
\n";
$h .= _("Required:") . "
\n";
$h .= "
\n"; # configvariablediv
$h .= "
\n"; # configdatadiv
$h .= " \n"; # end config variables
$h .= " \n";
$h .= "
\n";
$h .= "
\n";
$h .= "
\n";
$h .= " \n";
$h .= " " . _("Close") . "\n";
$h .= " \n";
$h .= " \n";
$h .= "
\n";
$h .= "
\n";
return $h;
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn detailStatusHTML($reqid)
///
/// \param $reqid - a request id
///
/// \return html text showing detailed status from computerloadlog for specified
/// request
///
/// \brief gathers information about the state flow for $reqid and formats it
/// nicely for a user to view
///
////////////////////////////////////////////////////////////////////////////////
function detailStatusHTML($reqid) {
$requests = getUserRequests("all");
$found = 0;
foreach($requests as $request) {
if($request['id'] == $reqid) {
$found = 1;
break;
}
}
if(! $found) {
$text = _("The selected reservation is no longer available. You can request a new reservation or select another one that is available.");
return $text;
}
if($request['currstateid'] == 11 ||
($request['currstateid'] == 12 && $request['laststateid'] == 11))
return "" .
_("The selected reservation has timed out and is no longer available.") .
" ";
if($request['imageid'] == $request['compimageid'])
$nowreq = 1;
else
$nowreq = 0;
$flow = getCompStateFlow($request['computerid']);
# cluster reservations not supported here yet
# info on reboots/reinstalls not available yet
if(empty($flow) ||
count($request['reservations']) > 0 ||
($request['currstateid'] == 14 && $request['laststateid'] == 26) ||
($request['currstateid'] == 14 && $request['laststateid'] == 24) ||
/*($request['currstateid'] == 14 && $request['laststateid'] == 27) ||*/
($request['currstateid'] == 14 && $request['laststateid'] == 28)) {
$noinfo = _("No detailed loading information is available for this reservation.");
return $noinfo;
}
$logdata = getCompLoadLog($request['resid']);
# determine an estimated load time for the image
$imgLoadTime = getImageLoadEstimate($request['imageid']);
if($imgLoadTime == 0) {
$images = getImages(0, $request['imageid']);
$imgLoadTime = $images[$request['imageid']]['reloadtime'] * 60;
}
$time = 0;
$now = time();
$text = "";
$text .= "";
$text .= " ";
$text .= " ";
$text .= " ";
$text .= " ";
$text .= "";
$text .= " " . _("State") . " ";
$text .= "Est/Act " . _("Time") . " ";
$text .= "Total " . _("Time") . " ";
$text .= " ";
$slash = "/ ";
$total = 0;
$id = "";
$last = array();
$logstateids = array();
$skippedstates = array();
# loop through all states in the log data
foreach($logdata as $data) {
# keep track of the states in the log data
array_push($logstateids, $data['loadstateid']);
# keep track of any skipped states
if(! empty($last) &&
$last['loadstateid'] != $flow['repeatid'] &&
$data['loadstateid'] != $flow['data'][$last['loadstateid']]['nextstateid']) {
array_push($skippedstates, $flow['data'][$last['loadstateid']]['nextstateid']);
}
// if we reach a repeat state, include a message about having to go back
if($data['loadstateid'] == $flow['repeatid']) {
if(empty($id))
return $noinfo;
$text .= "";
$text .= " " . _("problem at state");
$text .= " \"{$flow['data'][$id]['nextstate']}\"";
$query = "SELECT additionalinfo "
. "FROM computerloadlog "
. "WHERE loadstateid = {$flow['repeatid']} AND "
. "reservationid = {$request['resid']} AND "
. "timestamp = '" . unixToDatetime($data['ts']) . "'";
$qh = doQuery($query, 101);
if($row = mysql_fetch_assoc($qh)) {
$reason = $row['additionalinfo'];
$text .= " " . _("retrying at state") . " \"$reason\"";
}
$text .= " ";
$total += $data['time'];
$last = $data;
continue;
}
$id = $data['loadstateid'];
// if in post config state, compute estimated time for the state
if($flow['data'][$id]['statename'] == 'loadimagecomplete') {
$addtime = 0;
foreach($skippedstates as $stateid)
$addtime += $flow['data'][$stateid]['statetime'];
# this state's time is (avg image load time - all other states time +
# state time for any skipped states)
$tmp = $imgLoadTime - $flow['totaltime'] + $addtime;
if($tmp < 0)
$flow['data'][$id]['statetime'] = 0;
else
$flow['data'][$id]['statetime'] = $tmp;
}
$total += $data['time'];
$text .= "";
$text .= "";
$text .= _($flow['data'][$id]['state']) . "($id) ";
$text .= "";
$text .= secToMinSec($flow['data'][$id]['statetime']) . $slash;
$text .= secToMinSec($data['time']) . " ";
$text .= "";
$text .= secToMinSec($total) . " ";
$text .= " ";
$last = $data;
}
# $id will be set if there was log data, use the first state in the flow
// if it isn't set
if(! empty($id))
$id = $flow['nextstates'][$id];
else
$id = $flow['stateids'][0];
# determine any skipped states
$matchingstates = array();
foreach($flow['stateids'] as $stateid) {
if($stateid == $id)
break;
array_push($matchingstates, $stateid);
}
$skippedstates = array_diff($matchingstates, $logstateids);
$addtime = 0;
foreach($skippedstates as $stateid)
$addtime += $flow['data'][$stateid]['statetime'];
$first = 1;
$count = 0;
# loop through the states in the flow that haven't been reached yet
# $count is included to protect against an infinite loop
while(! is_null($id) && $count < 100) {
$count++;
// if in post config state, compute estimated time for the state
if($flow['data'][$id]['statename'] == 'loadimagecomplete') {
# this state's time is (avg image load time - all other states time +
# state time for any skipped states)
$tmp = $imgLoadTime - $flow['totaltime'] + $addtime;
if($tmp < 0)
$flow['data'][$id]['statetime'] = 0;
else
$flow['data'][$id]['statetime'] = $tmp;
}
// if first time through this loop, this is the current state
if($first) {
// if request has failed, it was during this state, get reason
if($request['currstateid'] == 5) {
$query = "SELECT additionalInfo, "
. "UNIX_TIMESTAMP(timestamp) AS ts "
. "FROM computerloadlog "
. "WHERE loadstateid = (SELECT id "
. "FROM computerloadstate "
. "WHERE loadstatename = 'failed') AND "
. "reservationid = {$request['resid']} "
. "ORDER BY id "
. "LIMIT 1";
$qh = doQuery($query, 101);
if($row = mysql_fetch_assoc($qh)) {
$reason = $row['additionalInfo'];
if(! empty($data))
$currtime = $row['ts'] - $data['ts'];
else
$currtime = $row['ts'] -
datetimeToUnix($request['daterequested']);
}
else {
$text = _("No detailed information is available for this reservation.");
return $text;
}
$text .= "";
$text .= "";
$text .= _($flow['data'][$id]['state']) . "($id) ";
$text .= "";
$text .= secToMinSec($flow['data'][$id]['statetime']);
$text .= $slash . secToMinSec($currtime) . " ";
$text .= "";
$text .= secToMinSec($total + $currtime) . " ";
$text .= " ";
$text .= "
";
if(strlen($reason))
$text .= "" . _("failed:") . " $reason ";
return $text;
}
# otherwise add text about current state
else {
if(! empty($data))
$currtime = $now - $data['ts'];
else
$currtime = $now - datetimeToUnix($request['daterequested']);
$text .= " ";
$text .= _($flow['data'][$id]['state']) . "($id) ";
$text .= "";
$text .= secToMinSec($flow['data'][$id]['statetime']);
$text .= $slash . secToMinSec($currtime) . " ";
$text .= "";
$text .= secToMinSec($total + $currtime) . " ";
$text .= "";
$first = 0;
}
}
# add text about future states
else {
$text .= "";
$text .= _($flow['data'][$id]['state']) . "($id) ";
$text .= "";
$text .= secToMinSec($flow['data'][$id]['statetime']) . " ";
$text .= " ";
$text .= "";
}
$id = $flow['nextstates'][$id];
}
$text .= "";
return $text;
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn viewRequestInfo()
///
/// \brief prints a page with information about a specific request
///
////////////////////////////////////////////////////////////////////////////////
function viewRequestInfo() {
$requestid = getContinuationVar('requestid');
$request = getRequestInfo($requestid);
if($request['forimaging'] || $request['stateid'] == 18 || $request['laststateid'] == 18)
$reservation = $request['reservations'][0];
else {
foreach($request["reservations"] as $res) {
if($res["forcheckout"]) {
$reservation = $res;
break;
}
}
}
$states = getStates();
$userinfo = getUserInfo($request["userid"], 1, 1);
print "\n";
print "
View Reservation \n";
print "
\n";
print " \n";
print " User: \n";
print " " . $userinfo["unityid"] . " \n";
print " \n";
print " \n";
print " Start Time: \n";
if(datetimeToUnix($request["start"]) <
datetimeToUnix($request["daterequested"])) {
print " " . prettyDatetime($request["daterequested"]) . " \n";
}
else {
print " " . prettyDatetime($request["start"]) . " \n";
}
print " \n";
print " \n";
print " End Time: \n";
print " " . prettyDatetime($request["end"]) . " \n";
print " \n";
print " \n";
print " Request Time: \n";
print " " . prettyDatetime($request["daterequested"]) . " \n";
print " \n";
print " \n";
print " Last Modified: \n";
if(! empty($request["datemodified"])) {
print " " . prettyDatetime($request["datemodified"]) . " \n";
}
else {
print " Never Modified \n";
}
print " \n";
print " \n";
print " Current State: \n";
print " " . $states[$request["stateid"]] . " \n";
print " \n";
print " \n";
print " Last State: \n";
print " ";
if($request["laststateid"]) {
print $states[$request["laststateid"]];
}
else {
print "None";
}
print " \n";
print " \n";
print " \n";
print " Image: \n";
print " {$reservation['prettyimage']} \n";
print " \n";
print " \n";
print " Hostname: \n";
print " {$request['reservations'][0]["hostname"]} \n";
print " \n";
print " \n";
print " IP Address: \n";
print " {$request['reservations'][0]["reservedIP"]} \n";
print " \n";
print "
\n";
if(count($request['reservations'] > 1)) {
array_shift($request['reservations']);
print "Subimages:
\n";
print "
\n";
foreach($request["reservations"] as $res) {
print " \n";
print " Image: \n";
print " {$res["prettyimage"]} \n";
print " \n";
print " \n";
print " Hostname: \n";
print " {$res["hostname"]} \n";
print " \n";
print " \n";
print " IP Address: \n";
print " {$res["reservedIP"]} \n";
print " \n";
}
print "
\n";
}
print "
\n";
print " \n";
/*print " \n";
print " \n";
print " \n";*/
print " \n";
$cdata = array('requestid' => $requestid,
'notbyowner' => 1,
'ttdata' => getContinuationVar('ttdata'),
'fromtimetable' => 1);
$cont = addContinuationsEntry('AJconfirmDeleteRequest', $cdata, SECINDAY);
print " \n";
print " " . _("Delete Reservation") . "\n";
print " \n";
print " \n";
print " \n";
print " \n";
print "
\n";
print "
\n";
print "\n";
print "
\n";
print "
\n";
print "
\n";
print "
\n";
print " \n";
print " " . _("Delete Reservation") . "\n";
print " \n";
print " \n";
print " \n";
print " " . _("Cancel") . "\n";
print " \n";
print " \n";
print "
\n";
print "
\n";
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJeditRequest()
///
/// \brief prints a page for a user to edit a previous request
///
////////////////////////////////////////////////////////////////////////////////
function AJeditRequest() {
global $submitErr, $user;
$requestid = getContinuationVar('requestid', 0);
$request = getRequestInfo($requestid, 1);
# check to see if reservation exists
if(is_null($request) || $request['stateid'] == 11 || $request['stateid'] == 12 ||
($request['stateid'] == 14 &&
($request['laststateid'] == 11 || $request['laststateid'] == 12))) {
sendJSON(array('status' => 'resgone'));
return;
}
$unixstart = datetimeToUnix($request["start"]);
$unixend = datetimeToUnix($request["end"]);
$duration = $unixend - $unixstart;
$now = time();
$maxtimes = getUserMaxTimes();
$groupid = getUserGroupID('Specify End Time', 1);
$members = getUserGroupMembers($groupid);
if(array_key_exists($user['id'], $members) || $request['serverrequest'])
$openend = 1;
else
$openend = 0;
$groupid = getUserGroupID('Allow No User Check', 1);
$members = getUserGroupMembers($groupid);
if(array_key_exists($user['id'], $members))
$nousercheck = 1;
else
$nousercheck = 0;
$h = '';
# determine the current total length of the reservation
$reslen = ($unixend - unixFloor15($unixstart)) / 60;
$timeval = getdate($unixstart);
if(($timeval["minutes"] % 15) != 0)
$reslen -= 15;
$cdata = array('requestid' => $requestid,
'openend' => $openend,
'nousercheck' => $nousercheck,
'modifystart' => 0,
'allowindefiniteend' => 0);
# generate HTML
if($request['serverrequest']) {
if(empty($request['servername']))
$request['servername'] = $request['reservations'][0]['prettyimage'];
$h .= _("Name") . ": ";
if($user['showallgroups'])
$groups = getUserGroups();
else
$groups = getUserGroups(0, $user['affiliationid']);
$h .= _("Admin User Group") . ": ";
$disabled = '';
if($request['stateid'] == 14 && $request['laststateid'] == 24)
$disabled = "disabled=\"true\"";
if(USEFILTERINGSELECT && count($groups) < FILTERINGSELECTTHRESHOLD) {
$h .= "";
}
else
$h .= "";
if(! empty($request['admingroupid']) &&
! array_key_exists($request['admingroupid'], $groups)) {
$id = $request['admingroupid'];
$name = getUserGroupName($request['admingroupid'], 1);
$h .= "$name \n";
}
$h .= "" . _("None") . " \n";
foreach($groups as $id => $group) {
if($id == $request['admingroupid'])
$h .= "{$group['name']} ";
else
$h .= "{$group['name']} ";
}
$h .= " ";
$h .= _("Access User Group") . ": ";
if(USEFILTERINGSELECT && count($groups) < FILTERINGSELECTTHRESHOLD) {
$h .= "";
}
else
$h .= "";
if(! empty($request['logingroupid']) &&
! array_key_exists($request['logingroupid'], $groups)) {
$id = $request['logingroupid'];
$name = getUserGroupName($request['logingroupid'], 1);
$h .= "$name \n";
}
$h .= "None \n";
foreach($groups as $id => $group) {
if($id == $request['logingroupid'])
$h .= "{$group['name']} ";
else
$h .= "{$group['name']} ";
}
$h .= " ";
}
elseif($nousercheck) {
$extra = array();
if($request['checkuser'] == 0)
$extra['checked'] = 'checked';
$h .= labeledFormItem('newnousercheck', _('Disable timeout for disconnected users'), 'check', '', '', '1', '', '', $extra);
$h .= " \n";
}
// if future, allow start to be modified
if($unixstart > $now) {
$cdata['modifystart'] = 1;
$txt = _("Modify reservation for") . " {$request['reservations'][0]['prettyimage']} ";
$txt .= _("starting") . " " . prettyDatetime($request["start"]) . ": ";
$h .= preg_replace("/(.{1,60}([ \n]|$))/", '\1 ', $txt);
$days = array();
$startday = date('l', $unixstart);
for($cur = time(), $end = $cur + DAYSAHEAD * SECINDAY;
$cur < $end;
$cur += SECINDAY) {
$index = date('Ymd', $cur);
$days[$index] = date('l', $cur);
}
$cdata['startdays'] = array_keys($days);
$h .= _("Start") . ": ";
foreach($days as $id => $name) {
if($name == $startday)
$h .= "$name ";
else
$h .= "$name ";
}
$h .= " ";
$h .= _(" At ");
$tmp = explode(' ' , $request['start']);
$stime = $tmp[1];
$h .= "
";
$h .= "(" . date('T') . ") ";
$durationmatch = 0;
if($request['serverrequest']) {
$cdata['allowindefiniteend'] = 1;
if($request['end'] == '2038-01-01 00:00:00') {
$h .= " ";
}
else {
$h .= " ";
}
$h .= "" . _("Indefinite Ending") . " ";
}
else {
$durationmin = $duration / 60;
if($request['forimaging'] && $maxtimes['initial'] < 720) # make sure at least 12 hours available for imaging reservations
$maxtimes['initial'] = 720;
$imgdata = getImages(1, $request['reservations'][0]['imageid']);
$maxlen = $imgdata[$request['reservations'][0]['imageid']]['maxinitialtime'];
if($maxlen > 0 && $maxlen < $maxtimes['initial'])
$maxtimes['initial'] = $maxlen;
$lengths = array();
if($maxtimes["initial"] >= 30) {
$lengths["30"] = "30 " . _("minutes");
if($durationmin == 30)
$durationmatch = 1;
}
if($maxtimes["initial"] >= 45) {
$lengths["45"] = "45 " . _("minutes");
if($durationmin == 45)
$durationmatch = 1;
}
if($maxtimes["initial"] >= 60) {
$lengths["60"] = "1 " . _("hour");
if($durationmin == 60)
$durationmatch = 1;
}
for($i = 120; $i <= $maxtimes["initial"] && $i < 2880; $i += 120) {
$lengths[$i] = $i / 60 . " " . _("hours");
if($durationmin == $i)
$durationmatch = 1;
}
for($i = 2880; $i <= $maxtimes["initial"]; $i += 1440) {
$lengths[$i] = $i / 1440 . " " . _("days");
if($durationmin == $i)
$durationmatch = 1;
}
if($openend) {
if($durationmatch) {
$h .= " ";
}
else {
$h .= " ";
}
$h .= "";
}
$h .= _("Duration") . ':';
if($openend)
$h .= " ";
$h .= "";
$cdata['lengths'] = array_keys($lengths);
foreach($lengths as $id => $name) {
if($id == $duration / 60)
$h .= "$name ";
else
$h .= "$name ";
}
$h .= " ";
}
if($openend) {
if($request['serverrequest'] && $request['end'] == '2038-01-01 00:00:00') {
$h .= " ";
$edate = '';
$etime = '';
}
else {
if(! $request['serverrequest'] && $durationmatch) {
$h .= " ";
}
else {
$h .= " ";
}
$tmp = explode(' ', $request['end']);
$edate = $tmp[0];
$etime = $tmp[1];
}
$h .= "";
$h .= _("End:");
$h .= " ";
$h .= "
";
$h .= "
";
$h .= "(" . date('T') . ") ";
}
$h .= " ";
$cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
$data = array('status' => 'modify',
'html' => $h,
'requestid' => $requestid,
'cont' => $cont);
sendJSON($data);
return;
}
# check for max time being reached
if($request['forimaging'] && $maxtimes['total'] < 720)
$maxcheck = 720;
else
$maxcheck = $maxtimes['total'];
if(! $openend && ($reslen >= $maxcheck)) {
$h = sprintf(_("You are only allowed to extend your reservation such that it has a total length of %s. "), minToHourMin($maxcheck));
$h .=_("This reservation already meets that length. Therefore, you are not allowed to extend your reservation any further.");
$h = preg_replace("/(.{1,60}([ \n]|$))/", '\1 ', $h) . " ";
sendJSON(array('status' => 'nomodify', 'html' => $h));
return;
}
// if started, only allow end to be modified
# check for following reservations
$timeToNext = timeToNextReservation($request);
# check for 30 minutes because need 15 minute buffer and min can
# extend by is 15 min
if($timeToNext < 30) {
$movedall = 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
$checkend = unixToDatetime($unixend + 900);
foreach($request["reservations"] as $res) {
if(! retryGetSemaphore(1, 1, $res['managementnodeid'], $res['computerid'], $request['start'], $checkend, $requestid)) {
$lockedall = 0;
break;
}
}
}
if($lockedall) {
foreach($request["reservations"] as $res) {
if(! moveReservationsOffComputer($res["computerid"], 1)) {
$movedall = 0;
break;
}
}
}
cleanSemaphore();
if(! $request['serverrequest'] && (! $movedall || ! $lockedall)) {
$msg = _("The computer you are using has another reservation immediately following yours. Therefore, you cannot extend your reservation because it would overlap with the next one.");
$h = preg_replace("/(.{1,60}( |$))/", '\1 ', $msg) . " ";
sendJSON(array('status' => 'nomodify', 'html' => $h));
return;
}
$timeToNext = timeToNextReservation($request);
}
if($timeToNext >= 15)
$timeToNext -= 15;
//if have time left to extend it, create an array of lengths based on maxextend that has a cap
# so we don't run into another reservation and we can't extend past the totalmax
$lengths = array();
if($request['forimaging'] && $maxtimes['total'] < 720) # make sure at least 12 hours available for imaging reservations
$maxtimes['total'] = 720;
if($timeToNext == -1) {
// there is no following reservation
if((($reslen + 15) <= $maxtimes["total"]) && (15 <= $maxtimes["extend"]))
$lengths["15"] = "15 " . _("minutes");
if((($reslen + 30) <= $maxtimes["total"]) && (30 <= $maxtimes["extend"]))
$lengths["30"] = "30 " . _("minutes");
if((($reslen + 45) <= $maxtimes["total"]) && (45 <= $maxtimes["extend"]))
$lengths["45"] = "45 " . _("minutes");
if((($reslen + 60) <= $maxtimes["total"]) && (60 <= $maxtimes["extend"]))
$lengths["60"] = _("1 hour");
for($i = 120; (($reslen + $i) <= $maxtimes["total"]) && ($i <= $maxtimes["extend"]) && $i < 2880; $i += 120)
$lengths[$i] = $i / 60 . " " . _("hours");
for($i = 2880; (($reslen + $i) <= $maxtimes["total"]) && ($i <= $maxtimes["extend"]); $i += 1440)
$lengths[$i] = $i / 1440 . " " . _("days");
}
else {
if($timeToNext >= 15 && (($reslen + 15) <= $maxtimes["total"]) && (15 <= $maxtimes["extend"]))
$lengths["15"] = "15 " . _("minutes");
if($timeToNext >= 30 && (($reslen + 30) <= $maxtimes["total"]) && (30 <= $maxtimes["extend"]))
$lengths["30"] = "30 " . _("minutes");
if($timeToNext >= 45 && (($reslen + 45) <= $maxtimes["total"]) && (45 <= $maxtimes["extend"]))
$lengths["45"] = "45 " . _("minutes");
if($timeToNext >= 60 && (($reslen + 60) <= $maxtimes["total"]) && (60 <= $maxtimes["extend"]))
$lengths["60"] = _("1 hour");
for($i = 120; ($i <= $timeToNext) && (($reslen + $i) <= $maxtimes["total"]) && ($i <= $maxtimes["extend"]) && $i < 2880; $i += 120)
$lengths[$i] = $i / 60 . " " . _("hours");
for($i = 2880; ($i <= $timeToNext) && (($reslen + $i) <= $maxtimes["total"]) && ($i <= $maxtimes["extend"]); $i += 1440)
$lengths[$i] = $i / 1440 . " " . _("days");
}
$cdata['lengths'] = array_keys($lengths);
if($timeToNext == -1 || $timeToNext >= $maxtimes['total']) {
if($openend) {
if(! empty($lengths)) {
$m = _("You can extend this reservation by a selected amount or change the end time to a specified date and time.");
$h .= preg_replace("/(.{1,55}([ \n]|$))/", '\1 ', $m) . " ";
}
else
$h .= _("Modify the end time for this reservation:") . " ";
}
else {
if($request['forimaging'] && $maxtimes['total'] < 720)
$maxcheck = 720;
else
$maxcheck = $maxtimes['total'];
$m = sprintf(_("You can extend this reservation by up to %s but not exceeding %s for your total reservation time."),
minToHourMin($maxtimes['extend']), minToHourMin($maxcheck));
$h .= preg_replace("/(.{1,60}([ \n]|$))/", '\1 ', $m) . " ";
}
}
elseif(! $request['serverrequest']) {
$m = sprintf(_("The computer you are using has another reservation following yours. Therefore, you can only extend this reservation for another %s."),
prettyLength($timeToNext));
$h .= preg_replace("/(.{1,60}( |$))/", '\1 ', $m);
}
# extend by drop down
# extend by specifying end time if $openend
$noindefinite = 0;
if($openend) {
if($request['serverrequest']) {
$cdata['allowindefiniteend'] = 1;
$endchecked = 0;
if($request['end'] == '2038-01-01 00:00:00') {
$h .= " ";
$h .= "" . _("Indefinite Ending") . " ";
$h .= " ";
}
else {
$h .= " ";
$h .= "";
$h .= _("Indefinite Ending") . " ";
$h .= " ";
$endchecked = 1;
}
$h .= "";
}
elseif(! empty($lengths)) {
$h .= " ";
$h .= "" . _("Extend reservation by:") . " ";
$h .= "";
foreach($lengths as $id => $name)
$h .= "$name ";
$h .= " ";
$h .= " ";
$h .= "";
}
if($request['serverrequest']) {
$h .= _("End:");
if($endchecked) {
$tmp = explode(' ', $request['end']);
$edate = $tmp[0];
$etime = $tmp[1];
}
else {
$edate = '';
$etime = '';
}
}
else {
$h .= _("Change ending to:");
$tmp = explode(' ', $request['end']);
$edate = $tmp[0];
$etime = $tmp[1];
}
if(! empty($lengths) || $request['serverrequest'])
$h .= " ";
$h .= "
";
$h .= "
";
$h .= "(" . date('T') . ") ";
$h .= " ";
if($request['serverrequest'] && $timeToNext == 0) {
$h .= "";
$m = "" . _("NOTE:") . " ";
$m .= _("Due to an upcoming reservation on the same computer, you cannot extend this reservation.");
$h .= preg_replace("/(.{1,80}([ \n]|$))/", '\1 ', $m);
$h .= " ";
$noindefinite = 1;
}
elseif($timeToNext > -1) {
$extend = $unixend + ($timeToNext * 60);
$extend = date('m/d/Y g:i A', $extend);
$h .= "";
$m = "" . _("NOTE:") . " ";
$m .= sprintf(_("Due to an upcoming reservation on the same computer, you can only extend this reservation until %s."),
$extend);
$h .= preg_replace("/(.{1,80}([ \n]|$))/", '\1 ', $m);
$h .= " ";
$cdata['maxextend'] = $extend;
$noindefinite = 1;
}
}
else {
$h .= _("Extend reservation by:");
$h .= "";
foreach($lengths as $id => $name)
$h .= "$name ";
$h .= " ";
}
$h .= " ";
$cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
$data = array('status' => 'modify',
'html' => $h,
'requestid' => $requestid,
'cont' => $cont);
if($noindefinite)
$data['status'] = 'noindefinite';
sendJSON($data);
return;
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJsubmitEditRequest()
///
/// \brief submits changes to a request and prints that it has been changed
///
////////////////////////////////////////////////////////////////////////////////
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' => _('The selected reservation no longer exists.') . ' ',
'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' => _('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' => _("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' => _("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' => _("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' => _("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' => _("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' => _("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 = _("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 ', $m) . " ";
}
else {
$m = sprintf(_("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 ', $m) . " ";
}
$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(_("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 ', $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 = _("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 ', $m) . " ";
$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 = _("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 ', $m) . " ";
$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 = _("The time period you have requested is not available. Please select a different time.");
$h .= preg_replace("/(.{1,55}([ \n]|$))/", '\1 ', $m) . " ";
$cdata = getContinuationVar();
$cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
$data['status'] = 'conflict';
$data['errmsg'] = $h;
$data['cont'] = $cont;
sendJSON($data);
}
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJconfirmDeleteRequest()
///
/// \brief prints a confirmation page about deleting a request
///
////////////////////////////////////////////////////////////////////////////////
function AJconfirmDeleteRequest() {
global $user;
$requestid = getContinuationVar('requestid', 0);
$notbyowner = getContinuationVar('notbyowner', 0);
$fromtimetable = getContinuationVar('fromtimetable', 0);
$skipconfirm = processInputVar('skipconfirm', ARG_NUMERIC, 0);
if($skipconfirm != 0 && $skipconfirm != 1)
$skipconfirm = 0;
$request = getRequestInfo($requestid, 1);
if(is_null($request)) {
$data = array('error' => 1,
'refresh' => 1,
'msg' => _("The specified reservation no longer exists."));
sendJSON($data);
return;
}
if($request['stateid'] == 11 || $request['stateid'] == 12 ||
($request['stateid'] == 14 &&
($request['laststateid'] == 11 || $request['laststateid'] == 12))) {
$data = array('error' => 1,
'refresh' => 1,
'msg' => _("This reservation has timed out due to lack of user activity and is no longer available."));
sendJSON($data);
return;
}
if($request['forimaging'])
$reservation = $request['reservations'][0];
else {
foreach($request["reservations"] as $res) {
if($res["forcheckout"]) {
$reservation = $res;
break;
}
}
}
if(! $skipconfirm && $user['id'] != $request['userid']) {
$data = array('status' => 'serverconfirm');
sendJSON($data);
return;
}
if(datetimeToUnix($request["start"]) > time()) {
$text = sprintf(_("Delete reservation for %s starting %s?"),
"{$reservation["prettyimage"]} ",
prettyDatetime($request["start"]));
}
else {
if($notbyowner == 0 && ! $reservation["production"]) {
AJconfirmDeleteRequestProduction($request);
return;
}
else {
if(datetimeToUnix($request["start"]) <
datetimeToUnix($request["daterequested"]))
$showstart = prettyDatetime($request["daterequested"]);
else
$showstart = prettyDatetime($request["start"]);
if($notbyowner == 0) {
$text = sprintf(_("Are you finished with your reservation for %s that started %s?"),
"{$reservation["prettyimage"]} ", $showstart);
}
else {
$userinfo = getUserInfo($request["userid"], 1, 1);
$text = sprintf(_("Delete reservation by %s for %s that started %s?"),
"{$userinfo['unityid']}@{$userinfo['affiliation']}",
"{$reservation["prettyimage"]} ",
$showstart);
}
}
}
$cdata = array('requestid' => $requestid,
'notbyowner' => $notbyowner,
'fromtimetable' => $fromtimetable);
if($fromtimetable)
$cdata['ttdata'] = getContinuationVar('ttdata');
$cont = addContinuationsEntry('AJsubmitDeleteRequest', $cdata, SECINDAY, 0, 0);
$text = preg_replace("/(.{1,70}([ \n]|$))/", '\1 ', $text) . ' ';
$data = array('content' => $text,
'cont' => $cont,
'requestid' => $requestid,
'status' => 'success',
'btntxt' => _('Delete Reservation'));
sendJSON($data);
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJconfirmDeleteRequestProduction($request)
///
/// \param $request - a request array as returend from getRequestInfo
///
/// \brief prints a page asking if the user is ready to make the image
/// production or just end this reservation
///
////////////////////////////////////////////////////////////////////////////////
function AJconfirmDeleteRequestProduction($request) {
$cdata = array('requestid' => $request['id']);
$text = '';
$title = "" . _("End Reservation/Make Production") . " ";
$text .= _("Are you satisfied that this environment is ready to be made production and replace the current production version, or would you just like to end this reservation and test it again later?");
if(isImageBlockTimeActive($request['reservations'][0]['imageid'])) {
$text .= "\n";
$text .= _("WARNING: This environment is part of an active block allocation. Changing the production version of the environment at this time will result in new reservations under the block allocation to have full reload times instead of a < 1 minutes wait. You can change the production version later by going to Manage Images->Edit Image Profiles and clicking Edit for this environment.");
$text .= " ";
}
$cont = addContinuationsEntry('AJsetImageProduction', $cdata, SECINDAY, 0, 1);
$radios = '';
$radios .= " ";
$radios .= _("Make this the production version") . " ";
$cont = addContinuationsEntry('AJsubmitDeleteRequest', $cdata, SECINDAY, 0, 0);
$radios .= " ";
$radios .= _("Just end the reservation") . " ";
$text = preg_replace("/(.{1,60}([ \n]|$))/", '\1 ', $text);
$data = array('content' => $title . $text . $radios,
'cont' => $cont,
'btntxt' => _('Submit'));
sendJSON($data);
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJsubmitDeleteRequest()
///
/// \brief submits deleting a request and prints that it has been deleted
///
////////////////////////////////////////////////////////////////////////////////
function AJsubmitDeleteRequest() {
global $mode;
$mode = 'AJviewRequests';
$requestid = getContinuationVar('requestid', 0);
$fromtimetable = getContinuationVar('fromtimetable', 0);
$request = getRequestInfo($requestid);
deleteRequest($request);
if($fromtimetable) {
$cdata = getContinuationVar('ttdata');
$cont = addContinuationsEntry('showTimeTable', $cdata);
print "window.location.href='" . BASEURL . SCRIPT . "?continuation=$cont';";
return;
}
viewRequests();
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJconfirmRemoveRequest()
///
/// \brief populates a confirmation dialog box
///
////////////////////////////////////////////////////////////////////////////////
function AJconfirmRemoveRequest() {
$requestid = getContinuationVar('requestid', 0);
$request = getRequestInfo($requestid, 1);
if(is_null($request)) {
$data = array('error' => 1,
'msg' => _("The specified reservation no longer exists."));
sendJSON($data);
return;
}
if($request['stateid'] != 11 && $request['laststateid'] != 11 &&
$request['stateid'] != 12 && $request['laststateid'] != 12 &&
$request['stateid'] != 5 && $request['laststateid'] != 5) {
$data = array('error' => 2,
'msg' => _("The reservation is no longer failed or timed out."),
'url' => BASEURL . SCRIPT . "?mode=viewRequests");
sendJSON($data);
return;
}
if($request['stateid'] == 11 || $request['stateid'] == 12 ||
$request['stateid'] == 12 || $request['laststateid'] == 12) {
$text = _("Remove timed out reservation from list of current reservations?");
$text .= " \n";
}
else {
$text = _("Remove failed reservation from list of current reservations?");
$text .= " \n";
}
$cdata = array('requestid' => $requestid);
$cont = addContinuationsEntry('AJsubmitRemoveRequest', $cdata, SECINDAY, 0, 0);
$text = preg_replace("/(.{1,60}([ \n]|$))/", '\1 ', $text);
$data = array('content' => $text,
'cont' => $cont);
sendJSON($data);
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJsubmitRemoveRequest()
///
/// \brief submits deleting a request and prints that it has been deleted
///
////////////////////////////////////////////////////////////////////////////////
function AJsubmitRemoveRequest() {
global $mode;
$mode = 'AJviewRequests';
$requestid = getContinuationVar('requestid', 0);
$request = getRequestInfo($requestid, 1);
if(is_null($requestid)) {
viewRequests();
return;
}
if($request['serverrequest']) {
$query = "SELECT id FROM serverrequest WHERE requestid = $requestid";
$qh = doQuery($query);
if($row = mysql_fetch_assoc($qh)) {
$query = "DELETE FROM serverrequest WHERE requestid = $requestid";
doQuery($query, 152);
deleteVariable("fixedIPsr{$row['id']}");
}
}
$query = "DELETE FROM request WHERE id = $requestid";
doQuery($query, 153);
$query = "DELETE FROM reservation WHERE requestid = $requestid";
doQuery($query, 154);
viewRequests();
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJrebootRequest()
///
/// \brief sets a reservation to the reboot state and refreshes the Current
/// Reservations page
///
////////////////////////////////////////////////////////////////////////////////
function AJrebootRequest() {
$requestid = getContinuationVar('requestid');
$reqdata = getRequestInfo($requestid, 1);
if(is_null($reqdata) || $reqdata['stateid'] == 11 || $reqdata['stateid'] == 12 ||
($reqdata['stateid'] == 14 &&
($reqdata['laststateid'] == 11 || $reqdata['laststateid'] == 12))) {
print "resGone('reboot'); ";
print "dijit.byId('editResDlg').show();";
print "setTimeout(resRefresh, 1500);";
return;
}
$reboottype = processInputVar('reboottype', ARG_NUMERIC);
$newstateid = 26;
if($reboottype == 1) {
$newstateid = 28;
addChangeLogEntryOther($reqdata['logid'], "event:reboothard");
}
else
addChangeLogEntryOther($reqdata['logid'], "event:rebootsoft");
$query = "UPDATE request SET stateid = $newstateid WHERE id = $requestid";
doQuery($query, 101);
print "resRefresh();";
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJshowReinstallRequest()
///
/// \brief generates text for prompting user about reinstalling reservation
///
////////////////////////////////////////////////////////////////////////////////
function AJshowReinstallRequest() {
global $user;
$requestid = getContinuationVar('requestid');
$reqdata = getRequestInfo($requestid, 1);
if(is_null($reqdata) || $reqdata['stateid'] == 11 || $reqdata['stateid'] == 12 ||
($reqdata['stateid'] == 14 &&
($reqdata['laststateid'] == 11 || $reqdata['laststateid'] == 12))) {
sendJSON(array('status' => 'resgone'));
return;
}
$imageid = $reqdata['reservations'][0]['imageid'];
$imgdata = getImages(0, $imageid);
$t = '';
$cdata = getContinuationVar();
$cont = addContinuationsEntry('AJreinstallRequest', $cdata, 300, 1, 0);
if(count($reqdata['reservations']) == 1 &&
($imgdata[$imageid]['ownerid'] == $user['id'] ||
checkUserHasPerm('View Debug Information')) &&
count($imgdata[$imageid]['imagerevision']) > 1) {
# prompt for which revision to use for reinstall
$m = _("This will cause the reserved machine to be reinstalled. You may select which version of the environment you would like to use for the reinstall. The currently installed version is initally selected.");
$t .= preg_replace("/(.{1,85}([ \n]|$))/", '\1 ', $m) . " ";
$t .= " ";
$t .= "" . _("NOTE:") . " ";
}
else
$t .= _("This will cause the reserved machine to be reinstalled.") . " ";
$t .= _("Any data saved only to the reserved machine will be lost .") . " ";
$t .= _("Are you sure you want to continue?") . " ";
sendJSON(array('status' => 'success', 'txt' => $t, 'cont' => $cont));
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJreinstallRequest()
///
/// \brief sets a reservation to the reinstall state and refreshes the Current
/// Reservations page
///
////////////////////////////////////////////////////////////////////////////////
function AJreinstallRequest() {
$requestid = getContinuationVar('requestid');
$reqdata = getRequestInfo($requestid, 1);
if(is_null($reqdata)) {
sendJSON(array('status' => 'resgone'));
return;
}
$revisionid = processInputVar('revisionid', ARG_NUMERIC, 0);
if($revisionid != 0) {
$imageid = $reqdata['reservations'][0]['imageid'];
$imgdata = getImages(0, $imageid);
if(! array_key_exists($revisionid, $imgdata[$imageid]['imagerevision'])) {
$cdata = getContinuationVar();
$cont = addContinuationsEntry('AJreinstallRequest', $cdata, 300, 1, 0);
sendJSON(array('status' => 'invalidrevisionid', 'cont' => $cont));
return;
}
if($reqdata['reservations'][0]['imagerevisionid'] != $revisionid) {
$query = "UPDATE reservation "
. "SET imagerevisionid = $revisionid "
. "WHERE id = {$reqdata['reservations'][0]['reservationid']}";
doQuery($query, 101);
}
addChangeLogEntryOther($reqdata['logid'], "event:reinstall|revisionid:$revisionid");
}
else
addChangeLogEntryOther($reqdata['logid'], "event:reinstall");
$query = "UPDATE request SET stateid = 27 WHERE id = $requestid";
doQuery($query, 101);
sendJSON(array('status' => 'success'));
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJconnectRequest()
///
/// \brief generates data to explain to user how to connect to a reservation;
/// sets IPaddress for the request
///
////////////////////////////////////////////////////////////////////////////////
function AJconnectRequest() {
global $remoteIP, $user;
$requestid = getContinuationVar('requestid');
$requestData = getRequestInfo($requestid, 1);
if(is_null($requestData)) {
$h = _("This reservation is no longer available.");
sendJSON(array('html' => $h, 'refresh' => 1));
return;
}
if($requestData['stateid'] == 11 || $requestData['stateid'] == 12 ||
($requestData['stateid'] == 14 &&
($requestData['laststateid'] == 11 || $requestData['laststateid'] == 12))) {
$h = _("This reservation has timed out due to lack of user activity and is no longer available.");
sendJSON(array('html' => $h, 'refresh' => 1));
return;
}
$h = '';
$now = time();
if($requestData['reservations'][0]['remoteIP'] != $remoteIP) {
$query = "UPDATE reservation "
. "SET remoteIP = '$remoteIP' "
. "WHERE requestid = $requestid";
$qh = doQuery($query, 226);
addChangeLogEntry($requestData["logid"], $remoteIP);
if($requestData['reservations'][0]['remoteIP'] == '')
addConnectTimeout($requestData['reservations'][0]['reservationid'],
$requestData['reservations'][0]['computerid']);
}
$timeout = getReservationNextTimeout($requestData['reservations'][0]['reservationid']);
if(! is_null($timeout))
$h .= " \n";
if($requestData['forimaging']) {
$h .= "";
$m = "" . _("NOTICE:") . " ";
$m .= _("Later in this process, you must accept a click-through agreement about software licensing.");
$h .= preg_replace('|(.+) |', '\1 ', $m);
$h .= " \n";
}
$imagenotes = getImageNotes($requestData['reservations'][0]['imageid']);
if(! preg_match('/^\s*$/', $imagenotes['usage'])) {
$h .= "" . _("Notes on using this environment:") . " \n";
$h .= "{$imagenotes['usage']} \n";
}
if(count($requestData["reservations"]) > 1)
$cluster = 1;
else
$cluster = 0;
if($cluster) {
$h .= "" . _("Cluster Reservation") . " \n";
$h .= _("This is a cluster reservation. Depending on the makeup of the cluster, you may need to use different methods to connect to the different environments in your cluster.");
$h .= " \n";
}
foreach($requestData["reservations"] as $key => $res) {
$osname = $res["OS"];
if(array_key_exists($user['id'], $requestData['passwds'][$res['reservationid']]))
$passwd = $requestData['passwds'][$res['reservationid']][$user['id']];
else
$passwd = '';
$connectData = getImageConnectMethodTexts($res['imageid'],
$res['imagerevisionid']);
$natports = getNATports($res['reservationid']);
$usenat = 0;
if(count($natports))
$usenat = 1;
$first = 1;
if($cluster) {
$h .= "\n";
$h .= "{$res['prettyimage']} \n";
}
foreach($connectData as $cmid => $method) {
if($first)
$first = 0;
else
$h .= " \n";
if($requestData['forimaging'] && $res['OStype'] == 'windows')
$conuser = 'Administrator';
elseif(preg_match('/(.*)@(.*)/', $user['unityid'], $matches))
$conuser = $matches[1];
else
$conuser = $user['unityid'];
if(! strlen($passwd))
$passwd = _('(use your campus password)');
if($cluster)
$h .= "" . _("Connect to reservation using") . " {$method['description']} \n";
else
$h .= "" . _("Connect to reservation using") . " {$method['description']} \n";
$froms = array('/#userid#/',
'/#password#/',
'/#connectIP#/');
# check that connecttext includes port if nat is being used
if($usenat) {
$found = 0;
foreach($method['ports'] as $port) {
if(preg_match("/{$port['key']}/", $method['connecttext'])) {
$found = 1;
break;
}
}
if(! $found) {
# no port in connect text, assume first port will work
$method['connecttext'] = preg_replace("/#connectIP#/", "#connectIP#:{$method['ports'][0]['key']}", $method['connecttext']);
}
}
$tos = array($conuser,
$passwd,
$res['connectIP']);
$msg = preg_replace($froms, $tos, $method['connecttext']);
foreach($method['ports'] as $port) {
if($usenat && array_key_exists($port['key'], $natports[$cmid]))
$msg = preg_replace("/{$port['key']}/", $natports[$cmid][$port['key']]['publicport'], $msg);
else {
if((preg_match('/remote desktop/i', $method['description']) ||
preg_match('/RDP/i', $method['description'])) &&
$port['key'] == '#Port-TCP-3389#')
$msg = preg_replace("/{$port['key']}/", $user['rdpport'], $msg);
else
$msg = preg_replace("/{$port['key']}/", $port['port'], $msg);
}
}
#$h .= preg_replace("/(.{1,120}([ ]|$))/", '\1 ', $msg);
$h .= $msg;
if(preg_match('/remote desktop/i', $method['description']) ||
preg_match('/RDP/i', $method['description'])) {
#$h .= "
\n";
#$h .= "\n";
$h .= "\n";
#$h .= "
\n";
}
}
if($cluster)
$h .= " \n";
}
$cdata = array('requestid' => $requestid);
$cont = addContinuationsEntry('AJcheckConnectTimeout', $cdata, SECINDAY);
$h .= " \n";
$return = array('html' => $h);
if(! is_null($timeout)) {
$return['timeoutid'] = "timeoutvalue|$requestid";
$return['timeout'] = $timeout;
}
sendJSON($return);
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJcheckConnectTimeout()
///
/// \brief checks to see if a reservation has timed out
///
////////////////////////////////////////////////////////////////////////////////
function AJcheckConnectTimeout() {
$requestid = getContinuationVar('requestid');
$reqdata = getRequestInfo($requestid, 1);
$stateid = $reqdata['stateid'];
if($stateid == 14)
$stateid = $reqdata['laststateid'];
if(is_null($reqdata) ||
$stateid == 1 ||
$stateid == 11 ||
$stateid == 12 ||
$stateid == 16 ||
$stateid == 17) {
$data['status'] = 'timeout';
sendJSON($data);
return;
}
$data['status'] = 'inuse';
sendJSON($data);
return;
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn connectRDPapplet()
///
/// \brief prints a page to launch the RDP java applet
///
////////////////////////////////////////////////////////////////////////////////
/*function connectRDPapplet() {
global $user;
$requestid = processInputVar("requestid", ARG_NUMERIC);
$requestData = getRequestInfo($requestid);
$server = processInputVar("reservedIP", ARG_STRING, $requestData["reservations"][0]["reservedIP"]);
$password = "";
foreach($requestData["reservations"] as $res) {
if($res["reservedIP"] == $server) {
$password = $res["password"];
break;
}
}
print "\n";
print "
Connect! \n";
print "Launching applet. You will have to grant it any permissions it requests.
\n";
print "
\n";
print " \n";
print " \n";
print " \n";
print " \n";
print " \n";
print " \n";
print " \n";
print "
\n";
}*/
////////////////////////////////////////////////////////////////////////////////
///
/// \fn connectMindterm
///
/// \brief prints a page with an embedded mindterm client
///
////////////////////////////////////////////////////////////////////////////////
/*function connectMindterm() {
global $user;
$passwd = processInputVar("passwd", ARG_STRING);
$serverIP = processInputVar("serverip", ARG_STRING);
$requestid = processInputVar("requestid", ARG_NUMERIC);
$requestData = getRequestInfo($requestid);
$reserv = "";
foreach($requestData["reservations"] as $key => $res) {
if($res["reservedIP"] == $serverIP) {
$reserv = $res;
break;
}
}
print "Connect! \n";
print "{$reserv["prettyimage"]} \n";
print "\n";
print "Platform : {$reserv["OS"]} \n";
print "Remote Computer : {$reserv["reservedIP"]} \n";
print "User ID : " . $user['unityid'] . " \n";
if(strlen($reserv['password']))
print "Password : {$reserv['password']} \n";
else
print "Password : (use your campus password) \n";
print " \n";
print "\n";
print " \n";
print " \n";
print " \n";
#print " \n";
print " \n";
print " \n";
print " \n";
print " \n";
print " \n";
}*/
////////////////////////////////////////////////////////////////////////////////
///
/// \fn processRequestInput($checks)
///
/// \param $checks - (optional) 1 to perform validation, 0 not to
///
/// \return an array with the following indexes (some may be empty):\n
/// requestid, day, hour, minute, meridian, length, started, os, imageid,
/// prettyimage, time, testjavascript, lengthchanged
///
/// \brief validates input from the previous form; if anything was improperly
/// submitted, sets submitErr and submitErrMsg
///
////////////////////////////////////////////////////////////////////////////////
function processRequestInput() {
global $user;
$baseaccess = getContinuationVar('baseaccess', 0);
$imagingaccess = getContinuationVar('imagingaccess', 0);
$serveraccess = getContinuationVar('serveraccess', 0);
$openend = getContinuationVar('openend', 0);
$nousercheck = getContinuationVar('nousercheck', 0);
$return['imaging'] = getContinuationVar('imaging', 0);
$maxinitial = getContinuationVar('maxinitial', 0);
$return = array('err' => 0);
# type
$return['type'] = processInputVar('type', ARG_STRING);
if(! preg_match('/^basic|imaging|server$/', $return['type'])) {
$return['err'] = 1;
$return['errmsg'] = _('Invalid data submitted');
return $return;
}
if(($return['type'] == 'basic' && ! $baseaccess) ||
($return['type'] == 'imaging' && ! $imagingaccess) ||
($return['type'] == 'server' && ! $serveraccess)) {
$return['err'] = 1;
$return['errmsg'] = _('No access to submitted reservation type');
return $return;
}
# ending
$return['ending'] = processInputVar('ending', ARG_STRING);
if(! preg_match('/^indefinite|endat|duration$/', $return['ending'])) {
$return['err'] = 1;
$return['errmsg'] = _('Invalid data submitted');
return $return;
}
if(($return['ending'] == 'duration' && ! $baseaccess) ||
($return['ending'] == 'indefinite' && ! $serveraccess) ||
($return['ending'] == 'endat' && ! $openend && ! $serveraccess)) {
$return['err'] = 1;
$return['errmsg'] = _('No access to submitted end type');
return $return;
}
# imageid
$return['imageid'] = processInputVar('imageid', ARG_NUMERIC);
$resources = getUserResources(array("imageAdmin", "imageCheckOut"));
$withnocheckout = $resources['image'];
$images = removeNoCheckout($resources["image"]);
$extraimages = getServerProfileImages($user['id']);
if(! array_key_exists($return['imageid'], $images) &&
($return['type'] != 'server' ||
! array_key_exists($return['imageid'], $extraimages)) &&
($return['type'] != 'imaging' ||
! array_key_exists($return['imageid'], $withnocheckout))) {
$return['err'] = 1;
$return['errmsg'] = _('No access to submitted environment');
return $return;
}
# nousercheck
$return['nousercheck'] = processInputVar('nousercheck', ARG_NUMERIC);
if(! $nousercheck || $return['nousercheck'] != 1)
$return['nousercheck'] = 0;
# revisionid
$revids = processInputVar("revisionid", ARG_STRING);
$revids = explode(':', $revids);
$images = getImages(0, $return['imageid']);
$return['revisionids'] = array();
if(array_key_exists('subimages', $images[$return['imageid']])) {
$subimages = $images[$return['imageid']]['subimages'];
array_unshift($subimages, $return['imageid']);
foreach($subimages as $key => $imgid) {
$revisions = getImageRevisions($imgid);
if(! array_key_exists($key, $revids) ||
! is_numeric($revids[$key]) ||
! array_key_exists($revids[$key], $revisions))
$revid = getProductionRevisionid($imgid);
else
$revid = $revids[$key];
if(! array_key_exists($imgid, $return['revisionids']))
$return['revisionids'][$imgid] = array();
$return['revisionids'][$imgid][] = $revid;
}
}
elseif($revids[0] != '' && is_numeric($revids[0]))
$return['revisionids'][$return['imageid']][] = $revids[0];
else
$return['revisionids'][$return['imageid']][] = getProductionRevisionid($return['imageid']);
# duration
if($return['ending'] == 'duration') {
$return['duration'] = processInputVar('duration', ARG_NUMERIC, 0);
if($return['duration'] > $maxinitial)
$return['duration'] = $maxinitial;
}
# start/end
$return['start'] = processInputVar('start', ARG_NUMERIC);
$return['end'] = processInputVar('end', ARG_NUMERIC, 0);
$now = time();
if($return['start'] == 0)
$start = $now;
else
$start = $return['start'];
if($return['ending'] == 'endat')
$end = $return['end'];
if($return['ending'] == 'indefinite')
$end = datetimeToUnix('2038-01-01 00:00:00');
elseif($return['ending'] == 'duration')
$end = $start + ($return['duration'] * 60);
if($start < $now) {
$return['err'] = 1;
$return['errmsg'] = _('The submitted start time is in the past.');
return $return;
}
if($start + 900 > $end) {
$return['err'] = 1;
$return['errmsg'] = _('The end time must be at least 15 minutes later than the start time.');
return $return;
}
$return['ipaddr'] = '';
$return['macaddr'] = '';
# server specific input
if($return['type'] == 'server') {
# name
$return['name'] = processInputVar('name', ARG_STRING);
if(! preg_match('/^([-a-zA-Z0-9_\. ]){0,255}$/', $return['name'])) {
$return['err'] = 1;
$return['errmsg'] = _('The reservation name can only contain letters, numbers, spaces, dashes(-), underscores(_), and periods(.) and can be up to 255 characters long');
return $return;
}
# ipaddr
$return['ipaddr'] = processInputVar('ipaddr', ARG_STRING);
if($return['ipaddr'] != '') {
# validate fixed IP address
if(! validateIPv4addr($return['ipaddr'])) {
$return['err'] = 1;
$return['errmsg'] = _('Invalid IP address. Must be w.x.y.z with each of w, x, y, and z being between 1 and 255 (inclusive)');
return $return;
}
# validate netmask
$return['netmask'] = processInputVar('netmask', ARG_STRING);
$bnetmask = ip2long($return['netmask']);
if(! preg_match('/^[1]+0[^1]+$/', sprintf('%032b', $bnetmask))) {
$return['err'] = 1;
$return['errmsg'] = _('Invalid netmask specified');
return $return;
}
# validate router
$return['router'] = processInputVar('router', ARG_STRING);
if(! validateIPv4addr($return['router'])) {
$return['err'] = 1;
$return['errmsg'] = _('Invalid router address. Must be w.x.y.z with each of w, x, y, and z being between 1 and 255 (inclusive)');
return $return;
}
$return['network'] = ip2long($return['ipaddr']) & $bnetmask;
if($return['network'] != (ip2long($return['router']) & $bnetmask)) {
$return['err'] = 1;
$return['errmsg'] = _('IP address and router are not on the same subnet based on the specified netmask.');
return $return;
}
# validate dns server(s)
$dns = processInputVar('dns', ARG_STRING);
$tmp = explode(',', $dns);
$cnt = 0;
$return['dnsArr'] = array();
foreach($tmp as $dnsaddr) {
if($cnt && $dnsaddr == '')
continue;
if($cnt == 3) {
$return['err'] = 1;
$return['errmsg'] = _('Too many DNS servers specified - up to 3 are allowed.');
return $return;
}
if(! validateIPv4addr($dnsaddr)) {
$return['err'] = 1;
$return['errmsg'] = _('Invalid DNS server specified.');
return $return;
}
$return['dnsArr'][] = $dnsaddr;
$cnt++;
}
# check that a management node can handle the network
$mappedmns = getMnsFromImage($return['imageid']);
$mnnets = checkAvailableNetworks($return['ipaddr']);
$intersect = array_intersect($mappedmns, $mnnets);
if(empty($intersect)) {
$return['err'] = 1;
$return['errmsg'] = _('There are no management nodes that can deploy the selected image with the specified IP address.');
return $return;
}
}
# macaddr
$return['macaddr'] = processInputVar('macaddr', ARG_STRING);
if($return['macaddr'] != '' && ! preg_match('/^(([A-Fa-f0-9]){2}:){5}([A-Fa-f0-9]){2}$/', $return['macaddr'])) {
$return['err'] = 1;
$return['errmsg'] = _('Invalid MAC address. Must be XX:XX:XX:XX:XX:XX with each pair of XX being from 00 to FF (inclusive)');
return $return;
}
# profileid
$return['profileid'] = processInputVar('profileid', ARG_NUMERIC, 0);
$resources = getUserResources(array("serverCheckOut", "serverProfileAdmin"),
array("available","administer"));
if(! array_key_exists($return['profileid'], $resources['serverprofile']))
$return['profileid'] = 0;
elseif($return['profileid'] != 0) {
$tmp = getServerProfiles($return['profileid']);
$tmp = $tmp[$return['profileid']];
if($tmp['imageid'] != $return['imageid'] &&
(($tmp['fixedIP'] != $return['ipaddr'] && $tmp['fixedMAC'] != $return['macaddr']) ||
($tmp['fixedIP'] == $return['ipaddr'] && $return['ipaddr'] == '' &&
$tmp['fixedMAC'] == $return['macaddr'] && $return['macaddr'] == '')))
$return['profileid'] = 0;
}
# admingroupid
$usergroups = getUserGroups();
$return['admingroupid'] = processInputVar('admingroupid', ARG_NUMERIC);
if($return['admingroupid'] != 0 && ! array_key_exists($return['admingroupid'], $usergroups)) {
$return['err'] = 1;
$return['errmsg'] = _('You do not have access to use the specified admin user group.');
return $return;
}
# logingroupid
$return['logingroupid'] = processInputVar('logingroupid', ARG_NUMERIC);
if($return['logingroupid'] != 0 && ! array_key_exists($return['logingroupid'], $usergroups)) {
$return['err'] = 1;
$return['errmsg'] = _('You do not have access to use the specified access user group.');
return $return;
}
# monitored
$return['monitored'] = processInputVar('monitored', ARG_NUMERIC, 0);
if($return['monitored'] != 0 && $return['monitored'] != 1)
$return['monitored'] = 0;
# configs
# TODO configs
/*$tmp = getUserResources(array("configAdmin"));
$userconfigs = $tmp['config'];
$initconfigs = getMappedConfigs($return['imageid']);
if(array_key_exists('configdata', $_POST)) {
if(get_magic_quotes_gpc())
$_POST['configdata'] = stripslashes($_POST['configdata']);
$configdata = json_decode($_POST['configdata']);
}
if(array_key_exists('configdata', $_POST) &&
isset($configdata->configs))
$configs = $configdata->configs;
else
$configs = (object)array();
$return['configs'] = array();
foreach($initconfigs as $id => $config) {
if(isset($configs->{$id}) &&
isset($configs->{$id}->applied) &&
$configs->{$config['id']}->applied != 'true' &&
$configs->{$config['id']}->applied != 'false')
unset($configs->{$config['id']});
if($config['optional'] &&
(! isset($configs->{$id}) ||
! $configs->{$id}->applied))
continue;
$return['configs'][$id] = array('configid' => $config['configid'],
'configmapid' => $config['configmapid'],
'imageid' => $config['subimageid']);
if(isset($configs->{$id}))
unset($configs->{$id});
}
$rescfgmapids = array();
foreach($configs as $id => $config) {
if(! array_key_exists($config->configid, $userconfigs))
continue;
$return['configs'][$id] = array('configid' => $config->configid,
'configstageid' => $config->configstageid,
'imageid' => $config->imageid);
$tmp = explode('/', $id);
$rescfgmapids[$tmp[1]] = 1;
}
# configvars
$tmp = array_splice($initconfigs, 0);
$initconfigvars = getImageConfigVariables($tmp);
if(array_key_exists('configdata', $_POST) &&
isset($configdata->configvars))
$configvars = $configdata->configvars;
else
$configvars = (object)array();
#print "/*";
#printArray($initconfigvars);
#printArray($configvars);
#print "*" . "/";
$return['configvars'] = array();
foreach($initconfigvars as $id => $configvar) {
$tmp = explode('/', $id);
$cfgid = "{$tmp[0]}/{$tmp[1]}";
$varid = $tmp[2];
if($configvar['ask'] == 0 ||
! isset($configvars->{$id}) ||
! isset($configvars->{$id}->value)) {
$return['configvars'][$cfgid][$varid] =
array('value' => $configvar['defaultvalue']);
}
else {
switch($configvar['datatype']) {
case 'bool':
case 'int':
case 'float':
$value = processInputData($configvars->{$id}->value, ARG_NUMERIC);
break;
default:
$value = processInputData($configvars->{$id}->value, ARG_STRING);
break;
}
$return['configvars'][$cfgid][$varid] = array('value' => $value);
}
if(isset($configvars->{$id}))
unset($configvars->{$id});
}*/
/*print "/*";
printArray($rescfgmapids);
foreach($configvars as $id => $var) {
$cfgid = explode('/', $id);
print "cfgid: {$cfgid[1]}\n";
if(! array_key_exists($cfgid[1], $rescfgmapids))
continue;
// TODO validate based on var type
$value = processInputData($configvars->{$id}->value, ARG_STRING);
$return['configvars']["{$cfgid[0]}/{$cfgid[1]}"][$cfgid[2]] = array('value' => $value);
}
printArray($configvars);*/
#print "*/";
}
return $return;
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn getReservationNextTimeout($resid)
///
/// \param $resid - reservation id
///
/// \return unix timestamp
///
/// \brief determines the time at which the specified reservation will time out
/// if not acknowledged or NULL if there is no entry
///
////////////////////////////////////////////////////////////////////////////////
function getReservationNextTimeout($resid) {
global $user;
$query = "SELECT UNIX_TIMESTAMP(cll.timestamp) AS timestamp, "
. "cls.loadstatename, "
. "COALESCE(v2.value, v1.value) AS acknowledgetimeout, "
. "COALESCE(v4.value, v3.value) AS initialconnecttimeout, "
. "COALESCE(v6.value, v5.value) AS reconnecttimeout "
. "FROM computerloadlog cll, "
. "computerloadstate cls, "
. "variable v1, "
. "variable v3, "
. "variable v5 "
. "LEFT JOIN variable v2 ON (v2.name = 'acknowledgetimeout|{$user['affiliation']}') "
. "LEFT JOIN variable v4 ON (v4.name = 'initialconnecttimeout|{$user['affiliation']}') "
. "LEFT JOIN variable v6 ON (v6.name = 'reconnecttimeout|{$user['affiliation']}') "
. "WHERE cll.reservationid = $resid AND "
. "cll.loadstateid = cls.id AND "
. "cll.loadstateid IN (SELECT id "
. "FROM computerloadstate "
. "WHERE loadstatename IN ('acknowledgetimeout', 'initialconnecttimeout', 'reconnecttimeout')) AND "
. "v1.name = 'acknowledgetimeout' AND "
. "v3.name = 'initialconnecttimeout' AND "
. "v5.name = 'reconnecttimeout' "
. "ORDER BY cll.timestamp DESC "
. "LIMIT 1";
$qh = doQuery($query);
if($row = mysql_fetch_assoc($qh)) {
if(! is_numeric($row['timestamp']))
return NULL;
if($row['loadstatename'] == 'acknowledgetimeout')
return $row['timestamp'] + $row['acknowledgetimeout'] + 5;
elseif($row['loadstatename'] == 'initialconnecttimeout')
return $row['timestamp'] + $row['initialconnecttimeout'] + 5;
elseif($row['loadstatename'] == 'reconnecttimeout')
return $row['timestamp'] + $row['reconnecttimeout'] + 5;
else
return NULL;
}
else
return NULL;
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn addConnectTimeout($resid, $compid)
///
/// \param $resid - reservation id
/// \param $compid - computer id
///
/// \brief inserts a connecttimeout entry in computerloadlog for $resid/$compid
///
////////////////////////////////////////////////////////////////////////////////
function addConnectTimeout($resid, $compid) {
$query = "INSERT INTO computerloadlog "
. "(reservationid, "
. "computerid, "
. "loadstateid, "
. "timestamp) "
. "SELECT $resid, "
. "$compid, "
. "id, "
. "NOW() "
. "FROM computerloadstate "
. "WHERE loadstatename = 'initialconnecttimeout'";
doQuery($query);
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn getReserveDayData()
///
/// \return array where each key is a unix timestamp, each value is a day of the
/// week
///
/// \brief generates days a user can select for making a future reservation
///
////////////////////////////////////////////////////////////////////////////////
function getReserveDayData() {
$days = array();
for($cur = time(), $end = $cur + DAYSAHEAD * SECINDAY;
$cur < $end;
$cur += SECINDAY) {
$tmp = getdate($cur);
$index = $cur;
$days[$index] = _($tmp["weekday"]);
}
return $days;
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJsetImageProduction()
///
/// \brief prompts user if really ready to set image to production
///
////////////////////////////////////////////////////////////////////////////////
function AJsetImageProduction() {
$requestid = getContinuationVar('requestid');
$data = getRequestInfo($requestid);
foreach($data["reservations"] as $res) {
if($res["forcheckout"]) {
$prettyimage = $res["prettyimage"];
break;
}
}
$title = "" . _("Change Test Image to Production") . " \n";
$text = sprintf(_("This will update %s so that new reservations for it will be for the newly created revision. Are you sure it works correctly and is ready to be made the production revision?"), "$prettyimage ") . " \n";
$cdata = array('requestid' => $requestid);
$cont = addContinuationsEntry('AJsubmitSetImageProduction', $cdata, SECINDAY, 0, 0);
$text = preg_replace("/(.{1,60}[ \n])/", '\1 ', $text);
$data = array('content' => $title . $text,
'cont' => $cont,
'btntxt' => _('Make Production'));
sendJSON($data);
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJsubmitSetImageProduction()
///
/// \brief sets request state to 'makeproduction', notifies user that
/// "productioning" process has started
///
////////////////////////////////////////////////////////////////////////////////
function AJsubmitSetImageProduction() {
$requestid = getContinuationVar('requestid');
$data = getRequestInfo($requestid);
foreach($data["reservations"] as $res) {
if($res["forcheckout"]) {
$prettyimage = $res["prettyimage"];
break;
}
}
$query = "UPDATE request SET stateid = 17 WHERE id = $requestid";
doQuery($query, 101);
$content = sprintf(_("%s is now in the process of being updated to use the newly created revision."), "$prettyimage ") . " ";
$content = preg_replace("/(.{1,60}[ \n])/", '\1 ', $content);
$a = "var dlg = new dijit.Dialog({"
. "title: \"" . _("Change Test Image to Production") . "\","
. "id: \"toproddlg\""
. "});"
. "var content = '$content"
. ""
. ""
. _("Close")
. ""
. " "
. "
';"
. "dlg.set(\"content\", content);"
. "dlg.show();"
. "resRefresh();";
print $a;
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJpreviewClickThrough()
///
/// \brief prompts user if really ready to set image to production
///
////////////////////////////////////////////////////////////////////////////////
function AJpreviewClickThrough() {
global $clickThroughText;
$text = sprintf($clickThroughText, '');
$text = preg_replace("/(.{1,80}([ \n]|$))/", '\1 ', $text);
$text = preg_replace("/<\/p>\n /", '', $text);
sendJSON(array('text' => $text));
}
?>