beginexp.php3 28 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2
3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2004 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
#
# Remove this if we need to bring this page back.
#
header("Location: beginexp_html.php3?" . $_SERVER['QUERY_STRING']);
exit(0);

13
14
15
16
17
18
19
20
21
22
23
24
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);

25
$idleswaptimeout = TBGetSiteVar("idle/threshold");
26
27
28
29
30
31
32

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

34
35
36
37
38
39
40
    $errors[$tag] = $value;
    SPITFORM($formfields, $errors);
    PAGEFOOTER();
    die("");
}

#
41
42
# Spit the form out using the array of data.
#
43
44
function SPITFORM($formfields, $errors)
{
45
46
    global $TBDB_PIDLEN, $TBDB_GIDLEN, $TBDB_EIDLEN, $TBDOCBASE;
    global $nsdata, $nsref, $projlist, $exp_nsfile;
Chad Barb's avatar
   
Chad Barb committed
47
    global $uid, $guid;
48
    global $idleswaptimeout;
49
50
51
52
53
54
55
    global $view, $view_style;

    #
    # Handle pre-defined view styles
    #
    if ($view_style == "plab") {
	$view['hide_proj'] = $view['hide_group'] = $view['hide_swap'] =
56
57
	    $view['hide_preload'] = $view['hide_batch'] = $view['quiet'] =
	    $view['plab_ns_message'] = 1;
58
    }
59

60
61
62
    PAGEHEADER("Begin a Testbed Experiment");

    if ($errors) {
Chad Barb's avatar
   
Chad Barb committed
63
64
	echo "<table class=nogrid
                     align=center border=0 cellpadding=6 cellspacing=0>
65
              <tr>
Chad Barb's avatar
   
Chad Barb committed
66
                 <th align=center colspan=2>
67
                   <font size=+1 color=red>
Chad Barb's avatar
   
Chad Barb committed
68
                      &nbsp;Oops, please fix the following errors!&nbsp;
69
70
71
72
73
74
                   </font>
                 </td>
              </tr>\n";

	while (list ($name, $message) = each ($errors)) {
	    echo "<tr>
Chad Barb's avatar
   
Chad Barb committed
75
76
77
78
                     <td align=right>
                       <font color=red>$name:&nbsp;</font></td>
                     <td align=left>
                       <font color=red>$message</font></td>
79
80
81
82
                  </tr>\n";
	}
	echo "</table><br>\n";
    }
83
    else {
84
	    
85
86
	if (!isset($nsdata) && !isset($nsref) &&
	    !isset($view['quiet'])) {
87
88
89
90
91
92
93
94
95
	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
96
	} else {
97
98
99
100
101
102
103
104
	    if (isset($view['plab_ns_message'])) {
		echo "<p>To finish creating your slice, edit the following " .
		     "information if you wish, and click Submit.</p>\n";
	    } else {
		echo "<p><b>Your automatically generated NS file has been " .
		     "uploaded.</b> To finish creating your experiment, " .
		     "please fill out the following information:</p>";
	    }
Chad Barb's avatar
   
Chad Barb committed
105
        }
106
    }
107

108
109
    echo "<table align=center border=1>\n";
    echo "<form name='form1' enctype=multipart/form-data
110
111
                action=beginexp.php3 method=post>\n";

112
113
114
115
116
117
118
119
    #
    # Include view_style in a hidden field so that it gets preserved if there
    # are errors
    #
    if ($view_style) {
	echo "<input type='hidden' name='view_style' value='$view_style'>\n";
    }

120
121
122
    #
    # Select Project
    #
123
    if (isset($view['hide_proj']) && (count($projlist) == 1)) {
124
125
126
127
	# Just include the project as a hidden field - since the user has
	# only a single project, grab that project, which is the first thing
	# in $projlist
	list($project) = each($projlist);
128
129
130
131
132
	echo "<input type='hidden' name='formfields[exp_pid]' value='$project'>\n";
    } else {
	echo "<tr>
		  <td class='pad4'>Select Project:</td>
		  <td class='pad4'><select name=\"formfields[exp_pid]\">\n";
133

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

139
140
	while (list($project) = each($projlist)) {
	    $selected = "";
141

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

145
146
147
148
149
150
	    echo "        <option $selected value=\"$project\">
				 $project </option>\n";
	}
	echo "       </select>";
	echo "    </td>
	      </tr>\n";
151
152
    }

153
154
    #
    # Select a group
155
    #
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
    if (isset($view['hide_group'])) {
	if ($formfields['group']) {
	    $group = $formfields['group'];
	} else {
	    $group = "";
	}
	echo "<input type='hidden' name='formfields[exp_gid]' value='$group'>\n";
    } else {
	echo "<tr>
		  <td class='pad4'>Group:</td>
		  <td class='pad4'><select name=\"formfields[exp_gid]\">
			<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";

		    echo "<option $selected value=\"$group\">
			       $project/$group</option>\n";
		}
186
187
	    }
	}
