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

9
#
10 11 12
# No PAGEHEADER since we spit out a Location header later. See below.
# 

13
#
14
# Get current user.
15 16
#
$this_user = CheckLogin($check_status);
17

18 19 20 21 22 23 24
#
# Verify page arguments.
#
$optargs = OptionalPageArguments("submit",       PAGEARG_STRING,
				 "finished",     PAGEARG_BOOLEAN,
				 "formfields",   PAGEARG_ARRAY);

25 26 27 28 29
#
# See if we are in an initial Emulab setup.
#
$FirstInitState = (TBGetFirstInitState() == "createproject");

30
#
31 32 33
# If a uid came in, then we check to see if the login is valid.
# If the login is not valid. We require that the user be logged in
# to start a second project.
34
#
35
if ($this_user && !$FirstInitState) {
36 37
    # Allow unapproved users to create multiple projects ...
    # Must be verified though.
38 39
    CheckLoginOrDie(CHECKLOGIN_UNAPPROVED|CHECKLOGIN_WEBONLY);
    $proj_head_uid = $this_user->uid();
40
    $returning = 1;
41
}
42 43 44 45 46
else {
    #
    # No uid, so must be new.
    #
    $returning = 0;
47
}
48
unset($addpubkeyargs);
49

Leigh Stoller's avatar
Leigh Stoller committed
50 51 52
$ACCOUNTWARNING =
    "Before continuing, please make sure your username " .
    "reflects your normal login name. ".
53
    "Emulab accounts are not to be shared amongst users!";
54

Leigh Stoller's avatar
Leigh Stoller committed
55 56 57
$EMAILWARNING =
    "Before continuing, please make sure the email address you have ".
    "provided is current and non-pseudonymic. Redirections and anonymous ".
58 59
    "email addresses are not allowed.";

