newproject.php3 32.3 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
# 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 B. Stoller's avatar
Leigh B. 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 B. Stoller's avatar
Leigh B. 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) {
Chad Barb's avatar
   
Chad Barb committed
101
102
	echo "<table class=nogrid
                     align=center border=0 cellpadding=6 cellspacing=0>
103
              <tr>
Chad Barb's avatar
   
Chad Barb committed
104
                 <th align=center colspan=2>
105
                   <font size=+1 color=red>
Chad Barb's avatar
   
Chad Barb committed
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>
Chad Barb's avatar
   
Chad Barb committed
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>
Chad Barb's avatar
   
Chad Barb committed
153
                Fields marked with * are required.
154
155
156
            </td>
          </tr>\n

157
          <form enctype=multipart/form-data name=myform
Leigh B. Stoller's avatar
Leigh B. Stoller committed
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>
Chad Barb's avatar
   
Chad Barb committed
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>
Chad Barb's avatar
   
Chad Barb committed
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>*
Leigh B. Stoller's avatar
Leigh B. Stoller committed
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
                  <td colspan=2>*Institutional<br>Affiliation:</td>
242
243
244
                  <td class=left>
                      <input type=text
                             name=\"formfields[usr_affil]\"
245
                             value=\"" . $formfields["usr_affil"] . "\"
246
247
248
249
250
251
252
253
	                     size=40>
                  </td>
              </tr>\n";

	#
	# User URL
	#
	echo "<tr>
254
                  <td colspan=2>Home Page URL:</td>
255
256
257
                  <td class=left>
                      <input type=text
                             name=\"formfields[usr_URL]\"
258
                             value=\"" . $formfields["usr_URL"] . "\"
259
260
261
262
263
264
265
266
	                     size=45>
                  </td>
              </tr>\n";

	#
	# Email:
	#
	echo "<tr>
267
                  <td colspan=2>*Email Address[<b>1</b>]:</td>
268
269
270
                  <td class=left>
                      <input type=text
                             name=\"formfields[usr_email]\"
271
                             value=\"" . $formfields["usr_email"] . "\"
272
                             onchange=\"alert('$EMAILWARNING')\"
273
274
275
276
277
	                     size=30>
                  </td>
              </tr>\n";


Chad Barb's avatar
   
Chad Barb committed
278
279
280
281
282
	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]\"
283
                           value=\"" . $formfields["usr_addr"] . "\"
Chad Barb's avatar
   
Chad Barb committed
284
285
286
287
	                   size=45></td></tr>
		  <tr><td>Line 2</td><td colspan=3>
                    <input type=text
                           name=\"formfields[usr_addr2]\"
288
                           value=\"" . $formfields["usr_addr2"] . "\"
Chad Barb's avatar
   
Chad Barb committed
289
290
291
292
	                   size=45></td></tr>
		  <tr><td>City</td><td>
                    <input type=text
                           name=\"formfields[usr_city]\"
293
                           value=\"" . $formfields["usr_city"] . "\"
Chad Barb's avatar
   
Chad Barb committed
294
295
296
297
	                   size=25></td>
		      <td>State/Province</td><td>
                    <input type=text
                           name=\"formfields[usr_state]\"
298
                           value=\"" . $formfields["usr_state"] . "\"
Chad Barb's avatar
   
Chad Barb committed
299
300
301
302
	                   size=2></td></tr>
		  <tr><td>ZIP/Postal Code</td><td>
                    <input type=text
                           name=\"formfields[usr_zip]\"
303
                           value=\"" . $formfields["usr_zip"] . "\"
Chad Barb's avatar
   
Chad Barb committed
304
305
306
307
	                   size=10></td>
		      <td>Country</td><td>
                    <input type=text
                           name=\"formfields[usr_country]\"
308
                           value=\"" . $formfields["usr_country"] . "\"
Chad Barb's avatar
   
Chad Barb committed
309
310
	                   size=15></td></tr>
               </table></center></td></tr>";
