Project

General

Profile

Download (37.1 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 (http://www.pfsense.org)
11
	Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
12
	All rights reserved.
13

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

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

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

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

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

    
47
require("guiconfig.inc");
48

    
49
if(!$g['services_dhcp_server_enable']) {
50
	Header("Location: /");
51
	exit;
52
}
53

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

    
59
/* This function will remove entries from dhcpd.leases that would otherwise
60
 * overlap with static DHCP reservations. If we don't clean these out,
61
 * then DHCP will print a warning in the logs about a duplicate lease
62
 */
63
function dhcp_clean_leases() {
64
	global $g, $config;
65
	$leasesfile = "{$g['dhcpd_chroot_path']}/var/db/dhcpdv6.leases";
66
	if (!file_exists($leasesfile))
67
		return;
68
	/* Build list of static MACs */
69
	$staticmacs = array();
70
	foreach($config['interfaces'] as $ifname => $ifarr)
71
		if (is_array($config['dhcpdv6'][$ifname]['staticmap']))
72
			foreach($config['dhcpdv6'][$ifname]['staticmap'] as $static)
73
				$staticmacs[] = $static['mac'];
74
	/* Read existing leases */
75
	$leases_contents = explode("\n", file_get_contents($leasesfile));
76
	$newleases_contents = array();
77
	$i=0;
78
	while ($i < count($leases_contents)) {
79
		/* Find a lease definition */
80
		if (substr($leases_contents[$i], 0, 6) == "lease ") {
81
			$templease = array();
82
			$thismac = "";
83
			/* Read to the end of the lease declaration */
84
			do {
85
				if (substr($leases_contents[$i], 0, 20) == "  hardware ethernet ")
86
					$thismac = substr($leases_contents[$i], 20, 17);
87
				$templease[] = $leases_contents[$i];
88
				$i++;
89
			} while ($leases_contents[$i-1] != "}");
90
			/* Check for a matching MAC address and if not present, keep it. */
91
			if (! in_array($thismac, $staticmacs))
92
				$newleases_contents = array_merge($newleases_contents, $templease);
93
		} else {
94
			/* It's a line we want to keep, copy it over. */
95
			$newleases_contents[] = $leases_contents[$i];
96
			$i++;
97
		}
98
	}
99
	/* Write out the new leases file */
100
	$fd = fopen($leasesfile, 'w');
101
	fwrite($fd, implode("\n", $newleases_contents));
102
	fclose($fd);
103
}
104

    
105
$if = $_GET['if'];
106
if ($_POST['if'])
107
	$if = $_POST['if'];
108

    
109
/* if OLSRD is enabled, allow WAN to house DHCP. */
110
if($config['installedpackages']['olsrd']) {
111
	foreach($config['installedpackages']['olsrd']['config'] as $olsrd) {
112
			if($olsrd['enable']) {
113
				$is_olsr_enabled = true;
114
				break;
115
			}
116
	}
117
}
118

    
119
if (!$_GET['if'])
120
	$savemsg = "<b>" . gettext("The DHCPv6 Server can only be enabled on interfaces configured with static IP addresses") . ".<p>" . gettext("Only interfaces configured with a static IP will be shown") . ".</p></b>";
121

    
122
$iflist = get_configured_interface_with_descr();
123

    
124
/* set the starting interface */
125
if (!$if || !isset($iflist[$if])) {
126
	foreach ($iflist as $ifent => $ifname) {
127
		$oc = $config['interfaces'][$ifent];
128
		if ((is_array($config['dhcpdv6'][$ifent]) && !isset($config['dhcpdv6'][$ifent]['enable']) && (!is_ipaddrv6($oc['ipaddrv6']))) ||
129
			(!is_array($config['dhcpdv6'][$ifent]) && (!is_ipaddrv6($oc['ipaddrv6']))))
130
			continue;
131
		$if = $ifent;
132
		break;
133
	}
134
}
135

    
136
if (is_array($config['dhcpdv6'][$if])){
137
	if (is_array($config['dhcpdv6'][$if]['range'])) {
138
		$pconfig['range_from'] = $config['dhcpdv6'][$if]['range']['from'];
139
		$pconfig['range_to'] = $config['dhcpdv6'][$if]['range']['to'];
140
	}
141
	$pconfig['mode'] = $config['dhcpdv6'][$if]['mode'];
142
	$pconfig['deftime'] = $config['dhcpdv6'][$if]['defaultleasetime'];
143
	$pconfig['maxtime'] = $config['dhcpdv6'][$if]['maxleasetime'];
144
	$pconfig['gateway'] = $config['dhcpdv6'][$if]['gateway'];
145
	$pconfig['domain'] = $config['dhcpdv6'][$if]['domain'];
146
	$pconfig['domainsearchlist'] = $config['dhcpdv6'][$if]['domainsearchlist'];
147
	$pconfig['enable'] = isset($config['dhcpdv6'][$if]['enable']);
148
	$pconfig['denyunknown'] = isset($config['dhcpdv6'][$if]['denyunknown']);
149
	$pconfig['staticarp'] = isset($config['dhcpdv6'][$if]['staticarp']);
150
	$pconfig['ddnsdomain'] = $config['dhcpdv6'][$if]['ddnsdomain'];
151
	$pconfig['ddnsupdate'] = isset($config['dhcpdv6'][$if]['ddnsupdate']);
152
	list($pconfig['ntp1'],$pconfig['ntp2']) = $config['dhcpdv6'][$if]['ntpserver'];
153
	$pconfig['tftp'] = $config['dhcpdv6'][$if]['tftp'];
154
	$pconfig['ldap'] = $config['dhcpdv6'][$if]['ldap'];
155
	$pconfig['netboot'] = isset($config['dhcpdv6'][$if]['netboot']);
156
	$pconfig['nextserver'] = $config['dhcpdv6'][$if]['next-server'];
157
	$pconfig['filename'] = $config['dhcpdv6'][$if]['filename'];
158
	$pconfig['rootpath'] = $config['dhcpdv6'][$if]['rootpath'];
159
	$pconfig['failover_peerip'] = $config['dhcpdv6'][$if]['failover_peerip'];
160
	$pconfig['netmask'] = $config['dhcpdv6'][$if]['netmask'];
161
	$pconfig['numberoptions'] = $config['dhcpdv6'][$if]['numberoptions'];
162
	if (!is_array($config['dhcpdv6'][$if]['staticmap']))
163
		$config['dhcpdv6'][$if]['staticmap'] = array();
164
	$a_maps = &$config['dhcpdv6'][$if]['staticmap'];
165
}
166

    
167
$ifcfgip = get_interface_ipv6($if);
168
$ifcfgsn = get_interface_subnetv6($if);
169

    
170
/*   set the enabled flag which will tell us if DHCP relay is enabled
171
 *   on any interface. We will use this to disable DHCP server since
172
 *   the two are not compatible with each other.
173
 */
174

    
175
$dhcrelay_enabled = false;
176
$dhcrelaycfg = $config['dhcrelay'];
177

    
178
if(is_array($dhcrelaycfg)) {
179
	foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) {
180
		if (isset($dhcrelayifconf['enable']) && isset($iflist[$dhcrelayif]) &&
181
			(!link_interface_to_bridge($dhcrelayif)))
182
			$dhcrelay_enabled = true;
183
	}
184
}
185

    
186
/* FIXME needs v6 code, use in subnet v6? */
187
function is_inrange($test, $start, $end) {
188
	if ( (ip2ulong($test) < ip2ulong($end)) && (ip2ulong($test) > ip2ulong($start)) )
189
		return true;
190
	else
191
		return false;
192
}
193

    
194
$modes = array("unmanaged" => "Unmanaged", "managed" => "Managed", "assist" => "Assisted");
195

    
196
if ($_POST) {
197

    
198
	unset($input_errors);
199

    
200
	$pconfig = $_POST;
201

    
202
	$numberoptions = array();
203
	for($x=0; $x<99; $x++) {
204
		if(isset($_POST["number{$x}"]) && ctype_digit($_POST["number{$x}"])) {
205
			$numbervalue = array();
206
			$numbervalue['number'] = htmlspecialchars($_POST["number{$x}"]);
207
			$numbervalue['value'] = htmlspecialchars($_POST["value{$x}"]);
208
			$numberoptions['item'][] = $numbervalue;
209
		}
210
	}
211
	// Reload the new pconfig variable that the forum uses.
212
	$pconfig['numberoptions'] = $numberoptions;
213

    
214
	/* input validation */
215
	if ($_POST['enable']) {
216
		$reqdfields = explode(" ", "range_from range_to");
217
		$reqdfieldsn = array(gettext("Range begin"),gettext("Range end"));
218

    
219
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
220

    
221
		if (($_POST['range_from'] && !is_ipaddrv6($_POST['range_from'])))
222
			$input_errors[] = gettext("A valid range must be specified.");
223
		if (($_POST['range_to'] && !is_ipaddrv6($_POST['range_to'])))
224
			$input_errors[] = gettext("A valid range must be specified.");
225
		if (($_POST['gateway'] && !is_ipaddrv6($_POST['gateway'])))
226
			$input_errors[] = gettext("A valid IPv6 address must be specified for the gateway.");
227
		if (($_POST['dns1'] && !is_ipaddrv6($_POST['dns1'])) || ($_POST['dns2'] && !is_ipaddrv6($_POST['dns2'])))
228
			$input_errors[] = gettext("A valid IPv6 address must be specified for the primary/secondary DNS servers.");
229

    
230
		if ($_POST['deftime'] && (!is_numeric($_POST['deftime']) || ($_POST['deftime'] < 60)))
231
			$input_errors[] = gettext("The default lease time must be at least 60 seconds.");
232
		if ($_POST['maxtime'] && (!is_numeric($_POST['maxtime']) || ($_POST['maxtime'] < 60) || ($_POST['maxtime'] <= $_POST['deftime'])))
233
			$input_errors[] = gettext("The maximum lease time must be at least 60 seconds and higher than the default lease time.");
234
		if (($_POST['ddnsdomain'] && !is_domain($_POST['ddnsdomain'])))
235
			$input_errors[] = gettext("A valid domain name must be specified for the dynamic DNS registration.");
236
		if (($_POST['ntp1'] && !is_ipaddrv6($_POST['ntp1'])) || ($_POST['ntp2'] && !is_ipaddrv6($_POST['ntp2'])))
237
			$input_errors[] = gettext("A valid IPv6 address must be specified for the primary/secondary NTP servers.");
238
		if (($_POST['domain'] && !is_domain($_POST['domain'])))
239
			$input_errors[] = gettext("A valid domain name must be specified for the DNS domain.");
240
		if ($_POST['tftp'] && !is_ipaddr($_POST['tftp']) && !is_domain($_POST['tftp']) && !is_URL($_POST['tftp']))
241
			$input_errors[] = gettext("A valid IPv6 address or hostname must be specified for the TFTP server.");
242
		if (($_POST['nextserver'] && !is_ipaddrv6($_POST['nextserver'])))
243
			$input_errors[] = gettext("A valid IPv6 address must be specified for the network boot server.");
244

    
245
		if(gen_subnet($ifcfgip, $ifcfgsn) == $_POST['range_from'])
246
			$input_errors[] = gettext("You cannot use the network address in the starting subnet range.");
247
		if(gen_subnet_max($ifcfgip, $ifcfgsn) == $_POST['range_to'])
248
			$input_errors[] = gettext("You cannot use the broadcast address in the ending subnet range.");
249

    
250
		// Disallow a range that includes the virtualip
251
		if (is_array($config['virtualip']['vip'])) {
252
			foreach($config['virtualip']['vip'] as $vip) {
253
				if($vip['interface'] == $if)
254
					if($vip['subnetv6'] && is_inrange($vip['subnetv6'], $_POST['range_from'], $_POST['range_to']))
255
						$input_errors[] = sprintf(gettext("The subnet range cannot overlap with virtual IPv6 address %s."),$vip['subnetv6']);
256
			}
257
		}
258

    
259
		$noip = false;
260
		if(is_array($a_maps))
261
			foreach ($a_maps as $map)
262
				if (empty($map['ipaddrv6']))
263
					$noip = true;
264
		if ($_POST['staticarp'] && $noip)
265
			$input_errors[] = "Cannot enable static ARP when you have static map entries without IP addresses. Ensure all static maps have IPv6 addresses and try again.";
266

    
267
		if (!$input_errors) {
268
			/* make sure the range lies within the current subnet */
269
			/* FIXME change for ipv6 subnet */
270
			$subnet_start = gen_subnetv6($ifcfgip, $ifcfgsn);
271
			$subnet_end = gen_subnetv6_max($ifcfgip, $ifcfgsn);
272

    
273
			if((! ip_in_subnet($_POST['range_from'], $subnet_start)) || (! ip_in_subnet($_POST['range_to'], $subnet_start))) {
274
				$input_errors[] = gettext("The specified range lies outside of the current subnet.");
275
			}
276

    
277
			/* no idea how to do this yet 
278
			if (ip2ulong($_POST['range_from']) > ip2ulong($_POST['range_to']))
279
				$input_errors[] = gettext("The range is invalid (first element higher than second element).");
280
			*/
281

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

    
286
			// $dynsubnet_start = ip2ulong($_POST['range_from']);
287
			// $dynsubnet_end = ip2ulong($_POST['range_to']);
288
			/* FIX later.
289
			if(is_array($a_maps)) {
290
				foreach ($a_maps as $map) {
291
					if (empty($map['ipaddrv6']))
292
						continue;
293
					if ((ip2ulong($map['ipaddrv6']) > $dynsubnet_start) &&
294
						(ip2ulong($map['ipaddr']) < $dynsubnet_end)) {
295
						$input_errors[] = sprintf(gettext("The DHCP range cannot overlap any static DHCP mappings."));
296
						break;
297
					}
298
				}
299
			}
300
			*/
301
		}
302
	}
303

    
304
	if (!$input_errors) {
305
		if (!is_array($config['dhcpdv6'][$if]))
306
			$config['dhcpdv6'][$if] = array();
307
		if (!is_array($config['dhcpdv6'][$if]['range']))
308
			$config['dhcpdv6'][$if]['range'] = array();
309

    
310
		$config['dhcpdv6'][$if]['mode'] = $_POST['mode'];
311
		$config['dhcpdv6'][$if]['range']['from'] = $_POST['range_from'];
312
		$config['dhcpdv6'][$if]['range']['to'] = $_POST['range_to'];
313
		$config['dhcpdv6'][$if]['defaultleasetime'] = $_POST['deftime'];
314
		$config['dhcpdv6'][$if]['maxleasetime'] = $_POST['maxtime'];
315
		$config['dhcpdv6'][$if]['netmask'] = $_POST['netmask'];
316
		$previous = $config['dhcpdv6'][$if]['failover_peerip'];
317
		if($previous <> $_POST['failover_peerip'])
318
			mwexec("/bin/rm -rf /var/dhcpd/var/db/*");
319

    
320
		$config['dhcpdv6'][$if]['failover_peerip'] = $_POST['failover_peerip'];
321

    
322
		unset($config['dhcpdv6'][$if]['winsserver']);
323

    
324
		unset($config['dhcpdv6'][$if]['dnsserver']);
325
		if ($_POST['dns1'])
326
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns1'];
327
		if ($_POST['dns2'])
328
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns2'];
329

    
330
		$config['dhcpdv6'][$if]['gateway'] = $_POST['gateway'];
331
		$config['dhcpdv6'][$if]['domain'] = $_POST['domain'];
332
		$config['dhcpdv6'][$if]['domainsearchlist'] = $_POST['domainsearchlist'];
333
		$config['dhcpdv6'][$if]['denyunknown'] = ($_POST['denyunknown']) ? true : false;
334
		$config['dhcpdv6'][$if]['enable'] = ($_POST['enable']) ? true : false;
335
		$config['dhcpdv6'][$if]['staticarp'] = ($_POST['staticarp']) ? true : false;
336
		$config['dhcpdv6'][$if]['ddnsdomain'] = $_POST['ddnsdomain'];
337
		$config['dhcpdv6'][$if]['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
338

    
339
		unset($config['dhcpdv6'][$if]['ntpserver']);
340
		if ($_POST['ntp1'])
341
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp1'];
342
		if ($_POST['ntp2'])
343
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp2'];
344

    
345
		$config['dhcpdv6'][$if]['tftp'] = $_POST['tftp'];
346
		$config['dhcpdv6'][$if]['ldap'] = $_POST['ldap'];
347
		$config['dhcpdv6'][$if]['netboot'] = ($_POST['netboot']) ? true : false;
348
		$config['dhcpdv6'][$if]['next-server'] = $_POST['nextserver'];
349
		$config['dhcpdv6'][$if]['filename'] = $_POST['filename'];
350
		$config['dhcpdv6'][$if]['rootpath'] = $_POST['rootpath'];
351

    
352
		// Handle the custom options rowhelper
353
		if(isset($config['dhcpdv6'][$if]['numberoptions']['item']))
354
			unset($config['dhcpdv6'][$if]['numberoptions']['item']);
355

    
356
		$config['dhcpdv6'][$if]['numberoptions'] = $numberoptions;
357

    
358
		write_config();
359

    
360
		$retval = 0;
361
		$retvaldhcp = 0;
362
		$retvaldns = 0;
363
		/* Stop DHCPv6 so we can cleanup leases */
364
		killbyname("dhcpdv6");
365
		dhcp_clean_leases();
366
		/* dnsmasq_configure calls dhcpd_configure */
367
		/* no need to restart dhcpd twice */
368
		if (isset($config['dnsmasq']['regdhcpstatic']))	{
369
			$retvaldns = services_dnsmasq_configure();
370
			if ($retvaldns == 0) {
371
				clear_subsystem_dirty('hosts');
372
				clear_subsystem_dirty('staticmaps');
373
			}
374
		} else {
375
			$retvaldhcp = services_dhcpd_configure();
376
			if ($retvaldhcp == 0)
377
				clear_subsystem_dirty('staticmaps');
378
		}
379
		if($retvaldhcp == 1 || $retvaldns == 1)
380
			$retval = 1;
381
		$savemsg = get_std_save_message($retval);
382
	}
383
}
384

    
385
if ($_GET['act'] == "del") {
386
	if ($a_maps[$_GET['id']]) {
387
		unset($a_maps[$_GET['id']]);
388
		write_config();
389
		if(isset($config['dhcpdv6'][$if]['enable'])) {
390
			mark_subsystem_dirty('staticmapsv6');
391
			if (isset($config['dnsmasq']['regdhcpstaticv6']))
392
				mark_subsystem_dirty('hosts');
393
		}
394
		header("Location: services_dhcpv6.php?if={$if}");
395
		exit;
396
	}
397
}
398

    
399
$pgtitle = array(gettext("Services"),gettext("DHCPv6 server"));
400
$statusurl = "status_dhcp_leases.php";
401
$logurl = "diag_logs_dhcp.php";
402

    
403
include("head.inc");
404

    
405
?>
406

    
407
<script type="text/javascript" src="/javascript/row_helper.js">
408
</script>
409

    
410
<script type="text/javascript">
411
	rowname[0] = "number";
412
	rowtype[0] = "textbox";
413
	rowsize[0] = "10";
414
	rowname[1] = "value";
415
	rowtype[1] = "textbox";
416
	rowsize[1] = "55";
417
</script>
418

    
419
<script type="text/javascript" language="JavaScript">
420
	function enable_change(disableFields) {
421
		document.iform.range_from.disabled = disableFields;
422
		document.iform.range_to.disabled = disableFields;
423
		document.iform.dns1.disabled = disableFields;
424
		document.iform.dns2.disabled = disableFields;
425
		document.iform.deftime.disabled = disableFields;
426
		document.iform.maxtime.disabled = disableFields;
427
		document.iform.gateway.disabled = disableFields;
428
		document.iform.failover_peerip.disabled = disableFields;
429
		document.iform.domain.disabled = disableFields;
430
		document.iform.domainsearchlist.disabled = disableFields;
431
		document.iform.staticarp.disabled = disableFields;
432
		document.iform.ddnsdomain.disabled = disableFields;
433
		document.iform.ddnsupdate.disabled = disableFields;
434
		document.iform.ntp1.disabled = disableFields;
435
		document.iform.ntp2.disabled = disableFields;
436
		document.iform.tftp.disabled = disableFields;
437
		document.iform.ldap.disabled = disableFields;
438
		document.iform.netboot.disabled = disableFields;
439
		document.iform.nextserver.disabled = disableFields;
440
		document.iform.filename.disabled = disableFields;
441
		document.iform.rootpath.disabled = disableFields;
442
		document.iform.denyunknown.disabled = disableFields;
443
	}
444

    
445
	function show_shownumbervalue() {
446
		document.getElementById("shownumbervaluebox").innerHTML='';
447
		aodiv = document.getElementById('shownumbervalue');
448
		aodiv.style.display = "block";
449
	}
450

    
451
	function show_ddns_config() {
452
		document.getElementById("showddnsbox").innerHTML='';
453
		aodiv = document.getElementById('showddns');
454
		aodiv.style.display = "block";
455
	}
456

    
457
	function show_ntp_config() {
458
		document.getElementById("showntpbox").innerHTML='';
459
		aodiv = document.getElementById('showntp');
460
		aodiv.style.display = "block";
461
	}
462

    
463
	function show_tftp_config() {
464
		document.getElementById("showtftpbox").innerHTML='';
465
		aodiv = document.getElementById('showtftp');
466
		aodiv.style.display = "block";
467
	}
468

    
469
	function show_ldap_config() {
470
		document.getElementById("showldapbox").innerHTML='';
471
		aodiv = document.getElementById('showldap');
472
		aodiv.style.display = "block";
473
	}
474

    
475
	function show_netboot_config() {
476
		document.getElementById("shownetbootbox").innerHTML='';
477
		aodiv = document.getElementById('shownetboot');
478
		aodiv.style.display = "block";
479
	}
480
</script>
481

    
482
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
483
<?php include("fbegin.inc"); ?>
484
<form action="services_dhcpv6.php" method="post" name="iform" id="iform">
485
<?php if ($input_errors) print_input_errors($input_errors); ?>
486
<?php if ($savemsg) print_info_box($savemsg); ?>
487
<?php
488
	if ($dhcrelay_enabled) {
489
		echo gettext("DHCP Relay is currently enabled. Cannot enable the DHCP Server service while the DHCP Relay is enabled on any interface.");
490
		include("fend.inc");
491
		echo "</body>";
492
		echo "</html>";
493
		exit;
494
	}
495
?>
496
<?php if (is_subsystem_dirty('staticmaps')): ?><p>
497
<?php 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."));?><br>
498
<?php endif; ?>
499
<table width="100%" border="0" cellpadding="0" cellspacing="0">
500
<tr><td>
501
<?php
502
	/* active tabs */
503
	$tab_array = array();
504
	$tabscounter = 0;
505
	$i = 0;
506
	foreach ($iflist as $ifent => $ifname) {
507
		$oc = $config['interfaces'][$ifent];
508
		if ((is_array($config['dhcpdv6'][$ifent]) && !isset($config['dhcpdv6'][$ifent]['enable']) && (!is_ipaddrv6($oc['ipaddrv6']))) ||
509
			(!is_array($config['dhcpdv6'][$ifent]) && (!is_ipaddrv6($oc['ipaddrv6']))))
510
			continue;
511
		if ($ifent == $if)
512
			$active = true;
513
		else
514
			$active = false;
515
		$tab_array[] = array($ifname, $active, "services_dhcpv6.php?if={$ifent}");
516
		$tabscounter++;
517
	}
518
	if ($tabscounter == 0) {
519
		echo "</td></tr></table></form>";
520
		include("fend.inc");
521
		echo "</body>";
522
		echo "</html>";
523
		exit;
524
	}
525
	display_top_tabs($tab_array);
526
?>
527
</td></tr>
528
<tr>
529
<td>
530
	<div id="mainarea">
531
		<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
532
			<tr>
533
			<td width="22%" valign="top" class="vtable">&nbsp;</td>
534
			<td width="78%" class="vtable">
535
				<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(this.checked);">
536
			<strong><?php printf(gettext("Enable DHCPv6 server on " .
537
			"%s " .
538
			"interface"),htmlspecialchars($iflist[$if]));?></strong></td>
539
			</tr>
540
			<tr>
541
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Operating Mode");?></td>
542
			<td width="78%" class="vtable">
543
				<select name="mode" id="mode" onchange="enable_change(this.value=='unmanaged');">
544
					<?php foreach($modes as $name => $value) { ?>
545
					<option value="<?=$name ?>" <?php if ($pconfig['mode'] == $name) echo "selected"; ?> > <?=$value ?></option>
546
					<?php } ?>
547
				</select><br />
548
			<strong><?php printf(gettext("Select the Operating Mode. Use Unmanaged for Router Advertising only, Managed for DHCPv6 only, Assisted for Combined"));?></strong></td>
549
			</tr>
550
			<tr>
551
			<td width="22%" valign="top" class="vtable">&nbsp;</td>
552
			<td width="78%" class="vtable">
553
				<input name="denyunknown" id="denyunknown" type="checkbox" value="yes" <?php if ($pconfig['denyunknown']) echo "checked"; ?>>
554
				<strong><?=gettext("Deny unknown clients");?></strong><br>
555
				<?=gettext("If this is checked, only the clients defined below will get DHCP leases from this server. ");?></td>
556
			</tr>
557
			<tr>
558
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Subnet");?></td>
559
			<td width="78%" class="vtable">
560
				<?=gen_subnetv6($ifcfgip, $ifcfgsn);?>
561
			</td>
562
			</tr>
563
			<tr>
564
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Subnet mask");?></td>
565
			<td width="78%" class="vtable">
566
				<?=$ifcfgsn;?> bits
567
			</td>
568
			</tr>
569
			<tr>
570
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Available range");?></td>
571
			<td width="78%" class="vtable">
572
			<?php
573
				$range_from = gen_subnetv6($ifcfgip, $ifcfgsn);
574
				$range_from++;
575
				echo $range_from;
576

    
577
			?>
578
			-
579
			<?php
580
				/* FIXME end of subnet calculation here */
581
				$range_to = gen_subnetv6_max($ifcfgip, $ifcfgsn);;
582
				echo $range_to;
583
			?>
584
			</td>
585
			</tr>
586
			<?php if($is_olsr_enabled): ?>
587
			<tr>
588
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Subnet Mask");?></td>
589
			<td width="78%" class="vtable">
590
				<select name="netmask" class="formselect" id="netmask">
591
				<?php
592
				for ($i = 128; $i > 0; $i--) {
593
					if($i <> 127) {
594
						echo "<option value=\"{$i}\" ";
595
						if ($i == $pconfig['netmask']) echo "selected";
596
						echo ">" . $i . "</option>";
597
					}
598
				}
599
				?>
600
				</select>
601
			</td>
602
			</tr>
603
			<?php endif; ?>
604
			<tr>
605
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Range");?></td>
606
			<td width="78%" class="vtable">
607
				<input name="range_from" type="text" class="formfld unknown" id="range_from" size="28" value="<?=htmlspecialchars($pconfig['range_from']);?>">
608
				&nbsp;<?=gettext("to"); ?>&nbsp; <input name="range_to" type="text" class="formfld unknown" id="range_to" size="28" value="<?=htmlspecialchars($pconfig['range_to']);?>">
609
			</td>
610
			</tr>
611
			<tr>
612
			<td width="22%" valign="top" class="vncell"><?=gettext("DNS servers");?></td>
613
			<td width="78%" class="vtable">
614
				<input name="dns1" type="text" class="formfld unknown" id="dns1" size="28" value="<?=htmlspecialchars($pconfig['dns1']);?>"><br>
615
				<input name="dns2" type="text" class="formfld unknown" id="dns2" size="28" value="<?=htmlspecialchars($pconfig['dns2']);?>"><br>
616
				<?=gettext("NOTE: leave blank to use the system default DNS servers - this interface's IP if DNS forwarder is enabled, otherwise the servers configured on the General page.");?>
617
			</td>
618
			</tr>
619
			<tr>
620
			<td width="22%" valign="top" class="vncell"><?=gettext("Gateway");?></td>
621
			<td width="78%" class="vtable">
622
				<input name="gateway" type="text" class="formfld host" id="gateway" size="28" value="<?=htmlspecialchars($pconfig['gateway']);?>"><br>
623
			 	 <?=gettext("The default is to use the IP on this interface of the firewall as the gateway. Specify an alternate gateway here if this is not the correct gateway for your network.");?>
624
			</td>
625
			</tr>
626
			<tr>
627
			<td width="22%" valign="top" class="vncell"><?=gettext("Domain name");?></td>
628
			<td width="78%" class="vtable">
629
				<input name="domain" type="text" class="formfld unknown" id="domain" size="28" value="<?=htmlspecialchars($pconfig['domain']);?>"><br>
630
				 <?=gettext("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.");?>
631
			 </td>
632
			</tr>
633
			<tr>
634
			<td width="22%" valign="top" class="vncell"><?=gettext("Domain search list");?></td>
635
			<td width="78%" class="vtable">
636
				<input name="domainsearchlist" type="text" class="formfld unknown" id="domainsearchlist" size="28" value="<?=htmlspecialchars($pconfig['domainsearchlist']);?>"><br>
637
				<?=gettext("The DHCP server can optionally provide a domain search list.");?>
638
			</td>
639
			</tr>
640
			<tr>
641
			<td width="22%" valign="top" class="vncell"><?=gettext("Default lease time");?></td>
642
			<td width="78%" class="vtable">
643
				<input name="deftime" type="text" class="formfld unknown" id="deftime" size="10" value="<?=htmlspecialchars($pconfig['deftime']);?>">
644
				<?=gettext("seconds");?><br>
645
				<?=gettext("This is used for clients that do not ask for a specific " .
646
				"expiration time."); ?><br>
647
				<?=gettext("The default is 7200 seconds.");?>
648
			</td>
649
			</tr>
650
			<tr>
651
			<td width="22%" valign="top" class="vncell"><?=gettext("Maximum lease time");?></td>
652
			<td width="78%" class="vtable">
653
				<input name="maxtime" type="text" class="formfld unknown" id="maxtime" size="10" value="<?=htmlspecialchars($pconfig['maxtime']);?>">
654
				<?=gettext("seconds");?><br>
655
				<?=gettext("This is the maximum lease time for clients that ask".
656
				" for a specific expiration time."); ?><br>
657
				<?=gettext("The default is 86400 seconds.");?>
658
			</td>
659
			</tr>
660
			<tr>
661
			<td width="22%" valign="top" class="vncell"><?=gettext("Failover peer IP:");?></td>
662
			<td width="78%" class="vtable">
663
				<input name="failover_peerip" type="text" class="formfld host" id="failover_peerip" size="28" value="<?=htmlspecialchars($pconfig['failover_peerip']);?>"><br>
664
				<?=gettext("Leave blank to disable.  Enter the interface IP address of the other machine.  Machines must be using CARP.");?>
665
			</td>
666
			</tr>
667
			<tr>
668
			<td width="22%" valign="top" class="vncell"><?=gettext("Static ARP");?></td>
669
			<td width="78%" class="vtable">
670
				<table>
671
					<tr>
672
					<td>
673
						<input valign="middle" type="checkbox" value="yes" name="staticarp" id="staticarp" <?php if($pconfig['staticarp']) echo " checked"; ?>>&nbsp;
674
					</td>
675
					<td><b><?=gettext("Enable Static ARP entries");?></b></td>
676
					</tr>
677
					<tr>
678
					<td>&nbsp;</td>
679
					<td>
680
						<span class="red"><strong><?=gettext("Note:");?></strong></span> <?=gettext("Only the machines listed below will be able to communicate with the firewall on this NIC.");?>
681
					</td>
682
					</tr>
683
				</table>
684
			</td>
685
			</tr>
686
			<tr>
687
			<td width="22%" valign="top" class="vncell"><?=gettext("Dynamic DNS");?></td>
688
			<td width="78%" class="vtable">
689
				<div id="showddnsbox">
690
					<input type="button" onClick="show_ddns_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show Dynamic DNS");?></a>
691
				</div>
692
				<div id="showddns" style="display:none">
693
					<input valign="middle" type="checkbox" value="yes" name="ddnsupdate" id="ddnsupdate" <?php if($pconfig['ddnsupdate']) echo " checked"; ?>>&nbsp;
694
					<b><?=gettext("Enable registration of DHCP client names in DNS.");?></b><br />
695
					<p>
696
					<input name="ddnsdomain" type="text" class="formfld unknown" id="ddnsdomain" size="28" value="<?=htmlspecialchars($pconfig['ddnsdomain']);?>"><br />
697
					<?=gettext("Note: Leave blank to disable dynamic DNS registration.");?><br />
698
					<?=gettext("Enter the dynamic DNS domain which will be used to register client names in the DNS server.");?>
699
				</div>
700
			</td>
701
			</tr>
702
			<tr>
703
			<td width="22%" valign="top" class="vncell"><?=gettext("NTP servers");?></td>
704
			<td width="78%" class="vtable">
705
				<div id="showntpbox">
706
					<input type="button" onClick="show_ntp_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show NTP configuration");?></a>
