9b8deaa9f2c4654b037282b39da266f80c199fc7
[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 $nodes = $adm->GetNodes(array('node_id' => (int)$_GET['node_id']));
20 if (!empty($nodes)) {
21   $node = $nodes[0];
22 }
23
24 if (!isset($node)) {
25   readfile($file_name); 
26   exit();
27 }
28
29
30 $problem_models = array("Dell Precision 340", "Unknown");
31
32 $hostname= trim($node['hostname']);
33 $model= trim($node['model']);
34
35 /* pull LatLong data */
36 $sites = $adm->GetSites(array($node['site_id']));
37 if (!empty($sites)) {
38   $site_name= $sites[0]['name'];
39   $mylat= $sites[0]['latitude'];
40   $mylong= $sites[0]['longitude'];
41 } else {
42   $site_name= "Unknown";
43   $mylat= 0;
44   $mylong= 0;
45 }
46
47 /* typical NTP settings */
48
49 print( "# node $hostname site $site_name $mylat $mylong $model\n");
50 print( "driftfile /var/lib/ntp/ntp.drift\n" );
51 print( "statsdir /var/log/ntpstats/\n" );
52 print( "# Permit time synchronization with our time source, but do not\n");
53 print( "# permit the source to query or modify the service on this system.\n");
54 print( "restrict default kod nomodify notrap nopeer noquery\n");
55 print( "restrict -6 default kod nomodify notrap nopeer noquery\n");
56 print( "restrict 127.0.0.1\n");
57 print( "restrict -6 ::1\n");
58
59 if (is_numeric(array_search($model, $problem_models))) {
60   print( "tinker stepout 0\n" );
61 }
62
63 /* Look for config file */
64
65 $hostname_bits = explode('.', $hostname);
66 $chunk_counter = sizeof ($hostname_bits);
67 $compare_chunk = $hostname ;
68 $found_file = 0;
69
70 /* look for host specific overrides */
71 $file_name = $config_directory . "host/" . $file_prefix . $compare_chunk ;
72 if (is_file($file_name)) {
73   $chunk_counter = 0;
74   $found_file = 1;
75 }
76
77 /* look for domain specific overrides */
78 while ($chunk_counter > 0) {
79   $file_name = $config_directory . $file_prefix . $compare_chunk ;
80   if (is_file($file_name)) {
81     $chunk_counter = 0;
82     $found_file = 1;
83   }
84   else {
85     array_shift($hostname_bits);
86     $compare_chunk = implode('.',$hostname_bits);
87     $chunk_counter--;
88   }
89 }
90
91
92 if ($found_file and is_readable($file_name)) {
93   readfile($file_name);
94
95 else {
96   if (is_numeric(array_search($model,$problem_models))) {
97     $file_name = $config_directory . $file_prefix . "prob." . $default_name ;
98   }
99   else {
100     $file_name = $config_directory . $file_prefix . $default_name ;
101   }
102   readfile($file_name); 
103
104
105 ?>