Project

General

Profile

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