Project

General

Profile

Download (37.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	services_dhcpv6.php
4
*/
5
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *	Copyright (c)  2010 Seth Mos <seth.mos@dds.nl>
8
 *
9
 *	Some or all of this file is based on the m0n0wall project which is
10
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
11
 *
12
 *	Redistribution and use in source and binary forms, with or without modification,
13
 *	are permitted provided that the following conditions are met:
14
 *
15
 *	1. Redistributions of source code must retain the above copyright notice,
16
 *		this list of conditions and the following disclaimer.
17
 *
18
 *	2. Redistributions in binary form must reproduce the above copyright
19
 *		notice, this list of conditions and the following disclaimer in
20
 *		the documentation and/or other materials provided with the
21
 *		distribution.
22
 *
23
 *	3. All advertising materials mentioning features or use of this software
24
 *		must display the following acknowledgment:
25
 *		"This product includes software developed by the pfSense Project
26
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
27
 *
28
 *	4. The names "pfSense" and "pfSense Project" must not be used to
29
 *		 endorse or promote products derived from this software without
30
 *		 prior written permission. For written permission, please contact
31
 *		 coreteam@pfsense.org.
32
 *
33
 *	5. Products derived from this software may not be called "pfSense"
34
 *		nor may "pfSense" appear in their names without prior written
35
 *		permission of the Electric Sheep Fencing, LLC.
36
 *
37
 *	6. Redistributions of any form whatsoever must retain the following
38
 *		acknowledgment:
39
 *
40
 *	"This product includes software developed by the pfSense Project
41
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
42
 *
43
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
44
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
46
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
47
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
54
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
55
 *
56
 *	====================================================================
57
 *
58
 */
59

    
60
##|+PRIV
61
##|*IDENT=page-services-dhcpv6server
62
##|*NAME=Services: DHCPv6 server
63
##|*DESCR=Allow access to the 'Services: DHCPv6 server' page.
64
##|*MATCH=services_dhcpv6.php*
65
##|-PRIV
66

    
67
require("guiconfig.inc");
68
require_once("filter.inc");
69

    
70
function dhcpv6_apply_changes($dhcpdv6_enable_changed) {
71
	$retval = 0;
72
	$retvaldhcp = 0;
73
	$retvaldns = 0;
74
	/* Stop DHCPv6 so we can cleanup leases */
75
	killbypid("{$g['dhcpd_chroot_path']}{$g['varrun_path']}/dhcpdv6.pid");
76
	// dhcp_clean_leases();
77
	/* dnsmasq_configure calls dhcpd_configure */
78
	/* no need to restart dhcpd twice */
79
	if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstatic']))	{
80
		$retvaldns = services_dnsmasq_configure();
81
		if ($retvaldns == 0) {
82
			clear_subsystem_dirty('hosts');
83
			clear_subsystem_dirty('staticmaps');
84
		}
85
	} else if (isset($config['unbound']['enable']) && isset($config['unbound']['regdhcpstatic'])) {
86
		$retvaldns = services_unbound_configure();
87
		if ($retvaldns == 0) {
88
			clear_subsystem_dirty('unbound');
89
			clear_subsystem_dirty('staticmaps');
90
		}
91
	} else {
92
		$retvaldhcp = services_dhcpd_configure();
93
		if ($retvaldhcp == 0) {
94
			clear_subsystem_dirty('staticmaps');
95
		}
96
	}
97
	if ($dhcpdv6_enable_changed) {
98
		$retvalfc = filter_configure();
99
	}
100
	if ($retvaldhcp == 1 || $retvaldns == 1 || $retvalfc == 1) {
101
		$retval = 1;
102
	}
103
	return get_std_save_message($retval);
104
}
105

    
106
if (!$g['services_dhcp_server_enable']) {
107
	header("Location: /");
108
	exit;
109
}
110

    
111
/*	Fix failover DHCP problem
112
 *	http://article.gmane.org/gmane.comp.security.firewalls.pfsense.support/18749
113
 */