311

312
313
314
315
	#
	# Phone
	#
	echo "<tr>
316
                  <td colspan=2>*Phone #:</td>
317
318
319
                  <td class=left>
                      <input type=text
                             name=\"formfields[usr_phone]\"
320
                             value=\"" . $formfields["usr_phone"] . "\"
321
322
323
324
	                     size=15>
                  </td>
              </tr>\n";

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

        echo "<tr>
357
                  <td colspan=2>*Retype Password:</td>
358
359
360
                  <td class=left>
                      <input type=password
                             name=\"formfields[password2]\"
361
                             value=\"" . $formfields["password2"] . "\"
362
363
364
365
366
367
368
                             size=8></td>
             </tr>\n";
    }

    #
    # Project information
    #
Chad Barb's avatar
   
Chad Barb committed
369
370
371
372
    echo "<tr><th colspan=3>
               Project Information: 
               <!-- <em>(replace the example entries)</em> -->
              </th>
373
374
375
376
377
378
          </tr>\n";

    #
    # Project Name:
    #
    echo "<tr>
379
              <td colspan=2>*Project Name (alphanumeric):</td>
380
381
382
              <td class=left>
                  <input type=text
                         name=\"formfields[pid]\"
383
                         value=\"" . $formfields["pid"] . "\"
384
385
386
387
388
389
390
391
	                 size=$TBDB_PIDLEN maxlength=$TBDB_PIDLEN>
              </td>
          </tr>\n";

    #
    # Project Description:
    #
    echo "<tr>
392
              <td colspan=2>*Project Description:</td>
393
394
395
              <td class=left>
                  <input type=text
                         name=\"formfields[proj_name]\"
396
                         value=\"" . $formfields["proj_name"] . "\"
397
398
399
400
401
402
403
404
	                 size=40>
              </td>
          </tr>\n";

    #
    # URL:
    #
    echo "<tr>
405
              <td colspan=2>*URL:</td>
406
407
408
              <td class=left>
                  <input type=text
                         name=\"formfields[proj_URL]\"
409
                         value=\"" . $formfields["proj_URL"] . "\"
410
411
412
413
414
415
416
417
                         size=45>
              </td>
          </tr>\n";

    #
    # Publicly visible.
    #
    echo "<tr>
418
419
              <td colspan=2>*Can we list your project publicly as
                             an \"Emulab User?\":
