Project

General

Profile

Download (31.1 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
if (!$g['services_dhcp_server_enable']) {
71
	header("Location: /");
72
	exit;
73
}
74

    
75
/*	Fix failover DHCP problem
76
 *	http://article.gmane.org/gmane.comp.security.firewalls.pfsense.support/18749
77
 */
78
ini_set("memory_limit", "64M");
79

    
80
$if = $_GET['if'];
81
if ($_POST['if']) {
82
	$if = $_POST['if'];
83
}
84

    
85
/* if OLSRD is enabled, allow WAN to house DHCP. */
86
if ($config['installedpackages']['olsrd']) {
87
	foreach ($config['installedpackages']['olsrd']['config'] as $olsrd) {
88
		if ($olsrd['enable']) {
89
			$is_olsr_enabled = true;
90
			break;
91
		}
92
	}
93
}
94

    
95
$iflist = get_configured_interface_with_descr();
96
$iflist = array_merge($iflist, get_configured_pppoe_server_interfaces());
97

    
98
/* set the starting interface */
99
if (!$if || !isset($iflist[$if])) {
100
	foreach ($iflist as $ifent => $ifname) {
101
		$oc = $config['interfaces'][$ifent];
102

    
103
		if ((is_array($config['dhcpdv6'][$ifent]) && !isset($config['dhcpdv6'][$ifent]['enable']) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6'])))) ||
104
		    (!is_array($config['dhcpdv6'][$ifent]) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6']))))) {
105
			continue;
106
		}
107
		$if = $ifent;
108
		break;
109
	}
110
}
111

    
112
if (is_array($config['dhcpdv6'][$if])) {
113
	/* DHCPv6 */
114
	if (is_array($config['dhcpdv6'][$if]['range'])) {
115
		$pconfig['range_from'] = $config['dhcpdv6'][$if]['range']['from'];
116
		$pconfig['range_to'] = $config['dhcpdv6'][$if]['range']['to'];
117
	}
118
	if (is_array($config['dhcpdv6'][$if]['prefixrange'])) {
119
		$pconfig['prefixrange_from'] = $config['dhcpdv6'][$if]['prefixrange']['from'];
120
		$pconfig['prefixrange_to'] = $config['dhcpdv6'][$if]['prefixrange']['to'];
121
		$pconfig['prefixrange_length'] = $config['dhcpdv6'][$if]['prefixrange']['prefixlength'];
122
	}
123
	$pconfig['deftime'] = $config['dhcpdv6'][$if]['defaultleasetime'];
124
	$pconfig['maxtime'] = $config['dhcpdv6'][$if]['maxleasetime'];
125
	$pconfig['domain'] = $config['dhcpdv6'][$if]['domain'];
126
	$pconfig['domainsearchlist'] = $config['dhcpdv6'][$if]['domainsearchlist'];
127
	list($pconfig['wins1'], $pconfig['wins2']) = $config['dhcpdv6'][$if]['winsserver'];
128
	list($pconfig['dns1'], $pconfig['dns2'], $pconfig['dns3'], $pconfig['dns4']) = $config['dhcpdv6'][$if]['dnsserver'];
129
	$pconfig['enable'] = isset($config['dhcpdv6'][$if]['enable']);
130
	$pconfig['ddnsdomain'] = $config['dhcpdv6'][$if]['ddnsdomain'];
131
	$pconfig['ddnsdomainprimary'] = $config['dhcpdv6'][$if]['ddnsdomainprimary'];
132
	$pconfig['ddnsdomainkeyname'] = $config['dhcpdv6'][$if]['ddnsdomainkeyname'];
133
	$pconfig['ddnsdomainkey'] = $config['dhcpdv6'][$if]['ddnsdomainkey'];
134
	$pconfig['ddnsupdate'] = isset($config['dhcpdv6'][$if]['ddnsupdate']);
135
	list($pconfig['ntp1'], $pconfig['ntp2']) = $config['dhcpdv6'][$if]['ntpserver'];
136
	$pconfig['tftp'] = $config['dhcpdv6'][$if]['tftp'];
137
	$pconfig['ldap'] = $config['dhcpdv6'][$if]['ldap'];
138
	$pconfig['netboot'] = isset($config['dhcpdv6'][$if]['netboot']);
139
	$pconfig['bootfile_url'] = $config['dhcpdv6'][$if]['bootfile_url'];
140
	$pconfig['netmask'] = $config['dhcpdv6'][$if]['netmask'];
141
	$pconfig['numberoptions'] = $config['dhcpdv6'][$if]['numberoptions'];
142
	$pconfig['dhcpv6leaseinlocaltime'] = $config['dhcpdv6'][$if]['dhcpv6leaseinlocaltime'];
143
	if (!is_array($config['dhcpdv6'][$if]['staticmap'])) {
144
		$config['dhcpdv6'][$if]['staticmap'] = array();
145
	}
146
	$a_maps = &$config['dhcpdv6'][$if]['staticmap'];
147
}
148

    
149
$ifcfgip = get_interface_ipv6($if);
150
$ifcfgsn = get_interface_subnetv6($if);
151

    
152
/*	 set the enabled flag which will tell us if DHCP relay is enabled
153
 *	 on any interface. We will use this to disable DHCP server since
154
 *	 the two are not compatible with each other.
155
 */
156

    
157
$dhcrelay_enabled = false;
158
$dhcrelaycfg = $config['dhcrelay6'];
159

    
160
if (is_array($dhcrelaycfg)) {
161
	foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) {
162
		if (isset($dhcrelayifconf['enable']) && isset($iflist[$dhcrelayif]) &&
163
		    (!link_interface_to_bridge($dhcrelayif))) {
164
			$dhcrelay_enabled = true;
165
		}
166
	}
167
}
168

    
169
if ($_POST) {
170
	unset($input_errors);
171

    
172
	$old_dhcpdv6_enable = ($pconfig['enable'] == true);
173
	$new_dhcpdv6_enable = ($_POST['enable'] ? true : false);
174
	$dhcpdv6_enable_changed = ($old_dhcpdv6_enable != $new_dhcpdv6_enable);
175

    
176
	$pconfig = $_POST;
177

    
178
	$numberoptions = array();
179
	for ($x = 0; $x < 99; $x++) {
180
		if (isset($_POST["number{$x}"]) && ctype_digit($_POST["number{$x}"])) {
181
			$numbervalue = array();
182
			$numbervalue['number'] = htmlspecialchars($_POST["number{$x}"]);
183
			$numbervalue['value'] = base64_encode($_POST["value{$x}"]);
184
			$numberoptions['item'][] = $numbervalue;
185
		}
186
	}
187
	// Reload the new pconfig variable that the forum uses.
188
	$pconfig['numberoptions'] = $numberoptions;
189

    
190
	/* input validation */
191
	if ($_POST['enable']) {
192
		$reqdfields = explode(" ", "range_from range_to");
193
		$reqdfieldsn = array(gettext("Range begin"), gettext("Range end"));
194

    
195
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
196

    
197
		if (($_POST['prefixrange_from'] && !is_ipaddrv6($_POST['prefixrange_from']))) {
198
			$input_errors[] = gettext("A valid prefix range must be specified.");
199
		}
200
		if (($_POST['prefixrange_to'] && !is_ipaddrv6($_POST['prefixrange_to']))) {
201
			$input_errors[] = gettext("A valid prefix range must be specified.");
202
		}
203
		if (($_POST['range_from'] && !is_ipaddrv6($_POST['range_from']))) {
204
			$input_errors[] = gettext("A valid range must be specified.");
205
		}
206
		if (($_POST['range_to'] && !is_ipaddrv6($_POST['range_to']))) {
207
			$input_errors[] = gettext("A valid range must be specified.");
208
		}
209
		if (($_POST['gateway'] && !is_ipaddrv6($_POST['gateway']))) {
210
			$input_errors[] = gettext("A valid IPv6 address must be specified for the gateway.");
211
		}
212
		if (($_POST['dns1'] && !is_ipaddrv6($_POST['dns1'])) ||
213
		    ($_POST['dns2'] && !is_ipaddrv6($_POST['dns2'])) ||
214
		    ($_POST['dns3'] && !is_ipaddrv6($_POST['dns3'])) ||
215
		    ($_POST['dns4'] && !is_ipaddrv6($_POST['dns4']))) {
216
			$input_errors[] = gettext("A valid IPv6 address must be specified for each of the DNS servers.");
217
		}
218

    
219
		if ($_POST['deftime'] && (!is_numeric($_POST['deftime']) || ($_POST['deftime'] < 60))) {
220
			$input_errors[] = gettext("The default lease time must be at least 60 seconds.");
221
		}
222
		if ($_POST['maxtime'] && (!is_numeric($_POST['maxtime']) || ($_POST['maxtime'] < 60) || ($_POST['maxtime'] <= $_POST['deftime']))) {
223
			$input_errors[] = gettext("The maximum lease time must be at least 60 seconds and higher than the default lease time.");
224
		}
225
		if (($_POST['ddnsdomain'] && !is_domain($_POST['ddnsdomain']))) {
226
			$input_errors[] = gettext("A valid domain name must be specified for the dynamic DNS registration.");
227
		}
228
		if (($_POST['ddnsdomain'] && !is_ipaddrv4($_POST['ddnsdomainprimary']))) {
229
			$input_errors[] = gettext("A valid primary domain name server IPv4 address must be specified for the dynamic domain name.");
230
		}
231
		if (($_POST['ddnsdomainkey'] && !$_POST['ddnsdomainkeyname']) ||
232
		    ($_POST['ddnsdomainkeyname'] && !$_POST['ddnsdomainkey'])) {
233
			$input_errors[] = gettext("You must specify both a valid domain key and key name.");
234
		}
235
		if ($_POST['domainsearchlist']) {
236
			$domain_array=preg_split("/[ ;]+/", $_POST['domainsearchlist']);
237
			foreach ($domain_array as $curdomain) {
238
				if (!is_domain($curdomain)) {
239
					$input_errors[] = gettext("A valid domain search list must be specified.");
240
					break;
241
				}
242
			}
243
		}
244

    
245
		if (($_POST['ntp1'] && !is_ipaddrv6($_POST['ntp1'])) || ($_POST['ntp2'] && !is_ipaddrv6($_POST['ntp2']))) {
246
			$input_errors[] = gettext("A valid IPv6 address must be specified for the primary/secondary NTP servers.");
247
		}
248
		if (($_POST['domain'] && !is_domain($_POST['domain']))) {
249
			$input_errors[] = gettext("A valid domain name must be specified for the DNS domain.");
250
		}
251
		if ($_POST['tftp'] && !is_ipaddr($_POST['tftp']) && !is_domain($_POST['tftp']) && !is_URL($_POST['tftp'])) {
252
			$input_errors[] = gettext("A valid IPv6 address or hostname must be specified for the TFTP server.");
253
		}
254
		if (($_POST['bootfile_url'] && !is_URL($_POST['bootfile_url']))) {
255
			$input_errors[] = gettext("A valid URL must be specified for the network bootfile.");
256
		}
257

    
258
		// Disallow a range that includes the virtualip
259
		if (is_array($config['virtualip']['vip'])) {
260
			foreach ($config['virtualip']['vip'] as $vip) {
261
				if ($vip['interface'] == $if) {
262
					if ($vip['subnetv6'] && is_inrange_v6($vip['subnetv6'], $_POST['range_from'], $_POST['range_to'])) {
263
						$input_errors[] = sprintf(gettext("The subnet range cannot overlap with virtual IPv6 address %s."), $vip['subnetv6']);
264
					}
265
				}
266
			}
267
		}
268

    
269
		$noip = false;
270
		if (is_array($a_maps)) {
271
			foreach ($a_maps as $map) {
272
				if (empty($map['ipaddrv6'])) {
273
					$noip = true;
274
				}
275
			}
276
		}
277
		if (!$input_errors) {
278
			/* make sure the range lies within the current subnet */
279
			$subnet_start = gen_subnetv6($ifcfgip, $ifcfgsn);
280
			$subnet_end = gen_subnetv6_max($ifcfgip, $ifcfgsn);
281

    
282
			if (is_ipaddrv6($ifcfgip)) {
283
				if ((!is_inrange_v6($_POST['range_from'], $subnet_start, $subnet_end)) ||
284
				    (!is_inrange_v6($_POST['range_to'], $subnet_start, $subnet_end))) {
285
					$input_errors[] = gettext("The specified range lies outside of the current subnet.");
286
				}
287
			}
288
			/* "from" cannot be higher than "to" */
289
			if (inet_pton($_POST['range_from']) > inet_pton($_POST['range_to'])) {
290
				$input_errors[] = gettext("The range is invalid (first element higher than second element).");
291
			}
292

    
293
			/* make sure that the DHCP Relay isn't enabled on this interface */
294
			if (isset($config['dhcrelay'][$if]['enable'])) {
295
				$input_errors[] = sprintf(gettext("You must disable the DHCP relay on the %s interface before enabling the DHCP server."), $iflist[$if]);
296
			}
297

    
298

    
299
			/* Verify static mappings do not overlap:
300
			   - available DHCP range
301
			   - prefix delegation range (FIXME: still need to be completed) */
302
			$dynsubnet_start = inet_pton($_POST['range_from']);
303
			$dynsubnet_end = inet_pton($_POST['range_to']);
304

    
305
			if (is_array($a_maps)) {
306
				foreach ($a_maps as $map) {
307
					if (empty($map['ipaddrv6'])) {
308
						continue;
309
					}
310
					if ((inet_pton($map['ipaddrv6']) > $dynsubnet_start) &&
311
					    (inet_pton($map['ipaddrv6']) < $dynsubnet_end)) {
312
						$input_errors[] = sprintf(gettext("The DHCP range cannot overlap any static DHCP mappings."));
313
						break;
314
					}
315
				}
316
			}
317
		}
318
	}
319

    
320
	if (!$input_errors) {
321
		if (!is_array($config['dhcpdv6'][$if])) {
322
			$config['dhcpdv6'][$if] = array();
323
		}
324
		if (!is_array($config['dhcpdv6'][$if]['range'])) {
325
			$config['dhcpdv6'][$if]['range'] = array();
326
		}
327
		if (!is_array($config['dhcpdv6'][$if]['prefixrange'])) {
328
			$config['dhcpdv6'][$if]['prefixrange'] = array();
329
		}
330

    
331
		$config['dhcpdv6'][$if]['range']['from'] = $_POST['range_from'];
332
		$config['dhcpdv6'][$if]['range']['to'] = $_POST['range_to'];
333
		$config['dhcpdv6'][$if]['prefixrange']['from'] = $_POST['prefixrange_from'];
334
		$config['dhcpdv6'][$if]['prefixrange']['to'] = $_POST['prefixrange_to'];
335
		$config['dhcpdv6'][$if]['prefixrange']['prefixlength'] = $_POST['prefixrange_length'];
336
		$config['dhcpdv6'][$if]['defaultleasetime'] = $_POST['deftime'];
337
		$config['dhcpdv6'][$if]['maxleasetime'] = $_POST['maxtime'];
338
		$config['dhcpdv6'][$if]['netmask'] = $_POST['netmask'];
339

    
340
		unset($config['dhcpdv6'][$if]['winsserver']);
341

    
342
		unset($config['dhcpdv6'][$if]['dnsserver']);
343
		if ($_POST['dns1']) {
344
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns1'];
345
		}
346
		if ($_POST['dns2']) {
347
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns2'];
348
		}
349
		if ($_POST['dns3']) {
350
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns3'];
351
		}
352
		if ($_POST['dns4']) {
353
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns4'];
354
		}
355

    
356
		$config['dhcpdv6'][$if]['domain'] = $_POST['domain'];
357
		$config['dhcpdv6'][$if]['domainsearchlist'] = $_POST['domainsearchlist'];
358
		$config['dhcpdv6'][$if]['enable'] = ($_POST['enable']) ? true : false;
359
		$config['dhcpdv6'][$if]['ddnsdomain'] = $_POST['ddnsdomain'];
360
		$config['dhcpdv6'][$if]['ddnsdomainprimary'] = $_POST['ddnsdomainprimary'];
361
		$config['dhcpdv6'][$if]['ddnsdomainkeyname'] = $_POST['ddnsdomainkeyname'];
362
		$config['dhcpdv6'][$if]['ddnsdomainkey'] = $_POST['ddnsdomainkey'];
363
		$config['dhcpdv6'][$if]['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
364

    
365
		unset($config['dhcpdv6'][$if]['ntpserver']);
366
		if ($_POST['ntp1']) {
367
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp1'];
368
		}
369
		if ($_POST['ntp2']) {
370
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp2'];
371
		}
372

    
373
		$config['dhcpdv6'][$if]['tftp'] = $_POST['tftp'];
374
		$config['dhcpdv6'][$if]['ldap'] = $_POST['ldap'];
375
		$config['dhcpdv6'][$if]['netboot'] = ($_POST['netboot']) ? true : false;
376
		$config['dhcpdv6'][$if]['bootfile_url'] = $_POST['bootfile_url'];
377
		$config['dhcpdv6'][$if]['dhcpv6leaseinlocaltime'] = $_POST['dhcpv6leaseinlocaltime'];
378

    
379
		// Handle the custom options rowhelper
380
		if (isset($config['dhcpdv6'][$if]['numberoptions']['item'])) {
381
			unset($config['dhcpdv6'][$if]['numberoptions']['item']);
382
		}
383

    
384
		$config['dhcpdv6'][$if]['numberoptions'] = $numberoptions;
385

    
386
		write_config();
387

    
388
		$retval = 0;
389
		$retvaldhcp = 0;
390
		$retvaldns = 0;
391
		/* Stop DHCPv6 so we can cleanup leases */
392
		killbypid("{$g['dhcpd_chroot_path']}{$g['varrun_path']}/dhcpdv6.pid");
393
		// dhcp_clean_leases();
394
		/* dnsmasq_configure calls dhcpd_configure */
395
		/* no need to restart dhcpd twice */
396
		if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstatic']))	{
397
			$retvaldns = services_dnsmasq_configure();
398
			if ($retvaldns == 0) {
399
				clear_subsystem_dirty('hosts');
400
				clear_subsystem_dirty('staticmaps');
401
			}
402
		} else if (isset($config['unbound']['enable']) && isset($config['unbound']['regdhcpstatic'])) {
403
			$retvaldns = services_unbound_configure();
404
			if ($retvaldns == 0) {
405
				clear_subsystem_dirty('unbound');
406
				clear_subsystem_dirty('staticmaps');
407
			}
408
		} else {
409
			$retvaldhcp = services_dhcpd_configure();
410
			if ($retvaldhcp == 0) {
411
				clear_subsystem_dirty('staticmaps');
412
			}
413
		}
414
		if ($dhcpdv6_enable_changed) {
415
			$retvalfc = filter_configure();
416
		}
417
		if ($retvaldhcp == 1 || $retvaldns == 1 || $retvalfc == 1) {
418
			$retval = 1;
419
		}
420
		$savemsg = get_std_save_message($retval);
421
	}
422
}
423

    
424
if ($_GET['act'] == "del") {
425
	if ($a_maps[$_GET['id']]) {
426
		unset($a_maps[$_GET['id']]);
427
		write_config();
428
		if (isset($config['dhcpdv6'][$if]['enable'])) {
429
			mark_subsystem_dirty('staticmapsv6');
430
			if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstaticv6'])) {
431
				mark_subsystem_dirty('hosts');
432
			}
433
		}
434
		header("Location: services_dhcpv6.php?if={$if}");
435
		exit;
436
	}
437
}
438

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

    
441
if (!empty($if) && !$dhcrelay_enabled && isset($iflist[$if])) {
442
	$pgtitle[] = $iflist[$if];
443
}
444
$pgtitle[] = gettext("DHCPv6 Server");
445
$shortcut_section = "dhcp6";
446

    
447
include("head.inc");
448

    
449
if ($input_errors) {
450
	print_input_errors($input_errors);
451
}
452

    
453
if ($savemsg) {
454
	print_info_box($savemsg, 'success');
455
}
456

    
457
if ($dhcrelay_enabled) {
458
	print_info_box(gettext("DHCP Relay is currently enabled. Cannot enable the DHCP Server service while the DHCP Relay is enabled on any interface."), 'danger');
459
	include("foot.inc");
460
	exit;
461
}
462

    
463
if (is_subsystem_dirty('staticmaps')) {
464
	print_apply_box(gettext('The static mapping configuration has been changed.') . '<br />' . gettext('You must apply the changes in order for them to take effect.'));
465
}
466

    
467
/* active tabs */
468
$tab_array = array();
469
$tabscounter = 0;
470
$i = 0;
471

    
472
foreach ($iflist as $ifent => $ifname) {
473
	$oc = $config['interfaces'][$ifent];
474

    
475

    
476
	if ((is_array($config['dhcpdv6'][$ifent]) && !isset($config['dhcpdv6'][$ifent]['enable']) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6'])))) ||
477
	    (!is_array($config['dhcpdv6'][$ifent]) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6']))))) {
478
		continue;
479
	}
480

    
481
	if ($ifent == $if) {
482
		$active = true;
483
	} else {
484
		$active = false;
485
	}
486

    
487
	$tab_array[] = array($ifname, $active, "services_dhcpv6.php?if={$ifent}");
488
	$tabscounter++;
489
}
490

    
491
/* tack on PPPoE or PPtP servers here */
492
/* pppoe server */
493
if (is_array($config['pppoes']['pppoe'])) {
494
	foreach ($config['pppoes']['pppoe'] as $pppoe) {
495
		if ($pppoe['mode'] == "server") {
496
			$ifent = "poes". $pppoe['pppoeid'];
497
			$ifname = strtoupper($ifent);
498

    
499
			if ($ifent == $if) {
500
				$active = true;
501
			} else {
502
				$active = false;
503
			}
504

    
505
			$tab_array[] = array($ifname, $active, "services_dhcpv6.php?if={$ifent}");
506
			$tabscounter++;
507
		}
508
	}
509
}
510

    
511
if ($tabscounter == 0) {
512
	print_info_box(gettext("The DHCPv6 Server can only be enabled on interfaces configured with a static IPv6 address. This system has none."), 'danger');
513
	include("foot.inc");
514
	exit;
515
}
516

    
517
display_top_tabs($tab_array);
518

    
519
$tab_array = array();
520
$tab_array[] = array(gettext("DHCPv6 Server"),		 true,	"services_dhcpv6.php?if={$if}");
521
$tab_array[] = array(gettext("Router Advertisements"), false, "services_router_advertisements.php?if={$if}");
522
display_top_tabs($tab_array, false, 'nav nav-tabs');
523

    
524
$form = new Form(new Form_Button(
525
	'Submit',
526
	'Save'
527
));
528

    
529
$section = new Form_Section('DHCPv6 Options');
530

    
531
$section->addInput(new Form_Checkbox(
532
	'enable',
533
	'DHCPv6 Server',
534
	'Enable DHCPv6 server on interface ' . $iflist[$if],
535
	$pconfig['enable']
536
))->toggles('.form-group:not(:first-child)');
537

    
538
if (is_ipaddrv6($ifcfgip)) {
539

    
540
	$section->addInput(new Form_StaticText(
541
		'Subnet',
542
		gen_subnetv6($ifcfgip, $ifcfgsn)
543
		));
544

    
545
	$section->addInput(new Form_StaticText(
546
		'Subnet Mask',
547
		$ifcfgsn . ' bits'
548
		));
549

    
550
	$section->addInput(new Form_StaticText(
551
		'Available Range',
552
		$range_from = gen_subnetv6($ifcfgip, $ifcfgsn) . ' to ' . gen_subnetv6_max($ifcfgip, $ifcfgsn)
553
		));
554
}
555

    
556
if ($is_olsr_enabled) {
557
	$section->addInput(new Form_Select(
558
	'netmask',
559
	'Subnet Mask',
560
	$pconfig['netmask'],
561
	array_combine(range(128, 1, -1), range(128, 1, -1))
562
	));
563
}
564

    
565
$f1 = new Form_Input(
566
	'range_from',
567
	null,
568
	'text',
569
	$pconfig['range_from']
570
);
571

    
572
$f1->setHelp('To');
573

    
574
$f2 = new Form_Input(
575
	'range_to',
576
	null,
577
	'text',
578
	$pconfig['range_to']
579
);
580

    
581
$f2->setHelp('From');
582

    
583
$group = new Form_Group('Range');
584

    
585
$group->add($f1);
586
$group->add($f2);
587

    
588
$section->add($group);
589

    
590
$f1 = new Form_Input(
591
	'prefixrange_from',
592
	null,
593
	'text',
594
	$pconfig['prefixrange_from']
595
);
596

    
597
$f1->setHelp('To');
598

    
599
$f2 = new Form_Input(
600
	'prefixrange_to',
601
	null,
602
	'text',
603
	$pconfig['prefixrange_to']
604
);
605

    
606
$f2->setHelp('From');
607
$group = new Form_Group('Prefix Delegation Range');
608

    
609
$group->add($f1);
610
$group->add($f2);
611

    
612
$section->add($group);
613

    
614
$section->addInput(new Form_Select(
615
	'prefixrange_length',
616
	'Prefix Delegation Size',
617
	$pconfig['prefixrange_length'],
618
	array(
619
		'48' => '48',
620
		'52' => '52',
621
		'56' => '56',
622
		'60' => '60',
623
		'62' => '62',
624
		'63' => '63',
625
		'64' => '64'
626
		)
627
))->setHelp('You can define a Prefix range 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.');
628

    
629
$group = new Form_Group('DNS Servers');
630

    
631
for ($i=1;$i<=4; $i++) {
632
	$group->add(new Form_input(
633
		'dns' . $i,
634
		null,
635
		'text',
636
		$pconfig['dns' . $i],
637
		['placeholder' => 'DNS ' . $i]
638
	));
639
}
640

    
641
$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.');
642
$section->add($group);
643

    
644
$section->addInput(new Form_Input(
645
	'domain',
646
	'Domain Name',
647
	'text',
648
	$pconfig['domain']
649
))->setHelp('The default is to use the domain name of this system as the default domain name provided by DHCP. You may specify an alternate domain name here. ');
650

    
651
$section->addInput(new Form_Input(
652
	'domainsearchlist',
653
	'Domain search list',
654
	'text',
655
	$pconfig['domainsearchlist']
656
))->setHelp('The DHCP server can optionally provide a domain search list. Use the semicolon character as separator');
657

    
658
$section->addInput(new Form_Input(
659
	'deftime',
660
	'Default lease time',
661
	'text',
662
	$pconfig['deftime']
663
))->setHelp('Seconds . Used for clients that do not ask for a specific expiration time. ' . ' <br />' .
664
			'The default is 7200 seconds.');
665

    
666
$section->addInput(new Form_Input(
667
	'maxtime',
668
	'Max lease time',
669
	'text',
670
	$pconfig['maxtime']
671
))->setHelp('Maximum lease time for clients that ask for a specific expiration time.' . ' <br />' .
672
			'The default is 86400 seconds.');
673

    
674
$section->addInput(new Form_Checkbox(
675
	'dhcpv6leaseinlocaltime',
676
	'Time Format Change',
677
	'Change DHCPv6 display lease time from UTC to local time',
678
	$pconfig['dhcpv6leaseinlocaltime']
679
))->setHelp('By default DHCPv6 leases are displayed in UTC time. ' .
680
			'By checking this box DHCPv6 lease time will be displayed in local time and set to time zone selected. ' .
681
			'This will be used for all DHCPv6 interfaces lease time.');
682

    
683
$btndyndns = new Form_Button(
684
	'btndyndns',
685
	'Advanced'
686
);
687

    
688
$btndyndns->removeClass('btn-primary')->addClass('btn-default btn-sm');
689

    
690
$section->addInput(new Form_StaticText(
691
	'Dynamic DNS',
692
	$btndyndns . '&nbsp;' . 'Show dynamic DNS settings'
693
));
694

    
695
$section->addInput(new Form_Checkbox(
696
	'ddnsupdate',
697
	'DHCP Registration',
698
	'Enable registration of DHCP client names in DNS.',
699
	$pconfig['ddnsupdate']
700
));
701

    
702
$section->addInput(new Form_Input(
703
	'ddnsdomain',
704
	'DDNS Domain',
705
	'text',
706
	$pconfig['ddnsdomain']
707
))->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.');
708

    
709
$section->addInput(new Form_IpAddress(
710
	'ddnsdomainprimary',
711
	'DDNS Server IP',
712
	$pconfig['ddnsdomainprimary']
713
))->setHelp('Enter the primary domain name server IP address for the dynamic domain name.');
714

    
715
$section->addInput(new Form_Input(
716
	'ddnsdomainkeyname',
717
	'DDNS Domain Key name',
718
	'text',
719
	$pconfig['ddnsdomainkeyname']
720
))->setHelp('Enter the dynamic DNS domain key name which will be used to register client names in the DNS server.');
721

    
722
$section->addInput(new Form_Input(
723
	'ddnsdomainkey',
724
	'DDNS Domain Key secret',
725
	'text',
726
	$pconfig['ddnsdomainkey']
727
))->setHelp('Enter the dynamic DNS domain key secret which will be used to register client names in the DNS server.');
728

    
729
$btnntp = new Form_Button(
730
	'btnntp',
731
	'Advanced'
732
);
733

    
734
$btnntp->removeClass('btn-primary')->addClass('btn-default btn-sm');
735

    
736
$section->addInput(new Form_StaticText(
737
	'NTP servers',
738
	$btnntp . '&nbsp;' . 'Show NTP Configuration'
739
));
740

    
741
$group = new Form_Group('NTP Servers');
742

    
743
$group->add(new Form_Input(
744
	'ntp1',
745
	'NTP Server 1',
746
	'text',
747
	$pconfig['ntp1'],
748
	['placeholder' => 'NTP 1']
749
));
750

    
751
$group->add(new Form_Input(
752
	'ntp2',
753
	'NTP Server 2',
754
	'text',
755
	$pconfig['ntp2'],
756
	['placeholder' => 'NTP 2']
757
));
758

    
759
$group->addClass('ntpclass');
760

    
761
$section->add($group);
762

    
763
$btnldap = new Form_Button(
764
	'btnldap',
765
	'Advanced'
766
);
767

    
768
$btnldap->removeClass('btn-primary')->addClass('btn-default btn-sm');
769

    
770
$section->addInput(new Form_StaticText(
771
	'LDAP',
772
	$btnldap . '&nbsp;' . 'Show LDAP Configuration'
773
));
774

    
775
$section->addInput(new Form_Input(
776
	'ldap',
777
	'LDAP URI',
778
	'text',
779
	$pconfig['ldap']
780
));
781

    
782
$btnnetboot = new Form_Button(
783
	'btnnetboot',
784
	'Advanced'
785
);
786

    
787
$btnnetboot->removeClass('btn-primary')->addClass('btn-default btn-sm');
788

    
789
$section->addInput(new Form_StaticText(
790
	'Network booting',
791
	$btnnetboot . '&nbsp;' . 'Show Network booting'
792
));
793

    
794
$section->addInput(new Form_Checkbox(
795
	'shownetboot',
796
	'Network booting',
797
	'Enable Network Booting',
798
	$pconfig['shownetboot']
799
));
800

    
801
$section->addInput(new Form_Input(
802
	'bootfile_url',
803
	'Bootfile URL',
804
	'text',
805
	$pconfig['bootfile_url']
806
));
807

    
808
$btnadnl = new Form_Button(
809
	'btnadnl',
810
	'Advanced'
811
);
812

    
813
$btnadnl->removeClass('btn-primary')->addClass('btn-default btn-sm');
814

    
815
$section->addInput(new Form_StaticText(
816
	'Additional BOOTP/DHCP Options',
817
	$btnadnl . '&nbsp;' . 'Additional BOOTP/DHCP Options'
818
));
819

    
820
$form->add($section);
821

    
822
$title = 'Show Additional BOOTP/DHCP Options';
823

    
824
if (!$pconfig['numberoptions']) {
825
	$noopts = true;
826
	$pconfig['numberoptions']['item'] = array(0 => array('number' => "", 'value' => ""));
827
} else {
828
	$noopts = false;
829
}
830

    
831
$counter = 0;
832
$last = count($pconfig['numberoptions']['item']) - 1;
833

    
834
foreach ($pconfig['numberoptions']['item'] as $item) {
835
	$group = new Form_Group(null);
836
	$group->addClass('repeatable');
837
	$group->addClass('adnloptions');
838

    
839
	$group->add(new Form_Input(
840
		'number' . $counter,
841
		null,
842
		'text',
843
		$item['number']
844
	))->setHelp($counter == $last ? 'Number':null);
845

    
846
	$group->add(new Form_Input(
847
		'value' . $counter,
848
		null,
849
		'text',
850
		base64_decode($item['value'])
851
	))->setHelp($counter == $last ? 'Value':null);
852

    
853
	$btn = new Form_Button(
854
		'deleterow' . $counter,
855
		'Delete'
856
	);
857

    
858
	$btn->removeClass('btn-primary')->addClass('btn-warning');
859
	$group->add($btn);
860
	$section->add($group);
861
	$counter++;
862
}
863

    
864

    
865
$btnaddopt = new Form_Button(
866
	'addrowt',
867
	'Add Option'
868
);
869

    
870
$btnaddopt->removeClass('btn-primary')->addClass('btn-success btn-sm')->addClass('adnloptions');
871

    
872
$section->addInput($btnaddopt);
873

    
874
$section->addInput(new Form_Input(
875
	'if',
876
	null,
877
	'hidden',
878
	$if
879
));
880

    
881
print($form);
882

    
883
?>
884
<div class="infoblock blockopen">
885
<?php
886
print_info_box(
887
	sprintf(
888
		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.'),
889
		'<a href="system.php">',
890
		'<a href="services_dnsmasq.php"/>',
891
		'</a>') . 
892
	'<br />' .
893
	sprintf(
894
		gettext('The DHCP lease table can be viewed on the %1$sStatus: DHCPv6 leases%2$s page.'),
895
		'<a href="status_dhcpv6_leases.php">',
896
		'</a>'),
897
	'info',
898
	false);
899
?>
900
</div>
901
<div class="panel panel-default">
902
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("DHCPv6 Static Mappings for this Interface");?></h2></div>
903
	<div class="panel-body table-responsive">
904
		<table class="table table-striped table-hover table-condensed">
905
			<thead>
906
				<tr>
907
					<th><?=gettext("DUID")?></th>
908
					<th><?=gettext("IPv6 address")?></th>
909
					<th><?=gettext("Hostname")?></th>
910
					<th><?=gettext("Description")?></th>
911
					<th><!-- Buttons --></th>
912
				</tr>
913
			</thead>
914
			<tbody>
915
<?php
916
if (is_array($a_maps)):
917
	$i = 0;
918
	foreach ($a_maps as $mapent):
919
		if ($mapent['duid'] != "" or $mapent['ipaddrv6'] != ""):
920
?>
921
				<tr>
922
					<td>
923
						<?=htmlspecialchars($mapent['duid'])?>
924
					</td>
925
					<td>
926
						<?=htmlspecialchars($mapent['ipaddrv6'])?>
927
					</td>
928
					<td>
929
						<?=htmlspecialchars($mapent['hostname'])?>
930
					</td>
931
					<td>
932
						<?=htmlspecialchars($mapent['descr'])?>
933
					</td>
934
					<td>
935
						<a class="fa fa-pencil"	title="<?=gettext('Edit static mapping')?>" href="services_dhcpv6_edit.php?if=<?=$if?>&amp;id=<?=$i?>"></a>
936
						<a class="fa fa-trash"	title="<?=gettext('Delete static mapping')?>" href="services_dhcpv6.php?if=<?=$if?>&amp;act=del&amp;id=<?=$i?>"></a>
937
					</td>
938
				</tr>
939
<?php
940
		endif;
941
	$i++;
942
	endforeach;
943
endif;
944
?>
945
			</tbody>
946
		</table>
947
	</div>
948
</div>
949

    
950
<nav class="action-buttons">
951
	<a href="services_dhcpv6_edit.php?if=<?=$if?>" class="btn btn-sm btn-success"/>
952
		<i class="fa fa-plus icon-embed-btn"></i>
953
		<?=gettext("Add")?>
954
	</a>
955
</nav>
956

    
957
<script type="text/javascript">
958
//<![CDATA[
959
events.push(function() {
960

    
961
	function hideDDNS(hide) {
962
		hideCheckbox('ddnsupdate', hide);
963
		hideInput('ddnsdomain', hide);
964
		hideInput('ddnsdomainprimary', hide);
965
		hideInput('ddnsdomainkeyname', hide);
966
		hideInput('ddnsdomainkey', hide);
967
	}
968

    
969
	// Make the 'Copy My MAC' button a plain button, not a submit button
970
	$("#btnmymac").prop('type','button');
971

    
972
	// On click, copy the hidden 'mymac' text to the 'mac' input
973
	$("#btnmymac").click(function() {
974
		$('#mac').val('<?=$mymac?>');
975
	});
976

    
977
	// Make the 'tftp' button a plain button, not a submit button
978
	$("#btntftp").prop('type','button');
979

    
980
	// Show tftp controls
981
	$("#btntftp").click(function() {
982
		hideInput('tftp', false);
983
	});
984

    
985
	// Make the 'ntp' button a plain button, not a submit button
986
	$("#btnntp").prop('type','button');
987

    
988
	// Show ntp controls
989
	$("#btnntp").click(function() {
990
		hideClass('ntpclass', false);
991
	});
992

    
993
	// Make the 'ddns' button a plain button, not a submit button
994
	$("#btndyndns").prop('type','button');
995

    
996
	// Show ddns controls
997
	$("#btndyndns").click(function() {
998
		hideDDNS(false);
999
	});
1000

    
1001
	// Make the 'ldap' button a plain button, not a submit button
1002
	$("#btnldap").prop('type','button');
1003

    
1004
	// Show ldap controls
1005
	$("#btnldap").click(function() {
1006
		hideInput('ldap', false);
1007
	});
1008

    
1009
	// Make the 'netboot' button a plain button, not a submit button
1010
	$("#btnnetboot").prop('type','button');
1011

    
1012
	// Show netboot controls
1013
	$("#btnnetboot").click(function() {
1014
		hideInput('bootfile_url', false);
1015
		hideCheckbox('shownetboot', false);
1016
	});
1017

    
1018
	// Make the 'additional options' button a plain button, not a submit button
1019
	$("#btnadnl").prop('type','button');
1020

    
1021
	// Show additional  controls
1022
	$("#btnadnl").click(function() {
1023
		hideClass('adnloptions', false);
1024
		hideInput('btnaddopt', false);
1025
	});
1026

    
1027
	// On initial load
1028
	hideDDNS(true);
1029
	hideClass('ntpclass', true);
1030
	hideInput('tftp', true);
1031
	hideInput('ldap', true);
1032
	hideInput('bootfile_url', true);
1033
	hideCheckbox('shownetboot', true);
1034
	hideClass('adnloptions', <?php echo json_encode($noopts); ?>);
1035
	hideInput('btnaddopt', true);
1036
});
1037
//]]>
1038
</script>
1039

    
1040
<?php include('foot.inc');
(121-121/229)