Commit 51310e62 authored by Leigh Stoller's avatar Leigh Stoller

Commit functioning XML interface. At present, only isadmin people will

see this new page. That allows me to inflict pain on testbed
developers while we work out any kinks. These new pages implement an
XML interface to experiment creation.

Some new files:

beginexp_html.php3: A wrapper for the actual beginexp form. This page
includes the form, and then invokes the XMLRPC backend page.

beginexp_form.html: The original form code, split out from beginexp
and turned into a module that can be included into another file.  It
is slightly reorganized to make it easier to include as a module.  The
idea is that the plab_ez form will be recast in this model, reducing
some redundant complexity.

beginexp_xml.php3: The XML backend. The idea is that the html page
packages up the form arguments as an XMLRPC message, and invokes this
page with the XML goo encoded in the URL. It also passes along the
uid/cookie so that the authentication happens properly (https of
course). The page decodes the URL into PHP datatypes, and does much of
the same argument checking that beginexp used to do. Errors are stored
up in the same manner, but instead of spitting back html, it now spits
back a "structure", encoded in XML so that the _html page can put up a
new form. Basically, all output is sent back via an XML encoded
structure and displayed in a form that the invoking script deems
appropriate.

This gives us a pure XMLRPC interface, which we wrap with a form interface
so that it looks just like it did before.

The next step is to provide an alternate front end, but that will require
some certificate stuff that I have not worked out yet.

