Added a conditional/different directory hierarchy for f7/f8 mirrors.
[nodeconfig.git] / getupdatesxml.php
1 <?php
2 //
3 // Deprecated. Generates an XML file that the old PlanetLabConf script understands.
4 //
5 // Aaron Klingaman <alk@absarokasoft.com>
6 // Mark Huang <mlhuang@cs.princeton.edu>
7 //
8 // Copyright (C) 2006 The Trustees of Princeton University
9 //
10 // $Id$
11 //
12
13 // Get admin API handle
14 require_once 'plc_api.php';
15 global $adm;
16
17 function writeXMLHeader()
18 {
19   print( "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n\n" );
20 }
21
22 define("ENT_UNPARSED", 0); // i.e., CDATA
23 define("ENT_PARSED", 1); // i.e., PCDATA (attributes)
24
25 function xmlspecialchars_decode($string, $parsed = ENT_UNPARSED)
26 {
27   if ($parsed == ENT_PARSED) {
28     // &amp; to &
29     // &apos; to '
30     // &lt; to <
31     // &gt; to >
32     // &quot; to "
33     return str_replace('&amp;', '&',
34                        str_replace(array('&apos;', '&lt;', '&gt;', '&quot;'),
35                                    array("'", '<', '>', '"'),
36                                    $string));
37   } else {
38     // &amp; to &
39     // &apos; to '
40     // &lt; to <
41     // &gt; to >
42     // \" to "
43     // \\ to \
44     return str_replace('&amp;', '&',
45                        str_replace(array('&apos;', '&lt;', '&gt;', '\"', '\\'),
46                                    array("'", '<', '>', '"', "\\"),
47                                    $string));
48   }
49 }
50   
51 function xmlspecialchars($string, $parsed = ENT_UNPARSED)
52 {
53   if ($parsed == ENT_PARSED) {
54     // & to &amp;
55     // ' to &apos;
56     // < to &lt;
57     // > to &gt;
58     // " to &quot;
59     $string = str_replace(array("'", '<', '>', '"'),
60                           array('&apos;', '&lt;', '&gt;', '&quot;'),
61                           str_replace('&', '&amp;', $string));
62   } else {
63     // & to &amp;
64     // ' to &apos;
65     // < to &lt;
66     // > to &gt;
67     // " to \"
68     // \ to \\
69     $string = str_replace(array("'", '<', '>', '"'),
70                           array('&apos;', '&lt;', '&gt;', '\"'),
71                           str_replace(array('&', "\\"),
72                                       array('&amp;', '\\'),
73                                       $string));
74   }
75
76   return utf8_encode($string);
77 }
78     
79 // Look up the node
80 if (!empty($_REQUEST['node_id'])) {
81   $node = $adm->GetSlivers(intval($_REQUEST['node_id']));
82 } else {
83   $nodenetworks = $adm->GetNodeNetworks(array('ip' => $_SERVER['REMOTE_ADDR']));
84   if (!empty($nodenetworks)) {
85     $node = $adm->GetSlivers($nodenetworks[0]['node_id']);
86   }
87 }
88
89 if (empty($node)) {
90   exit();
91 }
92 $node_id = $node['node_id'];
93
94 writeXMLHeader();
95 $curtime= time();
96 print( "<planetlab_conf version=\"0.1\" time=\"$curtime\">\n" );
97 print( "<node id=\"$node_id\">\n" );
98
99 foreach( $node['conf_files'] as $conf_file )
100 {
101   $source            = xmlspecialchars($conf_file["source"]);
102   $dest              = xmlspecialchars($conf_file["dest"]);
103   $file_permissions  = xmlspecialchars($conf_file["file_permissions"]);
104   $file_owner        = xmlspecialchars($conf_file["file_owner"]);
105   $file_group        = xmlspecialchars($conf_file["file_group"]);
106   $preinstall_cmd    = xmlspecialchars($conf_file["preinstall_cmd"]);
107   $postinstall_cmd   = xmlspecialchars($conf_file["postinstall_cmd"]);
108   $error_cmd         = xmlspecialchars($conf_file["error_cmd"]);
109   $ignore_cmd_errors = $conf_file["ignore_cmd_errors"];
110   $always_update     = $conf_file["always_update"];
111
112   if( $ignore_cmd_errors == 1 )
113     $ignore_cmd_errors= "y";
114   else
115     $ignore_cmd_errors= "n";
116
117   if( $always_update == 1 )
118     $always_update= "y";
119   else
120     $always_update= "n";
121
122   print( "<file always_update=\"$always_update\" ignore_cmd_errors=\"$ignore_cmd_errors\">\n" );
123   print( "<source>$source</source>\n" );
124   print( "<destination>$dest</destination>\n" );
125   print( "<permissions>$file_permissions</permissions>\n" );
126   print( "<owner>$file_owner</owner>\n" );
127   print( "<group>$file_group</group>\n" );
128   print( "<preinstall_cmd>$preinstall_cmd</preinstall_cmd>\n" );
129   print( "<postinstall_cmd>$postinstall_cmd</postinstall_cmd>\n" );
130   print( "<error_cmd>$error_cmd</error_cmd>\n" );
131   print( "</file>\n" );
132 }
133
134 print( "</node>\n" );
135 print( "</planetlab_conf>\n" );
136
137 ?>