X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PlanetLabConf%2Fkeys.php;h=9d34c422abc83374fcf286f1b34d2c8b870383cf;hb=ce3fe64fdd40048f63d70b95e119821379800c7b;hp=9bbd867deaabcc6f676c94d04367443ae60e48e5;hpb=e9b0065a02763ed6ba0d6499c8d4fc723eb3a410;p=nodeconfig.git diff --git a/PlanetLabConf/keys.php b/PlanetLabConf/keys.php index 9bbd867..9d34c42 100755 --- a/PlanetLabConf/keys.php +++ b/PlanetLabConf/keys.php @@ -23,6 +23,13 @@ global $adm; $persons = array(); $keys = array(); +// backwards compatibility with the old 4.2 API +global $__PLC_API_VERSION; +if ( ! method_exists ($adm,"GetInterfaces")) + $__PLC_API_VERSION = 4.2; +else + $__PLC_API_VERSION = 4.3; + if (!empty($_REQUEST['role'])) { // XXX Implement API query filters // $persons = $adm->GetPersons(array('roles' => array($_REQUEST['role']))); @@ -40,14 +47,10 @@ if (isset($_REQUEST[PLC_SLICE_PREFIX . '_monitor'])) { } } -if (isset($_REQUEST['site_admin'])) { - // Look up the node - $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR'])); - if (!empty($interfaces)) { - $nodes = $adm->GetNodes(array($interfaces[0]['node_id'])); - if (!empty($nodes)) { - $node = $nodes[0]; - } +if (isset($_REQUEST['site_admin']) && isset($_REQUEST['node_id'])) { + $nodes = $adm->GetNodes(array(intval($_REQUEST['node_id']))); + if (!empty($nodes)) { + $node = $nodes[0]; } if (isset($node)) { // Look up the site @@ -55,35 +58,33 @@ if (isset($_REQUEST['site_admin'])) { // Can't filter on roles so have to bruit force through entire userlist of site. if ($sites && $sites[0]['person_ids']) { $all_persons = $adm->GetPersons($sites[0]['person_ids']); - foreach ($all_persons as $person) { - if ((in_array('pi', $person['roles']) || in_array('tech', $person['roles'])) && - $person['enabled']) { - $persons[] = $person; - } - } + if (!empty($all_persons)) + foreach ($all_persons as $person) + if ((in_array('pi', $person['roles']) || in_array('tech', $person['roles'])) && $person['enabled']) + $persons[] = $person; } } } -if (isset($_REQUEST['root'])) { +if (isset($_REQUEST['root'])) $keys[] = array('key' => file_get_contents(PLC_ROOT_SSH_KEY_PUB)); -} if (!empty($persons)) { $key_ids = array(); foreach ($persons as $person) { - if ($person['key_ids']) { - $key_ids[] = $person['key_ids'][0]; - } + if ($person['key_ids']) { + $person_key_ids = $person['key_ids']; + foreach ($person_key_ids as $person_key_id) { + $key_ids[] = $person_key_id; + } + } } - if (!empty($key_ids)) { + if (!empty($key_ids)) $keys = $adm->GetKeys($key_ids); - } } -foreach ($keys as $key) { +foreach ($keys as $key) print $key['key']. "\n"; -} ?>