approveproject.php3 10.8 KB
Newer Older
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
#
24 25 26
include("defs.php3");

#
27
# Only known and logged in users can do this.
28
#
29 30
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
31

32 33 34 35 36
# Verify page arguments.
$reqargs = RequiredPageArguments("project",  PAGEARG_PROJECT,
				 "approval", PAGEARG_STRING);
$optargs = OptionalPageArguments("head_uid", PAGEARG_STRING,
				 "user_interface", PAGEARG_STRING,
37
				 "message", PAGEARG_ANYTHING,
38 39 40
				 "silent", PAGEARG_BOOLEAN,
				 "pcplab_okay", PAGEARG_BOOLEAN,
				 "ron_okay", PAGEARG_BOOLEAN);
41

42 43 44 45
$sendemail = 1;
if (isset($silent) && $silent) {
    $sendemail = 0;
}
46

47 48 49 50 51
#
# Standard Testbed Header
#
PAGEHEADER("New Project Approved");

52 53 54
#
# Of course verify that this uid has admin privs!
#
55
$isadmin = ISADMIN();
56
if (! $isadmin) {
Chad Barb's avatar
Chad Barb committed
57
    USERERROR("You do not have admin privileges to approve projects!", 1);
58 59
}

60 61 62 63 64
#
# See if we are in an initial Emulab setup.
#
$FirstInitState = (TBGetFirstInitState() == "approveproject");

65
#
66
# Grab the head_uid for this project. This verifies it is a valid project.
67
#
68 69
if (! ($this_project = $project)) {
    TBERROR("Unknown project", 1);
70
}
71 72 73 74 75 76 77
# For error messages.
$pid = $this_project->pid();

echo "<center><h2>
      Approving Project '$pid' ...
      </h2></center>";

78 79 80 81
if (! ($leader = $this_project->GetLeader())) {
    TBERROR("Error getting leader for $pid", 1);
}
$headuid = $this_project->head_uid();
82

83 84 85 86
#
# If the user wanted to change the head uid, do that now (we change both
# the head_uid and the leader of the default project)
#
87
if ($approval == "approve" && isset($head_uid) && $head_uid != "") {
88 89 90 91 92 93 94
    if (! ($newleader = User::Lookup($head_uid))) {
	TBERROR("Unknown user $head_uid", 1);
    }
    if ($this_project->ChangeLeader($newleader) < 0) {
	TBERROR("Error changing leader to $head_uid", 1);
    }
    $leader  = $newleader;
95 96 97
    $headuid = $head_uid;
}

98 99 100 101 102
if (!isset($user_interface) ||
    !in_array($user_interface, $TBDB_USER_INTERFACE_LIST)) {
    $user_interface = TBDB_USER_INTERFACE_EMULAB;
}

103 104 105 106 107 108 109 110 111 112
#
# Get the current status for the headuid, which we might need to change
# anyway, and to verify that the user is a valid user. We also need
# the email address to let the user know what happened.
#
# We change the status only if this person is starting his first project.
# In this case, the status will be either "newuser" or "unapproved",
# and we will change it to "unapproved" or "active", respectively.
# If the status is "active", we leave it alone. 
#
113 114 115
$curstatus     = $leader->status();
$headuid_email = $leader->email();
$headname      = $leader->name();
116
#$headidx       = $leader->uid_idx();
117
#echo "Status = $curstatus, Email = $headuid_email<br>\n";
118

119
#
Leigh Stoller's avatar
Leigh Stoller committed
120 121
# Then we check that the headuid is really listed in the group_membership
# table (default group), just to be sure. 
122
#
123
if (! $this_project->IsMember($leader, $ignore)) {
124 125
    USERERROR("User $headuid is not the leader of project $pid.", 1);
}
126

127 128 129 130 131 132 133 134
# For email below
$APPROVAL_MAIL = $TBMAIL_APPROVAL;
if ($this_project->isAPT()) {
    $APPROVAL_MAIL = "aptlab-approval@aptlab.net";
}
elseif ($this_project->isCloud()) {
    $APPROVAL_MAIL = "cloudlab-approval@cloudlab.us";
}
135 136 137
elseif ($this_project->isPNet()) {
    $APPROVAL_MAIL = "phantomnet-approval@phantomnet.org";
}
138 139 140
elseif ($this_project->isPowder()) {
    $APPROVAL_MAIL = "powder-approval@powderwireless.net";
}
141

