Commit 670184b9 authored by Robert Ricci's avatar Robert Ricci
Browse files

Add support for uploading TinyOS images. This page now accepts a

'nodetype=mote' parameter to display only the options that matter for
a mote.

This is implemented much like the menu and the beginexp page, with a
$view hash, set from the nodetype argument, that controls
showing/hiding different parts of the page.

Added a file uplaod box to be used for mote images, which calls Tim's
webcopy script to copy the file into place.

Doesn't work quite yet - for some reason, even though the call to
webcopy is succeeding, the destination file doesn't show up. So we
have a little bit of debugging to do still.

Not linked in from anywhere yet. Not sure what the right thing is -
shoud there be a list at the top of this page of all special nodetypes
it supports? Or should we just link it in from the TinyOS tutorial or
the mote type pages?
parent 11ca6e52
......@@ -37,15 +37,34 @@ if (! count($projlist)) {
"you have permission to create new Image descriptors.", 1);
}
#
# Options for using this page with different types of nodes
#
$nodetypes = array( "mote" );
if ($nodetype == "mote") {
$view = array('hide_partition' => 1, 'hide_os' => 1, 'hide_version' => 1,
'hide_snapshot' => 1, 'hide_features' => 1,
'hide_opmode' => 1, 'hide_footnotes' => 1);
$nodeclass = "mote";
} else {
# Defaults to PC view
$view = array('hide_upload' => 1);
$nodeclass = "pc";
}
#
# Need a list of node types. We join this over the nodes table so that
# we get a list of just the nodes that currently in the testbed, not
# just in the node_types table.
# just in the node_types table. Limit by class if given.
#
$types_result =
DBQueryFatal("select distinct n.type from nodes as n ".
$types_querystring = "select distinct n.type from nodes as n ".
"left join node_types as nt on n.type=nt.type ".
"where nt.imageable=1");
"where nt.imageable=1 ";
if ($nodeclass) {
$types_querystring .= " and nt.class='$nodeclass' ";
}
$types_result = DBQueryFatal($types_querystring);
#
# Spit the form out using the array of data.
......@@ -53,10 +72,19 @@ $types_result =
function SPITFORM($formfields, $errors)
{
global $uid, $projlist, $isadmin, $types_result, $osid_oslist, $osid_opmodes,
$osid_featurelist;
$osid_featurelist, $nodetype, $filename_extension;
global $TBDB_OSID_OSNAMELEN, $TBDB_NODEIDLEN;
global $TBDB_OSID_VERSLEN, $TBBASE;
global $view;
#
# Explanation of the $view argument: used to turn on and off display of
# various parts of the form, so that it can be used for different types
# of nodes. It's an associative array, with contents like: 'hide_partition'.
# In general, when an option is hidden, it is replaced with a hidden
# field from $formfields
#
echo "<center><b>
See the
<a href=tutorial/docwrapper.php3?docname=tutorial.html#CustomOS>
......@@ -127,7 +155,7 @@ function SPITFORM($formfields, $errors)
}
else if (theform['formfields[imagename]'].value != '') {
var filename = theform['formfields[imagename]'].value +
'.ndz';
'.$filename_extension';
if (global) {
theform['formfields[path]'].value =
......@@ -153,7 +181,17 @@ function SPITFORM($formfields, $errors)
<em>(Fields marked with * are required)</em>
</td>
</tr>
<form action='newimageid_ez.php3' method=post name=idform>\n";
<form action='newimageid_ez.php3' enctype=\"multipart/form-data\"
method=post name=idform>\n";
#
# Carry along the nodetype variable - have to do it here, so that's inside
# the form
#
if (isset($nodetype)) {
echo "<input type=hidden name=nodetype value='$nodetype'>";
}
#
# Select Project
......@@ -240,6 +278,9 @@ function SPITFORM($formfields, $errors)
#
# Load Partition
#
if ($view[hide_partition]) {
spithidden($formfields, 'loadpart');
} else {
echo "<tr>
<td>*Which DOS Partition[<b>1</b>]:<br>
(DOS partitions are numbered 1-4)</td>
......@@ -257,10 +298,14 @@ function SPITFORM($formfields, $errors)
echo " </select>";
echo " </td>
</tr>\n";
}
#
# Select an OS
#
if ($view[hide_os]) {
spithidden($formfields, 'os_name');
} else {
echo "<tr>
<td>*Operating System:<br>
(OS that is on the partition)</td>
......@@ -282,10 +327,14 @@ function SPITFORM($formfields, $errors)
echo " </select>
</td>
</tr>\n";
}
#
# Version String
#
if ($view[hide_version]) {
spithidden($formfields, 'os_version');
} else {
echo "<tr>
<td>*OS Version:<br>
(eg: 4.3, 7.2, etc.)</td>
......@@ -293,9 +342,11 @@ function SPITFORM($formfields, $errors)
<input type=text
name=\"formfields[os_version]\"
value=\"" . $formfields[os_version] . "\"
size=$TBDB_OSID_VERSLEN maxlength=$TBDB_OSID_VERSLEN>
size=$TBDB_OSID_VERSLEN
maxlength=$TBDB_OSID_VERSLEN>
</td>
</tr>\n";
}
#
# Path to image.
......@@ -314,6 +365,9 @@ function SPITFORM($formfields, $errors)
#
# Node to Snapshot image from.
#
if ($view[hide_snapshot]) {
spithidden($formfields, 'node');
} else {
echo "<tr>
<td>Node to Obtain Snapshot from[<b>2</b>]:</td>
<td class=left>
......@@ -323,10 +377,17 @@ function SPITFORM($formfields, $errors)
size=$TBDB_NODEIDLEN maxlength=$TBDB_NODEIDLEN>
</td>
</tr>\n";
}
#
# OS Features.
#
if ($view[hide_features]) {
reset($osid_featurelist);
while (list ($feature, $userokay) = each($osid_featurelist)) {
spithidden($formfields, "os_feature_$feature");
}
} else {
echo "<tr>
<td>OS Features[<b>3</b>]:</td>
<td>";
......@@ -348,10 +409,14 @@ function SPITFORM($formfields, $errors)
}
echo " </td>
</tr>\n";
}
#
# Operational Mode
#
if ($view[hide_opmode]) {
spithidden($formfields, 'op_mode');
} else {
echo "<tr>
<td>*Operational Mode[<b>4</b>]:</td>
<td><select name=\"formfields[op_mode]\">
......@@ -372,12 +437,16 @@ function SPITFORM($formfields, $errors)
echo " </select>
</td>
</tr>\n";
}
#
# Node Types.
#
if (!$view[hide_footnotes]) {
$footnote = "[<b>5</b>]";
}
echo "<tr>
<td>Node Types[<b>5</b>]:</td>
<td>Node Types${footnote}:</td>
<td>\n";
mysql_data_seek($types_result, 0);
......@@ -400,6 +469,9 @@ function SPITFORM($formfields, $errors)
#
# Whole Disk Image
#
if ($view[hide_snapshot]) {
spithidden($formfields, 'wholedisk');
} else {
echo "<tr>
<td>Whole Disk Image?[<b>6</b>]:</td>
<td class=left>
......@@ -414,10 +486,14 @@ function SPITFORM($formfields, $errors)
echo " > Yes
</td>
</tr>\n";
}
#
# Maxiumum concurrent loads
#
if ($view[hide_snapshot]) {
spithidden($formfields, 'max_concurrent');
} else {
echo "<tr>
<td>Maximum concurrent loads[<b>7</b>]:</td>
<td class=left>
......@@ -428,10 +504,14 @@ function SPITFORM($formfields, $errors)
</td>
</tr>\n";
}
#
# Shared?
#
if ($view[hide_snapshot]) {
spithidden($formfields, 'shared');
} else {
echo "<tr>
<td>Shared?:<br>
(available to all subgroups)</td>
......@@ -448,6 +528,23 @@ function SPITFORM($formfields, $errors)
echo " > Yes
</td>
</tr>\n";
}
#
# Upload an image file
#
if ($view[hide_upload]) {
#spithidden($formfields, 'upload_file');
} else {
echo "<tr>
<td>Upload a file:</td>
<td class=left>
<input type=file
name=\"upload_file\"
value=''
size=35></tr>";
}
if ($isadmin) {
#
......@@ -481,6 +578,7 @@ function SPITFORM($formfields, $errors)
echo "</form>
</table>\n";
if (!$view[hide_footnotes]) {
echo "<h4><blockquote>
<ol type=1 start=1>
<li> If you don't know what partition you have customized,
......@@ -546,6 +644,18 @@ function SPITFORM($formfields, $errors)
</li>
</ol>
</blockquote></h4>\n";
}
}
#
# If the given field is defined in the given set of fields, spit out a hidden
# form element for it
#
function spithidden($formfields, $field) {
if (isset($formfields[$field])) {
echo "<input type=hidden name=formfields[$field] value='" .
$formfields[$field] . "'>\n";
}
}
#
......@@ -553,6 +663,20 @@ function SPITFORM($formfields, $errors)
#
if (! $submit) {
$defaults = array();
$defaults[path] = "/proj/";
$defaults[shared] = "Nope";
if ($nodetype == "mote") {
# Defaults for mote-type nodes
$defaults[loadpart] = "1";
$defaults[op_mode] = TBDB_MINIMAL_OPMODE;
$defaults[os_name] = "TinyOS";
$defaults[os_version] = "1.1.0";
# Default to 'srec' files for use with uisp
$filename_extension = "srec";
} else {
# Defaulys for PC-type nodes
$defaults[loadpart] = "X";
$defaults[path] = "/proj/";
$defaults[op_mode] = TBDB_DEFAULT_OSID_OPMODE;
......@@ -565,6 +689,10 @@ if (! $submit) {
# mtypes checked in the virgin form.
$defaults[mtype_all] = "Yep";
# Default to imagezip ndz files
$filename_extension = "ndz";
}
#
# For users that are in one project and one subgroup, it is usually
# the case that they should use the subgroup, and since they also tend
......@@ -882,7 +1010,20 @@ $confirmationWarning = "";
# If user does not define a node to suck the image from,
# we seek confirmation.
#
if (! isset($node)) {
if ($nodetype == "mote") {
# We expect them to give us a file to upload
if (! isset($_FILES['upload_file'])) {
# We expect them to pick a node to take a snapshot from
$confirmationWarning .=
"<h2>You have not uploaded a file for this image.
If you continue, the image descriptor will be created,
but, you will need to copy your image into the pathname
you gave in the form yourself.<br />
Continue only if this is what you want.</h2>";
}
} else {
if (! isset($node)) {
# We expect them to pick a node to take a snapshot from
$confirmationWarning .=
"<h2>You have not defined a node to obtain a snapshot from!
If you continue, the image descriptor will be created,
......@@ -892,6 +1033,7 @@ if (! isset($node)) {
page for the new image and choosing
'Snapshot Node Disk into Image' from the menu.<br />
Continue only if this is what you want.</h2>";
}
}
#
......@@ -899,7 +1041,8 @@ if (! isset($node)) {
#
if (!isset($confirmed) && 0 != strcmp($confirmationWarning,"")) {
echo "<center><br />$confirmationWarning<br />";
echo "<form action='newimageid_ez.php3' method=post>";
echo "<form enctype=\"multipart/form-data\" action='newimageid_ez.php3'
method=post name=idform>";
#
# tramp all of their settings along.
#
......@@ -907,6 +1050,9 @@ if (!isset($confirmed) && 0 != strcmp($confirmationWarning,"")) {
while (list($key, $value) = each($formfields)) {
echo "<input type=hidden name=\"formfields[$key]\" value=\"$value\"></input>\n";
}
if (isset($nodetype)) {
echo "<input type=hidden name=nodetype value='$nodetype'>";
}
echo "<input type=hidden name='submit' value='Submit'>\n";
echo "<input type=submit name=confirmed value=Confirm>&nbsp;";
echo "<input type=submit name=cancelled value=Back>\n";
......@@ -1051,6 +1197,31 @@ if (isset($node)) {
the node at all!<br>\n";
}
#
# If we were given a file that represents the image, save that to the correct
# place now
#
if (isset($_FILES['upload_file']) &&
$_FILES['upload_file']['name'] != "" &&
$_FILES['upload_file']['name'] != "none") {
# Get the correct group information for this image
TBGroupUnixInfo($pid, $gid, $unix_gid, $unix_name);
$tmpfile = $_FILES['upload_file']['tmp_name'];
$localfile = $formfields['path'];
if (! preg_match("/^[-\w\.\/]*$/", $localfile)) {
# Taint check shell arguments always!
$errors["Image File"] = "Invalid characters";
} else {
# Note - the script we call takes care of making sure that the local
# filename is in /proj or /groups
$retval = SUEXEC($uid, "$pid,$unix_gid", "webcopy $tmpfile $localfile",
SUEXEC_ACTION_DUPDIE);
}
}
#
# Standard Testbed Footer
#
......
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