deleteosid.php3 4.97 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2002, 2006, 2007, 2008 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5 6
# All rights reserved.
#
7
include("defs.php3");
8
include_once("osinfo_defs.php");
9 10 11 12

#
# Standard Testbed Header
#
13
PAGEHEADER("Delete an OS Descriptor");
14 15 16 17

#
# Only known and logged in users can end experiments.
#
18 19 20
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
21 22

#
23 24 25 26 27
# Verify page arguments.
#
$reqargs = RequiredPageArguments("osinfo", PAGEARG_OSINFO);
$optargs = OptionalPageArguments("canceled", PAGEARG_BOOLEAN,
				 "confirmed", PAGEARG_BOOLEAN);
28

29 30 31 32
# Need these below
$osid   = $osinfo->osid();
$pid    = $osinfo->pid();
$osname = $osinfo->osname();
33 34

#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
35
# Verify permission.
36
#
37
if (!$osinfo->AccessCheck($this_user, $TB_OSID_DESTROY)) {
38 39 40
    USERERROR("You do not have permission to delete OS Descriptor $osid!", 1);
}

41 42
$conflicts = 0;

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#
# 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'];
68
	$pid       = $row['pid'];
69 70 71 72 73 74 75 76

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

80
# Ditto for node_types ...
81
$query_result =
82 83 84 85 86 87
    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'");
88 89 90 91

if (mysql_num_rows($query_result)) {
    echo "<br> <center>
            The following node_types are using this OS Descriptor<br>
92
            in the osid, jail_osid and/or delay_osid fields.<br>
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
            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++;
}

116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
# 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++;
}

144
if ($conflicts) {
145 146
    PAGEFOOTER();
    return;
147 148 149 150 151 152 153 154
}

#
# 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.
#
155
if (isset($canceled) && $canceled) {
156
    echo "<center><h2><br>
157
          OS Descriptor removal canceled!
158 159 160 161 162 163
          </h2></center>\n";
    
    PAGEFOOTER();
    return;
}

164
if (!isset($confirmed)) {
165 166
    echo "<center><h2><br>
          Are you <b>REALLY</b>
167
          sure you want to delete OS Descriptor '$osname' in Project $pid?
168
          </h2>\n";
169 170

    $url = CreateURL("deleteosid", $osinfo);
171
    
172
    echo "<form action='$url' method=\"post\">";
173 174 175 176 177 178 179 180 181 182 183 184
    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
185
DBQueryFatal("DELETE FROM os_info WHERE osid='$osid'");
186 187 188

echo "<p>
      <center><h2>
189
      OS Descriptor '$osname' in Project $pid has been deleted!
190 191
      </h2></center>\n";

192 193 194
echo "<br>
      <a href='showosid_list.php3'>Back to OS Descriptor list</a>\n";

195 196 197 198 199
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>