Project

General

Profile

Download (21.4 KB) Statistics
| Branch: | Tag: | Revision:
1 cf180ccc jim-p
<?php
2
/*
3 c5d81585 Renato Botelho
 * services_ntpd.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 38809d47 Renato Botelho do Couto
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8 8f585441 Luiz Souza
 * Copyright (c) 2014-2021 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * Copyright (c) 2013 Dagorlad
10
 * All rights reserved.
11
 *
12 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
13
 * you may not use this file except in compliance with the License.
14
 * You may obtain a copy of the License at
15 c5d81585 Renato Botelho
 *
16 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
17 c5d81585 Renato Botelho
 *
18 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
19
 * distributed under the License is distributed on an "AS IS" BASIS,
20
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
 * See the License for the specific language governing permissions and
22
 * limitations under the License.
23 f4439c00 Stephen Beaver
 */
24 cf180ccc jim-p
25
##|+PRIV
26
##|*IDENT=page-services-ntpd
27 448280c3 k-paulius
##|*NAME=Services: NTP Settings
28
##|*DESCR=Allow access to the 'Services: NTP Settings' page.
29 cf180ccc jim-p
##|*MATCH=services_ntpd.php*
30
##|-PRIV
31
32 820562e8 NewEraCracker
define('NUMTIMESERVERS', 10);		// The maximum number of configurable time servers
33 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
34 c1e68244 nagyrobi
require_once('rrd.inc');
35
require_once("shaper.inc");
36 cf180ccc jim-p
37 8ef6844a jim-p
global $ntp_poll_min_default, $ntp_poll_max_default;
38
$ntp_poll_values = system_ntp_poll_values();
39 27e1febb Viktor G
$auto_pool_suffix = "pool.ntp.org";
40 9c2fcbf6 kiokoman
$max_candidate_peers = 25;
41 aef7d92a kiokoman
$min_candidate_peers = 4;
42 8ef6844a jim-p
43 7a6f0ebc Phil Davis
if (!is_array($config['ntpd'])) {
44 08005d0a Ermal
	$config['ntpd'] = array();
45 7a6f0ebc Phil Davis
}
46 08005d0a Ermal
47
if (empty($config['ntpd']['interface'])) {
48
	if (is_array($config['installedpackages']['openntpd']) && is_array($config['installedpackages']['openntpd']['config']) &&
49 20db3e1a Phil Davis
	    is_array($config['installedpackages']['openntpd']['config'][0]) && !empty($config['installedpackages']['openntpd']['config'][0]['interface'])) {
50 46ca7f3d jim-p
		$pconfig['interface'] = explode(",", $config['installedpackages']['openntpd']['config'][0]['interface']);
51 cf180ccc jim-p
		unset($config['installedpackages']['openntpd']);
52 62725308 Viktor Gurov
		write_config(gettext("Upgraded settings from openntpd"));
53 7a6f0ebc Phil Davis
	} else {
54 cf180ccc jim-p
		$pconfig['interface'] = array();
55 7a6f0ebc Phil Davis
	}
56
} else {
57 cf180ccc jim-p
	$pconfig['interface'] = explode(",", $config['ntpd']['interface']);
58 7a6f0ebc Phil Davis
}
59 cf180ccc jim-p
60 08d56bd1 sbeaver
if ($_POST) {
61 cf180ccc jim-p
	unset($input_errors);
62
	$pconfig = $_POST;
63
64 bfcf5d7c Viktor Gurov
	if (!empty($_POST['ntpmaxpeers']) && (!is_numericint($_POST['ntpmaxpeers']) ||
65
	    ($_POST['ntpmaxpeers'] < $min_candidate_peers) || ($_POST['ntpmaxpeers'] > $max_candidate_peers))) {
66 b33465da kiokoman
		$input_errors[] = sprintf(gettext("Max candidate pool peers must be a number between %d and %d"), $min_candidate_peers, $max_candidate_peers);
67 38fcf2c5 kiokoman
	}
68
	
69 531c3486 jim-p
	if ((strlen($pconfig['ntporphan']) > 0) && (!is_numericint($pconfig['ntporphan']) || ($pconfig['ntporphan'] < 1) || ($pconfig['ntporphan'] > 15))) {
70
		$input_errors[] = gettext("The supplied value for NTP Orphan Mode is invalid.");
71
	}
72
73 8ef6844a jim-p
	if (!array_key_exists($pconfig['ntpminpoll'], $ntp_poll_values)) {
74
		$input_errors[] = gettext("The supplied value for Minimum Poll Interval is invalid.");
75
	}
76
77
	if (!array_key_exists($pconfig['ntpmaxpoll'], $ntp_poll_values)) {
78
		$input_errors[] = gettext("The supplied value for Maximum Poll Interval is invalid.");
79
	}
80
81 27e1febb Viktor G
	for ($i = 0; $i < NUMTIMESERVERS; $i++) {
82
		if (isset($pconfig["servselect{$i}"]) && (isset($pconfig["servispool{$i}"]) || 
83
		    (substr_compare($pconfig["server{$i}"], $auto_pool_suffix, strlen($pconfig["server{$i}"]) - strlen($auto_pool_suffix), strlen($auto_pool_suffix)) === 0))) {
84
			$input_errors[] = gettext("It is not possible to use 'No Select' for pools.");
85
		}
86 cb92c086 Viktor Gurov
		if (!empty($pconfig["server{$i}"]) && !is_domain($pconfig["server{$i}"]) &&
87
		    !is_ipaddr($pconfig["server{$i}"])) {
88
			$input_errors[] = gettext("NTP Time Server names must be valid domain names, IPv4 addresses, or IPv6 addresses");
89
		}
90 27e1febb Viktor G
	}
91
92 8ef6844a jim-p
	if (is_numericint($pconfig['ntpminpoll']) &&
93
	    is_numericint($pconfig['ntpmaxpoll']) &&
94
	    ($pconfig['ntpmaxpoll'] < $pconfig['ntpminpoll'])) {
95
		$input_errors[] = gettext("The supplied value for Minimum Poll Interval is higher than NTP Maximum Poll Interval.");
96
	}
97
98 9108d083 Viktor G
	if (isset($pconfig['serverauth'])) {
99
		if (empty($pconfig['serverauthkey'])) {
100
			$input_errors[] = gettext("The supplied value for NTP Authentication key can't be empty.");
101 a69f79bd Viktor G
		} elseif (($pconfig['serverauthalgo'] == 'md5') && ((strlen($pconfig['serverauthkey']) > 20) ||
102
		    !ctype_print($pconfig['serverauthkey']))) {
103
			$input_errors[] = gettext("The supplied value for NTP Authentication key for MD5 digest must be from 1 to 20 printable characters.");
104
		} elseif (($pconfig['serverauthalgo'] == 'sha1') && ((strlen($pconfig['serverauthkey']) != 40) ||
105 9108d083 Viktor G
		    !ctype_xdigit($pconfig['serverauthkey']))) {
106
			$input_errors[] = gettext("The supplied value for NTP Authentication key for SHA1 digest must be hex-encoded string of 40 characters.");
107 1d7ae980 Viktor G
		} elseif (($pconfig['serverauthalgo'] == 'sha256') && ((strlen($pconfig['serverauthkey']) != 64) ||
108
		    !ctype_xdigit($pconfig['serverauthkey']))) {
109
			$input_errors[] = gettext("The supplied value for NTP Authentication key for SHA256 digest must be hex-encoded string of 64 characters.");
110 9108d083 Viktor G
		}
111
	}
112
113 cf180ccc jim-p
	if (!$input_errors) {
114 c62e31f2 Viktor Gurov
		$config['ntpd']['enable'] = isset($_POST['enable']) ? 'enabled' : 'disabled';
115 7a6f0ebc Phil Davis
		if (is_array($_POST['interface'])) {
116 58168f4e jim-p
			$config['ntpd']['interface'] = implode(",", $_POST['interface']);
117 7a6f0ebc Phil Davis
		} elseif (isset($config['ntpd']['interface'])) {
118 58168f4e jim-p
			unset($config['ntpd']['interface']);
119 7a6f0ebc Phil Davis
		}
120 cf180ccc jim-p
121 c1e68244 nagyrobi
		unset($config['ntpd']['prefer']);
122
		unset($config['ntpd']['noselect']);
123 fbb652ed jim-p
		unset($config['ntpd']['ispool']);
124 c1e68244 nagyrobi
		$timeservers = '';
125 08d56bd1 sbeaver
126 83b9d03e Phil Davis
		for ($i = 0; $i < NUMTIMESERVERS; $i++) {
127 08005d0a Ermal
			$tserver = trim($_POST["server{$i}"]);
128 c1e68244 nagyrobi
			if (!empty($tserver)) {
129
				$timeservers .= "{$tserver} ";
130 27e1febb Viktor G
				if (isset($_POST["servprefer{$i}"])) {
131 7a6f0ebc Phil Davis
					$config['ntpd']['prefer'] .= "{$tserver} ";
132
				}
133 27e1febb Viktor G
				if (isset($_POST["servselect{$i}"])) {
134 7a6f0ebc Phil Davis
					$config['ntpd']['noselect'] .= "{$tserver} ";
135
				}
136 27e1febb Viktor G
				if (isset($_POST["servispool{$i}"])) {
137 fbb652ed jim-p
					$config['ntpd']['ispool'] .= "{$tserver} ";
138
				}
139 c1e68244 nagyrobi
			}
140
		}
141 7a6f0ebc Phil Davis
		if (trim($timeservers) == "") {
142 4e6b0a0e nagyrobi
			$timeservers = "pool.ntp.org";
143 7a6f0ebc Phil Davis
		}
144 c1e68244 nagyrobi
		$config['system']['timeservers'] = trim($timeservers);
145
146 bfcf5d7c Viktor Gurov
		if (!empty($pconfig['ntpmaxpeers'])) {
147
			$config['ntpd']['ntpmaxpeers'] = $pconfig['ntpmaxpeers'];
148
		} else {
149
			unset($config['ntpd']['ntpmaxpeers']);
150
		}
151 531c3486 jim-p
		$config['ntpd']['orphan'] = trim($pconfig['ntporphan']);
152 8ef6844a jim-p
		$config['ntpd']['ntpminpoll'] = $pconfig['ntpminpoll'];
153
		$config['ntpd']['ntpmaxpoll'] = $pconfig['ntpmaxpoll'];
154 bdb26b26 Viktor G
		$config['ntpd']['dnsresolv'] = $pconfig['dnsresolv'];
155 c1e68244 nagyrobi
156 7a6f0ebc Phil Davis
		if (!empty($_POST['logpeer'])) {
157 c1e68244 nagyrobi
			$config['ntpd']['logpeer'] = $_POST['logpeer'];
158 7a6f0ebc Phil Davis
		} elseif (isset($config['ntpd']['logpeer'])) {
159 c1e68244 nagyrobi
			unset($config['ntpd']['logpeer']);
160 7a6f0ebc Phil Davis
		}
161 c1e68244 nagyrobi
162 7a6f0ebc Phil Davis
		if (!empty($_POST['logsys'])) {
163 c1e68244 nagyrobi
			$config['ntpd']['logsys'] = $_POST['logsys'];
164 7a6f0ebc Phil Davis
		} elseif (isset($config['ntpd']['logsys'])) {
165 c1e68244 nagyrobi
			unset($config['ntpd']['logsys']);
166 7a6f0ebc Phil Davis
		}
167 c1e68244 nagyrobi
168 7a6f0ebc Phil Davis
		if (!empty($_POST['clockstats'])) {
169 c1e68244 nagyrobi
			$config['ntpd']['clockstats'] = $_POST['clockstats'];
170 7a6f0ebc Phil Davis
		} elseif (isset($config['ntpd']['clockstats'])) {
171 c1e68244 nagyrobi
			unset($config['ntpd']['clockstats']);
172 7a6f0ebc Phil Davis
		}
173 c1e68244 nagyrobi
174 7a6f0ebc Phil Davis
		if (!empty($_POST['loopstats'])) {
175 c1e68244 nagyrobi
			$config['ntpd']['loopstats'] = $_POST['loopstats'];
176 7a6f0ebc Phil Davis
		} elseif (isset($config['ntpd']['loopstats'])) {
177 c1e68244 nagyrobi
			unset($config['ntpd']['loopstats']);
178 7a6f0ebc Phil Davis
		}
179 c1e68244 nagyrobi
180 7a6f0ebc Phil Davis
		if (!empty($_POST['peerstats'])) {
181 c1e68244 nagyrobi
			$config['ntpd']['peerstats'] = $_POST['peerstats'];
182 7a6f0ebc Phil Davis
		} elseif (isset($config['ntpd']['peerstats'])) {
183 c1e68244 nagyrobi
			unset($config['ntpd']['peerstats']);
184 7a6f0ebc Phil Davis
		}
185 c1e68244 nagyrobi
186 7a6f0ebc Phil Davis
		if ((empty($_POST['statsgraph'])) == (isset($config['ntpd']['statsgraph']))) {
187 e2caaee8 k-paulius
			$enable_rrd_graphing = true;
188 7a6f0ebc Phil Davis
		}
189
		if (!empty($_POST['statsgraph'])) {
190 c1e68244 nagyrobi
			$config['ntpd']['statsgraph'] = $_POST['statsgraph'];
191 7a6f0ebc Phil Davis
		} elseif (isset($config['ntpd']['statsgraph'])) {
192 c1e68244 nagyrobi
			unset($config['ntpd']['statsgraph']);
193 7a6f0ebc Phil Davis
		}
194
		if (isset($enable_rrd_graphing)) {
195 e2caaee8 k-paulius
			enable_rrd_graphing();
196 7a6f0ebc Phil Davis
		}
197 c1e68244 nagyrobi
198 f99f8a67 Phil Davis
		if (!empty($_POST['leaptext'])) {
199
			$config['ntpd']['leapsec'] = base64_encode($_POST['leaptext']);
200 7a6f0ebc Phil Davis
		} elseif (isset($config['ntpd']['leapsec'])) {
201 c1e68244 nagyrobi
			unset($config['ntpd']['leapsec']);
202 7a6f0ebc Phil Davis
		}
203 c1e68244 nagyrobi
204 7a6f0ebc Phil Davis
		if (is_uploaded_file($_FILES['leapfile']['tmp_name'])) {
205 c1e68244 nagyrobi
			$config['ntpd']['leapsec'] = base64_encode(file_get_contents($_FILES['leapfile']['tmp_name']));
206 7a6f0ebc Phil Davis
		}
207 c1e68244 nagyrobi
208 9108d083 Viktor G
		if (!empty($_POST['serverauth'])) {
209
			$config['ntpd']['serverauth'] = $_POST['serverauth'];
210
			$config['ntpd']['serverauthkey'] = base64_encode(trim($_POST['serverauthkey']));
211
			$config['ntpd']['serverauthalgo'] = $_POST['serverauthalgo'];
212
		} elseif (isset($config['ntpd']['serverauth'])) {
213
			unset($config['ntpd']['serverauth']);
214
			unset($config['ntpd']['serverauthkey']);
215
			unset($config['ntpd']['serverauthalgo']);
216
		}
217
218 cf180ccc jim-p
		write_config("Updated NTP Server Settings");
219
220 44c42356 Phil Davis
		$changes_applied = true;
221 cf180ccc jim-p
		$retval = 0;
222 44c42356 Phil Davis
		$retval |= system_ntp_configure();
223 08d56bd1 sbeaver
	}
224
}
225
226
function build_interface_list() {
227
	global $pconfig;
228
229
	$iflist = array('options' => array(), 'selected' => array());
230
231
	$interfaces = get_configured_interface_with_descr();
232 62725308 Viktor Gurov
	$interfaces['lo0'] = "Localhost";
233
234 08d56bd1 sbeaver
	foreach ($interfaces as $iface => $ifacename) {
235 2a5960b0 Luiz Otavio O Souza
		if (!is_ipaddr(get_interface_ip($iface)) &&
236
		    !is_ipaddrv6(get_interface_ipv6($iface))) {
237 08d56bd1 sbeaver
			continue;
238 1fe07ba8 Chris Buechler
		}
239 08d56bd1 sbeaver
240 d05950fb Stephen Beaver
		$iflist['options'][$iface] = $ifacename;
241 08d56bd1 sbeaver
242 1fe07ba8 Chris Buechler
		if (in_array($iface, $pconfig['interface'])) {
243
			array_push($iflist['selected'], $iface);
244
		}
245 cf180ccc jim-p
	}
246 08d56bd1 sbeaver
247
	return($iflist);
248 cf180ccc jim-p
}
249 08d56bd1 sbeaver
250 c6c398c6 jim-p
init_config_arr(array('ntpd'));
251 c1e68244 nagyrobi
$pconfig = &$config['ntpd'];
252 0b5b700d Viktor G
$pconfig['enable'] = ($config['ntpd']['enable'] != 'disabled') ? 'enabled' : 'disabled';
253 7a6f0ebc Phil Davis
if (empty($pconfig['interface'])) {
254 63d5a5e0 Jean Cyr
	$pconfig['interface'] = array();
255 7a6f0ebc Phil Davis
} else {
256 63d5a5e0 Jean Cyr
	$pconfig['interface'] = explode(",", $pconfig['interface']);
257 7a6f0ebc Phil Davis
}
258 448280c3 k-paulius
$pgtitle = array(gettext("Services"), gettext("NTP"), gettext("Settings"));
259 edcd7535 Phil Davis
$pglinks = array("", "@self", "@self");
260 b32dd0a6 jim-p
$shortcut_section = "ntp";
261 cf180ccc jim-p
include("head.inc");
262
263 20db3e1a Phil Davis
if ($input_errors) {
264 08d56bd1 sbeaver
	print_input_errors($input_errors);
265 20db3e1a Phil Davis
}
266 44c42356 Phil Davis
267
if ($changes_applied) {
268
	print_apply_result_box($retval);
269 20db3e1a Phil Davis
}
270 08d56bd1 sbeaver
271
$tab_array = array();
272 448280c3 k-paulius
$tab_array[] = array(gettext("Settings"), true, "services_ntpd.php");
273 31b15180 jim-p
$tab_array[] = array(gettext("ACLs"), false, "services_ntpd_acls.php");
274 08d56bd1 sbeaver
$tab_array[] = array(gettext("Serial GPS"), false, "services_ntpd_gps.php");
275
$tab_array[] = array(gettext("PPS"), false, "services_ntpd_pps.php");
276
display_top_tabs($tab_array);
277
278
$form = new Form;
279 76763c4c Phil Davis
$form->setMultipartEncoding();	// Allow file uploads
280 08d56bd1 sbeaver
281 70dc5cd6 Phil Davis
$section = new Form_Section('NTP Server Configuration');
282 08d56bd1 sbeaver
283 b5d5da0c Viktor Gurov
$section->addInput(new Form_Checkbox(
284
	'enable',
285
	'Enable',
286
	'Enable NTP Server',
287 c62e31f2 Viktor Gurov
	($pconfig['enable'] == 'enabled')
288 c67c74dd Steve Beaver
))->setHelp('You may need to disable NTP if %1$s is running in a virtual machine and the host is responsible for the clock.', $g['product_label']);
289 b5d5da0c Viktor Gurov
290 08d56bd1 sbeaver
$iflist = build_interface_list();
291
292
$section->addInput(new Form_Select(
293
	'interface',
294
	'Interface',
295
	$iflist['selected'],
296
	$iflist['options'],
297
	true
298 3fd41815 Phil Davis
))->setHelp('Interfaces without an IP address will not be shown.%1$s' .
299
			'Selecting no interfaces will listen on all interfaces with a wildcard.%1$s' .
300
			'Selecting all interfaces will explicitly listen on only the interfaces/IPs specified.', '<br />');