420
421
422
423
424
425
                  <br>
                  (See our <a href=\"projectlist.php3\"
                              target=\"Users\">Users</a> page)
              </td>
              <td><input type=checkbox value=checked
                         name=\"formfields[proj_public]\"
426
                         " . $formfields["proj_public"] . ">
427
428
429
430
431
                         Yes &nbsp
 	          <br>
                  *If \"No\" please tell us why not:<br>
                  <input type=text
                         name=\"formfields[proj_whynotpublic]\"
432
                         value=\"" . $formfields["proj_whynotpublic"] . "\"
433
434
435
436
	                 size=45>
             </td>
      </tr>\n";

437
438
439
440
441
    #
    # Will you add a link?
    #
    echo "<tr>
              <td colspan=2>*Will you add a link on your project page
442
                        to <a href=\"$TBDOCBASE\" target='_blank'>$WWWHOST</a>?
443
444
445
              </td>
              <td><input type=checkbox value=checked
                         name=\"formfields[proj_linked]\"
446
                         " . $formfields["proj_linked"] . ">
447
448
449
450
                         Yes &nbsp
              </td>
      </tr>\n";

451
452
453
454
    #
    # Funders/Grant numbers
    #
    echo "<tr>
455
              <td colspan=2>*Funding Sources and Grant Numbers:<br>
456
457
458
459
                  (Type \"none\" if not funded)</td>
              <td class=left>
                  <input type=text
                         name=\"formfields[proj_funders]\"
460
                         value=\"" . $formfields["proj_funders"] . "\"
461
462
463
464
465
466
467
468
	                 size=45>
              </td>
          </tr>\n";

    #
    # Nodes and PCs and Users
    #
    echo "<tr>
469
              <td colspan=2>*Estimated #of Project Members:</td>
470
471
472
              <td class=left>
                  <input type=text
                         name=\"formfields[proj_members]\" 
473
                         value=\"" . $formfields["proj_members"] . "\"
474
475
476
477
478
                         size=4>
              </td>
          </tr>\n";

    echo "<tr>
479
              <td colspan=2>*Estimated #of
480
        <a href=\"$TBDOCBASE/docwrapper.php3?docname=hardware.html#tbpcs\" target='_blank'>
481
                             PCs</a>:</td>
482
483
484
              <td class=left>
                  <input type=text
                         name=\"formfields[proj_pcs]\"
485
                         value=\"" . $formfields["proj_pcs"] . "\"
486
487
488
489
490
                         size=4>
              </td>
          </tr>\n";

    echo "<tr>
491
              <td colspan=2>Request Access to 
492
493
                  <a href=\"$TBDOCBASE/docwrapper.php3?docname=widearea.html\"
                      target='_blank'>Planetlab PCs</a>:</td>
494
              <td class=left>
495
                  <input type=checkbox value=checked
496
497
498
                         name=\"formfields[proj_plabpcs]\" " .
	                  (isset($formfields["proj_plabpcs"]) ?
			   $formfields["proj_plabpcs"] : "") . ">Yes &nbsp
499
500
501
502
              </td>
          </tr>\n";

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

    #
    # Why!
    # 
    echo "<tr>
518
              <td colspan=3>
519
520
521
522
               *Please describe how and why you'd like to use the testbed.
              </td>
          </tr>
          <tr>
523
              <td colspan=3 align=center class=left>
524
525
                  <textarea name=\"formfields[proj_why]\"
                    rows=10 cols=60>" .
526
	            ereg_replace("\r", "", $formfields["proj_why"]) .
527
528
529
530
531
	            "</textarea>
              </td>
          </tr>\n";

    echo "<tr>
532
              <td colspan=3 align=center>
533
534
535
536
537
538
539
540
541
542
                 <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
543
                 <a href = 'docwrapper.php3?docname=security.html' target='_blank'>
544
                 security policies</a> for information
545
546
547
                 regarding passwords and email addresses.\n";
    if (! $returning) {
	echo "<li> If you want us to use your existing ssh public key,
548
                   then please specify the path to your
549
                   your identity.pub file. <font color=red>NOTE:</font>
550
                   We use the <a href=http://www.openssh.org target='_blank'>OpenSSH</a>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
551
                   key format,
552
553
                   which has a slightly different protocol 2 public key format
                   than some of the commercial vendors such as
554
                   <a href=http://www.ssh.com target='_blank'>SSH Communications</a>. If you
555
                   use one of these commercial vendors, then please
556
557
                   upload the public key file and we will convert it
                   for you.\n";
558
559
    }
    echo "</ol>
560
561
          </blockquote></blockquote>
          </h4>\n";
562
}
563
564
565
566

#
# The conclusion of a newproject request. See below.
# 
567
if (isset($finished)) {
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
    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;
588
}
589
590
591
592

#
# On first load, display a virgin form and exit.
#
593
if (! isset($submit)) {
594
    $defaults = array();
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
    $defaults["proj_head_uid"]  = "";
    $defaults["usr_name"]       = "";
    $defaults["wikiname"]       = "";
    $defaults["usr_title"]      = "";
    $defaults["usr_affil"]      = "";
    $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"]       = "";
624
625

    if ($FirstInitState == "createproject") {
626
627
628
629
630
631
	$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 ".
632
633
	    "administrators to develop and test new software. ";
    }
634
635
636
637
    
    SPITFORM($defaults, $returning, 0);
    PAGEFOOTER();
    return;
638
}
639
640
641
642

# Form submitted. Make sure we have a formfields array.
if (!isset($formfields)) {
    PAGEARGERROR("Invalid form arguments.");
643
}
644
645
646
647
648
649
650
651
652
653

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

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

794
795
if (!isset($formfields["pid"]) ||
    strcmp($formfields["pid"], "") == 0) {
796
    $errors["Project Name"] = "Missing Field";
797
}
798
else {
799
    if (!TBvalid_newpid($formfields["pid"])) {
800
	$errors["Project Name"] = TBFieldErrorString();
801
    }
802
    elseif (Project::LookupByPid($formfields["pid"])) {
803
804
805
	$errors["Project Name"] =
	    "Already in use. Select another";
    }
806
}
807

808
809
if (!isset($formfields["proj_name"]) ||
    strcmp($formfields["proj_name"], "") == 0) {
810
    $errors["Project Description"] = "Missing Field";
811
}
812
elseif (! TBvalid_description($formfields["proj_name"])) {
813
814
    $errors["Project Description"] = TBFieldErrorString();
}
815
816
817
if (!isset($formfields["proj_URL"]) ||
    strcmp($formfields["proj_URL"], "") == 0 ||
    strcmp($formfields["proj_URL"], $HTTPTAG) == 0) {    
818
    $errors["Project URL"] = "Missing Field";
819
}
820
elseif (! CHECKURL($formfields["proj_URL"], $urlerror)) {
821
    $errors["Project URL"] = $urlerror;
822
}
823
824
if (!isset($formfields["proj_funders"]) ||
    strcmp($formfields["proj_funders"], "") == 0) {
825
    $errors["Funding Sources"] = "Missing Field";
826
}
827
elseif (! TBvalid_description($formfields["proj_funders"])) {
828
829
    $errors["Funding Sources"] = TBFieldErrorString();
}
830
831
if (!isset($formfields["proj_members"]) ||
    strcmp($formfields["proj_members"], "") == 0) {
832
    $errors["#of Members"] = "Missing Field";
833
}
834
elseif (! TBvalid_num_members($formfields["proj_members"])) {
835
    $errors["#of Members"] = TBFieldErrorString();
836
}
837
838
if (!isset($formfields["proj_pcs"]) ||
    strcmp($formfields["proj_pcs"], "") == 0) {
839
    $errors["#of PCs"] = "Missing Field";
840
}
841
elseif (! TBvalid_num_pcs($formfields["proj_pcs"])) {
842
    $errors["#of PCs"] = TBFieldErrorString();
843
}
844

845
846
847
if (isset($formfields["proj_plabpcs"]) &&
    strcmp($formfields["proj_plabpcs"], "") &&
    strcmp($formfields["proj_plabpcs"], "checked")) {
848
    $errors["Planetlab Access"] = "Bad Value";
849
}
850
851
852
if (isset($formfields["proj_ronpcs"]) &&
    strcmp($formfields["proj_ronpcs"], "") &&
    strcmp($formfields["proj_ronpcs"], "checked")) {
853
    $errors["Ron Access"] = "Bad Value";
854
}
855
856
if (!isset($formfields["proj_why"]) ||
    strcmp($formfields["proj_why"], "") == 0) {
857
    $errors["How and Why?"] = "Missing Field";
858
}
859
elseif (! TBvalid_why($formfields["proj_why"])) {
860
    $errors["How and Why?"] = TBFieldErrorString();
861
}
862
863
864
865
if ((!isset($formfields["proj_public"]) ||
     strcmp($formfields["proj_public"], "checked")) &&
    (!isset($formfields["proj_whynotpublic"]) ||
     strcmp($formfields["proj_whynotpublic"], "") == 0)) {
866
    $errors["Why Not Public?"] = "Missing Field";
867
}
868
869
870
if (isset($formfields["proj_linked"]) &&
    strcmp($formfields["proj_linked"], "") &&
    strcmp($formfields["proj_linked"], "checked")) {
871
872
    $errors["Link to Us"] = "Bad Value";
}
873

874
# Present these errors before we call out to do pubkey stuff; saves work.
875
876
877
878
if (count($errors)) {
    SPITFORM($formfields, $returning, $errors);
    PAGEFOOTER();
    return;
879
880
}

881
882
883
884
885
886
887
888
889
890
891
# Done with sanity checks!
if (count($errors)) {
    SPITFORM($formfields, $returning, $errors);
    PAGEFOOTER();
    return;
}

#
# Certain of these values must be escaped or otherwise sanitized.
#
if (!$returning) {
892
    $args = array();
893
894
895
896
897
898
899
900
901
    $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"];
902
    $args["shell"]         = 'tcsh';
903
904
905
906
    $args["title"]         = $formfields["usr_title"];
    $args["affiliation"]   = $formfields["usr_affil"];
    $args["password"]      = $formfields["password1"];
    $args["wikiname"]      = ($WIKISUPPORT ? $formfields["wikiname"] : "");
907

908
909
910
    if (isset($formfields["usr_URL"]) &&
	$formfields["usr_URL"] != $HTTPTAG && $formfields["usr_URL"] != "") {
	$args["URL"] = $formfields["usr_URL"];
911
    }
912
    if ($USERSELECTUIDS || $FirstInitState == "createproject") {
913
	$args["login"] = $formfields["proj_head_uid"];
914
    }
915
916
917
918
919
920
921
922

    # 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);
923
    }
924

925
926
927
928
929
930
931
    if (! ($leader = User::NewNewUser(TBDB_NEWACCOUNT_PROJLEADER,
				      $args,
				      $error)) != 0) {
	$errors["Error Creating User"] = $error;
	SPITFORM($formfields, $returning, $errors);
	PAGEFOOTER();
	return;
932
933
934
    }
    # If null; used below
    $proj_head_uid = $leader->uid();
935
936
}
else {
937
    $leader = $this_user;
938
}
939

