deleteuser.php3 7.47 KB
Newer Older
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2003, 2006, 2007, 2009, 2010 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5 6
# All rights reserved.
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
7 8 9 10 11
include("defs.php3");

#
# Only known and logged in users allowed.
#
12 13 14
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
15 16

#
17
# Verify page arguments.
18
#
19 20 21 22 23 24 25 26
$reqargs = RequiredPageArguments("target_user",     PAGEARG_USER);
$optargs = OptionalPageArguments("target_project",  PAGEARG_PROJECT,
				 "canceled",        PAGEARG_BOOLEAN,
				 "confirmed",       PAGEARG_BOOLEAN,
				 "confirmed_twice", PAGEARG_BOOLEAN,
				 "request",         PAGEARG_BOOLEAN);

# Need these below.
27 28
$target_dbuid = $target_user->uid();
$target_uid   = $target_user->uid();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
29

30 31 32 33 34
#
# Standard Testbed Header
#
PAGEHEADER("Remove User");

Leigh B. Stoller's avatar
Leigh B. Stoller committed
35
#
36 37 38
# Requesting? Fire off email and we are done. 
# 
if (isset($request) && $request) {
39 40
    $uid_name  = $this_user->name();
    $uid_email = $this_user->email();
41 42 43 44

    TBMAIL($TBMAIL_OPS,
	   "Delete User Request: '$target_uid'",
	   "$uid is requesting that user account '$target_uid' be deleted\n".
45
	   "from the testbed since $target_uid is no longer a member of any ".
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
	   "projects.\n",
	   "From: $uid_name '$uid' <$uid_email>\n".
	   "Errors-To: $TBMAIL_WWW");

    echo "A request to remove user '$target_uid' has been sent to Testbed
          Operations. If you do not hear back within a reasonable amount
          of time, please contact $TBMAILADDR.\n";

    #
    # Standard Testbed Footer
    # 
    PAGEFOOTER();
    return;
}

#
62 63
# Must not be the head of the project being removed from, or any projects
# if being completely removed.
64
#
65
if (isset($target_project)) {
66 67
    $target_pid = $target_project->pid();
    
68 69 70 71
    if (! $isadmin &&
	! $target_project->AccessCheck($this_user, $TB_PROJECT_DELUSER)) {
	USERERROR("You do not have permission to remove user ".
		  "$target_uid from project $target_pid!", 1);
72
    }
73
    
74 75 76
    $leader = $target_project->GetLeader();

    if ($leader->SameUser($target_user)) {
77 78 79 80
	USERERROR("$target_uid is the leader of project $target_pid!", 1);
    }
}
else {
81
    $projlist = $target_user->ProjectMembershipList(TBDB_TRUSTSTRING_PROJROOT);
82

83
    if (count($projlist)) {
84 85
	USERERROR("$target_uid is still heading up projects!", 1);
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
86 87 88
}

#
89 90 91
# Must not be the head of any groups in the project, or any groups if
# being deleted from the testbed.
#
92
if (isset($target_project)) {
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
    $query_result =
	DBQueryFatal("select pid,gid from groups ".
		     "where leader='$target_uid' and pid='$target_pid'");
    
    if (mysql_num_rows($query_result)) {
	USERERROR("$target_uid is still leading groups in ".
		  "project '$target_pid'", 1);
    }
}
else {
    $query_result =
	DBQueryFatal("select pid,gid from groups where leader='$target_uid'");

    if (mysql_num_rows($query_result)) {
	USERERROR("$target_uid is still heading up groups!", 1);
    }
}

#
# User must not be heading up any experiments at all. If deleting from
# just a specific project, must not be heading up experiments in that
# project. 
115 116 117 118
#
$experimentlist =
    $target_user->ExperimentList(1, ((isset($target_project)) ?
				     $target_project->DefaultGroup() : null));
119

120
if (count($experimentlist)) {
121 122
    echo "<center><h3>
          User '$target_uid' is heading up the following experiments ".
123
	  (isset($target_project) ? "in project '$target_pid' " : "") .
124 125 126 127 128 129 130 131 132 133 134
	  ":</h3></center>\n";

    echo "<table align=center border=1 cellpadding=2 cellspacing=2>\n";

    echo "<tr>
              <th align=center>PID</td>
              <th align=center>EID</td>
              <th align=center>State</td>
              <th align=center>Description</td>
          </tr>\n";

135 136 137 138 139 140 141 142
    foreach ($experimentlist as $experiment) {
	$pid   = $experiment->pid();
	$eid   = $experiment->eid();
	$state = $experiment->state();
	$desc  = $experiment->description();
	
	if ($experiment->swap_requests() > 0) {
	    $state .= "&nbsp;(idle)";
143
	}
144 145 146

	$showproj_url = CreateURL("showproject", $experiment->Project());
	$showexp_url  = CreateURL("showexp", $experiment);
147 148 149 150 151
	
        echo "<tr>
                 <td><A href='showproject.php3?pid=$pid'>$pid</A></td>
                 <td><A href='showexp.php3?pid=$pid&eid=$eid'>$eid</A></td>
		 <td>$state</td>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
152
                 <td>$desc</td>
153 154 155 156 157 158 159 160 161
             </tr>\n";
    }
    echo "</table>\n";

    USERERROR("They must be terminated before you can remove the user!", 1);
}

#
# We do a double confirmation, running this script multiple times. 
Leigh B. Stoller's avatar
Leigh B. Stoller committed
162
#
163
if (isset($canceled) && $canceled) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
164 165 166 167 168 169 170 171
    echo "<center><h2><br>
          User Removal Canceled!
          </h2></center>\n";
    
    PAGEFOOTER();
    return;
}

