Project

General

Profile

Download (37.9 KB) Statistics
| Branch: | Tag: | Revision:
1 99caa67c Seth Mos
<?php
2
/*
3
	services_dhcpv6.php
4
*/
5 df6cb8fe Stephen Beaver
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *	Copyright (c)  2010 Seth Mos <seth.mos@dds.nl>
8
 *
9 cb41dd63 Renato Botelho
 *	Some or all of this file is based on the m0n0wall project which is
10
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
11 191cb31d Stephen Beaver
 *
12 df6cb8fe Stephen Beaver
 *	Redistribution and use in source and binary forms, with or without modification,
13
 *	are permitted provided that the following conditions are met:
14
 *
15
 *	1. Redistributions of source code must retain the above copyright notice,
16
 *		this list of conditions and the following disclaimer.
17
 *
18
 *	2. Redistributions in binary form must reproduce the above copyright
19
 *		notice, this list of conditions and the following disclaimer in
20
 *		the documentation and/or other materials provided with the
21
 *		distribution.
22
 *
23
 *	3. All advertising materials mentioning features or use of this software
24
 *		must display the following acknowledgment:
25
 *		"This product includes software developed by the pfSense Project
26
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
27
 *
28
 *	4. The names "pfSense" and "pfSense Project" must not be used to
29
 *		 endorse or promote products derived from this software without
30
 *		 prior written permission. For written permission, please contact
31
 *		 coreteam@pfsense.org.
32
 *
33
 *	5. Products derived from this software may not be called "pfSense"
34
 *		nor may "pfSense" appear in their names without prior written
35
 *		permission of the Electric Sheep Fencing, LLC.
36
 *
37
 *	6. Redistributions of any form whatsoever must retain the following
38
 *		acknowledgment:
39
 *
40
 *	"This product includes software developed by the pfSense Project
41
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
42
 *
43
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
44
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
46
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
47
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
54
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
55
 *
56
 *	====================================================================
57
 *
58
 */
59 99caa67c Seth Mos
60
##|+PRIV
61
##|*IDENT=page-services-dhcpv6server
62 5230f468 jim-p
##|*NAME=Services: DHCPv6 server
63 99caa67c Seth Mos
##|*DESCR=Allow access to the 'Services: DHCPv6 server' page.
64
##|*MATCH=services_dhcpv6.php*
65
##|-PRIV
66
67 aceaf18c Phil Davis
require_once("guiconfig.inc");
68 472ad9a0 Renato Botelho
require_once("filter.inc");
69 99caa67c Seth Mos
70 8f36f87a jim-p
function dhcpv6_apply_changes($dhcpdv6_enable_changed) {
71
	$retval = 0;
72
	$retvaldhcp = 0;
73
	$retvaldns = 0;
74
	/* Stop DHCPv6 so we can cleanup leases */
75
	killbypid("{$g['dhcpd_chroot_path']}{$g['varrun_path']}/dhcpdv6.pid");
76
	// dhcp_clean_leases();
77
	/* dnsmasq_configure calls dhcpd_configure */
78
	/* no need to restart dhcpd twice */
79
	if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstatic']))	{
80
		$retvaldns = services_dnsmasq_configure();
81
		if ($retvaldns == 0) {
82
			clear_subsystem_dirty('hosts');
83
			clear_subsystem_dirty('staticmaps');
84
		}
85
	} else if (isset($config['unbound']['enable']) && isset($config['unbound']['regdhcpstatic'])) {
86
		$retvaldns = services_unbound_configure();
87
		if ($retvaldns == 0) {
88
			clear_subsystem_dirty('unbound');
89
			clear_subsystem_dirty('staticmaps');
90
		}
91
	} else {
92
		$retvaldhcp = services_dhcpd_configure();
93
		if ($retvaldhcp == 0) {
94
			clear_subsystem_dirty('staticmaps');
95
		}
96
	}
97
	if ($dhcpdv6_enable_changed) {
98
		$retvalfc = filter_configure();
99
	}
100
	if ($retvaldhcp == 1 || $retvaldns == 1 || $retvalfc == 1) {
101
		$retval = 1;
102
	}
103
	return get_std_save_message($retval);
104
}
105
106 8f8682f7 Phil Davis
if (!$g['services_dhcp_server_enable']) {
107 6f3d2063 Renato Botelho
	header("Location: /");
108 99caa67c Seth Mos
	exit;
109
}
110
111 cd2c7940 sbeaver
/*	Fix failover DHCP problem
112
 *	http://article.gmane.org/gmane.comp.security.firewalls.pfsense.support/18749
113 99caa67c Seth Mos
 */
114 8f8682f7 Phil Davis
ini_set("memory_limit", "64M");
115 99caa67c Seth Mos
116
$if = $_GET['if'];
117 8f8682f7 Phil Davis
if ($_POST['if']) {
118 99caa67c Seth Mos
	$if = $_POST['if'];
119 8f8682f7 Phil Davis
}
120 99caa67c Seth Mos
121
/* if OLSRD is enabled, allow WAN to house DHCP. */
122 8f8682f7 Phil Davis
if ($config['installedpackages']['olsrd']) {
123
	foreach ($config['installedpackages']['olsrd']['config'] as $olsrd) {
124
		if ($olsrd['enable']) {
125 cd2c7940 sbeaver
			$is_olsr_enabled = true;
126
			break;
127
		}
128 99caa67c Seth Mos
	}
129
}
130
131
$iflist = get_configured_interface_with_descr();
132 16d9ad13 smos
$iflist = array_merge($iflist, get_configured_pppoe_server_interfaces());
133 99caa67c Seth Mos
134
/* set the starting interface */
135
if (!$if || !isset($iflist[$if])) {
136
	foreach ($iflist as $ifent => $ifname) {
137
		$oc = $config['interfaces'][$ifent];
138 2bf455ca Renato Botelho
		$valid_if_ipaddrv6 = (bool) ($oc['ipaddrv6'] == 'track6' ||
139
		    (is_ipaddrv6($oc['ipaddrv6']) &&
140
		    !is_linklocal($oc['ipaddrv6'])));
141 c80e6a6a Stephen Beaver
142 48602774 Renato Botelho
		if ((!is_array($config['dhcpdv6'][$ifent]) ||
143
		    !isset($config['dhcpdv6'][$ifent]['enable'])) &&
144
		    !$valid_if_ipaddrv6) {
145 99caa67c Seth Mos
			continue;
146 8f8682f7 Phil Davis
		}
147 99caa67c Seth Mos
		$if = $ifent;
148
		break;
149
	}
150
}
151
152 8f8682f7 Phil Davis
if (is_array($config['dhcpdv6'][$if])) {
153 fe838158 smos
	/* DHCPv6 */
154 99caa67c Seth Mos
	if (is_array($config['dhcpdv6'][$if]['range'])) {
155
		$pconfig['range_from'] = $config['dhcpdv6'][$if]['range']['from'];
156
		$pconfig['range_to'] = $config['dhcpdv6'][$if]['range']['to'];
157
	}
158 bfb3e717 Seth Mos
	if (is_array($config['dhcpdv6'][$if]['prefixrange'])) {
159
		$pconfig['prefixrange_from'] = $config['dhcpdv6'][$if]['prefixrange']['from'];
160
		$pconfig['prefixrange_to'] = $config['dhcpdv6'][$if]['prefixrange']['to'];
161
		$pconfig['prefixrange_length'] = $config['dhcpdv6'][$if]['prefixrange']['prefixlength'];
162
	}
163 99caa67c Seth Mos
	$pconfig['deftime'] = $config['dhcpdv6'][$if]['defaultleasetime'];
164
	$pconfig['maxtime'] = $config['dhcpdv6'][$if]['maxleasetime'];
165
	$pconfig['domain'] = $config['dhcpdv6'][$if]['domain'];
166
	$pconfig['domainsearchlist'] = $config['dhcpdv6'][$if]['domainsearchlist'];
167 8f8682f7 Phil Davis
	list($pconfig['wins1'], $pconfig['wins2']) = $config['dhcpdv6'][$if]['winsserver'];
168
	list($pconfig['dns1'], $pconfig['dns2'], $pconfig['dns3'], $pconfig['dns4']) = $config['dhcpdv6'][$if]['dnsserver'];
169 99caa67c Seth Mos
	$pconfig['enable'] = isset($config['dhcpdv6'][$if]['enable']);
170
	$pconfig['ddnsdomain'] = $config['dhcpdv6'][$if]['ddnsdomain'];
171 87019fc4 Andres Petralli
	$pconfig['ddnsdomainprimary'] = $config['dhcpdv6'][$if]['ddnsdomainprimary'];
172
	$pconfig['ddnsdomainkeyname'] = $config['dhcpdv6'][$if]['ddnsdomainkeyname'];
173
	$pconfig['ddnsdomainkey'] = $config['dhcpdv6'][$if]['ddnsdomainkey'];
174 99caa67c Seth Mos
	$pconfig['ddnsupdate'] = isset($config['dhcpdv6'][$if]['ddnsupdate']);
175 391d63da Renato Botelho
	$pconfig['ddnsreverse'] = isset($config['dhcpdv6'][$if]['ddnsreverse']);
176
	$pconfig['ddnsclientupdates'] = $config['dhcpdv6'][$if]['ddnsclientupdates'];
177 8f8682f7 Phil Davis
	list($pconfig['ntp1'], $pconfig['ntp2']) = $config['dhcpdv6'][$if]['ntpserver'];
178 99caa67c Seth Mos
	$pconfig['tftp'] = $config['dhcpdv6'][$if]['tftp'];
179
	$pconfig['ldap'] = $config['dhcpdv6'][$if]['ldap'];
180
	$pconfig['netboot'] = isset($config['dhcpdv6'][$if]['netboot']);
181 bd942860 Renato Botelho
	$pconfig['bootfile_url'] = $config['dhcpdv6'][$if]['bootfile_url'];
182 99caa67c Seth Mos
	$pconfig['netmask'] = $config['dhcpdv6'][$if]['netmask'];
183
	$pconfig['numberoptions'] = $config['dhcpdv6'][$if]['numberoptions'];
184 138208bf Joecowboy
	$pconfig['dhcpv6leaseinlocaltime'] = $config['dhcpdv6'][$if]['dhcpv6leaseinlocaltime'];
185 8f8682f7 Phil Davis
	if (!is_array($config['dhcpdv6'][$if]['staticmap'])) {
186 99caa67c Seth Mos
		$config['dhcpdv6'][$if]['staticmap'] = array();
187 8f8682f7 Phil Davis
	}
188 99caa67c Seth Mos
	$a_maps = &$config['dhcpdv6'][$if]['staticmap'];
189
}
190
191 2bf455ca Renato Botelho
if ($config['interfaces'][$if]['ipaddrv6'] == 'track6') {
192 6c8beed3 Renato Botelho
	$trackifname = $config['interfaces'][$if]['track6-interface'];
193
	$trackcfg = $config['interfaces'][$trackifname];
194 a5776226 Chris Buechler
	$ifcfgsn = "64";
195 2bf455ca Renato Botelho
	$ifcfgip = '::';
196 6c8beed3 Renato Botelho
197
	$str_help_mask = dhcpv6_pd_str_help($ifcfgsn);
198 2bf455ca Renato Botelho
} else {
199
	$ifcfgip = get_interface_ipv6($if);
200
	$ifcfgsn = get_interface_subnetv6($if);
201
}
202 99caa67c Seth Mos
203 cd2c7940 sbeaver
/*	 set the enabled flag which will tell us if DHCP relay is enabled
204
 *	 on any interface. We will use this to disable DHCP server since
205
 *	 the two are not compatible with each other.
206 99caa67c Seth Mos
 */
