beginexp.php3 25.9 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2
3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5
6
# All rights reserved.
#
7
8
9
10
11
12
13
14
15
16
17
18
include("defs.php3");

#
# No PAGEHEADER since we spit out a Location header later. See below.
#

#
# Only known and logged in users can begin experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);

19
$idleswaptimeout = TBGetSiteVar("idle/threshold");
20
21
22
23
24
25
26

#
# Helper function to respit on error.
#
function RESPIT($tag, $value)
{
    global $formfields;
27

28
29
30
31
32
33
34
    $errors[$tag] = $value;
    SPITFORM($formfields, $errors);
    PAGEFOOTER();
    die("");
}

#
35
36
# Spit the form out using the array of data.
#
37
38
function SPITFORM($formfields, $errors)
{
39
40
    global $TBDB_PIDLEN, $TBDB_GIDLEN, $TBDB_EIDLEN, $TBDOCBASE;
    global $nsdata, $nsref, $projlist, $exp_nsfile;
Chad Barb's avatar
   
Chad Barb committed
41
    global $uid, $guid;
42
43
    global $idleswaptimeout;

44
45
46
    PAGEHEADER("Begin a Testbed Experiment");

    if ($errors) {
Chad Barb's avatar
   
Chad Barb committed
47
48
	echo "<table class=nogrid
                     align=center border=0 cellpadding=6 cellspacing=0>
49
              <tr>
Chad Barb's avatar
   
Chad Barb committed
50
                 <th align=center colspan=2>
51
                   <font size=+1 color=red>
Chad Barb's avatar
   
Chad Barb committed
52
                      &nbsp;Oops, please fix the following errors!&nbsp;
53
54
55
56
57
58
                   </font>
                 </td>
              </tr>\n";

	while (list ($name, $message) = each ($errors)) {
	    echo "<tr>
Chad Barb's avatar
   
Chad Barb committed
59
60
61
62
                     <td align=right>
                       <font color=red>$name:&nbsp;</font></td>
                     <td align=left>
                       <font color=red>$message</font></td>
63
64
65
66
                  </tr>\n";
	}
	echo "</table><br>\n";
    }
67
    else {
68
	    
Chad Barb's avatar
   
Chad Barb committed
69
	if (!isset($nsdata) && !isset($nsref)) {
70
71
72
73
74
75
76
77
78
	echo "<p><ul>
	    <li><b>If you have an NS file:</b><br> You may want to
                <b><a href='nscheck_form.php3'>syntax check it first</a></b>
	    <li><b>If you do not have an NS file:</b><br> You may want to
		<b><a href='buildui/bui.php3'>go to the NetBuild GUI</a></b>
		to graphically create one<font size=-2>
		(<a href='$TBDOCBASE/faq.php3#UTT-NETBUILD'>Additional 
		information</a>)</font>
	     </ul></p><br>";
Chad Barb's avatar
   
Chad Barb committed
79
80
	} else {
	echo "<p><b>Your NetBuild-generated NS file has been uploaded.</b> " .
81
             "To finish creating your experiment, " .
Chad Barb's avatar
   
Chad Barb committed
82
83
             "please fill out the following information:</p>";
        }
84
    }
85

86
87
    echo "<table align=center border=1>\n";
    echo "<form name='form1' enctype=multipart/form-data
88
89
90
91
92
93
                action=beginexp.php3 method=post>\n";

    #
    # Select Project
    #
    echo "<tr>
94
              <td class='pad4'>Select Project:</td>
95
              <td class='pad4'><select name=\"formfields[exp_pid]\">\n";
96
97
98
99
100

    # If just one project, make sure just the one option.
    if (count($projlist) != 1) {
	echo "<option value=''>Please Select &nbsp</option>\n";
    }
101

102
103
104
105
106
    while (list($project) = each($projlist)) {
	$selected = "";

	if (strcmp($formfields[exp_pid], $project) == 0)
	    $selected = "selected";
107

108
109
110
111
112
113
114
	echo "        <option $selected value=\"$project\">
                             $project </option>\n";
    }
    echo "       </select>";
    echo "    </td>
          </tr>\n";

115
116
    #
    # Select a group
117
    #
118
    echo "<tr>
119
120
              <td class='pad4'>Group:</td>
              <td class='pad4'><select name=\"formfields[exp_gid]\">
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
                    <option value=''>Default Group </option>\n";

    reset($projlist);
    while (list($project, $grouplist) = each($projlist)) {
	for ($i = 0; $i < count($grouplist); $i++) {
	    $group    = $grouplist[$i];

	    if (strcmp($project, $group)) {
		$selected = "";

		if (isset($formfields[exp_gid]) &&
		    isset($formfields[exp_pid]) &&
		    strcmp($formfields[exp_pid], $project) == 0 &&
		    strcmp($formfields[exp_gid], $group) == 0)
		    $selected = "selected";
136

137
138
139
140
141
142
		echo "<option $selected value=\"$group\">
                           $project/$group</option>\n";
	    }
	}
    }
    echo "     </select>
143
144
	  <font size=-1>(Must be default or correspond to selected project)
          </font>
145
146
147
             </td>
          </tr>\n";

148
149
150
151
    #
    # Name:
    #
    echo "<tr>
152
              <td class='pad4'>Name:
153
154
              <br><font size='-1'>(No blanks)</font></td>
              <td class='pad4' class=left>
155
156
157
158
159
160
161
162
163
164
165
166
                  <input type=text
                         name=\"formfields[exp_id]\"
                         value=\"" . $formfields[exp_id] . "\"
	                 size=$TBDB_EIDLEN
                         maxlength=$TBDB_EIDLEN>
              </td>
          </tr>\n";

    #
    # Description
    #
    echo "<tr>
167
              <td class='pad4'>Description:<br>
168
169
                  <font size='-1'>(A concise sentence)</font></td>
              <td class='pad4' class=left>
170
171
172
                  <input type=text
                         name=\"formfields[exp_description]\"
                         value=\"" . $formfields[exp_description] . "\"
173
	                 size=60>
174
175
176
177
178
179
180
181
              </td>
          </tr>\n";

    #
    # NS file
    #
    if (isset($nsdata)) {
        echo "<tr>
182
                  <td class='pad4'>Your Auto Generated NS file: &nbsp</td>
183
                      <input type=hidden name=nsdata value=$nsdata>
184
                  <td class='pad4'><a target=_blank href=spitnsdata.php3?nsdata=$nsdata>
185
186
                      View NS File</a></td>
              </tr>\n";
Chad Barb's avatar
   
Chad Barb committed
187
    } elseif (isset($nsref)) {
Chad Barb's avatar
   
Chad Barb committed
188
189
	if (isset($guid)) {
        echo "<tr>
190
                  <td class='pad4'>Your Auto Generated NS file: &nbsp</td>
Chad Barb's avatar
   
Chad Barb committed
191
192
                      <input type=hidden name=nsref value=$nsref>
                      <input type=hidden name=guid value=$guid>
193
                  <td class='pad4'><a target=_blank href=\"spitnsdata.php3?nsref=$nsref&guid=$guid\">
Chad Barb's avatar
   
Chad Barb committed
194
195
196
                      View NS File</a></td>
              </tr>\n";
        } else {
Chad Barb's avatar
   
Chad Barb committed
197
        echo "<tr>
198
                  <td class='pad4'>Your Auto Generated NS file: &nbsp</td>
Chad Barb's avatar
   
Chad Barb committed
199
                      <input type=hidden name=nsref value=$nsref>
200
                  <td class='pad4'><a target=_blank href=spitnsdata.php3?nsref=$nsref>
Chad Barb's avatar
   
Chad Barb committed
201
202
                      View NS File</a></td>
              </tr>\n";
Chad Barb's avatar
   
Chad Barb committed
203
        }
204
205
    }
    else {
206

207
	echo "<tr>
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
                  <td class='pad4'>Your NS file:<br>
<script language='JavaScript'>
<!--
function SyntaxCheck() {
  window.open('','nscheck','width=600,height=400,toolbar=no,resizeable=yes,scrollbars=yes,status=yes,menubar=yes');
  document.form1.target='nscheck';
  document.form1.submit();
}
function NormalSubmit() {
  document.form1.target='_self';
  document.form1.submit();
}
//-->
</script>
		  <input type=submit disabled id=syntax name='syntax' value='Syntax Check'
		   onclick='SyntaxCheck()'>
		  </td>
225
226
227
228
229
230
231
232
233
234

                  <td><table cellspacing=0 cellpadding=0 border=0>
                    <tr>
                      <td class='pad4'>Upload<br>
			<font size='-1'>(50k&nbsp;max)</font></td>
                      <td class='pad4'>
                        <input type=hidden name=MAX_FILE_SIZE value=51200>
	                <input type=file
                               name=exp_nsfile
                               value=\"" . $exp_nsfile . "\"
235
236
	                       size=30
			       onchange=\"this.form.syntax.disabled=(this.value=='')\">
237
238
239
240
241
242
243
244
245
246
                      </td>
                    </tr><tr>
                    <td>&nbsp;&nbsp;<b>or</b></td><td></td>
                    </tr><tr>
                      <td class='pad4'>On Server<br><font size='-1'>(<code>/proj</code>,
                        <code>/groups</code>, <code>/users</code>)</font></td>
                      <td class='pad4'>
	                <input type=text
                               name=\"formfields[exp_localnsfile]\"
                               value=\"" . $formfields[exp_localnsfile] . "\"
247
248
	                       size=40
			       onchange=\"this.form.syntax.disabled=(this.value=='')\">
249
250
                      </td>
                    </tr></table></td></tr>\n";
251
252
    }

253
254
255
    #
    # Swapping
    #
256
    # Add in hidden fields to send swappable and noswap_reason, since
257
    # they do not show on the form
258
    echo "<tr>
259
260
261
	      <td class='pad4'>
		<a href='$TBDOCBASE/docwrapper.php3?docname=swapping.html#swapping'>
		Swapping:</td>
262
263
264
265
266
267
268
269
270
271
272
	      <td>
	      <input type=hidden name='formfields[exp_swappable]' value='$formfields[exp_swappable]'>
	      <input type=hidden name='formfields[exp_noswap_reason]' value='";
    echo htmlspecialchars($formfields[exp_noswap_reason], ENT_QUOTES);
    echo "'>
	      <table cellpadding=0 cellspacing=0 border=0><tr>
              <td><input type='checkbox'
	             name='formfields[exp_idleswap]'
	             value='1'";
    if ($formfields[exp_idleswap] == "1") {
	echo " checked='1'";
273
    }
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
    echo "></td>
              <td><a href='$TBDOCBASE/docwrapper.php3?docname=swapping.html#idleswap'>
	      <b>Idle-Swap:</b></a> Swap out this experiment
	      after 
              <input type='text' name='formfields[exp_idleswap_timeout]'
		     value='";
    echo htmlspecialchars($formfields[exp_idleswap_timeout], ENT_QUOTES);
    echo "' size='3'> hours idle.</td>
	      </tr><tr>
              <td> </td>
	      <td>If not, why not?<br><textarea rows=2 cols=50
                          name='formfields[exp_noidleswap_reason]'>";
			  
    echo htmlspecialchars($formfields[exp_noidleswap_reason], ENT_QUOTES);
    echo "</textarea></td>
	      </tr><tr>
	      <td><input type='checkbox'
		     name='formfields[exp_autoswap]'
		     value='1' ";
    if ($formfields[exp_autoswap] == "1") {
	echo " checked='1'";
    }
    echo "></td>
	      <td><a href='$TBDOCBASE/docwrapper.php3?docname=swapping.html#autoswap'>
	      <b>Max. Duration:</b></a> Swap out after
              <input type='text' name='formfields[exp_autoswap_timeout]'
		     value='";
    echo htmlspecialchars($formfields[exp_autoswap_timeout], ENT_QUOTES);
    echo "' size='3'> hours, even if not idle.</td>
              </tr></table>
              </td>
           </tr>";
306
307
308
309
310

    #
    # Batch Experiment?
    #
    echo "<tr>
311
312
313
  	      <td class='pad4' colspan=2>
              <input type=checkbox name='formfields[exp_batched]' value='Yep'";

314
    if (isset($formfields[exp_batched]) &&
315
316
317
318
319
320
321
322
323
324
	strcmp($formfields[exp_batched], "Yep") == 0) {
	    echo " checked='1'";
	}

    echo ">\n";
    echo "Batch Mode Experiment &nbsp;
          <font size='-1'>(See
          <a href='$TBDOCBASE/tutorial/tutorial.php3#BatchMode'>Tutorial</a>
          for more information)</font>
          </td>
325
          </tr>\n";
326

327
328
329
    #
    # Preload?
    #
330
    echo "<tr>
331
332
  	      <td class='pad4' colspan=2>
              <input type=checkbox name='formfields[exp_preload]' value='Yep'";
333
334

    if (isset($formfields[exp_preload]) &&
335
336
337
338
339
	strcmp($formfields[exp_preload], "Yep") == 0) {
	    echo " checked='1'";
	}

    echo ">\n";
Mac Newbold's avatar
Mac Newbold committed
340
    echo "Do Not Swap In</td>
341
          </tr>\n";
342
343

    echo "<tr>
344
              <td class='pad4' align=center colspan=2>
345
346
                 <b><input type=submit value=Submit name=submit
			onclick='NormalSubmit()'></b></td>
347
348
349
350
         </tr>
        </form>
        </table>\n";

351
352
    echo "<p>
          <h3>Handy Links:</h3>
353
          <ul>
354
355
             <li> View a <a href='showosid_list.php3'>list of OSIDs</a>
                  that are available for you to use in your NS file.</li>
356
             <li> Create your own <a href='newimageid_ez.php3'>
357
358
                  custom disk images</a>.</li>
          </ul>\n";
359
360
}

