joinproject.php3 33.1 KB
Newer Older
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2014 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
include("defs.php3");

26 27 28 29 30 31 32 33 34 35
#
# This is a hack to support wikiregister.php3 - normally, this variable would
# be cleared by OptionalPageArguments()
#
if (isset($forwikionly) && $forwikionly == True) {
    $old_forwikionly = True;
} else {
    $old_forwikionly = False;
}

36 37 38
# Need this below;
$show_sslcertbox = TBGetSiteVar("protogeni/show_sslcertbox");

39 40
#
# No PAGEHEADER since we spit out a Location header later. See below.
41
#
42 43 44

#
# Get current user.
45 46
#
$this_user = CheckLogin($check_status);
47

48 49 50 51 52 53
#
# Verify page arguments.
#
$optargs = OptionalPageArguments("submit",       PAGEARG_STRING,
				 "forwikionly",  PAGEARG_BOOLEAN,
				 "finished",     PAGEARG_BOOLEAN,
54
				 "nopidokay",    PAGEARG_STRING,
55 56 57 58
				 "target_pid",   PAGEARG_STRING,
				 "target_gid",   PAGEARG_STRING,
				 "formfields",   PAGEARG_ARRAY);

59 60
#
# If a uid came in, then we check to see if the login is valid.
61
# We require that the user be logged in to start a second project.
62
#
63
if ($this_user) {
64 65
    # Allow unapproved users to join multiple groups ...
    # Must be verified though.
66 67 68
    CheckLoginOrDie(CHECKLOGIN_UNAPPROVED|
		    CHECKLOGIN_WEBONLY|CHECKLOGIN_WIKIONLY);
    $joining_uid = $this_user->uid();
69 70 71 72 73 74 75 76 77
    $returning = 1;
}
else {
    #
    # No uid, so must be new.
    #
    $returning = 0;
}

78 79 80
if ($old_forwikionly == True) {
    $forwikionly = True;
}
81
if (!isset($forwikionly)) {
82
    $forwikionly = False;
83
}
84
$nopidconfirm = 0;
85
unset($addpubkeyargs);
86 87
unset($pid);
unset($gid);
88

Leigh Stoller's avatar
Leigh Stoller committed
89 90 91 92
$ACCOUNTWARNING =
    "Before continuing, please make sure your username " .
    "reflects your normal login name. ".
    "Emulab accounts are not to be shared amongst users!";
93

Leigh Stoller's avatar
Leigh Stoller committed
94 95 96
$EMAILWARNING =
    "Before continuing, please make sure the email address you have ".
    "provided is current and non-pseudonymic. Redirections and anonymous ".
97 98
    "email addresses are not allowed.";

99 100 101 102 103 104
#
# Spit the form out using the array of data. 
# 
function SPITFORM($formfields, $returning, $errors)
{
    global $TBDB_UIDLEN, $TBDB_PIDLEN, $TBDB_GIDLEN;
105
    global $ACCOUNTWARNING, $EMAILWARNING;
106
    global $WIKISUPPORT, $forwikionly, $WIKIHOME, $USERSELECTUIDS;
107
    global $WIKIDOCURL;
108
    global $PROTOGENI, $show_sslcertbox, $nopidokay;
109 110 111 112 113

    if ($forwikionly)
	PAGEHEADER("Wiki Registration");
    else
	PAGEHEADER("Apply for Project Membership");
114

115
    if (! $returning) {
116 117 118 119 120 121 122
	echo "<center>\n";

	if ($forwikionly) {
	    echo "<font size=+2>Register for an Emulab Wiki account</font>
                  <br><br>\n";
	}
        echo "<font size=+1>
123 124 125
               If you already have an Emulab account,
               <a href=login.php3?refer=1>
               <font color=red>please log on first!</font></a>
126 127 128 129 130 131 132 133
              </font>\n";
	if ($forwikionly) {
	    echo "<br>(You will already have a wiki account)\n";
	}
	echo "</center><br>\n";	
    }
    elseif ($forwikionly) {
	USERERROR("You already have a Wiki account!", 1);
134 135
    }

136
    if ($errors) {
137 138
	echo "<table class=nogrid
                     align=center border=0 cellpadding=6 cellspacing=0>
139
              <tr>
140
                 <th align=center colspan=2>
141
                   <font size=+1 color=red>
142
                      &nbsp;Oops, please fix the following errors!&nbsp;
143 144 145 146 147
                   </font>
                 </td>
              </tr>\n";

	while (list ($name, $message) = each ($errors)) {
148 149
            # XSS prevention.
	    $message = CleanString($message);
150
	    echo "<tr>
151 152 153 154
                     <td align=right>
                       <font color=red>$name:&nbsp;</font></td>
                     <td align=left>
                       <font color=red>$message</font></td>
155 156 157 158
                  </tr>\n";
	}
	echo "</table><br>\n";
    }
159 160 161 162
    # XSS prevention.
    while (list ($key, $val) = each ($formfields)) {
	$formfields[$key] = CleanString($val);
    }
163 164 165 166
    if (isset($nopidokay)) {
        $nopidokay = CleanString($nopidokay);
        echo "<input type=hidden name=nopidokay value='$nopidokay'>\n";
    }
167
    
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
    echo "<SCRIPT LANGUAGE=JavaScript>
              function SetWikiName(theform) 
              {
	          var validchars = 'abcdefghijklmnopqrstuvwxyz0123456789';
                  var usrname    = theform['formfields[usr_name]'].value;
                  var wikiname   = '';
                  var docap      = 1;

		  for (var i = 0; i < usrname.length; i++) {
                      var letter = usrname.charAt(i).toLowerCase();

                      if (validchars.indexOf(letter) == -1) {
                          if (letter == ' ') {
                              docap = 1;
                          }
                          continue;
                      }
                      else {
                          if (docap == 1) {
                              letter = usrname.charAt(i).toUpperCase()
                              docap  = 0;
                          }
                          wikiname = wikiname + letter;
                      }
                  }
                  theform['formfields[wikiname]'].value = wikiname;
              }
          </SCRIPT>\n";
196 197 198

    echo "<table align=center border=1> 
          <tr>
199 200
            <td align=center colspan=3><font size=-1>
                Fields marked with * are required.</font>
201 202 203
            </td>
          </tr>\n

204 205 206 207
          <form name=myform enctype=multipart/form-data
                action=" . ($forwikionly ?
			    "wikiregister.php3" : "joinproject.php3") . " " .
	        "method=post>\n";