114
ini_set("memory_limit", "64M");
115

    
116
$if = $_GET['if'];
117
if ($_POST['if']) {
118
	$if = $_POST['if'];
119
}
120

    
121
/* if OLSRD is enabled, allow WAN to house DHCP. */
122
if ($config['installedpackages']['olsrd']) {
123
	foreach ($config['installedpackages']['olsrd']['config'] as $olsrd) {
124
		if ($olsrd['enable']) {
125
			$is_olsr_enabled = true;
126
			break;
127
		}
128
	}
129
}
130

    
131
$iflist = get_configured_interface_with_descr();
132
$iflist = array_merge($iflist, get_configured_pppoe_server_interfaces());
133

    
134
/* set the starting interface */
135
if (!$if || !isset($iflist[$if])) {
136
	foreach ($iflist as $ifent => $ifname) {
137
		$oc = $config['interfaces'][$ifent];
138
		$valid_if_ipaddrv6 = (bool) ($oc['ipaddrv6'] == 'track6' ||
139
		    (is_ipaddrv6($oc['ipaddrv6']) &&
140
		    !is_linklocal($oc['ipaddrv6'])));
141

    
142
		if ((!is_array($config['dhcpdv6'][$ifent]) ||
143
		    !isset($config['dhcpdv6'][$ifent]['enable'])) &&
144
		    !$valid_if_ipaddrv6) {
145
			continue;
146
		}
147
		$if = $ifent;
148
		break;
149
	}
150
}
151

    
152
if (is_array($config['dhcpdv6'][$if])) {
153
	/* DHCPv6 */
154
	if (is_array($config['dhcpdv6'][$if]['range'])) {
155
		$pconfig['range_from'] = $config['dhcpdv6'][$if]['range']['from'];
156
		$pconfig['range_to'] = $config['dhcpdv6'][$if]['range']['to'];
157
	}
158
	if (is_array($config['dhcpdv6'][$if]['prefixrange'])) {
159
		$pconfig['prefixrange_from'] = $config['dhcpdv6'][$if]['prefixrange']['from'];
160
		$pconfig['prefixrange_to'] = $config['dhcpdv6'][$if]['prefixrange']['to'];
161
		$pconfig['prefixrange_length'] = $config['dhcpdv6'][$if]['prefixrange']['prefixlength'];
162
	}
163
	$pconfig['deftime'] = $config['dhcpdv6'][$if]['defaultleasetime'];
164
	$pconfig['maxtime'] = $config['dhcpdv6'][$if]['maxleasetime'];
165
	$pconfig['domain'] = $config['dhcpdv6'][$if]['domain'];
166
	$pconfig['domainsearchlist'] = $config['dhcpdv6'][$if]['domainsearchlist'];
167
	list($pconfig['wins1'], $pconfig['wins2']) = $config['dhcpdv6'][$if]['winsserver'];
168
	list($pconfig['dns1'], $pconfig['dns2'], $pconfig['dns3'], $pconfig['dns4']) = $config['dhcpdv6'][$if]['dnsserver'];
169
	$pconfig['enable'] = isset($config['dhcpdv6'][$if]['enable']);
170
	$pconfig['ddnsdomain'] = $config['dhcpdv6'][$if]['ddnsdomain'];
171
	$pconfig['ddnsdomainprimary'] = $config['dhcpdv6'][$if]['ddnsdomainprimary'];
172
	$pconfig['ddnsdomainkeyname'] = $config['dhcpdv6'][$if]['ddnsdomainkeyname'];
173
	$pconfig['ddnsdomainkey'] = $config['dhcpdv6'][$if]['ddnsdomainkey'];
174
	$pconfig['ddnsupdate'] = isset($config['dhcpdv6'][$if]['ddnsupdate']);
175
	$pconfig['ddnsreverse'] = isset($config['dhcpdv6'][$if]['ddnsreverse']);
176
	$pconfig['ddnsclientupdates'] = $config['dhcpdv6'][$if]['ddnsclientupdates'];
177
	list($pconfig['ntp1'], $pconfig['ntp2']) = $config['dhcpdv6'][$if]['ntpserver'];
178
	$pconfig['tftp'] = $config['dhcpdv6'][$if]['tftp'];
179
	$pconfig['ldap'] = $config['dhcpdv6'][$if]['ldap'];
180
	$pconfig['netboot'] = isset($config['dhcpdv6'][$if]['netboot']);
181
	$pconfig['bootfile_url'] = $config['dhcpdv6'][$if]['bootfile_url'];
182
	$pconfig['netmask'] = $config['dhcpdv6'][$if]['netmask'];
183
	$pconfig['numberoptions'] = $config['dhcpdv6'][$if]['numberoptions'];
184
	$pconfig['dhcpv6leaseinlocaltime'] = $config['dhcpdv6'][$if]['dhcpv6leaseinlocaltime'];
185
	if (!is_array($config['dhcpdv6'][$if]['staticmap'])) {
186
		$config['dhcpdv6'][$if]['staticmap'] = array();
187
	}
188
	$a_maps = &$config['dhcpdv6'][$if]['staticmap'];
189
}
190

    
191
if ($config['interfaces'][$if]['ipaddrv6'] == 'track6') {
192
	$trackifname = $config['interfaces'][$if]['track6-interface'];
193
	$trackcfg = $config['interfaces'][$trackifname];
194
	$ifcfgsn = "64";
195
	$ifcfgip = '::';
196

    
197
	$str_help_mask = dhcpv6_pd_str_help($ifcfgsn);
198
} else {
199
	$ifcfgip = get_interface_ipv6($if);
200
	$ifcfgsn = get_interface_subnetv6($if);
201
}
202

    
203
/*	 set the enabled flag which will tell us if DHCP relay is enabled
204
 *	 on any interface. We will use this to disable DHCP server since
205
 *	 the two are not compatible with each other.
206
 */