188
189
190
191
192
	echo "     </select>
	      <font size=-1>(Must be default or correspond to selected project)
	      </font>
		 </td>
	      </tr>\n";
193
194
    }

195
196
197
198
    #
    # Name:
    #
    echo "<tr>
199
              <td class='pad4'>Name:
200
201
              <br><font size='-1'>(No blanks)</font></td>
              <td class='pad4' class=left>
202
203
204
205
206
207
208
209
210
211
212
213
                  <input type=text
                         name=\"formfields[exp_id]\"
                         value=\"" . $formfields[exp_id] . "\"
	                 size=$TBDB_EIDLEN
                         maxlength=$TBDB_EIDLEN>
              </td>
          </tr>\n";

    #
    # Description
    #
    echo "<tr>
214
              <td class='pad4'>Description:<br>
215
216
                  <font size='-1'>(A concise sentence)</font></td>
              <td class='pad4' class=left>
217
218
219
                  <input type=text
                         name=\"formfields[exp_description]\"
                         value=\"" . $formfields[exp_description] . "\"
220
	                 size=60>
221
222
223
224
225
226
227
228
              </td>
          </tr>\n";

    #
    # NS file
    #
    if (isset($nsdata)) {
        echo "<tr>
229
                  <td class='pad4'>Your auto-generated NS file: &nbsp</td>
230
                      <input type=hidden name=nsdata value=$nsdata>
231
                  <td class='pad4'><a target=_blank href=spitnsdata.php3?nsdata=$nsdata>
232
233
                      View NS File</a></td>
              </tr>\n";
Chad Barb's avatar
   
Chad Barb committed
234
    } elseif (isset($nsref)) {
Chad Barb's avatar
   
Chad Barb committed
235
236
	if (isset($guid)) {
        echo "<tr>
237
                  <td class='pad4'>Your auto-generated NS file: &nbsp</td>
Chad Barb's avatar
   
Chad Barb committed
238
239
                      <input type=hidden name=nsref value=$nsref>
                      <input type=hidden name=guid value=$guid>
240
                  <td class='pad4'><a target=_blank href=\"spitnsdata.php3?nsref=$nsref&guid=$guid\">
Chad Barb's avatar
   
Chad Barb committed
241
242
243
                      View NS File</a></td>
              </tr>\n";
        } else {
Chad Barb's avatar
   
Chad Barb committed
244
        echo "<tr>
245
                  <td class='pad4'>Your auto-generated NS file: &nbsp</td>
Chad Barb's avatar
   
Chad Barb committed
246
                      <input type=hidden name=nsref value=$nsref>
247
                  <td class='pad4'><a target=_blank href=spitnsdata.php3?nsref=$nsref>
Chad Barb's avatar
   
Chad Barb committed
248
249
                      View NS File</a></td>
              </tr>\n";
Chad Barb's avatar
   
Chad Barb committed
250
        }
251
252
    }
    else {
253

254
	echo "<tr>
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
                  <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>
272
273
274
275
276
277
278
279
280
281

                  <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 . "\"
282
283
	                       size=30
			       onchange=\"this.form.syntax.disabled=(this.value=='')\">
284
285
286
287
288
289
290
291
292
293
                      </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] . "\"
294
295
	                       size=40
			       onchange=\"this.form.syntax.disabled=(this.value=='')\">
