wideareakeys.php3 5.41 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2004, 2006, 2007 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/>.
# 
# }}}
23 24 25 26 27 28
#
include("defs.php3");

#
# Only known and logged in users can do this.
#
29 30 31
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
32 33 34 35 36

if (!$isadmin) {
    USERERROR("You do not have permission to view this page!", 1);
}

37 38 39 40 41 42 43
#
# Verify Page arguments
#
$optargs = OptionalPageArguments("deletekey",  PAGEARG_STRING,
				 "canceled",   PAGEARG_STRING,
				 "confirmed",  PAGEARG_STRING);

44 45 46 47 48
if (isset($deletekey)) {
    #
    # Get the actual key.
    #
    $query_result =
49 50
	DBQueryFatal("select wa.*,i.node_id from widearea_privkeys as wa ".
		     "left join interfaces as i on wa.IP=i.IP ".
51
		     "where privkey='$deletekey'");
52 53

    if (! mysql_num_rows($query_result)) {
54
	USERERROR("No such widearea private key!", 1);
55
    }
56
    $row     = mysql_fetch_array($query_result);
57 58 59 60 61
    $name    = $row["user_name"];
    $email   = $row["user_email"];
    $when    = $row["requested"];
    $IP      = $row["IP"];
    $nodeid  = $row["node_id"];
62 63 64 65 66 67 68

    #
    # 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.
    #
69
    if (isset($canceled) && $canceled) {
70
        PAGEHEADER("Widearea Private Key Deletion Request");
71 72
    
        echo "<center><h2><br>
73
              Widearea Private Key deletion has been canceled!
74 75 76
              </h2></center>\n";

        echo "<br>
77
              Back to <a href=wideareakeys.php3>Back to Widearea Keys.</a>\n";
78 79 80 81 82
    
        PAGEFOOTER();
        return;
    }

83
    if (!isset($confirmed)) {
84
        PAGEHEADER("Widearea Private Key Deletion Request");
85

86
	echo "<center><h3><br>
87
              Are you <b>REALLY</b> sure you want to delete this Key?<br>
88
              </h3>\n";
89 90 91 92
	echo "</center>\n";

	echo "<table align=center border=1 cellpadding=2 cellspacing=2>\n";
	echo "<tr>
93 94 95
  	          <td>$name</td>
  	          <td>$email</td>
  	          <td>$IP</td>
96
  	          <td>$nodeid</td>
97
	          <td>$when</td>
98 99 100
             </tr>\n";
	echo "</table>\n";

101 102 103 104 105 106 107 108 109 110 111 112 113 114
	echo "<center>\n";
 	echo "<form action=wideareakeys.php3 method=post>";
	echo "<input type=hidden name=deletekey value=$deletekey>\n";
	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";

	echo "<br><font color=red>
              This will delete all trace including the node, vnodes, and
              interface table entries. Needless to say, deleting a key
              record of an active widearea node is a bad thing. Be sure!
              </font>\n";

115 116 117
	PAGEFOOTER();
	return;
    }
118
    DBQueryFatal("delete from widearea_privkeys where privkey='$deletekey'");
119 120

    if (isset($nodeid) && $nodeid) {
121 122
	$retval = SUEXEC($uid, $TBADMINGROUP, "webdeletenode -b $nodeid",
			 SUEXEC_ACTION_DIE);
123
    }
124
    header("Location: wideareakeys.php3");
125 126 127 128 129 130 131 132 133 134 135
}

#
# Get the list and show it.
#
#
# Standard Testbed Header, now that we know what we want to say.
#
PAGEHEADER("Widearea Private Keys");

$query_result =
136 137
    DBQueryFatal("select wa.*,i.node_id,cd.version ".
		 " from widearea_privkeys as wa ".
138
		 "left join interfaces as i on wa.IP=i.IP ".
139
		 "left join cdroms as cd on wa.cdkey=cd.cdkey ".
140
		 "order by requested DESC");
141 142

if (! mysql_num_rows($query_result)) {
143
    USERERROR("There are no widearea private keys!\n", 1);
144 145 146 147 148 149
}

echo "<table align=center border=1 cellpadding=2 cellspacing=2>\n";

echo "<tr>
          <td>Delete?</td>
150 151
          <td>Name</td>
          <td>Email</td>
152
          <td>IP</td>
153 154
          <td>Node</td>
          <td>Key</td>
155
	  <td>CD</td>
156
          <td>Requested</td>
157 158 159 160
          <td>Updated</td>
      </tr>\n";

while ($row = mysql_fetch_array($query_result)) {
161 162 163 164 165 166 167 168
    $name    = $row["user_name"];
    $email   = $row["user_email"];
    $requested = $row["requested"];
    $updated  = $row["updated"];
    $privkey = $row["privkey"];
    $IP      = $row["IP"];
    $nodeid  = $row["node_id"];
    $cdvers  = $row["version"];
169 170 171

    echo "<tr>
              <td align=center>
172
                  <A href='wideareakeys.php3?deletekey=$privkey'>
173 174 175 176 177 178 179 180 181 182 183 184
	                  <img alt=X src=redball.gif></A></td>
	      <td>$name</td>
	      <td>$email</td>
	      <td>$IP</td>\n";

    if (isset($nodeid)) {
	echo "<td><A href='shownode.php3?node_id=$nodeid'>$nodeid</a></td>\n";
    }
    else {
	echo "<td>&nbsp</td>\n";
    }
    echo "    <td>$privkey</td>
185
	      <td align=center>$cdvers</td>
186
	      <td>$requested</td>
187 188 189 190 191 192 193 194 195 196
	      <td>$updated</td>
         </tr>\n";
}
echo "</table>\n";

#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>