60 61 62 63 64
#
# Spit the form out using the array of data. 
# 
function SPITFORM($formfields, $returning, $errors)
{
65
    global $TBDB_UIDLEN, $TBDB_PIDLEN, $TBDOCBASE, $WWWHOST;
66
    global $usr_keyfile, $FirstInitState;
67
    global $ACCOUNTWARNING, $EMAILWARNING;
68
    global $WIKISUPPORT, $WIKIHOME, $USERSELECTUIDS;
69
    
70
    PAGEHEADER("Start a New Testbed Project");
71

72 73 74 75 76 77 78 79 80 81 82
    #
    # First initialization gets different text
    #
    if ($FirstInitState == "createproject") {
	echo "<center><font size=+1>
	      Please create your initial project.<br> A good Project Name
              for your first project is probably 'testbed', but you can
              choose anything you like.
              </font></center><br>\n";
    }
    else {
83
	echo "<center><font size=+1>
84 85 86
                 If you are a <font color=red>student
                 (undergrad or graduate)</font>, please
                 do not try to start a project! <br>Your advisor must do it.
87
                 <a href=docwrapper.php3?docname=auth.html target='_blank'>
88
                 Read this for more info.</a>
89
              </font></center><br>\n";
90 91 92 93 94 95 96 97

	if (! $returning) {
	    echo "<center><font size=+1>
                   If you already have an Emulab account,
                   <a href=login.php3?refer=1>
                   <font color=red>please log on first!</font></a>
                   </font></center><br>\n";
	}
98 99
    }

100
    if ($errors) {
101 102
	echo "<table class=nogrid
                     align=center border=0 cellpadding=6 cellspacing=0>
103
              <tr>
104
                 <th align=center colspan=2>
105
                   <font size=+1 color=red>
106
                      &nbsp;Oops, please fix the following errors!&nbsp;
107 108 109 110 111 112
                   </font>
                 </td>
              </tr>\n";

	while (list ($name, $message) = each ($errors)) {
	    echo "<tr>
113 114 115 116
                     <td align=right>
                       <font color=red>$name:&nbsp;</font></td>
                     <td align=left>
                       <font color=red>$message</font></td>
117 118 119 120
                  </tr>\n";
	}
	echo "</table><br>\n";
    }
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
    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";
149 150 151

    echo "<table align=center border=1> 
          <tr>
152
            <td align=center colspan=3>
153
                Fields marked with * are required.
154 155 156
            </td>
          </tr>\n

157
          <form enctype=multipart/form-data name=myform
158
                action=newproject.php3 method=post>\n";
159 160 161 162 163 164

    if (! $returning) {
        #
        # Start user information stuff. Presented for new users only.
        #
	echo "<tr>
165
                  <th colspan=3>
166 167 168
                      Project Head Information:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
                      <font size=-2>
                       (Prospective project leaders please read our
169
                       <a href='docwrapper.php3?docname=policies.html' target='_blank'>
170
                       Administrative Policies</a>)</font>
171
                  </th>
172 173 174
              </tr>\n";

        #
175
        # UID:
176
        #
177 178 179 180 181 182 183 184 185
	if ($USERSELECTUIDS || $FirstInitState == "createproject") {
	    echo "<tr>
                      <td colspan=2>*<a
                             href='docwrapper.php3?docname=security.html'
                             target=_blank>Username</a>
                                (alphanumeric, lowercase):</td>
                      <td class=left>
                          <input type=text
                                 name=\"formfields[proj_head_uid]\"
186
                                 value=\"" . $formfields["proj_head_uid"] . "\"
187 188 189 190 191 192
	                         size=$TBDB_UIDLEN
                                 onchange=\"alert('$ACCOUNTWARNING')\"
	                         maxlength=$TBDB_UIDLEN>
                      </td>
                  </tr>\n";
	}
193 194 195 196 197

	#
	# Full Name
	#
        echo "<tr>
198
                  <td colspan=2>*Full Name (first and last):</td>
199 200 201
                  <td class=left>
                      <input type=text
                             name=\"formfields[usr_name]\"
202
                             value=\"" . $formfields["usr_name"] . "\"
203
                             onchange=\"SetWikiName(myform);\"
204 205 206 207
	                     size=30>
                  </td>
              </tr>\n";

208 209 210 211 212 213
	#
	# WikiName
	#
	if ($WIKISUPPORT) {
	    echo "<tr>
                      <td colspan=2>*
214
                          <a href=${WIKIHOME}/bin/view/TWiki/WikiName
215 216 217
                            target=_blank>WikiName</a>:<td class=left>
                          <input type=text
                                 name=\"formfields[wikiname]\"
218
                                 value=\"" . $formfields["wikiname"] . "\"
219 220 221 222 223
	                         size=30>
                      </td>
                  </tr>\n";
	}

224 225 226 227
        #
	# Title/Position:
	# 
	echo "<tr>
228
                  <td colspan=2>*Job Title/Position:</td>
229 230 231
                  <td class=left>
                      <input type=text
                             name=\"formfields[usr_title]\"
232
                             value=\"" . $formfields["usr_title"] . "\"
233 234 235 236 237 238 239 240
	                     size=30>
                  </td>
              </tr>\n";

        #
	# Affiliation:
	# 
	echo "<tr>
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
                      <td colspan=2>*Institutional Affiliation:</td>
                      <td class=left>
			<table>
                          <tr>
                          <td>Name</td>
                          <td><input type=text
                                 name=\"formfields[usr_affil]\"
                                 value=\"" . $formfields["usr_affil"] . "\"
	                         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>
                      </td>
259 260 261 262 263 264
              </tr>\n";

	#
	# User URL
	#
	echo "<tr>
265
                  <td colspan=2>Home Page URL:</td>
266 267 268
                  <td class=left>
                      <input type=text
                             name=\"formfields[usr_URL]\"
269
                             value=\"" . $formfields["usr_URL"] . "\"
270 271 272 273 274 275 276 277
	                     size=45>
                  </td>
              </tr>\n";

	#
	# Email:
	#
	echo "<tr>
278
                  <td colspan=2>*Email Address[<b>1</b>]:</td>
279 280 281
                  <td class=left>
                      <input type=text
                             name=\"formfields[usr_email]\"
282
                             value=\"" . $formfields["usr_email"] . "\"
283
                             onchange=\"alert('$EMAILWARNING')\"
284 285 286 287 288
	                     size=30>
                  </td>
              </tr>\n";


289 290 291 292 293
	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]\"
294
                           value=\"" . $formfields["usr_addr"] . "\"
295 296 297 298
	                   size=45></td></tr>
		  <tr><td>Line 2</td><td colspan=3>
                    <input type=text
                           name=\"formfields[usr_addr2]\"
299
                           value=\"" . $formfields["usr_addr2"] . "\"
300 301 302 303
	                   size=45></td></tr>
		  <tr><td>City</td><td>
                    <input type=text
                           name=\"formfields[usr_city]\"
304
                           value=\"" . $formfields["usr_city"] . "\"
305 306 307 308
	                   size=25></td>
		      <td>State/Province</td><td>
                    <input type=text
                           name=\"formfields[usr_state]\"
309
                           value=\"" . $formfields["usr_state"] . "\"
310 311 312 313
	                   size=2></td></tr>
		  <tr><td>ZIP/Postal Code</td><td>
                    <input type=text
                           name=\"formfields[usr_zip]\"
314
                           value=\"" . $formfields["usr_zip"] . "\"
315 316 317 318
	                   size=10></td>
		      <td>Country</td><td>
                    <input type=text
                           name=\"formfields[usr_country]\"
319
                           value=\"" . $formfields["usr_country"] . "\"
320 321
	                   size=15></td></tr>
               </table></center></td></tr>";
322

323 324 325 326
	#
	# Phone
	#
	echo "<tr>
327
                  <td colspan=2>*Phone #:</td>
328 329 330
                  <td class=left>
                      <input type=text
                             name=\"formfields[usr_phone]\"
331
                             value=\"" . $formfields["usr_phone"] . "\"
332 333 334 335
	                     size=15>
                  </td>
              </tr>\n";

336 337 338 339
	#
	# SSH public key
	#
	echo "<tr>
340 341 342 343
                 <td colspan=2>Upload your SSH Pub Key[<b>2</b>]:<br>
                                   (1K max)</td>
   
                 <td>
344 345 346
                      <input type=hidden name=MAX_FILE_SIZE value=1024>
                      <input type=file
                             name=usr_keyfile
347 348 349
                             value=\"" .
	                           (isset($_FILES['usr_keyfile']) ?
				    $_FILES['usr_keyfile']['name'] : "") . "\"
350 351 352
	                     size=50>
                  </td>
              </tr>\n";
353
	
354 355 356 357 358
	#
	# Password. Note that we do not resend the password. User
	# must retype on error.
	#
	echo "<tr>
359
                  <td colspan=2>*Password[<b>1</b>]:</td>
360 361 362
                  <td class=left>
                      <input type=password
                             name=\"formfields[password1]\"
363
                             value=\"" . $formfields["password1"] . "\"
364 365 366 367
                             size=8></td>
              </tr>\n";

        echo "<tr>
368
                  <td colspan=2>*Retype Password:</td>
369 370 371
                  <td class=left>
                      <input type=password
                             name=\"formfields[password2]\"
372
                             value=\"" . $formfields["password2"] . "\"
373 374 375 376 377 378 379
                             size=8></td>
             </tr>\n";
    }

    #
    # Project information
    #
