1
|
<?php
|
2
|
/*
|
3
|
services_ntpd.php
|
4
|
*/
|
5
|
/* ====================================================================
|
6
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
7
|
* Copyright (c) 2004, 2005 Scott Ullrich
|
8
|
* Copyright (c) 2013 Dagorlad
|
9
|
*
|
10
|
* Redistribution and use in source and binary forms, with or without modification,
|
11
|
* are permitted provided that the following conditions are met:
|
12
|
*
|
13
|
* 1. Redistributions of source code must retain the above copyright notice,
|
14
|
* this list of conditions and the following disclaimer.
|
15
|
*
|
16
|
* 2. Redistributions in binary form must reproduce the above copyright
|
17
|
* notice, this list of conditions and the following disclaimer in
|
18
|
* the documentation and/or other materials provided with the
|
19
|
* distribution.
|
20
|
*
|
21
|
* 3. All advertising materials mentioning features or use of this software
|
22
|
* must display the following acknowledgment:
|
23
|
* "This product includes software developed by the pfSense Project
|
24
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
25
|
*
|
26
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
27
|
* endorse or promote products derived from this software without
|
28
|
* prior written permission. For written permission, please contact
|
29
|
* coreteam@pfsense.org.
|
30
|
*
|
31
|
* 5. Products derived from this software may not be called "pfSense"
|
32
|
* nor may "pfSense" appear in their names without prior written
|
33
|
* permission of the Electric Sheep Fencing, LLC.
|
34
|
*
|
35
|
* 6. Redistributions of any form whatsoever must retain the following
|
36
|
* acknowledgment:
|
37
|
*
|
38
|
* "This product includes software developed by the pfSense Project
|
39
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
40
|
*
|
41
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
42
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
43
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
44
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
45
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
46
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
47
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
48
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
49
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
50
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
51
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
52
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
53
|
*
|
54
|
* ====================================================================
|
55
|
*
|
56
|
*/
|
57
|
/*
|
58
|
pfSense_MODULE: ntpd
|
59
|
*/
|
60
|
|
61
|
##|+PRIV
|
62
|
##|*IDENT=page-services-ntpd
|
63
|
##|*NAME=Services: NTP
|
64
|
##|*DESCR=Allow access to the 'Services: NTP' page.
|
65
|
##|*MATCH=services_ntpd.php*
|
66
|
##|-PRIV
|
67
|
|
68
|
define(NUMTIMESERVERS, 10); // The maximum number of configurable time servers
|
69
|
require("guiconfig.inc");
|
70
|
require_once('rrd.inc');
|
71
|
require_once("shaper.inc");
|
72
|
|
73
|
if (!is_array($config['ntpd'])) {
|
74
|
$config['ntpd'] = array();
|
75
|
}
|
76
|
|
77
|
if (empty($config['ntpd']['interface'])) {
|
78
|
if (is_array($config['installedpackages']['openntpd']) && is_array($config['installedpackages']['openntpd']['config']) &&
|
79
|
is_array($config['installedpackages']['openntpd']['config'][0]) && !empty($config['installedpackages']['openntpd']['config'][0]['interface'])) {
|
80
|
$pconfig['interface'] = explode(",", $config['installedpackages']['openntpd']['config'][0]['interface']);
|
81
|
unset($config['installedpackages']['openntpd']);
|
82
|
write_config("Upgraded settings from openttpd");
|
83
|
} else {
|
84
|
$pconfig['interface'] = array();
|
85
|
}
|
86
|
} else {
|
87
|
$pconfig['interface'] = explode(",", $config['ntpd']['interface']);
|
88
|
}
|
89
|
|
90
|
if ($_POST) {
|
91
|
unset($input_errors);
|
92
|
$pconfig = $_POST;
|
93
|
|
94
|
if (!$input_errors) {
|
95
|
if (is_array($_POST['interface'])) {
|
96
|
$config['ntpd']['interface'] = implode(",", $_POST['interface']);
|
97
|
} elseif (isset($config['ntpd']['interface'])) {
|
98
|
unset($config['ntpd']['interface']);
|
99
|
}
|
100
|
|
101
|
if (!empty($_POST['gpsport']) && file_exists('/dev/'.$_POST['gpsport'])) {
|
102
|
$config['ntpd']['gpsport'] = $_POST['gpsport'];
|
103
|
} elseif (isset($config['ntpd']['gpsport'])) {
|
104
|
unset($config['ntpd']['gpsport']);
|
105
|
}
|
106
|
|
107
|
unset($config['ntpd']['prefer']);
|
108
|
unset($config['ntpd']['noselect']);
|
109
|
$timeservers = '';
|
110
|
|
111
|
for ($i = 0; $i < 10; $i++) {
|
112
|
$tserver = trim($_POST["server{$i}"]);
|
113
|
if (!empty($tserver)) {
|
114
|
$timeservers .= "{$tserver} ";
|
115
|
if (!empty($_POST["servprefer{$i}"])) {
|
116
|
$config['ntpd']['prefer'] .= "{$tserver} ";
|
117
|
}
|
118
|
if (!empty($_POST["servselect{$i}"])) {
|
119
|
$config['ntpd']['noselect'] .= "{$tserver} ";
|
120
|
}
|
121
|
}
|
122
|
}
|
123
|
if (trim($timeservers) == "") {
|
124
|
$timeservers = "pool.ntp.org";
|
125
|
}
|
126
|
$config['system']['timeservers'] = trim($timeservers);
|
127
|
|
128
|
if (!empty($_POST['ntporphan']) && ($_POST['ntporphan'] < 17) && ($_POST['ntporphan'] != '12')) {
|
129
|
$config['ntpd']['orphan'] = $_POST['ntporphan'];
|
130
|
} elseif (isset($config['ntpd']['orphan'])) {
|
131
|
unset($config['ntpd']['orphan']);
|
132
|
}
|
133
|
|
134
|
if (!empty($_POST['logpeer'])) {
|
135
|
$config['ntpd']['logpeer'] = $_POST['logpeer'];
|
136
|
} elseif (isset($config['ntpd']['logpeer'])) {
|
137
|
unset($config['ntpd']['logpeer']);
|
138
|
}
|
139
|
|
140
|
if (!empty($_POST['logsys'])) {
|
141
|
$config['ntpd']['logsys'] = $_POST['logsys'];
|
142
|
} elseif (isset($config['ntpd']['logsys'])) {
|
143
|
unset($config['ntpd']['logsys']);
|
144
|
}
|
145
|
|
146
|
if (!empty($_POST['clockstats'])) {
|
147
|
$config['ntpd']['clockstats'] = $_POST['clockstats'];
|
148
|
} elseif (isset($config['ntpd']['clockstats'])) {
|
149
|
unset($config['ntpd']['clockstats']);
|
150
|
}
|
151
|
|
152
|
if (!empty($_POST['loopstats'])) {
|
153
|
$config['ntpd']['loopstats'] = $_POST['loopstats'];
|
154
|
} elseif (isset($config['ntpd']['loopstats'])) {
|
155
|
unset($config['ntpd']['loopstats']);
|
156
|
}
|
157
|
|
158
|
if (!empty($_POST['peerstats'])) {
|
159
|
$config['ntpd']['peerstats'] = $_POST['peerstats'];
|
160
|
} elseif (isset($config['ntpd']['peerstats'])) {
|
161
|
unset($config['ntpd']['peerstats']);
|
162
|
}
|
163
|
|
164
|
if (empty($_POST['kod'])) {
|
165
|
$config['ntpd']['kod'] = 'on';
|
166
|
} elseif (isset($config['ntpd']['kod'])) {
|
167
|
unset($config['ntpd']['kod']);
|
168
|
}
|
169
|
|
170
|
if (empty($_POST['nomodify'])) {
|
171
|
$config['ntpd']['nomodify'] = 'on';
|
172
|
} elseif (isset($config['ntpd']['nomodify'])) {
|
173
|
unset($config['ntpd']['nomodify']);
|
174
|
}
|
175
|
|
176
|
if (!empty($_POST['noquery'])) {
|
177
|
$config['ntpd']['noquery'] = $_POST['noquery'];
|
178
|
} elseif (isset($config['ntpd']['noquery'])) {
|
179
|
unset($config['ntpd']['noquery']);
|
180
|
}
|
181
|
|
182
|
if (!empty($_POST['noserve'])) {
|
183
|
$config['ntpd']['noserve'] = $_POST['noserve'];
|
184
|
} elseif (isset($config['ntpd']['noserve'])) {
|
185
|
unset($config['ntpd']['noserve']);
|
186
|
}
|
187
|
|
188
|
if (empty($_POST['nopeer'])) {
|
189
|
$config['ntpd']['nopeer'] = 'on';
|
190
|
} elseif (isset($config['ntpd']['nopeer'])) {
|
191
|
unset($config['ntpd']['nopeer']);
|
192
|
}
|
193
|
|
194
|
if (empty($_POST['notrap'])) {
|
195
|
$config['ntpd']['notrap'] = 'on';
|
196
|
} elseif (isset($config['ntpd']['notrap'])) {
|
197
|
unset($config['ntpd']['notrap']);
|
198
|
}
|
199
|
|
200
|
if ((empty($_POST['statsgraph'])) == (isset($config['ntpd']['statsgraph']))) {
|
201
|
$enable_rrd_graphing = true;
|
202
|
}
|
203
|
if (!empty($_POST['statsgraph'])) {
|
204
|
$config['ntpd']['statsgraph'] = $_POST['statsgraph'];
|
205
|
} elseif (isset($config['ntpd']['statsgraph'])) {
|
206
|
unset($config['ntpd']['statsgraph']);
|
207
|
}
|
208
|
if (isset($enable_rrd_graphing)) {
|
209
|
enable_rrd_graphing();
|
210
|
}
|
211
|
|
212
|
if (!empty($_POST['leaptxt'])) {
|
213
|
$config['ntpd']['leapsec'] = base64_encode($_POST['leaptxt']);
|
214
|
} elseif (isset($config['ntpd']['leapsec'])) {
|
215
|
unset($config['ntpd']['leapsec']);
|
216
|
}
|
217
|
|
218
|
if (is_uploaded_file($_FILES['leapfile']['tmp_name'])) {
|
219
|
$config['ntpd']['leapsec'] = base64_encode(file_get_contents($_FILES['leapfile']['tmp_name']));
|
220
|
}
|
221
|
|
222
|
write_config("Updated NTP Server Settings");
|
223
|
|
224
|
$retval = 0;
|
225
|
$retval = system_ntp_configure();
|
226
|
$savemsg = get_std_save_message($retval);
|
227
|
}
|
228
|
}
|
229
|
|
230
|
function build_interface_list() {
|
231
|
global $pconfig;
|
232
|
|
233
|
$iflist = array('options' => array(), 'selected' => array());
|
234
|
|
235
|
$interfaces = get_configured_interface_with_descr();
|
236
|
$carplist = get_configured_carp_interface_list();
|
237
|
|
238
|
foreach ($carplist as $cif => $carpip) {
|
239
|
$interfaces[$cif] = $carpip . " (" . get_vip_descr($carpip) .")";
|
240
|
}
|
241
|
|
242
|
$aliaslist = get_configured_ip_aliases_list();
|
243
|
|
244
|
foreach ($aliaslist as $aliasip => $aliasif) {
|
245
|
$interfaces[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
|
246
|
}
|
247
|
|
248
|
$size = (count($interfaces) < 10) ? count($interfaces) : 10;
|
249
|
|
250
|
foreach ($interfaces as $iface => $ifacename) {
|
251
|
if (!is_ipaddr(get_interface_ip($iface)) && !is_ipaddr($iface)) {
|
252
|
continue;
|
253
|
}
|
254
|
|
255
|
$iflist['options'][$iface] = $ifacename;
|
256
|
|
257
|
if (in_array($iface, $pconfig['interface'])) {
|
258
|
array_push($iflist['selected'], $iface);
|
259
|
}
|
260
|
}
|
261
|
|
262
|
return($iflist);
|
263
|
}
|
264
|
|
265
|
$closehead = false;
|
266
|
$pconfig = &$config['ntpd'];
|
267
|
if (empty($pconfig['interface'])) {
|
268
|
$pconfig['interface'] = array();
|
269
|
} else {
|
270
|
$pconfig['interface'] = explode(",", $pconfig['interface']);
|
271
|
}
|
272
|
$pgtitle = array(gettext("Services"), gettext("NTP"));
|
273
|
$shortcut_section = "ntp";
|
274
|
include("head.inc");
|
275
|
|
276
|
if ($input_errors)
|
277
|
print_input_errors($input_errors);
|
278
|
if ($savemsg)
|
279
|
print_info_box($savemsg, 'success');
|
280
|
|
281
|
$tab_array = array();
|
282
|
$tab_array[] = array(gettext("NTP"), true, "services_ntpd.php");
|
283
|
$tab_array[] = array(gettext("Serial GPS"), false, "services_ntpd_gps.php");
|
284
|
$tab_array[] = array(gettext("PPS"), false, "services_ntpd_pps.php");
|
285
|
display_top_tabs($tab_array);
|
286
|
|
287
|
require_once('classes/Form.class.php');
|
288
|
|
289
|
$form = new Form;
|
290
|
|
291
|
$section = new Form_Section('NTP server configuration');
|
292
|
|
293
|
$iflist = build_interface_list();
|
294
|
|
295
|
$section->addInput(new Form_Select(
|
296
|
'interface',
|
297
|
'Interface',
|
298
|
$iflist['selected'],
|
299
|
$iflist['options'],
|
300
|
true
|
301
|
))->setHelp('Interfaces without an IP address will not be shown.' . '<br />' .
|
302
|
'Selecting no interfaces will listen on all interfaces with a wildcard.' . '<br />' .
|
303
|
'Selecting all interfaces will explicitly listen on only the interfaces/IPs specified.');
|
304
|
|
305
|
$maxrows = 3;
|
306
|
$timeservers = explode( ' ', $config['system']['timeservers']);
|
307
|
for ($counter=0; $counter < $maxrows; $counter++) {
|
308
|
$group = new Form_Group($counter == 0 ? 'Time servers':'');
|
309
|
$group->addClass('repeatable');
|
310
|
|
311
|
$group->add(new Form_Input(
|
312
|
'server' . $counter,
|
313
|
null,
|
314
|
'text',
|
315
|
$timeservers[$counter],
|
316
|
['placeholder' => 'Hostname']
|
317
|
))->setWidth(3);
|
318
|
|
319
|
$group->add(new Form_Checkbox(
|
320
|
'servprefer' . $counter,
|
321
|
null,
|
322
|
null,
|
323
|
isset($config['ntpd']['prefer']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['prefer'], $timeservers[$counter])
|
324
|
))->sethelp('Prefer');
|
325
|
|
326
|
$group->add(new Form_Checkbox(
|
327
|
'servselect' . $counter,
|
328
|
null,
|
329
|
null,
|
330
|
isset($config['ntpd']['noselect']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['noselect'], $timeservers[$counter])
|
331
|
))->sethelp('No Select');
|
332
|
|
333
|
$group->add(new Form_Button(
|
334
|
'deleterow' . $counter,
|
335
|
'Delete'
|
336
|
))->removeClass('btn-primary')->addClass('btn-warning');
|
337
|
|
338
|
$section->add($group);
|
339
|
}
|
340
|
|
341
|
$section->addInput(new Form_Button(
|
342
|
'addrow',
|
343
|
'Add'
|
344
|
))->removeClass('btn-primary')->addClass('btn-success');
|
345
|
|
346
|
$section->addInput(new Form_StaticText(
|
347
|
null,
|
348
|
$btnaddrow
|
349
|
))->setHelp('For best results three to five servers should be configured here.' . '<br />' .
|
350
|
'The prefer option indicates that NTP should favor the use of this server more than all others.' . '<br />' .
|
351
|
'The noselect option indicates that NTP should not use this server for time, but stats for this server will be collected and displayed.');
|
352
|
|
353
|
$section->addInput(new Form_Input(
|
354
|
'ntporphan',
|
355
|
'Orphan mode',
|
356
|
'text',
|
357
|
$pconfig['ntporphan']
|
358
|
))->setHelp('Orphan mode allows the system clock to be used when no other clocks are available. ' .
|
359
|
'The number here specifies the stratum reported during orphan mode and should normally be set to a number high enough ' .
|
360
|
'to insure that any other servers available to clients are preferred over this server. (default: 12).');
|
361
|
|
362
|
$section->addInput(new Form_Checkbox(
|
363
|
'statsgraph',
|
364
|
'NTP Graphs',
|
365
|
'Enable RRD graphs of NTP statistics (default: disabled).',
|
366
|
$pconfig['statsgraph']
|
367
|
));
|
368
|
|
369
|
$section->addInput(new Form_Checkbox(
|
370
|
'logpeer',
|
371
|
'Syslog logging',
|
372
|
'Enable logging of peer messages (default: disabled).',
|
373
|
$pconfig['logpeer']
|
374
|
));
|
375
|
|
376
|
$section->addInput(new Form_Checkbox(
|
377
|
'logsys',
|
378
|
null,
|
379
|
'Enable logging of system messages (default: disabled).',
|
380
|
$pconfig['logsys']
|
381
|
))->setHelp('These options enable additional messages from NTP to be written to the System Log ' .
|
382
|
'<a href="diag_logs_ntpd.php">' . 'Status > System Logs > NTP' . '</a>');
|
383
|
|
384
|
// Statistics logging section
|
385
|
$btnadvstats = new Form_Button(
|
386
|
'btnadvstats',
|
387
|
'Advanced'
|
388
|
);
|
389
|
|
390
|
$btnadvstats->removeClass('btn-primary')->addClass('btn-default btn-sm');
|
391
|
|
392
|
$section->addInput(new Form_StaticText(
|
393
|
'Statistics logging',
|
394
|
$btnadvstats
|
395
|
))->setHelp('Warning: These options will create persistent daily log files in /var/log/ntp.');
|
396
|
|
397
|
$section->addInput(new Form_Checkbox(
|
398
|
'clockstats',
|
399
|
null,
|
400
|
'Enable logging of reference clock statistics (default: disabled).',
|
401
|
$pconfig['clockstats']
|
402
|
));
|
403
|
|
404
|
$section->addInput(new Form_Checkbox(
|
405
|
'loopstats',
|
406
|
null,
|
407
|
'Enable logging of clock discipline statistics (default: disabled).',
|
408
|
$pconfig['loopstats']
|
409
|
));
|
410
|
|
411
|
$section->addInput(new Form_Checkbox(
|
412
|
'peerstats',
|
413
|
null,
|
414
|
'Enable logging of NTP peer statistics (default: disabled).',
|
415
|
$pconfig['peerstats']
|
416
|
));
|
417
|
|
418
|
// Access restrictions section
|
419
|
$btnadvrestr = new Form_Button(
|
420
|
'btnadvrestr',
|
421
|
'Advanced'
|
422
|
);
|
423
|
|
424
|
$btnadvrestr->removeClass('btn-primary')->addClass('btn-default btn-sm');
|
425
|
|
426
|
$section->addInput(new Form_StaticText(
|
427
|
'Access Restrictions',
|
428
|
$btnadvrestr
|
429
|
))->setHelp('These options control access to NTP from the WAN.');
|
430
|
|
431
|
$section->addInput(new Form_Checkbox(
|
432
|
'kod',
|
433
|
null,
|
434
|
'Enable Kiss-o\'-death packets (default: enabled).',
|
435
|
$pconfig['kod']
|
436
|
));
|
437
|
|
438
|
$section->addInput(new Form_Checkbox(
|
439
|
'nomodify',
|
440
|
null,
|
441
|
'Deny state modifications (i.e. run time configuration) by ntpq and ntpdc (default: enabled).',
|
442
|
$pconfig['nomodify']
|
443
|
));
|
444
|
|
445
|
$section->addInput(new Form_Checkbox(
|
446
|
'noquery',
|
447
|
null,
|
448
|
'Disable ntpq and ntpdc queries (default: disabled).',
|
449
|
$pconfig['noquery']
|
450
|
));
|
451
|
|
452
|
$section->addInput(new Form_Checkbox(
|
453
|
'noserve',
|
454
|
null,
|
455
|
'Disable all except ntpq and ntpdc queries (default: disabled).',
|
456
|
$pconfig['noserve']
|
457
|
));
|
458
|
|
459
|
$section->addInput(new Form_Checkbox(
|
460
|
'nopeer',
|
461
|
null,
|
462
|
'Deny packets that attempt a peer association (default: enabled).',
|
463
|
$pconfig['nopeer']
|
464
|
));
|
465
|
|
466
|
$section->addInput(new Form_Checkbox(
|
467
|
'notrap',
|
468
|
null,
|
469
|
'Deny mode 6 control message trap service (default: enabled).',
|
470
|
$pconfig['notrap']
|
471
|
))->addClass('advrestrictions');
|
472
|
|
473
|
// Leap seconds section
|
474
|
$btnleap = new Form_Button(
|
475
|
'btnleap',
|
476
|
'Advanced'
|
477
|
);
|
478
|
|
479
|
$btnleap->removeClass('btn-primary')->addClass('btn-default btn-sm');
|
480
|
|
481
|
$section->addInput(new Form_StaticText(
|
482
|
'Leap seconds',
|
483
|
$btnleap
|
484
|
))->setHelp('A leap second file allows NTP to advertize an upcoming leap second addition or subtraction. ' .
|
485
|
'Normally this is only useful if this server is a stratum 1 time server. ');
|
486
|
|
487
|
$section->addInput(new Form_Textarea(
|
488
|
'leaptext',
|
489
|
null,
|
490
|
base64_decode(chunk_split($pconfig['leapsec']))
|
491
|
))->setHelp('Enter Leap second configuration as text OR select a file to upload');
|
492
|
|
493
|
$section->addInput(new Form_Input(
|
494
|
'leapfile',
|
495
|
null,
|
496
|
'file'
|
497
|
))->addClass('btn-default');
|
498
|
|
499
|
$form->add($section);
|
500
|
print($form);
|
501
|
|
502
|
?>
|
503
|
|
504
|
<script>
|
505
|
//<![CDATA[
|
506
|
events.push(function(){
|
507
|
|
508
|
function setMasks() {
|
509
|
// Find all ipaddress masks and make dynamic based on address family of input
|
510
|
$('span.pfIpMask + select').each(function (idx, select){
|
511
|
var input = $(select).prevAll('input[type=text]');
|
512
|
|
513
|
input.on('change', function(e){
|
514
|
var isV6 = (input.val().indexOf(':') != -1), min = 0, max = 128;
|
515
|
if (!isV6)
|
516
|
max = 32;
|
517
|
|
518
|
if (input.val() == "")
|
519
|
return;
|
520
|
|
521
|
while (select.options.length > max)
|
522
|
select.remove(0);
|
523
|
|
524
|
if (select.options.length < max)
|
525
|
{
|
526
|
for (var i=select.options.length; i<=max; i++)
|
527
|
select.options.add(new Option(i, i), 0);
|
528
|
}
|
529
|
});
|
530
|
|
531
|
// Fire immediately
|
532
|
input.change();
|
533
|
});
|
534
|
}
|
535
|
|
536
|
// Complicated function to move all help text associated with this input id to the same id
|
537
|
// on the row above. That way if you delete the last row, you don't lose the help
|
538
|
function moveHelpText(id) {
|
539
|
$('#' + id).parent('div').parent('div').find('input').each(function() { // For each <span></span>
|
540
|
var fromId = this.id;
|
541
|
var toId = decrStringInt(fromId);
|
542
|
var helpSpan;
|
543
|
|
544
|
if(!$(this).hasClass('pfIpMask') && !$(this).hasClass('btn')) {
|
545
|
|
546
|
helpSpan = $('#' + fromId).parent('div').parent('div').find('span:last').clone();
|
547
|
if($(helpSpan).hasClass('help-block')) {
|
548
|
if($('#' + decrStringInt(fromId)).parent('div').hasClass('input-group'))
|
549
|
$('#' + decrStringInt(fromId)).parent('div').after(helpSpan);
|
550
|
else
|
551
|
$('#' + decrStringInt(fromId)).after(helpSpan);
|
552
|
}
|
553
|
}
|
554
|
});
|
555
|
}
|
556
|
|
557
|
// Increment the number at the end of the string
|
558
|
function bumpStringInt( str ) {
|
559
|
var data = str.match(/(\D*)(\d+)(\D*)/), newStr = "";
|
560
|
|
561
|
if( data )
|
562
|
newStr = data[ 1 ] + ( Number( data[ 2 ] ) + 1 ) + data[ 3 ];
|
563
|
|
564
|
return newStr || str;
|
565
|
}
|
566
|
|
567
|
// Decrement the number at the end of the string
|
568
|
function decrStringInt( str ) {
|
569
|
var data = str.match(/(\D*)(\d+)(\D*)/), newStr = "";
|
570
|
|
571
|
if( data )
|
572
|
newStr = data[ 1 ] + ( Number( data[ 2 ] ) - 1 ) + data[ 3 ];
|
573
|
|
574
|
return newStr || str;
|
575
|
}
|
576
|
|
577
|
// Called after a delete so that there are no gaps in the numbering. Most of the time the config system doesn't care about
|
578
|
// gaps, but I do :)
|
579
|
function renumber() {
|
580
|
var idx = 0;
|
581
|
|
582
|
$('.repeatable').each(function() {
|
583
|
|
584
|
$(this).find('input').each(function() {
|
585
|
$(this).prop("id", this.id.replace(/\d+$/, "") + idx);
|
586
|
$(this).prop("name", this.name.replace(/\d+$/, "") + idx);
|
587
|
});
|
588
|
|
589
|
$(this).find('select').each(function() {
|
590
|
$(this).prop("id", this.id.replace(/\d+$/, "") + idx);
|
591
|
$(this).prop("name", this.name.replace(/\d+$/, "") + idx);
|
592
|
});
|
593
|
|
594
|
$(this).find('label').attr('for', $(this).find('label').attr('for').replace(/\d+$/, "") + idx);
|
595
|
|
596
|
idx++;
|
597
|
});
|
598
|
}
|
599
|
|
600
|
function delete_row(row) {
|
601
|
$('#' + row).parent('div').parent('div').remove();
|
602
|
renumber();
|
603
|
}
|
604
|
|
605
|
function add_row() {
|
606
|
// Find the lst repeatable group
|
607
|
var lastRepeatableGroup = $('.repeatable:last');
|
608
|
|
609
|
// Clone it
|
610
|
var newGroup = lastRepeatableGroup.clone(true);
|
611
|
|
612
|
// Increment the suffix number for each input elemnt in the new group
|
613
|
$(newGroup).find('input').each(function() {
|
614
|
$(this).prop("id", bumpStringInt(this.id));
|
615
|
$(this).prop("name", bumpStringInt(this.name));
|
616
|
if(!$(this).is('[id^=delete]'))
|
617
|
$(this).val('');
|
618
|
});
|
619
|
|
620
|
// Do the same for selectors
|
621
|
$(newGroup).find('select').each(function() {
|
622
|
$(this).prop("id", bumpStringInt(this.id));
|
623
|
$(this).prop("name", bumpStringInt(this.name));
|
624
|
// If this selector lists mask bits, we need it to be reset to all 128 options
|
625
|
// and no items selected, so that automatic v4/v6 selection still works
|
626
|
if($(this).is('[id^=address_subnet]')) {
|
627
|
$(this).empty();
|
628
|
for(idx=128; idx>0; idx--) {
|
629
|
$(this).append($('<option>', {
|
630
|
value: idx,
|
631
|
text: idx
|
632
|
}));
|
633
|
}
|
634
|
}
|
635
|
});
|
636
|
|
637
|
// And for "for" tags
|
638
|
$(newGroup).find('label').attr('for', bumpStringInt($(newGroup).find('label').attr('for')));
|
639
|
$(newGroup).find('label').text(""); // Clear the label. We only want it on the very first row
|
640
|
|
641
|
// Insert the updated/cloned row
|
642
|
$(lastRepeatableGroup).after(newGroup);
|
643
|
/*
|
644
|
// Delete any help text from the group we have cloned
|
645
|
$(lastRepeatableGroup).find('.help-block').each(function() {
|
646
|
$(this).remove();
|
647
|
});
|
648
|
*/
|
649
|
setMasks();
|
650
|
|
651
|
$('[id^=address]').autocomplete({
|
652
|
source: addressarray
|
653
|
});
|
654
|
}
|
655
|
|
656
|
// These are action buttons, not submit buttons
|
657
|
$('[id^=addrow]').prop('type','button');
|
658
|
$('[id^=delete]').prop('type','button');
|
659
|
|
660
|
// on click . .
|
661
|
$('[id^=addrow]').click(function() {
|
662
|
add_row();
|
663
|
});
|
664
|
|
665
|
$('[id^=delete]').click(function(event) {
|
666
|
if($('.repeatable').length > 1) {
|
667
|
// moveHelpText(event.target.id);
|
668
|
delete_row(event.target.id);
|
669
|
}
|
670
|
else
|
671
|
alert('<?php echo gettext("You may not delete the last one!")?>');
|
672
|
});
|
673
|
|
674
|
// Make the ‘clear’ button a plain button, not a submit button
|
675
|
$('#btnadvstats').prop('type','button');
|
676
|
|
677
|
// On click, show the controls in the stats section
|
678
|
$("#btnadvstats").click(function() {
|
679
|
hideCheckbox('clockstats', false);
|
680
|
hideCheckbox('loopstats', false);
|
681
|
hideCheckbox('peerstats', false);
|
682
|
});
|
683
|
|
684
|
// Make the ‘clear’ button a plain button, not a submit button
|
685
|
$('#btnadvrestr').prop('type','button');
|
686
|
|
687
|
// On click, show the controls in the restrictions section
|
688
|
$("#btnadvrestr").click(function() {
|
689
|
hideCheckbox('nomodify', false);
|
690
|
hideCheckbox('noquery', false);
|
691
|
hideCheckbox('noserve', false);
|
692
|
hideCheckbox('nopeer', false);
|
693
|
hideCheckbox('notrap', false);
|
694
|
});
|
695
|
|
696
|
// Make the ‘btnleap’ button a plain button, not a submit button
|
697
|
$('#btnleap').prop('type','button');
|
698
|
|
699
|
// On click, show the controls in the leap seconds section
|
700
|
$("#btnleap").click(function() {
|
701
|
hideInput('leaptext', false);
|
702
|
hideInput('leapfile', false);
|
703
|
});
|
704
|
|
705
|
// Set intial states
|
706
|
hideCheckbox('clockstats', true);
|
707
|
hideCheckbox('loopstats', true);
|
708
|
hideCheckbox('peerstats', true);
|
709
|
hideCheckbox('kod', true);
|
710
|
hideCheckbox('nomodify', true);
|
711
|
hideCheckbox('noquery', true);
|
712
|
hideCheckbox('noserve', true);
|
713
|
hideCheckbox('nopeer', true);
|
714
|
hideCheckbox('notrap', true);
|
715
|
hideInput('leaptext', true);
|
716
|
hideInput('leapfile', true);
|
717
|
});
|
718
|
//]]>
|
719
|
</script>
|
720
|
|
721
|
<?php include("foot.inc");
|