beginexp_form.php3 20.1 KB
Newer Older
1
2
<?php
#
3
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23
24
25
26
27
28
29
#

#
# Display a virgin form and exit.
# 
function INITFORM($formfields, $projlist)
{
30
    global $nsref, $guid, $copyid;
31
32
33
    
    $defaults = array();

34
35
36
37
38
39
    # These defaults possibly set below.
    $defaults["exp_pid"]          = "";
    $defaults["exp_gid"]          = "";
    $defaults["exp_id"]           = "";
    $defaults["exp_description"]  = "";

40
    #
41
    # This is for experiment copying ...
42
    #
43
44
    if (isset($copyid) && $copyid != "") {
	$defaults["copyid"] = $copyid;
45
    }
46
47
48
49
50
51
52
53
54
    else {
	unset($copyid);

        #
        # This stuff is here for netbuild. The initial post from netbuild will
        # include these; they point to the nsfile. The right approach for doing
        # this is to have another page for netbuild that does some magic and
        # redirects the browser to this page. 
        #
Mike Hibler's avatar
Mike Hibler committed
55
	if (isset($nsref) && $nsref != "" && preg_match('/^[0-9]+$/', $nsref))
56
	    $defaults["nsref"] = $nsref;
57
	else
58
59
	    unset($nsref);
	
Mike Hibler's avatar
Mike Hibler committed
60
	if (isset($guid) && $guid != "" && preg_match('/^[0-9]+$/', $guid))
61
	    $defaults["guid"] = $guid;
62
63
	else
	    unset($guid);
64
    }
65
    
66
67
68
69
70
71
72
73
74
    #
    # 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.
    #
    if (count($projlist) == 1) {
	list($project, $grouplist) = each($projlist);

	if (count($grouplist) <= 2) {
75
	    $defaults["exp_pid"] = $project;
76
	    if (count($grouplist) == 1 || strcmp($project, $grouplist[0]))
77
		$defaults["exp_gid"] = $grouplist[0];
78
	    else
79
		$defaults["exp_gid"] = $grouplist[1];
80
81
82
83
	}
	reset($projlist);
    }

84
85
86
87
88
89
90
91
92
93
94
95
96
    $defaults["exp_swappable"]         = "1";
    $defaults["exp_noswap_reason"]     = "";
    $defaults["exp_idleswap"]          = "1";
    $defaults["exp_noidleswap_reason"] = "";
    $defaults["exp_idleswap_timeout"]  = TBGetSiteVar("idle/threshold");
    $defaults["exp_autoswap"]          = TBGetSiteVar("general/autoswap_mode");
    $defaults["exp_autoswap_timeout"]  = TBGetSiteVar("general/autoswap_threshold");
    $defaults["exp_localnsfile"]       = "";
    $defaults["exp_nsfile"]            = ""; # Multipart data.
    $defaults["exp_preload"]           = "no";
    $defaults["exp_batched"]           = "no";
    $defaults["exp_linktest"]          = 3;
    $defaults["exp_savedisk"]          = "no";
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

    #
    # Allow formfields that are already set to override defaults
    #
    if (isset($formfields)) {
	while (list ($field, $value) = each ($formfields)) {
	    $defaults[$field] = $formfields[$field];
	}
    }

    SPITFORM($defaults, 0);
    return;
}