207
208
$dhcrelay_enabled = false;
209 80c88a68 smos
$dhcrelaycfg = $config['dhcrelay6'];
210 99caa67c Seth Mos
211 9c06758b k-paulius
if (is_array($dhcrelaycfg) && isset($dhcrelaycfg['enable']) && isset($dhcrelaycfg['interface']) && !empty($dhcrelaycfg['interface'])) {
212
	$dhcrelayifs = explode(",", $dhcrelaycfg['interface']);
213
214
	foreach ($dhcrelayifs as $dhcrelayif) {
215
216
		if (isset($iflist[$dhcrelayif]) && (!link_interface_to_bridge($dhcrelayif))) {
217 99caa67c Seth Mos
			$dhcrelay_enabled = true;
218 9c06758b k-paulius
			break;
219 8f8682f7 Phil Davis
		}
220 99caa67c Seth Mos
	}
221
}
222
223 306cbbc8 Phil Davis
if (isset($_POST['apply'])) {
224 8f36f87a jim-p
	$savemsg = dhcpv6_apply_changes(false);
225 306cbbc8 Phil Davis
} elseif (isset($_POST['save'])) {
226 99caa67c Seth Mos
	unset($input_errors);
227
228 472ad9a0 Renato Botelho
	$old_dhcpdv6_enable = ($pconfig['enable'] == true);
229
	$new_dhcpdv6_enable = ($_POST['enable'] ? true : false);
230
	$dhcpdv6_enable_changed = ($old_dhcpdv6_enable != $new_dhcpdv6_enable);
231
232 99caa67c Seth Mos
	$pconfig = $_POST;
233
234
	$numberoptions = array();
235 6c07db48 Phil Davis
	for ($x = 0; $x < 99; $x++) {
236 8f8682f7 Phil Davis
		if (isset($_POST["number{$x}"]) && ctype_digit($_POST["number{$x}"])) {
237 99caa67c Seth Mos
			$numbervalue = array();
238
			$numbervalue['number'] = htmlspecialchars($_POST["number{$x}"]);
239 65cce9d7 Renato Botelho
			$numbervalue['value'] = base64_encode($_POST["value{$x}"]);
240 99caa67c Seth Mos
			$numberoptions['item'][] = $numbervalue;
241
		}
242
	}
243
	// Reload the new pconfig variable that the forum uses.
244
	$pconfig['numberoptions'] = $numberoptions;
245
246
	/* input validation */
247
	if ($_POST['enable']) {
248
		$reqdfields = explode(" ", "range_from range_to");
249 8f8682f7 Phil Davis
		$reqdfieldsn = array(gettext("Range begin"), gettext("Range end"));
250 99caa67c Seth Mos
251 1e9b4611 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
252 99caa67c Seth Mos
253 8f8682f7 Phil Davis
		if (($_POST['prefixrange_from'] && !is_ipaddrv6($_POST['prefixrange_from']))) {
254 0a8a90f7 Phil Davis
			$input_errors[] = gettext("A valid prefix range must be specified.");
255 8f8682f7 Phil Davis
		}
256
		if (($_POST['prefixrange_to'] && !is_ipaddrv6($_POST['prefixrange_to']))) {
257 bfb3e717 Seth Mos
			$input_errors[] = gettext("A valid prefix range must be specified.");
258 8f8682f7 Phil Davis
		}
259 bcc2b417 Renato Botelho
260
		if ($_POST['prefixrange_from'] && $_POST['prefixrange_to'] &&
261
		    $_POST['prefixrange_length']) {
262
			$netmask = Net_IPv6::getNetmask($_POST['prefixrange_from'],
263
			    $_POST['prefixrange_length']);
264
			$netmask = Net_IPv6::compress($netmask);
265
266 7ef4b39d Renato Botelho
			if ($netmask != Net_IPv6::compress(strtolower(
267
			    $_POST['prefixrange_from']))) {
268 bcc2b417 Renato Botelho
				$input_errors[] = sprintf(gettext(
269
				    "Prefix Delegation From address is not a valid IPv6 Netmask for %s"),
270
				    $netmask . '/' . $_POST['prefixrange_length']);
271
			}
272
273
			$netmask = Net_IPv6::getNetmask($_POST['prefixrange_to'],
274
			    $_POST['prefixrange_length']);
275
			$netmask = Net_IPv6::compress($netmask);
276
277 7ef4b39d Renato Botelho
			if ($netmask != Net_IPv6::compress(strtolower(
278
			    $_POST['prefixrange_to']))) {
279 bcc2b417 Renato Botelho
				$input_errors[] = sprintf(gettext(
280
				    "Prefix Delegation To address is not a valid IPv6 Netmask for %s"),
281
				    $netmask . '/' . $_POST['prefixrange_length']);
282
			}
283
		}
284
285 2bf455ca Renato Botelho
		if ($_POST['range_from']) {
286
			if (!is_ipaddrv6($_POST['range_from'])) {
287
				$input_errors[] = gettext("A valid range must be specified.");
288
			} elseif ($config['interfaces'][$if]['ipaddrv6'] == 'track6' &&
289 6c8beed3 Renato Botelho
			    !Net_IPv6::isInNetmask($_POST['range_from'], '::', $ifcfgsn)) {
290
				$input_errors[] = sprintf(gettext(
291
				    "The prefix (upper %s bits) must be zero.  Use the form %s"),
292
				    $ifcfgsn, $str_help_mask);
293 2bf455ca Renato Botelho
			}
294 8f8682f7 Phil Davis
		}
295 2bf455ca Renato Botelho
		if ($_POST['range_to']) {
296
			if (!is_ipaddrv6($_POST['range_to'])) {
297
				$input_errors[] = gettext("A valid range must be specified.");
298
			} elseif ($config['interfaces'][$if]['ipaddrv6'] == 'track6' &&
299 6c8beed3 Renato Botelho
			    !Net_IPv6::isInNetmask($_POST['range_to'], '::', $ifcfgsn)) {
300
				$input_errors[] = sprintf(gettext(
301
				    "The prefix (upper %s bits) must be zero.  Use the form %s"),
302
				    $ifcfgsn, $str_help_mask);
303 2bf455ca Renato Botelho
			}
304 8f8682f7 Phil Davis
		}
305
		if (($_POST['gateway'] && !is_ipaddrv6($_POST['gateway']))) {
306 99caa67c Seth Mos
			$input_errors[] = gettext("A valid IPv6 address must be specified for the gateway.");
307 8f8682f7 Phil Davis
		}
308
		if (($_POST['dns1'] && !is_ipaddrv6($_POST['dns1'])) ||
309 6e3488e9 Phil Davis
		    ($_POST['dns2'] && !is_ipaddrv6($_POST['dns2'])) ||
310
		    ($_POST['dns3'] && !is_ipaddrv6($_POST['dns3'])) ||
311
		    ($_POST['dns4'] && !is_ipaddrv6($_POST['dns4']))) {
312 3d88ea11 Phil Davis
			$input_errors[] = gettext("A valid IPv6 address must be specified for each of the DNS servers.");
313 8f8682f7 Phil Davis
		}
314 99caa67c Seth Mos
315 8f8682f7 Phil Davis
		if ($_POST['deftime'] && (!is_numeric($_POST['deftime']) || ($_POST['deftime'] < 60))) {
316 99caa67c Seth Mos
			$input_errors[] = gettext("The default lease time must be at least 60 seconds.");
317 8f8682f7 Phil Davis
		}
318
		if ($_POST['maxtime'] && (!is_numeric($_POST['maxtime']) || ($_POST['maxtime'] < 60) || ($_POST['maxtime'] <= $_POST['deftime']))) {
319 99caa67c Seth Mos
			$input_errors[] = gettext("The maximum lease time must be at least 60 seconds and higher than the default lease time.");
320 8f8682f7 Phil Davis
		}
321
		if (($_POST['ddnsdomain'] && !is_domain($_POST['ddnsdomain']))) {
322 99caa67c Seth Mos
			$input_errors[] = gettext("A valid domain name must be specified for the dynamic DNS registration.");
323 8f8682f7 Phil Davis
		}
324
		if (($_POST['ddnsdomain'] && !is_ipaddrv4($_POST['ddnsdomainprimary']))) {
325 87019fc4 Andres Petralli
			$input_errors[] = gettext("A valid primary domain name server IPv4 address must be specified for the dynamic domain name.");
326 8f8682f7 Phil Davis
		}
327 87019fc4 Andres Petralli
		if (($_POST['ddnsdomainkey'] && !$_POST['ddnsdomainkeyname']) ||
328 6e3488e9 Phil Davis
		    ($_POST['ddnsdomainkeyname'] && !$_POST['ddnsdomainkey'])) {
329 00ae93ff Stephen Beaver
			$input_errors[] = gettext("Both a valid domain key and key name must be specified.");
330 8f8682f7 Phil Davis
		}
331 a3de8b9e Pierre POMES
		if ($_POST['domainsearchlist']) {
332 8f8682f7 Phil Davis
			$domain_array=preg_split("/[ ;]+/", $_POST['domainsearchlist']);
333 a3de8b9e Pierre POMES
			foreach ($domain_array as $curdomain) {
334
				if (!is_domain($curdomain)) {
335
					$input_errors[] = gettext("A valid domain search list must be specified.");
336
					break;
337
				}
338
			}
339
		}
340
341 8f8682f7 Phil Davis
		if (($_POST['ntp1'] && !is_ipaddrv6($_POST['ntp1'])) || ($_POST['ntp2'] && !is_ipaddrv6($_POST['ntp2']))) {
342 99caa67c Seth Mos
			$input_errors[] = gettext("A valid IPv6 address must be specified for the primary/secondary NTP servers.");
343 8f8682f7 Phil Davis
		}
344
		if (($_POST['domain'] && !is_domain($_POST['domain']))) {
345 99caa67c Seth Mos
			$input_errors[] = gettext("A valid domain name must be specified for the DNS domain.");
346 8f8682f7 Phil Davis
		}
347
		if ($_POST['tftp'] && !is_ipaddr($_POST['tftp']) && !is_domain($_POST['tftp']) && !is_URL($_POST['tftp'])) {
348 99caa67c Seth Mos
			$input_errors[] = gettext("A valid IPv6 address or hostname must be specified for the TFTP server.");
349 8f8682f7 Phil Davis
		}
350
		if (($_POST['bootfile_url'] && !is_URL($_POST['bootfile_url']))) {
351 bd942860 Renato Botelho
			$input_errors[] = gettext("A valid URL must be specified for the network bootfile.");
352 8f8682f7 Phil Davis
		}
353 99caa67c Seth Mos
354
		// Disallow a range that includes the virtualip
355
		if (is_array($config['virtualip']['vip'])) {
356 8f8682f7 Phil Davis
			foreach ($config['virtualip']['vip'] as $vip) {
357
				if ($vip['interface'] == $if) {
358
					if ($vip['subnetv6'] && is_inrange_v6($vip['subnetv6'], $_POST['range_from'], $_POST['range_to'])) {
359
						$input_errors[] = sprintf(gettext("The subnet range cannot overlap with virtual IPv6 address %s."), $vip['subnetv6']);
360
					}
361
				}
362 99caa67c Seth Mos
			}
363
		}
364
365
		$noip = false;
366 8f8682f7 Phil Davis
		if (is_array($a_maps)) {
367 cd2c7940 sbeaver
			foreach ($a_maps as $map) {
368 8f8682f7 Phil Davis
				if (empty($map['ipaddrv6'])) {
369 99caa67c Seth Mos
					$noip = true;
370 8f8682f7 Phil Davis
				}
371 cd2c7940 sbeaver
			}
372
		}
373 99caa67c Seth Mos
		if (!$input_errors) {
374
			/* make sure the range lies within the current subnet */
375
			$subnet_start = gen_subnetv6($ifcfgip, $ifcfgsn);
376
			$subnet_end = gen_subnetv6_max($ifcfgip, $ifcfgsn);
377
378 16d9ad13 smos
			if (is_ipaddrv6($ifcfgip)) {
379 8f8682f7 Phil Davis
				if ((!is_inrange_v6($_POST['range_from'], $subnet_start, $subnet_end)) ||
380 6e3488e9 Phil Davis
				    (!is_inrange_v6($_POST['range_to'], $subnet_start, $subnet_end))) {
381 16d9ad13 smos
					$input_errors[] = gettext("The specified range lies outside of the current subnet.");
382
				}
383 99caa67c Seth Mos
			}
384 731de711 Pierre POMES
			/* "from" cannot be higher than "to" */
385 8f8682f7 Phil Davis
			if (inet_pton($_POST['range_from']) > inet_pton($_POST['range_to'])) {
386 99caa67c Seth Mos
				$input_errors[] = gettext("The range is invalid (first element higher than second element).");
387 8f8682f7 Phil Davis
			}
388 99caa67c Seth Mos
389
			/* make sure that the DHCP Relay isn't enabled on this interface */
390 8f8682f7 Phil Davis
			if (isset($config['dhcrelay'][$if]['enable'])) {
391 00ae93ff Stephen Beaver
				$input_errors[] = sprintf(gettext("The DHCP relay on the %s interface must be disabled before enabling the DHCP server."), $iflist[$if]);
392 8f8682f7 Phil Davis
			}
393 99caa67c Seth Mos
394 731de711 Pierre POMES
395
			/* Verify static mappings do not overlap:
396
			   - available DHCP range
397
			   - prefix delegation range (FIXME: still need to be completed) */
398
			$dynsubnet_start = inet_pton($_POST['range_from']);
399
			$dynsubnet_end = inet_pton($_POST['range_to']);
400
401 8f8682f7 Phil Davis
			if (is_array($a_maps)) {
402 99caa67c Seth Mos
				foreach ($a_maps as $map) {
403 8f8682f7 Phil Davis
					if (empty($map['ipaddrv6'])) {
404 99caa67c Seth Mos
						continue;
405 8f8682f7 Phil Davis
					}
406 731de711 Pierre POMES
					if ((inet_pton($map['ipaddrv6']) > $dynsubnet_start) &&
407 6e3488e9 Phil Davis
					    (inet_pton($map['ipaddrv6']) < $dynsubnet_end)) {
408 99caa67c Seth Mos
						$input_errors[] = sprintf(gettext("The DHCP range cannot overlap any static DHCP mappings."));
409
						break;
410
					}
411
				}
412
			}
413
		}
414
	}
415
416
	if (!$input_errors) {
417 8f8682f7 Phil Davis
		if (!is_array($config['dhcpdv6'][$if])) {
418 99caa67c Seth Mos
			$config['dhcpdv6'][$if] = array();
419 8f8682f7 Phil Davis
		}
420
		if (!is_array($config['dhcpdv6'][$if]['range'])) {
421 99caa67c Seth Mos
			$config['dhcpdv6'][$if]['range'] = array();
422 8f8682f7 Phil Davis
		}
423
		if (!is_array($config['dhcpdv6'][$if]['prefixrange'])) {
424 bfb3e717 Seth Mos
			$config['dhcpdv6'][$if]['prefixrange'] = array();
425 8f8682f7 Phil Davis
		}
426 99caa67c Seth Mos
427
		$config['dhcpdv6'][$if]['range']['from'] = $_POST['range_from'];
428
		$config['dhcpdv6'][$if]['range']['to'] = $_POST['range_to'];
429 bfb3e717 Seth Mos
		$config['dhcpdv6'][$if]['prefixrange']['from'] = $_POST['prefixrange_from'];
430
		$config['dhcpdv6'][$if]['prefixrange']['to'] = $_POST['prefixrange_to'];
431
		$config['dhcpdv6'][$if]['prefixrange']['prefixlength'] = $_POST['prefixrange_length'];
432 99caa67c Seth Mos
		$config['dhcpdv6'][$if]['defaultleasetime'] = $_POST['deftime'];
433
		$config['dhcpdv6'][$if]['maxleasetime'] = $_POST['maxtime'];
434
		$config['dhcpdv6'][$if]['netmask'] = $_POST['netmask'];
435
436
		unset($config['dhcpdv6'][$if]['winsserver']);
437
438
		unset($config['dhcpdv6'][$if]['dnsserver']);
439 8f8682f7 Phil Davis
		if ($_POST['dns1']) {
440 99caa67c Seth Mos
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns1'];
441 8f8682f7 Phil Davis
		}
442
		if ($_POST['dns2']) {
443 99caa67c Seth Mos
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns2'];
444 8f8682f7 Phil Davis
		}
445
		if ($_POST['dns3']) {
446 3d88ea11 Phil Davis
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns3'];
447 8f8682f7 Phil Davis
		}
448
		if ($_POST['dns4']) {
449 3d88ea11 Phil Davis
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns4'];
450 8f8682f7 Phil Davis
		}
451 99caa67c Seth Mos
452
		$config['dhcpdv6'][$if]['domain'] = $_POST['domain'];
453
		$config['dhcpdv6'][$if]['domainsearchlist'] = $_POST['domainsearchlist'];
454
		$config['dhcpdv6'][$if]['enable'] = ($_POST['enable']) ? true : false;
455
		$config['dhcpdv6'][$if]['ddnsdomain'] = $_POST['ddnsdomain'];
456 87019fc4 Andres Petralli
		$config['dhcpdv6'][$if]['ddnsdomainprimary'] = $_POST['ddnsdomainprimary'];
457
		$config['dhcpdv6'][$if]['ddnsdomainkeyname'] = $_POST['ddnsdomainkeyname'];
458
		$config['dhcpdv6'][$if]['ddnsdomainkey'] = $_POST['ddnsdomainkey'];
459 99caa67c Seth Mos
		$config['dhcpdv6'][$if]['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
460 391d63da Renato Botelho
		$config['dhcpdv6'][$if]['ddnsreverse'] = ($_POST['ddnsreverse']) ? true : false;
461
		$config['dhcpdv6'][$if]['ddnsclientupdates'] = $_POST['ddnsclientupdates'];
462 99caa67c Seth Mos
463
		unset($config['dhcpdv6'][$if]['ntpserver']);
464 8f8682f7 Phil Davis
		if ($_POST['ntp1']) {
465 99caa67c Seth Mos
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp1'];
466 8f8682f7 Phil Davis
		}
467
		if ($_POST['ntp2']) {
468 99caa67c Seth Mos
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp2'];
469 8f8682f7 Phil Davis
		}
470 99caa67c Seth Mos
471
		$config['dhcpdv6'][$if]['tftp'] = $_POST['tftp'];
472
		$config['dhcpdv6'][$if]['ldap'] = $_POST['ldap'];
473
		$config['dhcpdv6'][$if]['netboot'] = ($_POST['netboot']) ? true : false;
474 bd942860 Renato Botelho
		$config['dhcpdv6'][$if]['bootfile_url'] = $_POST['bootfile_url'];
475 138208bf Joecowboy
		$config['dhcpdv6'][$if]['dhcpv6leaseinlocaltime'] = $_POST['dhcpv6leaseinlocaltime'];
476 99caa67c Seth Mos
477
		// Handle the custom options rowhelper
478 8f8682f7 Phil Davis
		if (isset($config['dhcpdv6'][$if]['numberoptions']['item'])) {
479 99caa67c Seth Mos
			unset($config['dhcpdv6'][$if]['numberoptions']['item']);
480 8f8682f7 Phil Davis
		}
481 99caa67c Seth Mos
482
		$config['dhcpdv6'][$if]['numberoptions'] = $numberoptions;
483
484
		write_config();
485
486 8f36f87a jim-p
		$savemsg = dhcpv6_apply_changes($dhcpdv6_enable_changed);
487 99caa67c Seth Mos
	}
488
}
489
490
if ($_GET['act'] == "del") {
491
	if ($a_maps[$_GET['id']]) {
492
		unset($a_maps[$_GET['id']]);
493
		write_config();
494 8f8682f7 Phil Davis
		if (isset($config['dhcpdv6'][$if]['enable'])) {
495 99caa67c Seth Mos
			mark_subsystem_dirty('staticmapsv6');
496 8f8682f7 Phil Davis
			if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstaticv6'])) {
497 99caa67c Seth Mos
				mark_subsystem_dirty('hosts');
498 8f8682f7 Phil Davis
			}
499 99caa67c Seth Mos
		}
500
		header("Location: services_dhcpv6.php?if={$if}");
501
		exit;
502
	}
503
}
504
505 46b7214c k-paulius
$pgtitle = array(gettext("Services"), htmlspecialchars(gettext("DHCPv6 Server & RA")));
506 253fa019 k-paulius
507 40f00b73 Chris Buechler
if (!empty($if) && isset($iflist[$if])) {
508 253fa019 k-paulius
	$pgtitle[] = $iflist[$if];
509 9c06758b k-paulius
	$pgtitle[] = gettext("DHCPv6 Server");
510 253fa019 k-paulius
}
511 b32dd0a6 jim-p
$shortcut_section = "dhcp6";
512 99caa67c Seth Mos
513
include("head.inc");
514
515 6e3488e9 Phil Davis
if ($input_errors) {
516 cd2c7940 sbeaver
	print_input_errors($input_errors);
517 6e3488e9 Phil Davis
}
518 99caa67c Seth Mos
519 6e3488e9 Phil Davis
if ($savemsg) {
520 cd2c7940 sbeaver
	print_info_box($savemsg, 'success');
521 6e3488e9 Phil Davis
}
522 99caa67c Seth Mos
523 cd2c7940 sbeaver
if ($dhcrelay_enabled) {
524 9c06758b k-paulius
	print_info_box(gettext("DHCPv6 Relay is currently enabled. Cannot enable the DHCPv6 Server service while the DHCPv6 Relay is enabled on any interface."), 'danger', false);
525 cd2c7940 sbeaver
}
526 99caa67c Seth Mos
527 6e3488e9 Phil Davis
if (is_subsystem_dirty('staticmaps')) {
528 00ae93ff Stephen Beaver
	print_apply_box(gettext('The static mapping configuration has been changed.') . '<br />' . gettext('The changes must be applied for them to take effect.'));
529 6e3488e9 Phil Davis
}
530 99caa67c Seth Mos
531 cd2c7940 sbeaver
/* active tabs */
532
$tab_array = array();
533
$tabscounter = 0;
534
$i = 0;
535 c80e6a6a Stephen Beaver
536 cd2c7940 sbeaver
foreach ($iflist as $ifent => $ifname) {
537
	$oc = $config['interfaces'][$ifent];
538 2bf455ca Renato Botelho
	$valid_if_ipaddrv6 = (bool) ($oc['ipaddrv6'] == 'track6' ||
539
	    (is_ipaddrv6($oc['ipaddrv6']) &&
540
	    !is_linklocal($oc['ipaddrv6'])));
541 c80e6a6a Stephen Beaver
542 8f928dc3 Renato Botelho
	if ((!is_array($config['dhcpdv6'][$ifent]) ||
543
	    !isset($config['dhcpdv6'][$ifent]['enable'])) &&
544
	    !$valid_if_ipaddrv6) {
545 cd2c7940 sbeaver
		continue;
546 6e3488e9 Phil Davis
	}
547 cd2c7940 sbeaver
548 6e3488e9 Phil Davis
	if ($ifent == $if) {
549 cd2c7940 sbeaver
		$active = true;
550 6e3488e9 Phil Davis
	} else {
551 cd2c7940 sbeaver
		$active = false;
552 6e3488e9 Phil Davis
	}
553 cd2c7940 sbeaver
554
	$tab_array[] = array($ifname, $active, "services_dhcpv6.php?if={$ifent}");
555
	$tabscounter++;
556
}
557 c80e6a6a Stephen Beaver
558 cd2c7940 sbeaver
/* tack on PPPoE or PPtP servers here */
559
/* pppoe server */
560
if (is_array($config['pppoes']['pppoe'])) {
561 6e3488e9 Phil Davis
	foreach ($config['pppoes']['pppoe'] as $pppoe) {
562 cd2c7940 sbeaver
		if ($pppoe['mode'] == "server") {
563
			$ifent = "poes". $pppoe['pppoeid'];
564
			$ifname = strtoupper($ifent);
565
566 6e3488e9 Phil Davis
			if ($ifent == $if) {
567 cd2c7940 sbeaver
				$active = true;
568 6e3488e9 Phil Davis
			} else {
569 cd2c7940 sbeaver
				$active = false;
570 6e3488e9 Phil Davis
			}
571 cd2c7940 sbeaver
572
			$tab_array[] = array($ifname, $active, "services_dhcpv6.php?if={$ifent}");
573
			$tabscounter++;
574
		}
575 99caa67c Seth Mos
	}
576 cd2c7940 sbeaver
}
577 99caa67c Seth Mos
578 c80e6a6a Stephen Beaver
if ($tabscounter == 0) {
579 cd2c7940 sbeaver
	print_info_box(gettext("The DHCPv6 Server can only be enabled on interfaces configured with a static IPv6 address. This system has none."), 'danger');
580
	include("foot.inc");
581
	exit;
582
}
583 99caa67c Seth Mos
584 9b54ac32 Stephen Beaver
display_top_tabs($tab_array);
585
586 cd2c7940 sbeaver
$tab_array = array();
587
$tab_array[] = array(gettext("DHCPv6 Server"),		 true,	"services_dhcpv6.php?if={$if}");
588
$tab_array[] = array(gettext("Router Advertisements"), false, "services_router_advertisements.php?if={$if}");
589 6e3488e9 Phil Davis
display_top_tabs($tab_array, false, 'nav nav-tabs');
590 99caa67c Seth Mos
591 40f00b73 Chris Buechler
if ($dhcrelay_enabled) {
592
	include("foot.inc");
593
	exit;
594
}
595
596 8f58b51b jim-p
$form = new Form();
597 cd2c7940 sbeaver
598
$section = new Form_Section('DHCPv6 Options');
599
600
$section->addInput(new Form_Checkbox(
601
	'enable',
602
	'DHCPv6 Server',
603 ea6649f7 sbeaver
	'Enable DHCPv6 server on interface ' . $iflist[$if],
604 cd2c7940 sbeaver
	$pconfig['enable']
605 9eeb91dd Stephen Beaver
));
606 cd2c7940 sbeaver
607 6e3488e9 Phil Davis
if (is_ipaddrv6($ifcfgip)) {
608 cd2c7940 sbeaver
609 e1953efa Chris Buechler
	if ($ifcfgip == "::") {
610
		$sntext = "Prefix Delegation";
611
	} else {
612
		$sntext = gen_subnetv6($ifcfgip, $ifcfgsn);
613
	}
614 cd2c7940 sbeaver
	$section->addInput(new Form_StaticText(
615
		'Subnet',
616 e1953efa Chris Buechler
		$sntext
617 cd2c7940 sbeaver
		));
618
619
	$section->addInput(new Form_StaticText(
620
		'Subnet Mask',
621
		$ifcfgsn . ' bits'
622
		));
623
624
	$section->addInput(new Form_StaticText(
625
		'Available Range',
626
		$range_from = gen_subnetv6($ifcfgip, $ifcfgsn) . ' to ' . gen_subnetv6_max($ifcfgip, $ifcfgsn)
627 e1953efa Chris Buechler
		))->setHelp($trackifname ? 'Prefix Delegation subnet will be appended to the beginning of the defined range':'');
628 cd2c7940 sbeaver
}
629
630 6e3488e9 Phil Davis
if ($is_olsr_enabled) {
631 cd2c7940 sbeaver
	$section->addInput(new Form_Select(
632
	'netmask',
633 e32f02a5 Phil Davis
	'Subnet Mask',
634 cd2c7940 sbeaver
	$pconfig['netmask'],
635
	array_combine(range(128, 1, -1), range(128, 1, -1))
636
	));
637
}
638
639
$f1 = new Form_Input(
640
	'range_from',
641
	null,
642
	'text',
643
	$pconfig['range_from']
644 218600a2 Renato Botelho
);
645
646
$f1->setHelp('From');
647 cd2c7940 sbeaver
648
$f2 = new Form_Input(
649
	'range_to',
650
	null,
651
	'text',
652
	$pconfig['range_to']
653 218600a2 Renato Botelho
);
654
655
$f2->setHelp('To');
656 cd2c7940 sbeaver
657
$group = new Form_Group('Range');
658
659
$group->add($f1);
660
$group->add($f2);
661
662
$section->add($group);
663
664
$f1 = new Form_Input(
665 70f17067 Stephen Beaver
	'prefixrange_from',
666 cd2c7940 sbeaver
	null,
667
	'text',
668 70f17067 Stephen Beaver
	$pconfig['prefixrange_from']
669 218600a2 Renato Botelho
);
670
671
$f1->setHelp('From');
672 cd2c7940 sbeaver
673
$f2 = new Form_Input(
674 70f17067 Stephen Beaver
	'prefixrange_to',
675 cd2c7940 sbeaver
	null,
676
	'text',
677 70f17067 Stephen Beaver
	$pconfig['prefixrange_to']
678 218600a2 Renato Botelho
);
679
680
$f2->setHelp('To');
681 cd2c7940 sbeaver
682
$group = new Form_Group('Prefix Delegation Range');
683
684
$group->add($f1);
685
$group->add($f2);
686
687
$section->add($group);
688
689
$section->addInput(new Form_Select(
690
	'prefixrange_length',
691
	'Prefix Delegation Size',
692
	$pconfig['prefixrange_length'],
693
	array(
694
		'48' => '48',
695
		'52' => '52',
696
		'56' => '56',
697
		'60' => '60',
698
		'62' => '62',
699
		'63' => '63',
700
		'64' => '64'
701
		)
702 00ae93ff Stephen Beaver
))->setHelp('A Prefix range can be defined 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.');
703 cd2c7940 sbeaver
704
$group = new Form_Group('DNS Servers');
705
706 6e3488e9 Phil Davis
for ($i=1;$i<=4; $i++) {
707 cd2c7940 sbeaver
	$group->add(new Form_input(
708
		'dns' . $i,
709
		null,
710
		'text',
711 e32f02a5 Phil Davis
		$pconfig['dns' . $i],
712
		['placeholder' => 'DNS ' . $i]
713
	));
714 cd2c7940 sbeaver
}
715
716 6e3488e9 Phil Davis
$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.');
717 cd2c7940 sbeaver
$section->add($group);
718
719
$section->addInput(new Form_Input(
720
	'domain',
721 c6c8cfea NewEraCracker
	'Domain name',
722 cd2c7940 sbeaver
	'text',
723 ea6649f7 sbeaver
	$pconfig['domain']
724 00ae93ff Stephen Beaver
))->setHelp('The default is to use the domain name of this system as the default domain name provided by DHCP. An alternate domain name may be specified here. ');
725 cd2c7940 sbeaver
726
$section->addInput(new Form_Input(
727
	'domainsearchlist',
728
	'Domain search list',
729
	'text',
730 ea6649f7 sbeaver
	$pconfig['domainsearchlist']
731 48d321ca NewEraCracker
))->setHelp('The DHCP server can optionally provide a domain search list. Use the semicolon character as separator.');
732 cd2c7940 sbeaver
733
$section->addInput(new Form_Input(
734
	'deftime',
735
	'Default lease time',
736
	'text',
737 ea6649f7 sbeaver
	$pconfig['deftime']
738 558a7c62 Chris Buechler
))->setHelp('Lease time in seconds. Used for clients that do not ask for a specific expiration time. ' . ' <br />' .
739 cd2c7940 sbeaver
			'The default is 7200 seconds.');
