Project

General

Profile

Download (40.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * services_dhcpv6.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2020 Rubicon Communications, LLC (Netgate)
9
 * Copyright (c) 2010 Seth Mos <seth.mos@dds.nl>
10
 * All rights reserved.
11
 *
12
 * originally based on m0n0wall (http://m0n0.ch/wall)
13
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
14
 * All rights reserved.
15
 *
16
 * Licensed under the Apache License, Version 2.0 (the "License");
17
 * you may not use this file except in compliance with the License.
18
 * You may obtain a copy of the License at
19
 *
20
 * http://www.apache.org/licenses/LICENSE-2.0
21
 *
22
 * Unless required by applicable law or agreed to in writing, software
23
 * distributed under the License is distributed on an "AS IS" BASIS,
24
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
 * See the License for the specific language governing permissions and
26
 * limitations under the License.
27
 */
28

    
29
##|+PRIV
30
##|*IDENT=page-services-dhcpv6server
31
##|*NAME=Services: DHCPv6 Server
32
##|*DESCR=Allow access to the 'Services: DHCPv6 Server' page.
33
##|*MATCH=services_dhcpv6.php*
34
##|-PRIV
35

    
36
require_once("guiconfig.inc");
37
require_once("filter.inc");
38

    
39
function dhcpv6_apply_changes($dhcpdv6_enable_changed) {
40
	global $config, $g;
41

    
42
	$retval = 0;
43
	$retvaldhcp = 0;
44
	$retvaldns = 0;
45
	/* Stop DHCPv6 so we can cleanup leases */
46
	killbypid("{$g['dhcpd_chroot_path']}{$g['varrun_path']}/dhcpdv6.pid");
47
	// dhcp_clean_leases();
48
	/* dnsmasq_configure calls dhcpd_configure */
49
	/* no need to restart dhcpd twice */
50
	if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstatic']))	{
51
		$retvaldns |= services_dnsmasq_configure();
52
		if ($retvaldns == 0) {
53
			clear_subsystem_dirty('hosts');
54
			clear_subsystem_dirty('staticmaps');
55
		}
56
	} else if (isset($config['unbound']['enable']) && isset($config['unbound']['regdhcpstatic'])) {
57
		$retvaldns |= services_unbound_configure();
58
		if ($retvaldns == 0) {
59
			clear_subsystem_dirty('unbound');
60
			clear_subsystem_dirty('staticmaps');
61
		}
62
	} else {
63
		$retvaldhcp |= services_dhcpd_configure();
64
		if ($retvaldhcp == 0) {
65
			clear_subsystem_dirty('staticmaps');
66
		}
67
	}
68
	/* BIND package - Bug #3710 */
69
	if (!function_exists('is_package_installed')) {
70
		require_once('pkg-utils.inc');
71
	}
72
	if (is_package_installed('pfSense-pkg-bind') && isset($config['installedpackages']['bind']['config'][0]['enable_bind'])) {
73
		$reloadbind = false;
74
		if (is_array($config['installedpackages']['bindzone'])) {
75
			$bindzone = $config['installedpackages']['bindzone']['config'];
76
		} else {
77
			$bindzone = array();
78
		}
79
		for ($x = 0; $x < sizeof($bindzone); $x++) {
80
			$zone = $bindzone[$x];
81
			if ($zone['regdhcpstatic'] == 'on') {
82
				$reloadbind = true;
83
				break;
84
			}
85
		}
86
		if ($reloadbind === true) {
87
			if (file_exists("/usr/local/pkg/bind.inc")) {
88
				require_once("/usr/local/pkg/bind.inc");
89
				bind_sync();
90
			}
91
		}
92
	}
93
	if ($dhcpdv6_enable_changed) {
94
		$retvalfc |= filter_configure();
95
	}
96
	if ($retvaldhcp == 1 || $retvaldns == 1 || $retvalfc == 1) {
97
		$retval = 1;
98
	}
99
	return $retval;
100
}
101

    
102
if (!$g['services_dhcp_server_enable']) {
103
	header("Location: /");
104
	exit;
105
}
106

    
107
$if = $_REQUEST['if'];
108
$iflist = get_configured_interface_with_descr();
109
$iflist = array_merge($iflist, get_configured_pppoe_server_interfaces());
110

    
111
/* set the starting interface */
112
if (!$if || !isset($iflist[$if])) {
113
	foreach ($iflist as $ifent => $ifname) {
114
		$oc = $config['interfaces'][$ifent];
115
		$valid_if_ipaddrv6 = (bool) ($oc['ipaddrv6'] == 'track6' ||
116
		    (is_ipaddrv6($oc['ipaddrv6']) &&
117
		    !is_linklocal($oc['ipaddrv6'])));
118

    
119
		if ((!is_array($config['dhcpdv6'][$ifent]) ||
120
		    !isset($config['dhcpdv6'][$ifent]['enable'])) &&
121
		    !$valid_if_ipaddrv6) {
122
			continue;
123
		}
124
		$if = $ifent;
125
		break;
126
	}
127
}
128

    
129
if (is_array($config['dhcpdv6'][$if])) {
130
	/* DHCPv6 */
131
	if (is_array($config['dhcpdv6'][$if]['range'])) {
132
		$pconfig['range_from'] = $config['dhcpdv6'][$if]['range']['from'];
133
		$pconfig['range_to'] = $config['dhcpdv6'][$if]['range']['to'];
134
	}
135
	if (is_array($config['dhcpdv6'][$if]['prefixrange'])) {
136
		$pconfig['prefixrange_from'] = $config['dhcpdv6'][$if]['prefixrange']['from'];
137
		$pconfig['prefixrange_to'] = $config['dhcpdv6'][$if]['prefixrange']['to'];
138
		$pconfig['prefixrange_length'] = $config['dhcpdv6'][$if]['prefixrange']['prefixlength'];
139
	}
140
	$pconfig['deftime'] = $config['dhcpdv6'][$if]['defaultleasetime'];
141
	$pconfig['maxtime'] = $config['dhcpdv6'][$if]['maxleasetime'];
142
	$pconfig['domain'] = $config['dhcpdv6'][$if]['domain'];
143
	$pconfig['domainsearchlist'] = $config['dhcpdv6'][$if]['domainsearchlist'];
144
	list($pconfig['wins1'], $pconfig['wins2']) = $config['dhcpdv6'][$if]['winsserver'];
145
	list($pconfig['dns1'], $pconfig['dns2'], $pconfig['dns3'], $pconfig['dns4']) = $config['dhcpdv6'][$if]['dnsserver'];
146
	$pconfig['dhcp6c-dns'] = ($config['dhcpdv6'][$if]['dhcp6c-dns'] != 'disabled') ? "enabled" : "disabled";
147
	$pconfig['enable'] = isset($config['dhcpdv6'][$if]['enable']);
148
	$pconfig['ddnsdomain'] = $config['dhcpdv6'][$if]['ddnsdomain'];
149
	$pconfig['ddnsdomainprimary'] = $config['dhcpdv6'][$if]['ddnsdomainprimary'];
150
	$pconfig['ddnsdomainsecondary'] = $config['dhcpdv6'][$if]['ddnsdomainsecondary'];
151
	$pconfig['ddnsdomainkeyname'] = $config['dhcpdv6'][$if]['ddnsdomainkeyname'];
152
	$pconfig['ddnsdomainkeyalgorithm'] = $config['dhcpdv6'][$if]['ddnsdomainkeyalgorithm'];
153
	$pconfig['ddnsdomainkey'] = $config['dhcpdv6'][$if]['ddnsdomainkey'];
154
	$pconfig['ddnsupdate'] = isset($config['dhcpdv6'][$if]['ddnsupdate']);
155
	$pconfig['ddnsforcehostname'] = isset($config['dhcpdv6'][$if]['ddnsforcehostname']);
156
	$pconfig['ddnsreverse'] = isset($config['dhcpdv6'][$if]['ddnsreverse']);
157
	$pconfig['ddnsclientupdates'] = $config['dhcpdv6'][$if]['ddnsclientupdates'];
158
	list($pconfig['ntp1'], $pconfig['ntp2'], $pconfig['ntp3'] ) = $config['dhcpdv6'][$if]['ntpserver'];
159
	$pconfig['tftp'] = $config['dhcpdv6'][$if]['tftp'];
160
	$pconfig['ldap'] = $config['dhcpdv6'][$if]['ldap'];
161
	$pconfig['netboot'] = isset($config['dhcpdv6'][$if]['netboot']);
162
	$pconfig['bootfile_url'] = $config['dhcpdv6'][$if]['bootfile_url'];
163
	$pconfig['netmask'] = $config['dhcpdv6'][$if]['netmask'];
164
	$pconfig['numberoptions'] = $config['dhcpdv6'][$if]['numberoptions'];
165
	$pconfig['dhcpv6leaseinlocaltime'] = $config['dhcpdv6'][$if]['dhcpv6leaseinlocaltime'];
166
	if (!is_array($config['dhcpdv6'][$if]['staticmap'])) {
167
		$config['dhcpdv6'][$if]['staticmap'] = array();
168
	}
169
	init_config_arr(array('dhcpdv6', $if, 'staticmap'));
170
	$a_maps = &$config['dhcpdv6'][$if]['staticmap'];
171
}
172

    
173
if ($config['interfaces'][$if]['ipaddrv6'] == 'track6') {
174
	$trackifname = $config['interfaces'][$if]['track6-interface'];
175
	$trackcfg = $config['interfaces'][$trackifname];
176
	$ifcfgsn = "64";
177
	$ifcfgip = '::';
178

    
179
	$str_help_mask = dhcpv6_pd_str_help($ifcfgsn);
180
} else {
181
	$ifcfgip = get_interface_ipv6($if);
182
	$ifcfgsn = get_interface_subnetv6($if);
183
}
184

    
185
/*	 set the enabled flag which will tell us if DHCP relay is enabled
186
 *	 on any interface. We will use this to disable DHCP server since
187
 *	 the two are not compatible with each other.
188
 */
189

    
190
$dhcrelay_enabled = false;
191
$dhcrelaycfg = $config['dhcrelay6'];
192

    
193
if (is_array($dhcrelaycfg) && isset($dhcrelaycfg['enable']) && isset($dhcrelaycfg['interface']) && !empty($dhcrelaycfg['interface'])) {
194
	$dhcrelayifs = explode(",", $dhcrelaycfg['interface']);
195

    
196
	foreach ($dhcrelayifs as $dhcrelayif) {
197

    
198
		if (isset($iflist[$dhcrelayif]) && (!link_interface_to_bridge($dhcrelayif))) {
199
			$dhcrelay_enabled = true;
200
			break;
201
		}
202
	}
203
}
204

    
205
if (isset($_POST['apply'])) {
206
	$changes_applied = true;
207
	$retval = dhcpv6_apply_changes(false);
208
} elseif (isset($_POST['save'])) {
209
	unset($input_errors);
210

    
211
	$old_dhcpdv6_enable = ($pconfig['enable'] == true);
212
	$new_dhcpdv6_enable = ($_POST['enable'] ? true : false);
213
	$dhcpdv6_enable_changed = ($old_dhcpdv6_enable != $new_dhcpdv6_enable);
214

    
215
	$pconfig = $_POST;
216

    
217
	$numberoptions = array();
218
	for ($x = 0; $x < 99; $x++) {
219
		if (isset($_POST["number{$x}"]) && ctype_digit($_POST["number{$x}"])) {
220
			$numbervalue = array();
221
			$numbervalue['number'] = htmlspecialchars($_POST["number{$x}"]);
222
			$numbervalue['value'] = base64_encode($_POST["value{$x}"]);
223
			$numberoptions['item'][] = $numbervalue;
224
		}
225
	}
226
	// Reload the new pconfig variable that the form uses.
227
	$pconfig['numberoptions'] = $numberoptions;
228

    
229
	/* input validation */
230

    
231
	// Note: if DHCPv6 Server is not enabled, then it is OK to adjust other parameters without specifying range from-to.
232
	if ($_POST['enable']) {
233
		if ((empty($_POST['range_from']) || empty($_POST['range_to'])) &&
234
		    ($config['dhcpdv6'][$if]['ramode'] != 'stateless_dhcp')) {
235
			$input_errors[] = gettext("A valid range must be specified for any mode except Stateless DHCP.");
236
		}
237
	}
238

    
239
	if (($_POST['prefixrange_from'] && !is_ipaddrv6($_POST['prefixrange_from']))) {
240
		$input_errors[] = gettext("A valid prefix range must be specified.");
241
	}
242
	if (($_POST['prefixrange_to'] && !is_ipaddrv6($_POST['prefixrange_to']))) {
243
		$input_errors[] = gettext("A valid prefix range must be specified.");
244
	}
245

    
246
	if ($_POST['prefixrange_from'] && $_POST['prefixrange_to'] &&
247
		$_POST['prefixrange_length']) {
248
		$netmask = Net_IPv6::getNetmask($_POST['prefixrange_from'],
249
			$_POST['prefixrange_length']);
250
		$netmask = text_to_compressed_ip6($netmask);
251

    
252
		if ($netmask != text_to_compressed_ip6(strtolower(
253
			$_POST['prefixrange_from']))) {
254
			$input_errors[] = sprintf(gettext(
255
				"Prefix Delegation From address is not a valid IPv6 Netmask for %s"),
256
				$netmask . '/' . $_POST['prefixrange_length']);
257
		}
258

    
259
		$netmask = Net_IPv6::getNetmask($_POST['prefixrange_to'],
260
			$_POST['prefixrange_length']);
261
		$netmask = text_to_compressed_ip6($netmask);
262

    
263
		if ($netmask != text_to_compressed_ip6(strtolower(
264
			$_POST['prefixrange_to']))) {
265
			$input_errors[] = sprintf(gettext(
266
				"Prefix Delegation To address is not a valid IPv6 Netmask for %s"),
267
				$netmask . '/' . $_POST['prefixrange_length']);
268
		}
269
	}
270

    
271
	$range_from_to_ok = true;
272

    
273
	if ($_POST['range_from']) {
274
		if (!is_ipaddrv6($_POST['range_from'])) {
275
			$input_errors[] = gettext("A valid range must be specified.");
276
			$range_from_to_ok = false;
277
		} elseif ($config['interfaces'][$if]['ipaddrv6'] == 'track6' &&
278
			!Net_IPv6::isInNetmask($_POST['range_from'], '::', $ifcfgsn)) {
279
			$input_errors[] = sprintf(gettext(
280
				'The prefix (upper %1$s bits) must be zero.  Use the form %2$s'),
281
				$ifcfgsn, $str_help_mask);
282
			$range_from_to_ok = false;
283
		}
284
	}
285
	if ($_POST['range_to']) {
286
		if (!is_ipaddrv6($_POST['range_to'])) {
287
			$input_errors[] = gettext("A valid range must be specified.");
288
			$range_from_to_ok = false;
289
		} elseif ($config['interfaces'][$if]['ipaddrv6'] == 'track6' &&
290
			!Net_IPv6::isInNetmask($_POST['range_to'], '::', $ifcfgsn)) {
291
			$input_errors[] = sprintf(gettext(
292
				'The prefix (upper %1$s bits) must be zero.  Use the form %2$s'),
293
				$ifcfgsn, $str_help_mask);
294
			$range_from_to_ok = false;
295
		}
296
	}
297
	if (($_POST['range_from'] && !$_POST['range_to']) || ($_POST['range_to'] && !$_POST['range_from'])) {
298
		$input_errors[] = gettext("Range From and Range To must both be entered.");
299
	}
300
	if (($_POST['gateway'] && !is_ipaddrv6($_POST['gateway']))) {
301
		$input_errors[] = gettext("A valid IPv6 address must be specified for the gateway.");
302
	}
303
	if (($_POST['dns1'] && !is_ipaddrv6($_POST['dns1'])) ||
304
		($_POST['dns2'] && !is_ipaddrv6($_POST['dns2'])) ||
305
		($_POST['dns3'] && !is_ipaddrv6($_POST['dns3'])) ||
306
		($_POST['dns4'] && !is_ipaddrv6($_POST['dns4']))) {
307
		$input_errors[] = gettext("A valid IPv6 address must be specified for each of the DNS servers.");
308
	}
309

    
310
	if ($_POST['deftime'] && (!is_numeric($_POST['deftime']) || ($_POST['deftime'] < 60))) {
311
		$input_errors[] = gettext("The default lease time must be at least 60 seconds.");
312
	}
313
	if ($_POST['maxtime'] && (!is_numeric($_POST['maxtime']) || ($_POST['maxtime'] < 60) || ($_POST['maxtime'] <= $_POST['deftime']))) {
314
		$input_errors[] = gettext("The maximum lease time must be at least 60 seconds and higher than the default lease time.");
315
	}
316
	if ($_POST['ddnsupdate']) {
317
		if (!is_domain($_POST['ddnsdomain'])) {
318
			$input_errors[] = gettext("A valid domain name must be specified for the dynamic DNS registration.");
319
		}
320
		if (!is_ipaddr($_POST['ddnsdomainprimary'])) {
321
			$input_errors[] = gettext("A valid primary domain name server IP address must be specified for the dynamic domain name.");
322
		}
323
		if (!empty($_POST['ddnsdomainsecondary']) && !is_ipaddr($_POST['ddnsdomainsecondary'])) {
324
			$input_errors[] = gettext("A valid secondary domain name server IP address must be specified for the dynamic domain name.");
325
		}
326
		if (!$_POST['ddnsdomainkeyname'] || !$_POST['ddnsdomainkeyalgorithm'] || !$_POST['ddnsdomainkey']) {
327
			$input_errors[] = gettext("A valid domain key name, algorithm and secret must be specified.");
328
		}
329
		if (preg_match('/[^A-Za-z0-9\.\-\_]/', $_POST['ddnsdomainkeyname'])) {
330
			$input_errors[] = gettext("The domain key name may only contain the characters a-z, A-Z, 0-9, '-', '_' and '.'");
331
		}
332
		if ($_POST['ddnsdomainkey'] && !base64_decode($_POST['ddnsdomainkey'], true)) {
333
			$input_errors[] = gettext("The domain key secret must be a Base64 encoded value.");
334
		}
335
	}
336
	if ($_POST['domainsearchlist']) {
337
		$domain_array = preg_split("/[ ;]+/", $_POST['domainsearchlist']);
338
		foreach ($domain_array as $curdomain) {
339
			if (!is_domain($curdomain)) {
340
				$input_errors[] = gettext("A valid domain search list must be specified.");
341
				break;
342
			}
343
		}
344
	}
345

    
346
	if (($_POST['ntp1'] && !is_ipaddrv6($_POST['ntp1'])) ||
347
	    ($_POST['ntp2'] && !is_ipaddrv6($_POST['ntp2'])) ||
348
	    ($_POST['ntp3'] && !is_ipaddrv6($_POST['ntp3']))) {
349
		$input_errors[] = gettext("A valid IPv6 address must be specified for the primary/secondary NTP servers.");
350
	}
351
	if (($_POST['domain'] && !is_domain($_POST['domain']))) {
352
		$input_errors[] = gettext("A valid domain name must be specified for the DNS domain.");
353
	}
354
	if ($_POST['tftp'] && !is_ipaddr($_POST['tftp']) && !is_domain($_POST['tftp']) && !is_URL($_POST['tftp'])) {
355
		$input_errors[] = gettext("A valid IPv6 address or hostname must be specified for the TFTP server.");
356
	}
357
	if (($_POST['bootfile_url'] && !is_URL($_POST['bootfile_url']))) {
358
		$input_errors[] = gettext("A valid URL must be specified for the network bootfile.");
359
	}
360

    
361
	// Disallow a range that includes the virtualip
362
	if ($range_from_to_ok && is_array($config['virtualip']['vip'])) {
363
		foreach ($config['virtualip']['vip'] as $vip) {
364
			if ($vip['interface'] == $if) {
365
				if ($vip['subnetv6'] && is_inrange_v6($vip['subnetv6'], $_POST['range_from'], $_POST['range_to'])) {
366
					$input_errors[] = sprintf(gettext("The subnet range cannot overlap with virtual IPv6 address %s."), $vip['subnetv6']);
367
				}
368
			}
369
		}
370
	}
371

    
372
	$noip = false;
373
	if (is_array($a_maps)) {
374
		foreach ($a_maps as $map) {
375
			if (empty($map['ipaddrv6'])) {
376
				$noip = true;
377
			}
378
		}
379
	}
380

    
381
	/* make sure that the DHCP Relay isn't enabled on this interface */
382
	if ($_POST['enable'] && $dhcrelay_enabled) {
383
		$input_errors[] = sprintf(gettext("The DHCP relay on the %s interface must be disabled before enabling the DHCP server."), $iflist[$if]);
384
	}
385

    
386
	// If nothing is wrong so far, and we have range from and to, then check conditions related to the values of range from and to.
387
	if (!$input_errors && $_POST['range_from'] && $_POST['range_to']) {
388
		/* make sure the range lies within the current subnet */
389
		$subnet_start = gen_subnetv6($ifcfgip, $ifcfgsn);
390
		$subnet_end = gen_subnetv6_max($ifcfgip, $ifcfgsn);
391

    
392
		if (is_ipaddrv6($ifcfgip)) {
393
			if ((!is_inrange_v6($_POST['range_from'], $subnet_start, $subnet_end)) ||
394
				(!is_inrange_v6($_POST['range_to'], $subnet_start, $subnet_end))) {
395
				$input_errors[] = gettext("The specified range lies outside of the current subnet.");
396
			}
397
		}
398
		/* "from" cannot be higher than "to" */
399
		if (inet_pton($_POST['range_from']) > inet_pton($_POST['range_to'])) {
400
			$input_errors[] = gettext("The range is invalid (first element higher than second element).");
401
		}
402

    
403
		/* Verify static mappings do not overlap:
404
		   - available DHCP range
405
		   - prefix delegation range (FIXME: still need to be completed) */
406
		$dynsubnet_start = inet_pton($_POST['range_from']);
407
		$dynsubnet_end = inet_pton($_POST['range_to']);
408

    
409
		if (is_array($a_maps)) {
410
			foreach ($a_maps as $map) {
411
				if (empty($map['ipaddrv6'])) {
412
					continue;
413
				}
414
				if ((inet_pton($map['ipaddrv6']) > $dynsubnet_start) &&
415
					(inet_pton($map['ipaddrv6']) < $dynsubnet_end)) {
416
					$input_errors[] = sprintf(gettext("The DHCP range cannot overlap any static DHCP mappings."));
417
					break;
418
				}
419
			}
420
		}
421
	}
422

    
423
	if (!$input_errors) {
424
		if (!is_array($config['dhcpdv6'])) {
425
			$config['dhcpdv6'] = array();
426
		}
427
		if (!is_array($config['dhcpdv6'][$if])) {
428
			$config['dhcpdv6'][$if] = array();
429
		}
430
		if (!is_array($config['dhcpdv6'][$if]['range'])) {
431
			$config['dhcpdv6'][$if]['range'] = array();
432
		}
433
		if (!is_array($config['dhcpdv6'][$if]['prefixrange'])) {
434
			$config['dhcpdv6'][$if]['prefixrange'] = array();
435
		}
436

    
437
		$config['dhcpdv6'][$if]['range']['from'] = $_POST['range_from'];
438
		$config['dhcpdv6'][$if]['range']['to'] = $_POST['range_to'];
439
		$config['dhcpdv6'][$if]['prefixrange']['from'] = $_POST['prefixrange_from'];
440
		$config['dhcpdv6'][$if]['prefixrange']['to'] = $_POST['prefixrange_to'];
441
		$config['dhcpdv6'][$if]['prefixrange']['prefixlength'] = $_POST['prefixrange_length'];
442
		$config['dhcpdv6'][$if]['defaultleasetime'] = $_POST['deftime'];
443
		$config['dhcpdv6'][$if]['maxleasetime'] = $_POST['maxtime'];
444
		$config['dhcpdv6'][$if]['netmask'] = $_POST['netmask'];
445

    
446
		unset($config['dhcpdv6'][$if]['winsserver']);
447

    
448
		unset($config['dhcpdv6'][$if]['dnsserver']);
449
		if ($_POST['dns1']) {
450
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns1'];
451
		}
452
		if ($_POST['dns2']) {
453
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns2'];
454
		}
455
		if ($_POST['dns3']) {
456
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns3'];
457
		}
458
		if ($_POST['dns4']) {
459
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns4'];
460
		}
461
		$config['dhcpdv6'][$if]['dhcp6c-dns'] = ($_POST['dhcp6c-dns']) ? "enabled" : "disabled";
462
		$config['dhcpdv6'][$if]['domain'] = $_POST['domain'];
463
		$config['dhcpdv6'][$if]['domainsearchlist'] = $_POST['domainsearchlist'];
464
		$config['dhcpdv6'][$if]['enable'] = ($_POST['enable']) ? true : false;
465
		$config['dhcpdv6'][$if]['ddnsdomain'] = $_POST['ddnsdomain'];
466
		$config['dhcpdv6'][$if]['ddnsdomainprimary'] = $_POST['ddnsdomainprimary'];
467
		$config['dhcpdv6'][$if]['ddnsdomainsecondary'] = (!empty($_POST['ddnsdomainsecondary'])) ? $_POST['ddnsdomainsecondary'] : ''; 
468
		$config['dhcpdv6'][$if]['ddnsdomainkeyname'] = $_POST['ddnsdomainkeyname'];
469
		$config['dhcpdv6'][$if]['ddnsdomainkeyalgorithm'] = $_POST['ddnsdomainkeyalgorithm'];
470
		$config['dhcpdv6'][$if]['ddnsdomainkey'] = $_POST['ddnsdomainkey'];
471
		$config['dhcpdv6'][$if]['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
472
		$config['dhcpdv6'][$if]['ddnsforcehostname'] = ($_POST['ddnsforcehostname']) ? true : false;
473
		$config['dhcpdv6'][$if]['ddnsreverse'] = ($_POST['ddnsreverse']) ? true : false;
474
		$config['dhcpdv6'][$if]['ddnsclientupdates'] = $_POST['ddnsclientupdates'];
475

    
476
		unset($config['dhcpdv6'][$if]['ntpserver']);
477
		if ($_POST['ntp1']) {
478
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp1'];
479
		}
480
		if ($_POST['ntp2']) {
481
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp2'];
482
		}
483
		if ($_POST['ntp3']) {
484
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp3'];
485
		}
486

    
487
		$config['dhcpdv6'][$if]['tftp'] = $_POST['tftp'];
488
		$config['dhcpdv6'][$if]['ldap'] = $_POST['ldap'];
489
		$config['dhcpdv6'][$if]['netboot'] = ($_POST['netboot']) ? true : false;
490
		$config['dhcpdv6'][$if]['bootfile_url'] = $_POST['bootfile_url'];
491
		$config['dhcpdv6'][$if]['dhcpv6leaseinlocaltime'] = $_POST['dhcpv6leaseinlocaltime'];
492

    
493
		// Handle the custom options rowhelper
494
		if (isset($config['dhcpdv6'][$if]['numberoptions']['item'])) {
495
			unset($config['dhcpdv6'][$if]['numberoptions']['item']);
496
		}
497

    
498
		$config['dhcpdv6'][$if]['numberoptions'] = $numberoptions;
499

    
500
		write_config("DHCPv6 server settings saved");
501

    
502
		$changes_applied = true;
503
		$retval = dhcpv6_apply_changes($dhcpdv6_enable_changed);
504
	}
505
}
506

    
507
if ($_POST['act'] == "del") {
508
	if ($a_maps[$_POST['id']]) {
509
		unset($a_maps[$_POST['id']]);
510
		write_config("DHCPv6 server static map deleted");
511
		if (isset($config['dhcpdv6'][$if]['enable'])) {
512
			mark_subsystem_dirty('staticmapsv6');
513
			if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstaticv6'])) {
514
				mark_subsystem_dirty('hosts');
515
			}
516
		}
517
		header("Location: services_dhcpv6.php?if={$if}");
518
		exit;
519
	}
520
}
521

    
522
$pgtitle = array(gettext("Services"), htmlspecialchars(gettext("DHCPv6 Server & RA")));
523
$pglinks = array("", "services_dhcpv6.php");
524

    
525
if (!empty($if) && isset($iflist[$if])) {
526
	$pgtitle[] = $iflist[$if];
527
	$pglinks[] = "@self";
528
	$pgtitle[] = gettext("DHCPv6 Server");
529
	$pglinks[] = "@self";
530
}
531
$shortcut_section = "dhcp6";
532

    
533
include("head.inc");
534

    
535
if ($input_errors) {
536
	print_input_errors($input_errors);
537
}
538

    
539
if ($changes_applied) {
540
	print_apply_result_box($retval);
541
}
542

    
543
if (is_subsystem_dirty('staticmaps')) {
544
	print_apply_box(gettext('The static mapping configuration has been changed.') . '<br />' . gettext('The changes must be applied for them to take effect.'));
545
}
546

    
547
/* active tabs */
548
$tab_array = array();
549
$tabscounter = 0;
550
$i = 0;
551

    
552
foreach ($iflist as $ifent => $ifname) {
553
	$oc = $config['interfaces'][$ifent];
554
	$valid_if_ipaddrv6 = (bool) ($oc['ipaddrv6'] == 'track6' ||
555
	    (is_ipaddrv6($oc['ipaddrv6']) &&
556
	    !is_linklocal($oc['ipaddrv6'])));
557

    
558
	if ((!is_array($config['dhcpdv6'][$ifent]) ||
559
	    !isset($config['dhcpdv6'][$ifent]['enable'])) &&
560
	    !$valid_if_ipaddrv6) {
561
		continue;
562
	}
563

    
564
	if ($ifent == $if) {
565
		$active = true;
566
	} else {
567
		$active = false;
568
	}
569

    
570
	$tab_array[] = array($ifname, $active, "services_dhcpv6.php?if={$ifent}");
571
	$tabscounter++;
572
}
573

    
574
/* tack on PPPoE or PPtP servers here */
575
/* pppoe server */
576
if (is_array($config['pppoes']['pppoe'])) {
577
	foreach ($config['pppoes']['pppoe'] as $pppoe) {
578
		if ($pppoe['mode'] == "server") {
579
			$ifent = "poes". $pppoe['pppoeid'];
580
			$ifname = strtoupper($ifent);
581

    
582
			if ($ifent == $if) {
583
				$active = true;
584
			} else {
585
				$active = false;
586
			}
587

    
588
			$tab_array[] = array($ifname, $active, "services_dhcpv6.php?if={$ifent}");
589
			$tabscounter++;
590
		}
591
	}
592
}
593

    
594
if ($tabscounter == 0) {
595
	print_info_box(gettext("The DHCPv6 Server can only be enabled on interfaces configured with a static IPv6 address. This system has none."), 'danger');
596
	include("foot.inc");
597
	exit;
598
}
599

    
600
display_top_tabs($tab_array);
601

    
602
$tab_array = array();
603
$tab_array[] = array(gettext("DHCPv6 Server"),		 true,	"services_dhcpv6.php?if={$if}");
604
$tab_array[] = array(gettext("Router Advertisements"), false, "services_router_advertisements.php?if={$if}");
605
display_top_tabs($tab_array, false, 'nav nav-tabs');
606

    
607
$form = new Form();
608

    
609
$section = new Form_Section('DHCPv6 Options');
610

    
611
if ($dhcrelay_enabled) {
612
	$section->addInput(new Form_Checkbox(
613
		'enable',
614
		'DHCPv6 Server',
615
		gettext("DHCPv6 Relay is currently enabled. DHCPv6 Server canot be enabled while the DHCPv6 Relay is enabled on any interface."),
616
		$pconfig['enable']
617
	))->setAttribute('disabled', true);
618
} else {
619
	$section->addInput(new Form_Checkbox(
620
		'enable',
621
		'DHCPv6 Server',
622
		'Enable DHCPv6 server on interface ' . $iflist[$if],
623
		$pconfig['enable']
624
	));
625
}
626

    
627
if (is_ipaddrv6($ifcfgip)) {
628

    
629
	if ($ifcfgip == "::") {
630
		$sntext = "Prefix Delegation";
631
		if (get_interface_track6ip($if)) {
632
			$track6ip = get_interface_track6ip($if);
633
			$pdsubnet = gen_subnetv6($track6ip[0], $track6ip[1]);
634
			$sntext .= " ({$pdsubnet}/{$track6ip[1]})";
635
		}
636
	} else {
637
		$sntext = gen_subnetv6($ifcfgip, $ifcfgsn);
638
	}
639
	$section->addInput(new Form_StaticText(
640
		'Subnet',
641
		$sntext
642
		));
643

    
644
	$section->addInput(new Form_StaticText(
645
		'Subnet Mask',
646
		$ifcfgsn . ' bits'
647
		));
648

    
649
	$section->addInput(new Form_StaticText(
650
		'Available Range',
651
		$range_from = gen_subnetv6($ifcfgip, $ifcfgsn) . ' to ' . gen_subnetv6_max($ifcfgip, $ifcfgsn)
652
		))->setHelp($trackifname ? 'Prefix Delegation subnet will be appended to the beginning of the defined range':'');
653
}
654

    
655
$f1 = new Form_Input(
656
	'range_from',
657
	null,
658
	'text',
659
	$pconfig['range_from']
660
);
661

    
662
$f1->setHelp('From');
663

    
664
$f2 = new Form_Input(
665
	'range_to',
666
	null,
667
	'text',
668
	$pconfig['range_to']
669
);
670

    
671
$f2->setHelp('To');
672

    
673
$group = new Form_Group('*Range');
674

    
675
$group->add($f1);
676
$group->add($f2);
677

    
678
$section->add($group);
679

    
680
$f1 = new Form_Input(
681
	'prefixrange_from',
682
	null,
683
	'text',
684
	$pconfig['prefixrange_from']
685
);
686

    
687
$f1->setHelp('From');
688

    
689
$f2 = new Form_Input(
690
	'prefixrange_to',
691
	null,
692
	'text',
693
	$pconfig['prefixrange_to']
694
);
695

    
696
$f2->setHelp('To');
697

    
698
$group = new Form_Group('Prefix Delegation Range');
699

    
700
$group->add($f1);
701
$group->add($f2);
702

    
703
$section->add($group);
704

    
705
$section->addInput(new Form_Select(
706
	'prefixrange_length',
707
	'Prefix Delegation Size',
708
	$pconfig['prefixrange_length'],
709
	array(
710
		'48' => '48',
711
		'52' => '52',
712
		'56' => '56',
713
		'59' => '59',
714
		'60' => '60',
715
		'61' => '61',
716
		'62' => '62',
717
		'63' => '63',
718
		'64' => '64'
719
		)
720
))->setHelp('A Prefix range can be defined here for DHCP Prefix Delegation. This allows for assigning networks to subrouters. The start and end of the range must end on boundaries of the prefix delegation size.');
721

    
722
$group = new Form_Group('DNS Servers');
723

    
724
for ($i=1;$i<=4; $i++) {
725
	$group->add(new Form_input(
726
		'dns' . $i,
727
		null,
728
		'text',
729
		$pconfig['dns' . $i],
730
		['placeholder' => 'DNS ' . $i]
731
	));
732
}
733

    
734
$group->setHelp('Leave blank to use the system default DNS servers, this interface\'s IP if DNS forwarder is enabled, or the servers configured on the "General" page.');
735
$section->add($group);
736

    
737
$section->addInput(new Form_Checkbox(
738
	'dhcp6c-dns',
739
	null,
740
	'Provide DNS servers to DHCPv6 clients',
741
	($pconfig['dhcp6c-dns'] == "enabled")
742
))->setHelp('Unchecking this box disables the dhcp6.name-servers option. ' .
743
			'Use with caution, as the resulting behavior may violate RFCs and lead to unintended client behavior.');
744

    
745
$section->addInput(new Form_Input(
746
	'domain',
747
	'Domain name',
748
	'text',
749
	$pconfig['domain']
750
))->setHelp('The default is to use the domain name of this system as the default domain name provided by DHCP. An alternate domain name may be specified here. ');
751

    
752
$section->addInput(new Form_Input(
753
	'domainsearchlist',
754
	'Domain search list',
755
	'text',
756
	$pconfig['domainsearchlist']
757
))->setHelp('The DHCP server can optionally provide a domain search list. Use the semicolon character as separator.');
758

    
759
$section->addInput(new Form_Input(
760
	'deftime',
761
	'Default lease time',
762
	'text',
763
	$pconfig['deftime']
764
))->setHelp('Lease time in seconds. Used for clients that do not ask for a specific expiration time. %1$s' .
765
			'The default is 7200 seconds.', '<br />');
766

    
767
$section->addInput(new Form_Input(
768
	'maxtime',
769
	'Max lease time',
770
	'text',
771
	$pconfig['maxtime']
772
))->setHelp('Maximum lease time for clients that ask for a specific expiration time. %1$s' .
773
			'The default is 86400 seconds.', '<br />');
774

    
775
$section->addInput(new Form_Checkbox(
776
	'dhcpv6leaseinlocaltime',
777
	'Time Format Change',
778
	'Change DHCPv6 display lease time from UTC to local time',
779
	$pconfig['dhcpv6leaseinlocaltime']
780
))->setHelp('By default DHCPv6 leases are displayed in UTC time. ' .
781
			'By checking this box DHCPv6 lease time will be displayed in local time and set to time zone selected. ' .
782
			'This will be used for all DHCPv6 interfaces lease time.');
783

    
784
$btnadv = new Form_Button(
785
	'btnadvdns',
786
	'Display Advanced',
787
	null,
788
	'fa-cog'
789
);
790

    
791
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
792

    
793
$section->addInput(new Form_StaticText(
794
	'Dynamic DNS',
795
	$btnadv
796
));
797

    
798
$section->addInput(new Form_Checkbox(
799
	'ddnsupdate',
800
	'DHCP Registration',
801
	'Enable registration of DHCP client names in DNS.',
802
	$pconfig['ddnsupdate']
803
));
804

    
805
$section->addInput(new Form_Input(
806
	'ddnsdomain',
807
	'DDNS Domain',
808
	'text',
809
	$pconfig['ddnsdomain']
810
))->setHelp('Enter the dynamic DNS domain which will be used to register client names in the DNS server.');
811

    
812
$section->addInput(new Form_Checkbox(
813
	'ddnsforcehostname',
814
	'DDNS Hostnames',
815
	'Force dynamic DNS hostname to be the same as configured hostname for Static Mappings',
816
	$pconfig['ddnsforcehostname']
817
))->setHelp('Default registers host name option supplied by DHCP client.');
818

    
819
$section->addInput(new Form_IpAddress(
820
	'ddnsdomainprimary',
821
	'Primary DDNS address',
822
	$pconfig['ddnsdomainprimary'],
823
	'BOTH'
824
))->setHelp('Enter the primary domain name server IP address for the dynamic domain name.');
825

    
826
$section->addInput(new Form_IpAddress(
827
	'ddnsdomainsecondary',
828
	'Secondary DDNS address',
829
	$pconfig['ddnsdomainsecondary'],
830
	'BOTH'
831
))->setHelp('Enter the secondary domain name server IP address for the dynamic domain name.');
832

    
833
$section->addInput(new Form_Input(
834
	'ddnsdomainkeyname',
835
	'DDNS Domain Key name',
836
	'text',
837
	$pconfig['ddnsdomainkeyname']
838
))->setHelp('Enter the dynamic DNS domain key name which will be used to register client names in the DNS server.');
839

    
840
$section->addInput(new Form_Select(
841
	'ddnsdomainkeyalgorithm',
842
	'Key algorithm',
843
	$pconfig['ddnsdomainkeyalgorithm'],
844
	array(
845
		'hmac-md5' => 'HMAC-MD5 (legacy default)',
846
		'hmac-sha1' => 'HMAC-SHA1',
847
		'hmac-sha224' => 'HMAC-SHA224',
848
		'hmac-sha256' => 'HMAC-SHA256 (current bind9 default)',
849
		'hmac-sha384' => 'HMAC-SHA384',
850
		'hmac-sha512' => 'HMAC-SHA512 (most secure)',
851
	)
852
));
853

    
854
$section->addInput(new Form_Input(
855
	'ddnsdomainkey',
856
	'DDNS Domain Key secret',
857
	'text',
858
	$pconfig['ddnsdomainkey']
859
))->setAttribute('placeholder', 'Base64 encoded string')
860
->setHelp('Enter the dynamic DNS domain key secret which will be used to register client names in the DNS server.');
861

    
862
$section->addInput(new Form_Select(
863
	'ddnsclientupdates',
864
	'DDNS Client Updates',
865
	$pconfig['ddnsclientupdates'],
866
	array(
867
	    'allow' => gettext('Allow'),
868
	    'deny' => gettext('Deny'),
869
	    'ignore' => gettext('Ignore'))
870
))->setHelp('How Forward entries are handled when client indicates they wish to update DNS.  ' .
871
	    'Allow prevents DHCP from updating Forward entries, Deny indicates that DHCP will ' .
872
	    'do the updates and the client should not, Ignore specifies that DHCP will do the ' .
873
	    'update and the client can also attempt the update usually using a different domain name.');
874

    
875
$section->addInput(new Form_Checkbox(
876
	'ddnsreverse',
877
	'DDNS Reverse',
878
	'Add reverse dynamic DNS entries.',
879
	$pconfig['ddnsreverse']
880
));
881

    
882
$btnadv = new Form_Button(
883
	'btnadvntp',
884
	'Display Advanced',
885
	null,
886
	'fa-cog'
887
);
888

    
889
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
890

    
891
$section->addInput(new Form_StaticText(
892
	'NTP servers',
893
	$btnadv
894
));
895

    
896
$group = new Form_Group('NTP Servers');
897

    
898
$group->add(new Form_Input(
899
	'ntp1',
900
	'NTP Server 1',
901
	'text',
902
	$pconfig['ntp1'],
903
	['placeholder' => 'NTP 1']
904
));
905

    
906
$group->add(new Form_Input(
907
	'ntp2',
908
	'NTP Server 2',
909
	'text',
910
	$pconfig['ntp2'],
911
	['placeholder' => 'NTP 2']
912
));
913

    
914
$group->add(new Form_Input(
915
	'ntp3',
916
	'NTP Server 3',
917
	'text',
918
	$pconfig['ntp3'],
919
	['placeholder' => 'NTP 3']
920
));
921

    
922
$group->addClass('ntpclass');
923

    
924
$section->add($group);
925

    
926
$btnadv = new Form_Button(
927
	'btnadvldap',
928
	'Display Advanced',
929
	null,
930
	'fa-cog'
931
);
932

    
933
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
934

    
935
$section->addInput(new Form_StaticText(
936
	'LDAP',
937
	$btnadv
938
));
939

    
940
$section->addInput(new Form_Input(
941
	'ldap',
942
	'LDAP URI',
943
	'text',
944
	$pconfig['ldap']
945
));
946

    
947
$btnadv = new Form_Button(
948
	'btnadvnetboot',
949
	'Display Advanced',
950
	null,
951
	'fa-cog'
952
);
953

    
954
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
955

    
956
$section->addInput(new Form_StaticText(
957
	'Network booting',
958
	$btnadv
959
));
960

    
961
$section->addInput(new Form_Checkbox(
962
	'netboot',
963
	'Network booting',
964
	'Enable Network Booting',
965
	$pconfig['netboot']
966
));
967

    
968
$section->addInput(new Form_Input(
969
	'bootfile_url',
970
	'Bootfile URL',
971
	'text',
972
	$pconfig['bootfile_url']
973
));
974

    
975
$btnadv = new Form_Button(
976
	'btnadvopts',
977
	'Display Advanced',
978
	null,
979
	'fa-cog'
980
);
981

    
982
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
983

    
984
$section->addInput(new Form_StaticText(
985
	'Additional BOOTP/DHCP Options',
986
	$btnadv
987
));
988

    
989
$form->add($section);
990

    
991
$title = 'Show Additional BOOTP/DHCP Options';
992

    
993
if (!$pconfig['numberoptions']) {
994
	$noopts = true;
995
	$pconfig['numberoptions'] = array();
996
	$pconfig['numberoptions']['item'] = array(0 => array('number' => "", 'value' => ""));
997
} else {
998
	$noopts = false;
999
}
1000

    
1001
$counter = 0;
1002
if (!is_array($pconfig['numberoptions'])) {
1003
	$pconfig['numberoptions'] = array();
1004
}
1005
if (!is_array($pconfig['numberoptions']['item'])) {
1006
	$pconfig['numberoptions']['item'] = array();
1007
}
1008
$last = count($pconfig['numberoptions']['item']) - 1;
1009

    
1010
foreach ($pconfig['numberoptions']['item'] as $item) {
1011
	$group = new Form_Group(null);
1012
	$group->addClass('repeatable');
1013
	$group->addClass('adnloptions');
1014

    
1015
	$group->add(new Form_Input(
1016
		'number' . $counter,
1017
		null,
1018
		'text',
1019
		$item['number']
1020
	))->setHelp($counter == $last ? 'Number':null);
1021

    
1022
	$group->add(new Form_Input(
1023
		'value' . $counter,
1024
		null,
1025
		'text',
1026
		base64_decode($item['value'])
1027
	))->setHelp($counter == $last ? 'Value':null);
1028

    
1029
	$btn = new Form_Button(
1030
		'deleterow' . $counter,
1031
		'Delete',
1032
		null,
1033
		'fa-trash'
1034
	);
1035

    
1036
	$btn->addClass('btn-warning');
1037
	$group->add($btn);
1038
	$section->add($group);
1039
	$counter++;
1040
}
1041

    
1042

    
1043
$btnaddopt = new Form_Button(
1044
	'addrow',
1045
	'Add Option',
1046
	null,
1047
	'fa-plus'
1048
);
1049

    
1050
$btnaddopt->removeClass('btn-primary')->addClass('btn-success btn-sm');
1051

    
1052
$section->addInput($btnaddopt);
1053

    
1054
$form->addGlobal(new Form_Input(
1055
	'if',
1056
	null,
1057
	'hidden',
1058
	$if
1059
));
1060

    
1061
print($form);
1062

    
1063
?>
1064
<div class="infoblock blockopen">
1065
<?php
1066
print_info_box(
1067
	sprintf(
1068
		gettext('The DNS servers entered in %1$sSystem: General Setup%3$s (or the %2$sDNS forwarder%3$s if enabled) will be assigned to clients by the DHCP server.'),
1069
		'<a href="system.php">',
1070
		'<a href="services_dnsmasq.php"/>',
1071
		'</a>') .
1072
	'<br />' .
1073
	sprintf(
1074
		gettext('The DHCP lease table can be viewed on the %1$sStatus: DHCPv6 leases%2$s page.'),
1075
		'<a href="status_dhcpv6_leases.php">',
1076
		'</a>'),
1077
	'info',
1078
	false);
1079
?>
1080
</div>
1081
<div class="panel panel-default">
1082
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("DHCPv6 Static Mappings for this Interface");?></h2></div>
1083
	<div class="panel-body table-responsive">
1084
		<table class="table table-striped table-hover table-condensed">
1085
			<thead>
1086
				<tr>
1087
					<th><?=gettext("DUID")?></th>
1088
					<th><?=gettext("IPv6 address")?></th>
1089
					<th><?=gettext("Hostname")?></th>
1090
					<th><?=gettext("Description")?></th>
1091
					<th><!-- Buttons --></th>
1092
				</tr>
1093
			</thead>
1094
			<tbody>
1095
<?php
1096
if (is_array($a_maps)):
1097
	$i = 0;
1098
	foreach ($a_maps as $mapent):
1099
		if ($mapent['duid'] != "" or $mapent['ipaddrv6'] != ""):
1100
?>
1101
				<tr>
1102
					<td>
1103
						<?=htmlspecialchars($mapent['duid'])?>
1104
					</td>
1105
					<td>
1106
						<?=htmlspecialchars($mapent['ipaddrv6'])?>
1107
					</td>
1108
					<td>
1109
						<?=htmlspecialchars($mapent['hostname'])?>
1110
					</td>
1111
					<td>
1112
						<?=htmlspecialchars($mapent['descr'])?>
1113
					</td>
1114
					<td>
1115
						<a class="fa fa-pencil"	title="<?=gettext('Edit static mapping')?>" href="services_dhcpv6_edit.php?if=<?=$if?>&amp;id=<?=$i?>"></a>
1116
						<a class="fa fa-trash"	title="<?=gettext('Delete static mapping')?>" href="services_dhcpv6.php?if=<?=$if?>&amp;act=del&amp;id=<?=$i?>" usepost></a>
1117
					</td>
1118
				</tr>
1119
<?php
1120
		endif;
1121
	$i++;
1122
	endforeach;
1123
endif;
1124
?>
1125
			</tbody>
1126
		</table>
1127
	</div>
1128
</div>
1129

    
1130
<nav class="action-buttons">
1131
	<a href="services_dhcpv6_edit.php?if=<?=$if?>" class="btn btn-sm btn-success"/>
1132
		<i class="fa fa-plus icon-embed-btn"></i>
1133
		<?=gettext("Add")?>
1134
	</a>
1135
</nav>
1136

    
1137
<script type="text/javascript">
1138
//<![CDATA[
1139
events.push(function() {
1140

    
1141
	// Show advanced DNS options ======================================================================================
1142
	var showadvdns = false;
1143

    
1144
	function show_advdns(ispageload) {
1145
		var text;
1146
		// On page load decide the initial state based on the data.
1147
		if (ispageload) {
1148
<?php
1149
			if (!$pconfig['ddnsupdate'] &&
1150
			    !$pconfig['ddnsforcehostname'] &&
1151
			    empty($pconfig['ddnsdomain']) &&
1152
			    empty($pconfig['ddnsdomainprimary']) &&
1153
			    empty($pconfig['ddnsdomainsecondary']) &&
1154
			    empty($pconfig['ddnsdomainkeyname']) &&
1155
			    (empty($pconfig['ddnsdomainkeyalgorithm'])  || ($pconfig['ddnsdomainkeyalgorithm'] == "hmac-md5")) &&
1156
			    empty($pconfig['ddnsdomainkey']) &&
1157
			    (empty($pconfig['ddnsclientupdates']) || ($pconfig['ddnsclientupdates'] == "allow")) &&
1158
			    !$pconfig['ddnsreverse']) {
1159
				$showadv = false;
1160
			} else {
1161
				$showadv = true;
1162
			}
1163
?>
1164
			showadvdns = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1165
		} else {
1166
			// It was a click, swap the state.
1167
			showadvdns = !showadvdns;
1168
		}
1169

    
1170
		hideCheckbox('ddnsupdate', !showadvdns);
1171
		hideInput('ddnsdomain', !showadvdns);
1172
		hideCheckbox('ddnsforcehostname', !showadvdns);
1173
		hideInput('ddnsdomainprimary', !showadvdns);
1174
		hideInput('ddnsdomainsecondary', !showadvdns);
1175
		hideInput('ddnsdomainkeyname', !showadvdns);
1176
		hideInput('ddnsdomainkeyalgorithm', !showadvdns);
1177
		hideInput('ddnsdomainkey', !showadvdns);
1178
		hideInput('ddnsclientupdates', !showadvdns);
1179
		hideCheckbox('ddnsreverse', !showadvdns);
1180

    
1181
		if (showadvdns) {
1182
			text = "<?=gettext('Hide Advanced');?>";
1183
		} else {
1184
			text = "<?=gettext('Display Advanced');?>";
1185
		}
1186
		$('#btnadvdns').html('<i class="fa fa-cog"></i> ' + text);
1187
	}
1188

    
1189
	$('#btnadvdns').click(function(event) {
1190
		show_advdns();
1191
	});
1192

    
1193
	// Show advanced NTP options ======================================================================================
1194
	var showadvntp = false;
1195

    
1196
	function show_advntp(ispageload) {
1197
		var text;
1198
		// On page load decide the initial state based on the data.
1199
		if (ispageload) {
1200
<?php
1201
			if (empty($pconfig['ntp1']) && empty($pconfig['ntp2']) && empty($pconfig['ntp3'])) {
1202
				$showadv = false;
1203
			} else {
1204
				$showadv = true;
1205
			}
1206
?>
1207
			showadvntp = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1208
		} else {
1209
			// It was a click, swap the state.
1210
			showadvntp = !showadvntp;
1211
		}
1212

    
1213
		hideInput('ntp1', !showadvntp);
1214
		hideInput('ntp2', !showadvntp);
1215
		hideInput('ntp3', !showadvntp);
1216

    
1217
		if (showadvntp) {
1218
			text = "<?=gettext('Hide Advanced');?>";
1219
		} else {
1220
			text = "<?=gettext('Display Advanced');?>";
1221
		}
1222
		$('#btnadvntp').html('<i class="fa fa-cog"></i> ' + text);
1223
	}
1224

    
1225
	$('#btnadvntp').click(function(event) {
1226
		show_advntp();
1227
	});
1228

    
1229
	// Show advanced LDAP options ======================================================================================
1230
	var showadvldap = false;
1231

    
1232
	function show_advldap(ispageload) {
1233
		var text;
1234
		// On page load decide the initial state based on the data.
1235
		if (ispageload) {
1236
<?php
1237
			if (empty($pconfig['ldap'])) {
1238
				$showadv = false;
1239
			} else {
1240
				$showadv = true;
1241
			}
1242
?>
1243
			showadvldap = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1244
		} else {
1245
			// It was a click, swap the state.
1246
			showadvldap = !showadvldap;
1247
		}
1248

    
1249
		hideInput('ldap', !showadvldap);
1250

    
1251
		if (showadvldap) {
1252
			text = "<?=gettext('Hide Advanced');?>";
1253
		} else {
1254
			text = "<?=gettext('Display Advanced');?>";
1255
		}
1256
		$('#btnadvldap').html('<i class="fa fa-cog"></i> ' + text);
1257
	}
1258

    
1259
	$('#btnadvldap').click(function(event) {
1260
		show_advldap();
1261
	});
1262

    
1263
	// Show advanced Netboot options ======================================================================================
1264
	var showadvnetboot = false;
1265

    
1266
	function show_advnetboot(ispageload) {
1267
		var text;
1268
		// On page load decide the initial state based on the data.
1269
		if (ispageload) {
1270
<?php
1271
			if (!$pconfig['netboot'] && empty($pconfig['bootfile_url'])) {
1272
				$showadv = false;
1273
			} else {
1274
				$showadv = true;
1275
			}
1276
?>
1277
			showadvnetboot = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1278
		} else {
1279
			// It was a click, swap the state.
1280
			showadvnetboot = !showadvnetboot;
1281
		}
1282

    
1283
		hideCheckbox('netboot', !showadvnetboot);
1284
		hideInput('bootfile_url', !showadvnetboot);
1285

    
1286
		if (showadvnetboot) {
1287
			text = "<?=gettext('Hide Advanced');?>";
1288
		} else {
1289
			text = "<?=gettext('Display Advanced');?>";
1290
		}
1291
		$('#btnadvnetboot').html('<i class="fa fa-cog"></i> ' + text);
1292
	}
1293

    
1294
	$('#btnadvnetboot').click(function(event) {
1295
		show_advnetboot();
1296
	});
1297

    
1298
	// Show advanced additional opts options ===========================================================================
1299
	var showadvopts = false;
1300

    
1301
	function show_advopts(ispageload) {
1302
		var text;
1303
		// On page load decide the initial state based on the data.
1304
		if (ispageload) {
1305
<?php
1306
			if (empty($pconfig['numberoptions']) ||
1307
			    (empty($pconfig['numberoptions']['item'][0]['number']) && (empty($pconfig['numberoptions']['item'][0]['value'])))) {
1308
				$showadv = false;
1309
			} else {
1310
				$showadv = true;
1311
			}
1312
?>
1313
			showadvopts = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1314
		} else {
1315
			// It was a click, swap the state.
1316
			showadvopts = !showadvopts;
1317
		}
1318

    
1319
		hideClass('adnloptions', !showadvopts);
1320
		hideInput('addrow', !showadvopts);
1321

    
1322
		if (showadvopts) {
1323
			text = "<?=gettext('Hide Advanced');?>";
1324
		} else {
1325
			text = "<?=gettext('Display Advanced');?>";
1326
		}
1327
		$('#btnadvopts').html('<i class="fa fa-cog"></i> ' + text);
1328
	}
1329

    
1330
	$('#btnadvopts').click(function(event) {
1331
		show_advopts();
1332
		checkLastRow();
1333
	});
1334

    
1335
	// On initial load
1336
	show_advdns(true);
1337
	show_advntp(true);
1338
	show_advldap(true);
1339
	show_advnetboot(true);
1340
	show_advopts(true);
1341
	if ($('#enable').prop('checked')) {
1342
		hideClass('adnloptions', <?php echo json_encode($noopts); ?>);
1343
		hideInput('addrow', <?php echo json_encode($noopts); ?>);
1344
	} else {
1345
		hideClass('adnloptions', true);
1346
		hideInput('addrow', true);
1347
	}
1348

    
1349
});
1350
//]]>
1351
</script>
1352

    
1353
<?php include('foot.inc');
(124-124/230)