deleteosid.php3 5.66 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2
#
3
# Copyright (c) 2000-2002, 2006, 2007, 2008 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 B. Stoller's avatar
Leigh B. 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

#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
47
# Verify permission.
48
#
49
if (!$osinfo->AccessCheck($this_user, $TB_OSID_DESTROY)) {
50 51 52
    USERERROR("You do not have permission to delete OS Descriptor $osid!", 1);
}

53 54 55 56 57
#
# Standard Testbed Header
#
PAGEHEADER("Delete an OS Descriptor");

58 59
$conflicts = 0;

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
#
# 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 =
    DBQueryFatal("select * from images ".
		 "where part1_osid='$osid' or part2_osid='$osid' or ".
		 "      part3_osid='$osid' or part4_osid='$osid' or ".
		 "      default_osid='$osid'");

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'];
85
	$pid       = $row['pid'];
86 87 88 89 90 91 92 93

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

97
# Ditto for node_types ...
98
$query_result =
99 100 101 102 103 104
    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'");
105 106 107 108

if (mysql_num_rows($query_result)) {
    echo "<br> <center>
            The following node_types are using this OS Descriptor<br>
109
            in the osid, jail_osid and/or delay_osid fields.<br>
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
            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++;
}

133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
# 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++;
}

161
if ($conflicts) {
162 163
    PAGEFOOTER();
    return;
164 165 166 167 168 169 170 171
}

#
# 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.
#
172
if (isset($canceled) && $canceled) {
173
    echo "<center><h2><br>
174
          OS Descriptor removal canceled!
175 176 177 178 179 180
          </h2></center>\n";
    
    PAGEFOOTER();
    return;
}

181
if (!isset($confirmed)) {
182 183
    echo "<center><h2><br>
          Are you <b>REALLY</b>
184
          sure you want to delete OS Descriptor '$osname' in Project $pid?
185
          </h2>\n";
186 187

    $url = CreateURL("deleteosid", $osinfo);
188
    
189
    echo "<form action='$url' method=\"post\">";
190 191 192 193 194 195 196 197 198 199 200 201
    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;
}

#
# Delete the record,
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
202
DBQueryFatal("DELETE FROM os_info WHERE osid='$osid'");
203 204 205

echo "<p>
      <center><h2>
206
      OS Descriptor '$osname' in Project $pid has been deleted!
207 208
      </h2></center>\n";

209 210 211
echo "<br>
      <a href='showosid_list.php3'>Back to OS Descriptor list</a>\n";

212 213 214 215 216
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>