Project

General

Profile

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

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

    
66
require_once("guiconfig.inc");
67
require_once("filter.inc");
68

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

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

    
110
$if = $_GET['if'];
111
if ($_POST['if']) {
112
	$if = $_POST['if'];
113
}
114

    
115
/* if OLSRD is enabled, allow WAN to house DHCP. */
116
if ($config['installedpackages']['olsrd']) {
117
	foreach ($config['installedpackages']['olsrd']['config'] as $olsrd) {
118
		if ($olsrd['enable']) {
119
			$is_olsr_enabled = true;
120
			break;
121
		}
122
	}
123
}
124

    
125
$iflist = get_configured_interface_with_descr();
126
$iflist = array_merge($iflist, get_configured_pppoe_server_interfaces());
127

    
128
/* set the starting interface */
129
if (!$if || !isset($iflist[$if])) {
130
	foreach ($iflist as $ifent => $ifname) {
131
		$oc = $config['interfaces'][$ifent];
132
		$valid_if_ipaddrv6 = (bool) ($oc['ipaddrv6'] == 'track6' ||
133
		    (is_ipaddrv6($oc['ipaddrv6']) &&
134
		    !is_linklocal($oc['ipaddrv6'])));
135

    
136
		if ((!is_array($config['dhcpdv6'][$ifent]) ||
137
		    !isset($config['dhcpdv6'][$ifent]['enable'])) &&
138
		    !$valid_if_ipaddrv6) {
139
			continue;
140
		}
141
		$if = $ifent;
142
		break;
143
	}
144
}
145

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

    
186
if ($config['interfaces'][$if]['ipaddrv6'] == 'track6') {
187
	$trackifname = $config['interfaces'][$if]['track6-interface'];
188
	$trackcfg = $config['interfaces'][$trackifname];
189
	$ifcfgsn = "64";
190
	$ifcfgip = '::';
191

    
192
	$str_help_mask = dhcpv6_pd_str_help($ifcfgsn);
193
} else {
194
	$ifcfgip = get_interface_ipv6($if);
195
	$ifcfgsn = get_interface_subnetv6($if);
196
}
197

    
198
/*	 set the enabled flag which will tell us if DHCP relay is enabled
199
 *	 on any interface. We will use this to disable DHCP server since
200
 *	 the two are not compatible with each other.
201
 */