940
941
942
943
944
945
946
947
948
949
950
951
#
# Now for the new Project
#
$args = array();
$args["name"]              = $formfields["pid"];
$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"];
952

953
954
if (!isset($formfields["proj_public"]) ||
    $formfields["proj_public"] != "checked") {
955
    $args["public"] = 0;
956
957
}
else {
958
    $args["public"] = 1;
959
}
960
961
if (!isset($formfields["proj_linked"]) ||
    $formfields["proj_linked"] != "checked") {
962
    $args["linkedtous"] = 0;
963
964
}
else {
965
    $args["linkedtous"] = 1;
966
}
967
968
if (isset($formfields["proj_plabpcs"]) &&
    $formfields["proj_plabpcs"] == "checked") {
969
    $args["plab"] = 1;
970
}
971
972
if (isset($formfields["proj_ronpcs"]) &&
    $formfields["proj_ronpcs"] == "checked") {
973
    $args["ron"] = 1;
974
}
975

976
977
978
979
980
if (! ($project = Project::NewNewProject($leader, $args, $error))) {
    $errors["Error Creating Project"] = $error;
    SPITFORM($formfields, $returning, $errors);
    PAGEFOOTER();
    return;
981
}
982

983
#
984
985
# Need to do some extra work for the first project; eventually move to backend
# 
986
if ($FirstInitState) {
Russ Fish's avatar
Russ Fish committed
987
    $pid = $formfields["pid"];
988
989
    Group::Initialize($proj_head_uid, $pid);
    
990
991
992
993
994
995
996
997
998
    #
    # Move to next phase. 
    # 
    TBSetFirstInitPid($pid);
    TBSetFirstInitState("approveproject");
    header("Location: approveproject.php3?pid=$pid&approval=approve");
    return;
}

999
#
1000
1001
1002
# 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.
1003
# 
1004
1005
header("Location: newproject.php3?finished=1");

1006
?>