ssh-keys.php 2.47 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
<?php
#
# Copyright (c) 2000-2015 University of Utah and the Flux Group.
# 
# {{{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/>.
# 
# }}}
#
chdir("..");
include("defs.php3");
chdir("apt");
include("quickvm_sup.php");
$page_title = "My SSH Keys";

#
# Get current user.
#
RedirectSecure();
$this_user = CheckLoginOrRedirect();
$this_idx  = $this_user->idx();
36 37 38

$optargs = OptionalPageArguments("target_user",   PAGEARG_USER);

39 40
SPITHEADER(1);

41 42 43 44 45 46
# Default to current user.
if (!isset($target_user)) {
    $target_user = $this_user;
}
$target_uid = $target_user->uid();
$target_idx = $target_user->idx();
47
$nonlocal   = ($target_user->IsNonLocal() ? "true" : "false");
48 49 50 51 52 53

if (! ($target_user->SameUser($this_user) ||
       $target_user->AccessCheck($this_user, $TB_USERINFO_READINFO))) {
    USERERROR("You do not have permission to view ${target_uid}' keys!", 1);
}

54 55
$query_result =
    DBQueryFatal("select idx,comment,pubkey from user_pubkeys ".
56
                 "where uid_idx='$target_idx' and internal=0");
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

$pubkeys = array();
while ($row = mysql_fetch_array($query_result)) {
    $pubkeys[] = array("index"   => $row["idx"],
                       "pubkey"  => $row["pubkey"],
                       "comment" => $row["comment"]);
}
echo "<script type='text/plain' id='sshkey-list'>\n";
echo htmlentities(json_encode($pubkeys));
echo "</script>\n";

# Place to hang the toplevel template.
echo "<div id='page-body'></div>\n";

echo "<script type='text/javascript'>\n";
72 73
echo "    window.AJAXURL     = 'server-ajax.php';\n";
echo "    window.TARGET_UID  = '$target_uid';\n";
74
echo "    window.NONLOCAL    = $nonlocal;\n";
75 76 77 78 79 80 81
echo "</script>\n";
echo "<script src='js/lib/jquery-2.0.3.min.js'></script>\n";
echo "<script src='js/lib/bootstrap.js'></script>\n";
echo "<script src='js/lib/require.js' data-main='js/ssh-keys'></script>\n";

SPITFOOTER();
?>