Project

General

Profile

Download (17.7 KB) Statistics
| Branch: | Tag: | Revision:
1 cf180ccc jim-p
<?php
2
/*
3
	services_ntpd.php
4
5 c1e68244 nagyrobi
	Copyright (C) 2013	Dagorlad
6 cf180ccc jim-p
	Copyright (C) 2012	Jim Pingle
7
	All rights reserved.
8
9
	Redistribution and use in source and binary forms, with or without
10
	modification, 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 the
17
	   documentation and/or other materials provided with the distribution.
18
19
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
	POSSIBILITY OF SUCH DAMAGE.
29
*/
30
/*
31
	pfSense_MODULE:	ntpd
32
*/
33
34
##|+PRIV
35
##|*IDENT=page-services-ntpd
36
##|*NAME=Services: NTP
37
##|*DESCR=Allow access to the 'Services: NTP' page.
38
##|*MATCH=services_ntpd.php*
39
##|-PRIV
40
41
require("guiconfig.inc");
42 c1e68244 nagyrobi
require_once('rrd.inc');
43
require_once("shaper.inc");
44 cf180ccc jim-p
45 08005d0a Ermal
if (!is_array($config['ntpd']))
46
	$config['ntpd'] = array();
47
48
if (empty($config['ntpd']['interface'])) {
49
	if (is_array($config['installedpackages']['openntpd']) && is_array($config['installedpackages']['openntpd']['config']) &&
50
	    is_array($config['installedpackages']['openntpd']['config'][0]) && !empty($config['installedpackages']['openntpd']['config'][0]['interface'])) {
51 46ca7f3d jim-p
		$pconfig['interface'] = explode(",", $config['installedpackages']['openntpd']['config'][0]['interface']);
52 cf180ccc jim-p
		unset($config['installedpackages']['openntpd']);
53 08005d0a Ermal
		write_config("Upgraded settings from openttpd");
54 cf180ccc jim-p
	} else
55
		$pconfig['interface'] = array();
56 08005d0a Ermal
} else
57 cf180ccc jim-p
	$pconfig['interface'] = explode(",", $config['ntpd']['interface']);
