editexp.php3 15.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
#
include("defs.php3");

#
# No PAGEHEADER since we spit out a Location header later. See below.
28
#
29 30 31 32

#
# Only known and logged in users can end experiments.
#
33 34 35
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
36
$idleswaptimeout = TBGetSiteVar("idle/threshold");
37
$autoswap_max    = TBGetSiteVar("general/autoswap_max");
38 39 40

#
# Verify page arguments.
41
#
42 43 44
$reqargs = RequiredPageArguments("experiment", PAGEARG_EXPERIMENT);
$optargs = OptionalPageArguments("submit",     PAGEARG_STRING,
				 "formfields", PAGEARG_ARRAY);
45

46 47 48 49
# Need below
$pid = $experiment->pid();
$eid = $experiment->eid();

50 51 52
#
# Verify Permission.
#
53
if (! $experiment->AccessCheck($this_user, $TB_EXPT_MODIFY)) {
54 55 56 57
    USERERROR("You do not have permission to modify experiment $pid/$eid!", 1);
}

#
58 59
# Spit the form out using the array of data.
#
60
function SPITFORM($experiment, $formfields, $errors)
61
{
62
    global $isadmin, $TBDOCBASE, $linktest_levels, $EXPOSELINKTEST;
63
    global $WIKIDOCURL, $TBMAILADDR;
64
    global $autoswap_max;
65

66 67 68
    #
    # Standard Testbed Header
    #
69
    PAGEHEADER("Edit Experiment Settings");
70

71
    echo $experiment->PageHeader();
72 73 74 75 76 77 78 79 80 81 82 83 84 85
    echo "<br><br>\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)) {
86 87
            # XSS prevention.
	    $message = CleanString($message);
88 89 90 91 92 93 94 95 96
	    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";
    }
97 98 99 100
    # XSS prevention.
    while (list ($key, $val) = each ($formfields)) {
	$formfields[$key] = CleanString($val);
    }
101

102
    $url = CreateURL("editexp", $experiment);
103
    echo "<table align=center border=1>
104
          <form action='$url' method=post>\n";
105 106 107 108 109 110

    echo "<tr>
             <td>Description:</td>
             <td class=left>
                 <input type=text
                        name=\"formfields[description]\"
111
                        value='" . $formfields['description'] . "'
112 113 114 115 116 117
	                size=30>
             </td>
          </tr>\n";

    #
    # Swapping goo.
118
    #
119
    $swaplink = "$WIKIDOCURL/Swapping";
120 121 122 123 124 125 126

    echo "<tr>
	      <td class='pad4'>
		  <a href='${swaplink}#swapping'>Swapping:
              </td>
	      <td>
	          <table cellpadding=0 cellspacing=0 border=0>\n";
127
    if ($isadmin) {
128 129 130 131 132 133 134 135 136
        #
        # Batch Experiment?
        #
	echo "    <tr>
  	              <td>
                           <input type=checkbox
                                  name='formfields[idle_ignore]'
                                  value=1";

137 138
	if (isset($formfields["idle_ignore"]) &&
	    strcmp($formfields["idle_ignore"], "1") == 0) {
139 140 141 142 143 144 145 146 147
	    echo " checked='1'";
	}

	echo ">
                      </td>
                      <td>
	                   Idle Ignore
                      </td>
                  </tr>\n";
148

149 150 151 152 153 154
	echo "    <tr>
                       <td>
                          <input type='checkbox'
	                         name='formfields[swappable]'
	                         value='1'";

155
	if ($formfields["swappable"] == "1") {
156 157 158 159 160 161 162
	    echo " checked='1'";
	}
	echo ">
                      </td>
                      <td>
                          <a href='{$swaplink}#swapping'>
	                     <b>Swappable:</b></a>
163
                             This experiment can be swapped.
164 165 166 167 168 169 170
                      </td>
	              </tr>
	              <tr>
                      <td></td>
   	              <td>If not, why not (administrators option)?<br>
                          <textarea rows=2 cols=50
                                    name='formfields[noswap_reason]'>" .
171
	                               $formfields["noswap_reason"] .
172 173 174 175 176 177 178 179 180
	                 "</textarea>
                      </td>
	              </tr><tr>\n";
    }
    echo "            <td>
                      <input type='checkbox'
	                     name='formfields[idleswap]'
	                     value='1'";