707
				</div>
708
				<div id="showntp" style="display:none">
709
					<input name="ntp1" type="text" class="formfld unknown" id="ntp1" size="28" value="<?=htmlspecialchars($pconfig['ntp1']);?>"><br>
710
					<input name="ntp2" type="text" class="formfld unknown" id="ntp2" size="28" value="<?=htmlspecialchars($pconfig['ntp2']);?>">
711
				</div>
712
			</td>
713
			</tr>
714
			<tr>
715
			<td width="22%" valign="top" class="vncell"><?=gettext("TFTP server");?></td>
716
			<td width="78%" class="vtable">
717
			<div id="showtftpbox">
718
				<input type="button" onClick="show_tftp_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show TFTP configuration");?></a>
719
			</div>
720
			<div id="showtftp" style="display:none">
721
				<input name="tftp" type="text" class="formfld unknown" id="tftp" size="50" value="<?=htmlspecialchars($pconfig['tftp']);?>"><br>
722
				<?=gettext("Leave blank to disable.  Enter a full hostname or IP for the TFTP server.");?>
723
			</div>
724
			</td>
725
			</tr>
726
			<tr>
727
			<td width="22%" valign="top" class="vncell"><?=gettext("LDAP URI");?></td>
728
			<td width="78%" class="vtable">