208 209

    if (! $returning) {
210 211 212 213 214 215
	if ($USERSELECTUIDS) {
            #
            # UID.
            #
	    echo "<tr>
                      <td colspan=2>*<a
216
                             href='$WIKIDOCURL/SecReqs'
217
                             target=_blank>Username</a>
218
                                (alphanumeric):</td>
219 220 221
                      <td class=left>
                          <input type=text
                                 name=\"formfields[joining_uid]\"
222
                                 value=\"" . $formfields["joining_uid"] . "\"
223 224 225 226 227 228
	                         size=$TBDB_UIDLEN
                                 onchange=\"alert('$ACCOUNTWARNING')\"
	                         maxlength=$TBDB_UIDLEN>
                      </td>
                  </tr>\n";
	}
229 230 231 232 233

	#
	# Full Name
	#
        echo "<tr>
234
                  <td colspan=2>*Full Name (first and last):</td>
235 236
                  <td class=left>
                      <input type=text
237 238 239 240 241
                             name=\"formfields[usr_name]\" ";
	if ($WIKISUPPORT) {
	    echo "           onchange=\"SetWikiName(myform);\" ";
	}
	echo "               value=\"" . $formfields["usr_name"] . "\"
242 243 244 245 246
	                     size=30>
                  </td>
              </tr>\n";

	#
247
	# WikiName
248
	#
249 250
	if ($WIKISUPPORT) {
	    echo "<tr>
251 252
                      <td colspan=2>*<a
                            href=${WIKIHOME}/bin/view/TWiki/WikiName
253 254 255
                            target=_blank>WikiName</a>:<td class=left>
                          <input type=text
                                 name=\"formfields[wikiname]\"
256
                                 value=\"" . $formfields["wikiname"] . "\"
257 258 259 260 261 262 263 264 265 266
	                         size=30>
                      </td>
                  </tr>\n";
	}

	if (! $forwikionly) {
            #
            # Title/Position:
	    #
	    echo "<tr>
267
                      <td colspan=2>*Job Title/Position:</td>
268 269 270
                      <td class=left>
                          <input type=text
                                 name=\"formfields[usr_title]\"
271
                                 value=\"" . $formfields["usr_title"] . "\"
272 273 274 275 276 277 278 279
  	                         size=30>
                      </td>
                  </tr>\n";

            #
            # Affiliation:
            # 
	    echo "<tr>
280
                      <td colspan=2>*Institutional Affiliation:</td>
281
                      <td class=left>
282 283 284 285
			<table>
                          <tr>
                          <td>Name</td>
                          <td><input type=text
286
                                 name=\"formfields[usr_affil]\"
287
                                 value=\"" . $formfields["usr_affil"] . "\"
288 289 290 291 292 293 294 295 296
	                         size=40></td></tr>
			  <tr>
                          <td>Abbreviation:</td>
                          <td><input type=text
                                 name=\"formfields[usr_affil_abbrev]\"
                                 value=\"" . $formfields["usr_affil_abbrev"] . "\"
	                         size=16 maxlength=16> (e.g. MIT)</td>
			  </tr>
        		</table>
297 298 299 300 301 302
                      </td>
                  </tr>\n";

	    #
	    # User URL
	    #
303
	    echo "<tr>
304 305 306 307
                      <td colspan=2>Home Page URL:</td>
                      <td class=left>
                          <input type=text
                                 name=\"formfields[usr_URL]\"
308
                                 value=\"" . $formfields["usr_URL"] . "\"
309 310 311 312
	                         size=45>
                      </td>
                  </tr>\n";
	}
313 314 315 316 317

	#
	# Email:
	#
	echo "<tr>
318
                  <td colspan=2>*Email Address[<b>1</b>]:</td>
319 320 321
                  <td class=left>
                      <input type=text
                             name=\"formfields[usr_email]\"
322
                             value=\"" . $formfields["usr_email"] . "\"
323
                             onchange=\"alert('$EMAILWARNING')\"
324 325 326 327
	                     size=30>
                  </td>
              </tr>\n";

328 329 330 331 332 333 334 335 336
	if (! $forwikionly) {
	    #
	    # Postal Address
	    #
	    echo "<tr><td colspan=3>*Postal Address:<br /><center>
		    <table>
		      <tr><td>Line 1</td><td colspan=3>
                        <input type=text
                               name=\"formfields[usr_addr]\"
337
                               value=\"" . $formfields["usr_addr"] . "\"
338 339 340 341
	                       size=45></td></tr>
		      <tr><td>Line 2</td><td colspan=3>
                        <input type=text
                               name=\"formfields[usr_addr2]\"
342
                               value=\"" . $formfields["usr_addr2"] . "\"
343 344 345 346
	                       size=45></td></tr>
		      <tr><td>City</td><td>
                        <input type=text
                               name=\"formfields[usr_city]\"
347
                               value=\"" . $formfields["usr_city"] . "\"
348 349 350 351
	                       size=25></td>
		          <td>State/Province</td><td>
                        <input type=text
                               name=\"formfields[usr_state]\"
352
                               value=\"" . $formfields["usr_state"] . "\"
353 354 355 356
	                       size=2></td></tr>
		      <tr><td>ZIP/Postal Code</td><td>
                        <input type=text
                               name=\"formfields[usr_zip]\"
357
                               value=\"" . $formfields["usr_zip"] . "\"
358 359 360 361
	                       size=10></td>
		          <td>Country</td><td>
                        <input type=text
                               name=\"formfields[usr_country]\"
362
                               value=\"" . $formfields["usr_country"] . "\"
363 364 365 366 367 368 369 370 371 372 373
	                       size=15></td></tr>
                   </table></center></td></tr>";

	    #
	    # Phone
	    #
	    echo "<tr>
                      <td colspan=2>*Phone #:</td>
                      <td class=left>
                          <input type=text
                                 name=\"formfields[usr_phone]\"
374
                                 value=\"" . $formfields["usr_phone"] . "\"
375 376 377
	                         size=15>
                      </td>
                  </tr>\n";
378

379 380 381 382
	    #
	    # SSH public key
	    #
	    echo "<tr>
383
                     <td colspan=2>Upload your SSH Pub Key[<b>2</b>]:<br>
384
                                       (4K max)</td>
385 386
   
                     <td>
387
                          <input type=hidden name=MAX_FILE_SIZE value=4096>
388
                          <input type=file
389 390 391 392 393 394
                                 size=50
                                 name=usr_keyfile ";
	    if (isset($_FILES['usr_keyfile'])) {
		echo "        value=\"" .
		    $_FILES['usr_keyfile']['name'] . "\"";
	    }
Russ Fish's avatar
Russ Fish committed
395
	    echo         "> </td>
396 397
                  </tr>\n";
	}
398

399 400 401 402 403
	#
	# Password. Note that we do not resend the password. User
	# must retype on error.
	#
	echo "<tr>
404
                  <td colspan=2>*Password[<b>1</b>]:</td>
405 406 407
                  <td class=left>
                      <input type=password
                             name=\"formfields[password1]\"
408
                             value=\"" . $formfields["password1"] . "\"
409 410 411 412
                             size=8></td>
              </tr>\n";

        echo "<tr>
413
                  <td colspan=2>*Retype Password:</td>
414 415 416
                  <td class=left>
                      <input type=password
                             name=\"formfields[password2]\"
417
                             value=\"" . $formfields["password2"] . "\"
418 419
                             size=8></td>
             </tr>\n";
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448

	#
	# Geni Passphrase.
	#
	if ($PROTOGENI && $show_sslcertbox) {
	    echo "<tr></tr><tr>
                   <th class=center colspan=3>Geni Account<br>
                 <a href='http://users.emulab.net/trac/emulab/wiki/GeniBlurb'
			target=_blank><font size=-2>what's this?</font></a></td>
                  </tr>\n";

	    echo "<tr>
                  <td colspan=2>Geni SSL Pass Phrase[<b>3</b>]:</td>
                  <td class=left>
                      <input type=password
                             name=\"formfields[passphrase1]\"
                             value=\"" . $formfields["passphrase1"] . "\"
                             size=32></td>
              </tr>\n";

	    echo "<tr>
                  <td colspan=2>Retype Geni Pass Phrase:</td>
                  <td class=left>
                      <input type=password
                             name=\"formfields[passphrase2]\"
                             value=\"" . $formfields["passphrase2"] . "\"
                             size=32></td>
             </tr>\n";
	}
449
    }