207

    
208
$dhcrelay_enabled = false;
209
$dhcrelaycfg = $config['dhcrelay6'];
210

    
211
if (is_array($dhcrelaycfg) && isset($dhcrelaycfg['enable']) && isset($dhcrelaycfg['interface']) && !empty($dhcrelaycfg['interface'])) {
212
	$dhcrelayifs = explode(",", $dhcrelaycfg['interface']);
213

    
214
	foreach ($dhcrelayifs as $dhcrelayif) {
215

    
216
		if (isset($iflist[$dhcrelayif]) && (!link_interface_to_bridge($dhcrelayif))) {
217
			$dhcrelay_enabled = true;
218
			break;
219
		}
220
	}
221
}
222

    
223
if (isset($_POST['apply'])) {
224
	$savemsg = dhcpv6_apply_changes(false);
225
} elseif (isset($_POST['save'])) {
226
	unset($input_errors);
227

    
228
	$old_dhcpdv6_enable = ($pconfig['enable'] == true);
229
	$new_dhcpdv6_enable = ($_POST['enable'] ? true : false);
230
	$dhcpdv6_enable_changed = ($old_dhcpdv6_enable != $new_dhcpdv6_enable);
231

    
232
	$pconfig = $_POST;
233

    
234
	$numberoptions = array();
235
	for ($x = 0; $x < 99; $x++) {
236
		if (isset($_POST["number{$x}"]) && ctype_digit($_POST["number{$x}"])) {
237
			$numbervalue = array();
238
			$numbervalue['number'] = htmlspecialchars($_POST["number{$x}"]);
239
			$numbervalue['value'] = base64_encode($_POST["value{$x}"]);
240
			$numberoptions['item'][] = $numbervalue;
241
		}
242
	}
243
	// Reload the new pconfig variable that the forum uses.
244
	$pconfig['numberoptions'] = $numberoptions;
245

    
246
	/* input validation */
247
	if ($_POST['enable']) {
248
		$reqdfields = explode(" ", "range_from range_to");
249
		$reqdfieldsn = array(gettext("Range begin"), gettext("Range end"));
250

    
251
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
252

    
253
		if (($_POST['prefixrange_from'] && !is_ipaddrv6($_POST['prefixrange_from']))) {
254
			$input_errors[] = gettext("A valid prefix range must be specified.");
255
		}
256
		if (($_POST['prefixrange_to'] && !is_ipaddrv6($_POST['prefixrange_to']))) {
257
			$input_errors[] = gettext("A valid prefix range must be specified.");
258
		}
259

    
260
		if ($_POST['prefixrange_from'] && $_POST['prefixrange_to'] &&
261
		    $_POST['prefixrange_length']) {
262
			$netmask = Net_IPv6::getNetmask($_POST['prefixrange_from'],
263
			    $_POST['prefixrange_length']);
264
			$netmask = Net_IPv6::compress($netmask);
265

    
266
			if ($netmask != Net_IPv6::compress(strtolower(
267
			    $_POST['prefixrange_from']))) {
268
				$input_errors[] = sprintf(gettext(
269
				    "Prefix Delegation From address is not a valid IPv6 Netmask for %s"),
270
				    $netmask . '/' . $_POST['prefixrange_length']);
271
			}
272

    
273
			$netmask = Net_IPv6::getNetmask($_POST['prefixrange_to'],
274
			    $_POST['prefixrange_length']);
275
			$netmask = Net_IPv6::compress($netmask);
276

    
277
			if ($netmask != Net_IPv6::compress(strtolower(
278
			    $_POST['prefixrange_to']))) {
279
				$input_errors[] = sprintf(gettext(
280
				    "Prefix Delegation To address is not a valid IPv6 Netmask for %s"),
281
				    $netmask . '/' . $_POST['prefixrange_length']);
282
			}
283
		}
284

    
285
		if ($_POST['range_from']) {
286
			if (!is_ipaddrv6($_POST['range_from'])) {
287
				$input_errors[] = gettext("A valid range must be specified.");
288
			} elseif ($config['interfaces'][$if]['ipaddrv6'] == 'track6' &&
289
			    !Net_IPv6::isInNetmask($_POST['range_from'], '::', $ifcfgsn)) {
290
				$input_errors[] = sprintf(gettext(
291
				    "The prefix (upper %s bits) must be zero.  Use the form %s"),
292
				    $ifcfgsn, $str_help_mask);
293
			}
294
		}
295
		if ($_POST['range_to']) {
296
			if (!is_ipaddrv6($_POST['range_to'])) {
297
				$input_errors[] = gettext("A valid range must be specified.");
298
			} elseif ($config['interfaces'][$if]['ipaddrv6'] == 'track6' &&
299
			    !Net_IPv6::isInNetmask($_POST['range_to'], '::', $ifcfgsn)) {
300
				$input_errors[] = sprintf(gettext(
301
				    "The prefix (upper %s bits) must be zero.  Use the form %s"),
302
				    $ifcfgsn, $str_help_mask);
303
			}
304
		}
305
		if (($_POST['gateway'] && !is_ipaddrv6($_POST['gateway']))) {
306
			$input_errors[] = gettext("A valid IPv6 address must be specified for the gateway.");
307
		}
308
		if (($_POST['dns1'] && !is_ipaddrv6($_POST['dns1'])) ||
309
		    ($_POST['dns2'] && !is_ipaddrv6($_POST['dns2'])) ||
310
		    ($_POST['dns3'] && !is_ipaddrv6($_POST['dns3'])) ||
311
		    ($_POST['dns4'] && !is_ipaddrv6($_POST['dns4']))) {
312
			$input_errors[] = gettext("A valid IPv6 address must be specified for each of the DNS servers.");
313
		}
314

    
315
		if ($_POST['deftime'] && (!is_numeric($_POST['deftime']) || ($_POST['deftime'] < 60))) {
316
			$input_errors[] = gettext("The default lease time must be at least 60 seconds.");
317
		}
318
		if ($_POST['maxtime'] && (!is_numeric($_POST['maxtime']) || ($_POST['maxtime'] < 60) || ($_POST['maxtime'] <= $_POST['deftime']))) {
319
			$input_errors[] = gettext("The maximum lease time must be at least 60 seconds and higher than the default lease time.");
320
		}
321
		if (($_POST['ddnsdomain'] && !is_domain($_POST['ddnsdomain']))) {
322
			$input_errors[] = gettext("A valid domain name must be specified for the dynamic DNS registration.");
323
		}
324
		if (($_POST['ddnsdomain'] && !is_ipaddrv4($_POST['ddnsdomainprimary']))) {
325
			$input_errors[] = gettext("A valid primary domain name server IPv4 address must be specified for the dynamic domain name.");
326
		}
327
		if (($_POST['ddnsdomainkey'] && !$_POST['ddnsdomainkeyname']) ||
328
		    ($_POST['ddnsdomainkeyname'] && !$_POST['ddnsdomainkey'])) {
329
			$input_errors[] = gettext("Both a valid domain key and key name must be specified.");
330
		}
331
		if ($_POST['domainsearchlist']) {
332
			$domain_array=preg_split("/[ ;]+/", $_POST['domainsearchlist']);
333
			foreach ($domain_array as $curdomain) {
334
				if (!is_domain($curdomain)) {
335
					$input_errors[] = gettext("A valid domain search list must be specified.");
336
					break;
337
				}
338
			}
339
		}
340

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

    
354
		// Disallow a range that includes the virtualip
355
		if (is_array($config['virtualip']['vip'])) {
356
			foreach ($config['virtualip']['vip'] as $vip) {
357
				if ($vip['interface'] == $if) {
358
					if ($vip['subnetv6'] && is_inrange_v6($vip['subnetv6'], $_POST['range_from'], $_POST['range_to'])) {
359
						$input_errors[] = sprintf(gettext("The subnet range cannot overlap with virtual IPv6 address %s."), $vip['subnetv6']);
360
					}
361
				}
362
			}
363
		}
364

    
365
		$noip = false;
366
		if (is_array($a_maps)) {
367
			foreach ($a_maps as $map) {
368
				if (empty($map['ipaddrv6'])) {
369
					$noip = true;
370
				}
371
			}
372
		}
373
		if (!$input_errors) {
374
			/* make sure the range lies within the current subnet */
375
			$subnet_start = gen_subnetv6($ifcfgip, $ifcfgsn);
376
			$subnet_end = gen_subnetv6_max($ifcfgip, $ifcfgsn);
377

    
378
			if (is_ipaddrv6($ifcfgip)) {
379
				if ((!is_inrange_v6($_POST['range_from'], $subnet_start, $subnet_end)) ||
380
				    (!is_inrange_v6($_POST['range_to'], $subnet_start, $subnet_end))) {
381
					$input_errors[] = gettext("The specified range lies outside of the current subnet.");
382
				}
383
			}
384
			/* "from" cannot be higher than "to" */
385
			if (inet_pton($_POST['range_from']) > inet_pton($_POST['range_to'])) {
386
				$input_errors[] = gettext("The range is invalid (first element higher than second element).");
387
			}
388

    
389
			/* make sure that the DHCP Relay isn't enabled on this interface */
390
			if (isset($config['dhcrelay'][$if]['enable'])) {
391
				$input_errors[] = sprintf(gettext("The DHCP relay on the %s interface must be disabled before enabling the DHCP server."), $iflist[$if]);
392
			}
393

    
394

    
395
			/* Verify static mappings do not overlap:
396
			   - available DHCP range
397
			   - prefix delegation range (FIXME: still need to be completed) */
398
			$dynsubnet_start = inet_pton($_POST['range_from']);
399
			$dynsubnet_end = inet_pton($_POST['range_to']);
400

    
401
			if (is_array($a_maps)) {
402
				foreach ($a_maps as $map) {
403
					if (empty($map['ipaddrv6'])) {
404
						continue;
405
					}
406
					if ((inet_pton($map['ipaddrv6']) > $dynsubnet_start) &&
407
					    (inet_pton($map['ipaddrv6']) < $dynsubnet_end)) {
408
						$input_errors[] = sprintf(gettext("The DHCP range cannot overlap any static DHCP mappings."));
409
						break;
410
					}
411
				}
412
			}
413
		}
414
	}
415

    
416
	if (!$input_errors) {
417
		if (!is_array($config['dhcpdv6'][$if])) {
418
			$config['dhcpdv6'][$if] = array();
419
		}
420
		if (!is_array($config['dhcpdv6'][$if]['range'])) {
421
			$config['dhcpdv6'][$if]['range'] = array();
422
		}
423
		if (!is_array($config['dhcpdv6'][$if]['prefixrange'])) {
424
			$config['dhcpdv6'][$if]['prefixrange'] = array();
425
		}
426

    
427
		$config['dhcpdv6'][$if]['range']['from'] = $_POST['range_from'];
428
		$config['dhcpdv6'][$if]['range']['to'] = $_POST['range_to'];
429
		$config['dhcpdv6'][$if]['prefixrange']['from'] = $_POST['prefixrange_from'];
430
		$config['dhcpdv6'][$if]['prefixrange']['to'] = $_POST['prefixrange_to'];
431
		$config['dhcpdv6'][$if]['prefixrange']['prefixlength'] = $_POST['prefixrange_length'];
432
		$config['dhcpdv6'][$if]['defaultleasetime'] = $_POST['deftime'];
433
		$config['dhcpdv6'][$if]['maxleasetime'] = $_POST['maxtime'];
434
		$config['dhcpdv6'][$if]['netmask'] = $_POST['netmask'];
435

    
436
		unset($config['dhcpdv6'][$if]['winsserver']);
437

    
438
		unset($config['dhcpdv6'][$if]['dnsserver']);
439
		if ($_POST['dns1']) {
440
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns1'];
441
		}
442
		if ($_POST['dns2']) {
443
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns2'];
444
		}
445
		if ($_POST['dns3']) {
446
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns3'];
447
		}
448
		if ($_POST['dns4']) {
449
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns4'];
450
		}
451

    
452
		$config['dhcpdv6'][$if]['domain'] = $_POST['domain'];
453
		$config['dhcpdv6'][$if]['domainsearchlist'] = $_POST['domainsearchlist'];
454
		$config['dhcpdv6'][$if]['enable'] = ($_POST['enable']) ? true : false;
455
		$config['dhcpdv6'][$if]['ddnsdomain'] = $_POST['ddnsdomain'];
456
		$config['dhcpdv6'][$if]['ddnsdomainprimary'] = $_POST['ddnsdomainprimary'];
457
		$config['dhcpdv6'][$if]['ddnsdomainkeyname'] = $_POST['ddnsdomainkeyname'];
458
		$config['dhcpdv6'][$if]['ddnsdomainkey'] = $_POST['ddnsdomainkey'];
459
		$config['dhcpdv6'][$if]['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
460
		$config['dhcpdv6'][$if]['ddnsreverse'] = ($_POST['ddnsreverse']) ? true : false;
461
		$config['dhcpdv6'][$if]['ddnsclientupdates'] = $_POST['ddnsclientupdates'];
462

    
463
		unset($config['dhcpdv6'][$if]['ntpserver']);
464
		if ($_POST['ntp1']) {
465
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp1'];
466
		}
467
		if ($_POST['ntp2']) {
468
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp2'];
469
		}
470

    
471
		$config['dhcpdv6'][$if]['tftp'] = $_POST['tftp'];
472
		$config['dhcpdv6'][$if]['ldap'] = $_POST['ldap'];
473
		$config['dhcpdv6'][$if]['netboot'] = ($_POST['netboot']) ? true : false;
474
		$config['dhcpdv6'][$if]['bootfile_url'] = $_POST['bootfile_url'];
475
		$config['dhcpdv6'][$if]['dhcpv6leaseinlocaltime'] = $_POST['dhcpv6leaseinlocaltime'];
476

    
477
		// Handle the custom options rowhelper
478
		if (isset($config['dhcpdv6'][$if]['numberoptions']['item'])) {
479
			unset($config['dhcpdv6'][$if]['numberoptions']['item']);
480
		}
481

    
482
		$config['dhcpdv6'][$if]['numberoptions'] = $numberoptions;
483

    
484
		write_config();
485

    
486
		$savemsg = dhcpv6_apply_changes($dhcpdv6_enable_changed);
487
	}
488
}
489

    
490
if ($_GET['act'] == "del") {
491
	if ($a_maps[$_GET['id']]) {
492
		unset($a_maps[$_GET['id']]);
493
		write_config();
494
		if (isset($config['dhcpdv6'][$if]['enable'])) {
495
			mark_subsystem_dirty('staticmapsv6');
496
			if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstaticv6'])) {
497
				mark_subsystem_dirty('hosts');
498
			}
499
		}
500
		header("Location: services_dhcpv6.php?if={$if}");
501
		exit;
502
	}
503
}
504

    
505
$pgtitle = array(gettext("Services"), htmlspecialchars(gettext("DHCPv6 Server & RA")));
506

    
507
if (!empty($if) && !$dhcrelay_enabled && isset($iflist[$if])) {
508
	$pgtitle[] = $iflist[$if];
509
	$pgtitle[] = gettext("DHCPv6 Server");
510
}
511
$shortcut_section = "dhcp6";
512

    
513
include("head.inc");
514

    
515
if ($input_errors) {
516
	print_input_errors($input_errors);
517
}
518

    
519
if ($savemsg) {
520
	print_info_box($savemsg, 'success');
521
}
522

    
523
if ($dhcrelay_enabled) {
524
	print_info_box(gettext("DHCPv6 Relay is currently enabled. Cannot enable the DHCPv6 Server service while the DHCPv6 Relay is enabled on any interface."), 'danger', false);
525
	include("foot.inc");
526
	exit;
527
}
528

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

    
533
/* active tabs */
534
$tab_array = array();
535
$tabscounter = 0;
536
$i = 0;
537

    
538
foreach ($iflist as $ifent => $ifname) {
539
	$oc = $config['interfaces'][$ifent];
540
	$valid_if_ipaddrv6 = (bool) ($oc['ipaddrv6'] == 'track6' ||
541
	    (is_ipaddrv6($oc['ipaddrv6']) &&
542
	    !is_linklocal($oc['ipaddrv6'])));
543

    
544
	if ((!is_array($config['dhcpdv6'][$ifent]) ||
545
	    !isset($config['dhcpdv6'][$ifent]['enable'])) &&
546
	    !$valid_if_ipaddrv6) {
547
		continue;
548
	}
549

    
550
	if ($ifent == $if) {
551
		$active = true;
552
	} else {
553
		$active = false;
554
	}
555

    
556
	$tab_array[] = array($ifname, $active, "services_dhcpv6.php?if={$ifent}");
557
	$tabscounter++;
558
}
559

    
560
/* tack on PPPoE or PPtP servers here */
561
/* pppoe server */
562
if (is_array($config['pppoes']['pppoe'])) {
563
	foreach ($config['pppoes']['pppoe'] as $pppoe) {
564
		if ($pppoe['mode'] == "server") {
565
			$ifent = "poes". $pppoe['pppoeid'];
566
			$ifname = strtoupper($ifent);
567

    
568
			if ($ifent == $if) {
569
				$active = true;
570
			} else {
571
				$active = false;
572
			}
573

    
574
			$tab_array[] = array($ifname, $active, "services_dhcpv6.php?if={$ifent}");
575
			$tabscounter++;
576
		}
577
	}
578
}
579

    
580
if ($tabscounter == 0) {
581
	print_info_box(gettext("The DHCPv6 Server can only be enabled on interfaces configured with a static IPv6 address. This system has none."), 'danger');
582
	include("foot.inc");
583
	exit;
584
}
585

    
586
display_top_tabs($tab_array);
587

    
588
$tab_array = array();
589
$tab_array[] = array(gettext("DHCPv6 Server"),		 true,	"services_dhcpv6.php?if={$if}");
590
$tab_array[] = array(gettext("Router Advertisements"), false, "services_router_advertisements.php?if={$if}");
591
display_top_tabs($tab_array, false, 'nav nav-tabs');
592

    
593
$form = new Form();
594

    
595
$section = new Form_Section('DHCPv6 Options');
596

    
597
$section->addInput(new Form_Checkbox(
598
	'enable',
599
	'DHCPv6 Server',
600
	'Enable DHCPv6 server on interface ' . $iflist[$if],
601
	$pconfig['enable']
602
));
603

    
604
if (is_ipaddrv6($ifcfgip)) {
605

    
606
	if ($ifcfgip == "::") {
607
		$sntext = "Prefix Delegation";
608
	} else {
609
		$sntext = gen_subnetv6($ifcfgip, $ifcfgsn);
610
	}
611
	$section->addInput(new Form_StaticText(
612
		'Subnet',
613
		$sntext
614
		));
615

    
616
	$section->addInput(new Form_StaticText(
617
		'Subnet Mask',
618
		$ifcfgsn . ' bits'
619
		));
620

    
621
	$section->addInput(new Form_StaticText(
622
		'Available Range',
623
		$range_from = gen_subnetv6($ifcfgip, $ifcfgsn) . ' to ' . gen_subnetv6_max($ifcfgip, $ifcfgsn)
624
		))->setHelp($trackifname ? 'Prefix Delegation subnet will be appended to the beginning of the defined range':'');
625
}
626

    
627
if ($is_olsr_enabled) {
628
	$section->addInput(new Form_Select(
629
	'netmask',
630
	'Subnet Mask',
631
	$pconfig['netmask'],
632
	array_combine(range(128, 1, -1), range(128, 1, -1))
633
	));
634
}
635

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

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

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

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

    
654
$group = new Form_Group('Range');
655

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

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

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

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

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

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

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

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

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

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

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

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

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

    
716
$section->addInput(new Form_Input(
717
	'domain',
718
	'Domain Name',
719
	'text',
720
	$pconfig['domain']
721
))->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. ');
722

    
723
$section->addInput(new Form_Input(
724
	'domainsearchlist',
725
	'Domain search list',
726
	'text',
727
	$pconfig['domainsearchlist']
728
))->setHelp('The DHCP server can optionally provide a domain search list. Use the semicolon character as separator');
729

    
730
$section->addInput(new Form_Input(
731
	'deftime',
732
	'Default lease time',
733
	'text',
734
	$pconfig['deftime']
735
))->setHelp('Lease time in seconds. Used for clients that do not ask for a specific expiration time. ' . ' <br />' .
736
			'The default is 7200 seconds.');