Chad Barb's avatar
   
Chad Barb committed
361
362
363
364
365
if (isset($nsref)) {
    if (strcmp($nsref, "") == 0 || !ereg("^[0-9]+$", $nsref))
	unset($nsref);
}

Chad Barb's avatar
   
Chad Barb committed
366
367
368
369
370
if (isset($guid)) {
    if (strcmp($guid, "") == 0 || !ereg("^[0-9]+$", $guid))
	unset($guid);
}

371
372
373
374
375
376
#
# See if nsdata was provided. Clear it if an empty string, otherwise
# reencode it *only* if not from the form. It appears that php decodes
# it for you when it comes in as GET argument, but leaves it encoded
# when its a POST argument.
#
Chad Barb's avatar
   
Chad Barb committed
377

378
if (isset($nsdata)) {
379
    if (strcmp($nsdata, "") == 0)
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
	unset($nsdata);
    elseif (! isset($submit))
	$nsdata = rawurlencode($nsdata);
}

#
# See what projects the uid can create experiments in. Must be at least one.
#
$projlist = TBProjList($uid, $TB_PROJECT_CREATEEXPT);

if (! count($projlist)) {
    USERERROR("You do not appear to be a member of any Projects in which ".
	      "you have permission to create new experiments.", 1);
}

#
# On first load, display a virgin form and exit.
#
398
if (! isset($submit) && ! isset($syntax)) {
399
400
    $defaults = array();

401
402
403
404
    #
    # For users that are in one project and one subgroup, it is usually
    # the case that they should use the subgroup, and since they also tend
    # to be in the clueless portion of our users, give them some help.
405
    #
406
407
    if (count($projlist) == 1) {
	list($project, $grouplist) = each($projlist);
408

409
	if (count($grouplist) <= 2) {
410
	    $defaults[exp_pid] = $project;
411
	    if (count($grouplist) == 1 || strcmp($project, $grouplist[0]))
412
413
414
415
416
417
		$defaults[exp_gid] = $grouplist[0];
	    else
		$defaults[exp_gid] = $grouplist[1];
	}
	reset($projlist);
    }
418
419
420
421
422
423
424
425
426

    $defaults[exp_swappable] = "1";
    $defaults[exp_noswap_reason] = "";
    $defaults[exp_idleswap]  = "1";
    $defaults[exp_noidleswap_reason] = "";
    $defaults[exp_idleswap_timeout] = "$idleswaptimeout";
    $defaults[exp_autoswap]  = "0";
    $defaults[exp_autoswap_timeout] = "10";

427
428
429
430
431
432
433
434
435
436
437
438
    SPITFORM($defaults, 0);
    PAGEFOOTER();
    return;
}

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