380 381 382 383
    echo "<tr><th colspan=3>
               Project Information: 
               <!-- <em>(replace the example entries)</em> -->
              </th>
384 385 386 387 388 389
          </tr>\n";

    #
    # Project Name:
    #
    echo "<tr>
390
              <td colspan=2>*Project Name (alphanumeric):</td>
391 392 393
              <td class=left>
                  <input type=text
                         name=\"formfields[pid]\"
394
                         value=\"" . $formfields["pid"] . "\"
395 396 397 398 399 400 401 402
	                 size=$TBDB_PIDLEN maxlength=$TBDB_PIDLEN>
              </td>
          </tr>\n";

    #
    # Project Description:
    #
    echo "<tr>
403
              <td colspan=2>*Project Description:</td>
404 405 406
              <td class=left>
                  <input type=text
                         name=\"formfields[proj_name]\"
407
                         value=\"" . $formfields["proj_name"] . "\"
408 409 410 411 412 413 414 415
	                 size=40>
              </td>
          </tr>\n";

    #
    # URL:
    #
    echo "<tr>
416
              <td colspan=2>*URL:</td>
417 418 419
              <td class=left>
                  <input type=text
                         name=\"formfields[proj_URL]\"
420
                         value=\"" . $formfields["proj_URL"] . "\"
421 422 423 424 425 426 427
                         size=45>
              </td>
          </tr>\n";

    #
    # Publicly visible.
    #
Leigh Stoller's avatar
Leigh Stoller committed
428 429 430
    if (!isset($formfields["proj_public"])) {
	$formfields["proj_public"] = "";
    }
431
    echo "<tr>
432 433
              <td colspan=2>*Can we list your project publicly as
                             an \"Emulab User?\":
