From: Marc Fiuczynski Date: Sun, 18 Jan 2009 16:15:24 +0000 (+0000) Subject: backwards compatibility with 4.2 X-Git-Tag: nodeconfig-4.3-2~8 X-Git-Url: http://git.onelab.eu/?p=nodeconfig.git;a=commitdiff_plain;h=b815095fec39d567d31901c610de18c611dd5db5 backwards compatibility with 4.2 --- diff --git a/PlanetLabConf/blacklist.php b/PlanetLabConf/blacklist.php index 622e6ce..33a04f9 100755 --- a/PlanetLabConf/blacklist.php +++ b/PlanetLabConf/blacklist.php @@ -21,8 +21,18 @@ require_once 'plc_api.php'; global $adm; +// 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; + // Look up the node -$interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR'])); +if ($__PLC_API_VERSION==4.2) + $interfaces = $adm->GetNodeNetworks(array('ip' => $_SERVER['REMOTE_ADDR'])); +else + $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR'])); if (!empty($interfaces)) { $nodes = $adm->GetNodes(array($interfaces[0]['node_id'])); if (!empty($nodes)) { diff --git a/PlanetLabConf/bwlimit.php b/PlanetLabConf/bwlimit.php index 850e864..a35bdeb 100755 --- a/PlanetLabConf/bwlimit.php +++ b/PlanetLabConf/bwlimit.php @@ -13,7 +13,18 @@ require_once 'plc_api.php'; global $adm; // Look up the node -$interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR'])); +// 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 ($__PLC_API_VERSION==4.2) + $interfaces = $adm->GetNodeNetworks(array('ip' => $_SERVER['REMOTE_ADDR'])); +else + $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR'])); + if (!empty($interfaces)) { if ($interfaces[0]['bwlimit'] !== NULL) { $rate = $interfaces[0]['bwlimit']; diff --git a/PlanetLabConf/keys.php b/PlanetLabConf/keys.php index 9bbd867..df466b5 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']))); @@ -42,7 +49,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 ($__PLC_API_VERSION==4.2) + $interfaces = $adm->GetNodeNetworks(array('ip' => $_SERVER['REMOTE_ADDR'])); + else + $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR'])); if (!empty($interfaces)) { $nodes = $adm->GetNodes(array($interfaces[0]['node_id'])); if (!empty($nodes)) { @@ -55,35 +65,28 @@ 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']) { + foreach ($persons as $person) + if ($person['key_ids']) $key_ids[] = $person['key_ids'][0]; - } - } - 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"; -} ?> diff --git a/PlanetLabConf/ntp.conf.php b/PlanetLabConf/ntp.conf.php index ea3ce63..afd0d76 100755 --- a/PlanetLabConf/ntp.conf.php +++ b/PlanetLabConf/ntp.conf.php @@ -18,7 +18,13 @@ $default_name = "default"; $file_name = $config_directory . $file_prefix . $default_name; // Look up the node -$interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR'])); + +// backwards compatibility with the old 4.2 API +if ( ! method_exists ($adm,"GetInterfaces")) + $interfaces = $adm->GetNodeNetworks(array('ip' => $_SERVER['REMOTE_ADDR'])); +else + $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR'])); + if (!empty($interfaces)) { $nodes = $adm->GetNodes(array($interfaces[0]['node_id'])); if (!empty($nodes)) { @@ -42,6 +48,10 @@ if (!empty($sites)) { $site_name= $sites[0]['name']; $mylat= $sites[0]['latitude']; $mylong= $sites[0]['longitude']; +} else { + $site_name= "Unknown"; + $mylat= 0; + $mylong= 0; } /* typical NTP settings */ diff --git a/PlanetLabConf/proxies.php b/PlanetLabConf/proxies.php index d2b893c..4431aca 100755 --- a/PlanetLabConf/proxies.php +++ b/PlanetLabConf/proxies.php @@ -18,7 +18,17 @@ require_once 'plc_api.php'; global $adm; // Look up the node -$interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR'])); +// 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 ($__PLC_API_VERSION==4.2) + $interfaces = $adm->GetNodeNetworks(array('ip' => $_SERVER['REMOTE_ADDR'])); +else + $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR'])); + if (!empty($interfaces)) { $nodes = $adm->GetNodes(array($interfaces[0]['node_id'])); if (!empty($nodes)) { @@ -30,7 +40,10 @@ if (!isset($node)) { exit(); } -$interfaces = $adm->GetInterfaces($node['interface_ids']); +if ($__PLC_API_VERSION==4.2) + $interfaces = $adm->GetInterfaces($node['nodenetwork_ids']); +else + $interfaces = $adm->GetInterfaces($node['interface_ids']); foreach ($interfaces as $interface) { // XXX PL2896: need interfaces.device diff --git a/PlanetLabConf/sysctl.php b/PlanetLabConf/sysctl.php index 127362e..a17d80c 100755 --- a/PlanetLabConf/sysctl.php +++ b/PlanetLabConf/sysctl.php @@ -15,12 +15,27 @@ global $adm; $ip_forward = 0; // Look up the node -$interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR'])); +// 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 ($__PLC_API_VERSION==4.2) + $interfaces = $adm->GetNodeNetworks(array('ip' => $_SERVER['REMOTE_ADDR'])); +else + $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]; - $interfaces = $adm->GetInterfaces($node['interface_ids']); + if ($__PLC_API_VERSION==4.2) + $interfaces = $adm->GetInterfaces($node['nodenetwork_ids']); + else + $interfaces = $adm->GetInterfaces($node['interface_ids']); + foreach ($interfaces as $interface) { // Nodes with proxy socket interfaces need to be able to forward // between the fake proxy0 interface and the real interface.