450 451 452
    echo "<tr></tr><tr>
              <th class=center colspan=3>Project Info</td>
          </tr>\n";
453

454 455 456 457 458 459 460 461 462
    if (! $forwikionly) {
        #
        # Project Name:
        #
	echo "<tr>
                  <td colspan=2>*Project Name:</td>
                  <td class=left>
                      <input type=text
                             name=\"formfields[pid]\"
463
                             value=\"" . $formfields["pid"] . "\"
464 465 466
	                     size=$TBDB_PIDLEN maxlength=$TBDB_PIDLEN>
                  </td>
              </tr>\n";
467

468 469 470 471 472 473 474 475 476
        #
        # Group Name:
        #
	echo "<tr>
                  <td colspan=2>Group Name:<br>
                  (Leave blank unless you <em>know</em> the group name)</td>
                  <td class=left>
                      <input type=text
                             name=\"formfields[gid]\"
477
                             value=\"" . $formfields["gid"] . "\"
478 479 480 481
	                     size=$TBDB_GIDLEN maxlength=$TBDB_GIDLEN>
                  </td>
              </tr>\n";
    }
482 483

    echo "<tr>
484
              <td colspan=3 align=center>
485 486 487 488 489 490 491 492 493 494
                 <b><input type=submit name=submit value=Submit></b>
              </td>
          </tr>\n";

    echo "</form>
          </table>\n";

    echo "<h4><blockquote><blockquote>
          <ol>
            <li> Please consult our