740
741
$section->addInput(new Form_Input(
742
	'maxtime',
743
	'Max lease time',
744
	'text',
745 ea6649f7 sbeaver
	$pconfig['maxtime']
746 cd2c7940 sbeaver
))->setHelp('Maximum lease time for clients that ask for a specific expiration time.' . ' <br />' .
747
			'The default is 86400 seconds.');
748
749
$section->addInput(new Form_Checkbox(
750
	'dhcpv6leaseinlocaltime',
751
	'Time Format Change',
752
	'Change DHCPv6 display lease time from UTC to local time',
753
	$pconfig['dhcpv6leaseinlocaltime']
754
))->setHelp('By default DHCPv6 leases are displayed in UTC time. ' .
755
			'By checking this box DHCPv6 lease time will be displayed in local time and set to time zone selected. ' .
756
			'This will be used for all DHCPv6 interfaces lease time.');
757
758 4aa42b06 Phil Davis
$btnadv = new Form_Button(
759
	'btnadvdns',
760
	'Display Advanced',
761 3314e626 jim-p
	null,
762
	'fa-cog'
763 cd2c7940 sbeaver
);
764
765 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
766 cd2c7940 sbeaver
767
$section->addInput(new Form_StaticText(
768
	'Dynamic DNS',
769 4aa42b06 Phil Davis
	$btnadv
770 cd2c7940 sbeaver
));
771
772
$section->addInput(new Form_Checkbox(
773
	'ddnsupdate',
774
	'DHCP Registration',
775
	'Enable registration of DHCP client names in DNS.',
776
	$pconfig['ddnsupdate']
777
));
778
779
$section->addInput(new Form_Input(
780
	'ddnsdomain',
781
	'DDNS Domain',
782
	'text',
783 ea6649f7 sbeaver
	$pconfig['ddnsdomain']
784 cd2c7940 sbeaver
))->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.');
785
786
$section->addInput(new Form_IpAddress(
787
	'ddnsdomainprimary',
788
	'DDNS Server IP',
789 ea6649f7 sbeaver
	$pconfig['ddnsdomainprimary']
790 cd2c7940 sbeaver
))->setHelp('Enter the primary domain name server IP address for the dynamic domain name.');
791
792
$section->addInput(new Form_Input(
793
	'ddnsdomainkeyname',
794
	'DDNS Domain Key name',
795
	'text',
796 ea6649f7 sbeaver
	$pconfig['ddnsdomainkeyname']
797 cd2c7940 sbeaver
))->setHelp('Enter the dynamic DNS domain key name which will be used to register client names in the DNS server.');
798
799
$section->addInput(new Form_Input(
800
	'ddnsdomainkey',
801
	'DDNS Domain Key secret',
802
	'text',
803 ea6649f7 sbeaver
	$pconfig['ddnsdomainkey']
804 cd2c7940 sbeaver
))->setHelp('Enter the dynamic DNS domain key secret which will be used to register client names in the DNS server.');
805
806 391d63da Renato Botelho
$section->addInput(new Form_Select(
807
	'ddnsclientupdates',
808
	'DDNS Client Updates',
809
	$pconfig['ddnsclientupdates'],
810
	array(
811
	    'allow' => gettext('Allow'),
812
	    'deny' => gettext('Deny'),
813
	    'ignore' => gettext('Ignore'))
814
))->setHelp('How Forward entries are handled when client indicates they wish to update DNS.  ' .
815
	    'Allow prevents DHCP from updating Forward entries, Deny indicates that DHCP will ' .
816
	    'do the updates and the client should not, Ignore specifies that DHCP will do the ' .
817
	    'update and the client can also attempt the update usually using a different domain name.');
