Commit 37d2649e authored by Leigh Stoller's avatar Leigh Stoller

Convert all of the new template code to PHP "classes." This was not as

much "fun" as the Perl conversion, but nothing about PHP is as much
fun as it is in perl.
parent 7e219a4a
......@@ -34,7 +34,7 @@ sub usage()
"-E <str> - A pithy sentence describing the template\n".
"-g <gid> - The group in which to create the experiment\n".
"<pid> - The project in which to create the experiment\n".
"<tid> - The template name (unique, alphanumeric, no blanks)\n".
"<tid> - The template name (alphanumeric, no blanks)\n".
"<input> - Input file for experiment.\n");
exit(-1);
}
......@@ -305,6 +305,9 @@ system("$makegraph $guid");
fatal(-1, "Error generating template graph.")
if ($?);
# Web interface depends on this line. Bad; need another way to send
# back the newly generated guid/version.
print "Template $guid/$vers has been created\n";
exit(0);
#
......
......@@ -5,7 +5,7 @@
# All rights reserved.
#
include("defs.php3");
include("template_defs.php");
include_once("template_defs.php");
#
# Only known and logged in users ...
......@@ -52,28 +52,26 @@ if (!TBvalid_integer($runidx)) {
PAGEHEADER("Experiment Run");
#
# Check to make sure this is a valid template.
# Check to make sure this is a valid template and user has permission.
#
if (! TBValidExperimentTemplate($guid, $version)) {
$template = Template::Lookup($guid, $version);
if (!$template) {
USERERROR("The experiment template $guid/$version is not a valid ".
"experiment template!", 1);
}
if (! TBIsTemplateInstanceExperiment($exptidx)) {
if (! $template->AccessCheck($uid, $TB_EXPT_READINFO)) {
USERERROR("You do not have permission to view experiment template ".
"$guid/$version!", 1);
}
$instance = TemplateInstance::LookupByExptidx($exptidx);
if (!$instance) {
USERERROR("The instance $exptidx is not a valid instance in ".
"template $guid/$version!", 1);
}
if (! TBValidExperimentRun($exptidx, $runidx)) {
if (! $instance->ValidRun($runidx)) {
USERERROR("The run $runidx is not a valid experiment run!", 1);
}
#
# Verify Permission.
#
if (! TBExptTemplateAccessCheck($uid, $guid, $TB_EXPT_READINFO)) {
USERERROR("You do not have permission to view experiment template ".
"$guid/$version!", 1);
}
echo "<font size=+2>Experiment Run<b> " .
MakeLink("instance",
"guid=$guid&version=$version&exptidx=$exptidx",
......@@ -82,7 +80,7 @@ echo "<font size=+2>Experiment Run<b> " .
echo "<br><br>\n";
SHOWEXPERIMENTRUN($exptidx, $runidx);
$instance->ShowRun($runidx);
#
# Standard Testbed Footer
......
......@@ -5,7 +5,7 @@
# All rights reserved.
#
include("defs.php3");
include("template_defs.php");
include_once("template_defs.php");
#
# Only known and logged in users ...
......@@ -45,24 +45,22 @@ if (!TBvalid_integer($exptidx)) {
PAGEHEADER("Template Instance");
#
# Check to make sure this is a valid template.
# Check to make sure this is a valid template and user has permission.
#
if (! TBValidExperimentTemplate($guid, $version)) {
$template = Template::Lookup($guid, $version);
if (!$template) {
USERERROR("The experiment template $guid/$version is not a valid ".
"experiment template!", 1);
}
if (! TBIsTemplateInstanceExperiment($exptidx)) {
USERERROR("The instance $exptidx is not a valid instance in ".
"template $guid/$version!", 1);
}
#
# Verify Permission.
#
if (! TBExptTemplateAccessCheck($uid, $guid, $TB_EXPT_READINFO)) {
if (! $template->AccessCheck($uid, $TB_EXPT_READINFO)) {
USERERROR("You do not have permission to view experiment template ".
"$guid/$version!", 1);
}
$instance = TemplateInstance::LookupByExptidx($exptidx);
if (!$instance) {
USERERROR("The instance $exptidx is not a valid instance in ".
"template $guid/$version!", 1);
}
echo "<font size=+2>Template Instance <b>" .
MakeLink("template",
......@@ -70,7 +68,7 @@ echo "<font size=+2>Template Instance <b>" .
"</b></font>\n";
echo "<br><br>\n";
SHOWTEMPLATEINSTANCE($guid, $version, $exptidx, 1);
$instance->Show(1);
#
# Standard Testbed Footer
......
......@@ -72,7 +72,7 @@ sajax_handle_client_request();
# Faster to do this after the sajax stuff
include("showstuff.php3");
include("template_defs.php");
include_once("template_defs.php");
#
# Need some DB info.
......@@ -97,11 +97,15 @@ $panic_date = $row["panic_date"];
$lockdown = $row["lockdown"];
# Template Instance Experiments get special treatment in this page.
$isinstance = ($EXPOSETEMPLATES &&
TBIsTemplateInstanceExperiment($expindex) ? 1 : 0);
if ($isinstance) {
$tag = "Template Instance";
TBPidEid2Template($pid, $eid, $guid, $version, $instance_idx);
$instance = NULL;
if ($EXPOSETEMPLATES) {
$instance = TemplateInstance::LookupByExptidx($expindex);
if (! is_null($instance)) {
$tag = "Template Instance";
$guid = $instance->guid();
$vers = $instance->vers();
}
}
#
......@@ -189,7 +193,7 @@ if ($expstate) {
}
elseif ($expstate == $TB_EXPTSTATE_ACTIVE ||
($expstate == $TB_EXPTSTATE_PANICED && $isadmin)) {
WRITESUBMENUBUTTON(($isinstance ?
WRITESUBMENUBUTTON(($instance ?
"Terminate Instance" :
"Swap Experiment Out"),
"swapexp.php3?inout=out&pid=$exp_pid&eid=$exp_eid");
......@@ -201,23 +205,23 @@ if ($expstate) {
}
}
if (!$isinstance && $expstate != $TB_EXPTSTATE_PANICED) {
if (!$instance && $expstate != $TB_EXPTSTATE_PANICED) {
WRITESUBMENUBUTTON("Terminate Experiment",
"endexp.php3?pid=$exp_pid&eid=$exp_eid");
}
# Batch experiments can be modifed only when paused.
if (!$isinstance && ($expstate == $TB_EXPTSTATE_SWAPPED ||
if (!$instance && ($expstate == $TB_EXPTSTATE_SWAPPED ||
(!$isbatch && $expstate == $TB_EXPTSTATE_ACTIVE))) {
WRITESUBMENUBUTTON("Modify Experiment",
"modifyexp.php3?pid=$exp_pid&eid=$exp_eid");
}
}
if ($isinstance && $expstate == $TB_EXPTSTATE_ACTIVE) {
if ($instance && $expstate == $TB_EXPTSTATE_ACTIVE) {
WRITESUBMENUBUTTON("Start New Experiment Run",
"template_exprun.php?action=start&guid=$guid".
"&version=$version&eid=$exp_eid");
"&version=$vers&eid=$exp_eid");
}
if ($expstate == $TB_EXPTSTATE_ACTIVE) {
......@@ -293,7 +297,7 @@ WRITESUBMENUDIVIDER();
WRITESUBMENUBUTTON("Show History",
"showstats.php3?showby=expt&which=$expindex");
if (!$isinstance && STUDLY()) {
if (!$instance && STUDLY()) {
WRITESUBMENUBUTTON("Duplicate Experiment",
"beginexp_html.php3?copyid=${exp_pid},${exp_eid}");
}
......@@ -408,11 +412,11 @@ if (TBExptFirewall($exp_pid, $exp_eid) &&
}
SUBPAGEEND();
if ($isinstance &&
if ($instance &&
($expstate == $TB_EXPTSTATE_ACTIVE ||
$expstate == $TB_EXPTSTATE_PANICED ||
$expstate == $TB_EXPTSTATE_ACTIVATING)) {
SHOWTEMPLATEINSTANCEBINDINGS($guid, $version, $instance_idx);
$instance->ShowBindings();
}
#
......
......@@ -129,7 +129,10 @@ function STARTLOG($pid, $eid)
</script>\n";
echo "<br>\n";
echo "<img id='busy' src='busy.gif'><span id='loading'> Loading...</span>";
echo "<center>\n";
echo "<img id='busy' src='busy.gif'>
<span id='loading'> Working ...</span>";
echo "</center>\n";
echo "<br>\n";
echo "<div><iframe id='outputframe' src='busy.gif' ".
......
......@@ -9,6 +9,7 @@
#
# Functions to dump out various things.
#
include_once("template_defs.php");
#
# A project
......@@ -863,16 +864,17 @@ function SHOWEXP($pid, $eid, $short = 0, $sortby = "") {
</tr>\n";
if (!$short) {
$isinstance = (TBIsTemplateInstanceExperiment($exptidx) ? 1 : 0);
$instance = TemplateInstance::LookupByExptidx($exptidx);
if ($isinstance) {
TBPidEid2Template($pid, $eid, $guid, $version, $instance_idx);
if (! is_null($instance)) {
$guid = $instance->guid();
$vers = $instance->vers();
echo "<tr>
<td>Template: </td>
<td class=\"left\">
<a href='template_show.php?guid=$guid&version=$version'>
$guid/$version</a></td>
<a href='template_show.php?guid=$guid&version=$vers'>
$guid/$vers</a></td>
</tr>\n";
}
......
......@@ -6,7 +6,7 @@
#
include("defs.php3");
include("showstuff.php3");
include("template_defs.php");
include_once("template_defs.php");
#
# Only known and logged in users can do this.
......
......@@ -5,7 +5,7 @@
# All rights reserved.
#
include("defs.php3");
include("template_defs.php");
include_once("template_defs.php");
#
# Only known and logged in users can begin experiments.
......@@ -109,19 +109,17 @@ if (isset($guid) && isset($version)) {
if (!TBvalid_tinyint($version)) {
PAGEARGERROR("Invalid GUID version");
}
#
# Check to make sure this is a valid template.
# Check to make sure this is a valid template and user has permission.
#
if (! TBValidExperimentTemplate($guid, $version)) {
$template = Template::Lookup($guid, $version);
if (!$template) {
USERERROR("The experiment template $guid/$version is not a valid ".
"experiment template!", 1);
}
#
# Verify Permission.
#
if (! TBExptTemplateAccessCheck($uid, $guid, $TB_EXPT_READINFO)) {
USERERROR("You do not have permission to view experiment template ".
if (! $template->AccessCheck($uid, $TB_EXPT_READINFO)) {
USERERROR("You do not have permission to modify experiment template ".
"$guid/$version!", 1);
}
header("Content-Type: text/plain");
......
......@@ -6,7 +6,7 @@
#
include("defs.php3");
include("showstuff.php3");
include("template_defs.php");
include_once("template_defs.php");
#
# Only known and logged in users can end experiments.
......@@ -100,9 +100,13 @@ if (! TBExptAccessCheck($uid, $exp_pid, $exp_eid, $TB_EXPT_MODIFY)) {
}
# Template Instance Experiments get special treatment in this page.
$isinstance = $EXPOSETEMPLATES && TBIsTemplateInstanceExperiment($exptidx);
if ($isinstance && $inout != "out") {
PAGEARGERROR("Invalid action for template instance");
$instance = NULL;
if ($EXPOSETEMPLATES) {
$instance = TemplateInstance::LookupByExptidx($exptidx);
if (! is_null($instance) && $inout != "out") {
PAGEARGERROR("Invalid action for template instance");
}
}
# Convert inout to informative text.
......@@ -133,7 +137,7 @@ elseif (!strcmp($inout, "restart")) {
$action = "restart";
}
if ($isinstance) {
if ($instance) {
echo "<font size=+2>Template Instance <b>";
}
else {
......@@ -162,7 +166,7 @@ if (!$confirmed) {
if ($force) {
echo "<font color=red><br>forcibly</br></font> ";
}
if ($isinstance) {
if ($instance) {
echo "terminate template instance";
}
else {
......@@ -226,10 +230,10 @@ if (!$confirmed) {
#
TBGroupUnixInfo($exp_pid, $exp_gid, $unix_gid, $unix_name);
if ($isinstance) {
if (! TBPidEid2Template($exp_pid, $exp_eid, $guid, $version, $instidx)) {
TBERROR("Could not map $pid/$eid to its template!", 1);
}
if ($instance) {
$guid = $instance->guid();
$version = $instance->vers();
echo "<br>\n";
echo "<b>Terminating template instance!</b> ... ";
echo "this will take a few minutes; please be patient.";
......@@ -253,7 +257,7 @@ $args = ($idleswap ? "-i" : ($autoswap ? "-a" : ""));
$retval = SUEXEC($uid, "$exp_pid,$unix_gid",
($force ?
"webidleswap $args $exp_pid $exp_eid" :
($isinstance ?
($instance ?
"webtemplate_swapout -e $exp_eid $guid/$version" :
"webswapexp -s $inout $exp_pid $exp_eid")),
SUEXEC_ACTION_IGNORE);
......@@ -279,7 +283,7 @@ if ($retval) {
echo "<blockquote><pre>$suexec_output<pre></blockquote>";
}
else {
if ($isinstance) {
if ($instance) {
STARTLOG($pid, $eid);
}
elseif ($isbatch) {
......
......@@ -5,7 +5,7 @@
# All rights reserved.
#
include("defs.php3");
include("template_defs.php");
include_once("template_defs.php");
#
# No PAGEHEADER since we spit out a Location header later. See below.
......@@ -310,9 +310,6 @@ if (!isset($formfields[tid]) || $formfields[tid] == "") {
elseif (!TBvalid_eid($formfields[tid])) {
$errors["Template ID"] = TBFieldErrorString();
}
elseif (TBValidExperimentTemplate($formfields[pid], $formfields[tid])) {
$errors["Template ID"] = "Already in use";
}
#
# Description:
......@@ -507,23 +504,26 @@ if ($retval) {
return;
}
unset($guid);
if (TBPidTid2Template($pid, $tid, $guid, $version)) {
#
# Parse the last line of output. Ick.
#
if (preg_match("/^Template\s+(\w+)\/(\w+)\s+/",
$suexec_output_array[count($suexec_output_array)-1],
$matches)) {
$guid = $matches[1];
$vers = $matches[2];
echo "<script type='text/javascript' language='javascript'>\n";
echo "PageReplace('template_show.php?guid=$guid&version=$version');\n";
echo "PageReplace('template_show.php?guid=$guid&version=$vers');\n";
echo "</script>\n";
}
#
# In case the above fails.
#
echo "Done!";
echo "<center><b>Done!</b></center>";
echo "<br><br>\n";
if (isset($guid)) {
SHOWTEMPLATE($guid, $version);
}
#
# Standard Testbed Footer
#
......
This diff is collapsed.
......@@ -5,7 +5,7 @@
# All rights reserved.
#
include("defs.php3");
include("template_defs.php");
include_once("template_defs.php");
#
# No PAGEHEADER since we spit out a Location header later. See below.
......@@ -28,7 +28,7 @@ $deletexmlfile = 0;
#
# Spit the form out using the array of data.
#
function SPITFORM($formfields, $parameters, $errors)
function SPITFORM($instance, $formfields, $parameters, $errors)
{
global $TBDB_EIDLEN;
global $guid, $version, $eid;
......@@ -36,7 +36,8 @@ function SPITFORM($formfields, $parameters, $errors)
PAGEHEADER("Start an Experiment Run");
echo "<center>\n";
SHOWTEMPLATE($guid, $version);
$template = $instance->template();
$template->Show();
echo "</center>\n";
echo "<br><br>\n";
......@@ -171,38 +172,33 @@ if (!TBvalid_eid($eid)) {
}
#
# Check to make sure this is a valid template.
# Check to make sure this is a valid template and user has permission.
#
if (! TBValidExperimentTemplate($guid, $version)) {
$template = Template::Lookup($guid, $version);
if (!$template) {
USERERROR("The experiment template $guid/$version is not a valid ".
"experiment template!", 1);
}
# Need this below.
if (! TBGuid2PidGid($guid, $pid, $gid)) {
TBERROR("Could not get template pid,gid for template $guid", 1);
if (! $template->AccessCheck($uid, $TB_EXPT_MODIFY)) {
USERERROR("You do not have permission to modify experiment template ".
"$guid/$version!", 1);
}
# Need these below.
$pid = $template->pid();
$gid = $template->gid();
if (($exptidx = TBExptIndex($pid, $eid)) < 0) {
TBERROR("Could not instance IDX for template instance $guid/$eid", 1);
TBERROR("No such experiment '$eid' for template $guid/$version/$eid", 1);
}
#
# Check to make sure and a valid instance that is actually swapped in.
#
if (! TBValidExperimentTemplateInstance($guid, $version, $exptidx)) {
USERERROR("Experiment Template Instance $guid/$version/$exptidx is not ".
"a valid experiment template instance!", 1);
}
TBTemplateInstanceIndex($guid, $version, $exptidx, $instance_idx);
# We need the eid for passing to the shell.
#
# Verify Permission.
#
if (! TBExptTemplateAccessCheck($uid, $guid, $TB_EXPT_UPDATE)) {
USERERROR("You do not have permission to instantiate experiment template ".
"$guid/$version!", 1);
$instance = TemplateInstance::LookupByExptidx($exptidx);
if (!$instance) {
TBERROR("Template Instance $guid/$version/$exptidx is not ".
"a valid experiment template instance!", 1);
}
#
......@@ -212,14 +208,12 @@ if (!isset($exprun)) {
#
#
#
TBTemplateNextExperimentRun($guid, $version, $exptidx, $nextidx);
$defaults['runid'] = "T${nextidx}";
$defaults['runid'] = $instance->NextRunID();
#
# Get the current bindings for the template instance.
#
TBTemplateInstanceBindings($guid, $version, $instance_idx, $bindings);
$instance->Bindings($bindings);
#
# Allow formfields that are already set to override defaults
......@@ -230,7 +224,7 @@ if (!isset($exprun)) {
}
}
SPITFORM($defaults, $bindings, 0);
SPITFORM($instance, $defaults, $bindings, 0);
PAGEFOOTER();
return;
}
......@@ -238,11 +232,6 @@ elseif (! isset($formfields)) {
PAGEARGERROR();
}
# Need this below.
if (! TBGuid2PidGid($guid, $pid, $gid)) {
TBERROR("Could not get template pid,gid for template $guid", 1);
}
#
# Okay, validate form arguments.
#
......@@ -283,7 +272,7 @@ else {
#
# Parameters. The XML file overrides stuff in the form.
#
TBTemplateFormalParameters($guid, $version, $parameter_masterlist);
$template->FormalParameters($parameter_masterlist);
if (count($parameter_masterlist)) {
if (isset($formfields[parameter_xmlfile]) &&
$formfields[parameter_xmlfile] != "") {
......@@ -338,7 +327,7 @@ if (count($parameter_masterlist)) {
}
if (count($errors)) {
SPITFORM($formfields, $parameters, $errors);
SPITFORM($instance, $formfields, $parameters, $errors);
PAGEFOOTER();
exit(1);
}
......@@ -346,9 +335,6 @@ if (count($errors)) {
#
# Grab the unix GID for running scripts.
#
if (! TBGuid2PidGid($guid, $pid, $gid)) {
TBERROR("Could not get template pid,gid for template $guid", 1);
}
TBGroupUnixInfo($pid, $gid, $unix_gid, $unix_name);
#
......@@ -365,8 +351,17 @@ echo "<font size=+2>Experiment Template <b>" .
"</b></font>\n";
echo "<br><br>\n";
echo "<b>Starting Experiment run</b> ... ";
echo "<script type='text/javascript' language='javascript' ".
" src='template_sup.js'>\n";
echo "</script>\n";
echo "<center>\n";
echo "<b>Starting experiment run!</b> ...<br>\n";
echo "This will take a few moments; please be patient.<br>\n";
echo "<br><br>\n";
echo "<img id='busy' src='busy.gif'><span id='loading'> Working ...</span>";
echo "<br><br>\n";
echo "</center>\n";
flush();
#
......@@ -376,6 +371,11 @@ $retval = SUEXEC($uid, "$pid,$unix_gid",
"webtemplate_exprun $command_options $guid/$version",
SUEXEC_ACTION_IGNORE);
/* Clear the 'loading' indicators above */
echo "<script type='text/javascript' language='javascript'>\n";
echo "ClearLoadingIndicators();\n";
echo "</script>\n";
if ($deletexmlfile) {
unlink($parameter_xmlfile);
}
......@@ -394,7 +394,15 @@ if ($retval) {
return;
}
STARTLOG($pid, $eid);
echo "<script type='text/javascript' language='javascript'>\n";
echo "PageReplace('template_show.php?guid=$guid&version=$version');\n";
echo "</script>\n";
#
# In case the above fails.
#
echo "<center><b>Done!</b></center>";
echo "<br><br>\n";
#
# Standard Testbed Footer
......
......@@ -5,12 +5,11 @@
# All rights reserved.
#
include("defs.php3");
include("template_defs.php");
include_once("template_defs.php");
#
# This script generates the contents of an image. No headers or footers,
# just spit back an image. The thumbs are public, so no checking is done.
# To obfuscate, do not use pid/eid, but rather use the resource index.
# just spit back an image.
#
#
......@@ -39,38 +38,31 @@ function SPITERROR()
readfile("coming-soon-thumb.gif");
}
function SPITGRAPH($guid)
function SPITGRAPH($template)
{
#
# Get the data from the DB.
#
$query_result =
DBQueryWarn("select image from experiment_template_graphs ".
"where parent_guid='$guid'");
$data = NULL;
if (!$query_result || !mysql_num_rows($query_result)) {
# No Data. Spit back a stub image.
if ($template->GraphImage($data) != 0 || $data == NULL || $data == "") {
SPITERROR();
return;
}
$row = mysql_fetch_array($query_result);
$data = $row['image'];
if ($data != "") {
else {
header("Content-type: image/png");
echo "$data";
}
else {
SPITERROR();
}
}
$template = Template::LookupRoot($guid);
if (!$template) {
# Bad template; spit back a stub image.
SPITERROR();
return;
}
#
# If the request did not specify a zoom, return whatever we have.
#
if (!isset($zoom)) {
SPITGRAPH($guid);
SPITGRAPH($template);
return;
}
......@@ -79,10 +71,8 @@ if (!isset($zoom)) {
#
$optarg = "-z " . ($zoom == "in" ? "in" : "out");
if (! TBGuid2PidGid($guid, $pid, $gid)) {
TBERROR("Could not get template pid,gid for template $guid", 0);
SPITERROR();
}
$pid = $template->pid();
$gid = $template->gid();
TBGroupUnixInfo($pid, $gid, $unix_gid, $unix_name);
$retval = SUEXEC($uid, "$pid,$unix_gid", "webtemplate_graph $optarg $guid",
......@@ -92,7 +82,7 @@ if ($retval) {
SPITERROR();
}
else {
SPITGRAPH();
SPITGRAPH($template);
}
#
......
......@@ -5,7 +5,7 @@
# All rights reserved.
#
include("defs.php3");
include("template_defs.php");
include_once("template_defs.php");
#
# Only known and logged in users can look at experiments.
......@@ -46,17 +46,14 @@ else {
PAGEHEADER("Experiment Template History");
#
# Check to make sure this is a valid template.
# Check to make sure this is a valid template and user has permission.
#
if (! TBValidExperimentTemplate($guid, $version)) {
$template = Template::Lookup($guid, $version);
if (!$template) {
USERERROR("The experiment template $guid/$version is not a valid ".
"experiment template!", 1);
}
#
# Verify Permission.
#
if (! TBExptTemplateAccessCheck($uid, $guid, $TB_EXPT_READINFO)) {
if (! $template->AccessCheck($uid, $TB_EXPT_READINFO)) {
USERERROR("You do not have permission to view experiment template ".
"$guid/$version!", 1);
}
......@@ -67,7 +64,7 @@ echo "<font size=+2>Experiment Template <b>" .
"</b></font>\n";
echo "<br><br>\n";
SHOWTEMPLATEHISTORY($guid, $version, $expand);
$template->ShowHistory($expand);
#
# Standard Testbed Footer
......