58
59
if ($_POST) {
60
61
	unset($input_errors);
62
	$pconfig = $_POST;
63
64
	if (!$input_errors) {
65 58168f4e jim-p
		if (is_array($_POST['interface']))
66
			$config['ntpd']['interface'] = implode(",", $_POST['interface']);
67
		elseif (isset($config['ntpd']['interface']))
68
			unset($config['ntpd']['interface']);
69 cf180ccc jim-p
70 5c8843d5 jim-p
		if (!empty($_POST['gpsport']) && file_exists('/dev/'.$_POST['gpsport']))
71
			$config['ntpd']['gpsport'] = $_POST['gpsport'];
72 6162b068 jim-p
		elseif (isset($config['ntpd']['gpsport']))
73 5c8843d5 jim-p
			unset($config['ntpd']['gpsport']);
74
75 c1e68244 nagyrobi
		unset($config['ntpd']['prefer']);
76
		unset($config['ntpd']['noselect']);
77
		$timeservers = '';
78
		for ($i = 0; $i < 10; $i++) {
79 08005d0a Ermal
			$tserver = trim($_POST["server{$i}"]);
80 c1e68244 nagyrobi
			if (!empty($tserver)) {
81
				$timeservers .= "{$tserver} ";
82
				if (!empty($_POST["servprefer{$i}"])) $config['ntpd']['prefer'] .= "{$tserver} ";
83
				if (!empty($_POST["servselect{$i}"])) $config['ntpd']['noselect'].= "{$tserver} ";
84
			}
85
		}
86
		$config['system']['timeservers'] = trim($timeservers);
87
88
		if (!empty($_POST['ntporphan']) && ($_POST['ntporphan'] < 17) && ($_POST['ntporphan'] != '12'))
89
			$config['ntpd']['orphan'] = $_POST['ntporphan'];
90
		elseif (isset($config['ntpd']['orphan']))
91
			unset($config['ntpd']['orphan']);
92
93
		if (!empty($_POST['logpeer']))
94
			$config['ntpd']['logpeer'] = $_POST['logpeer'];
95
		elseif (isset($config['ntpd']['logpeer']))
96
			unset($config['ntpd']['logpeer']);
97
98
		if (!empty($_POST['logsys']))
99
			$config['ntpd']['logsys'] = $_POST['logsys'];
100
		elseif (isset($config['ntpd']['logsys']))
101
			unset($config['ntpd']['logsys']);
102
103
		if (!empty($_POST['clockstats']))
104
			$config['ntpd']['clockstats'] = $_POST['clockstats'];
105
		elseif (isset($config['ntpd']['clockstats']))
106
			unset($config['ntpd']['clockstats']);
107
108
		if (!empty($_POST['loopstats']))
109
			$config['ntpd']['loopstats'] = $_POST['loopstats'];
110
		elseif (isset($config['ntpd']['loopstats']))
111
			unset($config['ntpd']['loopstats']);
112
113
		if (!empty($_POST['peerstats']))
114
			$config['ntpd']['peerstats'] = $_POST['peerstats'];
115
		elseif (isset($config['ntpd']['peerstats']))
116
			unset($config['ntpd']['peerstats']);
117
118
		if (empty($_POST['kod']))
119
			$config['ntpd']['kod'] = 'on';
120
		elseif (isset($config['ntpd']['kod']))
121
			unset($config['ntpd']['kod']);
122
123
		if (empty($_POST['nomodify']))
124
			$config['ntpd']['nomodify'] = 'on';
125
		elseif (isset($config['ntpd']['nomodify']))
126
			unset($config['ntpd']['nomodify']);
127
128
		if (!empty($_POST['noquery']))
129
			$config['ntpd']['noquery'] = $_POST['noquery'];
130
		elseif (isset($config['ntpd']['noquery']))
131
			unset($config['ntpd']['noquery']);
132
133
		if (!empty($_POST['noserve']))
134
			$config['ntpd']['noserve'] = $_POST['noserve'];
135
		elseif (isset($config['ntpd']['noserve']))
136
			unset($config['ntpd']['noserve']);
137
138
		if (empty($_POST['nopeer']))
139
			$config['ntpd']['nopeer'] = 'on';
140
		elseif (isset($config['ntpd']['nopeer']))
141
			unset($config['ntpd']['nopeer']);
142
143
		if (empty($_POST['notrap']))
144
			$config['ntpd']['notrap'] = 'on';
145
		elseif (isset($config['ntpd']['notrap']))
146
			unset($config['ntpd']['notrap']);
147
148
		if ((empty($_POST['statsgraph'])) != (isset($config['ntpd']['statsgraph'])));
149
			enable_rrd_graphing();
150
		if (!empty($_POST['statsgraph']))
151
			$config['ntpd']['statsgraph'] = $_POST['statsgraph'];
152
		elseif (isset($config['ntpd']['statsgraph']))
153
			unset($config['ntpd']['statsgraph']);
154
155
		if (!empty($_POST['leaptxt']))
156
			$config['ntpd']['leapsec'] = base64_encode($_POST['leaptxt']);
157
		elseif (isset($config['ntpd']['leapsec']))
158
			unset($config['ntpd']['leapsec']);
159
160
		if (is_uploaded_file($_FILES['leapfile']['tmp_name']))
161
			$config['ntpd']['leapsec'] = base64_encode(file_get_contents($_FILES['leapfile']['tmp_name']));
162
163 cf180ccc jim-p
		write_config("Updated NTP Server Settings");
164
165
		$retval = 0;
166
		$retval = system_ntp_configure();
167
		$savemsg = get_std_save_message($retval);
168
169
	}
170
}
171
172 c1e68244 nagyrobi
$pconfig = &$config['ntpd'];
173 cf180ccc jim-p
$pgtitle = array(gettext("Services"),gettext("NTP"));
174 b32dd0a6 jim-p
$shortcut_section = "ntp";
175 cf180ccc jim-p
include("head.inc");
176
177
?>
178
179 c1e68244 nagyrobi
<script type="text/javascript">
180
181
	//Generic show an advanced option function
182
	function show_advanced(showboxID, configvalueID) {
183
		document.getElementById(showboxID).innerHTML='';
184
		aodiv = document.getElementById(configvalueID);
185
		aodiv.style.display = "block";
186
	}
187
188
	//Insure only one of two mutually exclusive options are checked
189
	function CheckOffOther(clicked, checkOff) {
190
		if (document.getElementById(clicked).checked) {
191
			document.getElementById(checkOff).checked=false;
192
		}
193
	}
194
195
	//Show another time server line, limited to 10 servers
