Commit 87045a9d authored by Mac Newbold's avatar Mac Newbold

Make swappability easy to toggle after expt creation. This hopefully will

soon be used by admins only to grant swappability. For now, it is open to
anyone who has expt modify access as well.

The change is visible everywhere SHOWEXP is called, like showexp.php3 for
instance.

Also introduced toggle.php, a generic toggle script, similar to
adminmode.php, but useful for just about anything. To add something, just
add it to the list, specify the valid values it can have, and add its
permission check and action. Now you don't need a different php page for
each toggle switch. This page is already set up to take over from
adminmode.php, but I didn't change things over just yet.

(Should this go in the changelog?)
parent ca0afe8a
......@@ -541,9 +541,13 @@ function SHOWEXP($pid, $eid) {
$nodes = $exprow["count(r.node_id)"];
if ($swappable)
$swappable = "Yes";
$swappable = "Yes
<a href=\"toggle.php?type=swappable&value=0&pid=$pid&eid=$eid\">
<img src=\"greenball.gif\" border=0 alt=\"Toggle\"></a>";
else
$swappable = "No";
$swappable = "No
<a href=\"toggle.php?type=swappable&value=1&pid=$pid&eid=$eid\">
<img src=\"redball.gif\" border=0 alt=\"Toggle\"></a>";
#
# Generate the table.
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 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.
#
#
# Only known and logged in users can do this.
#
# Note different test though, since we want to allow logged in
# users with expired passwords to change them.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
#
# This page is a generic toggle page, like adminmode.php3, but more
# generalized. There are a set of things you can toggle, and each of
# those items has a permission check and a set (pair) of valid values.
#
# Usage: toggle.php?type=swappable&value=1&pid=foo&eid=bar
# (type & value are required, others are optional and vary by type)
# List of valid toggles
$toggles = array("adminoff", "swappable");
# list of valid values for each toggle
$values = array("adminoff" => array(0,1),
"swappable" => array(0,1) );
if (! in_array($type, $toggles)) {
USERERROR("There is no toggle for $type!", 1);
}
if (! in_array($value, $values[$type])) {
USERERROR("The value '$value' is illegal for the $type toggle!", 1);
}
#
# Permissions checks, and do the toggle...
#
if ($type=="adminoff") {
# must be admin
if (! ($CHECKLOGIN_STATUS & CHECKLOGIN_ISADMIN)) {
USERERROR("You do not have permission to toggle $type!", 1);
}
# Admins can change status for other users.
if (!isset($target_uid)) { $target_uid = $uid; }
DBQueryFatal("update users set adminoff=$value where uid='$target_uid'");
} elseif ($type=="swappable") {
# must be admin OR must have permission to modify the expt...
if (! ($CHECKLOGIN_STATUS & CHECKLOGIN_ISADMIN) ||
! TBExptAccessCheck($uid, $pid, $eid, $TB_EXPT_MODIFY)) {
USERERROR("You do not have permission to toggle $type!", 1);
}
# require pid/eid
if (!isset($pid) || !isset($eid) ||
!TBValidExperiment($pid, $eid)) {
USERERROR("Experiment '$pid/$eid' is not valid!", 1);
}
DBQueryFatal("update experiments set swappable=$value ".
"where pid='$pid' and eid='$eid'");
#} elseif ($type=="foo") {
# Add more here...
#
} else {
USERERROR("Nobody has permission to toggle $type!", 1);
}
#
# Spit out a redirect
#
if (isset($HTTP_REFERER) && strcmp($HTTP_REFERER, "")) {
header("Location: $HTTP_REFERER");
}
else {
header("Location: $TBBASE/showuser.php3?target_uid=$target_uid");
}
?>
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