Example #1
0
function viewRequests()
{
    global $user, $inContinuation, $mode, $skin;
    if ($inContinuation) {
        $lengthchanged = getContinuationVar('lengthchanged', 0);
    } else {
        $lengthchanged = processInputVar('lengthchanged', ARG_NUMERIC, 0);
    }
    $incPaneDetails = processInputVar('incdetails', ARG_NUMERIC, 0);
    $refreqid = processInputVar('reqid', ARG_NUMERIC, 0);
    $requests = getUserRequests("all");
    $images = getImages();
    $computers = getComputers();
    $resources = getUserResources(array("imageAdmin"));
    $text = '';
    $newbtnh = '';
    if (in_array("imageCheckOut", $user["privileges"]) || in_array("imageAdmin", $user["privileges"])) {
        $newbtnh .= "<button id=\"newrequestbtn\" dojoType=\"dijit.form.Button\">\n";
        $newbtnh .= "  " . i("New Reservation") . "\n";
        $newbtnh .= "  <script type=\"dojo/method\" event=\"onClick\">\n";
        $newbtnh .= "    showNewResDlg();\n";
        $newbtnh .= "  </script>\n";
        $newbtnh .= "</button><br><br>\n";
    }
    if ($mode != 'AJviewRequests') {
        print "<H2>" . i("Current Reservations") . "</H2>\n";
        if (count($requests) == 0) {
            print "<span id=\"noresspan\">\n";
        } else {
            print "<span id=\"noresspan\" class=\"hidden\">\n";
        }
        if ($newbtnh == '') {
            print i("You have no current reservations and do not have access to create new ones.") . "<br><br>\n";
        } else {
            print i("You have no current reservations.") . "<br><br>\n";
        }
        print "</span>\n";
        print $newbtnh;
    }
    if ($newbtnh == '' && count($requests) == 0) {
        return;
    }
    if ($mode != 'AJviewRequests') {
        print "<div id=subcontent>\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 .= "  <TR valign=top id=reqrow{$requests[$i]['id']}>\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 .= "    <TD></TD>\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 .= "    <TD></TD>\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 .= "    <TD></TD>\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'] = i("<br>Est:&nbsp;") . $remaining . i("&nbsp;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 .= "    <TD></TD>\n";
                    }
                }
            } else {
                # reservation is in the future
                $text .= "    <TD></TD>\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 .= "    <TD></TD>\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 && ($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 .= "       </div>\n";
                    $text .= "     </div>\n";
                    $text .= getViewRequestHTMLitem('timeoutdata', $requests[$i]['id'], $requests[$i]);
                    $text .= "    </TD>\n";
                } else {
                    $text .= "    <TD>";
                    $text .= getViewRequestHTMLitem('timeoutdata', $requests[$i]['id'], $requests[$i]);
                    $text .= "</TD>\n";
                }
            } else {
                $text .= "    <TD></TD>\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 .= "    <TD align=center><a id=\"req{$requests[$i]['id']}\" ";
                $text .= "tabindex=0>{$requests[$i]["id"]}</a>\n";
                $text .= "<div dojoType=\"vcldojo.HoverTooltip\" connectId=\"req{$requests[$i]['id']}\">";
                $text .= "<b>Mgmt node</b>: {$nodes[$requests[$i]["managementnodeid"]]['hostname']}<br>\n";
                $text .= "<b>Computer ID</b>: {$requests[$i]['computerid']}<br>\n";
                $text .= "<b>Comp hostname</b>: {$computers[$requests[$i]["computerid"]]["hostname"]}<br>\n";
                $text .= "<b>Comp IP</b>: {$requests[$i]["IPaddress"]}<br>\n";
                $text .= "<b>Comp State ID</b>: {$computers[$requests[$i]["computerid"]]["stateid"]}<br>\n";
                $text .= "<b>Comp Type</b>: {$requests[$i]['comptype']}<br>\n";
                if (!is_null($requests[$i]['vmhostid'])) {
                    $text .= "<b>VM Host</b>: {$vmhost}<br>\n";
                }
                $text .= "<b>Current State ID</b>: {$requests[$i]["currstateid"]}<br>\n";
                $text .= "<b>Last State ID</b>: {$requests[$i]["laststateid"]}<br>\n";
                $text .= "</div></TD>\n";
            }
            $text .= "  </TR>\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 .= i("You currently have the following <strong>normal</strong> reservations:") . "<br>\n";
        } else {
            $text .= i("You currently have the following normal reservations:") . "<br>\n";
        }
        if ($lengthchanged) {
            $text .= "<font color=red>";
            $text .= i("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 .= "</font>\n";
        }
        $text .= "<table id=reslisttable summary=\"lists reservations you currently have\" cellpadding=5>\n";
        $text .= "  <TR>\n";
        $text .= "    <TD colspan=3></TD>\n";
        $text .= "    <TH>" . i("Environment") . "</TH>\n";
        $text .= "    <TH>" . i("Starting") . "</TH>\n";
        $text .= "    <TH>" . i("Ending") . "</TH>\n";
        $text .= "    <TH>" . i("Initially requested") . "</TH>\n";
        if (checkUserHasPerm('View Debug Information')) {
            $text .= "    <TH>" . i("Req ID") . "</TH>\n";
        }
        $text .= "  </TR>\n";
        $text .= $normal;
        $text .= "</table>\n";
    }
    if (!empty($imaging)) {
        if (!empty($normal)) {
            $text .= "<hr>\n";
        }
        $text .= i("You currently have the following <strong>imaging</strong> reservations:") . "<br>\n";
        $text .= "<table id=imgreslisttable summary=\"lists imaging reservations you currently have\" cellpadding=5>\n";
        $text .= "  <TR>\n";
        $text .= "    <TD colspan=3></TD>\n";
        $text .= "    <TH>" . i("Environment") . "</TH>\n";
        $text .= "    <TH>" . i("Starting") . "</TH>\n";
        $text .= "    <TH>" . i("Ending") . "</TH>\n";
        $text .= "    <TH>" . i("Initially requested") . "</TH>\n";
        $computers = getComputers();
        if (checkUserHasPerm('View Debug Information')) {
            $text .= "    <TH>Req ID</TH>\n";
        }
        $text .= "  </TR>\n";
        $text .= $imaging;
        $text .= "</table>\n";
    }
    if (!empty($long)) {
        if (!empty($normal) || !empty($imaging)) {
            $text .= "<hr>\n";
        }
        $text .= i("You currently have the following <strong>long term</strong> reservations:") . "<br>\n";
        $text .= "<table id=\"longreslisttable\" summary=\"lists long term reservations you currently have\" cellpadding=5>\n";
        $text .= "  <TR>\n";
        $text .= "    <TD colspan=3></TD>\n";
        $text .= "    <TH>" . i("Environment") . "</TH>\n";
        $text .= "    <TH>" . i("Starting") . "</TH>\n";
        $text .= "    <TH>" . i("Ending") . "</TH>\n";
        $text .= "    <TH>" . i("Initially requested") . "</TH>\n";
        $computers = getComputers();
        if (checkUserHasPerm('View Debug Information')) {
            $text .= "    <TH>Req ID</TH>\n";
        }
        $text .= "  </TR>\n";
        $text .= $long;
        $text .= "</table>\n";
    }
    if (!empty($server)) {
        if (!empty($normal) || !empty($imaging) || !empty($long)) {
            $text .= "<hr>\n";
        }
        $text .= i("You currently have the following <strong>server</strong> reservations:") . "<br>\n";
        $text .= "<table id=\"longreslisttable\" summary=\"lists server reservations you currently have\" cellpadding=5>\n";
        $text .= "  <TR>\n";
        $text .= "    <TD colspan=3></TD>\n";
        $text .= "    <TH>" . i("Name") . "</TH>\n";
        $text .= "    <TH>" . i("Ending") . "</TH>\n";
        $computers = getComputers();
        $text .= "    <TH>" . i("Details") . "</TH>\n";
        if (checkUserHasPerm('View Debug Information')) {
            $text .= "    <TH>" . i("Req ID") . "</TH>\n";
        }
        $text .= "  </TR>\n";
        $text .= $server;
        $text .= "</table>\n";
    }
    # connect div
    if ($connect) {
        $text .= "<br><br>";
        $text .= i("Click the <b>Connect!</b> 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 .= "<br><br>";
        $text .= i("This page will automatically update every 20 seconds until the <font color=red><i>Pending...</i></font> reservation is ready.") . "\n";
    }
    if ($failed) {
        $text .= "<br><br>";
        $text .= i("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 .= "<INPUT type=hidden id=resRefreshCont value=\"{$cont}\">\n";
    $cont = addContinuationsEntry('AJpreviewClickThrough', array());
    $text .= "<INPUT type=hidden id=previewclickthroughcont value=\"{$cont}\">\n";
    $text .= "</div>\n";
    if ($mode != 'AJviewRequests') {
        $text .= newReservationHTML();
        $text .= newReservationConfigHTML();
        /*$text .= "<div dojoType=dijit.Dialog\n";
        		$text .= "      id=\"imageRevisionDlg\"\n";
        		$text .= "      title=\"" . i("Select Image Revisions") . "\"\n";
        		$text .= "      duration=250\n";
        		$text .= "      draggable=true\n";
        		$text .= "      width=\"50%\"\n";
        		#$text .= "      height=\"80%\">\n";
        		#$text .= "      style=\"height: 80%; width: 50%;\">\n";
        		$text .= "      style=\"width: 50%;\">\n";
        		#$text .= "<div dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\" style=\"width: 100%; height: 90%;\">\n";
        		#$text .= "<div dojoType=\"dijit.layout.ContentPane\" region=\"top\" style=\"height: 25px;\">\n";
        		$text .= i("There are multiple versions of this environment available.");
        		$text .= "<br>" . i("Please select the version you would like to check out:");
        		#$text .= "\n</div>\n"; # ContentPane
        		#$text .= " <div dojoType=\"dijit.layout.ContentPane\" region=\"center\">\n";
        		#$text .= "   <div id=\"imageRevisionContent\"></div>\n";
        		$text .= "   <div id=\"imageRevisionContent\" style=\"height: 85%; overflow: auto;\"></div>\n";
        		#$text .= "</div>\n"; # ContentPane
        		#$text .= " <div dojoType=\"dijit.layout.ContentPane\" region=\"bottom\" style=\"height: 25px;\">\n";
        		$text .= "   <div align=\"center\">\n";
        		$text .= "   <button id=\"imageRevBtn\" dojoType=\"dijit.form.Button\">\n";
        		$text .= "    " . i("Create Reservation") . "\n";
        		$text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        		$text .= "       submitNewReservation();\n";
        		$text .= "     </script>\n";
        		$text .= "   </button>\n";
        		$text .= "   <button dojoType=\"dijit.form.Button\">\n";
        		$text .= "     " . i("Cancel") . "\n";
        		$text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        		$text .= "       dijit.byId('imageRevisionDlg').hide();\n";
        		$text .= "     </script>\n";
        		$text .= "   </button>\n";
        		$text .= "   </div>\n"; # center
        		#$text .= "</div>\n"; # ContentPane
        		#$text .= "</div>\n"; # BorderContainer
        		$text .= "</div>\n"; # Dialog*/
        $text .= "<div dojoType=dojox.layout.FloatingPane\n";
        $text .= "      id=resStatusPane\n";
        $text .= "      resizable=true\n";
        $text .= "      closable=true\n";
        $text .= "      title=\"" . i("Detailed Reservation Status") . "\"\n";
        $text .= "      style=\"width: 350px; ";
        $text .= "height: 300px; ";
        $text .= "position: absolute; ";
        $text .= "left: 0px; ";
        $text .= "top: 0px; ";
        $text .= "visibility: hidden; ";
        $text .= "border: solid 1px #7EABCD;\"\n";
        $text .= ">\n";
        $text .= "<script type=\"dojo/method\" event=minimize>\n";
        $text .= "  this.hide();\n";
        $text .= "</script>\n";
        $text .= "<script type=\"dojo/method\" event=close>\n";
        $text .= "  this.hide();\n";
        $text .= "  return false;\n";
        $text .= "</script>\n";
        $text .= "<div id=resStatusText></div>\n";
        $text .= "<input type=hidden id=detailreqid value=0>\n";
        $text .= "</div>\n";
        $text .= "<div dojoType=dijit.Dialog\n";
        $text .= "      id=\"endResDlg\"\n";
        $text .= "      title=\"" . i("Delete Reservation") . "\"\n";
        $text .= "      duration=250\n";
        $text .= "      draggable=true\n";
        $text .= "      style=\"width: 315px;\">\n";
        $text .= "   <div id=\"endResDlgContent\"></div>\n";
        $text .= "   <input type=\"hidden\" id=\"endrescont\">\n";
        $text .= "   <input type=\"hidden\" id=\"endresid\">\n";
        $text .= "   <div align=\"center\">\n";
        $text .= "   <button id=\"endResDlgBtn\" dojoType=\"dijit.form.Button\">\n";
        $text .= "    " . i("Delete Reservation") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       submitDeleteReservation();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   <button dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Cancel") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       dijit.byId('endResDlg').hide();\n";
        $text .= "       dojo.byId('endResDlgContent').innerHTML = '';\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   </div>\n";
        $text .= "</div>\n";
        $text .= "<div dojoType=dijit.Dialog\n";
        $text .= "      id=\"remResDlg\"\n";
        $text .= "      title=\"" . i("Remove Reservation") . "\"\n";
        $text .= "      duration=250\n";
        $text .= "      draggable=true>\n";
        $text .= "   <div id=\"remResDlgContent\"></div>\n";
        $text .= "   <input type=\"hidden\" id=\"remrescont\">\n";
        $text .= "   <div align=\"center\">\n";
        $text .= "   <button id=\"remResDlgBtn\" dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Remove Reservation") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       submitRemoveReservation();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   <button dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Cancel") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       dijit.byId('remResDlg').hide();\n";
        $text .= "       dojo.byId('remResDlgContent').innerHTML = '';\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   </div>\n";
        $text .= "</div>\n";
        $text .= "<div dojoType=dijit.Dialog\n";
        $text .= "      id=\"editResDlg\"\n";
        $text .= "      title=\"" . i("Modify Reservation") . "\"\n";
        $text .= "      duration=250\n";
        $text .= "      draggable=true>\n";
        $text .= "    <script type=\"dojo/connect\" event=onHide>\n";
        $text .= "      hideEditResDlg();\n";
        $text .= "    </script>\n";
        $text .= "   <div id=\"editResDlgContent\"></div>\n";
        $text .= "   <input type=\"hidden\" id=\"editrescont\">\n";
        $text .= "   <input type=\"hidden\" id=\"editresid\">\n";
        $text .= "   <div id=\"editResDlgErrMsg\" class=\"rederrormsg\"></div>\n";
        $text .= "   <div align=\"center\">\n";
        $text .= "   <button id=\"editResDlgBtn\" dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Modify Reservation") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       submitEditReservation();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   <button dojoType=\"dijit.form.Button\" id=\"editResCancelBtn\">\n";
        $text .= "     " . i("Cancel") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       dijit.byId('editResDlg').hide();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   </div>\n";
        $text .= "</div>\n";
        $text .= "<div dojoType=dijit.Dialog\n";
        $text .= "      id=\"rebootdlg\"\n";
        $text .= "      title=\"" . i("Reboot Reservation") . "\"\n";
        $text .= "      duration=250\n";
        $text .= "      draggable=true>\n";
        $text .= "    <script type=\"dojo/connect\" event=onHide>\n";
        $text .= "      hideRebootResDlg();\n";
        $text .= "    </script>\n";
        $text .= "   <div id=\"rebootResDlgContent\">";
        $h = i("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<br>', $h);
        $text .= "<br><br></div>\n";
        $text .= "   <div id=\"rebootRadios\" style=\"margin-left: 90px;\">\n";
        $text .= "   <input type=\"radio\" name=\"reboottype\" id=\"softreboot\" checked>\n";
        $text .= "   <label for=\"softreboot\">" . i("Soft Reboot") . "</label><br>\n";
        $text .= "   <input type=\"radio\" name=\"reboottype\" id=\"hardreboot\">\n";
        $text .= "   <label for=\"hardreboot\">" . i("Hard Reboot") . "</label><br><br>\n";
        $text .= "   </div>\n";
        $text .= "   <input type=\"hidden\" id=\"rebootrescont\">\n";
        $text .= "   <div id=\"rebootResDlgErrMsg\" class=\"rederrormsg\"></div>\n";
        $text .= "   <div align=\"center\">\n";
        $text .= "   <button id=\"rebootResDlgBtn\" dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Reboot Reservation") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       submitRebootReservation();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   <button dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Cancel") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       dijit.byId('rebootdlg').hide();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   </div>\n";
        $text .= "</div>\n";
        $text .= "<div dojoType=dijit.Dialog\n";
        $text .= "      id=\"reinstalldlg\"\n";
        $text .= "      title=\"" . i("Reinstall Reservation") . "\"\n";
        $text .= "      duration=250\n";
        $text .= "      draggable=true>\n";
        $text .= "    <script type=\"dojo/connect\" event=onHide>\n";
        $text .= "      hideReinstallResDlg();\n";
        $text .= "    </script>\n";
        $text .= "   <div id=\"reinstallloading\" style=\"text-align: center\">";
        $text .= "<img src=\"themes/{$skin}/css/dojo/images/loading.gif\" ";
        $text .= "style=\"vertical-align: middle;\"> " . i("Loading...") . "</div>\n";
        $text .= "   <div id=\"reinstallResDlgContent\"></div>\n";
        $text .= "   <input type=\"hidden\" id=\"reinstallrescont\">\n";
        $text .= "   <div id=\"reinstallResDlgErrMsg\" class=\"rederrormsg\"></div>\n";
        $text .= "   <div align=\"center\" id=\"reinstallbtns\" class=\"hidden\">\n";
        $text .= "   <button id=\"reinstallResDlgBtn\" dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Reinstall Reservation") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       submitReinstallReservation();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   <button dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Cancel") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       dijit.byId('reinstalldlg').hide();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   </div>\n";
        $text .= "</div>\n";
        $text .= "<div dojoType=dijit.Dialog\n";
        $text .= "      id=\"suggestedTimes\"\n";
        $text .= "      title=\"" . i("Available Times") . "\"\n";
        $text .= "      duration=250\n";
        $text .= "      draggable=true>\n";
        $text .= "   <div id=\"suggestloading\" style=\"text-align: center\">";
        $text .= "<img src=\"themes/{$skin}/css/dojo/images/loading.gif\" ";
        $text .= "style=\"vertical-align: middle;\"> " . i("Loading...") . "</div>\n";
        $text .= "   <div id=\"suggestContent\"></div>\n";
        $text .= "   <input type=\"hidden\" id=\"suggestcont\">\n";
        $text .= "   <input type=\"hidden\" id=\"selectedslot\">\n";
        $text .= "   <div align=\"center\">\n";
        $text .= "   <button id=\"suggestDlgBtn\" dojoType=\"dijit.form.Button\" disabled>\n";
        $text .= "     " . i("Use Selected Time") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       useSuggestedEditSlot();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   <button id=\"suggestDlgCancelBtn\" dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Cancel") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       dijit.byId('suggestDlgBtn').set('disabled', true);\n";
        $text .= "       dojo.removeClass('suggestDlgBtn', 'hidden');\n";
        $text .= "       showDijitButton('suggestDlgBtn');\n";
        $text .= "       dijit.byId('suggestDlgCancelBtn').set('label', '" . i("Cancel") . "');\n";
        $text .= "       dijit.byId('suggestedTimes').hide();\n";
        $text .= "       dojo.byId('suggestContent').innerHTML = '';\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   </div>\n";
        $text .= "</div>\n";
        $text .= "<div dojoType=dijit.Dialog\n";
        $text .= "      id=\"startimagedlg\"\n";
        $text .= "      title=\"" . i("Create / Update Image") . "\"\n";
        $text .= "      duration=250\n";
        $text .= "      draggable=true>\n";
        $text .= "    <script type=\"dojo/connect\" event=onHide>\n";
        $text .= "      hideStartImageDlg();\n";
        $text .= "    </script>\n";
        $text .= "<div id=\"imageendrescontent\">\n";
        $text .= "<H2>" . i("Create / Update an Image") . "</H2>\n";
        $text .= "</div>\n";
        # imageendrescontent
        $text .= "<div id=\"imagekeeprescontent\">\n";
        $text .= "<H2>" . i("Keep Reservation &amp; Create / Update an Image") . "</H2>\n";
        $h = i("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 <strong>offline</strong> during the image capture process.");
        $h .= "\n \n";
        $h .= "<strong>" . i("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</strong> \n";
        $h .= i("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<br>', $h);
        $text .= "</div>\n";
        # imagekeeprescontent
        $text .= i("Are you creating a new image or updating an existing image?") . "<br><br>\n";
        $text .= "<input type=radio name=imgmode id=newimage value=\"\" checked>\n";
        $text .= "<label for=newimage>" . i("Creating New Image") . "</label><br>\n";
        $text .= "<input type=radio name=imgmode id=updateimage value=\"\">\n";
        $text .= "<label for=updateimage id=\"updateimagelabel\">";
        $text .= i("Update Existing Image") . "</label>";
        $text .= "<br><br>\n";
        $text .= "   <div align=\"center\" id=\"imagebtns\">\n";
        $text .= "   <button id=\"imageDlgBtn\" dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Submit") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       submitCreateUpdateImage();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   <button dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Cancel") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       dijit.byId('startimagedlg').hide();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   </div>\n";
        $text .= "</div>\n";
        $text .= "<div dojoType=dijit.Dialog\n";
        $text .= "      id=\"startimagedisableddlg\"\n";
        $text .= "      title=\"" . i("Create / Update Image") . "\"\n";
        $text .= "      duration=250\n";
        $text .= "      style=\"width: 30%;\"\n";
        $text .= "      draggable=true>\n";
        $text .= "<H2>" . i("Create / Update an Image") . "</H2>\n";
        $text .= i("You cannot create new images from this image because the owner of the image has set \"Users have administrative access\" to No under the Advanced Options of the image.");
        $text .= "<br><br>\n";
        $text .= "   <div align=\"center\">\n";
        $text .= "   <button dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Close") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       dijit.byId('startimagedisableddlg').hide();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   </div>\n";
        $text .= "</div>\n";
        $text .= "<div dojoType=dijit.Dialog\n";
        $text .= "      id=\"connectDlg\"\n";
        $text .= "      title=\"" . i("Connect") . "\"\n";
        $text .= "      duration=250\n";
        $text .= "      autofocus=false\n";
        $text .= "      draggable=true>\n";
        $text .= "   <div dojoType=\"dijit.layout.ContentPane\" id=\"connectDlgContent\" ";
        $text .= "        style=\"overflow: auto; width: 500px;\"></div>\n";
        $text .= "   <div align=\"center\">\n";
        $text .= "   <button dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Close") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       dijit.byId('connectDlg').hide();\n";
        $text .= "       dijit.byId('connectDlgContent').set('content', '');\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   </div>\n";
        $text .= "</div>\n";
        $text .= "<div dojoType=dijit.Dialog\n";
        $text .= "      id=\"timeoutdlg\"\n";
        $text .= "      title=\"" . i("Reservation Timed Out") . "\"\n";
        $text .= "      duration=250\n";
        $text .= "      draggable=false>\n";
        $h = i("This reservation has timed out and is no longer available.");
        $text .= preg_replace("/(.{1,30}([ \n]|\$))/", '\\1<br>', $h);
        $text .= "<br><br>\n";
        $text .= "   <div align=\"center\">\n";
        $text .= "   <button dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Okay") . "\n";
        $text .= "\t   <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       dijit.byId('timeoutdlg').hide();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   </div>\n";
        $text .= "</div>\n";
        $text .= "<input type=hidden id=addresourcecont>\n";
        $obj = new Image();
        $text .= $obj->addEditDialogHTML(1);
        $text .= "<div dojoType=dijit.Dialog\n";
        $text .= "      id=\"updateimagedlg\"\n";
        $text .= "      title=\"" . i("Update Existing Image") . "\"\n";
        $text .= "      duration=250\n";
        $text .= "      draggable=true>\n";
        $text .= "    <script type=\"dojo/connect\" event=onHide>\n";
        $text .= "      hideUpdateImageDlg();\n";
        $text .= "    </script>\n";
        $text .= "   <div id=\"updateimageDlgContent\">\n";
        $text .= "      <h3>" . i("New Revision Comments") . "</h3>\n";
        $h = i("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<br>', $h);
        $text .= "      <textarea dojoType=\"dijit.form.Textarea\" id=\"newcomments\" ";
        $text .= "      style=\"width: 400px; text-align: left;\">\n\n</textarea>\n";
        $text .= "      <h3>" . i("Previous Revision Comments") . "</h3>\n";
        $text .= "      <div id=\"previouscomments\"></div>\n";
        $text .= "   </div>\n";
        $text .= "   <div align=\"center\">\n";
        $text .= "   <button id=\"updateImageDlgBtn\" dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Submit") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       submitUpdateImage();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   <button dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Cancel") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       dijit.byId('updateimagedlg').hide();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   </div>\n";
        $text .= "</div>\n";
        $text .= "<div dojoType=dijit.Dialog\n";
        $text .= "      id=\"clickthroughdlg\"\n";
        $text .= "      duration=250\n";
        $text .= "      draggable=true>\n";
        $text .= "    <script type=\"dojo/connect\" event=onHide>\n";
        $text .= "      hideClickThroughDlg();\n";
        $text .= "    </script>\n";
        $text .= "   <div id=\"clickthroughDlgContent\">\n";
        $text .= "   </div>\n";
        $text .= "   <div align=\"center\" id=\"imagebtns\">\n";
        $text .= "   <button id=\"clickthroughDlgBtn\" dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("I agree") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       clickThroughAgree();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   <button dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("I do not agree") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       dijit.byId('clickthroughdlg').hide();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   </div>\n";
        $text .= "</div>\n";
        $text .= "<div dojoType=dijit.Dialog\n";
        $text .= "      id=\"clickthroughpreviewdlg\"\n";
        $text .= "      duration=250\n";
        $text .= "      draggable=true>\n";
        $text .= "   <div id=\"clickthroughPreviewDlgContent\"></div>\n";
        $text .= "   <div align=\"center\">\n";
        $text .= "   <button dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Close") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       dijit.byId('clickthroughpreviewdlg').hide();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   </div>\n";
        $text .= "</div>\n";
        $text .= "<div dojoType=dijit.Dialog\n";
        $text .= "      id=\"serverdeletedlg\"\n";
        $text .= "      duration=250\n";
        $text .= "      draggable=true>\n";
        $text .= "   <div id=\"serverDeleteDlgContent\">\n";
        $text .= "   <h2>Confirm Server Delete</h2>\n";
        $text .= "   <span class=\"rederrormsg\"><big>\n";
        $warn = i("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<br>', $warn);
        $text .= "   </big></span>\n";
        $text .= "   </div><br>\n";
        $text .= "   <div align=\"center\">\n";
        $text .= "   <input type=\"hidden\" id=\"deletecontholder\">\n";
        $text .= "   <button id=\"serverDeleteDlgBtn\" dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Confirm Delete Reservation") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       endServerReservation();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   <button dojoType=\"dijit.form.Button\">\n";
        $text .= "     " . i("Cancel") . "\n";
        $text .= "     <script type=\"dojo/method\" event=\"onClick\">\n";
        $text .= "       dijit.byId('serverdeletedlg').hide();\n";
        $text .= "     </script>\n";
        $text .= "   </button>\n";
        $text .= "   </div>\n";
        $text .= "</div>\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;
    }
}
Example #2
0
function XMLRPCgetRequestConnectData($requestid, $remoteIP)
{
    global $user;
    $requestid = processInputData($requestid, ARG_NUMERIC);
    $remoteIP = processInputData($remoteIP, ARG_STRING, 1);
    if (!preg_match('/^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})$/', $remoteIP, $matches) || $matches[1] < 1 || $matches[1] > 223 || $matches[2] > 255 || $matches[3] > 255 || $matches[4] > 255) {
        return array('status' => 'error', 'errorcode' => 2, 'errormsg' => 'invalid IP address');
    }
    $userRequests = getUserRequests('all', $user['id']);
    $found = 0;
    foreach ($userRequests as $req) {
        if ($req['id'] == $requestid) {
            $request = $req;
            $found = 1;
            break;
        }
    }
    if (!$found) {
        return array('status' => 'error', 'errorcode' => 1, 'errormsg' => 'unknown requestid');
    }
    // FIXME - add support for cluster requests
    if (requestIsReady($request)) {
        $requestData = getRequestInfo($requestid);
        $query = "UPDATE reservation " . "SET remoteIP = '{$remoteIP}' " . "WHERE requestid = {$requestid}";
        $qh = doQuery($query, 101);
        addChangeLogEntry($requestData["logid"], $remoteIP);
        $serverIP = $requestData["reservations"][0]["reservedIP"];
        $passwd = $requestData["reservations"][0]["password"];
        if ($requestData["forimaging"]) {
            $thisuser = '******';
        } else {
            if (preg_match('/(.*)@(.*)/', $user['unityid'], $matches)) {
                $thisuser = $matches[1];
            } else {
                $thisuser = $user['unityid'];
            }
        }
        return array('status' => 'ready', 'serverIP' => $serverIP, 'user' => $thisuser, 'password' => $passwd);
    }
    return array('status' => 'notready');
}
Example #3
0
function viewRequests()
{
    global $user, $viewmode, $inContinuation, $mode;
    if ($inContinuation) {
        $lengthchanged = getContinuationVar('lengthchanged', 0);
    } else {
        $lengthchanged = processInputVar('lengthchanged', ARG_NUMERIC, 0);
    }
    $incPaneDetails = processInputVar('incdetails', ARG_NUMERIC, 0);
    $refreqid = processInputVar('reqid', ARG_NUMERIC, 0);
    $requests = getUserRequests("all");
    $images = getImages();
    $computers = getComputers();
    if ($mode != 'AJviewRequests') {
        print "<div id=subcontent>\n";
    }
    $refresh = 0;
    $failed = 0;
    $connect = 0;
    $normal = '';
    $imaging = '';
    $long = '';
    if ($count = count($requests)) {
        $now = time();
        for ($i = 0, $noedit = 0, $text = ''; $i < $count; $i++, $noedit = 0, $text = '') {
            if ($requests[$i]['forcheckout'] == 0 && $requests[$i]['forimaging'] == 0) {
                continue;
            }
            $imageid = $requests[$i]["imageid"];
            $text .= "  <TR valign=top id=reqrow{$requests[$i]['id']}>\n";
            if (requestIsReady($requests[$i])) {
                $connect = 1;
                # request is ready, print Connect! and End buttons
                $cdata = array('requestid' => $requests[$i]['id']);
                $text .= "    <TD>\n";
                $text .= "      <FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
                $cont = addContinuationsEntry('connectRequest', $cdata, SECINDAY);
                $text .= "      <INPUT type=hidden name=continuation value=\"{$cont}\">\n";
                $text .= "      <INPUT type=submit value=\"Connect!\">\n";
                $text .= "      </FORM>\n";
                $text .= "    </TD>\n";
                if ($requests[$i]['forimaging']) {
                    # this is the imaging case, need to do sanity check here for if the request
                    #   state currstateid or laststateid are "inuse", otherwise disable out the
                    #   create image button
                    $noedit = 1;
                    $text .= "    <TD>\n";
                    if ($requests[$i]['currstateid'] == 8 || $requests[$i]['laststateid'] == 8) {
                        # the user has connected successfully so we will allow create image button
                        #   to be displayed
                        $text .= "      <FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
                        $cont = addContinuationsEntry('startImage', $cdata);
                        $text .= "      <INPUT type=hidden name=continuation value=\"{$cont}\">\n";
                        $text .= "      <INPUT type=submit value=\"Create\nImage\">\n";
                        $text .= "      </FORM>\n";
                    }
                    $text .= "    </TD>\n";
                    $text .= "    <TD>\n";
                    $text .= "      <FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
                    $cdata = array('requestid' => $requests[$i]['id']);
                    $cont = addContinuationsEntry('confirmDeleteRequest', $cdata, SECINDAY);
                    $text .= "      <INPUT type=hidden name=continuation value=\"{$cont}\">\n";
                    $text .= "      <INPUT type=submit value=Cancel>\n";
                    $text .= "      </FORM>\n";
                    $text .= "    </TD>\n";
                } else {
                    $text .= "    <TD>\n";
                    $text .= "      <FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
                    $cont = addContinuationsEntry('confirmDeleteRequest', $cdata, SECINDAY);
                    $text .= "      <INPUT type=hidden name=continuation value=\"{$cont}\">\n";
                    $text .= "      <INPUT type=submit value=End>\n";
                    $text .= "      </FORM>\n";
                    $text .= "    </TD>\n";
                }
                $startstamp = datetimeToUnix($requests[$i]["start"]);
            } elseif ($requests[$i]["currstateid"] == 5) {
                # request has failed
                $cdata = array('requestid' => $requests[$i]['id']);
                $text .= "    <TD colspan=2 nowrap>\n";
                $text .= "      <span class=scriptonly>\n";
                $text .= "      <span class=compstatelink>";
                $text .= "<a onClick=\"showResStatusPane({$requests[$i]['id']}); ";
                $text .= "return false;\" href=\"#\">Reservation failed</a></span>\n";
                $text .= "      </span>\n";
                $text .= "      <noscript>\n";
                $text .= "      <span class=scriptoff>\n";
                $text .= "      <span class=compstatelink>";
                $text .= "Reservation failed</span>\n";
                $text .= "      </span>\n";
                $text .= "      </noscript>\n";
                $text .= "    </TD>\n";
                $failed = 1;
                $noedit = 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
                    if ($requests[$i]['forimaging']) {
                        $text .= "    <TD colspan=3>\n";
                    } else {
                        $text .= "    <TD colspan=2>\n";
                    }
                    $text .= "      <span class=compstatelink>Reservation has ";
                    $text .= "timed out</span>\n";
                    $noedit = 1;
                    $text .= "    </TD>\n";
                } else {
                    # computer is loading, print Pending... and Delete button
                    $remaining = 1;
                    if ($requests[$i]['forimaging']) {
                        $noedit = 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;
                        }
                    }
                    # computer is loading, print Pending... and Delete button
                    if ($requests[$i]['forimaging']) {
                        $text .= "    <TD colspan=2>\n";
                    } else {
                        $text .= "    <TD>\n";
                    }
                    $text .= "      <span class=scriptonly>\n";
                    $text .= "      <span class=compstatelink><i>";
                    $text .= "<a onClick=\"showResStatusPane({$requests[$i]['id']}); ";
                    $text .= "return false;\" href=\"#\">Pending...</a></i></span>";
                    $text .= "      </span>\n";
                    $text .= "      <noscript>\n";
                    $text .= "      <span class=scriptoff>\n";
                    $text .= "      <span class=compstatelink>";
                    $text .= "<i>Pending...</i></span>\n";
                    $text .= "      </span>\n";
                    $text .= "      </noscript>\n";
                    $text .= "<br>Est:&nbsp;{$remaining}&nbsp;min remaining\n";
                    $refresh = 1;
                    $text .= "    </TD>\n";
                    $text .= "    <TD>\n";
                    $text .= "      <FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
                    $cdata = array('requestid' => $requests[$i]['id']);
                    $cont = addContinuationsEntry('confirmDeleteRequest', $cdata, SECINDAY);
                    $text .= "      <INPUT type=hidden name=continuation value=\"{$cont}\">\n";
                    $text .= "      <INPUT type=submit value=Delete>\n";
                    $text .= "      </FORM>\n";
                    $text .= "    </TD>\n";
                }
            } else {
                # reservation is in the future
                $text .= "    <TD></TD>\n";
                $text .= "    <TD>\n";
                $text .= "      <FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
                $cdata = array('requestid' => $requests[$i]['id']);
                $cont = addContinuationsEntry('confirmDeleteRequest', $cdata, SECINDAY);
                $text .= "      <INPUT type=hidden name=continuation value=\"{$cont}\">\n";
                $text .= "      <INPUT type=submit value=Delete>\n";
                $text .= "      </FORM>\n";
                $text .= "    </TD>\n";
            }
            if (!$noedit) {
                # print edit button
                $text .= "    <TD align=right>\n";
                $text .= "      <FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
                $cdata = array('requestid' => $requests[$i]['id']);
                $cont = addContinuationsEntry('editRequest', $cdata);
                $text .= "      <INPUT type=hidden name=continuation value=\"{$cont}\">\n";
                $text .= "      <INPUT type=submit value=Edit>\n";
                $text .= "      </FORM>\n";
                $text .= "    </TD>\n";
            } elseif ($requests[$i]['forimaging'] == 0) {
                $text .= "    <TD></TD>\n";
            }
            # print name of image, add (Testing) if it is the test version of an image
            $text .= "    <TD>" . str_replace("'", "&#39;", $requests[$i]["prettyimage"]);
            if ($requests[$i]["test"]) {
                $text .= " (Testing)";
            }
            $text .= "</TD>\n";
            # print start time
            if (datetimeToUnix($requests[$i]["start"]) < datetimeToUnix($requests[$i]["daterequested"])) {
                $text .= "    <TD>" . prettyDatetime($requests[$i]["daterequested"]) . "</TD>\n";
            } else {
                $text .= "    <TD>" . prettyDatetime($requests[$i]["start"]) . "</TD>\n";
            }
            # print end time
            $text .= "    <TD>" . prettyDatetime($requests[$i]["end"]) . "</TD>\n";
            # print date requested
            $text .= "    <TD>" . prettyDatetime($requests[$i]["daterequested"]) . "</TD>\n";
            if ($viewmode == ADMIN_DEVELOPER) {
                $text .= "    <TD align=center>" . $requests[$i]["id"] . "</TD>\n";
                $text .= "    <TD align=center>" . $requests[$i]["computerid"] . "</TD>\n";
                $text .= "    <TD>" . $requests[$i]["IPaddress"] . "</TD>\n";
                $text .= "    <TD align=center>" . $requests[$i]["currstateid"];
                $text .= "</TD>\n";
                $text .= "    <TD align=center>" . $requests[$i]["laststateid"];
                $text .= "</TD>\n";
                $text .= "    <TD align=center>";
                $text .= $computers[$requests[$i]["computerid"]]["stateid"] . "</TD>\n";
            }
            $text .= "  </TR>\n";
            if ($requests[$i]['forimaging']) {
                $imaging .= $text;
            } elseif ($requests[$i]['longterm']) {
                $long .= $text;
            } else {
                $normal .= $text;
            }
        }
    }
    $text = "<H2>Current Reservations</H2>\n";
    if (!empty($normal)) {
        if (!empty($imaging) || !empty($long)) {
            $text .= "You currently have the following <strong>normal</strong> reservations:<br>\n";
        } else {
            $text .= "You currently have the following normal reservations:<br>\n";
        }
        if ($lengthchanged) {
            $text .= "<font color=red>NOTE: The maximum allowed reservation ";
            $text .= "length for one of these reservations was less than the ";
            $text .= "length you submitted, and the length of that reservation ";
            $text .= "has been adjusted accordingly.</font>\n";
        }
        $text .= "<table id=reslisttable summary=\"lists reservations you currently have\" cellpadding=5>\n";
        $text .= "  <TR>\n";
        $text .= "    <TD colspan=3></TD>\n";
        $text .= "    <TH>Environment</TH>\n";
        $text .= "    <TH>Starting</TH>\n";
        $text .= "    <TH>Ending</TH>\n";
        $text .= "    <TH>Initially requested</TH>\n";
        if ($viewmode == ADMIN_DEVELOPER) {
            $text .= "    <TH>Req ID</TH>\n";
            $text .= "    <TH>Comp ID</TH>\n";
            $text .= "    <TH>IP address</TH>\n";
            $text .= "    <TH>Current State</TH>\n";
            $text .= "    <TH>Last State</TH>\n";
            $text .= "    <TH>Computer State</TH>\n";
        }
        $text .= "  </TR>\n";
        $text .= $normal;
        $text .= "</table>\n";
    }
    if (!empty($imaging)) {
        if (!empty($normal)) {
            $text .= "<hr>\n";
        }
        $text .= "You currently have the following <strong>imaging</strong> reservations:<br>\n";
        $text .= "<table id=imgreslisttable summary=\"lists imaging reservations you currently have\" cellpadding=5>\n";
        $text .= "  <TR>\n";
        $text .= "    <TD colspan=3></TD>\n";
        $text .= "    <TH>Environment</TH>\n";
        $text .= "    <TH>Starting</TH>\n";
        $text .= "    <TH>Ending</TH>\n";
        $text .= "    <TH>Initially requested</TH>\n";
        $computers = getComputers();
        if ($viewmode == ADMIN_DEVELOPER) {
            $text .= "    <TH>Req ID</TH>\n";
            $text .= "    <TH>Comp ID</TH>\n";
            $text .= "    <TH>IP address</TH>\n";
            $text .= "    <TH>Current State</TH>\n";
            $text .= "    <TH>Last State</TH>\n";
            $text .= "    <TH>Computer State</TH>\n";
        }
        $text .= "  </TR>\n";
        $text .= $imaging;
        $text .= "</table>\n";
    }
    if (!empty($long)) {
        if (!empty($normal) || !empty($imaging)) {
            $text .= "<hr>\n";
        }
        $text .= "You currently have the following <strong>long term</strong> reservations:<br>\n";
        $text .= "<table id=\"longreslisttable\" summary=\"lists long term reservations you currently have\" cellpadding=5>\n";
        $text .= "  <TR>\n";
        $text .= "    <TD colspan=3></TD>\n";
        $text .= "    <TH>Environment</TH>\n";
        $text .= "    <TH>Starting</TH>\n";
        $text .= "    <TH>Ending</TH>\n";
        $text .= "    <TH>Initially requested</TH>\n";
        $computers = getComputers();
        if ($viewmode == ADMIN_DEVELOPER) {
            $text .= "    <TH>Req ID</TH>\n";
            $text .= "    <TH>Comp ID</TH>\n";
            $text .= "    <TH>IP address</TH>\n";
            $text .= "    <TH>Current State</TH>\n";
            $text .= "    <TH>Last State</TH>\n";
            $text .= "    <TH>Computer State</TH>\n";
        }
        $text .= "  </TR>\n";
        $text .= $long;
        $text .= "</table>\n";
    }
    # connect div
    if ($connect) {
        $text .= "<br><br>Click the <strong>";
        $text .= "Connect!</strong> button to get further ";
        $text .= "information about connecting to the reserved system. You must ";
        $text .= "click the button from a web browser running on the same computer ";
        $text .= "from which you will be connecting to the remote computer; ";
        $text .= "otherwise, you may be denied access to the machine.\n";
    }
    if ($refresh) {
        $text .= "<br><br>This page will automatically update ";
        $text .= "every 20 seconds until the <font color=red><i>Pending...</i>";
        #$text .= "</font> reservation is ready.<br></div>\n";
        $text .= "</font> reservation is ready.\n";
        $cont = addContinuationsEntry('AJviewRequests', $cdata, SECINDAY);
        $text .= "<INPUT type=hidden id=resRefreshCont value=\"{$cont}\">\n";
    }
    if ($failed) {
        $text .= "<br><br>An error has occurred that has kept one of your reservations ";
        $text .= "from being processed. We apologize for any inconvenience ";
        $text .= "this may have caused.\n";
        if (!$refresh) {
            $cont = addContinuationsEntry('AJviewRequests', $cdata, SECINDAY);
            $text .= "<INPUT type=hidden id=resRefreshCont value=\"{$cont}\">\n";
        }
    }
    if (empty($normal) && empty($imaging) && empty($long)) {
        $text .= "You have no current reservations.<br>\n";
    }
    $text .= "</div>\n";
    if ($mode != 'AJviewRequests') {
        if ($refresh || $failed) {
            $text .= "<div dojoType=FloatingPane\n";
            $text .= "      id=resStatusPane\n";
            $text .= "      constrainToContainer=false\n";
            $text .= "      hasShadow=true\n";
            $text .= "      resizable=true\n";
            $text .= "      windowState=minimized\n";
            $text .= "      displayMinimizeAction=true\n";
            $text .= "      style=\"width: 350px; height: 280px; position: absolute; left: 130; top: 0px;\"\n";
            $text .= ">\n";
            $text .= "<div id=resStatusText></div>\n";
            $text .= "<input type=hidden id=detailreqid value=0>\n";
            $text .= "</div>\n";
            $text .= "<script type=\"text/javascript\">\n";
            $text .= "dojo.addOnLoad(showScriptOnly);\n";
            $text .= "dojo.byId('resStatusPane').title = \"Detailed Reservation Status\";\n";
            $text .= "</script>\n";
        }
        print $text;
    } else {
        $text = str_replace("\n", ' ', $text);
        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);
        }
        dbDisconnect();
        exit;
    }
}
Example #4
0
function XMLRPCgetRequestConnectData($requestid, $remoteIP)
{
    global $user;
    $requestid = processInputData($requestid, ARG_NUMERIC);
    $remoteIP = processInputData($remoteIP, ARG_STRING, 1);
    if (!preg_match('/^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})$/', $remoteIP, $matches) || $matches[1] < 1 || $matches[1] > 223 || $matches[2] > 255 || $matches[3] > 255 || $matches[4] > 255) {
        return array('status' => 'error', 'errorcode' => 2, 'errormsg' => 'invalid IP address');
    }
    $userRequests = getUserRequests('all', $user['id']);
    $found = 0;
    foreach ($userRequests as $req) {
        if ($req['id'] == $requestid) {
            $request = $req;
            $found = 1;
            break;
        }
    }
    if (!$found) {
        return array('status' => 'error', 'errorcode' => 1, 'errormsg' => 'unknown requestid');
    }
    // FIXME - add support for cluster requests
    if (requestIsReady($request)) {
        $requestData = getRequestInfo($requestid);
        $query = "UPDATE reservation " . "SET remoteIP = '{$remoteIP}' " . "WHERE requestid = {$requestid}";
        $qh = doQuery($query, 101);
        addChangeLogEntry($requestData["logid"], $remoteIP);
        $serverIP = $requestData["reservations"][0]["connectIP"];
        $passwd = $requestData["reservations"][0]["password"];
        $connectMethods = getImageConnectMethodTexts($requestData["reservations"][0]["imageid"], $requestData["reservations"][0]["imagerevisionid"]);
        if ($requestData["forimaging"]) {
            $thisuser = '******';
        } else {
            if (preg_match('/(.*)@(.*)/', $user['unityid'], $matches)) {
                $thisuser = $matches[1];
            } else {
                $thisuser = $user['unityid'];
            }
        }
        $natports = getNATports($requestData['reservations'][0]['reservationid']);
        $portdata = array();
        foreach ($connectMethods as $key => $cm) {
            $connecttext = $cm["connecttext"];
            $connecttext = preg_replace("/#userid#/", $thisuser, $connecttext);
            $connecttext = preg_replace("/#password#/", $passwd, $connecttext);
            $connecttext = preg_replace("/#connectIP#/", $serverIP, $connecttext);
            foreach ($cm['ports'] as $port) {
                if (!empty($natports) && array_key_exists($port['key'], $natports[$key])) {
                    $connecttext = preg_replace("/{$port['key']}/", $natports[$key][$port['key']]['publicport'], $connecttext);
                    $connectMethods[$key]['connectports'][] = "{$port['protocol']}:{$port['port']}:{$natports[$key][$port['key']]['publicport']}";
                } else {
                    if ((preg_match('/remote desktop/i', $cm['description']) || preg_match('/RDP/i', $cm['description'])) && $port['key'] == '#Port-TCP-3389#') {
                        $connecttext = preg_replace("/{$port['key']}/", $user['rdpport'], $connecttext);
                        $connectMethods[$key]['connectports'][] = "{$port['protocol']}:{$port['port']}:{$user['rdpport']}";
                    } else {
                        $connecttext = preg_replace("/{$port['key']}/", $port['port'], $connecttext);
                        $connectMethods[$key]['connectports'][] = "{$port['protocol']}:{$port['port']}:{$port['port']}";
                    }
                }
            }
            $connectMethods[$key]["connecttext"] = $connecttext;
            $portdata[$key] = $connectMethods[$key]['ports'];
            unset($connectMethods[$key]['ports']);
        }
        $tmp = array_keys($portdata);
        $cmid = $tmp[0];
        if (empty($natports)) {
            if ((preg_match('/remote desktop/i', $connectMethods[$cmid]['description']) || preg_match('/RDP/i', $connectMethods[$cmid]['description'])) && $portdata[$cmid][0]['port'] == 3389) {
                $connectport = $user['rdpport'];
            } else {
                $connectport = $portdata[$cmid][0]['port'];
            }
        } else {
            $key = $portdata[$cmid][0]['key'];
            $connectport = $natports[$cmid][$key]['publicport'];
        }
        return array('status' => 'ready', 'serverIP' => $serverIP, 'user' => $thisuser, 'password' => $passwd, 'connectport' => $connectport, 'connectMethods' => $connectMethods);
    }
    return array('status' => 'notready');
}