181
    if ($formfields["idleswap"] == "1") {
182 183 184 185 186 187 188
	echo " checked='1'";
    }
    echo ">
                  </td>
                  <td>
                      <a href='{$swaplink}#idleswap'>
	                 <b>Idle-Swap:</b></a>
189
                         Swap out this experiment after
190 191
                         <input type='text'
                                name='formfields[idleswap_timeout]'
192
		                value='" . $formfields["idleswap_timeout"] . "'
193 194 195 196 197 198 199 200 201
                                size='3'>
                         hours idle.
                  </td>
	          </tr>
	          <tr>
                  <td></td>
   	          <td>If not, why not?<br>
                      <textarea rows=2 cols=50
                                name='formfields[noidleswap_reason]'>" .
202
	                            $formfields["noidleswap_reason"] .
203 204 205 206 207 208 209
	             "</textarea>
                  </td>
	          </tr><tr>
  	          <td>
                      <input type='checkbox'
		             name='formfields[autoswap]'
		             value='1' ";
210

211
    if ($formfields["autoswap"] == "1") {
212 213 214 215 216 217
	echo " checked='1'";
    }
    echo ">
                  </td>
	          <td>
                      <a href='${swaplink}#autoswap'>
218
	                 <b>Max. Duration [1]:</b></a>
219 220 221
                      Swap out after
                        <input type='text'
                               name='formfields[autoswap_timeout]'
222
		               value='" . $formfields["autoswap_timeout"] . "'
223 224 225
                               size='3'>
                      hours, even if not idle.
                  </td>
226 227 228 229 230 231 232 233 234 235 236 237 238
                  </tr>";

    #
    # Swapout disk state saving
    # XXX requires more work, need to create/remove sigs as appropriate
    #
    if (0) {
    echo "<tr>
		  <td>
	              <input type='checkbox'
		             name='formfields[savedisk]'
	                     value='1' ";

239
    if ($formfields["savedisk"] == "1") {
240 241 242 243 244 245 246 247 248 249 250 251 252
	echo " checked='1'";
    }
    echo ">
                  </td>
                  <td>
                      <a href='${swaplink}#swapstatesave'>
		         <b>State Saving:</b></a>
                      Save disk state on swapout
		  </td>
	       </tr>";
    }

    echo "</table></td></tr>";
253 254 255 256 257 258 259 260 261

    #
    # Resource usage.
    #
    echo "<tr>
              <td class='pad4'>CPU Usage:</td>
              <td class=left>
                  <input type=text
                         name=\"formfields[cpu_usage]\"
262
                         value=\"" . $formfields["cpu_usage"] . "\"
263
	                 size=2>
264
                  (PlanetLab Nodes Only: 1 &lt= X &lt= 5)
265 266
              </td>
          </tr>\n";
267

268 269 270 271 272
    echo "<tr>
              <td class='pad4'>Mem Usage:</td>
              <td class=left>
                  <input type=text
                         name=\"formfields[mem_usage]\"
273
                         value=\"" . $formfields["mem_usage"] . "\"
274 275 276 277
	                 size=2>
                  (PlanetLab Nodes Only: 1 &lt= X &lt= 5)
              </td>
          </tr>\n";
278

279 280 281 282 283 284 285
    #
    # Batch Experiment?
    #
    echo "<tr>
  	      <td class=left colspan=2>
              <input type=checkbox name='formfields[batchmode]' value='1'";

286 287
    if (isset($formfields["batchmode"]) &&
	strcmp($formfields["batchmode"], "1") == 0) {
288 289 290 291 292 293
	    echo " checked='1'";
    }

    echo ">\n";
    echo "Batch Mode Experiment &nbsp;
          <font size='-1'>(See
294
          <a href='$WIKIDOCURL/Tutorial#BatchMode'>Tutorial</a>
295 296 297 298
          for more information)</font>
          </td>
          </tr>\n";

299 300 301
    #
    # Run linktest, and level. 
    # 