301 08d56bd1 sbeaver
302 20db3e1a Phil Davis
$timeservers = explode(' ', $config['system']['timeservers']);
303 83b9d03e Phil Davis
$maxrows = max(count($timeservers), 1);
304 f4439c00 Stephen Beaver
for ($counter=0; $counter < $maxrows; $counter++) {
305 ff8e3635 jim-p
	$group = new Form_Group($counter == 0 ? 'Time Servers':'');
306 c18d0d12 jskyboo
	$group->addClass('repeatable');
307
	$group->setAttribute('max_repeats', NUMTIMESERVERS);
308
	$group->setAttribute('max_repeats_alert', sprintf(gettext('%d is the maximum number of configured servers.'), NUMTIMESERVERS));
309 08d56bd1 sbeaver
310
	$group->add(new Form_Input(
311 f4439c00 Stephen Beaver
		'server' . $counter,
312 08d56bd1 sbeaver
		null,
313
		'text',
314 f4439c00 Stephen Beaver
		$timeservers[$counter],
315
		['placeholder' => 'Hostname']
316
	 ))->setWidth(3);
317 08d56bd1 sbeaver
318
	 $group->add(new Form_Checkbox(
319 f4439c00 Stephen Beaver
		'servprefer' . $counter,
320 08d56bd1 sbeaver
		null,
321 f4439c00 Stephen Beaver
		null,
322
		isset($config['ntpd']['prefer']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['prefer'], $timeservers[$counter])
323
	 ))->sethelp('Prefer');
324 08d56bd1 sbeaver
325
	 $group->add(new Form_Checkbox(
326 f4439c00 Stephen Beaver
		'servselect' . $counter,
327
		null,
328 08d56bd1 sbeaver
		null,
329 f4439c00 Stephen Beaver
		isset($config['ntpd']['noselect']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['noselect'], $timeservers[$counter])
330
	 ))->sethelp('No Select');
331
332 fbb652ed jim-p
	$group->add(new Form_Checkbox(
333
		'servispool' . $counter,
334
		null,
335
		null,
336
		(substr_compare($timeservers[$counter], $auto_pool_suffix, strlen($timeservers[$counter]) - strlen($auto_pool_suffix), strlen($auto_pool_suffix)) === 0)
337
		 || (isset($config['ntpd']['ispool']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['ispool'], $timeservers[$counter]))
338
	 ))->sethelp('Is a Pool');
339
340 f4439c00 Stephen Beaver
	$group->add(new Form_Button(
341
		'deleterow' . $counter,
342 faab522f Renato Botelho
		'Delete',
343 cd7ddae6 jim-p
		null,
344
		'fa-trash'
345
	))->addClass('btn-warning');
346 08d56bd1 sbeaver
347
	 $section->add($group);
348
}
349
350 f4439c00 Stephen Beaver
$section->addInput(new Form_Button(
351
	'addrow',
352 faab522f Renato Botelho
	'Add',
353 cd7ddae6 jim-p
	null,
354
	'fa-plus'
355
))->addClass('btn-success');
356 08d56bd1 sbeaver
357
$section->addInput(new Form_StaticText(
358
	null,
359
	$btnaddrow
360 239b15fb stilez
))->setHelp(
361
	'NTP will only sync if a majority of the servers agree on the time.  For best results you should configure between 3 and 5 servers ' .
362
	'(%4$sNTP support pages recommend at least 4 or 5%5$s), or a pool. If only one server is configured, it %2$swill%3$s be believed, and if 2 servers ' .
363
	'are configured and they disagree, %2$sneither%3$s will be believed. Options:%1$s' .
364
	'%2$sPrefer%3$s - NTP should favor the use of this server more than all others.%1$s' .
365
	'%2$sNo Select%3$s - NTP should not use this server for time, but stats for this server will be collected and displayed.%1$s' .
366
	'%2$sIs a Pool%3$s - this entry is a pool of NTP servers and not a single address. This is assumed for *.pool.ntp.org.',
367 179377b0 robjarsen
	'<br />',
368
	'<b>',
369
	'</b>',
370
	'<a target="_blank" href="https://support.ntp.org/bin/view/Support/ConfiguringNTP">',
371 239b15fb stilez
	'</a>'
372
	);
