Commit 7c304097 authored by Leigh B. Stoller's avatar Leigh B. Stoller

Minor cleanup of how we do features, osnames, and op_modes. Moved the

lists to a common "header" file, and change newosid and newimageid_ez
to grab from there. Also add notion of admin-only features (veths,
mlinks) and op_modes (NORMALv2) while I transition to new stuff.
parent c2733c7d
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
include("showstuff.php3");
include("osiddefs.php3");
#
# XXX
......@@ -26,32 +27,6 @@ $uid = GETLOGIN();
LOGGEDINORDIE($uid);
$isadmin = ISADMIN($uid);
#
# Default features. Needs to move someplace else!
#
$featurelist = array();
$featurelist["ping"] = "ping";
$featurelist["ssh"] = "ssh";
$featurelist["ipod"] = "ipod";
$featurelist["isup"] = "isup";
#
# Default OS strings. Needs to move someplace else!
#
$oslist = array();
$oslist["Linux"] = "Linux";
$oslist["FreeBSD"] = "FreeBSD";
$oslist["NetBSD"] = "NetBSD";
$oslist["Other"] = "Other";
#
# Default op modes. Needs to move someplace else!
#
$opmodes = array();
$opmodes["NORMALv1"] = "NORMALv1";
$opmodes["MINIMAL"] = "MINIMAL";
$opmodes["NORMAL"] = "NORMAL";
#
# See what projects the uid can do this in.
#
......@@ -77,8 +52,8 @@ $types_result =
#
function SPITFORM($formfields, $errors)
{
global $uid, $projlist, $isadmin, $types_result, $oslist, $opmodes,
$featurelist;
global $uid, $projlist, $isadmin, $types_result, $osid_oslist, $osid_opmodes,
$osid_featurelist;
global $TBDB_OSID_OSNAMELEN, $TBDB_NODEIDLEN;
global $TBDB_OSID_VERSLEN, $TBBASE;
......@@ -292,9 +267,12 @@ function SPITFORM($formfields, $errors)
<td><select name=\"formfields[os_name]\">
<option value=none>Please Select </option>\n";
while (list ($os, $value) = each($oslist)) {
while (list ($os, $userokay) = each($osid_oslist)) {
$selected = "";
if (!$userokay && !$isadmin)
continue;
if (isset($formfields[os_name]) &&
strcmp($formfields[os_name], $os) == 0)
$selected = "selected";
......@@ -353,10 +331,13 @@ function SPITFORM($formfields, $errors)
<td>OS Features[<b>3</b>]:</td>
<td>";
reset($featurelist);
while (list ($feature, $value) = each($featurelist)) {
reset($osid_featurelist);
while (list ($feature, $userokay) = each($osid_featurelist)) {
$checked = "";
if (!$userokay && !$isadmin)
continue;
if (isset($formfields["os_feature_$feature"]) &&
! strcmp($formfields["os_feature_$feature"], "checked"))
$checked = "checked";
......@@ -376,9 +357,12 @@ function SPITFORM($formfields, $errors)
<td><select name=\"formfields[op_mode]\">
<option value=none>Please Select </option>\n";
while (list ($mode, $value) = each($opmodes)) {
while (list ($mode, $userokay) = each($osid_opmodes)) {
$selected = "";
if (!$userokay && !$isadmin)
continue;
if (isset($formfields[op_mode]) &&
strcmp($formfields[op_mode], $mode) == 0)
$selected = "selected";
......@@ -532,12 +516,11 @@ function SPITFORM($formfields, $errors)
</ul>
</li>
<li> Guidelines for setting Operational Mode for your OS:
(Most images should use NORMALv1.)
(Most images should use " . TBDB_DEFAULT_OSID_OPMODE . ")
<ul>
<li> If it is based on a testbed image (one of our
RedHat Linux or FreeBSD images) use the same
op_mode as that image (should be NORMALv1,
or NORMAL for old images. Select it from the
op_mode as that image. Select it from the
<a href=\"$TBBASE/showosid_list.php3\"
>OS Descriptor List</a> to find out).
</li>
......@@ -572,7 +555,7 @@ if (! $submit) {
$defaults = array();
$defaults[loadpart] = "X";
$defaults[path] = "/proj/";
$defaults[op_mode] = "NORMALv1";
$defaults[op_mode] = TBDB_DEFAULT_OSID_OPMODE;
$defaults[os_feature_ping] = "checked";
$defaults[os_feature_ssh] = "checked";
$defaults[os_feature_ipod] = "checked";
......@@ -663,7 +646,7 @@ if (!isset($formfields[imagename]) ||
else {
if (! ereg("^[a-zA-Z0-9][-_a-zA-Z0-9\.\+]+$", $formfields[imagename])) {
$errors["Descriptor Name"] =
"Must be alphanumeric (includes _, -, +, and .)<br>".
"Must be alphanumeric (includes _, -, +, and .)<br>" .
"and must begin with an alphanumeric";
}
elseif (strlen($formfields[imagename]) > $TBDB_OSID_OSNAMELEN) {
......@@ -702,9 +685,15 @@ if (!isset($formfields[os_name]) ||
strcmp($formfields[os_name], "none") == 0) {
$errors["OS"] = "Not Selected";
}
elseif (! isset($oslist[$formfields[os_name]])) {
elseif (! preg_match("/^[-\w]+$/", $formfields[os_name])) {
$errors["OS"] = "Illegal Characters";
}
elseif (! array_key_exists($formfields[os_name], $osid_oslist)) {
$errors["OS"] = "Invalid OS";
}
elseif (! $osid_oslist[$formfields[os_name]] && !$isadmin) {
$errors["OS"] = "No enough permission";
}
#
# Version String
......@@ -778,10 +767,15 @@ elseif (! $isadmin) {
#
$os_features_array = array();
while (list ($feature, $value) = each($featurelist)) {
while (list ($feature, $userokay) = each($osid_featurelist)) {
if (isset($formfields["os_feature_$feature"]) &&
strcmp($formfields["os_feature_$feature"], "checked") == 0) {
$os_features_array[] = $feature;
if (!$userokay && !$isadmin) {
$errors["Feature - $feature"] = "Not enough permission";
}
else {
$os_features_array[] = $feature;
}
}
}
$os_features = join(",", $os_features_array);
......@@ -794,8 +788,14 @@ if (!isset($formfields[op_mode]) ||
strcmp($formfields[op_mode], "none") == 0) {
$errors["Op. Mode"] = "Not Selected";
}
elseif (! isset($opmodes[$formfields[op_mode]])) {
$errors["Op. Mode"] = "Invalid Op. Mode";
elseif (! preg_match("/^[-\w]+$/", $formfields[op_mode])) {
$errors["Op. Mode"] = "Illegal Characters";
}
elseif (! array_key_exists($formfields[op_mode], $osid_opmodes)) {
$errors["Op. Mode"] = "Invalid Operation Mode";
}
elseif (! $osid_opmodes[$formfields[os_mode]] && !$isadmin) {
$errors["Op. Mode"] = "No enough permission";
}
#
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
include("showstuff.php3");
include("osiddefs.php3");
#
# Standard Testbed Header
......@@ -37,16 +38,6 @@ if (!isset($description) ||
strcmp($description, "") == 0) {
FORMERROR("Description");
}
if (!isset($OS) ||
strcmp($OS, "") == 0 ||
(strcmp($OS, "Linux") &&
strcmp($OS, "FreeBSD") &&
strcmp($OS, "NetBSD") &&
strcmp($OS, "OSKit") &&
strcmp($OS, "Unknown"))) {
FORMERROR("Operating System (OS)");
}
if (isset($os_path) &&
strcmp($os_path, "") == 0) {
unset($os_path);
......@@ -57,8 +48,24 @@ if (isset($os_version) &&
}
#
# Check osname for sillyness.
# Check OS.
#
if (!isset($OS) ||
strcmp($OS, "") == 0 ||
strcmp($OS, "none") == 0) {
FORMERROR("Operating System (OS)");
}
elseif (! preg_match("/^[-\w]+$/", $OS)) {
USERERROR("Operating System (OS) - Illegal Characters", 1);
}
elseif (! array_key_exists($OS, $osid_oslist)) {
USERERROR("Operating System (OS) - Invalid OS", 1);
}
elseif (! $osid_oslist[$OS] && !$isadmin) {
USERERROR("Operating System (OS) - Not enough permission", 1);
}
# Check OSid.
if (! ereg("^[-_a-zA-Z0-9\.]+$", $osname)) {
USERERROR("The Descriptor name must consist of alphanumeric characters ".
"and dash, dot, or underscore!", 1);
......@@ -141,32 +148,42 @@ else {
}
#
# Form the os features set.
# OS Features.
#
# As a side effect of validating, form the os features set as a string
# for the insertion below.
#
$os_features_array = array();
if (isset($os_feature_ping)) {
$os_features_array[] = "ping";
}
if (isset($os_feature_ssh)) {
$os_features_array[] = "ssh";
}
if (isset($os_feature_ipod)) {
$os_features_array[] = "ipod";
}
if (isset($os_feature_ipod)) {
$os_features_array[] = "isup";
while (list ($feature, $userokay) = each($osid_featurelist)) {
$foo = "os_feature_$feature";
if (isset($$foo) && strcmp($$foo, "checked") == 0) {
if (!$userokay && !$isadmin) {
USERERROR("Feature '$feature' requires admin mode!", 1);
}
else {
$os_features_array[] = $feature;
}
}
}
$os_features = join(",", $os_features_array);
# Check op_mode
if (!isset($op_mode) ||
strcmp($op_mode, "") == 0 ||
(strcmp($op_mode, "MINIMAL") &&
strcmp($op_mode, "NORMAL") &&
strcmp($op_mode, "NORMALv1") &&
strcmp($op_mode, "Unknown"))) {
strcmp($op_mode, "none") == 0) {
FORMERROR("Operational Mode (op_mode)");
}
elseif (! preg_match("/^[-\w]+$/", $op_mode)) {
USERERROR("Operational Mode (op_mode) - Illegal Characters", 1);
}
elseif (! array_key_exists($op_mode, $osid_opmodes)) {
USERERROR("Operational Mode (op_mode) - Invalid op_mode", 1);
}
elseif (! $osid_opmodes[$OS] && !$isadmin) {
USERERROR("Operational Mode (o_mode) - Not enough permission", 1);
}
#
# And insert the record!
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# Copyright (c) 2000-2002, 2004 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
include("osiddefs.php3");
#
# Standard Testbed Header
......@@ -86,14 +87,15 @@ echo "<tr>
#
echo "<tr>
<td>*Select OS:</td>
<td><select name=OS>
<option value=none>Please Select &nbsp;</option>
<option value=Linux>Linux </option>
<option value=FreeBSD>FreeBSD </option>
<option value=NetBSD>NetBSD </option>
<option value=OSKit>OSKit </option>
<option value=Unknown>Other </option>
</select>
<td><select name=OS>\n";
while (list ($os, $userokay) = each($osid_oslist)) {
if (!$userokay && !$isadmin)
continue;
echo "<option value=$os>$os &nbsp </option>\n";
}
echo " </select>
</td>
</tr>\n";
......@@ -127,18 +129,22 @@ echo "<tr>
echo "<tr>
<td>OS Features:</td>
<td><input checked type=checkbox name=\"os_feature_ping\">ping &nbsp
<input checked type=checkbox name=\"os_feature_ssh\">ssh &nbsp
<input checked type=checkbox name=\"os_feature_ipod\">ipod &nbsp
<input checked type=checkbox name=\"os_feature_isup\">isup &nbsp
<p>
Guidelines for setting os_features for your OS:
<td>";
while (list ($feature, $userokay) = each($osid_featurelist)) {
if (!$userokay && !$isadmin)
continue;
echo "<input checked type=checkbox value=checked
name=\"os_feature_$feature\">$feature &nbsp\n";
}
echo "<p>Guidelines for setting os_features for your OS:
<ol>
<li> Mark ping and/or ssh if they are supported.
<li> If you use a testbed kernel, or are based on a
testbed kernel config, mark the ipod box.
<li> If it is based on a testbed image or sends its own
isup, mark isup.
isup, mark isup.
</ol>
</td>
</tr>\n";
......@@ -149,18 +155,25 @@ echo "<tr>
echo "<tr>
<td>*Operational Mode (op_mode):</td>
<td><select name=op_mode>
<option selected value=NORMALv1>NORMALv1 </option>
<option value=MINIMAL>MINIMAL &nbsp;</option>
<option value=NORMAL>NORMAL </option>
</select>
<p>
<td><select name=op_mode>\n";
while (list ($op_mode, $userokay) = each($osid_opmodes)) {
if (!$userokay && !$isadmin)
continue;
$selected = "";
if ($op_mode == TBDB_DEFAULT_OSID_OPMODE) {
$selected = "selected";
}
echo "<option $selected value=$op_mode>$op_mode &nbsp </option>\n";
}
echo " </select>
<p>
Guidelines for setting op_mode for your OS:
<ol>
<li> If it is based on a testbed image (one of our
RedHat Linux or FreeBSD images) use the same
op_mode as that image (should be NORMALv1,
or NORMAL for old images. Select it from the
RedHat Linux or FreeBSD images) use the same
op_mode as that image. Select it from the
<a href=\"$TBBASE/showosid_list.php3\"
>OS Descriptor List</a> to find out).
<li> If not, use MINIMAL.
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
# All rights reserved.
#
# Stuff for OSIDs. All this stuff should come from the DB instead!
#
# List of allowed OS types for creating OSIDs. The value is a user-okay flag.
$osid_oslist = array();
$osid_oslist["Linux"] = 1;
$osid_oslist["FreeBSD"] = 1;
$osid_oslist["NetBSD"] = 1;
$osid_oslist["Oskit"] = 0;
$osid_oslist["Other"] = 1;
# List of allowed OS features. The value is a user-okay flag.
$osid_featurelist = array();
$osid_featurelist["ping"] = 1;
$osid_featurelist["ssh"] = 1;
$osid_featurelist["ipod"] = 1;
$osid_featurelist["isup"] = 1;
$osid_featurelist["veths"] = 0;
$osid_featurelist["mlinks"] = 0;
# Default op modes. The value is a user-okay flag.
$osid_opmodes = array();
$osid_opmodes["NORMALv2"] = 0;
$osid_opmodes["NORMALv1"] = 1;
$osid_opmodes["MINIMAL"] = 1;
$osid_opmodes["NORMAL"] = 1;
define("TBDB_DEFAULT_OSID_OPMODE", "NORMALv1");
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