deleteuser.php3 8.13 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
# Copyright (c) 2000-2017 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 B. Stoller's avatar
Leigh B. Stoller committed
23
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
24 25 26 27 28
include("defs.php3");

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

#
34
# Verify page arguments.
35
#
36 37 38 39 40 41 42 43
$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.
44 45
$target_dbuid = $target_user->uid();
$target_uid   = $target_user->uid();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
46

47 48 49 50 51
#
# Standard Testbed Header
#
PAGEHEADER("Remove User");

Leigh B. Stoller's avatar
Leigh B. Stoller committed
52
#
53 54 55
# Requesting? Fire off email and we are done. 
# 
if (isset($request) && $request) {
56 57
    $uid_name  = $this_user->name();
    $uid_email = $this_user->email();
58 59 60 61

    TBMAIL($TBMAIL_OPS,
	   "Delete User Request: '$target_uid'",
	   "$uid is requesting that user account '$target_uid' be deleted\n".
62
	   "from the testbed since $target_uid is no longer a member of any ".
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
	   "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;
}

#
79 80
# Must not be the head of the project being removed from, or any projects
# if being completely removed.
81
#
82
if (isset($target_project)) {
83 84
    $target_pid = $target_project->pid();
    
85 86 87 88
    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);
89
    }
90
    
91 92 93
    $leader = $target_project->GetLeader();

    if ($leader->SameUser($target_user)) {
94 95 96 97
	USERERROR("$target_uid is the leader of project $target_pid!", 1);
    }
}
else {
98
    $projlist = $target_user->ProjectMembershipList(TBDB_TRUSTSTRING_PROJROOT);
99

100
    if (count($projlist)) {
101 102
	USERERROR("$target_uid is still heading up projects!", 1);
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
103 104 105
}

#
106 107 108
# Must not be the head of any groups in the project, or any groups if
# being deleted from the testbed.
#
109
if (isset($target_project)) {
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
    $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. 
132 133 134
#
$experimentlist =
    $target_user->ExperimentList(1, ((isset($target_project)) ?
135
				     $target_project : null));
136

137
if (count($experimentlist)) {
138 139
    echo "<center><h3>
          User '$target_uid' is heading up the following experiments ".
140
	  (isset($target_project) ? "in project '$target_pid' " : "") .
141 142 143 144 145 146 147 148 149 150 151
	  ":</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";

152 153 154 155
    foreach ($experimentlist as $experiment) {
	$pid   = $experiment->pid();
	$eid   = $experiment->eid();
	$state = $experiment->state();
156
	$desc  = CleanString($experiment->description());
157 158 159
	
	if ($experiment->swap_requests() > 0) {
	    $state .= "&nbsp;(idle)";
160
	}
161 162 163

	$showproj_url = CreateURL("showproject", $experiment->Project());
	$showexp_url  = CreateURL("showexp", $experiment);
164 165 166 167 168
	
        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
169
                 <td>$desc</td>
170 171 172 173 174 175 176 177 178
             </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
179
#
180
if (isset($canceled) && $canceled) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
181 182 183 184 185 186 187 188
    echo "<center><h2><br>
          User Removal Canceled!
          </h2></center>\n";
    
    PAGEFOOTER();
    return;
}

189
if (!isset($confirmed)) {
190 191
    echo "<center><br>\n";

192
    if (isset($target_project)) {
193
	echo "Are you <b>REALLY</b> sure you want to remove user
Leigh B. Stoller's avatar
Leigh B. Stoller committed
194
              '$target_uid' from project '$target_pid'?\n";
195 196 197 198 199
    }
    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
200
    
201 202 203 204 205 206
    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
207 208 209 210 211 212 213 214 215
    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;
}

216
if (!isset($confirmed_twice)) {
217
    echo "<center><br>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
218
	  Okay, let's be sure.<br>\n";
219

220
    if (isset($target_project)) {
221
	echo "Are you <b>REALLY REALLY</b> sure you want to remove user
Leigh B. Stoller's avatar
Leigh B. Stoller committed
222
              '$target_uid' from project '$target_pid'?\n";
223 224 225 226 227
    }
    else {
	echo "Are you <b>REALLY REALLY</b> sure you want to delete user 
              '$target_uid' from the testbed?\n";
    }
228 229 230 231 232

    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
233
    
234
    echo "<form action='$url' method=post>";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
235 236 237 238 239 240 241 242 243 244
    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;
}

245 246 247 248 249
if (isset($target_project)) {
    STARTBUSY("User '$target_uid' is being removed from '$target_pid'!");
}
else {
    STARTBUSY("User '$target_uid' is being removed!");
250
    DOLOGOUT($target_user);
251
}
252 253

#
254
# All the real work is done in the script.
255
#
256
SUEXEC($uid, $TBADMINGROUP,
257
       "webrmuser " . (isset($target_project) ? "-p $target_pid " : " ") .
258
       "$target_uid",
259
       SUEXEC_ACTION_DIE);
260

261
STOPBUSY();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
262 263

#
264 265 266 267
# 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
268
#
269
if (isset($target_project)) {
270 271 272
    $projlist = $target_user->ProjectMembershipList();
    
    if (! count($projlist)) {
Mike Hibler's avatar
Mike Hibler committed
273
	echo "<b>User '$target_uid' is no longer a member of any projects.\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
274

275
	$url = CreateURL("deleteuser", $target_user);
276 277 278
	    
	if ($isadmin) {
	    echo "Do you want to
279
                  <A href='$url'>delete this user from the testbed?</a>\n";
280 281 282
	}
	else {
	    echo "You can 
283
                  <A href='${url}&request=1'>request</a>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
284
                     that we delete this user from the testbed</a></b>\n";
285 286
	}
    }
287
    else {
288
	if (isset($target_project)) {
289 290
	    PAGEREPLACE(CreateURL("showgroup",
				  $target_project->DefaultGroup()));
291 292
	}
    }
293
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
294 295 296 297 298 299

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