818
819
$section->addInput(new Form_Checkbox(
820
	'ddnsreverse',
821
	'DDNS Reverse',
822
	'Add reverse dynamic DNS entries.',
823
	$pconfig['ddnsreverse']
824
));
825
826 4aa42b06 Phil Davis
$btnadv = new Form_Button(
827
	'btnadvntp',
828
	'Display Advanced',
829 3314e626 jim-p
	null,
830
	'fa-cog'
831 cd2c7940 sbeaver
);
832
833 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
834 cd2c7940 sbeaver
835
$section->addInput(new Form_StaticText(
836
	'NTP servers',
837 4aa42b06 Phil Davis
	$btnadv
838 cd2c7940 sbeaver
));
839
840
$group = new Form_Group('NTP Servers');
841
842
$group->add(new Form_Input(
843
	'ntp1',
844
	'NTP Server 1',
845
	'text',
846 ea6649f7 sbeaver
	$pconfig['ntp1'],
847 cd2c7940 sbeaver
	['placeholder' => 'NTP 1']
848
));
849
850
$group->add(new Form_Input(
851
	'ntp2',
852 e32f02a5 Phil Davis
	'NTP Server 2',
853 cd2c7940 sbeaver
	'text',
854 ea6649f7 sbeaver
	$pconfig['ntp2'],
855 cd2c7940 sbeaver
	['placeholder' => 'NTP 2']
856
));
857
858
$group->addClass('ntpclass');
859
860
$section->add($group);
861
862 4aa42b06 Phil Davis
$btnadv = new Form_Button(
863
	'btnadvldap',
864
	'Display Advanced',
865 3314e626 jim-p
	null,
866
	'fa-cog'
867 cd2c7940 sbeaver
);
868
869 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
870 cd2c7940 sbeaver
871
$section->addInput(new Form_StaticText(
872
	'LDAP',
873 4aa42b06 Phil Davis
	$btnadv
874 cd2c7940 sbeaver
));
875
876
$section->addInput(new Form_Input(
877
	'ldap',
878
	'LDAP URI',
879
	'text',
880 ea6649f7 sbeaver
	$pconfig['ldap']
881 cd2c7940 sbeaver
));
882
883 4aa42b06 Phil Davis
$btnadv = new Form_Button(
884
	'btnadvnetboot',
885
	'Display Advanced',
886 3314e626 jim-p
	null,
887
	'fa-cog'
888 cd2c7940 sbeaver
);
889
890 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
891 cd2c7940 sbeaver
892
$section->addInput(new Form_StaticText(
893
	'Network booting',
894 4aa42b06 Phil Davis
	$btnadv
895 cd2c7940 sbeaver
));
896
897
$section->addInput(new Form_Checkbox(
898
	'shownetboot',
899
	'Network booting',
900
	'Enable Network Booting',
901
	$pconfig['shownetboot']
902
));
903
904
$section->addInput(new Form_Input(
905
	'bootfile_url',
906
	'Bootfile URL',
907
	'text',
908 ea6649f7 sbeaver
	$pconfig['bootfile_url']
909 cd2c7940 sbeaver
));
910
911 4aa42b06 Phil Davis
$btnadv = new Form_Button(
912
	'btnadvopts',
913
	'Display Advanced',
914 3314e626 jim-p
	null,
915
	'fa-cog'
916 cd2c7940 sbeaver
);
917
918 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
919 cd2c7940 sbeaver
920
$section->addInput(new Form_StaticText(
921
	'Additional BOOTP/DHCP Options',
922 4aa42b06 Phil Davis
	$btnadv
923 cd2c7940 sbeaver
));
924
925
$form->add($section);
926
927
$title = 'Show Additional BOOTP/DHCP Options';
928
929 b090a0d9 Stephen Beaver
if (!$pconfig['numberoptions']) {
930 0716b616 Stephen Beaver
	$noopts = true;
931 b090a0d9 Stephen Beaver
	$pconfig['numberoptions']['item'] = array(0 => array('number' => "", 'value' => ""));
932 0716b616 Stephen Beaver
} else {
933
	$noopts = false;
934 b090a0d9 Stephen Beaver
}
935
936
$counter = 0;
937
$last = count($pconfig['numberoptions']['item']) - 1;
938
939
foreach ($pconfig['numberoptions']['item'] as $item) {
940
	$group = new Form_Group(null);
941
	$group->addClass('repeatable');
942 0716b616 Stephen Beaver
	$group->addClass('adnloptions');
943 b090a0d9 Stephen Beaver
944
	$group->add(new Form_Input(
945
		'number' . $counter,
946
		null,
947
		'text',
948
		$item['number']
949
	))->setHelp($counter == $last ? 'Number':null);
950
951
	$group->add(new Form_Input(
952
		'value' . $counter,
953
		null,
954
		'text',
955
		base64_decode($item['value'])
956
	))->setHelp($counter == $last ? 'Value':null);
957
958
	$btn = new Form_Button(
959
		'deleterow' . $counter,
960 faab522f Renato Botelho
		'Delete',
961 cd7ddae6 jim-p
		null,
962
		'fa-trash'
963 b090a0d9 Stephen Beaver
	);
964
965 cd7ddae6 jim-p
	$btn->addClass('btn-warning');
966 b090a0d9 Stephen Beaver
	$group->add($btn);
967
	$section->add($group);
968
	$counter++;
969 cd2c7940 sbeaver
}
970
971 b090a0d9 Stephen Beaver
972 cd2c7940 sbeaver
$btnaddopt = new Form_Button(
973 9eeb91dd Stephen Beaver
	'addrow',
974 faab522f Renato Botelho
	'Add Option',
975 cd7ddae6 jim-p
	null,
976
	'fa-plus'
977 cd2c7940 sbeaver
);
978
979 9eeb91dd Stephen Beaver
$btnaddopt->removeClass('btn-primary')->addClass('btn-success btn-sm');
980 cd2c7940 sbeaver
981
$section->addInput($btnaddopt);
982
983
$section->addInput(new Form_Input(
984
	'if',
985
	null,
986
	'hidden',
987
	$if
988
));
989
990
print($form);
991 b090a0d9 Stephen Beaver
992 f78bbe16 Phil Davis
?>
993 c95dabdd Stephen Beaver
<div class="infoblock blockopen">
994 f78bbe16 Phil Davis
<?php
995 0a8a90f7 Phil Davis
print_info_box(
996
	sprintf(
997 48d321ca NewEraCracker
		gettext('The DNS servers entered in %1$sSystem: General Setup%3$s (or the %2$sDNS forwarder%3$s if enabled) will be assigned to clients by the DHCP server.'),
998 0a8a90f7 Phil Davis
		'<a href="system.php">',
999
		'<a href="services_dnsmasq.php"/>',
1000 9eeb91dd Stephen Beaver
		'</a>') .
1001 0a8a90f7 Phil Davis
	'<br />' .
1002
	sprintf(
1003
		gettext('The DHCP lease table can be viewed on the %1$sStatus: DHCPv6 leases%2$s page.'),
1004
		'<a href="status_dhcpv6_leases.php">',
1005
		'</a>'),
1006
	'info',
1007
	false);