172
if (!isset($confirmed)) {
173 174
    echo "<center><br>\n";

175
    if (isset($target_project)) {
176
	echo "Are you <b>REALLY</b> sure you want to remove user
Leigh B. Stoller's avatar
Leigh B. Stoller committed
177
              '$target_uid' from project '$target_pid'?\n";
178 179 180 181 182
    }
    else {
	echo "Are you <b>REALLY</b> sure you want to delete user 
              '$target_uid' from the testbed?\n";
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
183
    
184 185 186 187 188 189
    if (isset($target_project))
	$url = CreateURL("deleteuser", $target_user, $target_project);
    else
	$url = CreateURL("deleteuser", $target_user);
    
    echo "<form action='$url' method=post>";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
190 191 192 193 194 195 196 197 198
    echo "<b><input type=submit name=confirmed value=Confirm></b>\n";
    echo "<b><input type=submit name=canceled value=Cancel></b>\n";
    echo "</form>\n";
    echo "</center>\n";

    PAGEFOOTER();
    return;
}

199
if (!isset($confirmed_twice)) {
200
    echo "<center><br>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
201
	  Okay, let's be sure.<br>\n";
202

203
    if (isset($target_project)) {
204
	echo "Are you <b>REALLY REALLY</b> sure you want to remove user
Leigh B. Stoller's avatar
Leigh B. Stoller committed
205
              '$target_uid' from project '$target_pid'?\n";
206 207 208 209 210
    }
    else {
	echo "Are you <b>REALLY REALLY</b> sure you want to delete user 
              '$target_uid' from the testbed?\n";
    }
211 212 213 214 215

    if (isset($target_project))
	$url = CreateURL("deleteuser", $target_user, $target_project);
    else
	$url = CreateURL("deleteuser", $target_user);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
216
    
217
    echo "<form action='$url' method=post>";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
218 219 220 221 222 223 224 225 226 227
    echo "<input type=hidden name=confirmed value=Confirm>\n";
    echo "<b><input type=submit name=confirmed_twice value=Confirm></b>\n";
    echo "<b><input type=submit name=canceled value=Cancel></b>\n";
    echo "</form>\n";
    echo "</center>\n";

    PAGEFOOTER();
    return;
}

228 229 230 231 232
if (isset($target_project)) {
    STARTBUSY("User '$target_uid' is being removed from '$target_pid'!");
}
else {
    STARTBUSY("User '$target_uid' is being removed!");
233
    DOLOGOUT($target_user);
234
}
235 236

#
237
# All the real work is done in the script.
238
#
239
SUEXEC($uid, $TBADMINGROUP,
240
       "webrmuser " . (isset($target_project) ? "-p $target_pid " : " ") .
241
       "$target_uid",
242
       SUEXEC_ACTION_DIE);
243

244
STOPBUSY();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
245 246

#
247 248 249 250
# If a user was removed from a project, and that user no longer has
# any project membership, ask if they want the user deleted. Admin
# people can act on it immediately of couse, but mere users, even
# project leaders, must send us a request for it.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
251
#
252
if (isset($target_project)) {
253 254 255 256
    $projlist = $target_user->ProjectMembershipList();
    
    if (! count($projlist)) {
	echo "<b>User 'target_uid' is no longer a member of any projects.\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
257

258
	$url = CreateURL("deleteuser", $target_user);
259 260 261
	    
	if ($isadmin) {
	    echo "Do you want to
262
                  <A href='$url'>delete this user from the testbed?</a>\n";
263 264 265
	}
	else {
	    echo "You can 
266
                  <A href='${url}&request=1'>request</a>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
267
                     that we delete this user from the testbed</a></b>\n";
268 269
	}
    }
270
    else {
271
	if (isset($target_project)) {
272 273
	    PAGEREPLACE(CreateURL("showgroup",
				  $target_project->DefaultGroup()));
274 275
	}
    }
276
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
277 278 279 280 281 282

#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>