7fc31cebd7cb384eda0004914c1daae9df4032bb
[nodeconfig.git] / PlanetLabConf / ntp / step-tickers.php
1 <?php
2 //
3 // /etc/ntp/step-tickers generator
4 //
5 // Marc Fiuczynski <mef@cs.princeton.edu>
6 // Copyright (C) 2006 The Trustees of Princeton University
7 // 
8 // $Id$
9 //
10
11 // Get admin API handle
12 require_once 'plc_api.php';
13 global $adm;
14
15 $config_directory= "/var/www/html/PlanetLabConf/ntp/";
16 $file_prefix= "ntp.conf.";
17 $default_name = "default";
18 $file_name = $config_directory . $file_prefix . $default_name;
19
20 // Look up the node
21 $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR']));
22 if (!empty($interfaces)) {
23   $nodes = $adm->GetNodes(array($interfaces[0]['node_id']));
24   if (!empty($nodes)) {
25     $node = $nodes[0];
26   }
27 }
28
29 if (!isset($node)) {
30   readfile($file_name); 
31   exit();
32 }
33
34 $hostname= trim($node['hostname']);
35
36 /* Look for config file */
37
38 $hostname_bits = explode('.', $hostname);
39 $chunk_counter = sizeof ($hostname_bits);
40 $compare_chunk = $hostname ;
41 $found_file = 0;
42
43 /* look for the host specific overrides */
44 $file_name = $config_directory . "host/". $file_prefix . $compare_chunk ;
45 if (is_file($file_name)) {
46   $chunk_counter = 0;
47   $found_file = 1;
48  }
49
50 /* look for the domain specific overrides */
51 while ($chunk_counter > 0) {
52   $file_name = $config_directory . $file_prefix . $compare_chunk ;
53   if (is_file($file_name)) {
54     $chunk_counter = 0;
55     $found_file = 1;
56   }
57   else {
58     array_shift($hostname_bits);
59     $compare_chunk = implode('.',$hostname_bits);
60     $chunk_counter--;
61   }
62 }
63
64 if ($found_file and is_readable($file_name)) {
65   $lines=file($file_name);
66
67 else {
68   $file_name = $config_directory . $file_prefix . $default_name ;
69   $lines=file($file_name);
70
71
72 foreach ($lines as $line_num => $line) {
73   $line=rtrim($line);
74   $elements=explode(' ',$line);
75   if ($elements[0] == "server") {
76     print ("$elements[1]\n");
77   }
78 }
79
80 ?>