729
				<div id="showldapbox">
730
					<input type="button" onClick="show_ldap_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show LDAP configuration");?></a>
731
				</div>
732
				<div id="showldap" style="display:none">
733
					<input name="ldap" type="text" class="formfld unknown" id="ldap" size="80" value="<?=htmlspecialchars($pconfig['ldap']);?>"><br>
734
					<?=gettext("Leave blank to disable.  Enter a full URI for the LDAP server in the form ldap://ldap.example.com/dc=example,dc=com");?>
735
				</div>
736
			</td>
737
			</tr>
738
			<tr>
739
			<td width="22%" valign="top" class="vncell"><?=gettext("Enable network booting");?></td>
740
			<td width="78%" class="vtable">
741
				<div id="shownetbootbox">
742
					<input type="button" onClick="show_netboot_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show Network booting");?></a>
743
				</div>
744
				<div id="shownetboot" style="display:none">
745
					<input valign="middle" type="checkbox" value="yes" name="netboot" id="netboot" <?php if($pconfig['netboot']) echo " checked"; ?>>&nbsp;
746
					<b><?=gettext("Enables network booting.");?></b>
747
					<p>
748
					<?=gettext("Enter the IP of the"); ?> <b><?=gettext("next-server"); ?></b>
749
					<input name="nextserver" type="text" class="formfld unknown" id="nextserver" size="28" value="<?=htmlspecialchars($pconfig['nextserver']);?>">