202

    
203
$dhcrelay_enabled = false;
204
$dhcrelaycfg = $config['dhcrelay6'];
205

    
206
if (is_array($dhcrelaycfg) && isset($dhcrelaycfg['enable']) && isset($dhcrelaycfg['interface']) && !empty($dhcrelaycfg['interface'])) {
207
	$dhcrelayifs = explode(",", $dhcrelaycfg['interface']);
208

    
209
	foreach ($dhcrelayifs as $dhcrelayif) {
210

    
211
		if (isset($iflist[$dhcrelayif]) && (!link_interface_to_bridge($dhcrelayif))) {
212
			$dhcrelay_enabled = true;
213
			break;
214
		}
215
	}
216
}
217

    
218
if (isset($_POST['apply'])) {
219
	$savemsg = dhcpv6_apply_changes(false);
220
} elseif (isset($_POST['save'])) {
221
	unset($input_errors);
222

    
223
	$old_dhcpdv6_enable = ($pconfig['enable'] == true);
224
	$new_dhcpdv6_enable = ($_POST['enable'] ? true : false);
225
	$dhcpdv6_enable_changed = ($old_dhcpdv6_enable != $new_dhcpdv6_enable);
226

    
227
	$pconfig = $_POST;
228

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

    
241
	/* input validation */
242
	if ($_POST['enable']) {
243
		$reqdfields = explode(" ", "range_from range_to");
244
		$reqdfieldsn = array(gettext("Range begin"), gettext("Range end"));
245

    
246
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
247

    
248
		if (($_POST['prefixrange_from'] && !is_ipaddrv6($_POST['prefixrange_from']))) {
249
			$input_errors[] = gettext("A valid prefix range must be specified.");
250
		}
251
		if (($_POST['prefixrange_to'] && !is_ipaddrv6($_POST['prefixrange_to']))) {
252
			$input_errors[] = gettext("A valid prefix range must be specified.");
253
		}
254

    
255
		if ($_POST['prefixrange_from'] && $_POST['prefixrange_to'] &&
256
		    $_POST['prefixrange_length']) {
257
			$netmask = Net_IPv6::getNetmask($_POST['prefixrange_from'],
258
			    $_POST['prefixrange_length']);
259
			$netmask = Net_IPv6::compress($netmask);
260

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

    
268
			$netmask = Net_IPv6::getNetmask($_POST['prefixrange_to'],
269
			    $_POST['prefixrange_length']);
270
			$netmask = Net_IPv6::compress($netmask);
271

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

    
280
		$range_from_to_ok = true;
281

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

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

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

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

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

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

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

    
395

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

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

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

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

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

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

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

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

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

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

    
484
		$config['dhcpdv6'][$if]['numberoptions'] = $numberoptions;
485

    
486
		write_config();
487

    
488
		$savemsg = dhcpv6_apply_changes($dhcpdv6_enable_changed);
489
	}
490
}
491

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

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

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

    
515
include("head.inc");
516

    
517
if ($input_errors) {
518
	print_input_errors($input_errors);
519
}
520

    
521
if ($savemsg) {
522
	print_info_box($savemsg, 'success');
523
}
524

    
525
if ($dhcrelay_enabled) {
526
	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);
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
if ($dhcrelay_enabled) {
594
	include("foot.inc");
595
	exit;
596
}
597

    
598
$form = new Form();
599

    
600
$section = new Form_Section('DHCPv6 Options');
601

    
602
$section->addInput(new Form_Checkbox(
603
	'enable',
604
	'DHCPv6 Server',
605
	'Enable DHCPv6 server on interface ' . $iflist[$if],
606
	$pconfig['enable']
607
));
608

    
609
if (is_ipaddrv6($ifcfgip)) {
610

    
611
	if ($ifcfgip == "::") {
612
		$sntext = "Prefix Delegation";
613
	} else {
614
		$sntext = gen_subnetv6($ifcfgip, $ifcfgsn);
615
	}
616
	$section->addInput(new Form_StaticText(
617
		'Subnet',
618
		$sntext
619
		));
620

    
621
	$section->addInput(new Form_StaticText(
622
		'Subnet Mask',
623
		$ifcfgsn . ' bits'
624
		));
625

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

    
632
if ($is_olsr_enabled) {
633
	$section->addInput(new Form_Select(
634
	'netmask',
635
	'Subnet Mask',
636
	$pconfig['netmask'],
637
	array_combine(range(128, 1, -1), range(128, 1, -1))
638
	));
639
}
640

    
641
$f1 = new Form_Input(
642
	'range_from',
643
	null,
644
	'text',
645
	$pconfig['range_from']
646
);
647

    
648
$f1->setHelp('From');
649

    
650
$f2 = new Form_Input(
651
	'range_to',
652
	null,
653
	'text',
654
	$pconfig['range_to']
655
);
656

    
657
$f2->setHelp('To');
658

    
659
$group = new Form_Group('Range');
660

    
661
$group->add($f1);
662
$group->add($f2);
663

    
664
$section->add($group);
665

    
666
$f1 = new Form_Input(
667
	'prefixrange_from',
668
	null,
669
	'text',
670
	$pconfig['prefixrange_from']
671
);
672

    
673
$f1->setHelp('From');
674

    
675
$f2 = new Form_Input(
676
	'prefixrange_to',
677
	null,
678
	'text',
679
	$pconfig['prefixrange_to']
680
);
681

    
682
$f2->setHelp('To');
683

    
684
$group = new Form_Group('Prefix Delegation Range');
685

    
686
$group->add($f1);
687
$group->add($f2);
688

    
689
$section->add($group);
690

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

    
706
$group = new Form_Group('DNS Servers');
707

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

    
718
$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.');
719
$section->add($group);
720

    
721
$section->addInput(new Form_Input(
722
	'domain',
723
	'Domain name',
724
	'text',
725
	$pconfig['domain']
726
))->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. ');
727

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

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

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

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

    
760
$btnadv = new Form_Button(
761
	'btnadvdns',
762
	'Display Advanced',
763
	null,
764
	'fa-cog'
765
);
766

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

    
769
$section->addInput(new Form_StaticText(
770
	'Dynamic DNS',
771
	$btnadv
772
));
773

    
774
$section->addInput(new Form_Checkbox(
775
	'ddnsupdate',
776
	'DHCP Registration',
777
	'Enable registration of DHCP client names in DNS.',
778
	$pconfig['ddnsupdate']
779
));
780

    
781
$section->addInput(new Form_Input(
782
	'ddnsdomain',
783
	'DDNS Domain',
784
	'text',
785
	$pconfig['ddnsdomain']
786
))->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.');
787

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

    
795
$section->addInput(new Form_IpAddress(
796
	'ddnsdomainprimary',
797
	'DDNS Server IP',
798
	$pconfig['ddnsdomainprimary'],
799
	'V4'
800
))->setHelp('Enter the primary domain name server IPv4 address for the dynamic domain name.');
801

    
802
$section->addInput(new Form_Input(
803
	'ddnsdomainkeyname',
804
	'DDNS Domain Key name',
805
	'text',
806
	$pconfig['ddnsdomainkeyname']
807
))->setHelp('Enter the dynamic DNS domain key name which will be used to register client names in the DNS server.');
808

    
809
$section->addInput(new Form_Input(
810
	'ddnsdomainkey',
811
	'DDNS Domain Key secret',
812
	'text',
813
	$pconfig['ddnsdomainkey']
814
))->setHelp('Enter the dynamic DNS domain key secret which will be used to register client names in the DNS server.');
815

    
816
$section->addInput(new Form_Select(
817
	'ddnsclientupdates',
818
	'DDNS Client Updates',
819
	$pconfig['ddnsclientupdates'],
820
	array(
821
	    'allow' => gettext('Allow'),
822
	    'deny' => gettext('Deny'),
823
	    'ignore' => gettext('Ignore'))
824
))->setHelp('How Forward entries are handled when client indicates they wish to update DNS.  ' .
825
	    'Allow prevents DHCP from updating Forward entries, Deny indicates that DHCP will ' .
826
	    'do the updates and the client should not, Ignore specifies that DHCP will do the ' .
827
	    'update and the client can also attempt the update usually using a different domain name.');
828

    
829
$section->addInput(new Form_Checkbox(
830
	'ddnsreverse',
831
	'DDNS Reverse',
832
	'Add reverse dynamic DNS entries.',
833
	$pconfig['ddnsreverse']
834
));
835

    
836
$btnadv = new Form_Button(
837
	'btnadvntp',
838
	'Display Advanced',
839
	null,
840
	'fa-cog'
841
);
842

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

    
845
$section->addInput(new Form_StaticText(
846
	'NTP servers',
847
	$btnadv
848
));
849

    
850
$group = new Form_Group('NTP Servers');
851

    
852
$group->add(new Form_Input(
853
	'ntp1',
854
	'NTP Server 1',
855
	'text',
856
	$pconfig['ntp1'],
857
	['placeholder' => 'NTP 1']
858
));
859

    
860
$group->add(new Form_Input(
861
	'ntp2',
862
	'NTP Server 2',
863
	'text',
864
	$pconfig['ntp2'],
865
	['placeholder' => 'NTP 2']
866
));
867

    
868
$group->addClass('ntpclass');
869

    
870
$section->add($group);
871

    
872
$btnadv = new Form_Button(
873
	'btnadvldap',
874
	'Display Advanced',
875
	null,
876
	'fa-cog'
877
);
878

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

    
881
$section->addInput(new Form_StaticText(
882
	'LDAP',
883
	$btnadv
884
));
885

    
886
$section->addInput(new Form_Input(
887
	'ldap',
888
	'LDAP URI',
889
	'text',
890
	$pconfig['ldap']
891
));
892

    
893
$btnadv = new Form_Button(
894
	'btnadvnetboot',
895
	'Display Advanced',
896
	null,
897
	'fa-cog'
898
);
899

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

    
902
$section->addInput(new Form_StaticText(
903
	'Network booting',
904
	$btnadv
905
));
906

    
907
$section->addInput(new Form_Checkbox(
908
	'shownetboot',
909
	'Network booting',
910
	'Enable Network Booting',
911
	$pconfig['shownetboot']
912
));
913

    
914
$section->addInput(new Form_Input(
915
	'bootfile_url',
916
	'Bootfile URL',
917
	'text',
918
	$pconfig['bootfile_url']
919
));
920

    
921
$btnadv = new Form_Button(
922
	'btnadvopts',
923
	'Display Advanced',
924
	null,
925
	'fa-cog'
926
);
927

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

    
930
$section->addInput(new Form_StaticText(
931
	'Additional BOOTP/DHCP Options',
932
	$btnadv
933
));
934

    
935
$form->add($section);
936

    
937
$title = 'Show Additional BOOTP/DHCP Options';
938

    
939
if (!$pconfig['numberoptions']) {
940
	$noopts = true;
941
	$pconfig['numberoptions']['item'] = array(0 => array('number' => "", 'value' => ""));
942
} else {
943
	$noopts = false;
944
}
945

    
946
$counter = 0;
947
$last = count($pconfig['numberoptions']['item']) - 1;
948

    
949
foreach ($pconfig['numberoptions']['item'] as $item) {
950
	$group = new Form_Group(null);
951
	$group->addClass('repeatable');
952
	$group->addClass('adnloptions');
953

    
954
	$group->add(new Form_Input(
955
		'number' . $counter,
956
		null,
957
		'text',
958
		$item['number']
959
	))->setHelp($counter == $last ? 'Number':null);
960

    
961
	$group->add(new Form_Input(
962
		'value' . $counter,
963
		null,
964
		'text',
965
		base64_decode($item['value'])
966
	))->setHelp($counter == $last ? 'Value':null);
967

    
968
	$btn = new Form_Button(
969
		'deleterow' . $counter,
970
		'Delete',
971
		null,
972
		'fa-trash'
973
	);
974

    
975
	$btn->addClass('btn-warning');
976
	$group->add($btn);
977
	$section->add($group);
978
	$counter++;
979
}
980

    
981

    
982
$btnaddopt = new Form_Button(
983
	'addrow',
984
	'Add Option',
985
	null,
986
	'fa-plus'
987
);
988

    
989
$btnaddopt->removeClass('btn-primary')->addClass('btn-success btn-sm');
990

    
991
$section->addInput($btnaddopt);
992

    
993
$section->addInput(new Form_Input(
994
	'if',
995
	null,
996
	'hidden',
997
	$if
998
));
999

    
1000
print($form);
1001

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

    
1069
<nav class="action-buttons">
1070
	<a href="services_dhcpv6_edit.php?if=<?=$if?>" class="btn btn-sm btn-success"/>
1071
		<i class="fa fa-plus icon-embed-btn"></i>
1072
		<?=gettext("Add")?>
1073
	</a>
1074
</nav>
1075

    
1076
<script type="text/javascript">
1077
//<![CDATA[
1078
events.push(function() {
1079

    
1080
	// Show advanced DNS options ======================================================================================
1081
	var showadvdns = false;
1082

    
1083
	function show_advdns(ispageload) {
1084
		var text;
1085
		// On page load decide the initial state based on the data.
1086
		if (ispageload) {
1087
<?php
1088
			if (!$pconfig['ddnsupdate'] &&
1089
			    !$pconfig['ddnsforcehostname'] &&
1090
			    empty($pconfig['ddnsdomain']) &&
1091
			    empty($pconfig['ddnsdomainprimary']) &&
1092
			    empty($pconfig['ddnsdomainkeyname']) &&
1093
			    empty($pconfig['ddnsdomainkey']) &&
1094
			    (empty($pconfig['ddnsclientupdates']) || ($pconfig['ddnsclientupdates'] == "allow")) &&
1095
			    !$pconfig['ddnsreverse']) {
1096
				$showadv = false;
1097
			} else {
1098
				$showadv = true;
1099
			}
1100
?>
1101
			showadvdns = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1102
		} else {
1103
			// It was a click, swap the state.
1104
			showadvdns = !showadvdns;
1105
		}
1106

    
1107
		hideCheckbox('ddnsupdate', !showadvdns);
1108
		hideInput('ddnsdomain', !showadvdns);
1109
		hideCheckbox('ddnsforcehostname', !showadvdns);
1110
		hideInput('ddnsdomainprimary', !showadvdns);
1111
		hideInput('ddnsdomainkeyname', !showadvdns);
1112
		hideInput('ddnsdomainkey', !showadvdns);
1113
		hideInput('ddnsclientupdates', !showadvdns);
1114
		hideCheckbox('ddnsreverse', !showadvdns);
1115

    
1116
		if (showadvdns) {
1117
			text = "<?=gettext('Hide Advanced');?>";
1118
		} else {
1119
			text = "<?=gettext('Display Advanced');?>";
1120
		}
1121
		$('#btnadvdns').html('<i class="fa fa-cog"></i> ' + text);
1122
	}
1123

    
1124
	$('#btnadvdns').click(function(event) {
1125
		show_advdns();
1126
	});
1127

    
1128
	// Show advanced NTP options ======================================================================================
1129
	var showadvntp = false;
1130

    
1131
	function show_advntp(ispageload) {
1132
		var text;
1133
		// On page load decide the initial state based on the data.
1134
		if (ispageload) {
1135
<?php
1136
			if (empty($pconfig['ntp1']) && empty($pconfig['ntp2'])) {
1137
				$showadv = false;
1138
			} else {
1139
				$showadv = true;
1140
			}
1141
?>
1142
			showadvntp = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1143
		} else {
1144
			// It was a click, swap the state.
1145
			showadvntp = !showadvntp;
1146
		}
1147

    
1148
		hideInput('ntp1', !showadvntp);
1149
		hideInput('ntp2', !showadvntp);
1150

    
1151
		if (showadvntp) {
1152
			text = "<?=gettext('Hide Advanced');?>";
1153
		} else {
1154
			text = "<?=gettext('Display Advanced');?>";
1155
		}
1156
		$('#btnadvntp').html('<i class="fa fa-cog"></i> ' + text);
1157
	}
1158

    
1159
	$('#btnadvntp').click(function(event) {
1160
		show_advntp();
1161
	});
1162

    
1163
	// Show advanced LDAP options ======================================================================================
1164
	var showadvldap = false;
1165

    
1166
	function show_advldap(ispageload) {
1167
		var text;
1168
		// On page load decide the initial state based on the data.
1169
		if (ispageload) {
1170
<?php
1171
			if (empty($pconfig['ldap'])) {
1172
				$showadv = false;
1173
			} else {
1174
				$showadv = true;
1175
			}
1176
?>
1177
			showadvldap = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1178
		} else {
1179
			// It was a click, swap the state.
1180
			showadvldap = !showadvldap;
1181
		}
1182

    
1183
		hideInput('ldap', !showadvldap);
1184

    
1185
		if (showadvldap) {
1186
			text = "<?=gettext('Hide Advanced');?>";
1187
		} else {
1188
			text = "<?=gettext('Display Advanced');?>";
1189
		}
1190
		$('#btnadvldap').html('<i class="fa fa-cog"></i> ' + text);
1191
	}
1192

    
1193
	$('#btnadvldap').click(function(event) {
1194
		show_advldap();
1195
	});
1196

    
1197
	// Show advanced Netboot options ======================================================================================
1198
	var showadvnetboot = false;
1199

    
1200
	function show_advnetboot(ispageload) {
1201
		var text;
1202
		// On page load decide the initial state based on the data.
1203
		if (ispageload) {
1204
<?php
1205
			if (!$pconfig['shownetboot'] && empty($pconfig['bootfile_url'])) {
1206
				$showadv = false;
1207
			} else {
1208
				$showadv = true;
1209
			}
1210
?>
1211
			showadvnetboot = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1212
		} else {
1213
			// It was a click, swap the state.
1214
			showadvnetboot = !showadvnetboot;
1215
		}
1216

    
1217
		hideCheckbox('shownetboot', !showadvnetboot);
1218
		hideInput('bootfile_url', !showadvnetboot);
1219

    
1220
		if (showadvnetboot) {
1221
			text = "<?=gettext('Hide Advanced');?>";
1222
		} else {
1223
			text = "<?=gettext('Display Advanced');?>";
1224
		}
1225
		$('#btnadvnetboot').html('<i class="fa fa-cog"></i> ' + text);
1226
	}
1227

    
1228
	$('#btnadvnetboot').click(function(event) {
1229
		show_advnetboot();
1230
	});
1231

    
1232
	// Show advanced additional opts options ===========================================================================
1233
	var showadvopts = false;
1234

    
1235
	function show_advopts(ispageload) {
1236
		var text;
1237
		// On page load decide the initial state based on the data.
1238
		if (ispageload) {
1239
<?php
1240
			if (empty($pconfig['numberoptions']) ||
1241
			    (empty($pconfig['numberoptions']['item'][0]['number']) && (empty($pconfig['numberoptions']['item'][0]['value'])))) {
1242
				$showadv = false;
1243
			} else {
1244
				$showadv = true;
1245
			}
1246
?>
1247
			showadvopts = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1248
		} else {
1249
			// It was a click, swap the state.
1250
			showadvopts = !showadvopts;
1251
		}
1252

    
1253
		hideClass('adnloptions', !showadvopts);
1254
		hideInput('addrow', !showadvopts);
1255

    
1256
		if (showadvopts) {
1257
			text = "<?=gettext('Hide Advanced');?>";
1258
		} else {
1259
			text = "<?=gettext('Display Advanced');?>";
1260
		}
1261
		$('#btnadvopts').html('<i class="fa fa-cog"></i> ' + text);
1262
	}
1263

    
1264
	$('#btnadvopts').click(function(event) {
1265
		show_advopts();
1266
		checkLastRow();
1267
	});
1268

    
1269
	$('#enable').click(function() {
1270
	    do_toggle();
1271
	});
1272

    
1273
	function do_toggle() {
1274
		if ($('#enable').prop('checked')) {
1275
			$('.form-group:not(:first-child)').show();
1276
			hideClass('adnloptions', <?php echo json_encode($noopts); ?>);
1277
			hideInput('addrow', <?php echo json_encode($noopts); ?>);
1278
		} else {
1279
			$('.form-group:not(:first-child)').hide();
1280
		}
1281
	}
1282

    
1283
	// On initial load
1284
	do_toggle();
1285
	show_advdns(true);
1286
	show_advntp(true);
1287
	show_advldap(true);
1288
	show_advnetboot(true);
1289
	show_advopts(true);
1290
	if ($('#enable').prop('checked')) {
1291
		hideClass('adnloptions', <?php echo json_encode($noopts); ?>);
1292
		hideInput('addrow', <?php echo json_encode($noopts); ?>);
1293
	} else {
1294
		hideClass('adnloptions', true);
1295
		hideInput('addrow', true);
1296
	}
1297

    
1298
});
1299
//]]>
1300
</script>
1301

    
1302
<?php include('foot.inc');
(122-122/227)