approveproject.php3 7.57 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5 6
# All rights reserved.
#
7 8
include("defs.php3");

9 10 11 12 13
#
# Standard Testbed Header
#
PAGEHEADER("New Project Approved");

14
#
15
# Only known and logged in users can do this.
16
#
17 18
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
19 20 21 22

#
# Of course verify that this uid has admin privs!
#
23
$isadmin = ISADMIN();
24
if (! $isadmin) {
Chad Barb's avatar
Chad Barb committed
25
    USERERROR("You do not have admin privileges to approve projects!", 1);
26 27
}

28 29 30 31 32
#
# See if we are in an initial Emulab setup.
#
$FirstInitState = (TBGetFirstInitState() == "approveproject");

33
echo "<center><h1>
34
      Approving Project '$pid' ...
35 36 37
      </h1></center>";

#
38
# Grab the head_uid for this project. This verifies it is a valid project.
39
#
40
if (! ($this_project = Project::Lookup($pid))) {
41 42
    TBERROR("Unknown project $pid", 1);
}
43 44 45 46
if (! ($leader = $this_project->GetLeader())) {
    TBERROR("Error getting leader for $pid", 1);
}
$headuid = $this_project->head_uid();
47

48 49 50 51
#
# 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)
#
52
if ($approval == "approve" && isset($head_uid) && $head_uid != "") {
53 54 55 56 57 58 59
    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;
60 61 62
    $headuid = $head_uid;
}

63 64 65 66 67
if (!isset($user_interface) ||
    !in_array($user_interface, $TBDB_USER_INTERFACE_LIST)) {
    $user_interface = TBDB_USER_INTERFACE_EMULAB;
}

68 69 70 71 72 73 74 75 76 77
#
# 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. 
#
78 79 80
$curstatus     = $leader->status();
$headuid_email = $leader->email();
$headname      = $leader->name();
81
#$headidx       = $leader->uid_idx();
82
#echo "Status = $curstatus, Email = $headuid_email<br>\n";
83

84
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
85 86
# Then we check that the headuid is really listed in the group_membership
# table (default group), just to be sure. 
87
#
88
if (! $this_project->IsMember($leader, $ignore)) {
89 90
    USERERROR("User $headuid is not the leader of project $pid.", 1);
}
91

92 93 94 95 96
#
# Well, looks like everything is okay. Change the project approval
# value appropriately.
#
if (strcmp($approval, "postpone") == 0) {
97 98
    if (isset($message) && strcmp($message, "")) {
	USERERROR("You requested postponement for $pid, but there is a ".
99 100 101
		  "message in the text box which will vanish. If that is ".
		  "not what you intended, the back button will give you ".
		  "another chance, with text intact.", 1);
102
    }
103 104 105 106 107 108
    echo "<p><h3>
             Project approval for project $pid (User: $headuid) was
             postponed for later decision.
          </h3>\n";
}
elseif (strcmp($approval, "moreinfo") == 0) {
109 110
    TBMAIL("$headname '$headuid' <$headuid_email>",
         "Project '$pid' Approval Postponed",
111 112
         "\n".
         "This message is to notify you that your project application\n".
113 114 115
         "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".
116 117 118
         "\n$message".
         "\n\n".
         "Thanks,\n".
119
         "Testbed Operations\n",
120 121
         "From: $TBMAIL_APPROVAL\n".
         "Bcc: $TBMAIL_APPROVAL\n".
122 123 124 125 126 127 128 129 130
         "Errors-To: $TBMAIL_WWW");

    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)) {
131
    SUEXEC($uid, $TBADMINGROUP, "rmproj $pid", 1);
132 133 134 135 136

    $sendemail = 1;
    if (isset($silent) && $silent == "Yep") {
	$sendemail = 0;
    }
137
    
138
    if ($sendemail) {
139 140 141 142 143 144 145 146 147 148 149 150 151
	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".
	       "Thanks,\n".
	       "Testbed Operations\n",
	       "From: $TBMAIL_APPROVAL\n".
	       "Bcc: $TBMAIL_APPROVAL\n".
	       "Errors-To: $TBMAIL_WWW");
    }
152 153

    #
154
    # Well, if the "destroy" option was given, kill the users account.
155
    #
156
    if ($approval == "destroy") {
157 158
	SUEXEC($uid, $TBADMINGROUP, "webrmuser $headuid", 1); 
	
159
	if ($sendemail) {
160 161 162 163 164 165 166 167 168 169 170 171
	    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".
		   "Thanks,\n".
		   "Testbed Operations\n",
		   "From: $TBMAIL_APPROVAL\n".
		   "Bcc: $TBMAIL_APPROVAL\n".
		   "Errors-To: $TBMAIL_WWW");
	}
172
    }
173

174 175 176 177 178
    echo "<h3><p>
              Project $pid (User: $headuid) has been denied.
          </h3>\n";
}
elseif (strcmp($approval, "approve") == 0) {
179 180 181 182 183 184
    $optargs = "";
    
    # Sanity check the leader status.
    if ($curstatus != TBDB_USERSTATUS_ACTIVE &&
	$curstatus != TBDB_USERSTATUS_UNAPPROVED) {
	TBERROR("Invalid $headuid status $curstatus", 1);
185
    }
186 187
    # Why is this here?
    $leader->SetUserInterface($user_interface);
188

189 190 191 192 193 194 195
    #
    # XXX
    # Temporary Plab hack.
    #
    $pcremote_ok = array();
    if (isset($pcplab_okay) &&
	!strcmp($pcplab_okay, "Yep")) {
196
	    $pcremote_ok[] = "pcplabphys";
197
    }
198
    # RON implies pcwa too.
199 200 201
    if (isset($ron_okay) &&
	!strcmp($ron_okay, "Yep")) {
	    $pcremote_ok[] = "pcron";
202
	    $pcremote_ok[] = "pcwa";
203 204 205
    }
    if (count($pcremote_ok)) {
	    $foo = implode(",", $pcremote_ok);
206
	    $this_project->SetRemoteOK($foo);
207 208
    }

209 210 211 212 213 214 215 216 217 218
    unset($tmpfname);
    if (isset($message)) {
	$tmpfname = tempnam("/tmp", "approveproj");
	$fp = fopen($tmpfname, "w");
	fwrite($fp, $message);
	fclose($fp);
	
	$optargs = " -f " . escapeshellarg($tmpfname);
    }

219 220 221 222
    #
    # Invoke the script. This does it all. If it fails, we will find out
    # about it.
    #
223 224 225 226
    STARTBUSY("Project '$pid' is being created");
    
    $retval = SUEXEC($uid, $TBADMINGROUP, "webmkproj $optargs $pid",
		     SUEXEC_ACTION_IGNORE);
227

228
    CLEARBUSY();
229

230 231 232 233 234 235 236 237 238 239 240 241
    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;
    }
242

243
    if (!$FirstInitState) {
244 245
	sleep(1);
	PAGEREPLACE(CreateURL("showproject", $this_project));
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
    }
    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";
        #
 	# Freeze the initial user.
        #
        DBQueryFatal("update users set ".
                     "  status='" . TBDB_USERSTATUS_FROZEN . "' ".
	             "where uid='$FIRSTUSER'");

        #
        # Move to next phase. 
        # 
        TBSetFirstInitState("Ready");
    }
267 268
}
else {
269 270 271
    TBERROR("Invalid approval value $approval in approveproject.php3.", 1);
}

272 273 274 275
#
# Standard Testbed Footer
# 
PAGEFOOTER();
276
?>