modifyexp.php3 9.77 KB
Newer Older
1 2 3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2008 University of Utah and the Flux Group.
5 6 7 8
# All rights reserved.
#
include("defs.php3");

9
$TMPDIR   = "/tmp/";
10 11

#
12
# Only known and logged in users.
13
#
14 15 16
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
17

18 19 20
# This will not return if its a sajax request.
include("showlogfile_sup.php3");

21 22 23 24 25 26 27 28 29
$reqargs = RequiredPageArguments("experiment",      PAGEARG_EXPERIMENT);
$optargs = OptionalPageArguments("go",              PAGEARG_STRING,
				 "syntax",          PAGEARG_STRING,
				 "reboot",          PAGEARG_BOOLEAN,
				 "eventrestart",    PAGEARG_BOOLEAN,
				 "nsdata",          PAGEARG_ANYTHING,
				 "exp_localnsfile", PAGEARG_STRING,
				 "formfields",      PAGEARG_ARRAY);

30 31 32 33 34
#
# Standard Testbed Header
#
PAGEHEADER("Modify Experiment");

35 36 37 38 39
# Need these below.
$pid = $experiment->pid();
$eid = $experiment->eid();
$unix_gid = $experiment->UnixGID();
$expstate = $experiment->state();
40 41 42 43 44 45
$geniflags = $experiment->geniflags();

# Must go through the geni interfaces.
if ($geniflags) {
    USERERROR("You cannot modify ProtoGeni experiments this way!", 1);
}
46 47

if (!$experiment->AccessCheck($this_user, $TB_EXPT_MODIFY)) {
48
    USERERROR("You do not have permission to modify this experiment.", 1);
49 50
}

51
if ($experiment->lockdown()) {
52 53 54
    USERERROR("Cannot proceed; experiment is locked down!", 1);
}

55 56
if (strcmp($expstate, $TB_EXPTSTATE_ACTIVE) &&
    strcmp($expstate, $TB_EXPTSTATE_SWAPPED)) {
57
    USERERROR("You cannot modify an experiment in transition.", 1);
58 59
}

60
# Okay, start.
61
echo $experiment->PageHeader();
62 63
echo "<br>\n";
flush();
64