1008 99caa67c Seth Mos
?>
1009 f78bbe16 Phil Davis
</div>
1010 cd2c7940 sbeaver
<div class="panel panel-default">
1011 544af3fe k-paulius
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("DHCPv6 Static Mappings for this Interface");?></h2></div>
1012 cd2c7940 sbeaver
	<div class="panel-body table-responsive">
1013
		<table class="table table-striped table-hover table-condensed">
1014
			<thead>
1015
				<tr>
1016
					<th><?=gettext("DUID")?></th>
1017
					<th><?=gettext("IPv6 address")?></th>
1018
					<th><?=gettext("Hostname")?></th>
1019
					<th><?=gettext("Description")?></th>
1020
					<th><!-- Buttons --></th>
1021
				</tr>
1022
			</thead>
1023
			<tbody>
1024 99caa67c Seth Mos
<?php
1025 6e3488e9 Phil Davis
if (is_array($a_maps)):
1026 99caa67c Seth Mos
	$i = 0;
1027 cd2c7940 sbeaver
	foreach ($a_maps as $mapent):
1028 6e3488e9 Phil Davis
		if ($mapent['duid'] != "" or $mapent['ipaddrv6'] != ""):
1029 99caa67c Seth Mos
?>
1030 cd2c7940 sbeaver
				<tr>