#
# Spit the form out using the array of data.
#
function SPITFORM($formfields, $errors)
{
    global $TBDB_PIDLEN, $TBDB_GIDLEN, $TBDB_EIDLEN, $TBDOCBASE;
117
    global $view, $view_style, $projlist, $linktest_levels;
118
    global $EXPOSELINKTEST, $EXPOSEARCHIVE;
119
    global $EXPOSESTATESAVE;
120
    global $TBVALIDDIRS_HTML;
121
    global $WIKIDOCURL, $WIKINODE;
122

123
    PAGEHEADER("Begin a Testbed Experiment");
124
125
126
127
128
129
130
131

    echo "<script language=JavaScript>
          <!--
          function NormalSubmit() {
              document.form1.target='_self';
              document.form1.submit();
          }
          function SyntaxCheck() {
Timothy Stack's avatar
   
Timothy Stack committed
132
              window.open('','nscheck','width=650,height=400,toolbar=no,".
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
	                      "resizeable=yes,scrollbars=yes,status=yes,".
	                      "menubar=yes');
              var action = document.form1.action;
              var target = document.form1.target;

              document.form1.action='nscheck.php3';
              document.form1.target='nscheck';
              document.form1.submit();

              document.form1.action=action;
              document.form1.target=target;
          }
          //-->
          </script>\n";

    if ($errors) {
	echo "<table class=nogrid
                     align=center border=0 cellpadding=6 cellspacing=0>
              <tr>
                 <th align=center colspan=2>
                   <font size=+1 color=red>
                      &nbsp;Oops, please fix the following errors!&nbsp;
                   </font>
                 </td>
              </tr>\n";

	while (list ($name, $message) = each ($errors)) {
160
161
            # XSS prevention.
	    $message = CleanString($message);
162
163
164
165
166
167
168
169
170
171
	    echo "<tr>
                     <td align=right>
                       <font color=red>$name:&nbsp;</font></td>
                     <td align=left>
                       <font color=red>$message</font></td>
                  </tr>\n";
	}
	echo "</table><br>\n";
    }
    else {
172
       if (! isset($formfields['copyid'])) {
173
	if (!isset($formfields['nsref']) && !isset($view['quiet'])) {
174
175
176
177
          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>
178
179
180
181
182
              <b><a href='clientui.php3'>New GUI editor</a></b> -
                An enhanced Java applet for editing topologies.
              (<b><a href='clientui-alt.php3'>ProtoGeni Version</a></b> -
                <a href='http://$WIKINODE/trac/protogeni/wiki'>
                  What's ProtoGeni?</a>)<br>
183
184
185
              The older <b><a href='buildui/bui.php3'>NetBuild GUI</a></b>
              can be used to graphically create topologies.<font size=-2>
              (<a href='$TBDOCBASE/faq.php3#netbuild'>Additional 
186
187
188
189
190
191
              information</a>)</font>.";
          #echo "<br>
          #    Or, you can download the Emulab
          #    <a href='netlab/client.php3'><b>client</b></a> and graphically
          #    create one from your desktop.
          echo "</ul></p><br>";
192
193
	} else {
	    if (isset($view['plab_ns_message'])) {
Kirk Webb's avatar
   
Kirk Webb committed
194
195
196
197
		echo "<center>
                        <p><b>To finish creating your slice, edit the 
                              following information as needed, and click 
                              Submit.  PlanetLab <font size=+1 color=red>  
Kirk Webb's avatar
   
Kirk Webb committed
198
                              requires</font>  users
Kirk Webb's avatar
   
Kirk Webb committed
199
                              to provide detail on what their slice will
Jay Lepreau's avatar
Jay Lepreau committed
200
                              be doing via its description (i.e., what kind 
Kirk Webb's avatar
   
Kirk Webb committed
201
                              of network traffic it will be producing).
Kirk Webb's avatar
   
Kirk Webb committed
202
                              Be sure to read over the
Jay Lepreau's avatar
Jay Lepreau committed
203
                              <a href='http://www.planet-lab.org/php/aup/'>
Kirk Webb's avatar
   
Kirk Webb committed
204
                              PlanetLab AUP</a> if you haven't already.
Kirk Webb's avatar
   
Kirk Webb committed
205
206
                       </b></p>
                      </center>\n";
207
208
209
210
211
212
	    } 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>";
	    }
        }
213
       }
214
    }
215
216
217
218
    # XSS prevention.
    while (list ($key, $val) = each ($formfields)) {
	$formfields[$key] = CleanString($val);
    }
219
220
221

    echo "<form name=form1 enctype=multipart/form-data
                onsubmit=\"return false;\"
222
                action=beginexp.php method=post>\n";
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
    # Something funky going on ...
    echo "<input type=hidden name=beginexp value=Submit>\n";
    echo "<table align=center border=1>\n";

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

    #
    # Select Project
    #
    if (isset($view['hide_proj']) && (count($projlist) == 1)) {
	# 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);
	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";

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

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

258
	    if (strcmp($formfields["exp_pid"], $project) == 0)
259
260
261
262
263
264
265
266
267
268
269
270
271
272
		$selected = "selected";

	    echo "        <option $selected value=\"$project\">
				 $project </option>\n";
	}
	echo "       </select>";
	echo "    </td>
	      </tr>\n";
    }

    #
    # Select a group
    #
    if (isset($view['hide_group'])) {
273
	if (isset($formfields['group'])) {
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
	    $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 = "";

294
295
296
297
		    if (isset($formfields["exp_gid"]) &&
			isset($formfields["exp_pid"]) &&
			strcmp($formfields["exp_pid"], $project) == 0 &&
			strcmp($formfields["exp_gid"], $group) == 0)
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
			$selected = "selected";

		    echo "<option $selected value=\"$group\">
			       $project/$group</option>\n";
		}
	    }
	}
	echo "     </select>
	      <font size=-1>(Must be default or correspond to selected project)
	      </font>
		 </td>
	      </tr>\n";
    }

    #
    # Name:
    #
    echo "<tr>
              <td class='pad4'>Name:
              <br><font size='-1'>(No blanks)</font></td>
              <td class='pad4' class=left>
                  <input type=text
                         name=\"formfields[exp_id]\"