#
# Project:
439
#
440
441
442
443
444
445
446
447
448
449
if (!isset($formfields[exp_pid]) ||
    strcmp($formfields[exp_pid], "") == 0) {
    $errors["Project"] = "Not Selected";
}
elseif (!TBValidProject($formfields[exp_pid])) {
    $errors["Project"] = "No such project";
}

#
# EID.
450
#
451
452
453
454
455
if (!isset($formfields[exp_id]) ||
    strcmp($formfields[exp_id], "") == 0) {
    $errors["Experiment Name"] = "Missing Field";
}
else {
456
457
458
    if (! ereg("^[-a-zA-Z0-9]+$", $formfields[exp_id])) {
	$errors["Experiment Name"] =
	    "Must be alphanumeric characters only (dash okay)!";
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
    }
    elseif (strlen($formfields[exp_id]) > $TBDB_EIDLEN) {
	$errors["Experiment Name"] =
	    "Too long! Must be less than or equal to $TBDB_EIDLEN";
    }
}

#
# Description
#
if (!isset($formfields[exp_description]) ||
    strcmp($formfields[exp_description], "") == 0) {
    $errors["Description"] = "Missing Field";
}

#
# Swappable
476
# Any of these which are not "1" become "0".
477
#
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
if (!isset($formfields[exp_swappable]) ||
    strcmp($formfields[exp_swappable], "1")) {
    $formfields[exp_swappable] = 0;

    if (!isset($formfields[exp_noswap_reason]) ||
        !strcmp($formfields[exp_noswap_reason], "")) {

        if (! ISADMIN($uid)) {
          $errors["Not Swappable"] = "No justification provided";
        } else {
          $formfields[exp_noswap_reason] = "ADMIN";
        }
    }
}

