Commit 950dc3ab authored by Leigh Stoller's avatar Leigh Stoller

Move image deletion to the backend where is belongs.

Clean up the web page a bit, and add a checkbox to retain
the image file in case the user wants to keep it around,
but delete the descriptor (perhaps to recreate it).
parent d39a9127
......@@ -558,6 +558,47 @@ sub Update($$)
return Refresh($self);
}
#
# Delete a descriptor.
#
sub Delete($)
{
my ($self) = @_;
# Must be a real reference.
return -1
if (! ref($self));
my $imageid = $self->imageid();
DBQueryWarn("lock tables images write, os_info write, ".
"osidtoimageid write, os_submap write")
or return -1;
#
# If this is an EZ imageid, then delete the corresponding OSID too.
#
DBQueryWarn("delete from osidtoimageid where imageid='$imageid'")
or goto bad;
DBQueryWarn("delete from images where imageid='$imageid'")
or goto bad;
if ($self->ezid()) {
DBQueryWarn("delete from os_submap where osid='$imageid'")
or goto bad;
DBQueryWarn("delete from os_info where osid='$imageid'")
or goto bad;
}
DBQueryWarn("unlock tables")
or return -1;
delete($images{"$imageid"});
return 0;
bad:
DBQueryWarn("unlock tables");
return -1;
}
#
# Load the project object for an image
#
......
......@@ -49,10 +49,11 @@ SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \
addspecialdevice addspecialiface imagehash clone_image \
addvpubaddr imageinfo ctrladdr image_import \
prereserve_check tcppd addexternalnetwork \
update_sitevars
update_sitevars delete_image
WEB_SBIN_SCRIPTS= webnewnode webdeletenode webspewconlog webarchive_list \
webwanodecheckin webspewimage webdumpdescriptor
webwanodecheckin webspewimage webdumpdescriptor \
webdelete_image
WEB_BIN_SCRIPTS = webcreate_image websetdest weblinkmon_ctl webspewevents \
webdelay_config
LIBEXEC_SCRIPTS = spewleds webcopy spewsource webcvsweb xlogin webviewvc \
......@@ -63,7 +64,7 @@ CTRLSBIN_SCRIPTS= opsdb_control.proxy daemon_wrapper
# These scripts installed setuid, with sudo.
SETUID_BIN_SCRIPTS = create_image
SETUID_SBIN_SCRIPTS = grabwebcams checkquota spewconlog opsdb_control suchown \
anonsendmail readblob image_import
anonsendmail readblob image_import delete_image
SETUID_SUEXEC_SCRIPTS = xlogin
#
......
#!/usr/bin/perl -w
#
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
use English;
use strict;
use Getopt::Std;
use Data::Dumper;
#
# Delete an image (descriptor)
#
sub usage()
{
print("Usage: delete_image [-p] <imagename>\n".
"Options:\n".
" -p Purge the disk image file\n");
exit(-1);
}
my $optlist = "dp";
my $debug = 0;
my $purge = 0;
#
# Configure variables
#
my $TB = "@prefix@";
my $PROJROOT = "@PROJROOT_DIR@";
my $TBOPS = "@TBOPSEMAIL@";
my $friskiller = "$TB/sbin/frisbeehelper";
#
# Untaint the path
#
$ENV{'PATH'} = "$TB/bin:$TB/sbin:/bin:/usr/bin:/usr/bin:/usr/sbin";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Turn off line buffering on output
#
$| = 1;
#
# We don't want to run this script unless its the real version.
#
if ($EUID != 0) {
die("*** $0:\n".
" Must be setuid! Maybe its a development version?\n");
}
#
# Load the Testbed support stuff.
#
use lib "@prefix@/lib";
use EmulabConstants;
use libtestbed;
use User;
use Image;
# Protos
sub fatal($);
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"d"})) {
$debug = 1;
}
if (defined($options{"p"})) {
$purge = 1;
}
usage()
if (@ARGV != 1);
my $imageid = shift(@ARGV);
#
# Map invoking user to object.
#
my $this_user = User->ThisUser();
if (! defined($this_user)) {
fatal("You ($UID) do not exist!");
}
my $image = Image->Lookup($imageid);
if (!defined($image)) {
fatal("Image does not exist in the DB!");
}
if (!$image->AccessCheck($this_user, TB_IMAGEID_DESTROY())) {
fatal("You do not have permission to delete this image!");
}
$imageid = $image->imageid();
my $imagename = $image->imagename();
my $imagepid = $image->pid();
#
# Need root to delete the image file later.
#
$EUID = $UID;
#
# Be sure to kill off running frisbee. If a node is trying to load that
# image, well tough.
#
system("$friskiller -k $imageid");
if ($?) {
fatal("Could not kill running frisbee for $imageid!");
}
#
# Since admins will often delete image descriptors for users, we are
# setuid root. Flip for deleting the image file.
#
if ($purge) {
my $filename = $image->path();
$EUID = 0;
foreach my $file ($filename, "${filename}.sha1", "${filename}.bak") {
if (-e $file) {
if (! unlink($file)) {
SENDMAIL($TBOPS,
"delete_image: Could not remove image file",
"Could not remove $file\n".
"Someone will need to do this by hand.\n");
}
}
}
$EUID = $UID;
}
if ($image->Delete() != 0) {
fatal("Could not delete image!");
}
$this_user->SendEmail("delete_image: Image has been deleted",
"Image $imagepid,$imagename ($imageid) has been deleted by $this_user\n");
exit(0);
sub fatal($)
{
my ($mesg) = @_;
die("*** $0:\n".
" $mesg\n");
}
......@@ -34,9 +34,10 @@ $isadmin = ISADMIN();
#
# Verify page arguments.
#
$reqargs = RequiredPageArguments("image", PAGEARG_IMAGE);
$optargs = OptionalPageArguments("canceled", PAGEARG_BOOLEAN,
"confirmed", PAGEARG_BOOLEAN);
$reqargs = RequiredPageArguments("image", PAGEARG_IMAGE);
$optargs = OptionalPageArguments("canceled", PAGEARG_BOOLEAN,
"confirmed", PAGEARG_BOOLEAN,
"purgefile", PAGEARG_BOOLEAN);
# Need these below
$imageid = $image->imageid();
......@@ -81,16 +82,20 @@ if (isset($canceled) && $canceled) {
}
if (!isset($confirmed)) {
echo "<center><h2><br>
echo "<center><h3><br>
Are you <b>REALLY</b>
sure you want to delete Image '$imagename' in project $pid?
</h2>\n";
</h3>\n";
$url = CreateURL("deleteimageid", $image);
echo "<form action='$url' method=post>";
echo "<b><input type=submit name=confirmed value=Confirm></b>\n";
echo "<b><input type=submit name=canceled value=Cancel></b>\n";
echo "<br><br>\n";
echo "<input type=checkbox checked name=purgefile value=yes><br>";
echo "Uncheck this box if you want your image file preserved.<br> ";
echo "Typically, you want to leave the box checked.";
echo "</form>\n";
echo "</center>\n";
......@@ -106,48 +111,29 @@ if (!isset($confirmed)) {
PAGEFOOTER();
return;
}
if (isset($purgefile) && $purgefile) {
$purgeopt = "-p";
}
else {
$purgeopt = "";
}
#
# Need to make sure that there is no frisbee process running before
# we kill it.
# Invoke the backend script.
#
STARTBUSY("Removing imageid");
STARTBUSY("Deleting Image Descriptor ");
$retval = SUEXEC($uid, $unix_pgid,
"webfrisbeekiller $imageid", SUEXEC_ACTION_DIE);
DBQueryFatal("lock tables images write, os_info write, ".
"osidtoimageid write, os_submap write");
#
# If this is an EZ imageid, then delete the corresponding OSID too.
#
# Delete the record(s).
#
DBQueryFatal("DELETE FROM images WHERE imageid='$imageid'");
DBQueryFatal("DELETE FROM osidtoimageid where imageid='$imageid'");
if ($image->ezid()) {
DBQueryFatal("DELETE FROM os_info WHERE osid='$imageid'");
DBQueryFatal("DELETE FROM os_submap WHERE osid='$imageid'");
}
DBQueryFatal("unlock tables");
"webdelete_image $purgeopt $imageid", SUEXEC_ACTION_DIE);
STOPBUSY();
echo "<br>
echo "<center>
<h3>
Image '$imageid' in project $pid has been deleted!\n";
if ($image->path() && $image->path() != "") {
$path = $image->path();
echo "<br>
<br>
<font color=red>Please remember to delete $path!</font>\n";
}
echo "</h3>\n";
Image '$imagename' in project $pid has been deleted!\n
</h3>\n";
echo "<br>
<center>
<a href='showimageid_list.php3'>Back to Image Descriptor list</a>
</center>
<br><br>\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