373 08d56bd1 sbeaver
374 38fcf2c5 kiokoman
$section->addInput(new Form_Input(
375
	'ntpmaxpeers',
376 9c2fcbf6 kiokoman
	'Max candidate pool peers',
377 38fcf2c5 kiokoman
	'number',
378
	$pconfig['ntpmaxpeers'],
379 aef7d92a kiokoman
	['min' => $min_candidate_peers, 'max' => $max_candidate_peers]
380 b33465da kiokoman
))->setHelp('Maximum number of candidate peers in the NTP pool. This value should be set low enough to provide sufficient alternate sources ' .
381
	    'while not contacting an excessively large number of peers. ' .
382
	    'Many servers inside public pools are provided by volunteers, ' .
383
	    'and a large candidate pool places unnecessary extra load ' .
384
	    'on the volunteer time servers for little to no added benefit. (Default: 5).');
385 38fcf2c5 kiokoman
386 08d56bd1 sbeaver
$section->addInput(new Form_Input(
387
	'ntporphan',
388 ff8e3635 jim-p
	'Orphan Mode',
389 08d56bd1 sbeaver
	'text',
390 d0db0f9b jim-p
	$pconfig['orphan'],
391
	['placeholder' => "12"]
392 08d56bd1 sbeaver
))->setHelp('Orphan mode allows the system clock to be used when no other clocks are available. ' .
393
			'The number here specifies the stratum reported during orphan mode and should normally be set to a number high enough ' .
394 bb80af58 NOYB
			'to insure that any other servers available to clients are preferred over this server (default: 12).');