1031 7d0ad4ec Joecowboy
					<td>
1032 cd2c7940 sbeaver
						<?=htmlspecialchars($mapent['duid'])?>
1033 7d0ad4ec Joecowboy
					</td>
1034
					<td>
1035 cd2c7940 sbeaver
						<?=htmlspecialchars($mapent['ipaddrv6'])?>
1036 7d0ad4ec Joecowboy
					</td>
1037
					<td>
1038 cd2c7940 sbeaver
						<?=htmlspecialchars($mapent['hostname'])?>
1039
					</td>
1040
					<td>
1041
						<?=htmlspecialchars($mapent['descr'])?>
1042
					</td>
1043
					<td>
1044 33f0b0d5 Stephen Beaver
						<a class="fa fa-pencil"	title="<?=gettext('Edit static mapping')?>" href="services_dhcpv6_edit.php?if=<?=$if?>&amp;id=<?=$i?>"></a>
1045
						<a class="fa fa-trash"	title="<?=gettext('Delete static mapping')?>" href="services_dhcpv6.php?if=<?=$if?>&amp;act=del&amp;id=<?=$i?>"></a>
1046 7d0ad4ec Joecowboy
					</td>
1047 99caa67c Seth Mos
				</tr>
1048 cd2c7940 sbeaver
<?php
1049
		endif;