750
					<?=gettext("and the filename");?>
751
					<input name="filename" type="text" class="formfld unknown" id="filename" size="28" value="<?=htmlspecialchars($pconfig['filename']);?>"><br>
752
					<?=gettext("Note: You need both a filename and a boot server configured for this to work!");?>
753
					<p>
754
					<?=gettext("Enter the"); ?> <b><?=gettext("root-path"); ?></b>-<?=gettext("string");?>
755
					<input name="rootpath" type="text" class="formfld unknown" id="rootpath" size="90" value="<?=htmlspecialchars($pconfig['rootpath']);?>"><br>
756
					<?=gettext("Note: string-format: iscsi:(servername):(protocol):(port):(LUN):targetname");?>
757
				</div>
758
			</td>
759
			</tr>
760
			<tr>
761
			<td width="22%" valign="top" class="vncell"><?=gettext("Additional BOOTP/DHCP Options");?></td>
762
			<td width="78%" class="vtable">
763
				<div id="shownumbervaluebox">
764
					<input type="button" onClick="show_shownumbervalue()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show Additional BOOTP/DHCP Options");?></a>
765
				</div>
766
				<div id="shownumbervalue" style="display:none">
767
				<table id="maintable">
768
				<tbody>
769
				<tr>
770
				<td colspan="3">