395 08d56bd1 sbeaver
396 8ef6844a jim-p
$section->addInput(new Form_Select(
397
	'ntpminpoll',
398
	'Minimum Poll Interval',
399
	$pconfig['ntpminpoll'],
400 4bdbb898 jim-p
	$ntp_poll_values
401 8ef6844a jim-p
))->setHelp('Minimum poll interval for NTP messages. If set, must be less than or equal to Maximum Poll Interval.');
402
403
$section->addInput(new Form_Select(
404
	'ntpmaxpoll',
405
	'Maximum Poll Interval',
406
	$pconfig['ntpmaxpoll'],
407 4bdbb898 jim-p
	$ntp_poll_values
408 8ef6844a jim-p
))->setHelp('Maximum poll interval for NTP messages. If set, must be greater than or equal to Minimum Poll Interval.');
409
410 08d56bd1 sbeaver
$section->addInput(new Form_Checkbox(
411
	'statsgraph',
412
	'NTP Graphs',
413
	'Enable RRD graphs of NTP statistics (default: disabled).',
414
	$pconfig['statsgraph']
415
));
416
417
$section->addInput(new Form_Checkbox(
418
	'logpeer',
419 ff8e3635 jim-p
	'Logging',
420
	'Log peer messages (default: disabled).',
421 08d56bd1 sbeaver
	$pconfig['logpeer']
422
));
423
424
$section->addInput(new Form_Checkbox(
425
	'logsys',
426
	null,
427 ff8e3635 jim-p
	'Log system messages (default: disabled).',
428 08d56bd1 sbeaver
	$pconfig['logsys']
429 3fd41815 Phil Davis
))->setHelp('These options enable additional messages from NTP to be written to the System Log %1$sStatus > System Logs > NTP%2$s',
430
			'<a href="status_logs.php?logfile=ntpd">', '</a>.');