321
                         value=\"" . $formfields['exp_id'] . "\"
322
323
324
325
326
327
328
329
	                 size=$TBDB_EIDLEN
                         maxlength=$TBDB_EIDLEN>
              </td>
          </tr>\n";

    #
    # Description
    #
330
    if (isset($view["plab_descr"])) {
Kirk Webb's avatar
   
Kirk Webb committed
331
332
333
334
335
336
          echo "<tr>
                    <td class='pad4'>Slice Description:<br>
                        <font size='-1'>(Please be detailed)</font></td>
                    <td class='pad4' class=left>
                        <textarea
                               name=\"formfields[exp_description]\"
337
338
339
	                       rows=5 cols=50>" .
	                       $formfields['exp_description'] .
                       "</textarea>
Kirk Webb's avatar
   
Kirk Webb committed
340
341
342
343
344
345
346
347
348
                    </td>
                </tr>\n";
    } else {
          echo "<tr>
                    <td class='pad4'>Description:<br>
                        <font size='-1'>(A concise sentence)</font></td>
                    <td class='pad4' class=left>
                        <input type=text
                               name=\"formfields[exp_description]\"
349
                               value=\"" . $formfields['exp_description'] . "\"
Kirk Webb's avatar
   
Kirk Webb committed
350
351
352
353
	                       size=60>
                    </td>
                </tr>\n";
    }
354
355
356
357

    #
    # NS file
    #
358
359
360
361
    if (isset($formfields['copyid'])) {
	$copyid = $formfields['copyid'];

	echo "<tr>
362
               <td class='pad4'>Copy of experiment $copyid: &nbsp</td>
363
364
               <td class='pad4'>
                   <a target=nsfile href=spitnsdata.php3?copyid=$copyid>
365
                      Click for NS File</a>\n";
366
367

        echo "  </td>
368
369
370
                <input type=hidden name=\"formfields[copyid]\" value='$copyid'>
              </tr>\n";
    }
