Project

General

Profile

Download (40.1 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-2022 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
if ($tabscounter == 0) {
575
	print_info_box(gettext("The DHCPv6 Server can only be enabled on interfaces configured with a static IPv6 address. This system has none."), 'danger');
576
	include("foot.inc");
577
	exit;
578
}
579

    
580
display_top_tabs($tab_array);
581

    
582
$tab_array = array();
583
$tab_array[] = array(gettext("DHCPv6 Server"),		 true,	"services_dhcpv6.php?if={$if}");
584
$tab_array[] = array(gettext("Router Advertisements"), false, "services_router_advertisements.php?if={$if}");
585
display_top_tabs($tab_array, false, 'nav nav-tabs');
586

    
587
$form = new Form();
588

    
589
$section = new Form_Section('DHCPv6 Options');
590

    
591
if ($dhcrelay_enabled) {
592
	$section->addInput(new Form_Checkbox(
593
		'enable',
594
		'DHCPv6 Server',
595
		gettext("DHCPv6 Relay is currently enabled. DHCPv6 Server canot be enabled while the DHCPv6 Relay is enabled on any interface."),
596
		$pconfig['enable']
597
	))->setAttribute('disabled', true);
598
} else {
599
	$section->addInput(new Form_Checkbox(
600
		'enable',
601
		'DHCPv6 Server',
602
		'Enable DHCPv6 server on interface ' . $iflist[$if],
603
		$pconfig['enable']
604
	));
605
}
606

    
607
if (is_ipaddrv6($ifcfgip)) {
608

    
609
	if ($ifcfgip == "::") {
610
		$sntext = "Prefix Delegation";
611
		if (get_interface_track6ip($if)) {
612
			$track6ip = get_interface_track6ip($if);
613
			$pdsubnet = gen_subnetv6($track6ip[0], $track6ip[1]);
614
			$sntext .= " ({$pdsubnet}/{$track6ip[1]})";
615
		}
616
	} else {
617
		$sntext = gen_subnetv6($ifcfgip, $ifcfgsn);
618
	}
619
	$section->addInput(new Form_StaticText(
620
		'Subnet',
621
		$sntext
622
		));
623

    
624
	$section->addInput(new Form_StaticText(
625
		'Subnet Mask',
626
		$ifcfgsn . ' bits'
627
		));
628

    
629
	$section->addInput(new Form_StaticText(
630
		'Available Range',
631
		$range_from = gen_subnetv6($ifcfgip, $ifcfgsn) . ' to ' . gen_subnetv6_max($ifcfgip, $ifcfgsn)
632
		))->setHelp($trackifname ? 'Prefix Delegation subnet will be appended to the beginning of the defined range':'');
633
}
634

    
635
$f1 = new Form_Input(
636
	'range_from',
637
	null,
638
	'text',
639
	$pconfig['range_from']
640
);
641

    
642
$f1->setHelp('From');
643

    
644
$f2 = new Form_Input(
645
	'range_to',
646
	null,
647
	'text',
648
	$pconfig['range_to']
649
);
650

    
651
$f2->setHelp('To');
652

    
653
$group = new Form_Group('*Range');
654

    
655
$group->add($f1);
656
$group->add($f2);
657

    
658
$section->add($group);
659

    
660
$f1 = new Form_Input(
661
	'prefixrange_from',
662
	null,
663
	'text',
664
	$pconfig['prefixrange_from']
665
);
666

    
667
$f1->setHelp('From');
668

    
669
$f2 = new Form_Input(
670
	'prefixrange_to',
671
	null,
672
	'text',
673
	$pconfig['prefixrange_to']
674
);
675

    
676
$f2->setHelp('To');
677

    
678
$group = new Form_Group('Prefix Delegation Range');
679

    
680
$group->add($f1);
681
$group->add($f2);
682

    
683
$section->add($group);
684

    
685
$section->addInput(new Form_Select(
686
	'prefixrange_length',
687
	'Prefix Delegation Size',
688
	$pconfig['prefixrange_length'],
689
	array(
690
		'48' => '48',
691
		'52' => '52',
692
		'56' => '56',
693
		'59' => '59',
694
		'60' => '60',
695
		'61' => '61',
696
		'62' => '62',
697
		'63' => '63',
698
		'64' => '64'
699
		)
700
))->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.');
701

    
702
$group = new Form_Group('DNS Servers');
703

    
704
for ($i=1;$i<=4; $i++) {
705
	$group->add(new Form_input(
706
		'dns' . $i,
707
		null,
708
		'text',
709
		$pconfig['dns' . $i],
710
		['placeholder' => 'DNS ' . $i]
711
	));
712
}
713

    
714
$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.');
715
$section->add($group);
716

    
717
$section->addInput(new Form_Checkbox(
718
	'dhcp6c-dns',
719
	null,
720
	'Provide DNS servers to DHCPv6 clients',
721
	($pconfig['dhcp6c-dns'] == "enabled")
722
))->setHelp('Unchecking this box disables the dhcp6.name-servers option. ' .
723
			'Use with caution, as the resulting behavior may violate RFCs and lead to unintended client behavior.');
724

    
725
$section->addInput(new Form_Input(
726
	'domain',
727
	'Domain name',
728
	'text',
729
	$pconfig['domain']
730
))->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. ');
731

    
732
$section->addInput(new Form_Input(
733
	'domainsearchlist',
734
	'Domain search list',
735
	'text',
736
	$pconfig['domainsearchlist']
737
))->setHelp('The DHCP server can optionally provide a domain search list. Use the semicolon character as separator.');
738

    
739
$section->addInput(new Form_Input(
740
	'deftime',
741
	'Default lease time',
742
	'text',
743
	$pconfig['deftime']
744
))->setHelp('Lease time in seconds. Used for clients that do not ask for a specific expiration time. %1$s' .
745
			'The default is 7200 seconds.', '<br />');
746

    
747
$section->addInput(new Form_Input(
748
	'maxtime',
749
	'Max lease time',
750
	'text',
751
	$pconfig['maxtime']
752
))->setHelp('Maximum lease time for clients that ask for a specific expiration time. %1$s' .
753
			'The default is 86400 seconds.', '<br />');
754

    
755
$section->addInput(new Form_Checkbox(
756
	'dhcpv6leaseinlocaltime',
757
	'Time Format Change',
758
	'Change DHCPv6 display lease time from UTC to local time',
759
	$pconfig['dhcpv6leaseinlocaltime']
760
))->setHelp('By default DHCPv6 leases are displayed in UTC time. ' .
761
			'By checking this box DHCPv6 lease time will be displayed in local time and set to time zone selected. ' .
762
			'This will be used for all DHCPv6 interfaces lease time.');
763

    
764
$btnadv = new Form_Button(
765
	'btnadvdns',
766
	'Display Advanced',
767
	null,
768
	'fa-cog'
769
);
770

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

    
773
$section->addInput(new Form_StaticText(
774
	'Dynamic DNS',
775
	$btnadv
776
));
777

    
778
$section->addInput(new Form_Checkbox(
779
	'ddnsupdate',
780
	'DHCP Registration',
781
	'Enable registration of DHCP client names in DNS.',
782
	$pconfig['ddnsupdate']
783
));
784

    
785
$section->addInput(new Form_Input(
786
	'ddnsdomain',
787
	'DDNS Domain',
788
	'text',
789
	$pconfig['ddnsdomain']
790
))->setHelp('Enter the dynamic DNS domain which will be used to register client names in the DNS server.');
791

    
792
$section->addInput(new Form_Checkbox(
793
	'ddnsforcehostname',
794
	'DDNS Hostnames',
795
	'Force dynamic DNS hostname to be the same as configured hostname for Static Mappings',
796
	$pconfig['ddnsforcehostname']
797
))->setHelp('Default registers host name option supplied by DHCP client.');
798

    
799
$section->addInput(new Form_IpAddress(
800
	'ddnsdomainprimary',
801
	'Primary DDNS address',
802
	$pconfig['ddnsdomainprimary'],
803
	'BOTH'
804
))->setHelp('Enter the primary domain name server IP address for the dynamic domain name.');
805

    
806
$section->addInput(new Form_IpAddress(
807
	'ddnsdomainsecondary',
808
	'Secondary DDNS address',
809
	$pconfig['ddnsdomainsecondary'],
810
	'BOTH'
811
))->setHelp('Enter the secondary domain name server IP address for the dynamic domain name.');
812

    
813
$section->addInput(new Form_Input(
814
	'ddnsdomainkeyname',
815
	'DDNS Domain Key name',
816
	'text',
817
	$pconfig['ddnsdomainkeyname']
818
))->setHelp('Enter the dynamic DNS domain key name which will be used to register client names in the DNS server.');
819

    
820
$section->addInput(new Form_Select(
821
	'ddnsdomainkeyalgorithm',
822
	'Key algorithm',
823
	$pconfig['ddnsdomainkeyalgorithm'],
824
	array(
825
		'hmac-md5' => 'HMAC-MD5 (legacy default)',
826
		'hmac-sha1' => 'HMAC-SHA1',
827
		'hmac-sha224' => 'HMAC-SHA224',
828
		'hmac-sha256' => 'HMAC-SHA256 (current bind9 default)',
829
		'hmac-sha384' => 'HMAC-SHA384',
830
		'hmac-sha512' => 'HMAC-SHA512 (most secure)',
831
	)
832
));
833

    
834
$section->addInput(new Form_Input(
835
	'ddnsdomainkey',
836
	'DDNS Domain Key secret',
837
	'text',
838
	$pconfig['ddnsdomainkey']
839
))->setAttribute('placeholder', 'Base64 encoded string')
840
->setHelp('Enter the dynamic DNS domain key secret which will be used to register client names in the DNS server.');
841

    
842
$section->addInput(new Form_Select(
843
	'ddnsclientupdates',
844
	'DDNS Client Updates',
845
	$pconfig['ddnsclientupdates'],
846
	array(
847
	    'allow' => gettext('Allow'),
848
	    'deny' => gettext('Deny'),
849
	    'ignore' => gettext('Ignore'))
850
))->setHelp('How Forward entries are handled when client indicates they wish to update DNS.  ' .
851
	    'Allow prevents DHCP from updating Forward entries, Deny indicates that DHCP will ' .
852
	    'do the updates and the client should not, Ignore specifies that DHCP will do the ' .
853
	    'update and the client can also attempt the update usually using a different domain name.');
854

    
855
$section->addInput(new Form_Checkbox(
856
	'ddnsreverse',
857
	'DDNS Reverse',
858
	'Add reverse dynamic DNS entries.',
859
	$pconfig['ddnsreverse']
860
));
861

    
862
$btnadv = new Form_Button(
863
	'btnadvntp',
864
	'Display Advanced',
865
	null,
866
	'fa-cog'
867
);
868

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

    
871
$section->addInput(new Form_StaticText(
872
	'NTP servers',
873
	$btnadv
874
));
875

    
876
$group = new Form_Group('NTP Servers');
877

    
878
$group->add(new Form_Input(
879
	'ntp1',
880
	'NTP Server 1',
881
	'text',
882
	$pconfig['ntp1'],
883
	['placeholder' => 'NTP 1']
884
));
885

    
886
$group->add(new Form_Input(
887
	'ntp2',
888
	'NTP Server 2',
889
	'text',
890
	$pconfig['ntp2'],
891
	['placeholder' => 'NTP 2']
892
));
893

    
894
$group->add(new Form_Input(
895
	'ntp3',
896
	'NTP Server 3',
897
	'text',
898
	$pconfig['ntp3'],
899
	['placeholder' => 'NTP 3']
900
));
901

    
902
$group->addClass('ntpclass');
903

    
904
$section->add($group);
905

    
906
$btnadv = new Form_Button(
907
	'btnadvldap',
908
	'Display Advanced',
909
	null,
910
	'fa-cog'
911
);
912

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

    
915
$section->addInput(new Form_StaticText(
916
	'LDAP',
917
	$btnadv
918
));
919

    
920
$section->addInput(new Form_Input(
921
	'ldap',
922
	'LDAP URI',
923
	'text',
924
	$pconfig['ldap']
925
));
926

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

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

    
936
$section->addInput(new Form_StaticText(
937
	'Network booting',
938
	$btnadv
939
));
940

    
941
$section->addInput(new Form_Checkbox(
942
	'netboot',
943
	'Network booting',
944
	'Enable Network Booting',
945
	$pconfig['netboot']
946
));
947

    
948
$section->addInput(new Form_Input(
949
	'bootfile_url',
950
	'Bootfile URL',
951
	'text',
952
	$pconfig['bootfile_url']
953
));
954

    
955
$btnadv = new Form_Button(
956
	'btnadvopts',
957
	'Display Advanced',
958
	null,
959
	'fa-cog'
960
);
961

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

    
964
$section->addInput(new Form_StaticText(
965
	'Additional BOOTP/DHCP Options',
966
	$btnadv
967
));
968

    
969
$form->add($section);
970

    
971
$title = 'Show Additional BOOTP/DHCP Options';
972

    
973
if (!$pconfig['numberoptions']) {
974
	$noopts = true;
975
	$pconfig['numberoptions'] = array();
976
	$pconfig['numberoptions']['item'] = array(0 => array('number' => "", 'value' => ""));
977
} else {
978
	$noopts = false;
979
}
980

    
981
$counter = 0;
982
if (!is_array($pconfig['numberoptions'])) {
983
	$pconfig['numberoptions'] = array();
984
}
985
if (!is_array($pconfig['numberoptions']['item'])) {
986
	$pconfig['numberoptions']['item'] = array();
987
}
988
$last = count($pconfig['numberoptions']['item']) - 1;
989

    
990
foreach ($pconfig['numberoptions']['item'] as $item) {
991
	$group = new Form_Group(null);
992
	$group->addClass('repeatable');
993
	$group->addClass('adnloptions');
994

    
995
	$group->add(new Form_Input(
996
		'number' . $counter,
997
		null,
998
		'text',
999
		$item['number']
1000
	))->setHelp($counter == $last ? 'Number':null);
1001

    
1002
	$group->add(new Form_Input(
1003
		'value' . $counter,
1004
		null,
1005
		'text',
1006
		base64_decode($item['value'])
1007
	))->setHelp($counter == $last ? 'Value':null);
1008

    
1009
	$btn = new Form_Button(
1010
		'deleterow' . $counter,
1011
		'Delete',
1012
		null,
1013
		'fa-trash'
1014
	);
1015

    
1016
	$btn->addClass('btn-warning');
1017
	$group->add($btn);
1018
	$section->add($group);
1019
	$counter++;
1020
}
1021

    
1022

    
1023
$btnaddopt = new Form_Button(
1024
	'addrow',
1025
	'Add Option',
1026
	null,
1027
	'fa-plus'
1028
);
1029

    
1030
$btnaddopt->removeClass('btn-primary')->addClass('btn-success btn-sm');
1031

    
1032
$section->addInput($btnaddopt);
1033

    
1034
$form->addGlobal(new Form_Input(
1035
	'if',
1036
	null,
1037
	'hidden',
1038
	$if
1039
));
1040

    
1041
print($form);
1042

    
1043
?>
1044
<div class="infoblock blockopen">
1045
<?php
1046
print_info_box(
1047
	sprintf(
1048
		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.'),
1049
		'<a href="system.php">',
1050
		'<a href="services_dnsmasq.php"/>',
1051
		'</a>') .
1052
	'<br />' .
1053
	sprintf(
1054
		gettext('The DHCP lease table can be viewed on the %1$sStatus: DHCPv6 leases%2$s page.'),
1055
		'<a href="status_dhcpv6_leases.php">',
1056
		'</a>'),
1057
	'info',
1058
	false);
1059
?>
1060
</div>
1061
<div class="panel panel-default">
1062
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("DHCPv6 Static Mappings for this Interface");?></h2></div>
1063
	<div class="panel-body table-responsive">
1064
		<table class="table table-striped table-hover table-condensed">
1065
			<thead>
1066
				<tr>
1067
					<th><?=gettext("DUID")?></th>
1068
					<th><?=gettext("IPv6 address")?></th>
1069
					<th><?=gettext("Hostname")?></th>
1070
					<th><?=gettext("Description")?></th>
1071
					<th><!-- Buttons --></th>
1072
				</tr>
1073
			</thead>
1074
			<tbody>
1075
<?php
1076
if (is_array($a_maps)):
1077
	$i = 0;
1078
	foreach ($a_maps as $mapent):
1079
		if ($mapent['duid'] != "" or $mapent['ipaddrv6'] != ""):
1080
?>
1081
				<tr>
1082
					<td>
1083
						<?=htmlspecialchars($mapent['duid'])?>
1084
					</td>
1085
					<td>
1086
						<?=htmlspecialchars($mapent['ipaddrv6'])?>
1087
					</td>
1088
					<td>
1089
						<?=htmlspecialchars($mapent['hostname'])?>
1090
					</td>
1091
					<td>
1092
						<?=htmlspecialchars($mapent['descr'])?>
1093
					</td>
1094
					<td>
1095
						<a class="fa fa-pencil"	title="<?=gettext('Edit static mapping')?>" href="services_dhcpv6_edit.php?if=<?=$if?>&amp;id=<?=$i?>"></a>
1096
						<a class="fa fa-trash"	title="<?=gettext('Delete static mapping')?>" href="services_dhcpv6.php?if=<?=$if?>&amp;act=del&amp;id=<?=$i?>" usepost></a>
1097
					</td>
1098
				</tr>
1099
<?php
1100
		endif;
1101
	$i++;
1102
	endforeach;
1103
endif;
1104
?>
1105
			</tbody>
1106
		</table>
1107
	</div>
1108
</div>
1109

    
1110
<nav class="action-buttons">
1111
	<a href="services_dhcpv6_edit.php?if=<?=$if?>" class="btn btn-sm btn-success"/>
1112
		<i class="fa fa-plus icon-embed-btn"></i>
1113
		<?=gettext("Add")?>
1114
	</a>
1115
</nav>
1116

    
1117
<script type="text/javascript">
1118
//<![CDATA[
1119
events.push(function() {
1120

    
1121
	// Show advanced DNS options ======================================================================================
1122
	var showadvdns = false;
1123

    
1124
	function show_advdns(ispageload) {
1125
		var text;
1126
		// On page load decide the initial state based on the data.
1127
		if (ispageload) {
1128
<?php
1129
			if (!$pconfig['ddnsupdate'] &&
1130
			    !$pconfig['ddnsforcehostname'] &&
1131
			    empty($pconfig['ddnsdomain']) &&
1132
			    empty($pconfig['ddnsdomainprimary']) &&
1133
			    empty($pconfig['ddnsdomainsecondary']) &&
1134
			    empty($pconfig['ddnsdomainkeyname']) &&
1135
			    (empty($pconfig['ddnsdomainkeyalgorithm'])  || ($pconfig['ddnsdomainkeyalgorithm'] == "hmac-md5")) &&
1136
			    empty($pconfig['ddnsdomainkey']) &&
1137
			    (empty($pconfig['ddnsclientupdates']) || ($pconfig['ddnsclientupdates'] == "allow")) &&
1138
			    !$pconfig['ddnsreverse']) {
1139
				$showadv = false;
1140
			} else {
1141
				$showadv = true;
1142
			}
1143
?>
1144
			showadvdns = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1145
		} else {
1146
			// It was a click, swap the state.
1147
			showadvdns = !showadvdns;
1148
		}
1149

    
1150
		hideCheckbox('ddnsupdate', !showadvdns);
1151
		hideInput('ddnsdomain', !showadvdns);
1152
		hideCheckbox('ddnsforcehostname', !showadvdns);
1153
		hideInput('ddnsdomainprimary', !showadvdns);
1154
		hideInput('ddnsdomainsecondary', !showadvdns);
1155
		hideInput('ddnsdomainkeyname', !showadvdns);
1156
		hideInput('ddnsdomainkeyalgorithm', !showadvdns);
1157
		hideInput('ddnsdomainkey', !showadvdns);
1158
		hideInput('ddnsclientupdates', !showadvdns);
1159
		hideCheckbox('ddnsreverse', !showadvdns);
1160

    
1161
		if (showadvdns) {
1162
			text = "<?=gettext('Hide Advanced');?>";
1163
		} else {
1164
			text = "<?=gettext('Display Advanced');?>";
1165
		}
1166
		$('#btnadvdns').html('<i class="fa fa-cog"></i> ' + text);
1167
	}
1168

    
1169
	$('#btnadvdns').click(function(event) {
1170
		show_advdns();
1171
	});
1172

    
1173
	// Show advanced NTP options ======================================================================================
1174
	var showadvntp = false;
1175

    
1176
	function show_advntp(ispageload) {
1177
		var text;
1178
		// On page load decide the initial state based on the data.
1179
		if (ispageload) {
1180
<?php
1181
			if (empty($pconfig['ntp1']) && empty($pconfig['ntp2']) && empty($pconfig['ntp3'])) {
1182
				$showadv = false;
1183
			} else {
1184
				$showadv = true;
1185
			}
1186
?>
1187
			showadvntp = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1188
		} else {
1189
			// It was a click, swap the state.
1190
			showadvntp = !showadvntp;
1191
		}
1192

    
1193
		hideInput('ntp1', !showadvntp);
1194
		hideInput('ntp2', !showadvntp);
1195
		hideInput('ntp3', !showadvntp);
1196

    
1197
		if (showadvntp) {
1198
			text = "<?=gettext('Hide Advanced');?>";
1199
		} else {
1200
			text = "<?=gettext('Display Advanced');?>";
1201
		}
1202
		$('#btnadvntp').html('<i class="fa fa-cog"></i> ' + text);
1203
	}
1204

    
1205
	$('#btnadvntp').click(function(event) {
1206
		show_advntp();
1207
	});
1208

    
1209
	// Show advanced LDAP options ======================================================================================
1210
	var showadvldap = false;
1211

    
1212
	function show_advldap(ispageload) {
1213
		var text;
1214
		// On page load decide the initial state based on the data.
1215
		if (ispageload) {
1216
<?php
1217
			if (empty($pconfig['ldap'])) {
1218
				$showadv = false;
1219
			} else {
1220
				$showadv = true;
1221
			}
1222
?>
1223
			showadvldap = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1224
		} else {
1225
			// It was a click, swap the state.
1226
			showadvldap = !showadvldap;
1227
		}
1228

    
1229
		hideInput('ldap', !showadvldap);
1230

    
1231
		if (showadvldap) {
1232
			text = "<?=gettext('Hide Advanced');?>";
1233
		} else {
1234
			text = "<?=gettext('Display Advanced');?>";
1235
		}
1236
		$('#btnadvldap').html('<i class="fa fa-cog"></i> ' + text);
1237
	}
1238

    
1239
	$('#btnadvldap').click(function(event) {
1240
		show_advldap();
1241
	});
1242

    
1243
	// Show advanced Netboot options ======================================================================================
1244
	var showadvnetboot = false;
1245

    
1246
	function show_advnetboot(ispageload) {
1247
		var text;
1248
		// On page load decide the initial state based on the data.
1249
		if (ispageload) {
1250
<?php
1251
			if (!$pconfig['netboot'] && empty($pconfig['bootfile_url'])) {
1252
				$showadv = false;
1253
			} else {
1254
				$showadv = true;
1255
			}
1256
?>
1257
			showadvnetboot = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1258
		} else {
1259
			// It was a click, swap the state.
1260
			showadvnetboot = !showadvnetboot;
1261
		}
1262

    
1263
		hideCheckbox('netboot', !showadvnetboot);
1264
		hideInput('bootfile_url', !showadvnetboot);
1265

    
1266
		if (showadvnetboot) {
1267
			text = "<?=gettext('Hide Advanced');?>";
1268
		} else {
1269
			text = "<?=gettext('Display Advanced');?>";
1270
		}
1271
		$('#btnadvnetboot').html('<i class="fa fa-cog"></i> ' + text);
1272
	}
1273

    
1274
	$('#btnadvnetboot').click(function(event) {
1275
		show_advnetboot();
1276
	});
1277

    
1278
	// Show advanced additional opts options ===========================================================================
1279
	var showadvopts = false;
1280

    
1281
	function show_advopts(ispageload) {
1282
		var text;
1283
		// On page load decide the initial state based on the data.
1284
		if (ispageload) {
1285
<?php
1286
			if (empty($pconfig['numberoptions']) ||
1287
			    (empty($pconfig['numberoptions']['item'][0]['number']) && (empty($pconfig['numberoptions']['item'][0]['value'])))) {
1288
				$showadv = false;
1289
			} else {
1290
				$showadv = true;
1291
			}
1292
?>
1293
			showadvopts = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1294
		} else {
1295
			// It was a click, swap the state.
1296
			showadvopts = !showadvopts;
1297
		}
1298

    
1299
		hideClass('adnloptions', !showadvopts);
1300
		hideInput('addrow', !showadvopts);
1301

    
1302
		if (showadvopts) {
1303
			text = "<?=gettext('Hide Advanced');?>";
1304
		} else {
1305
			text = "<?=gettext('Display Advanced');?>";
1306
		}
1307
		$('#btnadvopts').html('<i class="fa fa-cog"></i> ' + text);
1308
	}
1309

    
1310
	$('#btnadvopts').click(function(event) {
1311
		show_advopts();
1312
		checkLastRow();
1313
	});
1314

    
1315
	// On initial load
1316
	show_advdns(true);
1317
	show_advntp(true);
1318
	show_advldap(true);
1319
	show_advnetboot(true);
1320
	show_advopts(true);
1321
	if ($('#enable').prop('checked')) {
1322
		hideClass('adnloptions', <?php echo json_encode($noopts); ?>);
1323
		hideInput('addrow', <?php echo json_encode($noopts); ?>);
1324
	} else {
1325
		hideClass('adnloptions', true);
1326
		hideInput('addrow', true);
1327
	}
1328

    
1329
});
1330
//]]>
1331
</script>
1332

    
1333
<?php include('foot.inc');
(121-121/228)