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;
21 $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR']));
22 if (!empty($interfaces)) {
23 $nodes = $adm->GetNodes(array($interfaces[0]['node_id']));
34 $problem_models = array("Dell Precision 340", "Unknown");
36 $hostname= trim($node['hostname']);
37 $model= trim($node['model']);
39 /* pull LatLong data */
40 $sites = $adm->GetSites(array($node['site_id']));
42 $site_name= $sites[0]['name'];
43 $mylat= $sites[0]['latitude'];
44 $mylong= $sites[0]['longitude'];
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 if (is_numeric(array_search($model, $problem_models))) {
53 print( "tinker stepout 0\n" );
56 /* Look for config file */
58 $hostname_bits = explode('.', $hostname);
59 $chunk_counter = sizeof ($hostname_bits);
60 $compare_chunk = $hostname ;
63 /* look for host specific overrides */
64 $file_name = $config_directory . "host/" . $file_prefix . $compare_chunk ;
65 if (is_file($file_name)) {
70 /* look for domain specific overrides */
71 while ($chunk_counter > 0) {
72 $file_name = $config_directory . $file_prefix . $compare_chunk ;
73 if (is_file($file_name)) {
78 array_shift($hostname_bits);
79 $compare_chunk = implode('.',$hostname_bits);
85 if ($found_file and is_readable($file_name)) {
89 if (is_numeric(array_search($model,$problem_models))) {
90 $file_name = $config_directory . $file_prefix . "prob." . $default_name ;
93 $file_name = $config_directory . $file_prefix . $default_name ;