737

    
738
$section->addInput(new Form_Input(
739
	'maxtime',
740
	'Max lease time',
741
	'text',
742
	$pconfig['maxtime']
743
))->setHelp('Maximum lease time for clients that ask for a specific expiration time.' . ' <br />' .
744
			'The default is 86400 seconds.');
745

    
746
$section->addInput(new Form_Checkbox(
747
	'dhcpv6leaseinlocaltime',
748
	'Time Format Change',
749
	'Change DHCPv6 display lease time from UTC to local time',
750
	$pconfig['dhcpv6leaseinlocaltime']
751
))->setHelp('By default DHCPv6 leases are displayed in UTC time. ' .
752
			'By checking this box DHCPv6 lease time will be displayed in local time and set to time zone selected. ' .
753
			'This will be used for all DHCPv6 interfaces lease time.');
754

    
755
$btnadv = new Form_Button(
756
	'btnadvdns',
757
	'Display Advanced',
758
	null,
759
	'fa-cog'
760
);
761

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

    
764
$section->addInput(new Form_StaticText(
765
	'Dynamic DNS',
766
	$btnadv
767
));
768

    
769
$section->addInput(new Form_Checkbox(
770
	'ddnsupdate',
771
	'DHCP Registration',
772
	'Enable registration of DHCP client names in DNS.',
773
	$pconfig['ddnsupdate']
774
));
775

    
776
$section->addInput(new Form_Input(
777
	'ddnsdomain',
778
	'DDNS Domain',
779
	'text',
780
	$pconfig['ddnsdomain']
781
))->setHelp('Leave blank to disable dynamic DNS registration. Enter the dynamic DNS domain which will be used to register client names in the DNS server.');
782

    
783
$section->addInput(new Form_IpAddress(
784
	'ddnsdomainprimary',
785
	'DDNS Server IP',
786
	$pconfig['ddnsdomainprimary']
787
))->setHelp('Enter the primary domain name server IP address for the dynamic domain name.');
788

    
789
$section->addInput(new Form_Input(
790
	'ddnsdomainkeyname',
791
	'DDNS Domain Key name',
792
	'text',
793
	$pconfig['ddnsdomainkeyname']
794
))->setHelp('Enter the dynamic DNS domain key name which will be used to register client names in the DNS server.');
795

    
796
$section->addInput(new Form_Input(
797
	'ddnsdomainkey',
798
	'DDNS Domain Key secret',
799
	'text',
800
	$pconfig['ddnsdomainkey']
801
))->setHelp('Enter the dynamic DNS domain key secret which will be used to register client names in the DNS server.');
802

    
803
$section->addInput(new Form_Select(
804
	'ddnsclientupdates',
805
	'DDNS Client Updates',
806
	$pconfig['ddnsclientupdates'],
807
	array(
808
	    'allow' => gettext('Allow'),
809
	    'deny' => gettext('Deny'),
810
	    'ignore' => gettext('Ignore'))
811
))->setHelp('How Forward entries are handled when client indicates they wish to update DNS.  ' .
812
	    'Allow prevents DHCP from updating Forward entries, Deny indicates that DHCP will ' .
813
	    'do the updates and the client should not, Ignore specifies that DHCP will do the ' .
814
	    'update and the client can also attempt the update usually using a different domain name.');
