3 // /etc/ntp.conf generator
5 // Marc Fiuczynski <mef@cs.princeton.edu>
6 // Copyright (C) 2006 The Trustees of Princeton University
11 // Get admin API handle
12 require_once 'plc_api.php';
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;
22 $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR']));
24 if (!empty($interfaces)) {
25 $nodes = $adm->GetNodes(array($interfaces[0]['node_id']));
36 $problem_models = array("Dell Precision 340", "Unknown");
38 $hostname= trim($node['hostname']);
39 $model= trim($node['model']);
41 /* pull LatLong data */
42 $sites = $adm->GetSites(array($node['site_id']));
44 $site_name= $sites[0]['name'];
45 $mylat= $sites[0]['latitude'];
46 $mylong= $sites[0]['longitude'];
48 $site_name= "Unknown";
53 /* typical NTP settings */
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" );
62 /* Look for config file */
64 $hostname_bits = explode('.', $hostname);
65 $chunk_counter = sizeof ($hostname_bits);
66 $compare_chunk = $hostname ;
69 /* look for host specific overrides */
70 $file_name = $config_directory . "host/" . $file_prefix . $compare_chunk ;
71 if (is_file($file_name)) {
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)) {
84 array_shift($hostname_bits);
85 $compare_chunk = implode('.',$hostname_bits);
91 if ($found_file and is_readable($file_name)) {
95 if (is_numeric(array_search($model,$problem_models))) {
96 $file_name = $config_directory . $file_prefix . "prob." . $default_name ;
99 $file_name = $config_directory . $file_prefix . $default_name ;
101 readfile($file_name);