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