815

    
816
$section->addInput(new Form_Checkbox(
817
	'ddnsreverse',
818
	'DDNS Reverse',
819
	'Add reverse dynamic DNS entries.',
820
	$pconfig['ddnsreverse']
821
));
822

    
823
$btnadv = new Form_Button(
824
	'btnadvntp',
825
	'Display Advanced',
826
	null,
827
	'fa-cog'
828
);
829

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

    
832
$section->addInput(new Form_StaticText(
833
	'NTP servers',
834
	$btnadv
835
));
836

    
837
$group = new Form_Group('NTP Servers');
838

    
839
$group->add(new Form_Input(
840
	'ntp1',
841
	'NTP Server 1',
842
	'text',
843
	$pconfig['ntp1'],
844
	['placeholder' => 'NTP 1']
845
));
846

    
847
$group->add(new Form_Input(
848
	'ntp2',
849
	'NTP Server 2',
850
	'text',
851
	$pconfig['ntp2'],
852
	['placeholder' => 'NTP 2']
853
));
854

    
855
$group->addClass('ntpclass');
856

    
857
$section->add($group);
858

    
859
$btnadv = new Form_Button(
860
	'btnadvldap',
861
	'Display Advanced',
862
	null,
863
	'fa-cog'
864
);
865

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

    
868
$section->addInput(new Form_StaticText(
869
	'LDAP',
870
	$btnadv
871
));
872

    
873
$section->addInput(new Form_Input(
874
	'ldap',
875
	'LDAP URI',
876
	'text',
877
	$pconfig['ldap']
878
));
879

    
880
$btnadv = new Form_Button(
881
	'btnadvnetboot',
882
	'Display Advanced',
883
	null,
884
	'fa-cog'
885
);
886

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

    
889
$section->addInput(new Form_StaticText(
890
	'Network booting',
891
	$btnadv
892
));
893

    
894
$section->addInput(new Form_Checkbox(
895
	'shownetboot',
896
	'Network booting',
897
	'Enable Network Booting',
898
	$pconfig['shownetboot']
899
));
900

    
901
$section->addInput(new Form_Input(
902
	'bootfile_url',
903
	'Bootfile URL',
904
	'text',
905
	$pconfig['bootfile_url']
906
));
907

    
908
$btnadv = new Form_Button(
909
	'btnadvopts',
910
	'Display Advanced',
911
	null,
912
	'fa-cog'
913
);
914

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

    
917
$section->addInput(new Form_StaticText(
918
	'Additional BOOTP/DHCP Options',
919
	$btnadv
920
));
921

    
922
$form->add($section);
923

    
924
$title = 'Show Additional BOOTP/DHCP Options';
925

    
926
if (!$pconfig['numberoptions']) {
927
	$noopts = true;
928
	$pconfig['numberoptions']['item'] = array(0 => array('number' => "", 'value' => ""));
929
} else {
930
	$noopts = false;
931
}
932

    
933
$counter = 0;
934
$last = count($pconfig['numberoptions']['item']) - 1;
935

    
936
foreach ($pconfig['numberoptions']['item'] as $item) {
937
	$group = new Form_Group(null);
938
	$group->addClass('repeatable');
939
	$group->addClass('adnloptions');
940

    
941
	$group->add(new Form_Input(
942
		'number' . $counter,
943
		null,
944
		'text',
945
		$item['number']
946
	))->setHelp($counter == $last ? 'Number':null);
947

    
948
	$group->add(new Form_Input(
949
		'value' . $counter,
950
		null,
951
		'text',
952
		base64_decode($item['value'])
953
	))->setHelp($counter == $last ? 'Value':null);
954

    
955
	$btn = new Form_Button(
956
		'deleterow' . $counter,
957
		'Delete',
958
		null,
959
		'fa-trash'
960
	);
961

    
962
	$btn->addClass('btn-warning');
963
	$group->add($btn);
964
	$section->add($group);
965
	$counter++;
966
}
967

    
968

    
969
$btnaddopt = new Form_Button(
970
	'addrow',
971
	'Add Option',
972
	null,
973
	'fa-plus'
974
);
975

    
976
$btnaddopt->removeClass('btn-primary')->addClass('btn-success btn-sm');
977

    
978
$section->addInput($btnaddopt);
979

    
980
$section->addInput(new Form_Input(
981
	'if',
982
	null,
983
	'hidden',
984
	$if
985
));
986

    
987
print($form);
988

    
989
?>
990
<div class="infoblock blockopen">
991
<?php
992
print_info_box(
993
	sprintf(
994
		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.'),
995
		'<a href="system.php">',
996
		'<a href="services_dnsmasq.php"/>',
997
		'</a>') .
998
	'<br />' .
999
	sprintf(
1000
		gettext('The DHCP lease table can be viewed on the %1$sStatus: DHCPv6 leases%2$s page.'),
1001
		'<a href="status_dhcpv6_leases.php">',
1002
		'</a>'),
1003
	'info',
1004
	false);