495
                 <a href = '$WIKIDOCURL/SecReqs' target='_blank'>
496
                 security policies</a> for information
497
                 regarding passwords and email addresses.\n";
498
    if (!$returning && !$forwikionly) {
499
	echo "<li> If you want us to use your existing ssh public key,
500
                   then please specify the path to your
501
                   identity.pub file.  <font color=red>NOTE:</font>
502
                   We use the <a href=http://www.openssh.org target='_blank'>OpenSSH</a>
503
                   key format,
504 505
                   which has a slightly different protocol 2 public key format
                   than some of the commercial vendors such as
506
                   <a href=http://www.ssh.com target='_blank'>SSH Communications</a>. If you
507
                   use one of these commercial vendors, then please
508 509
                   upload the public key file and we will convert it
                   for you.";
510 511 512 513 514 515
	if ($PROTOGENI && $show_sslcertbox) {
	    echo "<li>";
	    echo "Pick a good pass phrase! They can be (much) longer than
                  Unix passwords; 10 to 30 character phrases are good,
                  and may include spaces and punctuation.";
	}
516 517
    }
    echo "</ol>
518 519 520 521 522 523 524
          </blockquote></blockquote>
          </h4>\n";
}

#
# The conclusion of a join request. See below.
# 
525
if (isset($finished)) {
526 527 528 529
    if ($forwikionly) 
	PAGEHEADER("Wiki Registration");
    else
	PAGEHEADER("Apply for Project Membership");
530 531 532 533

    #
    # Generate some warm fuzzies.
    #
534 535 536 537 538 539 540
    if ($forwikionly) {
	echo "An email message has been sent to your account so we may verify
              your email address. Please follow the instructions contained in
              that message, which will verify your account, and grant you
              access to the Wiki.\n";
    }
    elseif (! $returning) {
541 542
	echo "<p>
              As a pending user of the Testbed you will receive a key via email.
543
              When you receive the message, please follow the instructions
544 545 546 547 548
              contained in the message, which will verify your identity.
	      <br>
	      <p>
	      When you have done that, the project leader will be
	      notified of your application. ";
549 550
    }
    else {
551 552
          echo "<p>
	  	The project leader has been notified of your application. ";
553 554
    }

555 556 557 558
    echo "He/She will make a decision and either approve or deny your
          application, and you will be notified via email as soon as
	  that happens.\n";

559 560 561 562 563 564 565
    PAGEFOOTER();
    return;
}

