deletegroup.php3 2.53 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-2007 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");

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

#
17
# Verify page arguments.
Leigh Stoller's avatar
Leigh Stoller committed
18
#
19 20 21 22 23 24 25 26 27
$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();
28
$gid_idx  = $group->gid_idx();
Leigh Stoller's avatar
Leigh Stoller committed
29 30 31 32

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

#
38
# Verify permission, for the project not the group
Leigh Stoller's avatar
Leigh Stoller committed
39
#
40
if (! $project->AccessCheck($this_user, $TB_PROJECT_DELGROUP)) {
Leigh Stoller's avatar
Leigh Stoller committed
41 42 43 44
    USERERROR("You do not have permission to delete groups in project $pid!",
	      1);
}

45 46 47 48 49
#
# Standard Testbed Header
#
PAGEHEADER("Delete a Group");

Leigh Stoller's avatar
Leigh Stoller committed
50 51 52
#
# Check to see if there are any active experiments. Abort if there are.
#
53 54 55 56
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
57 58 59 60 61 62 63 64
}

#
# 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.
#
65
if (isset($canceled) && $canceled) {
Leigh Stoller's avatar
Leigh Stoller committed
66 67 68 69 70 71 72 73
    echo "<center><h2>
          Group removal canceled!
          </h2></center>\n";
    
    PAGEFOOTER();
    return;
}

74
if (!isset($confirmed)) {
Leigh Stoller's avatar
Leigh Stoller committed
75 76 77 78
    echo "<center><h2>
          Are you <b>REALLY</b> sure you want to remove Group $gid
          in Project $pid?
          </h2>\n";
79 80

    $url = CreateURL("deletegroup", $group);
Leigh Stoller's avatar
Leigh Stoller committed
81
    
82
    echo "<form action='$url' method=post>";
Leigh Stoller's avatar
Leigh Stoller committed
83 84 85 86 87 88 89 90 91
    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;
}

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

Leigh Stoller's avatar
Leigh Stoller committed
94
#
95 96
# Run the script. They will remove the group directory and the unix group,
# and the DB state.
Leigh Stoller's avatar
Leigh Stoller committed
97
#
98
SUEXEC($uid, $unix_gid, "webrmgroup $gid_idx", SUEXEC_ACTION_DIE);
99
STOPBUSY();
Leigh Stoller's avatar
Leigh Stoller committed
100

101
PAGEREPLACE(CreateURL("showproject", $project));
Leigh Stoller's avatar
Leigh Stoller committed
102 103 104 105 106 107

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