431 08d56bd1 sbeaver
432
// Statistics logging section
433 c0d1ceda Phil Davis
$btnadv = new Form_Button(
434 08d56bd1 sbeaver
	'btnadvstats',
435 c0d1ceda Phil Davis
	'Display Advanced',
436 3314e626 jim-p
	null,
437
	'fa-cog'
438 08d56bd1 sbeaver
);
439
440 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
441 08d56bd1 sbeaver
442
$section->addInput(new Form_StaticText(
443 ff8e3635 jim-p
	'Statistics Logging',
444 c0d1ceda Phil Davis
	$btnadv
445 1f1cd32f Chris Buechler
))->setHelp('Warning: These options will create persistent daily log files in /var/log/ntp.');
446 08d56bd1 sbeaver
447
$section->addInput(new Form_Checkbox(
448
	'clockstats',
449
	null,
450 ff8e3635 jim-p
	'Log reference clock statistics (default: disabled).',
451 08d56bd1 sbeaver
	$pconfig['clockstats']
452
));
453
454
$section->addInput(new Form_Checkbox(
455
	'loopstats',
456
	null,
457 ff8e3635 jim-p
	'Log clock discipline statistics (default: disabled).',
458 08d56bd1 sbeaver
	$pconfig['loopstats']
459
));
460
461
$section->addInput(new Form_Checkbox(
462
	'peerstats',
463
	null,
464 ff8e3635 jim-p
	'Log NTP peer statistics (default: disabled).',
465 08d56bd1 sbeaver
	$pconfig['peerstats']
466
));
467
468
// Leap seconds section
469 c0d1ceda Phil Davis
$btnadv = new Form_Button(
470
	'btnadvleap',
471
	'Display Advanced',
472 3314e626 jim-p
	null,
473
	'fa-cog'
474 08d56bd1 sbeaver
);
475
476 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
477 08d56bd1 sbeaver
478
$section->addInput(new Form_StaticText(
479
	'Leap seconds',
480 c0d1ceda Phil Davis
	$btnadv
481 239b15fb stilez
))->setHelp(
482
	'Leap seconds may be added or subtracted at the end of June or December. Leap seconds are administered by the ' .
483
	'%1$sIERS%2$s, who publish them in their Bulletin C approximately 6 - 12 months in advance.  Normally this correction ' .
484
	'should only be needed if the server is a stratum 1 NTP server, but many NTP servers do not advertise an upcoming leap ' .
485
	'second when other NTP servers synchronise to them.%3$s%4$sIf the leap second is important to your network services, ' .
486
	'it is %6$sgood practice%2$s to download and add the leap second file at least a day in advance of any time correction%5$s.%3$s ' .
487
	'More information and files for downloading can be found on their %1$swebsite%2$s, and also on the %7$NIST%2$s and %8$sNTP%2$s websites.',
488
	'<a target="_blank" href="https://www.iers.org">',
489
	'</a>',
490
	'<br />',
491
	'<b>',
492
	'</b>',
493
	'<a target="_blank" href="https://support.ntp.org/bin/view/Support/ConfiguringNTP">',
494
	'<a target="_blank" href="https://www.nist.gov">',
495
	'<a target="_blank" href="https://www.ntp.org">'
496
);
497 08d56bd1 sbeaver
498
$section->addInput(new Form_Textarea(
499
	'leaptext',
500
	null,
501
	base64_decode(chunk_split($pconfig['leapsec']))
502 e78ecb96 NOYB
))->setHelp('Enter Leap second configuration as text OR select a file to upload.');
503 08d56bd1 sbeaver
504
$section->addInput(new Form_Input(
505
	'leapfile',
506
	null,
507
	'file'
508
))->addClass('btn-default');
509
510 bdb26b26 Viktor G
$section->addInput(new Form_Select(
511
	'dnsresolv',
512
	'DNS Resolution',
513
	$pconfig['dnsresolv'],
514
	array(
515
		'auto' => 'Auto',
516
		'inet' => 'IPv4',
517
		'inet6' => 'IPv6',
518
	)
519
))->setHelp('Force NTP peers DNS resolution IP protocol. Do not affect pools.');
520
521 9108d083 Viktor G
$section->addInput(new Form_Checkbox(
522
	'serverauth',
523
	'Enable NTP Server Authentication',
524
	'Enable NTPv3 authentication (RFC 1305)',
525
	$pconfig['serverauth']
526
))->setHelp('Authentication allows the NTP client to confirm it is communicating with the intended server, ' .
527
	    'which protects against man-in-the-middle attacks.');
