editgroup.php3 10.3 KB
Newer Older
Leigh Stoller's avatar
Leigh Stoller committed
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
23
#
Leigh Stoller's avatar
Leigh Stoller committed
24 25 26 27 28
include("defs.php3");

#
# Only known and logged in users.
#
29 30 31
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
Leigh Stoller's avatar
Leigh Stoller committed
32 33

#
34
# Verify page arguments.
Leigh Stoller's avatar
Leigh Stoller committed
35
#
36
$reqargs = RequiredPageArguments("group", PAGEARG_GROUP);
37 38
$optargs = OptionalPageArguments("submit",     PAGEARG_STRING,
				 "formfields", PAGEARG_ARRAY);
Leigh Stoller's avatar
Leigh Stoller committed
39 40

#
41
# The default group membership cannot be changed, but the trust levels can.
Leigh Stoller's avatar
Leigh Stoller committed
42
#
43
$defaultgroup = $group->IsProjectGroup();
Leigh Stoller's avatar
Leigh Stoller committed
44

45 46 47
# Need these below;
$pid = $group->pid();
$gid = $group->gid();
48

Leigh Stoller's avatar
Leigh Stoller committed
49
#
50
# Verify permission.
Leigh Stoller's avatar
Leigh Stoller committed
51
#
52
if (! $group->AccessCheck($this_user, $TB_PROJECT_EDITGROUP)) {
Leigh Stoller's avatar
Leigh Stoller committed
53 54 55 56
    USERERROR("You do not have permission to edit group $gid in ".
	      "project $pid!", 1);
}

57 58 59 60 61
#
# Standard Testbed Header
#
PAGEHEADER("Edit Group Membership");

Chad Barb's avatar
Chad Barb committed
62 63 64 65
#
# See if user is allowed to add non-members to group.
# 
$grabusers = 0;
66
if ($group->AccessCheck($this_user, $TB_PROJECT_GROUPGRABUSERS)) {
Chad Barb's avatar
Chad Barb committed
67 68 69
    $grabusers = 1;
}

Chad Barb's avatar
Chad Barb committed
70 71 72 73
#
# See if user is allowed to bestow group_root upon members of group.
# 
$bestowgrouproot = 0;
74
if ($group->AccessCheck($this_user, $TB_PROJECT_BESTOWGROUPROOT)) {
Chad Barb's avatar
Chad Barb committed
75 76 77
    $bestowgrouproot = 1;
}

Leigh Stoller's avatar
Leigh Stoller committed
78
#
79 80 81 82 83
# Grab the current user list for the group. Provide a button selection
# of people that can be removed. The group leader cannot be removed!
# Do not include members that have not been approved
# to main group either! This will force them to go through the approval
# page first.
Leigh Stoller's avatar
Leigh Stoller committed
84
#
85
$curmembers = $group->MemberList();
Leigh Stoller's avatar
Leigh Stoller committed
86 87 88

#
# Grab the user list from the project. These are the people who can be
89 90 91
# added. Do not include people in the above list, obviously! Do not
# include members that have not been approved to main group either! This
# will force them to go through the approval page first.
92
#
93
$nonmembers = $group->NonMemberList();
94 95