142 143 144 145
#
# Well, looks like everything is okay. Change the project approval
# value appropriately.
#
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
if ($approval == "postpone") {
    if (isset($message) && $message != "") {
	echo "<table class=stealth align=center border=0>";
	echo "<tr><td class=stealth>";
	echo "You requested postponement for $pid, but there is a ".
	    "message in the text box which will vanish. If that is ".
	    "not what you intended, the Back button below will give you ".
	    "another chance, with text intact";
	echo "</td></tr>";
	echo "<tr><td class=stealth align=center>";
	echo "<form action='approveproject_form.php3?project=$pid'
               method=post>";

	if (isset($head_uid)) {
	    echo "<input type=hidden name=head_uid value=$head_uid>\n";
	}
	echo "<input type=hidden name=user_interface value=$user_interface>\n";
	echo "<input type=hidden name=silent value=$silent>\n";
	echo "<input type=hidden name=pcplab_okay value=$pcplab_okay>\n";
	echo "<input type=hidden name=ron_okay value=$ron_okay>\n";
	echo "<input type=hidden name=message value='".
167
	    CleanString($message) . "'>\n";
168 169 170 171 172 173
    
	echo "<b><input type=submit name=back value=Back></b>\n";
	echo "</form>\n";
	echo "</td></tr></table>";
	PAGEFOOTER();
	return;
174
    }
175 176 177 178 179 180
    echo "<p><h3>
             Project approval for project $pid (User: $headuid) was
             postponed for later decision.
          </h3>\n";
}
elseif (strcmp($approval, "moreinfo") == 0) {
181
    SendProjAdminMail
182
        ($this_project, "ADMIN", "$headname '$headuid' <$headuid_email>",
183
         "Project '$pid' Approval Postponed",
184
         "This message is to notify you that your project application\n".
185 186 187
         "for $pid has been postponed until we have more information\n".
         "or you take certain actions.  You can just reply to this message\n".
         "to provide that information or report your actions.\n".
188 189
         "\n$message".
         "\n\n".
190
         "Thanks!\n");
191 192 193 194 195 196 197 198

    echo "<p><h3>
             Project approval for project $pid (User: $headuid) was
             postponed pending the reception of more information.
          </h3>\n";
}
elseif ((strcmp($approval, "deny") == 0) ||
	(strcmp($approval, "destroy") == 0)) {
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
    
    #
    # If the "destroy" option was given, kill the users account.
    #
    if (strcmp($approval, "destroy") == 0) {
	#
	# Take the user out of the project group first.
	#
	SUEXEC($uid, $TBADMINGROUP, "webmodgroups -r $pid:$pid $headuid", 1);

	#
	# See if user is in any other projects (even unapproved).
	#
	$project_list = $leader->ProjectMembershipList();

	#
	# If yes, then we cannot safely delete the user account.
	#
	if (count($project_list)) {
	    echo "<p>
                  User $headuid was <b>denied</b> starting project $pid.
                  <br>
                  Since the user is a member (or requesting membership)
		  in other projects, the account cannot be safely removed.
		  <br>\n";
	}
	else {
	    #
	    # No other project membership. If the user is unapproved/newuser,
	    # it means he was never approved in any project, and so will
	    # likely not be missed. He will be unapproved if he did his
	    # verification.
	    #
	    if (strcmp($curstatus, "newuser") &&
		strcmp($curstatus, "unapproved")) {
		echo "<p>
		      User $headuid was <b>denied</b> starting project $pid.
		      <br>
		      Since the user has been approved by, or was active in other
		      projects in the past, the account cannot be safely removed.
		      \n";
	    }
	    else {
		SUEXEC($uid, $TBADMINGROUP, "webrmuser -n -p $pid $headuid", 1); 

		if ($sendemail) {
		    TBMAIL("$headname '$headuid' <$headuid_email>",
			   "Account '$headuid' Terminated",
			   "\n".
			   "This message is to notify you that your account has \n".
			   "been terminated because your project $pid was denied.\n".
			   "\n\n".
251 252
			   "Thanks\n",
			   "From: $APPROVAL_MAIL\n".
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
			   "Bcc: $TBMAIL_APPROVAL\n".
			   "Errors-To: $TBMAIL_WWW");
		}
		echo "<h3><p>
			User $headuid was <b>denied</b> starting project $pid.
			<br>
			The account has also been <b>terminated</b>!
		      </h3>\n";
	    }
	}
    }
    else {
	echo "<h3><p>
		  Project $pid (User: $headuid) has been denied.
	      </h3>\n";
    }

270
    SUEXEC($uid, $TBADMINGROUP, "webrmproj $pid", 1);
271 272

    if ($sendemail) {
273 274 275 276 277 278 279
	TBMAIL("$headname '$headuid' <$headuid_email>",
	       "Project '$pid' Denied",
	       "\n".
	       "This message is to notify you that your project application\n".
	       "for $pid has been denied.\n".
	       "\n$message".
	       "\n\n".
280 281
	       "Thanks\n",
	       "From: $APPROVAL_MAIL\n".
282 283 284
	       "Bcc: $TBMAIL_APPROVAL\n".
	       "Errors-To: $TBMAIL_WWW");
    }
285

286 287
}
elseif (strcmp($approval, "approve") == 0) {
288 289 290 291 292 293
    $optargs = "";
    
    # Sanity check the leader status.
    if ($curstatus != TBDB_USERSTATUS_ACTIVE &&
	$curstatus != TBDB_USERSTATUS_UNAPPROVED) {
	TBERROR("Invalid $headuid status $curstatus", 1);
294
    }
295 296
    # Why is this here?
    $leader->SetUserInterface($user_interface);
297

298 299 300 301 302 303 304
    #
    # XXX
    # Temporary Plab hack.
    #
    $pcremote_ok = array();
    if (isset($pcplab_okay) &&
	!strcmp($pcplab_okay, "Yep")) {
305
	    $pcremote_ok[] = "pcplabphys";
306
    }
307
    # RON implies pcwa too.
308 309 310
    if (isset($ron_okay) &&
	!strcmp($ron_okay, "Yep")) {
	    $pcremote_ok[] = "pcron";
311
	    $pcremote_ok[] = "pcwa";
312 313 314
    }
    if (count($pcremote_ok)) {
	    $foo = implode(",", $pcremote_ok);
315
	    $this_project->SetRemoteOK($foo);
316 317
    }

318 319 320 321 322 323 324 325 326 327
    unset($tmpfname);
    if (isset($message)) {
	$tmpfname = tempnam("/tmp", "approveproj");
	$fp = fopen($tmpfname, "w");
	fwrite($fp, $message);
	fclose($fp);
	
	$optargs = " -f " . escapeshellarg($tmpfname);
    }

328 329 330 331
    #
    # Invoke the script. This does it all. If it fails, we will find out
    # about it.
    #
332 333 334 335
    STARTBUSY("Project '$pid' is being created");
    
    $retval = SUEXEC($uid, $TBADMINGROUP, "webmkproj $optargs $pid",
		     SUEXEC_ACTION_IGNORE);
336

337
    CLEARBUSY();
338

339 340 341 342 343 344 345 346 347 348 349 350
    if (isset($tmpfname)) {
	unlink($tmpfname);
    }
    if ($retval) {
	# Lets tack the message onto the output so we have a record.
	if (isset($message)) {
	    $suexec_output .= "\n\n*** Saved approval message text:\n\n";
	    $suexec_output .= $message;
	}
	SUEXECERROR(SUEXEC_ACTION_DIE);
	return;
    }
351

352
    if (!$FirstInitState) {
353 354
	sleep(1);
	PAGEREPLACE(CreateURL("showproject", $this_project));
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
    }
    else {
	echo "<br><br><font size=+1>\n";
	echo "Congratulations! You have successfully setup your initial Emulab
              Project. You should now ".
	      "<a href=login.php3?vuid=$headuid>login</a>
              using the account you just
              created so that you can continue setting up your new Emulab!
              </font><br>\n";

        #
        # Move to next phase. 
        # 
        TBSetFirstInitState("Ready");
    }
370 371
}
else {
372 373 374
    TBERROR("Invalid approval value $approval in approveproject.php3.", 1);
}

375 376 377 378
#
# Standard Testbed Footer
# 
PAGEFOOTER();
379
?>