deleteuser.php3 8.18 KB
Newer Older
Leigh Stoller's avatar
Leigh Stoller committed
1
<?php
Leigh Stoller's avatar
Leigh 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 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 allowed.
#
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.
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 Stoller's avatar
Leigh Stoller committed
46

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

Leigh Stoller's avatar
Leigh 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 89
    if (! $isadmin) {
        if (! $target_project->CanDeleteUser($this_user, $target_user)) {
            USERERROR("You do not have permission to remove user ".
                      "$target_uid from project $target_pid!", 1);
        }
90
    }
91
    
92 93 94
    $leader = $target_project->GetLeader();

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

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

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

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

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

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

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

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

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

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

    if (isset($target_project))
	$url = CreateURL("deleteuser", $target_user, $target_project);
    else
	$url = CreateURL("deleteuser", $target_user);
Leigh Stoller's avatar
Leigh Stoller committed
234
    
235
    echo "<form action='$url' method=post>";
Leigh Stoller's avatar
Leigh Stoller committed
236 237 238 239 240 241 242 243 244 245
    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;
}

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

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

262
STOPBUSY();
Leigh Stoller's avatar
Leigh Stoller committed
263 264

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

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

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