remove legacy layer, just assume 4.3 and GetInterfaces
[nodeconfig.git] / PlanetLabConf / ntp.conf.php
1 <?php
2 //
3 // /etc/ntp.conf 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
22 $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR']));
23
24 if (!empty($interfaces)) {
25   $nodes = $adm->GetNodes(array($interfaces[0]['node_id']));
26   if (!empty($nodes)) {
27     $node = $nodes[0];
28   }
29 }
30
31 if (!isset($node)) {
32   readfile($file_name); 
33   exit();
34 }
35
36 $problem_models = array("Dell Precision 340", "Unknown");
37
38 $hostname= trim($node['hostname']);
39 $model= trim($node['model']);
40
41 /* pull LatLong data */
42 $sites = $adm->GetSites(array($node['site_id']));
43 if (!empty($sites)) {
44   $site_name= $sites[0]['name'];
45   $mylat= $sites[0]['latitude'];
46   $mylong= $sites[0]['longitude'];
47 } else {
48   $site_name= "Unknown";
49   $mylat= 0;
50   $mylong= 0;
51 }
52
53 /* typical NTP settings */
54
55 print( "# node $hostname site $site_name $mylat $mylong $model\n");
56 print( "driftfile /var/lib/ntp/ntp.drift\n" );
57 print( "statsdir /var/log/ntpstats/\n" );
58 if (is_numeric(array_search($model, $problem_models))) {
59   print( "tinker stepout 0\n" );
60 }
61
62 /* Look for config file */
63
64 $hostname_bits = explode('.', $hostname);
65 $chunk_counter = sizeof ($hostname_bits);
66 $compare_chunk = $hostname ;
67 $found_file = 0;
68
69 /* look for host specific overrides */
70 $file_name = $config_directory . "host/" . $file_prefix . $compare_chunk ;
71 if (is_file($file_name)) {
72   $chunk_counter = 0;
73   $found_file = 1;
74 }
75
76 /* look for domain specific overrides */
77 while ($chunk_counter > 0) {
78   $file_name = $config_directory . $file_prefix . $compare_chunk ;
79   if (is_file($file_name)) {
80     $chunk_counter = 0;
81     $found_file = 1;
82   }
83   else {
84     array_shift($hostname_bits);
85     $compare_chunk = implode('.',$hostname_bits);
86     $chunk_counter--;
87   }
88 }
89
90
91 if ($found_file and is_readable($file_name)) {
92   readfile($file_name);
93
94 else {
95   if (is_numeric(array_search($model,$problem_models))) {
96     $file_name = $config_directory . $file_prefix . "prob." . $default_name ;
97   }
98   else {
99     $file_name = $config_directory . $file_prefix . $default_name ;
100   }
101   readfile($file_name); 
102
103
104 ?>