1005
?>
1006
</div>
1007
<div class="panel panel-default">
1008
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("DHCPv6 Static Mappings for this Interface");?></h2></div>
1009
	<div class="panel-body table-responsive">
1010
		<table class="table table-striped table-hover table-condensed">
1011
			<thead>
1012
				<tr>
1013
					<th><?=gettext("DUID")?></th>
1014
					<th><?=gettext("IPv6 address")?></th>
1015
					<th><?=gettext("Hostname")?></th>
1016
					<th><?=gettext("Description")?></th>
1017
					<th><!-- Buttons --></th>
1018
				</tr>
1019
			</thead>
1020
			<tbody>
1021
<?php
1022
if (is_array($a_maps)):
1023
	$i = 0;
1024
	foreach ($a_maps as $mapent):
1025
		if ($mapent['duid'] != "" or $mapent['ipaddrv6'] != ""):
1026
?>
1027
				<tr>
1028
					<td>
1029
						<?=htmlspecialchars($mapent['duid'])?>
1030
					</td>
1031
					<td>
1032
						<?=htmlspecialchars($mapent['ipaddrv6'])?>
1033
					</td>
1034
					<td>
1035
						<?=htmlspecialchars($mapent['hostname'])?>
1036
					</td>
1037
					<td>
1038
						<?=htmlspecialchars($mapent['descr'])?>
