Commit 896c6bdd authored by Robert Ricci's avatar Robert Ricci
Browse files

Can now use this form to create new types, in addition to editing existing

ones. Provide defaults for many fields, when creating a new type.

Re-order a few fields to make a little more sense.

Add a javascript function to build a value for control_iface based on
what the user puts into control_net.
parent 0b877fc1
......@@ -26,12 +26,8 @@ if (! $isadmin) {
USERERROR("You do not have permission to edit node types!", 1);
}
#
# Verify page arguments.
#
if (!isset($node_type) ||
strcmp($node_type, "") == 0) {
PAGEARGERROR("You must provide a node type.");
if (!$new_type && (!isset($node_type) || !strcmp($node_type,""))) {
USERERROR("No type given!", 1);
}
#
......@@ -39,7 +35,7 @@ if (!isset($node_type) ||
#
function SPITFORM($node_type, $formfields, $errors)
{
global $osid_result, $imageid_result;
global $osid_result, $imageid_result, $new_type;
#
# Standard Testbed Header
......@@ -73,21 +69,46 @@ function SPITFORM($node_type, $formfields, $errors)
echo "</table><br>\n";
}
$formargs = "node_type=$node_type";
if ($new_type) {
$formargs .= "&new_type=1";
}
echo "<table align=center border=1>
<form action=editnodetype.php3?node_type=$node_type method=post>\n";
<form action=editnodetype.php3?$formargs method=post " .
" name=typeform>\n";
echo "<tr>
<td>Type:</td>
<td class=left>$node_type</td>
<td>Type:</td>\n";
if ($new_type) {
echo "<td class=left>
<input type=text
name=\"node_type\"
value=\"" . $node_type . "\"
size=10>
</td>\n";
} else {
echo "<td class=left>$node_type</td>
</tr>\n";
}
echo "<tr>
<td>Class:</td>
<td class=left>$formfields[class]</td>
<td>Class:</td>\n";
if ($new_type) {
echo "<td class=left>
<input type=text
name=\"formfields[class]\"
value=\"" . $formfields['class'] . "\"
size=10>
</td>\n";
} else {
echo "<td class=left>$formfields[class]</td>
</tr>\n";
}
echo "<tr>
<td>Processor:</td>
<td>Processor (eg. 'Pentium IV'):</td>
<td class=left>
<input type=text
name=\"formfields[proc]\"
......@@ -102,7 +123,7 @@ function SPITFORM($node_type, $formfields, $errors)
<input type=text
name=\"formfields[speed]\"
value=\"" . $formfields[speed] . "\"
size=5> MHZ
size=5> MHz
</td>
</tr>\n";
......@@ -136,19 +157,53 @@ function SPITFORM($node_type, $formfields, $errors)
</td>
</tr>\n";
WRITEOSIDMENU("Default OSID", "formfields[osid]",
$osid_result, $formfields[osid]);
#
# Function to set iface based on the control net
#
echo "<SCRIPT LANGUAGE=JavaScript>
function SetIface(theform)
{
var control_net = theform['formfields[control_net]'].value;
theform['formfields[control_iface]'].value =
'eth' + control_net;
}
</SCRIPT>\n";
echo "<tr>
<td>Control Network:</td>
<td>*Control Network:</td>
<td class=left>
<input type=text
name=\"formfields[control_net]\"
value=\"" . $formfields[control_net] . "\"
size=3>
size=3 onChange='SetIface(typeform);'>
</td>
</tr>\n";
echo "<tr>
<td>*Control Network Iface (eg. 'eth0'):</td>
<td class=left>
<input type=text
name=\"formfields[control_iface]\"
value=\"" . $formfields[control_iface] . "\"
size=6>
</td>
</tr>\n";
WRITEOSIDMENU("Default OSID", "formfields[osid]",
$osid_result, $formfields[osid]);
WRITEIMAGEIDMENU("Default ImageID", "formfields[imageid]",
$imageid_result, $formfields[imageid]);
WRITEOSIDMENU("Delay OSID", "formfields[delay_osid]",
$osid_result, $formfields[delay_osid]);
WRITEOSIDMENU("Jailbird OSID", "formfields[jail_osid]",
$osid_result, $formfields[jail_osid]);
echo "<tr>
<td>Power Cycle Time:</td>
<td class=left>
......@@ -159,8 +214,6 @@ function SPITFORM($node_type, $formfields, $errors)
</td>
</tr>\n";
WRITEIMAGEIDMENU("Default ImageID", "formfields[imageid]",
$imageid_result, $formfields[imageid]);
echo "<tr>
<td>Imageable?:</td>
......@@ -182,16 +235,6 @@ function SPITFORM($node_type, $formfields, $errors)
</td>
</tr>\n";
echo "<tr>
<td>Control Network Iface:</td>
<td class=left>
<input type=text
name=\"formfields[control_iface]\"
value=\"" . $formfields[control_iface] . "\"
size=6>
</td>
</tr>\n";
echo "<tr>
<td>Disktype (ad,da,ar):</td>
<td class=left>
......@@ -202,13 +245,6 @@ function SPITFORM($node_type, $formfields, $errors)
</td>
</tr>\n";
WRITEOSIDMENU("Delay OSID", "formfields[delay_osid]",
$osid_result, $formfields[delay_osid]);
WRITEOSIDMENU("Jailbird OSID", "formfields[jail_osid]",
$osid_result, $formfields[jail_osid]);
echo "<tr>
<td>isvirtnode:</td>
<td class=left>
......@@ -279,19 +315,32 @@ function SPITFORM($node_type, $formfields, $errors)
</table>\n";
}
#
# Suck the current info out of the database.
#
if (!preg_match("/^[-\w]+$/", $node_type)) {
USERERROR("$node_type contains illegal characters!", 1);
}
$query_result =
DBQueryFatal("select * from node_types where type='$node_type'");
if ($new_type) {
#
# We've starting a new node type - let's give some reasonable defaults
#
$defaults = array("class" => "pc", "power_time" => 60, "imageable" => 1,
"delay_capacity" => 2, "disktype" => "ad", "isvirtnode" => 0,
"isremotenode" => 0, "issubnode" => 0, "isplabdslice" => 0,
"issimnode" => 0, "simnode_capacity" => 20);
} else {
#
# We're editing an existing type - suck the current info out of the
# database.
#
if (!preg_match("/^[-\w]+$/", $node_type)) {
USERERROR("$node_type contains illegal characters!", 1);
}
$query_result =
DBQueryFatal("select * from node_types where type='$node_type'");
if (($defaults = mysql_fetch_array($query_result)) == 0) {
USERERROR("$node_type is not a valid node type!", 1);
if (($defaults = mysql_fetch_array($query_result)) == 0) {
USERERROR("$node_type is not a valid node type!", 1);
}
}
#
# We need a list of osids and imageids.
#
......@@ -316,7 +365,9 @@ if (! isset($submit)) {
#
# We do not allow these to be changed.
#
$formfields["class"] = $defaults["class"];
if (!$new_type) {
$formfields["class"] = $defaults["class"];
}
#
# Otherwise, must validate and redisplay if errors. Build up a DB insert
......@@ -325,6 +376,16 @@ $formfields["class"] = $defaults["class"];
$errors = array();
$inserts = array();
# Class (only for new types)
if ($new_type && isset($formfields['class']) && $formfields['class'] != "") {
if (! TBvalid_description($formfields['class'])) {
$errors["Class"] = TBFieldErrorString();
}
else {
$inserts["class"] = addslashes($formfields["class"]);
}
}
# Processor
if (isset($formfields[proc]) && $formfields[proc] != "") {
if (! TBvalid_description($formfields[proc])) {
......@@ -375,6 +436,30 @@ if (isset($formfields[max_interfaces]) && $formfields[max_interfaces] != "") {
}
}
# control_net
if (isset($formfields[control_net]) && $formfields[control_net] != "") {
if (! TBvalid_tinyint($formfields[control_net])) {
$errors["control_net"] = TBFieldErrorString();
}
else {
$inserts["control_net"] = $formfields[control_net];
}
} else {
$errors["control_net"] = "Field is required";
}
# control_iface
if (isset($formfields[control_iface]) && $formfields[control_iface] != "") {
if (! TBvalid_userdata($formfields[control_iface])) {
$errors["control_iface"] = TBFieldErrorString();
}
else {
$inserts["control_iface"] = addslashes($formfields[control_iface]);
}
} else {
$errors["control_iface"] = "Field is required";
}
# OSID
if (isset($formfields[osid]) && $formfields[osid] != "") {
if ($formfields[osid] == "none") {
......@@ -391,39 +476,61 @@ if (isset($formfields[osid]) && $formfields[osid] != "") {
}
}
# control_net
if (isset($formfields[control_net]) && $formfields[control_net] != "") {
if (! TBvalid_tinyint($formfields[control_net])) {
$errors["control_net"] = TBFieldErrorString();
# ImageID
if (isset($formfields[imageid]) && $formfields[imageid] != "") {
if ($formfields[imageid] == "none") {
$inserts["imageid"] = "";
}
elseif (! TBvalid_osid($formfields[imageid])) {
$errors["imageid"] = TBFieldErrorString();
}
elseif (! TBValidImageID($formfields[imageid])) {
$errors["imageid"] = "No such ImageID";
}
else {
$inserts["control_net"] = $formfields[control_net];
$inserts["imageid"] = $formfields[imageid];
}
}
# power_time
if (isset($formfields[power_time]) && $formfields[power_time] != "") {
if (! TBvalid_tinyint($formfields[power_time])) {
$errors["power_time"] = TBFieldErrorString();
# delay_osid
if (isset($formfields[delay_osid]) && $formfields[delay_osid] != "") {
if ($formfields[delay_osid] == "none") {
$inserts["delay_osid"] = "";
}
elseif (! TBvalid_osid($formfields[delay_osid])) {
$errors["delay_osid"] = TBFieldErrorString();
}
elseif (! TBValidOSID($formfields[delay_osid])) {
$errors["delay_osid"] = "No such osid";
}
else {
$inserts["power_time"] = $formfields[power_time];
$inserts["delay_osid"] = $formfields[delay_osid];
}
}
# ImageID
if (isset($formfields[imageid]) && $formfields[imageid] != "") {
if ($formfields[imageid] == "none") {
$inserts["imageid"] = "";
# jail_osid
if (isset($formfields[jail_osid]) && $formfields[jail_osid] != "") {
if ($formfields[jail_osid] == "none") {
$inserts["jail_osid"] = "";
}
elseif (! TBvalid_osid($formfields[imageid])) {
$errors["imageid"] = TBFieldErrorString();
elseif (! TBvalid_osid($formfields[jail_osid])) {
$errors["jail_osid"] = TBFieldErrorString();
}
elseif (! TBValidImageID($formfields[imageid])) {
$errors["imageid"] = "No such ImageID";
elseif (! TBValidOSID($formfields[jail_osid])) {
$errors["jail_osid"] = "No such osid";
}
else {
$inserts["imageid"] = $formfields[imageid];
$inserts["jail_osid"] = $formfields[jail_osid];
}
}
# power_time
if (isset($formfields[power_time]) && $formfields[power_time] != "") {
if (! TBvalid_tinyint($formfields[power_time])) {
$errors["power_time"] = TBFieldErrorString();
}
else {
$inserts["power_time"] = $formfields[power_time];
}
}
......@@ -447,16 +554,6 @@ if (isset($formfields[delay_capacity]) && $formfields[delay_capacity] != "") {
}
}
# control_iface
if (isset($formfields[control_iface]) && $formfields[control_iface] != "") {
if (! TBvalid_userdata($formfields[control_iface])) {
$errors["control_iface"] = TBFieldErrorString();
}
else {
$inserts["control_iface"] = addslashes($formfields[control_iface]);
}
}
# disktype
if (isset($formfields[disktype]) && $formfields[disktype] != "") {
if ($formfields[disktype] != "ad" &&
......@@ -469,38 +566,6 @@ if (isset($formfields[disktype]) && $formfields[disktype] != "") {
}
}
# delay_osid
if (isset($formfields[delay_osid]) && $formfields[delay_osid] != "") {
if ($formfields[delay_osid] == "none") {
$inserts["delay_osid"] = "";
}
elseif (! TBvalid_osid($formfields[delay_osid])) {
$errors["delay_osid"] = TBFieldErrorString();
}
elseif (! TBValidOSID($formfields[delay_osid])) {
$errors["delay_osid"] = "No such osid";
}
else {
$inserts["delay_osid"] = $formfields[delay_osid];
}
}
# jail_osid
if (isset($formfields[jail_osid]) && $formfields[jail_osid] != "") {
if ($formfields[jail_osid] == "none") {
$inserts["jail_osid"] = "";
}
elseif (! TBvalid_osid($formfields[jail_osid])) {
$errors["jail_osid"] = TBFieldErrorString();
}
elseif (! TBValidOSID($formfields[jail_osid])) {
$errors["jail_osid"] = "No such osid";
}
else {
$inserts["jail_osid"] = $formfields[jail_osid];
}
}
# isvirtnode
if (isset($formfields[isvirtnode]) && $formfields[isvirtnode] != "") {
if (! TBvalid_boolean($formfields[isvirtnode])) {
......@@ -579,9 +644,14 @@ foreach ($inserts as $name => $value) {
$insert_data[] = "$name='$value'";
}
DBQueryFatal("update node_types set ".
implode(",", $insert_data) . " ".
"where type='$node_type'");
if ($new_type) {
DBQueryFatal("insert into node_types set type='$node_type', ".
implode(",", $insert_data));
} else {
DBQueryFatal("update node_types set ".
implode(",", $insert_data) . " ".
"where type='$node_type'");
}
#
# Spit out a redirect so that the history does not include a post
......
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