function XMLRPCaffiliations() { $affils = getAffiliations(); $return = array(); foreach ($affils as $key => $val) { $tmp = array('id' => $key, 'name' => $val); array_push($return, $tmp); } return $return; }
function processMappingInput($maptypes) { # configid $return['configid'] = processInputVar('configid', ARG_NUMERIC); $tmp = getUserResources(array("configAdmin"), array("administer")); # TODO is this the criteria we want for which configs can be selected? if (!array_key_exists($return['configid'], $tmp['config'])) { $this->errmsg = "Invalid config submitted"; return 0; } # maptypeid $return['maptypeid'] = processInputVar('maptypeid', ARG_NUMERIC); if (!array_key_exists($return['maptypeid'], $maptypes)) { $this->errmsg = "Invalid map type submitted"; return 0; } # subid $return['subid'] = processInputVar('subid', ARG_NUMERIC); if ($maptypes[$return['maptypeid']] == 'Image') { $tmp = getUserResources(array("imageAdmin"), array("administer")); # TODO is this the criteria we want for which images can be selected? if (!array_key_exists($return['subid'], $tmp['image'])) { $this->errmsg = "Invalid image submitted"; return 0; } $return['mapto'] = $tmp['image'][$return['subid']]; } elseif ($maptypes[$return['maptypeid']] == 'OS Type') { $ostypes = getOStypes(); if (!array_key_exists($return['subid'], $ostypes)) { $this->errmsg = "Invalid os type submitted"; return 0; } $return['mapto'] = $ostypes[$return['subid']]; } elseif ($maptypes[$return['maptypeid']] == 'OS') { $oses = getOSList(); if (!array_key_exists($return['subid'], $oses)) { $this->errmsg = "Invalid OS submitted"; return 0; } $return['mapto'] = $oses[$return['subid']]['prettyname']; } elseif ($maptypes[$return['maptypeid']] == 'Config') { $tmp = getUserResources(array("configAdmin"), array("administer")); # TODO is this the criteria we want for which configs can be selected? $configs = $this->getUserConfigsNoCluster($tmp['config']); if (!array_key_exists($return['subid'], $configs)) { $this->errmsg = "Invalid config submitted"; return 0; } $return['mapto'] = $configs[$return['subid']]; } elseif ($maptypes[$return['maptypeid']] == 'Subimage') { $configsubimages = getConfigSubimages($tmp['config']); if (!array_key_exists($return['subid'], $configsubimages)) { $this->errmsg = "Invalid cluster submitted"; return 0; } $return['mapto'] = $configsubimages[$return['subid']]; } elseif ($maptypes[$return['maptypeid']] == 'Management Node') { $managementnodes = getManagementNodes(); if (!array_key_exists($return['subid'], $managementnodes)) { $this->errmsg = "Invalid managementnode submitted"; return 0; } $return['mapto'] = $managementnodes[$return['subid']]['hostname']; } # check for creating a loop - cannot have a parent that maps to # submitted config if ($maptypes[$return['maptypeid']] == 'Config' || $maptypes[$return['maptypeid']] == 'Subimage') { $rc = $this->mappingLoopCheck($maptypes[$return['maptypeid']], $return['configid'], $return['subid']); if ($rc != '') { $this->errmsg = "This mapping would create a loop. {$rc} is a<br>" . "parent/grandparent and is mapped to the selected config."; return 0; } } # affiliationid $return['affiliationid'] = processInputVar('affiliationid', ARG_NUMERIC); $affils = getAffiliations(); if (!array_key_exists($return['affiliationid'], $affils)) { $this->errmsg = "Invalid affiliation submitted"; return 0; } # stageid $return['stageid'] = processInputVar('stageid', ARG_NUMERIC); $stages = $this->getConfigMapStages(); if (!array_key_exists($return['stageid'], $stages)) { $this->errmsg = "Invalid stage submitted"; return 0; } # duplicate check # TODO do we also need to check the disabled field? $configmapid = getContinuationVar('configmapid', 0); $query = "SELECT id " . "FROM configmap " . "WHERE configid = {$return['configid']} AND " . "configmaptypeid = {$return['maptypeid']} AND " . "subid = {$return['subid']} AND " . "affiliationid = {$return['affiliationid']} AND " . "configstageid = {$return['stageid']} AND " . "id != {$configmapid}"; $qh = doQuery($query); if (mysql_num_rows($qh)) { $this->errmsg = "The specified mapping already exists."; return 0; } return $return; }
function viewStatistics() { global $submitErr, $submitErrMsg, $user; define("30MIN", 1800); define("1HOUR", 3600); define("2HOURS", 7200); define("4HOURS", 14400); $month1 = processInputVar("month1", ARG_NUMERIC); $day1 = processInputVar("day1", ARG_NUMERIC); $year1 = processInputVar("year1", ARG_NUMERIC); $month2 = processInputVar("month2", ARG_NUMERIC); $day2 = processInputVar("day2", ARG_NUMERIC); $year2 = processInputVar("year2", ARG_NUMERIC); $affilid = processInputVar("affilid", ARG_NUMERIC, $user['affiliationid']); $mode2 = getContinuationVar('mode', 'default'); $provid = processInputVar('provid', ARG_NUMERIC, 0); if ($mode2 == 'provisioning') { $affilid = 0; $provs = getContinuationVar('provs'); if (!array_key_exists($provid, $provs)) { $ids = array_keys($provs); $provid = $ids[0]; } } else { $provid = 0; } $affils = getAffiliations(); if (!checkUserHasPerm('View Statistics by Affiliation') || $affilid != 0 && !array_key_exists($affilid, $affils)) { $affilid = $user['affiliationid']; } if ($affilid == 0) { $statsfor = i("All Affiliations"); } else { $statsfor = $affils[$affilid]; } $start = "{$year1}-{$month1}-{$day1} 00:00:00"; $end = "{$year2}-{$month2}-{$day2} 23:59:59"; if (!checkdate($month1, $day1, $year1)) { $submitErr |= STARTERR; $submitErrMsg[STARTERR] = i("The selected start date is not valid. Please select a valid date.") . "<br>\n"; } if (!checkdate($month2, $day2, $year2)) { $submitErr |= ENDERR; $submitErrMsg[ENDERR] = i("The selected end date is not valid. Please select a valid date.") . "<br>\n"; } if (datetimeToUnix($start) > datetimeToUnix($end)) { $submitErr |= ORDERERR; $submitErrMsg[ORDERERR] = i("The selected end date is before the selected start date. Please select an end date equal to or greater than the start date.") . "<br>\n"; } if ($submitErr) { selectStatistics(); return; } $timestart = microtime(1); if ($mode2 == 'default') { print "<H2>" . i("Statistic Information for") . " {$statsfor}</H2>\n"; } elseif ($mode2 == 'provisioning') { print "<H2>" . i("Statistic Information for") . " {$provs[$provid]}</H2>\n"; } print "<H3>"; $tmp = mktime(0, 0, 0, $month1, $day1, $year1); $starttime = strftime('%x', $tmp); $tmp = mktime(0, 0, 0, $month2, $day2, $year2); $endtime = strftime('%x', $tmp); printf(i("Reservation information between %s and %s:"), $starttime, $endtime); print "</H3>\n"; $reloadid = getUserlistID('vclreload@Local'); if ($mode2 == 'default') { $query = "SELECT l.userid, " . "u.affiliationid, " . "l.nowfuture, " . "UNIX_TIMESTAMP(l.start) AS start, " . "(UNIX_TIMESTAMP(l.loaded) - UNIX_TIMESTAMP(l.start)) AS loadtime, " . "UNIX_TIMESTAMP(l.finalend) AS finalend, " . "l.wasavailable, " . "l.ending, " . "i.prettyname, " . "o.prettyname AS OS " . "FROM log l, " . "image i, " . "user u, " . "OS o " . "WHERE l.start >= '{$start}' AND " . "l.finalend <= '{$end}' AND " . "i.id = l.imageid AND " . "i.OSid = o.id AND " . "l.userid != {$reloadid} AND "; } elseif ($mode2 == 'provisioning') { $query = "SELECT l.userid, " . "u.affiliationid, " . "l.nowfuture, " . "UNIX_TIMESTAMP(l.start) AS start, " . "(UNIX_TIMESTAMP(l.loaded) - UNIX_TIMESTAMP(l.start)) AS loadtime, " . "UNIX_TIMESTAMP(l.finalend) AS finalend, " . "l.wasavailable, " . "l.ending, " . "i.prettyname, " . "o.prettyname AS OS " . "FROM image i, " . "user u, " . "OS o, " . "log l " . "JOIN (" . "SELECT s.logid, " . "MIN(s.computerid) AS computerid " . "FROM sublog s, " . "computer c " . "WHERE s.computerid = c.id AND " . "c.provisioningid = {$provid} " . "GROUP BY logid " . ") AS s ON (s.logid = l.id) " . "WHERE l.start >= '{$start}' AND " . "l.finalend <= '{$end}' AND " . "i.id = l.imageid AND " . "i.OSid = o.id AND " . "l.userid != {$reloadid} AND "; } if ($affilid != 0) { $query .= "u.affiliationid = {$affilid} AND "; } $query .= "l.userid = u.id " . "ORDER BY i.prettyname"; $qh = doQuery($query, 275); $totalreservations = 0; $users = array(); $nows = 0; $futures = 0; $notavailable = 0; $loadtimes = array("2less" => 0, "2to6" => 0, "6to8" => 0, "8more" => 0); $ending = array("deleted" => 0, "released" => 0, "failed" => 0, "noack" => 0, "nologin" => 0, "timeout" => 0, "EOR" => 0, "none" => 0); $imagecount = array(); $imageusers = array(); $imagehours = array(); $imageload2less = array(); $imageload2to6 = array(); $imageload6to8 = array(); $imageload8more = array(); $imagefails = array(); $lengths = array("30min" => 0, "1hour" => 0, "2hours" => 0, "4hours" => 0, "6hours" => 0, "8hours" => 0, "10hours" => 0, "10hrsplus" => 0); $totalhours = 0; $osusers = array(); while ($row = mysql_fetch_assoc($qh)) { if (!array_key_exists($row["prettyname"], $imageload2less)) { $imageload2less[$row["prettyname"]] = 0; } if (!array_key_exists($row["prettyname"], $imageload2to6)) { $imageload2to6[$row["prettyname"]] = 0; } if (!array_key_exists($row["prettyname"], $imageload6to8)) { $imageload6to8[$row["prettyname"]] = 0; } if (!array_key_exists($row["prettyname"], $imageload8more)) { $imageload8more[$row["prettyname"]] = 0; } # notavailable if ($row["wasavailable"] == 0) { $notavailable++; } else { $totalreservations++; # load times if ($row['loadtime'] <= 120) { $loadtimes['2less']++; # imageload2less $imageload2less[$row['prettyname']]++; } elseif ($row['loadtime'] > 120 && $row['loadtime'] <= 360) { $loadtimes['2to6']++; $imageload2to6[$row['prettyname']]++; } elseif ($row['loadtime'] > 360 && $row['loadtime'] <= 480) { $loadtimes['6to8']++; $imageload6to8[$row['prettyname']]++; } else { $loadtimes['8more']++; $imageload8more[$row['prettyname']]++; } } # users $users[$row['userid']] = 1; # nowfuture if ($row["nowfuture"] == "now") { $nows++; } else { $futures++; } # ending $ending[$row["ending"]]++; # imagecount if (!array_key_exists($row["prettyname"], $imagecount)) { $imagecount[$row["prettyname"]] = 0; } $imagecount[$row["prettyname"]]++; # imageusers if (!array_key_exists($row["prettyname"], $imageusers)) { $imageusers[$row["prettyname"]] = array(); } $imageusers[$row['prettyname']][$row['userid']] = 1; # lengths $length = $row["finalend"] - $row["start"]; if ($length < 0) { $length = 0; } if ($length <= 1800) { $lengths["30min"]++; } elseif ($length <= 3600) { $lengths["1hour"]++; } elseif ($length <= 7200) { $lengths["2hours"]++; } elseif ($length <= 14400) { $lengths["4hours"]++; } elseif ($length <= 21600) { $lengths["6hours"]++; } elseif ($length <= 28800) { $lengths["8hours"]++; } elseif ($length <= 36000) { $lengths["10hours"]++; } else { $lengths["10hrsplus"]++; } # imagehours if (!array_key_exists($row["prettyname"], $imagehours)) { $imagehours[$row["prettyname"]] = 0; } $imagehours[$row["prettyname"]] += $length / 3600; # imagefails if (!array_key_exists($row["prettyname"], $imagefails)) { $imagefails[$row["prettyname"]] = 0; } if ($row['ending'] == 'failed') { $imagefails[$row["prettyname"]] += 1; } # total hours $totalhours += $length; # osusers if (!array_key_exists($row["OS"], $osusers)) { $osusers[$row["OS"]] = array(); } $osusers[$row['OS']][$row['userid']] = 1; } print "<DIV align=center>\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TH align=right>" . i("Total Reservations:") . "</TH>\n"; print " <TD>{$totalreservations}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("Total Hours Used:") . "</TH>\n"; print " <TD>" . (int) ($totalhours / 3600) . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("\"Now\" Reservations:") . "</TH>\n"; print " <TD>{$nows}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("\"Later\" Reservations:") . "</TH>\n"; print " <TD>{$futures}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("Unavailable:") . "</TH>\n"; print " <TD>{$notavailable}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("Load times < 2 minutes:") . "</TH>\n"; print " <TD>{$loadtimes['2less']}</TD>\n"; print " </TR>\n"; print " <TH align=right>" . i("Load times 2-6 minutes:") . "</TH>\n"; print " <TD>{$loadtimes['2to6']}</TD>\n"; print " </TR>\n"; print " <TH align=right>" . i("Load times 6-8 minutes:") . "</TH>\n"; print " <TD>{$loadtimes['6to8']}</TD>\n"; print " <TR>\n"; print " <TH align=right>" . i("Load times >= 8 minutes:") . "</TH>\n"; print " <TD>{$loadtimes['8more']}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("Total Unique Users:") . "</TH>\n"; print " <TD>" . count($users) . "</TD>\n"; print " </TR>\n"; foreach (array_keys($osusers) as $key) { print " <TR>\n"; print " <TH align=right>"; printf(i("Unique Users of %s:"), $key); print "</TH>\n"; print " <TD>" . count($osusers[$key]) . "</TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TD></TD>\n"; print " <TH>" . i("Reservations") . "</TH>\n"; print " <TH>" . i("Unique Users") . "</TH>\n"; print " <TH>" . i("Hours Used") . "</TH>\n"; print " <TH>" . i("< 2 min wait") . "</TH>\n"; print " <TH>" . i("2-6 min wait") . "</TH>\n"; print " <TH>" . i("6-8 min wait") . "</TH>\n"; print " <TH>" . i(">= 8 min wait") . "</TH>\n"; print " <TH>" . i("Failures") . "</TH>\n"; print " </TR>\n"; foreach ($imagecount as $key => $value) { print " <TR>\n"; print " <TH align=right>{$key}:</TH>\n"; print " <TD align=center>{$value}</TD>\n"; print " <TD align=center>" . count($imageusers[$key]) . "</TD>\n"; if ((int) $imagehours[$key] == 0) { print " <TD align=center>1</TD>\n"; } else { print " <TD align=center>" . (int) $imagehours[$key] . "</TD>\n"; } print " <TD align=center>{$imageload2less[$key]}</TD>\n"; print " <TD align=center>{$imageload2to6[$key]}</TD>\n"; print " <TD align=center>{$imageload6to8[$key]}</TD>\n"; print " <TD align=center>{$imageload8more[$key]}</TD>\n"; if ($imagefails[$key]) { $percent = $imagefails[$key] * 100 / $value; if ($percent < 1) { $percent = sprintf('%.1f%%', $percent); } else { $percent = sprintf('%d%%', $percent); } print " <TD align=center><font color=red>{$imagefails[$key]} "; print "({$percent})</font></TD>\n"; } else { print " <TD align=center>{$imagefails[$key]}</TD>\n"; } print " </TR>\n"; } print "</TABLE>\n"; print "<H3>" . i("Durations:") . "</H3>\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TH align=right>" . i("0 - 30 Min:") . "</TH>\n"; print " <TD>" . $lengths["30min"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("30 Min - 1 Hour:") . "</TH>\n"; print " <TD>" . $lengths["1hour"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("1 Hour - 2 Hours:") . "</TH>\n"; print " <TD>" . $lengths["2hours"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("2 Hours - 4 Hours:") . "</TH>\n"; print " <TD>" . $lengths["4hours"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("4 Hours - 6 Hours:") . "</TH>\n"; print " <TD>" . $lengths["6hours"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("6 Hours - 8 Hours:") . "</TH>\n"; print " <TD>" . $lengths["8hours"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("8 Hours - 10 Hours:") . "</TH>\n"; print " <TD>" . $lengths["10hours"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("> 10 Hours:") . "</TH>\n"; print " <TD>" . $lengths["10hrsplus"] . "</TD>\n"; print " </TR>\n"; print "</TABLE>\n"; print "<H3>" . i("Ending information:") . "</H3>\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TH align=right>" . i("Deleted:") . "</TH>\n"; print " <TD>" . $ending["deleted"] . "</TD>\n"; print " <TD rowspan=7><img src=\"images/blank.gif\" width=5></TD>\n"; print " <TD>" . i("(Future reservation deleted before start time reached)") . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("Released:") . "</TH>\n"; print " <TD>" . $ending["released"] . "</TD>\n"; print " <TD>" . i("(Reservation released before end time reached)") . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("Not Acknowledged:") . "</TH>\n"; print " <TD>" . $ending["noack"] . "</TD>\n"; print " <TD>" . i("(\"Connect!\" button never clicked)") . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("No Login:"******"</TH>\n"; print " <TD>" . $ending["nologin"] . "</TD>\n"; print " <TD>" . i("(User never logged in)") . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("End of Reservation:") . "</TH>\n"; print " <TD>" . $ending["EOR"] . "</TD>\n"; print " <TD>" . i("(End of reservation reached)") . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("Timed Out:") . "</TH>\n"; print " <TD>" . $ending["timeout"] . "</TD>\n"; print " <TD>" . i("(Disconnect and no reconnection within 15 minutes)") . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("Failed:") . "</TH>\n"; print " <TD>" . $ending["failed"] . "</TD>\n"; print " <TD>" . i("(Reserved computer failed to get prepared for user)") . "</TD>\n"; print " </TR>\n"; print "</TABLE>\n"; print "<br>\n"; print "</div>\n"; $unixstart = datetimeToUnix($start); $unixend = datetimeToUnix($end); $start = date('Y-m-d', $unixstart); $end = date('Y-m-d', $unixend); $cdata = array('start' => $start, 'end' => $end, 'affilid' => $affilid, 'mode' => $mode2, 'provid' => $provid); print "<H2>" . i("Reservations by Day") . "</H2>\n"; print "<small>" . i("(Reservations with start time on given day)") . "</small><br>\n"; $cdata['divid'] = 'resbyday'; $cont = addContinuationsEntry('AJgetStatData', $cdata); print "<input type=hidden id=statdaycont value=\"{$cont}\">\n"; print "<div id=\"resbyday\" class=\"statgraph\">(Loading...)</div>\n"; print "<H2>" . i("Max Concurrent Reservations By Day") . "</H2>\n"; $cdata['divid'] = 'maxconcurresday'; $cont = addContinuationsEntry('AJgetStatData', $cdata); print "<input type=hidden id=statconcurrescont value=\"{$cont}\">\n"; print "<div id=\"maxconcurresday\" class=\"statgraph\">Loading graph data...</div>\n"; print "<H2>" . i("Max Concurrent Blade Reservations By Day") . "</H2>\n"; $cdata['divid'] = 'maxconcurbladeday'; $cont = addContinuationsEntry('AJgetStatData', $cdata); print "<input type=hidden id=statconcurbladecont value=\"{$cont}\">\n"; print "<div id=\"maxconcurbladeday\" class=\"statgraph\">Loading graph data...</div>\n"; print "<H2>" . i("Max Concurrent Virtual Machine Reservations By Day") . "</H2>\n"; $cdata['divid'] = 'maxconcurvmday'; $cont = addContinuationsEntry('AJgetStatData', $cdata); print "<input type=hidden id=statconcurvmcont value=\"{$cont}\">\n"; print "<div id=\"maxconcurvmday\" class=\"statgraph\">Loading graph data...</div>\n"; print "<H2>" . i("Reservations by Hour") . "</H2>\n"; print "<small>(" . i("Active reservations during given hour averaged over selected dates") . ")</small><br><br>\n"; $cdata['divid'] = 'resbyhour'; $cont = addContinuationsEntry('AJgetStatData', $cdata); print "<input type=hidden id=statreshourcont value=\"{$cont}\">\n"; print "<div id=\"resbyhour\" class=\"statgraph\">Loading graph data...</div>\n"; $endtime = microtime(1); $end = $endtime - $timestart; #print "running time: $endtime - $timestart = $end<br>\n"; }
function confirmEditOrAddGroup($state) { global $submitErr, $user; $data = processGroupInput(1); if ($submitErr) { editOrAddGroup($state); return; } $resourcetypes = getTypes("resources"); $usergroups = getUserGroups(); $affils = getAffiliations(); $editname = getContinuationVar('editname', 1); if ($state) { if ($data["type"] == "user") { $title = "Add User Group"; $question = "Add the following user group?"; $target = ""; } else { $title = "Add Resource Group"; $question = "Add the following resource group?"; $target = "#resources"; } $nextmode = "submitAddGroup"; } else { if ($data["type"] == "user") { $title = "Edit User Group"; $question = "Submit changes to the user group?"; $target = ""; } else { $title = "Edit Resource Group"; $question = "Submit changes to the resource group?"; $target = "#resources"; } $nextmode = "submitEditGroup"; } print "<DIV align=center>\n"; print "<H2>{$title}</H2>\n"; print "{$question}<br><br>\n"; if ($data['courseroll'] == 1 || $data['custom'] == 0 || $editname == 0) { if ($user['showallgroups']) { print "{$data['name']}@{$affils[$data['affiliationid']]}<br><br>\n"; } else { print "{$data['name']}<br><br>\n"; } } print "<TABLE>\n"; if ($data["type"] == "resource") { print " <TR>\n"; print " <TH align=right>Type:</TH>\n"; print " <TD>" . $resourcetypes["resources"][$data["resourcetypeid"]]; print "</TD>\n"; print " </TR>\n"; } if ($data['courseroll'] == 0 && $data['custom'] == 1 && $editname == 1) { print " <TR>\n"; print " <TH align=right>Name:</TH>\n"; if ($data['type'] == 'user' && ($user['showallgroups'] || $data['affiliationid'] != $user['affiliationid'])) { print " <TD>{$data["name"]}@{$affils[$data['affiliationid']]}</TD>\n"; } else { print " <TD>{$data["name"]}</TD>\n"; } print " </TR>\n"; } if ($data["type"] == "user") { if ($data['courseroll'] == 0 && $data['custom'] == 1) { print " <TR>\n"; print " <TH align=right>Owner:</TH>\n"; print " <TD>" . $data["owner"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Editable by:</TH>\n"; if ($state == 0 && $data['editgroupid'] == 0) { $usergroups[0]['name'] = 'None'; } elseif (!$user['showallgroups']) { $tmp = explode('@', $usergroups[$data["editgroupid"]]["name"]); if ($tmp[1] == $user['affiliation']) { $usergroups[$data["editgroupid"]]["name"] = $tmp[0]; } } print " <TD>" . $usergroups[$data["editgroupid"]]["name"] . "</TD>\n"; print " </TR>\n"; } $lengths = getReservationLengths(65535); print " <TR>\n"; print " <TH align=right>Initial Max Time:</TH>\n"; print " <TD>{$lengths[$data["initialmax"]]}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Total Max Time:</TH>\n"; print " <TD>{$lengths[$data["totalmax"]]}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Max Extend Time:</TH>\n"; print " <TD>{$lengths[$data["maxextend"]]}</TD>\n"; print " </TR>\n"; if (checkUserHasPerm('Set Overlapping Reservation Count')) { print " <TR>\n"; print " <TH align=right>Max Overlapping Reservations:</TH>\n"; print " <TD>{$data["overlap"]}</TD>\n"; print " </TR>\n"; } } else { print " <TR>\n"; print " <TH align=right>Owning User Group:</TH>\n"; if (!$user['showallgroups'] && preg_match("/^(.+)@{$user['affiliation']}\$/", $usergroups[$data['ownergroup']]['name'], $matches)) { print " <TD>{$matches[1]}"; } else { print " <TD>" . $usergroups[$data["ownergroup"]]["name"]; } print "</TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<TABLE>\n"; print " <TR valign=top>\n"; print " <TD>\n"; print " <FORM action=\"" . BASEURL . SCRIPT . "{$target}\" method=post>\n"; $cont = addContinuationsEntry($nextmode, $data, SECINDAY, 0, 0); print " <INPUT type=hidden name=continuation value=\"{$cont}\">\n"; print " <INPUT type=submit value=Submit>\n"; print " </FORM>\n"; print " </TD>\n"; print " <TD>\n"; print " <FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n"; print " <INPUT type=hidden name=mode value=viewGroups>\n"; print " <INPUT type=submit value=Cancel>\n"; print " </FORM>\n"; print " </TD>\n"; print " </TR>\n"; print "</TABLE>\n"; print "</DIV>\n"; }
function viewStatistics() { global $submitErr, $submitErrMsg, $user, $viewmode; define("30MIN", 1800); define("1HOUR", 3600); define("2HOURS", 7200); define("4HOURS", 14400); $month1 = processInputVar("month1", ARG_NUMERIC); $day1 = processInputVar("day1", ARG_NUMERIC); $year1 = processInputVar("year1", ARG_NUMERIC); $month2 = processInputVar("month2", ARG_NUMERIC); $day2 = processInputVar("day2", ARG_NUMERIC); $year2 = processInputVar("year2", ARG_NUMERIC); $affilid = processInputVar("affilid", ARG_NUMERIC, $user['affiliationid']); $affils = getAffiliations(); if ($viewmode < ADMIN_FULL || $affilid != 0 && !array_key_exists($affilid, $affils)) { $affilid = $user['affiliationid']; } $start = "{$year1}-{$month1}-{$day1} 00:00:00"; $end = "{$year2}-{$month2}-{$day2} 23:59:59"; if (!checkdate($month1, $day1, $year1)) { $submitErr |= STARTERR; $submitErrMsg[STARTERR] = "The selected start date is not valid. Please " . "select a valid date.<br>\n"; } if (!checkdate($month2, $day2, $year2)) { $submitErr |= ENDERR; $submitErrMsg[ENDERR] = "The selected end date is not valid. Please " . "select a valid date.<br>\n"; } if (datetimeToUnix($start) > datetimeToUnix($end)) { $submitErr |= ORDERERR; $submitErrMsg[ORDERERR] = "The selected end date is before the selected " . "start date. Please select an end date equal " . "to or greater than the start date.<br>\n"; } if ($submitErr) { selectStatistics(); return; } $timestart = microtime(1); print "<H2>Statistic Information</H2>\n"; print "<H3>Reservation information between {$month1}/{$day1}/{$year1} and "; print "{$month2}/{$day2}/{$year2}:\n"; print "</H3>\n"; $reloadid = getUserlistID('vclreload@Local'); $query = "SELECT l.userid, " . "l.nowfuture, " . "UNIX_TIMESTAMP(l.start) AS start, " . "(UNIX_TIMESTAMP(l.loaded) - UNIX_TIMESTAMP(l.start)) AS loadtime, " . "UNIX_TIMESTAMP(l.finalend) AS finalend, " . "l.wasavailable, " . "l.ending, " . "i.prettyname, " . "o.prettyname AS OS " . "FROM log l, " . "image i, " . "user u, " . "OS o " . "WHERE l.start >= '{$start}' AND " . "l.finalend <= '{$end}' AND " . "i.id = l.imageid AND " . "i.OSid = o.id AND " . "l.userid != {$reloadid} AND "; if ($affilid != 0) { $query .= "u.affiliationid = {$affilid} AND "; } $query .= "l.userid = u.id " . "ORDER BY i.prettyname"; $qh = doQuery($query, 275); $totalreservations = 0; $users = array(); $nows = 0; $futures = 0; $notavailable = 0; $loadtimes = array("2less" => 0, "2more" => 0); $ending = array("deleted" => 0, "released" => 0, "failed" => 0, "noack" => 0, "nologin" => 0, "timeout" => 0, "EOR" => 0, "none" => 0); $imagecount = array(); $imageusers = array(); $imagehours = array(); $imageload2less = array(); $imageload2more = array(); $lengths = array("30min" => 0, "1hour" => 0, "2hours" => 0, "4hours" => 0, "4hrsplus" => 0); $totalhours = 0; $osusers = array(); while ($row = mysql_fetch_assoc($qh)) { if (!array_key_exists($row["prettyname"], $imageload2less)) { $imageload2less[$row["prettyname"]] = 0; } if (!array_key_exists($row["prettyname"], $imageload2more)) { $imageload2more[$row["prettyname"]] = 0; } # notavailable if ($row["wasavailable"] == 0) { $notavailable++; } else { $totalreservations++; # load times if ($row['loadtime'] < 120) { $loadtimes['2less']++; # imageload2less $imageload2less[$row['prettyname']]++; } else { $loadtimes['2more']++; # imageload2more $imageload2more[$row['prettyname']]++; } } # users $users[$row['userid']] = 1; # nowfuture if ($row["nowfuture"] == "now") { $nows++; } else { $futures++; } # ending $ending[$row["ending"]]++; # imagecount if (!array_key_exists($row["prettyname"], $imagecount)) { $imagecount[$row["prettyname"]] = 0; } $imagecount[$row["prettyname"]]++; # imageusers if (!array_key_exists($row["prettyname"], $imageusers)) { $imageusers[$row["prettyname"]] = array(); } $imageusers[$row['prettyname']][$row['userid']] = 1; # lengths $length = $row["finalend"] - $row["start"]; if ($length <= 1800) { $lengths["30min"]++; } elseif ($length <= 3600) { $lengths["1hour"]++; } elseif ($length <= 7200) { $lengths["2hours"]++; } elseif ($length <= 14400) { $lengths["4hours"]++; } else { $lengths["4hrsplus"]++; } # imagehours if (!array_key_exists($row["prettyname"], $imagehours)) { $imagehours[$row["prettyname"]] = 0; } $imagehours[$row["prettyname"]] += $length / 3600; # total hours $totalhours += $length / 3600; # osusers if (!array_key_exists($row["OS"], $osusers)) { $osusers[$row["OS"]] = array(); } $osusers[$row['OS']][$row['userid']] = 1; } print "<DIV align=center>\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TH align=right>Total Reservations:</TH>\n"; print " <TD>{$totalreservations}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Total Hours Used:</TH>\n"; print " <TD>" . (int) $totalhours . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>\"Now\" Reservations:</TH>\n"; print " <TD>{$nows}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>\"Later\" Reservations:</TH>\n"; print " <TD>{$futures}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Unavailable:</TH>\n"; print " <TD>{$notavailable}</TD>\n"; print " </TR>\n"; if ($viewmode >= ADMIN_FULL) { print " <TR>\n"; print " <TH align=right>Load times < 2 minutes:</TH>\n"; print " <TD>{$loadtimes['2less']}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Load times >= 2 minutes:</TH>\n"; print " <TD>{$loadtimes['2more']}</TD>\n"; print " </TR>\n"; } print " <TR>\n"; print " <TH align=right>Total Unique Users:</TH>\n"; print " <TD>" . count($users) . "</TD>\n"; print " </TR>\n"; foreach (array_keys($osusers) as $key) { print " <TR>\n"; print " <TH align=right>Unique Users of {$key}:</TH>\n"; print " <TD>" . count($osusers[$key]) . "</TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TD></TD>\n"; print " <TH>Reservations</TH>\n"; print " <TH>Unique Users</TH>\n"; print " <TH>Hours Used</TH>\n"; if ($viewmode >= ADMIN_FULL) { print " <TH>< 2 min load time</TH>\n"; print " <TH>>= 2 min load time</TH>\n"; } print " </TR>\n"; foreach ($imagecount as $key => $value) { print " <TR>\n"; print " <TH align=right>{$key}:</TH>\n"; print " <TD align=center>{$value}</TD>\n"; print " <TD align=center>" . count($imageusers[$key]) . "</TD>\n"; if ((int) $imagehours[$key] == 0) { print " <TD align=center>1</TD>\n"; } else { print " <TD align=center>" . (int) $imagehours[$key] . "</TD>\n"; } if ($viewmode >= ADMIN_FULL) { print " <TD align=center>{$imageload2less[$key]}</TD>\n"; print " <TD align=center>{$imageload2more[$key]}</TD>\n"; } print " </TR>\n"; } print "</TABLE>\n"; print "<H3>Durations:</H3>\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TH align=right>0 - 30 Min:</TH>\n"; print " <TD>" . $lengths["30min"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>30 Min - 1 Hour:</TH>\n"; print " <TD>" . $lengths["1hour"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>1 Hour - 2 Hours:</TH>\n"; print " <TD>" . $lengths["2hours"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>2 Hours - 4 Hours:</TH>\n"; print " <TD>" . $lengths["4hours"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>> 4 Hours:</TH>\n"; print " <TD>" . $lengths["4hrsplus"] . "</TD>\n"; print " </TR>\n"; print "</TABLE>\n"; print "<H3>Ending information:</H3>\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TH align=right>Deleted:</TH>\n"; print " <TD>" . $ending["deleted"] . "</TD>\n"; print " <TD rowspan=7><img src=\"images/blank.gif\" width=5></TD>\n"; print " <TD>(Future reservation deleted before start time reached)</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Released:</TH>\n"; print " <TD>" . $ending["released"] . "</TD>\n"; print " <TD>(Reservation released before end time reached)</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Not Acknowledged:</TH>\n"; print " <TD>" . $ending["noack"] . "</TD>\n"; print " <TD>(\"Connect!\" button never clicked)</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>No Login:</TH>\n"; print " <TD>" . $ending["nologin"] . "</TD>\n"; print " <TD>(User never logged in)</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>End of Reservation:</TH>\n"; print " <TD>" . $ending["EOR"] . "</TD>\n"; print " <TD>(End of reservation reached)</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Timed Out:</TH>\n"; print " <TD>" . $ending["timeout"] . "</TD>\n"; print " <TD>(Disconnect and no reconnection within 15 minutes)</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Failed:</TH>\n"; print " <TD>" . $ending["failed"] . "</TD>\n"; print " <TD>(Reserved computer failed to get prepared for user)</TD>\n"; print " </TR>\n"; print "</TABLE>\n"; print "<br>\n"; $unixstart = datetimeToUnix($start); $unixend = datetimeToUnix($end); $start = date('Y-m-d', $unixstart); $end = date('Y-m-d', $unixend); $cdata = array('start' => $start, 'end' => $end, 'affilid' => $affilid); print "<H2>Reservations by Day</H2>\n"; $cont = addContinuationsEntry('statgraphday', $cdata); print "<img src=" . BASEURL . SCRIPT . "?continuation={$cont}>"; print "<H2>Max Concurrent Reservations By Day</H2>\n"; if ($unixend - $unixstart > SECINMONTH) { print "(this graph only available for up to a month of data)<br>\n"; } else { $cont = addContinuationsEntry('statgraphdayconcuruser', $cdata); print "<img src=" . BASEURL . SCRIPT . "?continuation={$cont}>"; } print "<H2>Max Concurrent Blade Reservations By Day</H2>\n"; if ($unixend - $unixstart > SECINMONTH) { print "(this graph only available for up to a month of data)<br>\n"; } else { $cont = addContinuationsEntry('statgraphdayconcurblade', $cdata); print "<img src=" . BASEURL . SCRIPT . "?continuation={$cont}>"; } print "<H2>Reservations by Hour</H2>\n"; print "(Averaged over the time period)<br><br>\n"; $cont = addContinuationsEntry('statgraphhour', $cdata); print "<img src=" . BASEURL . SCRIPT . "?continuation={$cont}>"; print "</div>\n"; $endtime = microtime(1); $end = $endtime - $timestart; #print "running time: $endtime - $timestart = $end<br>\n"; }
function getDashboardAffilID() { global $user; if (!checkUserHasPerm('View Dashboard (global)')) { return $user['affiliationid']; } $affilid = processInputVar('affilid', ARG_NUMERIC); $affils = getAffiliations(); if ($affilid != 0 && !array_key_exists($affilid, $affils)) { return 0; } return $affilid; }
function AJaddAffiliationSetting() { global $user; if (!checkUserHasPerm('Site Configuration (global)')) { $arr = array('status' => 'noaccess', 'msg' => i('You do not have access to modify settings for other affiliations.')); sendJSON($arr); return; } $affilid = processInputVar('affilid', ARG_NUMERIC); $affils = getAffiliations(); if (!array_key_exists($affilid, $affils)) { $arr = array('status' => 'failed', 'msgid' => "{$this->domidbase}msg", 'errmsg' => i('Invalid affiliation submitted.')); sendJSON($arr); return; } $value = processInputVar('value', ARG_NUMERIC); if ($value < $this->minval || $value > $this->maxval) { $arr = array('status' => 'failed', 'msgid' => "{$this->domidbase}msg", 'errmsg' => i('Invalid value submitted.')); sendJSON($arr); return; } $affil = $affils[$affilid]; $newval = $value; if ($this->scale60) { $newval = $newval * 60; } setVariable("{$this->key}|{$affil}", $newval, 'none'); # recreate delete and update continuations $data = getVariablesRegex("^{$this->key}.*"); $origvals = array(); $origvals[$this->key] = array('key' => $this->key, 'val' => $data[$this->key]); foreach ($data as $prekey => $val) { $key = str_replace('|', '_', $prekey); $origvals[$key] = array('key' => $prekey, 'val' => $val); } $cdata = $this->basecdata; $cdata['origvals'] = $origvals; $delcont = addContinuationsEntry('AJdeleteAffiliationSetting', $cdata); $savecont = addContinuationsEntry('AJupdateAllSettings', $cdata); $arr = array('status' => 'success', 'msgid' => "{$this->domidbase}msg", 'btn' => "{$this->domidbase}addbtn", 'affil' => $affil, 'affilid' => $affilid, 'value' => $value, 'id' => "{$this->key}_{$affil}", 'extrafunc' => "{$this->jsname}.addAffiliationSettingCBextra", 'deletecont' => $delcont, 'savecont' => $savecont, 'minval' => $this->minval, 'maxval' => $this->maxval, 'msg' => sprintf($this->addmsg, $affil)); sendJSON($arr); }
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"; }
function validateResourceData() { global $user; $return = array('error' => 0); $return['rscid'] = getContinuationVar('rscid', 0); $return['name'] = processInputVar('name', ARG_STRING); $return['owner'] = processInputVar('owner', ARG_STRING, "{$user['unityid']}@{$user['affiliation']}"); $return['ipaddress'] = processInputVar('ipaddress', ARG_STRING); $return['stateid'] = processInputVar('stateid', ARG_NUMERIC); $return['sysadminemail'] = processInputVar('sysadminemail', ARG_STRING); $return['sharedmailbox'] = processInputVar('sharedmailbox', ARG_STRING); $return['installpath'] = processInputVar('installpath', ARG_STRING); $return['timeservers'] = processInputVar('timeservers', ARG_STRING); $return['keys'] = processInputVar('keys', ARG_STRING); $return['sshport'] = processInputVar('sshport', ARG_NUMERIC); $return['imagelibenable'] = processInputVar('imagelibenable', ARG_NUMERIC); $return['imagelibgroupid'] = processInputVar('imagelibgroupid', ARG_NUMERIC); $return['imagelibuser'] = processInputVar('imagelibuser', ARG_STRING); $return['imagelibkey'] = processInputVar('imagelibkey', ARG_STRING); $return['publicIPconfig'] = processInputVar('publicIPconfig', ARG_STRING); $return['publicnetmask'] = processInputVar('publicnetmask', ARG_STRING); $return['publicgateway'] = processInputVar('publicgateway', ARG_STRING); $return['publicdnsserver'] = processInputVar('publicdnsserver', ARG_STRING); $return['checkininterval'] = processInputVar('checkininterval', ARG_NUMERIC); $return['availablenetworks'] = processInputVar('availablenetworks', ARG_STRING); $return['federatedauth'] = processInputVar('federatedauth', ARG_STRING); $return['nathostenabled'] = processInputVar('nathostenabled', ARG_NUMERIC); $return['natpublicIPaddress'] = processInputVar('natpublicipaddress', ARG_STRING); $return['natinternalIPaddress'] = processInputVar('natinternalipaddress', ARG_STRING); if (get_magic_quotes_gpc()) { $return['sysadminemail'] = stripslashes($return['sysadminemail']); $return['sharedmailbox'] = stripslashes($return['sharedmailbox']); } $olddata = getContinuationVar('olddata'); if ($return['rscid'] == 0) { $return['mode'] = 'add'; } else { $return['mode'] = 'edit'; } $errormsg = array(); # hostname if (!preg_match('/^[a-zA-Z0-9_][-a-zA-Z0-9_\\.]{1,49}$/', $return['name'])) { $return['error'] = 1; $errormsg[] = "Hostname can only contain letters, numbers, dashes(-), periods(.), and underscores(_). It can be from 1 to 50 characters long"; } elseif ($this->checkForMgmtnodeHostname($return['name'], $return['rscid'])) { $return['error'] = 1; $errormsg[] = "A node already exists with this hostname."; } # owner if (!validateUserid($return['owner'])) { $return['error'] = 1; $errormsg[] = "Submitted owner is not valid"; } # ipaddress if (!validateIPv4addr($return['ipaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } # sysadminemail if ($return['sysadminemail'] != '') { $addrs = explode(',', $return['sysadminemail']); foreach ($addrs as $addr) { if (!validateEmailAddress($addr)) { $return['error'] = 1; $errormsg[] = "Invalid email address entered for SysAdmin Email Address(es)"; break; } } } # sharedmailbox if ($return['sharedmailbox'] != '' && !validateEmailAddress($return['sharedmailbox'])) { $return['error'] = 1; $errormsg[] = "Invalid email address entered for Shadow Emails"; } # installpath if ($return['installpath'] != '' && !preg_match('/^([-a-zA-Z0-9_\\.\\/]){2,100}$/', $return['installpath'])) { $return['error'] = 1; $errormsg[] = "Install Path must be empty or only contain letters, numbers, dashes(-), periods(.), underscores(_), and forward slashes(/) and be from 2 to 100 characters long"; } # timeservers if ($return['timeservers'] != '') { if (strlen($return['timeservers']) > 1000) { $return['error'] = 1; $errormsg[] = "Too much data entered for Time Server(s)"; } else { $hosts = explode(',', $return['timeservers']); foreach ($hosts as $host) { if (preg_match('/^([0-9]{1,3}(\\.?))+$/', $host) && !validateIPv4addr($host) || !preg_match('/^[a-zA-Z0-9_][-a-zA-Z0-9_\\.]{1,50}$/', $host)) { $return['error'] = 1; $errormsg[] = "Time servers must be an IP address or a hostname containing only letters, numbers, dashes(-), periods(.), and underscores(_). Each host can be up to 50 characters long"; break; } } } } # keys if ($return['keys'] != '' && !preg_match('/^([-a-zA-Z0-9_\\.\\/,]){2,1024}$/', $return['keys'])) { $return['error'] = 1; $errormsg[] = "End Node SSH Identity Key Files can only contain letters, numbers, dashes(-), periods(.), underscores(_), forward slashes(/), and commas(,). It can be from 2 to 1024 characters long"; } # imagelibenable if ($return['imagelibenable'] == 1) { # imagelibgroupid $validgroups = getUserResources(array('mgmtNodeAdmin'), array('manageGroup'), 1); if (!array_key_exists($return['imagelibgroupid'], $validgroups['managementnode'])) { $return['error'] = 1; $errormsg[] = "The group selected for Image Library Management Node Group is not valid"; } # imagelibuser if (!preg_match('/^([-a-zA-Z0-9_\\.\\/,]){2,20}$/', $return['imagelibuser'])) { $return['error'] = 1; $errormsg[] = "Image Library User can only contain letters, numbers, and dashes(-) and can be from 2 to 20 characters long"; } # imagelibkey if (!preg_match('/^([-a-zA-Z0-9_\\.\\/,]){2,100}$/', $return['imagelibkey'])) { $return['error'] = 1; $errormsg[] = "Image Library SSH Identity Key File can only contain letters, numbers, dashes(-), periods(.), underscores(_), and forward slashes(/). It can be from 2 to 100 characters long"; } } else { $return['imagelibenable'] = 0; if ($return['mode'] == 'edit') { $return['imagelibgroupid'] = $olddata['imagelibgroupid']; $return['imagelibuser'] = $olddata['imagelibuser']; $return['imagelibkey'] = $olddata['imagelibkey']; } else { $return['imagelibgroupid'] = ''; $return['imagelibuser'] = ''; $return['imagelibkey'] = ''; } } # publicIPconfig if (!preg_match('/^(dynamicDHCP|manualDHCP|static)$/', $return['publicIPconfig'])) { $return['publicIPconfig'] = 'dynamicDHCP'; } if ($return['publicIPconfig'] == 'static') { # publicnetmask $bnetmask = ip2long($return['publicnetmask']); if (!preg_match('/^[1]+0[^1]+$/', sprintf('%032b', $bnetmask))) { $return['error'] = 1; $errormsg[] = "Invalid value specified for Public Netmask"; } # publicgateway if (preg_match('/^([0-9]{1,3}(\\.?))+$/', $return['publicgateway']) && !validateIPv4addr($return['publicgateway'])) { $return['error'] = 1; $errormsg[] = "Invalid value specified for Public Gateway"; } elseif (!preg_match('/^[a-zA-Z0-9_][-a-zA-Z0-9_\\.]{1,56}$/', $return["publicgateway"])) { $return['error'] = 1; $errormsg[] = "Public gateway must be an IP address or a hostname containing only letters, numbers, dashes(-), periods(.), and underscores(_). It can be up to 56 characters long"; } # publicdnsserver $servers = explode(',', $return['publicdnsserver']); if (empty($servers)) { $return['error'] = 1; $errormsg[] = "Please enter at least one Public DNS server"; } else { foreach ($servers as $server) { if (!validateIPv4addr($server)) { $return['error'] = 1; $errormsg[] = "Invalid IP address entered for Public DNS Server"; break; } } } } else { $return['publicnetmask'] = $olddata['publicnetmask']; $return['publicgateway'] = $olddata['publicgateway']; } # stateid 2 - available, 5 - failed, 10 - maintenance if (!preg_match('/^(2|5|10)$/', $return['stateid'])) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for State"; } # checkininterval if ($return['checkininterval'] < 5) { $return['checkininterval'] = 5; } elseif ($return['checkininterval'] > 30) { $return['checkininterval'] = 30; } # sshport if ($return['sshport'] < 1 || $return['sshport'] > 65535) { $return['sshport'] = 22; } # availablenetworks if ($return['availablenetworks'] != '') { if (strpos("\n", $return['availablenetworks'])) { $return['availablenetworks'] = preg_replace("/(\r)?\n/", ',', $return['availablenetworks']); } $return['availablenetworks2'] = explode(',', $return['availablenetworks']); foreach ($return['availablenetworks2'] as $key => $net) { $net = trim($net); if ($net == '') { unset($return['availablenetworks2'][$key]); $return['availablenetworks'] = implode("\n", $return['availablenetworks2']); continue; } $return['availablenetworks2'][$key] = $net; if (!preg_match('/^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\/([0-9]{2})$/', $net, $matches) || $matches[1] < 0 || $matches[1] > 255 || $matches[2] < 0 || $matches[2] > 255 || $matches[3] < 0 || $matches[3] > 255 || $matches[4] < 0 || $matches[4] > 255 || $matches[5] < 1 || $matches[5] > 32) { $return['error'] = 1; $errormsg[] = "Invalid network entered for Available Public Networks; must be comma delimited list of valid networks in the form of x.x.x.x/yy"; } } } # federatedauth if ($return['federatedauth'] != '') { $affils = getAffiliations(); $fedarr = explode(',', $return['federatedauth']); $test = array_udiff($fedarr, $affils, 'strcasecmp'); if (!empty($test)) { $new = array(); foreach ($test as $affil) { if (preg_match('/^[-0-9a-zA-Z_\\.:;,]*$/', $affil)) { $new[] = $affil; } } if (count($test) == count($new)) { $errormsg[] = "These affiliations do not exist: " . implode(', ', $new); } else { $errormsg[] = "Invalid data entered for Affiliations using Federated Authentication for Linux Images"; } $return['error'] = 1; } } $nathosterror = 0; # nathostenabled if ($return['nathostenabled'] != 0 && $return['nathostenabled'] != 1) { $return['error'] = 1; $errormsg[] = "Invalid value for Use as NAT Host"; $nathosterror = 1; } # natpublicIPaddress if ($return['nathostenabled']) { if (!validateIPv4addr($return['natpublicIPaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid NAT Public IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; $nathosterror = 1; } # natinternalIPaddress if (!validateIPv4addr($return['natinternalIPaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid NAT Internal IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; $nathosterror = 1; } } # nat host change - check for active reservations if (!$nathosterror && $return['mode'] == 'edit') { if ($olddata['nathostenabled'] != $return['nathostenabled'] || $olddata['natpublicIPaddress'] != $return['natpublicIPaddress'] || $olddata['natinternalIPaddress'] != $return['natinternalIPaddress']) { $vclreloadid = getUserlistID('vclreload@Local'); $query = "SELECT rq.id " . "FROM request rq, " . "reservation rs, " . "nathostcomputermap nhcm, " . "nathost nh " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = nhcm.computerid AND " . "nhcm.nathostid = nh.id AND " . "nh.resourceid = {$olddata['resourceid']} AND " . "rq.start <= NOW() AND " . "rq.end > NOW() AND " . "rq.stateid NOT IN (1,5,11,12) AND " . "rq.laststateid NOT IN (1,5,11,12) AND " . "rq.userid != {$vclreloadid}"; $qh = doQuery($query); if (mysql_num_rows($qh)) { $return['error'] = 1; $errormsg[] = "This management node is the NAT host for computers that have active reservations. NAT host<br>settings cannot be changed while providing NAT for active reservations."; } } } if ($return['error']) { $return['errormsg'] = implode('<br>', $errormsg); } return $return; }
function getPubliByRefHAL($refHAL, $version = 1) { $ret = null; $url = sprintf("http://api.archives-ouvertes.fr/search/?wt=json&q=halId_s:\"%s\"&q=version_i:\"%d\"&fl=*", $refHAL, $version); $hal = url($url); $hal = json_decode($hal); $hal = objectToArray($hal); if (isset($hal['response']['docs'][0])) { $publi = $hal['response']['docs'][0]; $ret = rosettise($publi); $ret['auteur'] = getAuteurs($publi); } /* transcodage latin1 */ array_walk_recursive($ret, function (&$value, $key) { if (is_array($value) == false) { $value = iconv('UTF-8', 'ISO-8859-1', $value); } }); /* parseAffiliations */ $laboratoires_parsed = getAffiliations($ret['auteur']['laboratoires']); unset($ret['auteur']['laboratoires']); fixAffiliations($ret['auteur'], $laboratoires_parsed); return $ret; }