if (!isset($formfields[exp_idleswap]) ||
    strcmp($formfields[exp_idleswap], "1")) {
    $formfields[exp_idleswap] = 0;

    if (!isset($formfields[exp_noidleswap_reason]) ||
	!strcmp($formfields[exp_noidleswap_reason], "")) {
	if (! ISADMIN($uid)) {
	    $errors["Not Idle-Swappable"] = "No justification provided";
	} else {
	    $formfields[exp_noidleswap_reason] = "ADMIN";
	}
    }
}

if (!isset($formfields[exp_idleswap_timeout]) ||
    ($formfields[exp_idleswap_timeout] + 0) <= 0 ||
    ($formfields[exp_idleswap_timeout] + 0) > $idleswaptimeout) {
    $errors["Idleswap"] = "No or invalid time provided - must be non-zero and <= $idleswaptimeout";
}

if (!isset($formfields[exp_noidleswap_reason])) {
    $formfields[exp_noidleswap_reason] = "";
}


if (!isset($formfields[exp_autoswap]) ||
    strcmp($formfields[exp_autoswap], "1")) {
    $formfields[exp_autoswap] = 0;
} else {
    if (!isset($formfields[exp_autoswap_timeout]) ||
	($formfields[exp_autoswap_timeout] + 0) == 0) {
	$errors["Max. Duration"] = "No or invalid time provided";
    }
526
527
}