#
96
# Spit the form out using the array of data.
97
#
98 99 100 101
function SPITFORM($formfields, $errors)
{
    global $group, $defaultgroup;
    global $grabusers, $bestowgrouproot, $curmembers, $nonmembers;
102
    global $WIKIDOCURL;
103

104 105 106 107 108 109 110 111 112 113
    if ($errors) {
	echo "<table class=nogrid
                     align=center border=0 cellpadding=6 cellspacing=0>
              <tr>
                 <th align=center colspan=2>
                   <font size=+1 color=red>
                      &nbsp;Oops, please fix the following errors!&nbsp;
                   </font>
                 </td>
              </tr>\n";
114

115
	while (list ($name, $message) = each ($errors)) {
116 117
            # XSS prevention.
	    $message = CleanString($message);
118 119 120 121 122 123
	    echo "<tr>
                     <td align=right>
                       <font color=red>$name:&nbsp;</font></td>
                     <td align=left>
                       <font color=red>$message</font></td>
                  </tr>\n";
124
	}
125 126
	echo "</table><br>\n";
    }
127 128 129 130
    # XSS prevention.
    while (list ($key, $val) = each ($formfields)) {
	$formfields[$key] = CleanString($val);
    }
131

132 133 134 135
    #
    # We do not allow the actual group info to be edited. Just the membership.
    #
    $group->Show();
136

137
    echo "<br><center>
138
	   Important <a href='$WIKIDOCURL/Groups#SECURITY'>
139
	   security issues</a> are discussed in the
140
	   <a href='$WIKIDOCURL/Groups'>Groups Tutorial</a>.
141
	  </center>\n";
Chad Barb's avatar
Chad Barb committed
142

143 144 145 146 147 148
    if (count($curmembers) ||
	($grabusers && count($nonmembers))) {
	$url = CreateURL("editgroup", $group);
	echo "<br>
	      <table align=center border=1>
	      <form action='$url' method=post>\n";
149 150
    }

151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
    if (count($curmembers)) {
	if ($defaultgroup) {
	    echo "<tr><td align=center colspan=2 nowrap=1>
		  <br>
		  <font size=+1><b>Edit Trust Level</b></font>
		  <br>
		  You may edit trust level in the default group,<br>
		    but you are not allowed to remove members.
		  </td></tr>\n";
	}
	else {
	    echo "<tr><td align=center colspan=2 nowrap=1>
		  <br>
		  <font size=+1><b>Remove/Edit Group Members.</b></font>
		  <br>
		  Deselect the ones you would like to remove,<br>
		       or edit their trust value.
		  </td></tr>\n";
	}

	foreach ($curmembers as $target_user) {
	    $target_uid = $target_user->uid();
	    $target_idx = $target_user->uid_idx();
	    $trust      = $target_user->GetTempData();
	    $showurl    = CreateURL("showuser", $target_user);
Leigh Stoller's avatar
Leigh Stoller committed
176
	    $longname   = $target_user->name();
177 178 179 180 181 182 183

	    if ($defaultgroup) {
		echo "<tr>
			 <td>
			   <input type=hidden 
				  name=\"formfields[change_$target_idx]\"
				  value=permit>
Leigh Stoller's avatar
Leigh Stoller committed
184
			      <A href='$showurl'>$target_uid ($longname) &nbsp</A>
185 186 187 188 189 190 191
			 </td>\n";
	    }
	    else {
		echo "<tr>
			 <td>   
			   <input checked type=checkbox value=permit
				  name=\"formfields[change_$target_idx]\">
Leigh Stoller's avatar
Leigh Stoller committed
192
			      <A href='$showurl'>$target_uid ($longname) &nbsp</A>
193 194 195 196 197
			 </td>\n";
	    }

	    echo "   <td align=center>
			<select name=\"formfields[U${target_idx}\$\$trust]\">\n";
Chad Barb's avatar
Chad Barb committed
198 199

	    #
200
	    # We want to have the current trust value selected in the menu.
Chad Barb's avatar
Chad Barb committed
201
	    #
202 203 204 205 206
	    if ($group->CheckTrustConsistency($target_user,
					      TBDB_TRUSTSTRING_USER, 0)) {
		echo "<option value='user' " .
		    ((strcmp($trust, "user") == 0) ? "selected" : "") .
			">User </option>\n";
207
	    }
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
	    if ($group->CheckTrustConsistency($target_user,
					      TBDB_TRUSTSTRING_LOCALROOT, 0)) {
		echo "<option value='local_root' " .
		    ((strcmp($trust, "local_root") == 0) ? "selected" : "") .
			">Local Root </option>\n";

		#
		# If group_root is already selected, or we have permission to set
		# it, show it. Otherwise do not.
		#
		if (strcmp($trust, "group_root") == 0 || $bestowgrouproot) {
		    echo "<option value='group_root' " .
			((strcmp($trust, "group_root") == 0) ? "selected" : "") .
			    ">Group Root </option>\n";
		}
223
	    }
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
	    echo "        </select>
		       </td>\n";
	}
	echo "</tr>\n";
	reset($curmembers);
    }

    if ($grabusers && count($nonmembers)) {
	echo "<tr><td align=center colspan=2 nowrap=1>
	      <br>
	      <font size=+1><b>Add Group Members</b></font>[<b>1</b>].
		 <br>
		 Select the ones you would like to add.<br>
		 Be sure to select the appropriate trust level.
	      </td></tr>\n";

	foreach ($nonmembers as $target_user) {
	    $target_uid = $target_user->uid();
	    $target_idx = $target_user->uid_idx();
Leigh Stoller's avatar
Leigh Stoller committed
243
	    $longname   = $target_user->name();
244 245
	    $trust      = $target_user->GetTempData();
	    $showurl    = CreateURL("showuser", $target_user);
Chad Barb's avatar
Chad Barb committed
246

247 248 249 250
	    echo "<tr>
		     <td>
		       <input type=checkbox value=permit 
			      name=\"formfields[add_$target_idx]\">
Leigh Stoller's avatar
Leigh Stoller committed
251
			  <A href='$showurl'>$target_uid ($longname) &nbsp</A>
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
		     </td>\n";

	    echo "   <td align=center>
		       <select name=\"formfields[U${target_idx}\$\$trust]\">\n";

	    if ($group->CheckTrustConsistency($target_user,
					      TBDB_TRUSTSTRING_USER, 0)) {
		echo "<option value='user' " .
		    ((strcmp($trust, "user") == 0) ? "selected" : "") .
			">User</option>\n";
	    }
	    if ($group->CheckTrustConsistency($target_user,
					      TBDB_TRUSTSTRING_LOCALROOT, 0)) {
		echo "<option value='local_root' " .
		    ((strcmp($trust, "local_root") == 0) ? "selected" : "") .
			">Local Root</option>\n";

		if ($bestowgrouproot) {
		    echo "<option value='group_root' " .
			((strcmp($trust, "group_root") == 0) ? "selected" : "") .
			    ">Group Root</option>\n";
		}
Chad Barb's avatar
Chad Barb committed
274
	    }
275 276
	    echo "        </select>
		</td>\n";
277
	}
278 279
	echo "</tr>\n";
	reset($nonmembers);
280
    }
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310

    if (count($curmembers) ||
	($grabusers && count($nonmembers))) {
	echo "<tr>
		 <td align=center colspan=2>
		     <b><input type=submit name=submit value=Submit></b>
		 </td>
	      </tr>\n";

	echo "</form>
	      </table>\n";
    }
    else {
	echo "<br><center>
	       <em>There are no project members who are eligible to be added
		   or removed from this group[<b>1</b>].</em>
		 </center>\n";
    }

    echo "<h4><blockquote><blockquote><blockquote>
	  <ol>
	   <li> Only members who have already been approved to the main
		project will be listed. If a project member is missing, please
		go to <a href=approveuser_form.php3>New User Approval</a>
		and approve the user to the main project group. Then you can
		reload this page and add those members to other groups in your
		project.\n";
    echo "</ol>
	  </blockquote></blockquote></blockquote>
	  </h4>\n";
311 312 313
}