771
					<div style="padding:5px; margin-top: 16px; margin-bottom: 16px; border:1px dashed #000066; background-color: #ffffff; color: #000000; font-size: 8pt;" id="itemhelp">
772
					<?=gettext("Enter the DHCP option number and the value for each item you would like to include in the DHCP lease information.  For a list of available options please visit this"); ?> <a href="http://www.iana.org/assignments/bootp-dhcp-parameters/" target="_new"><?=gettext("URL"); ?></a>
773
					</div>
774
				</td>
775
				</tr>
776
				<tr>
777
				<td><div id="onecolumn"><?=gettext("Number");?></div></td>
778
				<td><div id="twocolumn"><?=gettext("Value");?></div></td>
779
				</tr>
780
				<?php $counter = 0; ?>
781
				<?php
782
					if($pconfig['numberoptions'])
783
						foreach($pconfig['numberoptions']['item'] as $item):
784
				?>
785
					<?php
786
						$number = $item['number'];
787
						$value = $item['value'];
788
					?>
789
				<tr>
790
				<td>
791
					<input autocomplete="off" name="number<?php echo $counter; ?>" type="text" class="formfld" id="number<?php echo $counter; ?>" size="10" value="<?=htmlspecialchars($number);?>" />
792
				</td>
793
				<td>
