uid(); $isadmin = ISADMIN(); # This stuff will be setup below in CHECKPAGEARGS() $pid = ""; $eid = ""; $unix_gid = ""; $linktest_level = 0; $linktest_pid = 0; # # Need this argument checking in a function so it can called from the # request handlers. # function CHECKPAGEARGS() { global $this_user, $TB_EXPTSTATE_ACTIVE, $TB_EXPT_MODIFY; global $pid, $eid, $experiment; global $unix_gid, $linktest_level, $linktest_pid; $reqargs = RequiredPageArguments("experiment", PAGEARG_EXPERIMENT); if (!$experiment->AccessCheck($this_user, $TB_EXPT_MODIFY)) { USERERROR("You do not have permission to run linktest ". "on $pid/$eid!", 1); } if ($experiment->state() != $TB_EXPTSTATE_ACTIVE) { USERERROR("Experiment $eid must be active run linktest!", 1); } $pid = $experiment->pid(); $eid = $experiment->eid(); $unix_gid = $experiment->UnixGID(); $linktest_level = $experiment->linktest_level(); $linktest_pid = $experiment->linktest_pid(); } # # Stop a running linktest. # function stop_linktest() { global $linktest_pid; global $uid, $pid, $unix_gid, $eid, $suexec_output, $session_interactive; # Must do this! CHECKPAGEARGS(); if (! $linktest_pid) { if ($session_interactive) { USERERROR("$pid/$eid is not running linktest!", 1); } return "stopped:Linktest is not running on experiment $pid/$eid!"; } $retval = SUEXEC($uid, "$pid,$unix_gid", "weblinktest -k $pid $eid", SUEXEC_ACTION_IGNORE); if ($retval < 0) { return "failed:$suexec_output"; } return "stopped:Linktest has been stopped."; } # # If user hits stop button in the output side, stop linktest. # $linktest_running = 0; function SPEWCLEANUP() { global $pid, $unix_gid, $eid, $linktest_running; if (connection_aborted() && $linktest_running) { SUEXEC($uid, "$pid,$unix_gid", "weblinktest -k $pid $eid", SUEXEC_ACTION_IGNORE); } } # # Start linktest running. # function start_linktest($level) { global $linktest_pid, $linktest_running, $TBSUEXEC_PATH; global $uid, $pid, $unix_gid, $eid, $suexec_output; # Must do this! CHECKPAGEARGS(); if ($linktest_pid) { return "failed:Linktest is already running on experiment $pid/$eid!"; } if (! TBvalid_tinyint($level) || $level < 0 || $level > TBDB_LINKTEST_MAX) { return "failed:Linktest level ($level) must be an integer ". "1 <= level <= ". TBDB_LINKTEST_MAX; } # Make sure we shutdown if client goes away. register_shutdown_function("SPEWCLEANUP"); set_time_limit(0); # XXX Hackish! $linktest_running = 1; $fp = popen("$TBSUEXEC_PATH $uid $pid,$unix_gid ". "weblinktest -l $level $pid $eid", "r"); if (! $fp) { USERERROR("Could not start linktest!", 1); } header("Content-Type: text/plain"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); echo "Starting linktest run at level $level on " . date("D M d G:i:s T"); # Oh, this is soooooo bogus! for ($i = 0; $i < 1024; $i++) { echo " "; } echo "\n"; flush(); while (!feof($fp)) { $string = fgets($fp, 1024); echo "$string"; flush(); } $retval = pclose($fp); $linktest_running = 0; if ($retval > 0) { echo "Linktest reported errors! Stopped at " . date("D M d G:i:s T") . "\n"; } elseif ($retval < 0) { echo $suexec_output; } else { # Success. echo "Linktest run was successful! Stopped at " . date("D M d G:i:s T") . "\n"; } exit(0); } # See if this request is to one of the above functions. Does not return # if it is. Otherwise return and continue on. sajax_handle_client_request(); # # In plain kill mode, just use the stop_linktest function and then # redirect back to the showexp page. # if (isset($_REQUEST["kill"])) { stop_linktest(); header("Location: showexp.php3?pid=$pid&eid=$eid"); return; } if (isset($_REQUEST["start"]) && isset($_REQUEST["level"])) { start_linktest($_REQUEST["level"]); return; } # # Okay, this is the initial page. # PAGEHEADER("Run Linktest"); # Must do this! CHECKPAGEARGS(); echo "\n"; echo "Experiment ". "$pid/". "$eid\n"; echo "

Are you sure you want to run linktest?


\n"; $experiment->Show(1); echo "
\n"; echo "
"; echo "\n"; echo "\n"; echo "\n"; echo "
Linktest Option: "; echo "

\n"; if ($linktest_pid) { echo "\n"; } else { echo "\n"; } echo "
\n"; echo "
\n"; if ($linktest_pid) { echo "Linktest is already running\n"; } echo "
\n"; echo "
\n"; echo "\n"; # # Standard Testbed Footer # PAGEFOOTER(); ?>