#
314 315 316 317 318
# Accumulate error reports for the user, e.g.
#    $errors["Key"] = "Msg";
# Required page args may need to be checked early.
$errors  = array();

319
#
320
# On first load, display a virgin form and exit.
321
#
322 323
if (!isset($submit) || !isset($formfields)) {
    $defaults = array();
324

325 326 327 328
    SPITFORM($defaults, $errors);
    PAGEFOOTER();
    return;
}
329

330 331 332 333 334 335 336 337 338 339
# Check that the formfields members are at least formatted correctly.
if (isset($formfields)) {
    foreach ($formfields as $key => $value) {
	if ( !((preg_match("/^change_[0-9]+$/", $key) ||
		preg_match("/^add_[0-9]+$/", $key)) &&
	       $value=="permit") &&
             !(preg_match("/^U[0-9]+\\$\\\$trust$/", $key) &&
	       ($value=="user" || $value=="local_root" || 
		$value=="group_root")) ) {
	    $errors["Args"] = "Invalid form arguments! $key=$value";
Chad Barb's avatar
Chad Barb committed
340
	}
Leigh Stoller's avatar
Leigh Stoller committed
341 342 343 344
    }
}

#
345 346
# If any errors, respit the form with the current values and the
# error messages displayed. Iterate until happy.
Leigh Stoller's avatar
Leigh Stoller committed
347
# 
348 349 350 351 352
if (count($errors)) {
    SPITFORM($formfields, $errors);
    PAGEFOOTER();
    return;
}
353

354 355 356 357 358 359 360 361 362
#
# The trust args are in the formfields array by keyword/value.
#
if (! ($result = Group::EditGroup($group, $uid, $formfields, $errors))) {
    # Always respit the form so that the form fields are not lost.
    # I just hate it when that happens so lets not be guilty of it ourselves.
    SPITFORM($formfields, $errors);
    PAGEFOOTER();
    return;
Leigh Stoller's avatar
Leigh Stoller committed
363 364
}

365
###STOPBUSY();
366

Leigh Stoller's avatar
Leigh Stoller committed
367
#
368 369
# Spit out a redirect so that the history does not include a post
# in it. The back button skips over the post and to the form.
Leigh Stoller's avatar
Leigh Stoller committed
370
# 
371
PAGEREPLACE(CreateUrl("showgroup", $group));
372

373 374 375 376
#
# Standard Testbed Footer
# 
PAGEFOOTER();
Leigh Stoller's avatar
Leigh Stoller committed
377
?>