#
# On first load, display a virgin form and exit.
#
566
if (! isset($submit)) {
567
    $defaults = array();
568 569 570 571 572 573 574 575 576 577 578 579 580 581
    $defaults["pid"]         = "";
    $defaults["gid"]         = "";
    $defaults["joining_uid"] = "";
    $defaults["usr_name"]    = "";
    $defaults["usr_email"]   = "";
    $defaults["usr_addr"]    = "";
    $defaults["usr_addr2"]   = "";
    $defaults["usr_city"]    = "";
    $defaults["usr_state"]   = "";
    $defaults["usr_zip"]     = "";
    $defaults["usr_country"] = "";
    $defaults["usr_phone"]   = "";
    $defaults["usr_title"]   = "";
    $defaults["usr_affil"]   = "";
582
    $defaults["usr_affil_abbrev"] = "";
583 584
    $defaults["password1"]   = "";
    $defaults["password2"]   = "";
585 586
    $defaults["passphrase1"] = "";
    $defaults["passphrase2"] = "";
587 588 589
    $defaults["wikiname"]    = "";
    $defaults["usr_URL"]     = "$HTTPTAG";
    $defaults["usr_country"] = "USA";
590 591 592 593 594

    #
    # These two allow presetting the pid/gid.
    # 
    if (isset($target_pid) && strcmp($target_pid, "")) {
595
	$defaults["pid"] = $target_pid;
596 597
    }
    if (isset($target_gid) && strcmp($target_gid, "")) {
598
	$defaults["gid"] = $target_gid;
599
    }
600 601 602 603 604
    
    SPITFORM($defaults, $returning, 0);
    PAGEFOOTER();
    return;
}
605 606 607
# Form submitted. Make sure we have a formfields array.
if (!isset($formfields)) {
    PAGEARGERROR("Invalid form arguments.");
608
}
609 610 611 612 613 614 615 616 617 618

#
# Otherwise, must validate and redisplay if errors
#
$errors = array();