196
	function NewTimeServer(add) {
197
		//If the last line has a value
198
		var CheckServer = 'server' + (add - 1);
199
		var LastId = document.getElementById(CheckServer);
200
		if (document.getElementById(CheckServer).value != '') {
201
			if (add < 10) {
202
				var TimeServerID = 'timeserver' + add;
203
				document.getElementById(TimeServerID).style.display = 'block';
204
				//then revise the add another server line
205
				if (add < 9) {
206
					var next = add + 1;
207
					var newdiv = '<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="<?php echo gettext("Add another Time server");?>" OnClick="NewTimeServer(' + next + ')">\n';
208
					document.getElementById('addserver').innerHTML=newdiv;
209
				}else{
210
					document.getElementById('addserver').style.display = 'none';
211
				}
212
			}
213
		}
214
	}
215
	
216
</script>
217
218
219 cf180ccc jim-p
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
220
<?php include("fbegin.inc"); ?>
221 c1e68244 nagyrobi
<form action="services_ntpd.php" method="post" name="iform" id="iform" enctype="multipart/form-data" accept-charset="utf-8">
222 cf180ccc jim-p
<?php if ($input_errors) print_input_errors($input_errors); ?>
223
<?php if ($savemsg) print_info_box($savemsg); ?>
224
225
<table width="100%" border="0" cellpadding="0" cellspacing="0">
226 c1e68244 nagyrobi
  <tr>
227
	<td>
228
<?php
229
	$tab_array = array();
230
	$tab_array[] = array(gettext("NTP"), true, "services_ntpd.php");
231
	$tab_array[] = array(gettext("Serial GPS"), false, "services_ntpd_gps.php");
232
	$tab_array[] = array(gettext("PPS"), false, "services_ntpd_pps.php");
233
	display_top_tabs($tab_array);
234
?>
235
	</td>
236
  </tr>
237
  <tr>
238
	<td>
239
		<div id="mainarea">
240
		<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
241
			<tr>
242
				<td colspan="2" valign="top" class="listtopic"><?=gettext("NTP Server Configuration"); ?></td>
243
			</tr>
244
			<tr>
245
				<td width="22%" valign="top" class="vncellreq">Interface(s)</td>
246
				<td width="78%" class="vtable">
247 cf180ccc jim-p
<?php
248
	$interfaces = get_configured_interface_with_descr();
249
	$carplist = get_configured_carp_interface_list();
250
	foreach ($carplist as $cif => $carpip)
251
		$interfaces[$cif] = $carpip." (".get_vip_descr($carpip).")";
252
	$aliaslist = get_configured_ip_aliases_list();
253
	foreach ($aliaslist as $aliasip => $aliasif)