528
529
530
# None of the above errors count during a syntax check
if (isset($syntax)) { $errors = array(); }

531
532
533
#
# If any errors, respit the form with the current values and the
# error messages displayed. Iterate until happy.
534
#
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
if (count($errors)) {
    SPITFORM($formfields, $errors);
    PAGEFOOTER();
    return;
}

$exp_name    = addslashes($formfields[exp_description]);
$exp_pid     = $formfields[exp_pid];
$exp_id      = $formfields[exp_id];
if (isset($formfields[exp_gid])) {
    $exp_gid = $formfields[exp_gid];
}
if (isset($formfields[exp_localnsfile])) {
    $exp_localnsfile = $formfields[exp_localnsfile];
}

#
# Continue with error checks.
#
554
if (TBValidExperiment($exp_pid, $exp_id) && !isset($syntax)) {
555
556
557
558
559
560
561
562
563
564
    RESPIT("Experiment Name", "Already in use");
}

#
# Check group. If none specified, then use default group.
#
if (!isset($exp_gid) ||
    strcmp($exp_gid, "") == 0) {
    $exp_gid = $exp_pid;
}
565
if (!TBValidGroup($exp_pid, $exp_gid) && !isset($syntax)) {
Chad Barb's avatar
   
Chad Barb committed
566
    RESPIT("Group", "Group '$exp_gid' is not in project '$exp_pid'!");
567
568
569
570
571
}

