deletegroup.php3 3.21 KB
Newer Older
Leigh Stoller's avatar
Leigh Stoller committed
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2007 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 37 38 39 40 41 42 43 44
$reqargs = RequiredPageArguments("group", PAGEARG_GROUP);
$optargs = OptionalPageArguments("canceled", PAGEARG_BOOLEAN,
				 "confirmed", PAGEARG_BOOLEAN);

# Needed below.
$pid = $group->pid();
$gid = $group->gid();
$project  = $group->Project();
$unix_gid = $project->unix_gid();
45
$gid_idx  = $group->gid_idx();
Leigh Stoller's avatar
Leigh Stoller committed
46 47 48 49

#
# We do not allow the default group to be deleted. Never ever!
#
50
if ($group->IsProjectGroup()) {
Leigh Stoller's avatar
Leigh Stoller committed
51 52 53 54
    USERERROR("You are not allowed to delete a project's default group!", 1);
}

#
55
# Verify permission, for the project not the group
Leigh Stoller's avatar
Leigh Stoller committed
56
#
57
if (! $project->AccessCheck($this_user, $TB_PROJECT_DELGROUP)) {
Leigh Stoller's avatar
Leigh Stoller committed
58 59 60 61
    USERERROR("You do not have permission to delete groups in project $pid!",
	      1);
}

62 63 64 65 66
#
# Standard Testbed Header
#
PAGEHEADER("Delete a Group");

Leigh Stoller's avatar
Leigh Stoller committed
67 68 69
#
# Check to see if there are any active experiments. Abort if there are.
#
70 71 72 73
if ($group->ExperimentList(0)) {
    USERERROR("Project/Group '$pid/$gid' has active experiments.<br> ".
	      "You must terminate ".
	      "those experiments before you can remove the group!", 1);
Leigh Stoller's avatar
Leigh Stoller committed
74 75 76 77 78 79 80 81
}

#
# We run this twice. The first time we are checking for a confirmation
# by putting up a form. The next time through the confirmation will be
# set. Or, the user can hit the cancel button, in which case we should
# probably redirect the browser back up a level.
#
82
if (isset($canceled) && $canceled) {
Leigh Stoller's avatar
Leigh Stoller committed
83 84 85 86 87 88 89 90
    echo "<center><h2>
          Group removal canceled!
          </h2></center>\n";
    
    PAGEFOOTER();
    return;
}

91
if (!isset($confirmed)) {
Leigh Stoller's avatar
Leigh Stoller committed
92 93 94 95
    echo "<center><h2>
          Are you <b>REALLY</b> sure you want to remove Group $gid
          in Project $pid?
          </h2>\n";
96 97

    $url = CreateURL("deletegroup", $group);
Leigh Stoller's avatar
Leigh Stoller committed
98
    
99
    echo "<form action='$url' method=post>";
Leigh Stoller's avatar
Leigh Stoller committed
100 101 102 103 104 105 106 107 108
    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;
}

109
STARTBUSY("Group '$gid' in project '$pid' is being removed!");
110

Leigh Stoller's avatar
Leigh Stoller committed
111
#
112 113
# Run the script. They will remove the group directory and the unix group,
# and the DB state.
Leigh Stoller's avatar
Leigh Stoller committed
114
#
115
SUEXEC($uid, $unix_gid, "webrmgroup $gid_idx", SUEXEC_ACTION_DIE);
116
STOPBUSY();
Leigh Stoller's avatar
Leigh Stoller committed
117

118
PAGEREPLACE(CreateURL("showproject", $project));
Leigh Stoller's avatar
Leigh Stoller committed
119 120 121 122 123 124

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