freezeuser.php3 4.62 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2003, 2006, 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/>.
# 
# }}}
23 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();
32 33

#
34 35 36 37 38 39 40 41 42
# Verify page arguments.
#
$reqargs = RequiredPageArguments("target_user",     PAGEARG_USER);
$optargs = OptionalPageArguments("action",	    PAGEARG_STRING,
				 "request",	    PAGEARG_BOOLEAN,
				 "canceled",        PAGEARG_STRING,
				 "confirmed",       PAGEARG_STRING,
				 "confirmed_twice", PAGEARG_STRING);

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
if (isset($action)) {
    if (strcmp($action, "freeze") && strcmp($action, "thaw")) {
	USERERROR("You can freeze a user or you can thaw a user!", 1);
    }
}
else {
    $action = "freeze";
}

if (!strcmp($action, "thaw")) {
    $tag    = "thawed";
    $dbaction = TBDB_USERSTATUS_ACTIVE;
}
else {
    $tag      = "frozen";
    $dbaction = TBDB_USERSTATUS_FROZEN;
}

61
# Need these below.
62
$target_uid = $target_user->uid();
63
$userstatus = $target_user->status();
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

#
# Confirm a valid op.
#
if (!strcmp($action, "thaw") &&
     strcmp($userstatus, TBDB_USERSTATUS_FROZEN)) {
    USERERROR("You cannot thaw someone who is not frozen!", 1);
}
if (!strcmp($action, "freeze")) {
    if (!strcmp($userstatus, TBDB_USERSTATUS_FROZEN)) {
	USERERROR("You cannot freeze someone who is already iced over!", 1);
    }
    if (strcmp($userstatus, TBDB_USERSTATUS_ACTIVE)) {
	USERERROR("You cannot freeze someone who is not active!", 1);
    }
}

81 82 83 84 85
#
# Standard Testbed Header
#
PAGEHEADER("Freeze User Account");

86 87 88 89
#
# Requesting? Fire off email and we are done. 
# 
if (isset($request) && $request) {
90 91
    $uid_name  = $this_user->name();
    $uid_email = $this_user->email();
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119

    TBMAIL($TBMAIL_OPS,
	   "$action User Request: '$target_uid'",
	   "$uid is requesting that user account '$target_uid' be $tag!\n",
	   "From: $uid_name '$uid' <$uid_email>\n".
	   "Errors-To: $TBMAIL_WWW");

    echo "A request to $action 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;
}

#
# Only admins.
#
if (!$isadmin) {
    USERERROR("You do not have permission to $action user '$target_uid'", 1);
}

#
# We do a double confirmation, running this script multiple times. 
#
120
if (isset($canceled) && $canceled) {
121 122 123 124 125 126 127 128
    echo "<center><h2><br>
          The $action has been canceled!
          </h2></center>\n";
    
    PAGEFOOTER();
    return;
}

129
if (!isset($confirmed)) {
130 131 132
    echo "<center><br>\n";

    echo "Are you <b>REALLY</b> sure you want to $action user '$target_uid'\n";
133 134

    $url = CreateURL("freezeuser", $target_user, "action", $action);
135
    
136
    echo "<form action='$url' method=post>";
137 138 139 140 141 142 143 144 145
    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;
}

146
if (!isset($confirmed_twice)) {
147 148 149 150 151 152
    echo "<center><br>
	  Okay, lets be sure.<br>\n";

    echo "Are you <b>REALLY REALLY</b> sure you want to $action user
              '$target_uid'\n";
    
153 154 155
    $url = CreateURL("freezeuser", $target_user, "action", $action);
    
    echo "<form action='$url' method=post>";
156 157 158 159 160 161 162 163 164 165
    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;
}

166 167
# Change the DB first; backend requires it.
$target_user->SetStatus($dbaction);
168

169
STARTBUSY("User '$target_uid' is being ${tag}!");
170
SUEXEC($uid, $TBADMINGROUP, "webtbacct $action $target_uid",SUEXEC_ACTION_DIE);
171
STOPBUSY();
172

173 174 175
# Back to user display.
PAGEREPLACE(CreateURL("showuser", $target_user));

176 177 178 179 180
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>