794
					<input autocomplete="off" name="value<?php echo $counter; ?>" type="text" class="formfld" id="value<?php echo $counter; ?>" size="55" value="<?=htmlspecialchars($value);?>" />
795
				</td>
796
				<td>
797
					<input type="image" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" onclick="removeRow(this); return false;" value="<?=gettext("Delete");?>" />
798
				</td>
799
				</tr>
800
				<?php $counter++; ?>
801
				<?php endforeach; ?>
802
				</tbody>
803
				<tfoot>
804
				</tfoot>
805
				</table>
806
				<a onclick="javascript:addRowTo('maintable', 'formfldalias'); return false;" href="#">
807
					<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
808
				</a>
809
				<script type="text/javascript">
810
					field_counter_js = 2;
811
					rows = 1;
812
					totalrows = <?php echo $counter; ?>;
813
					loaded = <?php echo $counter; ?>;
814
				</script>
815
				</div>
816

    
817
				</td>
818
			</tr>
819
			<tr>
820
			<td width="22%" valign="top">&nbsp;</td>
821
			<td width="78%">
822
				<input name="if" type="hidden" value="<?=$if;?>">
823
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onclick="enable_change(true)">
824
			</td>
825
			</tr>
826
			<tr>
827
			<td width="22%" valign="top">&nbsp;</td>
