Added a conditional/different directory hierarchy for f7/f8 mirrors.
[nodeconfig.git] / keys.php
1 <?php
2 //
3 // Deprecated. Node Manager should manage keys.
4 //
5 // .ssh/authorized_keys generator
6 //
7 // Basic usage:
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)
11 //
12 // Mark Huang <mlhuang@cs.princeton.edu>
13 // Aaron Klingaman <alk@cs.princeton.edu>
14 // Copyright (C) 2004 The Trustees of Princeton University
15 //
16 // $Id$
17 //
18
19 // Get admin API handle
20 require_once 'plc_api.php';
21 global $adm;
22
23 $persons = array();
24 $keys = array();
25
26 if (!empty($_REQUEST['role'])) {
27   // XXX Implement API query filters
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'])) {
32       $persons[] = $person;
33     }
34   }
35 }
36
37 if (isset($_REQUEST['site_admin'])) {
38   // Look up the node
39   $nodenetworks = $adm->GetNodeNetworks(array('ip' => $_SERVER['REMOTE_ADDR']));
40   if (!empty($nodenetworks)) {
41     $nodes = $adm->GetNodes(array($nodenetworks[0]['node_id']));
42     if (!empty($nodes)) {
43       $node = $nodes[0];
44     }
45   }
46   if (isset($node)) {
47     // Look up the site
48     $sites = $adm->GetSites(array($node['site_id']));
49     // Can't filter on roles so have to bruit force through entire userlist of site.
50     if ($sites && $sites[0]['person_ids']) {
51       $all_persons = $adm->GetPersons($sites[0]['person_ids']);
52       foreach ($all_persons as $person) {
53             if ((in_array('pi', $person['roles']) || in_array('tech', $person['roles'])) && 
54         $person['enabled']) {
55           $persons[] = $person; 
56         }
57           }
58     }
59   }
60 }
61
62 if (isset($_REQUEST['root'])) {
63   $keys[] = array('key' => file_get_contents(PLC_ROOT_SSH_KEY_PUB));
64 }
65
66
67 if (!empty($persons)) {
68   $key_ids = array();
69   foreach ($persons as $person) {
70         if ($person['key_ids']) {
71       $key_ids[] = $person['key_ids'][0];
72         }
73   }
74   if (!empty($key_ids)) {
75     $keys = $adm->GetKeys($key_ids);
76   }
77 }
78
79 foreach ($keys as $key) {
80   print $key['key']. "\n";
81 }
82
83 ?>