#
# These fields are required!
#
if (! $returning) {
619
    if ($USERSELECTUIDS) {
620 621
	if (!isset($formfields["joining_uid"]) ||
	    strcmp($formfields["joining_uid"], "") == 0) {
622 623
	    $errors["Username"] = "Missing Field";
	}
624
	elseif (!TBvalid_uid($formfields["joining_uid"])) {
625 626
	    $errors["UserName"] = TBFieldErrorString();
	}
627 628
	elseif (User::Lookup($formfields["joining_uid"]) ||
		posix_getpwnam($formfields["joining_uid"])) {
629 630
	    $errors["UserName"] = "Already in use. Pick another";
	}
631
    }
632 633
    if (!isset($formfields["usr_name"]) ||
	strcmp($formfields["usr_name"], "") == 0) {
634 635
	$errors["Full Name"] = "Missing Field";
    }
636
    elseif (! TBvalid_usrname($formfields["usr_name"])) {
637
	$errors["Full Name"] = TBFieldErrorString();
638
    }
639
    # Make sure user name has at least two tokens!
640
    $tokens = preg_split("/[\s]+/", $formfields["usr_name"],
641 642 643 644
			 -1, PREG_SPLIT_NO_EMPTY);
    if (count($tokens) < 2) {
	$errors["Full Name"] = "Please provide a first and last name";
    }
645
    if ($WIKISUPPORT) {
646 647
	if (!isset($formfields["wikiname"]) ||
	    strcmp($formfields["wikiname"], "") == 0) {
648 649
	    $errors["WikiName"] = "Missing Field";
	}
650
	elseif (! TBvalid_wikiname($formfields["wikiname"])) {
651 652
	    $errors["WikiName"] = TBFieldErrorString();
	}
653
	elseif (User::LookupByWikiName($formfields["wikiname"])) {
654 655
	    $errors["WikiName"] = "Already in use. Pick another";
	}
656
    }
657
    if (!$forwikionly) {
658 659
	if (!isset($formfields["usr_title"]) ||
	    strcmp($formfields["usr_title"], "") == 0) {
660
	    $errors["Job Title/Position"] = "Missing Field";
661
	}
662
	elseif (! TBvalid_title($formfields["usr_title"])) {
663
	    $errors["Job Title/Position"] = TBFieldErrorString();
664
	}
665 666
	if (!isset($formfields["usr_affil"]) ||
	    strcmp($formfields["usr_affil"], "") == 0) {
667
	    $errors["Affiliation Name"] = "Missing Field";
668
	}
669
	elseif (! TBvalid_affiliation($formfields["usr_affil"])) {
670 671 672 673 674 675
	    $errors["Affiliation Name"] = TBFieldErrorString();
	}
	if (!isset($formfields["usr_affil_abbrev"]) ||
	    strcmp($formfields["usr_affil_abbrev"], "") == 0) {
	    $errors["Affiliation Abbreviation"] = "Missing Field";
	}
676
	elseif (! TBvalid_affiliation_abbreviation($formfields["usr_affil_abbrev"])) {
677
	    $errors["Affiliation Name"] = TBFieldErrorString();
678 679
	}
    }	
680 681
    if (!isset($formfields["usr_email"]) ||
	strcmp($formfields["usr_email"], "") == 0) {
682 683
	$errors["Email Address"] = "Missing Field";
    }
684
    elseif (! TBvalid_email($formfields["usr_email"])) {
685
	$errors["Email Address"] = TBFieldErrorString();
686
    }
687
    elseif (User::LookupByEmail($formfields["usr_email"])) {
688 689
	$errors["Email Address"] =
	    "Already in use. <b>Did you forget to login?</b>";
690
    }
691
    if (! $forwikionly) {
692 693
	if (isset($formfields["usr_URL"]) &&
	    strcmp($formfields["usr_URL"], "") &&
694 695 696 697 698 699 700 701 702 703
	    strcmp($formfields["usr_URL"], $HTTPTAG)) {
	    if (strcmp($HTTPTAG,
		       substr($formfields["usr_URL"], 0, strlen($HTTPTAG))) &&
		strcmp($HTTPSTAG,
		       substr($formfields["usr_URL"], 0, strlen($HTTPSTAG)))) {
		$formfields["usr_URL"] = "${HTTPTAG}" . $formfields["usr_URL"];
	    }
	    if (! CHECKURL($formfields["usr_URL"], $urlerror)) {
		$errors["Home Page URL"] = $urlerror;
	    }
704
	}
705 706
	if (!isset($formfields["usr_addr"]) ||
	    strcmp($formfields["usr_addr"], "") == 0) {
707 708
	    $errors["Address 1"] = "Missing Field";
	}
709
	elseif (! TBvalid_addr($formfields["usr_addr"])) {
710 711 712
	    $errors["Address 1"] = TBFieldErrorString();
	}
        # Optional
713 714
	if (isset($formfields["usr_addr2"]) &&
	    !TBvalid_addr($formfields["usr_addr2"])) {
715 716
	    $errors["Address 2"] = TBFieldErrorString();
	}
717 718
	if (!isset($formfields["usr_city"]) ||
	    strcmp($formfields["usr_city"], "") == 0) {
719 720
	    $errors["City"] = "Missing Field";
	}
721
	elseif (! TBvalid_city($formfields["usr_city"])) {
722 723
	    $errors["City"] = TBFieldErrorString();
	}
724 725
	if (!isset($formfields["usr_state"]) ||
	    strcmp($formfields["usr_state"], "") == 0) {
726 727
	    $errors["State"] = "Missing Field";
	}
728
	elseif (! TBvalid_state($formfields["usr_state"])) {
729 730
	    $errors["State"] = TBFieldErrorString();
	}
731 732
	if (!isset($formfields["usr_zip"]) ||
	    strcmp($formfields["usr_zip"], "") == 0) {
733 734
	    $errors["ZIP/Postal Code"] = "Missing Field";
	}
735
	elseif (! TBvalid_zip($formfields["usr_zip"])) {
736 737
	    $errors["Zip/Postal Code"] = TBFieldErrorString();
	}
738 739
	if (!isset($formfields["usr_country"]) ||
	    strcmp($formfields["usr_country"], "") == 0) {
740 741
	    $errors["Country"] = "Missing Field";
	}
742
	elseif (! TBvalid_country($formfields["usr_country"])) {
743 744
	    $errors["Country"] = TBFieldErrorString();
	}
745 746
	if (!isset($formfields["usr_phone"]) ||
	    strcmp($formfields["usr_phone"], "") == 0) {
747 748
	    $errors["Phone #"] = "Missing Field";
	}
749
	elseif (!TBvalid_phone($formfields["usr_phone"])) {
750 751
	    $errors["Phone #"] = TBFieldErrorString();
	}
752
    }
753 754
    if (!isset($formfields["password1"]) ||
	strcmp($formfields["password1"], "") == 0) {
755 756
	$errors["Password"] = "Missing Field";
    }
757 758
    if (!isset($formfields["password2"]) ||
	strcmp($formfields["password2"], "") == 0) {
759 760
	$errors["Confirm Password"] = "Missing Field";
    }
761
    elseif (strcmp($formfields["password1"], $formfields["password2"])) {
762 763
	$errors["Confirm Password"] = "Does not match Password";
    }
764
    elseif (! CHECKPASSWORD(($USERSELECTUIDS ?
765 766 767 768
			     $formfields["joining_uid"] : "ignored"),
			    $formfields["password1"],
			    $formfields["usr_name"],
			    $formfields["usr_email"], $checkerror)) {
769 770
	$errors["Password"] = "$checkerror";
    }
771 772 773 774 775 776 777 778 779
    if ($PROTOGENI && $show_sslcertbox &&
	isset($formfields["passphrase1"]) && $formfields["passphrase1"] != "") {
	if (!isset($formfields["passphrase2"]) ||
	    $formfields["passphrase2"] == "") {
	    $errors["Confirm Pass Phrase"] = "Missing Field";
	}
	elseif ($formfields["passphrase1"] != $formfields["passphrase2"]) {
	    $errors["Confirm Pass Phrase"] = "Does not match Pass Phrase";
	}
780 781 782 783
	elseif (strlen($formfields["passphrase1"]) < $TBDB_MINPASSPHRASE) {
	    $errors["Pass Phrase"] =
		"Too short; $TBDB_MINPASSPHRASE char minimum";
	}
784 785 786 787 788 789 790 791
	elseif (! CHECKPASSWORD(($USERSELECTUIDS ?
				 $formfields["joining_uid"] : "ignored"),
				$formfields["passphrase1"],
				$formfields["usr_name"],
				$formfields["usr_email"], $checkerror)) {
	    $errors["Pass Phrase"] = "$checkerror";
	}
    }
792
}
793
if (!$forwikionly) {
794
    if (!isset($formfields["pid"]) || $formfields["pid"] == "") {
795 796 797
	if ($returning) {
	    $errors["Project Name"] = "Missing Field";
	}
798 799 800 801 802 803 804
	elseif (!isset($nopidokay)) {
	    # 
	    # Sigh, no one reads or follows simple instructions.
	    #
	    $errors["Project Name"] = "Missing Field";
	}
	elseif (isset($nopidokay) && $nopidokay != "1") {
805 806 807 808 809 810 811
	    if ($nopidokay != "Confirm") {
		$errors["Project Name"] = "Please tell us the Project";
	    }
	}
	else {
	    $nopidconfirm = 1;
	}
812 813 814
    }
    else {
        # Confirm pid/gid early to avoid spamming the page.
815
	$pid = $formfields["pid"];
816

817 818
	if (isset($formfields["gid"]) && $formfields["gid"] != "") {
	    $gid = $formfields["gid"];
819 820 821 822 823
	}
	else {
	    $gid = $pid;
	}

824
	if (!TBvalid_pid($pid) || !Project::Lookup($pid)) {
825 826
	    $errors["Project Name"] = "Invalid Project Name";
	}
827
	elseif (!TBvalid_gid($gid) || !Group::LookupByPidGid($pid, $gid)) {
828 829 830
	    $errors["Group Name"] = "Invalid Group Name";
	}
    }
831 832
}