528
529
$group = new Form_Group('Authentication key');
530
$group->addClass('ntpserverauth');
531
532
$group->add(new Form_IpAddress(
533
	'serverauthkey',
534
	'NTP Authentication key',
535
	base64_decode($pconfig['serverauthkey']),
536
	['placeholder' => 'NTP Authentication key']
537
))->setHelp(
538 a69f79bd Viktor G
	'Key format: %1$s MD5 - The key is 1 to 20 printable characters %1$s' .
539 1d7ae980 Viktor G
	'SHA1 - The key is a hex-encoded ASCII string of 40 characters %1$s' .
540
	'SHA256 - The key is a hex-encoded ASCII string of 64 characters',
541 9108d083 Viktor G
	'<br />'
542
);
543
544
$group->add(new Form_Select(
545
	'serverauthalgo',
546
	null,
547
	$pconfig['serverauthalgo'],
548
	$ntp_auth_halgos
549
))->setWidth(3)->setHelp('Digest algorithm');
550
551
$section->add($group);
552
553 08d56bd1 sbeaver
$form->add($section);
554 31b15180 jim-p
555 08d56bd1 sbeaver
print($form);
556
557 cf180ccc jim-p
?>
558
559 8fd9052f Colin Fleming
<script type="text/javascript">
560
//<![CDATA[
561 08ec2d99 Stephen Beaver
	// If this variable is declared, any help text will not be deleted when rows are added
