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

#
# Standard Testbed Header
#
Leigh Stoller's avatar
Leigh Stoller committed
12
PAGEHEADER("Remove User");
Leigh Stoller's avatar
Leigh Stoller committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26

#
# Only known and logged in users allowed.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);

#
# Verify arguments.
# 
if (!isset($target_uid) ||
    strcmp($target_uid, "") == 0) {
    USERERROR("You must provide a User ID.", 1);
}
27 28 29 30
if (isset($target_pid) &&
    strcmp($target_pid, "") == 0) {
    USERERROR("You must provide a valid project ID.", 1);
}
Leigh Stoller's avatar
Leigh Stoller committed
31 32 33
$isadmin = ISADMIN($uid);

#
34 35 36
# Confirm target is a real user.
#
if (! TBCurrentUser($target_uid)) {
Leigh Stoller's avatar
Leigh Stoller committed
37 38 39 40
    USERERROR("No such user '$target_uid'", 1);
}

#
41 42 43 44 45 46 47 48
# Requesting? Fire off email and we are done. 
# 
if (isset($request) && $request) {
    TBUserInfo($uid, $uid_name, $uid_email);

    TBMAIL($TBMAIL_OPS,
	   "Delete User Request: '$target_uid'",
	   "$uid is requesting that user account '$target_uid' be deleted\n".
49
	   "from the testbed since $target_uid is no longer a member of any ".
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
	   "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;
}

#
# Confirm optional pid is a real pid.
#
if (isset($target_pid) && !TBValidProject($target_pid)) {
    USERERROR("No such project '$target_pid'", 1);
}

#
# Check user. Proj leaders can remove users from their project, but thats
# all we allow. Deleting user accounts is left to admin people only.
Leigh Stoller's avatar
Leigh Stoller committed
75 76
#
if (!$isadmin) {
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
    if (! isset($target_pid) ||
	! TBProjAccessCheck($uid, $target_pid, 0, $TB_PROJECT_DELUSER)) {
	USERERROR("You do not have permission to remove user '$target_uid'",
		  1);
    }
}

#
# Must not be the head of the project being removed from, or any projects
# if being completely removed.
#
if (isset($target_pid)) {
    TBProjLeader($target_pid, $leader_uid);
    if (! strcmp($target_uid, $leader_uid)) {
	USERERROR("$target_uid is the leader of project $target_pid!", 1);
    }
}
else {
    $query_result =
	DBQueryFatal("select pid from projects where head_uid='$target_uid'");

    if (mysql_num_rows($query_result)) {
	USERERROR("$target_uid is still heading up projects!", 1);
    }
Leigh Stoller's avatar
Leigh Stoller committed
101 102 103
}

#
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 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
# Must not be the head of any groups in the project, or any groups if
# being deleted from the testbed.
#
if (isset($target_pid)) {
    $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. 
# 
$query_result =
    DBQueryFatal("SELECT * FROM experiments ".
		 "where expt_head_uid='$target_uid' ".
		 (isset($target_pid) ? "and pid='$target_pid'" : ""));

if (mysql_num_rows($query_result)) {
    echo "<center><h3>
          User '$target_uid' is heading up the following experiments ".
	  (isset($target_pid) ? "in project '$target_pid' " : "") .
	  ":</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";

    while ($projrow = mysql_fetch_array($query_result)) {
	$pid  = $projrow[pid];
	$eid  = $projrow[eid];
	$state= $projrow[state];
	$name = stripslashes($projrow[expt_name]);
	if ($projrow[swap_requests] > 0) {
	  $state .= "&nbsp;(idle)";
	}
	
        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>
                 <td>$name</td>
             </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 Stoller's avatar
Leigh Stoller committed
174 175 176 177 178 179 180 181 182 183 184
#
if ($canceled) {
    echo "<center><h2><br>
          User Removal Canceled!
          </h2></center>\n";
    
    PAGEFOOTER();
    return;
}

if (!$confirmed) {
185 186 187 188
    echo "<center><br>\n";

    if (isset($target_pid)) {
	echo "Are you <b>REALLY</b> sure you want to remove user
Leigh Stoller's avatar
Leigh Stoller committed
189
              '$target_uid' from project '$target_pid'?\n";
190 191 192 193 194
    }
    else {
	echo "Are you <b>REALLY</b> sure you want to delete user 
              '$target_uid' from the testbed?\n";
    }
Leigh Stoller's avatar
Leigh Stoller committed
195
    
196
    echo "<form action=deleteuser.php3 method=post>";
Leigh Stoller's avatar
Leigh Stoller committed
197
    echo "<input type=hidden name=target_uid value=\"$target_uid\">\n";
198 199 200
    if (isset($target_pid)) {
	echo "<input type=hidden name=target_pid value=\"$target_pid\">\n";
    }
Leigh Stoller's avatar
Leigh Stoller committed
201 202 203 204 205 206 207 208 209 210
    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;
}

if (!$confirmed_twice) {
211
    echo "<center><br>
Leigh Stoller's avatar
Leigh Stoller committed
212
	  Okay, let's be sure.<br>\n";
213 214 215

    if (isset($target_pid)) {
	echo "Are you <b>REALLY REALLY</b> sure you want to remove user
Leigh Stoller's avatar
Leigh Stoller committed
216
              '$target_uid' from project '$target_pid'?\n";
217 218 219 220 221
    }
    else {
	echo "Are you <b>REALLY REALLY</b> sure you want to delete user 
              '$target_uid' from the testbed?\n";
    }
Leigh Stoller's avatar
Leigh Stoller committed
222
    
223
    echo "<form action=deleteuser.php3 method=post>";
Leigh Stoller's avatar
Leigh Stoller committed
224
    echo "<input type=hidden name=target_uid value=\"$target_uid\">\n";
225 226 227
    if (isset($target_pid)) {
	echo "<input type=hidden name=target_pid value=\"$target_pid\">\n";
    }
Leigh Stoller's avatar
Leigh Stoller committed
228 229 230 231 232 233 234 235 236 237
    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;
}

238 239 240 241 242 243
echo "<br>
      User '$target_uid' is being removed" .
      (isset($target_pid) ? " from project '$target_pid' " : "") . 
      "!<br><br>
      This will take a minute or two. <b>Please</b> do not click the Stop
      button during this time. If you do not receive notification within
244
      a reasonable amount of time, please contact $TBMAILADDR.<br>\n";
245
flush();
246 247

#
248
# All the real work is done in the script.
249
#
250 251 252 253
SUEXEC($uid, $TBADMINGROUP,
       "webrmuser " . (isset($target_pid) ? "-p $target_pid " : " ") .
       "$target_uid",
       1);
254

Leigh Stoller's avatar
Leigh Stoller committed
255 256 257
#
# Warm fuzzies.
#
258
echo "<br><br><b>Done</b><br><br>\n";
Leigh Stoller's avatar
Leigh Stoller committed
259 260

#
261 262 263 264
# 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 Stoller's avatar
Leigh Stoller committed
265
#
266 267 268 269
if (isset($target_pid)) {
    $query_result =
	DBQueryFatal("select pid,gid from group_membership ".
		     "where uid='$target_uid' and pid=gid");
Leigh Stoller's avatar
Leigh Stoller committed
270

271 272 273 274 275 276 277 278 279 280 281 282
    if (! mysql_num_rows($query_result)) {
	echo "<b>User '$target_uid' is no longer a member of any projects.\n";
	    
	if ($isadmin) {
	    echo "Do you want to
                  <A href='deleteuser.php3?target_uid=$target_uid'>
                     delete this user from the testbed?</a>\n";
	}
	else {
	    echo "You can 
                  <A href='deleteuser.php3?target_uid=$target_uid&request=1'>
                     request</a>
Leigh Stoller's avatar
Leigh Stoller committed
283
                     that we delete this user from the testbed</a></b>\n";
284 285 286
	}
    }
}
Leigh Stoller's avatar
Leigh Stoller committed
287 288 289 290 291 292

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