302
    if (STUDLY() || $EXPOSELINKTEST) {
303
    echo "<tr>
304
              <td><a href='$WIKIDOCURL/linktest'>Linktest</a> Option:</td>
305 306 307 308 309 310
              <td><select name=\"formfields[linktest_level]\">
                          <option value=0>Skip Linktest </option>\n";

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

311
	if (strcmp($formfields["linktest_level"], "$i") == 0)
312 313 314 315 316 317
	    $selected = "selected";
	
	echo "        <option $selected value=$i>Level $i - " .
	    $linktest_levels[$i] . "</option>\n";
    }
    echo "       </select>";
318
    echo "    (<a href='$WIKIDOCURL/linktest'><b>What is this?</b></a>)";
319 320
    echo "    </td>
          </tr>\n";
321
    }
322

323 324 325 326 327 328 329 330
    echo "<tr>
              <td colspan=2 align=center>
                 <b><input type=submit name=submit value=Submit></b>
              </td>
          </tr>\n";

    echo "</form>
          </table>\n";
331 332 333 334
    echo "<blockquote>
            <ol type=1 start=1>
	     <li> You may not turn off Maximum Duration, but you are allowed
                  to change the
335
                  the number of hours, up to $autoswap_max hours.
336 337 338 339 340
                  Contact " . $TBMAILADDR . " if you need more time.
             </li>
            </ol>
          </blockquote>\n";

341 342 343 344
}

#
# Construct a defaults array based on current DB info. Used for the initial
345
# form, and to determine if any changes were made.
346
#
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
$defaults                      = array();
$defaults["description"]       = $experiment->description();
$defaults["idle_ignore"]       = $experiment->idle_ignore();
$defaults["batchmode"]         = $experiment->batchmode();
$defaults["swappable"]         = $experiment->swappable();
$defaults["noswap_reason"]     = $experiment->noswap_reason();
$defaults["idleswap"]          = $experiment->idleswap();
$defaults["idleswap_timeout"]  = $experiment->idleswap_timeout() / 60.0;
$defaults["noidleswap_reason"] = $experiment->noidleswap_reason();
$defaults["autoswap"]          = $experiment->autoswap();
$defaults["autoswap_timeout"]  = $experiment->autoswap_timeout() / 60.0;
$defaults["savedisk"]          = $experiment->savedisk();
$defaults["mem_usage"]         = $experiment->mem_usage();
$defaults["cpu_usage"]         = $experiment->cpu_usage();
$defaults["linktest_level"]    = $experiment->linktest_level();
362 363 364 365

#
# A couple of defaults for turning things on.
#
366 367
if (!$defaults["autoswap"]) {
     $defaults["autoswap_timeout"] = 10;
368
}
369 370
if (!$defaults["idleswap"]) {
     $defaults["idleswap_timeout"] = $idleswaptimeout;
371 372 373
}

#
374
# On first load, display initial values and exit.
375 376
#
if (! isset($submit)) {
377
    SPITFORM($experiment, $defaults, 0);
378 379 380 381 382
    PAGEFOOTER();
    return;
}

#
383
# Build up argument array to pass along.
384
#
385
$args = array();
386

387 388 389 390
# Skip passing ones that are not changing from the default (DB state.)
if (isset($formfields["description"]) && $formfields["description"] != "" &&
    ($formfields["description"] != $experiment->description())) {
    $args["description"] = $formfields["description"];
391 392
}

393 394 395 396 397 398 399
if ($isadmin) {			# A couple of admin-only options.
    # Filter booleans from checkboxes to 0 or 1.
    $formfields["idle_ignore"] = 
	(!isset($formfields["idle_ignore"]) ||
	 strcmp($formfields["idle_ignore"], "1")) ? 0 : 1;
    if ($formfields["idle_ignore"] != $experiment->idle_ignore()) {
	$args["idle_ignore"] = $formfields["idle_ignore"];
400
    }
401

402 403 404 405 406 407 408 409 410
    $formfields["swappable"] = (!isset($formfields["swappable"]) ||
				strcmp($formfields["swappable"], "1")) ? 0 : 1;
    if ($formfields["swappable"] != $experiment->swappable()) {
	$args["swappable"] = $formfields["swappable"];
    }
    if (isset($formfields["noswap_reason"]) &&
	$formfields["noswap_reason"] != "" &&
	($formfields["noswap_reason"] != $experiment->noswap_reason())) {
	$args["noswap_reason"] = $formfields["noswap_reason"];
411 412 413
    }
}

