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