deletesfskey.php3 3.64 KB
Newer Older
1 2 3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
5 6 7 8 9 10
# All rights reserved.
#
include("defs.php3");

#
# No PAGEHEADER since we spit out a redirect later.
11
#
12 13 14 15

#
# Only known and logged in users can do this.
#
16 17 18
$this_user = CheckLoginOrDie(CHECKLOGIN_USERSTATUS|CHECKLOGIN_WEBONLY);
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
19

20 21 22 23 24 25 26
#
# Verify page arguments.
#
$reqargs = RequiredPageArguments("target_user", PAGEARG_USER,
				 "key",         PAGEARG_STRING);
$optargs = OptionalPageArguments("canceled",    PAGEARG_BOOLEAN,
				 "confirmed",   PAGEARG_BOOLEAN);
27

28 29
# Pedantic argument checking of the key.
if (! preg_match("/^[-\w\.\@\#]+$/", $key)) {
30
    PAGEARGERROR();
31 32
}

33
# Need these below
34
$target_uid   = $target_user->uid();
35 36 37 38 39

#
# Verify that this uid is a member of one of the projects that the
# target_uid is in. Must have proper permission in that group too. 
#
40 41 42
if (!$isadmin && 
    !$target_user->AccessCheck($this_user, $TB_USERINFO_MODIFYINFO)) {
    USERERROR("You do not have permission!", 1);
43 44 45 46 47
}

#
# Get the actual key.
#
48 49 50
$query_result =& $target_user->TableLookUp("user_sfskeys",
					   "pubkey,comment",
					   "comment='$key'");
51 52 53 54 55 56

if (! mysql_num_rows($query_result)) {
    USERERROR("SFS Key '$key' for user '$target_uid' does not exist!", 1);
}

$row    = mysql_fetch_array($query_result);
57 58
$pubkey = $row['pubkey'];
$comment= $row['comment'];
59 60 61 62 63 64 65 66
$chunky = chunk_split("$pubkey $comment", 70, "<br>\n");

#
# 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.
#
67
if (isset($canceled) && $canceled) {
68 69 70 71 72 73
    PAGEHEADER("SFS Public Key Maintenance");
    
    echo "<center><h2><br>
          SFS Public Key deletion canceled!
          </h2></center>\n";

74 75
    $url = CreateURL("deletesfskey", $target_user);

76
    echo "<br>
77
          Back to <a href='$url'>sfs public keys</a> for user '$uid'.\n";
78 79 80 81 82
    
    PAGEFOOTER();
    return;
}

83
if (!isset($confirmed)) {
84 85 86 87 88 89
    PAGEHEADER("SFS Public Key Maintenance");

    echo "<center><h3><br>
          Are you <b>REALLY</b>
          sure you want to delete this SFS Public Key for user '$target_uid'?
          </h3>\n";
90 91

    $url = CreateURL("deletesfskey", $target_user, "key", $key);
92
    
93
    echo "<form action='$url' method=post>";
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    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 "<table align=center border=1 cellpadding=2 cellspacing=2>
           <tr>
              <td>$chunky</td>
           </tr>
          </table>\n";
    
    PAGEFOOTER();
    return;
}

#
# Audit
#
112 113 114 115 116
$uid_name  = $this_user->name();
$uid_email = $this_user->email();

$targuid_name  = $target_user->name();
$targuid_email = $target_user->email();
117 118 119 120 121 122 123 124 125

TBMAIL("$targuid_name <$targuid_email>",
     "SFS Public Key for '$target_uid' Deleted",
     "\n".
     "SFS Public Key for '$target_uid' deleted by '$uid'.\n".
     "\n".
     "$chunky\n".
     "\n".
     "Thanks,\n".
126
     "Testbed Operations\n",
127
     "From: $uid_name <$uid_email>\n".
128
     "Bcc: $TBMAIL_AUDIT\n".
129 130
     "Errors-To: $TBMAIL_WWW");

131
$target_user->TableDelete("user_sfskeys", "comment='$key'");
132 133

#
134 135 136 137 138 139 140 141
# update sfs_users files and nodes if appropriate.
#
if (HASREALACCOUNT($uid)) {
    SUEXEC($uid, "nobody", "webaddsfskey -w $target_uid", 0);
}
else {
    SUEXEC("nobody", "nobody", "webaddsfskey -w $target_uid", 0);
}
142

143
PAGEREPLACE(CreateURL("showsfskeys", $target_user));
144

145 146 147 148
#
# Standard Testbed Footer
# 
PAGEFOOTER();
149
?>