371
372
    elseif (isset($formfields['nsref'])) {
	$nsref = $formfields['nsref'];
373
	
374
375
	if (isset($formfields['guid'])) {
	    $guid = $formfields['guid'];
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
	    
	    echo "<tr>
                  <td class='pad4'>Your auto-generated NS file: &nbsp</td>
                      <input type=hidden name=\"formfields[nsref]\" value=$nsref>
                      <input type=hidden name=\"formfields[guid]\" value=$guid>
                  <td class='pad4'>
                      <a target=_blank
                                href=\"spitnsdata.php3?nsref=$nsref&guid=$guid\">
                      View NS File</a></td>
                  </tr>\n";
        }
	else {
	    echo "<tr>
                   <td class='pad4'>Your auto-generated NS file: &nbsp</td>
                       <input type=hidden name=\"formfields[nsref]\"
                              value=$nsref>
                   <td class='pad4'>
                       <a target=_blank href=spitnsdata.php3?nsref=$nsref>
                       View NS File</a></td>
                 </tr>\n";
        }
    }
    else {
	echo "<tr>
                  <td class='pad4'>Your NS file:<br>
		      <input type=submit disabled id=syntax name=syntax value='Syntax Check' onclick=\"SyntaxCheck();\">
  		  </td>

                  <td><table cellspacing=0 cellpadding=0 border=0>
                    <tr>
                      <td class='pad4'>Upload<br>
407
			<font size='-1'>(500k&nbsp;max)</font></td>
408
                      <td class='pad4'>
409
                        <input type=hidden name=MAX_FILE_SIZE value=512000>
410
411
	                <input type=file
                               name=exp_nsfile
412
                               value=\"" . $formfields['exp_nsfile'] . "\"
413
414
415
416
417
418
419
	                       size=30
			       onchange=\"this.form.syntax.disabled=(this.value=='')\">
                      </td>
                    </tr><tr>
                    <td>&nbsp;&nbsp;<b>or</b></td><td></td>
                    </tr><tr>
                      <td class='pad4'>On Server<br>
420
421
                              <font size='-1'>(" . $TBVALIDDIRS_HTML .
	    		      ")</font></td>
422
423
424
                      <td class='pad4'>
	                <input type=text
                               name=\"formfields[exp_localnsfile]\"
425
                               value=\"" . $formfields['exp_localnsfile'] . "\"
426
427
428
429
430
431
432
433
434
435
436
437
	                       size=40
			       onchange=\"this.form.syntax.disabled=(this.value=='')\">
                      </td>
                    </tr></table></td></tr>\n";
    }

    #
    # Swapping
    #
    # Add in hidden fields to send swappable and noswap_reason, since
    # they do not show on the form
    echo "<input type=hidden name=\"formfields[exp_swappable]\"
438
                 value='" . $formfields['exp_swappable'] . "'>\n";
439
    echo "<input type=hidden name=\"formfields[exp_noswap_reason]\" value='";
440
    echo htmlspecialchars($formfields['exp_noswap_reason'], ENT_QUOTES);
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
    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'>
457
		    <a href='$WIKIDOCURL/Swapping#swapping'>
458
459
460
461
462
463
		    Swapping:</td>
		  <td>
		  <table cellpadding=0 cellspacing=0 border=0><tr>
		  <td><input type='checkbox'
			 name='formfields[exp_idleswap]'
			 value='1'";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
464
465
	if (isset($formfields['exp_idleswap']) &&
	    $formfields['exp_idleswap'] == "1") {
466
467
468
	    echo " checked='1'";
	}
	echo "></td>
469
		  <td><a href='$WIKIDOCURL/Swapping#idleswap'>
470
471
472
473
		  <b>Idle-Swap:</b></a> Swap out this experiment
		  after 
		  <input type='text' name='formfields[exp_idleswap_timeout]'
			 value='";
474
	echo htmlspecialchars($formfields['exp_idleswap_timeout'], ENT_QUOTES);
475
476
477
478
479
480
	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]'>";
			      
481
	echo htmlspecialchars($formfields['exp_noidleswap_reason'],ENT_QUOTES);
482
483
484
485
486
	echo "</textarea></td>
		  </tr><tr>
		  <td><input type='checkbox'
			 name='formfields[exp_autoswap]'
			 value='1' ";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
487
488
	if (isset($formfields['exp_autoswap']) &&
	    $formfields['exp_autoswap'] == "1") {
489
490
491
	    echo " checked='1'";
	}
	echo "></td>
492
		  <td><a href='$WIKIDOCURL/Swapping#autoswap'>
493
494
495
		  <b>Max. Duration:</b></a> Swap out after
		  <input type='text' name='formfields[exp_autoswap_timeout]'
			 value='";
496
	echo htmlspecialchars($formfields['exp_autoswap_timeout'], ENT_QUOTES);
497
	echo "' size='3'> hours, even if not idle.</td>
498
499
500
501
502
503
504
		  </tr>";

	if (STUDLY() || $EXPOSESTATESAVE) {
	    echo "<tr><td>
	         <input type=checkbox name='formfields[exp_savedisk]'
	         value='Yep'";

505
506
	    if (isset($formfields['exp_savedisk']) &&
		strcmp($formfields['exp_savedisk'], "Yep") == 0) {
507
508
509
510
		    echo " checked='1'";
	    }

	    echo "></td>\n";
511
	    echo "<td><a href='$WIKIDOCURL/Swapping#swapstatesave'>
512
513
514
515
		  <b>State Saving:</b></a> Save disk state on swapout</td>
		  </tr>";
	}
	echo "</table></td></tr>";
