approveproject.php3 8.41 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2003 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
$uid = GETLOGIN();
18 19 20 21 22
LOGGEDINORDIE($uid);

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

echo "<center><h1>
29
      Approving Project '$pid' ...
30 31 32
      </h1></center>";

#
33
# Grab the head_uid for this project. This verifies it is a valid project.
34
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
35 36
$query_result = 
    DBQueryFatal("SELECT head_uid from projects where pid='$pid'");
37 38 39 40
if (($row = mysql_fetch_row($query_result)) == 0) {
    TBERROR("Unknown project $pid", 1);
}
$headuid = $row[0];
41

42 43 44 45 46 47 48 49 50 51 52
#
# 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)
#
if (isset($head_uid) && strcmp($head_uid,"")) {
    $headuid = $head_uid;
    DBQueryFatal("UPDATE projects set head_uid='$headuid' where pid='$pid'");
    DBQueryFatal("UPDATE groups set leader='$headuid' where pid='$pid' and " .
	    "gid='$pid'");
}

53 54 55 56 57 58 59 60 61 62
#
# 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. 
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
63 64 65
$query_result = 
    DBQueryFatal("SELECT status,usr_email,usr_name from users ".
		 "where uid='$headuid'");
66 67 68 69 70 71
if (mysql_num_rows($query_result) == 0) {
    TBERROR("Unknown user $headuid", 1);
}
$row = mysql_fetch_row($query_result);
$curstatus     = $row[0];
$headuid_email = $row[1];
72
$headname      = $row[2];
73
#echo "Status = $curstatus, Email = $headuid_email<br>\n";
74

75
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
76 77
# Then we check that the headuid is really listed in the group_membership
# table (default group), just to be sure. 
78
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
79 80 81
$query_result =
    DBQueryFatal("SELECT trust from group_membership where ".
		 "uid='$headuid' and pid='$pid' and gid='$pid'");
82 83 84
if (mysql_num_rows($query_result) == 0) {
    USERERROR("User $headuid is not the leader of project $pid.", 1);
}
85

