Project

General

Profile

« Previous | Next » 

Revision bb39c283

Added by Jim Pingle about 13 years ago

Switch to ntpd from ports, add Services > NTP to select interfaces for binding. Respect old ntp settings in the process.

Conflicts:

etc/inc/system.inc
usr/local/www/fbegin.inc

View differences:

etc/inc/system.inc
33 33
	pfSense_BUILDER_BINARIES:	/usr/sbin/powerd	/usr/bin/killall	/sbin/sysctl	/sbin/route
34 34
	pfSense_BUILDER_BINARIES:	/bin/hostname	/bin/ls	/usr/sbin/syslogd	
35 35
	pfSense_BUILDER_BINARIES:	/usr/sbin/pccardd	/usr/local/sbin/lighttpd	/bin/chmod 	/bin/mkdir
36
	pfSense_BUILDER_BINARIES:	/usr/bin/tar		/usr/sbin/ntpd	/usr/sbin/ntpdate
36
	pfSense_BUILDER_BINARIES:	/usr/bin/tar		/usr/local/bin/ntpd	/usr/sbin/ntpdate
37 37
	pfSense_BUILDER_BINARIES:	/usr/bin/nohup	/sbin/dmesg	/usr/local/sbin/atareinit	/sbin/kldload
38 38
	pfSense_MODULE:	utils
39 39
*/
......
1120 1120

  
1121 1121
	$ntpcfg .= "driftfile {$driftfile}\n";
1122 1122

  
1123
	if (empty($config['ntpd']['interface']))
1124
		if (empty($config['openntpd']['config']['interface']))
1125
			$interfaces = explode(",", $config['installedpackages']['openntpd']['config'][0]['interface']);
1126
		else
1127
			$interfaces = array();
1128
	else
1129
		$interfaces = explode(",", $config['ntpd']['interface']);
1130

  
1131
	if (is_array($interfaces) && count($interfaces)) {
1132
		$ntpcfg .= "interface ignore all\n";
1133
		foreach ($interfaces as $interface) {
1134
			if (!is_ipaddr($interface)) {
1135
				$interface = get_real_interface($interface);
1136
			}
1137
			$ntpcfg .= "interface listen {$interface}\n";
1138
		}
1139
	}
1140

  
1123 1141
	/* open configuration for wrting or bail */
1124 1142
	$fd = fopen("{$g['varetc_path']}/ntpd.conf","w");