Oh, one more item. The syntax check stuff has been altered a bit.
Instead of invoking the beginexp page, which meant a zillion special
tests, I now invoke nscheck.php3 directly from the button. Took a few
extra lines of Javascript to do this, so watch out for problems there
too.
parent bbad8e64
This diff is collapsed.
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
#
# No PAGEHEADER since we spit out a Location header later. See below.
#
#
# Helper function to send back errors.
#
function EXPERROR()
{
global $formfields, $errors, $ifacetype;
SPITFORM($formfields, $errors);
PAGEFOOTER();
die("");
}
#
# Only known and logged in users can begin experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
#
# Handle pre-defined view styles
#
unset($view);
if (isset($view_style) && $view_style == "plab") {
$view['hide_proj'] = $view['hide_group'] = $view['hide_swap'] =
$view['hide_preload'] = $view['hide_batch'] = $view['quiet'] =
$view['plab_ns_message'] = 1;
include("plabexp_form.php3");
}
else {
include("beginexp_form.php3");
}
# Need this below;
$idleswaptimeout = TBGetSiteVar("idle/threshold");
#
# See what projects the uid can create experiments in. Must be at least one.
#
$projlist = TBProjList($uid, $TB_PROJECT_CREATEEXPT);
if (! count($projlist)) {
USERERROR("You do not appear to be a member of any Projects in which ".
"you have permission to create new experiments.", 1);
}
#
# On first load, display virgin form and exit.
#
if (!isset($beginexp)) {
# Allow initial formfields data.
INITFORM($formfields, $projlist);
PAGEFOOTER();
return;
}
#
# If we got form data then let the form code do some checking, and then
# return an XML representation of it. This allows us to test the XML
# handling, as if it came from the user.
#
if (isset($formfields)) {
$xmlcode = CHECKFORM($formfields, $projlist);
#
# Might not return. If the handler does not like what it sees, it
# will put up a new form. Otherwise we do the main checks below.
#
}
else {
PAGEHEADER("Begin a Testbed Experiment");
PAGEARGERROR();
}
#
# We are going to invoke the XML backend, and read back an XML representation
# of the results.
#
$url = "$TBBASE/beginexp_xml.php3?".
"nocookieuid=$uid&nocookieauth=" . $_COOKIE[$TBAUTHCOOKIE] .
"&xmlcode=" . urlencode($xmlcode);
$reply = "";
$fp = @fopen($url, "r");
if ($fp == FALSE) {
TBERROR("Could not invoke XML backend script. URL was:<br><br>\n".
"$url\n<br>", 1);
}
while (!feof($fp)) {
$reply .= fgets($fp, 1024);
}
fclose($fp);
#
# Error reporting is not well thought out yet. If the backend page gets
# an error, its possible no output will be sent back to us.
#
# Convert XML string back into PHP datatypes.
$foo = xmlrpc_decode_request($reply, $meth);
if (!isset($foo)) {
TBERROR("Could not decode XML reply! Form Input:\n\n" .
print_r($formfields, TRUE) . "\n\n".
"Output:\n\n$reply\n", 1);
}
$results = $foo[0];
if ($results[status] != "success") {
if ($results[status] == "xmlerror") {
#
# A formerror means we should respit the form with the error array.
#
SPITFORM($formfields, $results[errors]);
}
else {
PAGEHEADER("Begin a Testbed Experiment");
echo "<br><xmp>";
echo $results[message];
echo "</xmp><br>";
}
PAGEFOOTER();
return;
}
# Okay, we can spit back a header now that there is no worry of redirect.
PAGEHEADER("Begin a Testbed Experiment");
# Need these for output messages.
$exp_pid = $formfields[exp_pid];
$exp_id = $formfields[exp_id];
#
# Okay, time to do it.
#
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_id'>$exp_id</a></b>\n".
"</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 "<br><br>\n";
echo "While you are waiting, you can watch the log
in <a target=_blank href=spewlogfile.php3?pid=$exp_pid&eid=$exp_id>
realtime</a>.\n";
echo "<br>
</font>\n";
#
# Standard Testbed Footer
#
PAGEFOOTER();
?>
This diff is collapsed.
......@@ -75,6 +75,14 @@ putenv("HTTP_SCRIPT=1");
#
include("dbdefs.php3");
#
# Control how error messages are returned to the user. If the session is
# not actually "interactive" then do not send any output to the browser.
# Just save it up and let the page deal with it.
#
$session_interactive = 1;
$session_errorhandler = 0;
#
# Wrap up the mail function so we can prepend a tag to the subject
# line that indicates what testbed. Useful when multiple testbed
......@@ -105,8 +113,9 @@ function TBMAIL($to, $subject, $message, $headers = 0)
# should then terminate if required to do so.
#
function TBERROR ($message, $death, $xmp = 0) {
global $TBMAIL_WWW, $TBMAIL_OPS, $TBMAILADDR;
$script = $_SERVER['REQUEST_URI'];
global $TBMAIL_WWW, $TBMAIL_OPS, $TBMAILADDR, $TBMAILADDR_OPS;
global $session_interactive, $session_errorhandler;
$script = urldecode($_SERVER['REQUEST_URI']);
TBMAIL($TBMAIL_OPS,
"WEB ERROR REPORT",
......@@ -119,15 +128,13 @@ function TBERROR ($message, $death, $xmp = 0) {
"Errors-To: $TBMAIL_WWW");
if ($death) {
if ($xmp)
$message = "<XMP>$message</XMP>\n";
$msg = "<blockquote><pre>
$message
</pre></blockquote>
Could not continue. Please contact $TBMAILADDR\n";
PAGEERROR($msg);
if ($session_interactive)
PAGEERROR("Could not continue. Please contact $TBMAILADDR");
elseif ($session_errorhandler) {
$session_errorhandler("Could not continue. ".
"Please contact $TBMAILADDR_OPS", $death);
}
exit(1);
}
return 0;
}
......@@ -137,6 +144,18 @@ function TBERROR ($message, $death, $xmp = 0) {
#
function USERERROR($message, $death) {
global $TBMAILADDR;
global $session_interactive, $session_errorhandler;
if (! $session_interactive) {
if ($session_errorhandler)
$session_errorhandler($message, $death);
else
echo "$message";
if ($death)
exit(1);
return;
}
$msg = "<font size=+1><br>
$message
......
......@@ -372,9 +372,15 @@ function WRITESIDEBAR() {
#
WRITESIDEBARDIVIDER();
WRITESIDEBARBUTTON("Begin an Experiment",
$TBBASE, "beginexp.php3");
if (ISADMINISTRATOR()) {
WRITESIDEBARBUTTON("Begin an Experiment",
$TBBASE, "beginexp_html.php3");
}
else {
WRITESIDEBARBUTTON("Begin an Experiment",
$TBBASE, "beginexp.php3");
}
WRITESIDEBARBUTTON_NEW("Create a PlanetLab Slice",
$TBBASE, "plab_ez.php3");
......
......@@ -23,6 +23,7 @@ LOGGEDINORDIE($uid);
$speclocal = 0;
$specupload = 0;
$nsfile = "";
$exp_localnsfile = $formfields['exp_localnsfile'];
if (isset($exp_localnsfile) && strcmp($exp_localnsfile, "")) {
$speclocal = 1;
......@@ -61,10 +62,13 @@ if ($speclocal) {
# Do not allow anything outside of /users or /proj. I do not think there
# is a security worry, but good to enforce it anyway.
#
if (!preg_match("/^([-\@\w\.\/]+)$/", $exp_localnsfile)) {
USERERROR("NS File", "Pathname includes illegal characters", 1);
}
if (! ereg("^$TBPROJ_DIR/.*" ,$exp_localnsfile) &&
! ereg("^$TBUSER_DIR/.*" ,$exp_localnsfile) &&
! ereg("^$TBGROUP_DIR/.*" ,$exp_localnsfile)) {
USERERROR("You must specify a server resident in file in either ".
USERERROR("NS File: You must specify a server resident file in either ".
"$TBUSER_DIR/ or $TBPROJ_DIR/", 1);
}
......
......@@ -51,7 +51,8 @@ echo "<tr>
<input type=\"file\" name=\"exp_nsfile\" size=\"30\">
<br>
<br>
<input type=\"text\" name=\"exp_localnsfile\" size=\"40\">
<input type=\"text\" name=\"formfields[exp_localnsfile]\"
size=\"40\">
</td>
</tr>\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment