3 // Print a subset of the variables from the PLC configuration store in
4 // various formats (Perl, Python, PHP, sh)
6 // Mark Huang <mlhuang@cs.princeton.edu>
7 // Copyright (C) 2006 The Trustees of Princeton University
10 // Try the new plc_config.php file first
11 include 'plc_config.php';
12 require_once 'plc_api.php';
15 if (isset($_REQUEST['perl'])) {
16 $shebang = '#!/usr/bin/perl';
17 $format = "our $%s=%s;\n";
19 } elseif (isset($_REQUEST['python'])) {
20 $shebang = '#!/usr/bin/python';
23 } elseif (isset($_REQUEST['php'])) {
25 $format = "define('%s', %s);\n";
28 $shebang = '#!/bin/sh';
36 if (isset($_REQUEST['node_id']) ) {
37 $node_id = intval($_REQUEST['node_id']);
44 $nodes = $adm->GetNodes($node_id);
47 $tags = $adm->GetNodeTags(array('node_id' => $node_id,
48 'tagname' => 'infrastructure'));
51 if ( intval($tag['value']) == 1 ) {
52 $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR']));
53 if (!empty($interfaces)) {
54 $nodes = $adm->GetNodes(array($interfaces[0]['node_id']));
57 if ( $node['node_id'] == $node_id )
59 # NOTE: only provide complete view if
61 # node has infrastrucure tag
62 # infrastructure tag value == 1
63 # Check that the requestor is the node.
74 $plc_constants = array('PLC_API_HOST', 'PLC_API_PATH', 'PLC_API_PORT',
75 'PLC_WWW_HOST', 'PLC_BOOT_HOST', 'PLC_PLANETFLOW_HOST',
76 'PLC_NAME', 'PLC_SLICE_PREFIX', 'PLC_MONITOR_HOST',
77 'PLC_MAIL_SUPPORT_ADDRESS',
78 'PLC_MAIL_MOM_LIST_ADDRESS',
79 'PLC_MAIL_SLICE_ADDRESS');
81 $plc_constants = array();
82 $const = get_defined_constants(true);
83 foreach ( $const['user'] as $name => $v ){
84 if ( preg_match('/^PLC_/', $name) == 1 ){
85 $plc_constants[] = $name;
90 foreach ($plc_constants as $name) {
92 // Perl, PHP, Python, and sh all support strong single quoting
93 $value = "'" . str_replace("'", "\\'", constant($name)) . "'";
94 printf($format, $name, $value);
97 printf($format, 'PLC_API_CA_SSL_CRT', "'/usr/boot/cacert.pem'");
98 printf($format, 'PLC_ROOT_GPG_KEY_PUB', "'/usr/boot/pubring.gpg'");