1125 1143
	if(!$fd) {
......
1145 1163
		exec("/bin/mkdir -p /var/empty && chmod ug+rw /var/empty/.");
1146 1164

  
1147 1165
	/* start ntpd, allow a large initial skew, and use /var/etc/ntpd.conf - run through tcsh to work around a PHP shell exec bug. */
1148
	exec("echo /usr/sbin/ntpd -g -c {$g['varetc_path']}/ntpd.conf | tcsh");
1166
	exec("echo /usr/local/bin/ntpd -g -c {$g['varetc_path']}/ntpd.conf | tcsh");
1149 1167
	
1150 1168
	// Note that we are starting up
1151 1169
	log_error("NTPD is starting up.");
usr/local/sbin/ntpdate_sync_once.sh
26 26
fi
27 27

  
28 28
if [ -f /var/etc/ntpd.conf ]; then
29
	/usr/sbin/ntpd -g -c /var/etc/ntpd.conf
29
	/usr/local/bin/ntpd -g -c /var/etc/ntpd.conf
30 30
fi
usr/local/www/fbegin.inc
125 125
$services_menu[] = array("Dynamic DNS", "/services_dyndns.php");
126 126
$services_menu[] = array("IGMP proxy", "/services_igmpproxy.php");
127 127
$services_menu[] = array("Load Balancer", "/load_balancer_pool.php");
128
$services_menu[] = array(gettext("NTP"), "/services_ntpd.php");
128 129
$services_menu[] = array("OLSR", "/pkg_edit.php?xml=olsrd.xml&id=0");
129 130
$services_menu[] = array("PPPoE Server", "/vpn_pppoe.php");
130 131
$services_menu[] = array("RIP", "/pkg_edit.php?xml=routed.xml&id=0");
usr/local/www/services_ntpd.php
1
<?php
2
/*
3
	services_ntpd.php
4

  
5
	Copyright (C) 2012	Jim Pingle
6
	All rights reserved.
7

  
8
	Redistribution and use in source and binary forms, with or without
9
	modification, are permitted provided that the following conditions are met:
10

  
11
	1. Redistributions of source code must retain the above copyright notice,
12
	   this list of conditions and the following disclaimer.
13

  
14
	2. Redistributions in binary form must reproduce the above copyright
15
	   notice, this list of conditions and the following disclaimer in the
16
	   documentation and/or other materials provided with the distribution.
17

  
18
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
	POSSIBILITY OF SUCH DAMAGE.
28
*/
29
/*
30
	pfSense_MODULE:	ntpd
31
*/
32

  
33
##|+PRIV
34
##|*IDENT=page-services-ntpd
35
##|*NAME=Services: NTP
36
##|*DESCR=Allow access to the 'Services: NTP' page.
37
##|*MATCH=services_ntpd.php*
38
##|-PRIV
39

  
40
require("guiconfig.inc");
41

  
42
if (empty($config['ntpd']['interface']))
43
	if (empty($config['openntpd']['config']['interface'])) {
44
		$pconfig['interface'] = explode(",", $config['installedpackages']['openntpd']['config'][0]['interface']);
45
		unset($config['installedpackages']['openntpd']);
46
	} else
47
		$pconfig['interface'] = array();
48
else
49
	$pconfig['interface'] = explode(",", $config['ntpd']['interface']);
50

  
51
if ($_POST) {
52

  
53
	unset($input_errors);
54
	$pconfig = $_POST;
55

  
56
	/* input validation */
57
	$reqdfields = explode(" ", "interface");
58
	$reqdfieldsn = array(gettext("Interface"));
59

  
60
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
61

  
62
	if (!$input_errors) {
63
		$config['ntpd']['interface'] = implode(",", $_POST['interface']);
64

  
65
		write_config("Updated NTP Server Settings");
66

  
67
		$retval = 0;
68
		$retval = system_ntp_configure();
69
		$savemsg = get_std_save_message($retval);
70

  
71
	}
72
}
73

  
74
$pgtitle = array(gettext("Services"),gettext("NTP"));
75
include("head.inc");
76

  
77
?>
78

  
79
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
80
<?php include("fbegin.inc"); ?>
81
<form action="services_ntpd.php" method="post" name="iform" id="iform">
82
<?php if ($input_errors) print_input_errors($input_errors); ?>
83
<?php if ($savemsg) print_info_box($savemsg); ?>
84

  
85
<table width="100%" border="0" cellpadding="0" cellspacing="0">
86
<tr><td><div id="mainarea">
87
<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
88
<tr>
89
	<td colspan="2" valign="top" class="listtopic"><?=gettext("NTP Server Configuration"); ?></td>
90
</tr>
91
<tr>
92
	<td width="22%" valign="top" class="vncellreq">Interface(s)</td>
93
	<td width="78%" class="vtable">
94
<?php
95
	$interfaces = get_configured_interface_with_descr();
96
	$carplist = get_configured_carp_interface_list();
97
	foreach ($carplist as $cif => $carpip)
98
		$interfaces[$cif] = $carpip." (".get_vip_descr($carpip).")";
99
	$aliaslist = get_configured_ip_aliases_list();
100
	foreach ($aliaslist as $aliasip => $aliasif)
101
		$interfaces[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
102
	$size = (count($interfaces) < 10) ? count($interfaces) : 10;
103
?>
104
	<select id="interface" name="interface[]" multiple="true" class="formselect" size="<?php echo $size; ?>">
105
<?php	
106
	foreach ($interfaces as $iface => $ifacename) {
107
		if (!is_ipaddr(get_interface_ip($iface)) && !is_ipaddr($iface))
108
			continue;
109
		echo "<option value='{$iface}'";
110
		if (in_array($iface, $pconfig['interface']))
111
			echo "selected";
112
		echo ">{$ifacename}</option>\n";
113
	} ?>
114
	</select>
115
	<br/>Interfaces without an IP address will not be shown.
116
	<br/>
117
	<br/>Selecting no interfaces will listen on all interfaces with a wildcard.
118
	<br/>Selecting all interfaces will explicitly listen on only the interfaces/IPs specified.
119
	</td>
120
</tr>
121
<tr>
122
	<td width="22%" valign="top">&nbsp;</td>
123
	<td width="78%">
124
	<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onclick="enable_change(true)">
125
	</td>
126
</tr>
127
</table>
128
</div></td></tr></table>
129
</form>
130
<?php include("fend.inc"); ?>
131
</body>
132
</html>
usr/local/www/status_ntpd.php
29 29
	POSSIBILITY OF SUCH DAMAGE.
30 30
*/
31 31
/*
32
	pfSense_BUILDER_BINARIES:	/usr/sbin/ntpd	/usr/bin/ntpq
33
	pfSense_MODULE:	routing
32
	pfSense_BUILDER_BINARIES:	/usr/local/bin/ntpd	/usr/local/bin/ntpq
33
	pfSense_MODULE:	ntpd
34 34
*/
35 35

  
36 36
##|+PRIV
......
42 42

  
43 43
require_once("guiconfig.inc");
44 44

  
45
exec("/usr/bin/ntpq -pn | /usr/bin/tail +3", $ntpq_output);
45
exec("/usr/local/bin/ntpq -pn | /usr/bin/tail +3", $ntpq_output);
46 46
$ntpq_servers = array();
47 47
foreach ($ntpq_output as $line) {
48 48
	$server = array();
......
99 99
<table width="100%" border="0" cellpadding="0" cellspacing="0">
100 100
<tr><td><div id="mainarea">
101 101
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
102
		<tr><td>Status of the system's Network Time Protocol servers and clock.</td></tr>
102
		<tr><td class="listtopic">Network Time Protocol Status</td></tr>
103 103
	</table>
104 104
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
105 105
	<thead>

Also available in: Unified diff