#
# Verify permissions.
#
572
573
if (! TBProjAccessCheck($uid, $exp_pid, $exp_gid, $TB_PROJECT_CREATEEXPT)
    && !isset($syntax)) {
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
    RESPIT("Project/Group", "Not enough permission to create experiment");
}

#
# Not allowed to specify both a local and an upload!
#
$speclocal  = 0;
$specupload = 0;
$delnsfile  = 0;

if (isset($exp_localnsfile) && strcmp($exp_localnsfile, "")) {
    $speclocal = 1;
}
if (isset($exp_nsfile) && strcmp($exp_nsfile, "") &&
    strcmp($exp_nsfile, "none")) {
    $specupload = 1;
}

if ($speclocal && $specupload) {
593
594
595
596
597
598
599
    if (isset($syntax)) {
	echo "<h3 style='color: #f00'>Error: \n".
	    "Specified both a local and remote file!</h3>\n";
	die("");
    } else {
	RESPIT("NS File", "Specified both a local and remote file");
    }
600
601
602
603
604
}
if (!$specupload && strcmp($exp_nsfile_name, "")) {
    #
    # Catch an invalid filename.
    #
605
606
607
608
609
610
611
    if (isset($syntax)) {
	echo "<h3 style='color: #f00'>Error: \n".
	    "Local filename does not appear to be valid!</h3>\n";
	die("");
    } else {
	RESPIT("NS File", "Local filename does not appear to be valid");
    }
612
613
614
615
616
617
618
619
620
}

if ($speclocal) {
    #
    # No way to tell from here if this file actually exists, since
    # the web server runs as user nobody. The startexp script checks
    # for the file before going to ground, so the user will get immediate
    # feedback if the filename is bogus.
    #
621
    # Do not allow anything outside of special dirs. I do not think there
622
623
    # is a security worry, but good to enforce it anyway.
    #
624
625
626
627
628
629
630
631
632
633
    if (!preg_match("/^([-\@\w\.\/]+)$/", $exp_localnsfile)) {
	if (isset($syntax)) {
	    echo "<h3 style='color: #f00'>Error: \n".
		"Pathname includes illegal characters!</h3>\n";
	    die("");
	}
	else {
	    RESPIT("NS File", "Pathname includes illegal characters");
	}
    }
634
    if (! ereg("^$TBPROJ_DIR/.*" ,$exp_localnsfile) &&
635
636
        ! ereg("^$TBUSER_DIR/.*" ,$exp_localnsfile) &&
        ! ereg("^$TBGROUP_DIR/.*" ,$exp_localnsfile)) {
637
638
639
640
641
642
643
644
645
646
	if (isset($syntax)) {
	    echo "<h3 style='color: #f00'>Error: \n".
		"Server resident file must be in either ".
		"$TBUSER_DIR/, $TBPROJ_DIR/, or $TBGROUP_DIR/!</h3>\n";
	    die("");
	} else {
	    RESPIT("NS File",
		   "Server resident file must be in either ".
		   "$TBUSER_DIR/, $TBPROJ_DIR/, or $TBGROUP_DIR/");
	}
647
    }
648

649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
    $nsfile = $exp_localnsfile;
    $nonsfile = 0;
}
elseif ($specupload) {
    #
    # XXX
    # Set the permissions on the NS file so that the scripts can get to it.
    # It is owned by nobody, and most likely protected. This leaves the
    # script open for a short time. A potential security hazard we should
    # deal with at some point.
    #
    chmod($exp_nsfile, 0666);
    $nsfile = $exp_nsfile;
    $nonsfile = 0;
}
Chad Barb's avatar
   