828
			<td width="78%"> <p><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br>
829
				</strong></span><?=gettext("The DNS servers entered in"); ?> <a href="system.php"><?=gettext("System: " .
830
				"General setup"); ?></a> <?=gettext("(or the"); ?> <a href="services_dnsmasq.php"><?=gettext("DNS " .
831
				"forwarder"); ?></a>, <?=gettext("if enabled)"); ?> </span><span class="vexpl"><?=gettext("will " .
832
				"be assigned to clients by the DHCP server."); ?><br>
833
				<br>
834
				<?=gettext("The DHCP lease table can be viewed on the"); ?> <a href="status_dhcp_leases.php"><?=gettext("Status: " .
835
				"DHCP leases"); ?></a> <?=gettext("page."); ?><br>
836
				</span></p>
837
			</td>
838
			</tr>
839
		</table>
840
		<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
841
		<tr>
842
			<td width="25%" class="listhdrr"><?=gettext("MAC address");?></td>
843
			<td width="15%" class="listhdrr"><?=gettext("IP address");?></td>
844
			<td width="20%" class="listhdrr"><?=gettext("Hostname");?></td>
845
			<td width="30%" class="listhdr"><?=gettext("Description");?></td>
846
			<td width="10%" class="list">
847
			<table border="0" cellspacing="0" cellpadding="1">
