Project

General

Profile

Download (31.3 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
	pfSense_BUILDER_BINARIES:	/bin/rm
61
	pfSense_MODULE: interfaces
62
*/
63

    
64
##|+PRIV
65
##|*IDENT=page-services-dhcpv6server
66
##|*NAME=Services: DHCPv6 server
67
##|*DESCR=Allow access to the 'Services: DHCPv6 server' page.
68
##|*MATCH=services_dhcpv6.php*
69
##|-PRIV
70

    
71
require("guiconfig.inc");
72
require_once("filter.inc");
73

    
74
if (!$g['services_dhcp_server_enable']) {
75
	header("Location: /");
76
	exit;
77
}
78

    
79
/*	Fix failover DHCP problem
80
 *	http://article.gmane.org/gmane.comp.security.firewalls.pfsense.support/18749
81
 */
82
ini_set("memory_limit", "64M");
83

    
84
$if = $_GET['if'];
85
if ($_POST['if']) {
86
	$if = $_POST['if'];
87
}
88

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

    
99
$iflist = get_configured_interface_with_descr();
100
$iflist = array_merge($iflist, get_configured_pppoe_server_interfaces());
101

    
102
/* set the starting interface */
103
if (!$if || !isset($iflist[$if])) {
104
	foreach ($iflist as $ifent => $ifname) {
105
		$oc = $config['interfaces'][$ifent];
106

    
107
		if ((is_array($config['dhcpdv6'][$ifent]) && !isset($config['dhcpdv6'][$ifent]['enable']) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6'])))) ||
108
			(!is_array($config['dhcpdv6'][$ifent]) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6']))))) {
109
			continue;
110
		}
111
		$if = $ifent;
112
		break;
113
	}
114
}
115

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

    
153
$ifcfgip = get_interface_ipv6($if);
154
$ifcfgsn = get_interface_subnetv6($if);
155

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

    
161
$dhcrelay_enabled = false;
162
$dhcrelaycfg = $config['dhcrelay6'];
163

    
164
if (is_array($dhcrelaycfg)) {
165
	foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) {
166
		if (isset($dhcrelayifconf['enable']) && isset($iflist[$dhcrelayif]) &&
167
			(!link_interface_to_bridge($dhcrelayif))) {
168
			$dhcrelay_enabled = true;
169
		}
170
	}
171
}
172

    
173
if ($_POST) {
174
	unset($input_errors);
175

    
176
	$old_dhcpdv6_enable = ($pconfig['enable'] == true);
177
	$new_dhcpdv6_enable = ($_POST['enable'] ? true : false);
178
	$dhcpdv6_enable_changed = ($old_dhcpdv6_enable != $new_dhcpdv6_enable);
179

    
180
	$pconfig = $_POST;
181

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

    
194
	/* input validation */
195
	if ($_POST['enable']) {
196
		$reqdfields = explode(" ", "range_from range_to");
197
		$reqdfieldsn = array(gettext("Range begin"), gettext("Range end"));
198

    
199
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
200

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

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

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

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

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

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

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

    
302

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

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

    
324
	if (!$input_errors) {
325
		if (!is_array($config['dhcpdv6'][$if])) {
326
			$config['dhcpdv6'][$if] = array();
327
		}
328
		if (!is_array($config['dhcpdv6'][$if]['range'])) {
329
			$config['dhcpdv6'][$if]['range'] = array();
330
		}
331
		if (!is_array($config['dhcpdv6'][$if]['prefixrange'])) {
332
			$config['dhcpdv6'][$if]['prefixrange'] = array();
333
		}
334

    
335
		$config['dhcpdv6'][$if]['range']['from'] = $_POST['range_from'];
336
		$config['dhcpdv6'][$if]['range']['to'] = $_POST['range_to'];
337
		$config['dhcpdv6'][$if]['prefixrange']['from'] = $_POST['prefixrange_from'];
338
		$config['dhcpdv6'][$if]['prefixrange']['to'] = $_POST['prefixrange_to'];
339
		$config['dhcpdv6'][$if]['prefixrange']['prefixlength'] = $_POST['prefixrange_length'];
340
		$config['dhcpdv6'][$if]['defaultleasetime'] = $_POST['deftime'];
341
		$config['dhcpdv6'][$if]['maxleasetime'] = $_POST['maxtime'];
342
		$config['dhcpdv6'][$if]['netmask'] = $_POST['netmask'];
343

    
344
		unset($config['dhcpdv6'][$if]['winsserver']);
345

    
346
		unset($config['dhcpdv6'][$if]['dnsserver']);
347
		if ($_POST['dns1']) {
348
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns1'];
349
		}
350
		if ($_POST['dns2']) {
351
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns2'];
352
		}
353
		if ($_POST['dns3']) {
354
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns3'];
355
		}
356
		if ($_POST['dns4']) {
357
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns4'];
358
		}
359

    
360
		$config['dhcpdv6'][$if]['domain'] = $_POST['domain'];
361
		$config['dhcpdv6'][$if]['domainsearchlist'] = $_POST['domainsearchlist'];
362
		$config['dhcpdv6'][$if]['enable'] = ($_POST['enable']) ? true : false;
363
		$config['dhcpdv6'][$if]['ddnsdomain'] = $_POST['ddnsdomain'];
364
		$config['dhcpdv6'][$if]['ddnsdomainprimary'] = $_POST['ddnsdomainprimary'];
365
		$config['dhcpdv6'][$if]['ddnsdomainkeyname'] = $_POST['ddnsdomainkeyname'];
366
		$config['dhcpdv6'][$if]['ddnsdomainkey'] = $_POST['ddnsdomainkey'];
367
		$config['dhcpdv6'][$if]['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
368

    
369
		unset($config['dhcpdv6'][$if]['ntpserver']);
370
		if ($_POST['ntp1']) {
371
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp1'];
372
		}
373
		if ($_POST['ntp2']) {
374
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp2'];
375
		}
376

    
377
		$config['dhcpdv6'][$if]['tftp'] = $_POST['tftp'];
378
		$config['dhcpdv6'][$if]['ldap'] = $_POST['ldap'];
379
		$config['dhcpdv6'][$if]['netboot'] = ($_POST['netboot']) ? true : false;
380
		$config['dhcpdv6'][$if]['bootfile_url'] = $_POST['bootfile_url'];
381
		$config['dhcpdv6'][$if]['dhcpv6leaseinlocaltime'] = $_POST['dhcpv6leaseinlocaltime'];
382

    
383
		// Handle the custom options rowhelper
384
		if (isset($config['dhcpdv6'][$if]['numberoptions']['item'])) {
385
			unset($config['dhcpdv6'][$if]['numberoptions']['item']);
386
		}
387

    
388
		$config['dhcpdv6'][$if]['numberoptions'] = $numberoptions;
389

    
390
		write_config();
391

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

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

    
443
// Delete a row in the options table
444
if($_GET['act'] == "delopt") {
445
	$idx = $_GET['id'];
446

    
447
	if($pconfig['numberoptions'] && is_array($pconfig['numberoptions']['item'][$idx])) {
448
	   unset($pconfig['numberoptions']['item'][$idx]);
449
	}
450
}
451

    
452
// Add an option row
453
if($_GET['act'] == "addopt") {
454
	if(!is_array($pconfig['numberoptions']['item']))
455
		$pconfig['numberoptions']['item'] = array();
456

    
457
	array_push($pconfig['numberoptions']['item'], array('number' => null, 'value' => null));
458
}
459

    
460
$closehead = false;
461
$pgtitle = array(gettext("Services"), gettext("DHCPv6 Server"));
462
$shortcut_section = "dhcp6";
463

    
464
include("head.inc");
465

    
466
if ($input_errors)
467
	print_input_errors($input_errors);
468

    
469
if ($savemsg)
470
	print_info_box($savemsg, 'success');
471

    
472
if ($dhcrelay_enabled) {
473
	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');
474
	include("foot.inc");
475
	exit;
476
}
477

    
478
if (is_subsystem_dirty('staticmaps'))
479
	print_info_box_np(gettext('The static mapping configuration has been changed') . '.<br />' . gettext('You must apply the changes in order for them to take effect.'));
480

    
481
/* active tabs */
482
$tab_array = array();
483
$tabscounter = 0;
484
$i = 0;
485

    
486
foreach ($iflist as $ifent => $ifname) {
487
	$oc = $config['interfaces'][$ifent];
488

    
489

    
490
	if((is_array($config['dhcpdv6'][$ifent]) && !isset($config['dhcpdv6'][$ifent]['enable']) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6'])))) ||
491
		(!is_array($config['dhcpdv6'][$ifent]) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6'])))))
492
		continue;
493

    
494
	if ($ifent == $if)
495
		$active = true;
496
	else
497
		$active = false;
498

    
499
	$tab_array[] = array($ifname, $active, "services_dhcpv6.php?if={$ifent}");
500
	$tabscounter++;
501
}
502

    
503
/* tack on PPPoE or PPtP servers here */
504
/* pppoe server */
505
if (is_array($config['pppoes']['pppoe'])) {
506
	foreach($config['pppoes']['pppoe'] as $pppoe) {
507
		if ($pppoe['mode'] == "server") {
508
			$ifent = "poes". $pppoe['pppoeid'];
509
			$ifname = strtoupper($ifent);
510

    
511
			if ($ifent == $if)
512
				$active = true;
513
			else
514
				$active = false;
515

    
516
			$tab_array[] = array($ifname, $active, "services_dhcpv6.php?if={$ifent}");
517
			$tabscounter++;
518
		}
519
	}
520
}
521

    
522
if ($tabscounter == 0) {
523
	print_info_box(gettext("The DHCPv6 Server can only be enabled on interfaces configured with a static IPv6 address. This system has none."), 'danger');
524
	include("foot.inc");
525
	exit;
526
}
527

    
528
display_top_tabs($tab_array);
529

    
530
$tab_array = array();
531
$tab_array[] = array(gettext("DHCPv6 Server"),		 true,	"services_dhcpv6.php?if={$if}");
532
$tab_array[] = array(gettext("Router Advertisements"), false, "services_router_advertisements.php?if={$if}");
533
display_top_tabs($tab_array, false, 'nav nav-tabs' );
534

    
535
$form = new Form(new Form_Button(
536
	'Submit',
537
	'Save'
538
));
539

    
540
$section = new Form_Section('DHCPv6 Options');
541

    
542
$section->addInput(new Form_Checkbox(
543
	'enable',
544
	'DHCPv6 Server',
545
	'Enable DHCPv6 server on interface ' . $iflist[$if],
546
	$pconfig['enable']
547
))->toggles('.form-group:not(:first-child)');
548

    
549
if(is_ipaddrv6($ifcfgip)) {
550

    
551
	$section->addInput(new Form_StaticText(
552
		'Subnet',
553
		gen_subnetv6($ifcfgip, $ifcfgsn)
554
		));
555

    
556
	$section->addInput(new Form_StaticText(
557
		'Subnet Mask',
558
		$ifcfgsn . ' bits'
559
		));
560

    
561
	$section->addInput(new Form_StaticText(
562
		'Available Range',
563
		$range_from = gen_subnetv6($ifcfgip, $ifcfgsn) . ' to ' . gen_subnetv6_max($ifcfgip, $ifcfgsn)
564
		));
565
}
566

    
567
if($is_olsr_enabled) {
568
	$section->addInput(new Form_Select(
569
	'netmask',
570
	'Subnet Mask',
571
	$pconfig['netmask'],
572
	array_combine(range(128, 1, -1), range(128, 1, -1))
573
	));
574
}
575

    
576
$f1 = new Form_Input(
577
	'range_from',
578
	null,
579
	'text',
580
	$pconfig['range_from']
581
);
582

    
583
$f1->setHelp('To');
584

    
585
$f2 = new Form_Input(
586
	'range_to',
587
	null,
588
	'text',
589
	$pconfig['range_to']
590
);
591

    
592
$f2->setHelp('From');
593

    
594
$group = new Form_Group('Range');
595

    
596
$group->add($f1);
597
$group->add($f2);
598

    
599
$section->add($group);
600

    
601
$f1 = new Form_Input(
602
	'prefix_from',
603
	null,
604
	'text',
605
	$pconfig['prefix_from']
606
);
607

    
608
$f1->setHelp('To');
609

    
610
$f2 = new Form_Input(
611
	'prefix_to',
612
	null,
613
	'text',
614
	$pconfig['prefix_to']
615
);
616

    
617
$f2->setHelp('From');
618
$group = new Form_Group('Prefix Delegation Range');
619

    
620
$group->add($f1);
621
$group->add($f2);
622

    
623
$section->add($group);
624

    
625
$section->addInput(new Form_Select(
626
	'prefixrange_length',
627
	'Prefix Delegation Size',
628
	$pconfig['prefixrange_length'],
629
	array(
630
		'48' => '48',
631
		'52' => '52',
632
		'56' => '56',
633
		'60' => '60',
634
		'62' => '62',
635
		'63' => '63',
636
		'64' => '64'
637
		)
638
))->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.');
639

    
640
$group = new Form_Group('DNS Servers');
641

    
642
for($i=1;$i<=4; $i++) {
643
	$group->add(new Form_input(
644
		'dns' . $i,
645
		null,
646
		'text',
647
		$pconfig['dns' . $i],
648
		['placeholder' => 'DNS ' . $i]
649
	));
650
}
651

    
652
$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.');
653
$section->add($group);
654

    
655
$section->addInput(new Form_Input(
656
	'domain',
657
	'Domain Name',
658
	'text',
659
	$pconfig['domain']
660
))->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. ');
661

    
662
$section->addInput(new Form_Input(
663
	'domainsearchlist',
664
	'Domain search list',
665
	'text',
666
	$pconfig['domainsearchlist']
667
))->setHelp('The DHCP server can optionally provide a domain search list. Use the semicolon character as separator');
668

    
669
$section->addInput(new Form_Input(
670
	'deftime',
671
	'Default lease time',
672
	'text',
673
	$pconfig['deftime']
674
))->setHelp('Seconds . Used for clients that do not ask for a specific expiration time. ' . ' <br />' .
675
			'The default is 7200 seconds.');
676

    
677
$section->addInput(new Form_Input(
678
	'maxtime',
679
	'Max lease time',
680
	'text',
681
	$pconfig['maxtime']
682
))->setHelp('Maximum lease time for clients that ask for a specific expiration time.' . ' <br />' .
683
			'The default is 86400 seconds.');
684

    
685
$section->addInput(new Form_Checkbox(
686
	'dhcpv6leaseinlocaltime',
687
	'Time Format Change',
688
	'Change DHCPv6 display lease time from UTC to local time',
689
	$pconfig['dhcpv6leaseinlocaltime']
690
))->setHelp('By default DHCPv6 leases are displayed in UTC time. ' .
691
			'By checking this box DHCPv6 lease time will be displayed in local time and set to time zone selected. ' .
692
			'This will be used for all DHCPv6 interfaces lease time.');
693

    
694
$btndyndns = new Form_Button(
695
	'btndyndns',
696
	'Advanced'
697
);
698

    
699
$btndyndns->removeClass('btn-primary')->addClass('btn-default btn-sm');
700

    
701
$section->addInput(new Form_StaticText(
702
	'Dynamic DNS',
703
	$btndyndns . '&nbsp;' . 'Show dynamic DNS settings'
704
));
705

    
706
$section->addInput(new Form_Checkbox(
707
	'ddnsupdate',
708
	'DHCP Registration',
709
	'Enable registration of DHCP client names in DNS.',
710
	$pconfig['ddnsupdate']
711
));
712

    
713
$section->addInput(new Form_Input(
714
	'ddnsdomain',
715
	'DDNS Domain',
716
	'text',
717
	$pconfig['ddnsdomain']
718
))->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.');
719

    
720
$section->addInput(new Form_IpAddress(
721
	'ddnsdomainprimary',
722
	'DDNS Server IP',
723
	$pconfig['ddnsdomainprimary']
724
))->setHelp('Enter the primary domain name server IP address for the dynamic domain name.');
725

    
726
$section->addInput(new Form_Input(
727
	'ddnsdomainkeyname',
728
	'DDNS Domain Key name',
729
	'text',
730
	$pconfig['ddnsdomainkeyname']
731
))->setHelp('Enter the dynamic DNS domain key name which will be used to register client names in the DNS server.');
732

    
733
$section->addInput(new Form_Input(
734
	'ddnsdomainkey',
735
	'DDNS Domain Key secret',
736
	'text',
737
	$pconfig['ddnsdomainkey']
738
))->setHelp('Enter the dynamic DNS domain key secret which will be used to register client names in the DNS server.');
739

    
740
$btnntp = new Form_Button(
741
	'btnntp',
742
	'Advanced'
743
);
744

    
745
$btnntp->removeClass('btn-primary')->addClass('btn-default btn-sm');
746

    
747
$section->addInput(new Form_StaticText(
748
	'NTP servers',
749
	$btnntp . '&nbsp;' . 'Show NTP Configuration'
750
));
751

    
752
$group = new Form_Group('NTP Servers');
753

    
754
$group->add(new Form_Input(
755
	'ntp1',
756
	'NTP Server 1',
757
	'text',
758
	$pconfig['ntp1'],
759
	['placeholder' => 'NTP 1']
760
));
761

    
762
$group->add(new Form_Input(
763
	'ntp2',
764
	'NTP Server 2',
765
	'text',
766
	$pconfig['ntp2'],
767
	['placeholder' => 'NTP 2']
768
));
769

    
770
$group->addClass('ntpclass');
771

    
772
$section->add($group);
773

    
774
$btnldap = new Form_Button(
775
	'btnldap',
776
	'Advanced'
777
);
778

    
779
$btnldap->removeClass('btn-primary')->addClass('btn-default btn-sm');
780

    
781
$section->addInput(new Form_StaticText(
782
	'LDAP',
783
	$btnldap . '&nbsp;' . 'Show LDAP Configuration'
784
));
785

    
786
$section->addInput(new Form_Input(
787
	'ldap',
788
	'LDAP URI',
789
	'text',
790
	$pconfig['ldap']
791
));
792

    
793
$btnnetboot = new Form_Button(
794
	'btnnetboot',
795
	'Advanced'
796
);
797

    
798
$btnnetboot->removeClass('btn-primary')->addClass('btn-default btn-sm');
799

    
800
$section->addInput(new Form_StaticText(
801
	'Network booting',
802
	$btnnetboot . '&nbsp;' . 'Show Network booting'
803
));
804

    
805
$section->addInput(new Form_Checkbox(
806
	'shownetboot',
807
	'Network booting',
808
	'Enable Network Booting',
809
	$pconfig['shownetboot']
810
));
811

    
812
$section->addInput(new Form_Input(
813
	'bootfile_url',
814
	'Bootfile URL',
815
	'text',
816
	$pconfig['bootfile_url']
817
));
818

    
819
$btnadnl = new Form_Button(
820
	'btnadnl',
821
	'Advanced'
822
);
823

    
824
$btnadnl->removeClass('btn-primary')->addClass('btn-default btn-sm');
825

    
826
$section->addInput(new Form_StaticText(
827
	'Additional BOOTP/DHCP Options',
828
	$btnadnl . '&nbsp;' . 'Additional BOOTP/DHCP Options'
829
));
830

    
831
$form->add($section);
832

    
833
$title = 'Show Additional BOOTP/DHCP Options';
834

    
835
if($pconfig['numberoptions']) {
836
	$counter = 0;
837
	$last = count($pconfig['numberoptions']['item']) - 1;
838

    
839
	foreach($pconfig['numberoptions']['item'] as $item) {
840
		$group = new Form_Group(null);
841

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

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

    
856
		$btn = new Form_Button(
857
			'btn' . $counter,
858
			'Delete',
859
			'services_dhcpv6.php?if=' . $if . '&act=delopt' . '&id=' . $counter
860
		);
861

    
862
		$btn->removeClass('btn-primary')->addClass('btn-danger btn-xs adnlopt');
863
		$group->addClass('adnlopt');
864
		$group->add($btn);
865
		$section->add($group);
866
		$counter++;
867
	}
868
}
869

    
870
$btnaddopt = new Form_Button(
871
	'btnaddopt',
872
	'Add Option',
873
	'services_dhcpv6.php?if=' . $if . '&act=addopt'
874
);
875

    
876
$btnaddopt->removeClass('btn-primary')->addClass('btn-success btn-sm');
877

    
878
$section->addInput($btnaddopt);
879

    
880
$section->addInput(new Form_Input(
881
	'if',
882
	null,
883
	'hidden',
884
	$if
885
));
886

    
887
print($form);
888

    
889
print_info_box(gettext('The DNS servers entered in ') . '<a href="system.php">' . gettext(' System: General setup') . '</a>' .
890
			   gettext(' (or the ') . '<a href="services_dnsmasq.php"/>' . gettext('DNS forwarder') . '</a>, ' . gettext('if enabled) ') .
891
			   gettext('will be assigned to clients by the DHCP server.') . '<br />' .
892
			   gettext('The DHCP lease table can be viewed on the ') . '<a href="status_dhcpv6_leases.php">' .
893
			   gettext('Status: DHCPv6 leases') . '</a>' . gettext(' page.'));
894
?>
895

    
896
<div class="panel panel-default">
897
	<div class="panel-heading"><h2 class="panel-title">DHCPv6 Static Mappings for this interface.</h2></div>
898
	<div class="panel-body table-responsive">
899
		<table class="table table-striped table-hover table-condensed">
900
			<thead>
901
				<tr>
902
					<th><?=gettext("DUID")?></th>
903
					<th><?=gettext("IPv6 address")?></th>
904
					<th><?=gettext("Hostname")?></th>
905
					<th><?=gettext("Description")?></th>
906
					<th><!-- Buttons --></th>
907
				</tr>
908
			</thead>
909
			<tbody>
910
<?php
911
if(is_array($a_maps)):
912
	$i = 0;
913
	foreach ($a_maps as $mapent):
914
		if($mapent['duid'] != "" or $mapent['ipaddrv6'] != ""):
915
?>
916
				<tr>
917
					<td>
918
						<?=htmlspecialchars($mapent['duid'])?>
919
					</td>
920
					<td>
921
						<?=htmlspecialchars($mapent['ipaddrv6'])?>
922
					</td>
923
					<td>
924
						<?=htmlspecialchars($mapent['hostname'])?>
925
					</td>
926
					<td>
927
						<?=htmlspecialchars($mapent['descr'])?>
928
					</td>
929
					<td>
930
						<a class="fa fa-pencil"	title="<?=gettext('Edit static mapping')?>" href="services_dhcpv6_edit.php?if=<?=$if?>&amp;id=<?=$i?>"></a>
931
						<a class="fa fa-trash"	title="<?=gettext('Delete static mapping')?>" href="services_dhcpv6.php?if=<?=$if?>&amp;act=del&amp;id=<?=$i?>"></a>
932
					</td>
933
				</tr>
934
<?php
935
		endif;
936
	$i++;
937
	endforeach;
938
endif;
939
?>
940
			</tbody>
941
		</table>
942
	</div>
943
</div>
944

    
945
<nav class="action-buttons">
946
	<a href="services_dhcpv6_edit.php?if=<?=$if?>" class="btn btn-sm btn-success"/>
947
		<i class="fa fa-plus icon-embed-btn"></i>
948
		<?=gettext("Add")?>
949
	</a>
950
</nav>
951

    
952
<script type="text/javascript">
953
//<![CDATA[
954
events.push(function(){
955

    
956
	function hideDDNS(hide) {
957
		hideCheckBox('ddnsupdate', hide);
958
		hideInput('ddnsdomain', hide);
959
		hideInput('ddnsdomainprimary', hide);
960
		hideInput('ddnsdomainkeyname', hide);
961
		hideInput('ddnsdomainkey', hide);
962
	}
963

    
964
	// Make the 'Copy My MAC' button a plain button, not a submit button
965
	$("#btnmymac").prop('type','button');
966

    
967
	// On click, copy the hidden 'mymac' text to the 'mac' input
968
	$("#btnmymac").click(function() {
969
		$('#mac').val('<?=$mymac?>');
970
	});
971

    
972
	// Make the 'tftp' button a plain button, not a submit button
973
	$("#btntftp").prop('type','button');
974

    
975
	// Show tftp controls
976
	$("#btntftp").click(function() {
977
		hideInput('tftp', false);
978
	});
979

    
980
	// Make the 'ntp' button a plain button, not a submit button
981
	$("#btnntp").prop('type','button');
982

    
983
	// Show ntp controls
984
	$("#btnntp").click(function() {
985
		hideClass('ntpclass', false);
986
	});
987

    
988
	// Make the 'ddns' button a plain button, not a submit button
989
	$("#btndyndns").prop('type','button');
990

    
991
	// Show ddns controls
992
	$("#btndyndns").click(function() {
993
		hideDDNS(false);
994
	});
995

    
996
	// Make the 'ldap' button a plain button, not a submit button
997
	$("#btnldap").prop('type','button');
998

    
999
	// Show ldap controls
1000
	$("#btnldap").click(function() {
1001
		hideInput('ldap', false);
1002
	});
1003

    
1004
	// Make the 'netboot' button a plain button, not a submit button
1005
	$("#btnnetboot").prop('type','button');
1006

    
1007
	// Show netboot controls
1008
	$("#btnnetboot").click(function() {
1009
		hideInput('bootfile_url', false);
1010
		hideCheckBox('shownetboot', false);
1011
	});
1012

    
1013
	// Make the 'additional options' button a plain button, not a submit button
1014
	$("#btnadnl").prop('type','button');
1015

    
1016
	// Show additional  controls
1017
	$("#btnadnl").click(function() {
1018
		hideClass('adnlopt', false);
1019
		hideInput('btnaddopt', false);
1020
	});
1021

    
1022
	// On initial load
1023
	hideDDNS(true);
1024
	hideClass('ntpclass', true);
1025
	hideInput('tftp', true);
1026
	hideInput('ldap', true);
1027
	hideInput('bootfile_url', true);
1028
	hideCheckBox('shownetboot', true);
1029
	hideClass('adnlopt', true);
1030
	hideInput('btnaddopt', true);
1031
});
1032
//]]>
1033
</script>
1034

    
1035
<?php include('foot.inc');
(133-133/228)