833
# Present these errors before we call out to do pubkey stuff; saves work.
834 835 836 837 838 839
if (count($errors)) {
    SPITFORM($formfields, $returning, $errors);
    PAGEFOOTER();
    return;
}

840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860
#
# No project, lets confirm. 
#
if ($nopidconfirm) {
    PAGEHEADER("Apply for Project Membership");
    
    echo "<blockquote>\n";
    echo "You did not specify a project to join. If you do not join a project ";
    echo "you will not be able to use the testbed. ";
    echo "But if you are sure, click on <b>Confirm</b>. ";
    echo "Else click <b>Back</b> and ";
    echo "enter the name of the project you want to join.\n";
    echo "<br>\n";
    
    echo "<form enctype=\"multipart/form-data\" action='joinproject.php3'
            method=post name=idform>";
    #
    # Send all of their stuff along.
    #
    reset($formfields);
    while (list($key, $value) = each($formfields)) {
861 862 863 864
	if ($key != "nopidokay") {
	    echo "<input type=hidden name=\"formfields[$key]\" ".
		"value=\"$value\"></input>\n";
	}
865 866 867 868 869 870 871 872 873 874 875
    }
    echo "<input type=hidden name='submit' value='Submit'>\n";
    echo "<center><br>\n";
    echo "<input type=submit name=nopidokay value=Confirm>&nbsp;";
    echo "<input type=submit name=nopidokay value=Back>\n";
    echo "</center></form>";

    PAGEFOOTER();
    return;
}

876 877 878
#
# Need the user, project and group objects for the rest of this.
#
879
if (!$forwikionly && isset($pid)) {
880
    if (! ($project = Project::Lookup($pid))) {
881
	TBERROR("Could not lookup object for $pid!", 1);
882
    }
883 884
    if (! ($group = Group::LookupByPidGid($pid, $gid))) {
	TBERROR("Could not lookup object for $pid/$gid!", 1);
885
    }
886
    if ($returning) {
887 888
	$user = $this_user;
	if ($group->IsMember($user, $ignore)) {
889 890
	    $errors["Membership"] = "You are already a member";
	}
891
    }
892 893
}

894 895 896 897 898
#
# If this is a new user, only allow the user creation to proceed if 
# doing so would not add a non-admin (default for new users) to a 
# project with admins.
#
899 900
if ($ISOLATEADMINS && !$returning &&
    isset($project) && count($project->GetAdmins())) {
901
    $errors["Joining Project"] =
902
	"You cannot join this project due to security restrictions!"
903 904 905 906 907 908 909 910
	. "  If you were told to join this project specifically, email"
	. " either the project leader OR $TBMAILADDR_OPS.";
    TBERROR("New user '".$formfields["joining_uid"]."' attempted to join project ".
	    "'$pid'\n".
	    "which would create a mix of admin and non-admin ".
	    "users\n\n--- so the user creation was NOT allowed to occur!\n", 0);
}

911
# Done with sanity checks!
912 913 914 915 916 917 918
if (count($errors)) {
    SPITFORM($formfields, $returning, $errors);
    PAGEFOOTER();
    return;
}

