svn keywords, and url in specfile
[nodeconfig.git] / PlanetLabConf / get_plc_config.php
1 <?php
2 //
3 // Print a subset of the variables from the PLC configuration store in
4 // various formats (Perl, Python, PHP, sh)
5 //
6 // Mark Huang <mlhuang@cs.princeton.edu>
7 // Copyright (C) 2006 The Trustees of Princeton University
8 //
9
10 // Try the new plc_config.php file first
11 include 'plc_config.php';
12 require_once 'plc_api.php';
13 global $adm;
14
15 if (isset($_REQUEST['perl'])) {
16   $shebang = '#!/usr/bin/perl';
17   $format = "our $%s=%s;\n";
18   $end = '';
19 } elseif (isset($_REQUEST['python'])) {
20   $shebang = '#!/usr/bin/python';
21   $format = "%s=%s\n";
22   $end = '';
23 } elseif (isset($_REQUEST['php'])) {
24   $shebang = '<?php';
25   $format = "define('%s', %s);\n";
26   $end = '?>';
27 } else {
28   $shebang = '#!/bin/sh';
29   $format = "%s=%s\n";
30   $end = '';
31 }
32
33 echo $shebang . "\n";
34 $limit_view = True;
35
36 if (isset($_REQUEST['node_id']) ) {
37     $node_id = intval($_REQUEST['node_id']);
38 } else {
39     $node_id = 0;
40 }
41
42
43 if ($node_id) {
44     $nodes = $adm->GetNodes($node_id);
45     if (!empty($nodes)) {
46         $node = $nodes[0];
47         $tags = $adm->GetNodeTags(array('node_id' => $node_id,
48                                         'tagname' => 'infrastructure'));
49         if (!empty($tags)) {
50             $tag = $tags[0];
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']));
55                     if (!empty($nodes)) {
56                         $node = $nodes[0];
57                         if ( $node['node_id'] == $node_id )
58                         {
59                             # NOTE: only provide complete view if 
60                             #     node exists
61                             #   node has infrastrucure tag
62                             #   infrastructure tag value == 1
63                             # Check that the requestor is the node.
64                             $limit_view = False;
65                         }
66                       }
67                 }
68             }
69         }
70     }
71 }
72
73 if ( $limit_view ) {
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');
80 } else {
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;
86         }        
87     }
88 }
89
90 foreach ($plc_constants as $name) {
91     if (defined($name)) {
92         // Perl, PHP, Python, and sh all support strong single quoting
93         $value = "'" . str_replace("'", "\\'", constant($name)) . "'";
94         printf($format, $name, $value);
95     }
96 }
97 printf($format, 'PLC_API_CA_SSL_CRT', "'/usr/boot/cacert.pem'");
98 printf($format, 'PLC_ROOT_GPG_KEY_PUB', "'/usr/boot/pubring.gpg'");
99
100 echo $end . "\n";
101
102 ?>