Commit 1ef5ed02 authored by Leigh B. Stoller's avatar Leigh B. Stoller

Add web pages for creating and deletling imageids (the edit page was

done a couple of weeks ago).
parent de1318f3
<?php
include("defs.php3");
#
# Standard Testbed Header
#
PAGEHEADER("Delete an ImageID");
#
# Only known and logged in users can end experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
#
# Must provide the ImageID!
#
if (!isset($imageid) ||
strcmp($imageid, "") == 0) {
USERERROR("The ImageID was not provided!", 1);
}
if (! TBValidImageID($imageid)) {
USERERROR("The ImageID `$imageid' is not a valid ImageID.", 1);
}
#
# Verify permission.
#
if (!TBImageIDAccessCheck($uid, $imageid, $TB_IMAGEID_DESTROY)) {
USERERROR("You do not have permission to destroy ImageID $imageid!", 1);
}
#
# We run this twice. The first time we are checking for a confirmation
# by putting up a form. The next time through the confirmation will be
# set. Or, the user can hit the cancel button, in which case we should
# probably redirect the browser back up a level.
#
if ($canceled) {
echo "<center><h2><br>
ImageID termination canceled!
</h2></center>\n";
PAGEFOOTER();
return;
}
if (!$confirmed) {
echo "<center><h2><br>
Are you <b>REALLY</b>
sure you want to delete ImageID `$imageid?'
</h2>\n";
echo "<form action='deleteimageid.php3' method=post>";
echo "<input type=hidden name=imageid value='$imageid'>\n";
echo "<b><input type=submit name=confirmed value=Confirm></b>\n";
echo "<b><input type=submit name=canceled value=Cancel></b>\n";
echo "</form>\n";
echo "</center>\n";
PAGEFOOTER();
return;
}
#
# Delete the record,
#
DBQueryFatal("DELETE FROM images WHERE imageid='$imageid'");
echo "<p>
<center><h2>
ImageID `$imageid' has been deleted!
</h2></center>\n";
#
# Standard Testbed Footer
#
PAGEFOOTER();
?>
......@@ -92,16 +92,20 @@ $insert_result = DBQueryFatal($query_string);
SHOWIMAGEID($imageid, 0);
#
# Edit option
#
if (TBImageIDAccessCheck($uid, $imageid, $TB_IMAGEID_MODIFYINFO)) {
$fooid = rawurlencode($imageid);
echo "<p><center>
Do you want to edit this ImageID?
<A href='editimageid_form.php3?imageid=$fooid'>Yes</a>
</center>\n";
}
# Edit option.
$fooid = rawurlencode($imageid);
echo "<p><center>
Do you want to edit this ImageID?
<A href='editimageid_form.php3?imageid=$fooid'>Yes</a>
</center>\n";
echo "<br><br>\n";
# Delete option.
echo "<p><center>
Do you want to delete this ImageID?
<A href='deleteimageid.php3?imageid=$fooid'>Yes</a>
</center>\n";
#
# Standard Testbed Footer
......
<?php
include("defs.php3");
include("showstuff.php3");
#
# Standard Testbed Header
#
PAGEHEADER("Create a new ImageID");
#
# Only known and logged in users can create an OSID.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
$isadmin = ISADMIN($uid);
#
# First off, sanity check the form to make sure all the required fields
# were provided. I do this on a per field basis so that we can be
# informative. Be sure to correlate these checks with any changes made to
# the project form.
#
if (!isset($imageid) ||
strcmp($imageid, "") == 0) {
FORMERROR("ImageID");
}
if (!isset($pid) ||
strcmp($pid, "") == 0) {
FORMERROR("Select Project");
}
if (!isset($description) ||
strcmp($description, "") == 0) {
FORMERROR("ImageID Description");
}
if (!isset($loadpart) ||
strcmp($loadpart, "") == 0) {
FORMERROR("Starting DOS Slice");
}
if (!isset($loadlength) ||
strcmp($loadlength, "") == 0) {
FORMERROR("Number of DOS Slice");
}
if (!isset($path) ||
strcmp($path, "") == 0) {
FORMERROR("Path");
}
if (!isset($default_osid) ||
strcmp($default_osid, "") == 0) {
FORMERROR("Default OSID");
}
if (isset($loadaddr) &&
strcmp($loadaddr, "") == 0) {
unset($loadaddr);
}
#
# Check ID and others for sillyness.
#
if (! ereg("^[\.-_a-zA-Z0-9]+$", $imageid)) {
USERERROR("The ImageID must consist of alphanumeric characters and ".
"dash, dot, or underscore!", 1);
}
if (! ereg("^[\.-_a-zA-Z0-9\/]+$", $path)) {
USERERROR("The path contains invalid characters!", 1);
}
if (isset($loadaddr) &&
!ereg("^[\.0-9]+$", $loadaddr)) {
USERERROR("The load address contains invalid characters!", 1);
}
#
# Check sanity of the loadpart and loadlength.
#
if (! ereg("^[0-9]+$", $loadpart) ||
$loadpart < 0 || $loadpart > 4) {
USERERROR("The Load Partition must 0, or 1,2,3, or 4!", 1);
}
if (! ereg("^[0-9]+$", $loadlength) ||
$loadlength < 1 || $loadlength > 4) {
USERERROR("The Load Length must be 1,2,3, or 4!", 1);
}
if (($loadpart != 0 && $loadlength != 1)) {
USERERROR("Currently, only single slices or partial disks are allowed. ".
"If you specify a non-zero starting load partition, the load ".
"load length must be one (a single slice). If you specify zero ".
"for the starting load partition, then you can include any or ".
"all of the slices (1-4). Note that '0' means to start at the ".
"boot sector, while '1' means to start at the beginning of the ".
"first slice (typically starting at sector 63).", 1);
}
#
# Check sanity of the OSIDs for each slice. Permission checks not needed.
#
#
# Silently kill off all the extraneous OSIDs.
#
for ($i = 1; $i <= 4; $i++) {
$foo = "part${i}_osid";
$thisosid = $$foo;
if (($loadpart && $i == $loadpart) ||
(!$loadpart && $i <= $loadlength)) {
if (!isset($thisosid) ||
strcmp($thisosid, "none") == 0) {
USERERROR("You must select an OSID for Slice $i!", 1);
}
if (!TBValidOSID($thisosid)) {
USERERROR("The OSID '$this_osid' in not a valid OSID!", 1);
}
$$foo = "'$thisosid'";
}
else {
$$foo = "NULL";
}
}
if (!isset($default_osid) ||
strcmp($default_osid, "none") == 0) {
USERERROR("You must select a default boot OSID!", 1);
}
if (!TBValidOSID($default_osid)) {
USERERROR("The Default OSID '$default_osid' in not a valid OSID!", 1);
}
#
# Database limits
#
if (strlen($osid) > $TBDB_IMAGEID_IMAGEIDLEN) {
USERERROR("The ImageID name is too long! Please select another.", 1);
}
#
# Of course, the ImageID record may not already exist in the DB.
#
if (TBValidImageID($imageid)) {
USERERROR("The ImageID '$imageid' already exists! ".
"Please select another.", 1);
}
#
# Certain of these values must be escaped or otherwise sanitized.
#
$description = addslashes($description);
#
# Only admin types can set the PID to none (for sharing).
#
if (!isset($pid) ||
strcmp($pid, "none") == 0) {
if (!$isadmin) {
USERERROR("Only Emulab Administrators can specify 'None' for the ".
"project.", 1);
}
unset($pid);
}
else {
#
# Verify permission.
#
if (!TBProjAccessCheck($uid, $pid, 0, $TB_PROJECT_MAKEIMAGEID)) {
USERERROR("You do not have permission to create ImageID $imageid!", 1);
}
}
#
# And insert the record!
#
if (isset($pid)) {
$pid = "'$pid'";
}
else {
$pid = "NULL";
}
if (isset($loadaddr)) {
$loadaddr = "'$loadaddr'";
}
else {
$loadaddr = "NULL";
}
$query_result =
DBQueryFatal("INSERT INTO images ".
"(imageid, description, loadpart, loadlength, ".
" part1_osid, part2_osid, part3_osid, part4_osid, ".
" default_osid, path, pid, load_address) ".
"VALUES ".
" ('$imageid', '$description', $loadpart, $loadlength, ".
" $part1_osid, $part2_osid, $part3_osid, $part4_osid, ".
" '$default_osid', '$path', $pid, $loadaddr)");
#
# Dump os_info record.
#
SHOWIMAGEID($imageid, 0);
# Edit option.
$fooid = rawurlencode($imageid);
echo "<p><center>
Do you want to edit this ImageID?
<A href='editimageid_form.php3?imageid=$fooid'>Yes</a>
</center>\n";
echo "<br><br>\n";
# Delete option.
echo "<p><center>
Do you want to delete this ImageID?
<A href='deleteimageid.php3?imageid=$fooid'>Yes</a>
</center>\n";
#
# Standard Testbed Footer
#
PAGEFOOTER();
?>
<?php
include("defs.php3");
#
# Standard Testbed Header
#
PAGEHEADER("Create a new ImageID Form");
#
# Only known and logged in users can create a new OSID
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
$isadmin = ISADMIN($uid);
#
# See what projects the uid can do this in.
#
$projlist = TBProjList($uid, $TB_PROJECT_MAKEIMAGEID);
if (! count($projlist)) {
USERERROR("You do not appear to be a member of any Projects in which ".
"you have permission to create new ImageIDs.", 1);
}
#
# Get the OSID list that the user has access to.
#
if ($isadmin) {
$osid_result =
DBQueryFatal("select * from os_info ".
"where path='' or path is NULL ".
"order by osid");
}
else {
$osid_result =
DBQueryFatal("select distinct o.* from os_info as o ".
"left join group_membership as m ".
" on o.pid IS NULL or m.pid=o.pid ".
"where m.uid='$uid' and (path='' or path is NULL) ".
"order by o.pid,o.osid");
}
if (! mysql_num_rows($osid_result)) {
USERERROR("There are no OSIDs that you are able to use!", 1);
}
#
# Helper function to write out a menu.
#
function WRITEOSIDMENU($caption, $value, $osid_result)
{
echo "<tr>
<td>*$caption:</td>";
echo " <td><select name=$value>\n";
mysql_data_seek($osid_result, 0);
while ($row = mysql_fetch_array($osid_result)) {
$osid = $row[osid];
$pid = $row[pid];
if (!$pid)
$pid = "testbed";
echo "<option value='$osid'>$pid - $osid</option>\n";
}
echo "<option selected value=none>No OSID</option>\n";
echo " </select>";
echo " </td>
</tr>\n";
}
echo "<blockquote><blockquote>
Use this page to create a custom Image Identifier (ImageID).
Once you have one or more OSIDs and an ImageID, you can create your
own disk image that you can load on your nodes.
</blockquote></blockquote>\n";
echo "<table align=center border=1>
<tr>
<td align=center colspan=2>
<em>(Fields marked with * are required)</em>
</td>
</tr>
<form action='newimageid.php3' method=post>\n";
#
# ImageID:
#
# Note DB max length.
#
echo "<tr>
<td>*ImageID (no blanks):</td>
<td><input type=text name=imageid size=$TBDB_IMAGEID_IMAGEIDLEN
maxlength=$TBDB_IMAGEID_IMAGEIDLEN>
</td>
</tr>\n";
#
# Select Project
#
echo "<tr>
<td>*Select Project:</td>";
echo " <td><select name=pid>";
for ($i = 0; $i < count($projlist); $i++) {
$pid = $projlist[$i];
echo "<option value='$pid'>$pid</option>\n";
}
if ($isadmin) {
echo "<option value=none>None</option>\n";
}
echo " </select>";
echo " </td>
</tr>\n";
#
# Description
#
echo "<tr>
<td>*Description:</td>
<td><input type=text name=description size=50>
</td>
</tr>\n";
#
# Load Partition
#
echo "<tr>
<td>*Starting DOS Slice:<br>
(1-4, 0 means entire disk)</td>
<td><input type=text name=loadpart size=2>
</td>
</tr>\n";
#
# Load length
#
echo "<tr>
<td>*Number of DOS Slices:<br>
(1, 2, 3, or 4)</td>
<td><input type=text name=loadlength size=2>
</td>
</tr>\n";
WRITEOSIDMENU("Slice 1 OSID", "part1_osid", $osid_result);
WRITEOSIDMENU("Slice 2 OSID", "part2_osid", $osid_result);
WRITEOSIDMENU("Slice 2 OSID", "part3_osid", $osid_result);
WRITEOSIDMENU("Slice 3 OSID", "part3_osid", $osid_result);
WRITEOSIDMENU("Default OSID[<b>1</b>]", "default_osid", $osid_result);
#
# Path to Multiboot image.
#
echo "<tr>
<td>Path to Image[<b>2</b>]:<br>
(must reside in /proj)</td>
<td><input type=text name=path value='/proj/' size=40>
</td>
</tr>\n";
#
# Load Address
#
echo "<tr>
<td>Multicast Load Address[<b>3</b>]:</td>
<td><input type=text name=loadaddr size=30 maxlength=30>
</td>
</tr>\n";
echo "<tr>
<td align=center colspan=2>
<b><input type=submit value=Submit></b>
</td>
</tr>\n";
echo "</form>
</table>\n";
echo "<h4><blockquote><blockquote><blockquote>
<dl COMPACT>
<dt>[1]
<dd>The OSID (slice) that is active when the node boots up.
<dt>[2]
<dd>The image file must reside in the project directory so
that it is available via NFS.
<dt>[3]
<dd>Leave this blank unless you know what it means!
</dl>
</blockquote></blockquote></blockquote></h4>\n";
#
# Standard Testbed Footer
#
PAGEFOOTER();
?>
......@@ -40,13 +40,18 @@ SHOWIMAGEID($imageid, 0);
#
# Edit option.
#
if (TBImageIDAccessCheck($uid, $imageid, $TB_IMAGEID_MODIFYINFO)) {
$fooid = rawurlencode($imageid);
echo "<p><center>
Do you want to edit this ImageID?
<A href='editimageid_form.php3?imageid=$fooid'>Yes</a>
</center>\n";
}
$fooid = rawurlencode($imageid);
echo "<p><center>
Do you want to edit this ImageID?
<A href='editimageid_form.php3?imageid=$fooid'>Yes</a>
</center>\n";
echo "<br><br>\n";
echo "<p><center>
Do you want to delete this ImageID?
<A href='deleteimageid.php3?imageid=$fooid'>Yes</a>
</center>\n";
#
# Standard Testbed Footer
......
......@@ -70,6 +70,14 @@ while ($row = mysql_fetch_array($query_result)) {
}
echo "</table>\n";
# Create option.
echo "<p><center>
Do you want to create a new ImageID?
<A href='newimageid_form.php3'>Yes</a>
</center>\n";
echo "<br><br>\n";
#
# Standard Testbed Footer
#
......
......@@ -686,7 +686,6 @@ function SHOWIMAGEID($imageid, $edit) {
$part4_osid = $row[part4_osid];
$default_osid= $row[default_osid];
$path = $row[path];
$magic = $row[magic];
$pid = $row[pid];
$loadaddr = $row[load_address];
......@@ -695,8 +694,6 @@ function SHOWIMAGEID($imageid, $edit) {
if ($edit) {
if (!$description)
$description = "";
if (!$magic)
$magic = "";
if (!$path)
$path = "";
if (!$loadaddr)
......@@ -705,8 +702,6 @@ function SHOWIMAGEID($imageid, $edit) {
else {
if (!$description)
$description = "&nbsp";
if (!$magic)
$magic = "&nbsp";
if (!$path)
$path = "&nbsp";
if (!$loadaddr)
......@@ -814,20 +809,6 @@ function SHOWIMAGEID($imageid, $edit) {
echo " </td>
</tr>\n";
echo "<tr>
<td>Magic: </td>
<td class=left>\n";
if ($edit) {
echo "<input type=text name=magic size=60
maxlength=256 value='$magic'>";
}
else {
echo "$magic";
}
echo " </td>
</tr>\n";
echo "<tr>
<td>Load Address: </td>
<td class=left>\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