disable monitor
[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( "disable monitor\n" );
53 print( "# Permit time synchronization with our time source, but do not\n");
54 print( "# permit the source to query or modify the service on this system.\n");
55 print( "restrict default kod nomodify notrap nopeer noquery\n");
56 print( "restrict -6 default kod nomodify notrap nopeer noquery\n");
57 print( "restrict 127.0.0.1\n");
58 print( "restrict -6 ::1\n");
59
60 if (is_numeric(array_search($model, $problem_models))) {
61   print( "tinker stepout 0\n" );
62 }
63
64 /* Look for config file */
65
66 $hostname_bits = explode('.', $hostname);
67 $chunk_counter = sizeof ($hostname_bits);
68 $compare_chunk = $hostname ;
69 $found_file = 0;
70
71 /* look for host specific overrides */
72 $file_name = $config_directory . "host/" . $file_prefix . $compare_chunk ;
73 if (is_file($file_name)) {
74   $chunk_counter = 0;
75   $found_file = 1;
76 }
77
78 /* look for domain specific overrides */
79 while ($chunk_counter > 0) {
80   $file_name = $config_directory . $file_prefix . $compare_chunk ;
81   if (is_file($file_name)) {
82     $chunk_counter = 0;
83     $found_file = 1;
84   }
85   else {
86     array_shift($hostname_bits);
87     $compare_chunk = implode('.',$hostname_bits);
88     $chunk_counter--;
89   }
90 }
91
92
93 if ($found_file and is_readable($file_name)) {
94   readfile($file_name);
95
96 else {
97   if (is_numeric(array_search($model,$problem_models))) {
98     $file_name = $config_directory . $file_prefix . "prob." . $default_name ;
99   }
100   else {
101     $file_name = $config_directory . $file_prefix . $default_name ;
102   }
103   readfile($file_name); 
104
105
106 ?>