296
297
                      </td>
                    </tr></table></td></tr>\n";
298
299
    }

300
301
302
    #
    # Swapping
    #
303
    # Add in hidden fields to send swappable and noswap_reason, since
304
    # they do not show on the form
305
306
    echo "<input type=hidden name='formfields[exp_swappable]' value='$formfields[exp_swappable]'>\n";
    echo "<input type=hidden name='formfields[exp_noswap_reason]' value='";
307
    echo htmlspecialchars($formfields[exp_noswap_reason], ENT_QUOTES);
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
    echo "'>\n";
    if (isset($view['hide_swap'])) {
	$idlevars = array('exp_idleswap','exp_noidleswap_reason','exp_idleswap_timeout',
	                  'exp_autoswap','exp_autoswap_timeout');
	while (list($index,$value) = each($idlevars)) {
	    if (isset($formfields[$value])) {
		echo "<input type='hidden' name='formfields[$value]' value='$formfields[$value]'>\n";
	    }
	}

    } else {
	echo "<tr>
		  <td class='pad4'>
		    <a href='$TBDOCBASE/docwrapper.php3?docname=swapping.html#swapping'>
		    Swapping:</td>
		  <td>
		  <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'";
	}
	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>";
363
    }
364
365
366
367

    #
    # Batch Experiment?
    #
368
369
370
    if (isset($view['hide_batch'])) {
	if ($formfields['exp_batched']) {
	    echo "<input type='hidden' name='formfields[exp_batched]' value='Yep'\n";
371
	}
372
373
374
375
    } else {
	echo "<tr>
		  <td class='pad4' colspan=2>
		  <input type=checkbox name='formfields[exp_batched]' value='Yep'";
376

377
378
379
380
381
382
383
384
385
386
387
388
389
	if (isset($formfields[exp_batched]) &&
	    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>
	      </tr>\n";
    }
390

391
392
393
    #
    # Preload?
    #
394
395
396
    if (isset($view['hide_preload'])) { 
	if ($formfields['exp_preload']) {
	    echo "<input type='hidden' name='formfields[exp_preload]' value='Yep'>\n";
397
	}
398
399
400
401
    } else {
	echo "<tr>
		  <td class='pad4' colspan=2>
		      <input type=checkbox name='formfields[exp_preload]' value='Yep'";
402

403
404
405
406
407
408
409
410
411
	if (isset($formfields[exp_preload]) &&
	    strcmp($formfields[exp_preload], "Yep") == 0) {
		echo " checked='1'";
	    }

	echo ">\n";
	echo "Do Not Swap In</td>
	      </tr>\n";
    }
412
413

    echo "<tr>
414
              <td class='pad4' align=center colspan=2>
415
416
                 <b><input type=submit value=Submit name=submit
			onclick='NormalSubmit()'></b></td>
417
418
419
420
         </tr>
        </form>
        </table>\n";

421
422
423
424
425
426
427
428
429
430
    if (!isset($view['quiet'])) {
	echo "<p>
	      <h3>Handy Links:</h3>
	      <ul>
		 <li> View a <a href='showosid_list.php3'>list of OSIDs</a>
		      that are available for you to use in your NS file.</li>
		 <li> Create your own <a href='newimageid_ez.php3'>
		      custom disk images</a>.</li>
	      </ul>\n";
    }
431
432
}

Chad Barb's avatar
   
Chad Barb committed
433
434
435
436
437
if (isset($nsref)) {
    if (strcmp($nsref, "") == 0 || !ereg("^[0-9]+$", $nsref))
	unset($nsref);
}

Chad Barb's avatar
   
Chad Barb committed
438
439
440
441
442
if (isset($guid)) {
    if (strcmp($guid, "") == 0 || !ereg("^[0-9]+$", $guid))
	unset($guid);
}

443
444
445
446
447
448
#
# 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
449