86 87 88 89 90
#
# Well, looks like everything is okay. Change the project approval
# value appropriately.
#
if (strcmp($approval, "postpone") == 0) {
91 92 93 94
    if (isset($message) && strcmp($message, "")) {
	USERERROR("You requested postponement for $pid, but there is a ".
		  "message in the text box. Is this what you intended?", 1);
    }
95 96 97 98 99 100
    echo "<p><h3>
             Project approval for project $pid (User: $headuid) was
             postponed for later decision.
          </h3>\n";
}
elseif (strcmp($approval, "moreinfo") == 0) {
101 102
    TBMAIL("$headname '$headuid' <$headuid_email>",
         "Project '$pid' Approval Postponed",
103 104
         "\n".
         "This message is to notify you that your project application\n".
105 106
         "for $pid has been postponed until we have more information.\n".
         "You can just reply to this message to provide more information.\n".
107 108 109
         "\n$message".
         "\n\n".
         "Thanks,\n".
110
         "Testbed Operations\n",
111 112
         "From: $TBMAIL_APPROVAL\n".
         "Bcc: $TBMAIL_APPROVAL\n".
113 114 115 116 117 118 119 120
         "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) ||
121
	(strcmp($approval, "annihilate") == 0) ||
122
	(strcmp($approval, "destroy") == 0)) {
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
    SUEXEC($uid, $TBADMINGROUP, "rmproj $pid", 1);
    
    if (strcmp($approval, "annihilate")) {
	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");
    }
139 140

    #
141
    # Well, if the "destroy" option was given, kill the users account.
142
    #
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
    if ((strcmp($approval, "annihilate") == 0) ||
	(strcmp($approval, "destroy") == 0)) {
	SUEXEC($uid, $TBADMINGROUP, "webrmuser $headuid", 1); 
	
	if (strcmp($approval, "annihilate")) {
	    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");
	}
160
    }
161

162 163 164 165 166
    echo "<h3><p>
              Project $pid (User: $headuid) has been denied.
          </h3>\n";
}
elseif (strcmp($approval, "approve") == 0) {
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185

    #
    # Change the status if necessary. This only happens for new users
    # being approved in their first project. After this, the status is
    # going to be "active", and we just leave it that way.
    #
    if (strcmp($curstatus, "active")) {
        if (strcmp($curstatus, "unapproved") == 0) {
	    $newstatus = "active";
        }
        else {
	    TBERROR("Invalid $headuid status $curstatus in ".
                    "approveproject.php3", 1);
        }
	DBQueryFatal("UPDATE users set status='$newstatus' ".
		     "WHERE uid='$headuid'");
    }


186
    #
Leigh B. Stoller's avatar
Leigh B. Stoller committed
187
    # Change the trust value in group_membership to group_root, and set the
188 189
    # project "approved" field to true. 
    #
Leigh B. Stoller's avatar
Leigh B. Stoller committed
190 191 192
    DBQueryFatal("UPDATE group_membership ".
		 "set trust='project_root',date_approved=now() ".
		 "WHERE uid='$headuid' and pid='$pid' and gid='$pid'");
193

Leigh B. Stoller's avatar
Leigh B. Stoller committed
194
    DBQueryFatal("UPDATE projects set approved='1' WHERE pid='$pid'");
195

196 197 198 199 200
    #
    # XXX
    # Temporary Plab hack.
    #
    $pcremote_ok = array();
201
    $auxtypes    = array();
202 203
    if (isset($pcplab_okay) &&
	!strcmp($pcplab_okay, "Yep")) {
204 205 206 207 208 209
	    $pcremote_ok[] = "pcplabphys";
	    $auxtypes[]    = "pcplab";
	    $auxtypes[]    = "pcplabinet";
	    $auxtypes[]    = "pcplabinet2";
	    $auxtypes[]    = "pcplabintl";
	    $auxtypes[]    = "pcplabdsl";
210
    }
211
    # RON implies pcwa too.
212 213 214
    if (isset($ron_okay) &&
	!strcmp($ron_okay, "Yep")) {
	    $pcremote_ok[] = "pcron";
215
	    $pcremote_ok[] = "pcwa";
216 217 218 219 220 221 222 223 224 225
	    $auxtypes[]    = "pcvron";
	    $auxtypes[]    = "pcvroninet";
	    $auxtypes[]    = "pcvroninet2";
	    $auxtypes[]    = "pcvronintl";
	    $auxtypes[]    = "pcvrondsl";
	    $auxtypes[]    = "pcvwa";
	    $auxtypes[]    = "pcvwainet";
	    $auxtypes[]    = "pcvwainet2";
	    $auxtypes[]    = "pcvwaintl";
	    $auxtypes[]    = "pcvwadsl";
226 227 228 229 230 231
    }
    if (count($pcremote_ok)) {
	    $foo = implode(",", $pcremote_ok);
	    DBQueryFatal("UPDATE projects set pcremote_ok='$foo' ".
			 "WHERE pid='$pid'");
    }
232 233 234 235 236 237 238
    if (count($auxtypes)) {
	while (list ($idx, $type) = each ($auxtypes)) {
	    DBQueryFatal("insert into nodetypeXpid_permissions ".
			 "(pid, type) ".
			 "values ('$pid', '$type')");
	}
    }
239

240 241
    TBMAIL("$headname '$headuid' <$headuid_email>",
         "Project '$pid' Approval",
242
         "\n".
243 244 245 246
	 "This message is to notify you that your project '$pid'\n".
	 "has been approved.  We recommend that you save this link so that\n".
	 "you can send it to people you wish to have join your project.\n".
	 "Otherwise, tell them to go to ${TBBASE} and join it.\n".
247 248 249 250 251
	 "\n".
	 "    ${TBBASE}/joinproject.php3?target_pid=$pid\n".
         "\n".
	 "$message\n".
         "\n".
252
         "Thanks,\n".
253
         "Testbed Operations\n",
254 255
         "From: $TBMAIL_APPROVAL\n".
         "Bcc: $TBMAIL_APPROVAL\n".
256
         "Errors-To: $TBMAIL_WWW");
257

258
    #
259 260
    # Invoke the script. This does it all. If it fails, we will find out
    # about it.
261
    #
262 263 264 265 266 267
    echo "<br>
          Project '$pid' is being created!<br><br>
          This will take a minute or two. <b>Please</b> do not click the Stop
          button during this time. If you do not receive notification within
          a reasonable amount of time, please contact $TBMAILADDR.\n";
    flush();
268

269 270 271 272 273
    SUEXEC($uid, $TBADMINGROUP, "webmkproj $pid", 1); 

    echo "<p><b>
             Project $pid (User: $headuid) has been approved.
          </b>\n";
274 275
}
else {
276 277 278
    TBERROR("Invalid approval value $approval in approveproject.php3.", 1);
}

279 280 281 282
#
# Standard Testbed Footer
# 
PAGEFOOTER();
283
?>