414 415 416 417
$formfields["idleswap"] = (!isset($formfields["idleswap"]) ||
			   strcmp($formfields["idleswap"], "1")) ? 0 : 1;
if ($formfields["idleswap"] != $experiment->idleswap()) {
    $args["idleswap"] = $formfields["idleswap"];
418
}
419 420 421 422 423 424
# Note that timeouts are in hours in the UI, but in minutes in the DB. 
if (isset($formfields["idleswap_timeout"]) && 
    $formfields["idleswap_timeout"] != "" &&
    ($formfields["idleswap_timeout"] != 
     $experiment->idleswap_timeout() / 60.0)) {
    $args["idleswap_timeout"] = $formfields["idleswap_timeout"];
425
}
426 427 428 429
if (isset($formfields["noidleswap_reason"]) && 
    $formfields["noidleswap_reason"] != "" &&
    ($formfields["noidleswap_reason"] != $experiment->noidleswap_reason())) {
    $args["noidleswap_reason"] = $formfields["noidleswap_reason"];
430
}
431

432 433 434 435
$formfields["autoswap"] = (!isset($formfields["autoswap"]) ||
			   strcmp($formfields["autoswap"], "1")) ? 0 : 1;
if ($formfields["autoswap"] != $experiment->autoswap()) {
    $args["autoswap"] = $formfields["autoswap"];
436
}
437 438 439 440 441
if (isset($formfields["autoswap_timeout"]) && 
    $formfields["autoswap_timeout"] != "" &&
    ($formfields["autoswap_timeout"] != 
     $experiment->autoswap_timeout() / 60.0)) {
    $args["autoswap_timeout"] = $formfields["autoswap_timeout"];
442 443
}

444 445 446 447
$formfields["savedisk"] = (!isset($formfields["savedisk"]) ||
			   strcmp($formfields["savedisk"], "1")) ? 0 : 1;
if ($formfields["savedisk"] != $experiment->savedisk()) {
    $args["savedisk"] = $formfields["savedisk"];
448
}
449

450 451 452
if (isset($formfields["cpu_usage"]) && $formfields["cpu_usage"] != "" &&
    ($formfields["cpu_usage"] != $experiment->cpu_usage())) {
    $args["cpu_usage"] = $formfields["cpu_usage"];
453 454
}

455 456 457
if (isset($formfields["mem_usage"]) && $formfields["mem_usage"] != "" &&
    ($formfields["mem_usage"] != $experiment->mem_usage())) {
    $args["mem_usage"] = $formfields["mem_usage"];
458 459
}

460 461 462 463
$formfields["batchmode"] = (!isset($formfields["batchmode"]) ||
			    strcmp($formfields["batchmode"], "1")) ? 0 : 1;
if ($formfields["batchmode"] != $experiment->batchmode()) {
    $args["batchmode"] = $formfields["batchmode"];
464
}
465

466 467 468 469 470 471
# Select defaults to "none" if not set.
if (isset($formfields["linktest_level"]) &&
    $formfields["linktest_level"] != "none" && 
    $formfields["linktest_level"] != "" &&
    ($formfields["linktest_level"] != $experiment->linktest_level())) {
    $args["linktest_level"] = $formfields["linktest_level"];
472 473
}

474 475 476 477
$errors  = array();
if (! ($result = Experiment::EditExp($experiment, $args, $errors))) {
    # Always respit the form so that the form fields are not lost.
    # I just hate it when that happens so lets not be guilty of it ourselves.
478 479 480 481
    SPITFORM($experiment, $formfields, $errors);
    PAGEFOOTER();
    return;
}
482 483 484 485

#
# 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.
486
#
487
header("Location: " . CreateURL("showexp", $experiment));
488 489

?>