3 // Deprecated. Node Manager should manage keys.
5 // .ssh/authorized_keys generator
8 // keys.php?role=admin (all PlanetLab administrators)
9 // keys.php?root (PlanetLab root and users allowed root on the querying node)
10 // keys.php?site_admin (PIs and tech contacts at the querying node's site)
12 // Mark Huang <mlhuang@cs.princeton.edu>
13 // Aaron Klingaman <alk@cs.princeton.edu>
14 // Copyright (C) 2004 The Trustees of Princeton University
19 // Get admin API handle
20 require_once 'plc_api.php';
26 // backwards compatibility with the old 4.2 API
27 global $__PLC_API_VERSION;
28 if ( ! method_exists ($adm,"GetInterfaces"))
29 $__PLC_API_VERSION = 4.2;
31 $__PLC_API_VERSION = 4.3;
33 if (!empty($_REQUEST['role'])) {
34 // XXX Implement API query filters
35 // $persons = $adm->GetPersons(array('roles' => array($_REQUEST['role'])));
36 $all_persons = $adm->GetPersons();
37 foreach ($all_persons as $person) {
38 if (in_array($_REQUEST['role'], $person['roles'])) {
43 if (isset($_REQUEST[PLC_SLICE_PREFIX . '_monitor'])) {
44 $user = $adm->GetPersons(array('first_name' => 'Site', 'last_name' => 'Assistant'));
46 $persons[] = $user[0];
50 if (isset($_REQUEST['site_admin'])) {
52 if ($__PLC_API_VERSION==4.2)
53 $interfaces = $adm->GetNodeNetworks(array('ip' => $_SERVER['REMOTE_ADDR']));
55 $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR']));
56 if (!empty($interfaces)) {
57 $nodes = $adm->GetNodes(array($interfaces[0]['node_id']));
64 $sites = $adm->GetSites(array($node['site_id']));
65 // Can't filter on roles so have to bruit force through entire userlist of site.
66 if ($sites && $sites[0]['person_ids']) {
67 $all_persons = $adm->GetPersons($sites[0]['person_ids']);
68 if (!empty($all_persons))
69 foreach ($all_persons as $person)
70 if ((in_array('pi', $person['roles']) || in_array('tech', $person['roles'])) && $person['enabled'])
76 if (isset($_REQUEST['root']))
77 $keys[] = array('key' => file_get_contents(PLC_ROOT_SSH_KEY_PUB));
80 if (!empty($persons)) {
82 foreach ($persons as $person)
83 if ($person['key_ids'])
84 $key_ids[] = $person['key_ids'][0];
86 $keys = $adm->GetKeys($key_ids);
89 foreach ($keys as $key)
90 print $key['key']. "\n";