Chad Barb committed
664
elseif (isset($nsref) && strcmp($nsref, "")) {
Chad Barb's avatar
   
Chad Barb committed
665
666
667
668
669
    if (isset($guid)) {
      $nsfile = "/tmp/$guid-$nsref.nsfile";
    } else {
      $nsfile = "/tmp/$uid-$nsref.nsfile";
    }
Chad Barb's avatar
   
Chad Barb committed
670
671
672
    $delnsfile = 1;
    $nonsfile  = 0;
}
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
elseif (isset($nsdata) && strcmp($nsdata, "")) {
    #
    # The NS file is encoded in the URL. Must create a temp file
    # to hold it, and pass through to the backend.
    #
    # XXX Hard to believe, but there is no equiv of mkstemp in php3.
    #
    $nsfile    = tempnam("/tmp", "$exp_pid-$exp_id.nsfile.");
    $delnsfile = 1;
    $nonsfile  = 0;

    if (! ($fp = fopen($nsfile, "w"))) {
	TBERROR("Could not create temporary file $nsfile", 1);
    }
    fwrite($fp, urldecode($nsdata));
    fclose($fp);
689
    chmod($nsfile, 0666);
690
691
692
}
else {
    #
693
694
    # I am going to allow shell experiments to be created (No NS file),
    # but only by admin types.
695
    #
696
697
698
699
700
701
702
703
    if (isset($syntax)) {
	echo "<h3 style='color: #f00'>Error: \n".
	    "You must provide an NS file!</h3>\n";
	die("");
    } else {	
	if (! ISADMIN($uid)) {
	    RESPIT("NS File", "You must provide an NS file");
	}
704
705
    }
    $nonsfile = 1;
706
707
}

708
709
710
711
712
713
714
715
716
717
718
719
#
# Syntax Check:
# If this is a syntax check, do the magic now.
# Magic below courtesy of nscheck.php3
#

if (isset($syntax)) {
    #
    # Run the script. We use a script wrapper to deal with changing
    # to the proper directory and to keep most of these details out
    # of this.
    #
720
721
    $retval = SUEXEC($uid, $TBADMINGROUP, "webnscheck $nsfile",
		     SUEXEC_ACTION_IGNORE);
722
723
724
725
726
727
728

    echo "<div align=right>\n";
    echo "<a href='' onclick='window.close()'>Close Window</a>\n</div>\n";
    echo "<center>\n";
    echo "<h2>Syntax Check Results</h2>\n";
    echo "</center>\n";

729
    if ($retval < 0) {
730
731
732
733
734
	SUEXECERROR(SUEXEC_ACTION_DIE);
        #
        # Never returns ...
        #
        die("");
735
736
    }

737
738
739
740
741
742
743
744
745
746
747
    # Parse Error.	 
    if ($retval) {
	echo "<br><br><h2>
              Parse Failure($retval): Output as follows:
              </h2>
              <br>
              <XMP>$suexec_output</XMP>\n";
	PAGEFOOTER();
	die("");
    }

748
749
750
751
752
753
754
755
    echo "<center><br>";
    echo "<br>";
    echo "<h3>Your NS file looks good!</h3>";
    echo "</center>\n";
    
    exit();
}

756
#
757
# Convert Swappable, Batched params to arguments to script.
758
#
759
760
761
762
$exp_swappable = "";

if ($formfields[exp_swappable] == "1") {
    $exp_swappable .= " -s";
763
764
}

765
766
if ($formfields[exp_autoswap] == "1") {
    $exp_swappable .= " -a " . (60 * $formfields[exp_autoswap_timeout]);
767
}
768
769

if ($formfields[exp_idleswap] == "1") {
Mac Newbold's avatar
Mac Newbold committed
770
    $exp_swappable .= " -l " . (60 * $formfields[exp_idleswap_timeout]);
771
772
}

773
774
775
776
#
# All experiments are low priority for now.
#
$exp_priority  = "-n low";
777
778
779
$exp_batched   = 0;
$exp_preload   = 0;
$batcharg      = "-i";
780

781
782
783
784
if (isset($formfields[exp_batched]) &&
    strcmp($formfields[exp_batched], "Yep") == 0) {
    $exp_batched   = 1;
    $batcharg      = "";
785
786
787
788
789
}
if (isset($formfields[exp_preload]) &&
    strcmp($formfields[exp_preload], "Yep") == 0) {
    $exp_preload   = 1;
    $batcharg     .= " -f";
790
791
}

792
#
793
# I am not spitting out a redirection yet.
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
#
PAGEHEADER("Begin a Testbed Experiment");

#
# We need the email address for messages below.
#
TBUserInfo($uid, $user_name, $user_email);

# Expiration is hardwired for now.
$exp_expires = date("Y:m:d", time() + (86400 * 120));

#
# Grab the unix GID for running scripts.
#
TBGroupUnixInfo($exp_pid, $exp_gid, $unix_gid, $unix_name);