450
if (isset($nsdata)) {
451
    if (strcmp($nsdata, "") == 0)
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
	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.
#
470
if (! isset($submit) && ! isset($syntax)) {
471
472
    $defaults = array();

473
474
475
476
    #
    # 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.
477
    #
478
479
    if (count($projlist) == 1) {
	list($project, $grouplist) = each($projlist);
480

481
	if (count($grouplist) <= 2) {
482
	    $defaults[exp_pid] = $project;
483
	    if (count($grouplist) == 1 || strcmp($project, $grouplist[0]))
484
485
486
487
488
489
		$defaults[exp_gid] = $grouplist[0];
	    else
		$defaults[exp_gid] = $grouplist[1];
	}
	reset($projlist);
    }
490
491
492
493
494
495
496
497
498

    $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";

499
500
501
502
503
504
505
506
507
    #
    # Allow formfields that are already set to override defaults
    #
    if (isset($formfields)) {
	while (list ($field, $value) = each ($formfields)) {
	    $defaults[$field] = $formfields[$field];
	}
    }

508
509
510
511
512
513
514
515
516
517
518
519
    SPITFORM($defaults, 0);
    PAGEFOOTER();
    return;
}

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

#
# Project:
520
#
521
522
523
524
525
526
527
528
529
530
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.
531
#
532
533
534
535
536
if (!isset($formfields[exp_id]) ||
    strcmp($formfields[exp_id], "") == 0) {
    $errors["Experiment Name"] = "Missing Field";
}
else {
537
538
539
    if (! ereg("^[-a-zA-Z0-9]+$", $formfields[exp_id])) {
	$errors["Experiment Name"] =
	    "Must be alphanumeric characters only (dash okay)!";
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
    }
    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
557
# Any of these which are not "1" become "0".
558
#
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
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";
    }
607
608
}

609
610
611
# None of the above errors count during a syntax check
if (isset($syntax)) { $errors = array(); }

612
613
614
#
# If any errors, respit the form with the current values and the
# error messages displayed. Iterate until happy.
615
#
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
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.
#
635
if (TBValidExperiment($exp_pid, $exp_id) && !isset($syntax)) {
636
637
638
639
640
641
642
643
644
645
    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;
}
646
if (!TBValidGroup($exp_pid, $exp_gid) && !isset($syntax)) {
Chad Barb's avatar
   
Chad Barb committed
647
    RESPIT("Group", "Group '$exp_gid' is not in project '$exp_pid'!");
648
649
650
651
652
}

#
# Verify permissions.
#
653
654
if (! TBProjAccessCheck($uid, $exp_pid, $exp_gid, $TB_PROJECT_CREATEEXPT)
    && !isset($syntax)) {
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
    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) {
674
675
676
677
678
679
680
    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");
    }
681
682
683
684
685
}
if (!$specupload && strcmp($exp_nsfile_name, "")) {
    #
    # Catch an invalid filename.
    #
686
687
688
689
690
691
692
    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");
    }
693
694
695
696
697
698
699
700
701
}

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.
    #
702
    # Do not allow anything outside of special dirs. I do not think there
703
704
    # is a security worry, but good to enforce it anyway.
    #
705
706
707
708
709
710
711
712
713
714
    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");
	}
    }
715
    if (! ereg("^$TBPROJ_DIR/.*" ,$exp_localnsfile) &&
716
717
        ! ereg("^$TBUSER_DIR/.*" ,$exp_localnsfile) &&
        ! ereg("^$TBGROUP_DIR/.*" ,$exp_localnsfile)) {
718
719
720
721
722
723
724
725
726
727
	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/");
	}
728
    }
729

730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
    $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
745
elseif (isset($nsref) && strcmp($nsref, "")) {
Chad Barb's avatar
   
Chad Barb committed
746
747
748
749
750
    if (isset($guid)) {
      $nsfile = "/tmp/$guid-$nsref.nsfile";
    } else {
      $nsfile = "/tmp/$uid-$nsref.nsfile";
    }
Chad Barb's avatar
   
Chad Barb committed
751
752
753
    $delnsfile = 1;
    $nonsfile  = 0;
}
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
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);
770
    chmod($nsfile, 0666);
771
772
773
}
else {
    #
774
775
    # I am going to allow shell experiments to be created (No NS file),
    # but only by admin types.
776
    #
777
778
779
780
781
782
783
784
    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");
	}
