Project

General

Profile

Download (15.2 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 b8f91b7c Luiz Souza
 * Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * Copyright (c) 2013 Dagorlad
8
 * All rights reserved.
9
 *
10 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
11
 * you may not use this file except in compliance with the License.
12
 * You may obtain a copy of the License at
13 c5d81585 Renato Botelho
 *
14 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
15 c5d81585 Renato Botelho
 *
16 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
17
 * distributed under the License is distributed on an "AS IS" BASIS,
18
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
 * See the License for the specific language governing permissions and
20
 * limitations under the License.
21 f4439c00 Stephen Beaver
 */
22 cf180ccc jim-p
23
##|+PRIV
24
##|*IDENT=page-services-ntpd
25 448280c3 k-paulius
##|*NAME=Services: NTP Settings
26
##|*DESCR=Allow access to the 'Services: NTP Settings' page.
27 cf180ccc jim-p
##|*MATCH=services_ntpd.php*
28
##|-PRIV
29
30 820562e8 NewEraCracker
define('NUMTIMESERVERS', 10);		// The maximum number of configurable time servers
31 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
32 c1e68244 nagyrobi
require_once('rrd.inc');
33
require_once("shaper.inc");
34 cf180ccc jim-p
35 7a6f0ebc Phil Davis
if (!is_array($config['ntpd'])) {
36 08005d0a Ermal
	$config['ntpd'] = array();
37 7a6f0ebc Phil Davis
}
38 08005d0a Ermal
39
if (empty($config['ntpd']['interface'])) {
40
	if (is_array($config['installedpackages']['openntpd']) && is_array($config['installedpackages']['openntpd']['config']) &&
41 20db3e1a Phil Davis
	    is_array($config['installedpackages']['openntpd']['config'][0]) && !empty($config['installedpackages']['openntpd']['config'][0]['interface'])) {
42 46ca7f3d jim-p
		$pconfig['interface'] = explode(",", $config['installedpackages']['openntpd']['config'][0]['interface']);
43 cf180ccc jim-p
		unset($config['installedpackages']['openntpd']);
44 4bfc3f7d Phil Davis
		write_config(gettext("Upgraded settings from openttpd"));
45 7a6f0ebc Phil Davis
	} else {
46 cf180ccc jim-p
		$pconfig['interface'] = array();
47 7a6f0ebc Phil Davis
	}
48
} else {
49 cf180ccc jim-p
	$pconfig['interface'] = explode(",", $config['ntpd']['interface']);
50 7a6f0ebc Phil Davis
}
51 cf180ccc jim-p
52 08d56bd1 sbeaver
if ($_POST) {
53 cf180ccc jim-p
	unset($input_errors);
54
	$pconfig = $_POST;
55
56 531c3486 jim-p
	if ((strlen($pconfig['ntporphan']) > 0) && (!is_numericint($pconfig['ntporphan']) || ($pconfig['ntporphan'] < 1) || ($pconfig['ntporphan'] > 15))) {
57
		$input_errors[] = gettext("The supplied value for NTP Orphan Mode is invalid.");
58
	}
59
60 cf180ccc jim-p
	if (!$input_errors) {
61 7a6f0ebc Phil Davis
		if (is_array($_POST['interface'])) {
62 58168f4e jim-p
			$config['ntpd']['interface'] = implode(",", $_POST['interface']);
63 7a6f0ebc Phil Davis
		} elseif (isset($config['ntpd']['interface'])) {
64 58168f4e jim-p
			unset($config['ntpd']['interface']);
65 7a6f0ebc Phil Davis
		}
66 cf180ccc jim-p
67 7a6f0ebc Phil Davis
		if (!empty($_POST['gpsport']) && file_exists('/dev/'.$_POST['gpsport'])) {
68 5c8843d5 jim-p
			$config['ntpd']['gpsport'] = $_POST['gpsport'];
69 7a6f0ebc Phil Davis
		} elseif (isset($config['ntpd']['gpsport'])) {
70 5c8843d5 jim-p
			unset($config['ntpd']['gpsport']);
71 7a6f0ebc Phil Davis
		}
72 5c8843d5 jim-p
73 c1e68244 nagyrobi
		unset($config['ntpd']['prefer']);
74
		unset($config['ntpd']['noselect']);
75 fbb652ed jim-p
		unset($config['ntpd']['ispool']);
76 c1e68244 nagyrobi
		$timeservers = '';
77 08d56bd1 sbeaver
78 83b9d03e Phil Davis
		for ($i = 0; $i < NUMTIMESERVERS; $i++) {
79 08005d0a Ermal
			$tserver = trim($_POST["server{$i}"]);
80 c1e68244 nagyrobi
			if (!empty($tserver)) {
81
				$timeservers .= "{$tserver} ";
82 7a6f0ebc Phil Davis
				if (!empty($_POST["servprefer{$i}"])) {
83
					$config['ntpd']['prefer'] .= "{$tserver} ";
84
				}
85
				if (!empty($_POST["servselect{$i}"])) {
86
					$config['ntpd']['noselect'] .= "{$tserver} ";
87
				}
88 fbb652ed jim-p
				if (!empty($_POST["servispool{$i}"])) {
89
					$config['ntpd']['ispool'] .= "{$tserver} ";
90
				}
91 c1e68244 nagyrobi
			}
92
		}
93 7a6f0ebc Phil Davis
		if (trim($timeservers) == "") {
94 4e6b0a0e nagyrobi
			$timeservers = "pool.ntp.org";
95 7a6f0ebc Phil Davis
		}
96 c1e68244 nagyrobi
		$config['system']['timeservers'] = trim($timeservers);
97
98 531c3486 jim-p
		$config['ntpd']['orphan'] = trim($pconfig['ntporphan']);
99 c1e68244 nagyrobi
100 7a6f0ebc Phil Davis
		if (!empty($_POST['logpeer'])) {
101 c1e68244 nagyrobi
			$config['ntpd']['logpeer'] = $_POST['logpeer'];
102 7a6f0ebc Phil Davis
		} elseif (isset($config['ntpd']['logpeer'])) {
103 c1e68244 nagyrobi
			unset($config['ntpd']['logpeer']);
104 7a6f0ebc Phil Davis
		}
105 c1e68244 nagyrobi
106 7a6f0ebc Phil Davis
		if (!empty($_POST['logsys'])) {
107 c1e68244 nagyrobi
			$config['ntpd']['logsys'] = $_POST['logsys'];
108 7a6f0ebc Phil Davis
		} elseif (isset($config['ntpd']['logsys'])) {
109 c1e68244 nagyrobi
			unset($config['ntpd']['logsys']);
110 7a6f0ebc Phil Davis
		}
111 c1e68244 nagyrobi
112 7a6f0ebc Phil Davis
		if (!empty($_POST['clockstats'])) {
113 c1e68244 nagyrobi
			$config['ntpd']['clockstats'] = $_POST['clockstats'];
114 7a6f0ebc Phil Davis
		} elseif (isset($config['ntpd']['clockstats'])) {
115 c1e68244 nagyrobi
			unset($config['ntpd']['clockstats']);
116 7a6f0ebc Phil Davis
		}
117 c1e68244 nagyrobi
118 7a6f0ebc Phil Davis
		if (!empty($_POST['loopstats'])) {
119 c1e68244 nagyrobi
			$config['ntpd']['loopstats'] = $_POST['loopstats'];
120 7a6f0ebc Phil Davis
		} elseif (isset($config['ntpd']['loopstats'])) {
121 c1e68244 nagyrobi
			unset($config['ntpd']['loopstats']);
122 7a6f0ebc Phil Davis
		}
123 c1e68244 nagyrobi
124 7a6f0ebc Phil Davis
		if (!empty($_POST['peerstats'])) {
125 c1e68244 nagyrobi
			$config['ntpd']['peerstats'] = $_POST['peerstats'];
126 7a6f0ebc Phil Davis
		} elseif (isset($config['ntpd']['peerstats'])) {
127 c1e68244 nagyrobi
			unset($config['ntpd']['peerstats']);
128 7a6f0ebc Phil Davis
		}
129 c1e68244 nagyrobi
130 7a6f0ebc Phil Davis
		if ((empty($_POST['statsgraph'])) == (isset($config['ntpd']['statsgraph']))) {
131 e2caaee8 k-paulius
			$enable_rrd_graphing = true;
132 7a6f0ebc Phil Davis
		}
133
		if (!empty($_POST['statsgraph'])) {
134 c1e68244 nagyrobi
			$config['ntpd']['statsgraph'] = $_POST['statsgraph'];
135 7a6f0ebc Phil Davis
		} elseif (isset($config['ntpd']['statsgraph'])) {
136 c1e68244 nagyrobi
			unset($config['ntpd']['statsgraph']);
137 7a6f0ebc Phil Davis
		}
138
		if (isset($enable_rrd_graphing)) {
139 e2caaee8 k-paulius
			enable_rrd_graphing();
140 7a6f0ebc Phil Davis
		}
141 c1e68244 nagyrobi
142 f99f8a67 Phil Davis
		if (!empty($_POST['leaptext'])) {
143
			$config['ntpd']['leapsec'] = base64_encode($_POST['leaptext']);
144 7a6f0ebc Phil Davis
		} elseif (isset($config['ntpd']['leapsec'])) {
145 c1e68244 nagyrobi
			unset($config['ntpd']['leapsec']);
146 7a6f0ebc Phil Davis
		}
147 c1e68244 nagyrobi
148 7a6f0ebc Phil Davis
		if (is_uploaded_file($_FILES['leapfile']['tmp_name'])) {
149 c1e68244 nagyrobi
			$config['ntpd']['leapsec'] = base64_encode(file_get_contents($_FILES['leapfile']['tmp_name']));
150 7a6f0ebc Phil Davis
		}
151 c1e68244 nagyrobi
152 cf180ccc jim-p
		write_config("Updated NTP Server Settings");
153
154 44c42356 Phil Davis
		$changes_applied = true;
155 cf180ccc jim-p
		$retval = 0;
156 44c42356 Phil Davis
		$retval |= system_ntp_configure();
157 08d56bd1 sbeaver
	}
158
}
159
160
function build_interface_list() {
161
	global $pconfig;
162
163
	$iflist = array('options' => array(), 'selected' => array());
164
165
	$interfaces = get_configured_interface_with_descr();
166
	foreach ($interfaces as $iface => $ifacename) {
167 2a5960b0 Luiz Otavio O Souza
		if (!is_ipaddr(get_interface_ip($iface)) &&
168
		    !is_ipaddrv6(get_interface_ipv6($iface))) {
169 08d56bd1 sbeaver
			continue;
170 1fe07ba8 Chris Buechler
		}
171 08d56bd1 sbeaver
172 d05950fb Stephen Beaver
		$iflist['options'][$iface] = $ifacename;
173 08d56bd1 sbeaver
174 1fe07ba8 Chris Buechler
		if (in_array($iface, $pconfig['interface'])) {
175
			array_push($iflist['selected'], $iface);
176
		}
177 cf180ccc jim-p
	}
178 08d56bd1 sbeaver
179
	return($iflist);
180 cf180ccc jim-p
}
181 08d56bd1 sbeaver
182 c6c398c6 jim-p
init_config_arr(array('ntpd'));
183 c1e68244 nagyrobi
$pconfig = &$config['ntpd'];
184 7a6f0ebc Phil Davis
if (empty($pconfig['interface'])) {
185 63d5a5e0 Jean Cyr
	$pconfig['interface'] = array();
186 7a6f0ebc Phil Davis
} else {
187 63d5a5e0 Jean Cyr
	$pconfig['interface'] = explode(",", $pconfig['interface']);
188 7a6f0ebc Phil Davis
}
189 448280c3 k-paulius
$pgtitle = array(gettext("Services"), gettext("NTP"), gettext("Settings"));
190 edcd7535 Phil Davis
$pglinks = array("", "@self", "@self");
191 b32dd0a6 jim-p
$shortcut_section = "ntp";
192 cf180ccc jim-p
include("head.inc");
193
194 20db3e1a Phil Davis
if ($input_errors) {
195 08d56bd1 sbeaver
	print_input_errors($input_errors);
196 20db3e1a Phil Davis
}
197 44c42356 Phil Davis
198
if ($changes_applied) {
199
	print_apply_result_box($retval);
200 20db3e1a Phil Davis
}
201 08d56bd1 sbeaver
202
$tab_array = array();
203 448280c3 k-paulius
$tab_array[] = array(gettext("Settings"), true, "services_ntpd.php");
204 31b15180 jim-p
$tab_array[] = array(gettext("ACLs"), false, "services_ntpd_acls.php");
205 08d56bd1 sbeaver
$tab_array[] = array(gettext("Serial GPS"), false, "services_ntpd_gps.php");
206
$tab_array[] = array(gettext("PPS"), false, "services_ntpd_pps.php");
207
display_top_tabs($tab_array);
208
209
$form = new Form;
210 76763c4c Phil Davis
$form->setMultipartEncoding();	// Allow file uploads
211 08d56bd1 sbeaver
212 70dc5cd6 Phil Davis
$section = new Form_Section('NTP Server Configuration');
213 08d56bd1 sbeaver
214
$iflist = build_interface_list();
215
216
$section->addInput(new Form_Select(
217
	'interface',
218
	'Interface',
219
	$iflist['selected'],
220
	$iflist['options'],
221
	true
222 3fd41815 Phil Davis
))->setHelp('Interfaces without an IP address will not be shown.%1$s' .
223
			'Selecting no interfaces will listen on all interfaces with a wildcard.%1$s' .
224
			'Selecting all interfaces will explicitly listen on only the interfaces/IPs specified.', '<br />');
225 08d56bd1 sbeaver
226 20db3e1a Phil Davis
$timeservers = explode(' ', $config['system']['timeservers']);
227 83b9d03e Phil Davis
$maxrows = max(count($timeservers), 1);
228 fbb652ed jim-p
$auto_pool_suffix = "pool.ntp.org";
229 f4439c00 Stephen Beaver
for ($counter=0; $counter < $maxrows; $counter++) {
230 ff8e3635 jim-p
	$group = new Form_Group($counter == 0 ? 'Time Servers':'');
231 c18d0d12 jskyboo
	$group->addClass('repeatable');
232
	$group->setAttribute('max_repeats', NUMTIMESERVERS);
233
	$group->setAttribute('max_repeats_alert', sprintf(gettext('%d is the maximum number of configured servers.'), NUMTIMESERVERS));
234 08d56bd1 sbeaver
235
	$group->add(new Form_Input(
236 f4439c00 Stephen Beaver
		'server' . $counter,
237 08d56bd1 sbeaver
		null,
238
		'text',
239 f4439c00 Stephen Beaver
		$timeservers[$counter],
240
		['placeholder' => 'Hostname']
241
	 ))->setWidth(3);
242 08d56bd1 sbeaver
243
	 $group->add(new Form_Checkbox(
244 f4439c00 Stephen Beaver
		'servprefer' . $counter,
245 08d56bd1 sbeaver
		null,
246 f4439c00 Stephen Beaver
		null,
247
		isset($config['ntpd']['prefer']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['prefer'], $timeservers[$counter])
248
	 ))->sethelp('Prefer');
249 08d56bd1 sbeaver
250
	 $group->add(new Form_Checkbox(
251 f4439c00 Stephen Beaver
		'servselect' . $counter,
252
		null,
253 08d56bd1 sbeaver
		null,
254 f4439c00 Stephen Beaver
		isset($config['ntpd']['noselect']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['noselect'], $timeservers[$counter])
255
	 ))->sethelp('No Select');
256
257 fbb652ed jim-p
	$group->add(new Form_Checkbox(
258
		'servispool' . $counter,
259
		null,
260
		null,
261
		(substr_compare($timeservers[$counter], $auto_pool_suffix, strlen($timeservers[$counter]) - strlen($auto_pool_suffix), strlen($auto_pool_suffix)) === 0)
262
		 || (isset($config['ntpd']['ispool']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['ispool'], $timeservers[$counter]))
263
	 ))->sethelp('Is a Pool');
264
265 f4439c00 Stephen Beaver
	$group->add(new Form_Button(
266
		'deleterow' . $counter,
267 faab522f Renato Botelho
		'Delete',
268 cd7ddae6 jim-p
		null,
269
		'fa-trash'
270
	))->addClass('btn-warning');
271 08d56bd1 sbeaver
272
	 $section->add($group);
273
}
274
275 f4439c00 Stephen Beaver
$section->addInput(new Form_Button(
276
	'addrow',
277 faab522f Renato Botelho
	'Add',
278 cd7ddae6 jim-p
	null,
279
	'fa-plus'
280
))->addClass('btn-success');
281 08d56bd1 sbeaver
282
$section->addInput(new Form_StaticText(
283
	null,
284
	$btnaddrow
285 239b15fb stilez
))->setHelp(
286
	'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 ' .
287
	'(%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 ' .
288
	'are configured and they disagree, %2$sneither%3$s will be believed. Options:%1$s' .
289
	'%2$sPrefer%3$s - NTP should favor the use of this server more than all others.%1$s' .
290
	'%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' .
291
	'%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.',
292 179377b0 robjarsen
	'<br />',
293
	'<b>',
294
	'</b>',
295
	'<a target="_blank" href="https://support.ntp.org/bin/view/Support/ConfiguringNTP">',
296 239b15fb stilez
	'</a>'
297
	);
298 08d56bd1 sbeaver
299
$section->addInput(new Form_Input(
300
	'ntporphan',
301 ff8e3635 jim-p
	'Orphan Mode',
302 08d56bd1 sbeaver
	'text',
303 d0db0f9b jim-p
	$pconfig['orphan'],
304
	['placeholder' => "12"]
305 08d56bd1 sbeaver
))->setHelp('Orphan mode allows the system clock to be used when no other clocks are available. ' .
306
			'The number here specifies the stratum reported during orphan mode and should normally be set to a number high enough ' .
307 bb80af58 NOYB
			'to insure that any other servers available to clients are preferred over this server (default: 12).');
308 08d56bd1 sbeaver
309
$section->addInput(new Form_Checkbox(
310
	'statsgraph',
311
	'NTP Graphs',
312
	'Enable RRD graphs of NTP statistics (default: disabled).',
313
	$pconfig['statsgraph']
314
));
315
316
$section->addInput(new Form_Checkbox(
317
	'logpeer',
318 ff8e3635 jim-p
	'Logging',
319
	'Log peer messages (default: disabled).',
320 08d56bd1 sbeaver
	$pconfig['logpeer']
321
));
322
323
$section->addInput(new Form_Checkbox(
324
	'logsys',
325
	null,
326 ff8e3635 jim-p
	'Log system messages (default: disabled).',
327 08d56bd1 sbeaver
	$pconfig['logsys']
328 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',
329
			'<a href="status_logs.php?logfile=ntpd">', '</a>.');
330 08d56bd1 sbeaver
331
// Statistics logging section
332 c0d1ceda Phil Davis
$btnadv = new Form_Button(
333 08d56bd1 sbeaver
	'btnadvstats',
334 c0d1ceda Phil Davis
	'Display Advanced',
335 3314e626 jim-p
	null,
336
	'fa-cog'
337 08d56bd1 sbeaver
);
338
339 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
340 08d56bd1 sbeaver
341
$section->addInput(new Form_StaticText(
342 ff8e3635 jim-p
	'Statistics Logging',
343 c0d1ceda Phil Davis
	$btnadv
344 1f1cd32f Chris Buechler
))->setHelp('Warning: These options will create persistent daily log files in /var/log/ntp.');
345 08d56bd1 sbeaver
346
$section->addInput(new Form_Checkbox(
347
	'clockstats',
348
	null,
349 ff8e3635 jim-p
	'Log reference clock statistics (default: disabled).',
350 08d56bd1 sbeaver
	$pconfig['clockstats']
351
));
352
353
$section->addInput(new Form_Checkbox(
354
	'loopstats',
355
	null,
356 ff8e3635 jim-p
	'Log clock discipline statistics (default: disabled).',
357 08d56bd1 sbeaver
	$pconfig['loopstats']
358
));
359
360
$section->addInput(new Form_Checkbox(
361
	'peerstats',
362
	null,
363 ff8e3635 jim-p
	'Log NTP peer statistics (default: disabled).',
364 08d56bd1 sbeaver
	$pconfig['peerstats']
365
));
366
367
// Leap seconds section
368 c0d1ceda Phil Davis
$btnadv = new Form_Button(
369
	'btnadvleap',
370
	'Display Advanced',
371 3314e626 jim-p
	null,
372
	'fa-cog'
373 08d56bd1 sbeaver
);
374
375 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
376 08d56bd1 sbeaver
377
$section->addInput(new Form_StaticText(
378
	'Leap seconds',
379 c0d1ceda Phil Davis
	$btnadv
380 239b15fb stilez
))->setHelp(
381
	'Leap seconds may be added or subtracted at the end of June or December. Leap seconds are administered by the ' .
382
	'%1$sIERS%2$s, who publish them in their Bulletin C approximately 6 - 12 months in advance.  Normally this correction ' .
383
	'should only be needed if the server is a stratum 1 NTP server, but many NTP servers do not advertise an upcoming leap ' .
384
	'second when other NTP servers synchronise to them.%3$s%4$sIf the leap second is important to your network services, ' .
385
	'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 ' .
386
	'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.',
387
	'<a target="_blank" href="https://www.iers.org">',
388
	'</a>',
389
	'<br />',
390
	'<b>',
391
	'</b>',
392
	'<a target="_blank" href="https://support.ntp.org/bin/view/Support/ConfiguringNTP">',
393
	'<a target="_blank" href="https://www.nist.gov">',
394
	'<a target="_blank" href="https://www.ntp.org">'
395
);
396 08d56bd1 sbeaver
397
$section->addInput(new Form_Textarea(
398
	'leaptext',
399
	null,
400
	base64_decode(chunk_split($pconfig['leapsec']))
401 e78ecb96 NOYB
))->setHelp('Enter Leap second configuration as text OR select a file to upload.');
402 08d56bd1 sbeaver
403
$section->addInput(new Form_Input(
404
	'leapfile',
405
	null,
406
	'file'
407
))->addClass('btn-default');
408
409
$form->add($section);
410 31b15180 jim-p
411 08d56bd1 sbeaver
print($form);
412
413 cf180ccc jim-p
?>
414
415 8fd9052f Colin Fleming
<script type="text/javascript">
416
//<![CDATA[
417 08ec2d99 Stephen Beaver
	// If this variable is declared, any help text will not be deleted when rows are added
418
	// IOW the help text will appear on every row
419
	retainhelp = true;
420
</script>
421
422 8fd9052f Colin Fleming
<script type="text/javascript">
423 d9555fc5 Colin Fleming
//<![CDATA[
424 20db3e1a Phil Davis
events.push(function() {
425 08d56bd1 sbeaver
426 c0d1ceda Phil Davis
	// Show advanced stats options ============================================
427
	var showadvstats = false;
428 08d56bd1 sbeaver
429 c0d1ceda Phil Davis
	function show_advstats(ispageload) {
430
		var text;
431
		// On page load decide the initial state based on the data.
432
		if (ispageload) {
433
<?php
434
			if (!$pconfig['clockstats'] && !$pconfig['loopstats'] && !$pconfig['peerstats']) {
435
				$showadv = false;
436
			} else {
437
				$showadv = true;
438
			}
439
?>
440
			showadvstats = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
441
		} else {
442
			// It was a click, swap the state.
443
			showadvstats = !showadvstats;
444
		}
445
446
		hideCheckbox('clockstats', !showadvstats);
447
		hideCheckbox('loopstats', !showadvstats);
448
		hideCheckbox('peerstats', !showadvstats);
449
450
		if (showadvstats) {
451
			text = "<?=gettext('Hide Advanced');?>";
452
		} else {
453
			text = "<?=gettext('Display Advanced');?>";
454
		}
455
		$('#btnadvstats').html('<i class="fa fa-cog"></i> ' + text);
456
	}
457
458
	$('#btnadvstats').click(function(event) {
459
		show_advstats();
460 08d56bd1 sbeaver
	});
461
462 c0d1ceda Phil Davis
	// Show advanced leap second options ======================================
463
	var showadvleap = false;
464
465
	function show_advleap(ispageload) {
466
		var text;
467
		// On page load decide the initial state based on the data.
468
		if (ispageload) {
469
<?php
470
			// Note: leapfile is not a field saved in the config, so no need to test for it here.
471
			// leapsec is the encoded text in the config, leaptext is not a pconfig[] key.
472
			if (empty($pconfig['leapsec'])) {
473
				$showadv = false;
474
			} else {
475
				$showadv = true;
476
			}
477
?>
478
			showadvleap = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
479
		} else {
480
			// It was a click, swap the state.
481
			showadvleap = !showadvleap;
482
		}
483
484
		hideInput('leaptext', !showadvleap);
485
		hideInput('leapfile', !showadvleap);
486
487
		if (showadvleap) {
488
			text = "<?=gettext('Hide Advanced');?>";
489
		} else {
490
			text = "<?=gettext('Display Advanced');?>";
491
		}
492
		$('#btnadvleap').html('<i class="fa fa-cog"></i> ' + text);
493
	}
494 08d56bd1 sbeaver
495 c0d1ceda Phil Davis
	$('#btnadvleap').click(function(event) {
496
		show_advleap();
497 08d56bd1 sbeaver
	});
498
499 c0d1ceda Phil Davis
	// Set initial states
500
	show_advstats(true);
501
	show_advleap(true);
502 0bc61baa Stephen Beaver
503
	// Suppress "Delete row" button if there are fewer than two rows
504
	checkLastRow();
505 08d56bd1 sbeaver
});
506 d9555fc5 Colin Fleming
//]]>
507 c1e68244 nagyrobi
</script>
508 cf180ccc jim-p
509 c10cb196 Stephen Beaver
<?php include("foot.inc");