1039
					</td>
1040
					<td>
1041
						<a class="fa fa-pencil"	title="<?=gettext('Edit static mapping')?>" href="services_dhcpv6_edit.php?if=<?=$if?>&amp;id=<?=$i?>"></a>
1042
						<a class="fa fa-trash"	title="<?=gettext('Delete static mapping')?>" href="services_dhcpv6.php?if=<?=$if?>&amp;act=del&amp;id=<?=$i?>"></a>
1043
					</td>
1044
				</tr>
1045
<?php
1046
		endif;
1047
	$i++;
1048
	endforeach;
1049
endif;
1050
?>
1051
			</tbody>
1052
		</table>
1053
	</div>
1054
</div>
1055

    
1056
<nav class="action-buttons">
1057
	<a href="services_dhcpv6_edit.php?if=<?=$if?>" class="btn btn-sm btn-success"/>
1058
		<i class="fa fa-plus icon-embed-btn"></i>
1059
		<?=gettext("Add")?>
1060
	</a>
1061
</nav>
1062

    
1063
<script type="text/javascript">
1064
//<![CDATA[
1065
events.push(function() {
1066

    
1067
	// Show advanced DNS options ======================================================================================
1068
	var showadvdns = false;
1069

    
1070
	function show_advdns(ispageload) {
1071
		var text;
1072
		// On page load decide the initial state based on the data.
1073
		if (ispageload) {
1074
<?php
1075
			if (!$pconfig['ddnsupdate'] &&
1076
			    empty($pconfig['ddnsdomain']) &&
1077
			    empty($pconfig['ddnsdomainprimary']) &&
1078
			    empty($pconfig['ddnsdomainkeyname']) &&
1079
			    empty($pconfig['ddnsdomainkey']) &&
1080
			    (empty($pconfig['ddnsclientupdates']) || ($pconfig['ddnsclientupdates'] == "allow")) &&
1081
			    !$pconfig['ddnsreverse']) {
1082
				$showadv = false;
1083
			} else {
1084
				$showadv = true;
1085
			}
1086
?>
1087
			showadvdns = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1088
		} else {
1089
			// It was a click, swap the state.
1090
			showadvdns = !showadvdns;
1091
		}
1092

    
1093
		hideCheckbox('ddnsupdate', !showadvdns);
1094
		hideInput('ddnsdomain', !showadvdns);
1095
		hideInput('ddnsdomainprimary', !showadvdns);
1096
		hideInput('ddnsdomainkeyname', !showadvdns);
1097
		hideInput('ddnsdomainkey', !showadvdns);
1098
		hideInput('ddnsclientupdates', !showadvdns);
1099
		hideCheckbox('ddnsreverse', !showadvdns);
1100

    
1101
		if (showadvdns) {
1102
			text = "<?=gettext('Hide Advanced');?>";
1103
		} else {
1104
			text = "<?=gettext('Display Advanced');?>";
1105
		}
1106
		$('#btnadvdns').html('<i class="fa fa-cog"></i> ' + text);
1107
	}
1108

    
1109
	$('#btnadvdns').click(function(event) {
1110
		show_advdns();
1111
	});
1112

    
1113
	// Show advanced NTP options ======================================================================================
1114
	var showadvntp = false;
1115

    
1116
	function show_advntp(ispageload) {
1117
		var text;
1118
		// On page load decide the initial state based on the data.
1119
		if (ispageload) {
1120
<?php
1121
			if (empty($pconfig['ntp1']) && empty($pconfig['ntp2'])) {
1122
				$showadv = false;
1123
			} else {
1124
				$showadv = true;
1125
			}
1126
?>
1127
			showadvntp = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1128
		} else {
1129
			// It was a click, swap the state.
1130
			showadvntp = !showadvntp;
1131
		}
1132

    
1133
		hideInput('ntp1', !showadvntp);
1134
		hideInput('ntp2', !showadvntp);
1135

    
1136
		if (showadvntp) {
1137
			text = "<?=gettext('Hide Advanced');?>";
1138
		} else {
1139
			text = "<?=gettext('Display Advanced');?>";
1140
		}
1141
		$('#btnadvntp').html('<i class="fa fa-cog"></i> ' + text);
1142
	}
1143

    
1144
	$('#btnadvntp').click(function(event) {
1145
		show_advntp();
1146
	});
1147

    
1148
	// Show advanced LDAP options ======================================================================================
1149
	var showadvldap = false;
1150

    
1151
	function show_advldap(ispageload) {
1152
		var text;
1153
		// On page load decide the initial state based on the data.
1154
		if (ispageload) {
1155
<?php
1156
			if (empty($pconfig['ldap'])) {
1157
				$showadv = false;
1158
			} else {
1159
				$showadv = true;
1160
			}
1161
?>
1162
			showadvldap = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1163
		} else {
1164
			// It was a click, swap the state.
1165
			showadvldap = !showadvldap;
1166
		}
1167

    
1168
		hideInput('ldap', !showadvldap);
1169

    
1170
		if (showadvldap) {
1171
			text = "<?=gettext('Hide Advanced');?>";
1172
		} else {
1173
			text = "<?=gettext('Display Advanced');?>";
1174
		}
1175
		$('#btnadvldap').html('<i class="fa fa-cog"></i> ' + text);
1176
	}
1177

    
1178
	$('#btnadvldap').click(function(event) {
1179
		show_advldap();
1180
	});
1181

    
1182
	// Show advanced Netboot options ======================================================================================
1183
	var showadvnetboot = false;
1184

    
1185
	function show_advnetboot(ispageload) {
1186
		var text;
1187
		// On page load decide the initial state based on the data.
1188
		if (ispageload) {
1189
<?php
1190
			if (!$pconfig['shownetboot'] && empty($pconfig['bootfile_url'])) {
1191
				$showadv = false;
1192
			} else {
1193
				$showadv = true;
1194
			}
1195
?>
1196
			showadvnetboot = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1197
		} else {
1198
			// It was a click, swap the state.
1199
			showadvnetboot = !showadvnetboot;
1200
		}
1201

    
1202
		hideCheckbox('shownetboot', !showadvnetboot);
1203
		hideInput('bootfile_url', !showadvnetboot);
1204

    
1205
		if (showadvnetboot) {
1206
			text = "<?=gettext('Hide Advanced');?>";
1207
		} else {
1208
			text = "<?=gettext('Display Advanced');?>";
1209
		}
1210
		$('#btnadvnetboot').html('<i class="fa fa-cog"></i> ' + text);
1211
	}
1212

    
1213
	$('#btnadvnetboot').click(function(event) {
1214
		show_advnetboot();
1215
	});
1216

    
1217
	// Show advanced additional opts options ===========================================================================
1218
	var showadvopts = false;
1219

    
1220
	function show_advopts(ispageload) {
1221
		var text;
1222
		// On page load decide the initial state based on the data.
1223
		if (ispageload) {
1224
<?php
1225
			if (empty($pconfig['numberoptions']) ||
1226
			    (empty($pconfig['numberoptions']['item'][0]['number']) && (empty($pconfig['numberoptions']['item'][0]['value'])))) {
1227
				$showadv = false;
1228
			} else {
1229
				$showadv = true;
1230
			}
1231
?>
1232
			showadvopts = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1233
		} else {
1234
			// It was a click, swap the state.
1235
			showadvopts = !showadvopts;
1236
		}
1237

    
1238
		hideClass('adnloptions', !showadvopts);
1239
		hideInput('addrow', !showadvopts);
1240

    
1241
		if (showadvopts) {
1242
			text = "<?=gettext('Hide Advanced');?>";
1243
		} else {
1244
			text = "<?=gettext('Display Advanced');?>";
1245
		}
1246
		$('#btnadvopts').html('<i class="fa fa-cog"></i> ' + text);
1247
	}
1248

    
1249
	$('#btnadvopts').click(function(event) {
1250
		show_advopts();
1251
		checkLastRow();
1252
	});
1253

    
1254
	$('#enable').click(function() {
1255
	    do_toggle();
1256
	});
1257

    
1258
	function do_toggle() {
1259
		if ($('#enable').prop('checked')) {
1260
			$('.form-group:not(:first-child)').show();
1261
			hideClass('adnloptions', <?php echo json_encode($noopts); ?>);
1262
			hideInput('addrow', <?php echo json_encode($noopts); ?>);
1263
		} else {
1264
			$('.form-group:not(:first-child)').hide();
1265
		}
1266
	}
1267

    
1268
	// On initial load
1269
	do_toggle();
1270
	show_advdns(true);
1271
	show_advntp(true);
1272
	show_advldap(true);
1273
	show_advnetboot(true);
1274
	show_advopts(true);
1275
	if ($('#enable').prop('checked')) {
1276
		hideClass('adnloptions', <?php echo json_encode($noopts); ?>);
1277
		hideInput('addrow', <?php echo json_encode($noopts); ?>);
1278
	} else {
1279
		hideClass('adnloptions', true);
1280
		hideInput('addrow', true);
1281
	}
1282

    
1283
});
1284
//]]>
1285
</script>
1286

    
1287
<?php include('foot.inc');
(121-121/225)