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 // backwards compatibility with the old 4.2 API
23 if ( ! method_exists ($adm,"GetInterfaces"))
24 $interfaces = $adm->GetNodeNetworks(array('ip' => $_SERVER['REMOTE_ADDR']));
26 $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR']));
28 if (!empty($interfaces)) {
29 $nodes = $adm->GetNodes(array($interfaces[0]['node_id']));
40 $problem_models = array("Dell Precision 340", "Unknown");
42 $hostname= trim($node['hostname']);
43 $model= trim($node['model']);
45 /* pull LatLong data */
46 $sites = $adm->GetSites(array($node['site_id']));
48 $site_name= $sites[0]['name'];
49 $mylat= $sites[0]['latitude'];
50 $mylong= $sites[0]['longitude'];
52 $site_name= "Unknown";
57 /* typical NTP settings */
59 print( "# node $hostname site $site_name $mylat $mylong $model\n");
60 print( "driftfile /var/lib/ntp/ntp.drift\n" );
61 print( "statsdir /var/log/ntpstats/\n" );
62 if (is_numeric(array_search($model, $problem_models))) {
63 print( "tinker stepout 0\n" );
66 /* Look for config file */
68 $hostname_bits = explode('.', $hostname);
69 $chunk_counter = sizeof ($hostname_bits);
70 $compare_chunk = $hostname ;
73 /* look for host specific overrides */
74 $file_name = $config_directory . "host/" . $file_prefix . $compare_chunk ;
75 if (is_file($file_name)) {
80 /* look for domain specific overrides */
81 while ($chunk_counter > 0) {
82 $file_name = $config_directory . $file_prefix . $compare_chunk ;
83 if (is_file($file_name)) {
88 array_shift($hostname_bits);
89 $compare_chunk = implode('.',$hostname_bits);
95 if ($found_file and is_readable($file_name)) {
99 if (is_numeric(array_search($model,$problem_models))) {
100 $file_name = $config_directory . $file_prefix . "prob." . $default_name ;
103 $file_name = $config_directory . $file_prefix . $default_name ;
105 readfile($file_name);