Esempio n. 1
0
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' => i("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' => i("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(i("Delete reservation for %s starting %s?"), "<b>{$reservation["prettyimage"]}</b>", prettyDatetime($request["start"]));
    } else {
        if ($notbyowner == 0 && !$reservation["production"] && count($request['reservations']) == 1) {
            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(i("Are you finished with your reservation for %s that started %s?"), "<b>{$reservation["prettyimage"]}</b>", $showstart);
            } else {
                $userinfo = getUserInfo($request["userid"], 1, 1);
                $text = sprintf(i("Delete reservation by %s for %s that started %s?"), "{$userinfo['unityid']}@{$userinfo['affiliation']}", "<b>{$reservation["prettyimage"]}</b>", $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<br>', $text) . '<br>';
    $data = array('content' => $text, 'cont' => $cont, 'requestid' => $requestid, 'status' => 'success', 'btntxt' => i('Delete Reservation'));
    sendJSON($data);
}
Esempio n. 2
0
 function checkResourceInUse($rscid)
 {
     $msgs = array();
     # check reservations
     $query = "SELECT rq.end " . "FROM request rq, " . "reservation rs " . "WHERE rs.requestid = rq.id AND " . "rs.imageid = {$rscid} AND " . "rq.stateid NOT IN (1, 12) AND " . "rq.end > NOW() " . "ORDER BY rq.end DESC " . "LIMIT 1";
     $qh = doQuery($query);
     if ($row = mysql_fetch_assoc($qh)) {
         $msgs[] = sprintf(i("There is at least one <strong>reservation</strong> for this image. The latest end time is %s."), prettyDatetime($row['end'], 1));
     }
     # check blockComputers
     $query = "SELECT br.name, " . "bt.end " . "FROM blockRequest br, " . "blockTimes bt, " . "blockComputers bc " . "WHERE bc.imageid = {$rscid} AND " . "bc.blockTimeid = bt.id AND " . "bt.blockRequestid = br.id AND " . "bt.end > NOW() AND " . "bt.skip = 0 AND " . "br.status = 'accepted' " . "ORDER BY bt.end DESC " . "LIMIT 1";
     $qh = doQuery($query);
     if ($row = mysql_fetch_assoc($qh)) {
         $msgs[] = sprintf(i("There is at least one <strong>Block Allocation</strong> with computers currently allocated with this image. Block Allocation %s has the latest end time which is %s."), $row['name'], prettyDatetime($row['end'], 1));
     }
     # check blockRequest
     $query = "SELECT br.name, " . "bt.end " . "FROM blockRequest br, " . "blockTimes bt " . "WHERE br.imageid = {$rscid} AND " . "bt.blockRequestid = br.id AND " . "bt.end > NOW() AND " . "bt.skip = 0 AND " . "br.status = 'accepted' " . "ORDER BY bt.end DESC " . "LIMIT 1";
     $qh = doQuery($query);
     if ($row = mysql_fetch_assoc($qh)) {
         $msgs[] = sprintf(i("There is at least one <strong>Block Allocation</strong> configured to use this image. Block Allocation %s has the latest end time which is %s."), $row['name'], prettyDatetime($row['end'], 1));
     }
     # check serverprofile
     $query = "SELECT name " . "FROM serverprofile " . "WHERE imageid = {$rscid}";
     $qh = doQuery($query);
     $profiles = array();
     while ($row = mysql_fetch_assoc($qh)) {
         $profiles[] = $row['name'];
     }
     if (count($profiles)) {
         $msgs[] = i("The following <strong>Server Profiles</strong> are configured to use this image:") . "<br><br>\n" . implode("<br>\n", $profiles);
     }
     # check subimages
     $query = "SELECT DISTINCT i.prettyname " . "FROM image i, " . "imagemeta im, " . "subimages s " . "WHERE i.imagemetaid = im.id AND " . "im.subimages = 1 AND " . "s.imagemetaid = im.id AND " . "s.imageid = {$rscid}";
     $images = array();
     while ($row = mysql_fetch_assoc($qh)) {
         $images[] = $row['prettyname'];
     }
     if (count($images)) {
         $msgs[] = i("The following <strong>images</strong> have the selected image assigned as a <strong>subimage</strong>:") . "<br><br>\n" . implode("<br>\n", $images);
     }
     # check vmprofile
     $query = "SELECT profilename " . "FROM vmprofile " . "WHERE imageid = {$rscid}";
     $profiles = array();
     while ($row = mysql_fetch_assoc($qh)) {
         $profiles[] = $row['profilename'];
     }
     if (count($profiles)) {
         $msgs[] = i("The following <strong>VM Host Profiles</strong> have the this image selected:") . "<br><br>\n" . implode("<br>\n", $profiles);
     }
     if (empty($msgs)) {
         return '';
     }
     $msg = i("The selected image is currently being used in the following ways and cannot be deleted at this time.") . "<br><br>\n";
     $msg .= implode("<br><br>\n", $msgs) . "<br><br>\n";
     return $msg;
 }
Esempio n. 3
0
 function AJshowReservationHistory()
 {
     $compids = $this->validateCompIDs();
     if (array_key_exists('error', $compids)) {
         $ret = array('status' => 'error', 'errormsg' => $compids['msg']);
         sendJSON($ret);
         return;
     }
     if (count($compids) == 0) {
         $ret = array('status' => 'noaction');
         sendJSON($ret);
         return;
     }
     $complist = implode(',', $compids);
     $query = "SELECT UNIX_TIMESTAMP(l.start) AS start, " . "UNIX_TIMESTAMP(l.finalend) AS end, " . "i.prettyname AS image, " . "ir.revision, " . "c.hostname AS hostname, " . "mn.hostname AS managementnode, " . "l.ending, " . "CONCAT(u.unityid, '@', a.name) AS username " . "FROM computer c " . "LEFT JOIN sublog s ON (c.id = s.computerid) " . "LEFT JOIN image i ON (s.imageid = i.id) " . "LEFT JOIN imagerevision ir ON (s.imagerevisionid = ir.id) " . "LEFT JOIN managementnode mn ON (s.managementnodeid = mn.id) " . "LEFT JOIN log l ON (s.logid = l.id) " . "LEFT JOIN user u ON (l.userid = u.id) " . "LEFT JOIN affiliation a ON (u.affiliationid = a.id) " . "WHERE c.id IN ({$complist}) " . "ORDER BY c.hostname, " . "l.start DESC";
     $qh = doQuery($query);
     $data = array();
     while ($row = mysql_fetch_assoc($qh)) {
         if (!is_numeric($row['end'])) {
             continue;
         }
         $msg = "<strong>{$row['hostname']}</strong><br>";
         if ($row['start'] == '') {
             $msg .= "(No reservations)<br><hr>";
             $data[] = array('name' => $row['hostname'], 'msg' => $msg);
             continue;
         }
         $msg .= "User: {$row['username']}<br>";
         $msg .= "Image: {$row['image']}<br>";
         $msg .= "Revision: {$row['revision']}<br>";
         $msg .= "Start: " . prettyDatetime($row['start'], 1) . "<br>";
         if ($row['end'] == datetimeToUnix('2038-01-01 00:00:00')) {
             $msg .= "End: (indefinite)<br>";
         } else {
             $msg .= "End: " . prettyDatetime($row['end'], 1) . "<br>";
         }
         $msg .= "Management Node: {$row['managementnode']}<br>";
         $msg .= "Ending: {$row['ending']}<br>";
         $msg .= "<hr>";
         $data[] = array('name' => $row['hostname'], 'msg' => $msg);
     }
     $msg = '';
     foreach ($data as $item) {
         $msg .= $item['msg'];
     }
     $msg = substr($msg, 0, -4);
     $ret = array('status' => 'onestep', 'title' => 'Reservation History', 'actionmsg' => $msg);
     sendJSON($ret);
 }
Esempio n. 4
0
function submitCreateImage()
{
    global $submitErr, $user, $viewmode, $HTMLheader, $printedHTMLheader, $mode;
    if ($mode == 'submitCreateTestProd') {
        $data = getContinuationVar();
        $data["revisionid"] = processInputVar("revisionid", ARG_MULTINUMERIC);
        # TODO check for valid revisionid
    } else {
        $data = processRequestInput(0);
        $data['length'] = getContinuationVar('length');
    }
    $showrevisions = 0;
    $subimages = 0;
    $images = getImages();
    $revcount = count($images[$data['imageid']]['imagerevision']);
    if ($revcount > 1) {
        $showrevisions = 1;
    }
    if ($images[$data['imageid']]['imagemetaid'] != NULL && count($images[$data['imageid']]['subimages'])) {
        $subimages = 1;
        foreach ($images[$data['imageid']]['subimages'] as $subimage) {
            $revcount = count($images[$subimage]['imagerevision']);
            if ($revcount > 1) {
                $showrevisions = 1;
            }
        }
    }
    if ($data["time"] == "now") {
        $nowArr = getdate();
        if ($nowArr["minutes"] == 0) {
            $subtract = 0;
            $add = 0;
        } elseif ($nowArr["minutes"] < 15) {
            $subtract = $nowArr["minutes"] * 60;
            $add = 900;
        } elseif ($nowArr["minutes"] < 30) {
            $subtract = ($nowArr["minutes"] - 15) * 60;
            $add = 900;
        } elseif ($nowArr["minutes"] < 45) {
            $subtract = ($nowArr["minutes"] - 30) * 60;
            $add = 900;
        } elseif ($nowArr["minutes"] < 60) {
            $subtract = ($nowArr["minutes"] - 45) * 60;
            $add = 900;
        }
        $start = time() - $subtract;
        $start -= $start % 60;
        $nowfuture = "now";
    } else {
        $add = 0;
        $hour = $data["hour"];
        if ($data["hour"] == 12) {
            if ($data["meridian"] == "am") {
                $hour = 0;
            }
        } elseif ($data["meridian"] == "pm") {
            $hour = $data["hour"] + 12;
        }
        $tmp = explode('/', $data["day"]);
        $start = mktime($hour, $data["minute"], "0", $tmp[0], $tmp[1], $tmp[2]);
        if ($start < time()) {
            print $HTMLheader;
            print "<H2>Create / Update an Image</H2>\n";
            print "<font color=\"#ff0000\">The time you requested is in the past.";
            print " Please select \"Now\" or use a time in the future.</font><br>\n";
            $submitErr = 1;
            createSelectImage();
            return;
        }
        $nowfuture = "future";
    }
    // FIXME hard code length to 8 hours
    $data["length"] = 480;
    $end = $start + $data["length"] * 60 + $add;
    // get semaphore lock
    if (!semLock()) {
        abort(3);
    }
    $max = getMaxOverlap($user['id']);
    if (checkOverlap($start, $end, $max)) {
        $printedHTMLheader = 1;
        print $HTMLheader;
        print "<H2>New Reservation</H2>\n";
        if ($max == 0) {
            print "<font color=\"#ff0000\">The time you requested overlaps with ";
            print "another reservation you currently have.  You are only allowed ";
            print "to have a single reservation at any given time. Please select ";
            print "another time to use the application. If you are finished with ";
            print "an active reservation, click \"Current Reservations\", ";
            print "then click the \"End\" button of your active reservation.";
            print "</font><br><br>\n";
        } else {
            print "<font color=\"#ff0000\">The time you requested overlaps with ";
            print "another reservation you currently have.  You are allowed ";
            print "to have {$max} overlapping reservations at any given time. ";
            print "Please select another time to use the application. If you are ";
            print "finished with an active reservation, click \"Current ";
            print "Reservations\", then click the \"End\" button of your active ";
            print "reservation.</font><br><br>\n";
        }
        $submitErr = 1;
        createSelectImage();
        return;
    }
    // if user is owner of the image and there is a test revision of the image
    #   available, ask user if production or test image desired
    if ($mode != "submitCreateTestProd" && $showrevisions && $images[$data["imageid"]]["ownerid"] == $user["id"]) {
        $printedHTMLheader = 1;
        print $HTMLheader;
        print "<H2>New Reservation</H2>\n";
        if ($subimages) {
            print "This is a cluster environment. At least one image in the ";
            print "cluster has more than one revision available. Please select ";
            print "the revision you desire for each image listed below:<br>\n";
        } else {
            print "There are multiple revisions of this environment available.  Please ";
            print "select the revision you would like to check out:<br>\n";
        }
        print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post><br>\n";
        if (!array_key_exists('subimages', $images[$data['imageid']])) {
            $images[$data['imageid']]['subimages'] = array();
        }
        array_unshift($images[$data['imageid']]['subimages'], $data['imageid']);
        foreach ($images[$data['imageid']]['subimages'] as $subimage) {
            print "{$images[$subimage]['prettyname']}:<br>\n";
            print "<table summary=\"lists revisions of the selected environment, one must be selected to continue\">\n";
            print "  <TR>\n";
            print "    <TD></TD>\n";
            print "    <TH>Revision</TH>\n";
            print "    <TH>Creator</TH>\n";
            print "    <TH>Created</TH>\n";
            print "    <TH>Currently in Production</TH>\n";
            print "  </TR>\n";
            foreach ($images[$subimage]['imagerevision'] as $revision) {
                print "  <TR>\n";
                if (array_key_exists($subimage, $data['revisionid']) && $data['revisionid'][$subimage] == $revision['id']) {
                    print "    <TD align=center><INPUT type=radio name=revisionid[{$subimage}] value={$revision['id']} checked></TD>\n";
                } elseif ($revision['production']) {
                    print "    <TD align=center><INPUT type=radio name=revisionid[{$subimage}] value={$revision['id']} checked></TD>\n";
                } else {
                    print "    <TD align=center><INPUT type=radio name=revisionid[{$subimage}] value={$revision['id']}></TD>\n";
                }
                print "    <TD align=center>{$revision['revision']}</TD>\n";
                print "    <TD align=center>{$revision['user']}</TD>\n";
                print "    <TD align=center>{$revision['prettydate']}</TD>\n";
                if ($revision['production']) {
                    print "    <TD align=center>Yes</TD>\n";
                } else {
                    print "    <TD align=center>No</TD>\n";
                }
                print "  </TR>\n";
            }
            print "</TABLE>\n";
        }
        addContinuationsEntry('submitCreateImage', array(), SECINDAY, 1, 0);
        // we add this continuation back
        //   so the currently displayed
        //   page can be reloaded
        $cont = addContinuationsEntry('submitCreateTestProd', $data);
        print "<br><INPUT type=hidden name=continuation value=\"{$cont}\">\n";
        print "<INPUT type=submit value=Submit>\n";
        print "</FORM>\n";
        return;
    }
    $rc = isAvailable($images, $data["imageid"], $start, $end, $data["os"], 0, 0, 0, 1);
    if ($rc == -1) {
        $printedHTMLheader = 1;
        print $HTMLheader;
        print "<H2>Create / Update an Image</H2>\n";
        print "You have requested an environment that is limited in the number ";
        print "of concurrent reservations that can be made. No further ";
        print "reservations for the environment can be made for the time you ";
        print "have selected. Please select another time to use the ";
        print "environment.<br>";
    } elseif ($rc > 0) {
        $requestid = addRequest(1, $data['revisionid']);
        if ($data["time"] == "now") {
            header("Location: " . BASEURL . SCRIPT . "?mode=viewRequests");
            dbDisconnect();
            exit;
        } else {
            $time = prettyLength($data["length"]);
            if ($data["minute"] == 0) {
                $data["minute"] = "00";
            }
            $printedHTMLheader = 1;
            print $HTMLheader;
            print "<H2>Create / Update an Image</H2>\n";
            print "Your request to use <b>" . $images[$data["imageid"]]["prettyname"];
            print "</b> on " . prettyDatetime($start) . " for {$time} has been ";
            print "accepted.<br><br>\n";
            print "When your reservation time has been reached, the ";
            print "<b>Current Reservations</b> page will give you more ";
            print "information on connecting to the reserved computer. If you ";
            print "would like to modify your reservation, you can do that from ";
            print "the <b>Current Reservations</b> page as well.<br>\n";
        }
    } else {
        $printedHTMLheader = 1;
        print $HTMLheader;
        $cdata = array('imageid' => $data['imageid'], 'length' => $data['length']);
        $cont = addContinuationsEntry('selectTimeTable', $cdata);
        print "<H2>Create / Update an Image</H2>\n";
        print "The reservation you have requested is not available. You may ";
        print "<a href=\"" . BASEURL . SCRIPT . "?continuation={$cont}\">";
        print "view a timetable</a> of free and reserved times to find ";
        print "a time that will work for you.<br>\n";
        #addLogEntry($nowfuture, unixToDatetime($start),
        #            unixToDatetime($end), 0, $data["imageid"]);
    }
}
Esempio n. 5
0
function submitDeleteRequest()
{
    $requestid = getContinuationVar('requestid', 0);
    $request = getRequestInfo($requestid);
    if ($request['forimaging']) {
        $reservation = $request['reservations'][0];
    } else {
        foreach ($request["reservations"] as $res) {
            if ($res["forcheckout"]) {
                $reservation = $res;
                break;
            }
        }
    }
    deleteRequest($request);
    if (datetimeToUnix($request["start"]) > time()) {
        print "<H2>Delete Reservation</H2>";
        print "The reservation for <b>" . $reservation["prettyimage"];
        print "</b> starting " . prettyDatetime($request["start"]);
        print " has been deleted.<br>\n";
    } else {
        print "<H2>End Reservation</H2>";
        print "The reservation for <b>" . $reservation["prettyimage"];
        print "</b> starting ";
        if (datetimeToUnix($request["start"]) < datetimeToUnix($request["daterequested"])) {
            print prettyDatetime($request["daterequested"]);
        } else {
            print prettyDatetime($request["start"]);
        }
        print " has been released.<br>\n";
    }
}
Esempio n. 6
0
function userLookup()
{
    global $user, $viewmode;
    $userid = processInputVar("userid", ARG_STRING);
    print "<div align=center>\n";
    print "<H2>User Lookup</H2>\n";
    print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
    print "<TABLE>\n";
    print "  <TR>\n";
    print "    <TH>User ID:</TH>\n";
    print "    <TD><INPUT type=text name=userid value=\"{$userid}\" size=25></TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TD></TD>\n";
    print "    <TD align=right><INPUT type=submit value=Submit>\n";
    print "  </TR>\n";
    print "</TABLE>\n";
    $cont = addContinuationsEntry('submitUserLookup');
    print "<INPUT type=hidden name=continuation value=\"{$cont}\">\n";
    print "</FORM>\n";
    if (!empty($userid)) {
        $loginid = $userid;
        getAffilidAndLogin($loginid, $affilid);
        if (empty($affilid)) {
            print "{$matches[2]} is an unknown affiliation<br>\n";
            return;
        }
        if ($viewmode != ADMIN_DEVELOPER && $user['affiliationid'] != $affilid) {
            print "You are only allowed to look up users from your own affiliation.<br>\n";
            return;
        }
        $query = "SELECT id " . "FROM user " . "WHERE unityid = '{$loginid}' AND " . "affiliationid = {$affilid}";
        $qh = doQuery($query, 101);
        if (!mysql_num_rows($qh)) {
            print "<font color=red>{$userid} not currently found in VCL user database, will try to add...</font><br>\n";
        }
        $userdata = getUserInfo($userid);
        if (is_null($userdata)) {
            print "<font color=red>{$userid} not found in any known systems</font><br>\n";
            return;
        }
        print "<TABLE>\n";
        print "  <TR>\n";
        print "    <TH align=right>First Name:</TH>\n";
        print "    <TD>{$userdata["firstname"]}</TD>\n";
        print "  </TR>\n";
        print "  <TR>\n";
        print "    <TH align=right>Last Name:</TH>\n";
        print "    <TD>{$userdata["lastname"]}</TD>\n";
        print "  </TR>\n";
        print "  <TR>\n";
        print "    <TH align=right>Preferred Name:</TH>\n";
        print "    <TD>{$userdata["preferredname"]}</TD>\n";
        print "  </TR>\n";
        print "  <TR>\n";
        print "    <TH align=right>Email:</TH>\n";
        print "    <TD>{$userdata["email"]}</TD>\n";
        print "  </TR>\n";
        print "  <TR>\n";
        print "    <TH align=right>Admin Level:</TH>\n";
        print "    <TD>{$userdata["adminlevel"]}</TD>\n";
        print "  </TR>\n";
        print "  <TR>\n";
        print "    <TH align=right style=\"vertical-align: top\">Groups:</TH>\n";
        print "    <TD>\n";
        uasort($userdata["groups"], "sortKeepIndex");
        foreach ($userdata["groups"] as $group) {
            print "      {$group}<br>\n";
        }
        print "    </TD>\n";
        print "  </TR>\n";
        print "  <TR>\n";
        print "    <TH align=right style=\"vertical-align: top\">Privileges (found somewhere in the tree):</TH>\n";
        print "    <TD>\n";
        uasort($userdata["privileges"], "sortKeepIndex");
        foreach ($userdata["privileges"] as $priv) {
            if ($priv == "block" || $priv == "cascade") {
                continue;
            }
            print "      {$priv}<br>\n";
        }
        print "    </TD>\n";
        print "  </TR>\n";
        print "</TABLE>\n";
        # get user's resources
        $userResources = getUserResources(array("imageCheckOut"), array("available"), 0, 0, $userdata['id']);
        # find nodes where user has privileges
        $query = "SELECT p.name AS privnode, " . "upt.name AS userprivtype, " . "up.privnodeid " . "FROM userpriv up, " . "privnode p, " . "userprivtype upt " . "WHERE up.privnodeid = p.id AND " . "up.userprivtypeid = upt.id AND " . "up.userid = {$userdata['id']} " . "ORDER BY p.name, " . "upt.name";
        $qh = doQuery($query, 101);
        if (mysql_num_rows($qh)) {
            print "Nodes where user is granted privileges:<br>\n";
            print "<TABLE>\n";
            $privnodeid = 0;
            while ($row = mysql_fetch_assoc($qh)) {
                if ($privnodeid != $row['privnodeid']) {
                    if ($privnodeid) {
                        print "    </TD>\n";
                        print "  </TR>\n";
                    }
                    print "  <TR>\n";
                    $privnodeid = $row['privnodeid'];
                    print "    <TH align=right>{$row['privnode']}</TH>\n";
                    print "    <TD>\n";
                }
                print "      {$row['userprivtype']}<br>\n";
            }
            print "    </TD>\n";
            print "  </TR>\n";
            print "</TABLE>\n";
        }
        # find nodes where user's groups have privileges
        if (!empty($userdata['groups'])) {
            $query = "SELECT DISTINCT p.name AS privnode, " . "upt.name AS userprivtype, " . "up.privnodeid " . "FROM userpriv up, " . "privnode p, " . "userprivtype upt " . "WHERE up.privnodeid = p.id AND " . "up.userprivtypeid = upt.id AND " . "upt.name != 'cascade' AND " . "upt.name != 'block' AND " . "up.usergroupid IN (" . implode(',', array_keys($userdata['groups'])) . ") " . "ORDER BY p.name, " . "upt.name";
            $qh = doQuery($query, 101);
            if (mysql_num_rows($qh)) {
                print "Nodes where user's groups are granted privileges:<br>\n";
                print "<TABLE>\n";
                $privnodeid = 0;
                while ($row = mysql_fetch_assoc($qh)) {
                    if ($privnodeid != $row['privnodeid']) {
                        if ($privnodeid) {
                            print "    </TD>\n";
                            print "  </TR>\n";
                        }
                        print "  <TR>\n";
                        $privnodeid = $row['privnodeid'];
                        print "    <TH align=right>{$row['privnode']}</TH>\n";
                        print "    <TD>\n";
                    }
                    print "      {$row['userprivtype']}<br>\n";
                }
                print "    </TD>\n";
                print "  </TR>\n";
                print "</TABLE>\n";
            }
        }
        print "<table>\n";
        print "  <tr>\n";
        print "    <th>Images User Has Access To:<th>\n";
        print "    <td>\n";
        foreach ($userResources['image'] as $img) {
            print "      {$img}<br>\n";
        }
        print "    </td>\n";
        print "  </tr>\n";
        print "</table>\n";
        $requests = array();
        $query = "SELECT l.start AS start, " . "l.finalend AS end, " . "c.hostname, " . "i.prettyname AS prettyimage, " . "l.ending " . "FROM log l, " . "image i, " . "computer c, " . "sublog s " . "WHERE l.userid = {$userdata["id"]} AND " . "s.logid = l.id AND " . "i.id = s.imageid AND " . "c.id = s.computerid " . "ORDER BY l.start DESC " . "LIMIT 5";
        $qh = doQuery($query, 290);
        while ($row = mysql_fetch_assoc($qh)) {
            array_push($requests, $row);
        }
        $requests = array_reverse($requests);
        if (!empty($requests)) {
            print "<h3>User's last " . count($requests) . " reservations:</h3>\n";
            print "<table>\n";
            $first = 1;
            foreach ($requests as $req) {
                $thisstart = str_replace('&nbsp;', ' ', prettyDatetime($req["start"]));
                $thisend = str_replace('&nbsp;', ' ', prettyDatetime($req["end"]));
                if ($first) {
                    $first = 0;
                } else {
                    print "  <tr>\n";
                    print "    <td colspan=2><hr></td>\n";
                    print "  </tr>\n";
                }
                print "  <tr>\n";
                print "    <th align=right>Image:</th>\n";
                print "    <td>{$req['prettyimage']}</td>\n";
                print "  </tr>\n";
                print "  <tr>\n";
                print "    <th align=right>Computer:</th>\n";
                print "    <td>{$req['hostname']}</td>\n";
                print "  </tr>\n";
                print "  <tr>\n";
                print "    <th align=right>Start:</th>\n";
                print "    <td>{$thisstart}</td>\n";
                print "  </tr>\n";
                print "  <tr>\n";
                print "    <th align=right>End:</th>\n";
                print "    <td>{$thisend}</td>\n";
                print "  </tr>\n";
                print "  <tr>\n";
                print "    <th align=right>Ending:</th>\n";
                print "    <td>{$req['ending']}</td>\n";
                print "  </tr>\n";
            }
            print "</table>\n";
        } else {
            print "User made no reservations in the past week.<br>\n";
        }
    }
    print "</div>\n";
}
Esempio n. 7
0
function submitHelpForm()
{
    global $user, $submitErr, $submitErrMsg;
    $name = processInputVar("name", ARG_STRING);
    $email = processInputVar("email", ARG_STRING);
    $summary = processInputVar("summary", ARG_STRING);
    $text = processInputVar("comments", ARG_STRING);
    if (!ereg('^([A-Za-z]{1,}( )([A-Za-z]){2,})$', $name)) {
        $submitErr |= NAMEERR;
        $submitErrMsg[NAMEERR] = "You must submit your first and last name";
    }
    if (!eregi('^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$', $email)) {
        $submitErr |= EMAILERR;
        $submitErrMsg[EMAILERR] = "Invalid email address, please correct";
    }
    if (empty($summary)) {
        $submitErr |= SUMMARYERR;
        $submitErrMsg[SUMMARYERR] = "Please fill in a very short summary of the " . "problem";
    }
    if (empty($text)) {
        $submitErr |= TEXTERR;
        $submitErrMsg[TEXTERR] = "Please fill in your problem in the box below.<br>";
    }
    if ($submitErr) {
        printHelpForm();
        return;
    }
    $computers = getComputers();
    $requests = getUserRequests("all");
    $query = "SELECT l.start AS start, " . "l.finalend AS end, " . "l.computerid AS computerid, " . "i.prettyname AS prettyimage " . "FROM log l, " . "image i " . "WHERE l.userid = " . $user["id"] . " AND " . "i.id = l.imageid AND " . "(unix_timestamp(NOW()) - unix_timestamp(l.finalend)) < 14400";
    $qh = doQuery($query, 290);
    while ($row = mysql_fetch_assoc($qh)) {
        array_push($requests, $row);
    }
    $from = $user["email"];
    if (get_magic_quotes_gpc()) {
        $text = stripslashes($text);
    }
    $message = "Problem report submitted from VCL web form:\n\n" . "User: "******"unityid"] . "\n" . "Name: " . $name . "\n" . "Email: " . $email . "\n" . "Problem description:\n\n{$text}\n\n";
    $end = time();
    $start = $end - 14400;
    $recentrequests = "";
    foreach ($requests as $request) {
        if (datetimeToUnix($request["end"]) > $start || datetimeToUnix($request["start"] < $end)) {
            $thisstart = str_replace('&nbsp;', ' ', prettyDatetime($request["start"]));
            $thisend = str_replace('&nbsp;', ' ', prettyDatetime($request["end"]));
            $recentrequests .= "Image: " . $request["prettyimage"] . "\n" . "Computer: " . $computers[$request["computerid"]]["hostname"] . "\n" . "Start: {$thisstart}\n" . "End: {$thisend}\n\n";
        }
    }
    if (!empty($recentrequests)) {
        $message .= "-----------------------------------------------\n";
        $message .= "User's recent reservations:\n\n" . $recentrequests . "\n";
    } else {
        $message .= "User has no recent reservations\n";
    }
    $indrupal = getContinuationVar('indrupal', 0);
    if (!$indrupal) {
        print "<H2>VCL Help</H2>\n";
    }
    $mailParams = "-f" . ENVELOPESENDER;
    if (!mail(HELPEMAIL, "{$summary}", $message, "From: {$from}\r\nReply-To: {$email}\r\n", $mailParams)) {
        print "The Server was unable to send mail at this time. Please e-mail ";
        print "<a href=\"mailto:" . HELPEMAIL . "\">" . HELPEMAIL . "</a> for ";
        print "help with your problem.";
    } else {
        print "Your problem report has been submitted.  Thank you for letting ";
        print "us know of your problem so that we can improve this site.<br>\n";
    }
}
Esempio n. 8
0
function submitHelpForm()
{
    global $user, $submitErr, $submitErrMsg;
    $name = processInputVar("name", ARG_STRING);
    $email = processInputVar("email", ARG_STRING);
    $summary = processInputVar("summary", ARG_STRING);
    $text = processInputVar("comments", ARG_STRING);
    $testname = $name;
    if (get_magic_quotes_gpc()) {
        $testname = stripslashes($name);
    }
    if (!preg_match('/^([-A-Za-z \']{1,} [-A-Za-z \']{2,})*$/', $testname)) {
        $submitErr |= NAMEERR;
        $submitErrMsg[NAMEERR] = "Name can only contain letters, spaces, apostrophes ('), and dashes (-)";
    }
    if (!preg_match('/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$/i', $email)) {
        $submitErr |= EMAILERR;
        $submitErrMsg[EMAILERR] = "Invalid email address, please correct";
    }
    if (empty($summary)) {
        $submitErr |= SUMMARYERR;
        $submitErrMsg[SUMMARYERR] = "Please fill in a very short summary of the " . "problem";
    }
    if (empty($text)) {
        $submitErr |= TEXTERR;
        $submitErrMsg[TEXTERR] = "Please fill in your problem in the box below.<br>";
    }
    if ($submitErr) {
        printHelpForm();
        return;
    }
    $computers = getComputers();
    $requests = array();
    $query = "SELECT l.id, " . "l.start, " . "l.finalend AS end, " . "s.computerid, " . "i.prettyname AS prettyimage " . "FROM log l, " . "image i, " . "sublog s " . "WHERE l.userid = {$user["id"]} AND " . "i.id = l.imageid AND " . "s.logid = l.id AND " . "l.finalend < DATE_ADD(NOW(), INTERVAL 1 DAY) " . "ORDER BY l.finalend DESC " . "LIMIT 5";
    $qh = doQuery($query, 290);
    while ($row = mysql_fetch_assoc($qh)) {
        # only include 1 computer from cluster reservations
        if (array_key_exists($row['id'], $requests)) {
            continue;
        }
        $requests[$row['id']] = $row;
    }
    $from = $user["email"];
    if (get_magic_quotes_gpc()) {
        $text = stripslashes($text);
    }
    $message = "Problem report submitted from VCL web form:\n\n" . "User: "******"unityid"] . "\n" . "Name: " . $testname . "\n" . "Email: " . $email . "\n" . "Problem description:\n\n{$text}\n\n";
    $recentrequests = "";
    foreach ($requests as $request) {
        $thisstart = str_replace('&nbsp;', ' ', prettyDatetime($request["start"]));
        $thisend = str_replace('&nbsp;', ' ', prettyDatetime($request["end"]));
        $recentrequests .= "Image: {$request["prettyimage"]}\n" . "Computer: {$computers[$request["computerid"]]["hostname"]}\n" . "Start: {$thisstart}\n" . "End: {$thisend}\n\n";
    }
    if (!empty($recentrequests)) {
        $message .= "-----------------------------------------------\n";
        $message .= "User's recent reservations:\n\n" . $recentrequests . "\n";
    } else {
        $message .= "User has no recent reservations\n";
    }
    $indrupal = getContinuationVar('indrupal', 0);
    if (!$indrupal) {
        print "<H2>VCL Help</H2>\n";
    }
    $mailParams = "-f" . ENVELOPESENDER;
    if (get_magic_quotes_gpc()) {
        $summary = stripslashes($summary);
    }
    if (!mail(HELPEMAIL, "{$summary}", $message, "From: {$from}\r\nReply-To: {$email}\r\n", $mailParams)) {
        print "The Server was unable to send mail at this time. Please e-mail ";
        print "<a href=\"mailto:" . HELPEMAIL . "\">" . HELPEMAIL . "</a> for ";
        print "help with your problem.";
    } else {
        print "Your problem report has been submitted.  Thank you for letting ";
        print "us know of your problem so that we can improve this site.<br>\n";
    }
}
Esempio n. 9
0
function userLookup()
{
    global $user;
    $userid = processInputVar("userid", ARG_STRING);
    if (get_magic_quotes_gpc()) {
        $userid = stripslashes($userid);
    }
    $affilid = processInputVar('affiliationid', ARG_NUMERIC, $user['affiliationid']);
    $force = processInputVar('force', ARG_NUMERIC, 0);
    print "<div align=center>\n";
    print "<H2>User Lookup</H2>\n";
    print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
    print "<TABLE>\n";
    print "  <TR>\n";
    print "    <TH>Name (last, first) or User ID:</TH>\n";
    print "    <TD><INPUT type=text name=userid value=\"{$userid}\" size=25></TD>\n";
    if (checkUserHasPerm('User Lookup (global)')) {
        $affils = getAffiliations();
        print "    <TD>\n";
        print "@";
        printSelectInput("affiliationid", $affils, $affilid);
        print "    </TD>\n";
    }
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TD colspan=2>\n";
    print "      <input type=checkbox id=force name=force value=1>\n";
    print "      <label for=force>Attempt forcing an update from LDAP (User ID only)</label>\n";
    print "    </TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TD colspan=3 align=center><INPUT type=submit value=Submit>\n";
    print "  </TR>\n";
    print "</TABLE>\n";
    $cont = addContinuationsEntry('submitUserLookup');
    print "<INPUT type=hidden name=continuation value=\"{$cont}\">\n";
    print "</FORM><br>\n";
    if (!empty($userid)) {
        $esc_userid = mysql_real_escape_string($userid);
        if (preg_match('/,/', $userid)) {
            $mode = 'name';
            $force = 0;
        } else {
            $mode = 'userid';
        }
        if (!checkUserHasPerm('User Lookup (global)') && $user['affiliationid'] != $affilid) {
            print "<font color=red>{$userid} not found</font><br>\n";
            return;
        }
        if ($mode == 'userid') {
            $query = "SELECT id " . "FROM user " . "WHERE unityid = '{$esc_userid}' AND " . "affiliationid = {$affilid}";
            $affilname = getAffiliationName($affilid);
            $userid = "{$userid}@{$affilname}";
            $esc_userid = "{$esc_userid}@{$affilname}";
        } else {
            $tmp = explode(',', $userid);
            $last = mysql_real_escape_string(trim($tmp[0]));
            $first = mysql_real_escape_string(trim($tmp[1]));
            $query = "SELECT CONCAT(u.unityid, '@', a.name) AS unityid " . "FROM user u, " . "affiliation a " . "WHERE u.firstname = '{$first}' AND " . "u.lastname = '{$last}' AND " . "u.affiliationid = {$affilid} AND " . "a.id = {$affilid}";
        }
        $qh = doQuery($query, 101);
        if (!mysql_num_rows($qh)) {
            if ($mode == 'name') {
                print "<font color=red>User not found</font><br>\n";
                return;
            } else {
                print "<font color=red>{$userid} not currently found in VCL user database, will try to add...</font><br>\n";
            }
        } elseif ($force) {
            $_SESSION['userresources'] = array();
            $row = mysql_fetch_assoc($qh);
            $newtime = unixToDatetime(time() - SECINDAY - 5);
            $query = "UPDATE user SET lastupdated = '{$newtime}' WHERE id = {$row['id']}";
            doQuery($query, 101);
        } elseif ($mode == 'name') {
            $row = mysql_fetch_assoc($qh);
            $userid = $row['unityid'];
            $esc_userid = $row['unityid'];
        }
        $userdata = getUserInfo($esc_userid);
        if (is_null($userdata)) {
            $userdata = getUserInfo($esc_userid, 1);
            if (is_null($userdata)) {
                print "<font color=red>{$userid} not found</font><br>\n";
                return;
            }
        }
        $userdata["groups"] = getUsersGroups($userdata["id"], 1, 1);
        print "<TABLE>\n";
        if (!empty($userdata['unityid'])) {
            print "  <TR>\n";
            print "    <TH align=right>User ID:</TH>\n";
            print "    <TD>{$userdata["unityid"]}</TD>\n";
            print "  </TR>\n";
        }
        if (!empty($userdata['firstname'])) {
            print "  <TR>\n";
            print "    <TH align=right>First Name:</TH>\n";
            print "    <TD>{$userdata["firstname"]}</TD>\n";
            print "  </TR>\n";
        }
        if (!empty($userdata['lastname'])) {
            print "  <TR>\n";
            print "    <TH align=right>Last Name:</TH>\n";
            print "    <TD>{$userdata["lastname"]}</TD>\n";
            print "  </TR>\n";
        }
        if (!empty($userdata['preferredname'])) {
            print "  <TR>\n";
            print "    <TH align=right>Preferred Name:</TH>\n";
            print "    <TD>{$userdata["preferredname"]}</TD>\n";
            print "  </TR>\n";
        }
        if (!empty($userdata['affiliation'])) {
            print "  <TR>\n";
            print "    <TH align=right>Affiliation:</TH>\n";
            print "    <TD>{$userdata["affiliation"]}</TD>\n";
            print "  </TR>\n";
        }
        if (!empty($userdata['email'])) {
            print "  <TR>\n";
            print "    <TH align=right>Email:</TH>\n";
            print "    <TD>{$userdata["email"]}</TD>\n";
            print "  </TR>\n";
        }
        print "  <TR>\n";
        print "    <TH align=right style=\"vertical-align: top\">Groups:</TH>\n";
        print "    <TD>\n";
        uasort($userdata["groups"], "sortKeepIndex");
        foreach ($userdata["groups"] as $group) {
            print "      {$group}<br>\n";
        }
        print "    </TD>\n";
        print "  </TR>\n";
        print "  <TR>\n";
        print "    <TH align=right style=\"vertical-align: top\">User Group Permissions:</TH>\n";
        print "    <TD>\n";
        if (count($userdata['groupperms'])) {
            foreach ($userdata['groupperms'] as $perm) {
                print "      {$perm}<br>\n";
            }
        } else {
            print "      No additional user group permissions\n";
        }
        print "    </TD>\n";
        print "  </TR>\n";
        print "  <TR>\n";
        print "    <TH align=right style=\"vertical-align: top\">Privileges (found somewhere in the tree):</TH>\n";
        print "    <TD>\n";
        uasort($userdata["privileges"], "sortKeepIndex");
        foreach ($userdata["privileges"] as $priv) {
            if ($priv == "block" || $priv == "cascade") {
                continue;
            }
            print "      {$priv}<br>\n";
        }
        print "    </TD>\n";
        print "  </TR>\n";
        print "</TABLE>\n";
        # get user's resources
        $userResources = getUserResources(array("imageCheckOut"), array("available"), 0, 0, $userdata['id']);
        # find nodes where user has privileges
        $query = "SELECT p.name AS privnode, " . "upt.name AS userprivtype, " . "up.privnodeid " . "FROM userpriv up, " . "privnode p, " . "userprivtype upt " . "WHERE up.privnodeid = p.id AND " . "up.userprivtypeid = upt.id AND " . "up.userid = {$userdata['id']} " . "ORDER BY p.name, " . "upt.name";
        $qh = doQuery($query, 101);
        if (mysql_num_rows($qh)) {
            print "Nodes where user is granted privileges:<br>\n";
            print "<TABLE>\n";
            $privnodeid = 0;
            while ($row = mysql_fetch_assoc($qh)) {
                if ($privnodeid != $row['privnodeid']) {
                    if ($privnodeid) {
                        print "    </TD>\n";
                        print "  </TR>\n";
                    }
                    print "  <TR>\n";
                    $privnodeid = $row['privnodeid'];
                    $path = getNodePath($privnodeid);
                    print "    <TH align=right>{$path}</TH>\n";
                    print "    <TD>\n";
                }
                print "      {$row['userprivtype']}<br>\n";
            }
            print "    </TD>\n";
            print "  </TR>\n";
            print "</TABLE>\n";
        }
        # find nodes where user's groups have privileges
        if (!empty($userdata['groups'])) {
            $query = "SELECT DISTINCT p.name AS privnode, " . "upt.name AS userprivtype, " . "up.privnodeid " . "FROM userpriv up, " . "privnode p, " . "userprivtype upt " . "WHERE up.privnodeid = p.id AND " . "up.userprivtypeid = upt.id AND " . "upt.name != 'cascade' AND " . "upt.name != 'block' AND " . "up.usergroupid IN (" . implode(',', array_keys($userdata['groups'])) . ") " . "ORDER BY p.name, " . "upt.name";
            $qh = doQuery($query, 101);
            if (mysql_num_rows($qh)) {
                print "Nodes where user's groups are granted privileges:<br>\n";
                print "<TABLE>\n";
                $privnodeid = 0;
                while ($row = mysql_fetch_assoc($qh)) {
                    if ($privnodeid != $row['privnodeid']) {
                        if ($privnodeid) {
                            print "    </TD>\n";
                            print "  </TR>\n";
                        }
                        print "  <TR>\n";
                        $privnodeid = $row['privnodeid'];
                        $path = getNodePath($privnodeid);
                        print "    <TH align=right>{$path}</TH>\n";
                        print "    <TD>\n";
                    }
                    print "      {$row['userprivtype']}<br>\n";
                }
                print "    </TD>\n";
                print "  </TR>\n";
                print "</TABLE>\n";
            }
        }
        print "<table>\n";
        print "  <tr>\n";
        print "    <th>Images User Has Access To:<th>\n";
        print "    <td>\n";
        foreach ($userResources['image'] as $img) {
            print "      {$img}<br>\n";
        }
        print "    </td>\n";
        print "  </tr>\n";
        print "</table>\n";
        # login history
        $query = "SELECT authmech, " . "timestamp, " . "passfail, " . "remoteIP, " . "code " . "FROM loginlog " . "WHERE (user = '******'unityid']}' OR " . "user = '******'unityid']}@{$userdata['affiliation']}') AND " . "affiliationid = {$userdata['affiliationid']} " . "ORDER BY timestamp DESC " . "LIMIT 8";
        $logins = array();
        $qh = doQuery($query);
        while ($row = mysql_fetch_assoc($qh)) {
            $logins[] = $row;
        }
        if (count($logins)) {
            $logins = array_reverse($logins);
            print "<h3>Login History (last 8 attempts)</h3>\n";
            print "<table summary=\"login attempts\">\n";
            print "<colgroup>\n";
            print "<col class=\"logincol\" />\n";
            print "<col class=\"logincol\" />\n";
            print "<col class=\"logincol\" />\n";
            print "<col class=\"logincol\" />\n";
            print "<col />\n";
            print "</colgroup>\n";
            print "  <tr>\n";
            print "    <th>Authentication Method</th>\n";
            print "    <th>Timestamp</th>\n";
            print "    <th>Result</th>\n";
            print "    <th>Remote IP</th>\n";
            print "    <th>Extra Info</th>\n";
            print "  </tr>\n";
            foreach ($logins as $login) {
                print "  <tr>\n";
                print "    <td class=\"logincell\">{$login['authmech']}</td>\n";
                $ts = prettyDatetime($login['timestamp'], 1);
                print "    <td class=\"logincell\">{$ts}</td>\n";
                if ($login['passfail']) {
                    print "    <td class=\"logincell\"><font color=\"#008000\">Pass</font></td>\n";
                } else {
                    print "    <td class=\"logincell\"><font color=\"red\">Fail</font></td>\n";
                }
                print "    <td class=\"logincell\">{$login['remoteIP']}</td>\n";
                print "    <td class=\"logincell\">{$login['code']}</td>\n";
                print "  </tr>\n";
            }
            print "</table>\n";
        } else {
            print "<h3>Login History</h3>\n";
            print "There are no login attempts by this user.<br>\n";
        }
        # reservation history
        $requests = array();
        $query = "SELECT DATE_FORMAT(l.start, '%W, %b %D, %Y, %h:%i %p') AS start, " . "DATE_FORMAT(l.finalend, '%W, %b %D, %Y, %h:%i %p') AS end, " . "c.hostname, " . "i.prettyname AS prettyimage, " . "s.IPaddress, " . "l.ending " . "FROM log l, " . "image i, " . "computer c, " . "sublog s " . "WHERE l.userid = {$userdata['id']} AND " . "s.logid = l.id AND " . "i.id = s.imageid AND " . "c.id = s.computerid " . "ORDER BY l.start DESC " . "LIMIT 5";
        $qh = doQuery($query, 290);
        while ($row = mysql_fetch_assoc($qh)) {
            array_push($requests, $row);
        }
        $requests = array_reverse($requests);
        if (!empty($requests)) {
            print "<h3>User's last " . count($requests) . " reservations:</h3>\n";
            print "<table>\n";
            $first = 1;
            foreach ($requests as $req) {
                if ($first) {
                    $first = 0;
                } else {
                    print "  <tr>\n";
                    print "    <td colspan=2><hr></td>\n";
                    print "  </tr>\n";
                }
                print "  <tr>\n";
                print "    <th align=right>Image:</th>\n";
                print "    <td>{$req['prettyimage']}</td>\n";
                print "  </tr>\n";
                print "  <tr>\n";
                print "    <th align=right>Computer:</th>\n";
                print "    <td>{$req['hostname']}</td>\n";
                print "  </tr>\n";
                print "  <tr>\n";
                print "    <th align=right>Start:</th>\n";
                print "    <td>{$req['start']}</td>\n";
                print "  </tr>\n";
                print "  <tr>\n";
                print "    <th align=right>End:</th>\n";
                print "    <td>{$req['end']}</td>\n";
                print "  </tr>\n";
                if ($req['IPaddress'] != '') {
                    print "  <tr>\n";
                    print "    <th align=right>IP Address:</th>\n";
                    print "    <td>{$req['IPaddress']}</td>\n";
                    print "  </tr>\n";
                }
                print "  <tr>\n";
                print "    <th align=right>Ending:</th>\n";
                print "    <td>{$req['ending']}</td>\n";
                print "  </tr>\n";
            }
            print "</table>\n";
        } else {
            print "User made no reservations in the past week.<br>\n";
        }
        # current reservations
        $requests = array();
        $query = "SELECT DATE_FORMAT(rq.start, '%W, %b %D, %Y, %h:%i %p') AS start, " . "DATE_FORMAT(rq.end, '%W, %b %D, %Y, %h:%i %p') AS end, " . "rq.id AS requestid, " . "MIN(rs.id) AS reservationid, " . "c.hostname AS computer, " . "i.prettyname AS prettyimage, " . "c.IPaddress AS compIP, " . "rs.remoteIP AS userIP, " . "ch.hostname AS vmhost, " . "mn.hostname AS managementnode, " . "srq.name AS servername, " . "aug.name AS admingroup, " . "lug.name AS logingroup, " . "s1.name AS state, " . "s2.name AS laststate " . "FROM image i, " . "managementnode mn, " . "request rq " . "LEFT JOIN reservation rs ON (rs.requestid = rq.id) " . "LEFT JOIN computer c ON (rs.computerid = c.id) " . "LEFT JOIN vmhost vh ON (c.vmhostid = vh.id) " . "LEFT JOIN computer ch ON (vh.computerid = ch.id) " . "LEFT JOIN serverrequest srq ON (srq.requestid = rq.id) " . "LEFT JOIN usergroup aug ON (aug.id = srq.admingroupid) " . "LEFT JOIN usergroup lug ON (lug.id = srq.logingroupid) " . "LEFT JOIN state s1 ON (s1.id = rq.stateid) " . "LEFT JOIN state s2 ON (s2.id = rq.laststateid) " . "WHERE rq.userid = {$userdata['id']} AND " . "i.id = rs.imageid AND " . "mn.id = rs.managementnodeid " . "GROUP BY rq.id " . "ORDER BY rq.start";
        $qh = doQuery($query, 290);
        while ($row = mysql_fetch_assoc($qh)) {
            array_push($requests, $row);
        }
        $requests = array_reverse($requests);
        if (!empty($requests)) {
            print "<h3>User's current reservations:</h3>\n";
            print "<table>\n";
            $first = 1;
            foreach ($requests as $req) {
                if ($first) {
                    $first = 0;
                } else {
                    print "  <tr>\n";
                    print "    <td colspan=2><hr></td>\n";
                    print "  </tr>\n";
                }
                print "  <tr>\n";
                print "    <th align=right>Request ID:</th>\n";
                print "    <td>{$req['requestid']}</td>\n";
                print "  </tr>\n";
                if ($req['servername'] != '') {
                    print "  <tr>\n";
                    print "    <th align=right>Reservation Name:</th>\n";
                    print "    <td>{$req['servername']}</td>\n";
                    print "  </tr>\n";
                }
                print "  <tr>\n";
                print "    <th align=right>Image:</th>\n";
                print "    <td>{$req['prettyimage']}</td>\n";
                print "  </tr>\n";
                print "  <tr>\n";
                print "    <th align=right>State:</th>\n";
                if ($req['state'] == 'pending') {
                    print "    <td>{$req['laststate']}</td>\n";
                } else {
                    print "    <td>{$req['state']}</td>\n";
                }
                print "  </tr>\n";
                print "  <tr>\n";
                print "    <th align=right>Computer:</th>\n";
                print "    <td>{$req['computer']}</td>\n";
                print "  </tr>\n";
                if (!empty($req['vmhost'])) {
                    print "  <tr>\n";
                    print "    <th align=right>VM Host:</th>\n";
                    print "    <td>{$req['vmhost']}</td>\n";
                    print "  </tr>\n";
                }
                print "  <tr>\n";
                print "    <th align=right>Start:</th>\n";
                print "    <td>{$req['start']}</td>\n";
                print "  </tr>\n";
                print "  <tr>\n";
                print "    <th align=right>End:</th>\n";
                if ($req['end'] == 'Friday, Jan 1st, 2038, 12:00 AM') {
                    print "    <td>(indefinite)</td>\n";
                } else {
                    print "    <td>{$req['end']}</td>\n";
                }
                print "  </tr>\n";
                if ($req['compIP'] != '') {
                    print "  <tr>\n";
                    print "    <th align=right>Node's IP Address:</th>\n";
                    print "    <td>{$req['compIP']}</td>\n";
                    print "  </tr>\n";
                }
                if ($req['userIP'] != '') {
                    print "  <tr>\n";
                    print "    <th align=right>User's IP Address:</th>\n";
                    print "    <td>{$req['userIP']}</td>\n";
                    print "  </tr>\n";
                }
                if ($req['admingroup'] != '') {
                    print "  <tr>\n";
                    print "    <th align=right>Admin Group:</th>\n";
                    print "    <td>{$req['admingroup']}</td>\n";
                    print "  </tr>\n";
                }
                if ($req['logingroup'] != '') {
                    print "  <tr>\n";
                    print "    <th align=right>Access Group:</th>\n";
                    print "    <td>{$req['logingroup']}</td>\n";
                    print "  </tr>\n";
                }
                print "  <tr>\n";
                print "    <th align=right>Management Node:</th>\n";
                print "    <td>{$req['managementnode']}</td>\n";
                print "  </tr>\n";
            }
            print "</table>\n";
        } else {
            print "User does not have any current reservations.<br>\n";
        }
    }
    print "</div>\n";
}
Esempio n. 10
0
 function checkResourceInUse($rscid)
 {
     $msgs = array();
     # check reservations
     $query = "SELECT rq.end " . "FROM request rq, " . "reservation rs " . "WHERE rs.requestid = rq.id AND " . "rs.managementnodeid = {$rscid} AND " . "rq.stateid NOT IN (1, 12) AND " . "rq.end > NOW() " . "ORDER BY rq.end DESC " . "LIMIT 1";
     $qh = doQuery($query);
     if ($row = mysql_fetch_assoc($qh)) {
         $msgs[] = "There is at least one <strong>reservation</strong> being processed by this management node. The latest end time is " . prettyDatetime($row['end'], 1) . '.';
     }
     # check blockRequest
     $query = "SELECT br.name, " . "bt.end " . "FROM blockRequest br, " . "blockTimes bt " . "WHERE br.managementnodeid = {$rscid} AND " . "bt.blockRequestid = br.id AND " . "bt.end > NOW() AND " . "bt.skip = 0 AND " . "br.status = 'accepted' " . "ORDER BY bt.end DESC " . "LIMIT 1";
     $qh = doQuery($query);
     if ($row = mysql_fetch_assoc($qh)) {
         $msgs[] = "There is at least one <strong>Block Allocation</strong> being handled by this management node. Block Allocation \"{$row['name']}\" has the latest end time which is " . prettyDatetime($row['end'], 1) . '.';
     }
     if (empty($msgs)) {
         return '';
     }
     $msg = "The selected management node is currently being used in the following ways and cannot be deleted at this time.<br><br>\n";
     $msg .= implode("<br><br>\n", $msgs) . "<br><br>\n";
     return $msg;
 }