Project

General

Profile

Download (36.2 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['deftime'] = $config['dhcpdv6'][$if]['defaultleasetime'];
142
	$pconfig['maxtime'] = $config['dhcpdv6'][$if]['maxleasetime'];
143
	$pconfig['gateway'] = $config['dhcpdv6'][$if]['gateway'];
144
	$pconfig['domain'] = $config['dhcpdv6'][$if]['domain'];
145
	$pconfig['domainsearchlist'] = $config['dhcpdv6'][$if]['domainsearchlist'];
146
	$pconfig['enable'] = isset($config['dhcpdv6'][$if]['enable']);
147
	$pconfig['denyunknown'] = isset($config['dhcpdv6'][$if]['denyunknown']);
148
	$pconfig['staticarp'] = isset($config['dhcpdv6'][$if]['staticarp']);
149
	$pconfig['ddnsdomain'] = $config['dhcpdv6'][$if]['ddnsdomain'];
150
	$pconfig['ddnsupdate'] = isset($config['dhcpdv6'][$if]['ddnsupdate']);
151
	list($pconfig['ntp1'],$pconfig['ntp2']) = $config['dhcpdv6'][$if]['ntpserver'];
152
	$pconfig['tftp'] = $config['dhcpdv6'][$if]['tftp'];
153
	$pconfig['ldap'] = $config['dhcpdv6'][$if]['ldap'];
154
	$pconfig['netboot'] = isset($config['dhcpdv6'][$if]['netboot']);
155
	$pconfig['nextserver'] = $config['dhcpdv6'][$if]['next-server'];
156
	$pconfig['filename'] = $config['dhcpdv6'][$if]['filename'];
157
	$pconfig['rootpath'] = $config['dhcpdv6'][$if]['rootpath'];
158
	$pconfig['failover_peerip'] = $config['dhcpdv6'][$if]['failover_peerip'];
159
	$pconfig['netmask'] = $config['dhcpdv6'][$if]['netmask'];
160
	$pconfig['numberoptions'] = $config['dhcpdv6'][$if]['numberoptions'];
161
	if (!is_array($config['dhcpdv6'][$if]['staticmap']))
162
		$config['dhcpdv6'][$if]['staticmap'] = array();
163
	$a_maps = &$config['dhcpdv6'][$if]['staticmap'];
164
}
165

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

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

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

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

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

    
193
if ($_POST) {
194

    
195
	unset($input_errors);
196

    
197
	$pconfig = $_POST;
198

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

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

    
216
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
217

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

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

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

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

    
256
		$noip = false;
257
		if(is_array($a_maps))
258
			foreach ($a_maps as $map)
259
				if (empty($map['ipaddrv6']))
260
					$noip = true;
261
		if ($_POST['staticarp'] && $noip)
262
			$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.";
263

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

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

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

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

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

    
301
	if (!$input_errors) {
302
		if (!is_array($config['dhcpdv6'][$if]))
303
			$config['dhcpdv6'][$if] = array();
304
		if (!is_array($config['dhcpdv6'][$if]['range']))
305
			$config['dhcpdv6'][$if]['range'] = array();
306

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

    
316
		$config['dhcpdv6'][$if]['failover_peerip'] = $_POST['failover_peerip'];
317

    
318
		unset($config['dhcpdv6'][$if]['winsserver']);
319

    
320
		unset($config['dhcpdv6'][$if]['dnsserver']);
321
		if ($_POST['dns1'])
322
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns1'];
323
		if ($_POST['dns2'])
324
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns2'];
325

    
326
		$config['dhcpdv6'][$if]['gateway'] = $_POST['gateway'];
327
		$config['dhcpdv6'][$if]['domain'] = $_POST['domain'];
328
		$config['dhcpdv6'][$if]['domainsearchlist'] = $_POST['domainsearchlist'];
329
		$config['dhcpdv6'][$if]['denyunknown'] = ($_POST['denyunknown']) ? true : false;
330
		$config['dhcpdv6'][$if]['enable'] = ($_POST['enable']) ? true : false;
331
		$config['dhcpdv6'][$if]['staticarp'] = ($_POST['staticarp']) ? true : false;
332
		$config['dhcpdv6'][$if]['ddnsdomain'] = $_POST['ddnsdomain'];
333
		$config['dhcpdv6'][$if]['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
334

    
335
		unset($config['dhcpdv6'][$if]['ntpserver']);
336
		if ($_POST['ntp1'])
337
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp1'];
338
		if ($_POST['ntp2'])
339
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp2'];
340

    
341
		$config['dhcpdv6'][$if]['tftp'] = $_POST['tftp'];
342
		$config['dhcpdv6'][$if]['ldap'] = $_POST['ldap'];
343
		$config['dhcpdv6'][$if]['netboot'] = ($_POST['netboot']) ? true : false;
344
		$config['dhcpdv6'][$if]['next-server'] = $_POST['nextserver'];
345
		$config['dhcpdv6'][$if]['filename'] = $_POST['filename'];
346
		$config['dhcpdv6'][$if]['rootpath'] = $_POST['rootpath'];
347

    
348
		// Handle the custom options rowhelper
349
		if(isset($config['dhcpdv6'][$if]['numberoptions']['item']))
350
			unset($config['dhcpdv6'][$if]['numberoptions']['item']);
351

    
352
		$config['dhcpdv6'][$if]['numberoptions'] = $numberoptions;
353

    
354
		write_config();
355

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

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

    
395
$pgtitle = array(gettext("Services"),gettext("DHCPv6 server"));
396
$statusurl = "status_dhcp_leases.php";
397
$logurl = "diag_logs_dhcp.php";
398

    
399
include("head.inc");
400

    
401
?>
402

    
403
<script type="text/javascript" src="/javascript/row_helper.js">
404
</script>
405

    
406
<script type="text/javascript">
407
	rowname[0] = "number";
408
	rowtype[0] = "textbox";
409
	rowsize[0] = "10";
410
	rowname[1] = "value";
411
	rowtype[1] = "textbox";
412
	rowsize[1] = "55";
413
</script>
414

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

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

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

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

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

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

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

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

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

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