Commit 41f4d6a5 authored by Leigh Stoller's avatar Leigh Stoller

Move the bulk of what was in showlogfile, into showlogfile_sup, so

that it can be "included" into other scripts; showlogfile, beginexp,
swapexp, modifyexp, endexp.

Each of these scripts now appends the showlog directly to the page,
instead of providing a link to a different page.

Also changed the showlog code to place the output into an inner iframe
so that it can be sized to fit in the window, without the outer stuff
(like the menus) getting scrolled away.
parent 01585b4b
......@@ -28,6 +28,9 @@ function EXPERROR()
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
# This will not return if its a sajax request.
include("showlogfile_sup.php3");
#
# Handle pre-defined view styles
#
......@@ -182,18 +185,12 @@ echo "<font size=+2>Experiment <b>".
"</font>\n";
echo "<br><br>\n";
echo "<center><br>";
echo "<font size=+1>Starting experiment configuration.</font>
</center>";
echo "<br>\n";
echo $results[message];
echo "<b>Starting experiment configuration!</b> " . $results[message];
echo "<br><br>\n";
echo "While you are waiting, you can watch the log
in <a href=showlogfile.php3?pid=$exp_pid&eid=$exp_id>
realtime</a>.\n";
echo "<br>
</font>\n";
in realtime:<br>\n";
echo "</font>\n";
STARTLOG($exp_pid, $exp_id);
#
# Standard Testbed Footer
......
......@@ -13,6 +13,9 @@ include("showstuff.php3");
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
# This will not return if its a sajax request.
include("showlogfile_sup.php3");
#
# Must provide the EID!
#
......@@ -38,7 +41,7 @@ if ($canceled) {
#
# Standard Testbed Header, after checking for cancel above.
#
PAGEHEADER("Terminate a Testbed Experiment");
PAGEHEADER("Terminate Experiment");
#
# Check to make sure thats this is a valid PID/EID, while getting the
......@@ -65,7 +68,7 @@ if (! TBExptAccessCheck($uid, $exp_pid, $exp_eid, $TB_EXPT_DESTROY)) {
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_eid'>$exp_eid</a>".
"</b></font>\n";
"</b></font><br>\n";
# A locked down experiment means just that!
if ($lockdown) {
......@@ -106,16 +109,6 @@ if (!$confirmed) {
#
TBGroupUnixInfo($exp_pid, $exp_gid, $unix_gid, $unix_name);
#
# We run a wrapper script that does all the work of terminating the
# experiment.
#
# tbstopit <pid> <eid>
#
echo "<center><br>";
echo "<h2>Starting experiment termination. Please wait a moment ...
</h2></center>";
flush();
#
......@@ -146,7 +139,7 @@ if ($retval) {
echo "<blockquote><pre>$suexec_output<pre></blockquote>";
}
else {
echo "<h3>Your experiment is terminating!</h3><br>
echo "<b>Your experiment is terminating!</b>
You will be notified via email when the experiment has been torn
down, and you can reuse the experiment name.
This typically takes less than two minutes, depending on the
......@@ -155,10 +148,8 @@ else {
of time, please contact $TBMAILADDR.\n";
echo "<br><br>
If you are the morbid type, you can watch the experiment die in
<a href=showlogfile.php3?pid=$exp_pid&eid=$exp_eid>
realtime</a>.\n";
Watch the experiment die in realtime:<br>\n";
STARTLOG($exp_pid, $exp_eid);
}
#
......
......@@ -9,40 +9,21 @@ include("showstuff.php3");
$parser = "$TB/libexec/ns2ir/parse-ns";
#
# Standard Testbed Header
#
PAGEHEADER("Modify Experiment");
# the following hack is a page for Netbuild to
# point the users browser at after a successful modify.
# this does no error checking.
if ($justsuccess) {
echo "<br /><br />";
echo "<font size=+1>
<p>Experiment
<a href='showexp.php3?pid=$pid&eid=$eid'>$eid</a>
in project <A href='showproject.php3?pid=$pid'>$pid</A>
is being modified!</p><br />
<p>You will be notified via email when the operation is complete.
This could take one to ten minutes, depending on
whether nodes were added to the experiments, and whether
disk images had to be loaded.</p>
<p>While you are waiting, you can watch the log
in <a href=showlogfile.php3?pid=$pid&eid=$eid>
realtime</a>.</p></font>\n";
PAGEFOOTER();
return;
}
#
# Only known and logged in users can modify experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
$isadmin = ISADMIN($uid);
# This will not return if its a sajax request.
include("showlogfile_sup.php3");
#
# Standard Testbed Header
#
PAGEHEADER("Modify Experiment");
#
# Verify page arguments.
#
......@@ -65,21 +46,15 @@ $eid = addslashes($eid);
# Check to make sure this is a valid experiment.
#
if (! TBValidExperiment($pid, $eid)) {
# Netbuild requires the following line.
echo "\n\n<!-- NetBuild! Experiment does not exist -->\n\n";
USERERROR("The experiment $eid is not a valid experiment ".
"in project $pid.", 1);
}
if (! TBExptAccessCheck($uid, $pid, $eid, $TB_EXPT_MODIFY)) {
# Netbuild requires the following line.
echo "\n\n<!-- NetBuild! No permission to modify -->\n\n";
USERERROR("You do not have permission to modify this experiment.", 1);
}
if (TBExptLockedDown($pid, $eid)) {
# Netbuild requires the following line.
echo "\n\n<!-- NetBuild! No permission to modify -->\n\n";
USERERROR("Cannot proceed; experiment is locked down!", 1);
}
......@@ -87,8 +62,6 @@ $expstate = TBExptState($pid, $eid);
if (strcmp($expstate, $TB_EXPTSTATE_ACTIVE) &&
strcmp($expstate, $TB_EXPTSTATE_SWAPPED)) {
# Netbuild requires the following line.
echo "\n\n<!-- NetBuild! Experiment is in transition. -->\n\n";
USERERROR("You cannot modify an experiment in transition.", 1);
}
......@@ -96,7 +69,8 @@ if (strcmp($expstate, $TB_EXPTSTATE_ACTIVE) &&
echo "<font size=+2>Experiment <b>".
"<a href='showproject.php3?pid=$pid'>$pid</a>/".
"<a href='showexp.php3?pid=$pid&eid=$eid'>$eid</a></b></font>\n";
echo "<br><br>\n";
echo "<br>\n";
flush();
#
# Put up the modify form on first load.
......@@ -106,17 +80,6 @@ if (! isset($go)) {
"Modify Experiment Documentation (FAQ)</a></h3>";
echo "<br>";
#
# Unreleased option?
#
if ($isadmin) {
echo "<font size='+1'>You can ".
"<a href='buildui/bui.php3?action=modify&pid=$pid&eid=$eid'>".
"modify this experiment with NetBuild</a>, ".
"or edit the NS directly:</font>";
echo "<br>";
}
if (STUDLY()) {
echo "<font size='+1'>".
"<a href='clientui.php3?pid=$pid&eid=$eid'>GUI Editor</a>".
......@@ -124,7 +87,7 @@ if (! isset($go)) {
echo "<br>";
}
echo "<form action='modifyexp.php3' method='post'>";
echo "<form action='modifyexp.php3?pid=$pid&eid=$eid' method='post'>";
echo "<textarea cols='100' rows='40' name='nsdata'>";
$query_result =
......@@ -159,8 +122,6 @@ if (! isset($go)) {
Restart Event System in experiment (Highly Recommended)</input>";
}
echo "<br>";
echo "<input type='hidden' name='pid' value='$pid'>";
echo "<input type='hidden' name='eid' value='$eid'>";
echo "<input type='submit' name='go' value='Modify'>";
echo "</form>\n";
PAGEFOOTER();
......@@ -211,9 +172,6 @@ if ($retval != 0) {
if ($retval < 0) {
SUEXECERROR(SUEXEC_ACTION_CONTINUE);
}
# Netbuild requires the following line.
echo "\n\n<!-- NetBuild! Modifed NS file contains syntax errors -->\n\n";
echo "<br>";
echo "<h3>Modified NS file contains syntax errors</h3>";
echo "<blockquote><pre>$suexec_output<pre></blockquote>";
......@@ -222,12 +180,6 @@ if ($retval != 0) {
exit();
}
echo "<center>";
echo "<h2>Starting experiment modify. Please wait a moment ...
</h2></center>";
flush();
#
# Avoid SIGPROF in child.
#
......@@ -248,9 +200,6 @@ unlink($nsfile);
# do with the error. Also reports to tbops.
#
if ($retval < 0) {
# the following line is required for Netbuild interaction.
echo "\n\n<!-- Netbuild! Modify failed -->\n\n";
SUEXECERROR(SUEXEC_ACTION_DIE);
#
# Never returns ...
......@@ -265,16 +214,12 @@ echo "<br>\n";
if ($retval) {
echo "<h3>Experiment modify could not proceed</h3>";
echo "<blockquote><pre>$suexec_output<pre></blockquote>";
# the following line is required for Netbuild interaction.
echo "\n\n<!-- Netbuild! Modify failed -->\n\n";
}
else {
#
# Exit status 0 means the experiment is modifying.
#
echo "<br>";
echo "Your experiment is being modified!<br><br>";
echo "<b>Your experiment is being modified!</b> ";
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 ".
......@@ -283,12 +228,8 @@ else {
"reasonable amount time, please contact $TBMAILADDR. ".
"<br><br>".
"While you are waiting, you can watch the log of experiment ".
"modification in ".
"<a href=showlogfile.php3?pid=$pid&eid=$eid> ".
"realtime</a>.\n";
# the following line is required for Netbuild.
echo "\n\n<!-- Netbuild! success -->\n\n";
"modification in realtime:<br>\n";
STARTLOG($pid, $eid);
}
#
......
......@@ -110,14 +110,16 @@ function ml_getBodyText(ifr) {
/* @return The innerHeight of the window. */
function ml_getInnerHeight() {
var retval;
var win = document.getElementById('outputframe').contentWindow;
var doc = document.getElementById('outputframe').contentWindow.document;
if (self.innerHeight) // all except Explorer
retval = self.innerHeight;
else if (document.documentElement && document.documentElement.clientHeight)
if (win.innerHeight) // all except Explorer
retval = win.innerHeight;
else if (doc.documentElement && doc.documentElement.clientHeight)
// Explorer 6 Strict Mode
retval = document.documentElement.clientHeight;
else if (document.body) // other Explorers
retval = document.body.clientHeight;
retval = doc.documentElement.clientHeight;
else if (doc.body) // other Explorers
retval = doc.body.clientHeight;
return retval;
}
......@@ -125,9 +127,11 @@ function ml_getInnerHeight() {
/* @return The scrollTop of the window. */
function ml_getScrollTop() {
var retval;
var win = document.getElementById('outputframe').contentWindow;
var doc = document.getElementById('outputframe').contentWindow.document;
if (self.pageYOffset) // all except Explorer
retval = self.pageYOffset;
if (win.pageYOffset) // all except Explorer
retval = win.pageYOffset;
else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
retval = document.documentElement.scrollTop;
else if (document.body) // all other Explorers
......@@ -139,14 +143,16 @@ function ml_getScrollTop() {
/* @return The height of the document. */
function ml_getScrollHeight() {
var retval;
var test1 = document.body.scrollHeight;
var test2 = document.body.offsetHeight;
var win = document.getElementById('outputframe').contentWindow;
var doc = document.getElementById('outputframe').contentWindow.document;
var test1 = doc.body.scrollHeight;
var test2 = doc.body.offsetHeight;
if (test1 > test2) // all but Explorer Mac
retval = document.body.scrollHeight;
retval = doc.body.scrollHeight;
else // Explorer Mac;
//would also work in Explorer 6 Strict, Mozilla and Safari
retval = document.body.offsetHeight;
retval = doc.body.offsetHeight;
return retval;
}
......@@ -158,7 +164,9 @@ function ml_getScrollHeight() {
* @param state The state of the download.
*/
function ml_handleReadyState(state) {
var oa = document.getElementById('outputarea');
var Iframe = document.getElementById('outputframe');
var idoc = Iframe.contentWindow.document;
var oa = Iframe.contentWindow.document.getElementById('outputarea');
var dl = document.getElementById('downloader');
if ((rt = ml_getBodyText(dl)) == null) {
......@@ -237,7 +245,7 @@ function ml_handleReadyState(state) {
if (line.indexOf('***') != -1 ||
(lastError == i - 1) && line.indexOf(' ') == 0) {
if (plain != "") {
tn = document.createTextNode(plain);
tn = idoc.createTextNode(plain);
oa.appendChild(tn);
}
plain = "";
......@@ -281,9 +289,9 @@ function ml_handleReadyState(state) {
pnode = lengths[index];
plain += line.substring(lastIndex, index);
tn = document.createTextNode(plain);
tn = idoc.createTextNode(plain);
if (hasError) {
fn = document.createElement("font");
fn = idoc.createElement("font");
fn.setAttribute("color", "red");
fn.appendChild(tn);
oa.appendChild(fn);
......@@ -295,10 +303,11 @@ function ml_handleReadyState(state) {
/* Create the link. */
var linktext = line.substring(index, index + pnode.length);
var nlink = document.createElement("A");
var nlink = idoc.createElement("A");
nlink.setAttribute('href',
'shownode.php3?node_id=' + pnode);
tn = document.createTextNode(linktext);
nlink.setAttribute('target', '_parent');
tn = idoc.createTextNode(linktext);
nlink.appendChild(tn);
oa.appendChild(nlink);
......@@ -307,8 +316,8 @@ function ml_handleReadyState(state) {
}
if (hasError) {
/* It is an error line, turn it red. */
tn = document.createTextNode(line.substring(lastIndex));
fn = document.createElement("font");
tn = idoc.createTextNode(line.substring(lastIndex));
fn = idoc.createElement("font");
fn.setAttribute("color", "red");
fn.appendChild(tn);
oa.appendChild(fn);
......@@ -329,15 +338,15 @@ function ml_handleReadyState(state) {
if (state == LOG_STATE_LOADED)
plain += lastLine;
tn = document.createTextNode(plain);
tn = idoc.createTextNode(plain);
oa.appendChild(tn);
var nh = ml_getScrollHeight();
/* See if we should scroll the window down. */
if ((h - (y + ih)) < (y == 0 ? 200 : 10)) {
document.documentElement.scrollTop = nh;
document.body.scrollTop = nh;
Iframe.contentWindow.document.documentElement.scrollTop = nh;
Iframe.contentWindow.document.body.scrollTop = nh;
}
}
}
......@@ -7,17 +7,6 @@
include("defs.php3");
include("showstuff.php3");
require("Sajax.php");
sajax_init();
sajax_export("GetPNodes");
# If this call is to client request function, then turn off interactive mode.
# All errors will go to above function and get reported back through the
# Sajax interface.
if (sajax_client_request()) {
$session_interactive = 0;
}
#
# Only known and logged in users can look at experiments.
#
......@@ -25,63 +14,17 @@ $uid = GETLOGIN();
LOGGEDINORDIE($uid);
$isadmin = ISADMIN($uid);
function CHECKPAGEARGS($pid, $eid) {
global $uid, $TB_EXPT_READINFO;
#
# Verify page arguments.
#
if (!isset($pid) ||
strcmp($pid, "") == 0) {
USERERROR("You must provide a Project ID.", 1);
}
if (!isset($eid) ||
strcmp($eid, "") == 0) {
USERERROR("You must provide an Experiment ID.", 1);
}
#
# Check to make sure this is a valid PID/EID tuple.
#
if (! TBValidExperiment($pid, $eid)) {
USERERROR("The experiment $pid/$eid is not a valid experiment!", 1);
}
#
# Verify permission.
#
if (! TBExptAccessCheck($uid, $pid, $eid, $TB_EXPT_READINFO)) {
USERERROR("You do not have permission to view the log for $pid/$eid!", 1);
}
}
function GetPNodes($pid, $eid) {
CHECKPAGEARGS($pid, $eid);
$retval = array();
$query_result = DBQueryFatal(
"select r.node_id from reserved as r ".
"where r.eid='$eid' and r.pid='$pid' order by LENGTH(node_id) desc");
while ($row = mysql_fetch_array($query_result)) {
$retval[] = $row[node_id];
}
return $retval;
}
# 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();
CHECKPAGEARGS($pid, $eid);
# This will not return if its a sajax request.
include("showlogfile_sup.php3");
#
# Standard Testbed Header
#
PAGEHEADER("Experiment Activity Log");
# Otherwise, check page arguments.
CHECKPAGEARGS($pid, $eid);
#
# Check for a logfile. This file is transient, so it could be gone by
# the time we get to reading it.
......@@ -95,29 +38,8 @@ echo "<font size=+2>Experiment <b>".
"<a href='showexp.php3?pid=$pid&eid=$eid'>$eid</a></b></font>\n";
echo "<br /><br />\n";
?>
<pre id='outputarea'>
</pre>
<br>
<img id='busy' src='busy.gif'><span id='loading'> Loading...</span>
<?php
echo "
<script type='text/javascript' language='javascript' src='json.js'></script>
<script type='text/javascript' language='javascript' src='mungelog.js'></script>\n";
echo "
<script type='text/javascript' language='javascript'>\n";
sajax_show_javascript();
echo "
exp_pid = \"$pid\";
exp_eid = \"$eid\";
</script>
<iframe id='downloader' name='downloader' width=0 height=0 src='spewlogfile.php3?pid=$pid&eid=$eid' onload='ml_handleReadyState(LOG_STATE_LOADED);' border=0 style='width:0px; height:0px; border: 0px'>
</iframe>\n";
# This spits out the frame.
STARTLOG($pid, $eid);
#
# Standard Testbed Footer
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#
require("Sajax.php");
sajax_init();
sajax_export("GetPNodes");
# If this call is to client request function, then turn off interactive mode.
# All errors will go to above function and get reported back through the
# Sajax interface.
if (sajax_client_request()) {
$session_interactive = 0;
}
function CHECKPAGEARGS($pid, $eid) {
global $uid, $TB_EXPT_READINFO;
#
# Verify page arguments.
#
if (!isset($pid) ||
strcmp($pid, "") == 0) {
USERERROR("You must provide a Project ID.", 1);
}
if (!isset($eid) ||
strcmp($eid, "") == 0) {
USERERROR("You must provide an Experiment ID.", 1);
}
if (!TBvalid_pid($pid)) {
PAGEARGERROR("Invalid project ID.");
}
if (!TBvalid_eid($eid)) {
PAGEARGERROR("Invalid experiment ID.");
}
#
# Check to make sure this is a valid PID/EID tuple.
#
if (! TBValidExperiment($pid, $eid)) {
USERERROR("The experiment $pid/$eid is not a valid experiment!", 1);
}
#
# Verify permission.
#
if (! TBExptAccessCheck($uid, $pid, $eid, $TB_EXPT_READINFO)) {
USERERROR("You do not have permission to view the log for $pid/$eid!", 1);
}
}
function GetPNodes($pid, $eid) {
CHECKPAGEARGS($pid, $eid);
$retval = array();
$query_result = DBQueryFatal(
"select r.node_id from reserved as r ".
"where r.eid='$eid' and r.pid='$pid' order by LENGTH(node_id) desc");
while ($row = mysql_fetch_array($query_result)) {
$retval[] = $row[node_id];
}
return $retval;
}
function STARTLOG($pid, $eid)
{
global $BASEPATH;
echo "<script type='text/javascript' language='javascript'>\n";
echo "function SetupOutputArea() {
var Iframe = document.getElementById('outputframe');
var winheight = 0;
var yoff = 0;
// This tells us the total height of the browser window.
if (window.innerHeight) // all except Explorer
winheight = window.innerHeight;
else if (document.documentElement &&
document.documentElement.clientHeight)
// Explorer 6 Strict Mode
winheight = document.documentElement.clientHeight;
else if (document.body)
// other Explorers
winheight = document.body.clientHeight;
// Now get the Y offset of the outputframe.
yoff = Iframe.offsetTop;
Iframe.contentWindow.document.open();
Iframe.contentWindow.document.write('<html><head><base href=$BASEPATH/></head><body><pre id=outputarea></pre></body></html>');
Iframe.contentWindow.document.close();
if (winheight != 0)
// Now calculate how much room is left and make the iframe
// big enough to use most of the rest of the window.
if (yoff != 0)
winheight = winheight - (yoff + 175);
else
winheight = winheight * 0.7;
Iframe.height = winheight;
}
</script>\n";
echo "<br>\n";
echo "<img id='busy' src='busy.gif'><span id='loading'> Loading...</span>";
echo "<br>\n";
echo "<div><iframe id='outputframe' src='busy.gif' ".
"width=100% height=600 scrolling=auto border=4></iframe></div>\n";
echo "<script type='text/javascript' language='javascript' src='json.js'>
</script>".
"<script type='text/javascript' language='javascript'
src='mungelog.js'>
</script>\n";
echo "<script type='text/javascript' language='javascript'>\n";
echo "SetupOutputArea();\n";
sajax_show_javascript();
echo "exp_pid = \"$pid\";\n";
echo "exp_eid = \"$eid\";\n";
echo "</script>
<iframe id='downloader' name='downloader' width=0 height=0
src='spewlogfile.php3?pid=$pid&eid=$eid'
onload='ml_handleReadyState(LOG_STATE_LOADED);'
border=0 style='width:0px; height:0px; border: 0px'>
</iframe>\n";
}
# 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();
#
# We return to the including script ...
#
......@@ -13,6 +13,9 @@ include("showstuff.php3");
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
# This will not return if its a sajax request.
include("showlogfile_sup.php3");
#
# Must provide the EID!
#
......@@ -125,6 +128,8 @@ elseif (!strcmp($inout, "restart")) {
echo "<font size=+2>Experiment <b>".
"<a href='showproject.php3?pid=$pid'>$pid</a>/".
"<a href='showexp.php3?pid=$pid&eid=$eid'>$eid</a></b></font>\n";
echo "<br>\n";
flush();
# A locked down experiment means just that!
if ($lockdown) {
......@@ -202,18 +207,6 @@ if (!$confirmed) {
#
TBGroupUnixInfo($exp_pid, $exp_gid, $unix_gid, $unix_name);
#
# We run a wrapper script that does all the work of terminating the
# experiment.
#
# tbstopit <pid> <eid>
#
echo "<center>";
echo "<h2>Starting experiment state change. Please wait a moment ...
</h2></center>";
flush();
#
# Run the scripts. We use a script wrapper to deal with changing
# to the proper directory and to keep some of these details out
......@@ -280,6 +273,7 @@ else {
}
}
else {
echo "<div>";
if (strcmp($inout, "out") == 0 &&
strcmp($state, $TB_EXPTSTATE_ACTIVATING) == 0) {
......@@ -287,7 +281,7 @@ else {
It typically takes a few minutes for this to be recognized,
assuming you made your request early enough. You will
be notified via email when the original swapin request has
either aborted or finished.\n";
either aborted or finished. ";
}
else {
if (strcmp($inout, "in") == 0)
......@@ -295,20 +289,19 @@ else {
else
$howlong = "less than two";
echo "Your experiment has started its $action.
echo "<b>Your experiment has started its $action.</b>
You will be notified via email when the operation is complete.
This typically takes $howlong minutes, depending on the
number of nodes in the experiment.\n";
number of nodes in the experiment. ";
}
echo "<br><br>
If you do not receive
echo "If you do not receive
email notification within a reasonable amount of time,
please contact $TBMAILADDR.\n";
echo "<br><br>
While you are waiting, you can watch the log in
<a href=showlogfile.php3?pid=$exp_pid&eid=$exp_eid>
realtime</a>.\n";
While you are waiting, you can watch the log in realtime:<br>\n";
echo "</div>";
STARTLOG($pid, $eid);
}
}
......