#
919 920
# Create a new user. We do this by creating a little XML file to pass to
# the newuser script.
921 922
#
if (! $returning) {
923
    $args = array();
924 925 926 927 928 929 930 931 932
    $args["name"]	   = $formfields["usr_name"];
    $args["email"]         = $formfields["usr_email"];
    $args["address"]       = $formfields["usr_addr"];
    $args["address2"]      = $formfields["usr_addr2"];
    $args["city"]          = $formfields["usr_city"];
    $args["state"]         = $formfields["usr_state"];
    $args["zip"]           = $formfields["usr_zip"];
    $args["country"]       = $formfields["usr_country"];
    $args["phone"]         = $formfields["usr_phone"];
933
    $args["shell"]         = 'tcsh';
934 935
    $args["title"]         = $formfields["usr_title"];
    $args["affiliation"]   = $formfields["usr_affil"];
936
    $args["affiliation_abbreviation"] = $formfields["usr_affil_abbrev"];
937
    $args["password"]      = $formfields["password1"];
938 939 940
    if ($WIKISUPPORT) {
        $args["wikiname"] = $formfields["wikiname"];
    }
941

942 943
    if (isset($formfields["usr_URL"]) &&
	$formfields["usr_URL"] != $HTTPTAG && $formfields["usr_URL"] != "") {
Russ Fish's avatar
Russ Fish committed
944
	$args["URL"] = $formfields["usr_URL"];
945
    }
946
    if ($USERSELECTUIDS) {
947
	$args["uid"] = $formfields["joining_uid"];
948 949
    }

950 951 952 953 954
    # Backend verifies pubkey and returns error.
    if (!$forwikionly) {
	if (isset($_FILES['usr_keyfile']) &&
	    $_FILES['usr_keyfile']['name'] != "" &&
	    $_FILES['usr_keyfile']['name'] != "none") {
955

956 957 958
	    $localfile = $_FILES['usr_keyfile']['tmp_name'];
	    $args["pubkey"] = file_get_contents($localfile);
	}
959
    }
960 961 962 963
    if ($PROTOGENI && $show_sslcertbox &&
	isset($formfields["passphrase1"]) && $formfields["passphrase1"] != "") {
	$args["passphrase"] = $formfields["passphrase1"];
    }
964 965
    if (! ($user = User::NewNewUser(($forwikionly ?
				     TBDB_NEWACCOUNT_WIKIONLY : 0),
966 967 968 969 970 971
				    $args,
				    $error)) != 0) {
	$errors["Error Creating User"] = $error;
	SPITFORM($formfields, $returning, $errors);
	PAGEFOOTER();
	return;
972
    }
973
    $joining_uid = $user->uid();
974 975
}

976 977 978 979 980 981 982 983
#
# For wikionly registration, we are done.
# 
if ($forwikionly) {
    header("Location: wikiregister.php3?finished=1");
    exit();
}

984 985 986 987
#
# If this sitevar is set, check to see if this addition will create a
# mix of admin and non-admin people in the group. 
#
988
if ($ISOLATEADMINS && isset($project) &&
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
    !$project->IsMember($user, $ignore)) {
    $members = $project->MemberList();

    foreach ($members as $other_user) {
	if ($user->admin() != $other_user->admin()) {
	    if ($returning) {
		$errors["Joining Project"] =
		    "Improper mix of admin and non-admin users";
		SPITFORM($formfields, $returning, $errors);
		PAGEFOOTER();
		return;
	    }
	    else {
		#
		# The user creation still succeeds, which is good. Do not
		# want the effort to be wasted. But need to indicate that
		# something went wrong. Lets send email to tbops since this
		# should be an uncommon problem.
		#
		TBERROR("New user '$joining_uid' attempted to join project ".
			"'$pid'\n".
			"which would create a mix of admin and non-admin ".
			"users\n", 0);
		
		header("Location: joinproject.php3?finished=1");
		return;
	    }
	}
    }
}

1020 1021 1022 1023 1024 1025
# Done if no project to join
if (!isset($project)) {
    header("Location: joinproject.php3?finished=1");
    exit();
}

1026
#
1027
# If joining a subgroup, also add to project group.
1028
#
1029
if ($pid != $gid && ! $project->IsMember($user, $ignore)) {
1030 1031 1032
    if ($project->AddNewMember($user) < 0) {
	TBERROR("Could not add user $joining_uid to project group $pid", 1);
    }
1033 1034 1035
}

#
1036 1037
# Add to the group, but with trust=none. The project/group leader will have
# to upgrade the trust level, making the new user real.
1038
#
1039 1040
if ($group->AddNewMember($user) < 0) {
    TBERROR("Could not add user $joining_uid to group $pid/$gid", 1);
1041 1042
}

1043 1044 1045
#
# Generate an email message to the proj/group leaders.
#
1046
if ($returning) {
1047
    $group->NewMemberNotify($user);
1048
}
1049 1050 1051 1052 1053 1054 1055

#
# Spit out a redirect so that the history does not include a post
# in it. The back button skips over the post and to the form.
# See above for conclusion.
# 
header("Location: joinproject.php3?finished=1");
Russ Fish's avatar
Russ Fish committed
1056
?>