Commit b3155874 authored by Leigh Stoller's avatar Leigh Stoller

Add a toggle for "global" to the image descriptor; its something

we change often.
parent 8ed26b13
......@@ -233,6 +233,25 @@ class Image
return $newimage;
}
#
# Flip global bit. If making it global, turn off shared.
# Also, if an EZ image, flip the bit on the os_info entry too.
#
function SetGlobal($mode) {
$id = $this->imageid();
$mode = ($mode ? 1 : 0);
$extra = ($mode ? ",shared=0" : "");
DBQueryFatal("update images set global='$mode' $extra ".
"where imageid='$id'");
if ($this->ezid()) {
DBQueryFatal("update os_info set shared='$mode' ".
"where osid='$id'");
}
return 0;
}
#
# Class function to edit an image descriptor.
#
......@@ -385,13 +404,12 @@ class Image
$gid_idx= $user->uid_idx();
#
# Global ImageIDs can be read by anyone but written by Admins only.
# Global ImageIDs can be read by anyone but written with permission.
#
if ($global) {
if ($access_type == $TB_IMAGEID_READINFO) {
return 1;
}
return 0;
}
#
......@@ -661,11 +679,10 @@ class Image
<td>Global?: </td>
<td class=left>\n";
if ($globalid)
echo "Yes";
else
echo "No";
$globalflip = ($globalid ? 0 : 1);
$globalval = ($globalid ? "Yes" : "No");
echo "$globalval (<a href=toggle.php?imageid=$imageid".
"&type=imageglobal&value=$globalflip>Toggle</a>)";
echo " </td>
</tr>\n";
......
<?php
#
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -42,7 +42,7 @@ $isadmin = ISADMIN();
# List of valid toggles
$toggles = array("adminon", "webfreeze", "cvsweb", "lockdown", "stud",
"cvsrepo_public", "workbench", "hiderun", "widearearoot",
"skipvlans");
"imageglobal", "skipvlans");
# list of valid values for each toggle
$values = array("adminon" => array(0,1),
......@@ -54,6 +54,7 @@ $values = array("adminon" => array(0,1),
"cvsrepo_public" => array(0,1),
"workbench" => array(0,1),
"widearearoot" => array(0,1),
"imageglobal" => array(0,1),
"hiderun" => array(0,1));
# list of valid extra variables for the each toggle, and mandatory flag.
......@@ -66,6 +67,7 @@ $optargs = array("adminon" => array(),
"cvsrepo_public" => array("pid" => 1),
"workbench" => array("pid" => 1),
"widearearoot" => array("user" => 1),
"imageglobal" => array("imageid" => 1),
"hiderun" => array("instance" => 1, "runidx" => 1));
# Mandatory page arguments.
......@@ -183,6 +185,23 @@ elseif ($type == "skipvlans") {
$zapurl = CreateURL("showexp", $experiment);
$experiment->SetSkipVlans($value);
}
elseif ($type == "imageglobal") {
include("imageid_defs.php");
# Must validate since we allow non-admins to do this.
if (! TBvalid_imageid($imageid)) {
PAGEARGERROR("Invalid characters in $imageid");
}
if (! ($image = Image::Lookup($imageid))) {
PAGEARGERROR("Image $image is not a valid image!");
}
if (!$isadmin &&
!$image->AccessCheck($this_user, $TB_IMAGEID_MODIFYINFO)) {
USERERROR("You do not have permission to toggle $type!", 1);
}
$zapurl = CreateURL("showimageid", $image);
$image->SetGlobal($value);
}
elseif ($type == "cvsrepo_public") {
# Must validate the pid since we allow non-admins to do this.
if (! TBvalid_pid($pid)) {
......
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