From 47d8309a3d8c1fd8df70d86a417081fcfc465596 Mon Sep 17 00:00:00 2001
From: Stephen Soltesz <soltesz@cs.princeton.edu>
Date: Fri, 3 Jul 2009 20:33:51 +0000
Subject: [PATCH] allow for some specially tagged machines to get all plc
 config values.

---
 PlanetLabConf/get_plc_config.php | 74 ++++++++++++++++++++++++++------
 1 file changed, 62 insertions(+), 12 deletions(-)

diff --git a/PlanetLabConf/get_plc_config.php b/PlanetLabConf/get_plc_config.php
index 6fd4d4c..645bfe8 100755
--- a/PlanetLabConf/get_plc_config.php
+++ b/PlanetLabConf/get_plc_config.php
@@ -11,6 +11,8 @@
 
 // Try the new plc_config.php file first
 include 'plc_config.php';
+require_once 'plc_api.php';
+global $adm;
 
 if (isset($_REQUEST['perl'])) {
   $shebang = '#!/usr/bin/perl';
@@ -31,21 +33,69 @@ if (isset($_REQUEST['perl'])) {
 }
 
 echo $shebang . "\n";
+$limit_view = True;
 
-foreach (array('PLC_API_HOST', 'PLC_API_PATH', 'PLC_API_PORT',
-	       'PLC_WWW_HOST', 'PLC_BOOT_HOST', 'PLC_PLANETFLOW_HOST',
-	       'PLC_NAME', 'PLC_SLICE_PREFIX', 'PLC_MONITOR_HOST',
-	       'PLC_MAIL_SUPPORT_ADDRESS',
-	       'PLC_MAIL_MOM_LIST_ADDRESS',
-	       'PLC_MAIL_SLICE_ADDRESS')
-	 as $name) {
-  if (defined($name)) {
-    // Perl, PHP, Python, and sh all support strong single quoting
-    $value = "'" . str_replace("'", "\\'", constant($name)) . "'";
-    printf($format, $name, $value);
-  }
+if (isset($_REQUEST['node_id']) ) {
+	$node_id = intval($_REQUEST['node_id']);
+} else {
+	$node_id = 0;
+}
+
+
+if ($node_id) {
+	$nodes = $adm->GetNodes($node_id);
+    if (!empty($nodes)) {
+        $node = $nodes[0];
+        $tags = $adm->GetNodeTags(array('node_id' => $node_id,
+										'tagname' => 'infrastructure'));
+        if (!empty($tags)) {
+            $tag = $tags[0];
+            if ( intval($tag['value']) == 1 ) {
+				$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 ( $node['node_id'] == $node_id )
+						{
+							# NOTE: only provide complete view if 
+							#     node exists
+							#   node has infrastrucure tag
+							#   infrastructure tag value == 1
+							# Check that the requestor is the node.
+                			$limit_view = False;
+						}
+				  	}
+				}
+            }
+        }
+    }
 }
 
+if ( $limit_view ) {
+    $plc_constants = array('PLC_API_HOST', 'PLC_API_PATH', 'PLC_API_PORT',
+               'PLC_WWW_HOST', 'PLC_BOOT_HOST', 'PLC_PLANETFLOW_HOST',
+               'PLC_NAME', 'PLC_SLICE_PREFIX', 'PLC_MONITOR_HOST',
+               'PLC_MAIL_SUPPORT_ADDRESS',
+               'PLC_MAIL_MOM_LIST_ADDRESS',
+               'PLC_MAIL_SLICE_ADDRESS');
+} else {
+	$plc_constants = array();
+	$const = get_defined_constants(true);
+	foreach ( $const['user'] as $name => $v ){
+	    if ( preg_match('/^PLC_/', $name) == 1 ){
+			$plc_constants[] = $name;
+		}		
+	}
+}
+
+foreach ($plc_constants as $name) {
+	if (defined($name)) {
+		// Perl, PHP, Python, and sh all support strong single quoting
+		$value = "'" . str_replace("'", "\\'", constant($name)) . "'";
+		printf($format, $name, $value);
+	}
+}
 printf($format, 'PLC_API_CA_SSL_CRT', "'/usr/boot/cacert.pem'");
 printf($format, 'PLC_ROOT_GPG_KEY_PUB', "'/usr/boot/pubring.gpg'");
 
-- 
2.47.0