516
517
    }

518
519
520
    #
    # Run linktest, and level. 
    #
521
    if (STUDLY() || $EXPOSELINKTEST) {
Kirk Webb's avatar
   
Kirk Webb committed
522
      if (isset($view['hide_linktest'])) {
523
        if ($formfields['exp_linktest']) {
Kirk Webb's avatar
   
Kirk Webb committed
524
          echo "<input type='hidden' name='formfields[exp_linktest]'
525
                       value='" . $formfields['exp_linktest'] . "'\n";
Kirk Webb's avatar
   
Kirk Webb committed
526
527
        }
      } else {
528
    echo "<tr>
529
              <td><a href='$WIKIDOCURL/linktest'>Linktest</a> Option:</td>
530
531
532
533
534
535
              <td><select name=\"formfields[exp_linktest]\">
                          <option value=0>Skip Linktest </option>\n";

    for ($i = 1; $i <= TBDB_LINKTEST_MAX; $i++) {
	$selected = "";

536
	if (strcmp($formfields['exp_linktest'], "$i") == 0)
537
538
539
540
541
542
	    $selected = "selected";
	
	echo "        <option $selected value=$i>Level $i - " .
	    $linktest_levels[$i] . "</option>\n";
    }
    echo "       </select>";
543
    echo "    (<a href='$WIKIDOCURL/linktest'><b>What is this?</b></a>)";
544
545
    echo "    </td>
          </tr>\n";
Kirk Webb's avatar
   
Kirk Webb committed
546
      }
547
    }
548

549
550
551
552
553
554
    #
    # Batch Experiment?
    #
    if (isset($view['hide_batch'])) {
	if ($formfields['exp_batched']) {
	    echo "<input type='hidden' name='formfields[exp_batched]'
555
                         value='" . $formfields['exp_batched'] . "'\n";
556
557
558
559
560
561
562
	}
    } else {
	echo "<tr>
		  <td class='pad4' colspan=2>
		  <input type=checkbox name='formfields[exp_batched]'
                         value='Yep'";

563
564
	if (isset($formfields['exp_batched']) &&
	    strcmp($formfields['exp_batched'], "Yep") == 0) {
565
566
567
568
569
570
		echo " checked='1'";
	    }

	echo ">\n";
	echo "Batch Mode Experiment &nbsp;
	      <font size='-1'>(See
571
	      <a href='$WIKIDOCURL/Tutorial'>Tutorial</a>
572
573
574
575
576
577
578
579
580
581
582
	      for more information)</font>
	      </td>
	      </tr>\n";
    }

    #
    # Preload?
    #
    if (isset($view['hide_preload'])) { 
	if ($formfields['exp_preload']) {
	    echo "<input type='hidden' name='formfields[exp_preload]'
583
                         value='" . $formfields['exp_preload'] . "'>\n";
584
585
586
587
588
589
590
	}
    } else {
	echo "<tr>
		  <td class='pad4' colspan=2>
		      <input type=checkbox name='formfields[exp_preload]'
                             value='Yep'";

591
592
	if (isset($formfields['exp_preload']) &&
	    strcmp($formfields['exp_preload'], "Yep") == 0) {
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
		echo " checked='1'";
	    }

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

    echo "<tr>
              <td class='pad4' align=center colspan=2>
                 <b><input type=button value=Submit name=beginexp
                           onclick=\"NormalSubmit();\"></b>
              </td>
         </tr>
        </form>
        </table>\n";

    if (!isset($view['quiet'])) {
	echo "<p>
	      <h3>Handy Links:</h3>
	      <ul>
614
                  <li> View a <a href='showimageid_list.php3' target='_blank'>list
615
616
                      of OSIDs</a> that are available for you to use in your NS
                      file.</li>
617
618
619
620
621
622
		 <li> Create your own <a href='newimageid_ez.php3'>
		      custom disk images</a>.</li>
	      </ul>\n";
    }
}
?>