3 // .ssh/authorized_keys generator
4 // Node Manager should manage user keys.
5 // This script remains current for special cases like root, site_admin, and monitor
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 if (!empty($_REQUEST['role'])) {
27 // API cannot filter on role_ids nor roles
28 // $persons = $adm->GetPersons(array('roles' => array($_REQUEST['role'])));
29 $all_persons = $adm->GetPersons();
30 foreach ($all_persons as $person) {
31 if (in_array($_REQUEST['role'], $person['roles'])) {
37 // {ple,pl}_monitor user is created on the nodes by the monitor-runlevelagent init script.
38 if (isset($_REQUEST[PLC_SLICE_PREFIX . '_monitor'])) {
39 $user = $adm->GetPersons(array('first_name' => 'Site', 'last_name' => 'Assistant'));
41 $persons[] = $user[0];
45 if (isset($_REQUEST['site_admin']) && isset($_REQUEST['node_id'])) {
46 $nodes = $adm->GetNodes(array(intval($_REQUEST['node_id'])));
52 $sites = $adm->GetSites(array($node['site_id']));
53 // Can't filter on roles so have to brute force through entire userlist of site.
54 if ($sites && $sites[0]['person_ids']) {
55 $all_persons = $adm->GetPersons($sites[0]['person_ids']);
56 if (!empty($all_persons))
57 foreach ($all_persons as $person)
58 if ((in_array('pi', $person['roles']) || in_array('tech', $person['roles'])) && $person['enabled'])
64 if (isset($_REQUEST['root']))
65 $keys[] = array('key' => file_get_contents(PLC_ROOT_SSH_KEY_PUB));
68 if (!empty($persons)) {
70 foreach ($persons as $person) {
71 if ($person['key_ids']) {
72 $person_key_ids = $person['key_ids'];
73 foreach ($person_key_ids as $person_key_id) {
74 $key_ids[] = $person_key_id;
79 $keys = $adm->GetKeys($key_ids);
82 foreach ($keys as $key)
83 print $key['key']. "\n";