#
811
812
# Okay, time to do it.
#
813
814
815
816
817
818
echo "<font size=+2>Experiment <b>".
     "<a href='showproject.php3?pid=$exp_pid'>$exp_pid</a>/".
     "<a href='showexp.php3?pid=$exp_pid&eid=$exp_id'>$exp_id</a></b>\n".
     "</font>\n";
echo "<br><br>\n";

819
820
821
822
823
824
825
echo "<center><br>";
echo "<h2>Starting experiment configuration. Please wait a moment ...
      </h2></center>";

flush();

#
826
# Run the backend script.
827
828
#
# Avoid SIGPROF in child.
829
#
830
831
set_time_limit(0);

832
833
834
835
836
837
$retval = SUEXEC($uid, $unix_gid,
		 "webbatchexp $batcharg -x \"$exp_expires\" -E \"$exp_name\" ".
		 "$exp_priority $exp_swappable ".
		 "-p $exp_pid -g $exp_gid -e $exp_id ".
		 ($nonsfile ? "" : "$nsfile"),
		 SUEXEC_ACTION_IGNORE);
838
839
840
841
842

if ($delnsfile) {
    unlink($nsfile);
}

843
844
845
846
#
# Fatal Error. Report to the user, even though there is not much he can
# do with the error. Also reports to tbops.
# 
Leigh B. Stoller's avatar
Leigh B. Stoller committed
847
if ($retval < 0) {
848
849
850
851
    SUEXECERROR(SUEXEC_ACTION_DIE);
    #
    # Never returns ...
    #
852
853
854
    die("");
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
855
856
857
858
859
860
861
862
863
864
# User error. Tell user and exit.
if ($retval) {
    echo "<br>";
    echo "<h3>Experiment could not be created</h3>";
    echo "<blockquote><pre>$suexec_output<pre></blockquote>";

    PAGEFOOTER();
    exit();
}

865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
# add reasons to db, since we don't want to pass these on the command line.

if ($formfields[exp_noswap_reason]) {
    DBQueryFatal("UPDATE experiments " .
		 "SET noswap_reason='" .
                 addslashes($formfields[exp_noswap_reason]).
                 "' ".
		 "WHERE eid='$exp_id' and pid='$exp_pid'");
}

if ($formfields[exp_noidleswap_reason]) {
    DBQueryFatal("UPDATE experiments " .
		 "SET noidleswap_reason='" .
                 addslashes($formfields[exp_noidleswap_reason]).
                 "' ".
		 "WHERE eid='$exp_id' and pid='$exp_pid'");
}

883
884
echo "<br><br>";
echo "<font size=+1>
885
        Your experiment is configuring!<br><br>\n";
886

887
888
889
890
891
892
893
894
if ($nonsfile) {
    echo "Since you did not provide an NS script, no nodes have been
          allocated. You will not be able to modify or swap this experiment,
          nor do most other neat things you can do with a real experiment.
          <br><br>
          If this bothers you, <b>SUPPLY AN NS FILE!</b>\n";
}
elseif ($exp_preload) {
895
896
897
898
    echo "Since you are only pre-loading the experiment, this will typically
          take less than one minute. If you do not receive email notification
          within a reasonable amount of time, please contact $TBMAILADDR.<br>
          <br>
899
          While you are waiting, you can watch the log
900
901
902
          in <a target=_blank href=spewlogfile.php3?pid=$exp_pid&eid=$exp_id>
          realtime</a>.\n";
}
903
904
905
906
907
908
909
elseif ($exp_batched) {
    echo "Batch Mode experiments will be run when enough resources become
          available. This might happen immediately, or it may take hours
	  or days. You will be notified via email when the experiment has
          been run. If you do not receive email notification within a
          reasonable amount of time, please contact $TBMAILADDR.\n";
}
910
911
912
913
914
else {
    echo "You will be notified via email when the experiment has been fully
	  configured and you are able to proceed. This typically takes less
          than 10 minutes, depending on the number of nodes you have requested.
          If you do not receive email notification within a reasonable amount
915
916
917
          of time, please contact $TBMAILADDR.<br>
          <br>
          While you are waiting, you can watch the log of experiment creation
918
          in <a target=_blank href=spewlogfile.php3?pid=$exp_pid&eid=$exp_id>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
919
          realtime</a>.\n";
920
921
922
923
924
925
}
echo "<br>
      </font>\n";

#
# Standard Testbed Footer
926
#
927
928
PAGEFOOTER();
?>