Project

General

Profile

« Previous | Next » 

Revision b5d5da0c

Added by Viktor Gurov about 5 years ago

Add option to disable NTP server. Issue #3567

View differences:

src/etc/inc/rrd.inc
797 797
		/* End Captive Portal statistics */
798 798

  
799 799
		/* NTP, set up the ntpd rrd file */
800
		if (isset($config['ntpd']['statsgraph'])) {
800
		if (isset($config['ntpd']['statsgraph']) && ($config['ntpd']['enable'] != 'disabled')) {
801 801
			/* set up the ntpd rrd file */
802 802
			if (!file_exists("$rrddbpath$ntpd")) {
803 803
				$rrdcreate = "$rrdtool create $rrddbpath$ntpd --step $rrdntpdinterval ";
src/etc/inc/service-utils.inc
269 269
	$pconfig['description'] = gettext("PC/SC Smart Card Daemon");
270 270
	$services[] = $pconfig;
271 271

  
272
	$pconfig = array();
273
	$pconfig['name'] = "ntpd";
274
	$pconfig['description'] = gettext("NTP clock sync");
275
	$services[] = $pconfig;
272
	if (is_array($config['ntpd']) && ($config['ntpd']['enable'] != 'disabled')) {
273
		$pconfig = array();
274
		$pconfig['name'] = "ntpd";
275
		$pconfig['description'] = gettext("NTP clock sync");
276
		$services[] = $pconfig;
277
	}
276 278

  
277 279
	$pconfig = array();
278 280
	$pconfig['name'] = "syslogd";
src/etc/inc/system.inc
1592 1592
function system_ntp_setup_gps($serialport) {
1593 1593
	global $config, $g;
1594 1594

  
1595
	if (is_array($config['ntpd']) && ($config['ntpd']['enable'] == 'disabled')) {
1596
		return false;
1597
	}
1598

  
1595 1599
	init_config_arr(array('ntpd', 'gps', 'speed'));
1596 1600
	$gps_device = '/dev/gps0';
1597 1601
	$serialport = '/dev/'.$serialport;
......
1685 1689
	if (!file_exists($serialport)) {
1686 1690
		return false;
1687 1691
	}
1692
	// If ntpd is disabled, just return
1693
	if (is_array($config['ntpd']) && ($config['ntpd']['enable'] == 'disabled')) {
1694
		return false;
1695
	}
1688 1696

  
1689 1697
	// Create symlink that ntpd requires
1690 1698
	unlink_if_exists($pps_device);
......
1694 1702
	return true;
1695 1703
}
1696 1704

  
1697

  
1698 1705
function system_ntp_configure() {
1699 1706
	global $config, $g;
1700 1707
	global $ntp_poll_min_default_gps, $ntp_poll_max_default_gps;
......
1710 1717
	if (!is_array($config['ntpd'])) {
1711 1718
		$config['ntpd'] = array();
1712 1719
	}
1720
	// ntpd is disabled, just stop it and return
1721
	if ($config['ntpd']['enable'] == 'disabled') {
1722
		while (isvalidpid("{$g['varrun_path']}/ntpd.pid")) {
1723
			killbypid("{$g['varrun_path']}/ntpd.pid");
1724
		}
1725
		@unlink("{$g['varrun_path']}/ntpd.pid");
1726
		@unlink("{$g['varetc_path']}/ntpd.conf");
1727
		log_error("NTPD is disabled.");
1728
		return;
1729
	}
1730

  
1731
	if (platform_booting()) {
1732
		echo gettext("Starting NTP Server...");
1733
	}
1713 1734

  
1714 1735
	/* if ntpd is running, kill it */
1715 1736
	while (isvalidpid("{$g['varrun_path']}/ntpd.pid")) {
......
2050 2071
		mkdir("/var/empty", 0555, true);
2051 2072
	}
2052 2073

  
2053
	/* start opentpd, set time now and use /var/etc/ntpd.conf */
2074
	/* start ntpd, set time now and use /var/etc/ntpd.conf */
2054 2075
	mwexec("/usr/local/sbin/ntpd -g -c {$g['varetc_path']}/ntpd.conf -p {$g['varrun_path']}/ntpd.pid", false, true);
2055 2076

  
2056 2077
	// Note that we are starting up
2057 2078
	log_error("NTPD is starting up.");
2079

  
2080
	if (platform_booting()) {
2081
		echo gettext("done.") . "\n";
2082
	}
2083

  
2058 2084
	return;
2059 2085
}
2060 2086

  
src/etc/rc.bootup
290 290
system_routing_enable();
291 291

  
292 292
/* Enable ntpd */
293
echo "Starting NTP time client...";
294 293
system_ntp_configure();
295
echo "done.\n";
296 294

  
297 295
/* Configure console (and serial port - if necessary). */
298 296
console_configure();
src/usr/local/www/services_ntpd.php
93 93
	}
94 94

  
95 95
	if (!$input_errors) {
96
		$config['ntpd']['enable'] = isset($pconfig['enable']) ? 'enabled' : 'disabled';
96 97
		if (is_array($_POST['interface'])) {
97 98
			$config['ntpd']['interface'] = implode(",", $_POST['interface']);
98 99
		} elseif (isset($config['ntpd']['interface'])) {
......
221 222

  
222 223
init_config_arr(array('ntpd'));
223 224
$pconfig = &$config['ntpd'];
225
$config['ntpd']['enable'] = isset($pconfig['enable']) ? 'enabled' : 'disabled';
224 226
if (empty($pconfig['interface'])) {
225 227
	$pconfig['interface'] = array();
226 228
} else {
......
251 253

  
252 254
$section = new Form_Section('NTP Server Configuration');
253 255

  
256
$section->addInput(new Form_Checkbox(
257
	'enable',
258
	'Enable',
259
	'Enable NTP Server',
260
	$pconfig['enable']
261
))->setHelp('You may need to disable NTP if pfSense is running in a virtual machine and the host is responsible for the clock.');
262

  
254 263
$iflist = build_interface_list();
255 264

  
256 265
$section->addInput(new Form_Select(
src/usr/local/www/status_ntpd.php
45 45
	}
46 46
}
47 47

  
48
if ($allow_query) {
48
if ($allow_query && ($config['ntpd']['enable'] != 'disabled')) {
49 49
	if (isset($config['system']['ipv6allow'])) {
50 50
		$inet_version = "";
51 51
	} else {
......
206 206
function print_status() {
207 207
	global $config, $ntpq_servers, $allow_query;
208 208

  
209
	if (!$allow_query):
210

  
209
	if ($config['ntpd']['enable'] == 'disabled'):
210
		print("<tr>\n");
211
		print('<td class="warning" colspan="11">');
212
		printf(gettext('NTP Server is disabled'));
213
		print("</td>\n");
214
		print("</tr>\n");
215
	elseif (!$allow_query):
211 216
		print("<tr>\n");
212 217
		print('<td class="warning" colspan="11">');
213 218
		printf(gettext('Statistics unavailable because ntpq and ntpdc queries are disabled in the %1$sNTP service settings%2$s'), '<a href="services_ntpd.php">', '</a>');
src/usr/local/www/widgets/widgets/ntp_status.widget.php
30 30
// to once per 60 seconds, not once per 10 seconds
31 31
$widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period'] * 1000 * 6 : 60000;
32 32

  
33
if ($_REQUEST['updateme']) {
33
if ($_REQUEST['updateme'] && is_array($config['ntpd']) && ($config['ntpd']['enable'] != 'disabled')) {
34 34
//this block displays only on ajax refresh
35 35
	if (isset($config['system']['ipv6allow'])) {
36 36
		$inet_version = "";
......
147 147
?>
148 148

  
149 149
<table id="ntp_status_widget" class="table table-striped table-hover">
150
<?php if (is_array($config['ntpd']) && ($config['ntpd']['enable'] != 'disabled')): ?>
150 151
	<tr>
151 152
		<th><?=gettext('Server Time')?></th>
152 153
		<td id="ClockTime">
......
188 189
			</tr>
189 190
		<?php endif; ?>
190 191
	<?php endif; ?>
192
<?php else: ?>
193
	<tr>
194
		<td class="text-danger"><?=gettext('NTP Server is disabled')?></td>
195
	</tr>
196
<?php endif; ?>
191 197
</table>
192 198

  
193 199
<?php
......
225 231
<table id="ntpstatus" class="table table-striped table-hover">
226 232
	<tbody>
227 233
		<tr>
228
			<td>
229
				<?=gettext('Updating...')?>
230
			</td>
234
		<?php if (is_array($config['ntpd']) && ($config['ntpd']['enable'] != 'disabled')): ?>
235
			<td><?=gettext('Updating...')?></td>
236
		<?php else: ?>
237
			<td class="text-danger"><?=gettext('NTP Server is disabled')?></td>
238
		<?php endif; ?>
231 239
		</tr>
232 240
	</tbody>
233 241
</table>

Also available in: Unified diff