254
		$interfaces[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
255
	$size = (count($interfaces) < 10) ? count($interfaces) : 10;
256
?>
257 08005d0a Ermal
			<select id="interface" name="interface[]" multiple="true" class="formselect" size="<?php echo $size; ?>">
258 cf180ccc jim-p
<?php	
259
	foreach ($interfaces as $iface => $ifacename) {
260
		if (!is_ipaddr(get_interface_ip($iface)) && !is_ipaddr($iface))
261
			continue;
262
		echo "<option value='{$iface}'";
263 c1e68244 nagyrobi
		if (is_array($pconfig['interface']))
264 482c93e5 Ermal
			if (in_array($iface, $pconfig['interface'])) echo " selected=\"selected\"";
265 cf180ccc jim-p
		echo ">{$ifacename}</option>\n";
266
	} ?>
267 c1e68244 nagyrobi
					</select>
268
					<br/>
269
					<br/><?php echo gettext("Interfaces without an IP address will not be shown."); ?>
270
					<br/>
271
					<br/><?php echo gettext("Selecting no interfaces will listen on all interfaces with a wildcard."); ?>
272
					<br/><?php echo gettext("Selecting all interfaces will explicitly listen on only the interfaces/IPs specified."); ?>
273
				</td>
274
			</tr>
275
			<tr>
276
				<td width="22%" valign="top" class="vncellreq">Time servers</td>
277
				<td width="78%" class="vtable">
278
					<?php
279
					$timeservers = explode( ' ', $config['system']['timeservers']);
280
					for ($i = $j = 0; $i < 10; $i++){
281
						echo "<div id=\"timeserver{$i}\"";
282
						if ((isset($timeservers[$i])) || ($i < 3)) {
283
							$j++;
284
						}else{
285
							echo " style=\"display:none\"";
286
						}
287
						echo ">\n";
288
						
289
						echo "<input name=\"server{$i}\" class=\"formfld unknown\" id=\"server{$i}\" size=\"30\" value=\"{$timeservers[$i]}\" type=\"text\">&emsp;";
290
						echo "\n<input name=\"servprefer{$i}\" class=\"formcheckbox\" id=\"servprefer{$i}\" OnClick=\"CheckOffOther('servprefer{$i}', 'servselect{$i}')\" type=\"checkbox\"";
291
						if (substr_count($config['ntpd']['prefer'], $timeservers[$i])) echo ' checked';
292
						echo '>&nbsp;prefer&emsp;';
293
						echo "\n<input name=\"servselect{$i}\" class=\"formcheckbox\" id=\"servselect{$i}\" OnClick=\"CheckOffOther('servselect{$i}', 'servprefer{$i}')\" type=\"checkbox\"";
294
						if (substr_count($config['ntpd']['noselect'], $timeservers[$i])) echo ' checked';
295
						echo ">&nbsp;noselect\n<br/>\n</div>\n";
296
					}
297
					?>
298
					<div id="addserver">
299
					<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="<?php echo gettext("Add another Time server");?>" OnClick="NewTimeServer(<?php echo $j;?>)">
300
					</div>
301
					<br/>
302
					<?php echo gettext('For best results three to five servers should be configured here.'); ?>
303
					<br/>
304
					<?php echo gettext('The <i>prefer</i> option indicates that NTP should favor the use of this server more than all others.'); ?>
305
					<br/>
306
					<?php echo gettext('The <i>noselect</i> option indicates that NTP should not use this server for time, but stats for this server will be collected and displayed.'); ?>
307
				</td>
308
			</tr>
309
			<tr>
310
				<td width="22%" valign="top" class="vncellreq">Orphan mode</td>
311
				<td width="78%" class="vtable">
312
					<input name="ntporphan" type="text" class="formfld unknown" id="ntporphan" min="1" max="16" size="20" value="<?=htmlspecialchars($pconfig['orphan']);?>"><?php echo gettext("(0-15)");?><br>
313
					<?php echo gettext("Orphan mode allows the system clock to be used when no other clocks are available. The number here specifies the stratum reported during orphan mode and should normally be set to a number high enough to insure that any other servers available to clients are preferred over this server. (default: 12)."); ?>
314
				</td>
315
			</tr>
316
			<tr>
317
				<td width="22%" valign="top" class="vncellreq">NTP graphs</td>
318
				<td width="78%" class="vtable">
319
					<input name="statsgraph" type="checkbox" class="formcheckbox" id="statsgraph" <?php if($pconfig['statsgraph']) echo ' checked'; ?>>
320
					<?php echo gettext("Enable rrd graphs of NTP statistics (default: disabled)."); ?>
321
				</td>
322
			</tr>
323
			<tr>
324
				<td width="22%" valign="top" class="vncellreq">Syslog logging</td>
325
				<td width="78%" class="vtable">
326
					<?php echo gettext("These options enable additional messages from NTP to be written to the System Log");?> (<a href="diag_logs_ntpd.php"><?php echo gettext("Status > System Logs > NTP"); ?></a>).
327
					<br/><br/>
328
					<input name="logpeer" type="checkbox" class="formcheckbox" id="logpeer"<?php if($pconfig['logpeer']) echo ' checked'; ?>>
329
					<?php echo gettext("Enable logging of peer messages (default: disabled)."); ?>
330
					<br/>
331
					<input name="logsys" type="checkbox" class="formcheckbox" id="logsys"<?php if($pconfig['logsys']) echo ' checked'; ?>>
332
					<?php echo gettext("Enable logging of system messages (default: disabled)."); ?>
333
				</td>
334
			</tr>
335
			<tr>
336
				<td width="22%" valign="top" class="vncellreq">Statistics logging</td>
337
				<td width="78%" class="vtable">
338
					<div id="showstatisticsbox">
339
					<input type="button" onClick="show_advanced('showstatisticsbox', 'showstatistics')" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show statistics logging options");?></a>
340
					</div>
341
					<div id="showstatistics" style="display:none">
342
					<strong><?php echo gettext("Warning: ")?></strong><?php echo gettext("these options will create persistant daily log files in /var/log/ntp."); ?>
343
					<br/><br/>
344
					<input name="clockstats" type="checkbox" class="formcheckbox" id="clockstats"<?php if($pconfig['clockstats']) echo ' checked'; ?>>
345
					<?php echo gettext("Enable logging of reference clock statistics (default: disabled)."); ?>
346
					<br/>
347
					<input name="loopstats" type="checkbox" class="formcheckbox" id="loopstats"<?php if($pconfig['loopstats']) echo ' checked'; ?>>
348
					<?php echo gettext("Enable logging of clock discipline statistics (default: disabled)."); ?>
349
					<br/>
350
					<input name="peerstats" type="checkbox" class="formcheckbox" id="peerstats"<?php if($pconfig['peerstats']) echo ' checked'; ?>>
351
					<?php echo gettext("Enable logging of NTP peer statistics (default: disabled)."); ?>
352
					</div>
353
				</td>
354
			</tr>
355
			<tr>
356
				<td width="22%" valign="top" class="vncellreq">Access restrictions</td>
357
				<td width="78%" class="vtable">
358
					<div id="showrestrictbox">
359
					<input type="button" onClick="show_advanced('showrestrictbox', 'showrestrict')" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show access restriction options");?></a>
360
					</div>
361
					<div id="showrestrict" style="display:none">
362
					<?php echo gettext("these options control access to NTP from the WAN."); ?>
363
					<br/><br/>
364
					<input name="kod" type="checkbox" class="formcheckbox" id="kod"<?php if(!$pconfig['kod']) echo ' checked'; ?>>
365
					<?php echo gettext("Enable Kiss-o'-death packets (default: enabled)."); ?>
366
					<br/>
367
					<input name="nomodify" type="checkbox" class="formcheckbox" id="nomodify"<?php if(!$pconfig['nomodify']) echo ' checked'; ?>>
368
					<?php echo gettext("Deny state modifications (i.e. run time configuration) by ntpq and ntpdc (default: enabled)."); ?>
369
					<br/>
370
					<input name="noquery" type="checkbox" class="formcheckbox" id="noquery"<?php if($pconfig['noquery']) echo ' checked'; ?>>
371
					<?php echo gettext("Disable ntpq and ntpdc queries (default: disabled)."); ?>
372
					<br/>
373
					<input name="noserve" type="checkbox" class="formcheckbox" id="noserve"<?php if($pconfig['noserve']) echo ' checked'; ?>>
374
					<?php echo gettext("Disable all except ntpq and ntpdc queries (default: disabled)."); ?>
375
					<br/>
376
					<input name="nopeer" type="checkbox" class="formcheckbox" id="nopeer"<?php if(!$pconfig['nopeer']) echo ' checked'; ?>>
377
					<?php echo gettext("Deny packets that attempt a peer association (default: enabled)."); ?>
378
					<br/>
379
					<input name="notrap" type="checkbox" class="formcheckbox" id="notrap"<?php if(!$pconfig['notrap']) echo ' checked'; ?>>
380
					<?php echo gettext("Deny mode 6 control message trap service (default: enabled)."); ?>
381
					</div>
382
				</td>
383
			</tr>
384
			<tr>
385
				<td width="22%" valign="top" class="vncellreq">Leap seconds</td>
386
				<td width="78%" class="vtable">
387
					<div id="showleapsecbox">
388
					<input type="button" onClick="show_advanced('showleapsecbox', 'showleapsec')" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show Leap second configuration");?></a>
389
					</div>
390
					<div id="showleapsec" style="display:none">
391
					<?php echo gettext("A leap second file allows NTP to advertize an upcoming leap second addition or subtraction.");?>
392
					<?php echo gettext("Normally this is only useful if this server is a stratum 1 time server.");?>
393
					<br/><br/>
394
					<?php echo gettext("Enter Leap second configuration as text:");?><br />
395
					<textarea name="leaptxt" class="formpre" id="leaptxt" cols="65" rows="7"><?php $text = base64_decode(chunk_split($pconfig['leapsec'])); echo $text;?></textarea><br/>
396
					<strong><?php echo gettext("Or");?></strong>, <?php echo gettext("select a file to upload:");?>
397
					<input type="file" name="leapfile" class="formfld file" id="leapfile">
398
					</div>
399
				</td>
400
			</tr>
401
			<tr>
402
				<td width="22%" valign="top">&nbsp;</td>
403
				<td width="78%">
404
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>">
405
				</td>
406
			</tr>
407
		</table>
408 cf180ccc jim-p
</div></td></tr></table>
409
</form>
410
<?php include("fend.inc"); ?>
411
</body>
412
</html>