1
|
<?php
|
2
|
/*
|
3
|
services_ntpd.php
|
4
|
*/
|
5
|
/* ====================================================================
|
6
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
7
|
* Copyright (c) 2013 Dagorlad
|
8
|
*
|
9
|
* Redistribution and use in source and binary forms, with or without modification,
|
10
|
* are permitted provided that the following conditions are met:
|
11
|
*
|
12
|
* 1. Redistributions of source code must retain the above copyright notice,
|
13
|
* this list of conditions and the following disclaimer.
|
14
|
*
|
15
|
* 2. Redistributions in binary form must reproduce the above copyright
|
16
|
* notice, this list of conditions and the following disclaimer in
|
17
|
* the documentation and/or other materials provided with the
|
18
|
* distribution.
|
19
|
*
|
20
|
* 3. All advertising materials mentioning features or use of this software
|
21
|
* must display the following acknowledgment:
|
22
|
* "This product includes software developed by the pfSense Project
|
23
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
24
|
*
|
25
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
26
|
* endorse or promote products derived from this software without
|
27
|
* prior written permission. For written permission, please contact
|
28
|
* coreteam@pfsense.org.
|
29
|
*
|
30
|
* 5. Products derived from this software may not be called "pfSense"
|
31
|
* nor may "pfSense" appear in their names without prior written
|
32
|
* permission of the Electric Sheep Fencing, LLC.
|
33
|
*
|
34
|
* 6. Redistributions of any form whatsoever must retain the following
|
35
|
* acknowledgment:
|
36
|
*
|
37
|
* "This product includes software developed by the pfSense Project
|
38
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
39
|
*
|
40
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
41
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
42
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
43
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
44
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
45
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
46
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
47
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
48
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
49
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
50
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
51
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
52
|
*
|
53
|
* ====================================================================
|
54
|
*
|
55
|
*/
|
56
|
|
57
|
##|+PRIV
|
58
|
##|*IDENT=page-services-ntpd
|
59
|
##|*NAME=Services: NTP Settings
|
60
|
##|*DESCR=Allow access to the 'Services: NTP Settings' page.
|
61
|
##|*MATCH=services_ntpd.php*
|
62
|
##|-PRIV
|
63
|
|
64
|
define('NUMTIMESERVERS', 10); // The maximum number of configurable time servers
|
65
|
require_once("guiconfig.inc");
|
66
|
require_once('rrd.inc');
|
67
|
require_once("shaper.inc");
|
68
|
|
69
|
if (!is_array($config['ntpd'])) {
|
70
|
$config['ntpd'] = array();
|
71
|
}
|
72
|
|
73
|
if (empty($config['ntpd']['interface'])) {
|
74
|
if (is_array($config['installedpackages']['openntpd']) && is_array($config['installedpackages']['openntpd']['config']) &&
|
75
|
is_array($config['installedpackages']['openntpd']['config'][0]) && !empty($config['installedpackages']['openntpd']['config'][0]['interface'])) {
|
76
|
$pconfig['interface'] = explode(",", $config['installedpackages']['openntpd']['config'][0]['interface']);
|
77
|
unset($config['installedpackages']['openntpd']);
|
78
|
write_config(gettext("Upgraded settings from openttpd"));
|
79
|
} else {
|
80
|
$pconfig['interface'] = array();
|
81
|
}
|
82
|
} else {
|
83
|
$pconfig['interface'] = explode(",", $config['ntpd']['interface']);
|
84
|
}
|
85
|
|
86
|
if ($_POST) {
|
87
|
unset($input_errors);
|
88
|
$pconfig = $_POST;
|
89
|
|
90
|
if (!$input_errors) {
|
91
|
if (is_array($_POST['interface'])) {
|
92
|
$config['ntpd']['interface'] = implode(",", $_POST['interface']);
|
93
|
} elseif (isset($config['ntpd']['interface'])) {
|
94
|
unset($config['ntpd']['interface']);
|
95
|
}
|
96
|
|
97
|
if (!empty($_POST['gpsport']) && file_exists('/dev/'.$_POST['gpsport'])) {
|
98
|
$config['ntpd']['gpsport'] = $_POST['gpsport'];
|
99
|
} elseif (isset($config['ntpd']['gpsport'])) {
|
100
|
unset($config['ntpd']['gpsport']);
|
101
|
}
|
102
|
|
103
|
unset($config['ntpd']['prefer']);
|
104
|
unset($config['ntpd']['noselect']);
|
105
|
$timeservers = '';
|
106
|
|
107
|
for ($i = 0; $i < NUMTIMESERVERS; $i++) {
|
108
|
$tserver = trim($_POST["server{$i}"]);
|
109
|
if (!empty($tserver)) {
|
110
|
$timeservers .= "{$tserver} ";
|
111
|
if (!empty($_POST["servprefer{$i}"])) {
|
112
|
$config['ntpd']['prefer'] .= "{$tserver} ";
|
113
|
}
|
114
|
if (!empty($_POST["servselect{$i}"])) {
|
115
|
$config['ntpd']['noselect'] .= "{$tserver} ";
|
116
|
}
|
117
|
}
|
118
|
}
|
119
|
if (trim($timeservers) == "") {
|
120
|
$timeservers = "pool.ntp.org";
|
121
|
}
|
122
|
$config['system']['timeservers'] = trim($timeservers);
|
123
|
|
124
|
if (!empty($_POST['ntporphan']) && ($_POST['ntporphan'] < 17) && ($_POST['ntporphan'] != '12')) {
|
125
|
$config['ntpd']['orphan'] = $_POST['ntporphan'];
|
126
|
} elseif (isset($config['ntpd']['orphan'])) {
|
127
|
unset($config['ntpd']['orphan']);
|
128
|
}
|
129
|
|
130
|
if (!empty($_POST['logpeer'])) {
|
131
|
$config['ntpd']['logpeer'] = $_POST['logpeer'];
|
132
|
} elseif (isset($config['ntpd']['logpeer'])) {
|
133
|
unset($config['ntpd']['logpeer']);
|
134
|
}
|
135
|
|
136
|
if (!empty($_POST['logsys'])) {
|
137
|
$config['ntpd']['logsys'] = $_POST['logsys'];
|
138
|
} elseif (isset($config['ntpd']['logsys'])) {
|
139
|
unset($config['ntpd']['logsys']);
|
140
|
}
|
141
|
|
142
|
if (!empty($_POST['clockstats'])) {
|
143
|
$config['ntpd']['clockstats'] = $_POST['clockstats'];
|
144
|
} elseif (isset($config['ntpd']['clockstats'])) {
|
145
|
unset($config['ntpd']['clockstats']);
|
146
|
}
|
147
|
|
148
|
if (!empty($_POST['loopstats'])) {
|
149
|
$config['ntpd']['loopstats'] = $_POST['loopstats'];
|
150
|
} elseif (isset($config['ntpd']['loopstats'])) {
|
151
|
unset($config['ntpd']['loopstats']);
|
152
|
}
|
153
|
|
154
|
if (!empty($_POST['peerstats'])) {
|
155
|
$config['ntpd']['peerstats'] = $_POST['peerstats'];
|
156
|
} elseif (isset($config['ntpd']['peerstats'])) {
|
157
|
unset($config['ntpd']['peerstats']);
|
158
|
}
|
159
|
|
160
|
if ((empty($_POST['statsgraph'])) == (isset($config['ntpd']['statsgraph']))) {
|
161
|
$enable_rrd_graphing = true;
|
162
|
}
|
163
|
if (!empty($_POST['statsgraph'])) {
|
164
|
$config['ntpd']['statsgraph'] = $_POST['statsgraph'];
|
165
|
} elseif (isset($config['ntpd']['statsgraph'])) {
|
166
|
unset($config['ntpd']['statsgraph']);
|
167
|
}
|
168
|
if (isset($enable_rrd_graphing)) {
|
169
|
enable_rrd_graphing();
|
170
|
}
|
171
|
|
172
|
if (!empty($_POST['leaptext'])) {
|
173
|
$config['ntpd']['leapsec'] = base64_encode($_POST['leaptext']);
|
174
|
} elseif (isset($config['ntpd']['leapsec'])) {
|
175
|
unset($config['ntpd']['leapsec']);
|
176
|
}
|
177
|
|
178
|
if (is_uploaded_file($_FILES['leapfile']['tmp_name'])) {
|
179
|
$config['ntpd']['leapsec'] = base64_encode(file_get_contents($_FILES['leapfile']['tmp_name']));
|
180
|
}
|
181
|
|
182
|
write_config("Updated NTP Server Settings");
|
183
|
|
184
|
$retval = 0;
|
185
|
$retval = system_ntp_configure();
|
186
|
$savemsg = get_std_save_message($retval);
|
187
|
}
|
188
|
}
|
189
|
|
190
|
function build_interface_list() {
|
191
|
global $pconfig;
|
192
|
|
193
|
$iflist = array('options' => array(), 'selected' => array());
|
194
|
|
195
|
$interfaces = get_configured_interface_with_descr();
|
196
|
foreach ($interfaces as $iface => $ifacename) {
|
197
|
if (!is_ipaddr(get_interface_ip($iface)) &&
|
198
|
!is_ipaddrv6(get_interface_ipv6($iface))) {
|
199
|
continue;
|
200
|
}
|
201
|
|
202
|
$iflist['options'][$iface] = $ifacename;
|
203
|
|
204
|
if (in_array($iface, $pconfig['interface'])) {
|
205
|
array_push($iflist['selected'], $iface);
|
206
|
}
|
207
|
}
|
208
|
|
209
|
return($iflist);
|
210
|
}
|
211
|
|
212
|
$pconfig = &$config['ntpd'];
|
213
|
if (empty($pconfig['interface'])) {
|
214
|
$pconfig['interface'] = array();
|
215
|
} else {
|
216
|
$pconfig['interface'] = explode(",", $pconfig['interface']);
|
217
|
}
|
218
|
$pgtitle = array(gettext("Services"), gettext("NTP"), gettext("Settings"));
|
219
|
$shortcut_section = "ntp";
|
220
|
include("head.inc");
|
221
|
|
222
|
if ($input_errors) {
|
223
|
print_input_errors($input_errors);
|
224
|
}
|
225
|
if ($savemsg) {
|
226
|
print_info_box($savemsg, 'success');
|
227
|
}
|
228
|
|
229
|
$tab_array = array();
|
230
|
$tab_array[] = array(gettext("Settings"), true, "services_ntpd.php");
|
231
|
$tab_array[] = array(gettext("ACLs"), false, "services_ntpd_acls.php");
|
232
|
$tab_array[] = array(gettext("Serial GPS"), false, "services_ntpd_gps.php");
|
233
|
$tab_array[] = array(gettext("PPS"), false, "services_ntpd_pps.php");
|
234
|
display_top_tabs($tab_array);
|
235
|
|
236
|
$form = new Form;
|
237
|
|
238
|
$section = new Form_Section('NTP Server Configuration');
|
239
|
|
240
|
$iflist = build_interface_list();
|
241
|
|
242
|
$section->addInput(new Form_Select(
|
243
|
'interface',
|
244
|
'Interface',
|
245
|
$iflist['selected'],
|
246
|
$iflist['options'],
|
247
|
true
|
248
|
))->setHelp('Interfaces without an IP address will not be shown.' . '<br />' .
|
249
|
'Selecting no interfaces will listen on all interfaces with a wildcard.' . '<br />' .
|
250
|
'Selecting all interfaces will explicitly listen on only the interfaces/IPs specified.');
|
251
|
|
252
|
$timeservers = explode(' ', $config['system']['timeservers']);
|
253
|
$maxrows = max(count($timeservers), 1);
|
254
|
for ($counter=0; $counter < $maxrows; $counter++) {
|
255
|
$group = new Form_Group($counter == 0 ? 'Time Servers':'');
|
256
|
$group->addClass('repeatable');
|
257
|
|
258
|
$group->add(new Form_Input(
|
259
|
'server' . $counter,
|
260
|
null,
|
261
|
'text',
|
262
|
$timeservers[$counter],
|
263
|
['placeholder' => 'Hostname']
|
264
|
))->setWidth(3);
|
265
|
|
266
|
$group->add(new Form_Checkbox(
|
267
|
'servprefer' . $counter,
|
268
|
null,
|
269
|
null,
|
270
|
isset($config['ntpd']['prefer']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['prefer'], $timeservers[$counter])
|
271
|
))->sethelp('Prefer');
|
272
|
|
273
|
$group->add(new Form_Checkbox(
|
274
|
'servselect' . $counter,
|
275
|
null,
|
276
|
null,
|
277
|
isset($config['ntpd']['noselect']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['noselect'], $timeservers[$counter])
|
278
|
))->sethelp('No Select');
|
279
|
|
280
|
$group->add(new Form_Button(
|
281
|
'deleterow' . $counter,
|
282
|
'Delete',
|
283
|
null,
|
284
|
'fa-trash'
|
285
|
))->addClass('btn-warning');
|
286
|
|
287
|
$section->add($group);
|
288
|
}
|
289
|
|
290
|
$section->addInput(new Form_Button(
|
291
|
'addrow',
|
292
|
'Add',
|
293
|
null,
|
294
|
'fa-plus'
|
295
|
))->addClass('btn-success');
|
296
|
|
297
|
$section->addInput(new Form_StaticText(
|
298
|
null,
|
299
|
$btnaddrow
|
300
|
))->setHelp('For best results three to five servers should be configured here.' . '<br />' .
|
301
|
'The prefer option indicates that NTP should favor the use of this server more than all others.' . '<br />' .
|
302
|
'The no select option indicates that NTP should not use this server for time, but stats for this server will be collected and displayed.');
|
303
|
|
304
|
$section->addInput(new Form_Input(
|
305
|
'ntporphan',
|
306
|
'Orphan Mode',
|
307
|
'text',
|
308
|
$pconfig['ntporphan']
|
309
|
))->setHelp('Orphan mode allows the system clock to be used when no other clocks are available. ' .
|
310
|
'The number here specifies the stratum reported during orphan mode and should normally be set to a number high enough ' .
|
311
|
'to insure that any other servers available to clients are preferred over this server (default: 12).');
|
312
|
|
313
|
$section->addInput(new Form_Checkbox(
|
314
|
'statsgraph',
|
315
|
'NTP Graphs',
|
316
|
'Enable RRD graphs of NTP statistics (default: disabled).',
|
317
|
$pconfig['statsgraph']
|
318
|
));
|
319
|
|
320
|
$section->addInput(new Form_Checkbox(
|
321
|
'logpeer',
|
322
|
'Logging',
|
323
|
'Log peer messages (default: disabled).',
|
324
|
$pconfig['logpeer']
|
325
|
));
|
326
|
|
327
|
$section->addInput(new Form_Checkbox(
|
328
|
'logsys',
|
329
|
null,
|
330
|
'Log system messages (default: disabled).',
|
331
|
$pconfig['logsys']
|
332
|
))->setHelp('These options enable additional messages from NTP to be written to the System Log ' .
|
333
|
'<a href="status_logs.php?logfile=ntpd">' . 'Status > System Logs > NTP' . '</a>.');
|
334
|
|
335
|
// Statistics logging section
|
336
|
$btnadv = new Form_Button(
|
337
|
'btnadvstats',
|
338
|
'Display Advanced',
|
339
|
null,
|
340
|
'fa-cog'
|
341
|
);
|
342
|
|
343
|
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
|
344
|
|
345
|
$section->addInput(new Form_StaticText(
|
346
|
'Statistics Logging',
|
347
|
$btnadv
|
348
|
))->setHelp('Warning: These options will create persistent daily log files in /var/log/ntp.');
|
349
|
|
350
|
$section->addInput(new Form_Checkbox(
|
351
|
'clockstats',
|
352
|
null,
|
353
|
'Log reference clock statistics (default: disabled).',
|
354
|
$pconfig['clockstats']
|
355
|
));
|
356
|
|
357
|
$section->addInput(new Form_Checkbox(
|
358
|
'loopstats',
|
359
|
null,
|
360
|
'Log clock discipline statistics (default: disabled).',
|
361
|
$pconfig['loopstats']
|
362
|
));
|
363
|
|
364
|
$section->addInput(new Form_Checkbox(
|
365
|
'peerstats',
|
366
|
null,
|
367
|
'Log NTP peer statistics (default: disabled).',
|
368
|
$pconfig['peerstats']
|
369
|
));
|
370
|
|
371
|
// Leap seconds section
|
372
|
$btnadv = new Form_Button(
|
373
|
'btnadvleap',
|
374
|
'Display Advanced',
|
375
|
null,
|
376
|
'fa-cog'
|
377
|
);
|
378
|
|
379
|
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
|
380
|
|
381
|
$section->addInput(new Form_StaticText(
|
382
|
'Leap seconds',
|
383
|
$btnadv
|
384
|
))->setHelp('A leap second file allows NTP to advertise an upcoming leap second addition or subtraction. ' .
|
385
|
'Normally this is only useful if this server is a stratum 1 time server. ');
|
386
|
|
387
|
$section->addInput(new Form_Textarea(
|
388
|
'leaptext',
|
389
|
null,
|
390
|
base64_decode(chunk_split($pconfig['leapsec']))
|
391
|
))->setHelp('Enter Leap second configuration as text OR select a file to upload.');
|
392
|
|
393
|
$section->addInput(new Form_Input(
|
394
|
'leapfile',
|
395
|
null,
|
396
|
'file'
|
397
|
))->addClass('btn-default');
|
398
|
|
399
|
$form->add($section);
|
400
|
|
401
|
print($form);
|
402
|
|
403
|
?>
|
404
|
|
405
|
<script type="text/javascript">
|
406
|
//<![CDATA[
|
407
|
// If this variable is declared, any help text will not be deleted when rows are added
|
408
|
// IOW the help text will appear on every row
|
409
|
retainhelp = true;
|
410
|
</script>
|
411
|
|
412
|
<script type="text/javascript">
|
413
|
//<![CDATA[
|
414
|
events.push(function() {
|
415
|
|
416
|
// Show advanced stats options ============================================
|
417
|
var showadvstats = false;
|
418
|
|
419
|
function show_advstats(ispageload) {
|
420
|
var text;
|
421
|
// On page load decide the initial state based on the data.
|
422
|
if (ispageload) {
|
423
|
<?php
|
424
|
if (!$pconfig['clockstats'] && !$pconfig['loopstats'] && !$pconfig['peerstats']) {
|
425
|
$showadv = false;
|
426
|
} else {
|
427
|
$showadv = true;
|
428
|
}
|
429
|
?>
|
430
|
showadvstats = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
|
431
|
} else {
|
432
|
// It was a click, swap the state.
|
433
|
showadvstats = !showadvstats;
|
434
|
}
|
435
|
|
436
|
hideCheckbox('clockstats', !showadvstats);
|
437
|
hideCheckbox('loopstats', !showadvstats);
|
438
|
hideCheckbox('peerstats', !showadvstats);
|
439
|
|
440
|
if (showadvstats) {
|
441
|
text = "<?=gettext('Hide Advanced');?>";
|
442
|
} else {
|
443
|
text = "<?=gettext('Display Advanced');?>";
|
444
|
}
|
445
|
$('#btnadvstats').html('<i class="fa fa-cog"></i> ' + text);
|
446
|
}
|
447
|
|
448
|
$('#btnadvstats').click(function(event) {
|
449
|
show_advstats();
|
450
|
});
|
451
|
|
452
|
// Show advanced leap second options ======================================
|
453
|
var showadvleap = false;
|
454
|
|
455
|
function show_advleap(ispageload) {
|
456
|
var text;
|
457
|
// On page load decide the initial state based on the data.
|
458
|
if (ispageload) {
|
459
|
<?php
|
460
|
// Note: leapfile is not a field saved in the config, so no need to test for it here.
|
461
|
// leapsec is the encoded text in the config, leaptext is not a pconfig[] key.
|
462
|
if (empty($pconfig['leapsec'])) {
|
463
|
$showadv = false;
|
464
|
} else {
|
465
|
$showadv = true;
|
466
|
}
|
467
|
?>
|
468
|
showadvleap = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
|
469
|
} else {
|
470
|
// It was a click, swap the state.
|
471
|
showadvleap = !showadvleap;
|
472
|
}
|
473
|
|
474
|
hideInput('leaptext', !showadvleap);
|
475
|
hideInput('leapfile', !showadvleap);
|
476
|
|
477
|
if (showadvleap) {
|
478
|
text = "<?=gettext('Hide Advanced');?>";
|
479
|
} else {
|
480
|
text = "<?=gettext('Display Advanced');?>";
|
481
|
}
|
482
|
$('#btnadvleap').html('<i class="fa fa-cog"></i> ' + text);
|
483
|
}
|
484
|
|
485
|
$('#btnadvleap').click(function(event) {
|
486
|
show_advleap();
|
487
|
});
|
488
|
|
489
|
// Set initial states
|
490
|
show_advstats(true);
|
491
|
show_advleap(true);
|
492
|
|
493
|
// Suppress "Delete row" button if there are fewer than two rows
|
494
|
checkLastRow();
|
495
|
});
|
496
|
//]]>
|
497
|
</script>
|
498
|
|
499
|
<?php include("foot.inc");
|