deleteosid.php3 6.67 KB
Newer Older
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2014 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{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/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
23
#
24
include("defs.php3");
25
include_once("osinfo_defs.php");
26 27 28 29

#
# Only known and logged in users can end experiments.
#
30 31 32
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
33 34

#
35 36 37 38 39
# Verify page arguments.
#
$reqargs = RequiredPageArguments("osinfo", PAGEARG_OSINFO);
$optargs = OptionalPageArguments("canceled", PAGEARG_BOOLEAN,
				 "confirmed", PAGEARG_BOOLEAN);
40

41 42 43 44
# Need these below
$osid   = $osinfo->osid();
$pid    = $osinfo->pid();
$osname = $osinfo->osname();
45

46 47 48 49 50 51 52 53 54
#
# If this is an EZ image, redirect to that page since we never
# delete the os_info without deleting the image.
#
if ($osinfo->ezid()) {
    header("Location: deleteimageid.php3?image=$osid");
    exit(0);
}

55
#
Leigh Stoller's avatar
Leigh Stoller committed
56
# Verify permission.
57
#
58
if (!$osinfo->AccessCheck($this_user, $TB_OSID_DESTROY)) {
59 60 61
    USERERROR("You do not have permission to delete OS Descriptor $osid!", 1);
}

62 63 64 65 66
#
# Standard Testbed Header
#
PAGEHEADER("Delete an OS Descriptor");

67 68
$conflicts = 0;

69 70 71 72 73
#
# Check to see if the OSID is being used. Force whatever images are using
# it to be deleted or changed. This subsumes EZ created images/osids.
#
$query_result =
74 75 76 77 78
    DBQueryFatal("select v.* from images as i ".
		 "left join image_versions as v on v.imageid=i.imageid ".
		 "where v.part1_osid='$osid' or v.part2_osid='$osid' or ".
		 "      v.part3_osid='$osid' or v.part4_osid='$osid' or ".
		 "      v.default_osid='$osid'");
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94

if (mysql_num_rows($query_result)) {
    echo "<center>The following images are using this OS Descriptor.<br>
          They must be deleted first!</center><br>\n";
          
    echo "<table border=1 cellpadding=2 cellspacing=2 align='center'>\n";

    echo "<tr>
              <td align=center>Image</td>
              <td align=center>PID</td>
          </tr>\n";

    while ($row = mysql_fetch_array($query_result)) {
	$imageid   = $row['imageid'];
	$url       = rawurlencode($imageid);
	$imagename = $row['imagename'];
95
	$pid       = $row['pid'];
96 97 98 99 100 101 102 103

	echo "<tr>
                <td><A href='showimageid.php3?imageid=$url'>$imagename</A>
                    </td>
	        <td>$pid</td>
              </tr>\n";
    }
    echo "</table>\n";
104 105 106
    $conflicts++;
}

107
# Ditto for node_types ...
108
$query_result =
109 110 111 112 113 114
    DBQueryFatal("select class,a.type from node_type_attributes as a ".
		 "left join node_types as nt on nt.type=a.type ".
		 "where (a.attrkey='default_osid' or ".
		 "       a.attrkey='jail_osid' or ".
		 "       a.attrkey='delay_osid') and ".
		 "       a.attrvalue='$osid'");
115 116 117 118

if (mysql_num_rows($query_result)) {
    echo "<br> <center>
            The following node_types are using this OS Descriptor<br>
119
            in the osid, jail_osid and/or delay_osid fields.<br>
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
            They must be deleted first!
          </center><br>\n";
          
    echo "<table border=1 cellpadding=2 cellspacing=2 align='center'>\n";

    echo "<tr>
              <td align=center>Class</td>
              <td align=center>Type</td>
          </tr>\n";

    while ($row = mysql_fetch_array($query_result)) {
	$class   = $row['class'];
	$type    = $row['type'];

	echo "<tr>
                <td>$class</td>
	        <td>$type</td>
              </tr>\n";
    }
    echo "</table>\n";
    $conflicts++;
}

143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
# Ditto for nodes ...
$query_result =
    DBQueryFatal("select node_id from nodes where def_boot_osid=$osid");

if (mysql_num_rows($query_result)) {
    echo "<br> <center>
            The following nodes are using this OS Descriptor<br>
            as their default boot OSID.<br>
            Their def_boot_osid must be changed first!
          </center><br>\n";
          
    echo "<table border=1 cellpadding=2 cellspacing=2 align='center'>\n";

    echo "<tr>
              <td align=center>Node</td>
          </tr>\n";

    while ($row = mysql_fetch_array($query_result)) {
	$node_id = $row['node_id'];

	echo "<tr>
                <td>$node_id</td>
              </tr>\n";
    }
    echo "</table>\n";
    $conflicts++;
}

171
if ($conflicts) {
172 173
    PAGEFOOTER();
    return;
174 175 176 177 178 179 180 181
}

#
# We run this twice. The first time we are checking for a confirmation
# by putting up a form. The next time through the confirmation will be
# set. Or, the user can hit the cancel button, in which case we should
# probably redirect the browser back up a level.
#
182
if (isset($canceled) && $canceled) {
183
    echo "<center><h2><br>
184
          OS Descriptor removal canceled!
185 186 187 188 189 190
          </h2></center>\n";
    
    PAGEFOOTER();
    return;
}

191
if (!isset($confirmed)) {
192 193
    echo "<center><h2><br>
          Are you <b>REALLY</b>
194
          sure you want to delete OS Descriptor '$osname' in Project $pid?
195
          </h2>\n";
196 197

    $url = CreateURL("deleteosid", $osinfo);
198
    
199
    echo "<form action='$url' method=\"post\">";
200 201 202 203 204 205 206 207 208 209
    echo "<b><input type=submit name=confirmed value=Confirm></b>\n";
    echo "<b><input type=submit name=canceled value=Cancel></b>\n";
    echo "</form>\n";
    echo "</center>\n";

    PAGEFOOTER();
    return;
}

#
210 211 212
# If this descriptor is not referenced by a deleted image descriptor
# we can just delete it. Otherwise we have to mark it deleted and save
# it.
213
#
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
$query_result =
    DBQueryFatal("select v.* from image_versions as v ".
		 "where v.deleted is not null and ".
		 "      (v.part1_osid='$osid' or v.part2_osid='$osid' or ".
		 "       v.part3_osid='$osid' or v.part4_osid='$osid' or ".
		 "       v.default_osid='$osid')");

if (mysql_num_rows($query_result)) {
    DBQueryFatal("delete os_info,os_info_versions from os_info ".
		 "inner join os_info_versions on ".
		 "      os_info.osid=os_info_versions.osid ".
		 "where os_info.osid='$osid'");
}
else {
    DBQueryFatal("update os_info_versions set deleted=now() ".
		 "WHERE osid='$osid'");
    # This is always deleted.
    DBQueryFatal("delete from os_info where osid='$osid'");
}
233 234 235

echo "<p>
      <center><h2>
236
      OS Descriptor '$osname' in Project $pid has been deleted!
237 238
      </h2></center>\n";

239 240 241
echo "<br>
      <a href='showosid_list.php3'>Back to OS Descriptor list</a>\n";

242 243 244 245 246
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>