65 66 67
#
# Put up the modify form on first load.
# 
68
if (! isset($go)) {
69
    echo "<a href='faq.php3#swapmod'>".
70 71
	 "Modify Experiment Documentation (FAQ)</a></h3>";

72 73 74 75 76 77 78 79 80 81 82 83 84
    echo "<script language=JavaScript>
          <!--
          function NormalSubmit() {
              document.form1.target='_self';
              document.form1.submit();
          }
          function SyntaxCheck() {
              window.open('','nscheck','width=650,height=400,toolbar=no,".
                              "resizeable=yes,scrollbars=yes,status=yes,".
                              "menubar=yes');
              var action = document.form1.action;
              var target = document.form1.target;

85
              document.form1.action='nscheck.php3?fromform=1';
86 87 88 89 90 91 92 93 94 95
              document.form1.target='nscheck';
              document.form1.submit();

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

    echo "<table align=center border=1>\n";
96
    if (STUDLY()) {
97 98
	$ui_url = CreateURL("clientui", $experiment);
	
99
	echo "<tr><th colspan=2><font size='+1'>".
100
	    "<a href='$ui_url'>GUI Editor</a>".
101
	    " - Edit the topology using a Java applet.</font>";
102
	echo "</th></tr>";
103 104
    }

105 106 107 108 109
    $url = CreateURL("modifyexp", $experiment, "go", 1);
    
    echo "<form name='form1' action='$url' method='post'
             onsubmit=\"return false;\" enctype=multipart/form-data>";
    
110 111
    echo "<tr><th>Upload new NS file: </th>";
    echo "<td><input type=hidden name=MAX_FILE_SIZE value=512000>";
112 113 114
    echo "    <input type=file name=exp_nsfile size=30
                      onchange=\"this.form.syntax.disabled=(this.value=='')\"/>
           </td></tr>\n";
115
    echo "<tr><th><em>or</em> NS file on server: </th> ";
116 117
    echo "<td><input type=text name=\"exp_localnsfile\" size=40
                     onchange=\"this.form.syntax.disabled=(this.value=='')\" />
Mike Hibler's avatar
Mike Hibler committed
118
          </td></tr>\n";
119 120
    
    echo "<tr><td colspan=2><b><em>or</em> Edit:</b><br>\n";
121 122 123 124 125
    echo "<textarea cols='100' rows='40' name='nsdata'
                    onchange=\"this.form.syntax.disabled=(this.value=='')\">";

    $nsfile = $experiment->NSFile();
    if ($nsfile) {
126 127 128 129 130
	echo "$nsfile";
    }
    else {
	echo "# There was no stored NS file for $pid/$eid.\n";
    }
131
	
132
    echo "</textarea>";
133
    echo "</td></tr>\n";
134
    if (!strcmp($expstate, $TB_EXPTSTATE_ACTIVE)) {
135
	echo "<tr><td colspan=2><p><b>Note!</b> It is recommended that you 
136
	      reboot all nodes in your experiment by checking the box below.
137 138 139 140
	      This is especially important if changing your experiment
              topology (adding or removing nodes, links, and LANs).
	      If adding/removing a delay to/from an existing link, or
              replacing a lost node <i>without modifying the experiment
141 142 143 144
              topology</i>, this won't be necessary. Restarting the
	      event system is also highly recommended since the same nodes
	      in your virtual topology may get mapped to different physical
	      nodes.</p>";
145
	echo "<input type='checkbox' name='reboot' value='1' checked='1'>
146
	      Reboot nodes in experiment (Highly Recommended)</input>";
147 148
	echo "<br><input type='checkbox' name='eventrestart'
                         value='1' checked='1'>
149
	      Restart Event System in experiment (Highly Recommended)</input>";
150
      echo "</td></tr>";
151
    }
152
    echo "<tr><th colspan=2><center>";
153 154 155 156
    echo "<input type=submit disabled id=syntax name=syntax
                 value='Syntax Check' onclick=\"SyntaxCheck();\"> ";
    echo "<input type=button name='go' value='Modify'
                 onclick='NormalSubmit();'>\n";
157 158 159
    echo "<input type='reset'>";
    echo "</center></th></tr>\n";
    echo "</table>\n";
160 161 162 163
    echo "</form>\n";
    PAGEFOOTER();
    exit();
}
Chad Barb's avatar
Chad Barb committed
164

165 166 167
#
# Okay, form has been submitted.
#
168 169 170 171 172 173 174 175 176
$speclocal  = 0;
$specupload = 0;
$specform   = 0;
$nsfile     = "";
$tmpfile    = 0;

if (isset($exp_localnsfile) && strcmp($exp_localnsfile, "")) {
    $speclocal = 1;
}
177 178 179
if (isset($_FILES['exp_nsfile']) &&
    $_FILES['exp_nsfile']['name'] != "" &&
    $_FILES['exp_nsfile']['tmp_name'] != "") {
180 181 182
    if ($_FILES['exp_nsfile']['size'] == 0) {
        USERERROR("Uploaded NS file does not exist, or is empty");
    }
183 184 185 186 187 188 189 190 191 192
    $specupload = 1;
}
if (!$speclocal && !$specupload && isset($nsdata))  {
    $specform = 1;
}

if ($speclocal + $specupload + $specform > 1) {
    USERERROR("You may not specify both an uploaded NS file and an ".
	      "NS file that is located on the Emulab server", 1);
}
193
#
194 195 196 197 198 199 200 201 202 203 204 205 206
# Gotta be one of them!
#
if (!$speclocal && !$specupload && !$specform) {
    USERERROR("You must supply an NS file!", 1);
}

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.
    #
207 208
    # Do not allow anything outside of the usual directories. I do not think
    # there is a security worry, but good to enforce it anyway.
209 210
    #
    if (!preg_match("/^([-\@\w\.\/]+)$/", $exp_localnsfile)) {
Mike Hibler's avatar
Mike Hibler committed
211
	USERERROR("NS File: Pathname includes illegal characters", 1);
212
    }
213 214 215
    if (!VALIDUSERPATH($exp_localnsfile)) {
	USERERROR("NS File: You must specify a server resident file in " .
		  "one of: ${TBVALIDDIRS}.", 1);
216
    }
217
    
218 219 220 221 222 223 224 225 226 227 228
    $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.
    #
229 230
    $nsfile = $_FILES['exp_nsfile']['tmp_name'];
    chmod($nsfile, 0666);
231
    $nonsfile = 0;
232 233
}
elseif ($specform) {
234 235 236 237 238 239 240 241 242 243 244 245
    #
    # Take the NS file passed in from the form and write it out to a file
    #
    $tmpfile = 1;

    #
    # Generate a hopefully unique filename that is hard to guess.
    # See backend scripts.
    # 
    list($usec, $sec) = explode(' ', microtime());
    srand((float) $sec + ((float) $usec * 100000));
    $foo = rand();
246

247 248 249 250 251
    $nsfile = "/tmp/$uid-$foo.nsfile";
    $handle = fopen($nsfile,"w");
    fwrite($handle,$nsdata);
    fclose($handle);
    chmod($nsfile, 0666);
252
}
253

254 255
STARTBUSY("Starting Modify");

256 257 258
#
# Do an initial parse test.
#
259
$retval = SUEXEC($uid, "$pid,$unix_gid", "webnscheck $nsfile",
260 261 262
		 SUEXEC_ACTION_IGNORE);

if ($retval != 0) {
263 264
    HIDEBUSY();
    
265 266 267
    if ($tmpfile) {
        unlink($nsfile);
    }
268 269 270 271
    
    # Send error to tbops.
    if ($retval < 0) {
	SUEXECERROR(SUEXEC_ACTION_CONTINUE);
272
    }
273 274 275 276 277 278
    echo "<br>";
    echo "<h3>Modified NS file contains syntax errors</h3>";
    echo "<blockquote><pre>$suexec_output<pre></blockquote>";

    PAGEFOOTER();
    exit();
279 280 281 282 283
}

# Avoid SIGPROF in child.
set_time_limit(0);

284 285 286 287 288 289 290 291 292
# args.
$optargs = "";
if (isset($reboot) && $reboot) {
     $optargs .= " -r ";
}
if (isset($eventrestart) && $eventrestart) {
     $optargs .= " -e ";
}

293
# Run the script.
294
$retval = SUEXEC($uid, "$pid,$unix_gid",
295
		 "webswapexp $optargs -s modify $pid $eid $nsfile",
296 297 298
		 SUEXEC_ACTION_IGNORE);
		 
# It has been copied out by the program!
299 300 301
if ($tmpfile) {
    unlink($nsfile);
}
302
HIDEBUSY();
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327

#
# Fatal Error. Report to the user, even though there is not much he can
# do with the error. Also reports to tbops.
# 
if ($retval < 0) {
    SUEXECERROR(SUEXEC_ACTION_DIE);
    #
    # Never returns ...
    #
    die("");
}

#
# Exit status 0 means the experiment is swapping, or will be.
#
echo "<br>\n";
if ($retval) {
    echo "<h3>Experiment modify could not proceed</h3>";
    echo "<blockquote><pre>$suexec_output<pre></blockquote>";
}
else {
    #
    # Exit status 0 means the experiment is modifying.
    #
328
    echo "<b>Your experiment is being modified!</b> ";
329 330 331 332 333 334 335 336
    echo "You will be notified via email when the experiment has ".
	"finished modifying and you are able to proceed. This ".
	"typically takes less than 10 minutes, depending on the ".
	"number of nodes in the experiment. ".
	"If you do not receive email notification within a ".
	"reasonable amount time, please contact $TBMAILADDR. ".
	"<br><br>".
	"While you are waiting, you can watch the log of experiment ".
Leigh B. Stoller's avatar
Leigh B. Stoller committed
337
	"modification in realtime:<br><br>\n";
338
    STARTLOG($experiment);    
339 340
}

341 342 343 344 345 346 347
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>