3 // /etc/ntp.conf generator
5 // Marc Fiuczynski <mef@cs.princeton.edu>
6 // Copyright (C) 2006 The Trustees of Princeton University
9 // Get admin API handle
10 require_once 'plc_api.php';
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;
19 $nodes = $adm->GetNodes(array('node_id' => (int)$_GET['node_id']));
30 $problem_models = array("Dell Precision 340", "Unknown");
32 $hostname= trim($node['hostname']);
33 $model= trim($node['model']);
35 /* pull LatLong data */
36 $sites = $adm->GetSites(array($node['site_id']));
38 $site_name= $sites[0]['name'];
39 $mylat= $sites[0]['latitude'];
40 $mylong= $sites[0]['longitude'];
42 $site_name= "Unknown";
47 /* typical NTP settings */
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");
56 print( "restrict 127.0.0.1");
57 print( "restrict -6 ::1");
59 if (is_numeric(array_search($model, $problem_models))) {
60 print( "tinker stepout 0\n" );
63 /* Look for config file */
65 $hostname_bits = explode('.', $hostname);
66 $chunk_counter = sizeof ($hostname_bits);
67 $compare_chunk = $hostname ;
70 /* look for host specific overrides */
71 $file_name = $config_directory . "host/" . $file_prefix . $compare_chunk ;
72 if (is_file($file_name)) {
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)) {
85 array_shift($hostname_bits);
86 $compare_chunk = implode('.',$hostname_bits);
92 if ($found_file and is_readable($file_name)) {
96 if (is_numeric(array_search($model,$problem_models))) {
97 $file_name = $config_directory . $file_prefix . "prob." . $default_name ;
100 $file_name = $config_directory . $file_prefix . $default_name ;
102 readfile($file_name);