562
	// IOW the help text will appear on every row
563
	retainhelp = true;
564
</script>
565
566 8fd9052f Colin Fleming
<script type="text/javascript">
567 d9555fc5 Colin Fleming
//<![CDATA[
568 20db3e1a Phil Davis
events.push(function() {
569 08d56bd1 sbeaver
570 c0d1ceda Phil Davis
	// Show advanced stats options ============================================
571
	var showadvstats = false;
572 08d56bd1 sbeaver
573 c0d1ceda Phil Davis
	function show_advstats(ispageload) {
574
		var text;
575
		// On page load decide the initial state based on the data.
576
		if (ispageload) {
577
<?php
578
			if (!$pconfig['clockstats'] && !$pconfig['loopstats'] && !$pconfig['peerstats']) {
579
				$showadv = false;
580
			} else {
581
				$showadv = true;
582
			}
583
?>
584
			showadvstats = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
585
		} else {
586
			// It was a click, swap the state.
587
			showadvstats = !showadvstats;
588
		}
589
590
		hideCheckbox('clockstats', !showadvstats);
591
		hideCheckbox('loopstats', !showadvstats);
592
		hideCheckbox('peerstats', !showadvstats);
593
594
		if (showadvstats) {
595
			text = "<?=gettext('Hide Advanced');?>";
596
		} else {
597
			text = "<?=gettext('Display Advanced');?>";
598
		}
599
		$('#btnadvstats').html('<i class="fa fa-cog"></i> ' + text);
600
	}
601
602
	$('#btnadvstats').click(function(event) {
603
		show_advstats();
604 08d56bd1 sbeaver
	});
605
606 c0d1ceda Phil Davis
	// Show advanced leap second options ======================================
607
	var showadvleap = false;
608
609
	function show_advleap(ispageload) {
610
		var text;
611
		// On page load decide the initial state based on the data.
612
		if (ispageload) {
613
<?php
614
			// Note: leapfile is not a field saved in the config, so no need to test for it here.
615
			// leapsec is the encoded text in the config, leaptext is not a pconfig[] key.
616
			if (empty($pconfig['leapsec'])) {
617
				$showadv = false;
618
			} else {
619
				$showadv = true;
620
			}
621
?>
622
			showadvleap = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
623
		} else {
624
			// It was a click, swap the state.
625
			showadvleap = !showadvleap;
626
		}
627
628
		hideInput('leaptext', !showadvleap);
629
		hideInput('leapfile', !showadvleap);
630
631
		if (showadvleap) {
632
			text = "<?=gettext('Hide Advanced');?>";
633
		} else {
634
			text = "<?=gettext('Display Advanced');?>";
635
		}
636
		$('#btnadvleap').html('<i class="fa fa-cog"></i> ' + text);
637
	}
638 08d56bd1 sbeaver
639 9108d083 Viktor G
	function change_serverauth() {
640
		hideClass('ntpserverauth', !($('#serverauth').prop('checked')));
641
	}
642
643 c0d1ceda Phil Davis
	$('#btnadvleap').click(function(event) {
644
		show_advleap();
645 08d56bd1 sbeaver
	});
646
647 9108d083 Viktor G
	$('#serverauth').change(function () {
648
		change_serverauth();
649
	});
650
651 c0d1ceda Phil Davis
	// Set initial states
652
	show_advstats(true);
653
	show_advleap(true);
654 9108d083 Viktor G
	change_serverauth();
655 0bc61baa Stephen Beaver
656
	// Suppress "Delete row" button if there are fewer than two rows
657
	checkLastRow();
658 08d56bd1 sbeaver
});
659 d9555fc5 Colin Fleming
//]]>
660 c1e68244 nagyrobi
</script>
661 cf180ccc jim-p
662 c10cb196 Stephen Beaver
<?php include("foot.inc");