785
786
    }
    $nonsfile = 1;
787
788
}

789
790
791
792
793
794
795
796
797
798
799
800
#
# 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.
    #
801
802
    $retval = SUEXEC($uid, $TBADMINGROUP, "webnscheck $nsfile",
		     SUEXEC_ACTION_IGNORE);
803
804
805
806
807
808
809

    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";

810
    if ($retval < 0) {
811
812
813
814
815
	SUEXECERROR(SUEXEC_ACTION_DIE);
        #
        # Never returns ...
        #
        die("");
816
817
    }

818
819
820
821
822
823
824
825
826
827
828
    # Parse Error.	 
    if ($retval) {
	echo "<br><br><h2>
              Parse Failure($retval): Output as follows:
              </h2>
              <br>
              <XMP>$suexec_output</XMP>\n";
	PAGEFOOTER();
	die("");
    }

829
830
831
832
833
834
835
836
    echo "<center><br>";
    echo "<br>";
    echo "<h3>Your NS file looks good!</h3>";
    echo "</center>\n";
    
    exit();
}

837
#
838
# Convert Swappable, Batched params to arguments to script.
839
#
840
841
842
843
$exp_swappable = "";

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

846
847
if ($formfields[exp_autoswap] == "1") {
    $exp_swappable .= " -a " . (60 * $formfields[exp_autoswap_timeout]);
848
}
849
850

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

854
855
856
857
#
# All experiments are low priority for now.
#
$exp_priority  = "-n low";
858
859
860
$exp_batched   = 0;
$exp_preload   = 0;
$batcharg      = "-i";
861

862
863
864
865
if (isset($formfields[exp_batched]) &&
    strcmp($formfields[exp_batched], "Yep") == 0) {
    $exp_batched   = 1;
    $batcharg      = "";
866
867
868
869
870
}
if (isset($formfields[exp_preload]) &&
    strcmp($formfields[exp_preload], "Yep") == 0) {
    $exp_preload   = 1;
    $batcharg     .= " -f";
871
872
}

873
#
874
# I am not spitting out a redirection yet.
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
#
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);

#
892
893
# Okay, time to do it.
#
894
895
896
897
898
899
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";

900
901
902
903
904
905
906
echo "<center><br>";
echo "<h2>Starting experiment configuration. Please wait a moment ...
      </h2></center>";

flush();

#
907
# Run the backend script.
908
909
#
# Avoid SIGPROF in child.
910
#
911
912
set_time_limit(0);

913
914
915
916
917
918
$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);
919
920
921
922
923

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

924
925
926
927
#
# 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
928
if ($retval < 0) {
929
930
931
932
    SUEXECERROR(SUEXEC_ACTION_DIE);
    #
    # Never returns ...
    #
933
934
935
    die("");
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
936
937
938
939
940
941
942
943
944
945
# 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();
}

946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
# 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'");
}

964
965
echo "<br><br>";
echo "<font size=+1>
966
        Your experiment is configuring!<br><br>\n";
967

968
969
970
971
972
973
974
975
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) {
976
977
978
979
    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>
980
          While you are waiting, you can watch the log
981
982
983
          in <a target=_blank href=spewlogfile.php3?pid=$exp_pid&eid=$exp_id>
          realtime</a>.\n";
}
984
985
986
987
988
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
989
990
991
992
993
994
          reasonable amount of time, please contact $TBMAILADDR.
          <br>
          <br>
          While you are waiting, you can watch the log of start attempts
          in <a target=_blank href=spewlogfile.php3?pid=$exp_pid&eid=$exp_id>
          realtime</a>.\n";
995
}
996
997
998
999
1000
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
1001
1002
1003
          of time, please contact $TBMAILADDR.<br>
          <br>
          While you are waiting, you can watch the log of experiment creation
1004
          in <a target=_blank href=spewlogfile.php3?pid=$exp_pid&eid=$exp_id>
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1005
          realtime</a>.\n";
1006
1007
1008
1009
1010
1011
}
echo "<br>
      </font>\n";

#
# Standard Testbed Footer
1012
#
1013
1014
PAGEFOOTER();
?>