434 435 436 437 438 439
                  <br>
                  (See our <a href=\"projectlist.php3\"
                              target=\"Users\">Users</a> page)
              </td>
              <td><input type=checkbox value=checked
                         name=\"formfields[proj_public]\"
440
                         " . $formfields["proj_public"] . ">
441 442 443 444 445
                         Yes &nbsp
 	          <br>
                  *If \"No\" please tell us why not:<br>
                  <input type=text
                         name=\"formfields[proj_whynotpublic]\"
446
                         value=\"" . $formfields["proj_whynotpublic"] . "\"
447 448 449 450
	                 size=45>
             </td>
      </tr>\n";

451 452 453
    #
    # Will you add a link?
    #
Leigh Stoller's avatar
Leigh Stoller committed
454 455 456
    if (!isset($formfields["proj_linked"])) {
	$formfields["proj_linked"] = "";
    }
457 458
    echo "<tr>
              <td colspan=2>*Will you add a link on your project page
459
                        to <a href=\"$TBDOCBASE\" target='_blank'>$WWWHOST</a>?
460 461 462
              </td>
              <td><input type=checkbox value=checked
                         name=\"formfields[proj_linked]\"
463
                         " . $formfields["proj_linked"] . ">
464 465 466 467
                         Yes &nbsp
              </td>
      </tr>\n";

468 469 470 471
    #
    # Funders/Grant numbers
    #
    echo "<tr>
472
              <td colspan=2>*Funding Sources and Grant Numbers:<br>
473 474 475 476
                  (Type \"none\" if not funded)</td>
              <td class=left>
                  <input type=text
                         name=\"formfields[proj_funders]\"
477
                         value=\"" . $formfields["proj_funders"] . "\"
478 479 480 481 482 483 484 485
	                 size=45>
              </td>
          </tr>\n";

    #
    # Nodes and PCs and Users
    #
    echo "<tr>
486
              <td colspan=2>*Estimated #of Project Members:</td>
487 488 489
              <td class=left>
                  <input type=text
                         name=\"formfields[proj_members]\" 
490
                         value=\"" . $formfields["proj_members"] . "\"
491 492 493 494 495
                         size=4>
              </td>
          </tr>\n";

    echo "<tr>
496
              <td colspan=2>*Estimated #of
497
        <a href=\"$TBDOCBASE/hardware.php#tbpcs\" target='_blank'>
498
                             PCs</a>:</td>
499 500 501
              <td class=left>
                  <input type=text
                         name=\"formfields[proj_pcs]\"
502
                         value=\"" . $formfields["proj_pcs"] . "\"
503 504 505 506 507
                         size=4>
              </td>
          </tr>\n";

    echo "<tr>
508
              <td colspan=2>Request Access to 
509 510
                  <a href=\"$TBDOCBASE/docwrapper.php3?docname=widearea.html\"
                      target='_blank'>Planetlab PCs</a>:</td>
511
              <td class=left>
512
                  <input type=checkbox value=checked
513 514 515
                         name=\"formfields[proj_plabpcs]\" " .
	                  (isset($formfields["proj_plabpcs"]) ?
			   $formfields["proj_plabpcs"] : "") . ">Yes &nbsp
516 517 518 519
              </td>
          </tr>\n";

    echo "<tr>
520
              <td colspan=2>Request Access to 
521 522
                 <a href=\"$TBDOCBASE/docwrapper.php3?docname=widearea.html\"
                    target='_blank'>wide-area PCs</a>:</td>
523
              <td class=left>
524
                  <input type=checkbox value=checked
525 526 527
                         name=\"formfields[proj_ronpcs]\" " .
	                  (isset($formfields["proj_ronpcs"]) ?
			   $formfields["proj_ronpcs"] : "") . ">Yes &nbsp
528 529 530 531 532 533 534
              </td>
          </tr>\n";

    #
    # Why!
    # 
    echo "<tr>
535
              <td colspan=3>
536 537 538 539
               *Please describe how and why you'd like to use the testbed.
              </td>
          </tr>
          <tr>
540
              <td colspan=3 align=center class=left>
541 542
                  <textarea name=\"formfields[proj_why]\"
                    rows=10 cols=60>" .
543
	            ereg_replace("\r", "", $formfields["proj_why"]) .
544 545 546 547 548
	            "</textarea>
              </td>
          </tr>\n";

    echo "<tr>
549
              <td colspan=3 align=center>
550 551 552 553 554 555 556 557 558 559
                 <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
560
                 <a href = 'docwrapper.php3?docname=security.html' target='_blank'>
561
                 security policies</a> for information
562 563 564
                 regarding passwords and email addresses.\n";
    if (! $returning) {
	echo "<li> If you want us to use your existing ssh public key,
565
                   then please specify the path to your
566
                   your identity.pub file. <font color=red>NOTE:</font>
567
                   We use the <a href=http://www.openssh.org target='_blank'>OpenSSH</a>
568
                   key format,
569 570
                   which has a slightly different protocol 2 public key format
                   than some of the commercial vendors such as
571
                   <a href=http://www.ssh.com target='_blank'>SSH Communications</a>. If you
572
                   use one of these commercial vendors, then please
573 574
                   upload the public key file and we will convert it
                   for you.\n";
575 576
    }
    echo "</ol>
577 578
          </blockquote></blockquote>
          </h4>\n";
579
}
580 581 582 583

#
# The conclusion of a newproject request. See below.
# 
584
if (isset($finished)) {
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
    PAGEHEADER("Start a New Testbed Project");

    echo "<center><h2>
           Your project request has been successfully queued.
          </h2></center>
          Testbed Operations has been notified of your application.
          Most applications are reviewed within a day; some even within
          the hour, but sometimes as long as a week (rarely). We will notify
          you by e-mail when a decision has been made.\n";

    if (! $returning) {
	echo "<br>
              <p>
              In the meantime, as a new user of the Testbed you will receive
              a key via email.
              When you receive the message, please follow the instructions
              contained in the message on how to verify your account.\n";
    }
    PAGEFOOTER();
    return;
605
}
606 607 608 609

#
# On first load, display a virgin form and exit.
#
610
if (! isset($submit)) {
611
    $defaults = array();
612 613 614 615 616
    $defaults["proj_head_uid"]  = "";
    $defaults["usr_name"]       = "";
    $defaults["wikiname"]       = "";
    $defaults["usr_title"]      = "";
    $defaults["usr_affil"]      = "";
617
    $defaults["usr_affil_abbrev"] = "";
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
    $defaults["usr_URL"]        = "$HTTPTAG";
    $defaults["usr_email"]      = "";
    $defaults["usr_addr"]       = "";
    $defaults["usr_addr2"]      = "";
    $defaults["usr_city"]       = "";
    $defaults["usr_state"]      = "";
    $defaults["usr_zip"]        = "";
    $defaults["usr_country"]    = "USA";
    $defaults["usr_phone"]      = "";
    $defaults["password1"]      = "";
    $defaults["password2"]      = "";
    
    $defaults["pid"]            = "";
    $defaults["proj_name"]      = "";
    $defaults["proj_URL"]       = "$HTTPTAG";
    $defaults["proj_public"]    = "checked";
    $defaults["proj_whynotpublic"] = "";
    $defaults["proj_linked"]    = "checked";
    $defaults["proj_funders"]   = "";
    $defaults["proj_members"]   = "";
    $defaults["proj_pcs"]       = "";
    $defaults["proj_ronpcs"]    = "";
    $defaults["proj_plabpcs"]   = "";
    $defaults["proj_why"]       = "";
642 643

    if ($FirstInitState == "createproject") {
644 645 646 647 648 649
	$defaults["pid"]          = "testbed";
	$defaults["proj_pcs"]     = "256";
	$defaults["proj_members"] = "256";
	$defaults["proj_funders"] = "none";
	$defaults["proj_name"]    = "Your Testbed Project";
	$defaults["proj_why"]     = "This project is used for testbed ".
650 651
	    "administrators to develop and test new software. ";
    }
652 653 654 655
    
    SPITFORM($defaults, $returning, 0);
    PAGEFOOTER();
    return;
656
}
657 658 659 660

# Form submitted. Make sure we have a formfields array.
if (!isset($formfields)) {
    PAGEARGERROR("Invalid form arguments.");
661
}
662

Leigh Stoller's avatar
Leigh Stoller committed
663
#TBERROR("A\n\n" . print_r($formfields, TRUE), 0);
Leigh Stoller's avatar
Leigh Stoller committed
664

665 666 667 668 669 670 671 672 673
#
# Otherwise, must validate and redisplay if errors
#
$errors = array();

#
# These fields are required!
#
if (! $returning) {
674
    if ($USERSELECTUIDS || $FirstInitState == "createproject") {
675 676
	if (!isset($formfields["proj_head_uid"]) ||
	    strcmp($formfields["proj_head_uid"], "") == 0) {
677 678
	    $errors["Username"] = "Missing Field";
	}
679
	elseif (!TBvalid_uid($formfields["proj_head_uid"])) {
680 681
	    $errors["UserName"] = TBFieldErrorString();
	}
682 683
	elseif (User::Lookup($formfields["proj_head_uid"]) ||
		posix_getpwnam($formfields["proj_head_uid"])) {
684 685
	    $errors["UserName"] = "Already in use. Pick another";
	}
686
    }
687 688
    if (!isset($formfields["usr_title"]) ||
	strcmp($formfields["usr_title"], "") == 0) {
689
	$errors["Job Title/Position"] = "Missing Field";
690
    }
691
    elseif (! TBvalid_title($formfields["usr_title"])) {
692
	$errors["Job Title/Position"] = TBFieldErrorString();
693
    }
694 695
    if (!isset($formfields["usr_name"]) ||
	strcmp($formfields["usr_name"], "") == 0) {
696 697
	$errors["Full Name"] = "Missing Field";
    }
698
    elseif (! TBvalid_usrname($formfields["usr_name"])) {
699
	$errors["Full Name"] = TBFieldErrorString();
700
    }
701
    # Make sure user name has at least two tokens!
702
    $tokens = preg_split("/[\s]+/", $formfields["usr_name"],
703 704 705 706
			 -1, PREG_SPLIT_NO_EMPTY);
    if (count($tokens) < 2) {
	$errors["Full Name"] = "Please provide a first and last name";
    }
707
    if ($WIKISUPPORT) {
708 709
	if (!isset($formfields["wikiname"]) ||
	    strcmp($formfields["wikiname"], "") == 0) {
710 711
	    $errors["WikiName"] = "Missing Field";
	}
712
	elseif (! TBvalid_wikiname($formfields["wikiname"])) {
713 714
	    $errors["WikiName"] = TBFieldErrorString();
	}
715
	elseif (User::LookupByWikiName($formfields["wikiname"])) {
716 717 718
	    $errors["WikiName"] = "Already in use. Pick another";
	}
    }
719 720
    if (!isset($formfields["usr_affil"]) ||
	strcmp($formfields["usr_affil"], "") == 0) {
721
	$errors["Affiliation Name"] = "Missing Field";
722
    }
723
    elseif (! TBvalid_affiliation($formfields["usr_affil"])) {
724 725 726 727 728 729 730 731
	$errors["Affiliation Name"] = TBFieldErrorString();
    }
    if (!isset($formfields["usr_affil_abbrev"]) ||
	strcmp($formfields["usr_affil_abbrev"], "") == 0) {
	$errors["Affiliation Abbreviation"] = "Missing Field";
    }
    elseif (! TBvalid_affiliation_abbreviation($formfields["usr_affil"])) {
	$errors["Affiliation Name"] = TBFieldErrorString();
732
    }
733 734
    if (!isset($formfields["usr_email"]) ||
	strcmp($formfields["usr_email"], "") == 0) {
735 736
	$errors["Email Address"] = "Missing Field";
    }
737
    elseif (! TBvalid_email($formfields["usr_email"])) {
738
	$errors["Email Address"] = TBFieldErrorString();
739
    }
740
    elseif (User::LookupByEmail($formfields["usr_email"])) {
741 742 743
        #
        # Treat this error separate. Not allowed.
        #
744 745
	$errors["Email Address"] =
	    "Already in use. <b>Did you forget to login?</b>";
746
    }
747 748 749 750
    if (isset($formfields["usr_URL"]) &&
	strcmp($formfields["usr_URL"], "") &&
	strcmp($formfields["usr_URL"], $HTTPTAG) &&
	! CHECKURL($formfields["usr_URL"], $urlerror)) {
751 752
	$errors["Home Page URL"] = $urlerror;
    }
753 754
    if (!isset($formfields["usr_addr"]) ||
	strcmp($formfields["usr_addr"], "") == 0) {
755 756
	$errors["Address 1"] = "Missing Field";
    }
757
    elseif (! TBvalid_addr($formfields["usr_addr"])) {
758 759 760
	$errors["Address 1"] = TBFieldErrorString();
    }
    # Optional
761 762
    if (isset($formfields["usr_addr2"]) &&
	!TBvalid_addr($formfields["usr_addr2"])) {
763
	$errors["Address 2"] = TBFieldErrorString();
764
    }
765 766
    if (!isset($formfields["usr_city"]) ||
	strcmp($formfields["usr_city"], "") == 0) {
767 768
	$errors["City"] = "Missing Field";
    }
769
    elseif (! TBvalid_city($formfields["usr_city"])) {
770 771
	$errors["City"] = TBFieldErrorString();
    }
772 773
    if (!isset($formfields["usr_state"]) ||
	strcmp($formfields["usr_state"], "") == 0) {
774 775
	$errors["State"] = "Missing Field";
    }
776
    elseif (! TBvalid_state($formfields["usr_state"])) {
777 778
	$errors["State"] = TBFieldErrorString();
    }
779 780
    if (!isset($formfields["usr_zip"]) ||
	strcmp($formfields["usr_zip"], "") == 0) {
781 782
	$errors["ZIP/Postal Code"] = "Missing Field";
    }
783
    elseif (! TBvalid_zip($formfields["usr_zip"])) {
784 785
	$errors["Zip/Postal Code"] = TBFieldErrorString();
    }
786 787
    if (!isset($formfields["usr_country"]) ||
	strcmp($formfields["usr_country"], "") == 0) {
788
	$errors["Country"] = "Missing Field";
789
    }
790
    elseif (! TBvalid_country($formfields["usr_country"])) {
791 792
	$errors["Country"] = TBFieldErrorString();
    }
793 794
    if (!isset($formfields["usr_phone"]) ||
	strcmp($formfields["usr_phone"], "") == 0) {
795 796
	$errors["Phone #"] = "Missing Field";
    }
797
    elseif (!TBvalid_phone($formfields["usr_phone"])) {
798
	$errors["Phone #"] = TBFieldErrorString();
799
    }
800 801
    if (!isset($formfields["password1"]) ||
	strcmp($formfields["password1"], "") == 0) {
802 803
	$errors["Password"] = "Missing Field";
    }
804 805
    if (!isset($formfields["password2"]) ||
	strcmp($formfields["password2"], "") == 0) {
806 807
	$errors["Confirm Password"] = "Missing Field";
    }
808
    elseif (strcmp($formfields["password1"], $formfields["password2"])) {
809 810
	$errors["Confirm Password"] = "Does not match Password";
    }
811 812
    elseif (! CHECKPASSWORD((($USERSELECTUIDS ||
			     $FirstInitState == "createproject") ?
813 814 815 816
			     $formfields["proj_head_uid"] : "ignored"),
			    $formfields["password1"],
			    $formfields["usr_name"],
			    $formfields["usr_email"], $checkerror)) {
817 818
	$errors["Password"] = "$checkerror";
    }
819
}
820

821 822
if (!isset($formfields["pid"]) ||
    strcmp($formfields["pid"], "") == 0) {
823
    $errors["Project Name"] = "Missing Field";
824
}
825
else {
826
    if (!TBvalid_newpid($formfields["pid"])) {
827
	$errors["Project Name"] = TBFieldErrorString();
828
    }
829
    elseif (Project::LookupByPid($formfields["pid"])) {
830 831 832
	$errors["Project Name"] =
	    "Already in use. Select another";
    }
833
}
834

835 836
if (!isset($formfields["proj_name"]) ||
    strcmp($formfields["proj_name"], "") == 0) {
837
    $errors["Project Description"] = "Missing Field";
838
}
839
elseif (! TBvalid_description($formfields["proj_name"])) {
840 841
    $errors["Project Description"] = TBFieldErrorString();
}
842 843 844
if (!isset($formfields["proj_URL"]) ||
    strcmp($formfields["proj_URL"], "") == 0 ||
    strcmp($formfields["proj_URL"], $HTTPTAG) == 0) {    
845
    $errors["Project URL"] = "Missing Field";
846
}
847
elseif (! CHECKURL($formfields["proj_URL"], $urlerror)) {
848
    $errors["Project URL"] = $urlerror;
849
}
850 851
if (!isset($formfields["proj_funders"]) ||
    strcmp($formfields["proj_funders"], "") == 0) {
852
    $errors["Funding Sources"] = "Missing Field";
853
}
854
elseif (! TBvalid_description($formfields["proj_funders"])) {
855 856
    $errors["Funding Sources"] = TBFieldErrorString();
}
857 858
if (!isset($formfields["proj_members"]) ||
    strcmp($formfields["proj_members"], "") == 0) {
859
    $errors["#of Members"] = "Missing Field";
860
}
861
elseif (! TBvalid_num_members($formfields["proj_members"])) {
862
    $errors["#of Members"] = TBFieldErrorString();
863
}
864 865
if (!isset($formfields["proj_pcs"]) ||
    strcmp($formfields["proj_pcs"], "") == 0) {
866
    $errors["#of PCs"] = "Missing Field";
867
}
868
elseif (! TBvalid_num_pcs($formfields["proj_pcs"])) {
869
    $errors["#of PCs"] = TBFieldErrorString();
870
}
871

872 873 874
if (isset($formfields["proj_plabpcs"]) &&
    strcmp($formfields["proj_plabpcs"], "") &&
    strcmp($formfields["proj_plabpcs"], "checked")) {
875
    $errors["Planetlab Access"] = "Bad Value";
876
}
877 878 879
if (isset($formfields["proj_ronpcs"]) &&
    strcmp($formfields["proj_ronpcs"], "") &&
    strcmp($formfields["proj_ronpcs"], "checked")) {
880
    $errors["Ron Access"] = "Bad Value";
881
}
882 883
if (!isset($formfields["proj_why"]) ||
    strcmp($formfields["proj_why"], "") == 0) {
884
    $errors["How and Why?"] = "Missing Field";
885
}
886
elseif (! TBvalid_why($formfields["proj_why"])) {
887
    $errors["How and Why?"] = TBFieldErrorString();
888
}
889 890 891 892
if ((!isset($formfields["proj_public"]) ||
     strcmp($formfields["proj_public"], "checked")) &&
    (!isset($formfields["proj_whynotpublic"]) ||
     strcmp($formfields["proj_whynotpublic"], "") == 0)) {
893
    $errors["Why Not Public?"] = "Missing Field";
894
}
895 896 897
if (isset($formfields["proj_linked"]) &&
    strcmp($formfields["proj_linked"], "") &&
    strcmp($formfields["proj_linked"], "checked")) {
898 899
    $errors["Link to Us"] = "Bad Value";
}
900

Leigh Stoller's avatar
Leigh Stoller committed
901
# Present these errors before we call out to do anything else.
902 903 904 905 906 907 908
if (count($errors)) {
    SPITFORM($formfields, $returning, $errors);
    PAGEFOOTER();
    return;
}

#
909
# Create the User first, then the Project/Group.
910 911 912
# Certain of these values must be escaped or otherwise sanitized.
#
if (!$returning) {
913
    $args = array();
914 915 916 917 918 919 920 921 922
    $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"];
923
    $args["shell"]         = 'tcsh';
924 925
    $args["title"]         = $formfields["usr_title"];
    $args["affiliation"]   = $formfields["usr_affil"];
926
    $args["affiliation_abbreviation"] = $formfields["usr_affil_abbrev"];
927 928
    $args["password"]      = $formfields["password1"];
    $args["wikiname"]      = ($WIKISUPPORT ? $formfields["wikiname"] : "");
929

930 931 932
    if (isset($formfields["usr_URL"]) &&
	$formfields["usr_URL"] != $HTTPTAG && $formfields["usr_URL"] != "") {
	$args["URL"] = $formfields["usr_URL"];
933
    }
934
    if ($USERSELECTUIDS || $FirstInitState == "createproject") {
935
	$args["login"] = $formfields["proj_head_uid"];
936
    }
937 938 939 940 941 942 943 944

    # Backend verifies pubkey and returns error.
    if (isset($_FILES['usr_keyfile']) &&
	$_FILES['usr_keyfile']['name'] != "" &&
	$_FILES['usr_keyfile']['name'] != "none") {

	$localfile = $_FILES['usr_keyfile']['tmp_name'];
	$args["pubkey"] = file_get_contents($localfile);
945
    }
946

947 948 949 950 951 952 953 954 955 956 957
    # Just collect the user XML args here and pass the file to NewNewProject.
    # Underneath, newproj calls newuser with the XML file.
    #
    # Calling newuser down in Perl land makes creation of the leader account
    # and the project "atomic" from the user's point of view.  This avoids a
    # problem when the DB is locked for daily backup: in newproject, the call
    # on NewNewUser would block and then unblock and get done; meanwhile the
    # PHP thread went away so we never returned here to call NewNewProject.
    #
    if (! ($newuser_xml = User::NewNewUserXML($args, $errors)) != 0) {
	$errors["Error Creating User XML"] = $error;
Leigh Stoller's avatar
Leigh Stoller committed
958
	TBERROR("B\n${error}\n\n" . print_r($args, TRUE), 0);
959 960 961
	SPITFORM($formfields, $returning, $errors);
	PAGEFOOTER();
	return;
962
    }
963
}
964

965 966 967 968
#
# Now for the new Project
#
$args = array();
969 970 971 972 973 974 975 976
if (isset($newuser_xml)) {
    $args["newuser_xml"]   = $newuser_xml;
}
if ($returning) {
    # An existing, logged-in user is starting the project.
    $args["leader"]	   = $this_user->uid();
}
$args["name"]		   = $formfields["pid"];
977 978 979 980 981 982 983
$args["short description"] = $formfields["proj_name"];
$args["URL"]               = $formfields["proj_URL"];
$args["members"]           = $formfields["proj_members"];
$args["num_pcs"]           = $formfields["proj_pcs"];
$args["long description"]  = $formfields["proj_why"];
$args["funders"]           = $formfields["proj_funders"];
$args["whynotpublic"]      = $formfields["proj_whynotpublic"];
984

985 986
if (!isset($formfields["proj_public"]) ||
    $formfields["proj_public"] != "checked") {
987
    $args["public"] = 0;
988 989
}
else {
990
    $args["public"] = 1;
991
}
992 993
if (!isset($formfields["proj_linked"]) ||
    $formfields["proj_linked"] != "checked") {
994
    $args["linkedtous"] = 0;
995 996
}
else {
997
    $args["linkedtous"] = 1;
998
}
999 1000
if (isset($formfields["proj_plabpcs"]) &&
    $formfields["proj_plabpcs"] == "checked") {
1001
    $args["plab"] = 1;
1002
}
1003 1004
if (isset($formfields["proj_ronpcs"]) &&
    $formfields["proj_ronpcs"] == "checked") {
1005
    $args["ron"] = 1;
1006
}
1007

1008
if (! ($project = Project::NewNewProject($args, $error))) {
1009
    $errors["Error Creating Project"] = $error;
Leigh Stoller's avatar
Leigh Stoller committed
1010
    TBERROR("C\n${error}\n\n" . print_r($args, TRUE), 0);
1011 1012 1013
    SPITFORM($formfields, $returning, $errors);
    PAGEFOOTER();
    return;
1014
}
1015

1016
#
1017 1018
# Need to do some extra work for the first project; eventually move to backend
# 
1019
if ($FirstInitState) {
1020 1021
    $leader = $project->GetLeader();
    $proj_head_uid = $leader->uid();
1022 1023
    # Set up the management group (emulab-ops).
    Group::Initialize($proj_head_uid);
1024
    
1025 1026 1027
    #
    # Move to next phase. 
    # 
1028
    $pid = $formfields["pid"];
1029 1030 1031 1032 1033 1034
    TBSetFirstInitPid($pid);
    TBSetFirstInitState("approveproject");
    header("Location: approveproject.php3?pid=$pid&approval=approve");
    return;
}

1035
#
1036 1037 1038
# 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.
1039
# 
1040 1041
header("Location: newproject.php3?finished=1");

1042
?>