Project

General

Profile

Download (30.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	services_dhcpv6.php
5
	parts of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	part of pfSense (https://www.pfsense.org)
11
	Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
12
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
13
	All rights reserved.
14

    
15
	Redistribution and use in source and binary forms, with or without
16
	modification, are permitted provided that the following conditions are met:
17

    
18
	1. Redistributions of source code must retain the above copyright notice,
19
	   this list of conditions and the following disclaimer.
20

    
21
	2. Redistributions in binary form must reproduce the above copyright
22
	   notice, this list of conditions and the following disclaimer in the
23
	   documentation and/or other materials provided with the distribution.
24

    
25
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
26
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
29
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
	POSSIBILITY OF SUCH DAMAGE.
35
*/
36
/*
37
	pfSense_BUILDER_BINARIES:	/bin/rm
38
	pfSense_MODULE: interfaces
39
*/
40

    
41
##|+PRIV
42
##|*IDENT=page-services-dhcpv6server
43
##|*NAME=Services: DHCPv6 server page
44
##|*DESCR=Allow access to the 'Services: DHCPv6 server' page.
45
##|*MATCH=services_dhcpv6.php*
46
##|-PRIV
47

    
48
require("guiconfig.inc");
49
require_once("filter.inc");
50

    
51
if(!$g['services_dhcp_server_enable']) {
52
	header("Location: /");
53
	exit;
54
}
55

    
56
/*	Fix failover DHCP problem
57
 *	http://article.gmane.org/gmane.comp.security.firewalls.pfsense.support/18749
58
 */
59
ini_set("memory_limit","64M");
60

    
61
$if = $_GET['if'];
62

    
63
if ($_POST['if'])
64
	$if = $_POST['if'];
65

    
66
/* if OLSRD is enabled, allow WAN to house DHCP. */
67
if($config['installedpackages']['olsrd']) {
68
	foreach($config['installedpackages']['olsrd']['config'] as $olsrd) {
69
		if($olsrd['enable']) {
70
			$is_olsr_enabled = true;
71
			break;
72
		}
73
	}
74
}
75

    
76
$iflist = get_configured_interface_with_descr();
77
$iflist = array_merge($iflist, get_configured_pppoe_server_interfaces());
78

    
79
/* set the starting interface */
80
if (!$if || !isset($iflist[$if])) {
81
	foreach ($iflist as $ifent => $ifname) {
82
		$oc = $config['interfaces'][$ifent];
83
		if ((is_array($config['dhcpdv6'][$ifent]) && !isset($config['dhcpdv6'][$ifent]['enable']) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6'])))) ||
84
			(!is_array($config['dhcpdv6'][$ifent]) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6'])))))
85
			continue;
86

    
87
		$if = $ifent;
88
		break;
89
	}
90
}
91

    
92
if (is_array($config['dhcpdv6'][$if])){
93
	/* DHCPv6 */
94
	if (is_array($config['dhcpdv6'][$if]['range'])) {
95
		$pconfig['range_from'] = $config['dhcpdv6'][$if]['range']['from'];
96
		$pconfig['range_to'] = $config['dhcpdv6'][$if]['range']['to'];
97
	}
98
	if (is_array($config['dhcpdv6'][$if]['prefixrange'])) {
99
		$pconfig['prefixrange_from'] = $config['dhcpdv6'][$if]['prefixrange']['from'];
100
		$pconfig['prefixrange_to'] = $config['dhcpdv6'][$if]['prefixrange']['to'];
101
		$pconfig['prefixrange_length'] = $config['dhcpdv6'][$if]['prefixrange']['prefixlength'];
102
	}
103
	$pconfig['deftime'] = $config['dhcpdv6'][$if]['defaultleasetime'];
104
	$pconfig['maxtime'] = $config['dhcpdv6'][$if]['maxleasetime'];
105
	$pconfig['domain'] = $config['dhcpdv6'][$if]['domain'];
106
	$pconfig['domainsearchlist'] = $config['dhcpdv6'][$if]['domainsearchlist'];
107
	list($pconfig['wins1'],$pconfig['wins2']) = $config['dhcpdv6'][$if]['winsserver'];
108
	list($pconfig['dns1'],$pconfig['dns2'],$pconfig['dns3'],$pconfig['dns4']) = $config['dhcpdv6'][$if]['dnsserver'];
109
	$pconfig['enable'] = isset($config['dhcpdv6'][$if]['enable']);
110
	$pconfig['ddnsdomain'] = $config['dhcpdv6'][$if]['ddnsdomain'];
111
	$pconfig['ddnsdomainprimary'] = $config['dhcpdv6'][$if]['ddnsdomainprimary'];
112
	$pconfig['ddnsdomainkeyname'] = $config['dhcpdv6'][$if]['ddnsdomainkeyname'];
113
	$pconfig['ddnsdomainkey'] = $config['dhcpdv6'][$if]['ddnsdomainkey'];
114
	$pconfig['ddnsupdate'] = isset($config['dhcpdv6'][$if]['ddnsupdate']);
115
	list($pconfig['ntp1'],$pconfig['ntp2']) = $config['dhcpdv6'][$if]['ntpserver'];
116
	$pconfig['tftp'] = $config['dhcpdv6'][$if]['tftp'];
117
	$pconfig['ldap'] = $config['dhcpdv6'][$if]['ldap'];
118
	$pconfig['netboot'] = isset($config['dhcpdv6'][$if]['netboot']);
119
	$pconfig['bootfile_url'] = $config['dhcpdv6'][$if]['bootfile_url'];
120
	$pconfig['netmask'] = $config['dhcpdv6'][$if]['netmask'];
121
	$pconfig['numberoptions'] = $config['dhcpdv6'][$if]['numberoptions'];
122
	$pconfig['dhcpv6leaseinlocaltime'] = $config['dhcpdv6'][$if]['dhcpv6leaseinlocaltime'];
123
	if (!is_array($config['dhcpdv6'][$if]['staticmap']))
124
		$config['dhcpdv6'][$if]['staticmap'] = array();
125
	$a_maps = &$config['dhcpdv6'][$if]['staticmap'];
126
}
127

    
128
$ifcfgip = get_interface_ipv6($if);
129
$ifcfgsn = get_interface_subnetv6($if);
130

    
131
/*	 set the enabled flag which will tell us if DHCP relay is enabled
132
 *	 on any interface. We will use this to disable DHCP server since
133
 *	 the two are not compatible with each other.
134
 */
135

    
136
$dhcrelay_enabled = false;
137
$dhcrelaycfg = $config['dhcrelay6'];
138

    
139
if(is_array($dhcrelaycfg)) {
140
	foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) {
141
		if (isset($dhcrelayifconf['enable']) && isset($iflist[$dhcrelayif]) &&
142
			(!link_interface_to_bridge($dhcrelayif)))
143
			$dhcrelay_enabled = true;
144
	}
145
}
146

    
147
if ($_POST) {
148
	unset($input_errors);
149

    
150
	$old_dhcpdv6_enable = ($pconfig['enable'] == true);
151
	$new_dhcpdv6_enable = ($_POST['enable'] ? true : false);
152
	$dhcpdv6_enable_changed = ($old_dhcpdv6_enable != $new_dhcpdv6_enable);
153

    
154
	$pconfig = $_POST;
155

    
156
	$numberoptions = array();
157
	for($x=0; $x<99; $x++) {
158
		if(isset($_POST["number{$x}"]) && ctype_digit($_POST["number{$x}"])) {
159
			$numbervalue = array();
160
			$numbervalue['number'] = htmlspecialchars($_POST["number{$x}"]);
161
			$numbervalue['value'] = htmlspecialchars($_POST["value{$x}"]);
162
			$numberoptions['item'][] = $numbervalue;
163
		}
164
	}
165
	// Reload the new pconfig variable that the forum uses.
166
	$pconfig['numberoptions'] = $numberoptions;
167

    
168
	/* input validation */
169
	if ($_POST['enable']) {
170
		$reqdfields = explode(" ", "range_from range_to");
171
		$reqdfieldsn = array(gettext("Range begin"),gettext("Range end"));
172

    
173
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
174

    
175
		if (($_POST['prefixrange_from'] && !is_ipaddrv6($_POST['prefixrange_from'])))
176
			$input_errors[] = gettext("A valid range must be specified.");
177
		if (($_POST['prefixrange_to'] && !is_ipaddrv6($_POST['prefixrange_to'])))
178
			$input_errors[] = gettext("A valid prefix range must be specified.");
179
		if (($_POST['range_from'] && !is_ipaddrv6($_POST['range_from'])))
180
			$input_errors[] = gettext("A valid range must be specified.");
181
		if (($_POST['range_to'] && !is_ipaddrv6($_POST['range_to'])))
182
			$input_errors[] = gettext("A valid range must be specified.");
183
		if (($_POST['gateway'] && !is_ipaddrv6($_POST['gateway'])))
184
			$input_errors[] = gettext("A valid IPv6 address must be specified for the gateway.");
185
		if (($_POST['dns1'] && !is_ipaddrv6($_POST['dns1'])) || ($_POST['dns2'] && !is_ipaddrv6($_POST['dns2'])) || ($_POST['dns3'] && !is_ipaddrv6($_POST['dns3'])) || ($_POST['dns4'] && !is_ipaddrv6($_POST['dns4'])))
186
			$input_errors[] = gettext("A valid IPv6 address must be specified for each of the DNS servers.");
187

    
188
		if ($_POST['deftime'] && (!is_numeric($_POST['deftime']) || ($_POST['deftime'] < 60)))
189
			$input_errors[] = gettext("The default lease time must be at least 60 seconds.");
190
		if ($_POST['maxtime'] && (!is_numeric($_POST['maxtime']) || ($_POST['maxtime'] < 60) || ($_POST['maxtime'] <= $_POST['deftime'])))
191
			$input_errors[] = gettext("The maximum lease time must be at least 60 seconds and higher than the default lease time.");
192
		if (($_POST['ddnsdomain'] && !is_domain($_POST['ddnsdomain'])))
193
			$input_errors[] = gettext("A valid domain name must be specified for the dynamic DNS registration.");
194
		if (($_POST['ddnsdomain'] && !is_ipaddrv4($_POST['ddnsdomainprimary'])))
195
			$input_errors[] = gettext("A valid primary domain name server IPv4 address must be specified for the dynamic domain name.");
196
		if (($_POST['ddnsdomainkey'] && !$_POST['ddnsdomainkeyname']) ||
197
			($_POST['ddnsdomainkeyname'] && !$_POST['ddnsdomainkey']))
198
			$input_errors[] = gettext("You must specify both a valid domain key and key name.");
199
		if ($_POST['domainsearchlist']) {
200
			$domain_array=preg_split("/[ ;]+/",$_POST['domainsearchlist']);
201
			foreach ($domain_array as $curdomain) {
202
				if (!is_domain($curdomain)) {
203
					$input_errors[] = gettext("A valid domain search list must be specified.");
204
					break;
205
				}
206
			}
207
		}
208

    
209
		if (($_POST['ntp1'] && !is_ipaddrv6($_POST['ntp1'])) || ($_POST['ntp2'] && !is_ipaddrv6($_POST['ntp2'])))
210
			$input_errors[] = gettext("A valid IPv6 address must be specified for the primary/secondary NTP servers.");
211
		if (($_POST['domain'] && !is_domain($_POST['domain'])))
212
			$input_errors[] = gettext("A valid domain name must be specified for the DNS domain.");
213
		if ($_POST['tftp'] && !is_ipaddr($_POST['tftp']) && !is_domain($_POST['tftp']) && !is_URL($_POST['tftp']))
214
			$input_errors[] = gettext("A valid IPv6 address or hostname must be specified for the TFTP server.");
215
		if (($_POST['bootfile_url'] && !is_URL($_POST['bootfile_url'])))
216
			$input_errors[] = gettext("A valid URL must be specified for the network bootfile.");
217

    
218
		// Disallow a range that includes the virtualip
219
		if (is_array($config['virtualip']['vip'])) {
220
			foreach($config['virtualip']['vip'] as $vip) {
221
				if($vip['interface'] == $if)
222
					if($vip['subnetv6'] && is_inrange_v6($vip['subnetv6'], $_POST['range_from'], $_POST['range_to']))
223
						$input_errors[] = sprintf(gettext("The subnet range cannot overlap with virtual IPv6 address %s."),$vip['subnetv6']);
224
			}
225
		}
226

    
227
		$noip = false;
228

    
229
		if(is_array($a_maps)) {
230
			foreach ($a_maps as $map) {
231
				if (empty($map['ipaddrv6']))
232
					$noip = true;
233
			}
234
		}
235

    
236
		if (!$input_errors) {
237
			/* make sure the range lies within the current subnet */
238
			$subnet_start = gen_subnetv6($ifcfgip, $ifcfgsn);
239
			$subnet_end = gen_subnetv6_max($ifcfgip, $ifcfgsn);
240

    
241
			if (is_ipaddrv6($ifcfgip)) {
242
				if ((! is_inrange_v6($_POST['range_from'], $subnet_start, $subnet_end)) ||
243
				 (! is_inrange_v6($_POST['range_to'], $subnet_start, $subnet_end))) {
244
					$input_errors[] = gettext("The specified range lies outside of the current subnet.");
245
				}
246
			}
247
			/* "from" cannot be higher than "to" */
248
			if (inet_pton($_POST['range_from']) > inet_pton($_POST['range_to']))
249
				$input_errors[] = gettext("The range is invalid (first element higher than second element).");
250

    
251
			/* make sure that the DHCP Relay isn't enabled on this interface */
252
			if (isset($config['dhcrelay'][$if]['enable']))
253
				$input_errors[] = sprintf(gettext("You must disable the DHCP relay on the %s interface before enabling the DHCP server."),$iflist[$if]);
254

    
255

    
256
			/* Verify static mappings do not overlap:
257
			   - available DHCP range
258
			   - prefix delegation range (FIXME: still need to be completed) */
259
			$dynsubnet_start = inet_pton($_POST['range_from']);
260
			$dynsubnet_end = inet_pton($_POST['range_to']);
261

    
262
			if(is_array($a_maps)) {
263
				foreach ($a_maps as $map) {
264
					if (empty($map['ipaddrv6']))
265
						continue;
266
					if ((inet_pton($map['ipaddrv6']) > $dynsubnet_start) &&
267
						(inet_pton($map['ipaddrv6']) < $dynsubnet_end)) {
268
						$input_errors[] = sprintf(gettext("The DHCP range cannot overlap any static DHCP mappings."));
269
						break;
270
					}
271
				}
272
			}
273
		}
274
	}
275

    
276
	if (!$input_errors) {
277
		if (!is_array($config['dhcpdv6'][$if]))
278
			$config['dhcpdv6'][$if] = array();
279
		if (!is_array($config['dhcpdv6'][$if]['range']))
280
			$config['dhcpdv6'][$if]['range'] = array();
281
		if (!is_array($config['dhcpdv6'][$if]['prefixrange']))
282
			$config['dhcpdv6'][$if]['prefixrange'] = array();
283

    
284
		$config['dhcpdv6'][$if]['range']['from'] = $_POST['range_from'];
285
		$config['dhcpdv6'][$if]['range']['to'] = $_POST['range_to'];
286
		$config['dhcpdv6'][$if]['prefixrange']['from'] = $_POST['prefixrange_from'];
287
		$config['dhcpdv6'][$if]['prefixrange']['to'] = $_POST['prefixrange_to'];
288
		$config['dhcpdv6'][$if]['prefixrange']['prefixlength'] = $_POST['prefixrange_length'];
289
		$config['dhcpdv6'][$if]['defaultleasetime'] = $_POST['deftime'];
290
		$config['dhcpdv6'][$if]['maxleasetime'] = $_POST['maxtime'];
291
		$config['dhcpdv6'][$if]['netmask'] = $_POST['netmask'];
292

    
293
		unset($config['dhcpdv6'][$if]['winsserver']);
294

    
295
		unset($config['dhcpdv6'][$if]['dnsserver']);
296
		if ($_POST['dns1'])
297
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns1'];
298
		if ($_POST['dns2'])
299
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns2'];
300
		if ($_POST['dns3'])
301
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns3'];
302
		if ($_POST['dns4'])
303
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns4'];
304

    
305
		$config['dhcpdv6'][$if]['domain'] = $_POST['domain'];
306
		$config['dhcpdv6'][$if]['domainsearchlist'] = $_POST['domainsearchlist'];
307
		$config['dhcpdv6'][$if]['enable'] = ($_POST['enable']) ? true : false;
308
		$config['dhcpdv6'][$if]['ddnsdomain'] = $_POST['ddnsdomain'];
309
		$config['dhcpdv6'][$if]['ddnsdomainprimary'] = $_POST['ddnsdomainprimary'];
310
		$config['dhcpdv6'][$if]['ddnsdomainkeyname'] = $_POST['ddnsdomainkeyname'];
311
		$config['dhcpdv6'][$if]['ddnsdomainkey'] = $_POST['ddnsdomainkey'];
312
		$config['dhcpdv6'][$if]['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
313

    
314
		unset($config['dhcpdv6'][$if]['ntpserver']);
315
		if ($_POST['ntp1'])
316
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp1'];
317
		if ($_POST['ntp2'])
318
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp2'];
319

    
320
		$config['dhcpdv6'][$if]['tftp'] = $_POST['tftp'];
321
		$config['dhcpdv6'][$if]['ldap'] = $_POST['ldap'];
322
		$config['dhcpdv6'][$if]['netboot'] = ($_POST['netboot']) ? true : false;
323
		$config['dhcpdv6'][$if]['bootfile_url'] = $_POST['bootfile_url'];
324
		$config['dhcpdv6'][$if]['dhcpv6leaseinlocaltime'] = $_POST['dhcpv6leaseinlocaltime'];
325

    
326
		// Handle the custom options rowhelper
327
		if(isset($config['dhcpdv6'][$if]['numberoptions']['item']))
328
			unset($config['dhcpdv6'][$if]['numberoptions']['item']);
329

    
330
		$config['dhcpdv6'][$if]['numberoptions'] = $numberoptions;
331

    
332
		write_config();
333

    
334
		$retval = 0;
335
		$retvaldhcp = 0;
336
		$retvaldns = 0;
337
		/* Stop DHCPv6 so we can cleanup leases */
338
		killbypid("{$g['dhcpd_chroot_path']}{$g['varrun_path']}/dhcpdv6.pid");
339
		// dhcp_clean_leases();
340
		/* dnsmasq_configure calls dhcpd_configure */
341
		/* no need to restart dhcpd twice */
342
		if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstatic']))	{
343
			$retvaldns = services_dnsmasq_configure();
344
			if ($retvaldns == 0) {
345
				clear_subsystem_dirty('hosts');
346
				clear_subsystem_dirty('staticmaps');
347
			}
348
		} else if (isset($config['unbound']['enable']) && isset($config['unbound']['regdhcpstatic'])) {
349
			$retvaldns = services_unbound_configure();
350
			if ($retvaldns == 0)
351
				clear_subsystem_dirty('unbound');
352
		} else {
353
			$retvaldhcp = services_dhcpd_configure();
354
			if ($retvaldhcp == 0)
355
				clear_subsystem_dirty('staticmaps');
356
		}
357
		if ($dhcpdv6_enable_changed)
358
			$retvalfc = filter_configure();
359
		if($retvaldhcp == 1 || $retvaldns == 1 || $retvalfc == 1)
360
			$retval = 1;
361
		$savemsg = get_std_save_message($retval);
362
	}
363
}
364

    
365
if ($_GET['act'] == "del") {
366
	if ($a_maps[$_GET['id']]) {
367
		unset($a_maps[$_GET['id']]);
368
		write_config();
369
		if(isset($config['dhcpdv6'][$if]['enable'])) {
370
			mark_subsystem_dirty('staticmapsv6');
371
			if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstaticv6']))
372
				mark_subsystem_dirty('hosts');
373
		}
374
		header("Location: services_dhcpv6.php?if={$if}");
375
		exit;
376
	}
377
}
378

    
379
// Delete a row in the options table
380
if($_GET['act'] == "delopt") {
381
	$idx = $_GET['id'];
382

    
383
	if($pconfig['numberoptions'] && is_array($pconfig['numberoptions']['item'][$idx])) {
384
	   unset($pconfig['numberoptions']['item'][$idx]);
385
	}
386
}
387

    
388
// Add an option row
389
if($_GET['act'] == "addopt") {
390
	if(!is_array($pconfig['numberoptions']['item']))
391
		$pconfig['numberoptions']['item'] = array();
392

    
393
	array_push($pconfig['numberoptions']['item'], array('number' => null, 'value' => null));
394
}
395

    
396
$closehead = false;
397
$pgtitle = array(gettext("Services"),gettext("DHCPv6 server"));
398
$shortcut_section = "dhcp6";
399

    
400
include("head.inc");
401

    
402
if ($input_errors)
403
	print_input_errors($input_errors);
404

    
405
if ($savemsg)
406
	print_info_box($savemsg, 'success');
407

    
408
if ($dhcrelay_enabled) {
409
	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');
410
	include("foot.inc");
411
	exit;
412
}
413

    
414
if (is_subsystem_dirty('staticmaps'))
415
	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.'));
416

    
417
/* active tabs */
418
$tab_array = array();
419
$tabscounter = 0;
420
$i = 0;
421
foreach ($iflist as $ifent => $ifname) {
422
	$oc = $config['interfaces'][$ifent];
423
	if ((is_array($config['dhcpdv6'][$ifent]) && !isset($config['dhcpdv6'][$ifent]['enable']) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6'])))) ||
424
		(!is_array($config['dhcpdv6'][$ifent]) && !(is_ipaddrv6($oc['ipaddrv6']) && (!is_linklocal($oc['ipaddrv6'])))))
425
		continue;
426

    
427
	if ($ifent == $if)
428
		$active = true;
429
	else
430
		$active = false;
431

    
432
	$tab_array[] = array($ifname, $active, "services_dhcpv6.php?if={$ifent}");
433
	$tabscounter++;
434
}
435
/* tack on PPPoE or PPtP servers here */
436
/* pppoe server */
437
if (is_array($config['pppoes']['pppoe'])) {
438
	foreach($config['pppoes']['pppoe'] as $pppoe) {
439
		if ($pppoe['mode'] == "server") {
440
			$ifent = "poes". $pppoe['pppoeid'];
441
			$ifname = strtoupper($ifent);
442

    
443
			if ($ifent == $if)
444
				$active = true;
445
			else
446
				$active = false;
447

    
448
			$tab_array[] = array($ifname, $active, "services_dhcpv6.php?if={$ifent}");
449
			$tabscounter++;
450
		}
451
	}
452
}
453

    
454
if (empty($tabs_array)) {
455
	print_info_box(gettext("The DHCPv6 Server can only be enabled on interfaces configured with a static IPv6 address. This system has none."), 'danger');
456
	include("foot.inc");
457
	exit;
458
}
459

    
460
$tab_array = array();
461
$tab_array[] = array(gettext("DHCPv6 Server"),		 true,	"services_dhcpv6.php?if={$if}");
462
$tab_array[] = array(gettext("Router Advertisements"), false, "services_router_advertisements.php?if={$if}");
463
display_top_tabs($tab_array);
464

    
465
require('classes/Form.class.php');
466

    
467
$form = new Form(new Form_Button(
468
	'Submit',
469
	'Save'
470
));
471

    
472
$section = new Form_Section('DHCPv6 Options');
473

    
474
$section->addInput(new Form_Checkbox(
475
	'enable',
476
	'DHCPv6 Server',
477
	'Enable DHCPv6 server on interface ' . $iflist[$if],
478
	$pconfig['enable']
479
))->toggles('.form-group:not(:first-child)');
480

    
481
if(is_ipaddrv6($ifcfgip)) {
482

    
483
	$section->addInput(new Form_StaticText(
484
		'Subnet',
485
		gen_subnetv6($ifcfgip, $ifcfgsn)
486
		));
487

    
488
	$section->addInput(new Form_StaticText(
489
		'Subnet Mask',
490
		$ifcfgsn . ' bits'
491
		));
492

    
493
	$section->addInput(new Form_StaticText(
494
		'Available Range',
495
		$range_from = gen_subnetv6($ifcfgip, $ifcfgsn) . ' to ' . gen_subnetv6_max($ifcfgip, $ifcfgsn)
496
		));
497
}
498

    
499
if($is_olsr_enabled) {
500
	$section->addInput(new Form_Select(
501
	'netmask',
502
	'Subnetmask',
503
	$pconfig['netmask'],
504
	array_combine(range(128, 1, -1), range(128, 1, -1))
505
	));
506
}
507

    
508
$f1 = new Form_Input(
509
	'range_from',
510
	null,
511
	'text',
512
	$pconfig['range_from']
513
);
514

    
515
$f1->setHelp('To');
516

    
517
$f2 = new Form_Input(
518
	'range_to',
519
	null,
520
	'text',
521
	$pconfig['range_to']
522
);
523

    
524
$f2->setHelp('From');
525

    
526
$group = new Form_Group('Range');
527

    
528
$group->add($f1);
529
$group->add($f2);
530

    
531
$section->add($group);
532

    
533
$f1 = new Form_Input(
534
	'prefix_from',
535
	null,
536
	'text',
537
	$pconfig['prefix_from']
538
);
539

    
540
$f1->setHelp('To');
541

    
542
$f2 = new Form_Input(
543
	'prefix_to',
544
	null,
545
	'text',
546
	$pconfig['prefix_to']
547
);
548

    
549
$f2->setHelp('From');
550
$group = new Form_Group('Prefix Delegation Range');
551

    
552
$group->add($f1);
553
$group->add($f2);
554

    
555
$section->add($group);
556

    
557
$section->addInput(new Form_Select(
558
	'prefixrange_length',
559
	'Prefix Delegation Size',
560
	$pconfig['prefixrange_length'],
561
	array(
562
		'48' => '48',
563
		'52' => '52',
564
		'56' => '56',
565
		'60' => '60',
566
		'62' => '62',
567
		'63' => '63',
568
		'64' => '64'
569
		)
570
))->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.');
571

    
572
$group = new Form_Group('DNS Servers');
573

    
574
for($i=1;$i<=4; $i++) {
575
	$group->add(new Form_input(
576
		'dns' . $i,
577
		null,
578
		'text',
579
		$pconfig['dns' . $i]
580
	))->setHelp('DNS ' . $i);
581
}
582

    
583
$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.');
584
$section->add($group);
585

    
586
$section->addInput(new Form_Input(
587
	'domain',
588
	'Domain Name',
589
	'text',
590
	$pconfig['domain']
591
))->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. ');
592

    
593
$section->addInput(new Form_Input(
594
	'domainsearchlist',
595
	'Domain search list',
596
	'text',
597
	$pconfig['domainsearchlist']
598
))->setHelp('The DHCP server can optionally provide a domain search list. Use the semicolon character as separator');
599

    
600
$section->addInput(new Form_Input(
601
	'deftime',
602
	'Default lease time',
603
	'text',
604
	$pconfig['deftime']
605
))->setHelp('Seconds . Used for clients that do not ask for a specific expiration time. ' . ' <br />' .
606
			'The default is 7200 seconds.');
607

    
608
$section->addInput(new Form_Input(
609
	'maxtime',
610
	'Max lease time',
611
	'text',
612
	$pconfig['maxtime']
613
))->setHelp('Maximum lease time for clients that ask for a specific expiration time.' . ' <br />' .
614
			'The default is 86400 seconds.');
615

    
616
$section->addInput(new Form_Checkbox(
617
	'dhcpv6leaseinlocaltime',
618
	'Time Format Change',
619
	'Change DHCPv6 display lease time from UTC to local time',
620
	$pconfig['dhcpv6leaseinlocaltime']
621
))->setHelp('By default DHCPv6 leases are displayed in UTC time. ' .
622
			'By checking this box DHCPv6 lease time will be displayed in local time and set to time zone selected. ' .
623
			'This will be used for all DHCPv6 interfaces lease time.');
624

    
625
$btndyndns = new Form_Button(
626
	'btndyndns',
627
	'Advanced'
628
);
629

    
630
$btndyndns->removeClass('btn-primary')->addClass('btn-default btn-sm');
631

    
632
$section->addInput(new Form_StaticText(
633
	'Dynamic DNS',
634
	$btndyndns . '&nbsp;' . 'Show dynamic DNS settings'
635
));
636

    
637
$section->addInput(new Form_Checkbox(
638
	'ddnsupdate',
639
	'DHCP Registration',
640
	'Enable registration of DHCP client names in DNS.',
641
	$pconfig['ddnsupdate']
642
));
643

    
644
$section->addInput(new Form_Input(
645
	'ddnsdomain',
646
	'DDNS Domain',
647
	'text',
648
	$pconfig['ddnsdomain']
649
))->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.');
650

    
651
$section->addInput(new Form_IpAddress(
652
	'ddnsdomainprimary',
653
	'DDNS Server IP',
654
	$pconfig['ddnsdomainprimary']
655
))->setHelp('Enter the primary domain name server IP address for the dynamic domain name.');
656

    
657
$section->addInput(new Form_Input(
658
	'ddnsdomainkeyname',
659
	'DDNS Domain Key name',
660
	'text',
661
	$pconfig['ddnsdomainkeyname']
662
))->setHelp('Enter the dynamic DNS domain key name which will be used to register client names in the DNS server.');
663

    
664
$section->addInput(new Form_Input(
665
	'ddnsdomainkey',
666
	'DDNS Domain Key secret',
667
	'text',
668
	$pconfig['ddnsdomainkey']
669
))->setHelp('Enter the dynamic DNS domain key secret which will be used to register client names in the DNS server.');
670

    
671
$btnntp = new Form_Button(
672
	'btnntp',
673
	'Advanced'
674
);
675

    
676
$btnntp->removeClass('btn-primary')->addClass('btn-default btn-sm');
677

    
678
$section->addInput(new Form_StaticText(
679
	'NTP servers',
680
	$btnntp . '&nbsp;' . 'Show NTP Configuration'
681
));
682

    
683
$group = new Form_Group('NTP Servers');
684

    
685
$group->add(new Form_Input(
686
	'ntp1',
687
	'NTP Server 1',
688
	'text',
689
	$pconfig['ntp1'],
690
	['placeholder' => 'NTP 1']
691
));
692

    
693
$group->add(new Form_Input(
694
	'ntp2',
695
	'NTP Server 1',
696
	'text',
697
	$pconfig['ntp2'],
698
	['placeholder' => 'NTP 2']
699
));
700

    
701
$group->addClass('ntpclass');
702

    
703
$section->add($group);
704

    
705
$btnldap = new Form_Button(
706
	'btnldap',
707
	'Advanced'
708
);
709

    
710
$btnldap->removeClass('btn-primary')->addClass('btn-default btn-sm');
711

    
712
$section->addInput(new Form_StaticText(
713
	'LDAP',
714
	$btnldap . '&nbsp;' . 'Show LDAP Configuration'
715
));
716

    
717
$section->addInput(new Form_Input(
718
	'ldap',
719
	'LDAP URI',
720
	'text',
721
	$pconfig['ldap']
722
));
723

    
724
$btnnetboot = new Form_Button(
725
	'btnnetboot',
726
	'Advanced'
727
);
728

    
729
$btnnetboot->removeClass('btn-primary')->addClass('btn-default btn-sm');
730

    
731
$section->addInput(new Form_StaticText(
732
	'Network booting',
733
	$btnnetboot . '&nbsp;' . 'Show Netwok booting'
734
));
735

    
736
$section->addInput(new Form_Checkbox(
737
	'shownetboot',
738
	'Network booting',
739
	'Enable Network Booting',
740
	$pconfig['shownetboot']
741
));
742

    
743
$section->addInput(new Form_Input(
744
	'bootfile_url',
745
	'Bootfile URL',
746
	'text',
747
	$pconfig['bootfile_url']
748
));
749

    
750
$btnadnl = new Form_Button(
751
	'btnadnl',
752
	'Advanced'
753
);
754

    
755
$btnadnl->removeClass('btn-primary')->addClass('btn-default btn-sm');
756

    
757
$section->addInput(new Form_StaticText(
758
	'Additional BOOTP/DHCP Options',
759
	$btnadnl . '&nbsp;' . 'Aditional BOOTP/DHCP Options'
760
));
761

    
762
$form->add($section);
763

    
764
$title = 'Show Additional BOOTP/DHCP Options';
765

    
766
if($pconfig['numberoptions']) {
767
	$counter = 0;
768
	$last = count($pconfig['numberoptions']['item']) - 1;
769

    
770
	foreach($pconfig['numberoptions']['item'] as $item) {
771
		$group = new Form_Group(null);
772

    
773
		$group->add(new Form_Input(
774
			'number' . $counter,
775
			null,
776
			'text',
777
			$item['number']
778
		))->setHelp($counter == $last ? 'Number':null);
779

    
780
		$group->add(new Form_Input(
781
			'value' . $counter,
782
			null,
783
			'text',
784
			$item['value']
785
		))->setHelp($counter == $last ? 'Value':null);
786

    
787
		$btn = new Form_Button(
788
			'btn' . $counter,
789
			'Delete',
790
			'services_dhcpv6.php?if=' . $if . '&act=delopt' . '&id=' . $counter
791
		);
792

    
793
		$btn->removeClass('btn-primary')->addClass('btn-danger btn-xs adnlopt');
794
		$group->addClass('adnlopt');
795
		$group->add($btn);
796
		$section->add($group);
797
		$counter++;
798
	}
799
}
800

    
801
$btnaddopt = new Form_Button(
802
	'btnaddopt',
803
	'Add Option',
804
	'services_dhcpv6.php?if=' . $if . '&act=addopt'
805
);
806

    
807
$btnaddopt->removeClass('btn-primary')->addClass('btn-success btn-sm');
808

    
809
$section->addInput($btnaddopt);
810

    
811
$section->addInput(new Form_Input(
812
	'if',
813
	null,
814
	'hidden',
815
	$if
816
));
817

    
818
print($form);
819

    
820
print_info_box(gettext('The DNS servers entered in ') . '<a href="system.php">' . gettext(' System: General setup') . '</a>' .
821
			   gettext(' (or the ') . '<a href="services_dnsmasq.php"/>' . gettext('DNS forwarder') . '</a>, ' . gettext('if enabled) ') .
822
			   gettext('will be assigned to clients by the DHCP server.') . '<br />' .
823
			   gettext('The DHCP lease table can be viewed on the ') . '<a href="status_dhcpv6_leases.php">' .
824
			   gettext('Status: DHCPv6 leases') . '</a>' . gettext(' page.'));
825
?>
826

    
827
<div class="panel panel-default">
828
	<div class="panel-heading">DHCPv6 Static Mappings for this interface.</div>
829
	<div class="panel-body table-responsive">
830
		<table class="table table-striped table-hover table-condensed">
831
			<thead>
832
				<tr>
833
					<th><?=gettext("DUID")?></th>
834
					<th><?=gettext("IPv6 address")?></th>
835
					<th><?=gettext("Hostname")?></th>
836
					<th><?=gettext("Description")?></th>
837
					<th><!-- Buttons --></th>
838
				</tr>
839
			</thead>
840
			<tbody>
841
<?php
842
if(is_array($a_maps)):
843
	$i = 0;
844
	foreach ($a_maps as $mapent):
845
		if($mapent['duid'] != "" or $mapent['ipaddrv6'] != ""):
846
?>
847
				<tr>
848
					<td>
849
						<?=htmlspecialchars($mapent['duid'])?>
850
					</td>
851
					<td>
852
						<?=htmlspecialchars($mapent['ipaddrv6'])?>
853
					</td>
854
					<td>
855
						<?=htmlspecialchars($mapent['hostname'])?>
856
					</td>
857
					<td>
858
						<?=htmlspecialchars($mapent['descr'])?>
859
					</td>
860
					<td>
861
						<a href="services_dhcpv6_edit.php?if=<?=$if?>&amp;id=<?=$i?>" class="btn btn-info btn-xs"/>Edit</a>
862
						<a href="services_dhcpv6.php?if=<?=$if?>&amp;act=del&amp;id=<?=$i?>" class="btn btn-danger btn-xs"/>Delete</a>
863
					</td>
864
				</tr>
865
<?php
866
		endif;
867
	$i++;
868
	endforeach;
869
endif;
870
?>
871
			</tbody>
872
		</table>
873
	</div>
874
</div>
875

    
876
<nav class="action-buttons">
877
	<a href="services_dhcpv6_edit.php?if=<?=$if?>" class="btn btn-sm btn-success"/>Add</a>
878
</nav>
879

    
880
<script>
881
//<![CDATA[
882
events.push(function(){
883
	// Hides the <div> in which the specified input element lives so that the input, its label and help text are hidden
884
	function hideInput(id, hide) {
885
		if(hide)
886
			$('#' + id).parent().parent('div').addClass('hidden');
887
		else
888
			$('#' + id).parent().parent('div').removeClass('hidden');
889
	}
890

    
891
	// Hides the <div> in which the specified icheckbox lives so that the input, its label and help text are hidden
892
	// Checkboxes live inside <label></label> tags so we need another parent level
893
	function hideCheckBox(id, hide) {
894
		if(hide)
895
			$('#' + id).parent().parent().parent('div').addClass('hidden');
896
		else
897
			$('#' + id).parent().parent().parent('div').removeClass('hidden');
898
	}
899

    
900
	// Hides all elements of the specified class. This will usually be a section or group
901
	function hideClass(s_class, hide) {
902
		if(hide)
903
			$('.' + s_class).hide();
904
		else
905
			$('.' + s_class).show();
906
	}
907

    
908
	function hideDDNS(hide) {
909
		hideCheckBox('ddnsupdate', hide);
910
		hideInput('ddnsdomain', hide);
911
		hideInput('ddnsdomainprimary', hide);
912
		hideInput('ddnsdomainkeyname', hide);
913
		hideInput('ddnsdomainkey', hide);
914
	}
915

    
916
	// Make the ‘Copy My MAC’ button a plain button, not a submit button
917
	$("#btnmymac").prop('type','button');
918

    
919
	// On click, copy the hidden 'mymac' text to the 'mac' input
920
	$("#btnmymac").click(function() {
921
		$('#mac').val('<?=$mymac?>');
922
	});
923

    
924
	// Make the ‘tftp’ button a plain button, not a submit button
925
	$("#btntftp").prop('type','button');
926

    
927
	// Show tftp controls
928
	$("#btntftp").click(function() {
929
		hideInput('tftp', false);
930
	});
931

    
932
	// Make the ‘ntp’ button a plain button, not a submit button
933
	$("#btnntp").prop('type','button');
934

    
935
	// Show ntp controls
936
	$("#btnntp").click(function() {
937
		hideClass('ntpclass', false);
938
	});
939

    
940
	// Make the ‘ddns’ button a plain button, not a submit button
941
	$("#btndyndns").prop('type','button');
942

    
943
	// Show ddns controls
944
	$("#btndyndns").click(function() {
945
		hideDDNS(false);
946
	});
947

    
948
	// Make the ‘ldap’ button a plain button, not a submit button
949
	$("#btnldap").prop('type','button');
950

    
951
	// Show ldap controls
952
	$("#btnldap").click(function() {
953
		hideInput('ldap', false);
954
	});
955

    
956
	// Make the ‘netboot’ button a plain button, not a submit button
957
	$("#btnnetboot").prop('type','button');
958

    
959
	// Show netboot controls
960
	$("#btnnetboot").click(function() {
961
		hideInput('bootfile_url', false);
962
		hideCheckBox('shownetboot', false);
963
	});
964

    
965
	// Make the ‘aditional options’ button a plain button, not a submit button
966
	$("#btnadnl").prop('type','button');
967

    
968
	// Show aditional  controls
969
	$("#btnadnl").click(function() {
970
		hideClass('adnlopt', false);
971
		hideInput('btnaddopt', false);
972
	});
973

    
974
	// On initial load
975
	hideDDNS(true);
976
	hideClass('ntpclass', true);
977
	hideInput('tftp', true);
978
	hideInput('ldap', true);
979
	hideInput('bootfile_url', true);
980
	hideCheckBox('shownetboot', true);
981
	hideClass('adnlopt', true);
982
	hideInput('btnaddopt', true);
983
});
984
//]]>
985
</script>
986

    
987
<?php include('foot.inc');
(139-139/241)