1050
	$i++;
1051
	endforeach;
1052
endif;
1053
?>
1054
			</tbody>
1055 99caa67c Seth Mos
		</table>
1056
	</div>
1057 cd2c7940 sbeaver
</div>
1058
1059 c10cb196 Stephen Beaver
<nav class="action-buttons">
1060 c9679d8c Stephen Beaver
	<a href="services_dhcpv6_edit.php?if=<?=$if?>" class="btn btn-sm btn-success"/>
1061 9d5a20cf heper
		<i class="fa fa-plus icon-embed-btn"></i>
1062 c9679d8c Stephen Beaver
		<?=gettext("Add")?>
1063
	</a>
1064 cd2c7940 sbeaver
</nav>
1065
1066 8fd9052f Colin Fleming
<script type="text/javascript">
1067 ee9530e1 Colin Fleming
//<![CDATA[
1068 6e3488e9 Phil Davis
events.push(function() {
1069 cd2c7940 sbeaver
1070 4aa42b06 Phil Davis
	// Show advanced DNS options ======================================================================================
1071
	var showadvdns = false;
1072
1073
	function show_advdns(ispageload) {
1074
		var text;
1075
		// On page load decide the initial state based on the data.
1076
		if (ispageload) {
1077
<?php
1078
			if (!$pconfig['ddnsupdate'] &&
1079
			    empty($pconfig['ddnsdomain']) &&
1080
			    empty($pconfig['ddnsdomainprimary']) &&
1081
			    empty($pconfig['ddnsdomainkeyname']) &&
1082
			    empty($pconfig['ddnsdomainkey']) &&
1083
			    (empty($pconfig['ddnsclientupdates']) || ($pconfig['ddnsclientupdates'] == "allow")) &&
1084
			    !$pconfig['ddnsreverse']) {
1085
				$showadv = false;
1086
			} else {
1087
				$showadv = true;
1088
			}
1089
?>
1090
			showadvdns = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1091
		} else {
1092
			// It was a click, swap the state.
1093
			showadvdns = !showadvdns;
1094
		}
1095
1096
		hideCheckbox('ddnsupdate', !showadvdns);
1097
		hideInput('ddnsdomain', !showadvdns);
1098
		hideInput('ddnsdomainprimary', !showadvdns);
1099
		hideInput('ddnsdomainkeyname', !showadvdns);
1100
		hideInput('ddnsdomainkey', !showadvdns);
1101
		hideInput('ddnsclientupdates', !showadvdns);
1102
		hideCheckbox('ddnsreverse', !showadvdns);
1103
1104
		if (showadvdns) {
1105
			text = "<?=gettext('Hide Advanced');?>";
1106
		} else {
1107
			text = "<?=gettext('Display Advanced');?>";
1108
		}
1109
		$('#btnadvdns').html('<i class="fa fa-cog"></i> ' + text);
1110 cd2c7940 sbeaver
	}
1111
1112 4aa42b06 Phil Davis
	$('#btnadvdns').click(function(event) {
1113
		show_advdns();
1114 cd2c7940 sbeaver
	});
1115
1116 4aa42b06 Phil Davis
	// Show advanced NTP options ======================================================================================
1117
	var showadvntp = false;
1118 cd2c7940 sbeaver
1119 4aa42b06 Phil Davis
	function show_advntp(ispageload) {
1120
		var text;
1121
		// On page load decide the initial state based on the data.
1122
		if (ispageload) {
1123
<?php
1124
			if (empty($pconfig['ntp1']) && empty($pconfig['ntp2'])) {
1125
				$showadv = false;
1126
			} else {
1127
				$showadv = true;
1128
			}
1129
?>
1130
			showadvntp = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1131
		} else {
1132
			// It was a click, swap the state.
1133
			showadvntp = !showadvntp;
1134
		}
1135 cd2c7940 sbeaver
1136 4aa42b06 Phil Davis
		hideInput('ntp1', !showadvntp);
1137
		hideInput('ntp2', !showadvntp);
1138 cd2c7940 sbeaver
1139 4aa42b06 Phil Davis
		if (showadvntp) {
1140
			text = "<?=gettext('Hide Advanced');?>";
1141
		} else {
1142
			text = "<?=gettext('Display Advanced');?>";
1143
		}
1144
		$('#btnadvntp').html('<i class="fa fa-cog"></i> ' + text);
1145
	}
1146 cd2c7940 sbeaver
1147 4aa42b06 Phil Davis
	$('#btnadvntp').click(function(event) {
1148
		show_advntp();
1149 cd2c7940 sbeaver
	});
1150
1151 4aa42b06 Phil Davis
	// Show advanced LDAP options ======================================================================================
1152
	var showadvldap = false;
1153 cd2c7940 sbeaver
1154 4aa42b06 Phil Davis
	function show_advldap(ispageload) {
1155
		var text;
1156
		// On page load decide the initial state based on the data.
1157
		if (ispageload) {
1158
<?php
1159
			if (empty($pconfig['ldap'])) {
1160
				$showadv = false;
1161
			} else {
1162
				$showadv = true;
1163
			}
1164
?>
1165
			showadvldap = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1166
		} else {
1167
			// It was a click, swap the state.
1168
			showadvldap = !showadvldap;
1169
		}
1170
1171
		hideInput('ldap', !showadvldap);
1172
1173
		if (showadvldap) {
1174
			text = "<?=gettext('Hide Advanced');?>";
1175
		} else {
1176
			text = "<?=gettext('Display Advanced');?>";
1177
		}
1178
		$('#btnadvldap').html('<i class="fa fa-cog"></i> ' + text);
1179
	}
1180
1181
	$('#btnadvldap').click(function(event) {
1182
		show_advldap();
1183 cd2c7940 sbeaver
	});
1184
1185 4aa42b06 Phil Davis
	// Show advanced Netboot options ======================================================================================
1186
	var showadvnetboot = false;
1187
1188
	function show_advnetboot(ispageload) {
1189
		var text;
1190
		// On page load decide the initial state based on the data.
1191
		if (ispageload) {
1192
<?php
1193
			if (!$pconfig['shownetboot'] && empty($pconfig['bootfile_url'])) {
1194
				$showadv = false;
1195
			} else {
1196
				$showadv = true;
1197
			}
1198
?>
1199
			showadvnetboot = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1200
		} else {
1201
			// It was a click, swap the state.
1202
			showadvnetboot = !showadvnetboot;
1203
		}
1204
1205
		hideCheckbox('shownetboot', !showadvnetboot);
1206
		hideInput('bootfile_url', !showadvnetboot);
1207
1208
		if (showadvnetboot) {
1209
			text = "<?=gettext('Hide Advanced');?>";
1210
		} else {
1211
			text = "<?=gettext('Display Advanced');?>";
1212
		}
1213
		$('#btnadvnetboot').html('<i class="fa fa-cog"></i> ' + text);
1214
	}
1215
1216
	$('#btnadvnetboot').click(function(event) {
1217
		show_advnetboot();
1218 cd2c7940 sbeaver
	});
1219
1220 4aa42b06 Phil Davis
	// Show advanced additional opts options ===========================================================================
1221
	var showadvopts = false;
1222
1223
	function show_advopts(ispageload) {
1224
		var text;
1225
		// On page load decide the initial state based on the data.
1226
		if (ispageload) {
1227
<?php
1228
			if (empty($pconfig['numberoptions']) ||
1229
			    (empty($pconfig['numberoptions']['item'][0]['number']) && (empty($pconfig['numberoptions']['item'][0]['value'])))) {
1230
				$showadv = false;
1231
			} else {
1232
				$showadv = true;
1233
			}
1234
?>
1235
			showadvopts = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1236
		} else {
1237
			// It was a click, swap the state.
1238
			showadvopts = !showadvopts;
1239
		}
1240
1241
		hideClass('adnloptions', !showadvopts);
1242
		hideInput('addrow', !showadvopts);
1243
1244
		if (showadvopts) {
1245
			text = "<?=gettext('Hide Advanced');?>";
1246
		} else {
1247
			text = "<?=gettext('Display Advanced');?>";
1248
		}
1249
		$('#btnadvopts').html('<i class="fa fa-cog"></i> ' + text);
1250
	}
1251
1252
	$('#btnadvopts').click(function(event) {
1253
		show_advopts();
1254 9eeb91dd Stephen Beaver
		checkLastRow();
1255 cd2c7940 sbeaver
	});
1256
1257 0f0c4473 Renato Botelho
	$('#enable').click(function() {
1258
	    do_toggle();
1259
	});
1260
1261
	function do_toggle() {
1262
		if ($('#enable').prop('checked')) {
1263
			$('.form-group:not(:first-child)').show();
1264 ad1188d9 Stephen Beaver
			hideClass('adnloptions', <?php echo json_encode($noopts); ?>);
1265
			hideInput('addrow', <?php echo json_encode($noopts); ?>);
1266 0f0c4473 Renato Botelho
		} else {
1267
			$('.form-group:not(:first-child)').hide();
1268
		}
1269 9eeb91dd Stephen Beaver
	}
1270
1271 cd2c7940 sbeaver
	// On initial load
1272 9eeb91dd Stephen Beaver
	do_toggle();
1273 4aa42b06 Phil Davis
	show_advdns(true);
1274
	show_advntp(true);
1275
	show_advldap(true);
1276
	show_advnetboot(true);
1277
	show_advopts(true);
1278 611cc5ca Renato Botelho
	if ($('#enable').prop('checked')) {
1279
		hideClass('adnloptions', <?php echo json_encode($noopts); ?>);
1280
		hideInput('addrow', <?php echo json_encode($noopts); ?>);
1281
	} else {
1282
		hideClass('adnloptions', true);
1283
		hideInput('addrow', true);
1284
	}
1285 9eeb91dd Stephen Beaver
1286 cd2c7940 sbeaver
});
1287 ee9530e1 Colin Fleming
//]]>
1288 99caa67c Seth Mos
</script>
1289 cd2c7940 sbeaver
1290 2f5dafed heper
<?php include('foot.inc');