Revision b2305621
Added by Ermal LUÇI about 14 years ago
etc/inc/system.inc | ||
---|---|---|
1147 | 1147 |
function system_ntp_configure() { |
1148 | 1148 |
global $config, $g; |
1149 | 1149 |
|
1150 |
$syscfg =& $config['system']; |
|
1151 |
|
|
1152 |
/* open configuration for wrting or bail */ |
|
1153 |
$fd = fopen("{$g['varetc_path']}/ntpd.conf","w"); |
|
1154 |
if(!$fd) { |
|
1155 |
log_error("Could not open {$g['varetc_path']}/ntpd.conf for writing"); |
|
1156 |
return; |
|
1157 |
} |
|
1158 |
|
|
1159 |
fwrite($fd, "# \n"); |
|
1160 |
fwrite($fd, "# pfSense OpenNTPD configuration file \n"); |
|
1161 |
fwrite($fd, "# \n\n"); |
|
1150 |
$ntpcfg = "# \n"; |
|
1151 |
$ntpcfg .= "# pfSense OpenNTPD configuration file \n"; |
|
1152 |
$ntpcfg .= "# \n\n"; |
|
1162 | 1153 |
|
1163 | 1154 |
/* foreach through servers and write out to ntpd.conf */ |
1164 |
foreach (explode(' ', $syscfg['timeservers']) as $ts)
|
|
1165 |
fwrite($fd, "servers {$ts}\n");
|
|
1155 |
foreach (explode(' ', $config['system']['timeservers']) as $ts)
|
|
1156 |
$ntpcfg .= "servers {$ts}\n";
|
|
1166 | 1157 |
|
1167 | 1158 |
/* Setup listener(s) if the user has configured one */ |
1168 | 1159 |
if ($config['installedpackages']['openntpd']) { |
... | ... | |
1175 | 1166 |
$ips = array_map('find_interface_ip', $ifaces); |
1176 | 1167 |
foreach ($ips as $ip) { |
1177 | 1168 |
if (is_ipaddr($ip)) |
1178 |
fwrite($fd, "listen on $ip\n");
|
|
1169 |
$ntpdcfg .= "listen on $ip\n";
|
|
1179 | 1170 |
} |
1180 | 1171 |
} |
1181 | 1172 |
} |
1173 |
$ntpdcfg .= "\n"; |
|
1182 | 1174 |
|
1183 |
fwrite($fd, "\n"); |
|
1175 |
/* open configuration for wrting or bail */ |
|
1176 |
$fd = fopen("{$g['varetc_path']}/ntpd.conf","w"); |
|
1177 |
if(!$fd) { |
|
1178 |
log_error("Could not open {$g['varetc_path']}/ntpd.conf for writing"); |
|
1179 |
return; |
|
1180 |
} |
|
1181 |
fwrite($fd, $ntpcfg); |
|
1184 | 1182 |
|
1185 | 1183 |
/* slurp! */ |
1186 | 1184 |
fclose($fd); |
... | ... | |
1208 | 1206 |
function sync_system_time() { |
1209 | 1207 |
global $config, $g; |
1210 | 1208 |
|
1211 |
$syscfg = $config['system']; |
|
1212 |
|
|
1213 | 1209 |
if ($g['booting']) |
1214 | 1210 |
echo "Syncing system time before startup..."; |
1215 | 1211 |
|
1216 | 1212 |
/* foreach through servers and write out to ntpd.conf */ |
1217 |
foreach (explode(' ', $syscfg['timeservers']) as $ts) {
|
|
1213 |
foreach (explode(' ', $config['system']['timeservers']) as $ts) {
|
|
1218 | 1214 |
mwexec("/usr/sbin/ntpdate -s $ts"); |
1219 | 1215 |
} |
1220 | 1216 |
|
Also available in: Unified diff
Generate the config file in a variable then write it as a whole to a file.