848
			<tr>
849
			<td valign="middle" width="17"></td>
850
			<td valign="middle"><a href="services_dhcpv6_edit.php?if=<?=$if;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
851
			</tr>
852
			</table>
853
			</td>
854
		</tr>
855
			<?php if(is_array($a_maps)): ?>
856
			<?php $i = 0; foreach ($a_maps as $mapent): ?>
857
			<?php if($mapent['mac'] <> "" or $mapent['ipaddr'] <> ""): ?>
858
		<tr>
859
		<td class="listlr" ondblclick="document.location='services_dhcpv6_edit.php?if=<?=$if;?>&id=<?=$i;?>';">
860
			<?=htmlspecialchars($mapent['mac']);?>
861
		</td>
862
		<td class="listr" ondblclick="document.location='services_dhcpv6_edit.php?if=<?=$if;?>&id=<?=$i;?>';">
863
			<?=htmlspecialchars($mapent['ipaddrv6']);?>&nbsp;
864
		</td>
865
		<td class="listr" ondblclick="document.location='services_dhcpv6_edit.php?if=<?=$if;?>&id=<?=$i;?>';">
866
			<?=htmlspecialchars($mapent['hostname']);?>&nbsp;
867
		</td>
868
		<td class="listbg" ondblclick="document.location='services_dhcpv6_edit.php?if=<?=$if;?>&id=<?=$i;?>';">
869
			<?=htmlspecialchars($mapent['descr']);?>&nbsp;
870
		</td>
871
		<td valign="middle" nowrap class="list">
872
			<table border="0" cellspacing="0" cellpadding="1">
873
			<tr>
874
			<td valign="middle"><a href="services_dhcpv6_edit.php?if=<?=$if;?>&id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td>
875
			<td valign="middle"><a href="services_dhcpv6.php?if=<?=$if;?>&act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this mapping?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
876
			</tr>
877
			</table>
878
		</td>
879
		</tr>
880
		<?php endif; ?>
881
		<?php $i++; endforeach; ?>
882
		<?php endif; ?>
883
		<tr>
884
		<td class="list" colspan="4"></td>
885
		<td class="list">
886
			<table border="0" cellspacing="0" cellpadding="1">
887
			<tr>
888
			<td valign="middle" width="17"></td>
889
			<td valign="middle"><a href="services_dhcpv6_edit.php?if=<?=$if;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
890
			</tr>
891
			</table>
892
		</td>
893
		</tr>
894
		</table>
895
	</div>
896
</td>
897
</tr>
898
</table>
899
</form>
900
<script language="JavaScript">
901
<!--
902
enable_change(false);
903
//-->
904
</script>
905
<?php include("fend.inc"); ?>
906
</body>
907
</html>
(144-144/231)