Commit 46d45461 authored by Leigh Stoller's avatar Leigh Stoller

More refactoring and cleanup.

parent 30b53ed2
......@@ -1442,21 +1442,6 @@ function TBGetExptIdleIgnore($pid,$eid) {
return $row[idle_ignore];
}
#
# Get the default user interface that has been selected for the project.
#
function TBGetDefaultProjectUserInterface($pid) {
$query_result =
DBQueryWarn("select default_user_interface from projects ".
"where pid='$pid'");
if (mysql_num_rows($query_result) == 0) {
return 0;
}
$row = mysql_fetch_array($query_result);
return $row[0];
}
#
# Check if a site-specific variable exists.
#
......
......@@ -456,6 +456,13 @@ function ARRAY_PRINT($arr) {
}
}
#
# Return Yes or No given boolean
#
function YesNo($bool) {
return ($bool ? "Yes" : "No");
}
#
# Beware empty spaces (cookies)!
#
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003, 2005, 2006 University of Utah and the Flux Group.
# Copyright (c) 2000-2003, 2005, 2006, 2007 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
......@@ -74,7 +74,7 @@ if ($group->AccessCheck($this_user, $TB_PROJECT_BESTOWGROUPROOT)) {
# to main group either! This will force them to go through the approval
# page first.
#
$curmembers = $group->MemberList();
$curmembers =& $group->MemberList();
#
# Grab the user list from the project. These are the people who can be
......@@ -87,7 +87,7 @@ $nonmembers = $group->NonMemberList();
#
# We do not allow the actual group info to be edited. Just the membership.
#
SHOWGROUP($pid, $gid, $uid);
$group->Show();
echo "<br><center>
Important <a href='docwrapper.php3?docname=groups.html#SECURITY'>
......
......@@ -124,6 +124,13 @@ class Group
return $leader;
}
#
# Is this group the default project group. Returns boolean.
#
function IsProjectGroup() {
return $this->pid_idx() == $this->gid_idx();
}
#
# Access Check, which for now uses the global function to avoid duplication
# until all code is changed.
......@@ -686,4 +693,215 @@ class Group
}
return $mailstr;
}
function Show() {
global $OURDOMAIN;
global $MAILMANSUPPORT;
echo "<center>
<h3>Group Profile</h3>
</center>
<table align=center border=1>\n";
$pid = $this->pid();
$gid = $this->gid();
$gid_idx = $this->gid_idx();
$created = $this->created();
$leader = $this->leader();
$description = $this->description();
$expt_count = $this->expt_count();
$expt_last = $this->expt_last();
$unix_gid = $this->unix_gid();
$unix_name = $this->unix_name();
if ($this->IsProjectGroup())
$mail = "$pid" . "-users@" . $OURDOMAIN;
else
$mail = "$pid-$gid" . "-users@" . $OURDOMAIN;
if (!$expt_last) {
$expt_last = "&nbsp;";
}
if (! ($leader_user = $this->GetLeader())) {
TBERROR("Could not lookup object for user $leader", 1);
}
$showuser_url = CreateURL("showuser", $leader_user);
echo "<tr>
<td>GID: </td>
<td class=\"left\">
<a href='showgroup.php3?pid=$pid&gid=$gid'>$gid ($gid_idx)".
"</a></td>
</tr>\n";
echo "<tr>
<td>PID: </td>
<td class=\"left\">
<a href='showproject.php3?pid=$pid'>$pid</a></td>
</tr>\n";
echo "<tr>
<td>Description: </td>
<td class=\"left\">$description</td>
</tr>\n";
echo "<tr>
<td>Unix GID: </td>
<td class=\"left\">$unix_gid</td>
</tr>\n";
echo "<tr>
<td>Unix Group Name: </td>
<td class=\"left\">$unix_name</td>
</tr>\n";
echo "<tr>
<td>Group Leader: </td>
<td class=\"left\">
<a href='$showuser_url'>$leader</a></td>
</tr>\n";
if ($MAILMANSUPPORT) {
$mmurl = "gotommlist.php3?pid=$pid&gid=$gid";
echo "<tr>
<td>Email List:</td>
<td class=\"left\">
<a href='$mmurl'>$mail</a> ";
if (ISADMIN()) {
$mmurl .= "&wantadmin=1";
echo "<a href='$mmurl'>(admin page)</a>";
}
echo " </td>
</tr>\n";
}
else {
echo "<tr>
<td>Email List: </td>
<td class=\"left\">$mail</td>
</tr>\n";
}
echo "<tr>
<td>Created: </td>
<td class=\"left\">$created</td>
</tr>\n";
echo "<tr>
<td>Experiments Created:</td>
<td class=\"left\">$expt_count</td>
</tr>\n";
echo "<tr>
<td>Date of last experiment:</td>
<td class=\"left\">$expt_last</td>
</tr>\n";
echo "</table>\n";
}
#
# Pretty display of group members.
#
function ShowMembers($prived = 0) {
$gid_idx = $this->gid_idx();
$pid_idx = $this->pid_idx();
$query_result =
DBQueryFatal("select uid_idx,trust from group_membership ".
"where pid_idx='$pid_idx' and gid_idx='$gid_idx'");
if (! mysql_num_rows($query_result)) {
return;
}
$showdel = (($prived && $pid_idx == $gid_idx) ? 1 : 0);
$projgrp = (($pid_idx == $gid_idx) ? 1 : 0);
echo "<center>\n";
if ($projgrp)
echo "<h3>Project Members</h3>\n";
else
echo "<h3>Group Members</h3>\n";
echo "</center>
<table align=center border=1 cellpadding=1 cellspacing=2>\n";
echo "<tr>
<th>Name</th>\n";
if (! $projgrp) {
echo "<th>Email</th>\n";
}
echo " <th>UID</th>
<th>Privs</th>\n";
if ($showdel) {
echo "<th>Remove</th>\n";
}
echo "</tr>\n";
while ($row = mysql_fetch_array($query_result)) {
$uid_idx = $row["uid_idx"];
$trust = $row["trust"];
if (! ($target_user = User::Lookup($uid_idx))) {
TBERROR("Could not lookup object for user $target_uid", 1);
}
$usr_name = $target_user->name();
$usr_email = $target_user->email();
$usr_uid = $target_user->uid();
$showuser_url = CreateURL("showuser", $target_user);
$deluser_url = CreateURL("deleteuser", $target_user,
URLARG_PID, $pid);
echo "<tr>
<td>$usr_name</td>\n";
if (! $projgrp) {
echo "<td>$usr_email</td>\n";
}
echo " <td>
<a href='$showuser_url'>$usr_uid</a>
</td>\n";
if ($trust == TBDB_TRUSTSTRING_NONE)
echo "<td><font color=red>$trust</font></td>\n";
else
echo "<td>$trust</td>\n";
if ($showdel) {
echo "<td align=center>
<a href='$deluser_url'>
<img alt='Delete User' src=redball.gif></td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
}
function ShowStats() {
$gid_idx = $this->gid_idx();
$query_result =
DBQueryFatal("SELECT * from group_stats ".
"where gid_idx='$gid_idx'");
if (! mysql_num_rows($query_result)) {
return;
}
$row = mysql_fetch_assoc($query_result);
#
# Not pretty printed yet.
#
echo "<table align=center border=1>\n";
foreach($row as $key => $value) {
echo "<tr>
<td>$key:</td>
<td>$value</td>
</tr>\n";
}
echo "</table>\n";
}
}
......@@ -300,6 +300,9 @@ class Project
$this->group = $group;
return $group;
}
function Group() {
return $this->LoadGroup();
}
#
# Return user object for leader.
......@@ -424,8 +427,262 @@ class Project
$this->project["pcremote_ok"] = $ok;
return 0;
}
function Show() {
global $WIKISUPPORT, $CVSSUPPORT, $TBPROJ_DIR, $TBCVSREPO_DIR;
global $MAILMANSUPPORT, $OPSCVSURL, $USERNODE;
$group = $this->Group();
$pid = $this->pid();
$proj_idx = $this->pid_idx();
$proj_created = $this->created();
$proj_name = $this->name();
$proj_URL = $this->URL();
$proj_public = YesNo($this->public());
$proj_funders = $this->funders();
$proj_head_idx = $this->head_idx();
$proj_members = $this->num_members();
$proj_pcs = $this->num_pcs();
# These are now booleans, not actual counts.
$proj_ronpcs = YesNo($this->num_ron());
$proj_plabpcs = YesNo($this->num_pcplab());
$proj_linked = YesNo($this->linked_to_us());
$proj_why = nl2br($this->why());
$approved = YesNo($this->approved());
$expt_count = $this->expt_count();
$expt_last = $this->expt_last();
$wikiname = $group->wikiname();
$cvsrepo_public = $this->cvsrepo_public();
if (! ($head_user = User::Lookup($proj_head_idx))) {
TBERROR("Could not lookup object for user $proj_head_idx", 1);
}
$showuser_url = CreateURL("showuser", $head_user);
$showproj_url = CreateURL("showproject", $this);
$proj_head_uid = $head_user->uid();
if (!$expt_last) {
$expt_last = "&nbsp;";
}
echo "<center>
<h3>Project Profile</h3>
</center>
<table align=center cellpadding=2 border=1>\n";
#
# Generate the table.
#
echo "<tr>
<td>Name: </td>
<td class=\"left\">
<a href='showproj_url'>$pid ($proj_idx)</a></td>
</tr>\n";
echo "<tr>
<td>Description: </td>
<td class=\"left\">$proj_name</td>
</tr>\n";
echo "<tr>
<td>Project Head: </td>
<td class=\"left\">
<a href='$showuser_url'>$proj_head_uid</a></td>
</tr>\n";
echo "<tr>
<td>URL: </td>
<td class=\"left\">
<a href='$proj_URL'>$proj_URL</a></td>
</tr>\n";
if ($WIKISUPPORT && isset($wikiname)) {
$wikiurl = "gotowiki.php3?redurl=$wikiname/WebHome";
echo "<tr>
<td>Project Wiki:</td>
<td class=\"left\">
<a href='$wikiurl'>$wikiname</a></td>
</tr>\n";
}
if ($CVSSUPPORT) {
$cvsdir = "$TBCVSREPO_DIR/$pid";
$cvsurl = "cvsweb/cvsweb.php3?pid=$pid";
echo "<tr>
<td>Project CVS Repository:</td>
<td class=\"left\">
$cvsdir <a href='$cvsurl'>(CVSweb)</a></td>
</tr>\n";
$YesNo = YesNo($cvsrepo_public);
$flip = ($cvsrepo_public ? 0 : 1);
echo "<tr>
<td>CVS Repository Publically Readable?:</td>
<td><a href=toggle.php?pid=$pid&type=cvsrepo_public".
"&value=$flip>$YesNo</a> (Click to toggle)</td>
</tr>\n";
if ($cvsrepo_public) {
$puburl = "$OPSCVSURL/?cvsroot=$pid";
$pserver = ":pserver:anoncvs@$USERNODE:/cvsrepos/$pid";
echo "<tr>
<td>Public CVSWeb Address:</td>
<td><a href=$puburl>" .
htmlspecialchars($puburl) . "</a></td>
</tr>\n";
echo "<tr>
<td>CVS pserver Address:</td>
<td>" . htmlspecialchars($pserver) . "</td>
</tr>\n";
}
}
if ($MAILMANSUPPORT) {
$mmurl = "gotommlist.php3?pid=$pid";
echo "<tr>
<td>Project Mailing List:</td>
<td class=\"left\">
<a href='$mmurl'>${pid}-users</a> ";
if (ISADMIN()) {
$mmurl .= "&wantadmin=1";
echo "<a href='$mmurl'>(admin access)</a>";
}
echo " </td>
</tr>\n";
}
echo "<tr>
<td>Publicly Visible: </td>
<td class=\"left\">$proj_public</td>
</tr>\n";
echo "<tr>
<td>Link to Us?: </td>
<td class=\"left\">$proj_linked</td>
</tr>\n";
echo "<tr>
<td>Funders: </td>
<td class=\"left\">$proj_funders</td>
</tr>\n";
echo "<tr>
<td>#Project Members: </td>
<td class=\"left\">$proj_members</td>
</tr>\n";
echo "<tr>
<td>#PCs: </td>
<td class=\"left\">$proj_pcs</td>
</tr>\n";
echo "<tr>
<td>Planetlab Access: </td>
<td class=\"left\">$proj_plabpcs</td>
</tr>\n";
echo "<tr>
<td>RON Access: </td>
<td class=\"left\">$proj_ronpcs</td>
</tr>\n";
echo "<tr>
<td>Created: </td>
<td class=\"left\">$proj_created</td>
</tr>\n";
echo "<tr>
<td>Experiments Created:</td>
<td class=\"left\">$expt_count</td>
</tr>\n";
echo "<tr>
<td>Date of last experiment:</td>
<td class=\"left\">$expt_last</td>
</tr>\n";
echo "<tr>
<td>Approved?: </td>
<td class=\"left\">$approved</td>
</tr>\n";
echo "<tr>
<td colspan='2'>Why?:</td>
</tr>\n";
echo "<tr>
<td colspan='2' width=600>$proj_why</td>
</tr>\n";
echo "</table>\n";
}
function ShowGroupList() {
$pid_idx = $this->pid_idx();
$query_result =
DBQueryFatal("select * from groups where pid_idx='$pid_idx'");
if (!$query_result || !mysql_num_rows($query_result)) {
return;
}
echo "<h3>Project Groups</h3>\n";
echo "<table align=center border=1>\n";
echo "<tr>
<th>GID</th>
<th>Description</th>
<th>Leader</th>
</tr>\n";
while ($row = mysql_fetch_array($query_result)) {
$gid = $row[gid];
$desc = $row[description];
$leader = $row[leader];
if (! ($leader_user = User::Lookup($leader))) {
TBERROR("Could not lookup object for user $leader", 1);
}
$showuser_url = CreateURL("showuser", $leader_user);
echo "<tr>
<td><A href='showgroup.php3?pid=$pid&gid=$gid'>$gid</a></td>
<td>$desc</td>
<td><A href='$showuser_url'>$leader</A></td>
</tr>\n";
}
echo "</table>\n";
}
function ShowStats() {
$pid_idx = $this->pid_idx();
$query_result =
DBQueryFatal("select * from project_stats ".
"where pid_idx='$pid_idx'");
if (! mysql_num_rows($query_result)) {
return;
}
$row = mysql_fetch_assoc($query_result);
#
# Not pretty printed yet.
#
echo "<table align=center border=1>\n";
foreach($row as $key => $value) {
echo "<tr>
<td>$key:</td>
<td>$value</td>
</tr>\n";
}
echo "</table>\n";
}
}
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003, 2005, 2006 University of Utah and the Flux Group.
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
......@@ -12,7 +12,6 @@ include("showstuff.php3");
#
PAGEHEADER("Show Group Information");
#
# Note the difference with which this page gets it arguments!
# I invoke it using GET arguments, so uid and pid are are defined
......@@ -43,42 +42,43 @@ if (!isset($gid) ||
#
# Check to make sure thats this is a valid PID/GID.
#
$query_result =
DBQueryFatal("SELECT * FROM groups WHERE pid='$pid' and gid='$gid'");
if (mysql_num_rows($query_result) == 0) {
USERERROR("The group $pid/$gid is not a valid group", 1);
if (! ($group = Group::LookupByPidGid($pid, $gid))) {
USERERROR("No such group group $gid in project $pid!", 1);
}
$project = $group->Project();
#
# Verify permission to look at the group. This is a little different,
# since the standard test would look for permission in just the group,
# but we also want to allow user from the project with appropriate
# but we also want to allow users from the project with appropriate
# privs to look at the group.
#
if (! TBProjAccessCheck($uid, $pid, $gid, $TB_PROJECT_READINFO) &&
! TBMinTrust(TBGrpTrust($uid, $pid, $pid), $TBDB_TRUST_GROUPROOT)) {
USERERROR("You are not a member of group $gid in project $pid!", 1);
if (! ($group->AccessCheck($this_user, $TB_PROJECT_READINFO) ||
$project->AccessCheck($this_user, $TB_PROJECT_EDITGROUP))) {
USERERROR("You do not have permission to view ".
"group $gid in project $pid!", 1);
}
#
# See if user is privledged for deletion.
#
$prived = 0;
if ($isadmin || TBProjAccessCheck($uid, $pid, $pid, $TB_PROJECT_DELUSER)) {
if ($isadmin || $project->AccessCheck($this_user, $TB_PROJECT_DELUSER)) {
$prived = 1;
}
#
# This menu only makes sense for people with privs to use them.
#
if (TBProjAccessCheck($uid, $pid, $gid, $TB_PROJECT_EDITGROUP) ||
(strcmp($gid, $pid) &&
TBProjAccessCheck($uid, $pid, $pid, $TB_PROJECT_DELGROUP))) {
$showmenu = ($group->AccessCheck($this_user, $TB_PROJECT_EDITGROUP) ||
(! $group->IsProjectGroup() &&
$project->AccessCheck($this_user, $TB_PROJECT_DELGROUP)));
if ($showmenu) {
SUBPAGESTART();
SUBMENUSTART("Group Options");
if (TBProjAccessCheck($uid, $pid, $gid, $TB_PROJECT_EDITGROUP)) {
if ($group->AccessCheck($this_user, $TB_PROJECT_EDITGROUP)) {
WRITESUBMENUBUTTON("Edit this Group",
"editgroup_form.php3?pid=$pid&gid=$gid");
}
......@@ -86,19 +86,18 @@ if (TBProjAccessCheck($uid, $pid, $gid, $TB_PROJECT_EDITGROUP) ||
#
# A delete option, but not for the default group!
#
if (strcmp($gid, $pid) &&
TBProjAccessCheck($uid, $pid, $pid, $TB_PROJECT_DELGROUP)) {
if (! $group->IsProjectGroup() &&
$project->AccessCheck($this_user, $TB_PROJECT_DELGROUP)) {
WRITESUBMENUBUTTON("Delete this Group",
"deletegroup.php3?pid=$pid&gid=$gid");
}
SUBMENUEND();
}
SHOWGROUP($pid, $gid, $uid);
SHOWGROUPMEMBERS($pid, $gid, $prived);
$group->Show();
$group->ShowMembers($prived);
if (TBProjAccessCheck($uid, $pid, $gid, $TB_PROJECT_EDITGROUP) ||
TBProjAccessCheck($uid, $pid, $pid, $TB_PROJECT_DELGROUP)) {
if ($showmenu) {
SUBPAGEEND();
}
......@@ -117,7 +116,7 @@ if ($isadmin) {
<h3>Group Stats</h3>
</center>\n";
SHOWGROUPSTATS($pid, $gid);
$group->ShowStats();
}
#
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2006 University of Utah and the Flux Group.
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
......@@ -42,14 +42,15 @@ if (!TBvalid_pid($pid)) {
#
# Check to make sure thats this is a valid PID.
#
if (! TBValidProject($pid)) {
if (! ($project = Project::Lookup($pid))) {
USERERROR("The project '$pid' is not a valid project.", 1);
}
$group = $project->Group();
#
# Verify that this uid is a member of the project being displayed.
#
if (! TBProjAccessCheck($uid, $pid, $pid, $TB_PROJECT_READINFO)) {
if (! $project->AccessCheck($this_user, $TB_PROJECT_READINFO)) {
USERERROR("You are not a member of Project $pid.", 1);
}
......@@ -86,7 +87,7 @@ if ($numpcs) {
echo "</font></center>\n";
}
SHOWPROJECT($pid, $uid);
$project->Show();
SUBPAGEEND();
echo "<center>\n";
......@@ -96,41 +97,15 @@ echo "<tr valign=top><td class=stealth align=center>\n";
#
# A list of project members (from the default group).
#
SHOWGROUPMEMBERS($pid, $pid, 0);
$group->ShowMembers();
echo "</td><td align=center class=stealth>\n";
#
# A list of project Groups
#
echo "<h3>Project Groups</h3>\n";
$query_result =
DBQueryFatal("SELECT * FROM groups WHERE pid='$pid'");
echo "<table align=center border=1>\n";
echo "<tr>
<th>GID</th>
<th>Description</th>
<th>Leader</th>
</tr>\n";
while ($row = mysql_fetch_array($query_result)) {
$gid = $row[gid];
$desc = stripslashes($row[description]);
$leader = $row[leader];
if (! ($leader_user = User::Lookup($leader))) {
TBERROR("Could not lookup object for user $leader", 1);
}
$showuser_url = CreateURL("showuser", $leader_user);
echo "<tr>
<td><A href='showgroup.php3?pid=$pid&gid=$gid'>$gid</a></td>
<td>$desc</td>
<td><A href='$showuser_url'>$leader</A></td>
</tr>\n";
}
echo "</table>\n";
$project->ShowGroupList();