Project

General

Profile

Download (5.91 KB) Statistics
| Branch: | Tag: | Revision:
1 cf180ccc jim-p
<?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 d2b2872a jim-p
	if ($config['installedpackages']['openntpd'] && empty($config['installedpackages']['openntpd']['config'][0]['interface'])) {
44 46ca7f3d jim-p
		$pconfig['interface'] = explode(",", $config['installedpackages']['openntpd']['config'][0]['interface']);
45 cf180ccc jim-p
		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
	if (!$input_errors) {
57 58168f4e jim-p
		if (is_array($_POST['interface']))
58
			$config['ntpd']['interface'] = implode(",", $_POST['interface']);
59
		elseif (isset($config['ntpd']['interface']))
60
			unset($config['ntpd']['interface']);
61 cf180ccc jim-p
62 5c8843d5 jim-p
		if (!empty($_POST['gpsport']) && file_exists('/dev/'.$_POST['gpsport']))
63
			$config['ntpd']['gpsport'] = $_POST['gpsport'];
64 6162b068 jim-p
		elseif (isset($config['ntpd']['gpsport']))
65 5c8843d5 jim-p
			unset($config['ntpd']['gpsport']);
66
67 cf180ccc jim-p
		write_config("Updated NTP Server Settings");
68
69
		$retval = 0;
70
		$retval = system_ntp_configure();
71
		$savemsg = get_std_save_message($retval);
72
73
	}
74
}
75
76
$pgtitle = array(gettext("Services"),gettext("NTP"));
77 b32dd0a6 jim-p
$shortcut_section = "ntp";
78 cf180ccc jim-p
include("head.inc");
79
80
?>
81
82
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
83
<?php include("fbegin.inc"); ?>
84
<form action="services_ntpd.php" method="post" name="iform" id="iform">
85
<?php if ($input_errors) print_input_errors($input_errors); ?>
86
<?php if ($savemsg) print_info_box($savemsg); ?>
87
88
<table width="100%" border="0" cellpadding="0" cellspacing="0">
89
<tr><td><div id="mainarea">
90
<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
91
<tr>
92
	<td colspan="2" valign="top" class="listtopic"><?=gettext("NTP Server Configuration"); ?></td>
93
</tr>
94
<tr>
95
	<td width="22%" valign="top" class="vncellreq">Interface(s)</td>
96
	<td width="78%" class="vtable">
97
<?php
98
	$interfaces = get_configured_interface_with_descr();
99
	$carplist = get_configured_carp_interface_list();
100
	foreach ($carplist as $cif => $carpip)
101
		$interfaces[$cif] = $carpip." (".get_vip_descr($carpip).")";
102
	$aliaslist = get_configured_ip_aliases_list();
103
	foreach ($aliaslist as $aliasip => $aliasif)
104
		$interfaces[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
105
	$size = (count($interfaces) < 10) ? count($interfaces) : 10;
106
?>
107
	<select id="interface" name="interface[]" multiple="true" class="formselect" size="<?php echo $size; ?>">
108
<?php	
109
	foreach ($interfaces as $iface => $ifacename) {
110
		if (!is_ipaddr(get_interface_ip($iface)) && !is_ipaddr($iface))
111
			continue;
112
		echo "<option value='{$iface}'";
113
		if (in_array($iface, $pconfig['interface']))
114
			echo "selected";
115
		echo ">{$ifacename}</option>\n";
116
	} ?>
117
	</select>
118
	<br/>
119 5c8843d5 jim-p
	<br/><?php echo gettext("Interfaces without an IP address will not be shown."); ?>
120
	<br/>
121
	<br/><?php echo gettext("Selecting no interfaces will listen on all interfaces with a wildcard."); ?>
122
	<br/><?php echo gettext("Selecting all interfaces will explicitly listen on only the interfaces/IPs specified."); ?>
123
	</td>
124
</tr>
125
<?php /* Probing would be nice, but much more complex. Would need to listen to each port for 1s+ and watch for strings. */ ?>
126
<?php $serialports = glob("/dev/cua?[0-9]{,.[0-9]}", GLOB_BRACE); ?>
127
<?php if (!empty($serialports)): ?>
128
<tr>
129
	<td width="22%" valign="top" class="vncellreq">Serial GPS</td>
130
	<td width="78%" class="vtable">
131
		<select name="gpsport">
132
			<option value="">none</option>
133
			<?php foreach ($serialports as $port):
134
				$shortport = substr($port,5);
135
				$selected = ($shortport == $config['ntpd']['gpsport']) ? " selected" : "";?>
136
				<option value="<?php echo $shortport;?>"<?php echo $selected;?>><?php echo $shortport;?></option>
137
			<?php endforeach; ?>
138
		</select>
139
		<br/>
140 5a429ed6 jim-p
		<br/><?php echo gettext("The GPS must provide NMEA format output!"); ?>
141 5c8843d5 jim-p
		<br/>
142
		<br/><?php echo gettext("All serial ports are listed, be sure to pick only the port with the GPS attached."); ?>
143
		<br/>
144 c1406943 jim-p
		<br/><?php echo gettext("It is best to configure at least 2 servers under"); ?> <a href="system.php"><?php echo gettext("System > General"); ?></a> <?php echo gettext("to avoid loss of sync if the GPS data is not valid over time. Otherwise ntpd may only use values from the unsynchronized local clock when providing time to clients."); ?>
145 cf180ccc jim-p
	</td>
146
</tr>
147 5c8843d5 jim-p
<?php endif; ?>
148 cf180ccc jim-p
<tr>
149
	<td width="22%" valign="top">&nbsp;</td>
150
	<td width="78%">
151
	<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onclick="enable_change(true)">
152
	</td>
153
</tr>
154
</table>
155
</div></td></tr></table>
156
</form>
157
<?php include("fend.inc"); ?>
158
</body>
159
</html>